Skip to content

Commit 9754335

Browse files
authored
Merge branch 'main' into i22440
2 parents 3c4148a + 81e057a commit 9754335

File tree

291 files changed

+5702
-1283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

291 files changed

+5702
-1283
lines changed

.github/workflows/lts-backport.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
with:
1616
fetch-depth: 0
1717
- uses: coursier/cache-action@v6
18-
- uses: VirtusLab/scala-cli-setup@v1.5.4
18+
- uses: VirtusLab/scala-cli-setup@v1.6.1
1919
- run: scala-cli ./project/scripts/addToBackportingProject.scala -- ${{ github.sha }}
2020
env:
2121
GRAPHQL_API_TOKEN: ${{ secrets.GRAPHQL_API_TOKEN }}

.github/workflows/publish-sdkman.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- platform: WINDOWS_64
4747
archive : 'scala3-${{ inputs.version }}-x86_64-pc-win32.zip'
4848
steps:
49-
- uses: sdkman/sdkman-release-action@1f2d4209b4f5a38721d4ae20014ea8e1689d869e
49+
- uses: sdkman/sdkman-release-action@a60691d56279724b4c9ff0399c0ae21d641ab75e
5050
with:
5151
CONSUMER-KEY : ${{ secrets.CONSUMER-KEY }}
5252
CONSUMER-TOKEN : ${{ secrets.CONSUMER-TOKEN }}

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
818818

819819
methSymbol = dd.symbol
820820
jMethodName = methSymbol.javaSimpleName
821-
returnType = asmMethodType(dd.symbol).returnType
821+
returnType = asmMethodType(methSymbol).returnType
822822
isMethSymStaticCtor = methSymbol.isStaticConstructor
823823

824824
resetMethodBookkeeping(dd)
@@ -915,7 +915,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
915915
for (p <- params) { emitLocalVarScope(p.symbol, veryFirstProgramPoint, onePastLastProgramPoint, force = true) }
916916
}
917917

918-
if (isMethSymStaticCtor) { appendToStaticCtor(dd) }
918+
if (isMethSymStaticCtor) { appendToStaticCtor() }
919919
} // end of emitNormalMethodBody()
920920

