Skip to content

Add support for js-sources #8636

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

Merged
merged 7 commits into from
Jan 22, 2023
Merged

Conversation

hsyl20
Copy link
Collaborator

@hsyl20 hsyl20 commented Dec 14, 2022

This PR adds support for js-sources with GHC, not only GHCJS.

Caveat: for now, similarly to asm-sources and cmm-sources, js-sources only works for library components, not executable components. See #8639

Not sure how to add tests for this as it requires GHC >= 9.6 built for the JS target. I've only tested it locally.


@hsyl20
Copy link
Collaborator Author

hsyl20 commented Dec 20, 2022

I've opened #8639 to track the issue with executable components. It has a larger scope because asm-sources and cmm-sources are concerned too.

@hsyl20 hsyl20 changed the title Draft: add support for js-sources Add support for js-sources Dec 20, 2022
@hsyl20
Copy link
Collaborator Author

hsyl20 commented Dec 20, 2022

@Mikolaj Could you or someone else take this PR over to ensure that it gets included in GHC 9.6 (and in GHC HEAD as soon as possible)? Users that try the JS backend will quickly face this issue (and #8639).

@Mikolaj
Copy link
Member

Mikolaj commented Dec 20, 2022

Local tests are fine in this case. A tiny changelog file would be very welcome though.

@hsyl20: I presume this is ready for review? Based on this assumption, I've set the label and asked @bgamari to have a look (or delegate to somebody in GHC team that works on related issues).

Re including in GHC 9.6, we plan to release cabal 3.10 in step with GHC 9.6, so if this PR gets merged in 2022 or shortly thereafter, it's going to be included in GHC 9.6 and in cabal 3.10. I will bug people to make sure it doesn't just get forgotten.

@Mikolaj Mikolaj added this to the Considered for 3.10 milestone Dec 20, 2022
@hsyl20
Copy link
Collaborator Author

hsyl20 commented Dec 20, 2022

I've added a changelog. Now it's ready for review. :)

@@ -561,6 +561,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
, toNubListR (cxxSources libBi)
, toNubListR (cmmSources libBi)
, toNubListR (asmSources libBi)
, toNubListR (jsSources libBi)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adding JS to cLikeSources. Is "C-like" a misnomer or was the original intention to exclude JS? Change of plans? I don't see any "non-C-like sources" list in the codebase that we could add JS source to, instead, so this must be the right place.

Perhaps the C-like vs non-C-like distinction is a left over from some special cases for GHCJS? Is JS C-like enough when considered by GHC JS backend, but not C-like when fed to GHCJS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes for the JS backend we've reworked the way JS sources are treated. They are now C-like because we've added support for a "compilation" from .js to .o files (basically a file renaming with a header added). It makes them less special for tools like Hadrian and cabal.

(in the GHCJS code path (Distribution.Simple.GHCJS) these files were directly passed as link options)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this deserves a NOTE JS Sources are C-Like or similar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Profpatsch: GHC note or cabal note? Or one of those and hyperlink from the other place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a comment explaining that JS sources are C-like in the JS backend.

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified that this PR changes all the bits of code that are likely to need changing. However, I don't know this functionality enough to understand whether these changes make sense, so I have to trust the results of local testing by the PR author. This is unlikely to break other stuff, though.

@Mikolaj Mikolaj removed the request for review from bgamari January 2, 2023 15:23
@jneira
Copy link
Member

jneira commented Jan 3, 2023

hi, this looks great but it would be nice to know the plans to add or modify existing tests

@jneira
Copy link
Member

jneira commented Jan 3, 2023

Not sure how to add tests for this as it requires GHC >= 9.6 built for the JS target. I've only tested it locally.

A possible way would be write tests and run them conditionally on ghc version. They will be eventually executed everywhere.

@jneira
Copy link
Member

jneira commented Jan 4, 2023

This pr seems to be related with #8633 and i guess tests also would be related

@hsyl20
Copy link
Collaborator Author

hsyl20 commented Jan 6, 2023

A possible way would be write tests and run them conditionally on ghc version. They will be eventually executed everywhere.

I'll try to do this.

This pr seems to be related with #8633 and i guess tests also would be related

The two PRs aren't related. This other one is for the wasm backend, this one is for the JS backend.

@Mikolaj Mikolaj requested a review from bgamari January 12, 2023 18:54
@Mikolaj
Copy link
Member

Mikolaj commented Jan 12, 2023

We'd like to include this commit in the 3.10 branch that is to be cut RSN so, in the worst case, perhaps we could add the test afterwards. However, we need a second review, an in-depth one, ideally prompting some more documentation to be added, so I'm kindly asking @ben to help with that.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 14, 2023

BTW, if this

#8675

is done in finite time and we have 9.6.1-alpha1 in CI, the test would be able to run. Probably not on Windows, though, because our CI is quite thoroughly broken with GHC >= 9.4 on Windows.

@hsyl20
Copy link
Collaborator Author

hsyl20 commented Jan 16, 2023

@Mikolaj You also will need a build of GHC cross-compiling for the JS target. Not sure if it is planned?

@hsyl20
Copy link
Collaborator Author

hsyl20 commented Jan 16, 2023

I've added a test but I couldn't run it with cabal-tests. It doesn't find the correct ghc-pkg and there is no --with-ghc-pkg flag to use.

