Skip to content

Commit

Permalink
rustc_trans: use ty::layout for ABI computation instead of LLVM types.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 21, 2017
1 parent b957df0 commit 6ac00de
Show file tree
Hide file tree
Showing 23 changed files with 1,001 additions and 1,690 deletions.
32 changes: 13 additions & 19 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,13 +1853,15 @@ impl<'a, 'tcx> TyLayout<'tcx> {
ty::TyInt(_) |
ty::TyUint(_) |
ty::TyFloat(_) |
ty::TyFnPtr(_) |
ty::TyNever |
ty::TyFnDef(..) |
ty::TyDynamic(..) => {
ty::TyFnPtr(_) => {
bug!("TyLayout::field_type({:?}): not applicable", self)
}

// ZSTs.
ty::TyNever |
ty::TyFnDef(..) |
ty::TyDynamic(..) => 0,

// Potentially-fat pointers.
ty::TyRef(..) |
ty::TyRawPtr(_) => {
Expand All @@ -1883,14 +1885,13 @@ impl<'a, 'tcx> TyLayout<'tcx> {

// ADTs.
ty::TyAdt(def, _) => {
let v = if def.is_enum() {
self.variant_index.expect("variant index required")
} else {
assert_eq!(self.variant_index, None);
let v = self.variant_index.unwrap_or(0);
if def.variants.is_empty() {
assert_eq!(v, 0);
0
};

def.variants[v].fields.len()
} else {
def.variants[v].fields.len()
}
}

ty::TyProjection(_) | ty::TyAnon(..) | ty::TyParam(_) |
Expand Down Expand Up @@ -1961,14 +1962,7 @@ impl<'a, 'tcx> TyLayout<'tcx> {

// ADTs.
ty::TyAdt(def, substs) => {
let v = if def.is_enum() {
self.variant_index.expect("variant index required")
} else {
assert_eq!(self.variant_index, None);
0
};

def.variants[v].fields[i].ty(tcx, substs)
def.variants[self.variant_index.unwrap_or(0)].fields[i].ty(tcx, substs)
}

ty::TyProjection(_) | ty::TyAnon(..) | ty::TyParam(_) |
Expand Down
Loading

0 comments on commit 6ac00de

Please sign in to comment.