Skip to content

Commit 3caf508

Browse files
committed
Disable the TrivialMoveOnlyTypeEliminator pass.
This fixes the `consuming` and `borrowing` keywords for some basic cases. In particular, if a nontrivial struct contains a trivial 'let' field, then this pass would result in invalid SIL types: class C {} struct BV { let p: UnsafeRawPointer let c: C } func getPointer(bv: consuming BV) -> UnsafeRawPointer { return bv.p } Ultimately, this pass makes sense, but there is something strange about the way move-only-ness propagates into fields of aggregates which needs to be fixed first. Until then, other features are blocked on basic support for these keywords. Fixes rdar://122701694 (`consuming` keyword causes verification error on invalid SIL types)
1 parent 21fd18f commit 3caf508

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,22 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
174174
if (EnableDeinitDevirtualizer)
175175
P.addDeinitDevirtualizer();
176176

177+
// FIXME: rdar://122701694 (`consuming` keyword causes verification error on
178+
// invalid SIL types)
179+
//
177180
// Lower move only wrapped trivial types.
178-
P.addTrivialMoveOnlyTypeEliminator();
181+
// P.addTrivialMoveOnlyTypeEliminator();
182+
179183
// Check no uses after consume operator of a value in an address.
180184
P.addConsumeOperatorCopyableAddressesChecker();
181185
// No uses after consume operator of copyable value.
182186
P.addConsumeOperatorCopyableValuesChecker();
183187

188+
// As a temporary measure, we also eliminate move only for non-trivial types
189+
// until we can audit the later part of the pipeline. Eventually, this should
190+
// occur before IRGen.
191+
P.addMoveOnlyTypeEliminator();
192+
184193
//
185194
// End Ownership Optimizations
186195
//===---
@@ -246,11 +255,6 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
246255
// Canonical swift requires all non cond_br critical edges to be split.
247256
P.addSplitNonCondBrCriticalEdges();
248257

249-
// As a temporary measure, we also eliminate move only for non-trivial types
250-
// until we can audit the later part of the pipeline. Eventually, this should
251-
// occur before IRGen.
252-
P.addMoveOnlyTypeEliminator();
253-
254258
// For embedded Swift: Specialize generic class vtables.
255259
P.addVTableSpecializer();
256260

test/SILOptimizer/noimplicitcopy_consuming_parameters.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Klass {
99

1010
public struct NonTrivialStruct {
1111
var k = Klass()
12+
let i = 0
1213

1314
func doSomethingDefault() {}
1415
borrowing func doSomethingBorrowing() {}
@@ -230,6 +231,10 @@ func testLoadableConsumingCopyOperator(_ x: consuming NonTrivialStruct) {
230231
_ = copy x
231232
}
232233

234+
func testLoadableConsumingTrivialLetField(_ x: consuming NonTrivialStruct) -> Int {
235+
return x.i
236+
}
237+
233238
//////////////////////////////////////////
234239
// MARK: Trivial Struct Consuming Tests //
235240
//////////////////////////////////////////

0 commit comments

Comments
 (0)