Page MenuHomePhabricator

wuhao5 (Hao Wu)
User

Projects

User does not belong to any projects.

User Details

User Since
Mar 14 2019, 10:09 AM (103 w, 3 d)

Recent Activity

Mar 19 2019

wuhao5 added a comment to D58514: Avoid needlessly copying blocks that initialize or are assigned to local auto variables to the heap.

Okay, so really just a block self-reference. We could really just add a feature for that that would avoid both the complexity and the expense of the self-capture dance.

Is there a plan to cover this case? or is it a legitimate use case that Clang should handle?

You are currently relying on something that ARC doesn't guarantee, so the client code should be fixed to explicitly copy the block. I think we would be happy to consider a proposal in the long run to allow blocks to self-reference more easily, which will effectively bypass the problem.

Mar 19 2019, 1:34 PM · Restricted Project
wuhao5 added a comment to D58514: Avoid needlessly copying blocks that initialize or are assigned to local auto variables to the heap.

Okay, so really just a block self-reference. We could really just add a feature for that that would avoid both the complexity and the expense of the self-capture dance.

Mar 19 2019, 11:31 AM · Restricted Project

Mar 14 2019

wuhao5 added a comment to D58514: Avoid needlessly copying blocks that initialize or are assigned to local auto variables to the heap.

Can I ask why you want a weak reference to a block in the first place? It seems basically useless — blocks can certainly appear in reference cycles, but I don't know why you'd ever try to break that cycle with the block instead of somewhere else.

Mar 14 2019, 12:00 PM · Restricted Project
wuhao5 added a comment to D58514: Avoid needlessly copying blocks that initialize or are assigned to local auto variables to the heap.

The specified user model of blocks is that they stay on the stack until they get copied, and there can be multiple such copies. ARC just automates that process. So the address of a block is not consistent before you've forced a copy.

I tend to agree that a better user model would have been for blocks to be allocated in one place, without any of this copying business, and for the compiler to make an intelligent decision about stack vs. heap based on how the block is used. That's the model we've used for closures in Swift. But that would've required the compiler to have a better ability to propagate information about how the block was used, which Clang isn't really set up for, and it would've required noescape annotations to be introduced and used reliably throughout the SDK, which seemed like a big request at the time. So it's not how it works.

There is no way in the existing ABI for copying a block to cause other references to the block to become references to the heap block. We do do that for __block variables, but not for block objects themselves.

Mar 14 2019, 11:23 AM · Restricted Project
wuhao5 added a comment to D58514: Avoid needlessly copying blocks that initialize or are assigned to local auto variables to the heap.

Hey guys, this is Hao, I am working with Chrome team to sort this issue out.

Mar 14 2019, 10:21 AM · Restricted Project