-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Use TypingMode
throughout the compiler instead of ParamEnv
#132460
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #132276) made this pull request unmergeable. Please resolve the merge conflicts. |
fcc8c1b
to
36542fc
Compare
This comment has been minimized.
This comment has been minimized.
36542fc
to
f0f4405
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
6eddc58
to
3f906ca
Compare
This comment has been minimized.
This comment has been minimized.
3f906ca
to
ed391c3
Compare
ed391c3
to
1d78b92
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
`TypingMode` sure seems like a good idea ## `infcx.typing_env` while defining opaque types I don't know how'll be able to correctly handle opaque types when using something taking a `TypingEnv` while defining opaque types. To correctly handle the opaques we need to be able to pass in the current `opaque_type_storage` and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This is ## `layout_of` and `Reveal::All` We convert the `ParamEnv` to `Reveal::All` right at the start of the `layout_of` query, so I've changed callers of `layout_of` to already use a post analysis `TypingEnv` when encountering it. https://github.com/rust-lang/rust/blob/ca87b535a05097df6abbe2a031b057de2cefac5b/compiler/rustc_ty_utils/src/layout.rs#L51 r? `@ghost`
This comment has been minimized.
This comment has been minimized.
debug_assert_eq!(self.param_env.reveal(), Reveal::All); | ||
TypingMode::PostAnalysis | ||
ty::TypingEnv { typing_mode: ty::TypingMode::PostAnalysis, param_env: self.param_env } |
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.
This is also used by Miri. So if Miri should use TypingMode::fully_monomorphized()
, then something seems wrong here?
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.
the param_env
is always empty in MIRI, so ty::TypingEnv { typing_mode: ty::TypingMode::PostAnalysis, param_env: self.param_env }
is equal to ty::TypingEnv::fully_monomorphized()
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.
Ah, okay.
aa489f6
to
ead13fb
Compare
rustc_span::DUMMY_SP, | ||
typing_env.param_env, | ||
MiriMachine::new(config, layout_cx) | ||
); |
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.
); | |
); | |
assert_eq!(ecx.typing_env(), typing_env); |
Does this make sense? Currently it seems a bit odd that we only pass part of the typing env to InterpCx
.
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.
The assert should hold, I don't like adding that assert from a style perspective however
a question here is the following:
- const evaluation should always run in the
PostAnalysis/Reveal::All
mode, so we don't need to store theTypingMode
in the interpcx - we still want to assert that users of const eval pass in the correct
typing_env
and don't accidentally switch toPostAnalysis
without noticing - not sure about the final result from my chat with @compiler-errors, but I think we probably want to store a full
TypingEnv
in theInterpCx
and const eval in general and just assert that theTypingMode
isPostAnalysis
. Storing another 16? bytes in the context really shouldn't matter I think
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.
I don't like adding that assert from a style perspective however
It seems currently there is a non-local invariant encoded by how typing_env()
is implemented on InterpCx. I'd like to ensure that we realize if this ever breaks.
we still want to assert that users of const eval pass in the correct typing_env and don't accidentally switch to PostAnalysis without noticing
That sounds reasonable, but that's a different assertion -- that would be somewhere in the const_eval queries. This here is about Miri.
I think we probably want to store a full TypingEnv in the InterpCx and const eval in general and just assert that the TypingMode is PostAnalysis. Storing another 16? bytes in the context really shouldn't matter I think
I'm fine with that as well.
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.
do you mind me changing InterpCx
to contain the typing_env
directly in a followup PR?
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.
Yeah feel free to stage this however.
e96e4bc
to
278c91b
Compare
TypingMode
sure seems like a good ideaTypingMode
throughout the compiler instead of ParamEnv
@@ -1126,7 +1126,7 @@ fn check_type_defn<'tcx>( | |||
let ty = tcx.type_of(variant.tail().did).instantiate_identity(); | |||
let ty = tcx.erase_regions(ty); | |||
assert!(!ty.has_infer()); | |||
ty.needs_drop(tcx, tcx.param_env(item.owner_id)) | |||
ty.needs_drop(tcx, ty::TypingEnv::non_body_analysis(tcx, item.owner_id.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.
why not wfcx.infcx.typing_env?
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.
🤷 fixed
@@ -1257,7 +1257,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
) -> Option<FxIndexSet<UpvarMigrationInfo>> { | |||
let ty = self.resolve_vars_if_possible(self.node_ty(var_hir_id)); | |||
|
|||
if !ty.has_significant_drop(self.tcx, self.tcx.param_env(closure_def_id)) { | |||
// FIXME(#132279): Using `non_body_analysis` here feels wrong. |
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.
i think i agree -- canonicalizing here would mean we can peek through opaques, which seems good?
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.
later tho
i left some questions, but i think this can be rebased one more time, and i think i can do a final review of the delta, then ill approve after? |
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
278c91b
to
2e087d2
Compare
@bors r+ rollup=never p=1 |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b71fb5e): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 0.6%, secondary 2.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary -2.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 789.97s -> 792.184s (0.28%) |
Visiting for rustc-perf triage
@lcnr and @compiler-errors , is that consistent with your view of the situation? The regression here seems like is probably acceptable (and perhaps just yet another instance of measurement bias in our perf system), but I don't want to mark this case as triaged without at least getting an ACK from either of you. |
I think that a small negative perf hit is expected here but unavoidable. We need to track additional information in multiple queries |
Fix required due to the following changes to Rust's internal API: - rust-lang/rust#132460 - rust-lang/rust#133212 - rust-lang/rust#131326 Resolves #3731 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Zyad Hassan <88045115+zhassan-aws@users.noreply.github.com>
…rors Use `TypingMode` throughout the compiler instead of `ParamEnv` Hopefully the biggest single PR as part of rust-lang/types-team#128. ## `infcx.typing_env` while defining opaque types I don't know how'll be able to correctly handle opaque types when using something taking a `TypingEnv` while defining opaque types. To correctly handle the opaques we need to be able to pass in the current `opaque_type_storage` and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This is ## `layout_of` and `Reveal::All` We convert the `ParamEnv` to `Reveal::All` right at the start of the `layout_of` query, so I've changed callers of `layout_of` to already use a post analysis `TypingEnv` when encountering it. https://github.com/rust-lang/rust/blob/ca87b535a05097df6abbe2a031b057de2cefac5b/compiler/rustc_ty_utils/src/layout.rs#L51 ## `Ty::is_[unpin|sized|whatever]` I haven't migrated `fn is_item_raw` to use `TypingEnv`, will do so in a followup PR, this should significantly reduce the amount of `typing_env.param_env`. At some point there will probably be zero such uses as using the type system while ignoring the `typing_mode` is incorrect. ## `MirPhase` and phase-transitions When inside of a MIR-body, we can mostly use its `MirPhase` to figure out the right `typing_mode`. This does not work during phase transitions, most notably when transitioning from `Analysis` to `Runtime`: https://github.com/rust-lang/rust/blob/dae7ac133b9eda152784c075facb31a6688c92b1/compiler/rustc_mir_transform/src/lib.rs#L606-L625 All these passes still run with `MirPhase::Analysis`, but we should only use `Reveal::All` once we're run the `RevealAll` pass. This required me to manually construct the right `TypingEnv` in all these passes. Given that it feels somewhat easy to accidentally miss this going forward, I would maybe like to change `Body::phase` to an `Option` and replace it at the start of phase transitions. This then makes it clear that the MIR is currently in a weird state. r? `@ghost`
Hopefully the biggest single PR as part of rust-lang/types-team#128.
infcx.typing_env
while defining opaque typesI don't know how'll be able to correctly handle opaque types when using something taking a
TypingEnv
while defining opaque types. To correctly handle the opaques we need to be able to pass in the currentopaque_type_storage
and return constraints, i.e. we need to use a proper canonical query. We should migrate all the queries used during HIR typeck and borrowck where this matters to proper canonical queries. This islayout_of
andReveal::All
We convert the
ParamEnv
toReveal::All
right at the start of thelayout_of
query, so I've changed callers oflayout_of
to already use a post analysisTypingEnv
when encountering it.rust/compiler/rustc_ty_utils/src/layout.rs
Line 51 in ca87b53
Ty::is_[unpin|sized|whatever]
I haven't migrated
fn is_item_raw
to useTypingEnv
, will do so in a followup PR, this should significantly reduce the amount oftyping_env.param_env
. At some point there will probably be zero such uses as using the type system while ignoring thetyping_mode
is incorrect.MirPhase
and phase-transitionsWhen inside of a MIR-body, we can mostly use its
MirPhase
to figure out the righttyping_mode
. This does not work during phase transitions, most notably when transitioning fromAnalysis
toRuntime
:rust/compiler/rustc_mir_transform/src/lib.rs
Lines 606 to 625 in dae7ac1
All these passes still run with
MirPhase::Analysis
, but we should only useReveal::All
once we're run theRevealAll
pass. This required me to manually construct the rightTypingEnv
in all these passes. Given that it feels somewhat easy to accidentally miss this going forward, I would maybe like to changeBody::phase
to anOption
and replace it at the start of phase transitions. This then makes it clear that the MIR is currently in a weird state.r? @ghost