-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 engine: support extra function (pointer) values #62245
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1297a27
Add basic support for "other" kinds of values for function pointers, …
RalfJung 5612feb
add machine hook to handle calls to 'extra' function values
RalfJung 486720f
fix determinig the size of foreign static allocations
RalfJung b4be08a
fix for tidy
RalfJung 842bbd2
make Memory::get_fn take a Scalar like most of the Memory API surface
RalfJung 317c6ac
use get_size_and_align to test if an allocation is live
RalfJung d9d6b3b
turns out that dangling pointer branch is dead code; remove it and im…
RalfJung ceb496c
improve validity error range printing for singleton ranges
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,7 @@ impl interpret::MayLeak for ! { | |
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> { | ||
type MemoryKinds = !; | ||
type PointerTag = (); | ||
type ExtraFnVal = !; | ||
|
||
type FrameExtra = (); | ||
type MemoryExtra = (); | ||
|
@@ -370,6 +371,16 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, | |
})) | ||
} | ||
|
||
fn call_extra_fn( | ||
_ecx: &mut InterpCx<'mir, 'tcx, Self>, | ||
fn_val: !, | ||
_args: &[OpTy<'tcx>], | ||
_dest: Option<PlaceTy<'tcx>>, | ||
_ret: Option<mir::BasicBlock>, | ||
) -> InterpResult<'tcx> { | ||
match fn_val {} | ||
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 think @nikomatsakis or @canndrew brought up the idea of omitting trait methods when they're uncallable due to uninhabited arguments (and presumably they could be null in the vtable and direct calls can be replaced with But for now this seems fine. |
||
} | ||
|
||
fn call_intrinsic( | ||
ecx: &mut InterpCx<'mir, 'tcx, Self>, | ||
instance: ty::Instance<'tcx>, | ||
|
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
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.
So, my prior understanding was that the never (
!
) type is never realized (and thus is the "return type" of functions that don't return, likepanic!
), so I'm confused about how we can use it as a function argument? If we can't get a value of!
, then how can we call this function? And if we can't call this function, what is it for?(really sorry, I told you I wasn't the most qualified reviewer 😰 )
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.
We can't call this function indeed. :)
It's a trait method, and the type of
fn_val
is an associated type. So there might be (and, in fact, there are) other implementations of the trait that pick a non-empty type, and thencall_extra_fn
takes that type. For example Miri instantiates this trait, and therecall_extra_fn
looks likeNotice the
Dlsym
instead of the!
.By using
!
in theconst_eval
instance, I basically opt-out of the ability (that theMachine
trait offers) to have "other" function values, and because there are no "other" function values,call_extra_fn
does not have to do anything. This surfaces in the type of the method as you said; so we can implement the method trivially without even panicking or so, just by matching onfn_val
to "prove" to the compiler that we are in unreachable code.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.
We could ask @eddyb to also take a look if you want -- but it's hard to get a time slice from his scheduler. ;)