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-8107] Compiler crash "TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT" in Swift 4.2 #50639

Closed
lilyball mannequin opened this issue Jun 25, 2018 · 9 comments
Closed

[SR-8107] Compiler crash "TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT" in Swift 4.2 #50639

lilyball mannequin opened this issue Jun 25, 2018 · 9 comments

Comments

@lilyball
Copy link
Mannequin

@lilyball lilyball mannequin commented Jun 25, 2018

Previous ID SR-8107
Radar rdar://problem/41474371
Original Reporter @lilyball
Type Bug
Status Closed
Resolution Done
Environment

Xcode 10.0 (10L177m)
Apple Swift version 4.2-dev (LLVM b1d038f9d7, Clang 83813a3b3b, Swift 1e07724)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, CompilerCrash, SILGen
Assignee @lilyball
Priority Medium

md5: 79ca28deff985aba0a1cc528d1f21cb9

Issue Description:

When compiling my Swift 4 app with the latest Swift 4.2 toolchain I get a compiler crash

TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT <<debugloc at "<compiler-generated>":0:0>>  argument value:   %6 = partial_apply [callee_guaranteed] %5<Value, Error, ObjcValue, ObjcError>(%4) : $@convention(thin) @pseudogeneric <τ_0_0, τ_0_1><τ_1_0, τ_1_1 where τ_1_0 : AnyObject, τ_1_1 : AnyObject> (@guaranteed @callee_guaranteed (@guaranteed ObjcBox<τ_0_0>) -> (), @guaranteed @callee_guaranteed (@guaranteed ObjcBox<τ_0_1>) -> (), @guaranteed @convention(block) (@convention(block) (ObjcBox<τ_0_0>) -> (), @convention(block) (ObjcBox<τ_0_1>) -> ()) -> ()) -> ()
  parameter type: $@callee_guaranteed (@guaranteed @callee_guaranteed (@guaranteed ObjcBox<Value>) -> (), @guaranteed @callee_guaranteed (@guaranteed ObjcBox<Error>) -> ()) -> ()

[…stack trace…]

1.  While silgen emitConstructor SIL function "@$S12Tomorrowland7PromiseV9TwitchKitE9_bridging12resultMapperACyxq_GSo8TWFutureCyqd__qd_0_G_So08TWResultG0CyAD7ObjcBox33_DA7F7CEE4B414290E144F07A4CB20784LLCyxGAOyq_Gqd__qd_0_GtcRld__CRld_0_Cr0_luANLlfC".
 for 'init(_bridging:resultMapper:)' at /Users/eridius/Dev/Twitch/twitch-iphone/Twitch.tv/Code/TwitchKit/TwitchKit/TwitchKit/Tomorrowland/Tomorrowland+TWSReactive.swift:119:13
2.  While silgen closureexpr SIL function "@$S12Tomorrowland7PromiseV9TwitchKitE9_bridging12resultMapperACyxq_GSo8TWFutureCyqd__qd_0_G_So08TWResultG0CyAD7ObjcBox33_DA7F7CEE4B414290E144F07A4CB20784LLCyxGAOyq_Gqd__qd_0_GtcRld__CRld_0_Cr0_luANLlfcyAC8ResolverVyxq__GcfU_".
 for expression at [/Users/eridius/Dev/Twitch/twitch-iphone/Twitch.tv/Code/TwitchKit/TwitchKit/TwitchKit/Tomorrowland/Tomorrowland+TWSReactive.swift:120:35 - line:133:9] RangeText="{ (resolver) in
            let completion = resultMapper.flatMapFuture(future, onCancel: {
                resolver.cancel()
            }).onComplete({ (resultSwitchBlock) in
                resultSwitchBlock({ (value) in
                    resolver.fulfill(with: value.value)
                }, { (error) in
                    resolver.reject(with: error.value)
                })
            })
            resolver.onRequestCancel(on: .main, { (_) in
                completion.cancel()
            })
        }"

The source code looks like

extension Promise {
    private init<ObjcValue, ObjcError>(_bridging future: TWFuture<ObjcValue, ObjcError>, resultMapper: TWResultMapper<ObjcBox<Value>, ObjcBox<Error>, ObjcValue, ObjcError>) {
        self.init(on: .immediate, { (resolver) in
            let completion = resultMapper.flatMapFuture(future, onCancel: {
                resolver.cancel()
            }).onComplete({ (resultSwitchBlock) in
                resultSwitchBlock({ (value) in
                    resolver.fulfill(with: value.value)
                }, { (error) in
                    resolver.reject(with: error.value)
                })
            })
            resolver.onRequestCancel(on: .main, { (_) in
                completion.cancel()
            })
        })
    }
}

If it matters, TWFuture and TWResultMapper are Obj-C types, and ObjcBox is a thin wrapper (to deal with the fact that Obj-C generics require AnyObject) that looks like

private class ObjcBox<T> {
    let value: T
    
    init(_ value: T) {
        self.value = value
    }
}
@belkadan
Copy link
Contributor

@belkadan belkadan commented Jun 26, 2018

This looks familiar but I don't know if we have a bug for it already.

@swift-ci create

@jckarter
Copy link
Member

@jckarter jckarter commented Jun 26, 2018

Is `Promise` also an ObjC class in this example?

@lilyball
Copy link
Mannequin Author

@lilyball lilyball mannequin commented Jun 26, 2018

No, Promise is a Swift struct (that wraps a Swift class that inherits from an Obj-C class). The Promise type comes from https://github.com/kballard/Tomorrowland.

@lilyball
Copy link
Mannequin Author

@lilyball lilyball mannequin commented Jun 26, 2018

Also if it makes a difference, Promise is defined in a different module from the code that triggers the crash. Promise comes from Tomorrowland.framework, which is a dependency of TwitchKit.framework which is where the crashing code resides.

@jckarter
Copy link
Member

@jckarter jckarter commented Jun 26, 2018

Thanks. I was able to reproduce after adding these declarations to an ObjC header in a project:

@interface TWCompletion

- (void)cancel;

@end

@interface TWFuture<Value, Error>: NSObject

- (TWCompletion*)onComplete: (void (^)(void(^)(void (^)(Value), void (^)(Error))))completeBlock;

@end

@interface TWResultMapper<Value1, Error1, Value2, Error2>: NSObject

- (TWFuture<Value1, Error1>*)flatMapFuture:(TWFuture<Value2, Error2>*)x onCancel: (void(^)(void))y;

@end

@jckarter
Copy link
Member

@jckarter jckarter commented Jun 27, 2018

PR for master: #17547
PR for 4.2: #17548

@jckarter
Copy link
Member

@jckarter jckarter commented Jun 27, 2018

Merged. Should be fixed in future seeds.

@AnnaZaks
Copy link
Mannequin

@AnnaZaks AnnaZaks mannequin commented Aug 4, 2018

Eridius (JIRA User), Could you verify if the problem is fixed and if so move the JIRA to "Closed"?
Thanks!
Anna

@lilyball
Copy link
Mannequin Author

@lilyball lilyball mannequin commented Aug 5, 2018

Xcode 10 beta 5 is able to compile all of the Swift code in my app at this point, so it appears as though this issue 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

2 participants