From 6e4c926b4a4c5e8dd350ae3a150490a794b139ca Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 17 Dec 2013 10:36:26 +0100 Subject: Use macro expandee, rather than expansion, in pres. compiler The presentation compiler is primarily interested in trees that represent the code that one sees in the IDE, not the expansion of macros. This commit continues to expand macros, but adds a hook in which the presentation compiler discards the expansion, retaining instead the expandee. The expandee is attributed with the type of the expansion, which allows white box macros to work. In addition, any domain specific errors and warnings issued by the macro will still be reported, as a side-effect of the expansion. The failing test from the last commit now correctly resolves hyperlinks in macro arguments. Related IDE ticket: https://www.assembla.com/spaces/scala-ide/tickets/1001449# This facility is configured as follows: // expand macros as per normal -Ymacro-expand:normal // don't expand the macro, takes the place of -Ymacro-no-expand -Ymacro-expand:none // expand macros to compute type and emit warnings, // but retain expandee. Set automatically be the presentation // compiler -Ymacro-expand:discard This leaves to door ajar for a new option: // Don't expand blackbox macros; expand whitebox // but retain expandee -Ymacro-expand:discard-whitebox-only The existing test for SI-6812 has been duplicated. One copy exercises the now-deprecated -Ymacro-no-expand, and the other uses the new option. --- test/files/presentation/hyperlinks-macro.check | 4 ++-- .../hyperlinks-macro/src/MacroCall.scala | 1 - test/scaladoc/run/SI-6812.check | 1 + test/scaladoc/run/SI-6812.scala | 2 +- test/scaladoc/run/SI-6812b.check | 1 + test/scaladoc/run/SI-6812b.scala | 24 ++++++++++++++++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/scaladoc/run/SI-6812b.check create mode 100644 test/scaladoc/run/SI-6812b.scala (limited to 'test') diff --git a/test/files/presentation/hyperlinks-macro.check b/test/files/presentation/hyperlinks-macro.check index 39e66d1eca..80d2268fa1 100644 --- a/test/files/presentation/hyperlinks-macro.check +++ b/test/files/presentation/hyperlinks-macro.check @@ -1,8 +1,8 @@ reload: MacroCall.scala -askHyperlinkPos for `` at (5,7) MacroCall.scala +askHyperlinkPos for `foo` at (5,7) MacroCall.scala ================================================================================ -[response] found askHyperlinkPos for `` at (1,13) MacroCall.scala +[response] found askHyperlinkPos for `foo` at (2,7) MacroCall.scala ================================================================================ askHyperlinkPos for `foo` at (9,7) MacroCall.scala diff --git a/test/files/presentation/hyperlinks-macro/src/MacroCall.scala b/test/files/presentation/hyperlinks-macro/src/MacroCall.scala index 42685735b2..d9676b3d2a 100644 --- a/test/files/presentation/hyperlinks-macro/src/MacroCall.scala +++ b/test/files/presentation/hyperlinks-macro/src/MacroCall.scala @@ -9,4 +9,3 @@ object Test { foo/*#*/ } } -// Currently, the hyperlink within the argument to the macro `reify` does not resolve correctly. diff --git a/test/scaladoc/run/SI-6812.check b/test/scaladoc/run/SI-6812.check index 619c56180b..3be8a300e7 100644 --- a/test/scaladoc/run/SI-6812.check +++ b/test/scaladoc/run/SI-6812.check @@ -1 +1,2 @@ +warning: -Ymacro-no-expand is deprecated: Use -Ymacro-expand:none Done. diff --git a/test/scaladoc/run/SI-6812.scala b/test/scaladoc/run/SI-6812.scala index 059c327e7e..6893e816d0 100644 --- a/test/scaladoc/run/SI-6812.scala +++ b/test/scaladoc/run/SI-6812.scala @@ -19,6 +19,6 @@ object Test extends ScaladocModelTest { """ def scaladocSettings = "" - override def extraSettings = super.extraSettings + " -Ymacro-no-expand" + override def extraSettings = super.extraSettings + " -Ymacro-no-expand -deprecation" def testModel(root: Package) = () } diff --git a/test/scaladoc/run/SI-6812b.check b/test/scaladoc/run/SI-6812b.check new file mode 100644 index 0000000000..619c56180b --- /dev/null +++ b/test/scaladoc/run/SI-6812b.check @@ -0,0 +1 @@ +Done. diff --git a/test/scaladoc/run/SI-6812b.scala b/test/scaladoc/run/SI-6812b.scala new file mode 100644 index 0000000000..b8a8140357 --- /dev/null +++ b/test/scaladoc/run/SI-6812b.scala @@ -0,0 +1,24 @@ +import scala.tools.nsc.doc.model._ +import scala.tools.partest.ScaladocModelTest +import language._ + +object Test extends ScaladocModelTest { + + override def code = """ + import scala.reflect.macros.BlackboxContext + import language.experimental.macros + + object Macros { + def impl(c: BlackboxContext) = c.literalUnit + def foo: Unit = macro impl + } + + class C { + def bar = Macros.foo + } + """ + + def scaladocSettings = "" + override def extraSettings = super.extraSettings + " -Ymacro-expand:none" + def testModel(root: Package) = () +} -- cgit v1.2.3