Skip to content

Generalize function symbol synthesis logic #2398

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

Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 8, 2017

We will need other synthesized symbols down the road (e.g.
function types in phantom universes). With this commit one
can provide for that by installing a synthesizer in a
scope.

We will need other synthesized symbols down the road (e.g.
function types in phantom universes). With this commit one
can provide for that by installing a synthesizer in a
scope.
@odersky odersky requested a review from nicolasstucki May 8, 2017 17:16
lazy val ScalaPackageClass = {
val cls = ScalaPackageVal.moduleClass.asClass
cls.info.decls.openForMutations.useSynthesizer(
name => ctx =>
Copy link
Member

Choose a reason for hiding this comment

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

Where is the ctx parameter used here?

Copy link
Contributor

Choose a reason for hiding this comment

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

This might be needed for other synthetic functions like the functions that take phantom parameters.

@@ -204,6 +210,12 @@ object Scopes {
*/
private var elemsCache: List[Symbol] = null

/** The synthesizer to be used, or `null` if no synthesis is done on this scope */
private var synthesize: SymbolSynthesizer = null
Copy link
Member

Choose a reason for hiding this comment

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

Note that with both scalac and doty, not using private[this] here will generate a pair of getter and setter, this is arguably something that we should fix in the compiler since private[this] and private should be considered equivalent in an object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave it like this. Do we have an issue for this?

* the given name in the given context. Returns `NoSymbol` if the
* no symbol should be synthesized for the given name.
*/
type SymbolSynthesizer = Name => Context => Symbol
Copy link
Member

Choose a reason for hiding this comment

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

For efficiency, I would consider using (Name, Context) => Symbol instead, but that might be a premature optimization.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would assume that with our current simple use cases the JVM must be capable of inlineing the this additional lambda. Seem a bit premature optimization.

@nicolasstucki
Copy link
Contributor

LGTM

@odersky odersky merged commit 058658d into scala:master May 11, 2017
@allanrenucci allanrenucci deleted the change-generalize-name-synthesis branch December 14, 2017 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants