Skip to content

Commit 28e4f52

Browse files
authored
Merge pull request swiftlang#28192 from CodaFi/synthetic-symptotics
Remove SourceFile::SynthesizedDecls
2 parents 7e377d9 + 0775808 commit 28e4f52

12 files changed

+32
-77
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,6 @@ class ASTContext final {
553553
ForeignLanguage language,
554554
const DeclContext *dc);
555555

556-
/// Add a declaration that was synthesized to a per-source file list if
557-
/// if is part of a source file.
558-
void addSynthesizedDecl(Decl *decl);
559-
560556
/// Add a cleanup function to be called when the ASTContext is deallocated.
561557
void addCleanup(std::function<void(void)> cleanup);
562558

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ class SourceFile final : public FileUnit {
147147
/// A set of synthesized declarations that need to be type checked.
148148
llvm::SmallVector<Decl *, 8> SynthesizedDecls;
149149

150-
/// We might perform type checking on the same source file more than once,
151-
/// if its the main file or a REPL instance, so keep track of the last
152-
/// checked synthesized declaration to avoid duplicating work.
153-
unsigned LastCheckedSynthesizedDecl = 0;
154-
155150
/// A mapping from Objective-C selectors to the methods that have
156151
/// those selectors.
157152
llvm::DenseMap<ObjCSelector, llvm::TinyPtrVector<AbstractFunctionDecl *>>

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,12 +1366,6 @@ bool ASTContext::hasArrayLiteralIntrinsics() const {
13661366
&& getDeallocateUninitializedArray();
13671367
}
13681368

1369-
void ASTContext::addSynthesizedDecl(Decl *decl) {
1370-
auto *fileUnit = decl->getDeclContext()->getModuleScopeContext();
1371-
if (auto *sf = dyn_cast<SourceFile>(fileUnit))
1372-
sf->SynthesizedDecls.push_back(decl);
1373-
}
1374-
13751369
void ASTContext::addCleanup(std::function<void(void)> cleanup) {
13761370
getImpl().Cleanups.push_back(std::move(cleanup));
13771371
}

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,8 @@ static FuncDecl *deriveEncodable_encode(DerivedConformance &derived) {
741741
encodeDecl->copyFormalAccessFrom(derived.Nominal,
742742
/*sourceIsParentContext*/ true);
743743

744-
C.addSynthesizedDecl(encodeDecl);
745-
746744
derived.addMembersToConformanceContext({encodeDecl});
745+
747746
return encodeDecl;
748747
}
749748

@@ -1019,9 +1018,8 @@ static ValueDecl *deriveDecodable_init(DerivedConformance &derived) {
10191018
initDecl->copyFormalAccessFrom(derived.Nominal,
10201019
/*sourceIsParentContext*/ true);
10211020

1022-
C.addSynthesizedDecl(initDecl);
1023-
10241021
derived.addMembersToConformanceContext({initDecl});
1022+
10251023
return initDecl;
10261024
}
10271025

lib/Sema/DerivedConformanceCodingKey.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ static ValueDecl *deriveInitDecl(DerivedConformance &derived, Type paramType,
145145

146146
initDecl->setAccess(derived.Nominal->getFormalAccess());
147147

148-
C.addSynthesizedDecl(initDecl);
149-
150148
derived.addMembersToConformanceContext({initDecl});
149+
151150
return initDecl;
152151
}
153152

@@ -176,9 +175,7 @@ static ValueDecl *deriveProperty(DerivedConformance &derived, Type type,
176175
// Synthesize the body.
177176
synthesizer(getterDecl);
178177

179-
auto *dc = cast<IterableDeclContext>(derived.ConformanceDecl);
180-
dc->addMember(propDecl);
181-
dc->addMember(pbDecl);
178+
derived.addMembersToConformanceContext({propDecl, pbDecl});
182179
return propDecl;
183180
}
184181

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,6 @@ deriveEquatable_eq(
769769

770770
eqDecl->copyFormalAccessFrom(derived.Nominal, /*sourceIsParentContext*/ true);
771771

772-
C.addSynthesizedDecl(eqDecl);
773-
774772
// Add the operator to the parent scope.
775773
derived.addMembersToConformanceContext({eqDecl});
776774

@@ -890,9 +888,8 @@ deriveHashable_hashInto(
890888

891889
hashDecl->copyFormalAccessFrom(derived.Nominal);
892890

893-
C.addSynthesizedDecl(hashDecl);
894-
895891
derived.addMembersToConformanceContext({hashDecl});
892+
896893
return hashDecl;
897894
}
898895

@@ -1253,10 +1250,12 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
12531250
auto *patDecl = PatternBindingDecl::createImplicit(
12541251
C, StaticSpellingKind::None, hashValuePat, /*InitExpr*/ nullptr,
12551252
parentDC);
1256-
C.addSynthesizedDecl(hashValueDecl);
1257-
C.addSynthesizedDecl(getterDecl);
12581253

1259-
derived.addMembersToConformanceContext({hashValueDecl, patDecl});
1254+
// If any of the members we synthesized didn't typecheck, bail out.
1255+
if (derived.addMembersToConformanceContext({hashValueDecl, patDecl})) {
1256+
return nullptr;
1257+
}
1258+
12601259
return hashValueDecl;
12611260
}
12621261

lib/Sema/DerivedConformanceRawRepresentable.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,6 @@ deriveRawRepresentable_init(DerivedConformance &derived) {
434434
// an instance without function call overhead.
435435
maybeMarkAsInlinable(derived, initDecl);
436436

437-
C.addSynthesizedDecl(initDecl);
438-
439437
derived.addMembersToConformanceContext({initDecl});
440438
return initDecl;
441439
}

lib/Sema/DerivedConformances.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ DeclContext *DerivedConformance::getConformanceContext() const {
3535
return cast<DeclContext>(ConformanceDecl);
3636
}
3737

38-
void DerivedConformance::addMembersToConformanceContext(
38+
bool DerivedConformance::addMembersToConformanceContext(
3939
ArrayRef<Decl *> children) {
4040
auto IDC = cast<IterableDeclContext>(ConformanceDecl);
41+
bool anyInvalid = false;
4142
for (auto child : children) {
4243
IDC->addMember(child);
44+
TypeChecker::typeCheckDecl(child);
45+
anyInvalid |= child->isInvalid();
4346
}
47+
return anyInvalid;
4448
}
4549

4650
Type DerivedConformance::getProtocolType() const {
@@ -281,39 +285,28 @@ DerivedConformance::createSelfDeclRef(AbstractFunctionDecl *fn) {
281285
AccessorDecl *DerivedConformance::
282286
addGetterToReadOnlyDerivedProperty(VarDecl *property,
283287
Type propertyContextType) {
284-
auto getter =
285-
declareDerivedPropertyGetter(property, propertyContextType);
286-
287-
property->setImplInfo(StorageImplInfo::getImmutableComputed());
288-
property->setAccessors(SourceLoc(), {getter}, SourceLoc());
289-
290-
return getter;
291-
}
292-
293-
AccessorDecl *
294-
DerivedConformance::declareDerivedPropertyGetter(VarDecl *property,
295-
Type propertyContextType) {
296288
auto &C = property->getASTContext();
297289
auto parentDC = property->getDeclContext();
298290
ParameterList *params = ParameterList::createEmpty(C);
299291

300292
Type propertyInterfaceType = property->getInterfaceType();
301-
302-
auto getterDecl = AccessorDecl::create(C,
293+
294+
auto getter = AccessorDecl::create(C,
303295
/*FuncLoc=*/SourceLoc(), /*AccessorKeywordLoc=*/SourceLoc(),
304296
AccessorKind::Get, property,
305297
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
306298
/*Throws=*/false, /*ThrowsLoc=*/SourceLoc(),
307299
/*GenericParams=*/nullptr, params,
308300
TypeLoc::withoutLoc(propertyInterfaceType), parentDC);
309-
getterDecl->setImplicit();
310-
getterDecl->setIsTransparent(false);
301+
getter->setImplicit();
302+
getter->setIsTransparent(false);
311303

312-
getterDecl->copyFormalAccessFrom(property);
304+
getter->copyFormalAccessFrom(property);
313305

314-
C.addSynthesizedDecl(getterDecl);
306+
property->setImplInfo(StorageImplInfo::getImmutableComputed());
307+
property->setAccessors(SourceLoc(), {getter}, SourceLoc());
315308

316-
return getterDecl;
309+
return getter;
317310
}
318311

319312
std::pair<VarDecl *, PatternBindingDecl *>

lib/Sema/DerivedConformances.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class DerivedConformance {
4646
DeclContext *getConformanceContext() const;
4747

4848
/// Add \c children as members of the context that declares the conformance.
49-
void addMembersToConformanceContext(ArrayRef<Decl *> children);
49+
///
50+
/// \returns True if any of the added members were found to be invalid after type
51+
/// checking.
52+
bool addMembersToConformanceContext(ArrayRef<Decl *> children);
5053

5154
/// Get the declared type of the protocol that this is conformance is for.
5255
Type getProtocolType() const;
@@ -197,12 +200,7 @@ class DerivedConformance {
197200
/// Add a getter to a derived property. The property becomes read-only.
198201
static AccessorDecl *
199202
addGetterToReadOnlyDerivedProperty(VarDecl *property,
200-
Type propertyContextType);
201-
202-
/// Declare a getter for a derived property.
203-
/// The getter will not be added to the property yet.
204-
static AccessorDecl *declareDerivedPropertyGetter(VarDecl *property,
205-
Type propertyContextType);
203+
Type propertyContextType);
206204

207205
/// Build a reference to the 'self' decl of a derived function.
208206
static DeclRefExpr *createSelfDeclRef(AbstractFunctionDecl *fn);

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3641,6 +3641,7 @@ void TypeChecker::typeCheckDecl(Decl *D) {
36413641
// Returns 'nullptr' if this is the setter's 'newValue' parameter;
36423642
// otherwise, returns the corresponding parameter of the subscript
36433643
// declaration.
3644+
36443645
static ParamDecl *getOriginalParamFromAccessor(AbstractStorageDecl *storage,
36453646
AccessorDecl *accessor,
36463647
ParamDecl *param) {

0 commit comments

Comments
 (0)