-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand non-transparent macros after Typer #9984
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
Changes from all commits
dde8fdc
b703406
823185d
ff97f28
ed1072e
14e6d28
b1bd9be
072e71a
af91ebe
d71a64e
3b16547
a87dbde
acdb5db
d02b865
da59cad
67658c8
e483d23
4a7e576
99014e0
077d364
7085eee
1f4e3e6
04989b1
bd41f01
5e489ea
b850f2a
4953991
90e5733
2f4ee75
f96ced3
1333adf
fc04bcd
0858612
c455e84
caa1a79
7e40bb2
b6371ea
0206a6e
6251b0f
72765f9
c17e82a
1b7dcd1
4cb4bbb
e33c632
df1ba15
e3858e4
d335b0f
dd24130
f465f6a
adee773
aee1555
53d69cd
891a96a
dea04b3
ec71a61
bdf2482
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+7 −5 | modules/deriving/src/main/scala/shapeless3/deriving/kinds.scala |
+2 −2 | utest/src-3/utest/TestSuite.scala | |
+8 −1 | utest/src-3/utest/Tests.scala | |
+1 −1 | utest/src-3/utest/asserts/Asserts.scala | |
+1 −1 | utest/test/src-3/test/utest/AssertsTests.scala |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,15 +38,26 @@ class CompilationUnit protected (val source: SourceFile) { | |
*/ | ||
val freshNames: FreshNameCreator = new FreshNameCreator.Default | ||
|
||
/** Will be set to `true` if there are inline call that must be inlined after typer. | ||
* The information is used in phase `Inlining` in order to avoid traversing trees that need no transformations. | ||
*/ | ||
var needsInlining: Boolean = false | ||
|
||
/** Will be set to `true` if contains `Quote`. | ||
* The information is used in phase `Staging` in order to avoid traversing trees that need no transformations. | ||
*/ | ||
var needsStaging: Boolean = false | ||
|
||
/** Will be set to `true` if contains `Quote` that needs to be pickled | ||
* The information is used in phase `PickleQuotes` in order to avoid traversing trees that need no transformations. | ||
*/ | ||
var needsQuotePickling: Boolean = false | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some cases where we only need one of them. Each causes a full tree traversal as these are |
||
/** A structure containing a temporary map for generating inline accessors */ | ||
val inlineAccessors: InlineAccessors = new InlineAccessors | ||
|
||
var suspended: Boolean = false | ||
var suspendedAtInliningPhase: Boolean = false | ||
|
||
/** Can this compilation unit be suspended */ | ||
def isSuspendable: Boolean = true | ||
|
@@ -61,6 +72,8 @@ class CompilationUnit protected (val source: SourceFile) { | |
report.echo(i"suspended: $this") | ||
suspended = true | ||
ctx.run.suspendedUnits += this | ||
if ctx.phase == Phases.inliningPhase then | ||
suspendedAtInliningPhase = true | ||
throw CompilationUnit.SuspendException() | ||
|
||
private var myAssignmentSpans: Map[Int, List[Span]] = null | ||
|
@@ -90,7 +103,9 @@ object CompilationUnit { | |
if (forceTrees) { | ||
val force = new Force | ||
force.traverse(unit1.tpdTree) | ||
unit1.needsStaging = force.needsStaging | ||
unit1.needsStaging = force.containsQuote | ||
unit1.needsQuotePickling = force.containsQuote | ||
unit1.needsInlining = force.containsInline | ||
} | ||
unit1 | ||
} | ||
|
@@ -116,10 +131,13 @@ object CompilationUnit { | |
|
||
/** Force the tree to be loaded */ | ||
private class Force extends TreeTraverser { | ||
var needsStaging = false | ||
var containsQuote = false | ||
var containsInline = false | ||
def traverse(tree: Tree)(using Context): Unit = { | ||
if (tree.symbol.isQuote) | ||
needsStaging = true | ||
containsQuote = true | ||
if tree.symbol.is(Flags.Inline) then | ||
containsInline = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only happens when unpickling a quote and we do not allow inline definitions in quotes. Therefore it should be ok. |
||
traverseChildren(tree) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package dotty.tools | ||
package dotc | ||
package transform | ||
|
||
import dotty.tools.dotc.core.Contexts._ | ||
import dotty.tools.dotc.core.Decorators._ | ||
import dotty.tools.dotc.core.Flags._ | ||
import dotty.tools.dotc.core.Types._ | ||
import dotty.tools.dotc.transform.MegaPhase.MiniPhase | ||
import dotty.tools.dotc.typer.Inliner | ||
|
||
/** Check that `tree.rhs` can be right hand-side of an `inline` value definition. */ | ||
class InlineVals extends MiniPhase: | ||
import ast.tpd._ | ||
|
||
def phaseName: String = "inlineVals" | ||
|
||
override def checkPostCondition(tree: Tree)(using Context): Unit = | ||
if !ctx.erasedTypes then | ||
tree match | ||
case tree: ValDef => checkInlineConformant(tree) | ||
case _ => | ||
|
||
override def transformValDef(tree: ValDef)(using Context): Tree = | ||
checkInlineConformant(tree) | ||
tree | ||
|
||
/** Check that `tree.rhs` can be right hand-side of an `inline` value definition. */ | ||
private def checkInlineConformant(tree: ValDef)(using Context): Unit = { | ||
if tree.symbol.is(Inline, butNot = DeferredOrTermParamOrAccessor) | ||
&& !Inliner.inInlineMethod | ||
then | ||
val rhs = tree.rhs | ||
val tpt = tree.tpt | ||
tpt.tpe.widenTermRefExpr.dealias.normalized match | ||
case tp: ConstantType => | ||
if !isPureExpr(rhs) then | ||
val details = if enclosingInlineds.isEmpty then "" else em"but was: $rhs" | ||
report.error(s"inline value must be pure$details", rhs.srcPos) | ||
case _ => | ||
val pos = if tpt.span.isZeroExtent then rhs.srcPos else tpt.srcPos | ||
report.error(em"inline value must have a literal constant type", pos) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the issue have a number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question about CB. Why did you change
import.{given, _}
toimport._
? I guess it's good to already putimport given
to prepare for future migration.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are imports of extension methods that are in the correct path to not require the given imports. We needed those a long time ago, but users have kept copying the old version anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will open an issue for it. It looks like it is something related to #11247.