Skip to content

Preliminary support for MIR in trans #29217

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 18 commits into from
Nov 4, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6d7c66e
Introduce a "liberated fn sigs" map so that we have easy access to this
nikomatsakis Oct 21, 2015
88a9c3e
Build the MIR using the liberated fn sigs, and track the return type
nikomatsakis Oct 21, 2015
1e30f3e
Change ShallowDrop to Free, so that it matches what trans will do
nikomatsakis Oct 21, 2015
15c1da4
Convert from using named fields to always using indices
nikomatsakis Oct 21, 2015
3c07b46
Pass the mir map to trans
nikomatsakis Oct 21, 2015
b5d3580
Move the "HAIR" code that reads the tcx tables etc out of the `tcx`
nikomatsakis Oct 21, 2015
3ab29d3
Add adt_def into Switch, since it's convenient to have in trans
nikomatsakis Oct 21, 2015
044096b
Change Call operands to be, well, Operands
nikomatsakis Oct 21, 2015
0a62158
Add helper methods that require tcx; these compute types of
nikomatsakis Oct 21, 2015
81ff2c2
Change adt case handling fn to be less tied to match
nikomatsakis Oct 21, 2015
877b93a
Move shifting code out of expr and into somewhere more accessible
nikomatsakis Oct 21, 2015
02017b3
New trans codepath that builds fn body from MIR instead.
nikomatsakis Oct 21, 2015
e84829d
Plumbing to omit allocas for temps when possible (currently unused)
nikomatsakis Nov 2, 2015
544b06d
Add a MIR visitor
nikomatsakis Nov 3, 2015
6a5b263
Add (and use) an analysis to determine which temps can forgo an alloca.
nikomatsakis Nov 3, 2015
9c9f4be
correct typos
nikomatsakis Nov 3, 2015
b46c0fc
address nits from dotdash
nikomatsakis Nov 3, 2015
e787863
remove unused import
nikomatsakis Nov 4, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert from using named fields to always using indices
  • Loading branch information
nikomatsakis committed Nov 3, 2015
commit 15c1da4e27587951a8806b6485a8051103019a02
7 changes: 7 additions & 0 deletions src/librustc/middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,13 @@ impl<'tcx, 'container> VariantDefData<'tcx, 'container> {
self.fields.iter().find(|f| f.name == name)
}

#[inline]
pub fn index_of_field_named(&self,
name: ast::Name)
-> Option<usize> {
self.fields.iter().position(|f| f.name == name)
}

#[inline]
pub fn field_named(&self, name: ast::Name) -> &FieldDefData<'tcx, 'container> {
self.find_field_named(name).unwrap()
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,19 @@ impl<'a,'tcx> Builder<'a,'tcx> {
block.and(Rvalue::Aggregate(AggregateKind::Closure(closure_id, substs), upvars))
}
ExprKind::Adt { adt_def, variant_index, substs, fields, base } => { // see (*) above
// first process the set of fields
// first process the set of fields that were provided
// (evaluating them in order given by user)
let fields_map: FnvHashMap<_, _> =
fields.into_iter()
.map(|f| (f.name, unpack!(block = this.as_operand(block, f.expr))))
.collect();

let field_names = this.hir.fields(adt_def, variant_index);

// if base expression is given, evaluate it now
let base = base.map(|base| unpack!(block = this.as_lvalue(block, base)));

// get list of all fields that we will need
let field_names = this.hir.all_fields(adt_def, variant_index);

// for the actual values we use, take either the
// expr the user specified or, if they didn't
// specify something for this field name, create a
Expand Down
21 changes: 14 additions & 7 deletions src/librustc_mir/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,19 @@ pub type LvalueProjection<'tcx> =
pub type LvalueElem<'tcx> =
ProjectionElem<'tcx,Operand<'tcx>>;

/// Index into the list of fields found in a `VariantDef`
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Field {
Named(Name),
Indexed(usize),
pub struct Field(u32);

impl Field {
pub fn new(value: usize) -> Field {
assert!(value < (u32::MAX) as usize);
Field(value as u32)
}

pub fn index(self) -> usize {
self.0 as usize
}
}

impl<'tcx> Lvalue<'tcx> {
Expand Down Expand Up @@ -491,10 +500,8 @@ impl<'tcx> Debug for Lvalue<'tcx> {
write!(fmt,"({:?} as {:?})", data.base, variant_index),
ProjectionElem::Deref =>
write!(fmt,"(*{:?})", data.base),
ProjectionElem::Field(Field::Named(name)) =>
write!(fmt,"{:?}.{:?}", data.base, name),
ProjectionElem::Field(Field::Indexed(index)) =>
write!(fmt,"{:?}.{:?}", data.base, index),
ProjectionElem::Field(field) =>
write!(fmt,"{:?}.{:?}", data.base, field.index()),
ProjectionElem::Index(ref index) =>
write!(fmt,"{:?}[{:?}]", data.base, index),
ProjectionElem::ConstantIndex { offset, min_length, from_end: false } =>
Expand Down