-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
webidl: Add a method of whitelisting an API as not mutating its byte slice argument #1005
Comments
I've just found that |
@RReverser just to confirm, but do you mean it doesn't need a mutable slice? (it looks like it already takes a mutable slice) |
Yeah, I'm saying that I found that it currently requires mutable slice in the Rust API, but it shouldn't. |
Ah yes, then indeed this is the right issue! Currently a whitelist isn't implemented, though, that would need to be done first. (that's what this issue is about) |
Ah sorry, I misread, I thought the issue was merely about finding and marking methods that need to accept immutable slices. |
@alexcrichton where might one start looking in order to implement the whitelist? Any tips / guidance for diving in here? Background: You end up running into minor inconveniences very frequently when working on WebGL applications since you're using a bunch of these APIs that require mutable slices very frequently. Nothing too, too painful - just inconvenient. So if this is do-able for a beginner contributor I'd love to take a look! Thanks! |
Sure yeah! Here's at least one way I think this could be implemented today:
Digging around again, the main point of creation of the mutable type vs immutable happens here. I think we'll want to change that to something like: let idl_type = arg.ty.to_idl_type(self);
let idl_type = maybe_adjust(idl_type, id);
idl_args.push(idl_type); The And I think that may be good enough to start here? |
One thing that is not clear to me is how we intend to deal with semver here -- changing an |
I'm personally hoping that because |
Super helpful guidance thanks! Should be taking a look later this week. |
Came here to point out that |
@fitzgen FWIW in terms of literal code, I think this is a non-breaking change, this compiles on the playground: fn a(_: &[u8]) {}
fn b() {
a(&mut Vec::new());
a(&mut []);
a(&mut [1]);
a(&mut [1;2]);
a(&mut [3][..]);
} If, however, someone did something like |
SGTM 👍 |
This comment was marked as abuse.
This comment was marked as abuse.
Just hasn't been done yet, PRs are always welcome to update the whitelist! |
Spawned off from #978, we currently pessmize all slices to be mutable when passed to JS. This conservative decision is required for correctness, but we typically know on a one-off basis that the mutable borrow isn't actually necessary.
We should add a specific method to whitelist particular APIs and switch the to using an immutable slice instead of a mutable one!
The text was updated successfully, but these errors were encountered: