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-8495] emitArchetypeTypeMetadataRef assertion failure #51015

Closed
mayoff opened this issue Aug 8, 2018 · 2 comments
Closed

[SR-8495] emitArchetypeTypeMetadataRef assertion failure #51015

mayoff opened this issue Aug 8, 2018 · 2 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 IRGen LLVM IR generation

Comments

@mayoff
Copy link

mayoff commented Aug 8, 2018

Previous ID SR-8495
Radar rdar://problem/43096256
Original Reporter @mayoff
Type Bug
Status Resolved
Resolution Done
Environment

swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-07-a.xctoolchain

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

md5: 5c66fecead73879a7596d6d902c0c744

Issue Description:

The crash happened when I added the Strideable conformance (see test program below).

Here's the terminal output:

:; /Library/Developer/Toolchains/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-07-a.xctoolchain/usr/bin/swiftc main.swift
Assertion failed: (!archetype->isPrimary() && "type metadata for primary archetype was not bound in context"), function emitArchetypeTypeMetadataRef, file /Users/buildnode/jenkins/workspace/oss-swift-4.2-package-osx/swift/lib/IRGen/GenArchetype.cpp, line 67.
0  swift                    0x000000010f5110e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010f510327 llvm::sys::RunSignalHandlers() + 39
2  swift                    0x000000010f511762 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff5c732f5a _sigtramp + 26
4  libsystem_platform.dylib 0x00000000000038b8 _sigtramp + 2743929208
5  libsystem_c.dylib        0x00007fff5c4d01ae abort + 127
6  libsystem_c.dylib        0x00007fff5c4981ac basename_r + 0
7  swift                    0x000000010bd4e447 swift::irgen::emitArchetypeTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::irgen::DynamicMetadataRequest) + 311
8  swift                    0x000000010bec5cc4 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 1476
9  swift                    0x000000010bec55e3 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 131
10 swift                    0x000000010bec56ca swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 58
11 swift                    0x000000010be23bb4 swift::irgen::MetadataPath::followComponent(swift::irgen::IRGenFunction&, swift::irgen::LocalTypeDataKey&, swift::irgen::MetadataResponse, swift::irgen::MetadataPath::Component, swift::irgen::DynamicMetadataRequest) + 2004
12 swift                    0x000000010be23107 swift::irgen::MetadataPath::follow(swift::irgen::IRGenFunction&, swift::irgen::LocalTypeDataKey, swift::irgen::MetadataResponse, swift::EncodedSequence<swift::irgen::MetadataPath::Component>::iterator, swift::EncodedSequence<swift::irgen::MetadataPath::Component>::iterator, swift::irgen::DynamicMetadataRequest, swift::EncodedSequence<swift::irgen::MetadataPath::Component>::Map<swift::irgen::MetadataResponse>*) + 1303
13 swift                    0x000000010be2337f swift::irgen::MetadataPath::followFromWitnessTable(swift::irgen::IRGenFunction&, swift::CanType, swift::ProtocolConformanceRef, swift::irgen::MetadataResponse, swift::irgen::DynamicMetadataRequest, swift::EncodedSequence<swift::irgen::MetadataPath::Component>::Map<swift::irgen::MetadataResponse>*) const + 239
14 swift                    0x000000010bd4e98c swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) + 860
15 swift                    0x000000010be259db swift::irgen::emitWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanType, llvm::Value**, swift::ProtocolConformanceRef) + 123
16 swift                    0x000000010be29010 bool llvm::function_ref<bool (unsigned int, swift::CanType, swift::ProtocolDecl*)>::callback_fn<emitConditionalConformancesBuffer(swift::irgen::IRGenFunction&, swift::ProtocolConformance const*)::$_14>(long, unsigned int, swift::CanType, swift::ProtocolDecl*) + 160
17 swift                    0x000000010ca6644d swift::SILWitnessTable::enumerateWitnessTableConditionalConformances(swift::ProtocolConformance const*, llvm::function_ref<bool (unsigned int, swift::CanType, swift::ProtocolDecl*)>) + 205
18 swift                    0x000000010be28b2b emitWitnessTableAccessorCall(swift::irgen::IRGenFunction&, swift::ProtocolConformance const*, llvm::Value**) + 203
19 swift                    0x000000010be21a58 swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 2840
20 swift                    0x000000010bd96a8d swift::irgen::IRGenerator::emitGlobalTopLevel(bool) + 1053
21 swift                    0x000000010be62380 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1168
22 swift                    0x000000010be6299e swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, unsigned int, llvm::GlobalVariable**) + 94
23 swift                    0x000000010bcfa780 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 15536
24 swift                    0x000000010bcf5ab2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2946
25 swift                    0x000000010bcb0338 main + 1128
26 libdyld.dylib            0x00007fff5c424015 start + 1
27 libdyld.dylib            0x000000000000000d start + 2747121657
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-07-a.xctoolchain/usr/bin/swift -frontend -c -primary-file main.swift -target x86_64-apple-darwin17.7.0 -enable-objc-interop -color-diagnostics -module-name main -o /var/folders/b4/7x_fkxrj6dz1bl7fq2xcv65jchzn9t/T/main-b52fc7.o 
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)

