@@ -2509,28 +2509,6 @@ String SemanticsVisitor::getCallSignatureString(OverloadResolveContext& context)
2509
2509
Expr* SemanticsVisitor::ResolveInvoke (InvokeExpr* expr)
2510
2510
{
2511
2511
OverloadResolveContext context;
2512
- // check if this is a core module operator call, if so we want to use cached results
2513
- // to speed up compilation
2514
- bool shouldAddToCache = false ;
2515
- OperatorOverloadCacheKey key;
2516
- TypeCheckingCache* typeCheckingCache = getLinkage ()->getTypeCheckingCache ();
2517
- if (auto opExpr = as<OperatorExpr>(expr))
2518
- {
2519
- if (key.fromOperatorExpr (opExpr))
2520
- {
2521
- key.isGLSLMode = getShared ()->glslModuleDecl != nullptr ;
2522
- OverloadCandidate candidate;
2523
- if (typeCheckingCache->resolvedOperatorOverloadCache .tryGetValue (key, candidate))
2524
- {
2525
- context.bestCandidateStorage = candidate;
2526
- context.bestCandidate = &context.bestCandidateStorage ;
2527
- }
2528
- else
2529
- {
2530
- shouldAddToCache = true ;
2531
- }
2532
- }
2533
- }
2534
2512
2535
2513
// Look at the base expression for the call, and figure out how to invoke it.
2536
2514
auto funcExpr = expr->functionExpr ;
@@ -2570,6 +2548,43 @@ Expr* SemanticsVisitor::ResolveInvoke(InvokeExpr* expr)
2570
2548
context.loc = expr->loc ;
2571
2549
context.sourceScope = m_outerScope;
2572
2550
context.baseExpr = GetBaseExpr (funcExpr);
2551
+
2552
+ // check if this is a core module operator call, if so we want to use cached results
2553
+ // to speed up compilation
2554
+ bool shouldAddToCache = false ;
2555
+ OperatorOverloadCacheKey key;
2556
+ TypeCheckingCache* typeCheckingCache = getLinkage ()->getTypeCheckingCache ();
2557
+ if (auto opExpr = as<OperatorExpr>(expr))
2558
+ {
2559
+ if (key.fromOperatorExpr (opExpr))
2560
+ {
2561
+ key.isGLSLMode = getShared ()->glslModuleDecl != nullptr ;
2562
+ ResolvedOperatorOverload candidate;
2563
+ if (typeCheckingCache->resolvedOperatorOverloadCache .tryGetValue (key, candidate))
2564
+ {
2565
+ // We should only use the cached candidate if it is persistent direct declref created
2566
+ // from GlobalSession's ASTBuilder, or it is created in the current Linkage.
2567
+ if (candidate.cacheVersion == typeCheckingCache->version ||
2568
+ as<DirectDeclRef>(candidate.candidate .item .declRef .declRefBase ))
2569
+ {
2570
+ context.bestCandidateStorage = candidate.candidate ;
2571
+ context.bestCandidate = &context.bestCandidateStorage ;
2572
+ }
2573
+ else
2574
+ {
2575
+ LookupResultItem overloadCandidate = {};
2576
+ overloadCandidate.declRef = getOuterGenericOrSelf (candidate.decl );
2577
+ AddDeclRefOverloadCandidates (overloadCandidate, context, 0 );
2578
+ shouldAddToCache = true ;
2579
+ }
2580
+ }
2581
+ else
2582
+ {
2583
+ shouldAddToCache = true ;
2584
+ }
2585
+ }
2586
+ }
2587
+
2573
2588
// We run a special case here where an `InvokeExpr`
2574
2589
// with a single argument where the base/func expression names
2575
2590
// a type should always be treated as an explicit type coercion
@@ -2737,7 +2752,11 @@ Expr* SemanticsVisitor::ResolveInvoke(InvokeExpr* expr)
2737
2752
getShared ()->glslModuleDecl ==
2738
2753
getModuleDecl (context.bestCandidate ->item .declRef .getDecl ()))
2739
2754
{
2740
- typeCheckingCache->resolvedOperatorOverloadCache [key] = *context.bestCandidate ;
2755
+ ResolvedOperatorOverload overloadResult;
2756
+ overloadResult.candidate = *context.bestCandidate ;
2757
+ overloadResult.decl = context.bestCandidate ->item .declRef .getDecl ();
2758
+ overloadResult.cacheVersion = typeCheckingCache->version ;
2759
+ typeCheckingCache->resolvedOperatorOverloadCache [key] = overloadResult;
2741
2760
}
2742
2761
}
2743
2762
0 commit comments