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

Compiler crash with circular reference, redundant conformance requirements #72695

Open
karwa opened this issue Mar 29, 2024 · 0 comments
Open
Labels
assertion failure Bug → crash: An assertion failure 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 declarations Feature: declarations generics Feature: generic declarations and types inheritance clauses Feature → type declarations: Type inheritance clauses protocol Feature → type declarations: Protocol declarations swift 6.0 type checker Area → compiler: Semantic analysis typealias Feature → type declarations: `typealias` declarations

Comments

@karwa
Copy link
Collaborator

karwa commented Mar 29, 2024

Description

No response

Reproduction

public protocol P: P.T {
    typealias T = X
}
public protocol X {}

Stack dump

<source>:1:22: error: circular reference
1 │ public protocol P: P.T {
  │                 │    ╰─ error: circular reference
  │                 ├─ note: protocol 'P' declared here
  │                 ╰─ note: through reference here
2 │     typealias T = X
3 │ }

<source>:1:22: error: circular reference
1 │ public protocol P: P.T {
  │                 │    ╰─ error: circular reference
  │                 ├─ note: through reference here
  │                 ╰─ note: through reference here
2 │     typealias T = X
3 │ }

Redundant conformance requirements in signature <Self where Self : P>:
Ours:
- Copyable
- Escapable
- X
Theirs:
- X
All requirements:
(requirement "Self" conforms_to "Copyable")
(requirement "Self" conforms_to "Escapable")
(requirement "Self" conforms_to "X")
Requirement machine for <τ_0_0 where τ_0_0 : P>
Rewrite system: {
- [P].[P] => [P] [permanent]
- [P].[X] => [P] [explicit]
- [P].T.[concrete: X] => [P].T [explicit]
- [P].[Copyable] => [P] [explicit]
- [P].[Escapable] => [P] [explicit]
- [X].[X] => [X] [permanent]
- [X].[Copyable] => [X] [explicit]
- [X].[Escapable] => [X] [explicit]
- [Copyable].[Copyable] => [Copyable] [permanent]
- [Escapable].[Escapable] => [Escapable] [permanent]
- τ_0_0.[P] => τ_0_0 [explicit]
- τ_0_0.[X] => τ_0_0
- τ_0_0.T.[concrete: X] => τ_0_0.T
- τ_0_0.[Copyable] => τ_0_0
- τ_0_0.[Escapable] => τ_0_0
}
Property map: {
  [P] => { conforms_to: [P X Copyable Escapable] }
  [X] => { conforms_to: [X Copyable Escapable] }
  [Copyable] => { conforms_to: [Copyable] }
  [Escapable] => { conforms_to: [Escapable] }
  τ_0_0 => { conforms_to: [P X Copyable Escapable] }
  [P].T => { concrete_type: [concrete: X] }
  τ_0_0.T => { concrete_type: [concrete: X] }
}
Conformance paths: {
}
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend -frontend -S -primary-file <source> -target x86_64-unknown-linux-gnu -disable-objc-interop -g -debug-info-format=dwarf -dwarf-version=4 -empty-abi-descriptor -resource-dir /opt/compiler-explorer/swift-nightly/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /app -Xllvm --x86-asm-syntax=intel -module-name output -plugin-path /opt/compiler-explorer/swift-nightly/usr/lib/swift/host/plugins -plugin-path /opt/compiler-explorer/swift-nightly/usr/local/lib/swift/host/plugins -o /app/output.s
1.	Swift version 6.0-dev (LLVM 87789f04c6598f1, Swift 52e8fbc115ca18f)
2.	Compiling with effective version 5.10
3.	While evaluating request TypeCheckSourceFileRequest(source_file "<source>")
4.	While type-checking 'P' (at <source>:1:8)
5.	While checking generic signature <τ_0_0 where τ_0_0 : P>
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend 0x000055dda016e357
1  swift-frontend 0x000055dda016c05e
2  swift-frontend 0x000055dda016e9cf
3  libc.so.6      0x00007fc83e442520
4  libc.so.6      0x00007fc83e4969fc pthread_kill + 300
5  libc.so.6      0x00007fc83e442476 raise + 22
6  libc.so.6      0x00007fc83e4287f3 abort + 211
7  swift-frontend 0x000055dd9b16d343
8  swift-frontend 0x000055dd9b16d288
9  swift-frontend 0x000055dd9aa3d0d8
10 swift-frontend 0x000055dd9aa3a194
11 swift-frontend 0x000055dd9ab33598
12 swift-frontend 0x000055dd9ab35d37
13 swift-frontend 0x000055dd9ab334b5
14 swift-frontend 0x000055dd997ddd79
15 swift-frontend 0x000055dd997d582a
16 swift-frontend 0x000055dd997d57c7
17 swift-frontend 0x000055dd994c4d8e
18 swift-frontend 0x000055dd994b1e85
19 swift-frontend 0x000055dd994b01e3
20 swift-frontend 0x000055dd9926fe64
21 libc.so.6      0x00007fc83e429d90
22 libc.so.6      0x00007fc83e429e40 __libc_start_main + 128
23 swift-frontend 0x000055dd9926ed0e

