Skip to content

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

Merged
merged 8 commits into from
Aug 22, 2017
Merged

Conversation

nicolasstucki
Copy link
Contributor

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.

@nicolasstucki nicolasstucki requested a review from odersky July 28, 2017 14:03
val newOrder = (liftedDefs zip indices).sortBy(_._2).unzip._1
liftedDefs = ListBuffer.empty
liftedDefs ++= newOrder
liftedDefs = (liftedDefs zip indices).sortBy(_._2).unzip._1.to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

case nil => -1
}
}

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor

@odersky odersky left a 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)
Copy link
Contributor

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]
Copy link
Contributor

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
Copy link
Contributor

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 = {
Copy link
Contributor

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 = {
Copy link
Contributor

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.

@odersky odersky assigned nicolasstucki and biboudis and unassigned odersky Aug 16, 2017
@nicolasstucki
Copy link
Contributor Author

Ready for review

@nicolasstucki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 jobs in total.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit https://liufengyun.github.io/bench/2931 to see the changes.

@felixmulder felixmulder merged commit c75c4ac into scala:master Aug 22, 2017
@allanrenucci allanrenucci deleted the fix-i2916 branch December 14, 2017 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants