Skip to content

ICE "anonymous bound region BrAnon(0) in return but not args" #43567

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

Closed
SimonSapin opened this issue Jul 31, 2017 · 37 comments
Closed

ICE "anonymous bound region BrAnon(0) in return but not args" #43567

SimonSapin opened this issue Jul 31, 2017 · 37 comments
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

rustc 1.21.0-nightly (aac223f 2017-07-30) ICEs on https://github.com/rtbo/rust-xcb (full output below), although 1.20.0-beta.1 and some not-much-older nightlies succeed.

Some more context around the line in the error message:

#[repr(C)]
pub struct xcb_depth_iterator_t<'a> {
    pub data:  *mut xcb_depth_t,
    pub rem:   c_int,
    pub index: c_int,
    _phantom:  std::marker::PhantomData<&'a xcb_depth_t>,
}
// […]
#[link(name="xcb")]
extern {
// […]
    pub fn xcb_screen_allowed_depths_iterator (R: *const xcb_screen_t)
            -> xcb_depth_iterator_t;

So the xcb_depth_iterator_t does have lifetime parameter that’s elided in this function declaration’s return type without any elided lifetime in the parameters. Maybe this code should indeed be rejected, but in that case we need a proper error message rather than a compiler panic. Although it used to be accepted, so this is a breaking change. Adding an explicit lifetime parameter to the function fixes this, but that’s not easy to do properly since this is generated code.

Full output:

% RUST_BACKTRACE=1 cargo +nightly build -v
       Fresh log v0.3.8
       Fresh libc v0.2.28
   Compiling xcb v0.8.0 (file:///home/simon/projects/rust-xcb)
     Running `rustc --crate-name xcb src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=f22742bf239db509 -C extra-filename=-f22742bf239db509 --out-dir /home/simon/projects/rust-xcb/target/debug/deps -L dependency=/home/simon/projects/rust-xcb/target/debug/deps --extern log=/home/simon/projects/rust-xcb/target/debug/deps/liblog-2b956ee286098ab8.rlib --extern libc=/home/simon/projects/rust-xcb/target/debug/deps/liblibc-c727996240879c34.rlib`
error: internal compiler error: /checkout/src/librustc_typeck/astconv.rs:1267: anonymous bound region BrAnon(0) in return but not args
    --> src/ffi/xproto.rs:5654:16
     |
5654 |             -> xcb_depth_iterator_t;
     |                ^^^^^^^^^^^^^^^^^^^^

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.21.0-nightly (aac223f4f 2017-07-30) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:438:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:380
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:390
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:610
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: rustc::session::opt_span_bug_fmt::{{closure}}
   8: rustc::session::span_bug_fmt
   9: <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ty_of_fn
  10: rustc_typeck::collect::fn_sig
  11: rustc::dep_graph::graph::DepGraph::with_task
  12: rustc::ty::maps::<impl rustc::ty::maps::queries::fn_sig<'tcx>>::try_get
  13: rustc::ty::maps::TyCtxtAt::fn_sig
  14: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::fn_sig
  15: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  16: rustc_typeck::check_crate::{{closure}}::{{closure}}
  17: rustc_typeck::check_crate
  18: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  19: rustc_driver::driver::phase_3_run_analysis_passes
  20: rustc_driver::driver::compile_input
  21: rustc_driver::run_compiler

error: Could not compile `xcb`.

Caused by:
  process didn't exit successfully: `rustc --crate-name xcb src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=f22742bf239db509 -C extra-filename=-f22742bf239db509 --out-dir /home/simon/projects/rust-xcb/target/debug/deps -L dependency=/home/simon/projects/rust-xcb/target/debug/deps --extern log=/home/simon/projects/rust-xcb/target/debug/deps/liblog-2b956ee286098ab8.rlib --extern libc=/home/simon/projects/rust-xcb/target/debug/deps/liblibc-c727996240879c34.rlib` (exit code: 101)
@petrochenkov
Copy link
Contributor

Must be a regression from #43543

Looks like #32330 wasn't fixed in foreign functions :(
I'll prepare a patch.

@SimonSapin
Copy link
Contributor Author

@petrochenkov Do you mean a patch that would make xcb compile, or produce a better error message?

@petrochenkov
Copy link
Contributor

@SimonSapin
Don't know yet, need to look closer.
A proper fix may require a warning, deprecation period, etc, but immediate fix for the ICE making xcb compile can always be done by partially reverting #43543.

@SimonSapin
Copy link
Contributor Author

Ok, thanks for looking into it.

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 1, 2017
@Mark-Simulacrum
Copy link
Member

Performance collection for the style crate is also broken because of this.

@eddyb
Copy link
Member

eddyb commented Aug 1, 2017

cc @nikomatsakis Should we add elision logic to foreign functions?

@Manishearth
Copy link
Member

#43594 has a simpler testcase that also involves elision.

Also, yes, I think elision should work on FFI. Firstly, it used to, and it's a breaking change otherwise.

Secondly, this is extremely useful when paired with bindgen to have a modicum of safety wrt returning non-owners pointers from FFI. Dereferenced raw pointers yield values of arbitrary lifetime, and guarding against this in FFI-heavy code is extremely tedious. In an FFI-heavy project the risk of introducing unsafety in the FFI layer can outweigh the risk of just writing it all in C++, largely due to things like this.

@eddyb
Copy link
Member

eddyb commented Aug 1, 2017

@Manishearth Elision never worked, what you were getting was an unbound lifetime in the return.

@eddyb
Copy link
Member

eddyb commented Aug 1, 2017

@Manishearth It was even you who reported #35851. I found two crates that would break so we didn't go through with adding elision to them.

@Manishearth
Copy link
Member

Wait, what? I could swear we've had lifetime errors on this before. Or perhaps they were in nearby FFI wrappers. Hmm.

@Manishearth
Copy link
Member

Oh, right, I didn't remember that was all elision.

Opt in would be okay by me too, really. Then again, we also need this on stable.

Can we add elision for the cases where there isn't a function returning a dangling lifetime (and deal with the backcompat hazard separately?). That seems like it can be done a without breaking anyone. As it stands this will break stylo, and it is super nontrivial to fix given the amount of FFI we do.

@Manishearth
Copy link
Member

I can also try to fix those crates preemptively.

@eddyb
Copy link
Member

eddyb commented Aug 1, 2017

If anyone wants to test with the no-elision-in-FFI hack turned off, change this match arm to => None.

@SimonSapin
Copy link
Contributor Author

I think this is not a case of valid elision. If I add a non-FFI function with the same signature it fails to build with a proper error message because there is no implicit lifetime in the function’s parameters.

    pub fn xcb_screen_allowed_depths_iterator__ (R: *const xcb_screen_t)
            -> xcb_depth_iterator_t { unimplemented!() }
error[E0106]: missing lifetime specifier
 --> src/ffi/xproto.rs:8:16
  |
8 |             -> xcb_depth_iterator_t { unimplemented!() }
  |                ^^^^^^^^^^^^^^^^^^^^ expected lifetime parameter
  |
  = help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
  = help: consider giving it an explicit bounded or 'static lifetime

@Manishearth
Copy link
Member

FWIW the testcase in #43594 is a case of valid elision, even though it's invalid here.

@Manishearth
Copy link
Member

Actually, it occurs to me that this bound region bug is going to happen anyway and break all of the crates rely on this anyway, so we should just enable elision for extern fns .. ?

@Manishearth
Copy link
Member

PR to fix rust-xcb: https://github.com/rtbo/rust-xcb/pull/41

@Manishearth
Copy link
Member

Fixed liquidfun-rust rjanicek/liquidfun-rust#4

Might be worth a fresh crater run.

@eddyb
Copy link
Member

eddyb commented Aug 1, 2017

cc @Mark-Simulacrum Cargobomb would be helpful.

@Mark-Simulacrum
Copy link
Member

I don't have access to cargobomb myself, but @tomprince and @brson do, I believe. A patch would be useful either way.

@kornelski
Copy link
Contributor

I've ran into the same error. Here's a minimal case:

extern "C" {
    fn ice(ice: &mut u32) -> &u32;
}

error: internal compiler error: src/librustc_typeck/astconv.rs:1267: anonymous bound region BrAnon(1) in return but not args

rustc 1.21.0-nightly (1d2a6df 2017-08-03) running on x86_64-apple-darwin

bors added a commit that referenced this issue Aug 5, 2017
Fix ICE with elided lifetimes in return type of foreign functions

cc #43567

This is for a preliminary crater/cargobomb run.
Lifetime elision still produces a late-bound lifetime, but it is caught by the same check as catches `type F = for<'a> fn() -> &'a u8` and reported as an error.

If the breakage is significant, I'll have to partially revert #43543 (all the stuff that was required for dealing with late bound lifetimes in this position).

r? @eddyb
Manishearth added a commit to Manishearth/rust that referenced this issue Aug 6, 2017
@emilio
Copy link
Contributor

emilio commented Aug 8, 2017

This also happens on Stylo FWIW.

@Manishearth
Copy link
Member

(we know, see #43594)

@Manishearth
Copy link
Member

I've fixed up stylo so that the fix for this issue will play nice with it (and the fix for this issue should be in nightly now)

@emilio
Copy link
Contributor

emilio commented Aug 8, 2017

It panics on current master with ./mach cargo-geckolib build, so did you forget to update the bindings? Or is it another instance of the problem?

@Manishearth
Copy link
Member

Compiles for me on latest nightly :)

@main--
Copy link
Contributor

main-- commented Aug 8, 2017

@SimonSapin
Copy link
Contributor Author

I’m also still seeing this failure with rustc 1.21.0-nightly (cbbe17a 2017-08-07) (same as @main--) on Servo. @Manishearth, which version did you use, and what did you test?

@Manishearth
Copy link
Member

Oh, right, I used stable by accident. Oops.

Looks like it never landed on master, only try.

@eddyb
Copy link
Member

eddyb commented Aug 9, 2017

@Manishearth I think @tomprince started the cargobomb run only today.

@michaelwoerister michaelwoerister added P-high High priority and removed I-nominated labels Aug 10, 2017
@michaelwoerister
Copy link
Member

Discussed in the compiler team meeting. P-high.

@petrochenkov
Copy link
Contributor

In the meantime, could someone fix these issues in xcb/stylo/etc by adding explicit lifetimes?
If something ICEs with this message now, there's a good chance it will be an error sooner or later (maybe after deprecation period), so it will need to be fixed anyway.

@Manishearth
Copy link
Member

It should be fixed in stylo.

I am unable to fix XCB, they use a pretty weird custom bindings generation setup that uses lifetimes but doesn't carry enough info around for those lifetimes to be used consistently. A maintainer of that crate will have to fix it; I'm just not familiar enough with this custom setup to deal with it.

@SimonSapin
Copy link
Contributor Author

SimonSapin commented Aug 11, 2017

(I think Stylo was not affected, only Servo. We worked around by forking xcb and modifying manually the generated code. Hopefully this is temporary until someone can figure out a proper fix in the code generation script.)

@nox
Copy link
Contributor

nox commented Aug 14, 2017

This kind of bug is why mozilla-central should never use the system Rust, and always download its own that it knows will work.

bors added a commit that referenced this issue Aug 16, 2017
Fix ICE with elided lifetimes in return type of foreign functions

cc #43567

This is for a preliminary crater/cargobomb run.
Lifetime elision in foreign functions now works exactly like in other functions or function-like entities.

If the breakage is significant, I'll have to partially revert #43543 (all the stuff that was required for dealing with late bound lifetimes in this position).

r? @eddyb
@petrochenkov
Copy link
Contributor

Fixed in #43651

@SimonSapin
Copy link
Contributor Author

Confirmed that Firefox compiles on Rust Nightly, with #43651. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests