Skip to content
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

Merged
merged 8 commits into from
Mar 14, 2017

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Feb 28, 2017

We can now turn non-capturing closures into function pointers (and then back into Fn trait objects)

Diff best viewed without whitespace changes

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(),
}))
Copy link
Member

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!

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 2, 2017

Added rustup to @eddyb's PR of doom awesomeness

format!("extern {} ", fn_def.abi)
};
format!("function pointer: {}: {}{}", name, abi, fn_def.sig)
format!("function pointer: {}: {}", name, fn_def.sig.skip_binder())
Copy link
Member

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!

Copy link
Contributor Author

@oli-obk oli-obk Mar 2, 2017

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

Copy link
Member

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!(),
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@solson solson left a 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) => {
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/statik/static_/

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
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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).

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reran on rust test suite:

   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

Copy link
Member

@solson solson Mar 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. fn(&[u8]) -> std::option::Option<u8>
    fn(&[u8]) -> std::option::Option<u8>
  2. fn(&A<'_>)
    fn(&A)
  3. extern "C" fn(usize) -> Foo
    extern "C" fn(usize) -> u32
  4. 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.

pub fn erase_lifetimes<T>(self, value: &Binder<T>) -> T
where T : TypeFoldable<'tcx>
{
let value = self.tcx.erase_late_bound_regions(value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon here.

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 14, 2017

fixed

@solson solson merged commit 6ee8595 into rust-lang:master Mar 14, 2017
@oli-obk oli-obk deleted the rustup branch March 17, 2017 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants