Skip to content

handle reexported wasm globals #7467

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 5 commits into from
Jun 3, 2018
Merged

handle reexported wasm globals #7467

merged 5 commits into from
Jun 3, 2018

Conversation

sokra
Copy link
Member

@sokra sokra commented Jun 2, 2018

What kind of change does this PR introduce?
bugfix

Did you add tests for your changes?
yes

Does this PR introduce a breaking change?
no

What needs to be documented once your changes are merged?
nothing

@webpack-bot
Copy link
Contributor

webpack-bot commented Jun 2, 2018

For maintainers only:

  • This need to be documented (issue in webpack/webpack.js.org will be filed when merged)

Copy link
Member

@xtuc xtuc left a comment

Choose a reason for hiding this comment

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

Ok that looks good.

@@ -225,7 +227,7 @@ const rewriteImportedGlobals = state => bin => {

node.init = [
// Poisong globals, they are meant to be rewritten
t.objectInstruction("const", valtype, [t.numberLiteralFromRaw(666)])
t.objectInstruction("const", valtype, [t.numberLiteralFromRaw(0)])
Copy link
Member

Choose a reason for hiding this comment

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

That was useful for testing, do you think we shouldn't do it? (also comment above)

Copy link
Member Author

Choose a reason for hiding this comment

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

It increases the size of the wasm. But we can use 66.

})
);
};
let needExportsCopy = false;
Copy link
Member

Choose a reason for hiding this comment

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

It's not really a copy? It's more a rewire or a connection

Copy link
Member Author

Choose a reason for hiding this comment

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

This variable is about a shallow copy of the exports object.

If false it can use module.exports = instance.exports.
If true it has to use for(var key in instance.exports) exports[key] = instance.exports[key]

Copy link
Member

Choose a reason for hiding this comment

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

@sokra sokra force-pushed the bugfix/reexport-wasm-global branch from 95c2f7d to 1e4d2b7 Compare June 2, 2018 15:38
@@ -403,14 +411,20 @@ class WebAssemblyGenerator extends Generator {
const nextTypeIndex = getNextTypeIndex(ast);

const usedDependencyMap = getUsedDependencyMap(module);
const invalidExports = new Set(
Copy link
Member

Choose a reason for hiding this comment

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

invalidExports sounds confusing to me, these are the exports that are handled by Webpack now, right? Maybe something like exportsToRemove?

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

Copy link
Member

@xtuc xtuc left a comment

Choose a reason for hiding this comment

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

thanks

@sokra sokra merged commit e82b849 into master Jun 3, 2018
@sokra sokra deleted the bugfix/reexport-wasm-global branch June 4, 2018 07:02
(import "./env.js" "n" (global i32))
(import "./env.js" "m" (global $g2 f64))
(export "v" (global 0))
(global $g i32 (get_global 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this is valid. Doesn't it break WebAssembly validation to have a non-constant initialization expression, per https://webassembly.github.io/spec/core/bikeshed/index.html#globals%E2%91%A2 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right, I'll dig further into figuring out why the test doesn't pass in Node 11.

Copy link
Member

Choose a reason for hiding this comment

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

which test? (sorry I'm just catching up here)

Copy link
Contributor

Choose a reason for hiding this comment

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

Running this test, modified to check for WebAssembly.Global objects, against a Node 11 nightly build, failed for me. My next step is to see if I can make a smaller reproduction directly in V8.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I was just confused. V8 supports this just fine (it's tested in test/mjsunit/wasm/globals.js TestImportedExported), and now I'm wondering if the issue is actually the logic in this patch to improve handling of re-exported globals is responsible for getting a Number rather than a WebAssembly.Global. I'm wondering, for systems that have WebAssembly.Global, should we just wrap the Number in a Global?

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

Successfully merging this pull request may close these issues.

4 participants