-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Simplify Source Positions #5713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
d5dfe16
to
c816b6e
Compare
test performance please |
performance test scheduled: 3 job(s) in queue, 1 running. |
Unfortunately, but not unexpectedly, there's again a bunch of REPL tests that break. REPL seems to build trees with multiple source files that are really all different objects standing for the same file. That's a bad idea now, since it will result in missing positions. |
test performance please |
performance test scheduled: 3 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/5713/ to see the changes. Benchmarks is based on merging with master (615fdc9) |
Performance looks OK. So maybe we finally reach the end of the tunnel? |
36c1314
to
f494bd1
Compare
@nicolasstucki Could you give this another round for getting the repl tests to pass? Thanks! |
I will have a look at the repl failures. |
c5635cb
to
4f58ba4
Compare
Rebased |
There is still an issue with
is called twice with the same object. |
Not anymore. Now it only happens when calling |
Are you sure ? The initial span in Positioned is computed using |
I missed that one. |
The issue is that they come from two different files |
Then let's use the same filename 😄. I am wondering if we could use |
That used to work but one commit in this PR actually changed equality to not be based on filenames: 1a358c0 this is more correct in general but means we can't get away with just using the same name for the repl |
I'm already working on that. The solution is to have the same |
test performance please |
performance test scheduled: 1 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/5713/ to see the changes. Benchmarks is based on merging with master (5547a0b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commits for @odersky LGTM
if (f == null || f.isVirtual) | ||
// don't trust virtual files for tree creation - replTest fails otherwise | ||
ctx.source | ||
if (f == null) ctx.source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relieved that we could remove this!
|
||
import scala.annotation.internal.sharable | ||
|
||
/** A parsing result from string input */ | ||
sealed trait ParseResult | ||
|
||
/** An error free parsing resulting in a list of untyped trees */ | ||
case class Parsed(sourceCode: String, trees: List[untpd.Tree]) extends ParseResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks much better.
Commits for @nicolasstucki LGTM |
I ran some stats to find out how many SimpleIdentityMaps of size > 4 we create, and of what size. Test inputs is everything in dotc/typer (about 10000 loc). Here's what we have: SimpleIdentityMap/5 -> 205 Nothing beyond that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff !
This is more efficient, especially for small sizes where setup cost for Array.copy is higher.
This makes the source change tracking in MacroTransform redundant.
@smarter All points addressed now, I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
def Ident(tree: Tree)(name: Name): Ident = tree match { | ||
protected def srcCtx(tree: Tree)(implicit ctx: Context) = ctx.withSource(tree.source) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is never used.
|
||
/** Removes all Inlined trees, replacing them with blocks. | ||
* Repositions all trees directly inside an inlined expansion of a non empty call to the position of the call. | ||
* Any tree directly inside an empty call (inlined in the inlined code) retains their position. | ||
*/ | ||
class Reposition extends TreeMap { | ||
override def transform(tree: Tree)(implicit ctx: Context): Tree = { | ||
tree match { | ||
if (tree.source != ctx.source && tree.source.exists) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed since TreeMap does that now.
@@ -71,11 +71,11 @@ object Parsers { | |||
/** Positions tree. | |||
* If `t` does not have a position yet, set its position to the given one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
position -> span ?
// Nodes which have the same positions as their parents are omitted. | ||
// offset_Deltas give difference of start/end offset wrt to the | ||
// same offset in the previously recorded node (or 0 for the first recorded node) | ||
Delta = Int // Difference between consecutive offsets, | ||
SOURCE = 4 // Impossible as header, since addr_Delta = 0 implies that we refer to the | ||
// same treeas the previous one, but then hasStartDiff = 1 implies that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// same treeas the previous one, but then hasStartDiff = 1 implies that | |
// same tree as the previous one, but then hasStartDiff = 1 implies that |
... and bump major Tasty version Also: drop unused method
005ff4e
to
652b570
Compare
Based on #5644, this PR simplifies and clarifies the handling of source positions.
The source file of a tree is always given explicitly when we construct the tree.
The initial span of the tree is computed from all children that have the
same source as the tree.
Computing the initial span of a tree or setting it using
withSpan
also fills in children's spans where possible. A filled-in child span is one ofWith these changes, there were now various trees that got rejected since they do not have a position (typically since all children come from different sources). This required various fixes, mostly in Inliner and Stager.