Skip to content

Commit b02f5c2

Browse files
committed
Get rid of structural records in libsyntax and the last bit in librustc.
1 parent 41a4151 commit b02f5c2

25 files changed

+330
-241
lines changed

src/libfuzzer/fuzzer.rc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn parse_and_print(code: @~str) -> ~str {
466466
sess.cm,
467467
// Assuming there are no token_trees
468468
syntax::parse::token::mk_fake_ident_interner(),
469-
sess.span_diagnostic,
469+
copy sess.span_diagnostic,
470470
crate,
471471
filename.to_str(),
472472
rdr, a,
@@ -622,7 +622,7 @@ pub fn check_variants(files: &[Path], cx: Context) {
622622
sess.cm,
623623
// Assuming no token_trees
624624
syntax::parse::token::mk_fake_ident_interner(),
625-
sess.span_diagnostic,
625+
copy sess.span_diagnostic,
626626
crate,
627627
file_str,
628628
rdr, a,

src/librustc/driver/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use syntax::ast::node_id;
2525
use syntax::ast::{int_ty, uint_ty, float_ty};
2626
use syntax::codemap::span;
2727
use syntax::diagnostic;
28-
use syntax::parse::parse_sess;
28+
use syntax::parse::ParseSess;
2929
use syntax::{ast, codemap};
3030
use syntax;
3131

@@ -151,7 +151,7 @@ pub struct Session_ {
151151
targ_cfg: @config,
152152
opts: @options,
153153
cstore: @mut metadata::cstore::CStore,
154-
parse_sess: parse_sess,
154+
parse_sess: @mut ParseSess,
155155
codemap: @codemap::CodeMap,
156156
// For a library crate, this is always none
157157
main_fn: @mut Option<(node_id, codemap::span)>,

src/librustc/front/test.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
// Code that generates a test runner to run all the tests in a crate
1212

13-
// XXX - Need to finish off libsyntax first
14-
#[legacy_records];
15-
#[allow(structural_records)];
16-
1713
use core::prelude::*;
1814

1915
use driver::session;
@@ -25,7 +21,7 @@ use core::option;
2521
use core::vec;
2622
use syntax::ast_util::*;
2723
use syntax::attr;
28-
use syntax::codemap::{dummy_sp, span, ExpandedFrom};
24+
use syntax::codemap::{dummy_sp, span, ExpandedFrom, CallInfo, NameAndSpan};
2925
use syntax::codemap;
3026
use syntax::fold;
3127
use syntax::print::pprust;
@@ -81,11 +77,13 @@ fn generate_test_harness(sess: session::Session,
8177
testfns: ~[]
8278
};
8379

84-
cx.ext_cx.bt_push(ExpandedFrom({
85-
call_site: dummy_sp(),
86-
callie: {
87-
name: ~"test",
88-
span: None}}));
80+
cx.ext_cx.bt_push(ExpandedFrom(CallInfo {
81+
call_site: dummy_sp(),
82+
callee: NameAndSpan {
83+
name: ~"test",
84+
span: None
85+
}
86+
}));
8987

9088
let precursor = @fold::AstFoldFns {
9189
fold_crate: fold::wrap(|a,b| fold_crate(cx, a, b) ),

src/librustc/middle/astencode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,18 +1193,18 @@ fn decode_item_ast(par_doc: ebml::Doc) -> @ast::item {
11931193
#[cfg(test)]
11941194
trait fake_ext_ctxt {
11951195
fn cfg() -> ast::crate_cfg;
1196-
fn parse_sess() -> parse::parse_sess;
1196+
fn parse_sess() -> @mut parse::ParseSess;
11971197
fn call_site() -> span;
11981198
fn ident_of(+st: ~str) -> ast::ident;
11991199
}
12001200
12011201
#[cfg(test)]
1202-
type fake_session = parse::parse_sess;
1202+
type fake_session = @mut parse::ParseSess;
12031203
12041204
#[cfg(test)]
12051205
impl fake_ext_ctxt for fake_session {
12061206
fn cfg() -> ast::crate_cfg { ~[] }
1207-
fn parse_sess() -> parse::parse_sess { self }
1207+
fn parse_sess() -> @mut parse::ParseSess { self }
12081208
fn call_site() -> span {
12091209
codemap::span {
12101210
lo: codemap::BytePos(0),

src/libsyntax/codemap.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,16 @@ pub struct LocWithOpt {
196196
// used to be structural records. Better names, anyone?
197197
pub struct FileMapAndLine {fm: @FileMap, line: uint}
198198
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
199+
pub struct NameAndSpan {name: ~str, span: Option<span>}
200+
201+
pub struct CallInfo {
202+
call_site: span,
203+
callee: NameAndSpan
204+
}
199205

200206
/// Extra information for tracking macro expansion of spans
201207
pub enum ExpnInfo {
202-
ExpandedFrom({call_site: span,
203-
callie: {name: ~str, span: Option<span>}})
208+
ExpandedFrom(CallInfo)
204209
}
205210

206211
pub type FileName = ~str;

src/libsyntax/diagnostic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ fn highlight_lines(cm: @codemap::CodeMap,
290290

291291
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) {
292292
do option::iter(&sp.expn_info) |ei| {
293-
let ss = option::map_default(&ei.callie.span, @~"",
293+
let ss = option::map_default(&ei.callee.span, @~"",
294294
|span| @cm.span_to_str(*span));
295295
print_diagnostic(*ss, note,
296-
fmt!("in expansion of %s!", ei.callie.name));
296+
fmt!("in expansion of %s!", ei.callee.name));
297297
let ss = cm.span_to_str(ei.call_site);
298298
print_diagnostic(ss, note, ~"expansion site");
299299
print_macro_backtrace(cm, ei.call_site);

src/libsyntax/ext/base.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use core::prelude::*;
1313
use ast;
1414
use codemap;
1515
use codemap::{CodeMap, span, ExpnInfo, ExpandedFrom, dummy_sp};
16+
use codemap::{CallInfo, NameAndSpan};
1617
use diagnostic::span_handler;
1718
use ext;
1819
use parse;
@@ -166,7 +167,7 @@ pub fn syntax_expander_table() -> SyntaxExtensions {
166167
// -> expn_info of their expansion context stored into their span.
167168
pub trait ext_ctxt {
168169
fn codemap(@mut self) -> @CodeMap;
169-
fn parse_sess(@mut self) -> parse::parse_sess;
170+
fn parse_sess(@mut self) -> @mut parse::ParseSess;
170171
fn cfg(@mut self) -> ast::crate_cfg;
171172
fn call_site(@mut self) -> span;
172173
fn print_backtrace(@mut self);
@@ -190,22 +191,22 @@ pub trait ext_ctxt {
190191
fn ident_of(@mut self, st: ~str) -> ast::ident;
191192
}
192193

193-
pub fn mk_ctxt(parse_sess: parse::parse_sess,
194+
pub fn mk_ctxt(parse_sess: @mut parse::ParseSess,
194195
cfg: ast::crate_cfg) -> ext_ctxt {
195196
struct CtxtRepr {
196-
parse_sess: parse::parse_sess,
197+
parse_sess: @mut parse::ParseSess,
197198
cfg: ast::crate_cfg,
198199
backtrace: Option<@ExpnInfo>,
199200
mod_path: ~[ast::ident],
200201
trace_mac: bool
201202
}
202203
impl ext_ctxt for CtxtRepr {
203204
fn codemap(@mut self) -> @CodeMap { self.parse_sess.cm }
204-
fn parse_sess(@mut self) -> parse::parse_sess { self.parse_sess }
205+
fn parse_sess(@mut self) -> @mut parse::ParseSess { self.parse_sess }
205206
fn cfg(@mut self) -> ast::crate_cfg { self.cfg }
206207
fn call_site(@mut self) -> span {
207208
match self.backtrace {
208-
Some(@ExpandedFrom({call_site: cs, _})) => cs,
209+
Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
209210
None => self.bug(~"missing top span")
210211
}
211212
}
@@ -216,18 +217,18 @@ pub fn mk_ctxt(parse_sess: parse::parse_sess,
216217
fn mod_path(@mut self) -> ~[ast::ident] { return self.mod_path; }
217218
fn bt_push(@mut self, ei: codemap::ExpnInfo) {
218219
match ei {
219-
ExpandedFrom({call_site: cs, callie: ref callie}) => {
220+
ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
220221
self.backtrace =
221-
Some(@ExpandedFrom({
222+
Some(@ExpandedFrom(CallInfo {
222223
call_site: span {lo: cs.lo, hi: cs.hi,
223224
expn_info: self.backtrace},
224-
callie: (*callie)}));
225+
callee: (*callee)}));
225226
}
226227
}
227228
}
228229
fn bt_pop(@mut self) {
229230
match self.backtrace {
230-
Some(@ExpandedFrom({
231+
Some(@ExpandedFrom(CallInfo {
231232
call_site: span {expn_info: prev, _}, _
232233
})) => {
233234
self.backtrace = prev

src/libsyntax/ext/build.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ use ext::build;
1919
use core::dvec;
2020
use core::option;
2121

22+
pub struct Field {
23+
ident: ast::ident,
24+
ex: @ast::expr
25+
}
26+
2227
pub fn mk_expr(cx: ext_ctxt,
2328
sp: codemap::span,
2429
expr: ast::expr_)
@@ -147,47 +152,37 @@ pub fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
147152
pub fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
148153
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::expr_vstore_uniq)
149154
}
150-
pub fn mk_field(sp: span, f: &{ident: ast::ident, ex: @ast::expr})
151-
-> ast::field {
155+
pub fn mk_field(sp: span, f: &Field) -> ast::field {
152156
codemap::spanned {
153157
node: ast::field_ { mutbl: ast::m_imm, ident: f.ident, expr: f.ex },
154158
span: sp,
155159
}
156160
}
157-
pub fn mk_fields(sp: span, fields: ~[{ident: ast::ident, ex: @ast::expr}])
158-
-> ~[ast::field] {
161+
pub fn mk_fields(sp: span, fields: ~[Field]) -> ~[ast::field] {
159162
fields.map(|f| mk_field(sp, f))
160163
}
161-
pub fn mk_rec_e(cx: ext_ctxt,
162-
sp: span,
163-
fields: ~[{ident: ast::ident, ex: @ast::expr}])
164-
-> @ast::expr {
164+
pub fn mk_rec_e(cx: ext_ctxt, sp: span, fields: ~[Field]) -> @ast::expr {
165165
mk_expr(cx, sp, ast::expr_rec(mk_fields(sp, fields),
166166
option::None::<@ast::expr>))
167167
}
168-
pub fn mk_struct_e(cx: ext_ctxt,
169-
sp: span,
170-
ctor_path: ~[ast::ident],
171-
fields: ~[{ident: ast::ident, ex: @ast::expr}])
172-
-> @ast::expr {
168+
pub fn mk_struct_e(cx: ext_ctxt, sp: span, ctor_path: ~[ast::ident],
169+
fields: ~[Field]) -> @ast::expr {
173170
mk_expr(cx, sp,
174171
ast::expr_struct(mk_raw_path(sp, ctor_path),
175172
mk_fields(sp, fields),
176173
option::None::<@ast::expr>))
177174
}
178-
pub fn mk_global_struct_e(cx: ext_ctxt,
179-
sp: span,
175+
pub fn mk_global_struct_e(cx: ext_ctxt, sp: span,
180176
ctor_path: ~[ast::ident],
181-
fields: ~[{ident: ast::ident, ex: @ast::expr}])
177+
fields: ~[Field])
182178
-> @ast::expr {
183179
mk_expr(cx, sp,
184180
ast::expr_struct(mk_raw_path_global(sp, ctor_path),
185181
mk_fields(sp, fields),
186182
option::None::<@ast::expr>))
187183
}
188-
pub fn mk_glob_use(cx: ext_ctxt,
189-
sp: span,
190-
path: ~[ast::ident]) -> @ast::view_item {
184+
pub fn mk_glob_use(cx: ext_ctxt, sp: span, path: ~[ast::ident])
185+
-> @ast::view_item {
191186
let glob = @codemap::spanned {
192187
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
193188
span: sp,

src/libsyntax/ext/expand.rs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ast::{crate, expr_, expr_mac, mac_invoc_tt};
1414
use ast::{tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
1515
use ast;
1616
use attr;
17-
use codemap::{span, ExpandedFrom};
17+
use codemap::{span, CallInfo, ExpandedFrom, NameAndSpan};
1818
use ext::base::*;
1919
use fold::*;
2020
use parse::{parser, parse_expr_from_source_str, new_parser_from_tts};
@@ -48,8 +48,12 @@ pub fn expand_expr(exts: SyntaxExtensions, cx: ext_ctxt,
4848
}
4949
Some(NormalTT(SyntaxExpanderTT{expander: exp,
5050
span: exp_sp})) => {
51-
cx.bt_push(ExpandedFrom({call_site: s,
52-
callie: {name: *extname, span: exp_sp}}));
51+
cx.bt_push(ExpandedFrom(CallInfo{
52+
call_site: s,
53+
callee: NameAndSpan {
54+
name: *extname, span: exp_sp
55+
}
56+
}));
5357

5458
let expanded = match exp(cx, (*mac).span, (*tts)) {
5559
MRExpr(e) => e,
@@ -105,9 +109,13 @@ pub fn expand_mod_items(exts: SyntaxExtensions, cx: ext_ctxt,
105109
match exts.find(&mname) {
106110
None | Some(NormalTT(_)) | Some(ItemTT(*)) => items,
107111
Some(ItemDecorator(dec_fn)) => {
108-
cx.bt_push(ExpandedFrom({call_site: attr.span,
109-
callie: {name: /*bad*/ copy *mname,
110-
span: None}}));
112+
cx.bt_push(ExpandedFrom(CallInfo {
113+
call_site: attr.span,
114+
callee: NameAndSpan {
115+
name: /*bad*/ copy *mname,
116+
span: None
117+
}
118+
}));
111119
let r = dec_fn(cx, attr.span, attr.node.value, items);
112120
cx.bt_pop();
113121
r
@@ -170,9 +178,13 @@ pub fn expand_item_mac(exts: SyntaxExtensions,
170178
given '%s'", *extname,
171179
*cx.parse_sess().interner.get(it.ident)));
172180
}
173-
cx.bt_push(ExpandedFrom({call_site: it.span,
174-
callie: {name: *extname,
175-
span: (*expand).span}}));
181+
cx.bt_push(ExpandedFrom(CallInfo {
182+
call_site: it.span,
183+
callee: NameAndSpan {
184+
name: *extname,
185+
span: (*expand).span
186+
}
187+
}));
176188
((*expand).expander)(cx, it.span, tts)
177189
}
178190
Some(ItemTT(ref expand)) => {
@@ -181,9 +193,13 @@ pub fn expand_item_mac(exts: SyntaxExtensions,
181193
fmt!("macro %s! expects an ident argument",
182194
*extname));
183195
}
184-
cx.bt_push(ExpandedFrom({call_site: it.span,
185-
callie: {name: *extname,
186-
span: (*expand).span}}));
196+
cx.bt_push(ExpandedFrom(CallInfo {
197+
call_site: it.span,
198+
callee: NameAndSpan {
199+
name: *extname,
200+
span: (*expand).span
201+
}
202+
}));
187203
((*expand).expander)(cx, it.span, it.ident, tts)
188204
}
189205
_ => cx.span_fatal(
@@ -228,8 +244,10 @@ pub fn expand_stmt(exts: SyntaxExtensions, cx: ext_ctxt,
228244

229245
Some(NormalTT(
230246
SyntaxExpanderTT{expander: exp, span: exp_sp})) => {
231-
cx.bt_push(ExpandedFrom(
232-
{call_site: sp, callie: {name: *extname, span: exp_sp}}));
247+
cx.bt_push(ExpandedFrom(CallInfo {
248+
call_site: sp,
249+
callee: NameAndSpan { name: *extname, span: exp_sp }
250+
}));
233251
let expanded = match exp(cx, mac.span, tts) {
234252
MRExpr(e) =>
235253
@codemap::spanned { node: stmt_expr(e, cx.next_id()),
@@ -321,7 +339,7 @@ pub fn core_macros() -> ~str {
321339
}";
322340
}
323341

324-
pub fn expand_crate(parse_sess: parse::parse_sess,
342+
pub fn expand_crate(parse_sess: @mut parse::ParseSess,
325343
cfg: ast::crate_cfg, c: @crate) -> @crate {
326344
let exts = syntax_expander_table();
327345
let afp = default_ast_fold();

src/libsyntax/ext/fmt.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,18 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
118118
sp,
119119
make_path_vec(cx, @~"Conv"),
120120
~[
121-
{ident: intr.intern(@~"flags"), ex: flags_expr},
122-
{ident: intr.intern(@~"width"), ex: width_expr},
123-
{ident: intr.intern(@~"precision"), ex: precision_expr},
124-
{ident: intr.intern(@~"ty"), ex: ty_expr},
121+
build::Field {
122+
ident: intr.intern(@~"flags"), ex: flags_expr
123+
},
124+
build::Field {
125+
ident: intr.intern(@~"width"), ex: width_expr
126+
},
127+
build::Field {
128+
ident: intr.intern(@~"precision"), ex: precision_expr
129+
},
130+
build::Field {
131+
ident: intr.intern(@~"ty"), ex: ty_expr
132+
},
125133
]
126134
)
127135
}

src/libsyntax/ext/pipes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
6868
tt: ~[ast::token_tree]) -> base::MacResult {
6969
let sess = cx.parse_sess();
7070
let cfg = cx.cfg();
71-
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
71+
let tt_rdr = new_tt_reader(copy cx.parse_sess().span_diagnostic,
7272
cx.parse_sess().interner, None, tt);
7373
let rdr = tt_rdr as reader;
7474
let rust_parser = Parser(sess, cfg, rdr.dup());

0 commit comments

Comments
 (0)