Skip to content

Commit c3fb137

Browse files
Merge pull request #67752 from nate-chandler/opaque-values/20230804/1/any-hashable-var
[OpaqueValues] Emit RValue of AnyHashable erasure into new context.
2 parents 9d5b175 + 999f2b0 commit c3fb137

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/SILGen/SILGenExpr.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2059,10 +2059,10 @@ RValue RValueEmitter::visitAnyHashableErasureExpr(AnyHashableErasureExpr *E,
20592059
auto sourceOrigType = AbstractionPattern::getOpaque();
20602060
auto subExpr = E->getSubExpr();
20612061
auto &sourceOrigTL = SGF.getTypeLowering(sourceOrigType, subExpr->getType());
2062-
auto source =
2063-
SGF.silConv.useLoweredAddresses()
2064-
? SGF.emitMaterializedRValueAsOrig(subExpr, sourceOrigType)
2065-
: SGF.emitRValueAsOrig(subExpr, sourceOrigType, sourceOrigTL, C);
2062+
auto source = SGF.silConv.useLoweredAddresses()
2063+
? SGF.emitMaterializedRValueAsOrig(subExpr, sourceOrigType)
2064+
: SGF.emitRValueAsOrig(subExpr, sourceOrigType,
2065+
sourceOrigTL, SGFContext());
20662066

20672067
return SGF.emitAnyHashableErasure(E, source, subExpr->getType(),
20682068
E->getConformance(), C);

test/SILGen/opaque_values_silgen.swift

+22
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,25 @@ func callMutatingFooOnInoutExistential(_ i: inout any MutatingFooable) {
760760
struct WeakBox<T : AnyObject> {
761761
weak var t: T?
762762
}
763+
764+
// CHECK-LABEL: sil {{.*}}[ossa] @intIntoAnyHashableVar : {{.*}} {
765+
// CHECK: [[VAR_BOX_ADDR:%[^,]+]] = project_box
766+
// CHECK: [[INT:%[^,]+]] = apply
767+
// CHECK: [[CONVERT:%[^,]+]] = function_ref @$ss21_convertToAnyHashableys0cD0VxSHRzlF
768+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[CONVERT]]<Int>([[INT]])
769+
// CHECK: store [[INSTANCE]] to [init] [[VAR_BOX_ADDR]]
770+
// CHECK-LABEL: } // end sil function 'intIntoAnyHashableVar'
771+
@_silgen_name("intIntoAnyHashableVar")
772+
func intIntoAnyHashableVar() {
773+
var anyHashable: AnyHashable = 0
774+
}
775+
776+
// CHECK-LABEL: sil {{.*}}[ossa] @intIntoAnyHashableLet : {{.*}} {
777+
// CHECK: [[INT:%[^,]+]] = apply
778+
// CHECK: [[CONVERT:%[^,]+]] = function_ref @$ss21_convertToAnyHashableys0cD0VxSHRzlF
779+
// CHECK: [[INSTANCE:%[^,]+]] = apply [[CONVERT]]<Int>([[INT]])
780+
// CHECK-LABEL: } // end sil function 'intIntoAnyHashableLet'
781+
@_silgen_name("intIntoAnyHashableLet")
782+
func intIntoAnyHashableLet() {
783+
let anyHashable: AnyHashable = 0
784+
}

0 commit comments

Comments
 (0)