scalamacros / paradise

(No longer actively maintained.)
http://scalamacros.org/
BSD 3-Clause "New" or "Revised" License
158 stars 53 forks source link

make macro annotation contract explicit #60

Closed Andrei-Pozolotin closed 9 years ago

Andrei-Pozolotin commented 9 years ago

it is not clear why using "magic name" macroTransform is the way to go: https://github.com/scalamacros/paradise/blob/2.11.5/plugin/src/main/scala/org/scalamacros/paradise/reflect/StdNames.scala#L10

would it be better ("type-safe"? :-)) to have explicit macro annotation contract instead:

abstract class MacroAnnotation extends scala.annotation.Annotation {
   def macroTransform = ???
}
xeno-by commented 9 years ago

It would be nice, indeed, but then all macro annotation developers would have to import that MacroAnnotation from somewhere. That somewhere would probably be a library accompanying the macro paradise plugin.

While having a companion library is not impossible (in fact, that's what we do to support quasiquotes in paradise 2.10), it creates extra hassle for the users, so we have to weigh that against the benefits that we're receiving. In my opinion, the extra bit of type safety isn't worth it. Wdyt?

Andrei-Pozolotin commented 9 years ago

I see your point. But from my macro newbie experience, I was not clear from your docs http://docs.scala-lang.org/overviews/macros/annotations.html that "macroTransform" is a magic name, and was a source of confusion for me.

Andrei-Pozolotin commented 9 years ago

Can you make this annotation part of standard scala.reflect.runtime name space?

xeno-by commented 9 years ago

@Andrei-Pozolotin I've updated the docs: https://github.com/scala/scala.github.com/pull/403. Do you find the wording reasonable?

xeno-by commented 9 years ago

As for scala.reflect.runtime, I think that Typesafe Scala team will be not very enthusiastic about putting something that's only useful for a non-standard compiler plugin into standard distribution. Also, there are binary compatibility constraints which mean that the earliest we can do that is Scala 2.12.0.

Andrei-Pozolotin commented 9 years ago

1) re: https://github.com/scala/scala.github.com/pull/403 yes, that clarifies it, thank you.

2) what about the other "magic name" annottees; have not run into that yet, but https://github.com/scalamacros/paradise/blob/2.11.5/plugin/src/main/scala/org/scalamacros/paradise/reflect/StdNames.scala#L9

xeno-by commented 9 years ago

2) Wow, looks like it's also hardcoded, but I completely forgot about this. Luckily, macro paradise will let you know if the signature is wrong.

Andrei-Pozolotin commented 9 years ago

oh, great. :-) probably could mention in the docs if you are still in the mood. feel free to close this, thank you.