Uh oh!
There was an error while loading. Please reload this page.
Make fields of Span private - #43968
Conversation
There was a problem hiding this comment.
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].
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yeah, seems better, I'll rename.
There was a problem hiding this comment.
Huh? Just return span.set_ctxt(SyntaxContext::empty().apply_mark(mark)) directly.
There was a problem hiding this comment.
Wouldn't it make more sense to do the following in all the set_x methods?
Span{lo, ..self}There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Is it really necessary to use the public getters in the impl?
There was a problem hiding this comment.
I guess it would be if spans were really interned. For now I'd also opt for just accessing the fields directly.
michaelwoerister
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks, @petrochenkov! I'm also for renaming the set_x methods to with_x. Other than that (and maybe not using the getters in impl Span) this is good to go.
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?
There was a problem hiding this comment.
I guess it would be if spans were really interned. For now I'd also opt for just accessing the fields directly.
petrochenkov
commented
Aug 18, 2017
I remembered there was a thread about this somewhere! Thanks for the link. |
petrochenkov
commented
Aug 18, 2017
Updated. |
There was a problem hiding this comment.
I believe this can be replaced with Some(sp_lhs.to(sp_rhs)).
bors
commented
Aug 19, 2017
☔ The latest upstream changes (presumably #43933) made this pull request unmergeable. Please resolve the merge conflicts. |
michaelwoerister
commented
Aug 19, 2017
Thanks! r=me after rebasing. |
petrochenkov
commented
Aug 19, 2017
@bors r=michaelwoerister |
bors
commented
Aug 19, 2017
📌 Commit cdae234 has been approved by |
bors
commented
Aug 19, 2017
⌛ Testing commit cdae2343dba5a47c3e9846b6e7c8521ac1102c2c with merge 17e924eb9a0484958fe948c38b20c93644eb3137... |
bors
commented
Aug 19, 2017
💔 Test failed - status-travis |
petrochenkov
commented
Aug 19, 2017
Sigh, need to send a PR to |
kennytm
commented
Aug 20, 2017
We've hit a deadlock situation where the I think this PR should be split into two stages,
|
petrochenkov
commented
Aug 20, 2017
@kennytm |
petrochenkov
commented
Aug 20, 2017
I gathered some span statistics from rustc/libstd and found a significant number of "reverse" spans with I'm going to add "normalization" to |
petrochenkov
commented
Aug 20, 2017
@bors r=michaelwoerister |
bors
commented
Aug 20, 2017
📌 Commit 3da163f has been approved by |
bors
commented
Aug 20, 2017
⌛ Testing commit 3da163f55b1dd62f247f63edee30f64e3e7da2f5 with merge 4ad2c420bbe6368916158ddb4b354a7652a02d72... |
bors
commented
Aug 21, 2017
💔 Test failed - status-travis |
petrochenkov
commented
Aug 21, 2017
@bors r=michaelwoerister |
bors
commented
Aug 21, 2017
📌 Commit c4125e2 has been approved by |
bors
commented
Aug 21, 2017
⌛ Testing commit c4125e26389fbe5beceed0c562a47dfb3e45df07 with merge c1ad7551a567319ae597b9643a3dcf627d9bf8e2... |
bors
commented
Aug 21, 2017
💔 Test failed - status-travis |
kennytm
commented
Aug 21, 2017
|
nrc
commented
Aug 22, 2017
Possibly a bad span produced in save-analysis? |
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. |
estebank
commented
Aug 22, 2017
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 |
petrochenkov
commented
Aug 23, 2017
Waiting on #44028 |
I have only numbers unfortunately. Looks like the only way to obtain the source of inverted spans from |
estebank
commented
Aug 24, 2017
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. |
bors
commented
Aug 26, 2017
☔ The latest upstream changes (presumably #44028) made this pull request unmergeable. Please resolve the merge conflicts. |
Not sure about |
This helps to avoid landing changes to rustc and rustfmt in one step
petrochenkov
commented
Aug 29, 2017
I'll try to land changes to rustc and rustfmt in two steps (rustfmt is moving forward too fast), so I made fields of |
bors
commented
Aug 29, 2017
📌 Commit a0c3264 has been approved by |
bors
commented
Aug 30, 2017
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.
bors
commented
Aug 30, 2017
☀️ Test successful - status-appveyor, status-travis |
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.