Skip to content

Commit 19311b6

Browse files
committedSep 14, 2014
auto merge of #13316 : eddyb/rust/ast-ptr, r=brson
Replaces Gc<T> in the AST with a custom owned smart pointer, P<T>. Fixes #7929. ## Benefits * **Identity** (affinity?): sharing AST nodes is bad for the various analysis passes (e.g. one could bypass borrowck with a shared `ExprAddrOf` node taking a mutable borrow), the only reason we haven't hit any serious issues with it is because of inefficient folding passes which will always deduplicate any such shared nodes. Even if we were to switch to an arena, this would still hold, i.e. we wouldn't just use `&'a T` in the AST, but rather an wrapper (`P<'a, T>`?). * **Immutability**: `P<T>` disallows mutating its inner `T` (unless that contains an `Unsafe` interior, which won't happen in the AST), unlike `~T`. * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`, the latter even when the input and output types differ (as it would be the case with arenas or an AST with type parameters to toggle macro support). Also, various algorithms have been changed from copying `Gc<T>` to using `&T` and iterators. * **Maintainability**: there is another reason I didn't just replace `Gc<T>` with `~T`: `P<T>` provides a fixed interface (`Deref`, `and_then` and `map`) which can remain fully functional even if the implementation changes (using a special thread-local heap, for example). Moreover, switching to, e.g. `P<'a, T>` (for a contextual arena) is easy and mostly automated.
2 parents 931b115 + 8577343 commit 19311b6

File tree

126 files changed

+4912
-5037
lines changed

Some content is hidden

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

126 files changed

+4912
-5037
lines changed
 

‎mk/crates.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ DEPS_graphviz := std
7070
DEPS_green := std native:context_switch
7171
DEPS_rustuv := std native:uv native:uv_support
7272
DEPS_native := std
73-
DEPS_syntax := std term serialize log fmt_macros debug
73+
DEPS_syntax := std term serialize log fmt_macros debug arena
7474
DEPS_rustc := syntax flate arena serialize getopts rbml \
7575
time log graphviz debug rustc_llvm rustc_back
7676
DEPS_rustc_llvm := native:rustllvm libc std

‎src/libfourcc/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ use syntax::ext::base::{ExtCtxt, MacExpr};
6363
use syntax::ext::build::AstBuilder;
6464
use syntax::parse::token;
6565
use syntax::parse::token::InternedString;
66+
use syntax::ptr::P;
6667
use rustc::plugin::Registry;
6768

68-
use std::gc::Gc;
69-
7069
#[plugin_registrar]
7170
pub fn plugin_registrar(reg: &mut Registry) {
7271
reg.register_macro("fourcc", expand_syntax_ext);
@@ -135,7 +134,7 @@ struct Ident {
135134
}
136135

137136
fn parse_tts(cx: &ExtCtxt,
138-
tts: &[ast::TokenTree]) -> (Gc<ast::Expr>, Option<Ident>) {
137+
tts: &[ast::TokenTree]) -> (P<ast::Expr>, Option<Ident>) {
139138
let p = &mut cx.new_parser_from_tts(tts);
140139
let ex = p.parse_expr();
141140
let id = if p.token == token::EOF {
@@ -156,7 +155,7 @@ fn parse_tts(cx: &ExtCtxt,
156155
fn target_endian_little(cx: &ExtCtxt, sp: Span) -> bool {
157156
let meta = cx.meta_name_value(sp, InternedString::new("target_endian"),
158157
ast::LitStr(InternedString::new("little"), ast::CookedStr));
159-
contains(cx.cfg().as_slice(), meta)
158+
contains(cx.cfg().as_slice(), &*meta)
160159
}
161160

162161
// FIXME (10872): This is required to prevent an LLVM assert on Windows

0 commit comments

Comments
 (0)
Please sign in to comment.