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

Fix -Z lower_128bit_ops handling of statics #46583

Merged
merged 1 commit into from Dec 20, 2017

Conversation

Projects
None yet
7 participants
@scottmcm
Member

scottmcm commented Dec 8, 2017

Avoids ICEs such as the following:

error: internal compiler error: src\librustc_metadata\cstore_impl.rs:131:
get_optimized_mir: missing MIR for DefId(8/0:40 ~ compiler_builtins[9532]::int[0]::addsub[0]::rust_i128_addo[0])

r? @nagisa

cc #45676 @est31

@nagisa

This comment has been minimized.

Show comment
Hide comment
@nagisa

nagisa Dec 8, 2017

Contributor

I think what should happen here is:

  1. We make sure MIR gets included into compiler-builtins for i128 language items. This should happen within the compiler (so the change supposedly should be somewhere within the collector);
  2. We make sure this pass gets run after constant propagation/miri runs, when those land.
Contributor

nagisa commented Dec 8, 2017

I think what should happen here is:

  1. We make sure MIR gets included into compiler-builtins for i128 language items. This should happen within the compiler (so the change supposedly should be somewhere within the collector);
  2. We make sure this pass gets run after constant propagation/miri runs, when those land.
@scottmcm

This comment has been minimized.

Show comment
Hide comment
@scottmcm

scottmcm Dec 10, 2017

Member

I'm not certain what I should do here. rkruppe is absolutely right that this PR is just changing an unsoundness to an incompleteness.

(1) Getting the MIR for the lang items themselves seems insufficient, as I first tried #[inline]ing them, which then just complained about the things they were calling. So that feels wrong, especially as it may require getting the MIR for a some things in core, which shouldn't be affected by this.

(2) This sounds great, though I'm not sure where this pass would then run, since I figure const fns calling other const fns need this to not be applied, at which point it feels like it can't be in the normal "run these passes as part of generating final MIR for these functions". Is there a spot in trans where the pass could run? Or at that point does having this be done on MIR no longer make sense...

Member

scottmcm commented Dec 10, 2017

I'm not certain what I should do here. rkruppe is absolutely right that this PR is just changing an unsoundness to an incompleteness.

(1) Getting the MIR for the lang items themselves seems insufficient, as I first tried #[inline]ing them, which then just complained about the things they were calling. So that feels wrong, especially as it may require getting the MIR for a some things in core, which shouldn't be affected by this.

(2) This sounds great, though I'm not sure where this pass would then run, since I figure const fns calling other const fns need this to not be applied, at which point it feels like it can't be in the normal "run these passes as part of generating final MIR for these functions". Is there a spot in trans where the pass could run? Or at that point does having this be done on MIR no longer make sense...

@nagisa

This comment has been minimized.

Show comment
Hide comment
@nagisa

nagisa Dec 10, 2017

Contributor

@bors r+

Contributor

nagisa commented Dec 10, 2017

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 10, 2017

Contributor

📌 Commit 1b88022 has been approved by nagisa

Contributor

bors commented Dec 10, 2017

📌 Commit 1b88022 has been approved by nagisa

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 10, 2017

Contributor

⌛️ Testing commit 1b88022 with merge ec06e86...

Contributor

bors commented Dec 10, 2017

⌛️ Testing commit 1b88022 with merge ec06e86...

bors added a commit that referenced this pull request Dec 10, 2017

Auto merge of #46583 - scottmcm:fix-static-i128-lower, r=nagisa
Fix -Z lower_128bit_ops handling of statics

Avoids ICEs such as the following:
>  error: internal compiler error: src\librustc_metadata\cstore_impl.rs:131:
>  get_optimized_mir: missing MIR for `DefId(8/0:40 ~
>  compiler_builtins[9532]::int[0]::addsub[0]::rust_i128_addo[0])`

r? @nagisa

cc #45676 @est31
@arielb1

This comment has been minimized.

Show comment
Hide comment
@arielb1

arielb1 Dec 10, 2017

Contributor

@bors r- retry

I don't think this actually fixes things - now const fns will generate bad i128 ops when called in a non-constant context.

Contributor

arielb1 commented Dec 10, 2017

@bors r- retry

I don't think this actually fixes things - now const fns will generate bad i128 ops when called in a non-constant context.

@arielb1

This comment has been minimized.

Show comment
Hide comment
@arielb1

arielb1 Dec 10, 2017

Contributor

I think the right way to fix it in the rustc_trans::mir::constant context would be to treat the i128 ops like intrinsics and "special-case-translate" them here:

