Skip to content

Commit ce43690

Browse files
committed
[AddressLowering] Handle existential_metatype.
The handling is the same as for value_metatype.
1 parent c3183d3 commit ce43690

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,11 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
26182618
vmi->setOperand(opAddr);
26192619
}
26202620

2621+
void visitExistentialMetatypeInst(ExistentialMetatypeInst *emi) {
2622+
SILValue opAddr = addrMat.materializeAddress(use->get());
2623+
emi->setOperand(opAddr);
2624+
}
2625+
26212626
void visitAddressOfBorrowBuiltinInst(BuiltinInst *bi, bool stackProtected) {
26222627
SILValue value = bi->getOperand(0);
26232628
SILValue addr = pass.valueStorageMap.getStorage(value).storageAddress;

test/SILOptimizer/opaque_values_Onone_stdlib.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1-
// RUN: %target-swift-frontend -parse-stdlib -enable-experimental-move-only -module-name main -enable-sil-opaque-values -parse-as-library -emit-sil -Onone %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -parse-stdlib -enable-experimental-move-only -module-name Swift -enable-sil-opaque-values -parse-as-library -emit-sil -Onone %s | %FileCheck %s
22

33
// Like opaque_values_Onone.swift but for code that needs to be compiled with
44
// -parse-stdlib.
55

6-
class X {}
6+
precedencegroup AssignmentPrecedence { assignment: true }
7+
precedencegroup CastingPrecedence {}
8+
9+
public protocol _ObjectiveCBridgeable {}
10+
11+
public protocol _ExpressibleByBuiltinBooleanLiteral {
12+
init(_builtinBooleanLiteral value: Builtin.Int1)
13+
}
14+
struct Bool : _ExpressibleByBuiltinBooleanLiteral {
15+
var _value: Builtin.Int1
16+
@_silgen_name("Bool_init_noargs")
17+
init()
18+
init(_ v: Builtin.Int1) { self._value = v }
19+
init(_ value: Bool) { self = value }
20+
init(_builtinBooleanLiteral value: Builtin.Int1) {
21+
self._value = value
22+
}
23+
}
724

25+
@_silgen_name("typeof")
26+
@_semantics("typechecker.type(of:)")
27+
public func type<T, Metatype>(of value: T) -> Metatype
28+
29+
class X {}
830
func consume(_ x : __owned X) {}
931

1032
func foo(@_noImplicitCopy _ x: __owned X) {
@@ -70,3 +92,8 @@ func toObject<T>(_ object: inout T) -> Builtin.BridgeObject {
7092
func getAnotherType<T, U>(_ object: inout T, to ty: U.Type) -> U {
7193
Builtin.reinterpretCast(object)
7294
}
95+
96+
@_silgen_name("isOfTypeOfAnyObjectType")
97+
func isOfTypeOfAnyObjectType(fromAny any: Any) -> Bool {
98+
type(of: any) is Builtin.AnyObject.Type
99+
}

0 commit comments

Comments
 (0)