-
Notifications
You must be signed in to change notification settings - Fork 184
Migrate Vec<ParameterKinds<()>>
and Vec<ParameterKinds<UniverseIndex>>
to interned
#386
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
+719
−225
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f369cd1
Add interning for parameter kinds.
crlf0710 2b0f5bb
Add wrappers.
crlf0710 02d1033
Switch `Vec<ParameterKind<UniverseIndex>>` to `ParameterKindsWithUniv…
crlf0710 761d360
Switch `Vec<ParameterKind<()>>` to `ParameterKinds<I>`.
crlf0710 1d1be29
Rename ParameterKindsWithUniverseIndex to CanonicalVarKinds
crlf0710 40369a2
Pass interner to IntoBindersAndValue trait associated fn.
crlf0710 557966e
Some fixes after rebase.
crlf0710 5f76ce4
nit: fix comment
nikomatsakis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use chalk_ir::fold::*; | ||
use chalk_ir::interner::HasInterner; | ||
use std::fmt::Debug; | ||
|
||
use super::*; | ||
|
@@ -30,9 +31,9 @@ impl<I: Interner> InferenceTable<I> { | |
bound: &Canonical<T>, | ||
) -> T::Result | ||
where | ||
T: Fold<I> + Debug, | ||
T: HasInterner<Interner = I> + Fold<I> + Debug, | ||
{ | ||
let subst = self.fresh_subst(interner, &bound.binders); | ||
let subst = self.fresh_subst(interner, &bound.binders.as_slice(interner)); | ||
subst.apply(&bound.value, interner) | ||
} | ||
|
||
|
@@ -61,28 +62,28 @@ impl<I: Interner> InferenceTable<I> { | |
} | ||
|
||
/// Variant on `instantiate_in` that takes a `Binders<T>`. | ||
pub(crate) fn instantiate_binders_existentially<T>( | ||
pub(crate) fn instantiate_binders_existentially<'a, T>( | ||
&mut self, | ||
interner: &I, | ||
arg: impl IntoBindersAndValue<Value = T>, | ||
interner: &'a I, | ||
arg: impl IntoBindersAndValue<'a, I, Value = T>, | ||
) -> T::Result | ||
where | ||
T: Fold<I>, | ||
{ | ||
let (binders, value) = arg.into_binders_and_value(); | ||
let (binders, value) = arg.into_binders_and_value(interner); | ||
let max_universe = self.max_universe; | ||
self.instantiate_in(interner, max_universe, binders, &value) | ||
} | ||
|
||
pub(crate) fn instantiate_binders_universally<T>( | ||
pub(crate) fn instantiate_binders_universally<'a, T>( | ||
&mut self, | ||
interner: &I, | ||
arg: impl IntoBindersAndValue<Value = T>, | ||
interner: &'a I, | ||
arg: impl IntoBindersAndValue<'a, I, Value = T>, | ||
) -> T::Result | ||
where | ||
T: Fold<I>, | ||
{ | ||
let (binders, value) = arg.into_binders_and_value(); | ||
let (binders, value) = arg.into_binders_and_value(interner); | ||
let ui = self.new_universe(); | ||
let parameters: Vec<_> = binders | ||
.into_iter() | ||
|
@@ -102,30 +103,34 @@ impl<I: Interner> InferenceTable<I> { | |
} | ||
} | ||
|
||
pub(crate) trait IntoBindersAndValue { | ||
pub(crate) trait IntoBindersAndValue<'a, I: Interner> { | ||
type Binders: IntoIterator<Item = ParameterKind<()>>; | ||
type Value; | ||
|
||
fn into_binders_and_value(self) -> (Self::Binders, Self::Value); | ||
fn into_binders_and_value(self, interner: &'a I) -> (Self::Binders, Self::Value); | ||
} | ||
|
||
impl<'a, T> IntoBindersAndValue for &'a Binders<T> { | ||
impl<'a, I, T> IntoBindersAndValue<'a, I> for &'a Binders<T> | ||
where | ||
I: Interner, | ||
T: HasInterner<Interner = I>, | ||
{ | ||
type Binders = std::iter::Cloned<std::slice::Iter<'a, ParameterKind<()>>>; | ||
type Value = &'a T; | ||
|
||
fn into_binders_and_value(self) -> (Self::Binders, Self::Value) { | ||
(self.binders.iter().cloned(), self.skip_binders()) | ||
fn into_binders_and_value(self, interner: &'a I) -> (Self::Binders, Self::Value) { | ||
(self.binders.iter(interner).cloned(), self.skip_binders()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see, it's because we actually return an interior here -- well, this seems ok. |
||
} | ||
} | ||
|
||
impl<'a, I> IntoBindersAndValue for &'a Fn<I> | ||
impl<'a, I> IntoBindersAndValue<'a, I> for &'a Fn<I> | ||
where | ||
I: Interner, | ||
{ | ||
type Binders = std::iter::Map<std::ops::Range<usize>, fn(usize) -> chalk_ir::ParameterKind<()>>; | ||
type Value = &'a Substitution<I>; | ||
|
||
fn into_binders_and_value(self) -> (Self::Binders, Self::Value) { | ||
fn into_binders_and_value(self, _interner: &'a I) -> (Self::Binders, Self::Value) { | ||
fn make_lifetime(_: usize) -> ParameterKind<()> { | ||
ParameterKind::Lifetime(()) | ||
} | ||
|
@@ -135,11 +140,11 @@ where | |
} | ||
} | ||
|
||
impl<'a, T> IntoBindersAndValue for (&'a Vec<ParameterKind<()>>, &'a T) { | ||
impl<'a, T, I: Interner> IntoBindersAndValue<'a, I> for (&'a Vec<ParameterKind<()>>, &'a T) { | ||
type Binders = std::iter::Cloned<std::slice::Iter<'a, ParameterKind<()>>>; | ||
type Value = &'a T; | ||
|
||
fn into_binders_and_value(self) -> (Self::Binders, Self::Value) { | ||
fn into_binders_and_value(self, _interner: &'a I) -> (Self::Binders, Self::Value) { | ||
(self.0.iter().cloned(), &self.1) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, this code doesn't seem like it's in the right place. ParameterKinds are just a list of, well, parameter kinds. They are not themselves a binder... Ah, well, I guess every time they are used, it's as part of a binder... ok, seems reasonable. 👍