Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Improved custom builder lookup (solves #6) #7

Merged

Conversation

mkubala
Copy link
Contributor

@mkubala mkubala commented Sep 27, 2014

This implementation uses auxilary macro.

@mkubala mkubala force-pushed the feature/moreElegantBuilderLookup branch from fd5fcf5 to 6f99f7b Compare September 27, 2014 12:55
case foundBuilderTree => foundBuilderTree
}

c.Expr[MemoCacheBuilder](Block(List(), builderTree))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it seems that putting an auxiliary macro call inside a quasiquote makes c.inferImplicitValue() work well, where calling this from an annotation macro context doesn't work in all cases? That's really meta-meta :) But it looks kinda like a bug to me, or at least some weird incosistency I cannot understand...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to do some investigation about this behaviour.
My Current clues:

  • I can't use auxilary macro directly, I need to weave a call to it in expanded code, because both macros live in the same compilation unit.
  • annotation macro can't infer implicits vals from enclosing class scope (implicit val members), but we are able to traverse them manually. This means that problem does not lie in lack of enclosure members visibility. Maybe this behaviour is intended? From @ macros we not only can add new members but even whole companion objects. But then c.inferImplicitVal should not lookup any implicits, for the same reasons..
  • based on previous clue - maybe compiler collect informations about implicits and scopes incrementally, during some typechecks or something like that? And static annotation expansions is done before phase in which compiler scan implicit vals within enclosure?

Edit:
AFAIK def macros are an (experimental) part of scala compiler, while annotation macros are still available via macroparadise plugin. Maybe this is the reason?

@xeno-by could you elaborate on this?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kciesielski The issue with c.typecheck (and c.inferImplicitValue that's essentially based on c.typecheck) in macro annotations is a yet unsolved problem in the design of macro annotations. That's indeed a bug.

@mkubala Your high-level hypothesis about the reason for this limitation is spot-on (if you're interested in details, scalamacros/paradise#14 provides a lot of information on the nature of the issue).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explanation 👍

kciesielski added a commit that referenced this pull request Sep 30, 2014
@kciesielski kciesielski merged commit ebe144d into kciesielski:master Sep 30, 2014
@mkubala mkubala deleted the feature/moreElegantBuilderLookup branch November 30, 2014 17:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants