Skip to content

macro regression in 2.12.5 when compiling on Java 9 or 10 ("macro implementation not found") #480

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

Closed
SethTisue opened this issue Mar 20, 2018 · 15 comments
Assignees
Milestone

Comments

@SethTisue
Copy link
Member

SethTisue commented Mar 20, 2018

EDIT: Adding bug description here at the top now that we know more about it, and since lots of people are hitting this:

====

original report follows:

on Java 9 https://gist.github.com/SethTisue/0681f6aa70662ecde47a4a842ed13fb6 gives

[info] Compiling 1 Scala source to /Users/tisue/tmp/20180320/target/scala-2.12/classes ...
[error] /Users/tisue/tmp/20180320/S.scala:5:4: macro implementation not found: macroTransform
[error] (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
[error]   @newtype case class WidgetId(toInt: Int)
[error]    ^

reported on Gitter by @CremboC

@SethTisue
Copy link
Member Author

another, perhaps related report on Gitter from @plokhotnyuk

compiling https://github.com/Sizmek/fast-string-interpolator on 2.12.5 and Java 9 gives

[error] /Users/tisue/fast-string-interpolator/benchmark/src/main/scala/com/sizmek/fsi/benchmark/StringConcatenationBenchmark.scala:41:5: macro implementation not found: fast
[error] (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
[error]     fast"${int}xxx${long}xxx${float}xxx${double}xxx${char}xxx${boolean}xxx$string".toString
[error]     ^

@lrytz
Copy link
Member

lrytz commented Mar 20, 2018

I was going to say it's most likely the macro/plugin classloader change (scala/scala#6314 / scala/scala#6400 / scala/scala#6412), but looking at the diffs, the code path with the cache disabled (whch ist the default) seems to be identical.

@hrhino
Copy link

hrhino commented Mar 20, 2018

It's because the classpath that it's looking at uses jrt:// urls. AbstractFile.getUrl returns null on those.

The salient line is in Macros#findMacroClassLoader:

val locations = classpath.map(u => Path(AbstractFile.getURL(u).file))

@lrytz
Copy link
Member

lrytz commented Mar 20, 2018

But it seems to me locations is only used if the cache is enabled, which is not the case by default?

@hrhino
Copy link

hrhino commented Mar 20, 2018

It's only used in that case, but it's computed always.

The cheap fix is probably to make it lazy.

The slightly more generous fix is to intermediately map only AbstractFile.getURL(u) and disable caching if any are null. Maybe with a kind explanation of why we don't have these specific nice things yet.

@lrytz
Copy link
Member

lrytz commented Mar 20, 2018

Ah, then .file throws an NPE, which is then caught by the macro engine. Thanks..

@SethTisue SethTisue changed the title macro regression in 2.12.5 on Java 9? macro regression in 2.12.5 on Java 9 Mar 20, 2018
@jvican jvican self-assigned this Mar 20, 2018
@jvican
Copy link
Member

jvican commented Mar 20, 2018

I have a fix on the way, thanks Harrison for the preliminary investigation. I'm not going to fix the fact that AbstractFile.getURL returns null for URLs starting with jrt. I'll leave that as a future improvement of Java 9 support in scalac.

jvican added a commit to scalacenter/scala that referenced this issue Mar 20, 2018
Fixes scala/scala-dev#480.

It reports whenever `AbstractFile.getUrl` returns `null` if verbose is
enabled.
@yanns
Copy link

yanns commented Mar 20, 2018

The same with https://github.com/lightbend/scala-logging:

[error] <...>: macro implementation not found: debug
[error] (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
[error]           logger.debug(s"Fetched ${results.count} on $uri. Stop = $stop")
[error]                       ^

@SethTisue
Copy link
Member Author

The same with https://github.com/lightbend/scala-logging

yeah, I think we can expect any macro to be affected.

@dragos
Copy link

dragos commented Mar 21, 2018

Stepped on this as well using scalatest, @dotta can provide more info. getURL returns null on paths starting with file:// as well, it seems.. (on Java 8)

@dotta
Copy link

dotta commented Mar 22, 2018

Stepped on this as well using scalatest, @dotta can provide more info. getURL returns null on paths starting with file:// as well, it seems.. (on Java 8)

Indeed. I don't have a reproducible, but if you manage to have a non-existing directory as part of the computed classpath, then AbstractFile.getURL(badDir) will return null.

@SethTisue SethTisue changed the title macro regression in 2.12.5 on Java 9 macro regression in 2.12.5 when compiling on Java 9 ("macro implementation not found") Mar 23, 2018
retronym pushed a commit to scalacenter/scala that referenced this issue Mar 23, 2018
Fixes scala/scala-dev#480.

It reports whenever `AbstractFile.getUrl` returns `null` if verbose is
enabled.
@retronym retronym added this to the 2.12.6 milestone Mar 23, 2018
@SethTisue SethTisue changed the title macro regression in 2.12.5 when compiling on Java 9 ("macro implementation not found") macro regression in 2.12.5 when compiling on Java 9 or 10 ("macro implementation not found") Mar 23, 2018
@huntc
Copy link

huntc commented Mar 29, 2018

Just adding that I stumbled upon this problem with utest.

@monksy
Copy link

monksy commented Apr 16, 2018

This is causing Scala test to fail

t.scala:183: error: value should is not a member of Int
[ERROR]       actual should be(expected)

rgladwell added a commit to rgladwell/microtesia that referenced this issue Apr 16, 2018
Fixed tests for Scala 2.12.X. This included:

 * Removing mocking from the tests
 * Refreshing dependencies
 * Removing support for Scala 2.10.X

Note, this release also ensures we run with Java 8 due to the
following issue with macros:

scala/scala-dev#480
retronym pushed a commit to retronym/scala that referenced this issue May 30, 2018
Fixes scala/scala-dev#480.

It reports whenever `AbstractFile.getUrl` returns `null` if verbose is
enabled.
retronym pushed a commit to retronym/scala that referenced this issue May 30, 2018
Fixes scala/scala-dev#480.

It reports whenever `AbstractFile.getUrl` returns `null` if verbose is
enabled.

[cherry-picked from 957780f after this was accidentally discarding
in scala#6575]
@unoexperto
Copy link

unoexperto commented Jul 29, 2018

It still happens for me in 2.12.6 when compiling in IntelliJ IDEA (sbt 1.1.6) with circe json library. It compiles from commandline sbt compile though.

@SethTisue
Copy link
Member Author

@unoexperto whatever problem you're having, I very much doubt it can have anything to do with this ticket besides happening to share an error message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests