Skip to content
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

Refactor constant folding of applications #20099

Merged
merged 2 commits into from
Apr 8, 2024

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 5, 2024

Move them in typedApply/typedTypeApply instead of leaving them until adapt. This aligns these folds with folds of unary operations, which are done already in typedSelect and avoids potentially several calls to ConstFold when arguments are passed to overloaded methods.

Move them in typedApply/typedTypeApply instead of leaving them until adapt.
This aligns these folds with folds of uniary operations, which are done already
in typedSelect and avoids potentially several calls to ConstFold when arguments
are passed to overloaded methods.
@odersky odersky marked this pull request as ready for review April 6, 2024 19:41
Copy link
Contributor

@EugeneFlesselle EugeneFlesselle left a comment

Choose a reason for hiding this comment

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

I believe the ConstFold in TypeAssigner could now also be removed

def assignType(tree: untpd.TypeApply, fn: Tree, args: List[Tree])(using Context): TypeApply = {
def fail = tree.withType(errorType(err.takesNoParamsMsg(fn, "type "), tree.srcPos))
ConstFold(fn.tpe.widen match {

Otherwise looks good to me !

@odersky
Copy link
Contributor Author

odersky commented Apr 8, 2024

Not sure about the TypeAssigner one. Directly constructed TypeApply don't go through Applications, so we would stop constant folding them.

@@ -1189,7 +1190,8 @@ trait Applications extends Compatibility {
case _ => tree.withType(TryDynamicCallType)
}
if (typedFn.tpe eq TryDynamicCallType) tryDynamicTypeApply()
else assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs)
else
ConstFold(assignType(cpy.TypeApply(tree)(typedFn, typedArgs), typedFn, typedArgs))
Copy link
Contributor

Choose a reason for hiding this comment

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

But do we need this one then ? I'm confused about why we need both of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. We don't need the one here.

@odersky odersky merged commit 321d0d2 into scala:main Apr 8, 2024
19 checks passed
@odersky odersky deleted the refactor-constfold branch April 8, 2024 20:42
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
WojciechMazur added a commit that referenced this pull request Jul 5, 2024
Backports #20099 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

3 participants