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

Remove the initializer from a global's type information #6349

Merged
merged 3 commits into from
May 8, 2023

Conversation

alexcrichton
Copy link
Member

This commit removes the Global::initializer field to instead only store type information about the global rather than its initialization state. Instead now the initializer is stored separately from the type of the global, and only for defined globals. This removes the need in a few locations to synthesize dummy initializers.

This commit removes the `Global::initializer` field to instead only
store type information about the global rather than its initialization
state. Instead now the initializer is stored separately from the type of
the global, and only for defined globals. This removes the need in a few
locations to synthesize dummy initializers.
@alexcrichton alexcrichton requested review from a team as code owners May 5, 2023 17:27
@alexcrichton alexcrichton requested review from jameysharp and removed request for a team May 5, 2023 17:27
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:wasm wasmtime:api Related to the API of the `wasmtime` crate itself labels May 5, 2023
@github-actions
Copy link

github-actions bot commented May 5, 2023

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "cranelift", "cranelift:wasm", "wasmtime:api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Contributor

@jameysharp jameysharp left a comment

Choose a reason for hiding this comment

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

This is great. There's one leftover bit I think you meant to delete and one thing maybe you can make more clear, but overall this makes perfect sense.

crates/types/src/lib.rs Outdated Show resolved Hide resolved
@@ -1015,7 +1015,7 @@ impl Instance {
// Initialize the global before writing to it
ptr::write(to, VMGlobalDefinition::new());

match global.initializer {
match module.global_initializers[def_index] {
Copy link
Contributor

Choose a reason for hiding this comment

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

The connection between indexes of global_initializers and defined_global_index seems a little subtle to me, but maybe that's just because I'm not that used to these idioms. I think defined_global_index should just be subtracting off num_imported_globals, right? Could you use Iterator::zip to join the initializers to their definitions?

Feel free to leave this as is, but if you see an easy way to make this more obviously correct that'd be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes indeed this can be simplified! I've switched it to iterate over module.global_initializers which is more direct and clearer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Looks great.

@alexcrichton alexcrichton enabled auto-merge May 8, 2023 18:14
@alexcrichton alexcrichton added this pull request to the merge queue May 8, 2023
Merged via the queue into bytecodealliance:main with commit d9cad60 May 8, 2023
@alexcrichton alexcrichton deleted the less-global-init branch May 8, 2023 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:wasm cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants