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-7876] Runtime crash on 'type metadata accessor for %Typename%' #50411

Closed
swift-ci opened this issue Jun 5, 2018 · 19 comments
Closed

[SR-7876] Runtime crash on 'type metadata accessor for %Typename%' #50411

swift-ci opened this issue Jun 5, 2018 · 19 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 regression run-time crash Bug → crash: Swift code crashed during execution swift 4.2

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 5, 2018

Previous ID SR-7876
Radar rdar://problem/40810002
Original Reporter broadway_lamb (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 10 beta (10L176w), macOS 10.14 Beta (18A293u)

Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, 4.2Regression, RunTimeCrash
Assignee broadway_lamb (JIRA)
Priority Medium

md5: 9657a246ce8b2e208b6a48ea60850d24

is duplicated by:

  • SR-8100 Compiled code crashes with a EXC_BAD_INSTRUCTION
  • SR-8341 Finish recursive metadata support for resilient types

Issue Description:

I'm experiencing a runtime crash when running my Vapor 3 project after I compile it with Xcode 10 beta. I didn't have this issue previously with Xcode 9/Swift 4.1

Stacktrace:

#​0 0x00000001025f3f50 in _dispatch_gate_wait_slow ()
#​1 0x00000001025e104b in dispatch_once_f ()
#​2 0x0000000101db2c19 in swift_once ()
#​3 0x000000010053d70f in type metadata accessor for Address ()
#&#8203;4 0x000000010053d671 in type metadata accessor for Identifier<Address> ()
#&#8203;5 0x00000001005460aa in ___lldb_unnamed_symbol55$$ServerCore ()
#&#8203;6 0x00000001025e10c2 in _dispatch_client_callout ()
#&#8203;7 0x00000001025e1000 in dispatch_once_f ()
#&#8203;8 0x0000000101db2c19 in swift_once ()
#&#8203;9 0x000000010053d70f in type metadata accessor for Address ()
#&#8203;10 0x000000010053cfe0 in static MigrationConfig.addAllMigrations() at /Users/sergej/Developer/Timetable-SPbU/Server/Sources/ServerCore/Migrations.swift:24
#&#8203;11 0x00000001005027b8 in configure(_:_:_:) at /Users/sergej/Developer/Timetable-SPbU/Server/Sources/App/configure.swift:27
#&#8203;12 0x0000000100002c80 in main at /Users/sergej/Developer/Timetable-SPbU/Server/Sources/Run/main.swift:13
#&#8203;13 0x00007fff6503fee1 in start ()

The project itself can be found at https://github.com/Timetable-SPbU/Server.

@belkadan
Copy link
Contributor

belkadan commented Jun 5, 2018

@swift-ci create

@mikeash
Copy link
Contributor

mikeash commented Jun 6, 2018

I'm having trouble building the project, are there any special steps I need to take? I'd like to reproduce the crash locally if possible.

Otherwise, could you attach a full crash log? That might be helpful to see what's going wrong.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 6, 2018

Comment by Sergej Jaskiewicz (JIRA)

@mikeash what trouble are you experiencing? I've just clean-cloned the project and built it successfully using SPM.

Here's my terminal output:

sergej@Sergejs-iMac Developer $ git clone https://github.com/Timetable-SPbU/Server.git
Cloning into 'Server'...
remote: Counting objects: 291, done.
remote: Compressing objects: 100% (219/219), done.
remote: Total 291 (delta 164), reused 193 (delta 66), pack-reused 0
Receiving objects: 100% (291/291), 62.67 KiB | 553.00 KiB/s, done.
Resolving deltas: 100% (164/164), done.
sergej@Sergejs-iMac Developer $ cd Server/
sergej@Sergejs-iMac Server (master) $ swiftenv global 4.2 
sergej@Sergejs-iMac Server (master) $ swift --version
Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3)
Target: x86_64-apple-darwin18.0.0
sergej@Sergejs-iMac Server (master) $ swift build
Fetching https://github.com/Timetable-SPbU/TimetableSDK.git
Fetching https://github.com/vapor/multipart.git
Fetching https://github.com/vapor/fluent.git
Fetching https://github.com/vapor/crypto.git
Fetching https://github.com/vapor/fluent-postgresql.git
Fetching https://github.com/broadwaylamb/Hammond.git
Fetching https://github.com/vapor/console.git
Fetching https://github.com/vapor/database-kit.git
Fetching https://github.com/vapor/postgresql.git
Fetching https://github.com/apple/swift-nio-ssl-support.git
Fetching https://github.com/dmcyk/CCurl.git
Fetching https://github.com/vapor/validation.git
Fetching https://github.com/vapor/websocket.git
Fetching https://github.com/vapor/core.git
Fetching https://github.com/vapor/template-kit.git
Fetching https://github.com/vapor/sql.git
Fetching https://github.com/apple/swift-nio-ssl.git
Fetching https://github.com/dmcyk/SwiftyCurl.git
Fetching https://github.com/vapor/vapor.git
Fetching https://github.com/vapor/routing.git
Fetching https://github.com/vapor/http.git
Fetching /Users/sergej/Developer/Timetable-SPbU/SPbUappModels
Fetching https://github.com/apple/swift-nio.git
Fetching https://github.com/apple/swift-nio-zlib-support.git
Fetching https://github.com/vapor/service.git
Fetching https://github.com/vapor/url-encoded-form.git
Completed resolution in 18.38s
Cloning https://github.com/vapor/routing.git
Resolving https://github.com/vapor/routing.git at 3.0.1
Cloning https://github.com/vapor/core.git
Resolving https://github.com/vapor/core.git at 3.2.2
Cloning https://github.com/vapor/template-kit.git
Resolving https://github.com/vapor/template-kit.git at 1.0.1
Cloning https://github.com/vapor/validation.git
Resolving https://github.com/vapor/validation.git at 2.0.0
Cloning https://github.com/dmcyk/SwiftyCurl.git
Resolving https://github.com/dmcyk/SwiftyCurl.git at 1.0.0
Cloning /Users/sergej/Developer/Timetable-SPbU/SPbUappModels
Resolving /Users/sergej/Developer/Timetable-SPbU/SPbUappModels at master
Cloning https://github.com/Timetable-SPbU/TimetableSDK.git
Resolving https://github.com/Timetable-SPbU/TimetableSDK.git at master
Cloning https://github.com/broadwaylamb/Hammond.git
Resolving https://github.com/broadwaylamb/Hammond.git at master
Cloning https://github.com/apple/swift-nio-ssl.git
Resolving https://github.com/apple/swift-nio-ssl.git at 1.1.1
Cloning https://github.com/vapor/postgresql.git
Resolving https://github.com/vapor/postgresql.git at 1.0.0-rc.2.2.3
Cloning https://github.com/apple/swift-nio-zlib-support.git
Resolving https://github.com/apple/swift-nio-zlib-support.git at 1.0.0
Cloning https://github.com/dmcyk/CCurl.git
Resolving https://github.com/dmcyk/CCurl.git at 0.2.0
Cloning https://github.com/vapor/vapor.git
Resolving https://github.com/vapor/vapor.git at 3.0.4
Cloning https://github.com/apple/swift-nio.git
Resolving https://github.com/apple/swift-nio.git at 1.8.0
Cloning https://github.com/vapor/http.git
Resolving https://github.com/vapor/http.git at 3.0.7
Cloning https://github.com/vapor/sql.git
Resolving https://github.com/vapor/sql.git at 1.0.0
Cloning https://github.com/vapor/multipart.git
Resolving https://github.com/vapor/multipart.git at 3.0.1
Cloning https://github.com/vapor/websocket.git
Resolving https://github.com/vapor/websocket.git at 1.0.1
Cloning https://github.com/vapor/url-encoded-form.git
Resolving https://github.com/vapor/url-encoded-form.git at 1.0.3
Cloning https://github.com/vapor/fluent.git
Resolving https://github.com/vapor/fluent.git at 3.0.0-rc.2.4.1
Cloning https://github.com/vapor/console.git
Resolving https://github.com/vapor/console.git at 3.0.2
Cloning https://github.com/vapor/database-kit.git
Resolving https://github.com/vapor/database-kit.git at 1.0.1
Cloning https://github.com/vapor/fluent-postgresql.git
Resolving https://github.com/vapor/fluent-postgresql.git at 1.0.0-rc.2.3
Cloning https://github.com/vapor/crypto.git
Resolving https://github.com/vapor/crypto.git at 3.2.0
Cloning https://github.com/apple/swift-nio-ssl-support.git
Resolving https://github.com/apple/swift-nio-ssl-support.git at 1.0.0
Cloning https://github.com/vapor/service.git
Resolving https://github.com/vapor/service.git at 1.0.0
Compile CNIOLinux shim.c
Compile CNIOSHA1 c_nio_sha1.c
Compile CNIOOpenSSL empty.c
Compile CNIOHTTPParser c_nio_http_parser.c
Compile libbcrypt bcrypt.c
Compile CNIOZlib empty.c
Compile libbcrypt blf.c
Compile CNIODarwin shim.c
Compile Swift Module 'SPbUappModelsV1' (4 sources)
Compile Swift Module 'NIOPriorityQueue' (2 sources)
Compile Swift Module 'SQL' (35 sources)
Compile Swift Module 'Hammond' (4 sources)
Compile Swift Module 'Debugging' (3 sources)
Compile Swift Module 'COperatingSystem' (1 sources)
Compile CNIOAtomics src/c-atomics.c
Compile Swift Module 'NIOConcurrencyHelpers' (2 sources)

