Skip to content

Commit c1581fc

Browse files
Initial work on the type system layer
1 parent 85641f7 commit c1581fc

File tree

54 files changed

+286
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+286
-39
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
16261626
| ty::Slice(_)
16271627
| ty::FnDef(_, _)
16281628
| ty::FnPtr(..)
1629+
| ty::UnsafeBinder(_)
16291630
| ty::Dynamic(_, _, _)
16301631
| ty::Closure(_, _)
16311632
| ty::CoroutineClosure(_, _)
@@ -1671,6 +1672,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
16711672
| ty::Ref(_, _, _)
16721673
| ty::FnDef(_, _)
16731674
| ty::FnPtr(..)
1675+
| ty::UnsafeBinder(_)
16741676
| ty::Dynamic(_, _, _)
16751677
| ty::CoroutineWitness(..)
16761678
| ty::Never

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ fn push_debuginfo_type_name<'tcx>(
432432
push_closure_or_coroutine_name(tcx, def_id, args, qualified, output, visited);
433433
}
434434
}
435+
ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binders)"),
435436
ty::Param(_)
436437
| ty::Error(_)
437438
| ty::Infer(_)

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ fn const_to_valtree_inner<'tcx>(
178178
| ty::Closure(..)
179179
| ty::CoroutineClosure(..)
180180
| ty::Coroutine(..)
181-
| ty::CoroutineWitness(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
181+
| ty::CoroutineWitness(..)
182+
| ty::UnsafeBinder(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
182183
}
183184
}
184185

@@ -358,7 +359,10 @@ pub fn valtree_to_const_value<'tcx>(
358359
| ty::FnPtr(..)
359360
| ty::Str
360361
| ty::Slice(_)
361-
| ty::Dynamic(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()),
362+
| ty::Dynamic(..)
363+
| ty::UnsafeBinder(_) => {
364+
bug!("no ValTree should have been created for type {:?}", ty.kind())
365+
}
362366
}
363367
}
364368

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
9090
| ty::CoroutineClosure(_, _)
9191
| ty::Coroutine(_, _)
9292
| ty::CoroutineWitness(..)
93+
| ty::UnsafeBinder(_)
9394
| ty::Never
9495
| ty::Tuple(_)
9596
| ty::Error(_) => ConstValue::from_target_usize(0u64, &tcx),

compiler/rustc_const_eval/src/interpret/stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
505505
// We don't want to do any queries, so there is not much we can do with ADTs.
506506
ty::Adt(..) => false,
507507

508+
ty::UnsafeBinder(_) => false,
509+
508510
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => false,
509511

510512
ty::Infer(ty::TyVar(_)) => false,

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
767767
// Nothing to check.
768768
interp_ok(true)
769769
}
770+
ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
770771
// The above should be all the primitive types. The rest is compound, we
771772
// check them by visiting their fields/variants.
772773
ty::Adt(..)

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
3838
| ty::FnPtr(..)
3939
| ty::Never
4040
| ty::Tuple(_)
41-
| ty::Dynamic(_, _, _) => self.pretty_print_type(ty),
41+
| ty::Dynamic(_, _, _)
42+
| ty::UnsafeBinder(_) => self.pretty_print_type(ty),
4243

4344
// Placeholders (all printed as `_` to uniformize them).
4445
ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => {

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ impl<'tcx> InherentCollect<'tcx> {
179179
| ty::Ref(..)
180180
| ty::Never
181181
| ty::FnPtr(..)
182-
| ty::Tuple(..) => self.check_primitive_impl(id, self_ty),
182+
| ty::Tuple(..)
183+
| ty::UnsafeBinder(_) => self.check_primitive_impl(id, self_ty),
183184
ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) | ty::Param(_) => {
184185
Err(self.tcx.dcx().emit_err(errors::InherentNominal { span: item_span }))
185186
}

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ pub(crate) fn orphan_check_impl(
225225
| ty::FnDef(..)
226226
| ty::FnPtr(..)
227227
| ty::Never
228-
| ty::Tuple(..) => (LocalImpl::Allow, NonlocalImpl::DisallowOther),
228+
| ty::Tuple(..)
229+
| ty::UnsafeBinder(_) => (LocalImpl::Allow, NonlocalImpl::DisallowOther),
229230

230231
ty::Closure(..)
231232
| ty::CoroutineClosure(..)

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,13 +2319,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23192319
self.lower_fn_ty(hir_ty.hir_id, bf.safety, bf.abi, bf.decl, None, Some(hir_ty)),
23202320
)
23212321
}
2322-
hir::TyKind::UnsafeBinder(_binder) => {
2323-
let guar = self
2324-
.dcx()
2325-
.struct_span_err(hir_ty.span, "unsafe binders are not yet implemented")
2326-
.emit();
2327-
Ty::new_error(tcx, guar)
2328-
}
2322+
hir::TyKind::UnsafeBinder(binder) => Ty::new_unsafe_binder(
2323+
tcx,
2324+
ty::Binder::bind_with_vars(
2325+
self.lower_ty(binder.inner_ty),
2326+
tcx.late_bound_vars(hir_ty.hir_id),
2327+
),
2328+
),
23292329
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
23302330
if let Some(guar) = self.prohibit_or_lint_bare_trait_object_ty(hir_ty) {
23312331
// Don't continue with type analysis if the `dyn` keyword is missing

compiler/rustc_hir_analysis/src/variance/constraints.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
322322
self.add_constraints_from_sig(current, sig_tys.with(hdr), variance);
323323
}
324324

325+
ty::UnsafeBinder(ty) => {
326+
let invariant = self.invariant(variance);
327+
self.add_constraints_from_ty(current, ty.skip_binder(), invariant);
328+
}
329+
325330
ty::Error(_) => {
326331
// we encounter this when walking the trait references for object
327332
// types, where we use Error as the Self type

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
117117
Some(&f) => self.pointer_kind(f, span)?,
118118
},
119119

120+
ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
121+
120122
// Pointers to foreign types are thin, despite being unsized
121123
ty::Foreign(..) => Some(PointerKind::Thin),
122124
// We should really try to normalize here.

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
441441
| ty::FnDef(..)
442442
| ty::FnPtr(..)
443443
| ty::Dynamic(..)
444+
| ty::UnsafeBinder(_)
444445
| ty::Never
445446
| ty::Tuple(..)
446447
| ty::Alias(..)

compiler/rustc_lint/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
12601260
FfiSafe
12611261
}
12621262

1263+
ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
1264+
12631265
ty::Param(..)
12641266
| ty::Alias(ty::Projection | ty::Inherent | ty::Weak, ..)
12651267
| ty::Infer(..)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
472472
| ty::CoroutineClosure(..)
473473
| ty::Coroutine(_, _)
474474
| ty::Never
475-
| ty::Tuple(_) => {
475+
| ty::Tuple(_)
476+
| ty::UnsafeBinder(_) => {
476477
let simp = ty::fast_reject::simplify_type(
477478
tcx,
478479
self_ty,
@@ -2309,6 +2310,7 @@ impl<'tcx> TyCtxt<'tcx> {
23092310
Ref,
23102311
FnDef,
23112312
FnPtr,
2313+
UnsafeBinder,
23122314
Placeholder,
23132315
Coroutine,
23142316
CoroutineWitness,

compiler/rustc_middle/src/ty/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl<'tcx> Ty<'tcx> {
191191
_ => "fn item".into(),
192192
},
193193
ty::FnPtr(..) => "fn pointer".into(),
194+
ty::UnsafeBinder(_) => "unsafe binder".into(),
194195
ty::Dynamic(..) => "trait object".into(),
195196
ty::Closure(..) | ty::CoroutineClosure(..) => "closure".into(),
196197
ty::Coroutine(def_id, ..) => {

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ impl FlagComputation {
253253
&ty::FnPtr(sig_tys, _) => self.bound_computation(sig_tys, |computation, sig_tys| {
254254
computation.add_tys(sig_tys.inputs_and_output);
255255
}),
256+
257+
&ty::UnsafeBinder(bound_ty) => {
258+
self.bound_computation(bound_ty.into(), |computation, ty| {
259+
computation.add_ty(ty);
260+
})
261+
}
256262
}
257263
}
258264

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,11 @@ where
816816
bug!("TyAndLayout::field({:?}): not applicable", this)
817817
}
818818

819+
ty::UnsafeBinder(bound_ty) => {
820+
let ty = tcx.instantiate_bound_regions_with_erased(bound_ty.into());
821+
field_ty_or_layout(TyAndLayout { ty, ..this }, cx, i)
822+
}
823+
819824
// Potentially-wide pointers.
820825
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
821826
assert!(i < this.fields.count());

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ fn characteristic_def_id_of_type_cached<'a>(
291291
| ty::Uint(_)
292292
| ty::Str
293293
| ty::FnPtr(..)
294+
| ty::UnsafeBinder(_)
294295
| ty::Alias(..)
295296
| ty::Placeholder(..)
296297
| ty::Param(_)

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
696696
}
697697
}
698698
ty::FnPtr(ref sig_tys, hdr) => p!(print(sig_tys.with(hdr))),
699+
ty::UnsafeBinder(ref bound_ty) => {
700+
self.wrap_binder(bound_ty, |ty, cx| cx.pretty_print_type(*ty))?;
701+
}
699702
ty::Infer(infer_ty) => {
700703
if self.should_print_verbose() {
701704
p!(write("{:?}", ty.kind()));

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
377377
ty::Tuple(ts) => ty::Tuple(ts.try_fold_with(folder)?),
378378
ty::FnDef(def_id, args) => ty::FnDef(def_id, args.try_fold_with(folder)?),
379379
ty::FnPtr(sig_tys, hdr) => ty::FnPtr(sig_tys.try_fold_with(folder)?, hdr),
380+
ty::UnsafeBinder(f) => ty::UnsafeBinder(f.try_fold_with(folder)?),
380381
ty::Ref(r, ty, mutbl) => {
381382
ty::Ref(r.try_fold_with(folder)?, ty.try_fold_with(folder)?, mutbl)
382383
}
@@ -427,6 +428,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
427428
ty::Tuple(ts) => ts.visit_with(visitor),
428429
ty::FnDef(_, args) => args.visit_with(visitor),
429430
ty::FnPtr(ref sig_tys, _) => sig_tys.visit_with(visitor),
431+
ty::UnsafeBinder(ref f) => f.visit_with(visitor),
430432
ty::Ref(r, ty, _) => {
431433
try_visit!(r.visit_with(visitor));
432434
ty.visit_with(visitor)

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,11 @@ impl<'tcx> Ty<'tcx> {
674674
Ty::new(tcx, FnPtr(sig_tys, hdr))
675675
}
676676

677+
#[inline]
678+
pub fn new_unsafe_binder(tcx: TyCtxt<'tcx>, b: Binder<'tcx, Ty<'tcx>>) -> Ty<'tcx> {
679+
Ty::new(tcx, UnsafeBinder(b.into()))
680+
}
681+
677682
#[inline]
678683
pub fn new_dynamic(
679684
tcx: TyCtxt<'tcx>,
@@ -963,6 +968,10 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
963968
Ty::new_pat(interner, ty, pat)
964969
}
965970

971+
fn new_unsafe_binder(interner: TyCtxt<'tcx>, ty: ty::Binder<'tcx, Ty<'tcx>>) -> Self {
972+
Ty::new_unsafe_binder(interner, ty)
973+
}
974+
966975
fn new_unit(interner: TyCtxt<'tcx>) -> Self {
967976
interner.types.unit
968977
}
@@ -1481,6 +1490,7 @@ impl<'tcx> Ty<'tcx> {
14811490
| ty::CoroutineWitness(..)
14821491
| ty::Never
14831492
| ty::Tuple(_)
1493+
| ty::UnsafeBinder(_)
14841494
| ty::Error(_)
14851495
| ty::Infer(IntVar(_) | FloatVar(_)) => tcx.types.u8,
14861496

@@ -1660,6 +1670,8 @@ impl<'tcx> Ty<'tcx> {
16601670
// metadata of `tail`.
16611671
ty::Param(_) | ty::Alias(..) => Err(tail),
16621672

1673+
| ty::UnsafeBinder(_) => todo!("FIXME(unsafe_binder)"),
1674+
16631675
ty::Infer(ty::TyVar(_))
16641676
| ty::Pat(..)
16651677
| ty::Bound(..)
@@ -1820,6 +1832,7 @@ impl<'tcx> Ty<'tcx> {
18201832
| ty::Float(_)
18211833
| ty::FnDef(..)
18221834
| ty::FnPtr(..)
1835+
| ty::UnsafeBinder(_)
18231836
| ty::RawPtr(..)
18241837
| ty::Char
18251838
| ty::Ref(..)
@@ -1899,6 +1912,8 @@ impl<'tcx> Ty<'tcx> {
18991912
// Might be, but not "trivial" so just giving the safe answer.
19001913
ty::Adt(..) | ty::Closure(..) | ty::CoroutineClosure(..) => false,
19011914

1915+
ty::UnsafeBinder(_) => false,
1916+
19021917
// Needs normalization or revealing to determine, so no is the safe answer.
19031918
ty::Alias(..) => false,
19041919

@@ -1977,7 +1992,8 @@ impl<'tcx> Ty<'tcx> {
19771992
| Coroutine(_, _)
19781993
| CoroutineWitness(..)
19791994
| Never
1980-
| Tuple(_) => true,
1995+
| Tuple(_)
1996+
| UnsafeBinder(_) => true,
19811997
Error(_) | Infer(_) | Alias(_, _) | Param(_) | Bound(_, _) | Placeholder(_) => false,
19821998
}
19831999
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ impl<'tcx> Ty<'tcx> {
12411241
| ty::Foreign(_)
12421242
| ty::Coroutine(..)
12431243
| ty::CoroutineWitness(..)
1244+
| ty::UnsafeBinder(_)
12441245
| ty::Infer(_)
12451246
| ty::Alias(..)
12461247
| ty::Param(_)
@@ -1281,6 +1282,7 @@ impl<'tcx> Ty<'tcx> {
12811282
| ty::Foreign(_)
12821283
| ty::Coroutine(..)
12831284
| ty::CoroutineWitness(..)
1285+
| ty::UnsafeBinder(_)
12841286
| ty::Infer(_)
12851287
| ty::Alias(..)
12861288
| ty::Param(_)
@@ -1322,6 +1324,9 @@ impl<'tcx> Ty<'tcx> {
13221324
| ty::Infer(ty::FreshIntTy(_))
13231325
| ty::Infer(ty::FreshFloatTy(_)) => AsyncDropGlueMorphology::Noop,
13241326

1327+
// FIXME(unsafe_binders):
1328+
ty::UnsafeBinder(_) => todo!(),
1329+
13251330
ty::Tuple(tys) if tys.is_empty() => AsyncDropGlueMorphology::Noop,
13261331
ty::Adt(adt_def, _) if adt_def.is_manually_drop() => AsyncDropGlueMorphology::Noop,
13271332

@@ -1522,7 +1527,7 @@ impl<'tcx> Ty<'tcx> {
15221527
false
15231528
}
15241529

1525-
ty::Foreign(_) | ty::CoroutineWitness(..) | ty::Error(_) => false,
1530+
ty::Foreign(_) | ty::CoroutineWitness(..) | ty::Error(_) | ty::UnsafeBinder(_) => false,
15261531
}
15271532
}
15281533

@@ -1681,7 +1686,8 @@ pub fn needs_drop_components_with_async<'tcx>(
16811686
| ty::Closure(..)
16821687
| ty::CoroutineClosure(..)
16831688
| ty::Coroutine(..)
1684-
| ty::CoroutineWitness(..) => Ok(smallvec![ty]),
1689+
| ty::CoroutineWitness(..)
1690+
| ty::UnsafeBinder(_) => Ok(smallvec![ty]),
16851691
}
16861692
}
16871693

compiler/rustc_middle/src/ty/walk.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
194194
sig_tys.skip_binder().inputs_and_output.iter().rev().map(|ty| ty.into()),
195195
);
196196
}
197+
ty::UnsafeBinder(bound_ty) => {
198+
stack.push(bound_ty.skip_binder().into());
199+
}
197200
},
198201
GenericArgKind::Lifetime(_) => {}
199202
GenericArgKind::Const(parent_ct) => match parent_ct.kind() {

compiler/rustc_mir_dataflow/src/move_paths/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
154154
| ty::Slice(_)
155155
| ty::FnDef(_, _)
156156
| ty::FnPtr(..)
157+
| ty::UnsafeBinder(..)
157158
| ty::Dynamic(_, _, _)
158159
| ty::Closure(..)
159160
| ty::CoroutineClosure(..)
@@ -197,6 +198,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
197198
| ty::Ref(_, _, _)
198199
| ty::FnDef(_, _)
199200
| ty::FnPtr(..)
201+
| ty::UnsafeBinder(_)
200202
| ty::Dynamic(_, _, _)
201203
| ty::CoroutineWitness(..)
202204
| ty::Never

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,8 @@ fn try_write_constant<'tcx>(
944944
| ty::Closure(..)
945945
| ty::CoroutineClosure(..)
946946
| ty::Coroutine(..)
947-
| ty::Dynamic(..) => throw_machine_stop_str!("unsupported type"),
947+
| ty::Dynamic(..)
948+
| ty::UnsafeBinder(_) => throw_machine_stop_str!("unsupported type"),
948949

949950
ty::Error(_) | ty::Infer(..) | ty::CoroutineWitness(..) => bug!(),
950951
}

0 commit comments

Comments
 (0)