Skip to content

Commit 7d2dac1

Browse files
committed
Define Requests
Define the LookupPrecedenceGroupRequest and OperatorPrecedenceGroupRequest for looking up an unvalidated precedence group declaration and retrieving then validating the precedence group associated with an operator. This allows us to drop both validateDecl overloads for these types out of the TypeChechecker
1 parent b09631f commit 7d2dac1

File tree

8 files changed

+101
-1
lines changed

8 files changed

+101
-1
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ SWIFT_TYPEID_NAMED(Decl *, Decl)
2828
SWIFT_TYPEID_NAMED(GenericParamList *, GenericParamList)
2929
SWIFT_TYPEID_NAMED(GenericSignature *, GenericSignature)
3030
SWIFT_TYPEID_NAMED(GenericTypeParamType *, GenericTypeParamType)
31+
SWIFT_TYPEID_NAMED(InfixOperatorDecl *, InfixOperatorDecl)
3132
SWIFT_TYPEID_NAMED(IterableDeclContext *, IterableDeclContext)
3233
SWIFT_TYPEID_NAMED(ModuleDecl *, ModuleDecl)
3334
SWIFT_TYPEID_NAMED(NominalTypeDecl *, NominalTypeDecl)
3435
SWIFT_TYPEID_NAMED(OperatorDecl *, OperatorDecl)
3536
SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>,
3637
PropertyWrapperMutability)
38+
SWIFT_TYPEID_NAMED(PrecedenceGroupDecl *, PrecedenceGroupDecl)
3739
SWIFT_TYPEID_NAMED(ProtocolDecl *, ProtocolDecl)
3840
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)
3941
SWIFT_TYPEID_NAMED(ValueDecl *, ValueDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ class Decl;
2626
class GenericParamList;
2727
class GenericSignature;
2828
class GenericTypeParamType;
29+
class InfixOperatorDecl;
2930
class IterableDeclContext;
3031
class ModuleDecl;
3132
class NominalTypeDecl;
3233
class OperatorDecl;
34+
class PrecedenceGroupDecl;
3335
struct PropertyWrapperBackingPropertyInfo;
3436
struct PropertyWrapperTypeInfo;
3537
enum class CtorInitializerKind;

include/swift/AST/NameLookupRequests.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "swift/AST/SimpleRequest.h"
2020
#include "swift/AST/ASTTypeIDs.h"
2121
#include "swift/Basic/Statistic.h"
22+
#include "llvm/ADT/Hashing.h"
2223
#include "llvm/ADT/TinyPtrVector.h"
2324

2425
namespace swift {
@@ -273,6 +274,56 @@ class GenericParamListRequest :
273274
void cacheResult(GenericParamList *value) const;
274275
};
275276

277+
struct PrecedenceGroupDescriptor {
278+
DeclContext *dc;
279+
Identifier ident;
280+
SourceLoc nameLoc;
281+
282+
SourceLoc getLoc() const;
283+
284+
friend llvm::hash_code hash_value(const PrecedenceGroupDescriptor &owner) {
285+
return hash_combine(llvm::hash_value(owner.dc),
286+
llvm::hash_value(owner.ident.getAsOpaquePointer()),
287+
llvm::hash_value(owner.nameLoc.getOpaquePointerValue()));
288+
}
289+
290+
friend bool operator==(const PrecedenceGroupDescriptor &lhs,
291+
const PrecedenceGroupDescriptor &rhs) {
292+
return lhs.dc == rhs.dc &&
293+
lhs.ident == rhs.ident &&
294+
lhs.nameLoc == rhs.nameLoc;
295+
}
296+
297+
friend bool operator!=(const PrecedenceGroupDescriptor &lhs,
298+
const PrecedenceGroupDescriptor &rhs) {
299+
return !(lhs == rhs);
300+
}
301+
};
302+
303+
void simple_display(llvm::raw_ostream &out, const PrecedenceGroupDescriptor &d);
304+
305+
class LookupPrecedenceGroupRequest
306+
: public SimpleRequest<LookupPrecedenceGroupRequest,
307+
PrecedenceGroupDecl *(PrecedenceGroupDescriptor),
308+
CacheKind::Cached> {
309+
public:
310+
using SimpleRequest::SimpleRequest;
311+
312+
private:
313+
friend SimpleRequest;
314+
315+
// Evaluation.
316+
llvm::Expected<PrecedenceGroupDecl *>
317+
evaluate(Evaluator &evaluator, PrecedenceGroupDescriptor descriptor) const;
318+
319+
public:
320+
// Source location
321+
SourceLoc getNearestLoc() const;
322+
323+
// Separate caching.
324+
bool isCached() const { return true; }
325+
};
326+
276327
#define SWIFT_TYPEID_ZONE NameLookup
277328
#define SWIFT_TYPEID_HEADER "swift/AST/NameLookupTypeIDZone.def"
278329
#include "swift/Basic/DefineTypeIDZone.h"

include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ SWIFT_REQUEST(NameLookup, InheritedDeclsReferencedRequest,
3030
DirectlyReferencedTypeDecls(
3131
llvm::PointerUnion<TypeDecl *, ExtensionDecl *>, unsigned),
3232
Uncached, HasNearestLocation)
33+
SWIFT_REQUEST(NameLookup, LookupPrecedenceGroupRequest,
34+
PrecedenceGroupDecl *(DeclContext *, Identifier, SourceLoc),
35+
Cached, NoLocationInfo)
3336
SWIFT_REQUEST(NameLookup, SelfBoundsFromWhereClauseRequest,
3437
SelfBounds(llvm::PointerUnion<TypeDecl *, ExtensionDecl *>),
3538
Uncached, NoLocationInfo)

include/swift/AST/TypeCheckRequests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AbstractStorageDecl;
3333
class AccessorDecl;
3434
enum class AccessorKind;
3535
class GenericParamList;
36+
class PrecedenceGroupDecl;
3637
struct PropertyWrapperBackingPropertyInfo;
3738
struct PropertyWrapperMutability;
3839
class RequirementRepr;
@@ -1209,6 +1210,25 @@ class UnderlyingTypeRequest :
12091210
void cacheResult(Type value) const;
12101211
};
12111212

