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-8730] Illegal instruction: 4; While emitting SIL for getter #51239

Closed
swift-ci opened this issue Sep 12, 2018 · 2 comments
Closed

[SR-8730] Illegal instruction: 4; While emitting SIL for getter #51239

swift-ci opened this issue Sep 12, 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-8730
Radar None
Original Reporter rshev (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

MacOS 10.13.6

Xcode 10 beta 6

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

md5: a5ddac2b086e227cf5b8602b57ce1fd6

duplicates:

  • SR-5581 Proper support for protocol 'where' clause with constraints on 'Self'

Issue Description:

Happens every time while compiling this:

import UIKit

protocol NibLoadable where Self: UIView {
    static var nibName: String { get }
}

extension NibLoadable {
    static var nibName: String {
        return String(describing: self)
    }

    static func instantiateFromNib() -> Self {
        return UINib(nibName: nibName, bundle: nil).instantiate(withOwner: nil, options: nil).first as! Self
    }
}

final class ReusableCollectionViewCell<View>: UICollectionViewCell where View: UIView {
    lazy var wrappedView: View = {
        let view: View
        if let NibView = View.self as? NibLoadable.Type {
            view = NibView.instantiateFromNib() as! View       // <- this line 
        } else {
            view = View(frame: .zero)
        }
        // ...
        return view
    }()
}

Happens when the marked line is added, with the following error:

1.  While emitting SIL for getter for wrappedView at /Users/asdfgh1/tmp/SwiftBug/SwiftBug/Bug.swift:18:14
2.  While silgen emitFunction SIL function "@$S8SwiftBug26ReusableCollectionViewCellC07wrappedE0xvg".
 for getter for wrappedView at /Users/asdfgh1/tmp/SwiftBug/SwiftBug/Bug.swift:18:14
3.  While silgen closureexpr SIL function "@$S8SwiftBug26ReusableCollectionViewCellC07wrappedE0xvgxyXEfU_".
 for expression at [/Users/asdfgh1/tmp/SwiftBug/SwiftBug/Bug.swift:18:34 - line:27:5] RangeText="{
        let view: View
        if let NibView = View.self as? NibLoadable.Type {
            view = NibView.instantiateFromNib() as! View
        } else {
            view = View(frame: .zero)
        }
        // ...
        return view
    }"
error: Illegal instruction: 4

Please find the test project attached.

@belkadan
Copy link
Contributor

Non-iOS version:

import Foundation

protocol NibLoadable where Self: NSObject {
    static var nibName: String { get }
}

extension NibLoadable {
    static var nibName: String {
        return String(describing: self)
    }

    static func instantiateFromNib() -> Self {
      fatalError()
    }
}

final class ReusableCollectionViewCell<View>: NSObject where View: NSObject {
    lazy var wrappedView: View = {
        let view: View
        if let NibView = View.self as? NibLoadable.Type {
            view = NibView.instantiateFromNib() as! View
        } else {
          fatalError()
        }
        // ...
        return view
    }()
}

@belkadan
Copy link
Contributor

It seems to work on master, so I'm going to put this into the bucket of "constraining to a protocol to a particular class type using where clauses was mostly unimplemented in Swift 4.2 and shouldn't have been allowed yet". You can get nearly the same effect by moving the where Self: UIView to the protocol extension and then casting to (UIView & NibLoadable).Type.

@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

3 participants