-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement pattern types as the backing logic of rustc_scalar_valid_range attributes #107299
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d1720e2
Add pattern types to the compiler
oli-obk 9286166
Allow range pattern types to allow the entire range (heh) of possible…
oli-obk 38d4b9e
Remove redundant tracing statement
oli-obk 6a9b008
Simplify accessing locals in a MirPatch
oli-obk 832c927
Actually create ranged types
oli-obk ce3e3d4
Enable matching on pattern types via constants
oli-obk 7b9502d
Fixup first commit
oli-obk 32d11e6
Handle new cast kinds in clippy and cranelift
oli-obk e236587
fix stage 2
oli-obk a1c0a3e
x fmt
oli-obk 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
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
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 |
---|---|---|
|
@@ -491,7 +491,27 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
) -> InterpResult<'tcx, bool> { | ||
// Go over all the primitive types | ||
let ty = value.layout.ty; | ||
match ty.kind() { | ||
match *ty.kind() { | ||
ty::Pat(inner, _) => { | ||
let mut value = value.clone(); | ||
value.layout.ty = inner; | ||
// First visit the inner type to report more targetted errors | ||
// if the value is already not valid at the inner type. | ||
self.visit_value(&value)?; | ||
// Then check the extra pattern restrictions. | ||
let scalar = self.read_immediate(&value, "initialized scalar value")?; | ||
match (*scalar, value.layout.abi) { | ||
(Immediate::Scalar(scalar), Abi::Scalar(s)) | ||
| (Immediate::ScalarPair(scalar, _), Abi::ScalarPair(s, _)) => { | ||
self.visit_scalar(scalar, s)? | ||
} | ||
other => span_bug!( | ||
self.ecx.cur_span(), | ||
"invalid abi {other:?} for pattern type {ty:?}" | ||
), | ||
} | ||
Comment on lines
+501
to
+512
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. Isn't this duplicating the scalar range check after this I assume for now patterns are restricted to things that can be actually represented in the |
||
Ok(true) | ||
} | ||
ty::Bool => { | ||
let value = self.read_scalar(value, "a boolean")?; | ||
try_validation!( | ||
|
@@ -545,11 +565,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | |
} | ||
ty::Ref(_, ty, mutbl) => { | ||
if matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { .. })) | ||
&& *mutbl == Mutability::Mut | ||
&& mutbl == Mutability::Mut | ||
{ | ||
// A mutable reference inside a const? That does not seem right (except if it is | ||
// a ZST). | ||
let layout = self.ecx.layout_of(*ty)?; | ||
let layout = self.ecx.layout_of(ty)?; | ||
if !layout.is_zst() { | ||
throw_validation_failure!(self.path, { "mutable reference in a `const`" }); | ||
} | ||
|
@@ -778,7 +798,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> | |
Abi::Scalar(scalar_layout) => { | ||
if !scalar_layout.is_uninit_valid() { | ||
// There is something to check here. | ||
let scalar = self.read_scalar(op, "initiailized scalar value")?; | ||
let scalar = self.read_scalar(op, "initialized scalar value")?; | ||
self.visit_scalar(scalar, scalar_layout)?; | ||
} | ||
} | ||
|
@@ -788,7 +808,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> | |
// the other must be init. | ||
if !a_layout.is_uninit_valid() && !b_layout.is_uninit_valid() { | ||
let (a, b) = | ||
self.read_immediate(op, "initiailized scalar value")?.to_scalar_pair(); | ||
self.read_immediate(op, "initialized scalar value")?.to_scalar_pair(); | ||
self.visit_scalar(a, a_layout)?; | ||
self.visit_scalar(b, b_layout)?; | ||
} | ||
|
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.
I can't parse this panic message... too many patterns?^^