... here goes a bunch of compiler warnings due to the usage of `@_inlineable` in the swift-nio package

Compile Swift Module 'NIOOpenSSL' (11 sources)
Compile Swift Module 'Random' (4 sources)
Compile Swift Module 'Core' (24 sources)
Compile Swift Module 'NIOWebSocket' (8 sources)
Compile Swift Module 'Validation' (16 sources)
Compile Swift Module 'Logging' (4 sources)
Compile Swift Module 'Multipart' (8 sources)
Compile Swift Module 'URLEncodedForm' (8 sources)
Compile Swift Module 'Service' (20 sources)
Compile Swift Module 'HTTP' (23 sources)
Compile Swift Module 'Crypto' (13 sources)
Compile Swift Module 'Routing' (12 sources)
Compile Swift Module 'TemplateKit' (41 sources)
Compile Swift Module 'Console' (27 sources)
Compile Swift Module 'DatabaseKit' (29 sources)
Compile Swift Module 'WebSocket' (5 sources)
Compile Swift Module 'PostgreSQL' (55 sources)
Compile Swift Module 'Command' (16 sources)
Compile Swift Module 'Fluent' (56 sources)
Compile Swift Module 'Vapor' (76 sources)
Compile Swift Module 'FluentSQL' (15 sources)
Compile Swift Module 'FluentPostgreSQL' (15 sources)
Compile Swift Module 'ServerCore' (30 sources)
Compile Swift Module 'APIVersion1' (2 sources)
Compile Swift Module 'App' (3 sources)
Compile Swift Module 'Run' (1 sources)
Linking ./.build/x86_64-apple-macosx10.10/debug/Run
sergej@Sergejs-iMac Server (master) $ swift run Run
Illegal instruction: 4
sergej@Sergejs-iMac Server (master)

