Skip to content

Commit f0e6fea

Browse files
adpaco-awstedinski
authored andcommitted
Conform with latest changes to Binder (used in closures) (rust-lang#27)
1 parent 7296610 commit f0e6fea

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

compiler/rustc_codegen_llvm/src/gotoc/metadata.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
2020
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
2121
use rustc_target::abi::{HasDataLayout, LayoutOf, TargetDataLayout};
2222
use rustc_target::spec::Target;
23+
use std::iter;
2324
use std::path::Path;
2425
use tracing::debug;
2526

@@ -327,18 +328,36 @@ impl<'tcx> GotocCtx<'tcx> {
327328
substs: ty::subst::SubstsRef<'tcx>,
328329
) -> ty::PolyFnSig<'tcx> {
329330
let sig = self.monomorphize(substs.as_closure().sig());
330-
let env_ty = self.tcx.closure_env_ty(def_id, substs).unwrap();
331-
let args = self.closure_params(substs);
332-
let sig = sig.map_bound(|sig| {
331+
332+
// In addition to `def_id` and `substs`, we need to provide the kind of region `env_region`
333+
// in `closure_env_ty`, which we can build from the bound variables as follows
334+
let bound_vars = self.tcx.mk_bound_variable_kinds(
335+
sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))),
336+
);
337+
let br = ty::BoundRegion {
338+
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
339+
kind: ty::BoundRegionKind::BrEnv,
340+
};
341+
let env_region = ty::ReLateBound(ty::INNERMOST, br);
342+
let env_ty = self.tcx.closure_env_ty(def_id, substs, env_region).unwrap();
343+
344+
// The parameter types are tupled, but we want to have them in a vector
345+
let params = self.closure_params(substs);
346+
let sig = sig.skip_binder();
347+
348+
// We build a binder from `sig` where:
349+
// * `inputs` contains a sequence with the closure and parameter types
350+
// * the rest of attributes are obtained from `sig`
351+
ty::Binder::bind_with_vars(
333352
self.tcx.mk_fn_sig(
334-
core::iter::once(env_ty.skip_binder()).chain(args),
353+
iter::once(env_ty).chain(params.iter().cloned()),
335354
sig.output(),
336355
sig.c_variadic,
337356
sig.unsafety,
338357
sig.abi,
339-
)
340-
});
341-
sig
358+
),
359+
bound_vars,
360+
)
342361
}
343362

344363
pub fn fn_sig_of_instance(&self, instance: Instance<'tcx>) -> ty::PolyFnSig<'tcx> {

compiler/rustc_codegen_llvm/src/gotoc/monomorphize/collector.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ pub fn custom_coerce_unsize_info<'tcx>(
3535
) -> CustomCoerceUnsized {
3636
let def_id = tcx.require_lang_item(LangItem::CoerceUnsized, None);
3737

38-
let trait_ref = ty::Binder::bind(ty::TraitRef {
39-
def_id,
40-
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
41-
});
38+
let trait_ref = ty::Binder::bind(
39+
ty::TraitRef { def_id, substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]) },
40+
tcx,
41+
);
4242

4343
match tcx.codegen_fulfill_obligation((ty::ParamEnv::reveal_all(), trait_ref)) {
4444
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {

compiler/rustc_codegen_llvm/src/gotoc/rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ impl<'tcx> GotocCtx<'tcx> {
682682
&mut self,
683683
def_id: DefId,
684684
_substs: ty::subst::SubstsRef<'tcx>,
685-
trait_ref_t: Binder<TraitRef<'tcx>>,
685+
trait_ref_t: Binder<'_, TraitRef<'tcx>>,
686686
t: Ty<'tcx>,
687687
) -> Expr {
688688
let function_name = self.tcx.item_name(def_id).to_string();
@@ -745,7 +745,7 @@ impl<'tcx> GotocCtx<'tcx> {
745745

746746
fn codegen_vtable_methods(
747747
&mut self,
748-
trait_ref_t: Binder<TraitRef<'tcx>>,
748+
trait_ref_t: Binder<'tcx, TraitRef<'tcx>>,
749749
t: Ty<'tcx>,
750750
) -> Vec<Expr> {
751751
//DSN This assumes that we always get the methods back in the same order.

compiler/rustc_codegen_llvm/src/gotoc/statement.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ impl<'tcx> GotocCtx<'tcx> {
205205
let tupe = fargs.remove(1);
206206
for (i, t) in self.closure_params(substs).iter().enumerate() {
207207
if !t.is_unit() {
208-
fargs.push(tupe.clone().member(&i.to_string(), &self.symbol_table));
208+
// Access the tupled parameters through the `member` operation
209+
let index_param = tupe.clone().member(&i.to_string(), &self.symbol_table);
210+
fargs.push(index_param);
209211
}
210212
}
211213
}
@@ -470,7 +472,7 @@ impl<'tcx> GotocCtx<'tcx> {
470472
let e = BuiltinFn::Memcpy.call(vec![dst, src, n], Location::none());
471473
e.as_stmt()
472474
}
473-
StatementKind::FakeRead(_, _)
475+
StatementKind::FakeRead(_)
474476
| StatementKind::Retag(_, _)
475477
| StatementKind::AscribeUserType(_, _)
476478
| StatementKind::Nop

compiler/rustc_codegen_llvm/src/gotoc/typ.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'tcx> GotocCtx<'tcx> {
201201
/// We solve this by normalizeing and removing the "&">::vol", but the inner type would be <&Rectangle as Vol>
202202
pub fn normalized_name_of_dynamic_object_type(
203203
&self,
204-
trait_ref_t: Binder<TraitRef<'tcx>>,
204+
trait_ref_t: Binder<'_, TraitRef<'tcx>>,
205205
) -> String {
206206
with_no_trimmed_paths(|| trait_ref_t.skip_binder().to_string().replace("&", ""))
207207
}

0 commit comments

Comments
 (0)