Here's main.swift:

struct Tagged<Tag, RawValue> {
    let rawValue: RawValue
    init(_ value: RawValue) { rawValue = value }
}

func combine<Tag, RawValue>(_ a: Tagged<Tag, RawValue>, _ b: Tagged<Tag, RawValue>, using combiner: (RawValue, RawValue) throws -> RawValue) rethrows -> Tagged<Tag, RawValue> {
    return Tagged<Tag, RawValue>(try combiner(a.rawValue, b.rawValue))
}

func formCombination<Tag, RawValue>(_ a: inout Tagged<Tag, RawValue>, _ b: Tagged<Tag, RawValue>, using combiner: (RawValue, RawValue) throws -> RawValue) rethrows {
    a = try combine(a, b, using: combiner)
}

extension Tagged: RawRepresentable {
    init?(rawValue: RawValue) { self.init(rawValue) }
}

extension Tagged: Encodable where RawValue: Encodable {
    func encode(to encoder: Encoder) throws {
        try rawValue.encode(to: encoder)
    }
}

extension Tagged: Decodable where RawValue: Decodable {
    init(from decoder: Decoder) throws {
        self.init(try RawValue.init(from: decoder))
    }
}

extension Tagged: CustomStringConvertible {
    var description: String { return String(describing: rawValue) }
}

extension Tagged: Equatable where RawValue: Equatable { }
extension Tagged: Hashable where RawValue: Hashable { }

extension Tagged: Comparable where RawValue: Comparable {
    static func <(_ a: Tagged, _ b: Tagged) -> Bool {  return a.rawValue < b.rawValue }
}

extension Tagged: ExpressibleByFloatLiteral where RawValue: ExpressibleByFloatLiteral {
    typealias FloatLiteralType = RawValue.FloatLiteralType
    init(floatLiteral: FloatLiteralType) { self.init(RawValue(floatLiteral: floatLiteral)) }
}

extension Tagged: ExpressibleByIntegerLiteral where RawValue: ExpressibleByIntegerLiteral {
    typealias IntegerLiteralType = RawValue.IntegerLiteralType
    init(integerLiteral: IntegerLiteralType) { self.init(RawValue(integerLiteral: integerLiteral)) }
}

extension Tagged: Numeric where RawValue: Numeric {
    typealias Magnitude = RawValue.Magnitude
    init?<T>(exactly source: T) where T : BinaryInteger {
        guard let value = RawValue(exactly: source) else { return nil }
        self.init(value)
    }
    var magnitude: Magnitude { return rawValue.magnitude }
    static func +(_ a: Tagged, _ b: Tagged) -> Tagged { return combine(a, b, using: +) }
    static func +=(_ a: inout Tagged, _ b: Tagged) { formCombination(&a, b, using: +) }
    static func -(_ a: Tagged, _ b: Tagged) -> Tagged { return combine(a, b, using: -) }
    static func -=(_ a: inout Tagged, _ b: Tagged) { formCombination(&a, b, using: -) }
    static func *(_ a: Tagged, _ b: Tagged) -> Tagged { return combine(a, b, using: *) }
    static func *=(_ a: inout Tagged, _ b: Tagged) { formCombination(&a, b, using: *) }
}

extension Tagged: SignedNumeric where RawValue: SignedNumeric { }

extension Tagged: Strideable where RawValue: Strideable, RawValue.Stride == RawValue {
    func distance(to other: Tagged) -> Stride { return Tagged(rawValue.distance(to: other.rawValue)) }
    func advanced(by n: Stride) -> Tagged { return Tagged(rawValue.advanced(by: n.rawValue)) }
    typealias Stride = Tagged<Tag, RawValue>
}
@belkadan
Copy link
Contributor

belkadan commented Aug 9, 2018

@swift-ci create

@slavapestov
Copy link
Member

#18760

@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 IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

4 participants