Skip to content

Commit ca9cf35

Browse files
committedAug 30, 2017
Auto merge of #43968 - petrochenkov:span2, r=michaelwoerister
Make fields of `Span` private I actually tried to intern spans and benchmark the result<sup>*</sup>, and this was a prerequisite. This kind of encapsulation will be a prerequisite for any other attempt to compress span's representation, so I decided to submit this change alone. The issue #43088 seems relevant, but it looks like `SpanId` won't be able to reuse this interface, unless the tables are global (like interner that I tried) and are not a part of HIR. r? @michaelwoerister anyway <sup>*</sup> Interning means 2-3 times more space is required for a single span, but duplicates are free. In practice it turned out that duplicates are not *that* common, so more memory was wasted by interning rather than saved.
2 parents c66e7fa + a0c3264 commit ca9cf35

File tree

60 files changed

+325
-346
lines changed

Some content is hidden

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

60 files changed

+325
-346
lines changed
 

‎src/libproc_macro/lib.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ impl FromStr for TokenStream {
8989
// notify the expansion info that it is unhygienic
9090
let mark = Mark::fresh(mark);
9191
mark.set_expn_info(expn_info);
92-
let span = syntax_pos::Span {
93-
ctxt: SyntaxContext::empty().apply_mark(mark),
94-
..call_site
95-
};
92+
let span = call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark));
9693
let stream = parse::parse_stream_from_source_str(name, src, sess, Some(span));
9794
Ok(__internal::token_stream_wrap(stream))
9895
})
@@ -177,10 +174,10 @@ pub struct Span(syntax_pos::Span);
177174
#[unstable(feature = "proc_macro", issue = "38356")]
178175
impl Default for Span {
179176
fn default() -> Span {
180-
::__internal::with_sess(|(_, mark)| Span(syntax_pos::Span {
181-
ctxt: SyntaxContext::empty().apply_mark(mark),
182-
..mark.expn_info().unwrap().call_site
183-
}))
177+
::__internal::with_sess(|(_, mark)| {
178+
let call_site = mark.expn_info().unwrap().call_site;
179+
Span(call_site.with_ctxt(SyntaxContext::empty().apply_mark(mark)))
180+
})
184181
}
185182
}
186183

@@ -570,7 +567,7 @@ impl TokenTree {
570567
}).into();
571568
},
572569
TokenNode::Term(symbol) => {
573-
let ident = ast::Ident { name: symbol.0, ctxt: self.span.0.ctxt };
570+
let ident = ast::Ident { name: symbol.0, ctxt: self.span.0.ctxt() };
574571
let token =
575572
if symbol.0.as_str().starts_with("'") { Lifetime(ident) } else { Ident(ident) };
576573
return TokenTree::Token(self.span.0, token).into();

‎src/librustc/hir/lowering.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,7 @@ impl<'a> LoweringContext<'a> {
425425
Symbol::gensym(s)
426426
}
427427

428-
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, mut span: Span)
429-
-> Span
428+
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span
430429
{
431430
let mark = Mark::fresh(Mark::root());
432431
mark.set_expn_info(codemap::ExpnInfo {
@@ -438,8 +437,7 @@ impl<'a> LoweringContext<'a> {
438437
allow_internal_unsafe: false,
439438
},
440439
});
441-
span.ctxt = SyntaxContext::empty().apply_mark(mark);
442-
span
440+
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
443441
}
444442

445443
fn with_catch_scope<T, F>(&mut self, catch_id: NodeId, f: F) -> T
@@ -613,7 +611,7 @@ impl<'a> LoweringContext<'a> {
613611
TyKind::Slice(ref ty) => hir::TySlice(self.lower_ty(ty)),
614612
TyKind::Ptr(ref mt) => hir::TyPtr(self.lower_mt(mt)),
615613
TyKind::Rptr(ref region, ref mt) => {
616-
let span = Span { hi: t.span.lo, ..t.span };
614+
let span = t.span.with_hi(t.span.lo());
617615
let lifetime = match *region {
618616
Some(ref lt) => self.lower_lifetime(lt),
619617
None => self.elided_lifetime(span)
@@ -1237,7 +1235,7 @@ impl<'a> LoweringContext<'a> {
12371235
name: self.lower_ident(match f.ident {
12381236
Some(ident) => ident,
12391237
// FIXME(jseyfried) positional field hygiene
1240-
None => Ident { name: Symbol::intern(&index.to_string()), ctxt: f.span.ctxt },
1238+
None => Ident { name: Symbol::intern(&index.to_string()), ctxt: f.span.ctxt() },
12411239
}),
12421240
vis: self.lower_visibility(&f.vis, None),
12431241
ty: self.lower_ty(&f.ty),

0 commit comments

Comments
 (0)
Please sign in to comment.