if let Some((ref dest, target)) = *destination {
let result = if fn_ty.fn_sig(tcx).abi() == Abi::RustIntrinsic {
match &tcx.item_name(def_id)[..] {
"size_of" => {
let llval = C_usize(self.ccx,
self.ccx.size_of(substs.type_at(0)).bytes());
Ok(Const::new(llval, tcx.types.usize))
}
"min_align_of" => {
let llval = C_usize(self.ccx,
self.ccx.align_of(substs.type_at(0)).abi());
Ok(Const::new(llval, tcx.types.usize))
}
_ => span_bug!(span, "{:?} in constant", terminator.kind)
}
} else {
MirConstContext::trans_def(self.ccx, def_id, substs, arg_vals)
};

by calling the appropriate binary op implementation if the function def-id matches, via an inverse of the item_for_op function:

fn item_for_op(bin_op: BinOp, is_signed: bool) -> Option<(LangItem, RhsKind)> {

Contributor

arielb1 commented Dec 10, 2017

I think the right way to fix it in the rustc_trans::mir::constant context would be to treat the i128 ops like intrinsics and "special-case-translate" them here:

if let Some((ref dest, target)) = *destination {
let result = if fn_ty.fn_sig(tcx).abi() == Abi::RustIntrinsic {
match &tcx.item_name(def_id)[..] {
"size_of" => {
let llval = C_usize(self.ccx,
self.ccx.size_of(substs.type_at(0)).bytes());
Ok(Const::new(llval, tcx.types.usize))
}
"min_align_of" => {
let llval = C_usize(self.ccx,
self.ccx.align_of(substs.type_at(0)).abi());
Ok(Const::new(llval, tcx.types.usize))
}
_ => span_bug!(span, "{:?} in constant", terminator.kind)
}
} else {
MirConstContext::trans_def(self.ccx, def_id, substs, arg_vals)
};

by calling the appropriate binary op implementation if the function def-id matches, via an inverse of the item_for_op function:

fn item_for_op(bin_op: BinOp, is_signed: bool) -> Option<(LangItem, RhsKind)> {

@scottmcm scottmcm changed the title from Fix -Z lower_128bit_ops handling of statics to [WIP] Fix -Z lower_128bit_ops handling of statics Dec 19, 2017

Fix -Z lower_128bit_ops handling of statics
Avoids ICEs such as the following:
 error: internal compiler error: src\librustc_metadata\cstore_impl.rs:131:
 get_optimized_mir: missing MIR for `DefId(8/0:40 ~
 compiler_builtins[9532]::int[0]::addsub[0]::rust_i128_addo[0])`

@scottmcm scottmcm changed the title from [WIP] Fix -Z lower_128bit_ops handling of statics to Fix -Z lower_128bit_ops handling of statics Dec 19, 2017

@scottmcm

This comment has been minimized.

Show comment
Hide comment
@scottmcm

scottmcm Dec 19, 2017

Member

Ok, updated to special-case-translate these calls in const trans. The inverse lookup can be found here: https://github.com/rust-lang/rust/pull/46583/files#diff-823b4422fff3f3018e53dfb6dc0a1fb3R468

Member

scottmcm commented Dec 19, 2017

Ok, updated to special-case-translate these calls in const trans. The inverse lookup can be found here: https://github.com/rust-lang/rust/pull/46583/files#diff-823b4422fff3f3018e53dfb6dc0a1fb3R468

@arielb1

This comment has been minimized.

Show comment
Hide comment
@arielb1

arielb1 Dec 19, 2017

Contributor

r? @eddyb - you know rustc_trans::mir::constant

Contributor

arielb1 commented Dec 19, 2017

r? @eddyb - you know rustc_trans::mir::constant

@rust-highfive rust-highfive assigned eddyb and unassigned nagisa Dec 19, 2017

@eddyb

This comment has been minimized.

Show comment
Hide comment
@eddyb
Member

eddyb commented Dec 19, 2017

@bors r+

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 19, 2017

Contributor

📌 Commit 4b95ca8 has been approved by eddyb

Contributor

bors commented Dec 19, 2017

📌 Commit 4b95ca8 has been approved by eddyb

@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 20, 2017

Contributor

⌛️ Testing commit 4b95ca8 with merge 7eb64b8...

Contributor

bors commented Dec 20, 2017

⌛️ Testing commit 4b95ca8 with merge 7eb64b8...

bors added a commit that referenced this pull request Dec 20, 2017

Auto merge of #46583 - scottmcm:fix-static-i128-lower, r=eddyb
Fix -Z lower_128bit_ops handling of statics

Avoids ICEs such as the following:
>  error: internal compiler error: src\librustc_metadata\cstore_impl.rs:131:
>  get_optimized_mir: missing MIR for `DefId(8/0:40 ~
>  compiler_builtins[9532]::int[0]::addsub[0]::rust_i128_addo[0])`

r? @nagisa

cc #45676 @est31
@bors

This comment has been minimized.

Show comment
Hide comment
@bors

bors Dec 20, 2017

Contributor

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 7eb64b8 to master...

Contributor

bors commented Dec 20, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 7eb64b8 to master...

@bors bors merged commit 4b95ca8 into rust-lang:master Dec 20, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@scottmcm scottmcm deleted the scottmcm:fix-static-i128-lower branch Dec 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment