Skip to content

Commit b925630

Browse files
committed
Sema: Stub out PreparedOverload
1 parent ed3961b commit b925630

File tree

6 files changed

+68
-8
lines changed

6 files changed

+68
-8
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace constraints {
6464

6565
class ConstraintSystem;
6666
class SyntacticElementTarget;
67+
struct PreparedOverload;
6768

6869
} // end namespace constraints
6970

@@ -2211,6 +2212,8 @@ class ConstraintSystem {
22112212
unsigned CountDisjunctions = 0;
22122213

22132214
private:
2215+
bool PreparingOverload = false;
2216+
22142217
/// A constraint that has failed along the current solver path.
22152218
/// Do not set directly, call \c recordFailedConstraint instead.
22162219
Constraint *failedConstraint = nullptr;
@@ -2752,6 +2755,7 @@ class ConstraintSystem {
27522755
SolverState *solverState = nullptr;
27532756

27542757
void recordChange(SolverTrail::Change change) {
2758+
ASSERT(!PreparingOverload);
27552759
solverState->Trail.recordChange(change);
27562760
}
27572761

@@ -4447,7 +4451,8 @@ class ConstraintSystem {
44474451
ValueDecl *decl,
44484452
FunctionRefInfo functionRefInfo,
44494453
ConstraintLocatorBuilder locator,
4450-
DeclContext *useDC);
4454+
DeclContext *useDC,
4455+
PreparedOverload *preparedOverload);
44514456

44524457
/// Return the type-of-reference of the given value.
44534458
///
@@ -4488,7 +4493,8 @@ class ConstraintSystem {
44884493
DeclReferenceType getTypeOfMemberReference(
44894494
Type baseTy, ValueDecl *decl, DeclContext *useDC, bool isDynamicLookup,
44904495
FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
4491-
SmallVectorImpl<OpenedType> *replacements = nullptr);
4496+
SmallVectorImpl<OpenedType> *replacements = nullptr,
4497+
PreparedOverload *preparedOverload = nullptr);
44924498

44934499
/// Retrieve a list of generic parameter types solver has "opened" (replaced
44944500
/// with a type variable) at the given location.

include/swift/Sema/PreparedOverload.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===--- PreparedOverload.h - A Choice from an Overload Set ----*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 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+
#ifndef SWIFT_SEMA_PREPAREDOVERLOAD_H
13+
#define SWIFT_SEMA_PREPAREDOVERLOAD_H
14+
15+
#include "swift/AST/AvailabilityRange.h"
16+
#include "swift/AST/FunctionRefInfo.h"
17+
#include "swift/AST/Types.h"
18+
#include "llvm/ADT/PointerIntPair.h"
19+
#include "llvm/Support/ErrorHandling.h"
20+
21+
namespace swift {
22+
namespace constraints {
23+
24+
struct PreparedOverload {
25+
26+
};
27+
28+
}
29+
}
30+
31+
#endif

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16013,6 +16013,8 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1601316013
Type second,
1601416014
ConstraintLocatorBuilder locator,
1601516015
bool isFavored) {
16016+
ASSERT(!PreparingOverload);
16017+
1601616018
assert(first && "Missing first type");
1601716019
assert(second && "Missing second type");
1601816020

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ bool ConstraintSystem::hasFreeTypeVariables() {
176176
}
177177

178178
void ConstraintSystem::addTypeVariable(TypeVariableType *typeVar) {
179+
ASSERT(!PreparingOverload);
180+
179181
TypeVariables.insert(typeVar);
180182

181183
// Notify the constraint graph.

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
12241224
openWitnessType =
12251225
cs->getTypeOfReference(
12261226
witness, FunctionRefInfo::doubleBaseNameApply(), witnessLocator,
1227-
/*useDC=*/nullptr)
1227+
/*useDC=*/nullptr, /*preparedOverload=*/nullptr)
12281228
.adjustedReferenceType;
12291229
}
12301230
openWitnessType = openWitnessType->getRValueType();

lib/Sema/TypeOfReference.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
#include "swift/AST/ProtocolConformance.h"
3030
#include "swift/AST/TypeTransform.h"
3131
#include "swift/Sema/ConstraintSystem.h"
32+
#include "swift/Sema/PreparedOverload.h"
3233
#include "swift/Basic/Assertions.h"
3334
#include "swift/Basic/Statistic.h"
35+
#include "swift/Basic/Defer.h"
3436

3537
using namespace swift;
3638
using namespace constraints;
@@ -932,7 +934,20 @@ DeclReferenceType
932934
ConstraintSystem::getTypeOfReference(ValueDecl *value,
933935
FunctionRefInfo functionRefInfo,
934936
ConstraintLocatorBuilder locator,
935-
DeclContext *useDC) {
937+
DeclContext *useDC,
938+
PreparedOverload *preparedOverload) {
939+
if (preparedOverload) {
940+
ASSERT(!PreparingOverload);
941+
PreparingOverload = true;
942+
}
943+
944+
SWIFT_DEFER {
945+
if (preparedOverload) {
946+
ASSERT(PreparingOverload);
947+
PreparingOverload = false;
948+
}
949+
};
950+
936951
if (value->getDeclContext()->isTypeContext() && isa<FuncDecl>(value)) {
937952
// Unqualified lookup can find operator names within nominal types.
938953
auto func = cast<FuncDecl>(value);
@@ -1507,13 +1522,15 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
15071522
DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
15081523
Type baseTy, ValueDecl *value, DeclContext *useDC, bool isDynamicLookup,
15091524
FunctionRefInfo functionRefInfo, ConstraintLocator *locator,
1510-
SmallVectorImpl<OpenedType> *replacementsPtr) {
1525+
SmallVectorImpl<OpenedType> *replacementsPtr,
1526+
PreparedOverload *preparedOverload) {
15111527
// Figure out the instance type used for the base.
15121528
Type resolvedBaseTy = getFixedTypeRecursive(baseTy, /*wantRValue=*/true);
15131529

15141530
// If the base is a module type, just use the type of the decl.
15151531
if (resolvedBaseTy->is<ModuleType>()) {
1516-
return getTypeOfReference(value, functionRefInfo, locator, useDC);
1532+
return getTypeOfReference(value, functionRefInfo, locator, useDC,
1533+
preparedOverload);
15171534
}
15181535

15191536
// Check to see if the self parameter is applied, in which case we'll want to
@@ -2427,10 +2444,12 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
24272444
declRefType = getTypeOfMemberReference(
24282445
baseTy, choice.getDecl(), useDC,
24292446
(kind == OverloadChoiceKind::DeclViaDynamic),
2430-
choice.getFunctionRefInfo(), locator, nullptr);
2447+
choice.getFunctionRefInfo(), locator, nullptr,
2448+
/*preparedOverload=*/nullptr);
24312449
} else {
24322450
declRefType = getTypeOfReference(
2433-
choice.getDecl(), choice.getFunctionRefInfo(), locator, useDC);
2451+
choice.getDecl(), choice.getFunctionRefInfo(), locator, useDC,
2452+
/*preparedOverload=*/nullptr);
24342453
}
24352454

24362455
openedType = declRefType.openedType;

0 commit comments

Comments
 (0)