And pretty much the same when building using the generated Xcode project. Which crash log do you mean?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 6, 2018

Comment by Sergej Jaskiewicz (JIRA)

Oh, I see, there's a local dependency. I'm sorry. Gonna upload it and make a separate branch.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 6, 2018

Comment by Sergej Jaskiewicz (JIRA)

@mikeash I've fixed the problem, now it should build. Please use the `swift-4.2-crash` branch.

@mikeash
Copy link
Contributor

mikeash commented Jun 6, 2018

Thanks, that seems to work. I hit another problem later on but I think it's related to my local configuration. I'll keep at it.

@mikeash
Copy link
Contributor

mikeash commented Jun 15, 2018

Just to keep you in the loop, I'm still trying to track this down but I have been able to replicate the crash here, so that's quite helpful!

@bjhomer
Copy link
Contributor

bjhomer commented Jul 9, 2018

I ran into this issue as well on another project today; I've added myself as a watcher to keep updated on the status.

@mikeash
Copy link
Contributor

mikeash commented Jul 10, 2018

Your comment reminded me that I should post another update. I've identified the problem and the outlines of a solution, but I'm still figuring out the details. Meanwhile, another change in the compiler has kicked this code off the bad path and it no longer triggers the crash. I definitely want to fix the underlying problem but you may find some relief from that in the meantime.

@bjhomer
Copy link
Contributor

bjhomer commented Jul 17, 2018

@mikeash: It appears that the compiler change to kick this code off the bad path is not included in Xcode 10 beta 4. Is that expected?

@mikeash
Copy link
Contributor

mikeash commented Jul 18, 2018

Not expected! Here's my simple test case:

import Foundation

public struct Identifier<T> {
  var x: UUID
}

final class Address {
  var id: Identifier<Address>?
}

print(Address.self)

Does that one work for you? If so, any ideas what might be different about the project where you're still hitting the problem?

@bjhomer
Copy link
Contributor

bjhomer commented Jul 18, 2018

Your simple test case does work for me. I'll see if I can reduce my case down into something simpler.

@bjhomer
Copy link
Contributor

bjhomer commented Jul 18, 2018

Here's a test case that still fails:

import Foundation

enum MarkdownNode {

    case link(destination: URL, children: [MarkdownNode])
    
