Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/rust-lang/chalk
Browse files Browse the repository at this point in the history
  • Loading branch information
hayashi-stl committed Aug 30, 2020
2 parents e0748ad + bb0b88f commit 6a6a68f
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 50 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
description = "Model of the Rust trait system"
license = "Apache-2.0/MIT"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand All @@ -21,13 +21,13 @@ salsa = "0.15.0"
serde = "1.0"
serde_derive = "1.0"

chalk-derive = { version = "0.24.0-dev.0", path = "chalk-derive" }
chalk-engine = { version = "0.24.0-dev.0", path = "chalk-engine" }
chalk-ir = { version = "0.24.0-dev.0", path = "chalk-ir" }
chalk-solve = { version = "0.24.0-dev.0", path = "chalk-solve" }
chalk-recursive = { version = "0.24.0-dev.0", path = "chalk-recursive" }
chalk-parse = { version = "0.24.0-dev.0", path = "chalk-parse" }
chalk-integration = { version = "0.24.0-dev.0", path = "chalk-integration" }
chalk-derive = { version = "0.26.0-dev.0", path = "chalk-derive" }
chalk-engine = { version = "0.26.0-dev.0", path = "chalk-engine" }
chalk-ir = { version = "0.26.0-dev.0", path = "chalk-ir" }
chalk-solve = { version = "0.26.0-dev.0", path = "chalk-solve" }
chalk-recursive = { version = "0.26.0-dev.0", path = "chalk-recursive" }
chalk-parse = { version = "0.26.0-dev.0", path = "chalk-parse" }
chalk-integration = { version = "0.26.0-dev.0", path = "chalk-integration" }

[workspace]

Expand Down
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

# Release 0.25.0

# Release 0.24.0

# Release 0.23.0

# Release 0.22.0
Expand Down
2 changes: 1 addition & 1 deletion chalk-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk-derive"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
description = "A helper crate for use by chalk crates for `derive` macros."
license = "Apache-2.0/MIT"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand Down
8 changes: 4 additions & 4 deletions chalk-engine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk-engine"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
description = "Core trait engine from Chalk project"
license = "Apache-2.0/MIT"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand All @@ -16,9 +16,9 @@ default = []
rustc-hash = { version = "1.1.0" }
tracing = "0.1"

chalk-derive = { version = "0.24.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.24.0-dev.0", path = "../chalk-ir" }
chalk-solve = { version = "0.24.0-dev.0", path = "../chalk-solve" }
chalk-derive = { version = "0.26.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.26.0-dev.0", path = "../chalk-ir" }
chalk-solve = { version = "0.26.0-dev.0", path = "../chalk-solve" }

[dev-dependencies]
chalk-integration = { path = "../chalk-integration" }
14 changes: 7 additions & 7 deletions chalk-integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk-integration"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
license = "Apache-2.0/MIT"
description = "Sample solver setup for Chalk"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand All @@ -14,9 +14,9 @@ string_cache = "0.8.0"
salsa = "0.15.0"
tracing = "0.1"

chalk-derive = { version = "0.24.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.24.0-dev.0", path = "../chalk-ir" }
chalk-solve = { version = "0.24.0-dev.0", path = "../chalk-solve" }
chalk-recursive = { version = "0.24.0-dev.0", path = "../chalk-recursive" }
chalk-engine = { version = "0.24.0-dev.0", path = "../chalk-engine" }
chalk-parse = { version = "0.24.0-dev.0", path = "../chalk-parse" }
chalk-derive = { version = "0.26.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.26.0-dev.0", path = "../chalk-ir" }
chalk-solve = { version = "0.26.0-dev.0", path = "../chalk-solve" }
chalk-recursive = { version = "0.26.0-dev.0", path = "../chalk-recursive" }
chalk-engine = { version = "0.26.0-dev.0", path = "../chalk-engine" }
chalk-parse = { version = "0.26.0-dev.0", path = "../chalk-parse" }
4 changes: 2 additions & 2 deletions chalk-ir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk-ir"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
description = "Chalk's internal representation of types, goals, and clauses"
license = "Apache-2.0/MIT"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand All @@ -11,4 +11,4 @@ edition = "2018"

[dependencies]
lazy_static = "1.4.0"
chalk-derive = { version = "0.24.0-dev.0", path = "../chalk-derive" }
chalk-derive = { version = "0.26.0-dev.0", path = "../chalk-derive" }
2 changes: 1 addition & 1 deletion chalk-parse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk-parse"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
description = "Parser for the Chalk project"
license = "Apache-2.0/MIT"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand Down
8 changes: 4 additions & 4 deletions chalk-recursive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk-recursive"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
description = "Recursive solver for the Chalk project"
license = "Apache-2.0/MIT"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand All @@ -16,9 +16,9 @@ default = []
rustc-hash = { version = "1.1.0" }
tracing = "0.1"

