Skip to content

Commit 1f9c529

Browse files
authored
Merge pull request #459 from Mcat12/cleanup/reorganize-crates
Cleanup crate structure and add features for SLG/recursive solvers
2 parents 0f195ad + 849a295 commit 1f9c529

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+194
-175
lines changed

Cargo.lock

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

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ salsa = "0.10.0"
2121
serde = "1.0"
2222
serde_derive = "1.0"
2323

24-
chalk-macros = { version = "0.10.1-dev", path = "chalk-macros" }
24+
chalk-base = { version = "0.10.1-dev", path = "chalk-base" }
2525
chalk-derive = { version = "0.10.1-dev", path = "chalk-derive" }
2626
chalk-engine = { version = "0.10.1-dev", path = "chalk-engine" }
2727
chalk-ir = { version = "0.10.1-dev", path = "chalk-ir" }
28-
chalk-rust-ir = { version = "0.10.1-dev", path = "chalk-rust-ir" }
2928
chalk-solve = { version = "0.10.1-dev", path = "chalk-solve" }
3029
chalk-parse = { version = "0.10.1-dev", path = "chalk-parse" }
3130
chalk-integration = { version = "0.10.1-dev", path = "chalk-integration" }

book/src/publishing.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
**Note: this is mostly only useful for maintainers**
44

55
The following crates get published to crates.io:
6-
- `chalk-macros`
6+
- `chalk-base`
77
- `chalk-derive`
88
- `chalk-engine`
99
- `chalk-ir`
10-
- `chalk-rust-ir`
1110
- `chalk-solve`
1211

1312
The following crates get versioned without publishing:

book/src/what_is_chalk/crates.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ role of each crate. This crate structure helps to serve Chalk's two goals:
1111
The following crates are "public facing" crates that you may use when embedding chalk into
1212
other programs:
1313

14-
* The `chalk-solve` crate, which defines the rules that translate Rust IR into logical predicates.
14+
* The `chalk-solve` crate, which defines the IR representing Rust concepts like
15+
traits and impls and the rules that translate Rust IR into logical predicates.
1516
* The `chalk-ir` crate, which defines the IR representing types and logical predicates.
16-
* The `chalk-rust-ir` crate, which defines the IR representing Rust concepts like traits and impls.
1717

1818
The following crate is an implementation detail, used internally by `chalk-solve`:
1919

2020
* The `chalk-engine` crate, which defines the actual engine that solves logical predicate. This
2121
engine is quite general and not really specific to Rust.
2222
* The `chalk-derive` crate defines custom derives for the `chalk_ir::fold::Fold` trait and other
2323
such things.
24-
* The `chalk-macros` crate defines a few miscellaneous utility macros.
24+
* The `chalk-base` crate defines some base solver types and a few miscellaneous
25+
utility macros.
2526

2627
## Crates for standalone REPL and testing
2728

@@ -30,9 +31,9 @@ harness. These crates build on the crates above. Essentially, they
3031
define a kind of "minimal embedding" of chalk.
3132

3233
* The `chalk-parser` crate can parse Rust syntax to product an AST.
33-
* The `chalk-integration` crate can take that AST and use it to drive
34-
the `chalk-solve` crate above. The AST is converted into
35-
`chalk-rust-ir` by a process called "lowering'.
34+
* The `chalk-integration` crate can take that AST and use it to drive the
35+
`chalk-solve` crate above. The AST is converted into Rust IR by a process
36+
called "lowering'.
3637
* Finally, the main `chalk` crate, along with the testing crate in the
3738
`tests` directory, define the actual entry points.
3839

book/src/what_is_chalk/walkthrough.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ impls, and struct definitions. Parsing is often the first "phase" of
4444
transformation that a program goes through in order to become a format that
4545
chalk can understand.
4646

47-
### Rust Intermediate Representation ([chalk_rust_ir])
47+
### Rust Intermediate Representation ([chalk_solve::rust_ir])
4848

4949
After getting the AST we convert it to a more convenient intermediate
50-
representation called [`chalk_rust_ir`][chalk_rust_ir]. This is sort of
50+
representation called `chalk_rust_ir`. This is sort of
5151
analogous to the [HIR] in Rust. The process of converting to IR is called
5252
*lowering*.
5353

@@ -133,12 +133,12 @@ queries is called the *solver*.
133133

