-
Notifications
You must be signed in to change notification settings - Fork 10.5k
NFC: Add GenericSignature::getCanonicalSignature
.
#29105
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
NFC: Add GenericSignature::getCanonicalSignature
.
#29105
Conversation
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for `GenericSignature` with underlying `nullptr`. This led to verbose workarounds when computing `CanGenericSignature` from `GenericSignature`. Solution: `GenericSignature::getCanonicalSignature` is a wrapper around `GenericSignatureImpl::getCanonicalSignature` that returns the canonical signature, or `nullptr` if the underlying pointer is `nullptr`. Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
One concern is that GenericSignature sig;
auto canSig1 = sig.getCanonicalSignature(); // newly added, returns `nullptr`
auto canSig2 = sig->getCanonicalSignature(); // crashes We could avoid this confusion by removing
|
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 awesome to me!
@swift-ci Please test |
Yes. We need to migrate most of the API up and out of the Impl type. This state of affairs only exists because there's some weird header dependency between Type.h and Types.h that goes through GenericSignature.h or somesuch nonsense. |
Build failed |
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.
Nice cleanup.
Linux CI fails for
Details
I'm not sure what causes this failure, but I can reproduce it locally on Linux. |
Simplify `GenericSignature::getCanonicalSignature` callers.
I tried merging // Note: the `do` statement is important to reproduce the crash.
do {
var a: ContiguousArray = [0]
while let element = a.popLast() {
}
} $ swift -O crash.swift
crash.swift:4:13: warning: value 'element' was defined but never used; consider replacing with boolean test
while let element = a.popLast() {
~~~~^~~~~~~~~~
!= nil
Stack dump:
0. Program arguments: /home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift -frontend -interpret crash.swift -disable-objc-interop -color-diagnostics -O -module-name crash
1. Swift version 5.2-dev
2. While running user code "crash.swift"
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x4b81b24]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x4b7f6fe]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x4b81de6]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12890)[0x7f950542c890]
[0x7f950585d0ce]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x507059]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x50b500]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x4f8730]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x4edb72]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x4e260c]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x4df413]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x473f85]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f9503872b97]
/home/danielzheng/swift-master/build/Ninja-ReleaseAssert+stdlib-Release/swift-linux-x86_64/bin/swift[0x473bca]
[1] 941 illegal hardware instruction (core dumped) $SWIFT_BIN/swift -O crash.swift Edit: others say this test failure was caused by an unrelated PR, and has since been fixed/reverted. Pulling from master and rerunning CI fixed the failure. |
@swift-ci Please test |
Build failed |
Build failed |
Motivation:
GenericSignatureImpl::getCanonicalSignature
crashes forGenericSignature
with underlyingnullptr
. This led to verbose workaroundswhen computing
CanGenericSignature
fromGenericSignature
:Solution:
GenericSignature::getCanonicalSignature
is a wrapper aroundGenericSignatureImpl::getCanonicalSignature
that returns the canonicalsignature, or
nullptr
if the underlying pointer isnullptr
.Rewrite all verbose workarounds using
GenericSignature::getCanonicalSignature
.Related forum discussion.
For reference: motivated by #29099.
Similarly,
Type::getCanonicalType
can be added, forwarding toTypeBase::getCanonicalType
.