diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-06-26 16:25:52 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-07-13 14:47:04 -0700 |
| commit | 07a81ad12e5cb7f84138af6624f30c5dbb75512f (patch) | |
| tree | 919cac823330022fbbf5bc5130c29901278ab22f /src/libsyntax | |
| parent | ee73b78e04860f0e4312e462c80ab8a6d37cd759 (diff) | |
Refactor how impl self types are stored
In order to avoid a confusing use of the tcache, I added an extra node ID field to trait refs. Now trait refs have a "ref ID" (the one that resolve3 resolves) and an "impl ID" (the one that you look up in the tcache to get the self type). Closes #2434
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/ast_map.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 4 |
4 files changed, 20 insertions, 8 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f79f6cbcae2..095038f02e3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -675,10 +675,15 @@ type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool}; /* trait_refs appear in both impls and in classes that implement traits. - resolve maps each trait_ref's id to its defining trait. + resolve maps each trait_ref's ref_id to its defining trait; that's all + that the ref_id is for. The impl_id maps to the "self type" of this impl. + If this impl is an item_impl, the impl_id is redundant (it could be the + same as the impl's node id). If this impl is actually an impl_class, then + conceptually, the impl_id stands in for the pair of (this class, this + trait) */ #[auto_serialize] -type trait_ref = {path: @path, id: node_id}; +type trait_ref = {path: @path, ref_id: node_id, impl_id: node_id}; #[auto_serialize] enum visibility { public, private } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 129a03f71aa..a5ae45d54ee 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -188,7 +188,7 @@ fn map_item(i: @item, cx: ctx, v: vt) { let item_path = @/* FIXME (#2543) */ copy cx.path; cx.map.insert(i.id, node_item(i, item_path)); alt i.node { - item_impl(_, _, _, ms) { + item_impl(_, opt_ir, _, ms) { let impl_did = ast_util::local_def(i.id); for ms.each |m| { map_method(impl_did, extend(cx, i.ident), m, @@ -218,8 +218,14 @@ fn map_item(i: @item, cx: ctx, v: vt) { let (_, ms) = ast_util::split_class_items(items); // Map trait refs to their parent classes. This is // so we can find the self_ty - do vec::iter(traits) |p| { cx.map.insert(p.id, - node_item(i, item_path)); }; + do vec::iter(traits) |p| { cx.map.insert(p.ref_id, + node_item(i, item_path)); + // This is so we can look up the right things when + // encoding/decoding + cx.map.insert(p.impl_id, + node_item(i, item_path)); + + }; let d_id = ast_util::local_def(i.id); let p = extend(cx, i.ident); // only need to handle methods diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 0e16d4bdca8..f5edb96f5e1 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -287,7 +287,8 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { } fn fold_trait_ref(&&p: @trait_ref, fld: ast_fold) -> @trait_ref { - @{path: fld.fold_path(p.path), id: fld.new_id(p.id)} + @{path: fld.fold_path(p.path), ref_id: fld.new_id(p.ref_id), + impl_id: fld.new_id(p.impl_id)} } fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5a1eb7636ba..7448f246698 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2189,7 +2189,7 @@ class parser { if option::is_none(ident) { ident = some(vec::last(path.idents)); } - some(@{path: path, id: self.get_id()}) + some(@{path: path, ref_id: self.get_id(), impl_id: self.get_id()}) } else { none }; let ident = alt ident { some(name) { name } @@ -2223,7 +2223,7 @@ class parser { fn parse_trait_ref() -> @trait_ref { @{path: self.parse_path_with_tps(false), - id: self.get_id()} + ref_id: self.get_id(), impl_id: self.get_id()} } fn parse_trait_ref_list() -> ~[@trait_ref] { |
