-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Join logic for unpickling top level and term tasty #4546
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8f5a8ab
Join logic for unpickling top level and term tasty
nicolasstucki cfac787
Rename TastyUnpickler to QuoteUnpickler
nicolasstucki ad111dd
Add comments
nicolasstucki 68043eb
Make DottyUnpickler mode a class parameter
nicolasstucki 0100c12
Add docs
nicolasstucki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,18 +74,12 @@ class TreeUnpickler(reader: TastyReader, | |
/** Enter all toplevel classes and objects into their scopes | ||
* @param roots a set of SymDenotations that should be overwritten by unpickling | ||
*/ | ||
def enterTopLevel(roots: Set[SymDenotation])(implicit ctx: Context): Unit = { | ||
def enter(roots: Set[SymDenotation])(implicit ctx: Context): Unit = { | ||
this.roots = roots | ||
val rdr = new TreeReader(reader).fork | ||
ownerTree = new OwnerTree(NoAddr, 0, rdr.fork, reader.endAddr) | ||
rdr.indexStats(reader.endAddr) | ||
} | ||
|
||
def unpickleExpr()(implicit ctx: Context): Tree = { | ||
this.roots = Set(ctx.owner) | ||
val rdr = new TreeReader(reader).fork | ||
ownerTree = new OwnerTree(NoAddr, 0, rdr.fork, reader.endAddr) | ||
rdr.readTerm() | ||
if (rdr.isTopLevel) | ||
rdr.indexStats(reader.endAddr) | ||
} | ||
|
||
def unpickleTypeTree()(implicit ctx: Context): Tree = { | ||
|
@@ -96,9 +90,14 @@ class TreeUnpickler(reader: TastyReader, | |
} | ||
|
||
/** The unpickled trees */ | ||
def unpickle()(implicit ctx: Context): List[Tree] = { | ||
def unpickle(mode: UnpickleMode)(implicit ctx: Context): List[Tree] = { | ||
assert(roots != null, "unpickle without previous enterTopLevel") | ||
new TreeReader(reader).readTopLevel() | ||
val rdr = new TreeReader(reader) | ||
mode match { | ||
case UnpickleMode.TopLevel => rdr.readTopLevel() | ||
case UnpickleMode.Term => rdr.readTerm() :: Nil | ||
case UnpickleMode.TypeTree => rdr.readTpt() :: Nil | ||
} | ||
} | ||
|
||
class Completer(owner: Symbol, reader: TastyReader) extends LazyType { | ||
|
@@ -885,21 +884,22 @@ class TreeUnpickler(reader: TastyReader, | |
} | ||
|
||
def skipToplevel()(implicit ctx: Context): Unit= { | ||
if (!isAtEnd) | ||
nextByte match { | ||
case IMPORT | PACKAGE => | ||
skipTree() | ||
skipToplevel() | ||
case _ => | ||
} | ||
if (!isAtEnd && isTopLevel) { | ||
skipTree() | ||
skipToplevel() | ||
} | ||
} | ||
|
||
def isTopLevel(implicit ctx: Context): Boolean = | ||
nextByte == IMPORT || nextByte == PACKAGE | ||
|
||
def readTopLevel()(implicit ctx: Context): List[Tree] = { | ||
@tailrec def read(acc: ListBuffer[Tree]): List[Tree] = nextByte match { | ||
case IMPORT | PACKAGE => | ||
@tailrec def read(acc: ListBuffer[Tree]): List[Tree] = { | ||
if (isTopLevel) { | ||
acc += readIndexedStat(NoSymbol) | ||
if (!isAtEnd) read(acc) else acc.toList | ||
case _ => // top-level trees which are not imports or packages are not part of tree | ||
} | ||
else // top-level trees which are not imports or packages are not part of tree | ||
acc.toList | ||
} | ||
read(new ListBuffer[tpd.Tree]) | ||
|
@@ -1298,6 +1298,21 @@ class TreeUnpickler(reader: TastyReader, | |
|
||
object TreeUnpickler { | ||
|
||
/** Define the expected format of the tasty bytes | ||
* - TopLevel: Tasty that contains a full class nested in its package | ||
* - Term: Tasty that contains only a term tree | ||
* - TypeTree: Tasty that contains only a type tree or a reference to a type | ||
*/ | ||
sealed trait UnpickleMode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs documentation for this trait and all its children. |
||
object UnpickleMode { | ||
/** Unpickle a full class in some package */ | ||
object TopLevel extends UnpickleMode | ||
/** Unpickle as a TermTree */ | ||
object Term extends UnpickleMode | ||
/** Unpickle as a TypeTree */ | ||
object TypeTree extends UnpickleMode | ||
} | ||
|
||
/** A marker value used to detect cyclic reference while unpickling definitions. */ | ||
@sharable val PoisonTree: tpd.Tree = Thicket(Nil) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of a field this could be a class parameter:
class DottyUnpickler(bytes: Array[Byte], mode: UnpickleMode = UnpickleMode.TopLevel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Done.