-
Notifications
You must be signed in to change notification settings - Fork 352
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
rustup to rustc 1.17.0-nightly (60a0edc6c 2017-02-26) #147
Conversation
src/memory.rs
Outdated
// FIXME: why doesn't this compile? | ||
//sig: tcx.erase_late_bound_regions(&fn_ty.sig), | ||
sig: fn_ty.sig.skip_binder(), | ||
})) |
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'm not sure this is the way to go. Did you see how this was implemented in librustc_trans
?
That is, it relies on an existing shim- oh, drat, you have that extra argument to take care of, nevermind me!
Added rustup to @eddyb's PR of |
format!("extern {} ", fn_def.abi) | ||
}; | ||
format!("function pointer: {}: {}{}", name, abi, fn_def.sig) | ||
format!("function pointer: {}: {}", name, fn_def.sig.skip_binder()) |
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 don't think skipping the binder is needed here at all!
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.
yes it is :) There's no Display impl for Binder
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.
Oh, right, it's Debug
only - should still do the right thing though.
@@ -196,7 +194,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { | |||
|
|||
Struct(_) => unimplemented!(), | |||
Tuple(_) => unimplemented!(), | |||
Function(_) => unimplemented!(), | |||
Function(_, _) => unimplemented!(), |
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.
Tempted to make this the way to refer to a TyFnDef
(now that it has Substs
), what do you think?
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.
it's unreachable ^^ At least in the run-pass tests that we run. We only use this function in mir::Literal::Value
, and I think that can only contain primitives
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.
Oh, I know, it's because we use Item
right now, and work around the awkwardness of it everywhere.
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.
Oh... you mean changing it that Literal::Item
stops referring to functions. Sounds good.
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.
Sorry for the delay!
src/lvalue.rs
Outdated
@@ -137,9 +137,9 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { | |||
Local(mir::RETURN_POINTER) => self.frame().return_lvalue, | |||
Local(local) => Lvalue::Local { frame: self.stack.len() - 1, local, field: None }, | |||
|
|||
Static(def_id) => { | |||
Static(ref statik) => { |
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.
s/statik/static_/
I prefer to use a deterministic keyword renaming (append _
) rather than coming up with weird unique replacements.
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.
sgtm, I was just following the style seen in rustc (krate
)
src/step.rs
Outdated
@@ -242,7 +242,8 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'tcx> { | |||
location: mir::Location | |||
) { | |||
self.super_lvalue(lvalue, context, location); | |||
if let mir::Lvalue::Static(def_id) = *lvalue { | |||
if let mir::Lvalue::Static(ref statik) = *lvalue { |
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.
s/statik/static_/
src/terminator/mod.rs
Outdated
return Err(EvalError::FunctionPointerTyMismatch(abi, sig, bare_fn_ty)); | ||
match fn_def { | ||
Function::Concrete(fn_def) => { | ||
// transmuting function pointers in miri is fine as long as the number of |
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.
Even if we check ABI, number of arguments, and argument and return type sizes, we might still not match true target calling convention behaviour because of weird differences between, for example, T
and struct Foo { x: T }
. I think maybe we should be more conservative and prevent the calling of transmuted function pointers.
Specifically, error out at call time when the call-site function type doesn't match the type of the function actually being dynamically called, since Miri can remember that. We should still allow round-tripping transmutes that never call a fn ptr with the wrong type, just like we allow round trips with other transmutes.
Differences like unsafe
vs. non-unsafe
should be fine, though. Anything that clearly doesn't affect the calling convention.
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.
yea... I tried to do that check, but since we also don't care about lifetime changes I tried to erase the lifetimes, which kept causing rustc to panic in weird corner cases.
I'll change the FIXME text
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.
oh... I remember sth else. Rustc tests whether we can transmute fn foo(*const i32)
to fn foo(Option<&i32>)
(or maybe the other direction).
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'd prefer to be more conservative than rustc about function pointer casts until a more formal definition comes along, unless it becomes essential for evaluating std 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.
1 tried to call a function with sig fn(&[u8]) -> std::option::Option<u8> through a function pointer of type fn(&[u8]) -> std::option::Option<u8>
1 tried to call a function with sig fn(&A<'_>) through a function pointer of type fn(&A)
1 tried to call a function with sig extern "C" fn(usize) -> Foo through a function pointer of type extern "C" fn(usize) -> u32
1 tried to call a function with sig extern "C" fn(&isize) -> std::option::Option<&isize> through a function pointer of type extern "C" fn(&isize) -> &isize
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.
fn(&[u8]) -> std::option::Option<u8>
fn(&[u8]) -> std::option::Option<u8>
fn(&A<'_>)
fn(&A)
extern "C" fn(usize) -> Foo
extern "C" fn(usize) -> u32
extern "C" fn(&isize) -> std::option::Option<&isize>
extern "C" fn(&isize) -> &isize
Of these, I think we should make sure 1 and 2 work (ignore lifetimes). I don't care about supporting 3 and 4 for now.
src/eval_context.rs
Outdated
pub fn erase_lifetimes<T>(self, value: &Binder<T>) -> T | ||
where T : TypeFoldable<'tcx> | ||
{ | ||
let value = self.tcx.erase_late_bound_regions(value) |
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.
Missing semicolon here.
fixed |
We can now turn non-capturing closures into function pointers (and then back into
Fn
trait objects)Diff best viewed without whitespace changes