Skip to content

Commit e3a1c5c

Browse files
committed
Encode both private and public class fields in metadata
This is necessary to calculate the correct offsets for field references. Simple cross-crate class tests (still with fields only) now pass.
1 parent 16dd6c4 commit e3a1c5c

File tree

6 files changed

+8
-24
lines changed

6 files changed

+8
-24
lines changed

src/rustc/metadata/decoder.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,8 @@ fn get_iface_methods(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
405405
@result
406406
}
407407

408-
/*
409-
FIXME
410-
This is not working. metadata is broken -- fields get encoded correctly,
411-
but not decoded. look at this code, see what it's actually writing out
412-
also see what "data" is
413-
*/
408+
/* Take a node ID for a class, return a vector of the class's
409+
member types */
414410
fn get_class_items(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
415411
-> [@ty::class_item_ty] {
416412
let data = cdata.data;

src/rustc/metadata/encoder.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
358358
encode_name(ebml_w, name);
359359

360360
for ci in items {
361-
alt ci.node.privacy {
362-
pub {
363-
ebml_w.start_tag(tag_items_class_member); // ???
361+
/* We encode both private and public fields -- need to include
362+
private fields to get the offsets right */
363+
ebml_w.start_tag(tag_items_class_member);
364364
alt ci.node.decl {
365365
instance_var(nm, _, _, id) {
366366
#debug("encode_info_for_class: doing %s %d", nm, id);
@@ -383,11 +383,6 @@ fn encode_info_for_class(ecx: @encode_ctxt, ebml_w: ebml::writer,
383383
}
384384
}
385385
ebml_w.end_tag();
386-
}
387-
priv {
388-
/* don't export it, then! */
389-
}
390-
}
391386
}
392387
}
393388

src/rustc/middle/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4128,7 +4128,7 @@ fn trans_item(ccx: @crate_ctxt, item: ast::item) {
41284128
// Register a type for obj
41294129
smallintmap::insert(*ccx.tcx.node_types,
41304130
rslt_loc_.id as uint, rslt_ty);
4131-
// Create the decl statement that initializers obj
4131+
// Create the decl statement that initializes obj
41324132
let rslt_loc : @ast::local =
41334133
@{node: rslt_loc_, span: ctor.node.body.span};
41344134
let rslt_decl_ : ast::decl_ = ast::decl_local([rslt_loc]);

src/rustc/middle/ty.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,11 +2437,7 @@ fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty {
24372437
// Look up the list of item types for a given class
24382438
// Fails if the id is not bound to a class.
24392439
fn lookup_class_item_tys(cx: ctxt, did: ast::def_id) -> [@class_item_ty] {
2440-
/*
2441-
TODO: Check whether this is a local id or not; use csearch / tcache
2442-
if it's external
2443-
*/
2444-
if did.crate == ast::local_crate {
2440+
if did.crate == ast::local_crate {
24452441
alt cx.items.find(did.node) {
24462442
some(ast_map::node_item(i,_)) {
24472443
alt i.node {
@@ -2454,7 +2450,7 @@ fn lookup_class_item_tys(cx: ctxt, did: ast::def_id) -> [@class_item_ty] {
24542450
_ { cx.sess.bug("class ID not bound to an item"); }
24552451
}
24562452
}
2457-
else {
2453+
else {
24582454
ret csearch::get_class_items(cx, did);
24592455
}
24602456
}

src/test/run-pass/classes-simple-cross-crate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// xfail-test
21
// xfail-fast
32
// aux-build:cci_class.rs
43
use cci_class;

src/test/run-pass/classes-simple.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// xfail-test FIXME: Needs metadata encoding
2-
31
class cat {
42
priv {
53
let mutable meows : uint;

0 commit comments

Comments
 (0)