Skip to content

Commit 35c0fa8

Browse files
authored
Merge pull request #26006 from DougGregor/property-wrapper-di-resilience
2 parents 4abefdb + ddb64a4 commit 35c0fa8

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,13 +1967,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
19671967
"assign instruction can only exist in raw SIL");
19681968
require(Dest->getType().isAddress(), "Must store to an address dest");
19691969

1970-
unsigned indirectInitResults = Src->getType().isAddress() ? 1 : 0;
1971-
19721970
SILValue initFn = AI->getInitializer();
19731971
CanSILFunctionType initTy = initFn->getType().castTo<SILFunctionType>();
19741972
SILFunctionConventions initConv(initTy, AI->getModule());
1975-
require(initConv.getNumIndirectSILResults() == indirectInitResults,
1976-
"init function has wrong number of indirect results");
19771973
unsigned firstArgIdx = initConv.getSILArgIndexOfFirstParam();
19781974
require(initConv.getNumSILArguments() == firstArgIdx + 1,
19791975
"init function has wrong number of arguments");
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@propertyWrapper
2+
public struct MyPublished<Value> {
3+
private var stored: Value
4+
5+
public var wrappedValue: Value {
6+
get { stored }
7+
set { stored = newValue }
8+
}
9+
10+
public init(initialValue: Value) {
11+
stored = initialValue
12+
}
13+
14+
public var projectedValue: Self {
15+
mutating get { self }
16+
set { self = newValue }
17+
}
18+
}

test/SILGen/property_wrappers.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// RUN: %target-swift-frontend -primary-file %s -emit-silgen | %FileCheck %s
2-
// FIXME: switch to %target-swift-emit-silgen once we have syntax tree support
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t -enable-library-evolution %S/Inputs/property_wrapper_defs.swift
3+
// RUN: %target-swift-emit-silgen -primary-file %s -I %t | %FileCheck %s
4+
import property_wrapper_defs
35

46
@propertyWrapper
57
struct Wrapper<T> {
@@ -408,6 +410,20 @@ struct WithTuples {
408410
}
409411
}
410412

413+
// Resilience with DI of wrapperValue assignments.
414+
// rdar://problem/52467175
415+
class TestResilientDI {
416+
@MyPublished var data: Int? = nil
417+
418+
// CHECK: assign_by_wrapper {{%.*}} : $Optional<Int> to {{%.*}} : $*MyPublished<Optional<Int>>, init {{%.*}} : $@callee_guaranteed (Optional<Int>) -> @out MyPublished<Optional<Int>>, set {{%.*}} : $@callee_guaranteed (Optional<Int>) -> ()
419+
420+
func doSomething() {
421+
self.data = Int()
422+
}
423+
}
424+
425+
426+
411427
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
412428
// CHECK-NEXT: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s17property_wrappers17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter
413429
// CHECK-NEXT: #ClassUsingWrapper.x!setter.1: (ClassUsingWrapper) -> (Int) -> () : @$s17property_wrappers17ClassUsingWrapperC1xSivs // ClassUsingWrapper.x.setter

0 commit comments

Comments
 (0)