Skip to content

Commit 0046ed9

Browse files
committed
Remove un-needed code for obsolete classes
and rename "class" to "struct" everywhere possible (except local vars, I was too lazy for that) -- that is why this commit is so big. No review, just dead code removal and renaming. Closes #3515
1 parent 3fcdb7d commit 0046ed9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+392
-668
lines changed

src/librustc/metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const tag_path_len: uint = 0x41u;
8484
const tag_path_elt_mod: uint = 0x42u;
8585
const tag_path_elt_name: uint = 0x43u;
8686
const tag_item_field: uint = 0x44u;
87-
const tag_class_mut: uint = 0x45u;
87+
const tag_struct_mut: uint = 0x45u;
8888

8989
const tag_region_param: uint = 0x46u;
9090
const tag_mod_impl_trait: uint = 0x47u;

src/librustc/metadata/csearch.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ use common::*;
2424
use std::map::HashMap;
2525
use dvec::DVec;
2626

27-
export class_dtor;
27+
export struct_dtor;
2828
export get_symbol;
29-
export get_class_fields;
30-
export get_class_method;
29+
export get_struct_fields;
3130
export get_field_type;
3231
export get_type_param_count;
3332
export get_region_param;
@@ -170,10 +169,10 @@ fn get_item_attrs(cstore: cstore::CStore,
170169
decoder::get_item_attrs(cdata, def_id.node, f)
171170
}
172171

173-
fn get_class_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
172+
fn get_struct_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
174173
let cstore = tcx.cstore;
175174
let cdata = cstore::get_crate_data(cstore, def.crate);
176-
decoder::get_class_fields(cstore.intr, cdata, def.node)
175+
decoder::get_struct_fields(cstore.intr, cdata, def.node)
177176
}
178177

179178
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty {
@@ -226,22 +225,11 @@ fn get_impl_method(cstore: cstore::CStore,
226225
decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
227226
}
228227

229-
/* Because classes use the trait format rather than the impl format
230-
for their methods (so that get_trait_methods can be reused to get
231-
class methods), classes require a slightly different version of
232-
get_impl_method. Sigh. */
233-
fn get_class_method(cstore: cstore::CStore,
234-
def: ast::def_id, mname: ast::ident)
235-
-> ast::def_id {
236-
let cdata = cstore::get_crate_data(cstore, def.crate);
237-
decoder::get_class_method(cstore.intr, cdata, def.node, mname)
238-
}
239-
240228
/* If def names a class with a dtor, return it. Otherwise, return none. */
241-
fn class_dtor(cstore: cstore::CStore, def: ast::def_id)
229+
fn struct_dtor(cstore: cstore::CStore, def: ast::def_id)
242230
-> Option<ast::def_id> {
243231
let cdata = cstore::get_crate_data(cstore, def.crate);
244-
decoder::class_dtor(cdata, def.node)
232+
decoder::struct_dtor(cdata, def.node)
245233
}
246234
// Local Variables:
247235
// mode: rust

src/librustc/metadata/decoder.rs

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ use syntax::parse::token::ident_interner;
3232
use hash::{Hash, HashUtil};
3333
use csearch::{ProvidedTraitMethodInfo, StaticMethodInfo};
3434

35-
export class_dtor;
36-
export get_class_fields;
35+
export struct_dtor;
36+
export get_struct_fields;
3737
export get_symbol;
3838
export get_enum_variants;
3939
export get_type;
4040
export get_region_param;
4141
export get_type_param_count;
4242
export get_impl_traits;
43-
export get_class_method;
4443
export get_impl_method;
4544
export get_static_methods_if_impl;
4645
export lookup_def;
@@ -228,15 +227,15 @@ fn each_reexport(d: ebml::Doc, f: fn(ebml::Doc) -> bool) {
228227
}
229228
}
230229

