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

fix(compiler): Write universal exports on linked module #2234

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ospencer
Copy link
Member

In #2104, the write_universal_exports function was previously called after linking, but I forgot to reinstate it. This restores that behavior.

I deleted some tests because they were testing old behavior that was valid for the intermediate (object) wasm files but are no longer valid in the output of final wasm modules.

@ospencer ospencer self-assigned this Jan 16, 2025
Copy link
Member

@spotandjake spotandjake left a comment

Choose a reason for hiding this comment

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

Mostly looks good just two small questions.

compiler/test/suites/modules.re Show resolved Hide resolved
compiler/test/suites/provides.re Show resolved Hide resolved
@spotandjake
Copy link
Member

spotandjake commented Jan 22, 2025

I was testing with this locally and I think we changed the behaviour of the start function.
The below program:

module Test

provide let _start = () => print("test")

when compiled with grain compile ./test.gr --use-start-section gives an error during compilation Fatal: Module::addFunction: _start already exists, oh actually interestingly I get that even if I omit the --use-start-section

We also get similar behaviour with provide let memory = () => 1 because of the memory section export.

@ospencer
Copy link
Member Author

@spotandjake Good catch. I restored the old behavior. We should maybe consider a warning for reserved export names, but that's not for this PR.

@spotandjake
Copy link
Member

spotandjake commented Jan 23, 2025

I just tried this again the _start stuff is fixed but I found a new bug if you have a program like:
b.gr:

module B

provide let x = (y) => 1

a.gr

module A
from "./b.gr" include B
provide let x = B.x

we seem to hit a Not_found exception.

It might also make sense to add regression tests for both the _start and example above.

I did some independent investigation on this and the problem is B.x is being imported as a global, and is in the export table as a global.

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

Successfully merging this pull request may close these issues.

2 participants