Skip to content

Collect checks to run in CrossVersionChecks #16037

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

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package dotty.tools
package dotc
package core

import Types._, Symbols._, Contexts._
import Types.*, Symbols.*, Contexts.*
import printing.Printer
import printing.Texts.Text

object Constants {
object Constants:

type Tag = Int
inline val NoTag = 0
inline val UnitTag = 1
inline val BooleanTag = 2
Expand All @@ -22,7 +23,7 @@ object Constants {
inline val NullTag = 11
inline val ClazzTag = 12

class Constant(val value: Any, val tag: Int) extends printing.Showable with Product1[Any] {
class Constant(val value: Any, val tag: Tag) extends printing.Showable with Product1[Any]:
import java.lang.Double.doubleToRawLongBits
import java.lang.Float.floatToRawIntBits

Expand Down Expand Up @@ -223,9 +224,8 @@ object Constants {
def get: Any = value
def isEmpty: Boolean = false
def _1: Any = value
}

object Constant {
object Constant:
def apply(x: Null): Constant = new Constant(x, NullTag)
def apply(x: Unit): Constant = new Constant(x, UnitTag)
def apply(x: Boolean): Constant = new Constant(x, BooleanTag)
Expand Down Expand Up @@ -257,5 +257,5 @@ object Constants {
)

def unapply(c: Constant): Constant = c
}
}

end Constant
29 changes: 24 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import config.Config
import reporting._
import io.{AbstractFile, NoAbstractFile, PlainFile, Path}
import scala.io.Codec
import collection.mutable
import collection.mutable, mutable.ArrayBuffer
import printing._
import config.{JavaPlatform, SJSPlatform, Platform, ScalaSettings}
import classfile.ReusableDataReader
Expand Down Expand Up @@ -52,8 +52,10 @@ object Contexts {
private val (notNullInfosLoc, store8) = store7.newLocation[List[NotNullInfo]]()
private val (importInfoLoc, store9) = store8.newLocation[ImportInfo | Null]()
private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner](TypeAssigner)
private val (usagesLoc, store11) = store10.newLocation[Any]() // unusages feature
private val (deferredChecksLoc, store12) = store11.newLocation[DeferredChecks]()

private val initialStore = store10
private val initialStore = store12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding something to the store is an expensive operation. It charges every time we copy a store with two additional slots to copy. if we look up the property not very often it's better to use a Property.


/** The current context */
inline def ctx(using ctx: Context): Context = ctx
Expand Down Expand Up @@ -93,6 +95,9 @@ object Contexts {
inline def atPhaseNoEarlier[T](limit: Phase)(inline op: Context ?=> T)(using Context): T =
op(using if !limit.exists || limit <= ctx.phase then ctx else ctx.withPhase(limit))

inline def deferredCheck(phase: String)(inline op: Context ?=> Unit)(using Context): Unit =
ctx.deferredChecks.add(phase)(op)

inline def inMode[T](mode: Mode)(inline op: Context ?=> T)(using ctx: Context): T =
op(using if mode != ctx.mode then ctx.fresh.setMode(mode) else ctx)

Expand Down Expand Up @@ -239,6 +244,8 @@ object Contexts {
/** The current type assigner or typer */
def typeAssigner: TypeAssigner = store(typeAssignerLoc)

def deferredChecks: DeferredChecks = store(deferredChecksLoc)

/** The new implicit references that are introduced by this scope */
protected var implicitsCache: ContextualImplicits | Null = null
def implicits: ContextualImplicits = {
Expand Down Expand Up @@ -812,6 +819,7 @@ object Contexts {
store = initialStore
.updated(settingsStateLoc, settingsGroup.defaultState)
.updated(notNullInfosLoc, Nil)
.updated(deferredChecksLoc, DeferredChecks())
.updated(compilationUnitLoc, NoCompilationUnit)
searchHistory = new SearchRoot
gadt = EmptyGadtConstraint
Expand Down Expand Up @@ -954,13 +962,13 @@ object Contexts {

protected[dotc] val indentTab: String = " "

private[Contexts] val exploreContexts = new mutable.ArrayBuffer[FreshContext]
private[Contexts] val exploreContexts = ArrayBuffer.empty[FreshContext]
private[Contexts] var exploresInUse: Int = 0

private[Contexts] val changeOwnerContexts = new mutable.ArrayBuffer[FreshContext]
private[Contexts] val changeOwnerContexts = ArrayBuffer.empty[FreshContext]
private[Contexts] var changeOwnersInUse: Int = 0

private[Contexts] val comparers = new mutable.ArrayBuffer[TypeComparer]
private[Contexts] val comparers = ArrayBuffer.empty[TypeComparer]
private[Contexts] var comparersInUse: Int = 0

private var charArray = new Array[Char](256)
Expand Down Expand Up @@ -996,4 +1004,15 @@ object Contexts {
if (thread == null) thread = Thread.currentThread()
else assert(thread == Thread.currentThread(), "illegal multithreaded access to ContextBase")
}

class DeferredChecks:
private val checks = mutable.Map[String, ArrayBuffer[Context ?=> Unit]]()

def add(phase: String)(item: Context ?=> Unit): Unit = checks.getOrElseUpdate(phase, ArrayBuffer.empty).addOne(item)

def run(phase: String)(using Context): Unit =
for items <- checks.remove(phase) do
for item <- items do
item
end DeferredChecks
}
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ object Decorators {
def ex(args: Shown*)(using Context): String =
explained(new StringFormatter(sc).assemble(args))

/** Print a message and stack trace, for debugging only.
*/
@deprecated("Stack trace facility for debugging only.", since="3.2")
def tr(args: Shown*)(using Context): Unit =
Console.err.println(i(args*))
Thread.dumpStack()

extension [T <: AnyRef](arr: Array[T])
def binarySearch(x: T | Null): Int = java.util.Arrays.binarySearch(arr.asInstanceOf[Array[Object | Null]], x)

Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ object Phases {
final def phasePlan: List[List[Phase]] = this.phasesPlan
final def setPhasePlan(phasess: List[List[Phase]]): Unit = this.phasesPlan = phasess

/** Squash TreeTransform's beloning to same sublist to a single TreeTransformer
* Each TreeTransform gets own period,
* whereas a combined TreeTransformer gets period equal to union of periods of it's TreeTransforms
*/
/** Squash TreeTransforms that belong to same sublist to a single TreeTransformer.
* Each TreeTransform gets own period,
* whereas a combined TreeTransformer gets period equal to union of periods of its TreeTransforms.
*/
final def fusePhases(phasess: List[List[Phase]],
phasesToSkip: List[String],
stopBeforePhases: List[String],
Expand Down
11 changes: 8 additions & 3 deletions compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@ object Inlines:
* @return An `Inlined` node that refers to the original call and the inlined bindings
* and body that replace it.
*/
def inlineCall(tree: Tree)(using Context): Tree =
def inlineCall(tree: Tree)(using Context): Tree = inlineCall(tree, retainer = false)

private def inlineCall(tree: Tree, retainer: Boolean)(using Context): Tree =
if tree.symbol.denot != SymDenotations.NoDenotation
&& tree.symbol.effectiveOwner == defn.CompiletimeTestingPackage.moduleClass
then
if (tree.symbol == defn.CompiletimeTesting_typeChecks) return Intrinsics.typeChecks(tree)
if (tree.symbol == defn.CompiletimeTesting_typeCheckErrors) return Intrinsics.typeCheckErrors(tree)

CrossVersionChecks.checkExperimentalRef(tree.symbol, tree.srcPos)
if !retainer then
CrossVersionChecks.checkExperimentalRef(tree.symbol, tree.srcPos)
CrossVersionChecks.checkDeprecatedDeferred(tree.symbol, tree.srcPos)

if tree.symbol.isConstructor then return tree // error already reported for the inline constructor definition

Expand Down Expand Up @@ -240,7 +244,8 @@ object Inlines:
retainer.deriveTargetNameAnnotation(meth, name => BodyRetainerName(name.asTermName))
DefDef(retainer, prefss =>
inlineCall(
ref(meth).appliedToArgss(prefss).withSpan(mdef.rhs.span.startPos))(
ref(meth).appliedToArgss(prefss).withSpan(mdef.rhs.span.startPos),
retainer = true)(
using ctx.withOwner(retainer)))
.showing(i"retainer for $meth: $result", inlining)

Expand Down
Loading