-
Notifications
You must be signed in to change notification settings - Fork 182
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
Add TypeFlags for TyKind in chalk-ir #639
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
use chalk_integration::interner::ChalkIr; | ||
use chalk_integration::{empty_substitution, lifetime, ty}; | ||
jackh726 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
use chalk_ir::cast::Cast; | ||
use chalk_ir::{PlaceholderIndex, TyKind, TypeFlags, UniverseIndex}; | ||
|
||
#[test] | ||
fn placeholder_ty_flags_correct() { | ||
let placeholder_ty = ty!(placeholder 0); | ||
assert_eq!( | ||
placeholder_ty.data(&ChalkIr).flags, | ||
TypeFlags::HAS_TY_PLACEHOLDER | ||
); | ||
} | ||
|
||
#[test] | ||
fn opaque_ty_flags_correct() { | ||
let opaque_ty = TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | ||
opaque_ty_id: chalk_ir::OpaqueTyId { | ||
0: chalk_integration::interner::RawId { index: 0 }, | ||
}, | ||
substitution: chalk_ir::Substitution::from_iter( | ||
&ChalkIr, | ||
Some( | ||
chalk_ir::ConstData { | ||
ty: TyKind::Placeholder(PlaceholderIndex { | ||
ui: chalk_ir::UniverseIndex::ROOT, | ||
idx: 0, | ||
}) | ||
.intern(&ChalkIr), | ||
value: chalk_ir::ConstValue::InferenceVar(chalk_ir::InferenceVar::from(0)), | ||
} | ||
.intern(&ChalkIr) | ||
.cast(&ChalkIr), | ||
), | ||
), | ||
})) | ||
.intern(&ChalkIr); | ||
assert_eq!( | ||
opaque_ty.data(&ChalkIr).flags, | ||
TypeFlags::HAS_TY_OPAQUE | ||
| TypeFlags::HAS_CT_INFER | ||
| TypeFlags::STILL_FURTHER_SPECIALIZABLE | ||
| TypeFlags::HAS_TY_PLACEHOLDER | ||
); | ||
} | ||
|
||
#[test] | ||
fn dyn_ty_flags_correct() { | ||
let internal_ty = TyKind::Scalar(chalk_ir::Scalar::Bool).intern(&ChalkIr); | ||
let projection_ty = chalk_ir::ProjectionTy { | ||
associated_ty_id: chalk_ir::AssocTypeId { | ||
0: chalk_integration::interner::RawId { index: 0 }, | ||
}, | ||
substitution: empty_substitution!(), | ||
}; | ||
let bounds = chalk_ir::Binders::<chalk_ir::QuantifiedWhereClauses<ChalkIr>>::empty( | ||
&ChalkIr, | ||
chalk_ir::QuantifiedWhereClauses::from_iter( | ||
&ChalkIr, | ||
vec![chalk_ir::Binders::<chalk_ir::WhereClause<ChalkIr>>::empty( | ||
&ChalkIr, | ||
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq { | ||
ty: internal_ty, | ||
alias: chalk_ir::AliasTy::Projection(projection_ty), | ||
}), | ||
)], | ||
), | ||
); | ||
let dyn_ty = chalk_ir::DynTy { | ||
lifetime: lifetime!(placeholder 5), | ||
bounds, | ||
}; | ||
let ty = TyKind::Dyn(dyn_ty).intern(&ChalkIr); | ||
assert_eq!( | ||
ty.data(&ChalkIr).flags, | ||
TypeFlags::HAS_TY_PROJECTION | ||
| TypeFlags::HAS_RE_PLACEHOLDER | ||
| TypeFlags::HAS_FREE_LOCAL_REGIONS | ||
| TypeFlags::HAS_FREE_REGIONS | ||
); | ||
} | ||
|
||
#[test] | ||
fn flagless_ty_has_no_flags() { | ||
let ty = TyKind::Str.intern(&ChalkIr); | ||
assert_eq!(ty.data(&ChalkIr).flags, TypeFlags::empty()); | ||
|
||
let fn_ty = TyKind::Function(chalk_ir::FnPointer { | ||
num_binders: 0, | ||
substitution: chalk_ir::FnSubst(empty_substitution!()), | ||
sig: chalk_ir::FnSig { | ||
abi: chalk_integration::interner::ChalkFnAbi::Rust, | ||
safety: chalk_ir::Safety::Safe, | ||
variadic: false, | ||
}, | ||
}) | ||
.intern(&ChalkIr); | ||
assert_eq!(fn_ty.data(&ChalkIr).flags, TypeFlags::empty()); | ||
} | ||
|
||
#[test] | ||
fn static_and_bound_lifetimes() { | ||
let substitutions = chalk_ir::Substitution::from_iter( | ||
&ChalkIr, | ||
vec![ | ||
chalk_ir::GenericArgData::Lifetime(chalk_ir::LifetimeData::Static.intern(&ChalkIr)) | ||
.intern(&ChalkIr), | ||
chalk_ir::GenericArgData::Lifetime(lifetime!(bound 5)).intern(&ChalkIr), | ||
], | ||
); | ||
|
||
let ty = TyKind::Adt( | ||
chalk_ir::AdtId { | ||
0: chalk_integration::interner::RawId { index: 0 }, | ||
}, | ||
substitutions, | ||
) | ||
.intern(&ChalkIr); | ||
|
||
assert_eq!( | ||
ty.data(&ChalkIr).flags, | ||
TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_RE_LATE_BOUND | ||
); | ||
} |
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.
This is probably a large enough change to be in another PR, but I would expect the interner to compute the flags, so that in the case it is actually interning it only has to compute flags when it's allocating.