Skip to content
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

Abusively eager loading of quasiquotes in Scala 2.11's typer #8392

Closed
scabug opened this issue Mar 11, 2014 · 3 comments
Closed

Abusively eager loading of quasiquotes in Scala 2.11's typer #8392

scabug opened this issue Mar 11, 2014 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Mar 11, 2014

The eager hardwiring of macro-processing in Analyzer makes an early call to Quasiquotes (in FastTrack), more specifically making a 2.11 scala-reflect.jar mandatory on the classpath of a 2.11 typer run which requires scala-reflect.jar.

To be more clear, you can run without scala-reflect on classpath, but if it's there, it needs to be the version that includes quasiquotes, i.e. 2.11.

However, It would be enjoyable to run typer with a 2.10 scala-reflect.jar on classpath (specifically for typing 2.10 projects, possibly referring to scala.reflect, with a 2.11 compiler using the -Xsource flag).

Perhaps the FastTrack optimization should be optional (depending on whether Quasiquotes are available), but more importantly, testing for the availability of the Quasiquotes Class in scala.reflect.Definitions should be more subtle than just testing if the reflection APi is there:

    lazy val QuasiquoteClass = if (ApiUniverseClass != NoSymbol) getMember(ApiUniverseClass, tpnme.Quasiquote) else NoSymbol

This throws a scala.reflect.internal.FatalError: class Universe does not have a member Quasiquote on any run that does not include the right scala-reflect.jar on classpath, despite those runs making sense.

A stopgap fix would be to add a test for the Xsource setting (>= 2.11) in the condition above. But it would be better, I think, to have the non-throwing version of getMember there, that returns NoSymbol if the quasiquotes member is not defined. I have fixes for both options ready to be pull-requested, just chime in with your vote.

The formal reproduction details follow:

Steps to reproduce :

.<path-to-2.11>/bin/scalac -nobootcp -Dscala.usejavacp=false -Xsource:2.10 -Ystop-after:typer -Ylog-classpath -classpath <path-to-2.10>/scala-library.jar:<path-to-2.10>/scala-reflect.jar ./src/play-ws/src/main/scala/play/api/libs/oauth/package.scala
  • Notice the following stack trace
error: scala.reflect.internal.FatalError: class Universe does not have a member Quasiquote
	at scala.reflect.internal.Definitions$DefinitionsClass.scala$reflect$internal$Definitions$DefinitionsClass$$fatalMissingSymbol(Definitions.scala:1163)
	at scala.reflect.internal.Definitions$DefinitionsClass.getMember(Definitions.scala:1180)
	at scala.reflect.internal.Definitions$DefinitionsClass.QuasiquoteClass$lzycompute(Definitions.scala:504)
	at scala.reflect.internal.Definitions$DefinitionsClass.QuasiquoteClass(Definitions.scala:504)
	at scala.reflect.internal.Definitions$DefinitionsClass.QuasiquoteClass_api$lzycompute(Definitions.scala:505)
	at scala.reflect.internal.Definitions$DefinitionsClass.QuasiquoteClass_api(Definitions.scala:505)
	at scala.reflect.internal.Definitions$DefinitionsClass.QuasiquoteClass_api_apply$lzycompute(Definitions.scala:506)
	at scala.reflect.internal.Definitions$DefinitionsClass.QuasiquoteClass_api_apply(Definitions.scala:506)
	at scala.tools.reflect.FastTrack$$anonfun$1.apply(FastTrack.scala:53)
	at scala.tools.reflect.FastTrack$$anonfun$1.apply(FastTrack.scala:43)
	at scala.reflect.internal.SymbolTable$perRunCaches$$anonfun$newGeneric$1.apply(SymbolTable.scala:386)
	at scala.tools.reflect.FastTrack$class.fastTrack(FastTrack.scala:42)
	at scala.tools.nsc.Global$$anon$1.fastTrack(Global.scala:458)
	at scala.tools.nsc.typechecker.Namers$Namer.methodSig(Namers.scala:1188)
	at scala.tools.nsc.typechecker.Namers$Namer.getSig$1(Namers.scala:1525)
	at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1537)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply$mcV$sp(Namers.scala:781)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:780)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:780)
	at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$logAndValidate(Namers.scala:1564)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:780)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:772)
	at scala.tools.nsc.typechecker.Namers$$anon$1.completeImpl(Namers.scala:1679)
	at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter$class.complete(Namers.scala:1687)
	at scala.tools.nsc.typechecker.Namers$$anon$1.complete(Namers.scala:1677)
	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1429)
	at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1576)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4918)
  • Notice the contents of ./src/play-ws/src/main/scala/play/api/libs/oauth/package.scala, namely
package play.api.libs

package object oauth
  • run the scalac command line above, this time removing scala-reflect.jar from classpath. This time everything runs fine.
@scabug
Copy link
Author

scabug commented Mar 11, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8392?orig=1
Reporter: @huitseeker
Affected Versions: 2.11.0-RC1

@scabug
Copy link
Author

scabug commented Mar 11, 2014

@gkossakowski said:
I'd vote for changing:

lazy val QuasiquoteClass             = if (ApiUniverseClass != NoSymbol) getMember(ApiUniverseClass, tpnme.Quasiquote) else NoSymbol

to

lazy val QuasiquoteClass             = if (ApiUniverseClass != NoSymbol) getMemberIfDefined(ApiUniverseClass, tpnme.Quasiquote) else NoSymbol

@scabug
Copy link
Author

scabug commented Mar 11, 2014

@huitseeker said:
scala/scala#3619

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

No branches or pull requests

2 participants