Skip to content

Commit 4f034f0

Browse files
authored
Merge pull request #64076 from jckarter/dont-di-consuming-box
SILGen: Don't DI the box for `consuming` parameters.
2 parents 2a7aa37 + 643efd0 commit 4f034f0

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,9 @@ struct ArgumentInitHelper {
445445
} else if (!pd->isImmutableInFunctionBody()) {
446446
// If it's a locally mutable parameter, then we need to move the argument
447447
// value into a local box to hold the mutated value.
448+
// We don't need to mark_uninitialized since we immediately initialize.
448449
auto mutableBox = SGF.emitLocalVariableWithCleanup(pd,
449-
MarkUninitializedInst::Var);
450+
/*uninitialized kind*/ None);
450451
argrv.ensurePlusOne(SGF, loc).forwardInto(SGF, loc, mutableBox.get());
451452
return;
452453
}

test/SILGen/consuming_parameter.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ func bar(_: String) {}
66
func foo(y: consuming String, z: String) -> () -> String {
77
// CHECK: bb0(%0 : @owned $String, %1 : @guaranteed $String):
88
// CHECK: [[BOX:%.*]] = alloc_box ${ var String }
9-
// CHECK: [[BOX0:%.*]] = mark_uninitialized [var] [[BOX]]
10-
// CHECK: [[BOX1:%.*]] = begin_borrow [lexical] [[BOX0]]
9+
// CHECK: [[BOX1:%.*]] = begin_borrow [lexical] [[BOX]]
1110
// CHECK: [[Y:%.*]] = project_box [[BOX1]]
1211
// CHECK: store %0 to [init] [[Y]]
1312

@@ -37,8 +36,7 @@ struct Butt {
3736
consuming func merged(with other: Butt) -> () -> Butt {
3837
// CHECK: bb0(%0 : @guaranteed $Butt, %1 : @owned $Butt):
3938
// CHECK: [[BOX:%.*]] = alloc_box ${ var Butt }
40-
// CHECK: [[BOX0:%.*]] = mark_uninitialized [var] [[BOX]]
41-
// CHECK: [[BOX1:%.*]] = begin_borrow [lexical] [[BOX0]]
39+
// CHECK: [[BOX1:%.*]] = begin_borrow [lexical] [[BOX]]
4240
// CHECK: [[SELF:%.*]] = project_box [[BOX1]]
4341
// CHECK: store %1 to [init] [[SELF]]
4442

0 commit comments

Comments
 (0)