Skip to content

Commit 74f4271

Browse files
committedSep 21, 2017
Use 64-bit span, keep 1-bit tag
1 parent 08a235c commit 74f4271

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed
 

‎src/libsyntax_pos/span_encoding.rs

+21-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use super::*;
2323
/// See `SpanData` for the info on span fields in decoded representation.
2424
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
2525
#[repr(packed)]
26-
pub struct Span(u32);
26+
pub struct Span(u64);
2727

2828
/// Dummy span, both position and length are zero, syntax context is zero as well.
2929
/// This span is kept inline and encoded with format 0.
@@ -45,9 +45,9 @@ impl Span {
4545
}
4646

4747
// Tags
48-
const TAG_INLINE: u32 = 0;
49-
const TAG_INTERNED: u32 = 1;
50-
const TAG_MASK: u32 = 1;
48+
const TAG_INLINE: u64 = 0;
49+
const TAG_INTERNED: u64 = 1;
50+
const TAG_MASK: u64 = 1;
5151

5252
// Fields indexes
5353
const BASE_INDEX: usize = 0;
@@ -56,39 +56,39 @@ const CTXT_INDEX: usize = 2;
5656

5757
// Tag = 0, inline format.
5858
// -----------------------------------
59-
// | base 31:8 | len 7:1 | tag 0:0 |
59+
// | base 63:39 | len 38:15 | ctxt 14:1 | tag 0:0 |
6060
// -----------------------------------
61-
const INLINE_SIZES: [u32; 3] = [24, 7, 0];
62-
const INLINE_OFFSETS: [u32; 3] = [8, 1, 1];
61+
const INLINE_SIZES: [u64; 3] = [25, 24, 14];
62+
const INLINE_OFFSETS: [u64; 3] = [39, 15, 1];
6363

6464
// Tag = 1, interned format.
6565
// ------------------------
66-
// | index 31:1 | tag 0:0 |
66+
// | index 63:1 | tag 0:0 |
6767
// ------------------------
68-
const INTERNED_INDEX_SIZE: u32 = 31;
69-
const INTERNED_INDEX_OFFSET: u32 = 1;
68+
const INTERNED_INDEX_SIZE: u64 = 63;
69+
const INTERNED_INDEX_OFFSET: u64 = 1;
7070

7171
fn encode(sd: &SpanData) -> Span {
72-
let (base, len, ctxt) = (sd.lo.0, sd.hi.0 - sd.lo.0, sd.ctxt.0);
72+
let (base, len, ctxt) = (sd.lo.0 as u64, (sd.hi.0 - sd.lo.0) as u64, sd.ctxt.0 as u64);
7373

7474
let val = if (base >> INLINE_SIZES[BASE_INDEX]) == 0 &&
7575
(len >> INLINE_SIZES[LEN_INDEX]) == 0 &&
7676
(ctxt >> INLINE_SIZES[CTXT_INDEX]) == 0 {
7777
(base << INLINE_OFFSETS[BASE_INDEX]) | (len << INLINE_OFFSETS[LEN_INDEX]) |
7878
(ctxt << INLINE_OFFSETS[CTXT_INDEX]) | TAG_INLINE
7979
} else {
80-
let index = with_span_interner(|interner| interner.intern(sd));
80+
let index = with_span_interner(|interner| interner.intern(sd)) as u64;
8181
(index << INTERNED_INDEX_OFFSET) | TAG_INTERNED
8282
};
8383
Span(val)
8484
}
8585

8686
fn decode(span: Span) -> SpanData {
87-
let val = span.0;
87+
let val = span.0 as u64;
8888

8989
// Extract a field at position `pos` having size `size`.
90-
let extract = |pos: u32, size: u32| {
91-
let mask = ((!0u32) as u64 >> (32 - size)) as u32; // Can't shift u32 by 32
90+
let extract = |pos: u64, size: u64| {
91+
let mask = (!0u64) >> (64 - size);
9292
(val >> pos) & mask
9393
};
9494

@@ -98,9 +98,13 @@ fn decode(span: Span) -> SpanData {
9898
extract(INLINE_OFFSETS[CTXT_INDEX], INLINE_SIZES[CTXT_INDEX]),
9999
)} else {
100100
let index = extract(INTERNED_INDEX_OFFSET, INTERNED_INDEX_SIZE);
101-
return with_span_interner(|interner| *interner.get(index));
101+
return with_span_interner(|interner| *interner.get(index as u32));
102102
};
103-
SpanData { lo: BytePos(base), hi: BytePos(base + len), ctxt: SyntaxContext(ctxt) }
103+
SpanData {
104+
lo: BytePos(base as u32),
105+
hi: BytePos((base + len) as u32),
106+
ctxt: SyntaxContext(ctxt as u32)
107+
}
104108
}
105109

106110
#[derive(Default)]

0 commit comments

Comments
 (0)
Please sign in to comment.