921921
lineNumber(rhs)
@@ -936,7 +936,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
936936
*
937937
* TODO document, explain interplay with `fabricateStaticInitAndroid()`
938938
*/
939-
private def appendToStaticCtor(dd: DefDef): Unit = {
939+
private def appendToStaticCtor(): Unit = {
940940

941941
def insertBefore(
942942
location: asm.tree.AbstractInsnNode,

compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import java.util.zip.{CRC32, Deflater, ZipEntry, ZipOutputStream}
1212

1313
import dotty.tools.dotc.core.Contexts.*
1414
import dotty.tools.dotc.core.Decorators.em
15+
import dotty.tools.dotc.util.chaining.*
1516
import dotty.tools.io.{AbstractFile, PlainFile, VirtualFile}
1617
import dotty.tools.io.PlainFile.toPlainFile
1718
import BTypes.InternalName
18-
import scala.util.chaining.*
1919
import dotty.tools.io.JarArchive
2020

2121
import scala.language.unsafeNulls

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,8 @@ class JSCodeGen()(using genCtx: Context) {
25692569
genCoercion(tree, receiver, code)
25702570
else if (code == JSPrimitives.THROW)
25712571
genThrow(tree, args)
2572+
else if (code == JSPrimitives.NEW_ARRAY)
2573+
genNewArray(tree, args)
25722574
else if (JSPrimitives.isJSPrimitive(code))
25732575
genJSPrimitive(tree, args, code, isStat)
25742576
else
@@ -3038,6 +3040,24 @@ class JSCodeGen()(using genCtx: Context) {
30383040
}
30393041
}
30403042

3043+
/** Gen a call to the special `newArray` method. */
3044+
private def genNewArray(tree: Apply, args: List[Tree]): js.Tree = {
3045+
implicit val pos: SourcePosition = tree.sourcePos
3046+
3047+
val List(elemClazz, Literal(arrayClassConstant), dimsArray: JavaSeqLiteral) = args: @unchecked
3048+
3049+
dimsArray.elems match {
3050+
case singleDim :: Nil =>
3051+
// Use a js.NewArray
3052+
val arrayTypeRef = toTypeRef(arrayClassConstant.typeValue).asInstanceOf[jstpe.ArrayTypeRef]
3053+
js.NewArray(arrayTypeRef, genExpr(singleDim))
3054+
case _ =>
3055+
// Delegate to jlr.Array.newInstance
3056+
js.ApplyStatic(js.ApplyFlags.empty, JLRArrayClassName, js.MethodIdent(JLRArrayNewInstanceMethodName),
3057+
List(genExpr(elemClazz), genJavaSeqLiteral(dimsArray)))(jstpe.AnyType)
3058+
}
3059+
}
3060+
30413061
/** Gen a "normal" apply (to a true method).
30423062
*
30433063
* But even these are further refined into:
@@ -4846,7 +4866,7 @@ class JSCodeGen()(using genCtx: Context) {
48464866

48474867
object JSCodeGen {
48484868

4849-
private val NullPointerExceptionClass = ClassName("java.lang.NullPointerException")
4869+
private val JLRArrayClassName = ClassName("java.lang.reflect.Array")
48504870
private val JSObjectClassName = ClassName("scala.scalajs.js.Object")
48514871
private val JavaScriptExceptionClassName = ClassName("scala.scalajs.js.JavaScriptException")
48524872

@@ -4856,6 +4876,9 @@ object JSCodeGen {
48564876

48574877
private val selectedValueMethodName = MethodName("selectedValue", Nil, ObjectClassRef)
48584878

4879+
private val JLRArrayNewInstanceMethodName =
4880+
MethodName("newInstance", List(jstpe.ClassRef(jsNames.ClassClass), jstpe.ArrayTypeRef(jstpe.IntRef, 1)), ObjectClassRef)
4881+
48594882
private val ObjectArgConstructorName = MethodName.constructor(List(ObjectClassRef))
48604883

48614884
private val thisOriginalName = OriginalName("this")

compiler/src/dotty/tools/backend/sjs/JSPrimitives.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ object JSPrimitives {
4747
inline val UNWRAP_FROM_THROWABLE = WRAP_AS_THROWABLE + 1 // js.special.unwrapFromThrowable
4848
inline val DEBUGGER = UNWRAP_FROM_THROWABLE + 1 // js.special.debugger
4949

50-
inline val THROW = DEBUGGER + 1
50+
inline val THROW = DEBUGGER + 1 // <special-ops>.throw
51+
inline val NEW_ARRAY = THROW + 1 // scala.runtime.Arrays.newArray
5152

52-
inline val UNION_FROM = THROW + 1 // js.|.from
53+
inline val UNION_FROM = NEW_ARRAY + 1 // js.|.from
5354
inline val UNION_FROM_TYPE_CONSTRUCTOR = UNION_FROM + 1 // js.|.fromTypeConstructor
5455

5556
inline val REFLECT_SELECTABLE_SELECTDYN = UNION_FROM_TYPE_CONSTRUCTOR + 1 // scala.reflect.Selectable.selectDynamic
@@ -135,6 +136,7 @@ class JSPrimitives(ictx: Context) extends DottyPrimitives(ictx) {
135136
addPrimitive(jsdefn.Special_debugger, DEBUGGER)
136137

137138
addPrimitive(defn.throwMethod, THROW)
139+
addPrimitive(defn.newArrayMethod, NEW_ARRAY)
138140

139141
addPrimitive(jsdefn.PseudoUnion_from, UNION_FROM)
140142
addPrimitive(jsdefn.PseudoUnion_fromTypeConstructor, UNION_FROM_TYPE_CONSTRUCTOR)

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn
5959

6060
var hasMacroAnnotations: Boolean = false
6161

62+
def hasUnrollDefs: Boolean = unrolledClasses.nonEmpty
63+
var unrolledClasses: Set[Symbol] = Set.empty
64+
6265
/** Set to `true` if inliner added anonymous mirrors that need to be completed */
6366
var needsMirrorSupport: Boolean = false
6467

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import typer.{TyperPhase, RefChecks}
77
import parsing.Parser
88
import Phases.Phase
99
import transform.*
10-
import dotty.tools.backend
1110
import backend.jvm.{CollectSuperCalls, GenBCode}
1211
import localopt.StringInterpolatorOpt
1312

@@ -34,12 +33,12 @@ class Compiler {
3433
protected def frontendPhases: List[List[Phase]] =
3534
List(new Parser) :: // Compiler frontend: scanner, parser
3635
List(new TyperPhase) :: // Compiler frontend: namer, typer
37-
List(new CheckUnused.PostTyper) :: // Check for unused elements
38-
List(new CheckShadowing) :: // Check shadowing elements
36+
List(CheckUnused.PostTyper(), CheckShadowing()) :: // Check for unused, shadowed elements
3937
List(new YCheckPositions) :: // YCheck positions
4038
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
4139
List(new semanticdb.ExtractSemanticDB.ExtractSemanticInfo) :: // Extract info into .semanticdb files
4240
List(new PostTyper) :: // Additional checks and cleanups after type checking
41+
List(new UnrollDefinitions) :: // Unroll annotated methods if detected in PostTyper
4342
List(new sjs.PrepJSInterop) :: // Additional checks and transformations for Scala.js (Scala.js only)
4443
List(new SetRootTree) :: // Set the `rootTreeOrProvider` on class symbols
4544
Nil
@@ -50,10 +49,10 @@ class Compiler {
5049
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
5150
List(new Inlining) :: // Inline and execute macros
5251
List(new PostInlining) :: // Add mirror support for inlined code
53-
List(new CheckUnused.PostInlining) :: // Check for unused elements
5452
List(new Staging) :: // Check staging levels and heal staged types
5553
List(new Splicing) :: // Replace level 1 splices with holes
5654
List(new PickleQuotes) :: // Turn quoted trees into explicit run-time data structures
55+
List(new CheckUnused.PostInlining) :: // Check for unused elements
5756
Nil
5857

5958
/** Phases dealing with the transformation from pickled trees to backend trees */

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ object desugar {
4747
*/
4848
val UntupledParam: Property.Key[Unit] = Property.StickyKey()
4949

50+
/** An attachment key to indicate that a ValDef originated from a pattern.
51+
*/
52+
val PatternVar: Property.Key[Unit] = Property.StickyKey()
53+
54+
/** An attachment key for Trees originating in for-comprehension, such as tupling of assignments.
55+
*/
56+
val ForArtifact: Property.Key[Unit] = Property.StickyKey()
57+
5058
/** An attachment key to indicate that a ValDef is an evidence parameter
5159
* for a context bound.
5260
*/
@@ -1507,7 +1515,7 @@ object desugar {
15071515
val matchExpr =
15081516
if (tupleOptimizable) rhs
15091517
else
1510-
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids))
1518+
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids).withAttachment(ForArtifact, ()))
15111519
Match(makeSelector(rhs, MatchCheck.IrrefutablePatDef), caseDef :: Nil)
15121520
vars match {
15131521
case Nil if !mods.is(Lazy) =>
@@ -1537,6 +1545,7 @@ object desugar {
15371545
ValDef(named.name.asTermName, tpt, selector(n))
15381546
.withMods(mods)
15391547
.withSpan(named.span)
1548+
.withAttachment(PatternVar, ())
15401549
)
15411550
flatTree(firstDef :: restDefs)
15421551
}
@@ -1922,6 +1931,7 @@ object desugar {
19221931
val vdef = ValDef(named.name.asTermName, tpt, rhs)
19231932
.withMods(mods)
19241933
.withSpan(original.span.withPoint(named.span.start))
1934+
.withAttachment(PatternVar, ())
19251935
val mayNeedSetter = valDef(vdef)
19261936
mayNeedSetter
19271937
}
@@ -2167,7 +2177,7 @@ object desugar {
21672177
case _ => Modifiers()
21682178
makePatDef(valeq, mods, defpat, rhs)
21692179
}
2170-
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat0, gen.expr, gen.checkMode) :: Nil, Block(pdefs, makeTuple(id0 :: ids)))
2180+
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat0, gen.expr, gen.checkMode) :: Nil, Block(pdefs, makeTuple(id0 :: ids).withAttachment(ForArtifact, ())))
21712181
val allpats = gen.pat :: pats
21722182
val vfrom1 = GenFrom(makeTuple(allpats), rhs1, GenCheckMode.Ignore)
21732183
makeFor(mapName, flatMapName, vfrom1 :: rest1, body)

compiler/src/dotty/tools/dotc/config/CliCommand.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Settings.*
77
import core.Contexts.*
88
import printing.Highlighting
99

10-
import scala.util.chaining.given
10+
import dotty.tools.dotc.util.chaining.*
1111
import scala.PartialFunction.cond
1212

1313
trait CliCommand:

0 commit comments

Comments
 (0)