Skip to content

Commit 6f425a9

Browse files
committed
implement the chalk traits, albeit with many placeholders
1 parent d022dd4 commit 6f425a9

File tree

10 files changed

+881
-155
lines changed

10 files changed

+881
-155
lines changed

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)