-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add pattern matcher optimizations #2829
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
c6076a0
Polishings
odersky 886b2a1
Add new pattern matcher
odersky b2aa27e
Fixes to pattern matcher
odersky 6fd3971
Make IsInstanceOfEvaluator more robust
odersky e8eb6d9
Fix isInstanceOfEvaluator
odersky f55959c
Test outer pointer in pattern matches
odersky e325601
Fixes to PatMat
odersky 0717f18
Make TypeTestsCasts an Object
odersky 4057fb2
Fix typo in TypeMap
odersky a43d8c1
Refine tpd.isInstance
odersky 003301b
Add structural equality === for some trees
odersky 2e7294c
Perform switch optimization in pattern matcher
odersky 96dd7fd
Warn on failed switch optimization
odersky ff473ba
Update test
odersky 499eed4
Refactorings
odersky fb03273
Replace previous pattern matcher
odersky 40910d8
More docs and some cleanups
odersky bcd9836
Turn optimisations for tests on again.
odersky 8c4323f
Turn off local optimizations again
odersky 90226bd
Some small tweaks
odersky 0e4e2bd
More extensive optimizations
odersky aaf9d7d
Split vars and labels
odersky eec5732
Update documentation
odersky 661f392
Fix typo
odersky e61ef5d
Refactor optimizations
odersky b4377dc
More aggressive variable sharing
odersky 7ce9e80
Fix docs
odersky 8eacccf
Improve sanitize algorithm
odersky 53d8fef
Refine condition when emitted code is a switch
odersky c97d783
Avoid test-pickling failure.
odersky e138568
Disable optimization
odersky 79493df
Address reviewers comments
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -663,6 +663,37 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => | |
case _ => | ||
false | ||
} | ||
|
||
/** Structural tree comparison (since == on trees is reference equality). | ||
* For the moment, only Ident, Select, Literal, Apply and TypeApply are supported | ||
*/ | ||
implicit class StructuralEqDeco(t1: Tree) { | ||
def === (t2: Tree)(implicit ctx: Context): Boolean = (t1, t2) match { | ||
case (t1: Ident, t2: Ident) => | ||
t1.symbol == t2.symbol | ||
case (t1 @ Select(q1, _), t2 @ Select(q2, _)) => | ||
t1.symbol == t2.symbol && q1 === q2 | ||
case (Literal(c1), Literal(c2)) => | ||
c1 == c2 | ||
case (Apply(f1, as1), Apply(f2, as2)) => | ||
f1 === f2 && as1.corresponds(as2)(_ === _) | ||
case (TypeApply(f1, ts1), TypeApply(f2, ts2)) => | ||
f1 === f2 && ts1.tpes.corresponds(ts2.tpes)(_ =:= _) | ||
case _ => | ||
false | ||
} | ||
def hash(implicit ctx: Context): Int = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code? |
||
t1.getClass.hashCode * 37 + { | ||
t1 match { | ||
case t1: Ident => t1.symbol.hashCode | ||
case t1 @ Select(q1, _) => t1.symbol.hashCode * 41 + q1.hash | ||
case Literal(c1) => c1.hashCode | ||
case Apply(f1, as1) => (f1.hash /: as1)((h, arg) => h * 41 + arg.hash) | ||
case TypeApply(f1, ts1) => (f1.hash /: ts1)((h, arg) => h * 41 + arg.tpe.hash) | ||
case _ => t1.hashCode | ||
} | ||
} | ||
} | ||
} | ||
|
||
object TreeInfo { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A lot of code in Dotty has a habbit of needlessly wrapping code in Block(Nil, expr).
It would be nice to add a case here that handles blocks to make it more robust.