| 112 | } |
| 113 | |
| 114 | std::optional<SimpleFunctionRegistry::ResolvedSimpleFunction> |
| 115 | SimpleFunctionRegistry::resolveFunction( |
| 116 | const std::string& name, |
| 117 | const std::vector<TypePtr>& argTypes) const { |
| 118 | const FunctionEntry* selectedCandidate = nullptr; |
| 119 | TypePtr selectedCandidateType = nullptr; |
| 120 | registeredFunctions_.withRLock([&](const auto& map) { |
| 121 | if (const auto* signatureMap = getSignatureMap(name, map)) { |
| 122 | for (const auto& [candidateSignature, functionEntry] : *signatureMap) { |
| 123 | SignatureBinder binder(candidateSignature, argTypes); |
| 124 | if (binder.tryBind()) { |
| 125 | auto* currentCandidate = functionEntry.get(); |
| 126 | if (!selectedCandidate || |
| 127 | currentCandidate->getMetadata().priority() < |
| 128 | selectedCandidate->getMetadata().priority()) { |
| 129 | selectedCandidate = currentCandidate; |
| 130 | selectedCandidateType = binder.tryResolveReturnType(); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | }); |
| 136 | |
| 137 | BOLT_DCHECK(!selectedCandidate || selectedCandidateType); |
| 138 | |
| 139 | return selectedCandidate |
| 140 | ? std::optional<ResolvedSimpleFunction>( |
| 141 | ResolvedSimpleFunction(*selectedCandidate, selectedCandidateType)) |
| 142 | : std::nullopt; |
| 143 | } |
| 144 | |
| 145 | } // namespace bytedance::bolt::exec |