Skip to content

Commit

Permalink
Merge branch 'main' into i22440
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzaremmal authored Jan 29, 2025
2 parents 3c4148a + 81e057a commit 9754335
Show file tree
Hide file tree
Showing 291 changed files with 5,702 additions and 1,283 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lts-backport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
fetch-depth: 0
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@v1.5.4
- uses: VirtusLab/scala-cli-setup@v1.6.1
- run: scala-cli ./project/scripts/addToBackportingProject.scala -- ${{ github.sha }}
env:
GRAPHQL_API_TOKEN: ${{ secrets.GRAPHQL_API_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-sdkman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- platform: WINDOWS_64
archive : 'scala3-${{ inputs.version }}-x86_64-pc-win32.zip'
steps:
- uses: sdkman/sdkman-release-action@1f2d4209b4f5a38721d4ae20014ea8e1689d869e
- uses: sdkman/sdkman-release-action@a60691d56279724b4c9ff0399c0ae21d641ab75e
with:
CONSUMER-KEY : ${{ secrets.CONSUMER-KEY }}
CONSUMER-TOKEN : ${{ secrets.CONSUMER-TOKEN }}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {

methSymbol = dd.symbol
jMethodName = methSymbol.javaSimpleName
returnType = asmMethodType(dd.symbol).returnType
returnType = asmMethodType(methSymbol).returnType
isMethSymStaticCtor = methSymbol.isStaticConstructor

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

if (isMethSymStaticCtor) { appendToStaticCtor(dd) }
if (isMethSymStaticCtor) { appendToStaticCtor() }
} // end of emitNormalMethodBody()

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

def insertBefore(
location: asm.tree.AbstractInsnNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import java.util.zip.{CRC32, Deflater, ZipEntry, ZipOutputStream}

import dotty.tools.dotc.core.Contexts.*
import dotty.tools.dotc.core.Decorators.em
import dotty.tools.dotc.util.chaining.*
import dotty.tools.io.{AbstractFile, PlainFile, VirtualFile}
import dotty.tools.io.PlainFile.toPlainFile
import BTypes.InternalName
import scala.util.chaining.*
import dotty.tools.io.JarArchive

import scala.language.unsafeNulls
Expand Down
25 changes: 24 additions & 1 deletion compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,8 @@ class JSCodeGen()(using genCtx: Context) {
genCoercion(tree, receiver, code)
else if (code == JSPrimitives.THROW)
genThrow(tree, args)
else if (code == JSPrimitives.NEW_ARRAY)
genNewArray(tree, args)
else if (JSPrimitives.isJSPrimitive(code))
genJSPrimitive(tree, args, code, isStat)
else
Expand Down Expand Up @@ -3038,6 +3040,24 @@ class JSCodeGen()(using genCtx: Context) {
}
}

/** Gen a call to the special `newArray` method. */
private def genNewArray(tree: Apply, args: List[Tree]): js.Tree = {
implicit val pos: SourcePosition = tree.sourcePos

val List(elemClazz, Literal(arrayClassConstant), dimsArray: JavaSeqLiteral) = args: @unchecked

dimsArray.elems match {
case singleDim :: Nil =>
// Use a js.NewArray
val arrayTypeRef = toTypeRef(arrayClassConstant.typeValue).asInstanceOf[jstpe.ArrayTypeRef]
js.NewArray(arrayTypeRef, genExpr(singleDim))
case _ =>
// Delegate to jlr.Array.newInstance
js.ApplyStatic(js.ApplyFlags.empty, JLRArrayClassName, js.MethodIdent(JLRArrayNewInstanceMethodName),
List(genExpr(elemClazz), genJavaSeqLiteral(dimsArray)))(jstpe.AnyType)
}
}

/** Gen a "normal" apply (to a true method).
*
* But even these are further refined into:
Expand Down Expand Up @@ -4846,7 +4866,7 @@ class JSCodeGen()(using genCtx: Context) {

object JSCodeGen {

private val NullPointerExceptionClass = ClassName("java.lang.NullPointerException")
private val JLRArrayClassName = ClassName("java.lang.reflect.Array")
private val JSObjectClassName = ClassName("scala.scalajs.js.Object")
private val JavaScriptExceptionClassName = ClassName("scala.scalajs.js.JavaScriptException")

Expand All @@ -4856,6 +4876,9 @@ object JSCodeGen {

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

private val JLRArrayNewInstanceMethodName =
MethodName("newInstance", List(jstpe.ClassRef(jsNames.ClassClass), jstpe.ArrayTypeRef(jstpe.IntRef, 1)), ObjectClassRef)

private val ObjectArgConstructorName = MethodName.constructor(List(ObjectClassRef))

private val thisOriginalName = OriginalName("this")
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSPrimitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ object JSPrimitives {
inline val UNWRAP_FROM_THROWABLE = WRAP_AS_THROWABLE + 1 // js.special.unwrapFromThrowable
inline val DEBUGGER = UNWRAP_FROM_THROWABLE + 1 // js.special.debugger

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

inline val UNION_FROM = THROW + 1 // js.|.from
inline val UNION_FROM = NEW_ARRAY + 1 // js.|.from
inline val UNION_FROM_TYPE_CONSTRUCTOR = UNION_FROM + 1 // js.|.fromTypeConstructor

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

addPrimitive(defn.throwMethod, THROW)
addPrimitive(defn.newArrayMethod, NEW_ARRAY)

addPrimitive(jsdefn.PseudoUnion_from, UNION_FROM)
addPrimitive(jsdefn.PseudoUnion_fromTypeConstructor, UNION_FROM_TYPE_CONSTRUCTOR)
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn

var hasMacroAnnotations: Boolean = false

def hasUnrollDefs: Boolean = unrolledClasses.nonEmpty
var unrolledClasses: Set[Symbol] = Set.empty

/** Set to `true` if inliner added anonymous mirrors that need to be completed */
var needsMirrorSupport: Boolean = false

Expand Down
7 changes: 3 additions & 4 deletions compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import typer.{TyperPhase, RefChecks}
import parsing.Parser
import Phases.Phase
import transform.*
import dotty.tools.backend
import backend.jvm.{CollectSuperCalls, GenBCode}
import localopt.StringInterpolatorOpt

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

/** Phases dealing with the transformation from pickled trees to backend trees */
Expand Down
14 changes: 12 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ object desugar {
*/
val UntupledParam: Property.Key[Unit] = Property.StickyKey()

/** An attachment key to indicate that a ValDef originated from a pattern.
*/
val PatternVar: Property.Key[Unit] = Property.StickyKey()

/** An attachment key for Trees originating in for-comprehension, such as tupling of assignments.
*/
val ForArtifact: Property.Key[Unit] = Property.StickyKey()

/** An attachment key to indicate that a ValDef is an evidence parameter
* for a context bound.
*/
Expand Down Expand Up @@ -1507,7 +1515,7 @@ object desugar {
val matchExpr =
if (tupleOptimizable) rhs
else
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids))
val caseDef = CaseDef(pat, EmptyTree, makeTuple(ids).withAttachment(ForArtifact, ()))
Match(makeSelector(rhs, MatchCheck.IrrefutablePatDef), caseDef :: Nil)
vars match {
case Nil if !mods.is(Lazy) =>
Expand Down Expand Up @@ -1537,6 +1545,7 @@ object desugar {
ValDef(named.name.asTermName, tpt, selector(n))
.withMods(mods)
.withSpan(named.span)
.withAttachment(PatternVar, ())
)
flatTree(firstDef :: restDefs)
}
Expand Down Expand Up @@ -1922,6 +1931,7 @@ object desugar {
val vdef = ValDef(named.name.asTermName, tpt, rhs)
.withMods(mods)
.withSpan(original.span.withPoint(named.span.start))
.withAttachment(PatternVar, ())
val mayNeedSetter = valDef(vdef)
mayNeedSetter
}
Expand Down Expand Up @@ -2167,7 +2177,7 @@ object desugar {
case _ => Modifiers()
makePatDef(valeq, mods, defpat, rhs)
}
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat0, gen.expr, gen.checkMode) :: Nil, Block(pdefs, makeTuple(id0 :: ids)))
val rhs1 = makeFor(nme.map, nme.flatMap, GenFrom(defpat0, gen.expr, gen.checkMode) :: Nil, Block(pdefs, makeTuple(id0 :: ids).withAttachment(ForArtifact, ())))
val allpats = gen.pat :: pats
val vfrom1 = GenFrom(makeTuple(allpats), rhs1, GenCheckMode.Ignore)
makeFor(mapName, flatMapName, vfrom1 :: rest1, body)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/CliCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Settings.*
import core.Contexts.*
import printing.Highlighting

import scala.util.chaining.given
import dotty.tools.dotc.util.chaining.*
import scala.PartialFunction.cond

trait CliCommand:
Expand Down
22 changes: 6 additions & 16 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory,
import Setting.ChoiceWithHelp
import ScalaSettingCategories.*

import scala.util.chaining.*
import dotty.tools.dotc.util.chaining.*

import java.util.zip.Deflater

Expand Down Expand Up @@ -173,28 +173,20 @@ private sealed trait WarningSettings:
choices = List(
ChoiceWithHelp("nowarn", ""),
ChoiceWithHelp("all", ""),
ChoiceWithHelp(
name = "imports",
description = "Warn if an import selector is not referenced.\n" +
"NOTE : overrided by -Wunused:strict-no-implicit-warn"),
ChoiceWithHelp("imports", "Warn if an import selector is not referenced."),
ChoiceWithHelp("privates", "Warn if a private member is unused"),
ChoiceWithHelp("locals", "Warn if a local definition is unused"),
ChoiceWithHelp("explicits", "Warn if an explicit parameter is unused"),
ChoiceWithHelp("implicits", "Warn if an implicit parameter is unused"),
ChoiceWithHelp("params", "Enable -Wunused:explicits,implicits"),
ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
//ChoiceWithHelp("inlined", "Apply -Wunused to inlined expansions"), // TODO
ChoiceWithHelp("linted", "Enable -Wunused:imports,privates,locals,implicits"),
ChoiceWithHelp(
name = "strict-no-implicit-warn",
description = "Same as -Wunused:import, only for imports of explicit named members.\n" +
"NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all"
),
// ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
ChoiceWithHelp(
name = "unsafe-warn-patvars",
description = "(UNSAFE) Warn if a variable bound in a pattern is unused.\n" +
"This warning can generate false positive, as warning cannot be\n" +
"suppressed yet."
)
),
default = Nil
)
Expand All @@ -206,7 +198,6 @@ private sealed trait WarningSettings:
// Is any choice set for -Wunused?
def any(using Context): Boolean = Wall.value || Wunused.value.nonEmpty

