Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9468b9a

Browse files
authored
Merge pull request#9630 from SethTisue/unseal-substmap
2 parentscefcd53 +35a9354 commit9468b9a

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

‎src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,10 +1439,11 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
14391439
to:List[Symbol],
14401440
targetClass:Symbol,
14411441
addressFields:Boolean)extendsTreeSymSubstituter(from, to) {
1442-
privatedefmatcher(sym1:Symbol,sym2:Symbol)=
1443-
if (sym2.isTypeSkolem) sym2.deSkolemize eq sym1
1444-
else sym1 eq sym2
1445-
overridevalsymSubst=SubstSymMap(from, to, matcher)
1442+
overridevalsymSubst=newSubstSymMap(from, to) {
1443+
overridedefmatches(sym1:Symbol,sym2:Symbol)=
1444+
if (sym2.isTypeSkolem) sym2.deSkolemize eq sym1
1445+
else sym1 eq sym2
1446+
}
14461447

14471448
privatedefisAccessible(sym:Symbol):Boolean=
14481449
if (currentOwner.isAnonymousFunction) {

‎src/reflect/scala/reflect/internal/Symbols.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3766,7 +3766,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
37663766
else {
37673767
valsyms1= mapList(syms)(_.cloneSymbol)
37683768
cloneSymbolsSubstSymMap.using { (msm:SubstSymMap)=>
3769-
msm.reload(syms, syms1)
3769+
msm.reset(syms, syms1)
37703770
syms1.foreach(_.modifyInfo(msm))
37713771
}
37723772
syms1

‎src/reflect/scala/reflect/internal/Types.scala‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4059,7 +4059,7 @@ trait Types
40594059
valresultThis= result.typeSymbol.thisType
40604060
valsubstThisMap=newSubstThisMap(original.typeSymbol, resultThis)
40614061
copyRefinedTypeSSM.using { (msm:SubstSymMap)=>
4062-
msm.reload(syms1, syms2)
4062+
msm.reset(syms1, syms2)
40634063
syms2.foreach(_.modifyInfo(info=> msm.apply(substThisMap.apply(info))))
40644064
}
40654065
}

‎src/reflect/scala/reflect/internal/tpe/TypeMaps.scala‎

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import Flags._
2020
importscala.annotation.{nowarn,tailrec}
2121
importVariance._
2222
importscala.collection.mutable.ListBuffer
23-
importscala.util.chaining._
2423

2524
private[internal]traitTypeMaps {
2625
self:SymbolTable=>
@@ -665,24 +664,27 @@ private[internal] trait TypeMaps {
665664
}
666665

667666
/** A base class to compute all substitutions.*/
668-
sealedabstractclassSubstMap[T>:Null]extendsTypeMap {
669-
private[this]var_from:List[Symbol]=Nil
670-
private[this]var_to:List[T]=Nil
667+
abstractclassSubstMap[T>:Null](from0:List[Symbol],to0:List[T])extendsTypeMap {
668+
private[this]varfrom:List[Symbol]=from0
669+
private[this]varto:List[T]= to0
671670

672671
private[this]varfromHasTermSymbol=false
673672
private[this]varfromMin=Int.MaxValue
674673
private[this]varfromMax=Int.MinValue
675674
private[this]varfromSize=0
676675

677-
finaldeffrom:List[Symbol]= _from
678-
finaldefto:List[T]= _to
676+
// So SubstTypeMap can expose them publicly
677+
// while SubstMap can continue to access them as private fields
678+
protected[this]finaldefaccessFrom:List[Symbol]= from
679+
protected[this]finaldefaccessTo:List[T]= to
679680

680-
defreload(from0:List[Symbol],to0:List[T]):this.type= {
681+
reset(from0, to0)
682+
defreset(from0:List[Symbol],to0:List[T]):this.type= {
681683
// OPT this check was 2-3% of some profiles, demoted to -Xdev
682684
if (isDeveloper) assert(sameLength(from, to),"Unsound substitution from"+ from+" to"+ to)
683685

684-
_from= from0
685-
_to= to0
686+
from= from0
687+
to= to0
686688

687689
fromHasTermSymbol=false
688690
fromMin=Int.MaxValue
@@ -783,7 +785,11 @@ private[internal] trait TypeMaps {
783785
}
784786

785787
/** A map to implement the `substSym` method.*/
786-
sealedclassSubstSymMapprivate ()extendsSubstMap[Symbol] {
788+
classSubstSymMap(from0:List[Symbol],to0:List[Symbol])extendsSubstMap[Symbol](from0, to0) {
789+
defthis(pairs: (Symbol,Symbol)*)=this(pairs.toList.map(_._1), pairs.toList.map(_._2))
790+
791+
private[this]finaldeffrom:List[Symbol]= accessFrom
792+
private[this]finaldefto:List[Symbol]= accessTo
787793

788794
protecteddeftoType(fromTpe:Type,sym:Symbol)= fromTpematch {
789795
caseTypeRef(pre, _, args)=> copyTypeRef(fromTpe, pre, sym, args)
@@ -845,19 +851,14 @@ private[internal] trait TypeMaps {
845851

846852
objectSubstSymMap {
847853
defapply():SubstSymMap=newSubstSymMap()
848-
defapply(from:List[Symbol],to:List[Symbol]):SubstSymMap=newSubstSymMap().tap(_.reload(from, to))
849-
defapply(from:List[Symbol],to:List[Symbol],cmp: (Symbol,Symbol)=>Boolean):SubstSymMap= {
850-
valssm=newSubstSymMap() {
851-
overrideprotecteddefmatches(sym:Symbol,sym1:Symbol):Boolean= cmp(sym, sym1)
852-
}
853-
ssm.tap(_.reload(from, to))
854-
}
855-
defapply(fromto: (Symbol,Symbol)):SubstSymMap= apply(List(fromto._1),List(fromto._2))
854+
defapply(from:List[Symbol],to:List[Symbol]):SubstSymMap=newSubstSymMap(from, to)
855+
defapply(fromto: (Symbol,Symbol)):SubstSymMap=newSubstSymMap(fromto)
856856
}
857857

858858
/** A map to implement the `subst` method.*/
859-
classSubstTypeMap(from0:List[Symbol],to0:List[Type])extendsSubstMap[Type] {
860-
super.reload(from0, to0)
859+
classSubstTypeMap(from0:List[Symbol],to0:List[Type])extendsSubstMap[Type](from0, to0) {
860+
finaldeffrom:List[Symbol]= accessFrom
861+
finaldefto:List[Type]= accessTo
861862

862863
overrideprotecteddeftoType(fromtp:Type,tp:Type)= tp
863864

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagescala.reflect.internal
2+
3+
importscala.tools.nsc.symtab.SymbolTableForUnitTesting
4+
5+
classSubstMapTest {
6+
objectsymbolTableextendsSymbolTableForUnitTesting
7+
importsymbolTable._
8+
9+
// compile-test for https://github.com/scala/community-build/pull/1413
10+
newSubstMap[String](Nil,Nil) {
11+
protecteddeftoType(fromtp:Type,tp:String)= fromtp
12+
}
13+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp