Skip to content

Commit b86d909

Browse files
committed
Auto merge of #50937 - nikomatsakis:chalkify-engine-2, r=scalexm
implement the chalk-engine traits Preliminary implementation for the Chalk traits in rustc. Lots of `panic!()` placeholders to be filled in later. This is currently blocked on us landing rust-lang/chalk#131 in chalk and issuing a new release, which should occur later today. r? @scalexm cc @leodasvacas
2 parents c2d4603 + 8fd316f commit b86d909

File tree

15 files changed

+934
-240
lines changed

15 files changed

+934
-240
lines changed

src/Cargo.lock

+28
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,23 @@ name = "cfg-if"
261261
version = "0.1.2"
262262
source = "registry+https://github.com/rust-lang/crates.io-index"
263263

264+
[[package]]
265+
name = "chalk-engine"
266+
version = "0.6.0"
267+
source = "registry+https://github.com/rust-lang/crates.io-index"
268+
dependencies = [
269+
"chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
270+
"rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
271+
]
272+
273+
[[package]]
274+
name = "chalk-macros"
275+
version = "0.1.0"
276+
source = "registry+https://github.com/rust-lang/crates.io-index"
277+
dependencies = [
278+
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
279+
]
280+
264281
[[package]]
265282
name = "chrono"
266283
version = "0.4.1"
@@ -1739,6 +1756,7 @@ dependencies = [
17391756
"backtrace 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
17401757
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
17411758
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
1759+
"chalk-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
17421760
"flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
17431761
"fmt_macros 0.0.0",
17441762
"graphviz 0.0.0",
@@ -1840,6 +1858,11 @@ name = "rustc-demangle"
18401858
version = "0.1.7"
18411859
source = "registry+https://github.com/rust-lang/crates.io-index"
18421860

1861+
[[package]]
1862+
name = "rustc-hash"
1863+
version = "1.0.0"
1864+
source = "registry+https://github.com/rust-lang/crates.io-index"
1865+
18431866
[[package]]
18441867
name = "rustc-main"
18451868
version = "0.0.0"
@@ -1982,6 +2005,7 @@ dependencies = [
19822005
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
19832006
"parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
19842007
"parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
2008+
"rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
19852009
"rustc-rayon 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
19862010
"rustc_cratesio_shim 0.0.0",
19872011
"serialize 0.0.0",
@@ -2216,6 +2240,7 @@ name = "rustc_traits"
22162240
version = "0.0.0"
22172241
dependencies = [
22182242
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2243+
"chalk-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
22192244
"graphviz 0.0.0",
22202245
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
22212246
"rustc 0.0.0",
@@ -2998,6 +3023,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
29983023
"checksum cargo_metadata 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ebd6272a2ca4fd39dbabbd6611eb03df45c2259b3b80b39a9ff8fbdcf42a4b3"
29993024
"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba"
30003025
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
3026+
"checksum chalk-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a146c19172c7eea48ea55a7123ac95da786639bc665097f1e14034ee5f1d8699"
3027+
"checksum chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "295635afd6853aa9f20baeb7f0204862440c0fe994c5a253d5f479dac41d047e"
30013028
"checksum chrono 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ba5f60682a4c264e7f8d77b82e7788938a76befdf949d4a98026d19099c9d873"
30023029
"checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536"
30033030
"checksum clippy_lints 0.0.200 (registry+https://github.com/rust-lang/crates.io-index)" = "d2432663f6bdb90255dcf9df5ca504f99b575bb471281591138f62f9d31f863b"
@@ -3142,6 +3169,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
31423169
"checksum rustc-ap-syntax 128.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf9ca2901388714e9ccc7de7281ef06cec55d9f245252ba1d635bc86c730d9a"
31433170
"checksum rustc-ap-syntax_pos 128.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5217444369a36e98e11f4ac976f03878704893832e2e0b57d49f2f31438139f"
31443171
"checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb"
3172+
"checksum rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e06ddba37baa245040f932b15403071a46681d7e0e4158e230741943c4718b84"
31453173
"checksum rustc-rayon 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1aa5cd8c3a706edb19b6ec6aa7b056bdc635b6e99c5cf7014f9af9d92f15e99"
31463174
"checksum rustc-rayon-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d69983f8613a9c3ba1a3bbf5e8bdf2fd5c42317b1d8dd8623ca8030173bf8a6b"
31473175
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"

src/librustc/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ syntax = { path = "../libsyntax" }
2626
syntax_pos = { path = "../libsyntax_pos" }
2727
backtrace = "0.3.3"
2828
byteorder = { version = "1.1", features = ["i128"]}
29+
chalk-engine = { version = "0.6.0", default-features=false }
2930

3031
# Note that these dependencies are a lie, they're just here to get linkage to
3132
# work.
@@ -56,3 +57,5 @@ byteorder = { version = "1.1", features = ["i128"]}
5657
# compiles, then please feel free to do so!
5758
flate2 = "1.0"
5859
tempdir = "0.3"
60+
61+

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ extern crate rustc_errors as errors;
8989
extern crate syntax_pos;
9090
extern crate jobserver;
9191
extern crate proc_macro;
92+
extern crate chalk_engine;
9293

9394
extern crate serialize as rustc_serialize; // used by deriving
9495

src/librustc/macros.rs

+36-9
Original file line numberDiff line numberDiff line change
@@ -250,25 +250,52 @@ macro_rules! BraceStructLiftImpl {
250250
macro_rules! EnumLiftImpl {
251251
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
252252
type Lifted = $lifted:ty;
253-
$(
254-
($variant:path) ( $( $variant_arg:ident),* )
255-
),*
256-
$(,)*
253+
$($variants:tt)*
257254
} $(where $($wc:tt)*)*) => {
258255
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
259256
$(where $($wc)*)*
260257
{
261258
type Lifted = $lifted;
262259

263260
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<$lifted> {
264-
match self {
265-
$($variant ( $($variant_arg),* ) => {
266-
Some($variant ( $(tcx.lift($variant_arg)?),* ))
267-
})*
268-
}
261+
EnumLiftImpl!(@Variants(self, tcx) input($($variants)*) output())
269262
}
270263
}
271264
};
265+
266+
(@Variants($this:expr, $tcx:expr) input() output($($output:tt)*)) => {
267+
match $this {
268+
$($output)*
269+
}
270+
};
271+
272+
(@Variants($this:expr, $tcx:expr)
273+
input( ($variant:path) ( $($variant_arg:ident),* ) , $($input:tt)*)
274+
output( $($output:tt)*) ) => {
275+
EnumLiftImpl!(
276+
@Variants($this, $tcx)
277+
input($($input)*)
278+
output(
279+
$variant ( $($variant_arg),* ) => {
280+
Some($variant ( $($tcx.lift($variant_arg)?),* ))
281+
}
282+
$($output)*
283+
)
284+
)
285+
};
286+
287+
(@Variants($this:expr, $tcx:expr)
288+
input( ($variant:path), $($input:tt)*)
289+
output( $($output:tt)*) ) => {
290+
EnumLiftImpl!(
291+
@Variants($this, $tcx)
292+
input($($input)*)
293+
output(
294+
$variant => { Some($variant) }
295+
$($output)*
296+
)
297+
)
298+
};
272299
}
273300

274301
#[macro_export]

src/librustc/traits/mod.rs

+61-1
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ pub use self::FulfillmentErrorCode::*;
1717
pub use self::Vtable::*;
1818
pub use self::ObligationCauseCode::*;
1919

20+
use chalk_engine;
2021
use hir;
2122
use hir::def_id::DefId;
2223
use infer::outlives::env::OutlivesEnvironment;
2324
use middle::region;
2425
use middle::const_val::ConstEvalErr;
2526
use ty::subst::Substs;
26-
use ty::{self, AdtKind, Slice, Ty, TyCtxt, GenericParamDefKind, TypeFoldable, ToPredicate};
27+
use ty::{self, AdtKind, Slice, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
2728
use ty::error::{ExpectedFound, TypeError};
29+
use ty::fold::{TypeFolder, TypeFoldable, TypeVisitor};
30+
use infer::canonical::{Canonical, Canonicalize};
2831
use infer::{InferCtxt};
2932

3033
use rustc_data_structures::sync::Lrc;
34+
use std::fmt::Debug;
3135
use std::rc::Rc;
3236
use syntax::ast;
3337
use syntax_pos::{Span, DUMMY_SP};
@@ -1003,3 +1007,59 @@ pub fn provide(providers: &mut ty::maps::Providers) {
10031007
..*providers
10041008
};
10051009
}
1010+
1011+
impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, Goal<'tcx>> {
1012+
// we ought to intern this, but I'm too lazy just now
1013+
type Canonicalized = Canonical<'gcx, ty::ParamEnvAnd<'gcx, Goal<'gcx>>>;
1014+
1015+
fn intern(
1016+
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
1017+
value: Canonical<'gcx, Self::Lifted>,
1018+
) -> Self::Canonicalized {
1019+
value
1020+
}
1021+
}
1022+
1023+
pub trait ExClauseFold<'tcx>
1024+
where
1025+
Self: chalk_engine::context::Context + Clone,
1026+
{
1027+
fn fold_ex_clause_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(
1028+
ex_clause: &chalk_engine::ExClause<Self>,
1029+
folder: &mut F,
1030+
) -> chalk_engine::ExClause<Self>;
1031+
1032+
fn visit_ex_clause_with<'gcx: 'tcx, V: TypeVisitor<'tcx>>(
1033+
ex_clause: &chalk_engine::ExClause<Self>,
1034+
visitor: &mut V,
1035+
) -> bool;
1036+
}
1037+
1038+
pub trait ExClauseLift<'tcx>
1039+
where
1040+
Self: chalk_engine::context::Context + Clone,
1041+
{
1042+
type LiftedExClause: Debug + 'tcx;
1043+
1044+
fn lift_ex_clause_to_tcx<'a, 'gcx>(
1045+
ex_clause: &chalk_engine::ExClause<Self>,
1046+
tcx: TyCtxt<'a, 'gcx, 'tcx>,
1047+
) -> Option<Self::LiftedExClause>;
1048+
}
1049+
1050+
impl<'gcx: 'tcx, 'tcx, C> Canonicalize<'gcx, 'tcx> for chalk_engine::ExClause<C>
1051+
where
1052+
C: chalk_engine::context::Context + Clone,
1053+
C: ExClauseLift<'gcx> + ExClauseFold<'tcx>,
1054+
C::Substitution: Clone,
1055+
C::RegionConstraint: Clone,
1056+
{
1057+
type Canonicalized = Canonical<'gcx, C::LiftedExClause>;
1058+
1059+
fn intern(
1060+
_gcx: TyCtxt<'_, 'gcx, 'gcx>,
1061+
value: Canonical<'gcx, Self::Lifted>,
1062+
) -> Self::Canonicalized {
1063+
value
1064+
}
1065+
}

0 commit comments

Comments
 (0)