@hsyl20
Copy link
Collaborator Author

hsyl20 commented Jan 16, 2023

Oops I forgot to push some changes, now done. Run example:

/home/hsyl20/projects/ghc/javascript-backend/libraries/Cabal/dist-newstyle/build/x86_64-linux/ghc-9.2.4/cabal-install-3.9.0.0/x/cabal/build/cabal/cabal --with-ghc='/home/hsyl20/projects/ghc/javascript-backend/_build/stage1/bin/js-unknown-ghcjs-ghc' --with-ghc-pkg='/home/hsyl20/projects/ghc/javascript-backend/_build/stage1/bin/js-unknown-ghcjs-ghc-pkg' run demo
Warning: this is a debug build of cabal-install with assertions enabled.
Warning: Unknown/unsupported 'ghc' version detected (Cabal 3.9.0.0 supports
'ghc' version < 9.6):
/home/hsyl20/projects/ghc/javascript-backend/_build/stage1/bin/js-unknown-ghcjs-ghc
is version 9.7.20230112
Resolving dependencies...
Build profile: -w ghc-9.7.20230112 -O1
In order, the following will be built (use -v for more details):
 - jssources-0 (lib) (first run)
 - jssources-0 (exe:demo) (first run)
Warning: this is a debug build of cabal-install with assertions enabled.
Configuring library for jssources-0..
Warning: this is a debug build of cabal-install with assertions enabled.
Preprocessing library for jssources-0..
Building library for jssources-0..
[1 of 1] Compiling Lib              ( src/Lib.hs, /home/hsyl20/projects/ghc/javascript-backend/libraries/Cabal/cabal-testsuite/PackageTests/JS/JsSources/dist-newstyle/build/js-ghcjs/ghc-9.7.20230112/jssources-0/
Warning: this is a debug build of cabal-install with assertions enabled.
Warning: this is a debug build of cabal-install with assertions enabled.
Configuring executable 'demo' for jssources-0..
Warning: this is a debug build of cabal-install with assertions enabled.
Preprocessing executable 'demo' for jssources-0..
Building executable 'demo' for jssources-0..
[1 of 1] Compiling Main             ( demo/Main.hs, /home/hsyl20/projects/ghc/javascript-backend/libraries/Cabal/cabal-testsuite/PackageTests/JS/JsSources/dist-newstyle/build/js-ghcjs/ghc-9.7.20230112/jssources-0/x/demo/build/demo/demo-tmp/Main.o )
[2 of 2] Linking /home/hsyl20/projects/ghc/javascript-backend/libraries/Cabal/cabal-testsuite/PackageTests/JS/JsSources/dist-newstyle/build/js-ghcjs/ghc-9.7.20230112/jssources-0/x/demo/build/demo/demo.jsexe
Hello JS!

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the test. I think it's fine as the first test of any functionality in any way related to JS.

@Mikolaj Mikolaj requested a review from mpickering January 16, 2023 11:10
@hsyl20
Copy link
Collaborator Author

hsyl20 commented Jan 16, 2023

I've also fixed skipIfGhcVersion in passing. It probably shouldn't belong to this MR but time is short.

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also fixed skipIfGhcVersion in passing. It probably shouldn't belong to this MR but time is short.

Thanks a lot. It is. :)

@Mikolaj
Copy link
Member

Mikolaj commented Jan 16, 2023

Splendid. That's descent behaviour and these are not blockers for this PR, IMHO.

@Mikolaj Mikolaj removed the request for review from mpickering January 19, 2023 15:01
@Mikolaj
Copy link
Member

Mikolaj commented Jan 19, 2023

@bgamari: thank you.

@hsyl20: Success! When you are ready, please kindly set the label (squash+merge_me, I suppose?) and then it's going to be merged in 2 days, unless further changes are made.

@hsyl20
Copy link
Collaborator Author

hsyl20 commented Jan 19, 2023

@Mikolaj Done! Thanks :)

@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Jan 21, 2023
@Mikolaj
Copy link
Member

Mikolaj commented Jan 21, 2023

@mergify refresh

@mergify
Copy link
Contributor

mergify bot commented Jan 21, 2023

refresh

✅ Pull request refreshed

@Mikolaj
Copy link
Member

Mikolaj commented Jan 21, 2023

Mergify is fussy today, so let me prod it manually.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 21, 2023

@mergify rebase

@haskell haskell deleted a comment from mergify bot Jan 21, 2023
@mergify
Copy link
Contributor

mergify bot commented Jan 21, 2023

⚠️ This pull request got rebased on behalf of a random user of the organization.
This behavior will change on the 1st February 2023, Mergify will pick the author of the pull request instead.

To get the future behavior now, you can configure bot_account options (e.g.: bot_account: { author } or update_bot_account: { author }.

Or you can create a dedicated github account for squash and rebase operations, and use it in different bot_account options.

@mergify
Copy link
Contributor

mergify bot commented Jan 21, 2023

rebase

✅ Branch has been successfully rebased

@cocreature cocreature force-pushed the hsyl20/support-js-sources branch from 9f4ea9d to b55d479 Compare January 21, 2023 22:35
@mergify mergify bot merged commit 605a3c6 into haskell:master Jan 22, 2023
Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

late to the party but thanks for working on this (and add the test!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: ghcjs js backend merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days re: ghc 9.6 squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants