You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears to be common practice to violate exclusivity using `Dictionary.subscript._modify` in a way that the compiler fails to diagnose.
I'm not too concerned about miscompiles yet. But I don't know how to plug this hole before it becomes bigger without possibly breaking a bunch of source. And I don't know how developers should fix their code without sticking silly 'let's in that defeat the purpose of the 'autoclosure'.
Exclusivity violations could also become apparent after inlining if we don't change anything.
It seems common to access a dictionary that is a struct stored property, and reference the same struct, or one of its members in the `defaultValue:` autoclosure.
In most cases, the violation should be harmless, ignoring possible compiler optimization. On the other hand, if we don't diagnose it, then the user could reentrantly access the dictionary in the middle of key insertion...
Nothing comes to mind. We can't fall back on dynamic enforcement since methods like getValue will be compiled on the premise that struct members don't need that. In general, I think we just have to acknowledge this as a bug that we have little choice but to fix. Users will need to factor the autoclosure in a way that doesn't need all of self; in your example, they could make getValue() a static method.
I don't see any way forward without breaking source. If the question boils down to how much code will break, I can start working through any cases I find in the SCK.
Everyone from the Core Team who's weighed in so far agrees that we should just treat this as a bug fix and accept the source compatibility break. We just need to document it properly in release notes.
Additional Detail from JIRA
md5: a2d9c4d922a9abe7ea94e9715dfcbc10
Issue Description:
It appears to be common practice to violate exclusivity using `Dictionary.subscript._modify` in a way that the compiler fails to diagnose.
I'm not too concerned about miscompiles yet. But I don't know how to plug this hole before it becomes bigger without possibly breaking a bunch of source. And I don't know how developers should fix their code without sticking silly 'let's in that defeat the purpose of the 'autoclosure'.
Exclusivity violations could also become apparent after inlining if we don't change anything.
It seems common to access a dictionary that is a struct stored property, and reference the same struct, or one of its members in the `defaultValue:` autoclosure.
In most cases, the violation should be harmless, ignoring possible compiler optimization. On the other hand, if we don't diagnose it, then the user could reentrantly access the dictionary in the middle of key insertion...
Here is an equivalent exclusivity violation that does not use coroutines and which we do enforce:
A PR that fixes diagnostics and breaks a bunch of code:
#28022
The text was updated successfully, but these errors were encountered: