@@ -2550,6 +2550,39 @@ void PreparedOverload::discharge(ConstraintSystem &cs,
2550
2550
}
2551
2551
}
2552
2552
2553
+ // / Populate the prepared overload with all type variables and constraints
2554
+ // / that are to be introduced into the constraint system when this choice
2555
+ // / is taken.
2556
+ // /
2557
+ // / FIXME: As a transitional mechanism, if preparedOverload is nullptr, this
2558
+ // / immediately performs all operations.
2559
+ DeclReferenceType
2560
+ ConstraintSystem::prepareOverload (ConstraintLocator *locator,
2561
+ OverloadChoice choice,
2562
+ DeclContext *useDC,
2563
+ PreparedOverload *preparedOverload) {
2564
+ // If we refer to a top-level decl with special type-checking semantics,
2565
+ // handle it now.
2566
+ auto semantics =
2567
+ TypeChecker::getDeclTypeCheckingSemantics (choice.getDecl ());
2568
+ if (semantics != DeclTypeCheckingSemantics::Normal) {
2569
+ return getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2570
+ *this , locator, semantics, preparedOverload);
2571
+ } else if (auto baseTy = choice.getBaseType ()) {
2572
+ // Retrieve the type of a reference to the specific declaration choice.
2573
+ assert (!baseTy->hasTypeParameter ());
2574
+
2575
+ return getTypeOfMemberReference (
2576
+ baseTy, choice.getDecl (), useDC,
2577
+ (choice.getKind () == OverloadChoiceKind::DeclViaDynamic),
2578
+ choice.getFunctionRefInfo (), locator, nullptr , preparedOverload);
2579
+ } else {
2580
+ return getTypeOfReference (
2581
+ choice.getDecl (), choice.getFunctionRefInfo (), locator, useDC,
2582
+ preparedOverload);
2583
+ }
2584
+ }
2585
+
2553
2586
void ConstraintSystem::resolveOverload (ConstraintLocator *locator,
2554
2587
Type boundType, OverloadChoice choice,
2555
2588
DeclContext *useDC) {
@@ -2560,34 +2593,29 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
2560
2593
Type adjustedRefType;
2561
2594
Type thrownErrorTypeOnAccess;
2562
2595
2563
- switch (auto kind = choice.getKind ()) {
2596
+ switch (choice.getKind ()) {
2564
2597
case OverloadChoiceKind::Decl:
2565
2598
case OverloadChoiceKind::DeclViaBridge:
2566
2599
case OverloadChoiceKind::DeclViaDynamic:
2567
2600
case OverloadChoiceKind::DeclViaUnwrappedOptional:
2568
2601
case OverloadChoiceKind::DynamicMemberLookup:
2569
2602
case OverloadChoiceKind::KeyPathDynamicMemberLookup: {
2570
- // If we refer to a top-level decl with special type-checking semantics,
2571
- // handle it now.
2572
- const auto semantics =
2573
- TypeChecker::getDeclTypeCheckingSemantics (choice.getDecl ());
2574
- DeclReferenceType declRefType;
2575
- if (semantics != DeclTypeCheckingSemantics::Normal) {
2576
- declRefType = getTypeOfReferenceWithSpecialTypeCheckingSemantics (
2577
- *this , locator, semantics);
2578
- } else if (auto baseTy = choice.getBaseType ()) {
2579
- // Retrieve the type of a reference to the specific declaration choice.
2580
- assert (!baseTy->hasTypeParameter ());
2581
-
2582
- declRefType = getTypeOfMemberReference (
2583
- baseTy, choice.getDecl (), useDC,
2584
- (kind == OverloadChoiceKind::DeclViaDynamic),
2585
- choice.getFunctionRefInfo (), locator, nullptr ,
2586
- /* preparedOverload=*/ nullptr );
2587
- } else {
2588
- declRefType = getTypeOfReference (
2589
- choice.getDecl (), choice.getFunctionRefInfo (), locator, useDC,
2590
- /* preparedOverload=*/ nullptr );
2603
+ bool enablePreparedOverloads = false ;
2604
+
2605
+ PreparedOverload preparedOverload;
2606
+ if (enablePreparedOverloads) {
2607
+ ASSERT (!PreparingOverload);
2608
+ PreparingOverload = true ;
2609
+ }
2610
+
2611
+ auto declRefType = prepareOverload (locator, choice, useDC,
2612
+ (enablePreparedOverloads
2613
+ ? &preparedOverload
2614
+ : nullptr ));
2615
+
2616
+ if (enablePreparedOverloads) {
2617
+ PreparingOverload = false ;
2618
+ preparedOverload.discharge (*this , locator);
2591
2619
}
2592
2620
2593
2621
openedType = declRefType.openedType ;
0 commit comments