Sub-optimal include directory resolution #488

Closed
opened 2023-09-06 16:54:55 +09:00 by zxq9 · 4 comments
zxq9 commented 2023-09-06 16:54:55 +09:00 (Migrated from gitlab.com)

Created by: hanssv

Not sure if it is a minimal reproducing example, but it should be small enough. Three files, in three different directories:
/tmp/foo.aes:

include "/tmp/dir1/bar.aes"
contract C =
  entrypoint f() = D.g()

/tmp/dir1/bar.aes:

include "../dir2/baz.aes"
namespace D =
  function g() = E.h()

/tmp/dir2/baz.aes:

namespace E =
  function h() = 42

Straight up compiling foo.aes fails:

Parse error in '/tmp/dir1/bar.aes' at line 1, col 1:
Couldn't find include file '../dir2/baz.aes'

The problem is that while resolving the includes in bar.aes (which is in dir1) we still do this relative to the root source file (i.e. in /tmp) this means we won't find ../dir2.

A workaround is to pass both the top level and the subdirectory as include paths:

$ ./aesophia_cli /tmp/foo.aes -i /tmp -i /tmp/dir2
cb_+JdGA6DSagnFZzPzngQuBCq056yYPk6ObA8ElyhfEBqi/J/jPMC4arg9/gbU40wCNwAHAQNU/kTWRB8ANwA3ABoOgj8BAz/+eCFrswI3AAcEAxEG1ONM/uC+/GEANwAHBAMReCFrs6cvBBEG1ONMES5FLmgRRNZEHxFpbml0EXgha7MRLkQuZxHgvvxhBWaCLwCFNy40LjAA3jUBlw==
*Created by: hanssv* Not sure if it is a minimal reproducing example, but it should be small enough. Three files, in three different directories: `/tmp/foo.aes`: ``` include "/tmp/dir1/bar.aes" contract C = entrypoint f() = D.g() ``` `/tmp/dir1/bar.aes`: ``` include "../dir2/baz.aes" namespace D = function g() = E.h() ``` `/tmp/dir2/baz.aes`: ``` namespace E = function h() = 42 ``` Straight up compiling `foo.aes` fails: ``` Parse error in '/tmp/dir1/bar.aes' at line 1, col 1: Couldn't find include file '../dir2/baz.aes' ``` The problem is that while resolving the includes in `bar.aes` (which is in `dir1`) we still do this relative to the root source file (i.e. in `/tmp`) this means we won't find `../dir2`. A workaround is to pass both the top level and the subdirectory as include paths: ``` $ ./aesophia_cli /tmp/foo.aes -i /tmp -i /tmp/dir2 cb_+JdGA6DSagnFZzPzngQuBCq056yYPk6ObA8ElyhfEBqi/J/jPMC4arg9/gbU40wCNwAHAQNU/kTWRB8ANwA3ABoOgj8BAz/+eCFrswI3AAcEAxEG1ONM/uC+/GEANwAHBAMReCFrs6cvBBEG1ONMES5FLmgRRNZEHxFpbml0EXgha7MRLkQuZxHgvvxhBWaCLwCFNy40LjAA3jUBlw== ```
zxq9 commented 2023-09-06 16:57:29 +09:00 (Migrated from gitlab.com)

Created by: marc0olo

thanks for creating the issue! 👍

maybe it would be good if the include path doesn't have to be referenced at all if every path is relative? 🤔

*Created by: marc0olo* thanks for creating the issue! 👍 maybe it would be good if the include path doesn't have to be referenced at all if every path is relative? 🤔
zxq9 commented 2023-09-06 17:03:53 +09:00 (Migrated from gitlab.com)

Created by: hanssv

Definitely - this contract should compile with aesophia_cli /tmp/foo.aes and nothing more.

*Created by: hanssv* Definitely - this contract should compile with `aesophia_cli /tmp/foo.aes` and nothing more.
zxq9 commented 2023-09-06 19:00:20 +09:00 (Migrated from gitlab.com)

Created by: radrow

Module system in Sophia is inherently broken and we plan to fix it in the rewritten version. I am giving it low priority because

  • It does not affect security
  • No major functionality is broken
  • There is a workaround
*Created by: radrow* Module system in Sophia is inherently broken and we plan to fix it in the rewritten version. I am giving it low priority because - It does not affect security - No major functionality is broken - There is a workaround
zxq9 commented 2023-09-08 05:21:45 +09:00 (Migrated from gitlab.com)

Created by: hanssv

Straighforward to fix for now 😅

*Created by: hanssv* Straighforward to fix for now 😅
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#488
No description provided.