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-1329] LLVM error when assigning protocol function to variable #43937

Closed
josephlord opened this issue Apr 26, 2016 · 6 comments
Closed

[SR-1329] LLVM error when assigning protocol function to variable #43937

josephlord opened this issue Apr 26, 2016 · 6 comments
Assignees
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

Comments

@josephlord
Copy link

Previous ID SR-1329
Radar None
Original Reporter @josephlord
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 7.3 (iOS and OS X SDKs)

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

md5: dee8c4a049fee4f9304cb69708b59296

relates to:

  • SR-75 Referencing a protocol function crashes the compiler

Issue Description:

I know this might not be valid and may become a normal error in Swift 3 but I thought I should report it anyway.

import Foundation

@objc protocol TestProtocol {
    func foo(i: Int)
}

class Test : TestProtocol {
    @objc func foo(i: Int) {
    }
}

func bar(t: TestProtocol?) {
    let foofunc = t?.foo
    foofunc?(5)
}

Results in:

xcrun -sdk macosx swiftc -v main.swift
Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)
Target: x86_64-apple-macosx10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file main.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name main -o /var/folders/n7/l0f7j3655lz047816hj6p3mr0000gn/T/main-014dff.o
Incorrect number of arguments passed to called function!
  call void @_TTOFP4main12TestProtocol3foofSiT_(i64 %0, %objc_object* %6) #​0
LLVM ERROR: Broken function found, compilation aborted!

This was quite hard to find in a big project. I needed to do command line build with -j1

This may be related to SR-44 but it didn't seem to match completely.

@belkadan
Copy link
Contributor

In a debug build:

Assertion failed: (false && "partial_apply of foreign functions not implemented"), function getPartialApplicationFunction, file /Volumes/Data/swift-public/swift/lib/IRGen/IRGenSIL.cpp, line 2069.

@slavapestov?

@slavapestov
Copy link
Member

This specific issue should be easy to fix. We actually do support emitting something very similar to this, a dynamic call on an AnyObject. In this case, even if the call is not curried we partial_apply the result of the method lookup and wrap it in an optional.

Really IRGen's code path for partial_apply should go away altogether, in favor of generalizing curry thunks in SILGen.

I'll take this one...

@slavapestov
Copy link
Member

@josephlord Oh, just to be 100% clear, any time the compiler crashes without producing a diagnostic is our fault and definitely a bug :-) The general design is that any invalid code must be caught in the type checker or early in SILGen; anything blowing up in IRGen means another part of the compiler screwed up. Also, SR-44 is a different issue, and appears to have been fixed.

@josephlord
Copy link
Author

Thanks @slavapestov. I thought that was probably the case but wasn't absolutely sure as it wasn't a swiftc crash as such. I was glad I could reduce it to a simple case.

@dabrahams
Copy link
Collaborator

I just repro'd this by mistake

@slavapestov
Copy link
Member

No longer crashes. I'm adding a regression test

@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
Projects
None yet
Development

No branches or pull requests

5 participants