Skip to content

[SR-14485] main compiler crash: GenericSignatureBuilder.cpp:8442: void checkGenericSignature(swift::CanGenericSignature, swift::GenericSignatureBuilder &): Assertion `isCanonicalAnchor(secondType)' failed #56840

@weissi

Description

@weissi
Previous ID SR-14485
Radar rdar://problem/76646764
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 5.5-dev (LLVM bcf6482631963a8, Swift 37aa203b753b23b)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Crash
Assignee None
Priority Medium

md5: d19231c42263e18d6f30726824d94f12

Issue Description:

The program from SR-14484 crashes the compiler (on main):

func truncate<Input: FixedWidthInteger & UnsignedInteger & BinaryInteger,
              Output: FixedWidthInteger & SignedInteger & BinaryInteger>(_ input: Input, outputType: Output.Type = Output.self) -> Output 
              where Output.Magnitude == Input {
    precondition(Output.Magnitude.self == Input.self)
    return Output(truncatingIfNeeded: input)
}

print(truncate(UInt(4), outputType: Int.self))

leads to

$ jw-docker-swift-main swift test.swift
docker.io/swiftlang/swift:nightly-main-bionic
test.swift:1:22: warning: redundant conformance constraint 'Input' : 'FixedWidthInteger'
func truncate<Input: FixedWidthInteger & UnsignedInteger & BinaryInteger,
                     ^
test.swift:2:23: note: conformance constraint 'Input' : 'FixedWidthInteger' implied here
              Output: FixedWidthInteger & SignedInteger & BinaryInteger>(_ input: Input, outputType: Output.Type = Output.self) -> Output 
                      ^
test.swift:1:42: warning: redundant conformance constraint 'Input' : 'UnsignedInteger'
func truncate<Input: FixedWidthInteger & UnsignedInteger & BinaryInteger,
                                         ^
test.swift:2:23: note: conformance constraint 'Input' : 'UnsignedInteger' implied here
              Output: FixedWidthInteger & SignedInteger & BinaryInteger>(_ input: Input, outputType: Output.Type = Output.self) -> Output 
                      ^
swift-frontend: /home/buildnode/jenkins/workspace/oss-swift-package-linux-ubuntu-18_04/swift/lib/AST/GenericSignatureBuilder.cpp:8442: void checkGenericSignature(swift::CanGenericSignature, swift::GenericSignatureBuilder &): Assertion `isCanonicalAnchor(secondType)' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /usr/bin/swift-frontend -frontend -interpret test.swift -disable-objc-interop -color-diagnostics -module-name test
1.  Swift version 5.5-dev (LLVM bcf6482631963a8, Swift 37aa203b753b23b)
2.  While evaluating request TypeCheckSourceFileRequest(source_file "test.swift")
3.  While type-checking 'truncate(_:outputType:)' (at test.swift:1:1)
4.  While evaluating request InterfaceTypeRequest(test.(file).truncate(_:outputType:)@test.swift:1:6)
5.  While evaluating request GenericSignatureRequest(test.(file).truncate(_:outputType:)@test.swift:1:6)
6.  While evaluating request InferredGenericSignatureRequest(test.test, NULL, test.(file).truncate(_:outputType:)@test.swift:1:6, {}, {(Input, Input), (Output.Type, Output.Type), (Output, Output)}, 0)
7.  While checking generic signature <τ_0_0, τ_0_1 where τ_0_0 == τ_0_0.Magnitude, τ_0_1 : FixedWidthInteger, τ_0_1 : SignedInteger, τ_0_0.Magnitude == τ_0_0.Magnitude.Magnitude.Magnitude> in requirement #&#8203;3
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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaregenericsFeature: generic declarations and types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions