Skip to content

Commit f03eab2

Browse files
committed
---
yaml --- r: 348147 b: refs/heads/master c: f7574e4 h: refs/heads/master i: 348145: f6a1828 348143: 289253a
1 parent 7401fe5 commit f03eab2

File tree

6 files changed

+130
-6
lines changed

6 files changed

+130
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: ece4dd093477fb7ed68df59a65358ad8c10b11b1
2+
refs/heads/master: f7574e4670c5f562dfc2903358496385914cfd77
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/SILGen/RValue.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Initialization.h"
2222
#include "SILGenFunction.h"
2323
#include "swift/AST/CanTypeVisitor.h"
24+
#include "swift/Basic/Defer.h"
2425
#include "swift/Basic/STLExtras.h"
2526
#include "swift/SIL/AbstractionPattern.h"
2627
#include "swift/SIL/SILArgument.h"
@@ -573,19 +574,19 @@ void RValue::assignInto(SILGenFunction &SGF, SILLocation loc,
573574

574575
ManagedValue RValue::getAsSingleValue(SILGenFunction &SGF, SILLocation loc) && {
575576
assert(!isUsed() && "r-value already used");
577+
SWIFT_DEFER {
578+
makeUsed();
579+
};
576580

577581
if (isInContext()) {
578-
makeUsed();
579582
return ManagedValue::forInContext();
580583
}
581584

582585
// Avoid killing and re-emitting the cleanup if the enclosed value isn't a
583586
// tuple.
584587
if (!isa<TupleType>(type)) {
585588
assert(values.size() == 1 && "exploded non-tuple?!");
586-
ManagedValue result = values[0];
587-
makeUsed();
588-
return result;
589+
return values[0];
589590
}
590591

591592
// *NOTE* Inside implodeTupleValues, we copy our values if they are not at +1.

trunk/lib/Sema/TypeCheckDecl.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,24 @@ static void validateSelfAccessKind(TypeChecker &TC, FuncDecl *FD) {
19661966
FD->setSelfAccessKind(SelfAccessKind::NonMutating);
19671967
else if (FD->getAttrs().hasAttribute<ConsumingAttr>())
19681968
FD->setSelfAccessKind(SelfAccessKind::__Consuming);
1969+
else if (auto accessor = dyn_cast<AccessorDecl>(FD)) {
1970+
if (accessor->getAccessorKind() == AccessorKind::Get ||
1971+
accessor->getAccessorKind() == AccessorKind::Set ||
1972+
accessor->getAccessorKind() == AccessorKind::DidSet ||
1973+
accessor->getAccessorKind() == AccessorKind::WillSet) {
1974+
auto storage = accessor->getStorage();
1975+
TC.validateDecl(storage);
1976+
if (accessor->getAccessorKind() == AccessorKind::Get) {
1977+
FD->setSelfAccessKind(storage->isGetterMutating()
1978+
? SelfAccessKind::Mutating
1979+
: SelfAccessKind::NonMutating);
1980+
} else {
1981+
FD->setSelfAccessKind(storage->isSetterMutating()
1982+
? SelfAccessKind::Mutating
1983+
: SelfAccessKind::NonMutating);
1984+
}
1985+
}
1986+
}
19691987

19701988
if (FD->isMutating()) {
19711989
if (!FD->isInstanceMember() ||

trunk/lib/Sema/TypeCheckStmt.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "TypeChecker.h"
18+
#include "TypeCheckAvailability.h"
1819
#include "TypeCheckType.h"
1920
#include "MiscDiagnostics.h"
2021
#include "ConstraintSystem.h"
@@ -2050,8 +2051,19 @@ static bool checkSuperInit(TypeChecker &tc, ConstructorDecl *fromCtor,
20502051
// super.init() call.
20512052
return true;
20522053
}
2054+
2055+
// Make sure we can reference the designated initializer correctly.
2056+
if (fromCtor->getResilienceExpansion() == ResilienceExpansion::Minimal) {
2057+
TypeChecker::FragileFunctionKind fragileKind;
2058+
bool treatUsableFromInlineAsPublic;
2059+
std::tie(fragileKind, treatUsableFromInlineAsPublic) =
2060+
tc.getFragileFunctionKind(fromCtor);
2061+
tc.diagnoseInlinableDeclRef(
2062+
fromCtor->getLoc(), ctor, fromCtor, fragileKind,
2063+
treatUsableFromInlineAsPublic);
2064+
}
20532065
}
2054-
2066+
20552067
return false;
20562068
}
20572069

trunk/test/SILGen/property_wrappers.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,67 @@ func testComposition() {
346346
_ = CompositionMembers(p1: nil)
347347
}
348348

349+
// Observers with non-default mutatingness.
350+
@propertyWrapper
351+
struct NonMutatingSet<T> {
352+
private var fixed: T
353+
354+
var wrappedValue: T {
355+
get { fixed }
356+
nonmutating set { }
357+
}
358+
359+
init(initialValue: T) {
360+
fixed = initialValue
361+
}
362+
}
363+
364+
@propertyWrapper
365+
struct MutatingGet<T> {
366+
private var fixed: T
367+
368+
var wrappedValue: T {
369+
mutating get { fixed }
370+
set { }
371+
}
372+
373+
init(initialValue: T) {
374+
fixed = initialValue
375+
}
376+
}
377+
378+
struct ObservingTest {
379+
// ObservingTest.text.setter
380+
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers13ObservingTestV4textSSvs : $@convention(method) (@owned String, @guaranteed ObservingTest) -> ()
381+
// CHECK: function_ref @$s17property_wrappers14NonMutatingSetV12wrappedValuexvg
382+
@NonMutatingSet var text: String = "" {
383+
didSet { }
384+
}
385+
386+
@NonMutatingSet var integer: Int = 17 {
387+
willSet { }
388+
}
389+
390+
@MutatingGet var text2: String = "" {
391+
didSet { }
392+
}
393+
394+
@MutatingGet var integer2: Int = 17 {
395+
willSet { }
396+
}
397+
}
398+
399+
// Tuple initial values.
400+
struct WithTuples {
401+
// CHECK-LABEL: sil hidden [ossa] @$s17property_wrappers10WithTuplesVACycfC : $@convention(method) (@thin WithTuples.Type) -> WithTuples {
402+
// CHECK: function_ref @$s17property_wrappers10WithTuplesV10$fractions33_F728088E0028E14D18C6A10CF68512E8LLAA07WrapperC12InitialValueVySd_S2dtGvpfi : $@convention(thin) () -> (Double, Double, Double)
403+
// CHECK: function_ref @$s17property_wrappers23WrapperWithInitialValueV07initialF0ACyxGx_tcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thin WrapperWithInitialValue<τ_0_0>.Type) -> @out WrapperWithInitialValue<τ_0_0>
404+
@WrapperWithInitialValue var fractions = (1.3, 0.7, 0.3)
405+
406+
static func getDefault() -> WithTuples {
407+
return .init()
408+
}
409+
}
349410

350411
// CHECK-LABEL: sil_vtable ClassUsingWrapper {
351412
// CHECK-NEXT: #ClassUsingWrapper.x!getter.1: (ClassUsingWrapper) -> () -> Int : @$s17property_wrappers17ClassUsingWrapperC1xSivg // ClassUsingWrapper.x.getter

trunk/test/attr/attr_inlinable.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ enum InternalEnum {
167167
_ = VersionedEnum.persimmon
168168
}
169169

170+
170171
// Inherited initializers - <rdar://problem/34398148>
171172
@usableFromInline
172173
@_fixed_layout
@@ -188,6 +189,7 @@ class Derived : Middle {
188189
}
189190
}
190191

192+
191193
// More inherited initializers
192194
@_fixed_layout
193195
public class Base2 {
@@ -208,6 +210,36 @@ class Derived2 : Middle2 {
208210
}
209211
}
210212

213+
214+
// Even more inherited initializers - https://bugs.swift.org/browse/SR-10940
215+
@_fixed_layout
216+
public class Base3 {}
217+
// expected-note@-1 {{initializer 'init()' is not '@usableFromInline' or public}}
218+
219+
@_fixed_layout
220+
public class Derived3 : Base3 {
221+
@inlinable
222+
public init(_: Int) {}
223+
// expected-error@-1 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
224+
}
225+
226+
@_fixed_layout
227+
public class Base4 {}
228+
229+
@_fixed_layout
230+
@usableFromInline
231+
class Middle4 : Base4 {}
232+
// expected-note@-1 {{initializer 'init()' is not '@usableFromInline' or public}}
233+
234+
@_fixed_layout
235+
@usableFromInline
236+
class Derived4 : Middle4 {
237+
@inlinable
238+
public init(_: Int) {}
239+
// expected-error@-1 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
240+
}
241+
242+
211243
// Stored property initializer expressions.
212244
//
213245
// Note the behavior here does not depend on the state of the -enable-library-evolution

0 commit comments

Comments
 (0)