Skip to content

move universes from environment into the inference table #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
94e6b28
stop instantating clause for no reason
nikomatsakis Nov 30, 2017
0b510d0
rustfmt
nikomatsakis Nov 30, 2017
4f8c24c
debug impls
nikomatsakis Dec 21, 2017
19d6e05
generalize instantiate internals to use `Parameter`
nikomatsakis Dec 21, 2017
fcac7cb
authorize universal_impl_trait
nikomatsakis Dec 22, 2017
945ead6
stop the `pub use` pattern in `unify`
nikomatsakis Dec 22, 2017
cd564a4
use `fresh_subst` in recursive solver, make `instantiate` private
nikomatsakis Jan 3, 2018
005c64d
rename `instantiate_with_subst` to `substitute`
nikomatsakis Jan 3, 2018
c1fc3ce
rename `subst` to `substitute`
nikomatsakis Jan 3, 2018
9e82528
rename `instantiate` module to `subst`
nikomatsakis Jan 3, 2018
d7aa689
replace `FullyReducedGoal` with `Canonical<InEnvironment<LeafGoal>>`
nikomatsakis Jan 3, 2018
177ca69
rename `Fulfill` methods to indicate they are only for initial goal
nikomatsakis Jan 6, 2018
4294006
introduce `u_canonicalize`
nikomatsakis Jan 3, 2018
8208241
canonical universes in recursive solver
nikomatsakis Jan 4, 2018
7772984
add a test for universe overflow
nikomatsakis Jan 4, 2018
5bb487d
move `instantiate_universally` to be method on `InferenceTable`
nikomatsakis Jan 4, 2018
591d95c
when lifetimes have been unified with X, apply occurs check to X
nikomatsakis Jan 8, 2018
c5234fd
make recursive solver work on goals, like SLG solver
nikomatsakis Jan 8, 2018
f539efc
move unification into `Fulfill::push_goal`
nikomatsakis Jan 8, 2018
f4b910f
move universe from environment to inference table
nikomatsakis Jan 7, 2018
110a071
enable the `overflow_universe` test, which works now
nikomatsakis Jan 16, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.lock

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

44 changes: 24 additions & 20 deletions src/bin/chalki.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![feature(match_default_bindings)]

extern crate rustyline;
extern crate chalk_parse;
extern crate chalk;
extern crate chalk_parse;
extern crate docopt;
extern crate rustyline;

