Skip to content

Commit 2cee652

Browse files
committed
Move test macros from chalk_ir to chalk_solve
1 parent 820eabe commit 2cee652

File tree

4 files changed

+119
-106
lines changed

4 files changed

+119
-106
lines changed

chalk-ir/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ macro_rules! impl_debugs {
2929
};
3030
}
3131

32-
#[macro_use]
33-
mod macros;
34-
3532
#[macro_use]
3633
pub mod zip;
3734

chalk-ir/src/macros.rs

Lines changed: 0 additions & 103 deletions
This file was deleted.

chalk-solve/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use std::sync::Arc;
99
#[macro_use]
1010
extern crate chalk_macros;
1111

12+
#[cfg(test)]
13+
#[macro_use]
14+
mod test_macros;
15+
1216
pub mod clauses;
1317
pub mod coherence;
1418
mod coinductive_goal;

chalk-solve/src/test_macros.rs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
//! Useful macros for writing unit tests. They let you gin up dummy types and things.
2+
3+
macro_rules! ty {
4+
(apply $n:tt $($arg:tt)*) => {
5+
chalk_ir::TyData::Apply(ApplicationTy {
6+
name: ty_name!($n),
7+
substitution: chalk_ir::Substitution::from(
8+
&chalk_integration::interner::ChalkIr,
9+
vec![$(arg!($arg)),*] as Vec<chalk_ir::Parameter<_>>
10+
),
11+
}).intern(&chalk_integration::interner::ChalkIr)
12+
};
13+
14+
(function $n:tt $($arg:tt)*) => {
15+
chalk_ir::TyData::Function(Fn {
16+
num_binders: $n,
17+
substitution: chalk_ir::Substitution::from(
18+
&chalk_integration::interner::ChalkIr,
19+
vec![$(arg!($arg)),*] as Vec<chalk_ir::Parameter<_>>
20+
),
21+
}).intern(&chalk_integration::interner::ChalkIr)
22+
};
23+
24+
(placeholder $n:expr) => {
25+
chalk_ir::TyData::Placeholder(PlaceholderIndex {
26+
ui: UniverseIndex { counter: $n },
27+
idx: 0,
28+
}).intern(&chalk_integration::interner::ChalkIr)
29+
};
30+
31+
(projection (item $n:tt) $($arg:tt)*) => {
32+
chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy {
33+
associated_ty_id: AssocTypeId(chalk_integration::interner::RawId { index: $n }),
34+
substitution: chalk_ir::Substitution::from(
35+
&chalk_integration::interner::ChalkIr,
36+
vec![$(arg!($arg)),*] as Vec<chalk_ir::Parameter<_>>
37+
),
38+
}).intern(&chalk_integration::interner::ChalkIr)
39+
};
40+
41+
(infer $b:expr) => {
42+
chalk_ir::TyData::InferenceVar(chalk_ir::InferenceVar::from($b))
43+
.intern(&chalk_integration::interner::ChalkIr)
44+
};
45+
46+
(bound $d:tt $b:tt) => {
47+
chalk_ir::TyData::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::new($d), $b))
48+
.intern(&chalk_integration::interner::ChalkIr)
49+
};
50+
51+
(bound $b:expr) => {
52+
chalk_ir::TyData::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::INNERMOST, $b))
53+
.intern(&chalk_integration::interner::ChalkIr)
54+
};
55+
56+
(expr $b:expr) => {
57+
$b.clone()
58+
};
59+
60+
(($($b:tt)*)) => {
61+
ty!($($b)*)
62+
};
63+
}
64+
65+
macro_rules! arg {
66+
((lifetime $b:tt)) => {
67+
chalk_ir::Parameter::new(
68+
&chalk_integration::interner::ChalkIr,
69+
chalk_ir::ParameterKind::Lifetime(lifetime!($b)),
70+
)
71+
};
72+
73+
($arg:tt) => {
74+
chalk_ir::Parameter::new(
75+
&chalk_integration::interner::ChalkIr,
76+
chalk_ir::ParameterKind::Ty(ty!($arg)),
77+
)
78+
};
79+
}
80+
81+
macro_rules! lifetime {
82+
(infer $b:expr) => {
83+
chalk_ir::LifetimeData::InferenceVar(chalk_ir::InferenceVar::from($b))
84+
.intern(&chalk_integration::interner::ChalkIr)
85+
};
86+
87+
(bound $d:tt $b:tt) => {
88+
chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::new($d), $b))
89+
.intern(&chalk_integration::interner::ChalkIr)
90+
};
91+
92+
(bound $b:expr) => {
93+
chalk_ir::LifetimeData::BoundVar(chalk_ir::BoundVar::new(chalk_ir::DebruijnIndex::INNERMOST, $b))
94+
.intern(&chalk_integration::interner::ChalkIr)
95+
};
96+
97+
(placeholder $b:expr) => {
98+
chalk_ir::LifetimeData::Placeholder(PlaceholderIndex { ui: UniverseIndex { counter: $b }, idx: 0})
99+
.intern(&chalk_integration::interner::ChalkIr)
100+
};
101+
102+
(expr $b:expr) => {
103+
$b.clone()
104+
};
105+
106+
(($($b:tt)*)) => {
107+
lifetime!($($b)*)
108+
};
109+
}
110+
111+
macro_rules! ty_name {
112+
((item $n:expr)) => {
113+
chalk_ir::TypeName::Struct(StructId(chalk_integration::interner::RawId { index: $n }))
114+
};
115+
}

0 commit comments

Comments
 (0)