Skip to content

Commit 595e15b

Browse files
committed
Properly pickle implicit/erased method types
Previously, the implicit/erased flags were lost. The tag used for METHODtype was changed to make the encoding of the implicit/erased flags more convenient, this requires a major TASTY bump.
1 parent 97dd197 commit 595e15b

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Standard-Section: "ASTs" TopLevelStat*
163163
BYNAMEtype underlying_Type
164164
PARAMtype Length binder_ASTref paramNum_Nat
165165
POLYtype Length result_Type NamesTypes
166-
METHODtype Length result_Type NamesTypes // needed for refinements
166+
methodType(_, _) Length result_Type NamesTypes // needed for refinements
167167
TYPELAMBDAtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
168168
SHAREDtype type_ASTRef
169169
NamesTypes = NameType*
@@ -226,7 +226,7 @@ Standard Section: "Positions" Assoc*
226226
object TastyFormat {
227227

228228
final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
229-
val MajorVersion = 4
229+
val MajorVersion = 5
230230
val MinorVersion = 0
231231

232232
/** Tags used to serialize names */
@@ -392,14 +392,28 @@ object TastyFormat {
392392
final val ANDtpt = 165
393393
final val ORtype = 166
394394
final val ORtpt = 167
395-
final val METHODtype = 168
396-
final val POLYtype = 169
397-
final val TYPELAMBDAtype = 170
398-
final val LAMBDAtpt = 171
399-
final val PARAMtype = 172
400-
final val ANNOTATION = 173
401-
final val TERMREFin = 174
402-
final val TYPEREFin = 175
395+
final val POLYtype = 168
396+
final val TYPELAMBDAtype = 169
397+
final val LAMBDAtpt = 170
398+
final val PARAMtype = 171
399+
final val ANNOTATION = 172
400+
final val TERMREFin = 173
401+
final val TYPEREFin = 174
402+
403+
// In binary: 101100EI
404+
// I = implicit method type
405+
// E = erased method type
406+
final val METHODtype = 176
407+
final val IMPLICITMETHODtype = 177
408+
final val ERASEDMETHODtype = 178
409+
final val ERASEDIMPLICITMETHODtype = 179
410+
411+
def methodType(isImplicit: Boolean = false, isErased: Boolean = false) = {
412+
val implicitOffset = if (isImplicit) 1 else 0
413+
val erasedOffset = if (isErased) 2 else 0
414+
METHODtype + implicitOffset + erasedOffset
415+
}
416+
403417
final val HOLE = 255
404418

405419
final val firstSimpleTreeTag = UNITconst
@@ -588,6 +602,9 @@ object TastyFormat {
588602
case BYNAMEtpt => "BYNAMEtpt"
589603
case POLYtype => "POLYtype"
590604
case METHODtype => "METHODtype"
605+
case IMPLICITMETHODtype => "IMPLICITMETHODtype"
606+
case ERASEDMETHODtype => "ERASEDMETHODtype"
607+
case ERASEDIMPLICITMETHODtype => "ERASEDIMPLICITMETHODtype"
591608
case TYPELAMBDAtype => "TYPELAMBDAtype"
592609
case LAMBDAtpt => "LAMBDAtpt"
593610
case PARAMtype => "PARAMtype"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class TreePickler(pickler: TastyPickler) {
251251
case tpe: PolyType if richTypes =>
252252
pickleMethodic(POLYtype, tpe)
253253
case tpe: MethodType if richTypes =>
254-
pickleMethodic(METHODtype, tpe)
254+
pickleMethodic(methodType(isImplicit = tpe.isImplicitMethod, isErased = tpe.isErasedMethod), tpe)
255255
case tpe: ParamRef =>
256256
assert(pickleParamRef(tpe), s"orphan parameter reference: $tpe")
257257
case tpe: LazyRef =>

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ class TreeUnpickler(reader: TastyReader,
287287
readMethodic(PolyType, _.toTypeName)
288288
case METHODtype =>
289289
readMethodic(MethodType, _.toTermName)
290+
case IMPLICITMETHODtype =>
291+
readMethodic(ImplicitMethodType, _.toTermName)
292+
case ERASEDMETHODtype =>
293+
readMethodic(ErasedMethodType, _.toTermName)
294+
case ERASEDIMPLICITMETHODtype =>
295+
readMethodic(ErasedImplicitMethodType, _.toTermName)
290296
case TYPELAMBDAtype =>
291297
readMethodic(HKTypeLambda, _.toTypeName)
292298
case PARAMtype =>

tests/pos/implicit-dep.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait HasT {
2+
type T
3+
}
4+
5+
object Test {
6+
7+
8+
def foo: implicit Int => implicit (g: HasT) => g.T = ???
9+
}

0 commit comments

Comments
 (0)