Skip to content

Commit 5a38d65

Browse files
committed
Move 'ConstExtract' request from TypeCheckRequest into its own component's collection of requests.
1 parent e79aefa commit 5a38d65

File tree

13 files changed

+135
-29
lines changed

13 files changed

+135
-29
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SWIFT_TYPEID_NAMED(CodeCompletionCallbacksFactory *,
4848
CodeCompletionCallbacksFactory)
4949
SWIFT_TYPEID_NAMED(ConstructorDecl *, ConstructorDecl)
5050
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
51+
SWIFT_TYPEID_NAMED(ConstValueTypeInfo *, ConstValueTypeInfo)
5152
SWIFT_TYPEID_NAMED(Decl *, Decl)
5253
SWIFT_TYPEID_NAMED(EnumDecl *, EnumDecl)
5354
SWIFT_TYPEID_NAMED(FuncDecl *, FuncDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ enum class ImplicitMemberAction : uint8_t;
8282
struct FingerprintAndMembers;
8383
class Identifier;
8484
class BodyAndFingerprint;
85+
struct ConstValueTypeInfo;
8586

8687
// Define the AST type zone (zone 1)
8788
#define SWIFT_TYPEID_ZONE AST

include/swift/AST/ConstTypeInfo.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace swift {
2121
class NominalTypeDecl;
2222
class VarDecl;
2323
class Type;
24-
} // namespace swift
2524

2625
/// Representation of a compile-time-known value, for example
2726
/// in a type property initializer expression
@@ -43,7 +42,7 @@ class CompileTimeValue {
4342
class RawLiteralValue : public CompileTimeValue {
4443
public:
4544
RawLiteralValue(std::string Value)
46-
: CompileTimeValue(ValueKind::RawLiteral), Value(Value) {}
45+
: CompileTimeValue(ValueKind::RawLiteral), Value(Value) {}
4746

4847
std::string getValue() const { return Value; }
4948

@@ -70,8 +69,8 @@ struct FunctionParameter {
7069
class InitCallValue : public CompileTimeValue {
7170
public:
7271
InitCallValue(std::string Name, std::vector<FunctionParameter> Parameters)
73-
: CompileTimeValue(ValueKind::InitCall), Name(Name),
74-
Parameters(Parameters) {}
72+
: CompileTimeValue(ValueKind::InitCall), Name(Name),
73+
Parameters(Parameters) {}
7574

7675
static bool classof(const CompileTimeValue *T) {
7776
return T->getKind() == ValueKind::InitCall;
@@ -127,5 +126,5 @@ struct ConstValueTypeInfo {
127126
swift::NominalTypeDecl *TypeDecl;
128127
std::vector<ConstValueTypePropertyInfo> Properties;
129128
};
130-
129+
} // namespace swift
131130
#endif

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
#include "swift/AST/ActorIsolation.h"
2020
#include "swift/AST/AnyFunctionRef.h"
21-
#include "swift/AST/ConstTypeInfo.h"
2221
#include "swift/AST/ASTNode.h"
2322
#include "swift/AST/ASTTypeIDs.h"
2423
#include "swift/AST/Effects.h"
@@ -714,26 +713,6 @@ class PropertyWrapperTypeInfoRequest
714713
bool isCached() const { return true; }
715714
};
716715

717-
/// Retrieve information about compile-time-known
718-
class ConstantValueInfoRequest
719-
: public SimpleRequest<ConstantValueInfoRequest,
720-
ConstValueTypeInfo(NominalTypeDecl *),
721-
RequestFlags::Cached> {
722-
public:
723-
using SimpleRequest::SimpleRequest;
724-
725-
private:
726-
friend SimpleRequest;
727-
728-
// Evaluation.
729-
ConstValueTypeInfo
730-
evaluate(Evaluator &eval, NominalTypeDecl *nominal) const;
731-
732-
public:
733-
// Caching
734-
bool isCached() const { return true; }
735-
};
736-
737716
/// Request the nominal type declaration to which the given custom attribute
738717
/// refers.
739718
class AttachedPropertyWrappersRequest :

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ SWIFT_REQUEST(TypeChecker, PropertyWrapperMutabilityRequest,
260260
SWIFT_REQUEST(TypeChecker, PropertyWrapperTypeInfoRequest,
261261
PropertyWrapperTypeInfo(NominalTypeDecl *), Cached,
262262
NoLocationInfo)
263-
SWIFT_REQUEST(TypeChecker, ConstantValueInfoRequest,
264-
ConstValueTypeInfo(NominalTypeDecl *), Cached,
265-
NoLocationInfo)
266263
SWIFT_REQUEST(TypeChecker, ProtocolRequiresClassRequest, bool(ProtocolDecl *),
267264
SeparatelyCached, NoLocationInfo)
268265
SWIFT_REQUEST(TypeChecker, PrimaryAssociatedTypesRequest,

include/swift/Basic/Statistics.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
261261
#include "swift/Sema/IDETypeCheckingRequestIDZone.def"
262262
#include "swift/IDE/IDERequestIDZone.def"
263263
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
264+
#include "swift/ConstExtract/ConstExtractTypeIDZone.def"
264265
#undef SWIFT_REQUEST
265266

266267
#define SWIFT_REQUEST(ZONE, NAME, Sig, Caching, LocOptions) FRONTEND_STATISTIC(SILGen, NAME)

include/swift/Basic/TypeIDZones.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ SWIFT_TYPEID_ZONE(IDE, 137)
3535

3636
SWIFT_TYPEID_ZONE(ClangImporter, 139)
3737

38+
SWIFT_TYPEID_ZONE(ConstExtract, 140)
39+
3840
// N.B. This is not a formal zone and exists solely to support the unit tests.
3941
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===------- ConstExtractRequests.h - Extraction Requests ------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines const-extraction requests.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
#ifndef SWIFT_CONST_EXTRACT_REQUESTS_H
17+
#define SWIFT_CONST_EXTRACT_REQUESTS_H
18+
19+
#include "swift/AST/SimpleRequest.h"
20+
#include "swift/AST/ASTTypeIDs.h"
21+
#include "swift/AST/ConstTypeInfo.h"
22+
#include "swift/AST/EvaluatorDependencies.h"
23+
#include "swift/AST/FileUnit.h"
24+
#include "swift/AST/Identifier.h"
25+
#include "swift/AST/NameLookup.h"
26+
#include "swift/Basic/Statistic.h"
27+
#include "llvm/ADT/Hashing.h"
28+
#include "llvm/ADT/TinyPtrVector.h"
29+
30+
namespace swift {
31+
32+
class Decl;
33+
class DeclName;
34+
class EnumDecl;
35+
36+
/// Retrieve information about compile-time-known values
37+
class ConstantValueInfoRequest
38+
: public SimpleRequest<ConstantValueInfoRequest,
39+
ConstValueTypeInfo(NominalTypeDecl *),
40+
RequestFlags::Cached> {
41+
public:
42+
using SimpleRequest::SimpleRequest;
43+
44+
private:
45+
friend SimpleRequest;
46+
47+
// Evaluation.
48+
ConstValueTypeInfo
49+
evaluate(Evaluator &eval, NominalTypeDecl *nominal) const;
50+
51+
public:
52+
// Caching
53+
bool isCached() const { return true; }
54+
};
55+
56+
#define SWIFT_TYPEID_ZONE ConstExtract
57+
#define SWIFT_TYPEID_HEADER "swift/ConstExtract/ConstExtractTypeIDZone.def"
58+
#include "swift/Basic/DefineTypeIDZone.h"
59+
#undef SWIFT_TYPEID_ZONE
60+
#undef SWIFT_TYPEID_HEADER
61+
62+
// Set up reporting of evaluated requests.
63+
template<typename Request>
64+
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
65+
const Request &request);
66+
67+
#define SWIFT_REQUEST(Zone, RequestType, Sig, Caching, LocOptions) \
68+
template <> \
69+
inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \
70+
const RequestType &request) { \
71+
++stats.getFrontendCounters().RequestType; \
72+
}
73+
#include "swift/ConstExtract/ConstExtractTypeIDZone.def"
74+
#undef SWIFT_REQUEST
75+
76+
} // end namespace swift
77+
78+
#endif // SWIFT_CONST_EXTRACT_REQUESTS_H
79+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===--- ConstExtractTypeIDZone.def ----------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This definition file describes the types in the const extract
14+
// TypeID zone, for use with the TypeID template.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
SWIFT_REQUEST(ConstExtract, ConstantValueInfoRequest,
19+
ConstValueTypeInfo(NominalTypeDecl *), Cached,
20+
NoLocationInfo)

include/swift/Subsystems.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ namespace swift {
386386
/// after forming the ASTContext.
387387
void registerClangImporterRequestFunctions(Evaluator &evaluator);
388388

389+
/// Register constant value extraction request functons with the evaluator.
390+
void registerConstExtractRequestFunctions(Evaluator &evaluator);
391+
389392
/// Register SILOptimizer passes necessary for IRGen.
390393
void registerIRGenSILTransforms(ASTContext &ctx);
391394

lib/ConstExtract/ConstExtract.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "swift/Basic/TypeID.h"
1314
#include "swift/ConstExtract/ConstExtract.h"
15+
#include "swift/ConstExtract/ConstExtractRequests.h"
1416
#include "swift/AST/ASTContext.h"
1517
#include "swift/AST/ASTWalker.h"
1618
#include "swift/AST/Decl.h"
@@ -23,6 +25,7 @@
2325
#include "llvm/Support/JSON.h"
2426
#include "llvm/Support/YAMLParser.h"
2527
#include "llvm/Support/YAMLTraits.h"
28+
#include "swift/Subsystems.h"
2629

2730
#include <set>
2831
#include <sstream>
@@ -239,3 +242,22 @@ bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
239242
}
240243

241244
} // namespace swift
245+
246+
#define SWIFT_TYPEID_ZONE ConstExtract
247+
#define SWIFT_TYPEID_HEADER "swift/ConstExtract/ConstExtractTypeIDZone.def"
248+
#include "swift/Basic/ImplementTypeIDZone.h"
249+
#undef SWIFT_TYPEID_ZONE
250+
#undef SWIFT_TYPEID_HEADER
251+
252+
// Define request evaluation functions for each of the name lookup requests.
253+
static AbstractRequestFunction *constExtractRequestFunctions[] = {
254+
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \
255+
reinterpret_cast<AbstractRequestFunction *>(&Name::evaluateRequest),
256+
#include "swift/ConstExtract/ConstExtractTypeIDZone.def"
257+
#undef SWIFT_REQUEST
258+
};
259+
260+
void swift::registerConstExtractRequestFunctions(Evaluator &evaluator) {
261+
evaluator.registerRequestFunctions(Zone::ConstExtract,
262+
constExtractRequestFunctions);
263+
}

lib/Frontend/Frontend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
239239
registerParseRequestFunctions(Context->evaluator);
240240
registerTypeCheckerRequestFunctions(Context->evaluator);
241241
registerClangImporterRequestFunctions(Context->evaluator);
242+
registerConstExtractRequestFunctions(Context->evaluator);
242243
registerSILGenRequestFunctions(Context->evaluator);
243244
registerSILOptimizerRequestFunctions(Context->evaluator);
244245
registerTBDGenRequestFunctions(Context->evaluator);

lib/IDETool/CompletionInstance.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
247247
registerIDERequestFunctions(tmpCtx->evaluator);
248248
registerTypeCheckerRequestFunctions(tmpCtx->evaluator);
249249
registerClangImporterRequestFunctions(tmpCtx->evaluator);
250+
registerConstExtractRequestFunctions(tmpCtx->evaluator);
250251
registerSILGenRequestFunctions(tmpCtx->evaluator);
251252
ModuleDecl *tmpM = ModuleDecl::create(Identifier(), *tmpCtx);
252253
SourceFile *tmpSF = new (*tmpCtx)

0 commit comments

Comments
 (0)