// overrided by strict-no-implicit-warn
def imports(using Context) =
(allOr("imports") || allOr("linted")) && !(strictNoImplicitWarn)
def locals(using Context) =
Expand All @@ -220,9 +211,8 @@ private sealed trait WarningSettings:
def params(using Context) = allOr("params")
def privates(using Context) =
allOr("privates") || allOr("linted")
def patvars(using Context) =
isChoiceSet("unsafe-warn-patvars") // not with "all"
// allOr("patvars") // todo : rename once fixed
def patvars(using Context) = allOr("patvars")
def inlined(using Context) = isChoiceSet("inlined")
def linted(using Context) =
allOr("linted")
def strictNoImplicitWarn(using Context) =
Expand Down
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ class Definitions {
@tu lazy val Predef_undefined: Symbol = ScalaPredefModule.requiredMethod(nme.???)
@tu lazy val ScalaPredefModuleClass: ClassSymbol = ScalaPredefModule.moduleClass.asClass

@tu lazy val SameTypeClass: ClassSymbol = requiredClass("scala.=:=")
@tu lazy val SameType_refl: Symbol = SameTypeClass.companionModule.requiredMethod(nme.refl)
@tu lazy val SubTypeClass: ClassSymbol = requiredClass("scala.<:<")
@tu lazy val SubType_refl: Symbol = SubTypeClass.companionModule.requiredMethod(nme.refl)

Expand Down Expand Up @@ -834,6 +836,7 @@ class Definitions {
@tu lazy val QuotedExprClass: ClassSymbol = requiredClass("scala.quoted.Expr")

@tu lazy val QuotesClass: ClassSymbol = requiredClass("scala.quoted.Quotes")
@tu lazy val Quotes_reflectModule: Symbol = QuotesClass.requiredClass("reflectModule")
@tu lazy val Quotes_reflect: Symbol = QuotesClass.requiredValue("reflect")
@tu lazy val Quotes_reflect_asTerm: Symbol = Quotes_reflect.requiredMethod("asTerm")
@tu lazy val Quotes_reflect_Apply: Symbol = Quotes_reflect.requiredValue("Apply")
Expand Down Expand Up @@ -955,6 +958,7 @@ class Definitions {
def NonEmptyTupleClass(using Context): ClassSymbol = NonEmptyTupleTypeRef.symbol.asClass
lazy val NonEmptyTuple_tail: Symbol = NonEmptyTupleClass.requiredMethod("tail")
@tu lazy val PairClass: ClassSymbol = requiredClass("scala.*:")
@tu lazy val PairClass_unapply: Symbol = PairClass.companionModule.requiredMethod("unapply")

@tu lazy val TupleXXLClass: ClassSymbol = requiredClass("scala.runtime.TupleXXL")
def TupleXXLModule(using Context): Symbol = TupleXXLClass.companionModule
Expand Down Expand Up @@ -1036,6 +1040,7 @@ class Definitions {
@tu lazy val MigrationAnnot: ClassSymbol = requiredClass("scala.annotation.migration")
@tu lazy val NowarnAnnot: ClassSymbol = requiredClass("scala.annotation.nowarn")
@tu lazy val UnusedAnnot: ClassSymbol = requiredClass("scala.annotation.unused")
@tu lazy val UnrollAnnot: ClassSymbol = requiredClass("scala.annotation.unroll")
@tu lazy val TransparentTraitAnnot: ClassSymbol = requiredClass("scala.annotation.transparentTrait")
@tu lazy val NativeAnnot: ClassSymbol = requiredClass("scala.native")
@tu lazy val RepeatedAnnot: ClassSymbol = requiredClass("scala.annotation.internal.Repeated")
Expand All @@ -1061,6 +1066,7 @@ class Definitions {
@tu lazy val UntrackedCapturesAnnot: ClassSymbol = requiredClass("scala.caps.untrackedCaptures")
@tu lazy val UseAnnot: ClassSymbol = requiredClass("scala.caps.use")
@tu lazy val VolatileAnnot: ClassSymbol = requiredClass("scala.volatile")
@tu lazy val LanguageFeatureMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.languageFeature")
@tu lazy val BeanGetterMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.beanGetter")
@tu lazy val BeanSetterMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.beanSetter")
@tu lazy val FieldMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.field")
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,9 @@ object Denotations {
def filterDisjoint(denots: PreDenotation)(using Context): SingleDenotation =
if (denots.exists && denots.matches(this)) NoDenotation else this
def filterWithFlags(required: FlagSet, excluded: FlagSet)(using Context): SingleDenotation =
val realExcluded = if ctx.isAfterTyper then excluded else excluded | Invisible
val realExcluded =
if ctx.isAfterTyper || ctx.mode.is(Mode.ResolveFromTASTy) then excluded
else excluded | Invisible
def symd: SymDenotation = this match
case symd: SymDenotation => symd
case _ => symbol.denot
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Mode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ object Mode {
/** Read original positions when unpickling from TASTY */
val ReadPositions: Mode = newMode(17, "ReadPositions")

/** We are resolving a SELECT name from TASTy */
val ResolveFromTASTy: Mode = newMode(18, "ResolveFromTASTy")

/** We are elaborating the fully qualified name of a package clause.
* In this case, identifiers should never be imported.
*/
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ object SymDenotations {
case _ =>
// Otherwise, no completion is necessary, see the preconditions of `markAbsent()`.
(myInfo `eq` NoType)
|| is(Invisible) && ctx.isTyper
|| (is(Invisible) && !ctx.mode.is(Mode.ResolveFromTASTy)) && ctx.isTyper
|| is(ModuleVal, butNot = Package) && moduleClass.isAbsent(canForce)
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3070,6 +3070,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
disjointnessBoundary(tp.effectiveBounds.hi)
case tp: ErrorType =>
defn.AnyType
case tp: NoType.type =>
defn.AnyType
end disjointnessBoundary

(disjointnessBoundary(tp1), disjointnessBoundary(tp2)) match
Expand Down
9 changes: 9 additions & 0 deletions compiler/src/dotty/tools/dotc/core/TypeEval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ object TypeEval:
nestedPairs(fieldLabels) :: nestedPairs(fieldTypes) :: Nil
else arg.widenDealias match
case arg @ defn.NamedTuple(_, _) => Some(arg)
case arg if arg.derivesFrom(defn.TupleClass) =>
val fieldTypesOpt = tupleElementTypes(arg)
fieldTypesOpt match
case Some(fieldTypes) =>
val fieldLabels = (for i <- 1 to fieldTypes.length yield ConstantType(Constant(s"_$i"))).toList
Some:
defn.NamedTupleTypeRef.appliedTo:
nestedPairs(fieldLabels) :: nestedPairs(fieldTypes) :: Nil
case _ => None
case _ => None

def constantFold1[T](extractor: Type => Option[T], op: T => Any): Option[Type] =
Expand Down
Loading

0 comments on commit 9754335

Please sign in to comment.