Skip to content

Use TypingMode throughout the compiler instead of ParamEnv#132460

Merged
bors merged 2 commits into
rust-lang:masterfrom
lcnr:questionable-uwu
Nov 19, 2024
Merged

Use TypingMode throughout the compiler instead of ParamEnv#132460
bors merged 2 commits into
rust-lang:masterfrom
lcnr:questionable-uwu

Conversation

@lcnr

@lcnr lcnr commented Nov 1, 2024

Copy link
Copy Markdown
Contributor

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.

let param_env = param_env.with_reveal_all_normalized(tcx);

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:

// These next passes must be executed together.
&add_call_guards::CriticalCallEdges,
// Must be done before drop elaboration because we need to drop opaque types, too.
&reveal_all::RevealAll,
// Calling this after reveal_all ensures that we don't deal with opaque types.
&add_subtyping_projections::Subtyper,
&elaborate_drops::ElaborateDrops,
// This will remove extraneous landing pads which are no longer
// necessary as well as forcing any call in a non-unwinding
// function calling a possibly-unwinding function to abort the process.
&abort_unwinding_calls::AbortUnwindingCalls,
// AddMovesForPackedDrops needs to run after drop
// elaboration.
&add_moves_for_packed_drops::AddMovesForPackedDrops,
// `AddRetag` needs to run after `ElaborateDrops` but before `ElaborateBoxDerefs`.
// Otherwise it should run fairly late, but before optimizations begin.
&add_retag::AddRetag,
&elaborate_box_derefs::ElaborateBoxDerefs,
&coroutine::StateTransform,
&Lint(known_panics_lint::KnownPanicsLint),

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

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants