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

Simplify defn.FunctionOf.unapply #18486

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class CheckCaptures extends Recheck, SymTransformer:
else if meth == defn.Caps_unsafeUnbox then
mapArgUsing(_.forceBoxStatus(false))
else if meth == defn.Caps_unsafeBoxFunArg then
def forceBox(tp: Type): Type = tp match
def forceBox(tp: Type): Type = tp.strippedDealias match
case defn.FunctionOf(paramtpe :: Nil, restpe, isContextual) =>
defn.FunctionOf(paramtpe.forceBoxStatus(true) :: Nil, restpe, isContextual)
case tp @ RefinedType(parent, rname, rinfo: MethodType) =>
Expand Down
13 changes: 5 additions & 8 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1143,16 +1143,13 @@ class Definitions {
else FunctionNOf(args, resultType, isContextual)

def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
ft.dealias match
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason to drop the dealias in the extractor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few reasons:

  • There are few places where that type is not already dealiased
  • In a few cases we used to repeatedly dealias the type in pattern match extractors for functions. Not dealiassing here forces the use site to dealias a single time. Sometimes this happens in cases of a single pattern match and sometimes in the recursion of a TypeMap.
  • This aligns the implementation closer to RefinedFunctionOf, PolyFunctionOf and FunctionTypeOfMethod (in Handle dependent context functions #18443).
  • It brings us one step closer to being able to have a derivedFunctionTypeOf method.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I agree it's good to align the unapply's towards no dealising.

ft match
case PolyFunctionOf(mt: MethodType) =>
Some(mt.paramInfos, mt.resType, mt.isContextualMethod)
case dft =>
val tsym = dft.typeSymbol
if isFunctionSymbol(tsym) && ft.isRef(tsym) then
val targs = dft.argInfos
if (targs.isEmpty) None
else Some(targs.init, targs.last, tsym.name.isContextFunction)
else None
case AppliedType(parent, targs) if isFunctionNType(ft) =>
Some(targs.init, targs.last, ft.typeSymbol.name.isContextFunction)
case _ =>
None
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Recheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object Recheck:
* - in function and method parameter types
* - under annotations
*/
def normalizeByName(tp: Type)(using Context): Type = tp match
def normalizeByName(tp: Type)(using Context): Type = tp.dealias match
case tp: ExprType =>
mapExprType(tp)
case tp: PolyType =>
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2003,10 +2003,7 @@ trait Applications extends Compatibility {
// the arity of that function, otherise -1.
def paramCount(ref: TermRef) =
val formals = ref.widen.firstParamTypes
if formals.length > idx then
formals(idx).dealias match
case defn.FunctionNOf(args, _, _) => args.length
case _ => -1
if formals.length > idx then defn.functionArity(formals(idx))
else -1

val numArgs = args.length
Expand Down