-
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
Constier maybe uninit #79621
Merged
Merged
Constier maybe uninit #79621
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8bd80e2
Make some of MaybeUninit's methods const
usbalbin 91772c3
Even more const
usbalbin 1ef5dbe
Resolved some of the comments
usbalbin f311db1
Added tests for assume_init
usbalbin 4f9fd2a
Undo fn -> const fn for all intrinsics but assert_inhabited
usbalbin d366ed2
abort() now takes a msg parameter
usbalbin 7bd754c
Fix tests (hopefully)
usbalbin 9476241
Still unable to get the tests working
usbalbin 4255a5a
Moved failing test to src/test/ui/
usbalbin 3282b54
Tests finally working
usbalbin 345f230
Fix comments related to abort()
usbalbin d0a1e40
Remove unused feature gate
usbalbin bdda98a
Add comment for assert_inhabited in compiler/rustc_mir/src/interpret/…
usbalbin 69ab0bc
Use 'error-pattern' in ui test
usbalbin 1749359
Make assume_init_{ref,mut} const
usbalbin 0775271
Make write and slice_as_[mut_]_ptr const
usbalbin 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 |
---|---|---|
|
@@ -407,6 +407,30 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { | |
sym::transmute => { | ||
self.copy_op_transmute(args[0], dest)?; | ||
} | ||
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_uninit_valid => { | ||
let ty = instance.substs.type_at(0); | ||
let layout = self.layout_of(ty)?; | ||
|
||
if layout.abi.is_uninhabited() { | ||
throw_ub_format!("attempted to instantiate uninhabited type `{}`", ty); | ||
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. This is wrong. It is not UB to fail an assertion. That is the entire point of this check, to avoid UB and replace it by a well-defined assertion. |
||
} | ||
if intrinsic_name == sym::assert_zero_valid | ||
&& !layout.might_permit_raw_init(self, /*zero:*/ true).unwrap() | ||
{ | ||
throw_ub_format!( | ||
"attempted to zero-initialize type `{}`, which is invalid", | ||
ty | ||
); | ||
} | ||
if intrinsic_name == sym::assert_uninit_valid | ||
&& !layout.might_permit_raw_init(self, /*zero:*/ false).unwrap() | ||
{ | ||
throw_ub_format!( | ||
"attempted to leave type `{}` uninitialized, which is invalid", | ||
ty | ||
); | ||
} | ||
} | ||
sym::simd_insert => { | ||
let index = u64::from(self.read_scalar(args[1])?.to_u32()?); | ||
let elem = args[2]; | ||
|
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
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.
@oli-obk how will such aborting intrinsics interact with function memoization?
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.
In particular with #75390 I am wondering if we'll get decent error messages here.
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.
that works fine, it will cause the const eval queries to return an error, similar to how the memoization of
size_of
can error if the type is not representable on the platform