-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
implied bounds: explicitly state which types are assumed to be wf #100676
Conversation
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.
r=me with a helper function
{ | ||
let param_env = tcx.param_env(body_def_id); | ||
let body_id = tcx.hir().local_def_id_to_hir_id(body_def_id); | ||
tcx.infer_ctxt().enter(|ref infcx| { | ||
let ocx = ObligationCtxt::new(infcx); | ||
|
||
let assumed_wf_types = tcx.assumed_wf_types(body_def_id); |
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.
can we make a helper function for this repeated code?
let normalized = ocx.normalize(cause.clone(), param_env, ty); | ||
implied_bounds.insert(normalized); | ||
} | ||
let implied_bounds = implied_bounds; |
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.
also here :)
👍 I'm generally in favor of cleaning up how we calculate wf and implied bounds. It's a bit of mess and confusing in some places. |
@bors r+ rollup=never |
@bors r=nikomatsakis |
💡 This pull request was already approved, no need to approve it again.
|
☀️ Test successful - checks-actions |
Finished benchmarking commit (a9bb589): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Footnotes |
this does actually change user visible behavior. We are now adding implied bounds for unnormalized types during wfcheck. I expect that this is the case of the perf regression. This means that the following now compiles: struct Foo<T>(T);
trait GoodBye {
type Forget;
}
impl<T> GoodBye for T {
type Forget = ();
}
trait NeedsWf<'a, 'b> {
type Assoc;
}
impl<'a, 'b> NeedsWf<'a, 'b> for Foo<<&'a &'b () as GoodBye>::Forget> {
type Assoc = &'a &'b ();
}
fn main() {} When using an impl, we don't actually check wf for these types before normalization, so while this change is desirable, it is currently unsound. I want to avoid reverting this PR and fixing this should be straightforward. Am on vacation right now, going to open an issue for this and intend to fix that once I am back. The fix will be fairly small so 2 weeks until the next beta-cutoff should be enough. |
Nominating for discussion at T-compiler meeting tomorrow. My gut tells me that we should revert this (primarily due to injection of unsoundness; secondarily due to it causing small-but-widespread performance regression). (If we were to revert it, the intention would be to encourage lcnr to re-land a fixed version of it when they are back from vacation.) That, or someone else should put effort into putting in a fix in the meantime. Note: I do understand the argument that lcnr is making; namely, that the branch of beta from nightly is on September 16 2022 and so lcnr would have a little over a week to land a fix. I just don't agree with the above argument. We should be very willing to do reverts in reaction to scenarios like this, unless there is immediate need for this change from T-types. @rustbot label: I-compiler-nominated (In addition to nominating, I also opened up an associated zulip thread) |
opened #100989 which reverts the behavior changes and (probably) the perf regression of this PR. |
no unnormalized types for implied bounds outside borrowck fixes rust-lang#100910 - introduced in rust-lang#100676 - by only considering normalized types for wf. r? types
Adds a new query which maps each definition to the types which that definition assumes to be well formed. The intent is to make it easier to reason about implied bounds.
This change should not influence the user-facing behavior of rustc. Notably,
borrowck
still only assumes that the function signature of associated functions is well formed whilewfcheck
assumes that the both the function signature and the impl trait ref is well formed. Not sure if that by itself can trigger UB or whether it's just annoying.As a next step, we can add
WellFormed
predicates topredicates_of
of these items and can stop adding the wf bounds at each place which uses them. I also intend to move the computation fromassumed_wf_types
toimplied_bounds
into theparam_env
computation. This requires me to take a deeper look atcompare_predicate_entailment
which is currently somewhat weird wrt implied bounds so I am not touching this here.r? @nikomatsakis