Skip to content

Commit 755c02c

Browse files
authored
Merge pull request #26235 from slavapestov/accessor-refactoring
Split off StorageImplInfo from AccessorRecord
2 parents adf107c + 454281b commit 755c02c

Some content is hidden

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

43 files changed

+504
-518
lines changed

include/swift/AST/Decl.h

Lines changed: 115 additions & 150 deletions
Large diffs are not rendered by default.

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4367,16 +4367,15 @@ WARNING(variable_never_used, none,
43674367
"consider replacing with '_' or removing it",
43684368
(Identifier, unsigned))
43694369
WARNING(immutable_value_never_used_but_assigned, none,
4370-
"immutable value %0 was never used; "
4371-
"consider removing it",
4370+
"immutable value %0 was never used; consider removing it",
43724371
(Identifier))
43734372
WARNING(variable_never_mutated, none,
4374-
"%select{variable|parameter}1 %0 was never mutated; "
4375-
"consider %select{removing 'var' to make it|changing to 'let'}2 constant",
4376-
(Identifier, unsigned, bool))
4373+
"variable %0 was never mutated; "
4374+
"consider %select{removing 'var' to make it|changing to 'let'}1 constant",
4375+
(Identifier, bool))
43774376
WARNING(variable_never_read, none,
4378-
"%select{variable|parameter}1 %0 was written to, but never read",
4379-
(Identifier, unsigned))
4377+
"variable %0 was written to, but never read",
4378+
(Identifier))
43804379

43814380
//------------------------------------------------------------------------------
43824381
// MARK: Debug diagnostics

