Skip to content
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

[SR-11685] assertion failure while generating SIL witness table protocol conformance #54094

Closed
marcrasi mannequin opened this issue Oct 30, 2019 · 4 comments
Closed

[SR-11685] assertion failure while generating SIL witness table protocol conformance #54094

marcrasi mannequin opened this issue Oct 30, 2019 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@marcrasi
Copy link
Mannequin

marcrasi mannequin commented Oct 30, 2019

Previous ID SR-11685
Radar None
Original Reporter @marcrasi
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: ad604467b746116369fad9ef439e97a1

relates to:

  • TF-938 constrain Array.DifferentiableView's Element to Differentiable

Issue Description:

Using the Ubuntu 18.04 trunk development snapshot from October 28, 2019, running swiftc on the following code

public struct Foo<Element> {}
  
public protocol P {
  associatedtype TV: Q
}

public protocol Q {}

extension Foo where Element : P {
  public struct View : P {
    public typealias TV = Foo<Element.TV>.View
    public var base: Foo
  }
}

extension Foo.View : Q where Element : Q {}

extension Foo : P where Element : P {
  public typealias TV = Foo<Element.TV>.View
}

Produces:

swift: /home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/llvm/include/llvm/ADT/PointerUnion.h:202: T llvm::PointerUnion<swift::ProtocolDecl *, swift::ProtocolConformance *>::get() const [PTs = <swift::ProtocolDecl *, swift::ProtocolConformance *>, T = swift::ProtocolConformance *]: Assertion `is<T>() && "Invalid accessor called"' failed.
Stack dump:
0.  Program arguments: /usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift -frontend -c -primary-file /usr/local/google/home/marcrasi/swift-base/build/Ninja-ReleaseAssert/swift-linux-x86_64/workspace/pi.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name pi -o /tmp/pi-e5cfb2.o 
1.  Swift version 5.1.1-dev (Swift 3f28e28784)
2.  While generating SIL witness table protocol conformance to 'P' (at /usr/local/google/home/marcrasi/swift-base/build/Ninja-ReleaseAssert/swift-linux-x86_64/workspace/pi.swift:3:8) for type 'Foo<Element>.View' (declared at [/usr/local/google/home/marcrasi/swift-base/build/Ninja-ReleaseAssert/swift-linux-x86_64/workspace/pi.swift:10:10 - line:13:3] RangeText="struct View : P {
    public typealias TV = Foo<Element.TV>.View
    public var base: Foo
  ")
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x4aaf4f4]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x4aad10e]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x4aaf7a8]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x123a0)[0x7fdf6a4fe3a0]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0x10b)[0x7fdf69575cfb]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x129)[0x7fdf695608ad]
/lib/x86_64-linux-gnu/libc.so.6(+0x2177f)[0x7fdf6956077f]
/lib/x86_64-linux-gnu/libc.so.6(+0x2f542)[0x7fdf6956e542]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x8ce73f]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x8ce58b]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x91236b]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x910363]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x911eea]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x9153d4]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x91202b]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x911fed]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x86bc7c]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x86cc22]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x86d1c7]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x4d6246]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x4d376d]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x473f00]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb)[0x7fdf6956252b]
/usr/local/google/home/marcrasi/Downloads/swift-toolchains/master-nightly/swift-DEVELOPMENT-SNAPSHOT-2019-10-28-a-ubuntu18.04/usr/bin/swift[0x473b4a]
<unknown>:0: error: unable to execute command: Aborted
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

I also tried the same code with the 5.1.1 and 4.2.4 releases, and these also produced assertion failures, with slightly different messages:

  • 4.2.4: /home/buildnode/jenkins/workspace/oss-swift-4.2-package-linux-ubuntu-18_04/llvm/include/llvm/ADT/Optional.h:160: T &&llvm::Optional<swift::ProtocolConformanceRef>::operator*() && [T = swift::ProtocolConformanceRef]: Assertion `hasVal' failed.

  • 5.1.1: /home/buildnode/jenkins/workspace/oss-swift-5.1-package-linux-ubuntu-18_04/swift/lib/AST/ProtocolConformance.cpp:77: swift::ProtocolDecl *swift::ProtocolConformanceRef::getRequirement() const: Assertion `!isInvalid()' failed.

@belkadan
Copy link
Contributor

The code is invalid, since Element.TV isn't known to conform to P, but of course that should be diagnosed!

@belkadan
Copy link
Contributor

@slavapestov, do we have an existing bug for "types in constrained extensions"?

@marcrasi
Copy link
Mannequin Author

marcrasi mannequin commented Oct 31, 2019

Oh, thanks for noticing the invalidity of this code! This was an attempt to reduce some more complex original code that also caused the crash, and I think that the original code was valid. If I manage to create some valid code that causes this crash, I'll post it here.

@dan-zheng
Copy link
Collaborator

This crash appears to be fixed on master, though I'm not sure when the fix landed. The reproducer is now diagnosed:

$ swift sr-11685.swift
sr-11685.swift:11:43: error: type 'Element.TV' does not conform to protocol 'P'
 public typealias TV = Foo<Element.TV>.View
 ^
sr-11685.swift:10:17: error: type 'Foo<Element>.View' does not conform to protocol 'P'
 public struct View : P {
 ^
sr-11685.swift:4:18: note: protocol requires nested type 'TV'; do you want to add it?
 associatedtype TV: Q
 ^
sr-11685.swift:19:41: error: type 'Element.TV' does not conform to protocol 'P'
 public typealias TV = Foo<Element.TV>.View
 ^
sr-11685.swift:18:1: error: type 'Foo<Element>' does not conform to protocol 'P'
extension Foo : P where Element : P {
^
sr-11685.swift:4:18: note: protocol requires nested type 'TV'; do you want to add it?
 associatedtype TV: Q
 ^

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

3 participants