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-11303] @Published causes compiler to crash when working with protocols #53704

Closed
swift-ci opened this issue Aug 14, 2019 · 4 comments
Closed
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

@swift-ci
Copy link
Collaborator

Previous ID SR-11303
Radar rdar://problem/54311335
Original Reporter chazza (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode beta 5, macOS 10.14.5, targeting iOS 13

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

md5: 16e95e48a27951facf31fcfa2877d5b4

is duplicated by:

  • SR-11264 Segmentation fault: 11 in Swift 5.1 compiler

Issue Description:

Minimum reproducible example:

import Combine
public protocol TestProtocol {}
public class TestClass<T> {
    @Published var value: T
    init<U: TestProtocol>(value: T, protocol: U) {
        self.value = value
    }
}

If you remove {code:swift}@published

@belkadan
Copy link
Contributor

On master-ish:

SIL verification failed: Operand is of an ArchetypeType that does not exist in the Caller's generic param list.: isArchetypeValidInFunction(A, F)
Verifying instruction:
     %7 = begin_borrow %6 : $TestClass<T>         // users: %23, %16, %10
->   %10 = ref_element_addr %7 : $TestClass<T>, #TestClass._value // user: %11
     %11 = begin_access [modify] [dynamic] %10 : $*Published<T> // users: %19, %18
In function:
// TestClass.init<A>(value:protocol:)
sil hidden [ossa] @$s4main9TestClassC5value8protocolACyxGx_qd__tcAA0B8ProtocolRd__lufc : $@convention(method) <T><U where U : TestProtocol> (@in T, @in U, @owned TestClass<T>) -> @owned TestClass<T> {

@swift-ci create

@DougGregor
Copy link
Member

Reproducer that takes Combine out of it:

@propertyWrapper
struct Published<Value> {
  var wrappedValue: Value
  
  init(initialValue: Value) {
    self.wrappedValue = initialValue
  }
}

public protocol TestProtocol {}

public class TestClass<T> {
    @Published var value: T
    init<U: TestProtocol>(value: T, protocol: U) {
        self.value = value
    }
} 

@theblixguy
Copy link
Collaborator

Slightly smaller reproducer that doesn't involve protocols:

@propertyWrapper 
struct Published<Value> {
  var wrappedValue: Value
  init(wrappedValue: Value) {
    self.wrappedValue = wrappedValue
  }
}

public class TestClass<T> {
  @Published var value: T
  init<U>(_:U) {
    self.value = 0 as! T
  }
} 

Seems like the root of the archetype has only T in the generic environment, where as the constructor's generic environment has both T & U.

@DougGregor
Copy link
Member

Yeah, that's the issue. The fix is at #27257

@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