include/swift/Parse/Parser.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ class Parser {
951951
bool parseVersionTuple(llvm::VersionTuple &Version, SourceRange &Range,
952952
const Diagnostic &D);
953953

954-
bool parseTypeAttributeList(VarDecl::Specifier &Specifier,
954+
bool parseTypeAttributeList(ParamDecl::Specifier &Specifier,
955955
SourceLoc &SpecifierLoc,
956956
TypeAttributes &Attributes) {
957957
if (Tok.isAny(tok::at_sign, tok::kw_inout) ||
@@ -961,7 +961,7 @@ class Parser {
961961
return parseTypeAttributeListPresent(Specifier, SpecifierLoc, Attributes);
962962
return false;
963963
}
964-
bool parseTypeAttributeListPresent(VarDecl::Specifier &Specifier,
964+
bool parseTypeAttributeListPresent(ParamDecl::Specifier &Specifier,
965965
SourceLoc &SpecifierLoc,
966966
TypeAttributes &Attributes);
967967
bool parseTypeAttribute(TypeAttributes &Attributes,
@@ -1103,7 +1103,7 @@ class Parser {
11031103
SourceLoc consumeImplicitlyUnwrappedOptionalToken();
11041104

11051105
TypeRepr *applyAttributeToType(TypeRepr *Ty, const TypeAttributes &Attr,
1106-
VarDecl::Specifier Specifier,
1106+
ParamDecl::Specifier Specifier,
11071107
SourceLoc SpecifierLoc);
11081108

11091109
//===--------------------------------------------------------------------===//
@@ -1142,7 +1142,7 @@ class Parser {
11421142
SourceLoc SpecifierLoc;
11431143

11441144
/// The parsed specifier kind, if present.
1145-
VarDecl::Specifier SpecifierKind = VarDecl::Specifier::Default;
1145+
ParamDecl::Specifier SpecifierKind = ParamDecl::Specifier::Default;
11461146

11471147
/// The location of the first name.
11481148
///
@@ -1260,7 +1260,7 @@ class Parser {
12601260

12611261

12621262
Pattern *createBindingFromPattern(SourceLoc loc, Identifier name,
1263-
VarDecl::Specifier specifier);
1263+
VarDecl::Introducer introducer);
12641264

12651265

12661266
/// Determine whether this token can only start a matching pattern

include/swift/Serialization/ModuleFormat.h

Lines changed: 24 additions & 17 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 = 501; // cond_fail messages
55+
const uint16_t SWIFTMODULE_VERSION_MINOR = 502; // move specifier down to ParamDecl
5656

5757
using DeclIDField = BCFixed<31>;
5858

@@ -247,14 +247,21 @@ using CtorInitializerKindField = BCFixed<2>;
247247

248248
// These IDs must \em not be renumbered or reordered without incrementing
249249
// the module version.
250-
enum class VarDeclSpecifier : uint8_t {
250+
enum class ParamDeclSpecifier : uint8_t {
251+
Default = 0,
252+
InOut = 1,
253+
Shared = 2,
254+
Owned = 3,
255+
};
256+
using ParamDeclSpecifierField = BCFixed<2>;
257+
258+
// These IDs must \em not be renumbered or reordered without incrementing
259+
// the module version.
260+
enum class VarDeclIntroducer : uint8_t {
251261
Let = 0,
252-
Var,
253-
InOut,
254-
Shared,
255-
Owned,
262+
Var = 1
256263
};
257-
using VarDeclSpecifierField = BCFixed<3>;
264+
using VarDeclIntroducerField = BCFixed<1>;
258265

259266
// These IDs must \em not be renumbered or reordered without incrementing
260267
// the module version.
@@ -1041,7 +1048,7 @@ namespace decls_block {
10411048
BCFixed<1>, // implicit?
10421049
BCFixed<1>, // explicitly objc?
10431050
BCFixed<1>, // static?
1044-
VarDeclSpecifierField, // specifier
1051+
VarDeclIntroducerField, // introducer
10451052
BCFixed<1>, // HasNonPatternBindingInit?
10461053
BCFixed<1>, // is getter mutating?
10471054
BCFixed<1>, // is setter mutating?
@@ -1063,15 +1070,15 @@ namespace decls_block {
10631070

10641071
using ParamLayout = BCRecordLayout<
10651072
PARAM_DECL,
1066-
IdentifierIDField, // argument name
1067-
IdentifierIDField, // parameter name
1068-
DeclContextIDField, // context decl
1069-
VarDeclSpecifierField, // specifier
1070-
TypeIDField, // interface type
1071-
BCFixed<1>, // isVariadic?
1072-
BCFixed<1>, // isAutoClosure?
1073-
DefaultArgumentField, // default argument kind
1074-
BCBlob // default argument text
1073+
IdentifierIDField, // argument name
1074+
IdentifierIDField, // parameter name
1075+
DeclContextIDField, // context decl
1076+
ParamDeclSpecifierField, // specifier
1077+
TypeIDField, // interface type
1078+
BCFixed<1>, // isVariadic?
1079+
BCFixed<1>, // isAutoClosure?
1080+
DefaultArgumentField, // default argument kind
1081+
BCBlob // default argument text
10751082
>;
10761083

10771084
using FuncLayout = BCRecordLayout<

lib/AST/ASTDumper.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -968,19 +968,16 @@ namespace {
968968
}
969969

970970
switch (P->getSpecifier()) {
971-
case VarDecl::Specifier::Let:
971+
case ParamDecl::Specifier::Default:
972972
/* nothing */
973973
break;
974-
case VarDecl::Specifier::Var:
975-
OS << " mutable";
976-
break;
977-
case VarDecl::Specifier::InOut:
974+
case ParamDecl::Specifier::InOut:
978975
OS << " inout";
979976
break;
980-
case VarDecl::Specifier::Shared:
977+
case ParamDecl::Specifier::Shared:
981978
OS << " shared";
982979
break;
983-
case VarDecl::Specifier::Owned:
980+
case ParamDecl::Specifier::Owned:
984981
OS << " owned";
985982
break;
986983
}

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,17 +2500,11 @@ void PrintAST::visitVarDecl(VarDecl *decl) {
25002500
|| Options.PrintParameterSpecifiers) {
25012501
// Map all non-let specifiers to 'var'. This is not correct, but
25022502
// SourceKit relies on this for info about parameter decls.
2503-
switch (decl->getSpecifier()) {
2504-
case VarDecl::Specifier::Let:
2503+
if (decl->isLet())
25052504
Printer << tok::kw_let;
2506-
break;
2507-
case VarDecl::Specifier::Var:
2508-
case VarDecl::Specifier::InOut:
2509-
case VarDecl::Specifier::Shared:
2510-
case VarDecl::Specifier::Owned:
2505+
else
25112506
Printer << tok::kw_var;
2512-
break;
2513-
}
2507+
25142508
Printer << " ";
25152509
}
25162510
}

lib/AST/ASTVerifier.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,23 +2448,12 @@ class Verifier : public ASTWalker {
24482448
void verifyChecked(VarDecl *var) {
24492449
PrettyStackTraceDecl debugStack("verifying VarDecl", var);
24502450

2451-
// Variables must have materializable type, unless they are parameters,
2452-
// in which case they must either have l-value type or be anonymous.
2451+
// Variables must have materializable type.
24532452
if (!var->getInterfaceType()->isMaterializable()) {
2454-
if (!isa<ParamDecl>(var)) {
2455-
Out << "VarDecl has non-materializable type: ";
2456-
var->getType().print(Out);
2457-
Out << "\n";
2458-
abort();
2459-
}
2460-
2461-
if (!var->isInOut() && var->hasName()) {
2462-
Out << "ParamDecl may only have non-materializable tuple type "
2463-
"when it is anonymous: ";
2464-
var->getType().print(Out);
2465-
Out << "\n";
2466-
abort();
2467-
}
2453+
Out << "VarDecl has non-materializable type: ";
2454+
var->getInterfaceType().print(Out);
2455+
Out << "\n";
2456+
abort();
24682457
}
24692458

24702459
// The fact that this is *directly* be a reference storage type

lib/AST/Builtins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ getBuiltinFunction(Identifier Id, ArrayRef<Type> argTypes, Type ResType,
160160
SmallVector<ParamDecl*, 4> params;
161161
for (Type argType : argTypes) {
162162
auto PD = new (Context)
163-
ParamDecl(VarDecl::Specifier::Default, SourceLoc(), SourceLoc(),
163+
ParamDecl(ParamDecl::Specifier::Default, SourceLoc(), SourceLoc(),
164164
Identifier(), SourceLoc(), Identifier(), DC);
165165
PD->setInterfaceType(argType);
166166
PD->setValidationToChecked();
@@ -203,7 +203,7 @@ getBuiltinGenericFunction(Identifier Id,
203203
for (unsigned i = 0, e = ArgParamTypes.size(); i < e; i++) {
204204
auto paramIfaceType = ArgParamTypes[i].getPlainType();
205205
auto specifier =
206-
VarDecl::getParameterSpecifierForValueOwnership(
206+
ParamDecl::getParameterSpecifierForValueOwnership(
207207
ArgParamTypes[i].getParameterFlags().getValueOwnership());
208208
auto PD = new (Context) ParamDecl(specifier,
209209
SourceLoc(), SourceLoc(),

0 commit comments

Comments
 (0)