Skip to content

Commit 7a5b939

Browse files
committed
Lower consts
1 parent 6172e9a commit 7a5b939

File tree

3 files changed

+47
-35
lines changed

3 files changed

+47
-35
lines changed

src/librustc_middle/traits/chalk.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! its name suggest, is to provide an abstraction boundary for creating
66
//! interned Chalk types.
77
8+
use rustc_middle::mir::interpret::ConstValue;
89
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
910
use rustc_middle::ty::{self, Ty, TyCtxt};
1011

@@ -63,7 +64,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
6364
type InternedType = Box<chalk_ir::TyData<Self>>;
6465
type InternedLifetime = Box<chalk_ir::LifetimeData<Self>>;
6566
type InternedConst = Box<chalk_ir::ConstData<Self>>;
66-
type InternedConcreteConst = u32;
67+
type InternedConcreteConst = ConstValue<'tcx>;
6768
type InternedGenericArg = Box<chalk_ir::GenericArgData<Self>>;
6869
type InternedGoal = Box<chalk_ir::GoalData<Self>>;
6970
type InternedGoals = Vec<chalk_ir::Goal<Self>>;

src/librustc_traits/chalk/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ fn binders_for<'tcx>(
468468
ty::subst::GenericArgKind::Type(_ty) => {
469469
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)
470470
}
471-
ty::subst::GenericArgKind::Const(_const) => {
472-
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)
471+
ty::subst::GenericArgKind::Const(c) => {
472+
chalk_ir::VariableKind::Const(c.ty.lower_into(interner))
473473
}
474474
}),
475475
)

src/librustc_traits/chalk/lowering.rs

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,26 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
100100
ty::PredicateKind::RegionOutlives(predicate) => {
101101
let (predicate, binders, _named_regions) =
102102
collect_bound_vars(interner, interner.tcx, predicate);
103-
103+
104104
Some(
105105
chalk_ir::ProgramClauseData::ForAll(chalk_ir::Binders::new(
106106
binders,
107107
chalk_ir::ProgramClauseImplication {
108108
consequence: chalk_ir::DomainGoal::Holds(
109-
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
110-
a: predicate.0.lower_into(interner),
111-
b: predicate.1.lower_into(interner),
112-
})
109+
chalk_ir::WhereClause::LifetimeOutlives(
110+
chalk_ir::LifetimeOutlives {
111+
a: predicate.0.lower_into(interner),
112+
b: predicate.1.lower_into(interner),
113+
},
114+
),
113115
),
114116
conditions: chalk_ir::Goals::new(interner),
115117
priority: chalk_ir::ClausePriority::High,
116118
},
117119
))
118120
.intern(interner),
119121
)
120-
},
122+
}
121123
// FIXME(chalk): need to add TypeOutlives
122124
ty::PredicateKind::TypeOutlives(_) => None,
123125
ty::PredicateKind::Projection(predicate) => {
@@ -188,9 +190,10 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
188190
chalk_ir::WhereClause::LifetimeOutlives(chalk_ir::LifetimeOutlives {
189191
a: predicate.0.lower_into(interner),
190192
b: predicate.1.lower_into(interner),
191-
})
192-
)).intern(interner)
193-
)
193+
}),
194+
))
195+
.intern(interner),
196+
),
194197
)
195198
}
196199
// FIXME(chalk): TypeOutlives
@@ -216,9 +219,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
216219
GenericArgKind::Lifetime(lt) => bug!("unexpect well formed predicate: {:?}", lt),
217220
},
218221

219-
ty::PredicateKind::ObjectSafe(t) => {
220-
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(*t)))
221-
}
222+
ty::PredicateKind::ObjectSafe(t) => chalk_ir::GoalData::DomainGoal(
223+
chalk_ir::DomainGoal::ObjectSafe(chalk_ir::TraitId(*t)),
224+
),
222225

223226
// FIXME(chalk): other predicates
224227
//
@@ -335,25 +338,34 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
335338
Adt(def, substs) => apply(struct_ty(def.did), substs.lower_into(interner)),
336339
Foreign(_def_id) => unimplemented!(),
337340
Str => apply(chalk_ir::TypeName::Str, empty()),
338-
Array(ty, _) => apply(
339-
chalk_ir::TypeName::Array,
340-
chalk_ir::Substitution::from(
341-
interner,
342-
&[
343-
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
344-
chalk_ir::GenericArgData::Const(
345-
chalk_ir::ConstData {
346-
ty: apply(chalk_ir::TypeName::Tuple(0), empty()),
347-
value: chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst {
348-
interned: 0,
349-
}),
350-
}
341+
Array(ty, len) => {
342+
let value = match len.val {
343+
ty::ConstKind::Value(val) => {
344+
chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: val })
345+
}
346+
ty::ConstKind::Bound(db, bound) => {
347+
chalk_ir::ConstValue::BoundVar(chalk_ir::BoundVar::new(
348+
chalk_ir::DebruijnIndex::new(db.as_u32()),
349+
bound.index(),
350+
))
351+
}
352+
_ => unimplemented!("Const not implemented. {:?}", len.val),
353+
};
354+
apply(
355+
chalk_ir::TypeName::Array,
356+
chalk_ir::Substitution::from(
357+
interner,
358+
&[
359+
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
360+
chalk_ir::GenericArgData::Const(
361+
chalk_ir::ConstData { ty: len.ty.lower_into(interner), value }
362+
.intern(interner),
363+
)
351364
.intern(interner),
352-
)
353-
.intern(interner),
354-
],
355-
),
356-
),
365+
],
366+
),
367+
)
368+
}
357369
Slice(ty) => apply(
358370
chalk_ir::TypeName::Slice,
359371
chalk_ir::Substitution::from1(
@@ -532,8 +544,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
532544
b: predicate.1.lower_into(interner),
533545
}),
534546
))
535-
536-
},
547+
}
537548
ty::PredicateKind::TypeOutlives(_predicate) => None,
538549
ty::PredicateKind::Projection(_predicate) => None,
539550
ty::PredicateKind::WellFormed(_ty) => None,

0 commit comments

Comments
 (0)