Skip to content

Commit b53da08

Browse files
committed
[ConstraintSystem] Add skeleton of constraint optimizer
1 parent 4730a4f commit b53da08

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5691,6 +5691,11 @@ class ConstraintSystem {
56915691
/// Collect the current inactive disjunction constraints.
56925692
void collectDisjunctions(SmallVectorImpl<Constraint *> &disjunctions);
56935693

5694+
/// Based on the given set of disjunctions, attempt to determine
5695+
/// favored choices and perform other optimizations to help the
5696+
/// solver.
5697+
void optimizeDisjunctions(SmallVectorImpl<Constraint *> &disjunctions);
5698+
56945699
/// Record a particular disjunction choice of
56955700
void recordDisjunctionChoice(ConstraintLocator *disjunctionLocator,
56965701
unsigned index) {

lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ add_swift_host_library(swiftSema STATIC
1010
CSSolver.cpp
1111
CSStep.cpp
1212
CSFix.cpp
13+
CSOptimizer.cpp
1314
CSDiagnostics.cpp
1415
CodeSynthesis.cpp
1516
CodeSynthesisDistributedActor.cpp

lib/Sema/CSOptimizer.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===--- CSOptimizer.cpp - Constraint Optimizer ---------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 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 implements disjunction and other constraint optimizations.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#include "swift/Sema/ConstraintSystem.h"
18+
#include "llvm/ADT/SmallVector.h"
19+
20+
using namespace swift;
21+
using namespace constraints;
22+
23+
void ConstraintSystem::optimizeDisjunctions(
24+
SmallVectorImpl<Constraint *> &disjunctions) {
25+
}

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,8 @@ Constraint *ConstraintSystem::selectDisjunction() {
17731773
if (disjunctions.empty())
17741774
return nullptr;
17751775

1776+
optimizeDisjunctions(disjunctions);
1777+
17761778
if (auto *disjunction = selectBestBindingDisjunction(*this, disjunctions))
17771779
return disjunction;
17781780

0 commit comments

Comments
 (0)