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

ICE when using an object-safe trait with methods marked as extern #51907

Closed
tuxmark5 opened this issue Jun 29, 2018 · 10 comments
Closed

ICE when using an object-safe trait with methods marked as extern #51907

tuxmark5 opened this issue Jun 29, 2018 · 10 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-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tuxmark5
Copy link

This snippet causes rustc to ICE:

trait Foo {
    extern fn method(&self);
}

struct Bar;
impl Foo for Bar { 
    extern fn method(&self) { }
}

fn main() {
    let foo: Box<dyn Foo> = Box::new(Bar);
    foo.method();
}

rustc version: rustc 1.28.0-nightly (2a1c4ee 2018-06-25)

Error message:

error: internal compiler error: librustc_codegen_llvm/abi.rs:304: FnType::new_vtable: non-pair self ArgType { layout: TyLayout { ty: &Foo, details: LayoutDetails { variants: Single { index: 0 }, fields: Arbitrary { offsets: [Size { raw: 0 }, Size { raw: 8 }], memory_index: [0, 1] }, abi: ScalarPair(Scalar { value: Pointer, valid_range: 1..=18446744073709551615 }, Scalar { value: Pointer, valid_range: 1..=18446744073709551615 }), align: Align { abi_pow2: 3, pref_pow2: 3 }, size: Size { raw: 16 } } }, pad: None, mode: Direct(ArgAttributes { regular: (empty), pointee_size: Size { raw: 0 }, pointee_align: None }) }
@kennytm kennytm added 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. C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Jun 29, 2018
@kennytm
Copy link
Member

kennytm commented Jun 29, 2018

This is a regression introduced since 1.24.

@nikomatsakis
Copy link
Contributor

Can we bisect this down to a nightly?

@nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis added the P-high High priority label Jul 5, 2018
@nikomatsakis
Copy link
Contributor

Marking as P-high, regression, but not assigning anyone till we have some better idea of the cause.

@pietroalbini
Copy link
Member

The regression happened in nightly-2017-11-21. In that range there is #45225, which is a refactoring by @eddyb on the file where the ICE is happening.

By the way, we shouldn't waste time bisecting regressions, we already have @nikomatsakis...

<nmatsakis> would be useful to know which PR
<nmatsakis> my money is on some massive eddyb refactoring ;)

@nikomatsakis
Copy link
Contributor

@eddyb do you think you can take a look at this bug?

@eddyb
Copy link
Member

eddyb commented Jul 5, 2018

Yeah this is #45225, looks like the pre-existing assumption of having the first argument split (because it's a pointer to a dyn Trait, i.e. a pair of pointer and vtable) stopped holding on non-Rust ABIs.
(technically a bug-fix, now we treat Rust "scalar pair" types like plain C structs, across FFI)

I'm surprised nobody hit this until now and that we have no tests for non-Rust ABIs in trait objects!

bors added a commit that referenced this issue Jul 12, 2018
rustc_codegen_llvm: replace the first argument early in FnType::new_vtable.

Fixes #51907 by removing the vtable pointer before the `ArgType` is even created.
This allows any ABI to support trait object method calls, regardless of how it passes `*dyn Trait`.

r? @nikomatsakis
@eddyb
Copy link
Member

eddyb commented Jul 13, 2018

Do we want to backport the fix or anything?

@pietroalbini
Copy link
Member

Well, this is pretty old, so backporting to stable is probably too much. Nominating for beta backport though. cc @rust-lang/compiler

@arielb1
Copy link
Contributor

arielb1 commented Jul 14, 2018

Please no backporting codegen changes to beta. They are likely to introduce more bugs. There's no sufficiently good reason to backport this.

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-stable Performance or correctness regression from one stable version to another. 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

6 participants