231-
fn field_mutability(d: ebml::Doc) -> ast::class_mutability {
230+
fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
232231
// Use maybe_get_doc in case it's a method
233232
option::map_default(
234-
&reader::maybe_get_doc(d, tag_class_mut),
235-
ast::class_immutable,
233+
&reader::maybe_get_doc(d, tag_struct_mut),
234+
ast::struct_immutable,
236235
|d| {
237236
match reader::doc_as_u8(*d) as char {
238-
'm' => ast::class_mutable,
239-
_ => ast::class_immutable
237+
'm' => ast::struct_mutable,
238+
_ => ast::struct_immutable
240239
}
241240
})
242241
}
@@ -338,7 +337,7 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
338337
let fam = item_family(item);
339338
match fam {
340339
Const => dl_def(ast::def_const(did)),
341-
Struct => dl_def(ast::def_class(did)),
340+
Struct => dl_def(ast::def_struct(did)),
342341
UnsafeFn => dl_def(ast::def_fn(did, ast::unsafe_fn)),
343342
Fn => dl_def(ast::def_fn(did, ast::impure_fn)),
344343
PureFn => dl_def(ast::def_fn(did, ast::pure_fn)),
@@ -419,34 +418,12 @@ fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
419418
found.get()
420419
}
421420

422-
fn get_class_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
423-
name: ast::ident) -> ast::def_id {
424-
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
425-
let mut found = None;
426-
let cls_items = match maybe_find_item(id, items) {
427-
Some(it) => it,
428-
None => fail (fmt!("get_class_method: class id not found \
429-
when looking up method %s", *intr.get(name)))
430-
};
431-
for reader::tagged_docs(cls_items, tag_item_trait_method) |mid| {
432-
let m_did = item_def_id(mid, cdata);
433-
if item_name(intr, mid) == name {
434-
found = Some(m_did);
435-
}
436-
}
437-
match found {
438-
Some(found) => found,
439-
None => fail (fmt!("get_class_method: no method named %s",
440-
*intr.get(name)))
441-
}
442-
}
443-
444-
fn class_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
421+
fn struct_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
445422
let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
446423
let mut found = None;
447424
let cls_items = match maybe_find_item(id, items) {
448425
Some(it) => it,
449-
None => fail (fmt!("class_dtor: class id not found \
426+
None => fail (fmt!("struct_dtor: class id not found \
450427
when looking up dtor for %d", id))
451428
};
452429
for reader::tagged_docs(cls_items, tag_item_dtor) |doc| {
@@ -905,15 +882,23 @@ fn get_item_attrs(cdata: cmd,
905882
}
906883
}
907884

908-
// Helper function that gets either fields or methods
909-
fn get_class_members(intr: @ident_interner, cdata: cmd, id: ast::node_id,
910-
p: fn(Family) -> bool) -> ~[ty::field_ty] {
885+
pure fn family_to_visibility(family: Family) -> ast::visibility {
886+
match family {
887+
PublicField => ast::public,
888+
PrivateField => ast::private,
889+
InheritedField => ast::inherited,
890+
_ => fail
891+
}
892+
}
893+
894+
fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
895+
-> ~[ty::field_ty] {
911896
let data = cdata.data;
912897
let item = lookup_item(id, data);
913898
let mut result = ~[];
914899
for reader::tagged_docs(item, tag_item_field) |an_item| {
915900
let f = item_family(an_item);
916-
if p(f) {
901+
if f == PublicField || f == PrivateField || f == InheritedField {
917902
let name = item_name(intr, an_item);
918903
let did = item_def_id(an_item, cdata);
919904
let mt = field_mutability(an_item);
@@ -924,21 +909,6 @@ fn get_class_members(intr: @ident_interner, cdata: cmd, id: ast::node_id,
924909
result
925910
}
926911

927-
pure fn family_to_visibility(family: Family) -> ast::visibility {
928-
match family {
929-
PublicField => ast::public,
930-
PrivateField => ast::private,
931-
InheritedField => ast::inherited,
932-
_ => fail
933-
}
934-
}
935-
936-
fn get_class_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
937-
-> ~[ty::field_ty] {
938-
get_class_members(intr, cdata, id, |f| f == PublicField
939-
|| f == PrivateField || f == InheritedField)
940-
}
941-
942912
fn family_has_type_params(fam: Family) -> bool {
943913
match fam {
944914
Const | ForeignType | Mod | ForeignMod | PublicField | PrivateField

src/librustc/metadata/encoder.rs

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ fn encode_region_param(ecx: @encode_ctxt, ebml_w: writer::Serializer,
120120
}
121121
}
122122

123-
fn encode_mutability(ebml_w: writer::Serializer, mt: class_mutability) {
124-
do ebml_w.wr_tag(tag_class_mut) {
123+
fn encode_mutability(ebml_w: writer::Serializer, mt: struct_mutability) {
124+
do ebml_w.wr_tag(tag_struct_mut) {
125125
let val = match mt {
126-
class_immutable => 'a',
127-
class_mutable => 'm'
126+
struct_immutable => 'a',
127+
struct_mutable => 'm'
128128
};
129129
ebml_w.writer.write(&[val as u8]);
130130
}
@@ -318,7 +318,7 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: writer::Serializer,
318318
// Encode info about all the module children.
319319
for md.items.each |item| {
320320
match item.node {
321-
item_impl(*) | item_class(*) => {
321+
item_impl(*) | item_struct(*) => {
322322
let (ident, did) = (item.ident, item.id);
323323
debug!("(encoding info for module) ... encoding impl %s \
324324
(%?/%?), exported? %?",
@@ -412,11 +412,9 @@ fn encode_method_sort(ebml_w: writer::Serializer, sort: char) {
412412
}
413413

414414
/* Returns an index of items in this class */
415-
fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: writer::Serializer,
416-
id: node_id, path: ast_map::path,
417-
class_tps: ~[ty_param],
415+
fn encode_info_for_struct(ecx: @encode_ctxt, ebml_w: writer::Serializer,
416+
path: ast_map::path,
418417
fields: ~[@struct_field],
419-
methods: ~[@method],
420418
global_index: @mut~[entry<int>]) -> ~[entry<int>] {
421419
/* Each class has its own index, since different classes
422420
may have fields with the same name */
@@ -432,7 +430,7 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: writer::Serializer,
432430
global_index.push({val: id,
433431
pos: ebml_w.writer.tell()});
434432
ebml_w.start_tag(tag_items_data_item);
435-
debug!("encode_info_for_class: doing %s %d",
433+
debug!("encode_info_for_struct: doing %s %d",
436434
tcx.sess.str_of(nm), id);
437435
encode_visibility(ebml_w, vis);
438436
encode_name(ecx, ebml_w, nm);
@@ -445,25 +443,6 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: writer::Serializer,
445443
unnamed_field => {}
446444
}
447445
}
448-
449-
for methods.each |m| {
450-
match m.vis {
451-
public | inherited => {
452-
index.push({val: m.id, pos: ebml_w.writer.tell()});
453-
global_index.push(
454-
{val: m.id, pos: ebml_w.writer.tell()});
455-
let impl_path = vec::append_one(path,
456-
ast_map::path_name(m.ident));
457-
debug!("encode_info_for_class: doing %s %d",
458-
ecx.tcx.sess.str_of(m.ident), m.id);
459-
encode_info_for_method(ecx, ebml_w, impl_path,
460-
should_inline(m.attrs), id, *m,
461-
vec::append(class_tps, m.tps));
462-
}
463-
_ => { /* don't encode private methods */ }
464-
}
465-
}
466-
467446
*index
468447
}
469448

@@ -556,7 +535,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
556535
let must_write =
557536
match item.node {
558537
item_enum(_, _) | item_impl(*)
559-
| item_trait(*) | item_class(*) => true,
538+
| item_trait(*) | item_struct(*) => true,
560539
_ => false
561540
};
562541
if !must_write && !reachable(ecx, item.id) { return; }
@@ -645,14 +624,13 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
645624
index,
646625
tps);
647626
}
648-
item_class(struct_def, tps) => {
649-
/* First, encode the fields and methods
627+
item_struct(struct_def, tps) => {
628+
/* First, encode the fields
650629
These come first because we need to write them to make
651630
the index, and the index needs to be in the item for the
652631
class itself */
653-
let idx = encode_info_for_class(ecx, ebml_w, item.id, path, tps,
654-
struct_def.fields, struct_def.methods,
655-
index);
632+
let idx = encode_info_for_struct(ecx, ebml_w, path,
633+
struct_def.fields, index);
656634
/* Encode the dtor */
657635
do struct_def.dtor.iter |dtor| {
658636
index.push({val: dtor.node.id, pos: ebml_w.writer.tell()});
@@ -677,9 +655,6 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
677655
encode_name(ecx, ebml_w, item.ident);
678656
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
679657
encode_region_param(ecx, ebml_w, item);
680-
for struct_def.traits.each |t| {
681-
encode_trait_ref(ebml_w, ecx, *t);
682-
}
683658
/* Encode the dtor */
684659
/* Encode id for dtor */
685660
do struct_def.dtor.iter |dtor| {
@@ -704,28 +679,6 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: writer::Serializer,
704679
}
705680
}
706681

707-
for struct_def.methods.each |m| {
708-
match m.vis {
709-
private => { /* do nothing */ }
710-
public | inherited => {
711-
/* Write the info that's needed when viewing this class
712-
as a trait */
713-
ebml_w.start_tag(tag_item_trait_method);
714-
encode_family(ebml_w, purity_fn_family(m.purity));
715-
encode_name(ecx, ebml_w, m.ident);
716-
encode_type_param_bounds(ebml_w, ecx, m.tps);
717-
encode_type(ecx, ebml_w, node_id_to_type(tcx, m.id));
718-
encode_def_id(ebml_w, local_def(m.id));
719-
encode_self_type(ebml_w, m.self_ty.node);
720-
ebml_w.end_tag();
721-
/* Write the info that's needed when viewing this class
722-
as an impl (just the method def_id and self type) */
723-
ebml_w.start_tag(tag_item_impl_method);
724-
ebml_w.writer.write(to_bytes(def_to_str(local_def(m.id))));
725-
ebml_w.end_tag();
726-
}
727-
}
728-
}
729682
/* Each class has its own index -- encode it */
730683
let bkts = create_index(idx);
731684
encode_index(ebml_w, bkts, write_int);

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
337337
debug!("parsed a def_id %?", did);
338338
let substs = parse_substs(st, conv);
339339
assert (next(st) == ']');
340-
return ty::mk_class(st.tcx, did, substs);
340+
return ty::mk_struct(st.tcx, did, substs);
341341
}
342342
c => { error!("unexpected char in type string: %c", c); fail;}
343343
}

src/librustc/metadata/tyencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
316316
enc_proto(w, p);
317317
}
318318
ty::ty_opaque_box => w.write_char('B'),
319-
ty::ty_class(def, ref substs) => {
319+
ty::ty_struct(def, ref substs) => {
320320
debug!("~~~~ %s", ~"a[");
321321
w.write_str(&"a[");
322322
let s = (cx.ds)(def);

src/librustc/middle/astencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ impl ast::def: tr {
372372
xcx.tr_id(nid2),
373373
xcx.tr_id(nid3))
374374
}
375-
ast::def_class(did) => {
376-
ast::def_class(did.tr(xcx))
375+
ast::def_struct(did) => {
376+
ast::def_struct(did.tr(xcx))
377377
}
378378
ast::def_region(nid) => ast::def_region(xcx.tr_id(nid)),
379379
ast::def_typaram_binder(nid) => {

0 commit comments

Comments
 (0)