Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMake fields of `Span` private #43968
Conversation
rust-highfive
assigned
michaelwoerister
Aug 18, 2017
petrochenkov
reviewed
Aug 18, 2017
| } | ||
| #[inline] | ||
| #[must_use] | ||
| pub fn set_lo(self, lo: BytePos) -> Span { |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Aug 18, 2017
•
Author
Contributor
I'm not sure set_x are the best possible names since the functions are not mutating, but at least I guarded them from mistakes with #[must_use].
This comment has been minimized.
This comment has been minimized.
estebank
Aug 18, 2017
Contributor
Should the fields be named with_x? In my mind that conjures the fact that the method returns a copy of the same type with the field having the new value.
This comment has been minimized.
This comment has been minimized.
kennytm
reviewed
Aug 18, 2017
| @@ -425,7 +425,7 @@ impl<'a> LoweringContext<'a> { | |||
| allow_internal_unsafe: false, | |||
| }, | |||
| }); | |||
| span.ctxt = SyntaxContext::empty().apply_mark(mark); | |||
| span = span.set_ctxt(SyntaxContext::empty().apply_mark(mark)); | |||
| span | |||
This comment has been minimized.
This comment has been minimized.
kennytm
Aug 18, 2017
Member
Huh? Just return span.set_ctxt(SyntaxContext::empty().apply_mark(mark)) directly.
estebank
reviewed
Aug 18, 2017
| #[inline] | ||
| #[must_use] | ||
| pub fn set_lo(self, lo: BytePos) -> Span { | ||
| Span::new(lo, self.hi(), self.ctxt()) |
This comment has been minimized.
This comment has been minimized.
estebank
Aug 18, 2017
Contributor
Wouldn't it make more sense to do the following in all the set_x methods?
Span {lo, ..self}
This comment has been minimized.
This comment has been minimized.
petrochenkov
Aug 18, 2017
Author
Contributor
It was necessary with interning (the same is true for #43968 (comment)). It will be necessary with any non-trivial Span::new/Span::lo/etc, so I left it.
| } | ||
| #[inline] | ||
| #[must_use] | ||
| pub fn set_lo(self, lo: BytePos) -> Span { |
This comment has been minimized.
This comment has been minimized.
estebank
Aug 18, 2017
Contributor
Should the fields be named with_x? In my mind that conjures the fact that the method returns a copy of the same type with the field having the new value.
| let lo = cmp::max(self.hi.0 - 1, self.lo.0); | ||
| Span { lo: BytePos(lo), ..self } | ||
| let lo = cmp::max(self.hi().0 - 1, self.lo().0); | ||
| self.set_lo(BytePos(lo)) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Aug 18, 2017
Contributor
I guess it would be if spans were really interned. For now I'd also opt for just accessing the fields directly.
michaelwoerister
reviewed
Aug 18, 2017
|
Looks good to me. Thanks, @petrochenkov! I'm also for renaming the You might be interested in this: A couple of years ago I did some experiments with span interning plus storing the span information directly in the interning key, if it fit in there (like a tagged pointer). The results were actually quite promising, if I remember correctly: https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/23. Maybe you want to revisit interning with this additional optimization? |
| let lo = cmp::max(self.hi.0 - 1, self.lo.0); | ||
| Span { lo: BytePos(lo), ..self } | ||
| let lo = cmp::max(self.hi().0 - 1, self.lo().0); | ||
| self.set_lo(BytePos(lo)) |
This comment has been minimized.
This comment has been minimized.
michaelwoerister
Aug 18, 2017
Contributor
I guess it would be if spans were really interned. For now I'd also opt for just accessing the fields directly.
This comment has been minimized.
This comment has been minimized.
I remembered there was a thread about this somewhere! Thanks for the link. |
petrochenkov
force-pushed the
petrochenkov:span2
branch
from
2c1d664
to
9fed6da
Aug 18, 2017
This comment has been minimized.
This comment has been minimized.
|
Updated. |
estebank
reviewed
Aug 19, 2017
| Some(Span::new( | ||
| cmp::min(sp_lhs.lo(), sp_rhs.lo()), | ||
| cmp::max(sp_lhs.hi(), sp_rhs.hi()), | ||
| sp_lhs.ctxt() |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Thanks! r=me after rebasing. |
petrochenkov
force-pushed the
petrochenkov:span2
branch
from
9fed6da
to
cdae234
Aug 19, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r=michaelwoerister |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Aug 19, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Sigh, need to send a PR to |
petrochenkov
referenced this pull request
Aug 19, 2017
Closed
Use getters to access `Span` fields #1899
This comment has been minimized.
This comment has been minimized.
|
We've hit a deadlock situation where the I think this PR should be split into two stages,
|
This comment has been minimized.
This comment has been minimized.
|
@kennytm |
This comment has been minimized.
This comment has been minimized.
|
I gathered some span statistics from rustc/libstd and found a significant number of "reverse" spans with I'm going to add "normalization" to |
nrc
added a commit
to rust-lang/rls
that referenced
this pull request
Aug 20, 2017
petrochenkov
force-pushed the
petrochenkov:span2
branch
from
cdae234
to
3da163f
Aug 20, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r=michaelwoerister |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Aug 20, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors r=michaelwoerister |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Aug 21, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
Possibly a bad span produced in save-analysis? |
This comment has been minimized.
This comment has been minimized.
|
The errors are caused by RLS update, not by span patches, i.e. 9061581 alone (without rust-lang/rls@f4e6f16) is enough to reproduce them. |
This comment has been minimized.
This comment has been minimized.
|
Could you provide a dump of the reversed spans? I've seen them every now and then but have put off investigating the root cause(s). There are a few possible very unseemly results that could happen, for example when doing |
arielb1
added
the
S-waiting-on-author
label
Aug 22, 2017
This comment has been minimized.
This comment has been minimized.
|
Waiting on #44028 |
This comment has been minimized.
This comment has been minimized.
I have only numbers unfortunately. Looks like the only way to obtain the source of inverted spans from |
This comment has been minimized.
This comment has been minimized.
|
Sounds reasonable. Will do. Are asserts only enabled on nightly? Would rather not cause ICEs for a rather benign bug just because it isn't caught in the test, but would like to see he effects of it on cargo bomb. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
Not sure about |
nrc
added a commit
to rust-lang/rls
that referenced
this pull request
Aug 27, 2017
petrochenkov
added some commits
Jul 31, 2017
petrochenkov
force-pushed the
petrochenkov:span2
branch
from
c4125e2
to
a0c3264
Aug 29, 2017
This comment has been minimized.
This comment has been minimized.
|
I'll try to land changes to rustc and rustfmt in two steps (rustfmt is moving forward too fast), so I made fields of |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Aug 30, 2017
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov commentedAug 18, 2017
•
edited
I actually tried to intern spans and benchmark the result*, 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
SpanIdwon'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
* 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.