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-12616] Compiler crasher while type checking generic code while evaluating generic signatures #55060

Open
swift-ci opened this issue Apr 18, 2020 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12616
Radar rdar://problem/62894479
Original Reporter saeta (JIRA User)
Type Bug
Status Reopened
Resolution
Environment

Latest development toolchains on both mac and linux.

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee @slavapestov
Priority Medium

md5: 7986c36ee2a59e900658286bf51a5c5b

duplicates:

  • SR-9398 Use-after-free caused by iterator invalidation in GSB::removeSelfDerived()

Issue Description:

Steps to reproduce: swiftc foo.swift

Expected result: the compiler doesn't crash

Actual result: the compiler crashes.

saeta@saeta:~/tmp/swift-org-toolchains$ ./swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swiftc foo.swift 
Stack dump:
0.  Program arguments: /usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift -frontend -c -primary-file foo.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name foo -o /tmp/foo-d76a6a.o 
1.  Swift version 5.3-dev (LLVM 55ab0064a0, Swift 6f018260a8)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "foo.swift")
3.  While type-checking extension of PropertyAdjacencyList (at foo.swift:33:1)
4.  While type-checking 'step(mailboxes:)' (at foo.swift:34:3)
5.  While evaluating request InterfaceTypeRequest(foo.(file).PropertyAdjacencyList extension.step(mailboxes:)@foo.swift:34:8)
6.  While evaluating request GenericSignatureRequest(foo.(file).PropertyAdjacencyList extension.step(mailboxes:)@foo.swift:34:8)
7.  While evaluating request InferredGenericSignatureRequest(foo.foo, <RawId where RawId : BinaryInteger>, foo.(file).PropertyAdjacencyList extension.step(mailboxes:)@foo.swift:34:8, {}, {(Mailboxes, Mailboxes)}, 0)
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x51bb7f4]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x51b93ee]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x51bbacc]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x13520)[0x7f3a79e23520]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x19479f3]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1945021]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x194ea77]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1951a23]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1456ff3]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1406537]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x14060b2]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1402881]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1401f78]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1402ce3]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x189abb6]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x189a932]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1872551]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1872216]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x13be3d8]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x18af10a]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x18aee82]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x187b851]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x186dbf1]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x13e74a1]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x13df881]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x13e42db]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x13df881]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x13df7b1]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1489135]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x148b140]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x148aea7]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x148adee]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1488e1e]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x1488df4]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x6b0778]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x6af7db]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x6aef80]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x55df93]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x55c9d9]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x4e7358]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb)[0x7f3a798a1bbb]
/usr/local/google/home/saeta/tmp/swift-org-toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swift[0x4e6efa]
<unknown>:0: error: unable to execute command: Segmentation fault
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
saeta@saeta:~/tmp/swift-org-toolchains$ ./swift-DEVELOPMENT-SNAPSHOT-2020-04-14-a-ubuntu18.04/usr/bin/swiftc --version
Swift version 5.3-dev (LLVM 55ab0064a0, Swift 6f018260a8)
Target: x86_64-unknown-linux-gnu
saeta@saeta:~/tmp/swift-org-toolchains$ cat foo.swift 
// Ways to fix the crasher:
// 1. Switch VertexId from `RawId` to `Int32`
// 2. Move `GraphProtocol` requirements from `MailboxProtocol` to `MailboxesProtocol`.
// 3. Remove the Equatable requirement from `VertexId`
// 4. ...

public protocol GraphProtocol {
  associatedtype VertexId: Equatable
}

public protocol MailboxProtocol {
  associatedtype Graph: GraphProtocol
}

public protocol MailboxesProtocol {
  associatedtype Graph

  associatedtype Mailbox: MailboxProtocol where Mailbox.Graph == Graph
}
public protocol ParallelGraph: GraphProtocol {
  func step<Mailboxes: MailboxesProtocol>(
    mailboxes: inout Mailboxes
  ) where Mailboxes.Graph == Self
}

struct PropertyAdjacencyList<
  RawId: BinaryInteger
>: GraphProtocol {
  public typealias VertexId = RawId
  // public typealias VertexId = Int32
}

extension PropertyAdjacencyList: ParallelGraph {
  func step<Mailboxes: MailboxesProtocol>(
    mailboxes: inout Mailboxes
  ) where Mailboxes.Graph == Self {}
}
@dabrahams
Copy link
Collaborator

Further reduction:

protocol E {}

protocol P {
  associatedtype V: E
}

protocol Q {
  associatedtype G: P
}

protocol R {
  associatedtype G
  associatedtype M: Q where M.G == G
}

struct A<I: E>: P {
  typealias V = I
  func f<N: R>(_: N) where N.G == Self {}
}

@dabrahams
Copy link
Collaborator

FWIW, I think the associatedtype G in R (Graph in MailboxesProtocol) is superfluous and could be replaced with

extension R {
  typealias G = M.G
}

which suppresses the bug, so that should at least give you a workaround.

@swift-ci
Copy link
Collaborator Author

Comment by Brennan Saeta (JIRA)

Can confirm that switching to typealiases works around the compiler crasher in the un-minimized case. Thanks @dabrahams!

@beccadax
Copy link
Contributor

beccadax commented May 5, 2020

@swift-ci create

@slavapestov
Copy link
Member

Re-opening this. I have a fix for the duped issue, but it doesn't address this one.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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.
Projects
None yet
Development

No branches or pull requests

4 participants