-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Presence of std::simd
sometimes breaks type inference
#90904
Comments
searched nightlies: from nightly-2021-10-16 to nightly-2021-11-14 bisected with cargo-bisect-rustc v0.6.1Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --preserve --start=2021-10-16 Bisected to #89167 - a big PR, I can't tell at a glance which addition is causing an ambiguity here. @rustbot label regression-from-stable-to-nightly |
Yes, it's a known issue that the portable SIMD API's presence weakens type inference for some things by introducing some possible collisions. Breaking type inference is called out as not considered as backwards-incompatible change in RFC 1105. I am still interested in seeing what breakage occurs, as it may justify adjusting what we do. |
std::simd
sometimes breaks type inference on nightly
Cross-posting another minimal example from #91378, which was bisected to #89167 as well. This minimized code example: fn main() -> Result<(), &'static str> {
let a = 0usize;
let b = &a;
let _c: usize = {
let d = &""
.parse()
.map_err(|_| "")?;
b + d
};
Ok(())
} should compile successfully. Instead, I get the following 2 compiler errors:
|
I'm not sure that this requires-nightly: the trait impls that affect inference are likely going to cause the same pain regardless of whether you're on nightly. The examples above also don't have any feature gates. So I'm going to drop that label temporarily, but feel free to re-add it if we have evidence this does require nightly. In that case, it's probably not (yet) a regression and will only be one after something stabilizes(?). |
std::simd
sometimes breaks type inference on nightlystd::simd
sometimes breaks type inference
You're right, actually. I forgot that nightly is actually implicitly present and we just haven't shipped it yet (i.e. this will hit stable after the appropriate cut). |
If we allow a change of the trait involved (and ignore the weird fn main() {
0usize + &Default::default();
} Compiles on stable, ambiguous on nightly, due to the new The There's nothing that can be done here at the level of the operator overload Maybe we shouldn't have let any of these examples compile before, but sadly I'm not aware of a heuristic that can tell "dangerous" cases of inference from "harmless" ones. |
Sorry, I forgot to look at the original example again. With this change, the error appears on stable: - (None, Some(val)) | (Some(val), None) => source + val,
+ (None, Some(&val)) | (Some(&val), None) => source + val, (or alternatively, dereferencing the So it's the same situation where (in this case) Though the error is very misleading, because it points to the wrong part of the code that is affected - this example has enough information flowing through from What seems to be breaking is the This is a pretty "compact" leap - the addition in one |
This was reviewed in the T-libs-api meeting today, right now, and it was decided that we will need to land a revert of the relevant impls that follow a format roughly equivalent to impl<const N: usize> Add<T> for Simd<T, N>
where
T, N, Simd<T, N>, AndYourDog: ManySimdBounds,
{
type Output = Self;
fn add(self, rhs: T) -> Self {
self.add(Simd::splat(rhs))
}
} and, because this breakage has currently hit beta, beta backport it. However, the backport should be deferred (not very long!) until after the next scheduled beta crater run (which is very soon to come, within a week) so we can see the amount of ecosystem breakage in play and understand the relevant mitigations we can take for landing these impls in the future, if any. Essentially, "Since we're here, we might as well see what all the broken cases actually are!" We have until January ~7, to make sure we don't miss the cut, but there will be no reason to wait that long. Ideally we could land these in the future, but it may be a more distant one depending on the results of that and what may need to happen in order to accommodate these cases, if at all. |
…, r=Mark-Simulacrum Sync portable-simd to remove autosplats This PR syncs portable-simd in up to rust-lang/portable-simd@a838552 in order to address the type inference breakages documented on nightly in rust-lang#90904 by removing the vector + scalar binary operations (called "autosplats", "broadcasting", or "rank promotion", depending on who you ask) that allow `{scalar} + &'_ {scalar}` to fail in some cases, because it becomes possible the programmer may have meant `{scalar} + &'_ {vector}`. A few quality-of-life improvements make their way in as well: - Lane counts can now go to 64, as LLVM seems to have fixed their miscompilation for those. - `{i,u}8x64` to `__m512i` is now available. - a bunch of `#[must_use]` notes appear throughout the module. - Some implementations, mostly instances of `impl core::ops::{Op}<Simd> for Simd` that aren't `{vector} + {vector}` (e.g. `{vector} + &'_ {vector}`), leverage some generics and `where` bounds now to make them easier to understand by reducing a dozen implementations into one (and make it possible for people to open the docs on less burly devices). - And some internal-only improvements. None of these changes should affect a beta backport, only actual users of `core::simd` (and most aren't even visible in the programmatic sense), though I can extract an even more minimal changeset for beta if necessary. It seemed simpler to just keep moving forward.
Splats are dropped on nightly, at the moment. |
Discussed in T-libs-api with crater results (see #91872); breakage was deemed higher than likely acceptable, so proceeding with the beta-backport and (already landed) revert on nightly makes sense. The right replacement/API design was judged out of scope for the meeting (in particular, as it didn't have portable-simd folks in attendance :) |
This will be fixed by #91484 and its backport. |
Merged and backported, closing. |
I tried this code:
I expected to see this happen: The code compiles successfully.
Instead, this happened: The code failed to compile:
Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=446e975abb9c2a303485f483494a6512.
The code works fine with stable toolchain.
Meta
Rustc version: 1.58.0-nightly (2021-11-13 b416e38)
The text was updated successfully, but these errors were encountered: