Skip to content

Commit 432d471

Browse files
committed
Drop untyped Tasty
1 parent 12862de commit 432d471

File tree

3 files changed

+1
-470
lines changed

3 files changed

+1
-470
lines changed

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

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,6 @@ Standard-Section: "ASTs" TopLevelStat*
207207
208208
Annotation = ANNOTATION Length tycon_Type fullAnnotation_Term
209209
210-
// --------------- untyped additions ------------------------------------------
211-
212-
TermUntyped = Term
213-
TYPEDSPLICE Length splice_Term
214-
FUNCTION Length body_Term arg_Term*
215-
INFIXOP Length op_NameRef left_Term right_Term
216-
TUPLE Length elem_Term*
217-
PATDEF Length type_Term rhs_Term pattern_Term* Modifier*
218-
EMPTYTYPETREE
219-
220210
Note: Tree tags are grouped into 5 categories that determine what follows, and thus allow to compute the size of the tagged tree in a generic way.
221211
222212
Category 1 (tags 1-49) : tag
@@ -321,7 +311,6 @@ object TastyFormat {
321311
final val ERASED = 35
322312
final val PARAMsetter = 36
323313
final val EMPTYTREE = 37
324-
final val EMPTYTYPETREE = 38
325314

326315
// Cat. 2: tag Nat
327316

@@ -437,13 +426,6 @@ object TastyFormat {
437426
final val MATCHtype = 190
438427
final val MATCHtpt = 191
439428

440-
// Tags for untyped trees only:
441-
final val TYPEDSPLICE = 200
442-
final val FUNCTION = 201
443-
final val INFIXOP = 202
444-
final val PATDEF = 203
445-
final val TUPLE = 204
446-
447429
def methodType(isImplicit: Boolean = false, isErased: Boolean = false) = {
448430
val implicitOffset = if (isImplicit) 1 else 0
449431
val erasedOffset = if (isErased) 2 else 0
@@ -459,7 +441,7 @@ object TastyFormat {
459441

460442
/** Useful for debugging */
461443
def isLegalTag(tag: Int) =
462-
firstSimpleTreeTag <= tag && tag <= EMPTYTYPETREE ||
444+
firstSimpleTreeTag <= tag && tag <= EMPTYTREE ||
463445
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
464446
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
465447
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -558,7 +540,6 @@ object TastyFormat {
558540
case STABLE => "STABLE"
559541
case PARAMsetter => "PARAMsetter"
560542
case EMPTYTREE => "EMPTYTREE"
561-
case EMPTYTYPETREE => "EMPTYTYPETREE"
562543

563544
case SHAREDterm => "SHAREDterm"
564545
case SHAREDtype => "SHAREDtype"
@@ -661,12 +642,6 @@ object TastyFormat {
661642
case PRIVATEqualified => "PRIVATEqualified"
662643
case PROTECTEDqualified => "PROTECTEDqualified"
663644
case HOLE => "HOLE"
664-
665-
case TYPEDSPLICE => "TYPEDSPLICE"
666-
case FUNCTION => "FUNCTION"
667-
case INFIXOP => "INFIXOP"
668-
case TUPLE => "TUPLE"
669-
case PATDEF => "PATDEF"
670645
}
671646

672647
/** @return If non-negative, the number of leading references (represented as nats) of a length/trees entry.

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

Lines changed: 0 additions & 238 deletions
Original file line numberDiff line numberDiff line change
@@ -664,244 +664,6 @@ class TreePickler(pickler: TastyPickler) {
664664
withLength { pickleType(ann.symbol.typeRef); pickleTree(ann.tree) }
665665
}
666666

667-
// ---- pickling untyped trees ----------------------------------
668-
669-
def pickleUntyped(tree: untpd.Tree)(implicit ctx: Context): Unit = {
670-
671-
def pickleDummyRef(): Unit = writeNat(0)
672-
673-
def pickleDummyType(): Unit = writeByte(EMPTYTYPETREE)
674-
675-
def pickleUnlessEmpty(tree: untpd.Tree): Unit =
676-
if (!tree.isEmpty) pickleUntyped(tree)
677-
678-
def pickleTpt(tree: untpd.Tree) = pickleUntyped(tree)(ctx.addMode(Mode.Type))
679-
def pickleTerm(tree: untpd.Tree) = pickleUntyped(tree)(ctx.retractMode(Mode.Type))
680-
681-
def pickleAllParams(tree: untpd.DefDef): Unit = {
682-
pickleParams(tree.tparams)
683-
for (vparams <- tree.vparamss) {
684-
writeByte(PARAMS)
685-
withLength { pickleParams(vparams) }
686-
}
687-
}
688-
689-
def pickleParams(trees: List[untpd.Tree]): Unit =
690-
trees.foreach(pickleParam)
691-
692-
def pickleParam(tree: untpd.Tree): Unit = tree match {
693-
case tree: untpd.ValDef => pickleDef(PARAM, tree, tree.tpt)
694-
case tree: untpd.DefDef => pickleDef(PARAM, tree, tree.tpt, tree.rhs)
695-
case tree: untpd.TypeDef => pickleDef(TYPEPARAM, tree, tree.rhs)
696-
}
697-
698-
def pickleParent(tree: untpd.Tree): Unit = tree match {
699-
case _: untpd.Apply | _: untpd.TypeApply => pickleUntyped(tree)
700-
case _ => pickleTpt(tree)
701-
}
702-
703-
def pickleDef(tag: Int, tree: untpd.MemberDef, tpt: untpd.Tree, rhs: untpd.Tree = untpd.EmptyTree, pickleParams: => Unit = ()) = {
704-
import untpd.modsDeco
705-
writeByte(tag)
706-
withLength {
707-
pickleName(tree.name)
708-
pickleParams
709-
pickleTpt(tpt)
710-
pickleUnlessEmpty(rhs)
711-
pickleModifiers(tree.mods, tree.name.isTermName)
712-
}
713-
}
714-
715-
def pickleModifiers(mods: untpd.Modifiers, isTerm: Boolean): Unit = {
716-
import Flags._
717-
var flags = mods.flags
718-
val privateWithin = mods.privateWithin
719-
if (!privateWithin.isEmpty) {
720-
writeByte(if (flags is Protected) PROTECTEDqualified else PRIVATEqualified)
721-
pickleUntyped(untpd.Ident(privateWithin))
722-
flags = flags &~ Protected
723-
}
724-
pickleFlags(flags, isTerm)
725-
mods.annotations.foreach(pickleAnnotation)
726-
}
727-
728-
def pickleAnnotation(annotTree: untpd.Tree) = {
729-
writeByte(ANNOTATION)
730-
withLength { pickleDummyType(); pickleUntyped(annotTree) }
731-
}
732-
733-
try tree match {
734-
case Ident(name) =>
735-
writeByte(if (name.isTypeName) TYPEREF else TERMREF)
736-
pickleName(name)
737-
pickleDummyType()
738-
case This(qual) =>
739-
writeByte(QUALTHIS)
740-
pickleUntyped(qual)
741-
case Select(qual, name) =>
742-
writeByte(if (name.isTypeName) SELECTtpt else SELECT)
743-
pickleName(name)
744-
if (qual.isType) pickleTpt(qual) else pickleTerm(qual)
745-
case Apply(fun, args) =>
746-
writeByte(APPLY)
747-
withLength {
748-
pickleUntyped(fun)
749-
args.foreach(pickleUntyped)
750-
}
751-
case untpd.Throw(exc) =>
752-
writeByte(THROW)
753-
pickleUntyped(exc)
754-
case TypeApply(fun, args) =>
755-
writeByte(TYPEAPPLY)
756-
withLength {
757-
pickleUntyped(fun)
758-
args.foreach(pickleTpt)
759-
}
760-
case Literal(const) =>
761-
pickleConstant(const)
762-
case Super(qual, mix) =>
763-
writeByte(SUPER)
764-
withLength {
765-
pickleUntyped(qual);
766-
if (!mix.isEmpty) pickleUntyped(mix)
767-
}
768-
case New(tpt) =>
769-
writeByte(NEW)
770-
pickleTpt(tpt)
771-
case Typed(expr, tpt) =>
772-
writeByte(TYPED)
773-
withLength { pickleUntyped(expr); pickleTpt(tpt) }
774-
case NamedArg(name, arg) =>
775-
writeByte(NAMEDARG)
776-
pickleName(name)
777-
pickleUntyped(arg)
778-
case Assign(lhs, rhs) =>
779-
writeByte(ASSIGN)
780-
withLength { pickleUntyped(lhs); pickleUntyped(rhs) }
781-
case Block(stats, expr) =>
782-
writeByte(BLOCK)
783-
withLength { pickleUntyped(expr); stats.foreach(pickleUntyped) }
784-
case If(cond, thenp, elsep) =>
785-
writeByte(IF)
786-
withLength { pickleUntyped(cond); pickleUntyped(thenp); pickleUntyped(elsep) }
787-
case Match(selector, cases) =>
788-
writeByte(MATCH)
789-
withLength { pickleUntyped(selector); cases.foreach(pickleUntyped) }
790-
case CaseDef(pat, guard, rhs) =>
791-
writeByte(CASEDEF)
792-
withLength { pickleUntyped(pat); pickleUntyped(rhs); pickleUnlessEmpty(guard) }
793-
case Return(expr, from) =>
794-
writeByte(RETURN)
795-
withLength { pickleDummyRef(); pickleUnlessEmpty(expr) }
796-
case WhileDo(cond, body) =>
797-
writeByte(WHILE)
798-
withLength { pickleUntyped(cond); pickleUntyped(body) }
799-
case Try(block, cases, finalizer) =>
800-
writeByte(TRY)
801-
withLength { pickleUntyped(block); cases.foreach(pickleUntyped); pickleUnlessEmpty(finalizer) }
802-
case Bind(name, body) =>
803-
writeByte(BIND)
804-
withLength {
805-
pickleName(name); pickleDummyType(); pickleUntyped(body)
806-
}
807-
case Alternative(alts) =>
808-
writeByte(ALTERNATIVE)
809-
withLength { alts.foreach(pickleUntyped) }
810-
case tree: untpd.ValDef =>
811-
pickleDef(VALDEF, tree, tree.tpt, tree.rhs)
812-
case tree: untpd.DefDef =>
813-
pickleDef(DEFDEF, tree, tree.tpt, tree.rhs, pickleAllParams(tree))
814-
case tree: untpd.TypeDef =>
815-
pickleDef(TYPEDEF, tree, tree.rhs)
816-
case tree: untpd.ModuleDef =>
817-
pickleDef(OBJECTDEF, tree, tree.impl)
818-
case tree: untpd.Template =>
819-
writeByte(TEMPLATE)
820-
withLength {
821-
tree.parents.foreach(pickleParent)
822-
if (!tree.self.isEmpty) {
823-
writeByte(SELFDEF); pickleName(tree.self.name); pickleTpt(tree.self.tpt)
824-
}
825-
pickleUntyped(tree.constr)
826-
tree.body.foreach(pickleUntyped)
827-
}
828-
case Import(expr, selectors) =>
829-
writeByte(IMPORT)
830-
withLength { pickleUntyped(expr); pickleSelectors(selectors) }
831-
case tree: untpd.TypeTree =>
832-
pickleDummyType()
833-
case SingletonTypeTree(ref) =>
834-
writeByte(SINGLETONtpt)
835-
pickleTerm(ref)
836-
case RefinedTypeTree(parent, refinements) =>
837-
writeByte(REFINEDtpt)
838-
withLength { pickleTpt(parent); refinements.foreach(pickleTerm) }
839-
case AppliedTypeTree(tycon, args) =>
840-
writeByte(APPLIEDtpt)
841-
withLength { pickleTpt(tycon); args.foreach(pickleTpt) }
842-
case AndTypeTree(tp1, tp2) =>
843-
writeByte(ANDtpt)
844-
withLength { pickleTpt(tp1); pickleTpt(tp2) }
845-
case OrTypeTree(tp1, tp2) =>
846-
writeByte(ORtpt)
847-
withLength { pickleTpt(tp1); pickleTpt(tp2) }
848-
case ByNameTypeTree(tp) =>
849-
writeByte(BYNAMEtpt)
850-
pickleTpt(tp)
851-
case Annotated(tree, annot) =>
852-
writeByte(ANNOTATEDtpt)
853-
withLength { pickleTpt(tree); pickleTerm(annot) }
854-
case MatchTypeTree(bound, selector, cases) =>
855-
writeByte(MATCHtpt)
856-
withLength {
857-
if (!bound.isEmpty) pickleTpt(bound)
858-
pickleTpt(selector)
859-
cases.foreach(pickleUntyped)
860-
}
861-
case LambdaTypeTree(tparams, body) =>
862-
writeByte(LAMBDAtpt)
863-
withLength { pickleParams(tparams); pickleTpt(body) }
864-
case TypeBoundsTree(lo, hi) =>
865-
writeByte(TYPEBOUNDStpt)
866-
withLength {
867-
pickleTpt(lo);
868-
if (hi ne lo) pickleTpt(hi)
869-
}
870-
case untpd.Function(args, body) =>
871-
writeByte(FUNCTION)
872-
withLength { pickleUntyped(body); args.foreach(pickleUntyped) }
873-
case untpd.InfixOp(l, op, r) =>
874-
writeByte(INFIXOP)
875-
withLength { pickleUntyped(l); pickleUntyped(op); pickleUntyped(r) }
876-
case untpd.Tuple(elems) =>
877-
writeByte(TUPLE)
878-
withLength { elems.foreach(pickleUntyped) }
879-
case untpd.PatDef(mods, pats, tpt, rhs) =>
880-
writeByte(PATDEF)
881-
withLength {
882-
pickleTpt(tpt)
883-
pickleUntyped(rhs)
884-
pats.foreach(pickleUntyped)
885-
pickleModifiers(mods, isTerm = true)
886-
}
887-
case untpd.TypedSplice(splice) =>
888-
writeByte(TYPEDSPLICE)
889-
withLength { pickleTree(splice) }
890-
case Thicket(trees) =>
891-
if (trees.isEmpty) writeByte(EMPTYTREE)
892-
else trees.foreach(pickleUntyped)
893-
case _ =>
894-
val tree1 = desugar(tree)
895-
assert(tree1 `ne` tree, s"Cannot pickle untyped tree $tree")
896-
pickleUntyped(tree1)
897-
}
898-
catch {
899-
case ex: AssertionError =>
900-
println(i"error when pickling tree $tree")
901-
throw ex
902-
}
903-
}
904-
905667
// ---- main entry points ---------------------------------------
906668

907669
def pickle(trees: List[Tree])(implicit ctx: Context) = {

0 commit comments

Comments
 (0)