-
Notifications
You must be signed in to change notification settings - Fork 181
intern "substitutions" #316
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
nikomatsakis
merged 6 commits into
rust-lang:master
from
nikomatsakis:cleanup-chalk-ir-no-vec-parameter
Jan 6, 2020
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57a2c7c
trait refs always have a self type parameter
nikomatsakis af61e50
improve the `self_type_parameter` helper
nikomatsakis bdb2c80
replace `Vec<Parameter<TF>>` with `Substition<TF>`
nikomatsakis 2042706
make `Substitution` fields private, remove `FromIterator` impl
nikomatsakis 234b855
intern the parameter list
nikomatsakis 68cec9c
fix nits from jackh726
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ use crate::tls; | |
| use crate::AssocTypeId; | ||
| use crate::GoalData; | ||
| use crate::LifetimeData; | ||
| use crate::Parameter; | ||
| use crate::ParameterData; | ||
| use crate::ProjectionTy; | ||
| use crate::RawId; | ||
|
|
@@ -68,6 +69,14 @@ pub trait TypeFamily: Debug + Copy + Eq + Ord + Hash { | |
| /// converted back to its underlying data via `goal_data`. | ||
| type InternedGoal: Debug + Clone + Eq + Ord + Hash; | ||
|
|
||
| /// "Interned" representation of a "substitution". In normal user code, | ||
| /// `Self::InternedSubstitution` is not referenced. Instead, we refer to | ||
| /// `Substitution<Self>`, which wraps this type. | ||
| /// | ||
| /// An `InternedSubstitution` is created by `intern_substitution` and can be | ||
| /// converted back to its underlying data via `substitution_data`. | ||
| type InternedSubstitution: Debug + Clone + Eq + Ord + Hash; | ||
|
|
||
| /// The core "id" type used for struct-ids and the like. | ||
| type DefId: Debug + Copy + Eq + Ord + Hash; | ||
|
|
||
|
|
@@ -146,8 +155,19 @@ pub trait TypeFamily: Debug + Copy + Eq + Ord + Hash { | |
| /// method). | ||
| fn intern_goal(data: GoalData<Self>) -> Self::InternedGoal; | ||
|
|
||
| /// Lookup the `GoalData` that was interned to create a `InternedGoal`. | ||
| /// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`. | ||
|
||
| fn goal_data(lifetime: &Self::InternedGoal) -> &GoalData<Self>; | ||
|
|
||
| /// Create an "interned" substitution from `data`. This is not | ||
| /// normally invoked directly; instead, you invoke | ||
| /// `SubstitutionData::intern` (which will ultimately call this | ||
| /// method). | ||
| fn intern_substitution<E>( | ||
| data: impl IntoIterator<Item = Result<Parameter<Self>, E>>, | ||
| ) -> Result<Self::InternedSubstitution, E>; | ||
|
|
||
| /// Lookup the `SubstitutionData` that was interned to create a `InternedSubstitution`. | ||
| fn substitution_data(lifetime: &Self::InternedSubstitution) -> &[Parameter<Self>]; | ||
| } | ||
|
|
||
| pub trait TargetTypeFamily<TF: TypeFamily>: TypeFamily { | ||
|
|
@@ -181,6 +201,7 @@ impl TypeFamily for ChalkIr { | |
| type InternedLifetime = LifetimeData<ChalkIr>; | ||
| type InternedParameter = ParameterData<ChalkIr>; | ||
| type InternedGoal = Arc<GoalData<ChalkIr>>; | ||
| type InternedSubstitution = Vec<Parameter<ChalkIr>>; | ||
| type DefId = RawId; | ||
|
|
||
| fn debug_struct_id( | ||
|
|
@@ -242,6 +263,16 @@ impl TypeFamily for ChalkIr { | |
| fn goal_data(goal: &Arc<GoalData<ChalkIr>>) -> &GoalData<ChalkIr> { | ||
| goal | ||
| } | ||
|
|
||
| fn intern_substitution<E>( | ||
| data: impl IntoIterator<Item = Result<Parameter<ChalkIr>, E>>, | ||
| ) -> Result<Vec<Parameter<ChalkIr>>, E> { | ||
| data.into_iter().collect() | ||
| } | ||
|
|
||
| fn substitution_data(substitution: &Vec<Parameter<ChalkIr>>) -> &[Parameter<ChalkIr>] { | ||
| substitution | ||
| } | ||
| } | ||
|
|
||
| impl HasTypeFamily for ChalkIr { | ||
|
|
||
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
Oops, something went wrong.
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.
Should this be
&self.substitution.with_angle()