Skip to content

Commit 4d41177

Browse files
committed
Rename various "concrete opaque type" terminology to say "hidden type"
1 parent ade8487 commit 4d41177

File tree

15 files changed

+82
-116
lines changed

15 files changed

+82
-116
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ pub fn provide(providers: &mut Providers) {
116116
/// Provider for `query mir_borrowck`. Similar to `typeck`, this must
117117
/// only be called for typeck roots which will then borrowck all
118118
/// nested bodies as well.
119-
fn mir_borrowck(
120-
tcx: TyCtxt<'_>,
121-
def: LocalDefId,
122-
) -> Result<&ConcreteOpaqueTypes<'_>, ErrorGuaranteed> {
119+
fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> Result<&HiddenTypes<'_>, ErrorGuaranteed> {
123120
assert!(!tcx.is_typeck_child(def.to_def_id()));
124121
let (input_body, _) = tcx.mir_promoted(def);
125122
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
@@ -130,7 +127,7 @@ fn mir_borrowck(
130127
Err(guar)
131128
} else if input_body.should_skip() {
132129
debug!("Skipping borrowck because of injected body");
133-
let opaque_types = ConcreteOpaqueTypes(Default::default());
130+
let opaque_types = HiddenTypes(Default::default());
134131
Ok(tcx.arena.alloc(opaque_types))
135132
} else {
136133
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: 28 additions & 51 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, HiddenTypes};
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 HiddenTypes<'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: &HiddenTypes<'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_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 HiddenTypes<'tcx>,
192192
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
193193
) -> Vec<DeferredOpaqueTypeError<'tcx>> {
194194
let mut errors = Vec::new();
@@ -201,30 +201,24 @@ 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(
216-
&rcx,
217-
concrete_opaque_types,
218-
&defining_uses,
219-
&mut errors,
220-
);
214+
compute_hidden_types_from_defining_uses(&rcx, hidden_types, &defining_uses, &mut errors);
221215
errors
222216
}
223217

224218
#[instrument(level = "debug", skip_all, ret)]
225219
fn collect_defining_uses<'tcx>(
226220
rcx: &mut RegionCtxt<'_, 'tcx>,
227-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
221+
hidden_types: &mut HiddenTypes<'tcx>,
228222
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
229223
errors: &mut Vec<DeferredOpaqueTypeError<'tcx>>,
230224
) -> Vec<DefiningUse<'tcx>> {
@@ -244,9 +238,9 @@ fn collect_defining_uses<'tcx>(
244238
// with `TypingMode::Borrowck`.
245239
if infcx.tcx.use_typing_mode_borrowck() {
246240
match err {
247-
NonDefiningUseReason::Tainted(guar) => add_concrete_opaque_type(
241+
NonDefiningUseReason::Tainted(guar) => add_hidden_type(
248242
infcx.tcx,
249-
concrete_opaque_types,
243+
hidden_types,
250244
opaque_type_key.def_id,
251245
OpaqueHiddenType::new_error(infcx.tcx, guar),
252246
),
@@ -277,9 +271,9 @@ fn collect_defining_uses<'tcx>(
277271
defining_uses
278272
}
279273

280-
fn compute_concrete_types_from_defining_uses<'tcx>(
274+
fn compute_hidden_types_from_defining_uses<'tcx>(
281275
rcx: &RegionCtxt<'_, 'tcx>,
282-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
276+
hidden_types: &mut HiddenTypes<'tcx>,
283277
defining_uses: &[DefiningUse<'tcx>],
284278
errors: &mut Vec<DeferredOpaqueTypeError<'tcx>>,
285279
) {
@@ -358,9 +352,9 @@ fn compute_concrete_types_from_defining_uses<'tcx>(
358352
},
359353
));
360354
}
361-
add_concrete_opaque_type(
355+
add_hidden_type(
362356
tcx,
363-
concrete_opaque_types,
357+
hidden_types,
364358
opaque_type_key.def_id,
365359
OpaqueHiddenType { span: hidden_type.span, ty },
366360
);
@@ -489,20 +483,20 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
489483
///
490484
/// It does this by equating the hidden type of each use with the instantiated final
491485
/// hidden type of the opaque.
492-
pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
486+
pub(crate) fn apply_hidden_types<'tcx>(
493487
infcx: &BorrowckInferCtxt<'tcx>,
494488
body: &Body<'tcx>,
495489
universal_regions: &UniversalRegions<'tcx>,
496490
region_bound_pairs: &RegionBoundPairs<'tcx>,
497491
known_type_outlives_obligations: &[ty::PolyTypeOutlivesPredicate<'tcx>],
498492
constraints: &mut MirTypeckRegionConstraints<'tcx>,
499-
concrete_opaque_types: &mut ConcreteOpaqueTypes<'tcx>,
493+
hidden_types: &mut HiddenTypes<'tcx>,
500494
opaque_types: &[(OpaqueTypeKey<'tcx>, OpaqueHiddenType<'tcx>)],
501495
) -> Vec<DeferredOpaqueTypeError<'tcx>> {
502496
let tcx = infcx.tcx;
503497
let mut errors = Vec::new();
504498
for &(key, hidden_type) in opaque_types {
505-
let Some(expected) = get_concrete_opaque_type(concrete_opaque_types, key.def_id) else {
499+
let Some(expected) = get_hidden_type(hidden_types, key.def_id) else {
506500
if !tcx.use_typing_mode_borrowck() {
507501
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
508502
&& alias_ty.def_id == key.def_id.to_def_id()
@@ -521,12 +515,7 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
521515
hidden_type.span,
522516
"non-defining use in the defining scope with no defining uses",
523517
);
524-
add_concrete_opaque_type(
525-
tcx,
526-
concrete_opaque_types,
527-
key.def_id,
528-
OpaqueHiddenType::new_error(tcx, guar),
529-
);
518+
add_hidden_type(tcx, hidden_types, key.def_id, OpaqueHiddenType::new_error(tcx, guar));
530519
continue;
531520
};
532521

@@ -566,18 +555,13 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
566555
"equating opaque types",
567556
),
568557
) {
569-
add_concrete_opaque_type(
570-
tcx,
571-
concrete_opaque_types,
572-
key.def_id,
573-
OpaqueHiddenType::new_error(tcx, guar),
574-
);
558+
add_hidden_type(tcx, hidden_types, key.def_id, OpaqueHiddenType::new_error(tcx, guar));
575559
}
576560
}
577561
errors
578562
}
579563

580-
/// In theory `apply_concrete_opaque_types` could introduce new uses of opaque types.
564+
/// In theory `apply_hidden_types` could introduce new uses of opaque types.
581565
/// We do not check these new uses so this could be unsound.
582566
///
583567
/// We detect any new uses and simply delay a bug if they occur. If this results in
@@ -682,13 +666,6 @@ impl<'tcx> InferCtxt<'tcx> {
682666
///
683667
/// (*) C1 and C2 were introduced in the comments on
684668
/// `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`
692669
#[instrument(level = "debug", skip(self))]
693670
fn infer_opaque_definition_from_instantiation(
694671
&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_hidden_types, clone_and_resolve_opaque_types, compute_hidden_types,
16+
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, HiddenTypes,
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: HiddenTypes<'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 HiddenTypes<'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_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_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)