#[macro_use]
extern crate serde_derive;
Expand Down Expand Up @@ -136,7 +136,8 @@ fn run() -> Result<()> {

/// Repeatedly calls `f`, passing in each line, using the given promt, until EOF is received
fn readline_loop<F>(rl: &mut rustyline::Editor<()>, prompt: &str, mut f: F) -> Result<()>
where F: FnMut(&mut rustyline::Editor<()>, &str)
where
F: FnMut(&mut rustyline::Editor<()>, &str),
{
loop {
match rl.readline(prompt) {
Expand All @@ -153,11 +154,12 @@ fn readline_loop<F>(rl: &mut rustyline::Editor<()>, prompt: &str, mut f: F) -> R
}

/// Process a single command
fn process(args: &Args,
command: &str,
rl: &mut rustyline::Editor<()>,
prog: &mut Option<Program>)
-> Result<()> {
fn process(
args: &Args,
command: &str,
rl: &mut rustyline::Editor<()>,
prog: &mut Option<Program>,
) -> Result<()> {
if command == "help" {
help()
} else if command == "program" {
Expand Down Expand Up @@ -211,24 +213,26 @@ fn goal(args: &Args, text: &str, prog: &Program) -> Result<()> {
let peeled_goal = goal.into_peeled_goal();
if args.flag_slg && args.flag_all_answers {
match slg::solve_root_goal(args.flag_overflow_depth, &prog.env, &peeled_goal) {
Ok(slg::Answers { answers }) => {
if answers.is_empty() {
println!("No answers found.");
} else {
println!("{} answer(s) found:", answers.len());
for answer in &answers {
println!("- {}{}",
answer.subst,
if answer.ambiguous { " [ambiguous]" } else { "" });
}
Ok(slg::Answers { answers }) => if answers.is_empty() {
println!("No answers found.");
} else {
println!("{} answer(s) found:", answers.len());
for answer in &answers {
println!(
"- {}{}",
answer.subst,
if answer.ambiguous { " [ambiguous]" } else { "" }
);
}
}
},
Err(error) => {
println!("exploration error: {:?}\n", error);
}
}
} else {
match args.solver_choice().solve_root_goal(&prog.env, &peeled_goal) {
match args.solver_choice()
.solve_root_goal(&prog.env, &peeled_goal)
{
Ok(Some(v)) => println!("{}\n", v),
Ok(None) => println!("No possible solution.\n"),
Err(e) => println!("Solver failed: {}", e),
Expand Down
13 changes: 9 additions & 4 deletions src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ map_impl!(impl[T: Cast<U>, U] Cast<InEnvironment<U>> for InEnvironment<T>);
map_impl!(impl[T: Cast<U>, U, E] Cast<Result<U, E>> for Result<T, E>);

impl<T, U> Cast<Canonical<U>> for Canonical<T>
where T: Cast<U>
where
T: Cast<U>,
{
fn cast(self) -> Canonical<U> {
// Subtle point: It should be ok to re-use the binders here,
Expand All @@ -192,13 +193,14 @@ impl<T, U> Cast<Canonical<U>> for Canonical<T>
// with. It just introduces new wrapper types.
Canonical {
value: self.value.cast(),
binders: self.binders
binders: self.binders,
}
}
}

impl<T, U> Cast<Vec<U>> for Vec<T>
where T: Cast<U>
where
T: Cast<U>,
{
fn cast(self) -> Vec<U> {
self.into_iter().casted().collect()
Expand All @@ -210,7 +212,10 @@ pub struct Casted<I, U> {
_cast: PhantomData<U>,
}

impl<I: Iterator, U> Iterator for Casted<I, U> where I::Item: Cast<U> {
impl<I: Iterator, U> Iterator for Casted<I, U>
where
I::Item: Cast<U>,
{
type Item = U;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
16 changes: 11 additions & 5 deletions src/coherence/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use petgraph::prelude::*;

use errors::Result;
use ir::{self, Program, ItemId};
use ir::{self, ItemId, Program};
use solve::SolverChoice;
use std::sync::Arc;

Expand All @@ -24,7 +24,10 @@ impl Program {
}

// Build the forest of specialization relationships.
fn build_specialization_forest(&self, solver_choice: SolverChoice) -> Result<Graph<ItemId, ()>> {
fn build_specialization_forest(
&self,
solver_choice: SolverChoice,
) -> Result<Graph<ItemId, ()>> {
// The forest is returned as a graph but built as a GraphMap; this is
// so that we never add multiple nodes with the same ItemId.
let mut forest = DiGraphMap::new();
Expand All @@ -41,11 +44,14 @@ impl Program {

// Recursively set priorities for those node and all of its children.
fn set_priorities(&mut self, idx: NodeIndex, forest: &Graph<ItemId, ()>, p: usize) {

// Get the impl datum recorded at this node and reset its priority
{
let impl_id = forest.node_weight(idx).expect("index should be a valid index into graph");
let impl_datum = self.impl_data.get_mut(impl_id).expect("node should be valid impl id");
let impl_id = forest
.node_weight(idx)
.expect("index should be a valid index into graph");
let impl_datum = self.impl_data
.get_mut(impl_id)
.expect("node should be valid impl id");
impl_datum.binders.value.specialization_priority = p;
}

Expand Down
1 change: 0 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ error_chain! {
}
}
}

98 changes: 0 additions & 98 deletions src/fold/instantiate.rs

This file was deleted.

37 changes: 23 additions & 14 deletions src/fold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use ir::*;
use std::fmt::Debug;
use std::sync::Arc;

mod instantiate;
mod shifted;
mod shifter;
mod subst;

pub use self::shifted::Shifted;
pub use self::shifter::Shifter;
pub use self::instantiate::Subst;
pub use self::subst::Subst;

/// A "folder" is a transformer that can be used to make a copy of
/// some term -- that is, some bit of IR, such as a `Goal` -- with
Expand Down Expand Up @@ -105,7 +105,11 @@ pub trait ExistentialFolder {
fn fold_free_existential_ty(&mut self, depth: usize, binders: usize) -> Fallible<Ty>;

/// As `fold_free_existential_ty`, but for lifetimes.
fn fold_free_existential_lifetime(&mut self, depth: usize, binders: usize) -> Fallible<Lifetime>;
fn fold_free_existential_lifetime(
&mut self,
depth: usize,
binders: usize,
) -> Fallible<Lifetime>;
}

/// A convenience trait. If you implement this, you get an
Expand All @@ -118,7 +122,11 @@ impl<T: IdentityExistentialFolder> ExistentialFolder for T {
Ok(Ty::Var(depth + binders))
}

fn fold_free_existential_lifetime(&mut self, depth: usize, binders: usize) -> Fallible<Lifetime> {
fn fold_free_existential_lifetime(
&mut self,
depth: usize,
binders: usize,
) -> Fallible<Lifetime> {
Ok(Lifetime::Var(depth + binders))
}
}
Expand Down Expand Up @@ -268,7 +276,9 @@ pub fn super_fold_ty(folder: &mut Folder, ty: &Ty, binders: usize) -> Fallible<T
}
}
Ty::Projection(ref proj) => Ok(Ty::Projection(proj.fold_with(folder, binders)?)),
Ty::UnselectedProjection(ref proj) => Ok(Ty::UnselectedProjection(proj.fold_with(folder, binders)?)),
Ty::UnselectedProjection(ref proj) => {
Ok(Ty::UnselectedProjection(proj.fold_with(folder, binders)?))
}
Ty::ForAll(ref quantified_ty) => Ok(Ty::ForAll(quantified_ty.fold_with(folder, binders)?)),
}
}
Expand Down Expand Up @@ -349,13 +359,12 @@ impl Fold for Substitution {
type Result = Substitution;
fn fold_with(&self, folder: &mut Folder, binders: usize) -> Fallible<Self::Result> {
// Do not fold the keys of the substitution, just the values.
let parameters =
self.parameters.iter()
.map(|(&key, value)| {
value.fold_with(folder, binders)
.map(|value| (key, value))
})
.collect::<Fallible<_>>()?;
let parameters = self.parameters
.iter()
.map(|(&key, value)| {
value.fold_with(folder, binders).map(|value| (key, value))
})
.collect::<Fallible<_>>()?;
Ok(Substitution { parameters })
}
}
Expand Down Expand Up @@ -433,7 +442,7 @@ struct_fold!(ProjectionTy {
});
struct_fold!(UnselectedProjectionTy {
type_name,
parameters
parameters,
});
struct_fold!(TraitRef {
trait_id,
Expand All @@ -446,7 +455,7 @@ struct_fold!(AssociatedTyValue {
value,
});
struct_fold!(AssociatedTyValueBound { ty, where_clauses });
struct_fold!(Environment { universe, clauses });
struct_fold!(Environment { clauses });
struct_fold!(InEnvironment[F] { environment, goal } where F: Fold);
struct_fold!(EqGoal { a, b });
struct_fold!(ProgramClauseImplication {
Expand Down
3 changes: 0 additions & 3 deletions src/fold/shifted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,3 @@ impl<T: Fold<Result = T>> Fold for Shifted<T> {
value.fold_with(folder, binders)
}
}



Loading