-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Miri: move ModifiedStatic to ConstEval errors #70241
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d9649a
move ModifiedStatic error to ConstEval errors, and generally adjust t…
RalfJung f70af91
bless; add test for mutating a static
RalfJung 69cf211
get back the more precise error message
RalfJung 58a56cc
bless you
RalfJung 7a73b87
fix const_prop ICE
RalfJung 1939b4c
actually we can reject all reads from mutable allocs in const-prop
RalfJung 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,9 @@ use std::hash::Hash; | |
use rustc_data_structures::fx::FxHashMap; | ||
|
||
use rustc::mir::AssertMessage; | ||
use rustc_span::source_map::Span; | ||
use rustc_ast::ast::Mutability; | ||
use rustc_span::symbol::Symbol; | ||
use rustc_span::{def_id::DefId, Span}; | ||
|
||
use crate::interpret::{ | ||
self, AllocId, Allocation, GlobalId, ImmTy, InterpCx, InterpResult, Memory, MemoryKind, OpTy, | ||
|
@@ -167,7 +168,7 @@ impl interpret::MayLeak for ! { | |
} | ||
|
||
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter { | ||
type MemoryKinds = !; | ||
type MemoryKind = !; | ||
type PointerTag = (); | ||
type ExtraFnVal = !; | ||
|
||
|
@@ -177,7 +178,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter { | |
|
||
type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>; | ||
|
||
const STATIC_KIND: Option<!> = None; // no copying of statics allowed | ||
const GLOBAL_KIND: Option<!> = None; // no copying of globals allowed | ||
|
||
// We do not check for alignment to avoid having to carry an `Align` | ||
// in `ConstValue::ByRef`. | ||
|
@@ -317,7 +318,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter { | |
} | ||
|
||
#[inline(always)] | ||
fn tag_static_base_pointer(_memory_extra: &MemoryExtra, _id: AllocId) -> Self::PointerTag {} | ||
fn tag_global_base_pointer(_memory_extra: &MemoryExtra, _id: AllocId) -> Self::PointerTag {} | ||
|
||
fn box_alloc( | ||
_ecx: &mut InterpCx<'mir, 'tcx, Self>, | ||
|
@@ -345,11 +346,19 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter { | |
Ok(()) | ||
} | ||
|
||
fn before_access_static( | ||
fn before_access_global( | ||
memory_extra: &MemoryExtra, | ||
_allocation: &Allocation, | ||
alloc_id: AllocId, | ||
allocation: &Allocation, | ||
def_id: Option<DefId>, | ||
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. Maybe rename this to |
||
is_write: bool, | ||
) -> InterpResult<'tcx> { | ||
if memory_extra.can_access_statics { | ||
if is_write && allocation.mutability == Mutability::Not { | ||
Err(err_ub!(WriteToReadOnly(alloc_id)).into()) | ||
} else if is_write { | ||
Err(ConstEvalErrKind::ModifiedGlobal.into()) | ||
} else if memory_extra.can_access_statics || def_id.is_none() { | ||
// `def_id.is_none()` indicates this is not a static, but a const or so. | ||
Ok(()) | ||
} else { | ||
Err(ConstEvalErrKind::ConstAccessesStatic.into()) | ||
|
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
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.
What does the comment mean?
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.
See 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.
Ah, "from
tcx
" was the missing part, at a glance this looks like it's talking aboutlet x = STATIC;
which confused me.