Skip to content

Commit 3506566

Browse files
committed
---
yaml --- r: 286447 b: refs/heads/master-next c: 7092be6 h: refs/heads/master i: 286445: 71ddf38 286443: 1414599 286439: fffb281 286431: f17517a
1 parent 8ad277c commit 3506566

File tree

7 files changed

+99
-15
lines changed

7 files changed

+99
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: a67ffadd758dfc7a0f10a8afde063b8864663208
3-
refs/heads/master-next: eaf22c2661fa0db0a34ba9df1b36fe687f501b13
3+
refs/heads/master-next: 7092be6a284e5c891f92d0a8b9b9e565399e72bf
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/include/swift/Serialization/ModuleFormat.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5252
/// describe what change you made. The content of this comment isn't important;
5353
/// it just ensures a conflict if two people change the module format.
5454
/// Don't worry about adhering to the 80-column limit for this line.
55-
const uint16_t SWIFTMODULE_VERSION_MINOR = 488; // assign_by_delegate
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 489; // backing variables
5656

5757
using DeclIDField = BCFixed<31>;
5858

@@ -1047,7 +1047,8 @@ namespace decls_block {
10471047
AccessLevelField, // access level
10481048
AccessLevelField, // setter access, if applicable
10491049
DeclIDField, // opaque return type decl
1050-
BCArray<TypeIDField> // accessors and dependencies
1050+
BCFixed<2>, // # of property delegate backing properties
1051+
BCArray<TypeIDField> // accessors, backing properties, and dependencies
10511052
>;
10521053

10531054
using ParamLayout = BCRecordLayout<

branches/master-next/lib/Sema/TypeCheckPropertyDelegate.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ AttachedPropertyDelegateRequest::evaluate(Evaluator &evaluator,
263263
if (!nominal || !nominal->getAttrs().hasAttribute<PropertyDelegateAttr>())
264264
continue;
265265

266+
// If the declaration came from a module file, we've already done all of
267+
// the semantic checking required.
268+
if (!dc->getParentSourceFile())
269+
return mutableAttr;
270+
266271
// Check various restrictions on which properties can have delegates
267272
// attached to them.
268273

branches/master-next/lib/Serialization/Deserialization.cpp

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include "swift/AST/Pattern.h"
2323
#include "swift/AST/ParameterList.h"
2424
#include "swift/AST/PrettyStackTrace.h"
25+
#include "swift/AST/PropertyDelegates.h"
2526
#include "swift/AST/ProtocolConformance.h"
27+
#include "swift/AST/TypeCheckRequests.h"
2628
#include "swift/ClangImporter/ClangImporter.h"
2729
#include "swift/ClangImporter/ClangModule.h"
2830
#include "swift/Serialization/BCReadingExtras.h"
@@ -2664,13 +2666,13 @@ class swift::DeclDeserializer {
26642666
DeclContextID contextID;
26652667
bool isImplicit, isObjC, isStatic, hasNonPatternBindingInit;
26662668
bool isGetterMutating, isSetterMutating;
2667-
unsigned rawSpecifier, numAccessors;
2669+
unsigned rawSpecifier, numAccessors, numBackingProperties;
26682670
uint8_t readImpl, writeImpl, readWriteImpl, opaqueReadOwnership;
26692671
uint8_t rawAccessLevel, rawSetterAccessLevel;
26702672
TypeID interfaceTypeID;
26712673
ModuleFile::AccessorRecord accessors;
26722674
DeclID overriddenID, opaqueReturnTypeID;
2673-
ArrayRef<uint64_t> accessorAndDependencyIDs;
2675+
ArrayRef<uint64_t> arrayFieldIDs;
26742676

26752677
decls_block::VarLayout::readRecord(scratch, nameID, contextID,
26762678
isImplicit, isObjC, isStatic, rawSpecifier,
@@ -2683,7 +2685,8 @@ class swift::DeclDeserializer {
26832685
overriddenID,
26842686
rawAccessLevel, rawSetterAccessLevel,
26852687
opaqueReturnTypeID,
2686-
accessorAndDependencyIDs);
2688+
numBackingProperties,
2689+
arrayFieldIDs);
26872690

26882691
Identifier name = MF.getIdentifier(nameID);
26892692

@@ -2693,13 +2696,17 @@ class swift::DeclDeserializer {
26932696
return llvm::make_error<OverrideError>(name);
26942697
}
26952698

2696-
// Exctract the accessor IDs.
2697-
for (DeclID accessorID : accessorAndDependencyIDs.slice(0, numAccessors)) {
2699+
// Extract the accessor IDs.
2700+
for (DeclID accessorID : arrayFieldIDs.slice(0, numAccessors)) {
26982701
accessors.IDs.push_back(accessorID);
26992702
}
2700-
accessorAndDependencyIDs = accessorAndDependencyIDs.slice(numAccessors);
2703+
arrayFieldIDs = arrayFieldIDs.slice(numAccessors);
2704+
2705+
// Extract the backing property IDs.
2706+
auto backingPropertyIDs = arrayFieldIDs.slice(0, numBackingProperties);
2707+
arrayFieldIDs = arrayFieldIDs.slice(numBackingProperties);
27012708

2702-
for (TypeID dependencyID : accessorAndDependencyIDs) {
2709+
for (TypeID dependencyID : arrayFieldIDs) {
27032710
auto dependency = MF.getTypeChecked(dependencyID);
27042711
if (!dependency) {
27052712
// Stored properties in classes still impact class object layout because
@@ -2787,7 +2794,28 @@ class swift::DeclDeserializer {
27872794
var->setOpaqueResultTypeDecl(
27882795
cast<OpaqueTypeDecl>(MF.getDecl(opaqueReturnTypeID)));
27892796
}
2790-
2797+
2798+
// If there are any backing properties, record the
2799+
if (numBackingProperties > 0) {
2800+
VarDecl *backingVar = cast<VarDecl>(MF.getDecl(backingPropertyIDs[0]));
2801+
VarDecl *storageDelegateVar = nullptr;
2802+
if (numBackingProperties > 1) {
2803+
storageDelegateVar = cast<VarDecl>(MF.getDecl(backingPropertyIDs[1]));
2804+
}
2805+
2806+
PropertyDelegateBackingPropertyInfo info(
2807+
backingVar, storageDelegateVar, nullptr, nullptr, nullptr);
2808+
ctx.evaluator.cacheOutput(
2809+
PropertyDelegateBackingPropertyInfoRequest{var}, std::move(info));
2810+
ctx.evaluator.cacheOutput(
2811+
PropertyDelegateBackingPropertyTypeRequest{var},
2812+
backingVar->getInterfaceType());
2813+
backingVar->setOriginalDelegatedProperty(var);
2814+
2815+
if (storageDelegateVar)
2816+
storageDelegateVar->setOriginalDelegatedProperty(var);
2817+
}
2818+
27912819
return var;
27922820
}
27932821

branches/master-next/lib/Serialization/Serialization.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/ParameterList.h"
2525
#include "swift/AST/Pattern.h"
2626
#include "swift/AST/PrettyStackTrace.h"
27+
#include "swift/AST/PropertyDelegates.h"
2728
#include "swift/AST/ProtocolConformance.h"
2829
#include "swift/AST/RawComment.h"
2930
#include "swift/AST/TypeCheckRequests.h"
@@ -3291,12 +3292,23 @@ void Serializer::writeDecl(const Decl *D) {
32913292
rawSetterAccessLevel =
32923293
getRawStableAccessLevel(var->getSetterFormalAccess());
32933294

3295+
unsigned numBackingProperties = 0;
32943296
Type ty = var->getInterfaceType();
3295-
SmallVector<TypeID, 2> accessorsAndDependencies;
3297+
SmallVector<TypeID, 2> arrayFields;
32963298
for (auto accessor : accessors.Decls)
3297-
accessorsAndDependencies.push_back(addDeclRef(accessor));
3299+
arrayFields.push_back(addDeclRef(accessor));
3300+
if (auto backingInfo = var->getPropertyDelegateBackingPropertyInfo()) {
3301+
if (backingInfo.backingVar) {
3302+
++numBackingProperties;
3303+
arrayFields.push_back(addDeclRef(backingInfo.backingVar));
3304+
}
3305+
if (backingInfo.storageDelegateVar) {
3306+
++numBackingProperties;
3307+
arrayFields.push_back(addDeclRef(backingInfo.storageDelegateVar));
3308+
}
3309+
}
32983310
for (Type dependency : collectDependenciesFromType(ty->getCanonicalType()))
3299-
accessorsAndDependencies.push_back(addTypeRef(dependency));
3311+
arrayFields.push_back(addTypeRef(dependency));
33003312

33013313
unsigned abbrCode = DeclTypeAbbrCodes[VarLayout::Code];
33023314
VarLayout::emitRecord(Out, ScratchRecord, abbrCode,
@@ -3318,7 +3330,8 @@ void Serializer::writeDecl(const Decl *D) {
33183330
addDeclRef(var->getOverriddenDecl()),
33193331
rawAccessLevel, rawSetterAccessLevel,
33203332
addDeclRef(var->getOpaqueResultTypeDecl()),
3321-
accessorsAndDependencies);
3333+
numBackingProperties,
3334+
arrayFields);
33223335
break;
33233336
}
33243337

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@_propertyDelegate
2+
public struct SomeDelegate<T> {
3+
public var value: T
4+
5+
public init(initialValue: T) {
6+
self.value = initialValue
7+
}
8+
}
9+
10+
public struct HasDelegates {
11+
@SomeDelegate public var x: Int = 17
12+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_property_delegates.swift
3+
// RUN: %target-swift-frontend -typecheck -I%t -verify %s -verify-ignore-unknown
4+
5+
// Same test, but with -enable-testing so we can see the backing properties
6+
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_property_delegates.swift -enable-testing
7+
// RUN: %target-swift-frontend -DTESTING -typecheck -I%t %s
8+
9+
#if TESTING
10+
@testable import def_property_delegates
11+
#else
12+
import def_property_delegates
13+
#endif
14+
15+
func useDelegates(hd: HasDelegates) {
16+
// Access the original properties
17+
let _: Int = hd.x
18+
19+
let _: SomeDelegate<Int> = hd.$x // expected-error{{'$x' is inaccessible due to 'internal' protection level}}
20+
21+
var mutableHD = hd
22+
mutableHD.x = 17
23+
24+
mutableHD.$x = SomeDelegate(initialValue: 42) // expected-error{{'$x' is inaccessible due to 'internal' protection level}}
25+
}

0 commit comments

Comments
 (0)