forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress returns that cross different stack sizes.
This is needed to avoid verify errors
- Loading branch information
Showing
4 changed files
with
132 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
compiler/src/dotty/tools/dotc/transform/RecordStackChange.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dotty.tools.dotc | ||
package transform | ||
|
||
import MegaPhase.MiniPhase | ||
import core.* | ||
import Contexts.* | ||
import Flags.Lazy | ||
import NonLocalReturns.isNonLocalReturn | ||
|
||
/** A trait shared between LiftTry and DropBreaks. | ||
* Overrides prepare methods for trees that push to the stack before some of their elements | ||
* are evaluated. | ||
*/ | ||
trait RecordStackChange extends MiniPhase: | ||
import ast.tpd.* | ||
|
||
/** The method to call to record a stack change */ | ||
protected def stackChange(using Context): Context | ||
|
||
override def prepareForApply(tree: Apply)(using Context): Context = | ||
stackChange | ||
|
||
override def prepareForValDef(tree: ValDef)(using Context): Context = | ||
if !tree.symbol.exists | ||
|| tree.symbol.isSelfSym | ||
|| tree.symbol.owner == ctx.owner.enclosingMethod | ||
&& !tree.symbol.is(Lazy) | ||
// The current implementation wraps initializers of lazy vals in | ||
// calls to an initialize method, which means that a `try` in the | ||
// initializer needs to be lifted. Note that the new scheme proposed | ||
// in #6979 would avoid this. | ||
then ctx | ||
else stackChange | ||
|
||
override def prepareForAssign(tree: Assign)(using Context): Context = | ||
if (tree.lhs.symbol.maybeOwner == ctx.owner.enclosingMethod) ctx | ||
else stackChange | ||
|
||
override def prepareForReturn(tree: Return)(using Context): Context = | ||
if (!isNonLocalReturn(tree)) ctx | ||
else stackChange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters