-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix opaque types leaking rhs when inlined and found in type params (a…
…nd a related stale symbol issue) (#22655) This PR fixes the 2 issues found in #20449, split into 2 commits. The first commit fixes the stale symbol related issue found if the files from the issue minimization are compiled together. After suspending and retrying compilation, the classDefs that are defined directly in packages previously would sometimes not have companion objects regenerated, instead relying on the stale symbols from the previous run, causing them not to to pass the reallyExists check when looking for a specific ref. Now we make sure to go through lastKnwonDenotation, since the current one may not exists and may not point us to a Module flag when checking if to regenerate it. The second commit fixes the opaque type alias rhs leaking in a macro. That was caused by building proxies for all parts of the type, including type arguments to opaque types - from the perspective of a type like Object[OpaqueType], the opaque type rhs should not be visible.
- Loading branch information
Showing
7 changed files
with
147 additions
and
2 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
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,3 @@ | ||
import scala.quoted.* | ||
transparent inline def getTypeInfo[T]() = ${ getTypeInfoImpl[T] } | ||
def getTypeInfoImpl[T: Type](using ctx: Quotes): Expr[Unit] = '{ () } |
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,6 @@ | ||
|
||
class Wrapper1[A] | ||
val a = { | ||
getTypeInfo[Any]() | ||
val wrapper2 = Wrapper1[Any]() | ||
} |
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,50 @@ | ||
------ UserName.T - Directly ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ UserName.T - Directly ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper1[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper2[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper1[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper2[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper1[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper2[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper1[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper2[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
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,29 @@ | ||
import scala.quoted.* | ||
|
||
class ForeignWrapper1[-A] { | ||
inline def getTypeInfo(inline source: String): String = | ||
${ getTypeInfoImpl[A]('source) } | ||
def createWrapper2 = ForeignWrapper2(this) | ||
} | ||
|
||
class ForeignWrapper2[-A](val self: ForeignWrapper1[A]) { | ||
inline def getTypeInfo(inline source: String): String = | ||
${getTypeInfoImpl[A]('source)} | ||
} | ||
|
||
transparent inline def getTypeInfo[T](inline source: String) = | ||
${ getTypeInfoImpl[T]('source) } | ||
|
||
def getTypeInfoImpl[T: Type](source: Expr[String])(using ctx: Quotes) : Expr[String] = { | ||
import ctx.reflect.* | ||
|
||
val tpe = TypeRepr.of[T] | ||
val str = | ||
s"""|------ ${source.valueOrAbort} ------- | ||
|Original: ${tpe.show} | ||
|Dealias: ${tpe.dealias.show} | ||
|Dealias dealias: ${tpe.dealias.dealias.show} | ||
""".stripMargin | ||
|
||
Expr(str) | ||
} |
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 @@ | ||
object UserName { | ||
opaque type T = String | ||
|
||
def apply(s: String): T = s | ||
} | ||
|
||
type UserName = UserName.T | ||
|
||
class Wrapper1[-A] { | ||
inline def getTypeInfo(inline source: String): String = | ||
${ getTypeInfoImpl[A]('source) } | ||
def createWrapper2 = Wrapper2(this) | ||
} | ||
|
||
class Wrapper2[-A](val self: Wrapper1[A]) { | ||
inline def getTypeInfo(inline source: String): String = | ||
${getTypeInfoImpl[A]('source)} | ||
} | ||
|
||
|
||
@main def Test() = { | ||
println(getTypeInfo[UserName.T]("UserName.T - Directly")) | ||
println(getTypeInfo[UserName]("UserName.T - Directly")) | ||
|
||
val foreignWrapper = ForeignWrapper1[UserName.T]() | ||
println(foreignWrapper.getTypeInfo("ForeignWrapper1[UserName.T]")) | ||
println(foreignWrapper.createWrapper2.getTypeInfo("ForeignWrapper2[UserName.T]")) | ||
|
||
val foreignWrapper2 = ForeignWrapper1[UserName]() | ||
println(foreignWrapper2.getTypeInfo("ForeignWrapper1[UserName]")) | ||
println(foreignWrapper2.createWrapper2.getTypeInfo("ForeignWrapper2[UserName]")) | ||
|
||
val wrapper = Wrapper1[UserName.T]() | ||
println(wrapper.getTypeInfo("Wrapper1[UserName.T]")) | ||
println(wrapper.createWrapper2.getTypeInfo("Wrapper2[UserName.T]")) | ||
|
||
val wrapper2 = Wrapper1[UserName]() | ||
println(wrapper2.getTypeInfo("Wrapper1[UserName]")) | ||
println(wrapper2.createWrapper2.getTypeInfo("Wrapper2[UserName]")) | ||
|
||
} |