Skip to content

Commit 5e1a005

Browse files
committed
removes -Xmacro-(.*)-classpath compiler options
These options were meant to be used to bootstrap macros defined in our codebase However we can bootstrap perfectly without any additional effort, because library classpath classloader can delegate to tool classpath classloader to load macro implementations from starr. Since then (for several months) this functionality hasn't proven to be useful, neither anyone on the mailing list or stackoverflow asked questions about it (even despite it was explicitly mentioned in the "cannot load macro impl" error message). Hence I suggest that it is totally unnecessary and should be removed.
1 parent f126f40 commit 5e1a005

File tree

4 files changed

+19
-68
lines changed

4 files changed

+19
-68
lines changed

src/compiler/scala/tools/nsc/settings/ScalaSettings.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ trait ScalaSettings extends AbsScalaSettings
205205

206206
// Feature extensions
207207
val XmacroSettings = MultiStringSetting("-Xmacro-settings", "option", "Custom settings for macros.")
208-
val XmacroPrimaryClasspath = PathSetting("-Xmacro-primary-classpath", "Classpath to load macros implementations from, defaults to compilation classpath (aka \"library classpath\".", "")
209-
val XmacroFallbackClasspath = PathSetting("-Xmacro-fallback-classpath", "Classpath to load macros implementations from if they cannot be loaded from library classpath.", "")
210208

211209
/**
212210
* IDE-specific settings

src/compiler/scala/tools/nsc/typechecker/Macros.scala

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -591,53 +591,34 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
591591
runtimeType
592592
}
593593

594-
/** Primary classloader that is used to resolve and run macro implementations.
595-
* Loads classes from -Xmacro-primary-classpath, or from -cp if the option is not specified.
594+
/** Macro classloader that is used to resolve and run macro implementations.
595+
* Loads classes from from -cp (aka the library classpath).
596596
* Is also capable of detecting REPL and reusing its classloader.
597597
*/
598-
private lazy val primaryClassloader: ClassLoader = {
598+
private lazy val macroClassloader: ClassLoader = {
599599
if (global.forMSIL)
600600
throw new UnsupportedOperationException("Scala reflection not available on this platform")
601601

602-
if (settings.XmacroPrimaryClasspath.value != "") {
603-
macroLogVerbose("primary macro classloader: initializing from -Xmacro-primary-classpath: %s".format(settings.XmacroPrimaryClasspath.value))
604-
val classpath = toURLs(settings.XmacroPrimaryClasspath.value)
605-
ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader)
606-
} else {
607-
macroLogVerbose("primary macro classloader: initializing from -cp: %s".format(global.classPath.asURLs))
608-
val classpath = global.classPath.asURLs
609-
var loader: ClassLoader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader)
610-
611-
// [Eugene] a heuristic to detect the REPL
612-
if (global.settings.exposeEmptyPackage.value) {
613-
macroLogVerbose("primary macro classloader: initializing from a REPL classloader".format(global.classPath.asURLs))
614-
import scala.tools.nsc.interpreter._
615-
val virtualDirectory = global.settings.outputDirs.getSingleOutput.get
616-
loader = new AbstractFileClassLoader(virtualDirectory, loader) {}
617-
}
602+
val classpath = global.classPath.asURLs
603+
macroLogVerbose("macro classloader: initializing from -cp: %s".format(classpath))
604+
val loader = ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader)
618605

606+
// [Eugene] a heuristic to detect the REPL
607+
if (global.settings.exposeEmptyPackage.value) {
608+
macroLogVerbose("macro classloader: initializing from a REPL classloader".format(global.classPath.asURLs))
609+
import scala.tools.nsc.interpreter._
610+
val virtualDirectory = global.settings.outputDirs.getSingleOutput.get
611+
new AbstractFileClassLoader(virtualDirectory, loader) {}
612+
} else {
619613
loader
620614
}
621615
}
622616

623-
/** Fallback classloader that is used to resolve and run macro implementations when `primaryClassloader` fails.
624-
* Loads classes from -Xmacro-fallback-classpath.
625-
*/
626-
private lazy val fallbackClassloader: ClassLoader = {
627-
if (global.forMSIL)
628-
throw new UnsupportedOperationException("Scala reflection not available on this platform")
629-
630-
macroLogVerbose("fallback macro classloader: initializing from -Xmacro-fallback-classpath: %s".format(settings.XmacroFallbackClasspath.value))
631-
val classpath = toURLs(settings.XmacroFallbackClasspath.value)
632-
ScalaClassLoader.fromURLs(classpath, self.getClass.getClassLoader)
633-
}
634-
635617
/** Produces a function that can be used to invoke macro implementation for a given macro definition:
636618
* 1) Looks up macro implementation symbol in this universe.
637-
* 2) Loads its enclosing class from the primary classloader.
638-
* 3) Loads the companion of that enclosing class from the primary classloader.
619+
* 2) Loads its enclosing class from the macro classloader.
620+
* 3) Loads the companion of that enclosing class from the macro classloader.
639621
* 4) Resolves macro implementation within the loaded companion.
640-
* 5) If 2-4 fails, repeats them for the fallback classloader.
641622
*
642623
* @return Some(runtime) if macro implementation can be loaded successfully from either of the mirrors,
643624
* None otherwise.
@@ -742,25 +723,10 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
742723
}
743724
}
744725

745-
val primary = loadMacroImpl(primaryClassloader)
746-
primary match {
747-
case Some((implObj, implMeth)) =>
726+
loadMacroImpl(macroClassloader) map {
727+
case (implObj, implMeth) =>
748728
def runtime(args: List[Any]) = implMeth.invoke(implObj, (args map (_.asInstanceOf[AnyRef])): _*).asInstanceOf[Any]
749-
Some(runtime _)
750-
case None =>
751-
if (settings.XmacroFallbackClasspath.value != "") {
752-
macroLogVerbose("trying to load macro implementation from the fallback mirror: %s".format(settings.XmacroFallbackClasspath.value))
753-
val fallback = loadMacroImpl(fallbackClassloader)
754-
fallback match {
755-
case Some((implObj, implMeth)) =>
756-
def runtime(args: List[Any]) = implMeth.invoke(implObj, (args map (_.asInstanceOf[AnyRef])): _*).asInstanceOf[Any]
757-
Some(runtime _)
758-
case None =>
759-
None
760-
}
761-
} else {
762-
None
763-
}
729+
runtime _
764730
}
765731
}
766732

@@ -1147,9 +1113,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
11471113
val macroDef = expandee.symbol
11481114
def notFound() = {
11491115
typer.context.error(expandee.pos, "macro implementation not found: " + macroDef.name + " " +
1150-
"(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)\n" +
1151-
"if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath " +
1152-
"in the second phase pointing to the output of the first phase")
1116+
"(the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)")
11531117
None
11541118
}
11551119
def fallBackToOverridden(tree: Tree): Option[Tree] = {

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -988,16 +988,6 @@ trait Namers extends MethodSynthesis {
988988
// (either "macro ???" as they used to or just "???" to maximally simplify their compilation)
989989
if (fastTrack contains ddef.symbol) ddef.symbol setFlag MACRO
990990

991-
// macro defs need to be typechecked in advance
992-
// because @macroImpl annotation only gets assigned during typechecking
993-
// otherwise we might find ourselves in the situation when we specified -Xmacro-fallback-classpath
994-
// but macros still don't expand
995-
// that might happen because macro def doesn't have its link a macro impl yet
996-
if (ddef.symbol.isTermMacro) {
997-
val pt = resultPt.substSym(tparamSyms, tparams map (_.symbol))
998-
typer.computeMacroDefType(ddef, pt)
999-
}
1000-
1001991
thisMethodType({
1002992
val rt = (
1003993
if (!tpt.isEmpty) {
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Impls_Macros_Test_1.scala:36: error: macro implementation not found: foo (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
2-
if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath in the second phase pointing to the output of the first phase
32
println(foo(2) + Macros.bar(2) * new Macros().quux(4))
43
^
54
one error found

0 commit comments

Comments
 (0)