chalk-derive = { version = "0.24.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.24.0-dev.0", path = "../chalk-ir" }
chalk-solve = { version = "0.24.0-dev.0", path = "../chalk-solve" }
chalk-derive = { version = "0.26.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.26.0-dev.0", path = "../chalk-ir" }
chalk-solve = { version = "0.26.0-dev.0", path = "../chalk-solve" }

[dev-dependencies]
chalk-integration = { path = "../chalk-integration" }
14 changes: 11 additions & 3 deletions chalk-recursive/src/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,17 @@ impl<'s, I: Interner, Solver: SolveDatabase<I>, Infer: RecursiveInferenceTable<I
solution,
} = self.prove(wc, minimums)?;

if solution.has_definite() {
if let Some(constrained_subst) =
solution.constrained_subst(self.interner())
if let Some(constrained_subst) = solution.definite_subst(self.interner()) {
// If the substitution is empty, we won't actually make any progress by applying it!
// So we need to check this to prevent endless loops.
// (An ambiguous solution with empty substitution
// can probably not happen in valid code, but it can
// happen e.g. when there are overlapping impls.)
if !constrained_subst.value.subst.is_empty(self.interner())
|| !constrained_subst
.value
.constraints
.is_empty(self.interner())
{
self.apply_solution(free_vars, universes, constrained_subst);
progress = true;
Expand Down
21 changes: 15 additions & 6 deletions chalk-recursive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,21 @@ impl<I: Interner> Solution<I> {
}

/// Determine whether this solution contains type information that *must*
/// hold.
pub(crate) fn has_definite(&self) -> bool {
match *self {
Solution::Unique(_) => true,
Solution::Ambig(Guidance::Definite(_)) => true,
_ => false,
/// hold, and returns the subst in that case.
pub(crate) fn definite_subst(&self, interner: &I) -> Option<Canonical<ConstrainedSubst<I>>> {
match self {
Solution::Unique(constrained) => Some(constrained.clone()),
Solution::Ambig(Guidance::Definite(canonical)) => {
let value = ConstrainedSubst {
subst: canonical.value.clone(),
constraints: Constraints::empty(interner),
};
Some(Canonical {
value,
binders: canonical.binders.clone(),
})
}
_ => None,
}
}

Expand Down
6 changes: 3 additions & 3 deletions chalk-solve/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chalk-solve"
version = "0.24.0-dev.0"
version = "0.26.0-dev.0"
description = "Combines the chalk-engine with chalk-ir"
license = "Apache-2.0/MIT"
authors = ["Rust Compiler Team", "Chalk developers"]
Expand All @@ -18,8 +18,8 @@ tracing-subscriber = { version = "0.2", optional = true }
tracing-tree = { version = "0.1.4", optional = true }
rustc-hash = { version = "1.1.0" }

chalk-derive = { version = "0.24.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.24.0-dev.0", path = "../chalk-ir" }
chalk-derive = { version = "0.26.0-dev.0", path = "../chalk-derive" }
chalk-ir = { version = "0.26.0-dev.0", path = "../chalk-ir" }

[dev-dependencies]
chalk-integration = { path = "../chalk-integration" }
Expand Down
32 changes: 32 additions & 0 deletions tests/test/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,3 +727,35 @@ fn canonicalization_regression() {
}
}
}

#[test]
fn empty_definite_guidance() {
test! {
disable_coherence;
program {
trait Trait<T> {}

struct S<'a> {}
struct A {}

impl<'a> Trait<S<'a>> for A {}
impl<'a> Trait<S<'a>> for A where A: 'a {}

trait OtherTrait<'a> {}
impl<'a> OtherTrait<'a> for A where A: Trait<S<'a>> {}
}

goal {
forall<'static> {
A: OtherTrait<'static>
}
// the program fails coherence, so which answer we get here exactly
// isn't that important -- this is mainly a regression test for a
// recursive solver infinite loop.
} yields[SolverChoice::slg_default()] {
"Unique"
} yields[SolverChoice::recursive()] {
"Ambiguous"
}
}
}
14 changes: 11 additions & 3 deletions tests/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ pub enum TestGoal {
macro_rules! test {
(program $program:tt $($goals:tt)*) => {{
let (program, goals) = parse_test_data!(program $program $($goals)*);
solve_goal(program, goals)
solve_goal(program, goals, true)
}};
(disable_coherence; program $program:tt $($goals:tt)*) => {{
let (program, goals) = parse_test_data!(program $program $($goals)*);
solve_goal(program, goals, false)
}};
}

Expand Down Expand Up @@ -215,7 +219,7 @@ macro_rules! parse_test_data {
};
}

fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>) {
fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>, coherence: bool) {
with_tracing_logs(|| {
println!("program {}", program_text);
assert!(program_text.starts_with("{"));
Expand All @@ -226,7 +230,11 @@ fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>) {
SolverChoice::default(),
);

let program = db.checked_program().unwrap();
let program = if coherence {
db.checked_program().unwrap()
} else {
db.program_ir().unwrap()
};

for (goal_text, solver_choice, expected) in goals {
match (&solver_choice, &expected) {
Expand Down

0 comments on commit 6a6a68f

Please sign in to comment.