Skip to content

Commit 662b7e0

Browse files
smarterbishabosha
authored andcommitted
Change extension method naming scheme to match 2.13
See scala/scala#7896 and follow-up scala/scala#7922, we can do both steps at once since we always run with a bootstrapped dotty-library on the classpath, even if the compiler itself is not bootstrapped.
1 parent a6efeb6 commit 662b7e0

File tree

1 file changed

+7
-41
lines changed

1 file changed

+7
-41
lines changed

compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
131131
else NoSymbol
132132

133133
private def createExtensionMethod(imeth: Symbol, staticClass: Symbol)(implicit ctx: Context): TermSymbol = {
134-
val extensionName = extensionNames(imeth).head.toTermName
135-
val extensionMeth = ctx.newSymbol(staticClass, extensionName,
134+
val extensionMeth = ctx.newSymbol(staticClass, extensionName(imeth),
136135
(imeth.flags | Final) &~ (Override | Protected | AbsOverride),
137136
fullyParameterizedType(imeth.info, imeth.owner.asClass),
138137
privateWithin = imeth.privateWithin, coord = imeth.coord)
@@ -180,48 +179,17 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
180179
object ExtensionMethods {
181180
val name: String = "extmethods"
182181

183-
/** Generate stream of possible names for the extension version of given instance method `imeth`.
184-
* If the method is not overloaded, this stream consists of just "imeth$extension".
185-
* If the method is overloaded, the stream has as first element "imeth$extenionX", where X is the
186-
* index of imeth in the sequence of overloaded alternatives with the same name. This choice will
187-
* always be picked as the name of the generated extension method.
188-
* After this first choice, all other possible indices in the range of 0 until the number
189-
* of overloaded alternatives are returned. The secondary choices are used to find a matching method
190-
* in `extensionMethod` if the first name has the wrong type. We thereby gain a level of insensitivity
191-
* of how overloaded types are ordered between phases and picklings.
192-
*/
193-
private def extensionNames(imeth: Symbol)(implicit ctx: Context): Stream[Name] = {
194-
val decl = imeth.owner.info.decl(imeth.name)
195-
196-
/** No longer needed for Dotty, as we are more disciplined with scopes now.
197-
// Bridge generation is done at phase `erasure`, but new scopes are only generated
198-
// for the phase after that. So bridges are visible in earlier phases.
199-
//
200-
// `info.member(imeth.name)` filters these out, but we need to use `decl`
201-
// to restrict ourselves to members defined in the current class, so we
202-
// must do the filtering here.
203-
val declTypeNoBridge = decl.filter(sym => !sym.isBridge).tpe
204-
*/
205-
decl match {
206-
case decl: MultiDenotation =>
207-
val alts = decl.alternatives
208-
val index = alts indexOf imeth.denot
209-
assert(index >= 0, alts + " does not contain " + imeth)
210-
def altName(index: Int) = UniqueExtMethName(imeth.name.asTermName, index)
211-
altName(index) #:: ((0 until alts.length).toStream filter (index != _) map altName)
212-
case decl =>
213-
assert(decl.exists, imeth.name + " not found in " + imeth.owner + "'s decls: " + imeth.owner.info.decls)
214-
Stream(ExtMethName(imeth.name.asTermName))
215-
}
216-
}
182+
/** Name of the extension method that corresponds to given instance method `meth`. */
183+
def extensionName(imeth: Symbol)(implicit ctx: Context): TermName =
184+
ExtMethName(imeth.name.asTermName)
217185

218186
/** Return the extension method that corresponds to given instance method `meth`. */
219187
def extensionMethod(imeth: Symbol)(implicit ctx: Context): TermSymbol =
220188
ctx.atPhase(ctx.extensionMethodsPhase.next) {
221189
// FIXME use toStatic instead?
222190
val companion = imeth.owner.companionModule
223191
val companionInfo = companion.info
224-
val candidates = extensionNames(imeth) map (companionInfo.decl(_).symbol) filter (_.exists)
192+
val candidates = companionInfo.decl(extensionName(imeth)).alternatives
225193
val matching = candidates filter (c => FullParameterization.memberSignature(c.info) == imeth.signature)
226194
assert(matching.nonEmpty,
227195
i"""no extension method found for:
@@ -234,9 +202,7 @@ object ExtensionMethods {
234202
|
235203
| Candidates (signatures normalized):
236204
|
237-
| ${candidates.map(c => c.name + ":" + c.info.signature + ":" + FullParameterization.memberSignature(c.info)).mkString("\n")}
238-
|
239-
| Eligible Names: ${extensionNames(imeth).mkString(",")}""")
240-
matching.head.asTerm
205+
| ${candidates.map(c => c.name + ":" + c.info.signature + ":" + FullParameterization.memberSignature(c.info)).mkString("\n")}""")
206+
matching.head.symbol.asTerm
241207
}
242208
}

0 commit comments

Comments
 (0)