[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:
Pavel Yaskevich
2025-06-27 12:04:37 -07:00
parent 3efb948ad8
commit c1e0e6622d
5 changed files with 50 additions and 1 deletions

View File

@@ -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"

View File

@@ -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)

View File

@@ -26,5 +26,6 @@ BLOCKLIST_ACTION(ShouldUseLayoutStringValueWitnesses)
BLOCKLIST_ACTION(ShouldDisableOwnershipVerification)
BLOCKLIST_ACTION(SkipEmittingFineModuleTrace)
BLOCKLIST_ACTION(SkipIndexingModule)
BLOCKLIST_ACTION(ShouldUseTypeCheckerPerfHacks)
#undef BLOCKLIST_ACTION

View File

@@ -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);
}

View 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