1213+
class OperatorPrecedenceGroupRequest
1214+
: public SimpleRequest<OperatorPrecedenceGroupRequest,
1215+
PrecedenceGroupDecl *(InfixOperatorDecl *),
1216+
CacheKind::Cached> {
1217+
public:
1218+
using SimpleRequest::SimpleRequest;
1219+
1220+
private:
1221+
friend SimpleRequest;
1222+
1223+
// Evaluation.
1224+
llvm::Expected<PrecedenceGroupDecl *>
1225+
evaluate(Evaluator &evaluator, InfixOperatorDecl *PGD) const;
1226+
1227+
public:
1228+
// Separate caching.
1229+
bool isCached() const { return true; }
1230+
};
1231+
12121232
// Allow AnyValue to compare two Type values, even though Type doesn't
12131233
// support ==.
12141234
template<>

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ SWIFT_REQUEST(TypeChecker, MangleLocalTypeDeclRequest,
8585
SWIFT_REQUEST(TypeChecker, OpaqueReadOwnershipRequest,
8686
OpaqueReadOwnership(AbstractStorageDecl *), SeparatelyCached,
8787
NoLocationInfo)
88+
SWIFT_REQUEST(TypeChecker, OperatorPrecedenceGroupRequest,
89+
PrecedenceGroupDecl *(PrecedenceGroupDecl *),
90+
Cached, NoLocationInfo)
8891
SWIFT_REQUEST(TypeChecker, OverriddenDeclsRequest,
8992
llvm::TinyPtrVector<ValueDecl *>(ValueDecl *), SeparatelyCached,
9093
NoLocationInfo)

lib/AST/NameLookupRequests.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,25 @@ void GenericParamListRequest::cacheResult(GenericParamList *params) const {
127127
}
128128

129129

130+
//----------------------------------------------------------------------------//
131+
// LookupPrecedenceGroupRequest computation.
132+
//----------------------------------------------------------------------------//
133+
134+
SourceLoc LookupPrecedenceGroupRequest::getNearestLoc() const {
135+
auto &desc = std::get<0>(getStorage());
136+
return desc.getLoc();
137+
}
138+
139+
SourceLoc PrecedenceGroupDescriptor::getLoc() const {
140+
return nameLoc;
141+
}
142+
143+
void swift::simple_display(llvm::raw_ostream &out,
144+
const PrecedenceGroupDescriptor &desc) {
145+
out << "precedence group " << desc.ident << " at ";
146+
desc.nameLoc.print(out, desc.dc->getASTContext().SourceMgr);
147+
}
148+
130149
// Define request evaluation functions for each of the name lookup requests.
131150
static AbstractRequestFunction *nameLookupRequestFunctions[] = {
132151
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \

lib/AST/TypeCheckRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ void GenericSignatureRequest::cacheResult(GenericSignature *value) const {
832832
}
833833

834834
//----------------------------------------------------------------------------//
835-
// GenericSignatureRequest computation.
835+
// InferredGenericSignatureRequest computation.
836836
//----------------------------------------------------------------------------//
837837

838838
void InferredGenericSignatureRequest::noteCycleStep(DiagnosticEngine &d) const {

0 commit comments

Comments
 (0)