Skip to content

Commit 76aabbe

Browse files
committed
Rename tag to enum throughout the compiler
This should reduce confusion of people trying to read the code.
1 parent 8420f8c commit 76aabbe

27 files changed

+314
-329
lines changed

src/comp/metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const tag_items_data_item_symbol: uint = 0x0du;
3030

3131
const tag_items_data_item_variant: uint = 0x0eu;
3232

33-
const tag_items_data_item_tag_id: uint = 0x0fu;
33+
const tag_items_data_item_enum_id: uint = 0x0fu;
3434

3535
const tag_index: uint = 0x11u;
3636

src/comp/metadata/csearch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import driver::session;
99
export get_symbol;
1010
export get_type_param_count;
1111
export lookup_defs;
12-
export get_tag_variants;
12+
export get_enum_variants;
1313
export get_impls_for_mod;
1414
export get_iface_methods;
1515
export get_type;
@@ -56,10 +56,10 @@ fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num,
5656
ret result;
5757
}
5858

59-
fn get_tag_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
59+
fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] {
6060
let cstore = tcx.sess.cstore;
6161
let cdata = cstore::get_crate_data(cstore, def.crate);
62-
ret decoder::get_tag_variants(cdata, def.node, tcx)
62+
ret decoder::get_enum_variants(cdata, def.node, tcx)
6363
}
6464

6565
fn get_impls_for_mod(cstore: cstore::cstore, def: ast::def_id,

src/comp/metadata/decoder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import syntax::print::pprust;
1111
import cmd=cstore::crate_metadata;
1212

1313
export get_symbol;
14-
export get_tag_variants;
14+
export get_enum_variants;
1515
export get_type;
1616
export get_type_param_count;
1717
export get_impl_iface;
@@ -86,8 +86,8 @@ fn item_symbol(item: ebml::doc) -> str {
8686
ret str::unsafe_from_bytes(ebml::doc_data(sym));
8787
}
8888

89-
fn variant_tag_id(d: ebml::doc) -> ast::def_id {
90-
let tagdoc = ebml::get_doc(d, tag_items_data_item_tag_id);
89+
fn variant_enum_id(d: ebml::doc) -> ast::def_id {
90+
let tagdoc = ebml::get_doc(d, tag_items_data_item_enum_id);
9191
ret parse_def_id(ebml::doc_data(tagdoc));
9292
}
9393

@@ -147,7 +147,7 @@ fn item_ty_param_count(item: ebml::doc) -> uint {
147147
n
148148
}
149149

150-
fn tag_variant_ids(item: ebml::doc, cdata: cmd) -> [ast::def_id] {
150+
fn enum_variant_ids(item: ebml::doc, cdata: cmd) -> [ast::def_id] {
151151
let ids: [ast::def_id] = [];
152152
let v = tag_items_data_item_variant;
153153
ebml::tagged_docs(item, v) {|p|
@@ -189,7 +189,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
189189
let item = lookup_item(did_.node, data);
190190
let fam_ch = item_family(item);
191191
let did = {crate: cnum, node: did_.node};
192-
// We treat references to tags as references to types.
192+
// We treat references to enums as references to types.
193193
let def =
194194
alt fam_ch as char {
195195
'c' { ast::def_const(did) }
@@ -205,7 +205,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
205205
'm' { ast::def_mod(did) }
206206
'n' { ast::def_native_mod(did) }
207207
'v' {
208-
let tid = variant_tag_id(item);
208+
let tid = variant_enum_id(item);
209209
tid = {crate: cnum, node: tid.node};
210210
ast::def_variant(tid, did)
211211
}
@@ -237,13 +237,13 @@ fn get_symbol(data: @[u8], id: ast::node_id) -> str {
237237
ret item_symbol(lookup_item(id, data));
238238
}
239239

240-
fn get_tag_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
240+
fn get_enum_variants(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
241241
-> [ty::variant_info] {
242242
let data = cdata.data;
243243
let items = ebml::get_doc(ebml::new_doc(data), tag_items);
244244
let item = find_item(id, items);
245245
let infos: [ty::variant_info] = [];
246-
let variant_ids = tag_variant_ids(item, cdata);
246+
let variant_ids = enum_variant_ids(item, cdata);
247247
let disr_val = 0;
248248
for did: ast::def_id in variant_ids {
249249
let item = find_item(did.node, items);

src/comp/metadata/encoder.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn encode_def_id(ebml_w: ebml::writer, id: def_id) {
3333

3434
type entry<T> = {val: T, pos: uint};
3535

36-
fn encode_tag_variant_paths(ebml_w: ebml::writer, variants: [variant],
36+
fn encode_enum_variant_paths(ebml_w: ebml::writer, variants: [variant],
3737
path: [str], &index: [entry<str>]) {
3838
for variant: variant in variants {
3939
add_to_index(ebml_w, path, index, variant.node.name);
@@ -118,13 +118,13 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
118118
encode_def_id(ebml_w, local_def(it.id));
119119
ebml::end_tag(ebml_w);
120120
}
121-
item_tag(variants, tps) {
121+
item_enum(variants, tps) {
122122
add_to_index(ebml_w, path, index, it.ident);
123123
ebml::start_tag(ebml_w, tag_paths_data_item);
124124
encode_name(ebml_w, it.ident);
125125
encode_def_id(ebml_w, local_def(it.id));
126126
ebml::end_tag(ebml_w);
127-
encode_tag_variant_paths(ebml_w, variants, path, index);
127+
encode_enum_variant_paths(ebml_w, variants, path, index);
128128
}
129129
item_iface(_, _) {
130130
add_to_index(ebml_w, path, index, it.ident);
@@ -222,25 +222,25 @@ fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: ebml::writer, disr_val: int) {
222222
ebml::end_tag(ebml_w);
223223
}
224224

225-
fn encode_tag_id(ebml_w: ebml::writer, id: def_id) {
226-
ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
225+
fn encode_enum_id(ebml_w: ebml::writer, id: def_id) {
226+
ebml::start_tag(ebml_w, tag_items_data_item_enum_id);
227227
ebml_w.writer.write(str::bytes(def_to_str(id)));
228228
ebml::end_tag(ebml_w);
229229
}
230230

231-
fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
231+
fn encode_enum_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer,
232232
id: node_id, variants: [variant],
233233
&index: [entry<int>], ty_params: [ty_param]) {
234234
let disr_val = 0;
235235
let i = 0;
236-
let vi = ty::tag_variants(ecx.ccx.tcx, {crate: local_crate, node: id});
236+
let vi = ty::enum_variants(ecx.ccx.tcx, {crate: local_crate, node: id});
237237
for variant: variant in variants {
238238
index += [{val: variant.node.id, pos: ebml_w.writer.tell()}];
239239
ebml::start_tag(ebml_w, tag_items_data_item);
240240
encode_def_id(ebml_w, local_def(variant.node.id));
241241
encode_family(ebml_w, 'v' as u8);
242242
encode_name(ebml_w, variant.node.name);
243-
encode_tag_id(ebml_w, local_def(id));
243+
encode_enum_id(ebml_w, local_def(id));
244244
encode_type(ecx, ebml_w,
245245
node_id_to_monotype(ecx.ccx.tcx, variant.node.id));
246246
if vec::len::<variant_arg>(variant.node.args) > 0u {
@@ -324,7 +324,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
324324
encode_name(ebml_w, item.ident);
325325
ebml::end_tag(ebml_w);
326326
}
327-
item_tag(variants, tps) {
327+
item_enum(variants, tps) {
328328
ebml::start_tag(ebml_w, tag_items_data_item);
329329
encode_def_id(ebml_w, local_def(item.id));
330330
encode_family(ebml_w, 't' as u8);
@@ -335,7 +335,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
335335
encode_variant_id(ebml_w, local_def(v.node.id));
336336
}
337337
ebml::end_tag(ebml_w);
338-
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
338+
encode_enum_variant_info(ecx, ebml_w, item.id, variants, index, tps);
339339
}
340340
item_res(_, tps, _, _, ctor_id) {
341341
let fn_ty = node_id_to_monotype(tcx, ctor_id);

src/comp/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
202202
let params: [ty::t] = [];
203203
while peek(st) as char != ']' { params += [parse_ty(st, conv)]; }
204204
st.pos = st.pos + 1u;
205-
ret ty::mk_tag(st.tcx, def, params);
205+
ret ty::mk_enum(st.tcx, def, params);
206206
}
207207
'x' {
208208
assert (next(st) as char == '[');

src/comp/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
117117
}
118118
}
119119
ty::ty_str { w.write_char('S'); }
120-
ty::ty_tag(def, tys) {
120+
ty::ty_enum(def, tys) {
121121
w.write_str("t[");
122122
w.write_str(cx.ds(def));
123123
w.write_char('|');

src/comp/middle/alias.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ fn ty_can_unsafely_include(cx: ctx, needle: unsafe_ty, haystack: ty::t,
502502
mut_contains(ty) { mut && ty == haystack }
503503
} { ret true; }
504504
alt ty::struct(tcx, haystack) {
505-
ty::ty_tag(_, ts) {
505+
ty::ty_enum(_, ts) {
506506
for t: ty::t in ts {
507507
if helper(tcx, needle, t, mut) { ret true; }
508508
}
@@ -565,7 +565,7 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
565565
ty::ty_fn(_) | ty::ty_native_fn(_, _) { 4u }
566566
ty::ty_str | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
567567
ty::ty_uniq(mt) { 1u + score_ty(tcx, mt.ty) }
568-
ty::ty_tag(_, ts) | ty::ty_tup(ts) {
568+
ty::ty_enum(_, ts) | ty::ty_tup(ts) {
569569
let sum = 0u;
570570
for t in ts { sum += score_ty(tcx, t); }
571571
sum
@@ -596,7 +596,7 @@ fn pattern_roots(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat)
596596
span: pat.span}];
597597
alt sub { some(p) { walk(tcx, mut, p, set); } _ {} }
598598
}
599-
ast::pat_tag(_, ps) | ast::pat_tup(ps) {
599+
ast::pat_enum(_, ps) | ast::pat_tup(ps) {
600600
for p in ps { walk(tcx, mut, p, set); }
601601
}
602602
ast::pat_rec(fs, _) {

src/comp/middle/check_alt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ fn pattern_supersedes(tcx: ty::ctxt, a: @pat, b: @pat) -> bool {
8080
_ { false }
8181
}
8282
}
83-
pat_tag(va, suba) {
83+
pat_enum(va, suba) {
8484
alt b.node {
85-
pat_tag(vb, subb) {
85+
pat_enum(vb, subb) {
8686
tcx.def_map.get(a.id) == tcx.def_map.get(b.id) &&
8787
patterns_supersede(tcx, suba, subb)
8888
}
@@ -154,9 +154,9 @@ fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
154154
for elt in elts { if is_refutable(tcx, elt) { ret true; } }
155155
false
156156
}
157-
pat_tag(_, args) {
157+
pat_enum(_, args) {
158158
let vdef = variant_def_ids(tcx.def_map.get(pat.id));
159-
if vec::len(*ty::tag_variants(tcx, vdef.tg)) != 1u { ret true; }
159+
if vec::len(*ty::enum_variants(tcx, vdef.tg)) != 1u { ret true; }
160160
for p: @pat in args { if is_refutable(tcx, p) { ret true; } }
161161
false
162162
}

src/comp/middle/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn check_crate(sess: session, crate: @crate) {
1515
fn check_item(it: @item, &&_is_const: bool, v: visit::vt<bool>) {
1616
alt it.node {
1717
item_const(_, ex) { v.visit_expr(ex, true, v); }
18-
item_tag(vs, _) {
18+
item_enum(vs, _) {
1919
for var in vs {
2020
option::may(var.node.disr_expr) {|ex|
2121
v.visit_expr(ex, true, v);

src/comp/middle/gc.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
108108
ty::ty_type | ty::ty_ptr(_) | ty::ty_native(_) {
109109
ret false;
110110
}
111-
112-
113-
114-
115-
116111
ty::ty_rec(fields) {
117112
for f in fields { if type_is_gc_relevant(cx, f.mt.ty) { ret true; } }
118113
ret false;
@@ -121,13 +116,8 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
121116
for elt in elts { if type_is_gc_relevant(cx, elt) { ret true; } }
122117
ret false;
123118
}
124-
125-
126-
127-
128-
129-
ty::ty_tag(did, tps) {
130-
let variants = ty::tag_variants(cx, did);
119+
ty::ty_enum(did, tps) {
120+
let variants = ty::enum_variants(cx, did);
131121
for variant in *variants {
132122
for aty in variant.args {
133123
let arg_ty = ty::substitute_type_params(cx, tps, aty);
@@ -136,11 +126,6 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
136126
}
137127
ret false;
138128
}
139-
140-
141-
142-
143-
144129
ty::ty_vec(tm) {
145130
ret type_is_gc_relevant(cx, tm.ty);
146131
}

src/comp/middle/mut.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
3131
ds += [@{mut: false, kind: unbox, outer_t: t}];
3232
t = ty::substitute_type_params(tcx, tps, inner);
3333
}
34-
ty::ty_tag(did, tps) {
35-
let variants = ty::tag_variants(tcx, did);
34+
ty::ty_enum(did, tps) {
35+
let variants = ty::enum_variants(tcx, did);
3636
if vec::len(*variants) != 1u ||
3737
vec::len(variants[0].args) != 1u {
3838
break;
@@ -90,7 +90,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
9090
ty::ty_box(mt) { is_mut = mt.mut == mut; }
9191
ty::ty_uniq(mt) { is_mut = mt.mut == mut; }
9292
ty::ty_res(_, _, _) { }
93-
ty::ty_tag(_, _) { }
93+
ty::ty_enum(_, _) { }
9494
ty::ty_ptr(mt) { is_mut = mt.mut == mut; }
9595
}
9696
ds += [@{mut: is_mut, kind: unbox, outer_t: base_t}];

src/comp/middle/pat_util.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ fn normalize_pat_def_map(dm: resolve::def_map, p: @pat) -> @pat {
2222
@{node: pat_ident(q, some(normalize_pat_def_map(dm, r)))
2323
with *p}
2424
}
25-
pat_tag(a_path, subs) {
26-
@{node: pat_tag(a_path,
25+
pat_enum(a_path, subs) {
26+
@{node: pat_enum(a_path,
2727
vec::map(subs, {|p| normalize_pat_def_map(dm, p)})) with *p}
2828
}
2929
pat_rec(field_pats, b) {
@@ -52,8 +52,8 @@ fn normalize_one(dm: resolve::def_map, p: @pat) -> @pat {
5252
alt dm.find(p.id) {
5353
some(d) {
5454
alt p.node {
55-
pat_ident(tag_path, _) { @{id: p.id,
56-
node: pat_tag(tag_path, []),
55+
pat_ident(enum_path, _) { @{id: p.id,
56+
node: pat_enum(enum_path, []),
5757
span: p.span} }
5858
_ { p }
5959
}
@@ -95,7 +95,7 @@ fn pat_bindings(pat: @pat, it: fn(@pat)) {
9595
alt pat.node {
9696
pat_ident(_, option::none) { it(pat); }
9797
pat_ident(_, option::some(sub)) { it(pat); pat_bindings(sub, it); }
98-
pat_tag(_, sub) { for p in sub { pat_bindings(p, it); } }
98+
pat_enum(_, sub) { for p in sub { pat_bindings(p, it); } }
9999
pat_rec(fields, _) { for f in fields { pat_bindings(f.pat, it); } }
100100
pat_tup(elts) { for elt in elts { pat_bindings(elt, it); } }
101101
pat_box(sub) { pat_bindings(sub, it); }

0 commit comments

Comments
 (0)