From 011d4281647e3a2a3cf0dbdda1fa65cc1b8ed881 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 10 Nov 2023 13:55:14 -0800 Subject: Cleanup builtin arithmetic interfaces. (#3317) * wip: clean up IArithmetic * wip. * Cleanup builtin arithmetic interfaces. * Fix. * Fixes. * Fix. * Fix. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-check-overload.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/slang/slang-check-overload.cpp') diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp index c668155df..27062fc0c 100644 --- a/source/slang/slang-check-overload.cpp +++ b/source/slang/slang-check-overload.cpp @@ -1070,6 +1070,15 @@ namespace Slang return 0; } + int getOverloadRank(DeclRef declRef) + { + if (!declRef.getDecl()) + return 0; + if (auto attr = declRef.getDecl()->findModifier()) + return attr->rank; + return 0; + } + int SemanticsVisitor::CompareOverloadCandidates( OverloadCandidate* left, OverloadCandidate* right) @@ -1142,6 +1151,11 @@ namespace Slang auto specificityDiff = compareOverloadCandidateSpecificity(left->item, right->item); if(specificityDiff) return specificityDiff; + + // If we reach here, we will attempt to use overload rank to break the ties. + auto overloadRankDiff = getOverloadRank(right->item.declRef) - getOverloadRank(left->item.declRef); + if (overloadRankDiff) + return overloadRankDiff; } return 0; -- cgit v1.2.3