-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Option::map_or is being instantiated too much #391
Comments
I don't think However, the initial IR we emit for Note that pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
match self {
Some(t) => f(t),
None => default,
}
} |
Right-- but there are way more copies of fn foo<A>(_: A) {
Some(()).map_or((), |()| println!("foo"));
}
fn foo2<A>(_: A) {
Some(()).map_or((), |()| println!("foo"));
}
foo(());
foo(5);
foo("");
foo2(());
foo2(5);
foo2(""); |
Sure in that case we could potentially merge the specializations, but
BTW: Lines 48 to 83 in b4e061f
This is a macro - I see 13*4=52 distinct non-generic calls to |
So I don't think
|
Sorry the OP is worded in a confusing way. I did not dig into this much before filing the issue but from looking at it now, this is a serde_json bug not a rustc bug. It is computing: // impl PartialEq<i8> for Value
self.as_i64().map_or(false, |i| i == (*other as i64))
// impl PartialEq<i16> for Value
self.as_i64().map_or(false, |i| i == (*other as i64))
// impl PartialEq<i32> for Value
self.as_i64().map_or(false, |i| i == (*other as i64))
// impl PartialEq<i64> for Value
self.as_i64().map_or(false, |i| i == (*other as i64))
// impl PartialEq<isize> for Value
self.as_i64().map_or(false, |i| i == (*other as i64))
// etc We (in serde_json) should be able to rearrange this to instantiate let other = *other as i64;
self.as_i64().map_or(false, |i| i == other) |
Until rust-lang/rust#46477 is addressed, we will need a helper function instead of calling eq_i64(self, *other as i64)
fn eq_i64(value: &Value, other: i64) {
// instantiate map_or once
value.as_i64().map_or(false, |i| i == other)
} |
And even with it addressed, each |
Hmm I don't think so @arielb1. We would use one helper function across |
If you move everything to helper functions, then you won't need rust-lang/rust#46477 |
Oh I see what you mean. Yes that is correct. Thanks! |
There should not be 59 copies of this.
The text was updated successfully, but these errors were encountered: