Skip to content

Commit 156d150

Browse files
authored
Rollup merge of #147109 - BoxyUwU:rename_concrete_opaques, r=lcnr
Rename various "concrete opaque type" things to say "hidden type" r? lcnr I've found "concrete opaque type" terminology to be somewhat confusing as in conversation and when explaining opaque type stuff to people I always just talk about things in terms of hidden types. Also the hidden types of opaques are very much not *concrete* in the same sense that a type without any generic parameters is concrete which is an unfortunate overlap in terminology. I've tried to update comments to also stop referring to things as concrete opaque types but this is mostly best effort as it difficult to find all such cases amongst the massive amounts of uses of "concrete" or "hidden" across the whole compiler.
2 parents 5a6ac8c + 66b664c commit 156d150

File tree

15 files changed

+83
-109
lines changed

15 files changed

+83
-109
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub fn provide(providers: &mut Providers) {
119119
fn mir_borrowck(
120120
tcx: TyCtxt<'_>,
121121
def: LocalDefId,
122-
) -> Result<&ConcreteOpaqueTypes<'_>, ErrorGuaranteed> {
122+
) -> Result<&DefinitionSiteHiddenTypes<'_>, ErrorGuaranteed> {
123123
assert!(!tcx.is_typeck_child(def.to_def_id()));
124124
let (input_body, _) = tcx.mir_promoted(def);
125125
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
@@ -130,7 +130,7 @@ fn mir_borrowck(
130130
Err(guar)
131131
} else if input_body.should_skip() {
132132
debug!("Skipping borrowck because of injected body");
133-
let opaque_types = ConcreteOpaqueTypes(Default::default());
133+
let opaque_types = DefinitionSiteHiddenTypes(Default::default());
134134
Ok(tcx.arena.alloc(opaque_types))
135135
} else {
136136
let mut root_cx = BorrowCheckRootCtxt::new(tcx, def, None);

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,10 +1382,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13821382
}
13831383

13841384
/// The constraints we get from equating the hidden type of each use of an opaque
1385-
/// with its final concrete type may end up getting preferred over other, potentially
1385+
/// with its final hidden type may end up getting preferred over other, potentially
13861386
/// longer constraint paths.
13871387
///
1388-
/// Given that we compute the final concrete type by relying on this existing constraint
1388+
/// Given that we compute the final hidden type by relying on this existing constraint
13891389
/// path, this can easily end up hiding the actual reason for why we require these regions
13901390
/// to be equal.
13911391
///

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

Lines changed: 29 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_infer::infer::outlives::env::RegionBoundPairs;
88
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, OpaqueTypeStorageEntries};
99
use rustc_infer::traits::ObligationCause;
1010
use rustc_macros::extension;
11-
use rustc_middle::mir::{Body, ConcreteOpaqueTypes, ConstraintCategory};
11+
use rustc_middle::mir::{Body, ConstraintCategory, DefinitionSiteHiddenTypes};
1212
use rustc_middle::ty::{
1313
self, DefiningScopeKind, EarlyBinder, FallibleTypeFolder, GenericArg, GenericArgsRef,
1414
OpaqueHiddenType, OpaqueTypeKey, Region, RegionVid, Ty, TyCtxt, TypeFoldable,
@@ -129,17 +129,17 @@ fn nll_var_to_universal_region<'tcx>(
129129
/// Collect all defining uses of opaque types inside of this typeck root. This
130130
/// expects the hidden type to be mapped to the definition parameters of the opaque
131131
/// and errors if we end up with distinct hidden types.
132-
fn add_concrete_opaque_type<'tcx>(
132+
fn add_hidden_type<'tcx>(
133133
tcx: TyCtxt<'tcx>,
134-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
134+
hidden_types: &mut DefinitionSiteHiddenTypes<'tcx>,
135135
def_id: LocalDefId,
136136
hidden_ty: OpaqueHiddenType<'tcx>,
137137
) {
138138
// Sometimes two opaque types are the same only after we remap the generic parameters
139139
// back to the opaque type definition. E.g. we may have `OpaqueType<X, Y>` mapped to
140140
// `(X, Y)` and `OpaqueType<Y, X>` mapped to `(Y, X)`, and those are the same, but we
141141
// only know that once we convert the generic parameters to those of the opaque type.
142-
if let Some(prev) = concrete_opaque_types.0.get_mut(&def_id) {
142+
if let Some(prev) = hidden_types.0.get_mut(&def_id) {
143143
if prev.ty != hidden_ty.ty {
144144
let guar = hidden_ty.ty.error_reported().err().unwrap_or_else(|| {
145145
let (Ok(e) | Err(e)) = prev.build_mismatch_error(&hidden_ty, tcx).map(|d| d.emit());
@@ -151,15 +151,15 @@ fn add_concrete_opaque_type<'tcx>(
151151
// FIXME(oli-obk): collect multiple spans for better diagnostics down the road.
152152
prev.span = prev.span.substitute_dummy(hidden_ty.span);
153153
} else {
154-
concrete_opaque_types.0.insert(def_id, hidden_ty);
154+
hidden_types.0.insert(def_id, hidden_ty);
155155
}
156156
}
157157

158-
fn get_concrete_opaque_type<'tcx>(
159-
concrete_opaque_types: &ConcreteOpaqueTypes<'tcx>,
158+
fn get_hidden_type<'tcx>(
159+
hidden_types: &DefinitionSiteHiddenTypes<'tcx>,
160160
def_id: LocalDefId,
161161
) -> Option<EarlyBinder<'tcx, OpaqueHiddenType<'tcx>>> {
162-
concrete_opaque_types.0.get(&def_id).map(|ty| EarlyBinder::bind(*ty))
162+
hidden_types.0.get(&def_id).map(|ty| EarlyBinder::bind(*ty))
163163
}
164164

165165
#[derive(Debug)]
@@ -173,22 +173,22 @@ struct DefiningUse<'tcx> {
173173
}
174174

175175
/// This computes the actual hidden types of the opaque types and maps them to their
176-
/// definition sites. Outside of registering the computed concrete types this function
176+
/// definition sites. Outside of registering the computed hidden types this function
177177
/// does not mutate the current borrowck state.
178178
///
179179
/// While it may fail to infer the hidden type and return errors, we always apply
180-
/// the computed concrete hidden type to all opaque type uses to check whether they
180+
/// the computed hidden type to all opaque type uses to check whether they
181181
/// are correct. This is necessary to support non-defining uses of opaques in their
182182
/// defining scope.
183183
///
184184
/// It also means that this whole function is not really soundness critical as we
185185
/// recheck all uses of the opaques regardless.
186-
pub(crate) fn compute_concrete_opaque_types<'tcx>(
186+
pub(crate) fn compute_definition_site_hidden_types<'tcx>(
187187
infcx: &BorrowckInferCtxt<'tcx>,
188188
universal_region_relations: &Frozen<UniversalRegionRelations<'tcx>>,
189189
constraints: &MirTypeckRegionConstraints<'tcx>,
190190
location_map: Rc<DenseLocationMap>,
191-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
191+
hidden_types: &mut DefinitionSiteHiddenTypes<'tcx>,
192192
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
193193
) -> Vec<DeferredOpaqueTypeError<'tcx>> {
194194
let mut errors = Vec::new();
@@ -201,20 +201,19 @@ pub(crate) fn compute_concrete_opaque_types<'tcx>(
201201
// We start by checking each use of an opaque type during type check and
202202
// check whether the generic arguments of the opaque type are fully
203203
// universal, if so, it's a defining use.
204-
let defining_uses =
205-
collect_defining_uses(&mut rcx, concrete_opaque_types, opaque_types, &mut errors);
204+
let defining_uses = collect_defining_uses(&mut rcx, hidden_types, opaque_types, &mut errors);
206205

207206
// We now compute and apply member constraints for all regions in the hidden
208207
// types of each defining use. This mutates the region values of the `rcx` which
209208
// is used when mapping the defining uses to the definition site.
210209
apply_member_constraints(&mut rcx, &defining_uses);
211210

212211
// After applying member constraints, we now check whether all member regions ended
213-
// up equal to one of their choice regions and compute the actual concrete type of
212+
// up equal to one of their choice regions and compute the actual hidden type of
214213
// the opaque type definition. This is stored in the `root_cx`.
215-
compute_concrete_types_from_defining_uses(
214+
compute_definition_site_hidden_types_from_defining_uses(
216215
&rcx,
217-
concrete_opaque_types,
216+
hidden_types,
218217
&defining_uses,
219218
&mut errors,
220219
);
@@ -224,7 +223,7 @@ pub(crate) fn compute_concrete_opaque_types<'tcx>(
224223
#[instrument(level = "debug", skip_all, ret)]
225224
fn collect_defining_uses<'tcx>(
226225
rcx: &mut RegionCtxt<'_, 'tcx>,
227-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
226+
hidden_types: &mut DefinitionSiteHiddenTypes<'tcx>,
228227
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
229228
errors: &mut Vec<DeferredOpaqueTypeError<'tcx>>,
230229
) -> Vec<DefiningUse<'tcx>> {
@@ -244,9 +243,9 @@ fn collect_defining_uses<'tcx>(
244243
// with `TypingMode::Borrowck`.
245244
if infcx.tcx.use_typing_mode_borrowck() {
246245
match err {
247-
NonDefiningUseReason::Tainted(guar) => add_concrete_opaque_type(
246+
NonDefiningUseReason::Tainted(guar) => add_hidden_type(
248247
infcx.tcx,
249-
concrete_opaque_types,
248+
hidden_types,
250249
opaque_type_key.def_id,
251250
OpaqueHiddenType::new_error(infcx.tcx, guar),
252251
),
@@ -277,9 +276,9 @@ fn collect_defining_uses<'tcx>(
277276
defining_uses
278277
}
279278

280-
fn compute_concrete_types_from_defining_uses<'tcx>(
279+
fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
281280
rcx: &RegionCtxt<'_, 'tcx>,
282-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
281+
hidden_types: &mut DefinitionSiteHiddenTypes<'tcx>,
283282
defining_uses: &[DefiningUse<'tcx>],
284283
errors: &mut Vec<DeferredOpaqueTypeError<'tcx>>,
285284
) {
@@ -358,9 +357,9 @@ fn compute_concrete_types_from_defining_uses<'tcx>(
358357
},
359358
));
360359
}
361-
add_concrete_opaque_type(
360+
add_hidden_type(
362361
tcx,
363-
concrete_opaque_types,
362+
hidden_types,
364363
opaque_type_key.def_id,
365364
OpaqueHiddenType { span: hidden_type.span, ty },
366365
);
@@ -489,20 +488,20 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
489488
///
490489
/// It does this by equating the hidden type of each use with the instantiated final
491490
/// hidden type of the opaque.
492-
pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
491+
pub(crate) fn apply_definition_site_hidden_types<'tcx>(
493492
infcx: &BorrowckInferCtxt<'tcx>,
494493
body: &Body<'tcx>,
495494
universal_regions: &UniversalRegions<'tcx>,
496495
region_bound_pairs: &RegionBoundPairs<'tcx>,
497496
known_type_outlives_obligations: &[ty::PolyTypeOutlivesPredicate<'tcx>],
498497
constraints: &mut MirTypeckRegionConstraints<'tcx>,
499-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
498+
hidden_types: &mut DefinitionSiteHiddenTypes<'tcx>,
500499
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
501500
) -> Vec<DeferredOpaqueTypeError<'tcx>> {
502501
let tcx = infcx.tcx;
503502
let mut errors = Vec::new();
504503
for &(key, hidden_type) in opaque_types {
505-
let Some(expected) = get_concrete_opaque_type(concrete_opaque_types, key.def_id) else {
504+
let Some(expected) = get_hidden_type(hidden_types, key.def_id) else {
506505
if !tcx.use_typing_mode_borrowck() {
507506
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
508507
&& alias_ty.def_id == key.def_id.to_def_id()
@@ -521,12 +520,7 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
521520
hidden_type.span,
522521
"non-defining use in the defining scope with no defining uses",
523522
);
524-
add_concrete_opaque_type(
525-
tcx,
526-
concrete_opaque_types,
527-
key.def_id,
528-
OpaqueHiddenType::new_error(tcx, guar),
529-
);
523+
add_hidden_type(tcx, hidden_types, key.def_id, OpaqueHiddenType::new_error(tcx, guar));
530524
continue;
531525
};
532526

@@ -566,18 +560,13 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
566560
"equating opaque types",
567561
),
568562
) {
569-
add_concrete_opaque_type(
570-
tcx,
571-
concrete_opaque_types,
572-
key.def_id,
573-
OpaqueHiddenType::new_error(tcx, guar),
574-
);
563+
add_hidden_type(tcx, hidden_types, key.def_id, OpaqueHiddenType::new_error(tcx, guar));
575564
}
576565
}
577566
errors
578567
}
579568

580-
/// In theory `apply_concrete_opaque_types` could introduce new uses of opaque types.
569+
/// In theory `apply_definition_site_hidden_types` could introduce new uses of opaque types.
581570
/// We do not check these new uses so this could be unsound.
582571
///
583572
/// We detect any new uses and simply delay a bug if they occur. If this results in
@@ -682,13 +671,6 @@ impl<'tcx> InferCtxt<'tcx> {
682671
///
683672
/// (*) C1 and C2 were introduced in the comments on
684673
/// `register_member_constraints`. Read that comment for more context.
685-
///
686-
/// # Parameters
687-
///
688-
/// - `def_id`, the `impl Trait` type
689-
/// - `args`, the args used to instantiate this opaque type
690-
/// - `instantiated_ty`, the inferred type C1 -- fully resolved, lifted version of
691-
/// `opaque_defn.concrete_ty`
692674
#[instrument(level = "debug", skip(self))]
693675
fn infer_opaque_definition_from_instantiation(
694676
&self,

compiler/rustc_borrowck/src/root_cx.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use smallvec::SmallVec;
1212
use crate::consumers::BorrowckConsumer;
1313
use crate::nll::compute_closure_requirements_modulo_opaques;
1414
use crate::region_infer::opaque_types::{
15-
apply_computed_concrete_opaque_types, clone_and_resolve_opaque_types,
16-
compute_concrete_opaque_types, detect_opaque_types_added_while_handling_opaque_types,
15+
apply_definition_site_hidden_types, clone_and_resolve_opaque_types,
16+
compute_definition_site_hidden_types, detect_opaque_types_added_while_handling_opaque_types,
1717
};
1818
use crate::type_check::{Locations, constraint_conversion};
1919
use crate::{
20-
ClosureRegionRequirements, CollectRegionConstraintsResult, ConcreteOpaqueTypes,
20+
ClosureRegionRequirements, CollectRegionConstraintsResult, DefinitionSiteHiddenTypes,
2121
PropagatedBorrowCheckResults, borrowck_check_region_constraints,
2222
borrowck_collect_region_constraints,
2323
};
@@ -27,7 +27,7 @@ use crate::{
2727
pub(super) struct BorrowCheckRootCtxt<'tcx> {
2828
pub tcx: TyCtxt<'tcx>,
2929
root_def_id: LocalDefId,
30-
concrete_opaque_types: ConcreteOpaqueTypes<'tcx>,
30+
hidden_types: DefinitionSiteHiddenTypes<'tcx>,
3131
/// The region constraints computed by [borrowck_collect_region_constraints]. This uses
3232
/// an [FxIndexMap] to guarantee that iterating over it visits nested bodies before
3333
/// their parents.
@@ -49,7 +49,7 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
4949
BorrowCheckRootCtxt {
5050
tcx,
5151
root_def_id,
52-
concrete_opaque_types: Default::default(),
52+
hidden_types: Default::default(),
5353
collect_region_constraints_results: Default::default(),
5454
propagated_borrowck_results: Default::default(),
5555
tainted_by_errors: None,
@@ -72,11 +72,11 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
7272
&self.propagated_borrowck_results[&nested_body_def_id].used_mut_upvars
7373
}
7474

75-
pub(super) fn finalize(self) -> Result<&'tcx ConcreteOpaqueTypes<'tcx>, ErrorGuaranteed> {
75+
pub(super) fn finalize(self) -> Result<&'tcx DefinitionSiteHiddenTypes<'tcx>, ErrorGuaranteed> {
7676
if let Some(guar) = self.tainted_by_errors {
7777
Err(guar)
7878
} else {
79-
Ok(self.tcx.arena.alloc(self.concrete_opaque_types))
79+
Ok(self.tcx.arena.alloc(self.hidden_types))
8080
}
8181
}
8282

@@ -88,12 +88,12 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
8888
&input.universal_region_relations,
8989
&mut input.constraints,
9090
);
91-
input.deferred_opaque_type_errors = compute_concrete_opaque_types(
91+
input.deferred_opaque_type_errors = compute_definition_site_hidden_types(
9292
&input.infcx,
9393
&input.universal_region_relations,
9494
&input.constraints,
9595
Rc::clone(&input.location_map),
96-
&mut self.concrete_opaque_types,
96+
&mut self.hidden_types,
9797
&opaque_types,
9898
);
9999
per_body_info.push((num_entries, opaque_types));
@@ -103,14 +103,14 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
103103
self.collect_region_constraints_results.values_mut().zip(per_body_info)
104104
{
105105
if input.deferred_opaque_type_errors.is_empty() {
106-
input.deferred_opaque_type_errors = apply_computed_concrete_opaque_types(
106+
input.deferred_opaque_type_errors = apply_definition_site_hidden_types(
107107
&input.infcx,
108108
&input.body_owned,
109109
&input.universal_region_relations.universal_regions,
110110
&input.region_bound_pairs,
111111
&input.known_type_outlives_obligations,
112112
&mut input.constraints,
113-
&mut self.concrete_opaque_types,
113+
&mut self.hidden_types,
114114
&opaque_types,
115115
);
116116
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn check_opaque(tcx: TyCtxt<'_>, def_id: LocalDefId) {
219219

220220
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
221221
// `async-std` (and `pub async fn` in general).
222-
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
222+
// Since rustdoc doesn't care about the hidden type behind `impl Trait`, just don't look at it!
223223
// See https://github.com/rust-lang/rust/issues/75100
224224
if tcx.sess.opts.actually_rustdoc {
225225
return;
@@ -252,7 +252,7 @@ pub(super) fn check_opaque_for_cycles<'tcx>(
252252
Ok(())
253253
}
254254

255-
/// Check that the concrete type behind `impl Trait` actually implements `Trait`.
255+
/// Check that the hidden type behind `impl Trait` actually implements `Trait`.
256256
///
257257
/// This is mostly checked at the places that specify the opaque type, but we
258258
/// check those cases in the `param_env` of that function, which may have

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ impl<'tcx> TaitConstraintLocator<'tcx> {
177177
let tables = tcx.typeck(item_def_id);
178178
if let Some(guar) = tables.tainted_by_errors {
179179
self.insert_found(ty::OpaqueHiddenType::new_error(tcx, guar));
180-
} else if let Some(&hidden_type) = tables.concrete_opaque_types.get(&self.def_id) {
180+
} else if let Some(&hidden_type) = tables.hidden_types.get(&self.def_id) {
181181
self.insert_found(hidden_type);
182182
} else {
183183
self.non_defining_use_in_defining_scope(item_def_id);
184184
}
185185
}
186186
DefiningScopeKind::MirBorrowck => match tcx.mir_borrowck(item_def_id) {
187187
Err(guar) => self.insert_found(ty::OpaqueHiddenType::new_error(tcx, guar)),
188-
Ok(concrete_opaque_types) => {
189-
if let Some(&hidden_type) = concrete_opaque_types.0.get(&self.def_id) {
188+
Ok(hidden_types) => {
189+
if let Some(&hidden_type) = hidden_types.0.get(&self.def_id) {
190190
debug!(?hidden_type, "found constraint");
191191
self.insert_found(hidden_type);
192192
} else if let Err(guar) = tcx
@@ -247,7 +247,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
247247
let tables = tcx.typeck(owner_def_id);
248248
if let Some(guar) = tables.tainted_by_errors {
249249
Ty::new_error(tcx, guar)
250-
} else if let Some(hidden_ty) = tables.concrete_opaque_types.get(&def_id) {
250+
} else if let Some(hidden_ty) = tables.hidden_types.get(&def_id) {
251251
hidden_ty.ty
252252
} else {
253253
assert!(!tcx.next_trait_solver_globally());
@@ -261,8 +261,8 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
261261
}
262262
}
263263
DefiningScopeKind::MirBorrowck => match tcx.mir_borrowck(owner_def_id) {
264-
Ok(concrete_opaque_types) => {
265-
if let Some(hidden_ty) = concrete_opaque_types.0.get(&def_id) {
264+
Ok(hidden_types) => {
265+
if let Some(hidden_ty) = hidden_types.0.get(&def_id) {
266266
hidden_ty.ty
267267
} else {
268268
let hir_ty = tcx.type_of_opaque_hir_typeck(def_id).instantiate_identity();

0 commit comments

Comments
 (0)