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-8341] Finish recursive metadata support for resilient types #50869

Closed
tkrajacic opened this issue Jul 22, 2018 · 6 comments
Closed

[SR-8341] Finish recursive metadata support for resilient types #50869

tkrajacic opened this issue Jul 22, 2018 · 6 comments

Comments

@tkrajacic
Copy link

@tkrajacic tkrajacic commented Jul 22, 2018

Previous ID SR-8341
Radar rdar://problem/42504962
Original Reporter @tkrajacic
Type Bug
Status Closed
Resolution Duplicate

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, RunTimeCrash
Assignee @jckarter
Priority Medium

md5: 3922fd6b016c1a251c7cb810b0c9a92a

duplicates:

  • SR-7876 Runtime crash on 'type metadata accessor for %Typename%'

Issue Description:

Attached is an example project. The code does work within a playground so I suppose it has to do with module boundaries.

Given:

import Foundation

public struct Property: Equatable, Hashable {
    public var key: String
    public var value: PropertyValue<Property>
}

public enum PropertyValue<P>: Equatable, Hashable where P: Equatable & Hashable {
    case boolValue(Bool?)
    case multipleValues(values: [P], options: String)
    case flight(code: String?, date: Date?)
}

When I just create an instance in the unit test bundle (Just press Command + U in the sample)

@testable import GenericEnumBug
import XCTest

final class PropertyValueTests: XCTestCase {
    func testEquality() {
        
        let p = PropertyValue<Property>.boolValue(true)
        
    }
}

I get a runtime crash with the stack showing

#&#8203;0 0x00007fff66928d1e in _dispatch_gate_wait_slow ()
#&#8203;1 0x0000000109b1d0f9 in swift_once ()
#&#8203;2 0x00000001025e5d0f in type metadata accessor for Property ()
#&#8203;3 0x00000001025e60f1 in type metadata accessor for PropertyValue<Property> ()
#&#8203;4 0x00000001025ea536 in ___lldb_unnamed_symbol1$$GenericEnumBug ()
#&#8203;5 0x00007fff66918db8 in _dispatch_client_callout ()
#&#8203;6 0x00007fff66918d6b in dispatch_once_f ()
#&#8203;7 0x0000000109b1d0f9 in swift_once ()
#&#8203;8 0x00000001025e5d0f in type metadata accessor for Property ()
#&#8203;9 0x00000001025da701 in type metadata accessor for PropertyValue<Property> ()
#&#8203;10 0x00000001025da66a in PropertyValueTests.testEquality() ()
#&#8203;11 0x00000001025da964 in @objc PropertyValueTests.testEquality() ()

This is in the latest Xcode 10 b4 and also with the latest Swift 4.2 toolchain from 22.July.

The runtime crash goes away as soon as I remove the `date: Date?` parameter from the one case of the enum.

That was seriously annoying to track down and I remember having already had one problem with a Date property once. So I wonder: What the heck is up with `Date`s and the Swift runtime? 🙂

See SR-7221

/cc @belkadan @slavapestov

I really want this in Swift 4.2! ❤️

@tkrajacic
Copy link
Author

@tkrajacic tkrajacic commented Jul 22, 2018

Oh, btw the same problem appears with `DateComponents`.

@tkrajacic
Copy link
Author

@tkrajacic tkrajacic commented Jul 22, 2018

Mhm, and it seems on my larger un-reduced project I also have a problem when I don't use Date or DateComponents. Oh boy…
I'll try to figure out more in the small test-project, but the error is always the same it seems.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Jul 23, 2018

I'd suspect it's a problem with resilient types, which we're mostly only using in Foundation right now.

@swift-ci create

@rjmccall
Copy link
Member

@rjmccall rjmccall commented Jul 23, 2018

That is definitely the same bug where in-place metadata initialization doesn't use the general metadata-construction infrastructure that supports recursive dependencies.

There should be an easy workaround, which is to make the case involving resilient library types (`Date`, `Data`, etc.) `indirect`.

@tkrajacic
Copy link
Author

@tkrajacic tkrajacic commented Jul 23, 2018

@rjmccall, @belkadan The workaround worked wonderfully.

I tried it before but forgot that all cases with any types from Foundation need to be annotated, so I gave up too early 🙂.

I really wonder though how this can not have been discovered before by other users. This seems like quite the mundane use case.

Anyway, you guys rock! Thx for even providing me with a workaround. ❤️

@tkrajacic
Copy link
Author

@tkrajacic tkrajacic commented Sep 14, 2018

I tested this is Xcode 10 and Swift 4.2 and can confirm this is fixed.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants