Skip to content

Commit 4391dc9

Browse files
committed
Merge branch 'main' into 23908
2 parents 754ca02 + 1315eda commit 4391dc9

File tree

156 files changed

+1952
-625
lines changed

Some content is hidden

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

156 files changed

+1952
-625
lines changed

compiler/src/dotty/tools/MainGenericCompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ case class CompileSettings(
8585

8686
object MainGenericCompiler {
8787

88-
val classpathSeparator = File.pathSeparator
88+
val classpathSeparator: String = File.pathSeparator
8989

9090
@sharable val javaOption = raw"""-J(.*)""".r
9191
@sharable val javaPropOption = raw"""-D(.+?)=(.?)""".r

compiler/src/dotty/tools/MainGenericRunner.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ case class Settings(
9696

9797
object MainGenericRunner {
9898

99-
val classpathSeparator = File.pathSeparator
99+
val classpathSeparator: String = File.pathSeparator
100100

101101
def processClasspath(cp: String, tail: List[String]): (List[String], List[String]) =
102102
val cpEntries = cp.split(classpathSeparator).toList

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class CodeGen(val int: DottyBackendInterface, val primitives: DottyPrimitives)(
152152
new interfaces.AbstractFile {
153153
override def name = absfile.name
154154
override def path = absfile.path
155-
override def jfile = Optional.ofNullable(absfile.file)
155+
override def jfile: Optional[java.io.File] = Optional.ofNullable(absfile.file)
156156
}
157157

158158
private def genClass(cd: TypeDef, unit: CompilationUnit): ClassNode = {

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

Lines changed: 194 additions & 60 deletions
Large diffs are not rendered by default.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ final class JSDefinitions()(using Context) {
8585
def JSGlobalScopeAnnot(using Context) = JSGlobalScopeAnnotType.symbol.asClass
8686
@threadUnsafe lazy val JSNameAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSName")
8787
def JSNameAnnot(using Context) = JSNameAnnotType.symbol.asClass
88+
@threadUnsafe lazy val JSOperatorAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSOperator")
89+
def JSOperatorAnnot(using Context) = JSOperatorAnnotType.symbol.asClass
8890
@threadUnsafe lazy val JSFullNameAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSFullName")
8991
def JSFullNameAnnot(using Context) = JSFullNameAnnotType.symbol.asClass
9092
@threadUnsafe lazy val JSBracketAccessAnnotType: TypeRef = requiredClassRef("scala.scalajs.js.annotation.JSBracketAccess")
@@ -213,6 +215,14 @@ final class JSDefinitions()(using Context) {
213215
@threadUnsafe lazy val WrappedArrayType: TypeRef = requiredClassRef("scala.scalajs.js.WrappedArray")
214216
def WrappedArrayClass(using Context) = WrappedArrayType.symbol.asClass
215217

218+
@threadUnsafe lazy val LinkingInfoModuleRef = requiredModuleRef("scala.scalajs.LinkingInfo")
219+
def LinkingInfoModule(using Context) = LinkingInfoModuleRef.symbol
220+
@threadUnsafe lazy val LinkingInfo_linkTimeIfR = LinkingInfoModule.requiredMethodRef("linkTimeIf")
221+
def LinkingInfo_linkTimeIf(using Context) = LinkingInfo_linkTimeIfR.symbol
222+
223+
@threadUnsafe lazy val LinkTimePropertyAnnotType: TypeRef = requiredClassRef("scala.scalajs.annotation.linkTimeProperty")
224+
def LinkTimePropertyAnnot(using Context) = LinkTimePropertyAnnotType.symbol.asClass
225+
216226
@threadUnsafe lazy val ScalaRunTime_isArrayR = defn.ScalaRuntimeModule.requiredMethodRef("isArray", List(???, ???))
217227
def ScalaRunTime_isArray(using Context): Symbol = ScalaRunTime_isArrayR.symbol
218228

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +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 // <special-ops>.throw
51-
inline val NEW_ARRAY = THROW + 1 // scala.runtime.Arrays.newArray
50+
inline val LINKTIME_IF = DEBUGGER + 1 // LinkingInfo.linkTimeIf
51+
52+
inline val THROW = LINKTIME_IF + 1 // <special-ops>.throw
53+
inline val NEW_ARRAY = THROW + 1 // scala.runtime.Arrays.newArray
5254

5355
inline val UNION_FROM = NEW_ARRAY + 1 // js.|.from
5456
inline val UNION_FROM_TYPE_CONSTRUCTOR = UNION_FROM + 1 // js.|.fromTypeConstructor
@@ -135,6 +137,8 @@ class JSPrimitives(ictx: Context) extends DottyPrimitives(ictx) {
135137
addPrimitive(jsdefn.Special_unwrapFromThrowable, UNWRAP_FROM_THROWABLE)
136138
addPrimitive(jsdefn.Special_debugger, DEBUGGER)
137139

140+
addPrimitive(jsdefn.LinkingInfo_linkTimeIf, LINKTIME_IF)
141+
138142
addPrimitive(defn.throwMethod, THROW)
139143
addPrimitive(defn.newArrayMethod, NEW_ARRAY)
140144

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class Compiler {
171171
val rctx =
172172
if ctx.settings.Xsemanticdb.value then
173173
ctx.addMode(Mode.ReadPositions)
174-
else if ctx.settings.YcheckInitGlobal.value then
174+
else if ctx.settings.YsafeInitGlobal.value then
175175
ctx.addMode(Mode.ReadPositions)
176176
else
177177
ctx

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ object desugar {
13471347
)).withSpan(tree.span)
13481348
end makePolyFunctionType
13491349

1350-
/** Invent a name for an anonympus given of type or template `impl`. */
1350+
/** Invent a name for an anonymous given of type or template `impl`. */
13511351
def inventGivenName(impl: Tree)(using Context): SimpleName =
13521352
val str = impl match
13531353
case impl: Template =>
@@ -2136,18 +2136,19 @@ object desugar {
21362136
* that refers to the bound variable for the pattern. Wildcard Binds are
21372137
* also replaced by Binds with fresh names.
21382138
*/
2139-
def makeIdPat(pat: Tree): (Tree, Ident) = pat match {
2140-
case bind @ Bind(name, pat1) =>
2141-
if name == nme.WILDCARD then
2142-
val name = UniqueName.fresh()
2143-
(cpy.Bind(pat)(name, pat1).withMods(bind.mods), Ident(name))
2144-
else (pat, Ident(name))
2139+
def makeIdPat(pat: Tree): (Tree, Ident) = pat match
2140+
case pat @ Bind(nme.WILDCARD, body) =>
2141+
val name =
2142+
body match
2143+
case Typed(Ident(nme.WILDCARD), tpt) if pat.mods.is(Given) => inventGivenName(tpt)
2144+
case _ => UniqueName.fresh()
2145+
(cpy.Bind(pat)(name, body).withMods(pat.mods), Ident(name))
2146+
case Bind(name, _) => (pat, Ident(name))
21452147
case id: Ident if isVarPattern(id) && id.name != nme.WILDCARD => (id, id)
21462148
case Typed(id: Ident, _) if isVarPattern(id) && id.name != nme.WILDCARD => (pat, id)
21472149
case _ =>
21482150
val name = UniqueName.fresh()
21492151
(Bind(name, pat), Ident(name))
2150-
}
21512152

21522153
/** Make a pattern filter:
21532154
* rhs.withFilter { case pat => true case _ => false }

compiler/src/dotty/tools/dotc/cc/Capability.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,9 @@ object Capabilities:
898898
case t @ AnnotatedType(parent, ann) =>
899899
val parent1 = this(parent)
900900
if ann.symbol.isRetains && ann.tree.toCaptureSet.containsCap then
901-
this(CapturingType(parent1, ann.tree.toCaptureSet))
901+
// Applying `this` can cause infinite recursion in some cases during printing.
902+
// scalac -Xprint:all tests/pos/i23885/S_1.scala tests/pos/i23885/S_2.scala
903+
mapOver(CapturingType(parent1, ann.tree.toCaptureSet))
902904
else
903905
t.derivedAnnotatedType(parent1, ann)
904906
case defn.RefinedFunctionOf(_) =>

compiler/src/dotty/tools/dotc/cc/CaptureOps.scala

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Annotations.Annotation
1414
import CaptureSet.VarState
1515
import Capabilities.*
1616
import StdNames.nme
17+
import config.Feature
1718

1819
/** Attachment key for capturing type trees */
1920
private val Captures: Key[CaptureSet] = Key()
@@ -634,13 +635,18 @@ extension (tp: AnnotatedType)
634635
case ann: CaptureAnnotation => ann.boxed
635636
case _ => false
636637

637-
/** Drop retains annotations in the type. */
638+
/** Drop retains annotations in the inferred type if CC is not enabled
639+
* or transform them into RetainingTypes if CC is enabled.
640+
*/
638641
class CleanupRetains(using Context) extends TypeMap:
639-
def apply(tp: Type): Type =
640-
tp match
641-
case AnnotatedType(tp, annot) if annot.symbol == defn.RetainsAnnot || annot.symbol == defn.RetainsByNameAnnot =>
642-
RetainingType(tp, defn.NothingType, byName = annot.symbol == defn.RetainsByNameAnnot)
643-
case _ => mapOver(tp)
642+
def apply(tp: Type): Type = tp match
643+
case AnnotatedType(parent, annot) if annot.symbol.isRetainsLike =>
644+
if Feature.ccEnabled then
645+
if annot.symbol == defn.RetainsAnnot || annot.symbol == defn.RetainsByNameAnnot then
646+
RetainingType(parent, defn.NothingType, byName = annot.symbol == defn.RetainsByNameAnnot)
647+
else mapOver(tp)
648+
else apply(parent)
649+
case _ => mapOver(tp)
644650

645651
/** A base class for extractors that match annotated types with a specific
646652
* Capability annotation.

0 commit comments

Comments
 (0)