-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,12 @@ object Scopes { | |
*/ | ||
private final val MaxRecursions = 1000 | ||
|
||
/** A function that optionally produces synthesized symbols with | ||
* 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For efficiency, I would consider using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
class ScopeEntry private[Scopes] (val name: Name, _sym: Symbol, val owner: Scope) { | ||
|
||
var sym: Symbol = _sym | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that with both scalac and doty, not using There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
/** Use specified synthesize for this scope */ | ||
def useSynthesizer(s: SymbolSynthesizer): Unit = synthesize = s | ||
|
||
protected def newScopeLikeThis() = new MutableScope() | ||
|
||
/** Clone scope, taking care not to force the denotations of any symbols in the scope. | ||
|
@@ -220,6 +232,7 @@ object Scopes { | |
val e = entries(i) | ||
scope.newScopeEntry(e.name, e.sym) | ||
} | ||
scope.synthesize = synthesize | ||
scope | ||
} | ||
|
||
|
@@ -350,7 +363,11 @@ object Scopes { | |
e = e.prev | ||
} | ||
} | ||
e | ||
if ((e eq null) && (synthesize != null)) { | ||
val sym = synthesize(name)(ctx) | ||
if (sym.exists) newScopeEntry(sym) else e | ||
} | ||
else e | ||
} | ||
|
||
/** lookup next entry with same name as this one */ | ||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.