Skip to content

Commit 3f1e20a

Browse files
Merge pull request #9984 from dotty-staging/move-blackbox-macro-exapnsion-after-typer
Expand non-transparent macros after Typer
2 parents 69d363b + bdf2482 commit 3f1e20a

File tree

99 files changed

+700
-177
lines changed

Some content is hidden

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

99 files changed

+700
-177
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,9 @@ community-build/sbt-scalajs-sbt
8989
*.check.out
9090
!/dist/bin/
9191

92+
# semanticdb test output files
93+
*.expect.scala.out
94+
*.expect.out
95+
9296
# Bloop
9397
.bsp

bench-run/src/main/scala/dotty/tools/benchmarks/tuples/TupleOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TupleOps {
5050
def tupleMergeSort(tuple: Tuple): Tuple =
5151
if (tuple.size <= 1) tuple
5252
else {
53-
val (tuple1, tuple2) = tuple.splitAt(tuple.size / 2)
53+
val (tuple1, tuple2) = tuple.splitAt(tuple.size / 2): (Tuple, Tuple)// TODO remove ascriptions (issue with type variable constraints)
5454
val (sorted1, sorted2) = (tupleMergeSort(tuple1), tupleMergeSort(tuple2))
5555
tupleMerge(sorted1, sorted2)
5656
}

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,26 @@ class CompilationUnit protected (val source: SourceFile) {
3838
*/
3939
val freshNames: FreshNameCreator = new FreshNameCreator.Default
4040

41+
/** Will be set to `true` if there are inline call that must be inlined after typer.
42+
* The information is used in phase `Inlining` in order to avoid traversing trees that need no transformations.
43+
*/
44+
var needsInlining: Boolean = false
45+
4146
/** Will be set to `true` if contains `Quote`.
4247
* The information is used in phase `Staging` in order to avoid traversing trees that need no transformations.
4348
*/
4449
var needsStaging: Boolean = false
4550

51+
/** Will be set to `true` if contains `Quote` that needs to be pickled
52+
* The information is used in phase `PickleQuotes` in order to avoid traversing trees that need no transformations.
53+
*/
54+
var needsQuotePickling: Boolean = false
55+
4656
/** A structure containing a temporary map for generating inline accessors */
4757
val inlineAccessors: InlineAccessors = new InlineAccessors
4858

4959
var suspended: Boolean = false
60+
var suspendedAtInliningPhase: Boolean = false
5061

5162
/** Can this compilation unit be suspended */
5263
def isSuspendable: Boolean = true
@@ -61,6 +72,8 @@ class CompilationUnit protected (val source: SourceFile) {
6172
report.echo(i"suspended: $this")
6273
suspended = true
6374
ctx.run.suspendedUnits += this
75+
if ctx.phase == Phases.inliningPhase then
76+
suspendedAtInliningPhase = true
6477
throw CompilationUnit.SuspendException()
6578

6679
private var myAssignmentSpans: Map[Int, List[Span]] = null
@@ -90,7 +103,9 @@ object CompilationUnit {
90103
if (forceTrees) {
91104
val force = new Force
92105
force.traverse(unit1.tpdTree)
93-
unit1.needsStaging = force.needsStaging
106+
unit1.needsStaging = force.containsQuote
107+
unit1.needsQuotePickling = force.containsQuote
108+
unit1.needsInlining = force.containsInline
94109
}
95110
unit1
96111
}
@@ -116,10 +131,13 @@ object CompilationUnit {
116131

117132
/** Force the tree to be loaded */
118133
private class Force extends TreeTraverser {
119-
var needsStaging = false
134+
var containsQuote = false
135+
var containsInline = false
120136
def traverse(tree: Tree)(using Context): Unit = {
121137
if (tree.symbol.isQuote)
122-
needsStaging = true
138+
containsQuote = true
139+
if tree.symbol.is(Flags.Inline) then
140+
containsInline = true
123141
traverseChildren(tree)
124142
}
125143
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Compiler {
5050
/** Phases dealing with TASTY tree pickling and unpickling */
5151
protected def picklerPhases: List[List[Phase]] =
5252
List(new Pickler) :: // Generate TASTY info
53+
List(new Inlining) :: // Inline and execute macros
5354
List(new PickleQuotes) :: // Turn quoted trees into explicit run-time data structures
5455
Nil
5556

@@ -61,6 +62,7 @@ class Compiler {
6162
new CookComments, // Cook the comments: expand variables, doc, etc.
6263
new CheckStatic, // Check restrictions that apply to @static members
6364
new BetaReduce, // Reduce closure applications
65+
new InlineVals, // Check right hand-sides of an `inline val`s
6466
new ExpandSAMs, // Expand single abstract method closures to anonymous classes
6567
new init.Checker) :: // Check initialization of objects
6668
List(new ElimRepeated, // Rewrite vararg parameters and arguments

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,27 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
101101
*/
102102
def units: List[CompilationUnit] = myUnits
103103

104-
var suspendedUnits: mutable.ListBuffer[CompilationUnit] = mutable.ListBuffer()
105-
106104
private def units_=(us: List[CompilationUnit]): Unit =
107105
myUnits = us
108106

107+
var suspendedUnits: mutable.ListBuffer[CompilationUnit] = mutable.ListBuffer()
108+
109+
def checkSuspendedUnits(newUnits: List[CompilationUnit])(using Context): Unit =
110+
if newUnits.isEmpty && suspendedUnits.nonEmpty && !ctx.reporter.errorsReported then
111+
val where =
112+
if suspendedUnits.size == 1 then i"in ${suspendedUnits.head}."
113+
else i"""among
114+
|
115+
| ${suspendedUnits.toList}%, %
116+
|"""
117+
val enableXprintSuspensionHint =
118+
if ctx.settings.XprintSuspension.value then ""
119+
else "\n\nCompiling with -Xprint-suspension gives more information."
120+
report.error(em"""Cyclic macro dependencies $where
121+
|Compilation stopped since no further progress can be made.
122+
|
123+
|To fix this, place macros in one set of files and their callers in another.$enableXprintSuspensionHint""")
124+
109125
/** The files currently being compiled (active or suspended).
110126
* This may return different results over time.
111127
* These files do not have to be source files since it's possible to compile

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {
227227
val Yinstrument: Setting[Boolean] = BooleanSetting("-Yinstrument", "Add instrumentation code that counts allocations and closure creations.")
228228
val YinstrumentDefs: Setting[Boolean] = BooleanSetting("-Yinstrument-defs", "Add instrumentation code that counts method calls; needs -Yinstrument to be set, too.")
229229

230+
val YforceInlineWhileTyping: Setting[Boolean] = BooleanSetting("-Yforce-inline-while-typing", "Make non-transparent inline methods inline when typing. Emulates the old inlining behavior of 3.0.0-M3.")
231+
230232
/** Dottydoc specific settings that are not used in scaladoc */
231233
val docSnapshot: Setting[Boolean] = BooleanSetting("-doc-snapshot", "Generate a documentation snapshot for the current Dotty version")
232234

0 commit comments

Comments
 (0)