Skip to content

Commit 1f9bc64

Browse files
committed
adt.rs renaming: "field" rather than "element"; set_discr -> start_init.
This way "field" refers to the abstraction and "element" (as in get_elt, "get element pointer", etc.) refers to the low-level LLVM operations.
1 parent e13111f commit 1f9bc64

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

src/librustc/middle/trans/_match.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ pub fn extract_variant_args(bcx: block,
838838
-> ExtractedBlock {
839839
let _icx = bcx.insn_ctxt("match::extract_variant_args");
840840
let args = do vec::from_fn(adt::num_args(repr, disr_val)) |i| {
841-
adt::trans_GEP(bcx, repr, val, disr_val, i)
841+
adt::trans_field_ptr(bcx, repr, val, disr_val, i)
842842
};
843843
844844
ExtractedBlock { vals: args, bcx: bcx }
@@ -1274,7 +1274,7 @@ pub fn compile_submatch(bcx: block,
12741274
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
12751275
let rec_vals = rec_fields.map(|field_name| {
12761276
let ix = ty::field_idx_strict(tcx, *field_name, field_tys);
1277-
adt::trans_GEP(bcx, pat_repr, val, discr, ix)
1277+
adt::trans_field_ptr(bcx, pat_repr, val, discr, ix)
12781278
});
12791279
compile_submatch(
12801280
bcx,
@@ -1293,7 +1293,7 @@ pub fn compile_submatch(bcx: block,
12931293
_ => ccx.sess.bug(~"non-tuple type in tuple pattern")
12941294
};
12951295
let tup_vals = do vec::from_fn(n_tup_elts) |i| {
1296-
adt::trans_GEP(bcx, tup_repr, val, 0, i)
1296+
adt::trans_field_ptr(bcx, tup_repr, val, 0, i)
12971297
};
12981298
compile_submatch(bcx, enter_tup(bcx, dm, m, col, val, n_tup_elts),
12991299
vec::append(tup_vals, vals_left), chk);
@@ -1315,7 +1315,7 @@ pub fn compile_submatch(bcx: block,
13151315
13161316
let struct_repr = adt::represent_type(bcx.ccx(), struct_ty);
13171317
let llstructvals = do vec::from_fn(struct_element_count) |i| {
1318-
adt::trans_GEP(bcx, struct_repr, val, 0, i)
1318+
adt::trans_field_ptr(bcx, struct_repr, val, 0, i)
13191319
};
13201320
compile_submatch(bcx,
13211321
enter_tuple_struct(bcx, dm, m, col, val,
@@ -1753,7 +1753,7 @@ pub fn bind_irrefutable_pat(bcx: block,
17531753
// This is the tuple struct case.
17541754
let repr = adt::represent_node(bcx, pat.id);
17551755
for vec::eachi(elems) |i, elem| {
1756-
let fldptr = adt::trans_GEP(bcx, repr,
1756+
let fldptr = adt::trans_field_ptr(bcx, repr,
17571757
val, 0, i);
17581758
bcx = bind_irrefutable_pat(bcx,
17591759
*elem,
@@ -1776,7 +1776,7 @@ pub fn bind_irrefutable_pat(bcx: block,
17761776
do expr::with_field_tys(tcx, pat_ty, None) |discr, field_tys| {
17771777
for vec::each(fields) |f| {
17781778
let ix = ty::field_idx_strict(tcx, f.ident, field_tys);
1779-
let fldptr = adt::trans_GEP(bcx, pat_repr, val,
1779+
let fldptr = adt::trans_field_ptr(bcx, pat_repr, val,
17801780
discr, ix);
17811781
bcx = bind_irrefutable_pat(bcx,
17821782
f.pat,
@@ -1789,7 +1789,7 @@ pub fn bind_irrefutable_pat(bcx: block,
17891789
ast::pat_tup(elems) => {
17901790
let repr = adt::represent_node(bcx, pat.id);
17911791
for vec::eachi(elems) |i, elem| {
1792-
let fldptr = adt::trans_GEP(bcx, repr, val, 0, i);
1792+
let fldptr = adt::trans_field_ptr(bcx, repr, val, 0, i);
17931793
bcx = bind_irrefutable_pat(bcx,
17941794
*elem,
17951795
fldptr,

src/librustc/middle/trans/adt.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,10 @@ pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
301301

302302
/**
303303
* Begin initializing a new value of the given case of the given
304-
* representation. The fields should then be initialized with
305-
* `trans_GEP` and stores.
304+
* representation. The fields, if any, should then be initialized via
305+
* `trans_field_ptr`.
306306
*/
307-
pub fn trans_set_discr(bcx: block, r: &Repr, val: ValueRef, discr: int) {
307+
pub fn trans_start_init(bcx: block, r: &Repr, val: ValueRef, discr: int) {
308308
match *r {
309309
Unit(the_discr) => {
310310
assert discr == the_discr;
@@ -339,8 +339,8 @@ pub fn num_args(r: &Repr, discr: int) -> uint {
339339
}
340340

341341
/// Access a field, at a point when the value's case is known.
342-
pub fn trans_GEP(bcx: block, r: &Repr, val: ValueRef, discr: int, ix: uint)
343-
-> ValueRef {
342+
pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
343+
ix: uint) -> ValueRef {
344344
// Note: if this ever needs to generate conditionals (e.g., if we
345345
// decide to do some kind of cdr-coding-like non-unique repr
346346
// someday), it will need to return a possibly-new bcx as well.
@@ -354,16 +354,16 @@ pub fn trans_GEP(bcx: block, r: &Repr, val: ValueRef, discr: int, ix: uint)
354354
NonStruct => val,
355355
StructWithDtor | StructWithoutDtor => GEPi(bcx, val, [0, 0])
356356
};
357-
struct_GEP(bcx, st, val, ix, false)
357+
struct_field_ptr(bcx, st, val, ix, false)
358358
}
359359
General(ref cases) => {
360-
struct_GEP(bcx, &cases[discr as uint],
361-
GEPi(bcx, val, [0, 1]), ix, true)
360+
struct_field_ptr(bcx, &cases[discr as uint],
361+
GEPi(bcx, val, [0, 1]), ix, true)
362362
}
363363
}
364364
}
365365

366-
fn struct_GEP(bcx: block, st: &Struct, val: ValueRef, ix: uint,
366+
fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
367367
needs_cast: bool) -> ValueRef {
368368
let ccx = bcx.ccx();
369369

@@ -501,10 +501,15 @@ pub fn const_get_discrim(ccx: @CrateContext, r: &Repr, val: ValueRef)
501501
}
502502
}
503503

504-
/// Access a field of a constant value.
505-
pub fn const_get_element(ccx: @CrateContext, r: &Repr, val: ValueRef,
506-
_discr: int, ix: uint) -> ValueRef {
507-
// Not to be confused with common::const_get_elt.
504+
/**
505+
* Extract a field of a constant value, as appropriate for its
506+
* representation.
507+
*
508+
* (Not to be confused with `common::const_get_elt`, which operates on
509+
* raw LLVM-level structs and arrays.)
510+
*/
511+
pub fn const_get_field(ccx: @CrateContext, r: &Repr, val: ValueRef,
512+
_discr: int, ix: uint) -> ValueRef {
508513
match *r {
509514
Unit(*) | CEnum(*) => ccx.sess.bug(~"element access in C-like enum \
510515
const"),

src/librustc/middle/trans/base.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
630630
let mut cx = cx;
631631

632632
for variant.args.eachi |i, &arg| {
633-
cx = f(cx, adt::trans_GEP(cx, repr, av, variant.disr_val, i),
633+
cx = f(cx,
634+
adt::trans_field_ptr(cx, repr, av, variant.disr_val, i),
634635
ty::subst_tps(tcx, tps, None, arg));
635636
}
636637
return cx;
@@ -642,7 +643,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
642643
let repr = adt::represent_type(cx.ccx(), t);
643644
do expr::with_field_tys(cx.tcx(), t, None) |discr, field_tys| {
644645
for vec::eachi(field_tys) |i, field_ty| {
645-
let llfld_a = adt::trans_GEP(cx, repr, av, discr, i);
646+
let llfld_a = adt::trans_field_ptr(cx, repr, av, discr, i);
646647
cx = f(cx, llfld_a, field_ty.mt.ty);
647648
}
648649
}
@@ -655,7 +656,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
655656
ty::ty_tup(args) => {
656657
let repr = adt::represent_type(cx.ccx(), t);
657658
for vec::eachi(args) |i, arg| {
658-
let llfld_a = adt::trans_GEP(cx, repr, av, 0, i);
659+
let llfld_a = adt::trans_field_ptr(cx, repr, av, 0, i);
659660
cx = f(cx, llfld_a, *arg);
660661
}
661662
}
@@ -1864,9 +1865,10 @@ pub fn trans_enum_variant(ccx: @CrateContext,
18641865
ty::node_id_to_type(ccx.tcx, enum_id));
18651866
let repr = adt::represent_type(ccx, enum_ty);
18661867

1867-
adt::trans_set_discr(bcx, repr, fcx.llretptr, disr);
1868+
adt::trans_start_init(bcx, repr, fcx.llretptr, disr);
18681869
for vec::eachi(args) |i, va| {
1869-
let lldestptr = adt::trans_GEP(bcx, repr, fcx.llretptr, disr, i);
1870+
let lldestptr = adt::trans_field_ptr(bcx, repr, fcx.llretptr,
1871+
disr, i);
18701872

18711873
// If this argument to this function is a enum, it'll have come in to
18721874
// this function as an opaque blob due to the way that type_of()
@@ -1936,7 +1938,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
19361938
let repr = adt::represent_type(ccx, tup_ty);
19371939
19381940
for fields.eachi |i, field| {
1939-
let lldestptr = adt::trans_GEP(bcx, repr, fcx.llretptr, 0, i);
1941+
let lldestptr = adt::trans_field_ptr(bcx, repr, fcx.llretptr, 0, i);
19401942
let llarg = match fcx.llargs.get(&field.node.id) {
19411943
local_mem(x) => x,
19421944
_ => {

src/librustc/middle/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn const_expr_unchecked(cx: @CrateContext, e: @ast::expr) -> ValueRef {
245245
let (bt, bv) = const_autoderef(cx, bt, bv);
246246
do expr::with_field_tys(cx.tcx, bt, None) |discr, field_tys| {
247247
let ix = ty::field_idx_strict(cx.tcx, field, field_tys);
248-
adt::const_get_element(cx, brepr, bv, discr, ix)
248+
adt::const_get_field(cx, brepr, bv, discr, ix)
249249
}
250250
}
251251

src/librustc/middle/trans/datum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ pub impl Datum {
687687
// rather than a ptr to the enum type.
688688
(
689689
Some(Datum {
690-
val: adt::trans_GEP(bcx, repr, self.val,
690+
val: adt::trans_field_ptr(bcx, repr, self.val,
691691
0, 0),
692692
ty: ty,
693693
mode: ByRef,
@@ -729,7 +729,7 @@ pub impl Datum {
729729
// destructors.
730730
(
731731
Some(Datum {
732-
val: adt::trans_GEP(bcx, repr, self.val,
732+
val: adt::trans_field_ptr(bcx, repr, self.val,
733733
0, 0),
734734
ty: ty,
735735
mode: ByRef,

src/librustc/middle/trans/expr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,8 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr,
726726
// Nullary variant.
727727
let ty = expr_ty(bcx, ref_expr);
728728
let repr = adt::represent_type(ccx, ty);
729-
adt::trans_set_discr(bcx, repr, lldest,
730-
variant_info.disr_val);
729+
adt::trans_start_init(bcx, repr, lldest,
730+
variant_info.disr_val);
731731
return bcx;
732732
}
733733
}
@@ -891,7 +891,7 @@ fn trans_lvalue_unadjusted(bcx: block, expr: @ast::expr) -> DatumBlock {
891891
datum: do base_datum.get_element(bcx,
892892
field_tys[ix].mt.ty,
893893
ZeroMem) |srcval| {
894-
adt::trans_GEP(bcx, repr, srcval, discr, ix)
894+
adt::trans_field_ptr(bcx, repr, srcval, discr, ix)
895895
},
896896
bcx: bcx
897897
}
@@ -1240,9 +1240,9 @@ fn trans_adt(bcx: block, repr: &adt::Repr, discr: int,
12401240
SaveIn(pos) => pos
12411241
};
12421242
let mut temp_cleanups = ~[];
1243-
adt::trans_set_discr(bcx, repr, addr, discr);
1243+
adt::trans_start_init(bcx, repr, addr, discr);
12441244
for fields.each |&(i, e)| {
1245-
let dest = adt::trans_GEP(bcx, repr, addr, discr, i);
1245+
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
12461246
let e_ty = expr_ty(bcx, e);
12471247
bcx = trans_into(bcx, e, SaveIn(dest));
12481248
add_clean_temp_mem(bcx, dest, e_ty);
@@ -1254,9 +1254,9 @@ fn trans_adt(bcx: block, repr: &adt::Repr, discr: int,
12541254
let base_datum = unpack_datum!(bcx, trans_to_datum(bcx, base.expr));
12551255
for base.fields.each |&(i, t)| {
12561256
let datum = do base_datum.get_element(bcx, t, ZeroMem) |srcval| {
1257-
adt::trans_GEP(bcx, repr, srcval, discr, i)
1257+
adt::trans_field_ptr(bcx, repr, srcval, discr, i)
12581258
};
1259-
let dest = adt::trans_GEP(bcx, repr, addr, discr, i);
1259+
let dest = adt::trans_field_ptr(bcx, repr, addr, discr, i);
12601260
bcx = datum.store_to(bcx, base.expr.id, INIT, dest);
12611261
}
12621262
}

src/librustc/middle/trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ pub fn trans_struct_drop(bcx: block,
507507
ty::struct_mutable_fields(bcx.tcx(), class_did,
508508
substs);
509509
for vec::eachi(field_tys) |i, fld| {
510-
let llfld_a = adt::trans_GEP(bcx, repr, v0, 0, i);
510+
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
511511
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
512512
}
513513

0 commit comments

Comments
 (0)