mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[TypeChecker] Implement a per-module block list for disjunction optimizer
Allow enabling performance hacks via a block list action - `ShouldUseTypeCheckerPerfHacks`
This commit is contained in:
@@ -5370,6 +5370,22 @@ public:
|
||||
bool isCached() const { return true; }
|
||||
};
|
||||
|
||||
class ModuleHasTypeCheckerPerformanceHacksEnabledRequest
|
||||
: public SimpleRequest<ModuleHasTypeCheckerPerformanceHacksEnabledRequest,
|
||||
bool(const ModuleDecl *),
|
||||
RequestFlags::Cached> {
|
||||
public:
|
||||
using SimpleRequest::SimpleRequest;
|
||||
|
||||
private:
|
||||
friend SimpleRequest;
|
||||
|
||||
bool evaluate(Evaluator &evaluator, const ModuleDecl *module) const;
|
||||
|
||||
public:
|
||||
bool isCached() const { return true; }
|
||||
};
|
||||
|
||||
#define SWIFT_TYPEID_ZONE TypeChecker
|
||||
#define SWIFT_TYPEID_HEADER "swift/AST/TypeCheckerTypeIDZone.def"
|
||||
#include "swift/Basic/DefineTypeIDZone.h"
|
||||
|
||||
@@ -637,3 +637,7 @@ SWIFT_REQUEST(TypeChecker, SemanticAvailabilitySpecRequest,
|
||||
SWIFT_REQUEST(TypeChecker, DefaultIsolationInSourceFileRequest,
|
||||
std::optional<DefaultIsolation>(const SourceFile *),
|
||||
Cached, NoLocationInfo)
|
||||
|
||||
SWIFT_REQUEST(TypeChecker, ModuleHasTypeCheckerPerformanceHacksEnabledRequest,
|
||||
bool(const ModuleDecl *),
|
||||
Cached, NoLocationInfo)
|
||||
@@ -26,5 +26,6 @@ BLOCKLIST_ACTION(ShouldUseLayoutStringValueWitnesses)
|
||||
BLOCKLIST_ACTION(ShouldDisableOwnershipVerification)
|
||||
BLOCKLIST_ACTION(SkipEmittingFineModuleTrace)
|
||||
BLOCKLIST_ACTION(SkipIndexingModule)
|
||||
BLOCKLIST_ACTION(ShouldUseTypeCheckerPerfHacks)
|
||||
|
||||
#undef BLOCKLIST_ACTION
|
||||
|
||||
@@ -466,7 +466,11 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
|
||||
if (options.contains(TypeCheckExprFlags::DisableMacroExpansions))
|
||||
csOptions |= ConstraintSystemFlags::DisableMacroExpansions;
|
||||
|
||||
if (Context.TypeCheckerOpts.EnableConstraintSolverPerformanceHacks)
|
||||
if (Context.TypeCheckerOpts.EnableConstraintSolverPerformanceHacks ||
|
||||
evaluateOrDefault(Context.evaluator,
|
||||
ModuleHasTypeCheckerPerformanceHacksEnabledRequest{
|
||||
dc->getParentModule()},
|
||||
false))
|
||||
csOptions |= ConstraintSystemFlags::EnablePerformanceHacks;
|
||||
|
||||
ConstraintSystem cs(dc, csOptions, diagnosticTransaction);
|
||||
@@ -2463,3 +2467,11 @@ void ConstraintSystem::forEachExpr(
|
||||
|
||||
expr->walk(ChildWalker(*this, callback));
|
||||
}
|
||||
|
||||
bool ModuleHasTypeCheckerPerformanceHacksEnabledRequest::evaluate(
|
||||
Evaluator &evaluator, const ModuleDecl *module) const {
|
||||
auto name = module->getRealName().str();
|
||||
return module->getASTContext().blockListConfig.hasBlockListAction(
|
||||
name, BlockListKeyKind::ModuleName,
|
||||
BlockListAction::ShouldUseTypeCheckerPerfHacks);
|
||||
}
|
||||
16
test/Constraints/perf_hacks_with_block_list.swift
Normal file
16
test/Constraints/perf_hacks_with_block_list.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: split-file %s %t
|
||||
|
||||
// RUN: %target-swift-frontend -typecheck -module-name Test -debug-constraints -blocklist-file %t/blocklist.yaml -verify %t/main.swift 2>%t.err
|
||||
// RUN: %FileCheck %t/main.swift < %t.err
|
||||
|
||||
//--- blocklist.yaml
|
||||
---
|
||||
ShouldUseTypeCheckerPerfHacks:
|
||||
ModuleName:
|
||||
- Test
|
||||
|
||||
//--- main.swift
|
||||
_ = 1 + 2 + 3
|
||||
|
||||
// CHECK: [favored] {{.*}} bound to decl Swift.(file).Int extension.+ : (Int.Type) -> (Int, Int) -> Int
|
||||
Reference in New Issue
Block a user