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

Syntax changes for new implicits #5825

Merged
merged 16 commits into from
Feb 4, 2019
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
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,8 @@ object desugar {
}

def makeContextualFunction(formals: List[Type], body: Tree)(implicit ctx: Context): Tree = {
val params = makeImplicitParameters(formals.map(TypeTree), Contextual)
new FunctionWithMods(params, body, Modifiers(Implicit | Contextual))
val params = makeImplicitParameters(formals.map(TypeTree), Given)
new FunctionWithMods(params, body, Modifiers(Implicit | Given))
}

/** Add annotation to tree:
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]

/** Is `tree` an implicit function or closure, possibly nested in a block? */
def isContextualClosure(tree: Tree)(implicit ctx: Context): Boolean = unsplice(tree) match {
case tree: FunctionWithMods => tree.mods.is(Contextual)
case Function((param: untpd.ValDef) :: _, _) => param.mods.is(Contextual)
case tree: FunctionWithMods => tree.mods.is(Given)
case Function((param: untpd.ValDef) :: _, _) => param.mods.is(Given)
case Closure(_, meth, _) => true
case Block(Nil, expr) => isContextualClosure(expr)
case Block(DefDef(nme.ANON_FUN, _, params :: _, _, _) :: Nil, cl: Closure) =>
params match {
case param :: _ => param.mods.is(Contextual)
case param :: _ => param.mods.is(Given)
case Nil => cl.tpt.eq(untpd.ContextualEmptyTree) || defn.isImplicitFunctionType(cl.tpt.typeOpt)
}
case _ => false
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {

def valueParam(name: TermName, origInfo: Type): TermSymbol = {
val maybeImplicit =
if (tp.isContextual) Implicit | Contextual
if (tp.isContextual) Implicit | Given
else if (tp.isImplicitMethod) Implicit
else EmptyFlags
val maybeErased = if (tp.isErasedMethod) Erased else EmptyFlags
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {

case class Implicit()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.ImplicitCommon)

case class Given()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.ImplicitCommon | Flags.Given)

case class Erased()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Erased)

case class Final()(implicit @constructorOnly src: SourceFile) extends Mod(Flags.Final)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Definitions {
* ImplicitFunctionN traits follow this template:
*
* trait ImplicitFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply with ($x0: T0, ..., $x{N_1}: T{N-1}): R
* def apply given ($x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
* ErasedFunctionN traits follow this template:
Expand All @@ -112,7 +112,7 @@ class Definitions {
* ErasedImplicitFunctionN traits follow this template:
*
* trait ErasedImplicitFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply with (erased $x0: T0, ..., $x{N_1}: T{N-1}): R
* def apply given (erased $x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
* ErasedFunctionN and ErasedImplicitFunctionN erase to Function0.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ object Flags {
/** An extension method */
final val Extension = termFlag(28, "<extension>")

/** A contextual (with) parameter */
final val Contextual = commonFlag(29, "<contextual>")
/** An inferable (`given`) parameter */
final val Given = commonFlag(29, "given")

/** Symbol is defined by a Java class */
final val JavaDefined: FlagSet = commonFlag(30, "<java>")
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ object StdNames {
val notifyAll_ : N = "notifyAll"
val notify_ : N = "notify"
val null_ : N = "null"
val of: N = "of"
val ofDim: N = "ofDim"
val opaque: N = "opaque"
val ordinal: N = "ordinal"
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3879,11 +3879,11 @@ object Types {
def selfType(implicit ctx: Context): Type = {
if (selfTypeCache == null)
selfTypeCache = {
val given = cls.givenSelfType
if (!given.isValueType) appliedRef
else if (cls is Module) given
val givenSelf = cls.givenSelfType
if (!givenSelf.isValueType) appliedRef
else if (cls is Module) givenSelf
else if (ctx.erasedTypes) appliedRef
else AndType(given, appliedRef)
else AndType(givenSelf, appliedRef)
}
selfTypeCache
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Standard-Section: "ASTs" TopLevelStat*
DEFAULTparameterized // Method with default parameters
STABLE // Method that is assumed to be stable
EXTENSION // An extension method
CONTEXTUAL // new style implicit parameters, introduced with `with`
GIVEN // new style implicit parameters, introduced with `given`
PARAMsetter // A setter without a body named `x_=` where `x` is pickled as a PARAM
Annotation

Expand Down Expand Up @@ -323,7 +323,7 @@ object TastyFormat {
final val ERASED = 34
final val OPAQUE = 35
final val EXTENSION = 36
final val CONTEXTUAL = 37
final val GIVEN = 37
final val PARAMsetter = 38

// Cat. 2: tag Nat
Expand Down Expand Up @@ -497,7 +497,7 @@ object TastyFormat {
| DEFAULTparameterized
| STABLE
| EXTENSION
| CONTEXTUAL
| GIVEN
| PARAMsetter
| ANNOTATION
| PRIVATEqualified
Expand Down Expand Up @@ -558,7 +558,7 @@ object TastyFormat {
case DEFAULTparameterized => "DEFAULTparameterized"
case STABLE => "STABLE"
case EXTENSION => "EXTENSION"
case CONTEXTUAL => "CONTEXTUAL"
case GIVEN => "GIVEN"
case PARAMsetter => "PARAMsetter"

case SHAREDterm => "SHAREDterm"
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class TreePickler(pickler: TastyPickler) {
if (flags is DefaultParameterized) writeByte(DEFAULTparameterized)
if (flags is StableRealizable) writeByte(STABLE)
if (flags is Extension) writeByte(EXTENSION)
if (flags is Contextual) writeByte(CONTEXTUAL)
if (flags is Given) writeByte(GIVEN)
if (flags is ParamAccessor) writeByte(PARAMsetter)
assert(!(flags is Label))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ class TreeUnpickler(reader: TastyReader,
case DEFAULTparameterized => addFlag(DefaultParameterized)
case STABLE => addFlag(StableRealizable)
case EXTENSION => addFlag(Extension)
case CONTEXTUAL => addFlag(Contextual)
case GIVEN => addFlag(Given)
case PARAMsetter =>
addFlag(ParamAccessor)
case PRIVATEqualified =>
Expand Down
Loading