Skip to content

Commit c1e0e66

Browse files
committed
[TypeChecker] Implement a per-module block list for disjunction optimizer
Allow enabling performance hacks via a block list action - `ShouldUseTypeCheckerPerfHacks`
1 parent 3efb948 commit c1e0e66

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

include/swift/AST/TypeCheckRequests.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5370,6 +5370,22 @@ class DefaultIsolationInSourceFileRequest
53705370
bool isCached() const { return true; }
53715371
};
53725372

5373+
class ModuleHasTypeCheckerPerformanceHacksEnabledRequest
5374+
: public SimpleRequest<ModuleHasTypeCheckerPerformanceHacksEnabledRequest,
5375+
bool(const ModuleDecl *),
5376+
RequestFlags::Cached> {
5377+
public:
5378+
using SimpleRequest::SimpleRequest;
5379+
5380+
private:
5381+
friend SimpleRequest;
5382+
5383+
bool evaluate(Evaluator &evaluator, const ModuleDecl *module) const;
5384+
5385+
public:
5386+
bool isCached() const { return true; }
5387+
};
5388+
53735389
#define SWIFT_TYPEID_ZONE TypeChecker
53745390
#define SWIFT_TYPEID_HEADER "swift/AST/TypeCheckerTypeIDZone.def"
53755391
#include "swift/Basic/DefineTypeIDZone.h"

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,3 +637,7 @@ SWIFT_REQUEST(TypeChecker, SemanticAvailabilitySpecRequest,
637637
SWIFT_REQUEST(TypeChecker, DefaultIsolationInSourceFileRequest,
638638
std::optional<DefaultIsolation>(const SourceFile *),
639639
Cached, NoLocationInfo)
640+
641+
SWIFT_REQUEST(TypeChecker, ModuleHasTypeCheckerPerformanceHacksEnabledRequest,
642+
bool(const ModuleDecl *),
643+
Cached, NoLocationInfo)

include/swift/Basic/BlockListAction.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ BLOCKLIST_ACTION(ShouldUseLayoutStringValueWitnesses)
2626
BLOCKLIST_ACTION(ShouldDisableOwnershipVerification)
2727
BLOCKLIST_ACTION(SkipEmittingFineModuleTrace)
2828
BLOCKLIST_ACTION(SkipIndexingModule)
29+
BLOCKLIST_ACTION(ShouldUseTypeCheckerPerfHacks)
2930

3031
#undef BLOCKLIST_ACTION

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,11 @@ TypeChecker::typeCheckTarget(SyntacticElementTarget &target,
466466
if (options.contains(TypeCheckExprFlags::DisableMacroExpansions))
467467
csOptions |= ConstraintSystemFlags::DisableMacroExpansions;
468468

469-
if (Context.TypeCheckerOpts.EnableConstraintSolverPerformanceHacks)
469+
if (Context.TypeCheckerOpts.EnableConstraintSolverPerformanceHacks ||
470+
evaluateOrDefault(Context.evaluator,
471+
ModuleHasTypeCheckerPerformanceHacksEnabledRequest{
472+
dc->getParentModule()},
473+
false))
470474
csOptions |= ConstraintSystemFlags::EnablePerformanceHacks;
471475

472476
ConstraintSystem cs(dc, csOptions, diagnosticTransaction);
@@ -2463,3 +2467,11 @@ void ConstraintSystem::forEachExpr(
24632467

24642468
expr->walk(ChildWalker(*this, callback));
24652469
}
2470+
2471+
bool ModuleHasTypeCheckerPerformanceHacksEnabledRequest::evaluate(
2472+
Evaluator &evaluator, const ModuleDecl *module) const {
2473+
auto name = module->getRealName().str();
2474+
return module->getASTContext().blockListConfig.hasBlockListAction(
2475+
name, BlockListKeyKind::ModuleName,
2476+
BlockListAction::ShouldUseTypeCheckerPerfHacks);
2477+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -typecheck -module-name Test -debug-constraints -blocklist-file %t/blocklist.yaml -verify %t/main.swift 2>%t.err
5+
// RUN: %FileCheck %t/main.swift < %t.err
6+
7+
//--- blocklist.yaml
8+
---
9+
ShouldUseTypeCheckerPerfHacks:
10+
ModuleName:
11+
- Test
12+
13+
//--- main.swift
14+
_ = 1 + 2 + 3
15+
16+
// CHECK: [favored] {{.*}} bound to decl Swift.(file).Int extension.+ : (Int.Type) -> (Int, Int) -> Int

0 commit comments

Comments
 (0)