-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat(compiler): Refactor exports #1244
Conversation
12a134f
to
a88e1a6
Compare
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.
This PR is 🔥 - I had a few questions/thoughts
@@ -14,21 +17,61 @@ let safe_to_remove_import = i => | |||
| _ => false | |||
}; | |||
|
|||
let is_used = ident => | |||
Option.is_some(Ident.find_same_opt(ident, used_symbols^)); |
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.
We should add some utilities to the Ident module (like contains
). Probably not needed in this PR.
a88e1a6
to
cc456d9
Compare
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.
Approved! 🎉
cc456d9
to
2e74700
Compare
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.
I mostly follow this, and it looks good to me. One very minor request for information, and then I think it's good to go.
| Path.PExternal(Path.PIdent(mod_) as p, ident, _) => | ||
let allocation_type = get_allocation_type(env, val_type); | ||
let mod_decl = Env.find_module(p, None, env); | ||
// Lookup external exports to import them into the module |
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.
I'm a little confused what this is doing. Can you clarify a little more?
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.
Yeah! So the way imports actually make it into the WebAssembly module is via lookup_symbol
registering the individual values and functions to include them in the module. Previously doing export foo
was sugar for export let foo = foo
, making foo
get used and thus be included as an import, but now an export
statement skips the extra binding. The lookup here is effectively us saying that we plan to use that value so it actually gets imported.
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.
I'm going to give this a LGTM from my skim read of what's going on.
2e74700
to
4074f39
Compare
This PR refactors how exports are compiled in Grain. Namely,
will now properly result in a type error, whereas previously
bar
was unexpectedly in scope.Because of these changes, the hello world module size is reduced again by 25%, coming in under 39k.