-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for optional numbers #630
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
Conversation
Thanks for this! It looks like the in-memory representation of optional types is a @fitzgen was experimenting using the "global stack" as well for the payload and/or discriminant, as this I believe would enable a blanket implementation for all Another option I was thinking of is that if we want to go the super-specialized route we could support I'm not sure what the best option is here, but I'm curious what @fitzgen thinks of this too! |
Other approaches are possible, yes. But implementing manually means that it's possible to do it better, more compact (like I do with optional Is passing (and converting) float significantly cheaper than passing 2 integers / integer and 32-bit float? |
True yeah! I personally like the idea of using more compact representations as well, and I think using In terms of cost I'm not actually sure, but I'd imagine that it's pretty negligible for wasm-bindgen's purposes |
crates/cli-support/src/descriptor.rs
Outdated
@@ -154,7 +154,27 @@ impl Descriptor { | |||
} | |||
} | |||
|
|||
pub fn get_64bit(&self) -> Option<bool> { | |||
pub fn is_primitive(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this perhaps be named slightly differently to something like is_wasm_native_type
or something like that?
crates/cli-support/src/descriptor.rs
Outdated
} | ||
} | ||
|
||
pub fn is_as_u32(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this perhaps be renamed to is_abi_as_u32
?
crates/cli-support/src/js/js2rust.rs
Outdated
"\n\ | ||
if (!isLikeNone({0})) {{\n\ | ||
_assertNum({0});\n\ | ||
}}\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nowadays all the \n\
markers here should be fine to clean up, the auto-formatting will strip them all away anyway!
b7f53ed
to
b374f95
Compare
I don't have any concrete work in progress, so don't block this on me! Regarding blanket vs targeted impls: I also doubt that there is observable overhead to putting a discriminant on the global stack. But targeted impls mean that we have to write many impls instead of a single one. I suspect that we will want to move to a blanket impl eventually. But it is also an implementation detail that can be changed at a later date. |
I think it's now implemented for all of the primitive types. |
Thanks so much @afdw! |
Fixes #624.