-
Notifications
You must be signed in to change notification settings - Fork 705
Module System #28761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Module System #28761
Conversation
bcad481 to
68be122
Compare
|
Note: I have not yet updated all the parser tests because that would make this PR very large (~20k lines) due to the |
|
more serious review to come |
|
if program |
This doesn't work today even without the module stuff right? And struct naming is global at the moment? But yeah would certainly be nice to have all that stuff working as one would expect. |
b987037 to
fef78a1
Compare
|
Addressed the first wave of comments in fef78a1 |
Alright so yeah we can make this work but only if |
Right yeah I wasn't really thinking about that. Maybe we just don't worry about it until the external structs stuff is complete. |
d0cd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful to have one of the existing leo-examples adapted to use the new module system. Or even add a new one!
Can we also file an issue in leo-docs-source to document this?
tests/expectations/compiler/modules/leaf_module_with_submodules.out
Outdated
Show resolved
Hide resolved
d0cd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the PR looks good! Left some relatively minor nits and questions. This should be good to go after the parser expectations are in.
There is also a fairly extensive example here: ProvableHQ/leo-examples#17
7014d1f to
c562c39
Compare
c562c39 to
2eb1c11
Compare
Closes #28770
This PR introduces a structured module system for Leo, enabling multi-file programs under the
src/directory with clear rules for module layout and resolution.📁 Example Directory Structure
📦 Modules and Their Access Paths
Given the structure above, the following modules are defined:
common.leodefines modulecommon, accessible frommain.leovia:common::<item>outer.leodefines moduleouter, accessible frommain.leovia:outer::<item>outer/inner.leodefines submoduleouter::inner, accessible from:main.leo:outer::inner::<item>outer.leo:inner::<item>📏 Module Layout Rules
This PR also enforces new rules to prevent ambiguity and ensure consistency:
foo.leofoo.leofile and afoo/directory containing the submodules:Only relative paths are implemented so far. That means that items in
outer.leocannot be accessed from items ininner.leo, for example. This is limiting for now but will no longer be an issue when we add absolute paths.The changes were tedious but not particularly complicated. The largest changes in the compiler is the replacement of
Expression::IdentifierwithExpression::Path.For now, modules can only have
struct,inline, andconst. We may decide to relax that restriction in the future.I've added support for modules in the current interpreter and added some tests. Hopefully mirroring this implementation in the new interpreter won't cause too much trouble.