-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Don't propagate imports into inlined code #16160
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
Imports are supposed to be resolved already, so they need not and should not be copied into inlined code. Fixes scala#16156, unfortuntely in the sense that it will not work.
This is not quite baked yet. There are several questions
@nicolasstucki WDYT? |
... except for language imports. It looks this does not change the underlying issue but it's good housekeeping anyway. The problem is that imports would not be transformed in a phase like ExplicitOuter since Import is not by default handled in MegaPhase's transform. As long as no-one checks this might not matter, but it's still weird. So better to get rid of them before.
Whatever you do, please, please don't make object StaticContext:
inline def summonMyEncoder[T]: String =
${ SummonEncoder.impl[T] }
implicit val encoderInstance: MyEncoder[String] =
new MyEncoder[String] { def encode = "blah" }
end StaticContext ...and then this: import StaticContext._ // Imports the `encoderInstance`
class Repo[T]:
inline def summonEncoder = {
summonMyEncoder[T]
}
object Use:
val repo = new Repo[String]
val v = repo.summonEncoder ...and then it will import the Also, if you define trait TraitContext:
inline def summonMyEncoder[T]: String =
${ SummonEncoder.impl[T] }
implicit val encoderInstance: MyEncoder[String] =
new MyEncoder[String] { def encode = "blah" }
end TraitContex ...and then this: class Repo[T] extends TraitContext:
inline def summonEncoder = {
summonMyEncoder[T]
}
object Use:
val repo = new Repo[String]
import repo._ // Imports the `encoderInstance`
val v = repo.summonEncoder Right now, every single Quill context uses this latter pattern. Quill couldn't possibly work without it. If |
@deusaquilus @nicolasstucki As far as I can see these are two different situations. One is where the inlined method sees an import in its outer scope. That will of course continue to work. All the examples you gave seem to fall in this category. The other is where an import is part of an inlined method body. Here I had thought that the import would have been resolved at typer and therefore would be redundant for inlining, so it could be removed. But I am not sure. In particular:
|
We rely a lot on inline imports in Kittens 3 and so far it worked without issues: |
This could influence inline summoning (such as |
While performing inline summoning, we do take into account local inline def f: Int = {
given Int = 10
compiletime.summonInline[Int]
}
def test = f In theory, to be consistent, we would need to keep local imports. But if the import is local, then we should be able to use the normal |
Looks like there are lots of reasons why this won't work. |
Footnote: I was recently looking at this PR because of |
Imports are supposed to be resolved already, so they need not and should not be copied into inlined code.
Fixes #16156, unfortuntely in the sense that it will not work.