-
Notifications
You must be signed in to change notification settings - Fork 13.6k
ScalarPairs are offset==0 field + other non-zst field #51307
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ use rustc::ty::layout::LayoutOf; | |
use syntax::codemap::Span; | ||
use rustc_target::spec::abi::Abi; | ||
|
||
use rustc::mir::interpret::{EvalResult, Scalar, Value}; | ||
use rustc::mir::interpret::{EvalResult, Value}; | ||
use super::{EvalContext, Place, Machine, ValTy}; | ||
|
||
use rustc_data_structures::indexed_vec::Idx; | ||
|
@@ -338,65 +338,39 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { | |
|
||
// unpack and write all other args | ||
let layout = self.layout_of(args[1].ty)?; | ||
if let ty::TyTuple(..) = args[1].ty.sty { | ||
if let ty::TyTuple(_) = args[1].ty.sty { | ||
if layout.is_zst() { | ||
// Nothing to do, no need to unpack zsts | ||
return Ok(()); | ||
} | ||
if self.frame().mir.args_iter().count() == layout.fields.count() + 1 { | ||
match args[1].value { | ||
Value::ByRef(ptr, align) => { | ||
for (i, arg_local) in arg_locals.enumerate() { | ||
let field = layout.field(&self, i)?; | ||
let offset = layout.fields.offset(i); | ||
let arg = Value::ByRef(ptr.ptr_offset(offset, &self)?, | ||
align.min(field.align)); | ||
let dest = | ||
self.eval_place(&mir::Place::Local(arg_local))?; | ||
trace!( | ||
"writing arg {:?} to {:?} (type: {})", | ||
arg, | ||
dest, | ||
field.ty | ||
); | ||
let valty = ValTy { | ||
value: arg, | ||
ty: field.ty, | ||
}; | ||
self.write_value(valty, dest)?; | ||
} | ||
} | ||
Value::Scalar(Scalar::Bits { defined: 0, .. }) => {} | ||
other => { | ||
trace!("{:#?}, {:#?}", other, layout); | ||
let mut layout = layout; | ||
'outer: loop { | ||
for i in 0..layout.fields.count() { | ||
let field = layout.field(&self, i)?; | ||
if layout.fields.offset(i).bytes() == 0 && layout.size == field.size { | ||
layout = field; | ||
continue 'outer; | ||
} | ||
} | ||
break; | ||
} | ||
{ | ||
let mut write_next = |value| { | ||
let dest = self.eval_place(&mir::Place::Local( | ||
arg_locals.next().unwrap(), | ||
))?; | ||
let valty = ValTy { | ||
value: Value::Scalar(value), | ||
ty: layout.ty, | ||
}; | ||
self.write_value(valty, dest) | ||
}; | ||
match other { | ||
Value::Scalar(value) | Value::ScalarPair(value, _) => write_next(value)?, | ||
_ => unreachable!(), | ||
} | ||
if let Value::ScalarPair(_, value) = other { | ||
write_next(value)?; | ||
} | ||
} | ||
assert!(arg_locals.next().is_none()); | ||
for (i, arg_local) in arg_locals.enumerate() { | ||
let field = layout.field(&self, i)?; | ||
if field.is_zst() { | ||
continue; | ||
} | ||
let offset = layout.fields.offset(i); | ||
let value = match args[1].value { | ||
Value::ByRef(ptr, align) => Value::ByRef( | ||
ptr.ptr_offset(offset, &self)?, | ||
align.min(field.align), | ||
), | ||
other if field.size == layout.size => { | ||
// this is the case where the field covers the entire type | ||
assert_eq!(offset.bytes(), 0); | ||
other | ||
}, | ||
Value::ScalarPair(a, _) if offset.bytes() == 0 => Value::Scalar(a), | ||
Value::ScalarPair(_, b) => Value::Scalar(b), | ||
Value::Scalar(_) => bug!("Scalar does not cover entire type"), | ||
}; | ||
let dest = | ||
self.eval_place(&mir::Place::Local(arg_local))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not do something like this for the source, too? |
||
let valty = ValTy { | ||
value, | ||
ty: field.ty, | ||
}; | ||
self.write_value(valty, dest)?; | ||
} | ||
} else { | ||
trace!("manual impl of rust-call ABI"); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ use rustc::ty::subst::Substs; | |
use rustc_data_structures::indexed_vec::IndexVec; | ||
use rustc::ty::ParamEnv; | ||
use rustc::ty::layout::{ | ||
LayoutOf, TyLayout, LayoutError, LayoutCx, | ||
LayoutOf, TyLayout, LayoutError, | ||
HasTyCtxt, TargetDataLayout, HasDataLayout, | ||
}; | ||
|
||
|
@@ -214,24 +214,10 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { | |
ProjectionElem::Field(field, _) => { | ||
trace!("field proj on {:?}", proj.base); | ||
let (base, ty, span) = self.eval_place(&proj.base)?; | ||
match base { | ||
Value::ScalarPair(a, b) => { | ||
trace!("by val pair: {:?}, {:?}", a, b); | ||
let base_layout = self.tcx.layout_of(self.param_env.and(ty)).ok()?; | ||
trace!("layout computed"); | ||
use rustc_data_structures::indexed_vec::Idx; | ||
let field_index = field.index(); | ||
let val = [a, b][field_index]; | ||
let cx = LayoutCx { | ||
tcx: self.tcx, | ||
param_env: self.param_env, | ||
}; | ||
let field = base_layout.field(cx, field_index).ok()?; | ||
trace!("projection resulted in: {:?}", val); | ||
Some((Value::Scalar(val), field.ty, span)) | ||
}, | ||
_ => None, | ||
} | ||
let (value, field_ty) = self.use_ecx(span, |this| { | ||
this.ecx.read_field(base, None, field, ty) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like this, maybe? |
||
})??; | ||
Some((value, field_ty, span)) | ||
}, | ||
_ => None, | ||
}, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-pass | ||
// https://github.com/rust-lang/rust/issues/51300 | ||
|
||
#[derive(PartialEq, Eq, Clone, Copy)] | ||
pub struct Stat { | ||
pub id: u8, | ||
pub index: usize, | ||
} | ||
|
||
impl Stat { | ||
pub const STUDENT_HAPPINESS: Stat = Stat{ | ||
id: 0, | ||
index: 0, | ||
}; | ||
pub const STUDENT_HUNGER: Stat = Stat{ | ||
id: 0, | ||
index: Self::STUDENT_HAPPINESS.index + 1, | ||
}; | ||
|
||
} | ||
|
||
pub fn from_index(id: u8, index: usize) -> Option<Stat> { | ||
let stat = Stat{id, index}; | ||
match stat { | ||
Stat::STUDENT_HAPPINESS => Some(Stat::STUDENT_HAPPINESS), | ||
Stat::STUDENT_HUNGER => Some(Stat::STUDENT_HUNGER), | ||
_ => None, | ||
} | ||
} | ||
|
||
fn main() { } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This comment is too specific.