-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Set, Dictionary: Clarify assert message when a duplicate key is found #15569
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
Conversation
… is found When a duplicate key is found during rehashing, it is usually either because a key was mutated after insertion, or because the dictionary itself was mutated from multiple threads at the same time. Both of these are serious programmer errors. Promote the sanity check for duplicate keys to a full precondition and improve the error message to point out the most probable cause of the failure.
@swift-ci test |
@swift-ci smoke benchmark |
This is just a quick patch to help people debug these issues. We aren't doing a great job at detecting them, though; we should try to catch them more often. (rdar://problem/36437535) |
Build comment file:Optimized (O)Regression (21)
Improvement (15)
No Changes (389)
Unoptimized (Onone)Regression (16)
Improvement (17)
No Changes (392)
Hardware Overview
|
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.
I don't know the surrounding code. If this is to be a precondition, should it be checked prior to calling unsafeAddNew
?
Precondition checks can be done at any time; there is no requirement to do them in any particular order wrt other operations. ( (The Set and Dictionary call |
Blërg, smoke benchmarks are noisy. I don't see an obviously relevant regression. |
So, it's no longer "unsafe"? Preconditions and debug preconditions are part of the standard library's interface. Sanity checks are for internal assertions. We need some kind of delineation between checks as part of the interface and internal invariant checks. Lacking features, my understanding is that we've done so through names such as "unsafe" or "unchecked", which we call after performing interface checks. |
My changing of Mutating a hash key is a subtle but serious programming error. It is special in that
This particular function, deep inside the guts of our hash tables, is one of the few places where hashed collections are sometimes able to detect mutated keys. Leaving the check as a |
LGTM! |
When a duplicate key is found during rehashing, it is usually either because a key was mutated after insertion, or because the dictionary itself was mutated from multiple threads at the same time.
Both of these are serious programmer errors. Promote the sanity check for duplicate keys to a full precondition and improve the error message to point out the most probable cause of the failure.