-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Create extractors for Tasty Trees #4279
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
Conversation
3eb7a5e
to
7fa845c
Compare
15670a8
to
4683e5d
Compare
|
||
object Lines { | ||
inline def line(dummy: Int): Int = ~lineImpl('(dummy)) | ||
def lineImpl(dummy: Expr[Int]): Expr[Int] = (dummy.toTasty.pos.startLine + 1).toExpr |
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.
Would that work?
object Lines {
implicit object CurrentPos
inline def line(implicit pos: CurrentPos.type): Int = ~lineImpl('(pos))
def lineImpl(dummy: Expr[CurrentPos.type]): Expr[Int] = (dummy.toTasty.pos.startLine + 1).toExpr
}
import Lines._
object Test {
def main(args: Array[String]): Unit = {
println(line)
}
}
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 tried that and it does not. The issue is that currently, the implicitly inferred tree does not have a position. We should add the position in the future to allow this use case to work.
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.
Even better, this one works and does not need an additional implicit
class LineNumber(val value: Int) {
override def toString: String = value.toString
}
object LineNumber {
implicit inline def line[T]: LineNumber = ~impl2('[T])
def impl2[T](x: Type[T]): Expr[LineNumber] = {
val pos = {
val (tree, ctx) = x.toTasty
tree.pos(ctx)
}
'(new LineNumber(~pos.startLine.toExpr))
}
}
Note that now the context is needed. The important part is that the quoted type has the position we need.
def foo(implicit line: LineNumber): Unit = {
println("foo " + line)
}
foo(line)
foo
a7f7502
to
603d753
Compare
780c2e1
to
1def5a9
Compare
@odersky this PR is ready for review |
@OlivierBlanvillain this is the PR for tasty reflection |
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.
LGTM
* Define TASTY data types in scala.tasty * Add method get a TASTY term from a quoted.Expr[T] * Implement TASTY tree extractors
* Remove type vars from tasty types * Fix impure by name arguments to macros
161ec94
to
6f52db5
Compare
Rebased |
Uh oh!
There was an error while loading. Please reload this page.