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 an issue where closure rewriting required class internals #1175

Merged
merged 3 commits into from
Jan 14, 2019

Conversation

alexcrichton
Copy link
Contributor

Surfaced through previous sanity-checking commits, this reorders some
internal operations to...

Closes #1174

Make sure that we don't actually try to expose something when they've
already been written, causing an internal tool panic rather than wrong
JS.
@alexcrichton
Copy link
Contributor Author

@fitzgen I'm curious if you have thoughts on this, we've had a good number of bugs about the ordering of operations in finalize in wasm-bindgen, I feel like we're constantly playing some sort of weird code golf to figure out the right ordering.

Do you have thoughts on how we might better structure this and/or fix this for good in terms of JS generation?

@@ -478,6 +484,10 @@ impl<'a> Context<'a> {
self.rewrite_imports(module_name);
self.update_producers_section();

// Cause any future calls to `should_write_global` to panic, making sure
// we don't ask for items which we can no longer emit.
self.globals_written = true;
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, exposed_globals could be an Option<...> and then we can have should_write_global do self.exposed_globals.as_mut().unwrap().insert(name) and then here do self.exposed_globals.take().unwrap().

This is equivalent to having a bool flag (which becomes the option discriminant in this scheme) but it is impossible to forget to check the flag in should_write_global or anything else that wants to touch exposed_globals thanks to the type system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -56,7 +56,7 @@ pub struct Context<'a> {
/// wasm-bindgen emits.
pub direct_imports: HashMap<&'a str, (&'a str, &'a str)>,

pub exported_classes: HashMap<String, ExportedClass>,
pub exported_classes: Option<HashMap<String, ExportedClass>>,
Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, this second commit is exactly the pattern that I was suggesting for the first one :-p

Throw it in an `Option` and then `take()` it when we consume it to
ensure that future calls to insert data into it panic instead of
producing inconsistent JS.
Surfaced through previous sanity-checking commits, this reorders some
internal operations to...

Closes rustwasm#1174
@alexcrichton alexcrichton merged commit 5c04427 into rustwasm:master Jan 14, 2019
@alexcrichton alexcrichton deleted the internal-consistency branch January 14, 2019 23:53
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