maybejustjames / zephyr Goto Github PK
View Code? Open in Web Editor NEWTree shaking breeze for PureScript CoreFn AST
License: Mozilla Public License 2.0
Tree shaking breeze for PureScript CoreFn AST
License: Mozilla Public License 2.0
Simply running
purs compile --codegen corefn (spago sources)
zephyr Main
gives me this error:
zephyr: output/Affjax/foreign.js: copyFile:atomicCopyFileContents:withReplacementFile:copyFileToHandle:openBinaryFile: does not exist (No such file or directory)
add-path
was deprecated today.
Needs to be replaced with this syntax.
echo "action_state=yellow" >> $GITHUB_ENV
Thank you very much for this nice tool. I use it for purescript-native cpp code generation:
PureScript Shared Objects
It is essential in the sence that the ffi implementations are not complete and zephyr allowes me to generate only the code which is just needed and does not pull in references of unimplemented functions. One issue i stumbled across is that zephyr creates new files for each run, regardless if the contents has changed or not. This will trigger all depending compilations which should not necessary at all. I worked around this by comparing the file sizes with the previous run, if they match then the new file gets the timestamp of the older file. (zephyr.bash in the mentioned repo)
The second issue is that I would like to get the dependencies for groups of entry points. I use this for automatic assembling of the libraries and applications. I worked around this by calling zephyr for each group for different output directories. This should be possible in one run too.
If this makes sense for you I would like to hear from you. I could try to implement this if you give me some guidance. Thanks a lot!
And ideally psc-package.
As mentioned in #64, Nix makes setting up a build/dev environment much easier.
Downloading the binary for zephyr 0.3.2 fails on my Arch Linux system with the following error.
/zephyr: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
I worked around this issue by simply symlinking my libtinfo.so.5
library to libtinfo.so.6
.
sudo ln -s /usr/lib/libtinfo.so.6 usr/liblibtinfo.so.5
I don't know if this work-around will go belly-up later (I haven't tested it), but I thought I'd pass it along in case it is helpful.
PureScript's 0.13.8 release changed the format of externs to use a binary encoding PR here.
If you try to use Zephyr on a project compiled with 0.13.8 you'll see an error like this:
zephyr: output/Affjax/externs.json: openBinaryFile: does not exist (No such file or directory)
There are no longer externs.json
files. Instead, this would be a externs.cbor
file in the same location in the output directory.
We'll need to update Zephyr to accommodate the new format.
(As a related note, there has been some discussion (1, 2) about moving Zephyr into the compiler, which would help with staying up-to-date with big changes in the compiler. Do you have any interest in this?)
I was surprised to see that using zephyr can sometimes increase bundle sizes. Is there a mistake in my workflow?
index.js | parcel minified |
|
---|---|---|
Just bundle-app |
316K | 128K |
With zephyr |
332K | 132K |
git clone https://github.com/purescript-halogen/purescript-halogen-template.git bundle-test
cd bundle-test
# Workflow with just spago bundle-app and parcel (no zephyr)
npm run build-prod
du -hs prod/index.js dist/prod.*.js
# 316K prod/index.js # bundle-app output
# 128K dist/prod.0a4f58ae.js # minified by parcel
# Including zephyr
rm -r dist
spago build --purs-args '--codegen js,corefn' && zephyr Main.main --dce-foreign
purs bundle -o prod/index.js -m Main dce-output/**/*.js
parcel build prod/index.html
du -hs prod/index.js dist/prod.*.js
# 332K prod/index.js # zephyr + bundle-app output
# 132K dist/prod.08b89072.js # minified by parcel
https://discourse.purescript.org/t/recommended-tooling-for-purescript-in-2020/1615/4
I don't see the option referenced anywhere except in the argument parser.
Being able to install via NPM would probably be nice and lower the barrier to using zephyr
Removed foreign declarations yield a warning.
Hello!
When attempting to build both zephyr-0.3.0
yesterday and zephyr-0.3.1
today the following errors have come up both times:
zephyr> build (lib + exe)
Preprocessing library for zephyr-0.3.1..
Building library for zephyr-0.3.1..
[1 of 7] Compiling Language.PureScript.DCE.Constants
[2 of 7] Compiling Language.PureScript.DCE.Errors
[3 of 7] Compiling Language.PureScript.DCE.Foreign
/mnt/c/code/hs/zephyr/src/Language/PureScript/DCE/Foreign.hs:135:21: error:
Not in scope: data constructor ‘JSAsyncFunction’
|
135 | isUsedInStmt n (JSAsyncFunction _ _ _ _ es _ (JSBlock _ ss _) _) =
| ^^^^^^^^^^^^^^^
/mnt/c/code/hs/zephyr/src/Language/PureScript/DCE/Foreign.hs:165:21: error:
Not in scope: data constructor ‘JSAwaitExpression’
Perhaps you meant one of these:
‘JSAssignExpression’ (imported from Language.JavaScript.Parser.AST),
‘JSCallExpression’ (imported from Language.JavaScript.Parser.AST),
‘JSClassExpression’ (imported from Language.JavaScript.Parser.AST)
|
165 | isUsedInExpr n (JSAwaitExpression _ e) = isUsedInExpr n e
| ^^^^^^^^^^^^^^^^^
-- While building package zephyr-0.3.1 using:
/home/me/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.w/home/wsl1/dist/x86_64-linux/Cabal-2.4.0.1 build lib:zephyr exe:zephyr --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
On investigation, the two mentioned constructors JSAsyncFunction
and JSAwaitExpression
only appear to have been included in Language.JavaScript.Parser.AST.JSExpression
in language-javascript-0.7.1.0
(and were not present in 0.7.0.0
).
The stack.yaml
specifically refers to language-javascript-0.7.0.0
and the zephyr.cabal
file has a version bound of language-javascript ^>=0.7
.
For reference, I'm building with stack build --copy-bins
using stack-2.3.1
on WSL1 Ubuntu 18.04
.
Bumping the version in the stack.yaml
to 0.7.1.0
allows everything to build fine. :)
It would be nice to remove dead branches of case expressions.
This is important for if
statements:
if (Utils.production == "production")
then ...
else ...
For this case there could be a flag to provide value of Utils.production
so zypher
could infer that this is a production build.
Hi there,
It would be great if zephyr had a macos-arm64
(aka aarch64-darwin
) build like purescript
itself does it would allow to provide this architecture for the easy-purescript-nix
tooling which doesn't currently support it because of https://github.com/justinwoo/easy-purescript-nix/blob/master/zephyr.nix#L20
Cheers,
Jun
zephyr
binary isn't compatible with musl and requires glibc (what about uclibc?). The errors I was getting trying to use Alpine Linux while trying to use the v0.3.2
release binary wasn't very clear but eventually I tracked it down to this incompatibility. It could be useful to mention this somewhere in the docs.
At work we use Zephyr built from source with PureScript 0.13.3 (after #21 landed) and it works fine with files compiled with other PureScript 0.13.x versions.
However, I recently switched us over to use the Zephyr which is included in easy-purescript-nix, which is the last release: 0.2.1. Running this version on a project compiled with PureScript 0.13.6 on Linux causes this error:
zephyr: dce-output/Web.Fetch.Integrity/externs.json: openBinaryFile: does not exist (No such file or directory)
I put together a reproduction of most of our PureScript dependencies, which uses version 0.13.6 of the compiler and version 0.2.1 of Zephyr. But this reproduction fails when compiled and run on Mac OS with a different error:
zephyr: output/Web.HTML.HTMLTableHeaderCellElement/corefn.json: openBinaryFile: resource exhausted (Too many open files)
This is despite setting a large upper limit on file handles on Mac OS, as described in #9.
I think these errors are red herrings and that projects running on 0.13.x ought to use versions of Zephyr compiled with PureScript 0.13.x. I have been having trouble updating the reproduction to compile Zephyr from source on the master branch using PureScript 0.13.3, but I'll test that out tomorrow and make an update here.
That said: I believe it's worth making a new release compiled with PureScript 0.13.3 which could be added to easy-purescript-nix for everyone to use, regardless of whether I can fully reproduce this issue outside our codebase here.
after running zephyr on this recipe after clicking on plus or minus it will throws an error.
the problem is inside the halogen free monad hooks, but I could not find the culprit.
I tried running zephyr on macOS 10.13 Beta (17A362a) in a clone of the pux-starter-app and got this:
± zephyr -f Main.main
zephyr: output/Data.DateTime/corefn.json: openBinaryFile: resource exhausted (Too many open files)
You can work around the problem with these commands:
sudo sysctl -w kern.maxfiles=1000000
ulimit -S -n 8000
Currently this is still pointed at 0.13.8, but 0.14.x has been out for a while. It appears to work, but a banner comment appears at the top of the file saying it's generated with PureScript 0.13.8 which raises some red flags to me.
The repo mentions "tree shaking tool" a lot, but grammatically it should be compound adjective as "tree-shaking tool" in the README and other places through the repo.
From Grammar Monster:
You can use a hyphen (or hyphens) to link the words in a compound adjective to show it is a single adjective. (A compound adjective is a single adjective that is made up of more than one word.) For example:
- two-seater aircraft
- never-to-be-forgotten experience
An existing example is in Rollup's documentation
So it seems like the latest purescript version doesn't generate json externs anymore so running zephyr breaks with errors like:
zephyr: output/Affjax/externs.json: openBinaryFile: does not exist (No such file or directory)
I tried running zephyr on the Spork todo-mvc example https://github.com/natefaubion/purescript-spork/blob/master/package.json#L6
yarn example:todo-mvc -- -- -g corefn
...
zephyr Todo.Main.main
And zephyr ate up about 30min of CPU time across 6 cores, after which I killed it. It seems unlikely that it was doing productive work for that amount of time.
Is it possible to integrate zephyr with purs loader?
$ zephyr -f Main.main
Error: Failed parsing:
output/Data.TraversableWithIndex/corefn.json
output/Data.Semigroup.Last/corefn.json
output/Control.Monad.Rec.Class/corefn.json
output/Data.Monoid.Generic/corefn.json
output/Data.Show.Generic/corefn.json
... (139 more)
It turned
exports.a = "❄";
into
exports.a = "�";
#10, other than turning off evaluation we could
I've been testing the spork todo-mvc example, and it is failing when using zephyrs output. The app loads, but I think there is a bad transform, particularly around pattern matches.
For example, some original output:
var update = function (model) {
return function (v) {
if (v instanceof None) {
return Spork_Transition.purely(model);
};
if (v instanceof UpdatePending) {
return Spork_Transition.purely({
pending: v.value0,
fresh: model.fresh,
todos: model.todos,
visibility: model.visibility
});
};
...
And the corresponding output from zephyr:
var update = function (model) {
return function (v) {
if (v instanceof None) {
return Spork_Transition.purely(model);
};
if (v instanceof UpdatePending) {
return Spork_Transition.purely({
pending: v,
fresh: model.fresh,
todos: model.todos,
visibility: model.visibility
});
};
...
In particular this diff:
pending: v.value0,
pending: v,
This is giving me a dreaded [object Object]
🙀
Hey @coot
Happy new year 🥳
I think it'd be great if zephyr worked with the new version of the compiler when it gets released.
I've tried to incorporate some older changes from @kl0tl but something seems amiss.
It'd be great if you could have a look at the changes here: https://github.com/working-group-purescript-es/zephyr/pull/1/files
This might actually be intentional and we will need to update the FFI in the "offending" module. I'm using react-basic-hooks
.
And that has code like this:
exports.useEffect_ = function (eq, deps, effect) {
var memoizedKey = exports.useMemo_(eq, deps);
React.useEffect(effect, [memoizedKey]);
};
I don't use useMemo_
(in fact I can't since it's not exported) but I use useEffect
which in turn uses useEffect_
which then can't find useMemo_
.
Would you say this is a bug or should the FFI be rewritten in a way that avoids this?
Edit: Yeah I just had a look at dce-output
and that's what's happening. I will try to rewrite the FFI.
I thought I would try out Zephyr and see if I could improve my build sizes, but I seem to be running into a problem when I run zephyr Main.main
. Here's what I did.
First I checked out the zephyr repo and ran stack install
, which added zephyr to my path. I have Stack Version 1.5.1 x86_64 hpack-0.17.1, PureScript 0.11.6, and Pulp 11.0.0. Then I went to my project's root and ran pulp build -- --dump-corefn
which compiled my project. Then I ran zephyr Main.main
and I got this error...
Error
Failed parsing:
output/DOM.File.FileReader/corefn.json
output/DOM.Event.WheelEvent/corefn.json
output/Data.HeytingAlgebra/corefn.json
output/DOM.HTML.HTMLMediaElement.NetworkState/corefn.json
output/Control.Monad.Writer.Class/corefn.json
output/Data.Bifunctor.Clown/corefn.json
output/DOM.HTML.HTMLOptGroupElement/corefn.json
output/Data.List.Lazy.NonEmpty/corefn.json
output/Data.Distributive/corefn.json
output/Data.Interval/corefn.json
output/Control.Monad.Gen/corefn.json
output/Data.Int.Bits/corefn.json
output/Data.Monoid.Dual/corefn.json
output/Data.Time.Component.Gen/corefn.json
output/Data.Identity/corefn.json
output/Data.Monoid/corefn.json
output/DOM.HTML.HTMLTableElement/corefn.json
output/Data.Char/corefn.json
output/DOM.XHR.Types/corefn.json
output/DOM.Node.NonElementParentNode/corefn.json
output/Data.Traversable/corefn.json
output/Control.Comonad.Store/corefn.json
....
I don't think there's anything unusual about the project I'm compiling. This is the bower.json file with my project dependencies.
purs compile bower_components/purescript-*/src/**/*.purs src/**/*.purs test/**/*test && zephyr -O1 Test.Main.main && node -e "require('./dce-output/Test.Main').main()"
[x] purescript-argonaut
[x] purescript-argonaut-core
[x] purescript-profunctor-lenses
[x] pulp (test suite & pulp itself)
Haskell and PureScript newbie here; I ran into this problem when trying to build purescript-halogen-realworld, which failed due to #38. Any insights are greatly appreciated!
cabal build exe:zephyr
Warning: Requested index-state2020-06-09T00:00:00Z is newer than
'hackage.haskell.org'! Falling back to older state (2020-06-08T22:11:02Z).
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: zephyr-0.3.0 (user goal)
[__1] trying: purescript-0.13.8 (dependency of zephyr)
[__2] next goal: base (dependency of zephyr)
[__2] rejecting: base-4.14.0.0/installed-4.14.0.0 (conflict: purescript =>
base>=4.11 && <4.13)
[__2] skipping: base-4.14.0.0, base-4.13.0.0 (has the same characteristics
that caused the previous version to fail: excluded by constraint '>=4.11 &&
<4.13' from 'purescript')
[__2] rejecting: base-4.12.0.0, base-4.11.1.0, base-4.11.0.0, base-4.10.1.0,
base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0,
base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1,
base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0,
base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0,
base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from
non-upgradeable package requires installed instance)
[__2] fail (backjumping, conflict set: base, purescript, zephyr)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: purescript, zephyr, base
For the record, a workaround is fixing the purescript version to 0.13.6 in purescript-halogen-realworld/package.json
:
"purescript": "0.13.6"
zephyr: An internal error occurred during compilation: "Missing value in mnLookup: App.Domain.
Route"
Please report this at https://github.com/purescript/purescript/issues
CallStack (from HasCallStack):
error, called at src/Language/PureScript/Crash.hs:24:3 in purescript-0.11.6-E9oYDASU5kVKQAjU
68tzan:Language.PureScript.Crash
internalError, called at src/Language/PureScript/CodeGen/JS.hs:128:35 in purescript-0.11.6-E
9oYDASU5kVKQAjU68tzan:Language.PureScript.CodeGen.JS
The cause is that the eval
function will evaluate Var{}
expressions. When evaluating Var{}
expressions this should be limited to only those that points to number, character or boolean literal, but preserve string (because it might be repeated many times), array and object literals (this is the direct cause of the failure: they may contain references to other modules).
I'm new to the pureacript ecosystem, what is the best way to use this with spago and parcel?
Hey there. After updating to PureScript 0.15 zephyr
fails with
$ zephyr -f Main.main
Error: Failed parsing:
output/Control.Comonad.Traced/corefn.json
output/Control.Monad.State/corefn.json
output/Control.Monad.Error.Class/corefn.json
output/Control.Monad.Identity.Trans/corefn.json
output/Main/corefn.json
... (346 more)
error Command failed with exit code 1.
This is the offending branch https://github.com/dnikolovv/purescriptify/tree/purescript-0.15. You can run yarn run bundle
to reproduce.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.