Skip to content
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

Generate ES imports/exports to enable tree shaking #6

Open
davidyuk opened this issue Mar 28, 2021 · 1 comment
Open

Generate ES imports/exports to enable tree shaking #6

davidyuk opened this issue Mar 28, 2021 · 1 comment

Comments

@davidyuk
Copy link

davidyuk commented Mar 28, 2021

purescript planning to introduce it in the next major release: purescript/purescript#3613

Until that we can try to rewrite require/module.exports by ourselves this way: https://github.com/jameswomack/replace-require-with-import/blob/master/index.js

Also, would be nice to import not the whole file, but only used parts, like

import { falsifyErrors as Erlang_Helpers_falsifyErrors } from "../Erlang.Helpers";

instead of

import Erlang_Helpers from "../Erlang.Helpers";

Tree shaking should significantly reduce the amount of imported code if the user needs one specific function, not the whole compiler.

@gorbak25
Copy link
Contributor

We started out with a tree shaking in mind but we unfortunately get rid of it at one point :(
The main issue is with circular imports - they are commonplace in erlang but strictly forbidden in purescript :(
In Erlang you can have a function in module A calling a function in module B calling a function in module A.
To work around it remote calls are being dispatched dynamically via a code server - https://github.com/erlscripten/erlps-core/blob/2be641733d1179a6198835f917c3d3cbbc820712/es6/ffi_es6_builtins.js#L998
This unfortunately is not optimal and incurs a performance penalty - the upside is that this allows us to match erlang's semantics closely and weird OTP stuff like on_load callbacks or hot code reloading are feasible to implement.

@radrow ES6 modules allow for circular imports - let's investigate whether we can make tree shaking working :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants