From f0e6fea7e20e22a446f0b6928f6a25df767f311a Mon Sep 17 00:00:00 2001 From: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com> Date: Fri, 9 Apr 2021 18:52:32 +0200 Subject: [PATCH] Conform with latest changes to `Binder` (used in closures) (#27) --- .../rustc_codegen_llvm/src/gotoc/metadata.rs | 33 +++++++++++++++---- .../src/gotoc/monomorphize/collector.rs | 8 ++--- .../rustc_codegen_llvm/src/gotoc/rvalue.rs | 4 +-- .../rustc_codegen_llvm/src/gotoc/statement.rs | 6 ++-- compiler/rustc_codegen_llvm/src/gotoc/typ.rs | 2 +- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/gotoc/metadata.rs b/compiler/rustc_codegen_llvm/src/gotoc/metadata.rs index abace07670d0f..c55b566ae95a4 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/metadata.rs @@ -20,6 +20,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable}; use rustc_target::abi::{HasDataLayout, LayoutOf, TargetDataLayout}; use rustc_target::spec::Target; +use std::iter; use std::path::Path; use tracing::debug; @@ -327,18 +328,36 @@ impl<'tcx> GotocCtx<'tcx> { substs: ty::subst::SubstsRef<'tcx>, ) -> ty::PolyFnSig<'tcx> { let sig = self.monomorphize(substs.as_closure().sig()); - let env_ty = self.tcx.closure_env_ty(def_id, substs).unwrap(); - let args = self.closure_params(substs); - let sig = sig.map_bound(|sig| { + + // In addition to `def_id` and `substs`, we need to provide the kind of region `env_region` + // in `closure_env_ty`, which we can build from the bound variables as follows + let bound_vars = self.tcx.mk_bound_variable_kinds( + sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), + ); + let br = ty::BoundRegion { + var: ty::BoundVar::from_usize(bound_vars.len() - 1), + kind: ty::BoundRegionKind::BrEnv, + }; + let env_region = ty::ReLateBound(ty::INNERMOST, br); + let env_ty = self.tcx.closure_env_ty(def_id, substs, env_region).unwrap(); + + // The parameter types are tupled, but we want to have them in a vector + let params = self.closure_params(substs); + let sig = sig.skip_binder(); + + // We build a binder from `sig` where: + // * `inputs` contains a sequence with the closure and parameter types + // * the rest of attributes are obtained from `sig` + ty::Binder::bind_with_vars( self.tcx.mk_fn_sig( - core::iter::once(env_ty.skip_binder()).chain(args), + iter::once(env_ty).chain(params.iter().cloned()), sig.output(), sig.c_variadic, sig.unsafety, sig.abi, - ) - }); - sig + ), + bound_vars, + ) } pub fn fn_sig_of_instance(&self, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> { diff --git a/compiler/rustc_codegen_llvm/src/gotoc/monomorphize/collector.rs b/compiler/rustc_codegen_llvm/src/gotoc/monomorphize/collector.rs index 2667305cf2826..adb5e22b0ecc7 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/monomorphize/collector.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/monomorphize/collector.rs @@ -35,10 +35,10 @@ pub fn custom_coerce_unsize_info<'tcx>( ) -> CustomCoerceUnsized { let def_id = tcx.require_lang_item(LangItem::CoerceUnsized, None); - let trait_ref = ty::Binder::bind(ty::TraitRef { - def_id, - substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]), - }); + let trait_ref = ty::Binder::bind( + ty::TraitRef { def_id, substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]) }, + tcx, + ); match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) { Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData { diff --git a/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs b/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs index fbb6dd55dfae9..f0510ed7b3f29 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs @@ -682,7 +682,7 @@ impl<'tcx> GotocCtx<'tcx> { &mut self, def_id: DefId, _substs: ty::subst::SubstsRef<'tcx>, - trait_ref_t: Binder>, + trait_ref_t: Binder<'_, TraitRef<'tcx>>, t: Ty<'tcx>, ) -> Expr { let function_name = self.tcx.item_name(def_id).to_string(); @@ -745,7 +745,7 @@ impl<'tcx> GotocCtx<'tcx> { fn codegen_vtable_methods( &mut self, - trait_ref_t: Binder>, + trait_ref_t: Binder<'tcx, TraitRef<'tcx>>, t: Ty<'tcx>, ) -> Vec { //DSN This assumes that we always get the methods back in the same order. diff --git a/compiler/rustc_codegen_llvm/src/gotoc/statement.rs b/compiler/rustc_codegen_llvm/src/gotoc/statement.rs index a5ba119e9a485..de489cb8ec56c 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/statement.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/statement.rs @@ -205,7 +205,9 @@ impl<'tcx> GotocCtx<'tcx> { let tupe = fargs.remove(1); for (i, t) in self.closure_params(substs).iter().enumerate() { if !t.is_unit() { - fargs.push(tupe.clone().member(&i.to_string(), &self.symbol_table)); + // Access the tupled parameters through the `member` operation + let index_param = tupe.clone().member(&i.to_string(), &self.symbol_table); + fargs.push(index_param); } } } @@ -470,7 +472,7 @@ impl<'tcx> GotocCtx<'tcx> { let e = BuiltinFn::Memcpy.call(vec![dst, src, n], Location::none()); e.as_stmt() } - StatementKind::FakeRead(_, _) + StatementKind::FakeRead(_) | StatementKind::Retag(_, _) | StatementKind::AscribeUserType(_, _) | StatementKind::Nop diff --git a/compiler/rustc_codegen_llvm/src/gotoc/typ.rs b/compiler/rustc_codegen_llvm/src/gotoc/typ.rs index 32ca47578275c..f8dc033109e1e 100644 --- a/compiler/rustc_codegen_llvm/src/gotoc/typ.rs +++ b/compiler/rustc_codegen_llvm/src/gotoc/typ.rs @@ -201,7 +201,7 @@ impl<'tcx> GotocCtx<'tcx> { /// We solve this by normalizeing and removing the "&">::vol", but the inner type would be <&Rectangle as Vol> pub fn normalized_name_of_dynamic_object_type( &self, - trait_ref_t: Binder>, + trait_ref_t: Binder<'_, TraitRef<'tcx>>, ) -> String { with_no_trimmed_paths(|| trait_ref_t.skip_binder().to_string().replace("&", "")) }