Skip to content

Commit

Permalink
Conform with latest changes to Binder (used in closures) (rust-lang#27
Browse files Browse the repository at this point in the history
)
  • Loading branch information
adpaco-aws authored and tedinski committed Apr 9, 2021
1 parent 7296610 commit f0e6fea
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
33 changes: 26 additions & 7 deletions compiler/rustc_codegen_llvm/src/gotoc/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ impl<'tcx> GotocCtx<'tcx> {
&mut self,
def_id: DefId,
_substs: ty::subst::SubstsRef<'tcx>,
trait_ref_t: Binder<TraitRef<'tcx>>,
trait_ref_t: Binder<'_, TraitRef<'tcx>>,
t: Ty<'tcx>,
) -> Expr {
let function_name = self.tcx.item_name(def_id).to_string();
Expand Down Expand Up @@ -745,7 +745,7 @@ impl<'tcx> GotocCtx<'tcx> {

fn codegen_vtable_methods(
&mut self,
trait_ref_t: Binder<TraitRef<'tcx>>,
trait_ref_t: Binder<'tcx, TraitRef<'tcx>>,
t: Ty<'tcx>,
) -> Vec<Expr> {
//DSN This assumes that we always get the methods back in the same order.
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_llvm/src/gotoc/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/gotoc/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TraitRef<'tcx>>,
trait_ref_t: Binder<'_, TraitRef<'tcx>>,
) -> String {
with_no_trimmed_paths(|| trait_ref_t.skip_binder().to_string().replace("&", ""))
}
Expand Down

0 comments on commit f0e6fea

Please sign in to comment.