Skip to content

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

Merged
merged 5 commits into from
Apr 3, 2015

Conversation

DarkDimius
Copy link
Contributor

To allow other phases to generate additional sections that refer to them.

@DarkDimius
Copy link
Contributor Author

@odersky please review

@DarkDimius DarkDimius mentioned this pull request Mar 18, 2015
@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd use a simple loop here:

for ((key, addr) <- mp.toList) mp(key) = adjusted(addr)

Shorter, clearer, faster.

Copy link
Member

Choose a reason for hiding this comment

The 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 mutable.AnyRefMap rather than a mutable.Map (which is a good idea for performance reasons anyway), you can use mp.transformValues(adjusted).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

@retronym: Good point. We could modify like this

for (key <- mp.keysIterator.toBuffer) mp(key) = adjusted(mp(key))

That looks like the most efficient safe solution. I believe efficiency is a concern here - these maps can become large.

Copy link
Member

Choose a reason for hiding this comment

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

Any reason to avoid AnyRefMap? IMO that should be the first choice when you need a map in the compiler. Its main claim to fame is that it can calls equals/hashCode rather than ==/``##` which is a non-negligible performance win.

@odersky
Copy link
Contributor

odersky commented Mar 19, 2015

Otherwise, LGTM

DarkDimius added a commit to dotty-staging/dotty that referenced this pull request Mar 25, 2015
DarkDimius added a commit to dotty-staging/dotty that referenced this pull request Apr 1, 2015
DarkDimius added a commit that referenced this pull request Apr 3, 2015
Populate addresses of symbols, types and trees after pickler
@DarkDimius DarkDimius merged commit 7c8fea7 into scala:master Apr 3, 2015
@allanrenucci allanrenucci deleted the pickler-modular branch December 14, 2017 19:24
tgodzik added a commit to tgodzik/scala3 that referenced this pull request May 27, 2025
Backport "Disallow empty parameter clauses in `extension` definition" to 3.3 LTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants