Skip to content

Commit 72a6072

Browse files
committed
Sema: Record argument lists in the trail
1 parent f2412f3 commit 72a6072

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

include/swift/Sema/CSTrail.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ LOCATOR_CHANGE(RecordedPackExpansionEnvironment, PackExpansionEnvironments)
4343
LOCATOR_CHANGE(RecordedDefaultedConstraint, DefaultedConstraints)
4444
LOCATOR_CHANGE(ResolvedOverload, ResolvedOverloads)
4545
LOCATOR_CHANGE(RecordedImplicitValueConversion, ImplicitValueConversions)
46+
LOCATOR_CHANGE(RecordedArgumentList, ArgumentLists)
4647

4748
EXPR_CHANGE(AppliedPropertyWrapper)
4849
EXPR_CHANGE(RecordedImpliedResult)

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,7 @@ class Solution {
16101610
/// A mapping from the constraint locators for references to various
16111611
/// names (e.g., member references, normal name references, possible
16121612
/// constructions) to the argument lists for the call to that locator.
1613-
llvm::MapVector<ConstraintLocator *, ArgumentList *> argumentLists;
1613+
llvm::DenseMap<ConstraintLocator *, ArgumentList *> argumentLists;
16141614

16151615
/// The set of implicitly generated `.callAsFunction` root expressions.
16161616
llvm::DenseMap<ConstraintLocator *, UnresolvedDotExpr *>
@@ -2397,7 +2397,7 @@ class ConstraintSystem {
23972397
/// A mapping from the constraint locators for references to various
23982398
/// names (e.g., member references, normal name references, possible
23992399
/// constructions) to the argument lists for the call to that locator.
2400-
llvm::MapVector<ConstraintLocator *, ArgumentList *> ArgumentLists;
2400+
llvm::DenseMap<ConstraintLocator *, ArgumentList *> ArgumentLists;
24012401

24022402
public:
24032403
/// A map from argument expressions to their applied property wrapper expressions.
@@ -2801,6 +2801,11 @@ class ConstraintSystem {
28012801
/// Associate an argument list with a call at a given locator.
28022802
void associateArgumentList(ConstraintLocator *locator, ArgumentList *args);
28032803

2804+
/// Same as associateArgumentList() except the locator points at the
2805+
/// argument list itself. Records a change in the trail.
2806+
void recordArgumentList(ConstraintLocator *locator,
2807+
ArgumentList *args);
2808+
28042809
/// If the given node is a function expression with a parent ApplyExpr,
28052810
/// returns the apply, otherwise returns the node itself.
28062811
ASTNode includingParentApply(ASTNode node);
@@ -2850,9 +2855,6 @@ class ConstraintSystem {
28502855
/// FIXME: Remove this.
28512856
unsigned numFixes;
28522857

2853-
/// The length of \c ArgumentLists.
2854-
unsigned numArgumentLists;
2855-
28562858
/// The length of \c ImplicitCallAsFunctionRoots.
28572859
unsigned numImplicitCallAsFunctionRoots;
28582860

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14665,7 +14665,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1466514665
getASTContext(), {Argument(SourceLoc(), Identifier(), nullptr)},
1466614666
/*firstTrailingClosureIndex=*/std::nullopt,
1466714667
AllocationArena::ConstraintSolver);
14668-
ArgumentLists.insert({argumentsLoc, argList});
14668+
recordArgumentList(argumentsLoc, argList);
1466914669
}
1467014670

1467114671
auto *memberTypeLoc = getConstraintLocator(

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ void ConstraintSystem::applySolution(const Solution &solution) {
450450

451451
// Register the argument lists.
452452
for (auto &argListMapping : solution.argumentLists) {
453-
ArgumentLists.insert(argListMapping);
453+
if (ArgumentLists.count(argListMapping.first) == 0)
454+
recordArgumentList(argListMapping.first, argListMapping.second);
454455
}
455456

456457
for (auto &implicitRoot : solution.ImplicitCallAsFunctionRoots) {
@@ -706,7 +707,6 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
706707

707708
numTypeVariables = cs.TypeVariables.size();
708709
numFixes = cs.Fixes.size();
709-
numArgumentLists = cs.ArgumentLists.size();
710710
numImplicitCallAsFunctionRoots = cs.ImplicitCallAsFunctionRoots.size();
711711
numSynthesizedConformances = cs.SynthesizedConformances.size();
712712

@@ -741,9 +741,6 @@ ConstraintSystem::SolverScope::~SolverScope() {
741741
// constraints introduced by the current scope.
742742
cs.solverState->rollback(this);
743743

744-
// Remove any argument lists no longer in scope.
745-
truncate(cs.ArgumentLists, numArgumentLists);
746-
747744
// Remove any implicitly generated root expressions for `.callAsFunction`
748745
// which are no longer in scope.
749746
truncate(cs.ImplicitCallAsFunctionRoots, numImplicitCallAsFunctionRoots);

lib/Sema/ConstraintSystem.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,12 +3542,13 @@ void ConstraintSystem::bindOverloadType(
35423542

35433543
// Associate an argument list for the implicit x[dynamicMember:] subscript
35443544
// if we haven't already.
3545-
auto *&argList = ArgumentLists[getArgumentInfoLocator(callLoc)];
3546-
if (!argList) {
3547-
argList = ArgumentList::createImplicit(
3545+
auto *argLoc = getArgumentInfoLocator(callLoc);
3546+
if (ArgumentLists.find(argLoc) == ArgumentLists.end()) {
3547+
auto *argList = ArgumentList::createImplicit(
35483548
ctx, {Argument(SourceLoc(), ctx.Id_dynamicMember, /*expr*/ nullptr)},
35493549
/*firstTrailingClosureIndex=*/std::nullopt,
35503550
AllocationArena::ConstraintSolver);
3551+
recordArgumentList(argLoc, argList);
35513552
}
35523553

35533554
auto *callerTy = FunctionType::get(
@@ -6521,13 +6522,20 @@ ArgumentList *ConstraintSystem::getArgumentList(ConstraintLocator *locator) {
65216522
return nullptr;
65226523
}
65236524

6525+
void ConstraintSystem::recordArgumentList(ConstraintLocator *locator,
6526+
ArgumentList *args) {
6527+
bool inserted = ArgumentLists.insert({locator, args}).second;
6528+
ASSERT(inserted);
6529+
6530+
if (solverState)
6531+
recordChange(SolverTrail::Change::RecordedArgumentList(locator));
6532+
}
6533+
65246534
void ConstraintSystem::associateArgumentList(ConstraintLocator *locator,
65256535
ArgumentList *args) {
6526-
assert(locator && locator->getAnchor());
6527-
auto *argInfoLoc = getArgumentInfoLocator(locator);
6528-
auto inserted = ArgumentLists.insert({argInfoLoc, args}).second;
6529-
assert(inserted && "Multiple argument lists at locator?");
6530-
(void)inserted;
6536+
ASSERT(locator && locator->getAnchor());
6537+
auto *argLoc = getArgumentInfoLocator(locator);
6538+
recordArgumentList(argLoc, args);
65316539
}
65326540

65336541
ArgumentList *Solution::getArgumentList(ConstraintLocator *locator) const {

0 commit comments

Comments
 (0)