-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Move unsafe operations from Expr to UnsafeExpr #8041
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
Move unsafe operations from Expr to UnsafeExpr #8041
Conversation
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.
From my experience with ScalaTest, usage of underlyingArgument
is pretty common. I don't see how moving it to another package can help meta-programmers.
It is common to use the reflect API variant of this method, we have it all over. But this is the Expr based basEd version which has never been used in any code so far. It is important to make explicit the fact that this is the only method in the Expr API that can change normal call semantics. This implies that macro that only uses Expr guarantees that call semantics are preserved the same way |
If it's not used, maybe we can remove them? Meta-programming is inherently dangerous and difficult, singling out this API and putting it in an unsafe package doesn't sound like a good idea. The safety warning can be reflected in the doc of the method. For example, |
These operations may be phased out into a library later. For now it is good to keep them around to see what legitimate use cases they support. But they should not be visible out of the box to any new user. |
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.
As discussed with @nicolasstucki , the eventual goal is to remove them, this is just an intermediate step.
Make it explicit that this operation may change the call semantics.
762f361
to
9185dc4
Compare
@nicolasstucki It looks like |
There where several issues with the version of inline def f(i: Int): Int = ${impl}
private def impl(i: Expr[Int]): Expr[Int] = '{
${Expr. underlyingArgument(i)}
${Expr. underlyingArgument(i)}
} var x = 0
def next: Int = {
x += 1
x
}
f(next) // would return 2
f(next) // would return 4 In general it is unsafe to use the result Furthermore, breaking this guaranties has also shown to cause compiler crashes. Originally Nevertheless, if it is for simple inspection there are some ways to provide a sound version of |
@nicolasstucki Interesting! My use-case for Quill is to parse the inlined tree and use it to generate SQL, not use it directly. There are situations where we splice parts of the tree back in but they are clearly delimited with a What approach would you recommend? Is using |
It is ok to use it and it will not disappear. Be careful if you extract any expression that defines a symbol. |
No description provided.