    static func test2() -> [MarkdownNode] {
        return []
    }
    
    static func test1() -> [MarkdownNode] {
        let nodes = MarkdownNode.test2()
        return nodes
    }
}

let result = MarkdownNode.test1()
print(result)

with this backtrace:

#&#8203;0 0x0000000100d311b1 in _dispatch_gate_wait_slow ()
#&#8203;1 0x00000001004c7989 in swift_once ()
#&#8203;2 0x00000001000022bf in type metadata accessor for MarkdownNode ()
#&#8203;3 0x0000000100002231 in type metadata accessor for [MarkdownNode] ()
#&#8203;4 0x0000000100002a10 in ___lldb_unnamed_symbol1$$test ()
#&#8203;5 0x0000000100d1fd8f in _dispatch_client_callout ()
#&#8203;6 0x0000000100d1fd6f in dispatch_once_f ()
#&#8203;7 0x00000001004c7989 in swift_once ()
#&#8203;8 0x00000001000022bf in type metadata accessor for MarkdownNode ()
#&#8203;9 0x0000000100002198 in static MarkdownNode.test2() ()
#&#8203;10 0x00000001000021e9 in static MarkdownNode.test1() at /Users/bjhomer/Desktop/test/test/main.swift:12

Update: Simplified the test case even further.

@mikeash
Copy link
Contributor

mikeash commented Jul 18, 2018

Perfect, thanks. I can confirm that your example crashes here as well. Hopefully I'll find a proper fix for all of it, but failing that I'll see if I can mitigate it consistently.

@rjmccall
Copy link
Member

Anyone seeing a bug like this that involves an enum can generally work around it by making a case indirect. That workaround won't work for a struct, though.

@rjmccall
Copy link
Member

I have a patch almost complete to fix this for value types.

@rjmccall
Copy link
Member

Value types (including BJ's test case) addressed by #18214

@belkadan
Copy link
Contributor

We think this is working on the swift-5.0-branch thanks to Slava's work back in August.

#18893
#18882
#18694

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 7, 2019

Comment by Matthaus Woolard (JIRA)

I seem to be getting this same crash (signal SIGABRT) on XCode Version 11.2.1 (11B53) (using swift 5) (only when running a release build on the iPad Pro (12.9-inch) (3rd generation) running iOS 13.2 (17B84) (we were not able to reproduce this on our phones)

For reference the line of code
```swift

print(JWT<JWTFields>.self)
```

The `JWT` type here is the struct from `https://github.com/IBM-Swift/Swift-JWT`.

```
Thread 3 Queue : com.test.purchases.serial (serial)
Thread 3 Queue : com.test.purchases.serial (serial)
#0 0x0000000187bd0efc in __pthread_kill ()
#1 0x0000000187af0d10 in pthread_kill ()
#2 0x0000000187a80a74 in abort ()
#3 0x00000001956d52a4 in swift_runtime_unreachable(char const*) ()
#4 0x00000001956d6e34 in swift_getWitnessTable ()
#5 0x0000000104e893d4 in lazy protocol witness table accessor for type JWTFields and conformance JWTFields [inlined] ()
#6 0x0000000104e893b4 in type metadata accessor for JWT<JWTFields> [inlined] ()
#7 0x0000000104e893a8 in specialized JWTProcessor.verifySignature(jwtString🙂 at *****/JWTProcessor.swift:28
#8 0x0000000104e5b480 in JWTProcessor.verifySignature(jwtString🙂 [inlined] ()
#9 0x0000000104e5b478 in specialized KeychainManager.checkKeychainLicense(completion🙂 at *****/KeychainManager.swift:63
#10 0x0000000104e4c360 in specialized KeychainManager.checkKeychainLicense(completion🙂 [inlined] ()
#11 0x0000000104e4c34c in closure
#3 in LicenseStateManager.checkLicenseState() at *****/LicenseStateManager.swift:85
#12 0x0000000104ea3a14 in thunk for @escaping @callee_guaranteed () -> () ()
#13 0x0000000105351e1c in _dispatch_call_block_and_release ()
#14 0x000000010535327c in _dispatch_client_callout ()
#15 0x000000010535a90c in _dispatch_lane_serial_drain ()
#16 0x000000010535b4fc in _dispatch_lane_invoke ()
#17 0x00000001053664dc in _dispatch_workloop_worker_thread ()
#18 0x0000000187af1a94 in _pthread_wqthread ()
```

@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 regression run-time crash Bug → crash: Swift code crashed during execution swift 4.2
Projects
None yet
Development

No branches or pull requests

6 participants