*** Signal 11: Backtracing from 0x7fc83e428898... done ***

*** Program crashed: Bad pointer dereference at 0x0000000000000000 ***

Thread 0 "swift-frontend" crashed:

0  0x00007fc83e428898 <unknown> in libc.so.6


Registers:

rax 0x0000000000000000  0
rdx 0x00007fc83eae5880  80 58 ae 3e c8 7f 00 00 a0 62 ae 3e c8 7f 00 00  ·X®>È··· b®>È···
rcx 0x00007fc83e4969fc  41 89 c5 41 f7 dd 3d 00 f0 ff ff b8 00 00 00 00  A·ÅA÷Ý=·ðÿÿ¸····
rbx 0x0000000000000006  6
rsi 0x0000000000000001  1
rdi 0x0000000000000001  1
rbp 0x00007fc83e61be90  01 00 00 00 01 00 00 00 80 58 ae 3e c8 7f 00 00  ·········X®>È···
rsp 0x00007ffd23821910  20 00 00 00 00 00 00 00 d4 48 51 3e c8 7f 00 00   ·······ÔHQ>È···
 r8 0x0000000000000000  0
 r9 0x0000000000000000  0
r10 0x0000000000000008  8
r11 0x0000000000000246  582
r12 0x00007ffd23821a58  a0 ad 5e a6 dd 55 00 00 50 a1 62 a6 dd 55 00 00   ­^¦ÝU··P¡b¦ÝU··
r13 0x0000000000000030  48
r14 0x000055dda160f145  0a 00 65 72 72 6f 72 3a 20 75 6e 6b 6e 6f 77 6e  ··error: unknown
r15 0x00007ffd23821dd8  10 a1 62 a6 dd 55 00 00 02 00 00 00 05 00 00 00  ·¡b¦ÝU··········
rip 0x00007fc83e428898  f4 83 3d 00 36 1f 00 05 75 14 c7 05 f4 35 1f 00  ô·=·6···u·Ç·ô5··

rflags 0x0000000000010246  ZF PF

cs 0x0033  fs 0x0000  gs 0x0000


Images (27 omitted):

0x00007fc83e400000–0x00007fc83e5bc341 c289da5071a3399de893d2af81d6a30c62646e1e libc.so.6 /lib/x86_64-linux-gnu/libc.so.6

Backtrace took 0.01s

Program terminated with signal: SIGSEGV
Compiler returned: 139

Expected behavior

Not really sure, to be honest. Previous versions of the compiler report a circular reference:

<source>:1:22: error: circular reference
public protocol P: P.T {
                     ^
<source>:1:17: note: protocol 'P' declared here
public protocol P: P.T {
                ^
<source>:1:17: note: through reference here
public protocol P: P.T {
                ^
<source>:1:22: error: circular reference
public protocol P: P.T {
                     ^
<source>:1:17: note: through reference here
public protocol P: P.T {
                ^
<source>:1:17: note: through reference here
public protocol P: P.T {
                ^
<source>:1:17: warning: protocol 'P' should be declared to refine 'X' due to a same-type constraint on 'Self'
public protocol P: P.T {

But is it really a circular reference? I'm not so sure.

Environment

Swift version 6.0-dev (LLVM 87789f04c6598f1, Swift 52e8fbc)
Target: x86_64-unknown-linux-gnu

Additional information

Godbolt

@karwa karwa added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels Mar 29, 2024
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis generics Feature: generic declarations and types protocol Feature → type declarations: Protocol declarations declarations Feature: declarations swift 6.0 typealias Feature → type declarations: `typealias` declarations assertion failure Bug → crash: An assertion failure inheritance clauses Feature → type declarations: Type inheritance clauses and removed triage needed This issue needs more specific labels labels Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertion failure Bug → crash: An assertion failure 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 declarations Feature: declarations generics Feature: generic declarations and types inheritance clauses Feature → type declarations: Type inheritance clauses protocol Feature → type declarations: Protocol declarations swift 6.0 type checker Area → compiler: Semantic analysis typealias Feature → type declarations: `typealias` declarations
Projects
None yet
Development

No branches or pull requests

2 participants