-
Notifications
You must be signed in to change notification settings - Fork 181
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
Support const evaulation #596
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
eea70d6
Basic support for unevaluated const expressions
hayashi-stl 58fb4ff
Merge branch 'master' of https://github.com/josh65536/chalk
hayashi-stl e0748ad
Code formatting and unevaluated const formatting
hayashi-stl 69623ba
Fixed tests
hayashi-stl b4684d0
Added newline, deleted unnecessary try_eval functions
hayashi-stl f4cd784
Added comments on tests
hayashi-stl f2ca1db
Moved UnevaluatedConstData to chalk-integration
hayashi-stl d767d7e
Removed const_eq for unevaluated consts. Rip reflexivity for now.
hayashi-stl 6a6a68f
Merge branch 'master' of https://github.com/rust-lang/chalk
hayashi-stl 3389719
Fixed tests
hayashi-stl bce9291
Added newline, deleted unnecessary try_eval functions
hayashi-stl 0b603f9
Added comments on tests
hayashi-stl d4ee9a3
Moved UnevaluatedConstData to chalk-integration
hayashi-stl d05b66c
Removed const_eq for unevaluated consts. Rip reflexivity for now.
hayashi-stl 60da39c
Disabled coherence in failing test and fixed comments in coherence tests
hayashi-stl 1c38d7c
Oops, merge conflicts
hayashi-stl e048d93
Deduplicated some logic and fixed a test
hayashi-stl 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 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 |
---|---|---|
|
@@ -12,3 +12,4 @@ chalk-parse/src/parser.rs | |
|
||
## IDE files | ||
/.idea/ | ||
/.vscode/ |
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -33,7 +33,7 @@ use crate::Ty; | |
use crate::TyData; | ||
use crate::VariableKind; | ||
use crate::VariableKinds; | ||
use crate::{Const, ConstData}; | ||
use crate::{Const, ConstData, ConstEvalError}; | ||
use std::fmt::{self, Debug}; | ||
use std::hash::Hash; | ||
use std::marker::PhantomData; | ||
|
@@ -93,6 +93,15 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { | |
/// evaluated consts. | ||
type InternedConcreteConst: Debug + Clone + Eq + Hash; | ||
|
||
/// "Interned" representation of an unevaluated const expression. In normal user code, | ||
/// `Self::InternedUnevaluatedConst` is not referenced. Instead, | ||
/// we refer to `UnevaluatedConst<Self>`, which wraps this type. | ||
/// | ||
/// `InternedUnevaluatedConst` instances are not created by chalk, | ||
/// it can only evaluate them with the [`try_eval_const`] method | ||
/// and check for (syntactic for now) equality between them. | ||
type InternedUnevaluatedConst: Debug + Clone + Eq + Hash; | ||
|
||
/// "Interned" representation of a "generic parameter", which can | ||
/// be either a type or a lifetime. In normal user code, | ||
/// `Self::InternedGenericArg` is not referenced. Instead, we refer to | ||
|
@@ -456,14 +465,21 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash { | |
/// Lookup the `ConstData` that was interned to create a `InternedConst`. | ||
fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a ConstData<Self>; | ||
|
||
/// Deterermine whether two concrete const values are equal. | ||
/// Determine whether two concrete const values are equal. | ||
fn const_eq( | ||
&self, | ||
ty: &Self::InternedType, | ||
c1: &Self::InternedConcreteConst, | ||
c2: &Self::InternedConcreteConst, | ||
) -> bool; | ||
|
||
/// Attempt to evaluate a const to a concrete const. | ||
fn try_eval_const( | ||
&self, | ||
ty: &Self::InternedType, | ||
constant: &Self::InternedUnevaluatedConst, | ||
) -> Result<Self::InternedConcreteConst, ConstEvalError>; | ||
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. I kind of expect this to take a set of substitutions. Consider how the rustc variant looks. |
||
|
||
/// Create an "interned" parameter from `data`. This is not | ||
/// normally invoked directly; instead, you invoke | ||
/// `GenericArgData::intern` (which will ultimately call this | ||
|
@@ -634,6 +650,12 @@ pub trait TargetInterner<I: Interner>: Interner { | |
const_evaluated: &I::InternedConcreteConst, | ||
) -> Self::InternedConcreteConst; | ||
|
||
/// Transfer unevaluated constant expressions to the target interner. | ||
fn transfer_unevaluated_const( | ||
&self, | ||
const_unevaluated: &I::InternedUnevaluatedConst, | ||
) -> Self::InternedUnevaluatedConst; | ||
|
||
/// Transfer function ABI to the target interner. | ||
fn transfer_abi(abi: I::FnAbi) -> Self::FnAbi; | ||
} | ||
|
@@ -666,6 +688,13 @@ impl<I: Interner> TargetInterner<I> for I { | |
const_evaluated.clone() | ||
} | ||
|
||
fn transfer_unevaluated_const( | ||
&self, | ||
const_unevaluated: &I::InternedUnevaluatedConst, | ||
) -> Self::InternedUnevaluatedConst { | ||
const_unevaluated.clone() | ||
} | ||
|
||
fn transfer_abi(abi: I::FnAbi) -> Self::FnAbi { | ||
abi | ||
} | ||
|
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.
Do we anticipate that this will carry a "substitutions"?
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.
I expect not, right?