Skip to content

Towards correct positions in TASTY types #1634

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

Merged
merged 10 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ Standard-Section: "ASTs" TopLevelStat*
BIND Length boundName_NameRef patType_Type pat_Term
ALTERNATIVE Length alt_Term*
UNAPPLY Length fun_Term ImplicitArg* pat_Type pat_Term*
IDENTtpt NameRef Type // used when type ident's type is not a TypeRef
IDENTtpt NameRef Type // used for all type idents
SELECTtpt NameRef qual_Term
SINGLETONtpt Path
REFINDtpt Length underlying_Term refinement_Stat*
REFINEDtpt Length underlying_Term refinement_Stat*
APPLIEDtpt Length tycon_Term arg_Term*
POLYtpt Length TypeParam* body_Term
TYPEBOUNDStpt Length low_Term high_Term
Expand Down
9 changes: 3 additions & 6 deletions src/dotty/tools/dotc/core/tasty/TastyPickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ class TastyPickler {
all.bytes
}

/**
* Addresses in TASTY file of trees, stored by pickling.
* Note that trees are checked for reference equality,
* so one can reliably use this function only directly after `pickler`.
* Note that a tree can have several addresses, if it is shared,
* i.e. accessible from different paths. Any such sharing is undone by pickling.
/** The address in the TASTY file of a given tree, or None if unknown.
* Note that trees are looked up by for reference equality,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "by for reference equality" -> "by reference equality"

* so one can reliably use this function only directly after `pickler`.
*/
var addrOfTree: tpd.Tree => Option[Addr] = (_ => None)

Expand Down
5 changes: 1 addition & 4 deletions src/dotty/tools/dotc/core/tasty/TreeBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ class TreeBuffer extends TastyBuffer(50000) {
private var delta: Array[Int] = _
private var numOffsets = 0

/** A map from trees to the address(es) at which a tree is pickled. There may be several
* such addresses if the tree is shared. To keep the map compact, the value type is a
* disjunction of a single address (which is the common case) and a list of addresses.
*/
/** A map from trees to the address at which a tree is pickled. */
private val treeAddrs = new java.util.IdentityHashMap[Tree, Any] // really: Addr | Null

def registerTreeAddr(tree: Tree): Addr = treeAddrs.get(tree) match {
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class TreePickler(pickler: TastyPickler) {
}
case AppliedTypeTree(tycon, args) =>
writeByte(APPLIEDtpt)
withLength { pickleTree(tycon); args.foreach(pickleTree(_)) }
withLength { pickleTree(tycon); args.foreach(pickleTree) }
case AndTypeTree(tp1, tp2) =>
writeByte(ANDtpt)
withLength { pickleTree(tp1); pickleTree(tp2) }
Expand Down
4 changes: 4 additions & 0 deletions src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
case JavaArrayType(elemtp) =>
return toText(elemtp) ~ "[]"
case tp: AnnotatedType if homogenizedView =>
// Positions of annotations in types are not serialized
// (they don;t need to because we keep the original type tree with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: don;t -> don't

// the original annotation anyway. Therefore, there will always be
// one version of the annotation tree that has the correct positions).
withoutPos(super.toText(tp))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment explaining why this is needed?

case tp: SelectionProto =>
return "?{ " ~ toText(tp.name) ~ (" " provided !tp.name.decode.last.isLetterOrDigit) ~
Expand Down