Skip to content

Commit e7c0172

Browse files
authored
Merge pull request #27546 from slavapestov/circular-validation-cleanups-3
Circular validation cleanups, part 3
2 parents e903595 + 52cf365 commit e7c0172

31 files changed

+327
-363
lines changed

include/swift/AST/ASTDemangler.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ class ASTBuilder {
5858
using BuiltTypeDecl = swift::GenericTypeDecl *; // nominal or type alias
5959
using BuiltProtocolDecl = swift::ProtocolDecl *;
6060
explicit ASTBuilder(ASTContext &ctx) : Ctx(ctx) {}
61-
62-
/// The resolver to use for type checking, if necessary.
63-
LazyResolver *Resolver = nullptr;
6461

6562
ASTContext &getASTContext() { return Ctx; }
6663
DeclContext *getNotionalDC();

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SWIFT_TYPEID_NAMED(InfixOperatorDecl *, InfixOperatorDecl)
3333
SWIFT_TYPEID_NAMED(IterableDeclContext *, IterableDeclContext)
3434
SWIFT_TYPEID_NAMED(ModuleDecl *, ModuleDecl)
3535
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
36+
SWIFT_TYPEID_NAMED(OpaqueTypeDecl *, OpaqueTypeDecl)
3637
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
3738
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
3839
PropertyWrapperMutability)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class IterableDeclContext;
3434
class ModuleDecl;
3535
class NominalTypeDecl;
3636
class OperatorDecl;
37+
class OpaqueTypeDecl;
3738
class PrecedenceGroupDecl;
3839
struct PropertyWrapperBackingPropertyInfo;
3940
struct PropertyWrapperTypeInfo;

include/swift/AST/Decl.h

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,10 @@ class alignas(1 << DeclAlignInBits) Decl {
418418
HasSingleExpressionBody : 1
419419
);
420420

421-
SWIFT_INLINE_BITFIELD(FuncDecl, AbstractFunctionDecl, 1+2+1+1+2,
421+
SWIFT_INLINE_BITFIELD(FuncDecl, AbstractFunctionDecl, 1+1+2+1+1+2,
422+
/// Whether we've computed the 'static' flag yet.
423+
IsStaticComputed : 1,
424+
422425
/// Whether this function is a 'static' method.
423426
IsStatic : 1,
424427

@@ -854,17 +857,6 @@ class alignas(1 << DeclAlignInBits) Decl {
854857
return getValidationState() > ValidationState::Unchecked;
855858
}
856859

857-
/// Manually indicate that validation is complete for the declaration. For
858-
/// example: during importing, code synthesis, or derived conformances.
859-
///
860-
/// For normal code validation, please use DeclValidationRAII instead.
861-
///
862-
/// FIXME -- Everything should use DeclValidationRAII instead of this.
863-
void setValidationToChecked() {
864-
if (!isBeingValidated())
865-
Bits.Decl.ValidationState = unsigned(ValidationState::Checked);
866-
}
867-
868860
bool escapedFromIfConfig() const {
869861
return Bits.Decl.EscapedFromIfConfig;
870862
}
@@ -2605,6 +2597,9 @@ class ValueDecl : public Decl {
26052597
/// if the base declaration is \c open, the override might have to be too.
26062598
bool hasOpenAccess(const DeclContext *useDC) const;
26072599

2600+
/// FIXME: This is deprecated.
2601+
bool isRecursiveValidation() const;
2602+
26082603
/// Retrieve the "interface" type of this value, which uses
26092604
/// GenericTypeParamType if the declaration is generic. For a generic
26102605
/// function, this will have a GenericFunctionType with a
@@ -2764,12 +2759,6 @@ class ValueDecl : public Decl {
27642759
/// Get the representative for this value's opaque result type, if it has one.
27652760
OpaqueReturnTypeRepr *getOpaqueResultTypeRepr() const;
27662761

2767-
/// Set the opaque return type decl for this decl.
2768-
///
2769-
/// `this` must be of a decl type that supports opaque return types, and
2770-
/// must not have previously had an opaque result type set.
2771-
void setOpaqueResultTypeDecl(OpaqueTypeDecl *D);
2772-
27732762
/// Retrieve the attribute associating this declaration with a
27742763
/// function builder, if there is one.
27752764
CustomAttr *getAttachedFunctionBuilder() const;
@@ -4530,8 +4519,6 @@ class AbstractStorageDecl : public ValueDecl {
45304519
Bits.AbstractStorageDecl.IsStatic = IsStatic;
45314520
}
45324521

4533-
OpaqueTypeDecl *OpaqueReturn = nullptr;
4534-
45354522
public:
45364523

45374524
/// Should this declaration be treated as if annotated with transparent
@@ -4789,14 +4776,6 @@ class AbstractStorageDecl : public ValueDecl {
47894776

47904777
bool hasAnyDynamicReplacementAccessors() const;
47914778

4792-
OpaqueTypeDecl *getOpaqueResultTypeDecl() const {
4793-
return OpaqueReturn;
4794-
}
4795-
void setOpaqueResultTypeDecl(OpaqueTypeDecl *decl) {
4796-
assert(!OpaqueReturn && "already has opaque type decl");
4797-
OpaqueReturn = decl;
4798-
}
4799-
48004779
// Implement isa/cast/dyncast/etc.
48014780
static bool classof(const Decl *D) {
48024781
return D->getKind() >= DeclKind::First_AbstractStorageDecl &&
@@ -5976,14 +5955,13 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, SelfAccessKind SAK);
59765955
class FuncDecl : public AbstractFunctionDecl {
59775956
friend class AbstractFunctionDecl;
59785957
friend class SelfAccessKindRequest;
5958+
friend class IsStaticRequest;
59795959

59805960
SourceLoc StaticLoc; // Location of the 'static' token or invalid.
59815961
SourceLoc FuncLoc; // Location of the 'func' token.
59825962

59835963
TypeLoc FnRetType;
59845964

5985-
OpaqueTypeDecl *OpaqueReturn = nullptr;
5986-
59875965
protected:
59885966
FuncDecl(DeclKind Kind,
59895967
SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
@@ -5999,14 +5977,14 @@ class FuncDecl : public AbstractFunctionDecl {
59995977
StaticLoc(StaticLoc), FuncLoc(FuncLoc) {
60005978
assert(!Name.getBaseName().isSpecial());
60015979

6002-
Bits.FuncDecl.IsStatic =
6003-
StaticLoc.isValid() || StaticSpelling != StaticSpellingKind::None;
60045980
Bits.FuncDecl.StaticSpelling = static_cast<unsigned>(StaticSpelling);
60055981

60065982
Bits.FuncDecl.ForcedStaticDispatch = false;
60075983
Bits.FuncDecl.SelfAccess =
60085984
static_cast<unsigned>(SelfAccessKind::NonMutating);
60095985
Bits.FuncDecl.SelfAccessComputed = false;
5986+
Bits.FuncDecl.IsStaticComputed = false;
5987+
Bits.FuncDecl.IsStatic = false;
60105988
}
60115989

60125990
private:
@@ -6026,6 +6004,13 @@ class FuncDecl : public AbstractFunctionDecl {
60266004
return None;
60276005
}
60286006

6007+
Optional<bool> getCachedIsStatic() const {
6008+
if (Bits.FuncDecl.IsStaticComputed)
6009+
return Bits.FuncDecl.IsStatic;
6010+
6011+
return None;
6012+
}
6013+
60296014
public:
60306015
/// Factory function only for use by deserialization.
60316016
static FuncDecl *createDeserialized(ASTContext &Context, SourceLoc StaticLoc,
@@ -6048,16 +6033,16 @@ class FuncDecl : public AbstractFunctionDecl {
60486033

60496034
Identifier getName() const { return getFullName().getBaseIdentifier(); }
60506035

6051-
bool isStatic() const {
6052-
return Bits.FuncDecl.IsStatic;
6053-
}
6036+
bool isStatic() const;
6037+
60546038
/// \returns the way 'static'/'class' was spelled in the source.
60556039
StaticSpellingKind getStaticSpelling() const {
60566040
return static_cast<StaticSpellingKind>(Bits.FuncDecl.StaticSpelling);
60576041
}
60586042
/// \returns the way 'static'/'class' should be spelled for this declaration.
60596043
StaticSpellingKind getCorrectStaticSpelling() const;
60606044
void setStatic(bool IsStatic = true) {
6045+
Bits.FuncDecl.IsStaticComputed = true;
60616046
Bits.FuncDecl.IsStatic = IsStatic;
60626047
}
60636048

@@ -6129,15 +6114,7 @@ class FuncDecl : public AbstractFunctionDecl {
61296114
}
61306115

61316116
OperatorDecl *getOperatorDecl() const;
6132-
6133-
OpaqueTypeDecl *getOpaqueResultTypeDecl() const {
6134-
return OpaqueReturn;
6135-
}
6136-
void setOpaqueResultTypeDecl(OpaqueTypeDecl *decl) {
6137-
assert(!OpaqueReturn && "already has opaque type decl");
6138-
OpaqueReturn = decl;
6139-
}
6140-
6117+
61416118
/// Returns true if the function is forced to be statically dispatched.
61426119
bool hasForcedStaticDispatch() const {
61436120
return Bits.FuncDecl.ForcedStaticDispatch;

include/swift/AST/FileUnit.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ class FileUnit : public DeclContext {
6060

6161
/// Look up an opaque return type by the mangled name of the declaration
6262
/// that defines it.
63-
virtual OpaqueTypeDecl *lookupOpaqueResultType(StringRef MangledName,
64-
LazyResolver *resolver) {
63+
virtual OpaqueTypeDecl *lookupOpaqueResultType(StringRef MangledName) {
6564
return nullptr;
6665
}
6766

include/swift/AST/Module.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
354354

355355
/// Look up an opaque return type by the mangled name of the declaration
356356
/// that defines it.
357-
OpaqueTypeDecl *lookupOpaqueResultType(StringRef MangledName,
358-
LazyResolver *resolver);
357+
OpaqueTypeDecl *lookupOpaqueResultType(StringRef MangledName);
359358

360359
/// Find ValueDecls in the module and pass them to the given consumer object.
361360
///

include/swift/AST/SourceFile.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ class SourceFile final : public FileUnit {
117117
/// The scope map that describes this source file.
118118
std::unique_ptr<ASTScope> Scope;
119119

120+
/// The set of validated opaque return type decls in the source file.
121+
llvm::SmallVector<OpaqueTypeDecl *, 4> OpaqueReturnTypes;
122+
llvm::StringMap<OpaqueTypeDecl *> ValidatedOpaqueReturnTypes;
123+
/// The set of parsed decls with opaque return types that have not yet
124+
/// been validated.
125+
llvm::SetVector<ValueDecl *> UnvalidatedDeclsWithOpaqueReturnTypes;
126+
120127
friend ASTContext;
121128
friend Impl;
122129
public:
@@ -130,13 +137,6 @@ class SourceFile final : public FileUnit {
130137
/// The list of local type declarations in the source file.
131138
llvm::SetVector<TypeDecl *> LocalTypeDecls;
132139

133-
/// The set of validated opaque return type decls in the source file.
134-
llvm::SmallVector<OpaqueTypeDecl *, 4> OpaqueReturnTypes;
135-
llvm::StringMap<OpaqueTypeDecl *> ValidatedOpaqueReturnTypes;
136-
/// The set of parsed decls with opaque return types that have not yet
137-
/// been validated.
138-
llvm::DenseSet<ValueDecl *> UnvalidatedDeclsWithOpaqueReturnTypes;
139-
140140
/// A set of special declaration attributes which require the
141141
/// Foundation module to be imported to work. If the foundation
142142
/// module is still not imported by the time type checking is
@@ -430,14 +430,13 @@ class SourceFile final : public FileUnit {
430430
void setSyntaxRoot(syntax::SourceFileSyntax &&Root);
431431
bool hasSyntaxRoot() const;
432432

433-
OpaqueTypeDecl *lookupOpaqueResultType(StringRef MangledName,
434-
LazyResolver *resolver) override;
433+
OpaqueTypeDecl *lookupOpaqueResultType(StringRef MangledName) override;
435434

436435
void addUnvalidatedDeclWithOpaqueResultType(ValueDecl *vd) {
437436
UnvalidatedDeclsWithOpaqueReturnTypes.insert(vd);
438437
}
439438

440-
void markDeclWithOpaqueResultTypeAsValidated(ValueDecl *vd);
439+
ArrayRef<OpaqueTypeDecl *> getOpaqueReturnTypeDecls();
441440

442441
private:
443442

include/swift/AST/TypeCheckRequests.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ class GenericSignatureRequest :
11881188
void cacheResult(GenericSignature value) const;
11891189
};
11901190

1191-
/// Compute the interface type of the underlying definition type of a typealias declaration.
1191+
/// Compute the underlying interface type of a typealias.
11921192
class UnderlyingTypeRequest :
11931193
public SimpleRequest<UnderlyingTypeRequest,
11941194
Type(TypeAliasDecl *),
@@ -1211,6 +1211,7 @@ class UnderlyingTypeRequest :
12111211
void diagnoseCycle(DiagnosticEngine &diags) const;
12121212
};
12131213

1214+
/// Looks up the precedence group of an operator declaration.
12141215
class OperatorPrecedenceGroupRequest
12151216
: public SimpleRequest<OperatorPrecedenceGroupRequest,
12161217
PrecedenceGroupDecl *(InfixOperatorDecl *),
@@ -1272,6 +1273,47 @@ class IsABICompatibleOverrideRequest
12721273
bool isCached() const { return true; }
12731274
};
12741275

1276+
/// Builds an opaque result type for a declaration.
1277+
class OpaqueResultTypeRequest
1278+
: public SimpleRequest<OpaqueResultTypeRequest,
1279+
OpaqueTypeDecl *(ValueDecl *),
1280+
CacheKind::Cached> {
1281+
public:
1282+
using SimpleRequest::SimpleRequest;
1283+
1284+
private:
1285+
friend SimpleRequest;
1286+
1287+
llvm::Expected<OpaqueTypeDecl *>
1288+
evaluate(Evaluator &evaluator, ValueDecl *VD) const;
1289+
1290+
public:
1291+
// Caching.
1292+
bool isCached() const { return true; }
1293+
};
1294+
1295+
/// Determines if a function declaration is 'static'.
1296+
class IsStaticRequest :
1297+
public SimpleRequest<IsStaticRequest,
1298+
bool(FuncDecl *),
1299+
CacheKind::SeparatelyCached> {
1300+
public:
1301+
using SimpleRequest::SimpleRequest;
1302+
1303+
private:
1304+
friend SimpleRequest;
1305+
1306+
// Evaluation.
1307+
llvm::Expected<bool>
1308+
evaluate(Evaluator &evaluator, FuncDecl *value) const;
1309+
1310+
public:
1311+
// Separate caching.
1312+
bool isCached() const { return true; }
1313+
Optional<bool> getCachedResult() const;
1314+
void cacheResult(bool value) const;
1315+
};
1316+
12751317
// Allow AnyValue to compare two Type values, even though Type doesn't
12761318
// support ==.
12771319
template<>

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ SWIFT_REQUEST(TypeChecker, MangleLocalTypeDeclRequest,
8888
SWIFT_REQUEST(TypeChecker, OpaqueReadOwnershipRequest,
8989
OpaqueReadOwnership(AbstractStorageDecl *), SeparatelyCached,
9090
NoLocationInfo)
91+
SWIFT_REQUEST(TypeChecker, OpaqueResultTypeRequest,
92+
OpaqueTypeDecl *(ValueDecl *),
93+
Cached, NoLocationInfo)
9194
SWIFT_REQUEST(TypeChecker, OperatorPrecedenceGroupRequest,
9295
PrecedenceGroupDecl *(PrecedenceGroupDecl *),
9396
Cached, NoLocationInfo)
@@ -144,3 +147,5 @@ SWIFT_REQUEST(TypeChecker, USRGenerationRequest, std::string(const ValueDecl *),
144147
Cached, NoLocationInfo)
145148
SWIFT_REQUEST(TypeChecker, IsABICompatibleOverrideRequest,
146149
bool(ValueDecl *), Cached, NoLocationInfo)
150+
SWIFT_REQUEST(TypeChecker, IsStaticRequest,
151+
bool(FuncDecl *), SeparatelyCached, NoLocationInfo)

include/swift/Sema/IDETypeChecking.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ namespace swift {
3636
class ValueDecl;
3737
class DeclName;
3838

39-
/// Typecheck a declaration parsed during code completion.
40-
void typeCheckCompletionDecl(Decl *D);
41-
4239
/// Typecheck binding initializer at \p bindingIndex.
4340
void typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned bindingIndex);
4441

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class SerializedASTFile final : public LoadedFile {
278278
virtual TypeDecl *lookupLocalType(StringRef MangledName) const override;
279279

280280
virtual OpaqueTypeDecl *
281-
lookupOpaqueResultType(StringRef MangledName, LazyResolver *resolver) override;
281+
lookupOpaqueResultType(StringRef MangledName) override;
282282

283283
virtual TypeDecl *
284284
lookupNestedType(Identifier name,

lib/AST/ASTDemangler.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ Type ASTBuilder::resolveOpaqueType(NodePointer opaqueDescriptor,
259259
if (!parentModule)
260260
return Type();
261261

262-
auto opaqueDecl = parentModule->lookupOpaqueResultType(mangledName,
263-
Resolver);
262+
auto opaqueDecl = parentModule->lookupOpaqueResultType(mangledName);
264263
if (!opaqueDecl)
265264
return Type();
266265
// TODO: multiple opaque types

lib/AST/ASTVerifier.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,12 +3190,6 @@ class Verifier : public ASTWalker {
31903190
void verifyParsed(AccessorDecl *FD) {
31913191
PrettyStackTraceDecl debugStack("verifying AccessorDecl", FD);
31923192

3193-
auto storage = FD->getStorage();
3194-
if (storage->isStatic() != FD->isStatic()) {
3195-
Out << "accessor static-ness must match static-ness of storage\n";
3196-
abort();
3197-
}
3198-
31993193
verifyParsedBase(FD);
32003194
}
32013195

0 commit comments

Comments
 (0)