Skip to content

Refactor function type logic #18193

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 10 commits into from
Jul 13, 2023
Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Jul 12, 2023

  • Rename isFucntionType to isFunctionNType
    (tests for FunctionN/ContextFunctionN)
  • Rename isFunctionOrPolyType to isFunctionType
    (tests for FunctionN/ContextFunctionN/PolyFunction/ErasedFunction)
  • Rename isRefinedFunctionType to isPolyOrErasedFunctionType
    (tests for PolyFunction/ErasedFunction)
  • Define isPolyFunctionType
  • Refactor uses of isPolyFunctionType/isErasedFunctionType/isPolyOrErasedFunctionType
  • Simplify/generalize erasure of refined function types

Followup of dotty-staging@6a349b5#r121364261

This way we are explicit on the fact that this methods does not cover
`PolyFunction` and `ErasedFunction`.
This method checks if the type is any kind of function type: `FunctionN`,
`ContextFunctionN`, `PolyFunction`, and `ErasedFunction`.
The erasure now supports polymorphic function types with erased parameters.
We still need to add support for this in the typer.
@nicolasstucki
Copy link
Contributor Author

We should double-check all uses of isFunctionNType to determine which ones might actually need isFunctionType.

@nicolasstucki nicolasstucki force-pushed the refector-isFunctionType branch from 1eedc1c to 8a202e5 Compare July 12, 2023 14:59
@nicolasstucki nicolasstucki marked this pull request as ready for review July 13, 2023 09:25
@nicolasstucki nicolasstucki requested a review from smarter July 13, 2023 09:25
Copy link
Member

@smarter smarter 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.

Comment on lines 1891 to 1893
case mt: MethodType if !mt.isParamDependent =>
assert(mt.hasErasedParams)
RefinedType(defn.ErasedFunctionType, nme.apply, mt)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding a case, I suggest changing the existing case mt: MethodType if !mt.isParamDependent => case to contain an if mt.hasErasedParams then ... else ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also moved !mt.isParamDependent into assertions to make it clear that this is unexpected.

@@ -1709,21 +1710,29 @@ class Definitions {
* - scala.FunctionN
* - scala.ContextFunctionN
*/
def isFunctionType(tp: Type)(using Context): Boolean =
def isFunctionNType(tp: Type)(using Context): Boolean =
isNonRefinedFunction(tp.dropDependentRefinement)

/** Is `tp` a specialized, refined function type? Either an `ErasedFunction` or a `PolyFunction`. */
def isRefinedFunctionType(tp: Type)(using Context): Boolean =
Copy link
Member

Choose a reason for hiding this comment

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

"refined function type" is a misleading name because dependent function types also contain a refinement but aren't covered here, so I would call this isPolyOrErasedFunctionType if we can't find something better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used isPolyOrErasedFunctionType

@smarter smarter assigned nicolasstucki and unassigned smarter Jul 13, 2023
@smarter smarter enabled auto-merge July 13, 2023 14:33
case info1: PolyType =>
return isSubInfo(info1, tp2.refinedInfo)
case _ =>
else
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure why there is a difference between the two comparisons. Would it work to always use the second one, which tests for RefinedType?

Copy link
Contributor Author

@nicolasstucki nicolasstucki Jul 13, 2023

Choose a reason for hiding this comment

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

I will try to merge the two cases into one (in #18200).

@smarter smarter merged commit 967aefc into scala:main Jul 13, 2023
@smarter smarter deleted the refector-isFunctionType branch July 13, 2023 19:12
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Kordyjan added a commit that referenced this pull request Dec 8, 2023
Backports #18193 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
@Kordyjan Kordyjan modified the milestones: 3.4.0, 3.3.2 Dec 14, 2023
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.

4 participants