-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Populate addresses of symbols, types and trees after pickler #416
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
Changes from 4 commits
fbad1dc
0d13962
af6f371
5597014
e47483a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,11 @@ class TreePickler(pickler: TastyPickler) { | |
op | ||
fillRef(lengthAddr, currentAddr, relative = true) | ||
} | ||
|
||
|
||
def addrOfSym(sym: Symbol): Option[Addr] = { | ||
symRefs.get(sym) | ||
} | ||
|
||
private var makeSymbolicRefsTo: Symbol = NoSymbol | ||
|
||
/** All references to members of class `sym` are pickled | ||
|
@@ -531,8 +535,16 @@ class TreePickler(pickler: TastyPickler) { | |
withLength { pickleType(ann.symbol.typeRef); pickleTree(ann.tree) } | ||
} | ||
|
||
def updateMapWithDeltas[T](mp: collection.mutable.Map[T, Addr]) = { | ||
mp.map{ | ||
case (key, addr) => (key, adjusted(addr)) | ||
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. I'd use a simple loop here:
Shorter, clearer, faster. 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. Updating a mutable data structure during iteration doesn't work in general. I guess this is safe because you don't change the key set, but I would be cautious about using the same approach in general. If you were to use an 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. That's way I wrote the code this way: at the point when I am updating the datastructure, I'm already iterating over a different one. 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. @retronym: Good point. We could modify like this
That looks like the most efficient safe solution. I believe efficiency is a concern here - these maps can become large. 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. Any reason to avoid |
||
}.foreach(mp += _) | ||
} | ||
|
||
|
||
trees.foreach(tree => if (!tree.isEmpty) pickleTree(tree)) | ||
assert(forwardSymRefs.isEmpty, i"unresolved symbols: ${forwardSymRefs.keySet.toList}%, %") | ||
compactify() | ||
} | ||
updateMapWithDeltas(symRefs) | ||
} | ||
} |
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.
Let's add doc comments for these.