Skip to content

Commit 1b40997

Browse files
committed
Fix callTrace if inlined methods
We need to keep the reference to the called method, not only the symbol of the to level class. This is important for the traces of the `assert` method that is defined in a different file. This might also be useful for macro annotations. This is also a solution to the awkward Select vs. Ident distinction to identify macros in `YCheckPositions`. Ww use `-Ycompile-scala3-library` to avoid the `stdLibPatches` patches in the community build test for `stdLib213` the same way we do in `scala-library-bootstrapped`.
1 parent 44a537b commit 1b40997

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

community-build/src/scala/dotty/communitybuild/projects.scala

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ object projects:
363363
extraSbtArgs = List("-Dscala.build.compileWithDotty=true"),
364364
sbtTestCommand = """set Global / fatalWarnings := false; library/compile""",
365365
sbtPublishCommand = """set Global / fatalWarnings := false; set library/Compile/packageDoc/publishArtifact := false; library/publishLocal""",
366+
scalacOptions = "-Ycompile-scala3-library" :: SbtCommunityProject.scalacOptions
366367
// sbtDocCommand = "library/doc" // Does no compile? No idea :/
367368
)
368369

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

+1
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ private sealed trait YSettings:
396396
val YnoExperimental: Setting[Boolean] = BooleanSetting("-Yno-experimental", "Disable experimental language features.")
397397
val YlegacyLazyVals: Setting[Boolean] = BooleanSetting("-Ylegacy-lazy-vals", "Use legacy (pre 3.3.0) implementation of lazy vals.")
398398
val YcompileScala2Library: Setting[Boolean] = BooleanSetting("-Ycompile-scala2-library", "Used when compiling the Scala 2 standard library.")
399+
val YcompileScala3Library: Setting[Boolean] = BooleanSetting("-Ycompile-scala3-library", "Used when compiling the Scala 3 standard library, including the Scala 2 library sources.")
399400
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting("-Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles")
400401

401402
val YprofileEnabled: Setting[Boolean] = BooleanSetting("-Yprofile-enabled", "Enable profiling.")

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

+12-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,18 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
367367
val pos = call.sourcePos
368368
CrossVersionChecks.checkExperimentalRef(call.symbol, pos)
369369
withMode(Mode.InlinedCall)(transform(call))
370-
val callTrace = Inlines.inlineCallTrace(call.symbol, pos)(using ctx.withSource(pos.source))
370+
val traceSym =
371+
if ctx.settings.YcompileScala3Library.value && call.symbol.owner == defn.ScalaPredefModuleClass then
372+
// These are inline method overrides that come from `scala.runtime.stdLibPatches.Predef`.
373+
// References to these members can cause conflicts when compiling the standard library.
374+
// FIXME: remove this workaround. Ideally we should not patch Predef when we compile the library to
375+
// avoid the `assert` overrides, but we also need the patches to make `summon` and other new features
376+
// work within the Scala 3 library sources. Note that currently compiling Predef.scala with
377+
// `-Ycompile-scala3-library` or without does not Ycheck. It does with `-Ycompile-scala2-library`,
378+
// because we do not apply the patches.
379+
call.symbol.topLevelClass
380+
else call.symbol
381+
val callTrace = ref(traceSym)(using ctx.withSource(pos.source)).withSpan(pos.span)
371382
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(using inlineContext(tree)))
372383
case templ: Template =>
373384
withNoCheckNews(templ.parents.flatMap(newPart)) {

compiler/src/dotty/tools/dotc/transform/YCheckPositions.scala

+3-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class YCheckPositions extends Phase {
3535
val currentSource = sources.head
3636
assert(tree.source == currentSource, i"wrong source set for $tree # ${tree.uniqueId} of ${tree.getClass}, set to ${tree.source} but context had $currentSource\n ${tree.symbol.flagsString}")
3737

38-
// Recursivlely check children while keeping track of current source
38+
// Recursively check children while keeping track of current source
3939
reporting.trace(i"check pos ${tree.getClass} ${tree.source} ${sources.head} $tree") {
4040
tree match {
4141
case tree @ Inlined(_, bindings, expansion) if tree.inlinedFromOuterScope =>
@@ -46,7 +46,7 @@ class YCheckPositions extends Phase {
4646
sources = old
4747
case tree @ Inlined(call, bindings, expansion) =>
4848
// bindings.foreach(traverse(_)) // TODO check inline proxies (see tests/tun/lst)
49-
sources = call.symbol.topLevelClass.source :: sources
49+
sources = call.symbol.source :: sources
5050
if (!isMacro(call)) // FIXME macro implementations can drop Inlined nodes. We should reinsert them after macro expansion based on the positions of the trees
5151
traverse(expansion)(using inlineContext(tree).withSource(sources.head))
5252
sources = sources.tail
@@ -61,10 +61,7 @@ class YCheckPositions extends Phase {
6161

6262
private def isMacro(call: Tree)(using Context) =
6363
call.symbol.is(Macro) ||
64-
(call.symbol.isClass && call.tpe.derivesFrom(defn.MacroAnnotationClass)) ||
65-
// The call of a macro after typer is encoded as a Select while other inlines are Ident
66-
// TODO remove this distinction once Inline nodes of expanded macros can be trusted (also in Inliner.inlineCallTrace)
67-
(!(ctx.phase <= postTyperPhase) && call.isInstanceOf[Select])
64+
(call.symbol.isClass && call.tpe.derivesFrom(defn.MacroAnnotationClass))
6865

6966
}
7067

0 commit comments

Comments
 (0)