From 4e9e0aae33261263e0dc8d5411097efef94f07e7 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Wed, 16 Aug 2023 08:43:30 +0300 Subject: [PATCH 1/4] subtyping_projections --- src/base.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/base.rs b/src/base.rs index 6d55fdc3074..06780567fb8 100644 --- a/src/base.rs +++ b/src/base.rs @@ -872,6 +872,9 @@ pub(crate) fn codegen_place<'tcx>( for elem in place.projection { match elem { + PlaceElem::Subtype(_) => { + continue; + } PlaceElem::Deref => { cplace = cplace.place_deref(fx); } From 8c3406f8bc3c20cb38c44514f1017c25ee566cd5 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 28 Aug 2023 11:19:19 +0300 Subject: [PATCH 2/4] Add docs, remove code, change subtyper code --- src/base.rs | 4 +--- src/value_and_place.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/base.rs b/src/base.rs index 06780567fb8..a13d3a0e115 100644 --- a/src/base.rs +++ b/src/base.rs @@ -872,13 +872,11 @@ pub(crate) fn codegen_place<'tcx>( for elem in place.projection { match elem { - PlaceElem::Subtype(_) => { - continue; - } PlaceElem::Deref => { cplace = cplace.place_deref(fx); } PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"), + PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, ty), PlaceElem::Field(field, _ty) => { cplace = cplace.place_field(fx, field); } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index d4273c0b593..34cde0a0e78 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -674,6 +674,14 @@ fn transmute_scalar<'tcx>( } } + pub(crate) fn place_transmute_type( + self, + fx: &mut FunctionCx<'_, '_, 'tcx>, + ty: Ty<'tcx>, + ) -> CPlace<'tcx> { + CPlace { inner: self.inner, layout: fx.layout_of(fx.monomorphize(ty)) } + } + pub(crate) fn place_field( self, fx: &mut FunctionCx<'_, '_, 'tcx>, From 646d8d982264b91bd1b434b30b25845f21508c48 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Sat, 30 Sep 2023 13:44:31 +0300 Subject: [PATCH 3/4] change is_subtype to relate_types --- src/base.rs | 2 +- src/value_and_place.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/base.rs b/src/base.rs index a13d3a0e115..0a451dad9d2 100644 --- a/src/base.rs +++ b/src/base.rs @@ -876,7 +876,7 @@ pub(crate) fn codegen_place<'tcx>( cplace = cplace.place_deref(fx); } PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"), - PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, ty), + PlaceElem::Subtype(ty) => cplace = cplace.place_transmute_type(fx, fx.monomorphize(ty)), PlaceElem::Field(field, _ty) => { cplace = cplace.place_field(fx, field); } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 34cde0a0e78..09033cfb23f 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -674,12 +674,14 @@ fn transmute_scalar<'tcx>( } } + /// Used for `ProjectionElem::Subtype`, ty has to be monomorphized before + /// passed on. pub(crate) fn place_transmute_type( self, fx: &mut FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>, ) -> CPlace<'tcx> { - CPlace { inner: self.inner, layout: fx.layout_of(fx.monomorphize(ty)) } + CPlace { inner: self.inner, layout: fx.layout_of(ty) } } pub(crate) fn place_field( From 27f88ee273edfbe69a7787a523d6ba081ab02709 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Mon, 2 Oct 2023 11:22:48 +0300 Subject: [PATCH 4/4] have better explanation for `relate_types` --- src/value_and_place.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 09033cfb23f..45893a4f3ac 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -674,7 +674,7 @@ fn transmute_scalar<'tcx>( } } - /// Used for `ProjectionElem::Subtype`, ty has to be monomorphized before + /// Used for `ProjectionElem::Subtype`, `ty` has to be monomorphized before /// passed on. pub(crate) fn place_transmute_type( self,