diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-19 15:03:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 15:03:56 -0700 |
| commit | 453683bf44f2112719802eaac2b332d49eebd640 (patch) | |
| tree | d399db4c9cba90c11980186d3df1ffcc4d423b5a /source/slang/slang-check-overload.cpp | |
| parent | ecf85df6eee3da76ef54b14e4ab083f22da89e46 (diff) | |
Tuple swizzling, concat, comparison and `countof`. (#4856)
* Tuple swizzling and element access.
* Update proposal status.
* Cleanup.
* Fix merrge error.
* Address review.
Diffstat (limited to 'source/slang/slang-check-overload.cpp')
| -rw-r--r-- | source/slang/slang-check-overload.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index 16f6ed7da..29cb74c23 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -680,6 +680,10 @@ namespace Slang packArg->type = paramType; resultArgs.add(packArg); } + + // Always add a flat cost for using an argument pack, + // so that we prefer non-pack overloads when possible. + candidate.conversionCostSum += kConversionCost_ParameterPack; } else { @@ -1669,26 +1673,6 @@ namespace Slang // Try to match the variadic part. // Is the corresponding argument a expand expr? If so it will map 1:1 to the type pack param. auto astBuilder = semantics->getASTBuilder(); - while (remainingArgCount > 0) - { - auto argType = getArgType(fixedParamCount); - if (auto typeType = as<TypeType>(argType)) - { - argType = typeType->getType(); - } - if (isAbstractTypePack(argType)) - { - MatchedArg arg; - arg.argExpr = getArg(fixedParamCount); - arg.argType = getArgType(fixedParamCount); - outMatchedArgs.add(arg); - fixedParamCount++; - remainingArgCount--; - typePackCount--; - continue; - } - break; - } if (remainingArgCount <= 0) return true; @@ -1704,6 +1688,24 @@ namespace Slang Index typePackSize = remainingArgCount / typePackCount; for (Index i = 0; i < typePackCount; ++i) { + // If type pack size is 1, we may not need to wrap things in a PackExpr, + // if the argument is already a pack. + if (typePackSize == 1) + { + auto argType = getArgType(fixedParamCount + i); + if (auto typeType = as<TypeType>(argType)) + { + argType = typeType->getType(); + } + if (isTypePack(argType)) + { + MatchedArg arg; + arg.argExpr = getArg(fixedParamCount + i); + arg.argType = getArgType(fixedParamCount + i); + outMatchedArgs.add(arg); + continue; + } + } PackExpr* packExpr = nullptr; if (mode == Mode::ForReal) { |
