Make runtime multistage programming and macros play together better #17851
Replies: 0 comments 4 replies
-
Can you describe the problem in more details? Is it that there are two classes called Type? If so, can't you rely on their fully-qualified name to distinguish them? |
Beta Was this translation helpful? Give feedback.
-
The phase consistency principle prevents us from using certain values at certain levels of quotes. Type[T] is created at level 0 at compile time in this code. genSumX tries to summon a Type[T] for the T it's given too. The issue is that the compiler sees this, and tries to use the level 0 Type[T] for genSumX, which violates the phase consistency principle. However, since genSumX is meant to generate and compile an expression at compile time, this should not be the case, as it can (and should) summon a Type[T] of its own at runtime. This is entirely a problem of the compiler seeing genSumX needs a Type[T] and trying to use the compile time version instead of stepping back and letting the runtime quotes generate the necessary information. I show this by making genSumX ask for |
Beta Was this translation helpful? Give feedback.
-
The compiler error may make the issue clearer. the code
Using |
Beta Was this translation helpful? Give feedback.
-
Minimized to import scala.quoted.*
def applyImpl[T](using qt: Quotes)(using t: Type[T]) = '{
given Quotes = ???
getType[T](using Type.of[T])
}
def getType[T](using Type[T]) = ??? The fix is - getType[T]
+ getType[T](using Type.of[T]) Not sure if we can automatically transform a reference to |
Beta Was this translation helpful? Give feedback.
-
Right now, using runtime multistage programming in macros is a nightmare because the 'Type' typeclass from macros is very hard to hide. Take for example this prototype Vector that uses macros and MSP:
The opaque type Hider here is used to hide the compile time
Type[T]
fromgenSumX
, which causes a compile time error complaining about the compile time Type[T] being used in too low of a scope.@smarter @nicolasstucki
Beta Was this translation helpful? Give feedback.
All reactions