-
Notifications
You must be signed in to change notification settings - Fork 100
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
Experiment: enable concise top-level imports #435
base: master
Are you sure you want to change the base?
Conversation
Interesting, but I wonder if moc is smart enough to dead-code the (many) unused fields of Lib.mo . We should verify that first otherwise folks will pull in all sort of code they don't use, bloating binaries. @nomeata might know the answer off the top of his head. On slack, I was actually suggesting we should add another form of abbreviated package import to motoko Something like:
that literally expands to:
So you don't just import everything but only the libraries you specify. |
Makes sense, +1. |
The frontend, type checker and IR-to-IR passes will spend time on all the modules, but the backend will skip all unused code. At least if it's just modules and functions; probably not tate like in the stable memory module. |
The state of experimentalstablememory is, I believe, hidden within the compiler primitives, so probably won't affect this either. |
The sugar would lift a convention (name the import like the basename of the file) into a language feature. Not sure if that’s advisable. And does it gain much over @rvanasa’s syntax? If the only benefit is that it’s faster to compile, I’d rather make the compiler optimize that syntax :-) |
does that already work, by defaulting
Otherwise it feels a bit like a convention too, no? |
I thought the lib.mo is implicit if you import a directory? Or did we drop that? |
Yep, this already works as shown! I had to limit the number of imports, though: CI output |
I think I never documented it because I didn't understand what it was doing... and maybe Andreas had objected? I can't even find the design doc you wrote now... Yep, undocumented: |
Ah, no, I think that's because the base test tries to import all libraries and compile them to wasmtime, which ExperimentalStableMemory.mo isn't able to do. Just a hunch though. My hunch is that excluding the IC related libraries (ExperimentalXXX.mo and CertifiedVariables) would be enough (and maybe even too much). That might suggest that the compiler isn't dead-coding as much as we think though... |
Don't worry, this can wait.... |
It looks like we can add everything except (at least one of the) |
Instead of relying on Lib.mo, we could, perhaps, extend this to profiles JS.mo (JS playground) Wasi.mo (wasmtime) and IC.mo and maybe use the default Lib.mo for a least common denominator. I think Rand.rand() might still be a (fixable) problem. Crazy? And we should fix the compiler to error gracefully, not crash. I'll take a look next week to see why it's crashing. |
+1! Perhaps we could also use this as an opportunity to capitalize what are currently specified as |
Adds a generated
lib.mo
file to enable the following import style:import { Nat; Array } "mo:base";
TODO:
lib.mo
via CI