Skip to content

Experimental Support for Dependent Type Arguments - Step 1: Parsing #8863

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 9 commits into from
May 26, 2020
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
18 changes: 18 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,11 @@ object Trees {
type ThisTree[-T >: Untyped] = LambdaTypeTree[T]
}

case class TermLambdaTypeTree[-T >: Untyped] private[ast] (params: List[ValDef[T]], body: Tree[T])(implicit @constructorOnly src: SourceFile)
extends TypTree[T] {
type ThisTree[-T >: Untyped] = TermLambdaTypeTree[T]
}

/** [bound] selector match { cases } */
case class MatchTypeTree[-T >: Untyped] private[ast] (bound: Tree[T], selector: Tree[T], cases: List[CaseDef[T]])(implicit @constructorOnly src: SourceFile)
extends TypTree[T] {
Expand Down Expand Up @@ -964,6 +969,7 @@ object Trees {
type RefinedTypeTree = Trees.RefinedTypeTree[T]
type AppliedTypeTree = Trees.AppliedTypeTree[T]
type LambdaTypeTree = Trees.LambdaTypeTree[T]
type TermLambdaTypeTree = Trees.TermLambdaTypeTree[T]
type MatchTypeTree = Trees.MatchTypeTree[T]
type ByNameTypeTree = Trees.ByNameTypeTree[T]
type TypeBoundsTree = Trees.TypeBoundsTree[T]
Expand Down Expand Up @@ -1135,6 +1141,10 @@ object Trees {
case tree: LambdaTypeTree if (tparams eq tree.tparams) && (body eq tree.body) => tree
case _ => finalize(tree, untpd.LambdaTypeTree(tparams, body)(sourceFile(tree)))
}
def TermLambdaTypeTree(tree: Tree)(params: List[ValDef], body: Tree)(implicit ctx: Context): TermLambdaTypeTree = tree match {
case tree: TermLambdaTypeTree if (params eq tree.params) && (body eq tree.body) => tree
case _ => finalize(tree, untpd.TermLambdaTypeTree(params, body)(sourceFile(tree)))
}
def MatchTypeTree(tree: Tree)(bound: Tree, selector: Tree, cases: List[CaseDef])(implicit ctx: Context): MatchTypeTree = tree match {
case tree: MatchTypeTree if (bound eq tree.bound) && (selector eq tree.selector) && (cases eq tree.cases) => tree
case _ => finalize(tree, untpd.MatchTypeTree(bound, selector, cases)(sourceFile(tree)))
Expand Down Expand Up @@ -1293,6 +1303,10 @@ object Trees {
inContext(localCtx) {
cpy.LambdaTypeTree(tree)(transformSub(tparams), transform(body))
}
case TermLambdaTypeTree(params, body) =>
inContext(localCtx) {
cpy.TermLambdaTypeTree(tree)(transformSub(params), transform(body))
}
case MatchTypeTree(bound, selector, cases) =>
cpy.MatchTypeTree(tree)(transform(bound), transform(selector), transformSub(cases))
case ByNameTypeTree(result) =>
Expand Down Expand Up @@ -1422,6 +1436,10 @@ object Trees {
inContext(localCtx) {
this(this(x, tparams), body)
}
case TermLambdaTypeTree(params, body) =>
inContext(localCtx) {
this(this(x, params), body)
}
case MatchTypeTree(bound, selector, cases) =>
this(this(this(x, bound), selector), cases)
case ByNameTypeTree(result) =>
Expand Down
11 changes: 9 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def RefinedTypeTree(tpt: Tree, refinements: List[Tree])(implicit src: SourceFile): RefinedTypeTree = new RefinedTypeTree(tpt, refinements)
def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit src: SourceFile): AppliedTypeTree = new AppliedTypeTree(tpt, args)
def LambdaTypeTree(tparams: List[TypeDef], body: Tree)(implicit src: SourceFile): LambdaTypeTree = new LambdaTypeTree(tparams, body)
def TermLambdaTypeTree(params: List[ValDef], body: Tree)(implicit src: SourceFile): TermLambdaTypeTree = new TermLambdaTypeTree(params, body)
def MatchTypeTree(bound: Tree, selector: Tree, cases: List[CaseDef])(implicit src: SourceFile): MatchTypeTree = new MatchTypeTree(bound, selector, cases)
def ByNameTypeTree(result: Tree)(implicit src: SourceFile): ByNameTypeTree = new ByNameTypeTree(result)
def TypeBoundsTree(lo: Tree, hi: Tree, alias: Tree = EmptyTree)(implicit src: SourceFile): TypeBoundsTree = new TypeBoundsTree(lo, hi, alias)
Expand Down Expand Up @@ -485,8 +486,14 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
ValDef(nme.syntheticParamName(n), if (tpt == null) TypeTree() else tpt, EmptyTree)
.withFlags(flags)

def lambdaAbstract(tparams: List[TypeDef], tpt: Tree)(implicit ctx: Context): Tree =
if (tparams.isEmpty) tpt else LambdaTypeTree(tparams, tpt)
def lambdaAbstract(params: List[ValDef] | List[TypeDef], tpt: Tree)(using Context): Tree =
params match
case Nil => tpt
case (vd: ValDef) :: _ => TermLambdaTypeTree(params.asInstanceOf[List[ValDef]], tpt)
case _ => LambdaTypeTree(params.asInstanceOf[List[TypeDef]], tpt)

def lambdaAbstractAll(paramss: List[List[ValDef] | List[TypeDef]], tpt: Tree)(using Context): Tree =
paramss.foldRight(tpt)(lambdaAbstract)

/** A reference to given definition. If definition is a repeated
* parameter, the reference will be a repeated argument.
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotc
package config

import core._
import Contexts._, Symbols._, Names._
import Contexts._, Symbols._, Names._, NameOps._
import StdNames.nme
import Decorators.{given _}
import util.SourcePosition
Expand All @@ -22,7 +22,7 @@ object Feature:
def enabledBySetting(feature: TermName, owner: Symbol = NoSymbol)(using Context): Boolean =
def toPrefix(sym: Symbol): String =
if !sym.exists || sym == defn.LanguageModule.moduleClass then ""
else toPrefix(sym.owner) + sym.name + "."
else toPrefix(sym.owner) + sym.name.stripModuleClassSuffix + "."
val prefix = if owner.exists then toPrefix(owner) else ""
ctx.base.settings.language.value.contains(prefix + feature)

Expand All @@ -38,7 +38,7 @@ object Feature:
def enabledByImport(feature: TermName, owner: Symbol = NoSymbol)(using Context): Boolean =
ctx.atPhase(ctx.typerPhase) {
ctx.importInfo != null
&& ctx.importInfo.featureImported(feature.toTermName,
&& ctx.importInfo.featureImported(feature,
if owner.exists then owner else defn.LanguageModule.moduleClass)
}

Expand All @@ -57,6 +57,9 @@ object Feature:
def dynamicsEnabled(using Context): Boolean =
enabled(nme.dynamics)

def dependentEnabled(using Context) =
enabled(nme.dependent, defn.LanguageExperimentalModule.moduleClass)

def sourceVersionSetting(using Context): SourceVersion =
SourceVersion.valueOf(ctx.settings.source.value)

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ class Definitions {
@tu lazy val Mirror_SingletonProxyClass: ClassSymbol = ctx.requiredClass("scala.deriving.Mirror.SingletonProxy")

@tu lazy val LanguageModule: Symbol = ctx.requiredModule("scala.language")
@tu lazy val LanguageExperimentalModule: Symbol = ctx.requiredModule("scala.language.experimental")
@tu lazy val NonLocalReturnControlClass: ClassSymbol = ctx.requiredClass("scala.runtime.NonLocalReturnControl")
@tu lazy val SelectableClass: ClassSymbol = ctx.requiredClass("scala.Selectable")

Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ object StdNames {
val definitions: N = "definitions"
val delayedInit: N = "delayedInit"
val delayedInitArg: N = "delayedInit$body"
val dependent: N = "dependent"
val derived: N = "derived"
val derives: N = "derives"
val drop: N = "drop"
Expand Down
Loading