Skip to content

Drop old syntax styles for givens #7245

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 20 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from 13 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/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context
val same = classSymbol.effectiveName.toString == dupClassSym.effectiveName.toString
ctx.atPhase(ctx.typerPhase) {
if (same)
the[Context].warning( // FIXME: This should really be an error, but then FromTasty tests fail
summon[Context].warning( // FIXME: This should really be an error, but then FromTasty tests fail
s"${cl1.show} and ${cl2.showLocated} produce classes that overwrite one another", cl1.sourcePos)
else
the[Context].warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
summon[Context].warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " +
"Such classes will overwrite one another on case-insensitive filesystems.", cl1.sourcePos)
}
}
Expand Down
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 @@ -893,7 +893,7 @@ object desugar {
* If the given member `mdef` is not of this form, flag it as an error.
*/

def makeExtensionDef(mdef: Tree, tparams: List[TypeDef], leadingParams: List[ValDef]) given (ctx: Context): Tree = {
def makeExtensionDef(mdef: Tree, tparams: List[TypeDef], leadingParams: List[ValDef])(given ctx: Context): Tree = {
val allowed = "allowed here, since collective parameters are given"
mdef match {
case mdef: DefDef =>
Expand Down Expand Up @@ -933,7 +933,7 @@ object desugar {

/** Invent a name for an anonympus given of type or template `impl`. */
def inventGivenName(impl: Tree)(implicit ctx: Context): SimpleName =
avoidIllegalChars(s"${inventName(impl)}_given".toTermName.asSimpleName)
avoidIllegalChars(s"given_${inventName(impl)}".toTermName.asSimpleName)

/** The normalized name of `mdef`. This means
* 1. Check that the name does not redefine a Scala core class.
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/MainProxies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import ast.Trees._
*/
object MainProxies {

def mainProxies(stats: List[tpd.Tree]) given Context: List[untpd.Tree] = {
def mainProxies(stats: List[tpd.Tree])(given Context): List[untpd.Tree] = {
import tpd._
def mainMethods(stats: List[Tree]): List[Symbol] = stats.flatMap {
case stat: DefDef if stat.symbol.hasAnnotation(defn.MainAnnot) =>
Expand All @@ -40,7 +40,7 @@ object MainProxies {
}

import untpd._
def mainProxy(mainFun: Symbol) given (ctx: Context): List[TypeDef] = {
def mainProxy(mainFun: Symbol)(given ctx: Context): List[TypeDef] = {
val mainAnnotSpan = mainFun.getAnnotation(defn.MainAnnot).get.tree.span
def pos = mainFun.sourcePos
val argsRef = Ident(nme.args)
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import util.Spans.Span

object Annotations {

def annotClass(tree: Tree) given Context =
def annotClass(tree: Tree)(given Context) =
if (tree.symbol.isConstructor) tree.symbol.owner
else tree.tpe.typeSymbol

Expand Down Expand Up @@ -121,7 +121,7 @@ object Annotations {
def deferred(sym: Symbol)(treeFn: ImplicitFunction1[Context, Tree])(implicit ctx: Context): Annotation =
new LazyAnnotation {
override def symbol(implicit ctx: Context): Symbol = sym
def complete(implicit ctx: Context) = treeFn given ctx
def complete(implicit ctx: Context) = treeFn(given ctx)
}

/** Create an annotation where the symbol and the tree are computed lazily. */
Expand All @@ -131,12 +131,12 @@ object Annotations {

override def symbol(implicit ctx: Context): Symbol = {
if (mySym == null || mySym.defRunId != ctx.runId) {
mySym = symf given ctx
mySym = symf(given ctx)
assert(mySym != null)
}
mySym
}
def complete(implicit ctx: Context) = treeFn given ctx
def complete(implicit ctx: Context) = treeFn(given ctx)
}

def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ object Decorators {
def (x: T) reporting[T](
op: ImplicitFunction1[WrappedResult[T], String],
printer: config.Printers.Printer = config.Printers.default): T = {
printer.println(op given WrappedResult(x))
printer.println(op(given WrappedResult(x)))
x
}
}
Expand Down
34 changes: 17 additions & 17 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ class Definitions {
* ErasedFunctionN traits follow this template:
*
* trait ErasedFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply erased ($x0: T0, ..., $x{N_1}: T{N-1}): R
* def apply(erased $x0: T0, ..., $x{N_1}: T{N-1}): R
* }
*
* ErasedImplicitFunctionN traits follow this template:
*
* trait ErasedImplicitFunctionN[T0,...,T{N-1}, R] extends Object {
* def apply given 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 Expand Up @@ -403,7 +403,7 @@ class Definitions {

@tu lazy val CollectionSeqType: TypeRef = ctx.requiredClassRef("scala.collection.Seq")
@tu lazy val SeqType: TypeRef = ctx.requiredClassRef("scala.collection.immutable.Seq")
def SeqClass given Context: ClassSymbol = SeqType.symbol.asClass
def SeqClass(given Context): ClassSymbol = SeqType.symbol.asClass
@tu lazy val Seq_apply : Symbol = SeqClass.requiredMethod(nme.apply)
@tu lazy val Seq_head : Symbol = SeqClass.requiredMethod(nme.head)
@tu lazy val Seq_drop : Symbol = SeqClass.requiredMethod(nme.drop)
Expand All @@ -412,7 +412,7 @@ class Definitions {
@tu lazy val Seq_toSeq : Symbol = SeqClass.requiredMethod(nme.toSeq)

@tu lazy val ArrayType: TypeRef = ctx.requiredClassRef("scala.Array")
def ArrayClass given Context: ClassSymbol = ArrayType.symbol.asClass
def ArrayClass(given Context): ClassSymbol = ArrayType.symbol.asClass
@tu lazy val Array_apply : Symbol = ArrayClass.requiredMethod(nme.apply)
@tu lazy val Array_update : Symbol = ArrayClass.requiredMethod(nme.update)
@tu lazy val Array_length : Symbol = ArrayClass.requiredMethod(nme.length)
Expand All @@ -422,10 +422,10 @@ class Definitions {
@tu lazy val ArrayModule: Symbol = ctx.requiredModule("scala.Array")

@tu lazy val UnitType: TypeRef = valueTypeRef("scala.Unit", java.lang.Void.TYPE, UnitEnc, nme.specializedTypeNames.Void)
def UnitClass given Context: ClassSymbol = UnitType.symbol.asClass
def UnitModuleClass given Context: Symbol = UnitType.symbol.asClass.linkedClass
def UnitClass(given Context): ClassSymbol = UnitType.symbol.asClass
def UnitModuleClass(given Context): Symbol = UnitType.symbol.asClass.linkedClass
@tu lazy val BooleanType: TypeRef = valueTypeRef("scala.Boolean", java.lang.Boolean.TYPE, BooleanEnc, nme.specializedTypeNames.Boolean)
def BooleanClass given Context: ClassSymbol = BooleanType.symbol.asClass
def BooleanClass(given Context): ClassSymbol = BooleanType.symbol.asClass
@tu lazy val Boolean_! : Symbol = BooleanClass.requiredMethod(nme.UNARY_!)
@tu lazy val Boolean_&& : Symbol = BooleanClass.requiredMethod(nme.ZAND) // ### harmonize required... calls
@tu lazy val Boolean_|| : Symbol = BooleanClass.requiredMethod(nme.ZOR)
Expand All @@ -441,13 +441,13 @@ class Definitions {
}).symbol

@tu lazy val ByteType: TypeRef = valueTypeRef("scala.Byte", java.lang.Byte.TYPE, ByteEnc, nme.specializedTypeNames.Byte)
def ByteClass given Context: ClassSymbol = ByteType.symbol.asClass
def ByteClass(given Context): ClassSymbol = ByteType.symbol.asClass
@tu lazy val ShortType: TypeRef = valueTypeRef("scala.Short", java.lang.Short.TYPE, ShortEnc, nme.specializedTypeNames.Short)
def ShortClass given Context: ClassSymbol = ShortType.symbol.asClass
def ShortClass(given Context): ClassSymbol = ShortType.symbol.asClass
@tu lazy val CharType: TypeRef = valueTypeRef("scala.Char", java.lang.Character.TYPE, CharEnc, nme.specializedTypeNames.Char)
def CharClass given Context: ClassSymbol = CharType.symbol.asClass
def CharClass(given Context): ClassSymbol = CharType.symbol.asClass
@tu lazy val IntType: TypeRef = valueTypeRef("scala.Int", java.lang.Integer.TYPE, IntEnc, nme.specializedTypeNames.Int)
def IntClass given Context: ClassSymbol = IntType.symbol.asClass
def IntClass(given Context): ClassSymbol = IntType.symbol.asClass
@tu lazy val Int_- : Symbol = IntClass.requiredMethod(nme.MINUS, List(IntType))
@tu lazy val Int_+ : Symbol = IntClass.requiredMethod(nme.PLUS, List(IntType))
@tu lazy val Int_/ : Symbol = IntClass.requiredMethod(nme.DIV, List(IntType))
Expand All @@ -456,18 +456,18 @@ class Definitions {
@tu lazy val Int_>= : Symbol = IntClass.requiredMethod(nme.GE, List(IntType))
@tu lazy val Int_<= : Symbol = IntClass.requiredMethod(nme.LE, List(IntType))
@tu lazy val LongType: TypeRef = valueTypeRef("scala.Long", java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long)
def LongClass given Context: ClassSymbol = LongType.symbol.asClass
def LongClass(given Context): ClassSymbol = LongType.symbol.asClass
@tu lazy val Long_+ : Symbol = LongClass.requiredMethod(nme.PLUS, List(LongType))
@tu lazy val Long_* : Symbol = LongClass.requiredMethod(nme.MUL, List(LongType))
@tu lazy val Long_/ : Symbol = LongClass.requiredMethod(nme.DIV, List(LongType))

@tu lazy val FloatType: TypeRef = valueTypeRef("scala.Float", java.lang.Float.TYPE, FloatEnc, nme.specializedTypeNames.Float)
def FloatClass given Context: ClassSymbol = FloatType.symbol.asClass
def FloatClass(given Context): ClassSymbol = FloatType.symbol.asClass
@tu lazy val DoubleType: TypeRef = valueTypeRef("scala.Double", java.lang.Double.TYPE, DoubleEnc, nme.specializedTypeNames.Double)
def DoubleClass given Context: ClassSymbol = DoubleType.symbol.asClass
def DoubleClass(given Context): ClassSymbol = DoubleType.symbol.asClass

@tu lazy val BoxedUnitClass: ClassSymbol = ctx.requiredClass("scala.runtime.BoxedUnit")
def BoxedUnit_UNIT given Context: TermSymbol = BoxedUnitClass.linkedClass.requiredValue("UNIT")
def BoxedUnit_UNIT(given Context): TermSymbol = BoxedUnitClass.linkedClass.requiredValue("UNIT")

@tu lazy val BoxedBooleanClass: ClassSymbol = ctx.requiredClass("java.lang.Boolean")
@tu lazy val BoxedByteClass : ClassSymbol = ctx.requiredClass("java.lang.Byte")
Expand Down Expand Up @@ -533,9 +533,9 @@ class Definitions {
// in scalac modified to have Any as parent

@tu lazy val ThrowableType: TypeRef = ctx.requiredClassRef("java.lang.Throwable")
def ThrowableClass given Context: ClassSymbol = ThrowableType.symbol.asClass
def ThrowableClass(given Context): ClassSymbol = ThrowableType.symbol.asClass
@tu lazy val SerializableType: TypeRef = JavaSerializableClass.typeRef
def SerializableClass given Context: ClassSymbol = SerializableType.symbol.asClass
def SerializableClass(given Context): ClassSymbol = SerializableType.symbol.asClass

@tu lazy val JavaEnumClass: ClassSymbol = {
val cls = ctx.requiredClass("java.lang.Enum")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Periods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class Periods { self: Context =>

/** Execute `op` at given phase id */
def atPhase[T](pid: PhaseId)(op: ImplicitFunction1[Context, T]): T =
op given ctx.withPhase(pid)
op(given ctx.withPhase(pid))

/** The period containing the current period where denotations do not change.
* We compute this by taking as first phase the first phase less or equal to
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait Phases {
def atNextPhase[T](op: ImplicitFunction1[Context, T]): T = atPhase(phase.next)(op)

def atPhaseNotLaterThan[T](limit: Phase)(op: ImplicitFunction1[Context, T]): T =
if (!limit.exists || phase <= limit) op given this else atPhase(limit)(op)
if (!limit.exists || phase <= limit) op(given this) else atPhase(limit)(op)

def isAfterTyper: Boolean = base.isAfterTyper(phase)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Signature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ object Signature {
y match {
case y: TypeName =>
// `Ordering[TypeName]` doesn't work due to `Ordering` still being invariant
the[Ordering[Name]].compare(x, y)
summon[Ordering[Name]].compare(x, y)
case y: Int =>
1
}
Expand All @@ -184,7 +184,7 @@ object Signature {
import scala.math.Ordering.Implicits.seqOrdering
val paramsOrdering = seqOrdering(paramSigOrdering).compare(x.paramsSig, y.paramsSig)
if (paramsOrdering != 0) paramsOrdering
else the[Ordering[Name]].compare(x.resSig, y.resSig)
else summon[Ordering[Name]].compare(x.resSig, y.resSig)
}
}
}
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 @@ -388,7 +388,6 @@ object StdNames {
val array_length : N = "array_length"
val array_update : N = "array_update"
val arraycopy: N = "arraycopy"
val as: N = "as"
val asTerm: N = "asTerm"
val asModule: N = "asModule"
val asMethod: N = "asMethod"
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
//}
assert(!ctx.settings.YnoDeepSubtypes.value)
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
ctx.log(TypeComparer.explained(the[Context].typeComparer.isSubType(tp1, tp2, approx)))
ctx.log(TypeComparer.explained(summon[Context].typeComparer.isSubType(tp1, tp2, approx)))
}
// Eliminate LazyRefs before checking whether we have seen a type before
val normalize = new TypeMap {
Expand Down Expand Up @@ -2309,7 +2309,7 @@ object TypeComparer {
/** Show trace of comparison operations when performing `op` */
def explaining[T](say: String => Unit)(op: ImplicitFunction1[Context, T])(implicit ctx: Context): T = {
val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_))
val res = try { op given nestedCtx } finally { say(nestedCtx.typeComparer.lastTrace()) }
val res = try { op(given nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) }
res
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TyperState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TyperState(private val previous: TyperState /* | Null */) {
*/
def test[T](op: ImplicitFunction1[Context, T])(implicit ctx: Context): T =
if (isShared)
op given ctx.fresh.setExploreTyperState()
op(given ctx.fresh.setExploreTyperState())
else {
val savedConstraint = myConstraint
val savedReporter = myReporter
Expand All @@ -113,7 +113,7 @@ class TyperState(private val previous: TyperState /* | Null */) {
testReporter.inUse = true
testReporter
}
try op given ctx
try op(given ctx)
finally {
testReporter.inUse = false
resetConstraintTo(savedConstraint)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Standard-Section: "ASTs" TopLevelStat*
METHODtype Length result_Type NamesTypes -- A method type `(NamesTypes)result`, needed for refinements
ERASEDMETHODtype Length result_Type NamesTypes -- A method type `erased (NamesTypes)result`, needed for refinements
GIVENMETHODtype Length result_Type NamesTypes -- A method type `given (NamesTypes)result`, needed for refinements
ERASEDGIVENMETHODtype Length result_Type NamesTypes -- A method type `given erased (NamesTypes)result`, needed for refinements
ERASEDGIVENMETHODtype Length result_Type NamesTypes -- A method type `given(erased NamesTypes)result`, needed for refinements
IMPLICITMETHODtype Length result_Type NamesTypes -- A method type `(implicit NamesTypes)result`, needed for refinements
// TODO: remove ERASEDIMPLICITMETHODtype
TYPELAMBDAtype Length result_Type NamesTypes -- A type lambda `[NamesTypes] => result`, variance encoded using VARIANT names
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ class TreeUnpickler(reader: TastyReader,
val args = until(end)(readTerm())
val splice = splices(idx)
def wrap(arg: Tree) =
if (arg.isTerm) given (qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, QuoteContext.scopeId)
if (arg.isTerm) (given qctx: scala.quoted.QuoteContext) => new TastyTreeExpr(arg, QuoteContext.scopeId)
else new TreeType(arg, QuoteContext.scopeId)
val reifiedArgs = args.map(wrap)
val filled = if (isType) {
Expand All @@ -1280,7 +1280,7 @@ class TreeUnpickler(reader: TastyReader,
}
else {
val splice1 = splice.asInstanceOf[Seq[Any] => ImplicitFunction1[scala.quoted.QuoteContext, quoted.Expr[?]]]
val quotedExpr = splice1(reifiedArgs) given dotty.tools.dotc.quoted.QuoteContext()
val quotedExpr = splice1(reifiedArgs)(given dotty.tools.dotc.quoted.QuoteContext())
PickledQuotes.quotedExprToTree(quotedExpr)
}
// We need to make sure a hole is created with the source file of the surrounding context, even if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
val atp = readTypeRef()
val phase = ctx.phase
Annotation.deferred(atp.typeSymbol)(
atReadPos(start, () => readAnnotationContents(end)(the[Context].withPhase(phase))))
atReadPos(start, () => readAnnotationContents(end)(summon[Context].withPhase(phase))))
}

/* Read an abstract syntax tree */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ object Interactive {
def localize(symbol: Symbol, sourceDriver: InteractiveDriver, targetDriver: InteractiveDriver): Symbol = {

def in[T](driver: InteractiveDriver)(fn: ImplicitFunction1[Context, T]): T =
fn given driver.currentCtx
fn(given driver.currentCtx)

if (sourceDriver == targetDriver) symbol
else {
Expand Down
Loading