Skip to content

Commit 6fd1808

Browse files
authored
Merge pull request #215 from detrumi/simplify-crate-structure
Simplify crate structure
2 parents eb1ed91 + e3b7e1e commit 6fd1808

18 files changed

+145
-185
lines changed

Cargo.lock

+5-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,4 @@ path = "chalk-engine"
4949
version = "0.1.0"
5050
path = "chalk-rust-ir"
5151

52-
[dependencies.chalk-rules]
53-
version = "0.1.0"
54-
path = "chalk-rules"
55-
5652
[workspace]

chalk-rules/Cargo.toml

-28
This file was deleted.

chalk-rules/src/lib.rs

-64
This file was deleted.

chalk-solve/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ keywords = ["compiler", "traits", "prolog"]
1010
edition = "2018"
1111

1212
[dependencies]
13+
derive-new = "0.5.6"
1314
ena = "0.10.1"
15+
failure = "0.1"
16+
itertools = "0.7.8"
17+
petgraph = "0.4.13"
1418

1519
[dependencies.chalk-macros]
1620
version = "0.1.0"
@@ -23,3 +27,7 @@ path = "../chalk-engine"
2327
[dependencies.chalk-ir]
2428
version = "0.1.0"
2529
path = "../chalk-ir"
30+
31+
[dependencies.chalk-rust-ir]
32+
version = "0.1.0"
33+
path = "../chalk-rust-ir"

chalk-rules/src/clauses.rs renamed to chalk-solve/src/clauses.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::RustIrSource;
1+
use crate::RustIrDatabase;
22
use chalk_ir::cast::{Cast, Caster};
33
use chalk_ir::fold::shift::Shift;
44
use chalk_ir::fold::Subst;
@@ -10,7 +10,7 @@ use std::iter;
1010
/// or struct definition) into its associated "program clauses" --
1111
/// that is, into the lowered, logical rules that it defines.
1212
pub trait ToProgramClauses {
13-
fn to_program_clauses(&self, program: &dyn RustIrSource, clauses: &mut Vec<ProgramClause>);
13+
fn to_program_clauses(&self, program: &dyn RustIrDatabase, clauses: &mut Vec<ProgramClause>);
1414
}
1515

1616
impl ToProgramClauses for ImplDatum {
@@ -22,7 +22,7 @@ impl ToProgramClauses for ImplDatum {
2222
/// Implemented(Vec<T>: Clone) :- Implemented(T: Clone).
2323
/// }
2424
/// ```
25-
fn to_program_clauses(&self, _program: &dyn RustIrSource, clauses: &mut Vec<ProgramClause>) {
25+
fn to_program_clauses(&self, _program: &dyn RustIrDatabase, clauses: &mut Vec<ProgramClause>) {
2626
clauses.push(
2727
self.binders
2828
.map_ref(|bound| ProgramClauseImplication {
@@ -69,7 +69,7 @@ pub fn push_auto_trait_impls(
6969
auto_trait: &TraitDatum,
7070
struct_id: StructId,
7171
struct_datum: &StructDatum,
72-
program: &dyn RustIrSource,
72+
program: &dyn RustIrDatabase,
7373
vec: &mut Vec<ProgramClause>,
7474
) {
7575
// Must be an auto trait.
@@ -153,7 +153,7 @@ impl ToProgramClauses for AssociatedTyValue {
153153
/// Normalize(<Vec<T> as Iterable>::IntoIter<'a> -> Iter<'a, T>).
154154
/// }
155155
/// ```
156-
fn to_program_clauses(&self, program: &dyn RustIrSource, clauses: &mut Vec<ProgramClause>) {
156+
fn to_program_clauses(&self, program: &dyn RustIrDatabase, clauses: &mut Vec<ProgramClause>) {
157157
let impl_datum = program.impl_datum(self.impl_id);
158158
let associated_ty = program.associated_ty_data(self.associated_ty_id);
159159

@@ -309,7 +309,7 @@ impl ToProgramClauses for StructDatum {
309309
/// forall<T> { DownstreamType(Box<T>) :- DownstreamType(T). }
310310
/// ```
311311
///
312-
fn to_program_clauses(&self, _program: &dyn RustIrSource, clauses: &mut Vec<ProgramClause>) {
312+
fn to_program_clauses(&self, _program: &dyn RustIrDatabase, clauses: &mut Vec<ProgramClause>) {
313313
let wf = self
314314
.binders
315315
.map_ref(|bound_datum| ProgramClauseImplication {
@@ -552,7 +552,7 @@ impl ToProgramClauses for TraitDatum {
552552
/// To implement fundamental traits, we simply just do not add the rule above that allows
553553
/// upstream types to implement upstream traits. Fundamental traits are not allowed to
554554
/// compatibly do that.
555-
fn to_program_clauses(&self, _program: &dyn RustIrSource, clauses: &mut Vec<ProgramClause>) {
555+
fn to_program_clauses(&self, _program: &dyn RustIrDatabase, clauses: &mut Vec<ProgramClause>) {
556556
let trait_ref = self.binders.value.trait_ref.clone();
557557

558558
let trait_ref_impl = WhereClause::Implemented(self.binders.value.trait_ref.clone());
@@ -777,7 +777,7 @@ impl ToProgramClauses for AssociatedTyDatum {
777777
/// FromEnv(Self: Foo) :- FromEnv((Foo::Assoc)<Self, 'a,T>).
778778
/// }
779779
/// ```
780-
fn to_program_clauses(&self, program: &dyn RustIrSource, clauses: &mut Vec<ProgramClause>) {
780+
fn to_program_clauses(&self, program: &dyn RustIrDatabase, clauses: &mut Vec<ProgramClause>) {
781781
let binders: Vec<_> = self
782782
.parameter_kinds
783783
.iter()

chalk-rules/src/coherence.rs renamed to chalk-solve/src/coherence.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use petgraph::prelude::*;
22

3-
use crate::ChalkRulesDatabase;
3+
use crate::solve::SolverChoice;
4+
use crate::ChalkSolveDatabase;
45
use chalk_ir::{self, Identifier, ImplId, TraitId};
56
use derive_new::new;
67
use failure::Fallible;
@@ -13,9 +14,10 @@ mod solve;
1314
#[derive(new)]
1415
pub struct CoherenceSolver<'db, DB>
1516
where
16-
DB: ChalkRulesDatabase,
17+
DB: ChalkSolveDatabase,
1718
{
1819
db: &'db DB,
20+
solver_choice: SolverChoice,
1921
trait_id: TraitId,
2022
}
2123

@@ -56,7 +58,7 @@ pub struct SpecializationPriority(usize);
5658

5759
impl<'db, DB> CoherenceSolver<'db, DB>
5860
where
59-
DB: ChalkRulesDatabase,
61+
DB: ChalkSolveDatabase,
6062
{
6163
pub fn specialization_priorities(&self) -> Fallible<Arc<SpecializationPriorities>> {
6264
let mut result = SpecializationPriorities::default();

chalk-rules/src/coherence/orphan.rs renamed to chalk-solve/src/coherence/orphan.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::coherence::CoherenceError;
2-
use crate::ChalkRulesDatabase;
2+
use crate::ext::GoalExt;
3+
use crate::solve::SolverChoice;
4+
use crate::ChalkSolveDatabase;
35
use chalk_ir::cast::*;
46
use chalk_ir::*;
5-
use chalk_solve::ext::*;
67
use failure::Fallible;
78

89
// Test if a local impl violates the orphan rules.
@@ -12,10 +13,11 @@ use failure::Fallible;
1213
// forall<T> { LocalImplAllowed(MyType<T>: Trait) }
1314
//
1415
// This must be provable in order to pass the orphan check.
15-
pub fn perform_orphan_check<DB>(db: &DB, impl_id: ImplId) -> Fallible<()>
16-
where
17-
DB: ChalkRulesDatabase,
18-
{
16+
pub fn perform_orphan_check(
17+
db: &dyn ChalkSolveDatabase,
18+
solver_choice: SolverChoice,
19+
impl_id: ImplId,
20+
) -> Fallible<()> {
1921
debug_heading!("orphan_check(impl={:#?})", impl_id);
2022

2123
let impl_datum = db.impl_datum(impl_id);
@@ -30,7 +32,10 @@ where
3032
.cast();
3133

3234
let canonical_goal = &impl_allowed.into_closed_goal();
33-
let is_allowed = db.solve(canonical_goal).is_some();
35+
let is_allowed = solver_choice
36+
.into_solver()
37+
.solve(db, canonical_goal)
38+
.is_some();
3439
debug!("overlaps = {:?}", is_allowed);
3540

3641
if !is_allowed {

chalk-rules/src/coherence/solve.rs renamed to chalk-solve/src/coherence/solve.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use crate::coherence::{CoherenceError, CoherenceSolver};
2-
use crate::ChalkRulesDatabase;
2+
use crate::ext::*;
3+
use crate::ChalkSolveDatabase;
4+
use crate::Solution;
35
use chalk_ir::cast::*;
46
use chalk_ir::fold::shift::Shift;
57
use chalk_ir::*;
68
use chalk_rust_ir::*;
7-
use chalk_solve::ext::*;
8-
use chalk_solve::Solution;
99
use failure::Fallible;
1010
use itertools::Itertools;
1111

1212
impl<'db, DB> CoherenceSolver<'db, DB>
1313
where
14-
DB: ChalkRulesDatabase,
14+
DB: ChalkSolveDatabase,
1515
{
1616
pub(super) fn visit_specializations_of_trait(
1717
&self,
@@ -135,7 +135,10 @@ where
135135
.negate();
136136

137137
let canonical_goal = &goal.into_closed_goal();
138-
let solution = self.db.solve(canonical_goal);
138+
let solution = self
139+
.solver_choice
140+
.into_solver()
141+
.solve(self.db, canonical_goal);
139142
let result = match solution {
140143
// Goal was proven with a unique solution, so no impl was found that causes these two
141144
// to overlap
@@ -214,7 +217,11 @@ where
214217
.quantify(QuantifierKind::ForAll, more_special.binders.binders.clone());
215218

216219
let canonical_goal = &goal.into_closed_goal();
217-
let result = match self.db.solve(canonical_goal) {
220+
let result = match self
221+
.solver_choice
222+
.into_solver()
223+
.solve(self.db, canonical_goal)
224+
{
218225
Some(sol) => sol.is_unique(),
219226
None => false,
220227
};

chalk-solve/src/coinductive_goal.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ impl IsCoinductive for Goal {
1717
fn is_coinductive(&self, db: &dyn ChalkSolveDatabase) -> bool {
1818
match self {
1919
Goal::Leaf(LeafGoal::DomainGoal(DomainGoal::Holds(wca))) => match wca {
20-
WhereClause::Implemented(tr) => db.is_coinductive_trait(tr.trait_id),
20+
WhereClause::Implemented(tr) => {
21+
db.trait_datum(tr.trait_id).binders.value.flags.auto
22+
}
2123
WhereClause::ProjectionEq(..) => false,
2224
},
2325
Goal::Leaf(LeafGoal::DomainGoal(DomainGoal::WellFormed(WellFormed::Trait(..)))) => true,

0 commit comments

Comments
 (0)