-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix up the deep equality demangler tests. #78812
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
base: main
Are you sure you want to change the base?
Conversation
cc @DmT021 |
@swift-ci please smoke test |
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.
Looks good to me, only a minor note about the assert. Nice catch, thanks.
@@ -251,6 +251,7 @@ class Node { | |||
} | |||
|
|||
static bool deepEquals(const Node *lhs, const Node *rhs) { | |||
assert(lhs && rhs && "Nodes being compared may not be null"); |
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.
If both pointers can't be null we don't need if ((!lhs && rhs) || (lhs && !rhs))
. Or we can require at least one of them to be non-null, then the assert should be lhs || rhs
.
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.
Also, if both of them may not be null it might be a good idea to take const references instead
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.
Good catch about the now-redundant comparison; removed it.
I think we want to keep the types as pointers, because NodePointer
(type alias of Node *
) is the "currency" type used by the demangler; there are no public APIs that consume a Node &
, so requiring the caller to dereference it in just this case would be a bit unusual.
These tests were broken. The `Demangler::demangleSymbol` function operates subtly differently than what `swift-demangle` does under the hood (which powers the `mangling.txt` lit test), which calls calls `Demangler::demangleSymbolAsNode` instead. That difference caused many valid partial manglings to fail and return `nullptr`. Unfortunately this was never caught, because `isDeepEqualTo` immediately passes `this` to a static method (so there was no actual null pointer dereference occurring), and then the two `nullptr`s were compared for equality, erroneously returning true. I only happened to catch this when running the test in an environment with more strict pointer enforcement. I've updated the tests to: * Separate the valid manglings from invalid manglings so that we can test both outcomes. * Assert inside `deepEquals` that neither pointer is `nullptr`. * Assert that the symbol, when demangled and printed as a string, matches the expected demangling (which was present in the `.def` file but never used). The latter point ensures that all behavior is being verified, making these tests equivalent to those in `manglings.txt` with the added nondeterminism check that was in the original PR.
5b851e6
to
d4ee054
Compare
@swift-ci please smoke test |
@swift-ci please smoke test Linux platform |
These tests were broken. The
Demangler::demangleSymbol
function operates subtly differently than whatswift-demangle
does under the hood (which powers themangling.txt
lit test), which callsDemangler::demangleSymbolAsNode
instead. That difference caused many valid partial manglings to fail and returnnullptr
.Unfortunately this was never caught, because
isDeepEqualTo
immediately passesthis
to a static method (so there was no actual null pointer dereference occurring), and then the twonullptr
s were compared for equality, erroneously returning true. I only happened to catch this when running the test in an environment with more strict pointer enforcement.I've updated the tests to:
deepEquals
that neither pointer isnullptr
..def
file but never used).The latter point ensures that all behavior is being verified, making these tests equivalent to those in
manglings.txt
with the added nondeterminism check that was in the original PR.