134134
Chalk's functionality is broken up into the following crates:
135135
- [**chalk_engine**][chalk_engine]: Defines the core [SLG solver][slg].
136-
- [**chalk_rust_ir**][chalk_rust_ir], containing the "HIR-like" form of the AST
137136
- [**chalk_ir**][chalk_ir]: Defines chalk's internal representation of
138137
types, lifetimes, and goals.
139138
- [**chalk_solve**][chalk_solve]: Combines `chalk_ir` and `chalk_engine`,
140139
effectively, which implements logic rules converting `chalk_rust_ir` to
141140
`chalk_ir`
141+
- Contains the `rust_ir` module, which defines the "HIR-like" Rust IR
142142
- Defines the `coherence` module, which implements coherence rules
143143
- [`chalk_engine::context`][engine-context] provides the necessary hooks.
144144
- [**chalk_parse**][chalk_parse]: Defines the raw AST and a parser.
@@ -197,7 +197,7 @@ Likewise, lowering tests use the [`lowering_success!` and
197197
[chalk_ir]: https://rust-lang.github.io/chalk/chalk_ir/index.html
198198
[chalk_parse]: https://rust-lang.github.io/chalk/chalk_parse/index.html
199199
[chalk_solve]: https://rust-lang.github.io/chalk/chalk_solve/index.html
200-
[chalk_rust_ir]: https://rust-lang.github.io/chalk/chalk_rust_ir/index.html
200+
[chalk_solve::rust_ir]: https://rust-lang.github.io/chalk/chalk_solve/rust_ir/index.html
201201
[doc-chalk]: https://rust-lang.github.io/chalk/chalk/index.html
202202
[engine-context]: https://rust-lang.github.io/chalk/chalk_engine/context/index.html
203203
[chalk-program]: https://rust-lang.github.io/chalk/chalk_integration/program/struct.Program.html
@@ -211,7 +211,7 @@ Likewise, lowering tests use the [`lowering_success!` and
211211
[chalki]: https://github.com/rust-lang/chalk/blob/master/src/main.rs
212212
[clause]: https://github.com/rust-lang/chalk/blob/master/GLOSSARY.md#clause
213213
[coherence-src]: https://rust-lang.github.io/chalk/chalk_solve/coherence/index.html
214-
[ir-code]: https://rust-lang.github.io/chalk/chalk_rust_ir/
214+
[ir-code]: https://rust-lang.github.io/chalk/chalk_solve/rust_ir/
215215
[solve-wf-src]: https://rust-lang.github.io/chalk/chalk_solve/wf/index.html
216216
[solve_goal]: https://github.com/rust-lang/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test.rs#L85
217217
[test-lowering-macros]: https://github.com/rust-lang/chalk/blob/4bce000801de31bf45c02f742a5fce335c9f035f/src/test_util.rs#L21-L54

chalk-macros/Cargo.toml renamed to chalk-base/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
2-
name = "chalk-macros"
2+
name = "chalk-base"
33
version = "0.10.1-dev"
4-
description = "Macros for Chalk"
4+
description = "Base types for Chalk logic engines"
55
license = "Apache-2.0/MIT"
66
authors = ["Rust Compiler Team", "Chalk developers"]
77
repository = "https://github.com/rust-lang/chalk"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Various macros used within Chalk.
1+
Base types used by the SLG and recursive solvers.
22

33
See [Github](https://github.com/rust-lang/chalk) for up-to-date information.

chalk-base/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[macro_use]
2+
extern crate lazy_static;
3+
4+
#[macro_use]
5+
mod macros;
6+
pub mod results;
7+
8+
pub use macros::*;
File renamed without changes.

chalk-macros/src/lib.rs renamed to chalk-base/src/macros/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use std::cell::RefCell;
22

3-
#[macro_use]
4-
extern crate lazy_static;
5-
6-
#[macro_use]
73
mod index;
84

95
lazy_static! {

chalk-engine/src/fallible.rs renamed to chalk-base/src/results.rs

+5
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ pub type Fallible<T> = Result<T, NoSolution>;
66
/// cannot be performed.
77
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
88
pub struct NoSolution;
9+
10+
/// Error type for the `UnificationOps::program_clauses` method --
11+
/// indicates that the complete set of program clauses for this goal
12+
/// cannot be enumerated.
13+
pub struct Floundered;

chalk-derive/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ fn derive_zip(mut s: synstructure::Structure) -> TokenStream {
235235
});
236236

237237
// when the two variants are different
238-
quote!((_, _) => Err(::chalk_engine::fallible::NoSolution)).to_tokens(&mut body);
238+
quote!((_, _) => Err(::chalk_base::results::NoSolution)).to_tokens(&mut body);
239239

240240
s.add_bounds(synstructure::AddBounds::None);
241241
s.bound_impl(
@@ -246,7 +246,7 @@ fn derive_zip(mut s: synstructure::Structure) -> TokenStream {
246246
zipper: &mut Z,
247247
a: &Self,
248248
b: &Self,
249-
) -> ::chalk_engine::fallible::Fallible<()>
249+
) -> ::chalk_base::results::Fallible<()>
250250
where
251251
#interner: 'i,
252252
{
@@ -316,7 +316,7 @@ fn derive_fold(mut s: synstructure::Structure) -> TokenStream {
316316
&self,
317317
folder: &mut dyn ::chalk_ir::fold::Folder < 'i, #interner, #target_interner >,
318318
outer_binder: ::chalk_ir::DebruijnIndex,
319-
) -> ::chalk_engine::fallible::Fallible<Self::Result>
319+
) -> ::chalk_base::results::Fallible<Self::Result>
320320
where
321321
#interner: 'i,
322322
#target_interner: 'i,

chalk-engine/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ default = []
1515
[dependencies]
1616
rustc-hash = { version = "1.1.0" }
1717

18-
chalk-macros = { version = "0.10.1-dev", path = "../chalk-macros" }
18+
chalk-base = { version = "0.10.1-dev", path = "../chalk-base" }

chalk-engine/src/context.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//! `DomainGoal` type, add arena lifetime parameters, and more. See
66
//! [`Context`] trait for a list of types.
77
8-
use crate::fallible::Fallible;
98
use crate::hh::HhGoal;
109
use crate::{CompleteAnswer, ExClause};
10+
use chalk_base::results::{Fallible, Floundered};
1111
use std::fmt::Debug;
1212
use std::hash::Hash;
1313

@@ -282,11 +282,6 @@ pub trait AggregateOps<C: Context> {
282282
/// other operations on terms.
283283
pub trait InferenceTable<C: Context>: ResolventOps<C> + TruncateOps<C> + UnificationOps<C> {}
284284

285-
/// Error type for the `UnificationOps::program_clauses` method --
286-
/// indicates that the complete set of program clauses for this goal
287-
/// cannot be enumerated.
288-
pub struct Floundered;
289-
290285
/// Methods for unifying and manipulating terms and binders.
291286
pub trait UnificationOps<C: Context> {
292287
// Used by: simplify

chalk-engine/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@
5454
//! Popularized by Lambda Prolog.
5555
5656
#[macro_use]
57-
extern crate chalk_macros;
57+
extern crate chalk_base;
5858

5959
use crate::context::Context;
6060
use std::cmp::min;
6161
use std::usize;
6262

6363
pub mod context;
6464
mod derived;
65-
pub mod fallible;
6665
pub mod forest;
6766
pub mod hh;
6867
mod logic;

chalk-engine/src/logic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::context::{
2-
Context, ContextOps, Floundered, InferenceTable, ResolventOps, TruncateOps, UnificationOps,
2+
Context, ContextOps, InferenceTable, ResolventOps, TruncateOps, UnificationOps,
33
};
4-
use crate::fallible::NoSolution;
54
use crate::forest::Forest;
65
use crate::hh::HhGoal;
76
use crate::stack::{Stack, StackIndex};
@@ -10,6 +9,7 @@ use crate::table::{AnswerIndex, Table};
109
use crate::{
1110
Answer, CompleteAnswer, ExClause, FlounderedSubgoal, Literal, Minimums, TableIndex, TimeStamp,
1211
};
12+
use chalk_base::results::{Floundered, NoSolution};
1313

1414
type RootSearchResult<T> = Result<T, RootSearchFail>;
1515

chalk-engine/src/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::context::{Context, ContextOps, InferenceTable};
2-
use crate::fallible::Fallible;
32
use crate::forest::Forest;
43
use crate::hh::HhGoal;
54
use crate::{ExClause, Literal, TimeStamp};
5+
use chalk_base::results::Fallible;
66

77
impl<C: Context> Forest<C> {
88
/// Simplifies an HH goal into a series of positive domain goals

chalk-integration/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ publish = false
1313
string_cache = "0.8.0"
1414
salsa = "0.10.0"
1515

16-
chalk-macros = { version = "0.10.1-dev", path = "../chalk-macros" }
16+
chalk-base = { version = "0.10.1-dev", path = "../chalk-base" }
1717
chalk-derive = { version = "0.10.1-dev", path = "../chalk-derive" }
1818
chalk-engine = { version = "0.10.1-dev", path = "../chalk-engine" }
1919
chalk-ir = { version = "0.10.1-dev", path = "../chalk-ir" }
20-
chalk-rust-ir = { version = "0.10.1-dev", path = "../chalk-rust-ir" }
2120
chalk-solve = { version = "0.10.1-dev", path = "../chalk-solve" }
2221
chalk-parse = { version = "0.10.1-dev", path = "../chalk-parse" }

0 commit comments

Comments
 (0)