Skip to content

Commit 5ed2928

Browse files
Rollup merge of rust-lang#157667 - jdonszelmann:rename-typingmode-again, r=lcnr
Rename typing modes to better describe real usage r? @lcnr cc: @BoxyUwU Lcnr and I brainstormed these names before RustWeek, but I never got to actually changing it. As for rationale: - `Coherence`: stays the same - `Analysis`: given that basically all of type checking is analyzing code, this didn't feel so accurate. It's now called `Typeck` to signify that it's mainly used during `hir_typeck`. - `Borrowck`: this is the one that actually started the discussion about renaming. Borrowck is used in quite a few places now that are *not* Borrowck, simply to avoid making inference progress on opaque types. It's renamed to `PostTypeckUntilBorrowck`, since its used after `Typeck`. - `PostBorrowckAnalysis` is now simply called `PostBorrowck`, since it's supposed to be used after borrowck finishes. - `PostAnalysis` stays the same, it's the typing mode used after all type analysis finished - There's now also a new `Codegen` typing mode. It's unchanged too. To preempt some questions, I mainly did this rename through normal editor renames. I then also did a search with various regexes over ever occurence of `//.*Analysis` and `//.*Borrowck` and `PostBorrowck`, and some more similar regexes to make sure as many comments as possible are updated, if not all. Notably, this PR does not update RustAnlayzer to use the same names yet. Warning: this PR may be somewhat conflicty :/
2 parents 96d240d + ad6fa33 commit 5ed2928

40 files changed

Lines changed: 189 additions & 193 deletions

File tree

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ pub(crate) struct BorrowckInferCtxt<'tcx> {
650650

