Skip to content

Move 'ConstExtract' request from TypeCheckRequest into its own component's collection of requests. #61792

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/AST/ASTTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ SWIFT_TYPEID_NAMED(CodeCompletionCallbacksFactory *,
CodeCompletionCallbacksFactory)
SWIFT_TYPEID_NAMED(ConstructorDecl *, ConstructorDecl)
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
SWIFT_TYPEID_NAMED(ConstValueTypeInfo *, ConstValueTypeInfo)
SWIFT_TYPEID_NAMED(Decl *, Decl)
SWIFT_TYPEID_NAMED(EnumDecl *, EnumDecl)
SWIFT_TYPEID_NAMED(FuncDecl *, FuncDecl)
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/ASTTypeIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum class ImplicitMemberAction : uint8_t;
struct FingerprintAndMembers;
class Identifier;
class BodyAndFingerprint;
struct ConstValueTypeInfo;

// Define the AST type zone (zone 1)
#define SWIFT_TYPEID_ZONE AST
Expand Down
9 changes: 4 additions & 5 deletions include/swift/AST/ConstTypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace swift {
class NominalTypeDecl;
class VarDecl;
class Type;
} // namespace swift

/// Representation of a compile-time-known value, for example
/// in a type property initializer expression
Expand All @@ -43,7 +42,7 @@ class CompileTimeValue {
class RawLiteralValue : public CompileTimeValue {
public:
RawLiteralValue(std::string Value)
: CompileTimeValue(ValueKind::RawLiteral), Value(Value) {}
: CompileTimeValue(ValueKind::RawLiteral), Value(Value) {}

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

Expand All @@ -70,8 +69,8 @@ struct FunctionParameter {
class InitCallValue : public CompileTimeValue {
public:
InitCallValue(std::string Name, std::vector<FunctionParameter> Parameters)
: CompileTimeValue(ValueKind::InitCall), Name(Name),
Parameters(Parameters) {}
: CompileTimeValue(ValueKind::InitCall), Name(Name),
Parameters(Parameters) {}

static bool classof(const CompileTimeValue *T) {
return T->getKind() == ValueKind::InitCall;
Expand Down Expand Up @@ -127,5 +126,5 @@ struct ConstValueTypeInfo {
swift::NominalTypeDecl *TypeDecl;
std::vector<ConstValueTypePropertyInfo> Properties;
};

} // namespace swift
#endif
21 changes: 0 additions & 21 deletions include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include "swift/AST/ActorIsolation.h"
#include "swift/AST/AnyFunctionRef.h"
#include "swift/AST/ConstTypeInfo.h"
#include "swift/AST/ASTNode.h"
#include "swift/AST/ASTTypeIDs.h"
#include "swift/AST/Effects.h"
Expand Down Expand Up @@ -714,26 +713,6 @@ class PropertyWrapperTypeInfoRequest
bool isCached() const { return true; }
};

/// Retrieve information about compile-time-known
class ConstantValueInfoRequest
: public SimpleRequest<ConstantValueInfoRequest,
ConstValueTypeInfo(NominalTypeDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

// Evaluation.
ConstValueTypeInfo
evaluate(Evaluator &eval, NominalTypeDecl *nominal) const;

public:
// Caching
bool isCached() const { return true; }
};

/// Request the nominal type declaration to which the given custom attribute
/// refers.
class AttachedPropertyWrappersRequest :
Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/TypeCheckerTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ SWIFT_REQUEST(TypeChecker, PropertyWrapperMutabilityRequest,
SWIFT_REQUEST(TypeChecker, PropertyWrapperTypeInfoRequest,
PropertyWrapperTypeInfo(NominalTypeDecl *), Cached,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ConstantValueInfoRequest,
ConstValueTypeInfo(NominalTypeDecl *), Cached,
NoLocationInfo)
SWIFT_REQUEST(TypeChecker, ProtocolRequiresClassRequest, bool(ProtocolDecl *),
SeparatelyCached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, PrimaryAssociatedTypesRequest,
Expand Down
1 change: 1 addition & 0 deletions include/swift/Basic/Statistics.def
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts)
#include "swift/Sema/IDETypeCheckingRequestIDZone.def"
#include "swift/IDE/IDERequestIDZone.def"
#include "swift/ClangImporter/ClangImporterTypeIDZone.def"
#include "swift/ConstExtract/ConstExtractTypeIDZone.def"
#undef SWIFT_REQUEST

#define SWIFT_REQUEST(ZONE, NAME, Sig, Caching, LocOptions) FRONTEND_STATISTIC(SILGen, NAME)
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Basic/TypeIDZones.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ SWIFT_TYPEID_ZONE(IDE, 137)

SWIFT_TYPEID_ZONE(ClangImporter, 139)

SWIFT_TYPEID_ZONE(ConstExtract, 140)

// N.B. This is not a formal zone and exists solely to support the unit tests.
SWIFT_TYPEID_ZONE(ArithmeticEvaluator, 255)
79 changes: 79 additions & 0 deletions include/swift/ConstExtract/ConstExtractRequests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//===------- ConstExtractRequests.h - Extraction Requests ------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines const-extraction requests.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_CONST_EXTRACT_REQUESTS_H
#define SWIFT_CONST_EXTRACT_REQUESTS_H

#include "swift/AST/SimpleRequest.h"
#include "swift/AST/ASTTypeIDs.h"
#include "swift/AST/ConstTypeInfo.h"
#include "swift/AST/EvaluatorDependencies.h"
#include "swift/AST/FileUnit.h"
#include "swift/AST/Identifier.h"
#include "swift/AST/NameLookup.h"
#include "swift/Basic/Statistic.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/TinyPtrVector.h"

namespace swift {

class Decl;
class DeclName;
class EnumDecl;

/// Retrieve information about compile-time-known values
class ConstantValueInfoRequest
: public SimpleRequest<ConstantValueInfoRequest,
ConstValueTypeInfo(NominalTypeDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

private:
friend SimpleRequest;

// Evaluation.
ConstValueTypeInfo
evaluate(Evaluator &eval, NominalTypeDecl *nominal) const;

public:
// Caching
bool isCached() const { return true; }
};

#define SWIFT_TYPEID_ZONE ConstExtract
#define SWIFT_TYPEID_HEADER "swift/ConstExtract/ConstExtractTypeIDZone.def"
#include "swift/Basic/DefineTypeIDZone.h"
#undef SWIFT_TYPEID_ZONE
#undef SWIFT_TYPEID_HEADER

// Set up reporting of evaluated requests.
template<typename Request>
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
const Request &request);

#define SWIFT_REQUEST(Zone, RequestType, Sig, Caching, LocOptions) \
template <> \
inline void reportEvaluatedRequest(UnifiedStatsReporter &stats, \
const RequestType &request) { \
++stats.getFrontendCounters().RequestType; \
}
#include "swift/ConstExtract/ConstExtractTypeIDZone.def"
#undef SWIFT_REQUEST

} // end namespace swift

#endif // SWIFT_CONST_EXTRACT_REQUESTS_H

20 changes: 20 additions & 0 deletions include/swift/ConstExtract/ConstExtractTypeIDZone.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//===--- ConstExtractTypeIDZone.def ----------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This definition file describes the types in the const extract
// TypeID zone, for use with the TypeID template.
//
//===----------------------------------------------------------------------===//

SWIFT_REQUEST(ConstExtract, ConstantValueInfoRequest,
ConstValueTypeInfo(NominalTypeDecl *), Cached,
NoLocationInfo)
3 changes: 3 additions & 0 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ namespace swift {
/// after forming the ASTContext.
void registerClangImporterRequestFunctions(Evaluator &evaluator);

/// Register constant value extraction request functons with the evaluator.
void registerConstExtractRequestFunctions(Evaluator &evaluator);

/// Register SILOptimizer passes necessary for IRGen.
void registerIRGenSILTransforms(ASTContext &ctx);

Expand Down
22 changes: 22 additions & 0 deletions lib/ConstExtract/ConstExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
//
//===----------------------------------------------------------------------===//

#include "swift/Basic/TypeID.h"
#include "swift/ConstExtract/ConstExtract.h"
#include "swift/ConstExtract/ConstExtractRequests.h"
#include "swift/AST/ASTContext.h"
#include "swift/AST/ASTWalker.h"
#include "swift/AST/Decl.h"
Expand All @@ -23,6 +25,7 @@
#include "llvm/Support/JSON.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/YAMLTraits.h"
#include "swift/Subsystems.h"

#include <set>
#include <sstream>
Expand Down Expand Up @@ -239,3 +242,22 @@ bool writeAsJSONToFile(const std::vector<ConstValueTypeInfo> &ConstValueInfos,
}

} // namespace swift

#define SWIFT_TYPEID_ZONE ConstExtract
#define SWIFT_TYPEID_HEADER "swift/ConstExtract/ConstExtractTypeIDZone.def"
#include "swift/Basic/ImplementTypeIDZone.h"
#undef SWIFT_TYPEID_ZONE
#undef SWIFT_TYPEID_HEADER

// Define request evaluation functions for each of the name lookup requests.
static AbstractRequestFunction *constExtractRequestFunctions[] = {
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \
reinterpret_cast<AbstractRequestFunction *>(&Name::evaluateRequest),
#include "swift/ConstExtract/ConstExtractTypeIDZone.def"
#undef SWIFT_REQUEST
};

void swift::registerConstExtractRequestFunctions(Evaluator &evaluator) {
evaluator.registerRequestFunctions(Zone::ConstExtract,
constExtractRequestFunctions);
}
1 change: 1 addition & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ bool CompilerInstance::setUpASTContextIfNeeded() {
registerParseRequestFunctions(Context->evaluator);
registerTypeCheckerRequestFunctions(Context->evaluator);
registerClangImporterRequestFunctions(Context->evaluator);
registerConstExtractRequestFunctions(Context->evaluator);
registerSILGenRequestFunctions(Context->evaluator);
registerSILOptimizerRequestFunctions(Context->evaluator);
registerTBDGenRequestFunctions(Context->evaluator);
Expand Down
1 change: 1 addition & 0 deletions lib/IDETool/CompletionInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ bool CompletionInstance::performCachedOperationIfPossible(
registerIDERequestFunctions(tmpCtx->evaluator);
registerTypeCheckerRequestFunctions(tmpCtx->evaluator);
registerClangImporterRequestFunctions(tmpCtx->evaluator);
registerConstExtractRequestFunctions(tmpCtx->evaluator);
registerSILGenRequestFunctions(tmpCtx->evaluator);
ModuleDecl *tmpM = ModuleDecl::create(Identifier(), *tmpCtx);
SourceFile *tmpSF = new (*tmpCtx)
Expand Down