Skip to content

Commit

Permalink
Merge branch 'main' into export-diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishiking committed Sep 21, 2023
2 parents a6dfec2 + b1fc943 commit 3daeaa6
Show file tree
Hide file tree
Showing 1,095 changed files with 10,588 additions and 3,354 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ jobs:
run: |
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues; tasty-core-bootstrapped/mimaReportBinaryIssues; stdlib-bootstrapped/mimaReportBinaryIssues"
- name: TASTy MiMa
run: |
# This script cleans the compiler and recompiles it from scratch (keep as last run)
./project/scripts/stdlib-bootstrapped-tasty-mima.sh
community_build_a:
runs-on: [self-hosted, Linux]
container:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ docs/_spec/.jekyll-metadata
# scaladoc related
scaladoc/output/

#coverage
coverage/

7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
[submodule "community-build/community-projects/scala-xml"]
path = community-build/community-projects/scala-xml
url = https://github.com/dotty-staging/scala-xml
[submodule "community-build/community-projects/shapeless"]
path = community-build/community-projects/shapeless
url = https://github.com/dotty-staging/shapeless
branch = shapeless-3-staging
[submodule "community-build/community-projects/xml-interpolator"]
path = community-build/community-projects/xml-interpolator
url = https://github.com/dotty-staging/xml-interpolator.git
Expand Down Expand Up @@ -222,3 +218,6 @@
[submodule "community-build/community-projects/parboiled2"]
path = community-build/community-projects/parboiled2
url = https://github.com/dotty-staging/parboiled2.git
[submodule "community-build/community-projects/shapeless-3"]
path = community-build/community-projects/shapeless-3
url = https://github.com/dotty-staging/shapeless-3.git
2 changes: 1 addition & 1 deletion community-build/community-projects/perspective
Submodule perspective updated 84 files
+47 −27 .scalafmt.conf
+27 −34 build.sbt
+26 −0 dotty/derivation/src/main/scala/perspective/derivation/ArrayProduct.scala
+252 −0 dotty/derivation/src/main/scala/perspective/derivation/Helpers.scala
+78 −0 dotty/derivation/src/main/scala/perspective/derivation/arrayProductK.scala
+363 −127 dotty/derivation/src/main/scala/perspective/derivation/hkdGeneric.scala
+1,102 −0 dotty/derivation/src/main/scala/perspective/derivation/inlineHkdGeneric.scala
+76 −38 dotty/derivation/src/main/scala/perspective/derivation/productK.scala
+172 −0 dotty/derivation/src/test/scala/perspective/derivation/CodecTests.scala
+161 −0 dotty/derivation/src/test/scala/perspective/derivation/HKDProductGenericTests.scala
+175 −0 dotty/derivation/src/test/scala/perspective/derivation/HKDSumGenericTests.scala
+45 −0 dotty/derivation/src/test/scala/perspective/derivation/HelpersTests.scala
+161 −0 dotty/derivation/src/test/scala/perspective/derivation/InlineCodecTests.scala
+327 −0 dotty/derivation/src/test/scala/perspective/derivation/InlineHKDProductGenericTests.scala
+358 −0 dotty/derivation/src/test/scala/perspective/derivation/InlineHKDSumGenericTests.scala
+58 −0 dotty/derivation/src/test/scala/perspective/derivation/InlineUnrollingCodecTests.scala
+78 −0 dotty/derivation/src/test/scala/perspective/derivation/ProductKTests.scala
+217 −65 dotty/examples/src/main/scala/perspective/examples/testing.scala
+11 −3 dotty/perspective/src/main/scala/perspective/ApplicativeK.scala
+17 −7 dotty/perspective/src/main/scala/perspective/ApplyK.scala
+11 −4 dotty/perspective/src/main/scala/perspective/Compose.scala
+7 −1 dotty/perspective/src/main/scala/perspective/Const.scala
+18 −10 dotty/perspective/src/main/scala/perspective/DistributiveK.scala
+26 −13 dotty/perspective/src/main/scala/perspective/Finite.scala
+12 −7 dotty/perspective/src/main/scala/perspective/FoldableK.scala
+54 −6 dotty/perspective/src/main/scala/perspective/FunctionK.scala
+19 −8 dotty/perspective/src/main/scala/perspective/FunctorK.scala
+2 −3 dotty/perspective/src/main/scala/perspective/Id.scala
+3 −3 dotty/perspective/src/main/scala/perspective/MonadK.scala
+27 −13 dotty/perspective/src/main/scala/perspective/RepresentableK.scala
+22 −8 dotty/perspective/src/main/scala/perspective/TraverseK.scala
+22 −7 dotty/perspective/src/main/scala/perspective/TupleK.scala
+8 −3 dotty/perspective/src/main/scala/perspective/ValueK.scala
+1 −1 project/build.properties
+2 −3 scala2/derivation/src/main/scala/perspective/derivation/ArrayProductK.scala
+77 −77 scala2/derivation/src/main/scala/perspective/derivation/ArrayProductKNewtypes.scala
+21 −8 scala2/derivation/src/main/scala/perspective/derivation/HKDProductGeneric.scala
+152 −23 scala2/derivation/src/main/scala/perspective/derivation/HKDProductGenericMacros.scala
+22 −13 scala2/derivation/src/main/scala/perspective/derivation/HKDSumGeneric.scala
+135 −8 scala2/derivation/src/main/scala/perspective/derivation/HKDSumGenericMacros.scala
+66 −52 scala2/derivation/src/main/scala/perspective/derivation/productK.scala
+1 −1 scala2/derivation/src/test/scala/perspective/derivation/DecoderDerive.scala
+37 −0 scala2/derivation/src/test/scala/perspective/derivation/DecoderDeriveFast.scala
+2 −2 scala2/derivation/src/test/scala/perspective/derivation/EncoderDerive.scala
+42 −0 scala2/derivation/src/test/scala/perspective/derivation/EncoderDeriveFast.scala
+6 −7 scala2/derivation/src/test/scala/perspective/derivation/GenericSpec.scala
+36 −0 scala2/derivation/src/test/scala/perspective/derivation/JsonFastSpec.scala
+4 −3 scala2/derivation/src/test/scala/perspective/derivation/JsonSpec.scala
+1 −1 scala2/examples/src/main/scala/perspective/examples/CodecDeriver.scala
+2 −2 scala2/examples/src/main/scala/perspective/examples/DecoderDerive.scala
+2 −2 scala2/examples/src/main/scala/perspective/examples/EncoderDerive.scala
+15 −11 scala2/examples/src/main/scala/perspective/examples/TestBig.scala
+9 −9 scala2/examples/src/main/scala/perspective/examples/testing.scala
+6 −4 scala2/macros/src/main/scala/perspective/macros/Derive.scala
+92 −98 scala2/macros/src/main/scala/perspective/macros/DeriveMacros.scala
+3 −4 scala2/macros/src/main/scala/perspective/macros/PerspectiveAnnotationMacros.scala
+2 −1 scala2/macros/src/main/scala/perspective/macros/hkd.scala
+0 −44 scala2/parameterized/src/main/scala/perspective/parameterized/Const.scala
+0 −29 scala2/parameterized/src/main/scala/perspective/parameterized/FunctionK.scala
+0 −17 scala2/parameterized/src/main/scala/perspective/parameterized/PApplicativeK.scala
+0 −14 scala2/parameterized/src/main/scala/perspective/parameterized/PApplyK.scala
+0 −22 scala2/parameterized/src/main/scala/perspective/parameterized/PFunctorK.scala
+0 −12 scala2/parameterized/src/main/scala/perspective/parameterized/PMonadK.scala
+0 −85 scala2/parameterized/src/main/scala/perspective/parameterized/package.scala
+1 −3 scala2/perspective/src/main/scala/perspective/ApplicativeK.scala
+1 −3 scala2/perspective/src/main/scala/perspective/ApplyK.scala
+1 −2 scala2/perspective/src/main/scala/perspective/DistributiveK.scala
+5 −2 scala2/perspective/src/main/scala/perspective/Finite.scala
+1 −3 scala2/perspective/src/main/scala/perspective/FoldableK.scala
+1 −3 scala2/perspective/src/main/scala/perspective/FunctorK.scala
+2 −4 scala2/perspective/src/main/scala/perspective/MonadK.scala
+2 −3 scala2/perspective/src/main/scala/perspective/RepresentableK.scala
+2 −3 scala2/perspective/src/main/scala/perspective/TraverseK.scala
+167 −71 scala2/perspective/src/main/scala/perspective/TupleInstances.scala
+3 −1 scala2/perspective/src/main/scala/perspective/package.scala
+1 −1 scala2/perspective/src/main/scala/perspective/syntax/ApplicativeKSyntax.scala
+11 −1 scala2/perspective/src/main/scala/perspective/syntax/ApplyKSyntax.scala
+3 −3 scala2/perspective/src/main/scala/perspective/syntax/DistributiveKSyntax.scala
+23 −3 scala2/perspective/src/main/scala/perspective/syntax/FoldableKSyntax.scala
+13 −1 scala2/perspective/src/main/scala/perspective/syntax/FunctorKSyntax.scala
+22 −3 scala2/perspective/src/main/scala/perspective/syntax/MonadKSyntax.scala
+15 −3 scala2/perspective/src/main/scala/perspective/syntax/RepresentableKSyntax.scala
+33 −3 scala2/perspective/src/main/scala/perspective/syntax/TraverseKSyntax.scala
+5 −3 scripts/makeArrayProductKNewtypes.sc
1 change: 0 additions & 1 deletion community-build/community-projects/shapeless
Submodule shapeless deleted from 04e8ce
1 change: 1 addition & 0 deletions community-build/community-projects/shapeless-3
Submodule shapeless-3 added at d27c5b
14 changes: 6 additions & 8 deletions community-build/src/scala/dotty/communitybuild/projects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ final case class SbtCommunityProject(
case Some(ivyHome) => List(s"-Dsbt.ivy.home=$ivyHome")
case _ => Nil
extraSbtArgs ++ sbtProps ++ List(
"-sbt-version", "1.9.0",
"-sbt-version", "1.9.3",
"-Dsbt.supershell=false",
s"-Ddotty.communitybuild.dir=$communitybuildDir",
s"--addPluginSbtFile=$sbtPluginFilePath"
Expand Down Expand Up @@ -366,12 +366,10 @@ object projects:
// sbtDocCommand = "library/doc" // Does no compile? No idea :/
)


lazy val shapeless = SbtCommunityProject(
project = "shapeless",
sbtTestCommand = """set deriving/scalacOptions -= "-Xfatal-warnings"; set typeable/scalacOptions -= "-Xfatal-warnings"; test""",
// selectively disable -Xfatal-warnings due to deprecations
sbtDocCommand = forceDoc("typeable", "deriving", "data"),
lazy val shapeless3 = SbtCommunityProject(
project = "shapeless-3",
sbtTestCommand = "testJVM; testJS",
sbtDocCommand = forceDoc("typeable", "deriving"),
scalacOptions = SbtCommunityProject.scalacOptions.filter(_ != "-Ysafe-init"), // due to -Xfatal-warnings
)

Expand Down Expand Up @@ -796,7 +794,7 @@ def allProjects = List(
projects.minitest,
projects.fastparse,
projects.stdLib213,
projects.shapeless,
projects.shapeless3,
projects.xmlInterpolator,
projects.effpi,
projects.sconfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CommunityBuildTestC:
@Test def scalaz = projects.scalaz.run()
@Test def scas = projects.scas.run()
@Test def sconfig = projects.sconfig.run()
@Test def shapeless = projects.shapeless.run()
@Test def shapeless3 = projects.shapeless3.run()
@Test def sourcecode = projects.sourcecode.run()
@Test def specs2 = projects.specs2.run()

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/MainGenericRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object MainGenericRunner {
case (o @ javaOption(striped)) :: tail =>
processArgs(tail, settings.withJavaArgs(striped).withScalaArgs(o))
case (o @ scalaOption(_*)) :: tail =>
val remainingArgs = (CommandLineParser.expandArg(o) ++ tail).toList
val remainingArgs = CommandLineParser.expandArg(o) ++ tail
processArgs(remainingArgs, settings)
case (o @ colorOption(_*)) :: tail =>
processArgs(tail, settings.withScalaArgs(o))
Expand Down
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,14 @@ trait BCodeSkelBuilder extends BCodeHelpers {
for (p <- params) { locals.makeLocal(p.symbol) }
// debug assert((params.map(p => locals(p.symbol).tk)) == asmMethodType(methSymbol).getArgumentTypes.toList, "debug")

if (params.size > MaximumJvmParameters) {
val paramsSize = params.map { param =>
val tpeTym = param.symbol.info.typeSymbol
if tpeTym == defn.LongClass || tpeTym == defn.DoubleClass then 2 else 1
}.sum
if (paramsSize > MaximumJvmParameters) {
// SI-7324
report.error(em"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters.", ctx.source.atSpan(methSymbol.span))
val info = if paramsSize == params.length then "" else " (Long and Double count as 2)" // https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.3.3
report.error(em"Platform restriction: a parameter list's length cannot exceed $MaximumJvmParameters$info.", ctx.source.atSpan(methSymbol.span))
return
}

Expand Down
9 changes: 9 additions & 0 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,20 @@ class CompilationUnit protected (val source: SourceFile) {
/** List of all comments present in this compilation unit */
var comments: List[Comment] = Nil

/** This is used to record dependencies to invalidate during incremental
* compilation, but only if `ctx.runZincPhases` is true.
*/
val depRecorder: sbt.DependencyRecorder = sbt.DependencyRecorder()

/** Suspends the compilation unit by thowing a SuspendException
* and recording the suspended compilation unit
*/
def suspend()(using Context): Nothing =
assert(isSuspendable)
// Clear references to symbols that may become stale. No need to call
// `depRecorder.sendToZinc()` since all compilation phases will be rerun
// when this unit is unsuspended.
depRecorder.clear()
if !suspended then
if (ctx.settings.XprintSuspension.value)
report.echo(i"suspended: $this")
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,16 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint

for (phase <- ctx.base.allPhases)
if (phase.isRunnable)
Stats.trackTime(s"$phase ms ") {
Stats.trackTime(s"phase time ms/$phase") {
val start = System.currentTimeMillis
val profileBefore = profiler.beforePhase(phase)
units = phase.runOn(units)
profiler.afterPhase(phase, profileBefore)
if (ctx.settings.Xprint.value.containsPhase(phase))
for (unit <- units)
lastPrintedTree =
printTree(lastPrintedTree)(using ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
def printCtx(unit: CompilationUnit) = phase.printingContext(
ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
lastPrintedTree = printTree(lastPrintedTree)(using printCtx(unit))
report.informTime(s"$phase ", start)
Stats.record(s"total trees at end of $phase", ast.Trees.ntrees)
for (unit <- units)
Expand Down
13 changes: 8 additions & 5 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ object desugar {

def makeImplicitParameters(
tpts: List[Tree], implicitFlag: FlagSet,
mkParamName: () => TermName,
mkParamName: Int => TermName,
forPrimaryConstructor: Boolean = false
)(using Context): List[ValDef] =
for (tpt, i) <- tpts.zipWithIndex yield {
val paramFlags: FlagSet = if (forPrimaryConstructor) LocalParamAccessor else Param
val epname = mkParamName()
val epname = mkParamName(i)
ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | implicitFlag)
}

Expand Down Expand Up @@ -254,7 +254,7 @@ object desugar {
// using clauses, we only need names that are unique among the
// parameters of the method since shadowing does not affect
// implicit resolution in Scala 3.
mkParamName = () =>
mkParamName = i =>
val index = seenContextBounds + 1 // Start at 1 like FreshNameCreator.
val ret = ContextBoundParamName(EmptyTermName, index)
seenContextBounds += 1
Expand Down Expand Up @@ -1602,9 +1602,12 @@ object desugar {
case vd: ValDef => vd
}

def makeContextualFunction(formals: List[Tree], body: Tree, erasedParams: List[Boolean])(using Context): Function = {
def makeContextualFunction(formals: List[Tree], paramNamesOrNil: List[TermName], body: Tree, erasedParams: List[Boolean])(using Context): Function = {
val mods = Given
val params = makeImplicitParameters(formals, mods, mkParamName = () => ContextFunctionParamName.fresh())
val params = makeImplicitParameters(formals, mods,
mkParamName = i =>
if paramNamesOrNil.isEmpty then ContextFunctionParamName.fresh()
else paramNamesOrNil(i))
FunctionWithMods(params, body, Modifiers(mods), erasedParams)
}

Expand Down
38 changes: 37 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,17 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
case _ =>
tree.tpe.isInstanceOf[ThisType]
}

/** Under capture checking, an extractor for qualified roots `cap[Q]`.
*/
object QualifiedRoot:

def unapply(tree: Apply)(using Context): Option[String] = tree match
case Apply(fn, Literal(lit) :: Nil) if fn.symbol == defn.Caps_capIn =>
Some(lit.value.asInstanceOf[String])
case _ =>
None
end QualifiedRoot
}

trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped] =>
Expand Down Expand Up @@ -799,12 +810,37 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
}
}

/** An extractor for def of a closure contained the block of the closure,
* possibly with type ascriptions.
*/
object possiblyTypedClosureDef:
def unapply(tree: Tree)(using Context): Option[DefDef] = tree match
case Typed(expr, _) => unapply(expr)
case _ => closureDef.unapply(tree)

/** If tree is a closure, its body, otherwise tree itself */
def closureBody(tree: Tree)(using Context): Tree = tree match {
case closureDef(meth) => meth.rhs
case _ => tree
}

/** Is `mdef` an eta-expansion of a method reference? To recognize this, we use
* the following criterion: A method definition is an eta expansion, if
* it contains at least one term paramter, the parameter has a zero extent span,
* and the right hand side is either an application or a closure with'
* an anonymous method that's itself characterized as an eta expansion.
*/
def isEtaExpansion(mdef: DefDef)(using Context): Boolean =
!rhsOfEtaExpansion(mdef).isEmpty

def rhsOfEtaExpansion(mdef: DefDef)(using Context): Tree = mdef.paramss match
case (param :: _) :: _ if param.asInstanceOf[Tree].span.isZeroExtent =>
mdef.rhs match
case rhs: Apply => rhs
case closureDef(mdef1) => rhsOfEtaExpansion(mdef1)
case _ => EmptyTree
case _ => EmptyTree

/** The variables defined by a pattern, in reverse order of their appearance. */
def patVars(tree: Tree)(using Context): List[Symbol] = {
val acc = new TreeAccumulator[List[Symbol]] { outer =>
Expand Down Expand Up @@ -954,7 +990,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
def isStructuralTermSelectOrApply(tree: Tree)(using Context): Boolean = {
def isStructuralTermSelect(tree: Select) =
def hasRefinement(qualtpe: Type): Boolean = qualtpe.dealias match
case defn.PolyOrErasedFunctionOf(_) =>
case defn.PolyFunctionOf(_) =>
false
case RefinedType(parent, rname, rinfo) =>
rname == tree.name || hasRefinement(parent)
Expand Down
18 changes: 14 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1344,10 +1344,17 @@ object Trees {
case tree: SeqLiteral if (elems eq tree.elems) && (elemtpt eq tree.elemtpt) => tree
case _ => finalize(tree, untpd.SeqLiteral(elems, elemtpt)(sourceFile(tree)))
}
def Inlined(tree: Tree)(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined = tree match {
case tree: Inlined if (call eq tree.call) && (bindings eq tree.bindings) && (expansion eq tree.expansion) => tree
case _ => finalize(tree, untpd.Inlined(call, bindings, expansion)(sourceFile(tree)))
}
// Positions of trees are automatically pushed down except when we reach an Inlined tree. Therefore, we
// make sure the new expansion has a position by copying the one of the original Inlined tree.
def Inlined(tree: Inlined)(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined =
if (call eq tree.call) && (bindings eq tree.bindings) && (expansion eq tree.expansion) then tree
else
// Copy the span from the original Inlined tree if the new expansion doesn't have a span.
val expansionWithSpan =
if expansion.span.exists then expansion
else expansion.withSpan(tree.expansion.span)
finalize(tree, untpd.Inlined(call, bindings, expansionWithSpan)(sourceFile(tree)))

def Quote(tree: Tree)(body: Tree, tags: List[Tree])(using Context): Quote = tree match {
case tree: Quote if (body eq tree.body) && (tags eq tree.tags) => tree
case _ => finalize(tree, untpd.Quote(body, tags)(sourceFile(tree)))
Expand Down Expand Up @@ -1589,6 +1596,9 @@ object Trees {
case tree @ TypeDef(name, rhs) =>
cpy.TypeDef(tree)(name, transform(rhs))
case tree @ Template(constr, parents, self, _) if tree.derived.isEmpty =>
// Currently we do not have cases where we expect `tree.derived` to contain trees for typed trees.
// If it is the case we will fall in `transformMoreCases` and throw an exception there.
// In the future we might keep the `derived` clause after typing, in that case we might want to start handling it here.
cpy.Template(tree)(transformSub(constr), transform(tree.parents), Nil, transformSub(self), transformStats(tree.body, tree.symbol))
case Import(expr, selectors) =>
cpy.Import(tree)(transform(expr), selectors)
Expand Down
27 changes: 15 additions & 12 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -349,24 +349,27 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {

/** An anonymous class
*
* new parents { forwarders }
* new parents { termForwarders; typeAliases }
*
* where `forwarders` contains forwarders for all functions in `fns`.
* @param parents a non-empty list of class types
* @param fns a non-empty of functions for which forwarders should be defined in the class.
* The class has the same owner as the first function in `fns`.
* Its position is the union of all functions in `fns`.
* @param parents a non-empty list of class types
* @param termForwarders a non-empty list of forwarding definitions specified by their name and the definition they forward to.
* @param typeMembers a possibly-empty list of type members specified by their name and their right hand side.
*
* The class has the same owner as the first function in `termForwarders`.
* Its position is the union of all symbols in `termForwarders`.
*/
def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(using Context): Block = {
AnonClass(fns.head.owner, parents, fns.map(_.span).reduceLeft(_ union _)) { cls =>
def forwarder(fn: TermSymbol, name: TermName) = {
def AnonClass(parents: List[Type], termForwarders: List[(TermName, TermSymbol)],
typeMembers: List[(TypeName, TypeBounds)] = Nil)(using Context): Block = {
AnonClass(termForwarders.head._2.owner, parents, termForwarders.map(_._2.span).reduceLeft(_ union _)) { cls =>
def forwarder(name: TermName, fn: TermSymbol) = {
val fwdMeth = fn.copy(cls, name, Synthetic | Method | Final).entered.asTerm
for overridden <- fwdMeth.allOverriddenSymbols do
if overridden.is(Extension) then fwdMeth.setFlag(Extension)
if !overridden.is(Deferred) then fwdMeth.setFlag(Override)
DefDef(fwdMeth, ref(fn).appliedToArgss(_))
}
fns.lazyZip(methNames).map(forwarder)
termForwarders.map((name, sym) => forwarder(name, sym)) ++
typeMembers.map((name, info) => TypeDef(newSymbol(cls, name, Synthetic, info).entered))
}
}

Expand Down Expand Up @@ -748,7 +751,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}
}

override def Inlined(tree: Tree)(call: Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined = {
override def Inlined(tree: Inlined)(call: Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined = {
val tree1 = untpdCpy.Inlined(tree)(call, bindings, expansion)
tree match {
case tree: Inlined if sameTypes(bindings, tree.bindings) && (expansion.tpe eq tree.expansion.tpe) =>
Expand Down Expand Up @@ -1149,7 +1152,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {

def etaExpandCFT(using Context): Tree =
def expand(target: Tree, tp: Type)(using Context): Tree = tp match
case defn.ContextFunctionType(argTypes, resType, _) =>
case defn.ContextFunctionType(argTypes, resType) =>
val anonFun = newAnonFun(
ctx.owner,
MethodType.companion(isContextual = true)(argTypes, resType),
Expand Down
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
case Floating
}

/** {x1, ..., xN} T (only relevant under captureChecking) */
/** {x1, ..., xN} T (only relevant under captureChecking)
* Created when parsing function types so that capture set and result type
* is combined in a single node.
*/
case class CapturesAndResult(refs: List[Tree], parent: Tree)(implicit @constructorOnly src: SourceFile) extends TypTree

/** A type tree appearing somewhere in the untyped DefDef of a lambda, it will be typed using `tpFun`.
Expand Down Expand Up @@ -512,6 +515,9 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def captureRoot(using Context): Select =
Select(scalaDot(nme.caps), nme.CAPTURE_ROOT)

def captureRootIn(using Context): Select =
Select(scalaDot(nme.caps), nme.capIn)

def makeRetaining(parent: Tree, refs: List[Tree], annotName: TypeName)(using Context): Annotated =
Annotated(parent, New(scalaAnnotationDot(annotName), List(refs)))

Expand Down
Loading

0 comments on commit 3daeaa6

Please sign in to comment.