Skip to content

Commit 18c7e92

Browse files
authored
Merge pull request swiftlang#21130 from slavapestov/remove-property-behaviors
Remove property behaviors
2 parents e160b85 + aa747dc commit 18c7e92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+32
-2572
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -744,14 +744,6 @@ class ASTContext final {
744744
DeclContext *dc,
745745
ProtocolConformanceState state);
746746

747-
/// Produce a new normal conformance for a property behavior.
748-
NormalProtocolConformance *
749-
getBehaviorConformance(Type conformingType,
750-
ProtocolDecl *protocol,
751-
SourceLoc loc,
752-
AbstractStorageDecl *storage,
753-
ProtocolConformanceState state);
754-
755747
/// Produce a self-conformance for the given protocol.
756748
SelfProtocolConformance *
757749
getSelfConformance(ProtocolDecl *protocol);

include/swift/AST/ASTMangler.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ class ASTMangler : public Mangler {
123123
std::string mangleClosureWitnessThunk(const ProtocolConformance *Conformance,
124124
const AbstractClosureExpr *Closure);
125125

126-
std::string mangleBehaviorInitThunk(const VarDecl *decl);
127-
128126
std::string mangleGlobalVariableFull(const VarDecl *decl);
129127

130128
std::string mangleGlobalInit(const VarDecl *decl, int counter,

include/swift/AST/Decl.h

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,38 +4160,6 @@ class ProtocolDecl final : public NominalTypeDecl {
41604160
}
41614161
};
41624162

4163-
/// Information about a behavior instantiated by a storage declaration.
4164-
///
4165-
/// TODO: Accessors, composed behaviors
4166-
struct alignas(1 << 3) BehaviorRecord {
4167-
// The behavior name.
4168-
TypeRepr *ProtocolName;
4169-
// The parameter expression, if any.
4170-
Expr *Param;
4171-
4172-
Optional<NormalProtocolConformance *> Conformance = None;
4173-
// The 'value' property from the behavior protocol that provides the property
4174-
// implementation.
4175-
VarDecl *ValueDecl = nullptr;
4176-
4177-
// Storage declaration and initializer for use by definite initialization.
4178-
VarDecl *StorageDecl = nullptr;
4179-
ConcreteDeclRef InitStorageDecl = nullptr;
4180-
4181-
bool needsInitialization() const {
4182-
assert((bool)StorageDecl == (bool)InitStorageDecl
4183-
&& "DI state not consistent");
4184-
return StorageDecl != nullptr;
4185-
}
4186-
4187-
BehaviorRecord(TypeRepr *ProtocolName,
4188-
Expr *Param)
4189-
: ProtocolName(ProtocolName), Param(Param)
4190-
{}
4191-
4192-
SourceLoc getLoc() const;
4193-
};
4194-
41954163
/// AbstractStorageDecl - This is the common superclass for VarDecl and
41964164
/// SubscriptDecl, representing potentially settable memory locations.
41974165
class AbstractStorageDecl : public ValueDecl {
@@ -4257,8 +4225,6 @@ class AbstractStorageDecl : public ValueDecl {
42574225
};
42584226

42594227
llvm::PointerIntPair<AccessorRecord*, 3, OptionalEnum<AccessLevel>> Accessors;
4260-
llvm::PointerIntPair<BehaviorRecord*, 3, OptionalEnum<AccessLevel>>
4261-
BehaviorInfo;
42624228

42634229
void setFieldsFromImplInfo(StorageImplInfo implInfo) {
42644230
Bits.AbstractStorageDecl.HasStorage = implInfo.hasStorage();
@@ -4401,9 +4367,6 @@ class AbstractStorageDecl : public ValueDecl {
44014367
/// This should only be used by the ClangImporter.
44024368
void setComputedSetter(AccessorDecl *Set);
44034369

4404-
/// Add a behavior to a property.
4405-
void addBehavior(TypeRepr *Type, Expr *Param);
4406-
44074370
/// Add a synthesized getter.
44084371
void setSynthesizedGetter(AccessorDecl *getter);
44094372

@@ -4547,28 +4510,6 @@ class AbstractStorageDecl : public ValueDecl {
45474510
/// property from the given module?
45484511
bool isResilient(ModuleDecl *M, ResilienceExpansion expansion) const;
45494512

4550-
/// Does the storage use a behavior?
4551-
bool hasBehavior() const {
4552-
return BehaviorInfo.getPointer() != nullptr;
4553-
}
4554-
4555-
/// Does the storage use a behavior, and require definite initialization
4556-
/// analysis.
4557-
bool hasBehaviorNeedingInitialization() const {
4558-
if (auto behavior = getBehavior()) {
4559-
return behavior->needsInitialization();
4560-
}
4561-
return false;
4562-
}
4563-
4564-
/// Get the behavior info.
4565-
const BehaviorRecord *getBehavior() const {
4566-
return BehaviorInfo.getPointer();
4567-
}
4568-
BehaviorRecord *getMutableBehavior() {
4569-
return BehaviorInfo.getPointer();
4570-
}
4571-
45724513
void setIsValidKeyPathComponent(bool value) {
45734514
Bits.AbstractStorageDecl.HasComputedValidKeyPathComponent = true;
45744515
Bits.AbstractStorageDecl.ValidKeyPathComponent = value;
@@ -5560,9 +5501,6 @@ class FuncDecl : public AbstractFunctionDecl {
55605501

55615502
TypeLoc FnRetType;
55625503

5563-
/// If this FuncDecl is an accessor for a property, this indicates
5564-
/// which property and what kind of accessor.
5565-
BehaviorRecord *BehaviorParamDecl = nullptr;
55665504
OperatorDecl *Operator = nullptr;
55675505

55685506
protected:
@@ -5709,16 +5647,6 @@ class FuncDecl : public AbstractFunctionDecl {
57095647
return cast_or_null<FuncDecl>(AbstractFunctionDecl::getOverriddenDecl());
57105648
}
57115649

5712-
/// Get the property behavior this function serves as a parameter for, if
5713-
/// any.
5714-
BehaviorRecord *getParamBehavior() const {
5715-
return BehaviorParamDecl;
5716-
}
5717-
5718-
void setParamBehavior(BehaviorRecord *behavior) {
5719-
BehaviorParamDecl = behavior;
5720-
}
5721-
57225650
OperatorDecl *getOperatorDecl() const {
57235651
return Operator;
57245652
}

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ ERROR(getset_init,none,
302302
"variable with getter/setter cannot have an initial value", ())
303303
ERROR(getset_cannot_be_implied,none,
304304
"variable with implied type cannot have implied getter/setter", ())
305-
ERROR(behavior_multiple_vars,none,
306-
"applying property behavior with parameter to multiple variables is "
307-
"not supported", ())
308305

309306
// Import
310307
ERROR(decl_expected_module_name,none,
@@ -862,10 +859,6 @@ ERROR(parameter_let_var_as_attr,none,
862859
(StringRef))
863860

864861

865-
ERROR(expected_behavior_name,none,
866-
"expected behavior name after '[' in property declaration", ())
867-
868-
869862
WARNING(parameter_extraneous_double_up,none,
870863
"extraneous duplicate parameter name; %0 already has an argument "
871864
"label", (Identifier))

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,63 +2452,6 @@ ERROR(self_in_nominal,none,
24522452
"'Self' is only available in a protocol or as the result of a "
24532453
"method in a class; did you mean '%0'?", (StringRef))
24542454

2455-
// Property behaviors
2456-
ERROR(property_behavior_not_protocol,none,
2457-
"property behavior name must refer to a protocol", ())
2458-
ERROR(property_behavior_protocol_reqt_ambiguous,none,
2459-
"property behavior protocol has ambiguous %0 member", (Identifier))
2460-
ERROR(property_behavior_protocol_no_value,none,
2461-
"property behavior protocol does not have a 'value' property", ())
2462-
ERROR(property_behavior_protocol_no_initStorage,none,
2463-
"property behavior protocol has a 'storage' requirement but does not "
2464-
"have a static 'initStorage' method with the expected type %0 or %1",
2465-
(Type, Type))
2466-
ERROR(property_behavior_unknown_requirement,none,
2467-
"property behavior protocol %0 has non-behavior requirement %1",
2468-
(Identifier, DeclBaseName))
2469-
NOTE(property_behavior_unknown_requirement_here,none,
2470-
"declared here", ())
2471-
NOTE(self_conformance_required_by_property_behavior,none,
2472-
"conformance to %0 required to contain an instance property with "
2473-
"behavior %1",
2474-
(Identifier, Identifier))
2475-
NOTE(value_conformance_required_by_property_behavior,none,
2476-
"behavior %1 requires property type to conform to protocol %0",
2477-
(Identifier, Identifier))
2478-
ERROR(property_behavior_with_self_requirement_not_in_type,none,
2479-
"property behavior %0 can only be used on instance properties "
2480-
"because it has 'Self' requirements",
2481-
(Identifier))
2482-
ERROR(property_behavior_with_feature_not_supported,none,
2483-
"property behavior %0 with %1 is not supported outside of "
2484-
"type contexts",
2485-
(Identifier, StringRef))
2486-
ERROR(property_behavior_value_type_doesnt_match,none,
2487-
"property behavior %0 provides 'value' property implementation with "
2488-
"type %1 that doesn't match type %2 of declared property %3",
2489-
(Identifier, Type, Identifier, Type))
2490-
NOTE(property_behavior_value_decl_here,none,
2491-
"'value' property declared here", ())
2492-
ERROR(property_behavior_invalid_parameter_reqt,none,
2493-
"property behavior %0 has a 'parameter' requirement that is "
2494-
"static or generic", (Identifier))
2495-
ERROR(property_behavior_requires_parameter,none,
2496-
"property behavior %0 requires a parameter in the declaration of %1",
2497-
(Identifier, Identifier))
2498-
ERROR(property_behavior_invalid_initializer,none,
2499-
"initializer expression provided, but property behavior %0 does not "
2500-
"use it",
2501-
(Identifier))
2502-
ERROR(property_behavior_unsupported_initializer,none,
2503-
"property behaviors do not support destructuring initialization of "
2504-
"multiple properties", ())
2505-
ERROR(property_behavior_invalid_parameter,none,
2506-
"parameter expression provided, but property behavior %0 does not "
2507-
"use it",
2508-
(Identifier))
2509-
ERROR(property_behavior_conformance_broken,none,
2510-
"property behavior for %0 in type %1 is broken", (DeclName, Type))
2511-
25122455
//------------------------------------------------------------------------------
25132456
// MARK: Type Check Attributes
25142457
//------------------------------------------------------------------------------

include/swift/AST/Expr.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ enum class AccessSemantics : uint8_t {
112112
/// implementation of this storage, bypassing any possibility of override.
113113
DirectToImplementation,
114114

115-
/// On a property or subscript reference, this is an access to a property
116-
/// behavior that may be an initialization. Reads always go through the
117-
/// 'get' accessor on the property. Writes may go through the 'init' or
118-
/// 'set' logic of the behavior based on its initialization state.
119-
BehaviorInitialization,
120-
121115
/// This is an ordinary access to a declaration, using whatever
122116
/// polymorphism is expected.
123117
Ordinary,

include/swift/AST/ProtocolConformance.h

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,6 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
308308
void printName(raw_ostream &os,
309309
const PrintOptions &PO = PrintOptions()) const;
310310

311-
/// True if the conformance is for a property behavior instantiation.
312-
bool isBehaviorConformance() const;
313-
314-
/// Get the property declaration for a behavior conformance, if this is one.
315-
AbstractStorageDecl *getBehaviorDecl() const;
316-
317311
/// Get any additional requirements that are required for this conformance to
318312
/// be satisfied, if it is possible for them to be computed.
319313
Optional<ArrayRef<Requirement>> getConditionalRequirementsIfAvailable() const;
@@ -351,9 +345,6 @@ class RootProtocolConformance : public ProtocolConformance {
351345
/// Retrieve the location of this conformance.
352346
SourceLoc getLoc() const;
353347

354-
/// Is this a behavior conformance?
355-
bool isBehaviorConformance() const;
356-
357348
bool isInvalid() const;
358349

359350
/// Whether this conformance is weak-imported.
@@ -425,14 +416,11 @@ class NormalProtocolConformance : public RootProtocolConformance,
425416
/// The location of this protocol conformance in the source.
426417
SourceLoc Loc;
427418

428-
using Context = llvm::PointerUnion<DeclContext *, AbstractStorageDecl *>;
429-
430419
/// The declaration context containing the ExtensionDecl or
431-
/// NominalTypeDecl that declared the conformance, or the VarDecl whose
432-
/// behavior this conformance represents.
420+
/// NominalTypeDecl that declared the conformance.
433421
///
434422
/// Also stores the "invalid" bit.
435-
llvm::PointerIntPair<Context, 1, bool> ContextAndInvalid;
423+
llvm::PointerIntPair<DeclContext *, 1, bool> ContextAndInvalid;
436424

437425
/// The reason that this conformance exists.
438426
///
@@ -491,18 +479,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
491479
"ProtocolConformances should store interface types");
492480
}
493481

494-
NormalProtocolConformance(Type conformingType,
495-
ProtocolDecl *protocol,
496-
SourceLoc loc, AbstractStorageDecl *behaviorStorage,
497-
ProtocolConformanceState state)
498-
: RootProtocolConformance(ProtocolConformanceKind::Normal, conformingType),
499-
ProtocolAndState(protocol, state), Loc(loc),
500-
ContextAndInvalid(behaviorStorage, false)
501-
{
502-
assert(!conformingType->hasArchetype() &&
503-
"ProtocolConformances should store interface types");
504-
}
505-
506482
void resolveLazyInfo() const;
507483

508484
void differenceAndStoreConditionalRequirements() const;
@@ -517,12 +493,7 @@ class NormalProtocolConformance : public RootProtocolConformance,
517493
/// Get the declaration context that contains the conforming extension or
518494
/// nominal type declaration.
519495
DeclContext *getDeclContext() const {
520-
auto context = ContextAndInvalid.getPointer();
521-
if (auto DC = context.dyn_cast<DeclContext *>()) {
522-
return DC;
523-
} else {
524-
return context.get<AbstractStorageDecl *>()->getDeclContext();
525-
}
496+
return ContextAndInvalid.getPointer();
526497
}
527498

528499
/// Get any additional requirements that are required for this conformance to
@@ -607,17 +578,6 @@ class NormalProtocolConformance : public RootProtocolConformance,
607578
/// This only matters to the AST verifier.
608579
bool isLazilyLoaded() const { return Loader != nullptr; }
609580

610-
/// True if the conformance describes a property behavior.
611-
bool isBehaviorConformance() const {
612-
return ContextAndInvalid.getPointer().is<AbstractStorageDecl *>();
613-
}
614-
615-
/// Return the declaration using the behavior for this conformance, or null
616-
/// if this isn't a behavior conformance.
617-
AbstractStorageDecl *getBehaviorDecl() const {
618-
return ContextAndInvalid.getPointer().dyn_cast<AbstractStorageDecl *>();
619-
}
620-
621581
/// A "retroactive" conformance is one that is defined in a module that
622582
/// is neither the module that defines the protocol nor the module that
623583
/// defines the conforming type.
@@ -811,12 +771,6 @@ class SelfProtocolConformance : public RootProtocolConformance {
811771
}
812772
};
813773

814-
inline bool RootProtocolConformance::isBehaviorConformance() const {
815-
if (auto normal = dyn_cast<NormalProtocolConformance>(this))
816-
return normal->isBehaviorConformance();
817-
return false;
818-
}
819-
820774
/// Specialized protocol conformance, which projects a generic protocol
821775
/// conformance to one of the specializations of the generic type.
822776
///

include/swift/AST/StorageImpl.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ class AccessStrategy {
8080
/// that storage directly.
8181
Storage,
8282

83-
/// The decl is a VarDecl with storage defined by a property behavior;
84-
/// this access may initialize or reassign the storage based on dataflow.
85-
BehaviorStorage,
86-
8783
/// Directly call an accessor of some sort. The strategy includes
8884
/// an accessor kind.
8985
DirectToAccessor,
@@ -107,7 +103,7 @@ class AccessStrategy {
107103

108104
AccessStrategy(Kind kind)
109105
: TheKind(kind) {
110-
assert(kind == Storage || kind == BehaviorStorage);
106+
assert(kind == Storage);
111107
}
112108

113109
AccessStrategy(Kind kind, AccessorKind accessor)
@@ -131,10 +127,6 @@ class AccessStrategy {
131127
return { Storage };
132128
}
133129

134-
static AccessStrategy getBehaviorStorage() {
135-
return { BehaviorStorage };
136-
}
137-
138130
static AccessStrategy getAccessor(AccessorKind accessor, bool dispatched) {
139131
return { dispatched ? DispatchToAccessor : DirectToAccessor, accessor };
140132
}

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,6 @@ namespace swift {
213213
/// Enable experimental #assert feature.
214214
bool EnableExperimentalStaticAssert = false;
215215

216-
/// Enable experimental property behavior feature.
217-
bool EnableExperimentalPropertyBehaviors = false;
218-
219216
/// Staging flag for treating inout parameters as Thread Sanitizer
220217
/// accesses.
221218
bool DisableTsanInoutInstrumentation = false;

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,6 @@ def enable_experimental_static_assert :
326326
Flag<["-"], "enable-experimental-static-assert">,
327327
HelpText<"Enable experimental #assert">;
328328

329-
def enable_experimental_property_behaviors :
330-
Flag<["-"], "enable-experimental-property-behaviors">,
331-
HelpText<"Enable experimental property behaviors">;
332-
333329
def enable_deserialization_recovery :
334330
Flag<["-"], "enable-deserialization-recovery">,
335331
HelpText<"Attempt to recover from missing xrefs (etc) in swiftmodules">;

0 commit comments

Comments
 (0)