Files
swift-mirror/validation-test/compiler_crashers_2_fixed/rdar138655637.swift
Slava Pestov 1acb61d23a SIL: Fix SILType::isLoweringOf() to correctly handle opaque archetypes
This predicate is meant to ask if the loweredType is equal to
`getLoweredType(pattern, formalType)` for *some* abstraction pattern.

If the formal type contained an opaque archetype, we performed a
different check, because we asked if loweredEqual is equal to
`getLoweredType(AbstractionPattern(formalType), formalType)`.

This caused a spurious SIL verifier failure when the payload of an
existential contained an opaque archetype, because we lower the
payload with the most general AbstractionPattern, so that
@thin metatypes become @thick, etc.

The regression test exercises this bug, and also another bug that was
present in 6.0 but was already fixed on main by one of my earlier
refactorings.

Fixes rdar://problem/138655637.
2024-10-30 13:19:46 -04:00

111 lines
2.2 KiB
Swift

// RUN: %target-swift-frontend -emit-ir -target %target-swift-5.9-abi-triple %s
protocol P {
var p: Int { get }
}
protocol Q {
func p(content: Int) -> Int
}
struct Zero: P {
var p: Int { 0 }
}
struct One: P {
var p: Int { 1 }
}
struct Add: Q {
let rhs: Int
func p(content: Int) -> Int {
content + rhs
}
}
struct Multiply: Q {
let rhs: Int
func p(content: Int) -> Int {
content * rhs
}
}
struct G<Content: P, each Modifier: Q>: P {
var content: Content
var modifiers: (repeat each Modifier)
init(content: Content, modifiers: (repeat each Modifier)) {
self.content = content
self.modifiers = modifiers
}
var p: Int {
var r = content.p
for m in repeat each modifiers {
r = m.p(content: r)
}
return r
}
}
extension G: Equatable where Content: Equatable,
repeat each Modifier: Equatable
{
static func ==(lhs: Self, rhs: Self) -> Bool {
guard lhs.content == rhs.content else { return false}
for (left, right) in repeat (each lhs.modifiers, each rhs.modifiers) {
guard left == right else { return false }
}
return true
}
}
extension G {
func modifier<T>(_ modifier: T) -> G<Content, repeat each Modifier, T> {
.init(content: content, modifiers: (repeat each modifiers, modifier))
}
func add(_ rhs: Int) -> G<Content, repeat each Modifier, some Q> {
modifier(Add(rhs: rhs))
}
func multiply(_ rhs: Int) -> G<Content, repeat each Modifier, some Q> {
modifier(Multiply(rhs: rhs))
}
}
extension P {
func modifier<T>(_ modifier: T) -> G<Self, T> {
return G(content: self, modifiers: modifier)
}
func add(_ rhs: Int) -> G<Self, some Q> {
modifier(Add(rhs: rhs))
}
func multiply(_ rhs: Int) -> G<Self, some Q> {
modifier(Multiply(rhs: rhs))
}
}
public func test() {
let r = Zero()
.multiply(1)
.multiply(2)
.add(3)
.multiply(4)
.add(2)
.multiply(6)
.add(2)
.multiply(6)
.add(2)
.multiply(6)
print(type(of: r))
}
test()