-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2916: Reorder parameters #2931
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
val newOrder = (liftedDefs zip indices).sortBy(_._2).unzip._1 | ||
liftedDefs = ListBuffer.empty | ||
liftedDefs ++= newOrder | ||
liftedDefs = (liftedDefs zip indices).sortBy(_._2).unzip._1.to |
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.
😮
case nil => -1 | ||
} | ||
} | ||
|
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.
Why not simply:
firstDiff(xs, ys.dropWhile(_ == EmptyTree), n)
?
val (liftable, rest) = typedArgs splitAt (typedArgs.length - eqSuffixLength) | ||
|
||
// Mapping of index of each `liftable` into original args ordering |
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.
Lots of state here; better to move this out to a separate method and describe what it does in a doc comment.
nextDefaultParamIndex += 1 | ||
} | ||
} | ||
|
||
typedArgs = liftArgs(liftedDefs, methType, liftable) ++ rest |
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.
Why does it not work if we lift args before reordering?
cf55e6a
to
ee8a4a8
Compare
ee8a4a8
to
733673f
Compare
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.
Otherwise LGTM
|
||
def orderedArgDefs = { | ||
val impureArgs = typedArgBuf.filterNot { // pure are not lifted by liftArgs | ||
case NamedArg(_, arg) => isPureExpr(arg) |
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.
Let's instead add a case for NamedArg
in TreeInfo.exprPurity
. That will avoid the special treatment here.
typedArgs = liftArgs(liftedDefs, methType, liftable) ++ rest | ||
|
||
// lift arguments in the definition order | ||
val argDefBuff = mutable.ListBuffer.empty[Tree] |
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.
Usual naming convention in dotc
is just Buf
for buffer, i.e no double ff.
case NamedArg(_, arg) => isPureExpr(arg) | ||
case arg => isPureExpr(arg) | ||
} | ||
var defaultParamIndex = args.size |
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.
Should be a val
val argDefBuff = mutable.ListBuffer.empty[Tree] | ||
typedArgs = liftArgs(argDefBuff, methType, typedArgs) | ||
|
||
def orderedArgDefs = { |
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.
Can be val
instead of def
.
val argDefBuff = mutable.ListBuffer.empty[Tree] | ||
typedArgs = liftArgs(argDefBuff, methType, typedArgs) | ||
|
||
def orderedArgDefs = { |
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.
Since the logic here is somewhat tricky, it would be good to add a comment with an example, what orderedArgDefs is supposed to achieve.
Ready for review |
test performance please |
performance test scheduled: 1 jobs in total. |
Performance test finished successfully: Visit https://liufengyun.github.io/bench/2931 to see the changes. |
This fixes the ordering issue described in #2916.
Additionally fixes another related issue where not all parameters that needed to be lifted where lifted. All these in presence of reordering done when having combination of effectful/pure arguments.