Skip to content

Commit aeb73db

Browse files
authored
Merge pull request #39 from withoutboats/overlap-check
First version of overlap check.
2 parents 759034a + 99db7c8 commit aeb73db

File tree

9 files changed

+382
-25
lines changed

9 files changed

+382
-25
lines changed

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
[package]
2+
authors = ["Niko Matsakis <[email protected]>"]
23
name = "chalk"
34
version = "0.1.0"
4-
authors = ["Niko Matsakis <[email protected]>"]
5-
6-
[workspace]
75

86
[dependencies]
9-
chalk-parse = { path = "chalk-parse" }
107
ena = "0.4"
118
error-chain = "0.7.2"
9+
itertools = "0.6.0"
1210
lalrpop-intern = "0.12.1"
1311
lazy_static = "0.2.2"
1412
rustyline = "1.0"
13+
14+
[dependencies.chalk-parse]
15+
path = "chalk-parse"
16+
17+
[workspace]

src/errors.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use chalk_parse::{self, ast};
2+
use ir;
23

34
error_chain! {
45
links {
@@ -27,6 +28,11 @@ error_chain! {
2728
description("not a trait")
2829
display("expected a trait, found `{}`, which is not a trait", identifier.str)
2930
}
31+
32+
OverlappingImpls(trait_id: ir::Identifier) {
33+
description("overlapping impls")
34+
display("overlapping impls of trait {:?}", trait_id)
35+
}
3036
}
3137
}
3238

src/fold/shifter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ up_shift_method!(Parameter);
3535
up_shift_method!(Lifetime);
3636
up_shift_method!(TraitRef);
3737
up_shift_method!(ProjectionTy);
38+
up_shift_method!(DomainGoal);
3839

3940
impl Folder for Shifter {
4041
fn fold_free_var(&mut self, depth: usize, binders: usize) -> Result<Ty> {

src/ir/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ impl<G> InEnvironment<G> {
160160
InEnvironment { environment: environment.clone(), goal }
161161
}
162162

163+
pub fn empty(goal: G) -> Self {
164+
InEnvironment { environment: Environment::new(), goal }
165+
}
166+
163167
pub fn map<OP, H>(self, op: OP) -> InEnvironment<H>
164168
where OP: FnOnce(G) -> H
165169
{
@@ -543,6 +547,12 @@ pub enum Goal {
543547
Leaf(LeafGoal),
544548
}
545549

550+
impl Goal {
551+
pub fn quantify(self, kind: QuantifierKind, binders: Vec<ParameterKind<()>>) -> Goal {
552+
Goal::Quantified(kind, Binders { value: Box::new(self), binders })
553+
}
554+
}
555+
546556
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
547557
pub enum QuantifierKind {
548558
ForAll, Exists

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern crate chalk_parse;
77
#[macro_use]
88
extern crate error_chain;
99
extern crate ena;
10+
extern crate itertools;
1011
extern crate lalrpop_intern;
1112
#[macro_use]
1213
extern crate lazy_static;
@@ -19,5 +20,6 @@ pub mod errors;
1920
pub mod fold;
2021
pub mod ir;
2122
pub mod lower;
23+
pub mod overlap;
2224
pub mod solve;
2325
pub mod zip;

src/lower/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use cast::Cast;
1+
use std::collections::HashMap;
2+
23
use chalk_parse::ast::*;
34
use lalrpop_intern::intern;
5+
6+
use cast::Cast;
47
use errors::*;
58
use ir;
6-
use std::collections::HashMap;
79

810
mod test;
911

@@ -183,7 +185,9 @@ impl LowerProgram for Program {
183185
}
184186
}
185187

186-
Ok(ir::Program { type_ids, type_kinds, struct_data, trait_data, impl_data, associated_ty_data, })
188+
let program = ir::Program { type_ids, type_kinds, struct_data, trait_data, impl_data, associated_ty_data, };
189+
program.check_overlapping_impls()?;
190+
Ok(program)
187191
}
188192
}
189193

0 commit comments

Comments
 (0)