Skip to content

Commit 2544b8c

Browse files
committed
Implement fn_def_datum
1 parent 3d73030 commit 2544b8c

File tree

12 files changed

+93
-61
lines changed

12 files changed

+93
-61
lines changed

Cargo.lock

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -429,15 +429,15 @@ dependencies = [
429429
[[package]]
430430
name = "chalk-base"
431431
version = "0.10.1-dev"
432-
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
432+
source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b"
433433
dependencies = [
434-
"lazy_static 1.4.0",
434+
"lazy_static",
435435
]
436436

437437
[[package]]
438438
name = "chalk-derive"
439439
version = "0.10.1-dev"
440-
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
440+
source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b"
441441
dependencies = [
442442
"proc-macro2 1.0.3",
443443
"quote 1.0.2",
@@ -448,7 +448,7 @@ dependencies = [
448448
[[package]]
449449
name = "chalk-engine"
450450
version = "0.10.1-dev"
451-
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
451+
source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b"
452452
dependencies = [
453453
"chalk-base",
454454
"chalk-derive",
@@ -459,7 +459,7 @@ dependencies = [
459459
[[package]]
460460
name = "chalk-ir"
461461
version = "0.10.1-dev"
462-
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
462+
source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b"
463463
dependencies = [
464464
"chalk-base",
465465
"chalk-derive",
@@ -468,13 +468,13 @@ dependencies = [
468468
[[package]]
469469
name = "chalk-solve"
470470
version = "0.10.1-dev"
471-
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
471+
source = "git+https://github.com/jackh726/chalk.git?rev=58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b#58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b"
472472
dependencies = [
473473
"chalk-base",
474474
"chalk-derive",
475475
"chalk-engine",
476476
"chalk-ir",
477-
"ena 0.14.0",
477+
"ena",
478478
"itertools 0.9.0",
479479
"petgraph",
480480
"rustc-hash",
@@ -1038,15 +1038,6 @@ dependencies = [
10381038
"strum_macros",
10391039
]
10401040

1041-
[[package]]
1042-
name = "ena"
1043-
version = "0.13.1"
1044-
source = "registry+https://github.com/rust-lang/crates.io-index"
1045-
checksum = "8944dc8fa28ce4a38f778bd46bf7d923fe73eed5a439398507246c8e017e6f36"
1046-
dependencies = [
1047-
"log",
1048-
]
1049-
10501041
[[package]]
10511042
name = "ena"
10521043
version = "0.14.0"
@@ -3267,7 +3258,7 @@ dependencies = [
32673258
"bitflags",
32683259
"cfg-if",
32693260
"crossbeam-utils 0.7.2",
3270-
"ena 0.14.0",
3261+
"ena",
32713262
"indexmap",
32723263
"jobserver",
32733264
"lazy_static",
@@ -3723,7 +3714,7 @@ dependencies = [
37233714
"bitflags",
37243715
"cfg-if",
37253716
"crossbeam-utils 0.7.2",
3726-
"ena 0.14.0",
3717+
"ena",
37273718
"indexmap",
37283719
"jobserver",
37293720
"lazy_static",

src/librustc_middle/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ rustc_serialize = { path = "../librustc_serialize" }
3030
rustc_ast = { path = "../librustc_ast" }
3131
rustc_span = { path = "../librustc_span" }
3232
byteorder = { version = "1.3" }
33-
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" }
33+
chalk-ir = { git = "https://github.com/jackh726/chalk.git", rev = "58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" }
3434
#chalk-ir = "0.10.0"
3535
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3636
measureme = "0.7.1"

src/librustc_traits/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ rustc_span = { path = "../librustc_span" }
1919
#chalk-ir = "0.10.0"
2020
#chalk-rust-ir = "0.10.0"
2121
#chalk-solve = "0.10.0"
22-
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" }
23-
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" }
22+
chalk-solve = { git = "https://github.com/jackh726/chalk.git", rev = "58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" }
23+
chalk-ir = { git = "https://github.com/jackh726/chalk.git", rev = "58e5a31f48ddd4b940c682e7079d3e79e6ffaa1b" }
2424
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
2525
rustc_infer = { path = "../librustc_infer" }
2626
rustc_trait_selection = { path = "../librustc_trait_selection" }

src/librustc_traits/chalk/db.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,39 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
175175

176176
fn fn_def_datum(
177177
&self,
178-
_fn_def_id: chalk_ir::FnDefId<RustInterner<'tcx>>,
178+
fn_def_id: chalk_ir::FnDefId<RustInterner<'tcx>>,
179179
) -> Arc<chalk_solve::rust_ir::FnDefDatum<RustInterner<'tcx>>> {
180-
unimplemented!()
180+
let def_id = match fn_def_id.0 {
181+
RustDefId::FnDef(def_id) => def_id,
182+
_ => bug!("Did not use `FnDef` variant when expecting FnDef."),
183+
};
184+
let bound_vars = bound_vars_for_item(self.tcx, def_id);
185+
let binders = binders_for(&self.interner, bound_vars);
186+
187+
let predicates = self.tcx.predicates_defined_on(def_id).predicates;
188+
let where_clauses: Vec<_> = predicates
189+
.into_iter()
190+
.map(|(wc, _)| wc.subst(self.tcx, &bound_vars))
191+
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
192+
193+
let sig = self.tcx.fn_sig(def_id);
194+
// FIXME(chalk): Why does this have a Binder
195+
let argument_types = sig
196+
.inputs()
197+
.skip_binder()
198+
.iter()
199+
.map(|t| t.subst(self.tcx, &bound_vars).lower_into(&self.interner))
200+
.collect();
201+
202+
let return_type =
203+
sig.output().skip_binder().subst(self.tcx, &bound_vars).lower_into(&self.interner);
204+
205+
let bound =
206+
chalk_solve::rust_ir::FnDefDatumBound { argument_types, where_clauses, return_type };
207+
Arc::new(chalk_solve::rust_ir::FnDefDatum {
208+
id: fn_def_id,
209+
binders: chalk_ir::Binders::new(binders, bound),
210+
})
181211
}
182212

183213
fn impl_datum(

src/librustc_traits/chalk/lowering.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
167167
ty::PredicateKind::Projection(predicate) => predicate.lower_into(interner),
168168
ty::PredicateKind::WellFormed(arg) => match arg.unpack() {
169169
GenericArgKind::Type(ty) => match ty.kind {
170-
// These types are always WF.
171-
ty::Str | ty::Placeholder(..) | ty::Error | ty::Never => {
172-
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
173-
}
174-
175-
// FIXME(chalk): Well-formed only if ref lifetime outlives type
176-
ty::Ref(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)),
177-
178-
ty::Param(..) => panic!("No Params expected."),
170+
// FIXME(chalk): In Chalk, a placeholder is WellFormed if it
171+
// `FromEnv`. However, when we "lower" Params, we don't update
172+
// the environment.
173+
ty::Placeholder(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)),
179174

180-
// FIXME(chalk) -- ultimately I think this is what we
181-
// want to do, and we just have rules for how to prove
182-
// `WellFormed` for everything above, instead of
183-
// inlining a bit the rules of the proof here.
184175
_ => chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::WellFormed(
185176
chalk_ir::WellFormed::Ty(ty.lower_into(interner)),
186177
)),
@@ -360,9 +351,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
360351
),
361352
)
362353
}
363-
FnDef(def_id, _) => apply(
354+
FnDef(def_id, substs) => apply(
364355
chalk_ir::TypeName::FnDef(chalk_ir::FnDefId(RustDefId::FnDef(def_id))),
365-
empty(),
356+
substs.lower_into(interner),
366357
),
367358
FnPtr(sig) => {
368359
let (inputs_and_outputs, binders, _named_regions) =

src/test/ui/chalkify/impl_wf.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ trait Bar {
88

99
impl Foo for i32 { }
1010

11-
// FIXME(chalk): blocked on better handling of builtin traits for non-struct
12-
// application types (or a workaround)
13-
/*
1411
impl Foo for str { }
15-
//^ ERROR the size for values of type `str` cannot be known at compilation time
16-
*/
12+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
13+
1714

1815
// Implicit `T: Sized` bound.
1916
impl<T> Foo for Option<T> { }

src/test/ui/chalkify/impl_wf.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
error[E0277]: the size for values of type `str` cannot be known at compilation time
2+
--> $DIR/impl_wf.rs:11:6
3+
|
4+
LL | trait Foo: Sized { }
5+
| ----- required by this bound in `Foo`
6+
...
7+
LL | impl Foo for str { }
8+
| ^^^ doesn't have a size known at compile-time
9+
|
10+
= help: the trait `std::marker::Sized` is not implemented for `str`
11+
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
12+
113
error[E0277]: the trait bound `f32: Foo` is not satisfied
2-
--> $DIR/impl_wf.rs:43:6
14+
--> $DIR/impl_wf.rs:40:6
315
|
416
LL | trait Baz<U: ?Sized> where U: Foo { }
517
| --- required by this bound in `Baz`
618
...
719
LL | impl Baz<f32> for f32 { }
820
| ^^^^^^^^ the trait `Foo` is not implemented for `f32`
921

10-
error: aborting due to previous error
22+
error: aborting due to 2 previous errors
1123

1224
For more information about this error, try `rustc --explain E0277`.

src/test/ui/chalkify/type_inference.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ fn main() {
1818
// is expecting a variable of type `i32`. This behavior differs from the
1919
// old-style trait solver. I guess this will change, that's why I'm
2020
// adding that test.
21-
// FIXME(chalk): partially blocked on float/int special casing
2221
only_foo(x); //~ ERROR the trait bound `f64: Foo` is not satisfied
2322

2423
// Here we have two solutions so we get back the behavior of the old-style
2524
// trait solver.
26-
// FIXME(chalk): blocked on float/int special casing
27-
//only_bar(x); // ERROR the trait bound `{float}: Bar` is not satisfied
25+
only_bar(x); //~ ERROR the trait bound `f64: Bar` is not satisfied
2826
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
error[E0277]: the trait bound `f64: Foo` is not satisfied
2-
--> $DIR/type_inference.rs:22:5
2+
--> $DIR/type_inference.rs:21:5
33
|
44
LL | fn only_foo<T: Foo>(_x: T) { }
55
| --- required by this bound in `only_foo`
66
...
77
LL | only_foo(x);
88
| ^^^^^^^^ the trait `Foo` is not implemented for `f64`
99

10-
error: aborting due to previous error
10+
error[E0277]: the trait bound `f64: Bar` is not satisfied
11+
--> $DIR/type_inference.rs:25:5
12+
|
13+
LL | fn only_bar<T: Bar>(_x: T) { }
14+
| --- required by this bound in `only_bar`
15+
...
16+
LL | only_bar(x);
17+
| ^^^^^^^^ the trait `Bar` is not implemented for `f64`
18+
19+
error: aborting due to 2 previous errors
1120

1221
For more information about this error, try `rustc --explain E0277`.

src/test/ui/chalkify/type_wf.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// FIXME(chalk): should have an error, see below
2-
// check-pass
1+
// check-fail
32
// compile-flags: -Z chalk
43

54
trait Foo { }
@@ -16,17 +15,11 @@ fn main() {
1615
x: 5,
1716
};
1817

19-
// FIXME(chalk): blocked on float/int special handling. Needs to know that {float}: !i32
20-
/*
21-
let s = S { // ERROR the trait bound `{float}: Foo` is not satisfied
18+
let s = S { //~ ERROR the trait bound `f64: Foo` is not satisfied
2219
x: 5.0,
2320
};
24-
*/
2521

26-
// FIXME(chalk): blocked on float/int special handling. Needs to know that {float}: Sized
27-
/*
2822
let s = S {
2923
x: Some(5.0),
3024
};
31-
*/
3225
}

0 commit comments

Comments
 (0)