Skip to content

Commit 333737b

Browse files
committed
[sil] Remove usage from TypeLowering of SILBuilder::create*AndFold().
These create*AndFold APIs are actively harmful when used in TypeLowering since: 1. In general they are a problem since it is weird for a builder API to remove an instruction. 2. These APIs do not take an erase callback that must be used in passes that need to update state before erasing the instruction. 3. The typelowering APIs that use this are emitDestroyValue/etc which are the main APIs that we are using to write code that works with OSSA/non-OSSA SIL. So we are going to use these APIs in many more places, introducing this bug in many places. With that in mind, I have been committing small cheap ARC optimizations to GuaranteedARCOpts (SemanticARCOpts with expensive optimizations turned off) so that we can eliminate this without massively churning the code. We are at this stage now, so it makes sense to turn this off.
1 parent 3ef6fba commit 333737b

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ namespace {
10761076
return;
10771077
}
10781078

1079-
B.emitReleaseValueAndFold(loc, aggValue);
1079+
B.createReleaseValue(loc, aggValue, B.getDefaultAtomicity());
10801080
}
10811081

10821082
void
@@ -1254,7 +1254,7 @@ namespace {
12541254
B.createDestroyValue(loc, value);
12551255
return;
12561256
}
1257-
B.emitReleaseValueAndFold(loc, value);
1257+
B.createReleaseValue(loc, value, B.getDefaultAtomicity());
12581258
}
12591259

12601260
void emitLoweredDestroyValue(SILBuilder &B, SILLocation loc, SILValue value,
@@ -1415,7 +1415,7 @@ namespace {
14151415
B.createDestroyValue(loc, value);
14161416
return;
14171417
}
1418-
B.emitStrongReleaseAndFold(loc, value);
1418+
B.createStrongRelease(loc, value, B.getDefaultAtomicity());
14191419
}
14201420
};
14211421

@@ -1501,13 +1501,13 @@ namespace {
15011501
void emitDestroyAddress(SILBuilder &B, SILLocation loc,
15021502
SILValue addr) const override {
15031503
if (!isTrivial())
1504-
B.emitDestroyAddrAndFold(loc, addr);
1504+
B.createDestroyAddr(loc, addr);
15051505
}
15061506

15071507
void emitDestroyRValue(SILBuilder &B, SILLocation loc,
15081508
SILValue value) const override {
15091509
if (!isTrivial())
1510-
B.emitDestroyAddrAndFold(loc, value);
1510+
B.createDestroyAddr(loc, value);
15111511
}
15121512

15131513
SILValue emitCopyValue(SILBuilder &B, SILLocation loc,

test/SILGen/unsafevalue.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public struct UnsafeValue<Element: AnyObject> {
4545
// CANONICAL-LABEL: sil [transparent] [serialized] @$s11unsafevalue11UnsafeValueV14unsafelyAssignACyxGxh_tcfC : $@convention(method) <Element where Element : AnyObject> (@guaranteed Element, @thin UnsafeValue<Element>.Type) -> UnsafeValue<Element> {
4646
// CANONICAL: bb0([[INPUT_ELEMENT:%.*]] : $Element,
4747
// CANONICAL-NEXT: debug_value
48+
// CANONICAL-NEXT: strong_retain [[INPUT_ELEMENT]]
4849
// CANONICAL-NEXT: [[UNMANAGED_ELEMENT:%.*]] = ref_to_unmanaged [[INPUT_ELEMENT]]
50+
// CANONICAL-NEXT: strong_release [[INPUT_ELEMENT]]
4951
// CANONICAL-NEXT: [[RESULT:%.*]] = struct $UnsafeValue<Element> ([[UNMANAGED_ELEMENT]] : $@sil_unmanaged Element)
5052
// CANONICAL-NEXT: return [[RESULT]]
5153
// CANONICAL: } // end sil function '$s11unsafevalue11UnsafeValueV14unsafelyAssignACyxGxh_tcfC'

test/SILOptimizer/mem2reg_resilient.sil

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ public struct ResilientStruct {
88
var x: AnyObject
99
}
1010

11-
// CHECK-LABEL: sil @mem2reg_debug_value_addr
11+
// CHECK-LABEL: sil @mem2reg_debug_value_addr :
1212
// CHECK: bb0(%0 : $*ResilientStruct):
13-
// CHECK-NEXT: %1 = load %0 : $*ResilientStruct
14-
// CHECK-NEXT: debug_value %1 : $ResilientStruct
15-
// CHECK-NEXT: %3 = tuple ()
16-
// CHECK-NEXT: return %3 : $()
17-
13+
// CHECK-NEXT: %1 = load %0
14+
// CHECK-NEXT: retain_value %1
15+
// CHECK-NEXT: debug_value %1
16+
// CHECK-NEXT: release_value %1
17+
// CHECK-NEXT: tuple ()
18+
// CHECK-NEXT: return {{%.*}} : $()
19+
// CHECK: } // end sil function 'mem2reg_debug_value_addr'
1820
sil @mem2reg_debug_value_addr : $@convention(thin) (@in_guaranteed ResilientStruct) -> () {
1921
bb0(%0 : $*ResilientStruct):
2022
%1 = alloc_stack $ResilientStruct

test/SILOptimizer/ownership_model_eliminator_resilience.sil

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// RUN: %target-sil-opt -ownership-model-eliminator -enable-library-evolution %s | %FileCheck %s
32

43
// copy_value and destroy_value operations are lowered away, except for
@@ -36,7 +35,9 @@ bb0(%0 : @guaranteed $Saddle):
3635
// CHECK: bb0(%0 : $Saddle):
3736
// CHECK: strong_retain %0 : $Saddle
3837
// CHECK: %2 = enum $Animal, #Animal.horse!enumelt, %0 : $Saddle
39-
// CHECK: release_value %2 : $Animal
40-
// CHECK: %4 = tuple ()
41-
// CHECK: return %4 : $()
38+
// CHECK: retain_value %2
39+
// CHECK: release_value %2
40+
// CHECK: release_value %2
41+
// CHECK: %6 = tuple ()
42+
// CHECK: return %6 : $()
4243
// CHECK: }

0 commit comments

Comments
 (0)