Skip to content

Commit ea3bcbb

Browse files
committed
WIP
1 parent 3238c6d commit ea3bcbb

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

chalk-ir/src/debug.rs

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ impl Debug for Ty {
8585
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
8686
match self {
8787
Ty::BoundVar(depth) => write!(fmt, "^{}", depth),
88+
Ty::Dyn(clauses) => write!(fmt, "{:?}", clauses),
89+
Ty::Opaque(clauses) => write!(fmt, "{:?}", clauses),
8890
Ty::InferenceVar(var) => write!(fmt, "{:?}", var),
8991
Ty::Apply(apply) => write!(fmt, "{:?}", apply),
9092
Ty::Projection(proj) => write!(fmt, "{:?}", proj),

chalk-ir/src/fold.rs

+2
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ pub fn super_fold_ty(folder: &mut dyn Folder, ty: &Ty, binders: usize) -> Fallib
341341
Ok(Ty::BoundVar(depth))
342342
}
343343
}
344+
Ty::Dyn(ref clauses) => Ok(Ty::Dyn(clauses.fold_with(folder, binders)?)),
345+
Ty::Opaque(ref clauses) => Ok(Ty::Opaque(clauses.fold_with(folder, binders)?)),
344346
Ty::InferenceVar(var) => folder.fold_inference_ty(var, binders),
345347
Ty::Apply(ref apply) => {
346348
let ApplicationTy {

chalk-ir/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ pub enum Ty {
222222
/// an empty list).
223223
Apply(ApplicationTy),
224224

225+
Dyn(Vec<QuantifiedWhereClause>),
226+
227+
/// An "opaque" type is one that is created via the "impl Trait" syntax.
228+
/// They are named so because the concrete type implementing the trait
229+
/// is unknown, and hence the type is opaque to us. The only information
230+
/// that we know of is that this type implements the traits listed by the
231+
/// user.
232+
Opaque(Vec<QuantifiedWhereClause>),
233+
225234
/// A "projection" type corresponds to an (unnormalized)
226235
/// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the
227236
/// trait and all its parameters are fully known.

chalk-parse/src/ast.rs

+6
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ pub enum Ty {
151151
Id {
152152
name: Identifier,
153153
},
154+
Dyn {
155+
bounds: Vec<QuantifiedInlineBound>,
156+
},
157+
Opaque {
158+
bounds: Vec<QuantifiedInlineBound>,
159+
},
154160
Apply {
155161
name: Identifier,
156162
args: Vec<Parameter>,

chalk-parse/src/parser.lalrpop

+6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ pub Ty: Ty = {
168168

169169
TyWithoutFor: Ty = {
170170
<n:Id> => Ty::Id { name: n},
171+
"dyn" <b:Plus<QuantifiedInlineBound>> => Ty::Dyn {
172+
bounds: b,
173+
},
174+
"impl" <b:Plus<QuantifiedInlineBound>> => Ty::Opaque {
175+
bounds: b,
176+
},
171177
<n:Id> "<" <a:Comma<Parameter>> ">" => Ty::Apply { name: n, args: a },
172178
<p:ProjectionTy> => Ty::Projection { proj: p },
173179
<proj:UnselectedProjectionTy> => Ty::UnselectedProjection { <> },

chalk-solve/src/solve/slg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ impl MayInvalidate {
409409

410410
// For everything else, be conservative here and just say we may invalidate.
411411
(Ty::ForAll(_), _)
412+
| (Ty::Dyn(_), _)
413+
| (Ty::Opaque(_), _)
412414
| (Ty::Apply(_), _)
413415
| (Ty::Projection(_), _)
414416
| (Ty::UnselectedProjection(_), _) => true,

src/lowering.rs

+12
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,18 @@ impl LowerTy for Ty {
876876
NameLookup::Parameter(d) => Ok(chalk_ir::Ty::BoundVar(d)),
877877
},
878878

879+
Ty::Dyn { bounds } => Ok(chalk_ir::Ty::Dyn(
880+
bounds.lower()?
881+
.flat_map(|qil| qil.into_where_clauses(chalk_ir::Ty::BoundVar(qil.binders.len())))
882+
.collect()
883+
)),
884+
885+
Ty::Opaque { bounds } => Ok(chalk_ir::Ty::Opaque(
886+
bounds.lower()?
887+
.flat_map(|qil| qil.into_where_clauses(chalk_ir::Ty::BoundVar(qil.binders.len())))
888+
.collect()
889+
)),
890+
879891
Ty::Apply { name, ref args } => {
880892
let id = match env.lookup(name)? {
881893
NameLookup::Type(id) => id,

0 commit comments

Comments
 (0)