651651
impl<'tcx> BorrowckInferCtxt<'tcx> {
652652
pub(crate) fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId, root_def_id: LocalDefId) -> Self {
653-
let typing_mode = if tcx.use_typing_mode_borrowck() {
653+
let typing_mode = if tcx.use_typing_mode_post_typeck_until_borrowck() {
654654
TypingMode::borrowck(tcx, def_id)
655655
} else {
656656
TypingMode::analysis_in_body(tcx, def_id)

compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ fn collect_defining_uses<'tcx>(
261261
DefiningScopeKind::MirBorrowck,
262262
) {
263263
// A non-defining use. This is a hard error on stable and gets ignored
264-
// with `TypingMode::Borrowck`.
265-
if infcx.tcx.use_typing_mode_borrowck() {
264+
// with `TypingMode::PostTypeckUntilBorrowck`.
265+
if infcx.tcx.use_typing_mode_post_typeck_until_borrowck() {
266266
match err {
267267
NonDefiningUseReason::Tainted(guar) => add_hidden_type(
268268
infcx.tcx,
@@ -327,7 +327,7 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
327327
// If we're using the next solver, the unconstrained region may be resolved by a
328328
// fully defining use from another body.
329329
// So we don't generate error eagerly here.
330-
if rcx.infcx.tcx.use_typing_mode_borrowck() {
330+
if rcx.infcx.tcx.use_typing_mode_post_typeck_until_borrowck() {
331331
unconstrained_hidden_type_errors.push(UnexpectedHiddenRegion {
332332
def_id,
333333
hidden_type,
@@ -366,7 +366,7 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
366366
// the hidden type becomes the opaque type itself. In this case, this was an opaque
367367
// usage of the opaque type and we can ignore it. This check is mirrored in typeck's
368368
// writeback.
369-
if !rcx.infcx.tcx.use_typing_mode_borrowck() {
369+
if !rcx.infcx.tcx.use_typing_mode_post_typeck_until_borrowck() {
370370
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
371371
hidden_type.ty.skip_binder().kind()
372372
&& def_id == opaque_type_key.def_id.to_def_id()
@@ -540,7 +540,7 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>(
540540
let mut errors = Vec::new();
541541
for &(key, hidden_type) in opaque_types {
542542
let Some(expected) = hidden_types.get(&key.def_id) else {
543-
if !tcx.use_typing_mode_borrowck() {
543+
if !tcx.use_typing_mode_post_typeck_until_borrowck() {
544544
if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) =
545545
hidden_type.ty.kind()
546546
&& def_id == key.def_id.to_def_id()

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Qualif for HasMutInterior {
102102
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, cx.body.span);
103103
let did = cx.body.source.def_id().expect_local();
104104

105-
let typing_env = if cx.tcx.use_typing_mode_borrowck() {
105+
let typing_env = if cx.tcx.use_typing_mode_post_typeck_until_borrowck() {
106106
cx.typing_env
107107
} else {
108108
ty::TypingEnv::new(cx.typing_env.param_env, TypingMode::analysis_in_body(cx.tcx, did))

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ fn retry_codegen_mode_with_postanalysis<'tcx, K: TypeVisitable<TyCtxt<'tcx>>, V>
4141
}
4242
}
4343
ty::TypingMode::Coherence
44-
| ty::TypingMode::Analysis { .. }
45-
| ty::TypingMode::Borrowck { .. }
46-
| ty::TypingMode::PostBorrowckAnalysis { .. }
44+
| ty::TypingMode::Typeck { .. }
45+
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
46+
| ty::TypingMode::PostBorrowck { .. }
4747
| ty::TypingMode::PostAnalysis => {}
4848
}
4949

compiler/rustc_const_eval/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ fn assert_typing_mode(typing_mode: ty::TypingMode<'_>) {
3232
// Const eval always happens in PostAnalysis or Codegen mode. See the comment in
3333
// `InterpCx::new` for more details.
3434
ty::TypingMode::Coherence
35-
| ty::TypingMode::Analysis { .. }
36-
| ty::TypingMode::Borrowck { .. }
37-
| ty::TypingMode::PostBorrowckAnalysis { .. } => bug!(
35+
| ty::TypingMode::Typeck { .. }
36+
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
37+
| ty::TypingMode::PostBorrowck { .. } => bug!(
3838
"Const eval should always happens in PostAnalysis or Codegen mode. See the comment on `assert_typing_mode` for more details."
3939
),
4040
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn check_opaque_meets_bounds<'tcx>(
317317
};
318318
let param_env = tcx.param_env(defining_use_anchor);
319319

320-
// FIXME(#132279): Once `PostBorrowckAnalysis` is supported in the old solver, this branch should be removed.
320+
// FIXME(#132279): Once `PostBorrowck` is supported in the old solver, this branch should be removed.
321321
let infcx = tcx.infer_ctxt().build(if tcx.next_trait_solver_globally() {
322322
TypingMode::post_borrowck_analysis(tcx, defining_use_anchor)
323323
} else {
@@ -2310,7 +2310,7 @@ pub(super) fn check_coroutine_obligations(
23102310
}
23112311
} else {
23122312
// We're not checking region constraints here, so we can simply drop the
2313-
// added opaque type uses in `TypingMode::Borrowck`.
2313+
// added opaque type uses in `TypingMode::PostTypeckUntilBorrowck`.
23142314
let _ = infcx.take_opaque_types();
23152315
}
23162316

@@ -2327,7 +2327,7 @@ pub(super) fn check_potentially_region_dependent_goals<'tcx>(
23272327
let typeck_results = tcx.typeck(def_id);
23282328
let param_env = tcx.param_env(def_id);
23292329

2330-
// We use `TypingMode::Borrowck` as we want to use the opaque types computed by HIR typeck.
2330+
// We use `TypingMode::PostTypeckUntilBorrowck` as we want to use the opaque types computed by HIR typeck.
23312331
let typing_mode = TypingMode::borrowck(tcx, def_id);
23322332
let infcx = tcx.infer_ctxt().ignoring_regions().build(typing_mode);
23332333
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
657657
self.select_obligations_where_possible(|_| {});
658658

659659
let defining_opaque_types_and_generators = match self.typing_mode() {
660-
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
660+
ty::TypingMode::Typeck { defining_opaque_types_and_generators } => {
661661
defining_opaque_types_and_generators
662662
}
663663
ty::TypingMode::Coherence
664-
| ty::TypingMode::Borrowck { .. }
665-
| ty::TypingMode::PostBorrowckAnalysis { .. }
664+
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
665+
| ty::TypingMode::PostBorrowck { .. }
666666
| ty::TypingMode::PostAnalysis
667667
| ty::TypingMode::Codegen => {
668668
bug!()

compiler/rustc_hir_typeck/src/opaque_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
9999

100100
let tcx = self.tcx;
101101
let defining_opaque_types_and_generators = match self.typing_mode() {
102-
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
102+
ty::TypingMode::Typeck { defining_opaque_types_and_generators } => {
103103
defining_opaque_types_and_generators
104104
}
105105
ty::TypingMode::Coherence
106-
| ty::TypingMode::Borrowck { .. }
107-
| ty::TypingMode::PostBorrowckAnalysis { .. }
106+
| ty::TypingMode::PostTypeckUntilBorrowck { .. }
107+
| ty::TypingMode::PostBorrowck { .. }
108108
| ty::TypingMode::PostAnalysis
109109
| ty::TypingMode::Codegen => {
110110
bug!()

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,19 @@ impl<'tcx> Drop for InferCtxt<'tcx> {
342342
let mut inner = self.inner.borrow_mut();
343343
let opaque_type_storage = &mut inner.opaque_type_storage;
344344

345-
// No need for the drop bomb when we're in TypingMode::Borrowck, and the InferCtxt doesn't consider regions.
346-
// This is okay since in `Borrowck`, the only reason we care about opaques is in relation to regions.
347-
// In some places *after* typeck, like in lints we use `TypingMode::Borrowck`
348-
// to prevent defining opaque types and we simply don't care about regions.
345+
// No need for the drop bomb when we're in `TypingMode::PostTypeckUntilBorrowck`, and the `InferCtxt`
346+
// doesn't consider regions. This is okay since after typeck, the only reason we care about opaques is
347+
// in relation to regions. In some places *after* typeck that aren't borrowck, like in lints we use
348+
// `TypingMode::PostTypeckUntilBorrowck` to prevent defining opaque types and we simply don't care about regions.
349349
match self.typing_mode_raw() {
350350
TypingMode::Coherence
351-
| TypingMode::Analysis { .. }
352-
| TypingMode::PostBorrowckAnalysis { .. }
351+
| TypingMode::Typeck { .. }
352+
| TypingMode::PostBorrowck { .. }
353353
| TypingMode::PostAnalysis
354354
| TypingMode::Codegen => {}
355355
// In erased mode, the opaque type storage is always empty
356356
TypingMode::ErasedNotCoherence(..) => {}
357-
TypingMode::Borrowck { .. } => {
357+
TypingMode::PostTypeckUntilBorrowck { .. } => {
358358
if !self.considering_regions {
359359
return;
360360
}
@@ -1146,17 +1146,15 @@ impl<'tcx> InferCtxt<'tcx> {
11461146
pub fn can_define_opaque_ty(&self, id: impl Into<DefId>) -> bool {
11471147
debug_assert!(!self.next_trait_solver());
11481148
match self.typing_mode_raw().assert_not_erased() {
1149-
TypingMode::Analysis {
1150-
defining_opaque_types_and_generators: defining_opaque_types,
1151-
}
1152-
| TypingMode::Borrowck { defining_opaque_types } => {
1149+
TypingMode::Typeck { defining_opaque_types_and_generators: defining_opaque_types }
1150+
| TypingMode::PostTypeckUntilBorrowck { defining_opaque_types } => {
11531151
id.into().as_local().is_some_and(|def_id| defining_opaque_types.contains(&def_id))
11541152
}
11551153
// FIXME(#132279): This function is quite weird in post-analysis
11561154
// and post-borrowck analysis mode. We may need to modify its uses
1157-
// to support PostBorrowckAnalysis in the old solver as well.
1155+
// to support PostBorrowck in the old solver as well.
11581156
TypingMode::Coherence
1159-
| TypingMode::PostBorrowckAnalysis { .. }
1157+
| TypingMode::PostBorrowck { .. }
11601158
| TypingMode::PostAnalysis
11611159
| TypingMode::Codegen => false,
11621160
}
@@ -1482,12 +1480,12 @@ impl<'tcx> InferCtxt<'tcx> {
14821480
// to handle them without proper canonicalization. This means we may cause cycle
14831481
// errors and fail to reveal opaques while inside of bodies. We should rename this
14841482
// function and require explicit comments on all use-sites in the future.
1485-
ty::TypingMode::Analysis { defining_opaque_types_and_generators: _ }
1486-
| ty::TypingMode::Borrowck { defining_opaque_types: _ } => {
1483+
ty::TypingMode::Typeck { defining_opaque_types_and_generators: _ }
1484+
| ty::TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: _ } => {
14871485
TypingMode::non_body_analysis()
14881486
}
14891487
mode @ (ty::TypingMode::Coherence
1490-
| ty::TypingMode::PostBorrowckAnalysis { .. }
1488+
| ty::TypingMode::PostBorrowck { .. }
14911489
| ty::TypingMode::PostAnalysis
14921490
| ty::TypingMode::Codegen) => mode,
14931491
ty::TypingMode::ErasedNotCoherence(MayBeErased) => unreachable!(),

compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'tcx> InferCtxt<'tcx> {
238238
// our trait.
239239
goals.push(Goal::new(tcx, param_env, ty::PredicateKind::Ambiguous));
240240
}
241-
ty::TypingMode::Analysis { .. } => {
241+
ty::TypingMode::Typeck { .. } => {
242242
let prev = self
243243
.inner
244244
.borrow_mut()
@@ -254,7 +254,7 @@ impl<'tcx> InferCtxt<'tcx> {
254254
);
255255
}
256256
}
257-
ty::TypingMode::Borrowck { .. } => {
257+
ty::TypingMode::PostTypeckUntilBorrowck { .. } => {
258258
let prev = self
259259
.inner
260260
.borrow_mut()
@@ -283,7 +283,7 @@ impl<'tcx> InferCtxt<'tcx> {
283283
.map(|obligation| obligation.as_goal()),
284284
);
285285
}
286-
mode @ (ty::TypingMode::PostBorrowckAnalysis { .. }
286+
mode @ (ty::TypingMode::PostBorrowck { .. }
287287
| ty::TypingMode::PostAnalysis
288288
| ty::TypingMode::Codegen) => {
289289
bug!("insert hidden type in {mode:?}")

0 commit comments

Comments
 (0)