GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 98.5% 256 / 0 / 260
Functions: 100.0% 18 / 0 / 18
Branches: 64.2% 298 / 0 / 464

src/typechecker/FunctionManager.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "FunctionManager.h"
4
5 #include <ast/ASTNodes.h>
6 #include <exception/SemanticError.h>
7 #include <model/GenericType.h>
8 #include <symboltablebuilder/Scope.h>
9 #include <symboltablebuilder/SymbolTableBuilder.h>
10 #include <typechecker/TypeChecker.h>
11 #include <typechecker/TypeMatcher.h>
12 #include <util/CodeLoc.h>
13 #include <util/CustomHashFunctions.h>
14
15 namespace spice::compiler {
16
17 // Static member initialization
18 std::unordered_map<uint64_t, Function *> FunctionManager::lookupCache = {};
19 size_t FunctionManager::lookupCacheHits = 0;
20 size_t FunctionManager::lookupCacheMisses = 0;
21
22 14434 Function *FunctionManager::insert(Scope *insertScope, const Function &baseFunction, std::vector<Function *> *nodeFunctionList) {
23 // Open a new manifestation list for the function definition
24
3/6
✓ Branch 2 → 3 taken 14434 times.
✗ Branch 2 → 43 not taken.
✓ Branch 3 → 4 taken 14434 times.
✗ Branch 3 → 40 not taken.
✓ Branch 4 → 5 taken 14434 times.
✗ Branch 4 → 38 not taken.
14434 const std::string fctId = baseFunction.name + ":" + baseFunction.declNode->codeLoc.toPrettyLineAndColumn();
25
2/4
✓ Branch 8 → 9 taken 14434 times.
✗ Branch 8 → 46 not taken.
✓ Branch 9 → 10 taken 14434 times.
✗ Branch 9 → 44 not taken.
14434 insertScope->functions.insert({fctId, FunctionManifestationList()});
26
27 // Collect substantiations
28 14434 std::vector<Function> manifestations;
29
1/2
✓ Branch 12 → 13 taken 14434 times.
✗ Branch 12 → 51 not taken.
14434 substantiateOptionalParams(baseFunction, manifestations);
30
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 14434 times.
14434 assert(!manifestations.empty());
31
32 // Save substantiations in declaration node
33 14434 Function *manifestationPtr = nullptr;
34
2/2
✓ Branch 26 → 18 taken 15411 times.
✓ Branch 26 → 27 taken 14432 times.
29843 for (const Function &manifestation : manifestations) {
35
2/2
✓ Branch 19 → 20 taken 15409 times.
✓ Branch 19 → 50 taken 2 times.
15411 manifestationPtr = insertSubstantiation(insertScope, manifestation, baseFunction.declNode);
36
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 15409 times.
15409 assert(manifestationPtr != nullptr);
37
1/2
✓ Branch 22 → 23 taken 15409 times.
✗ Branch 22 → 24 not taken.
15409 if (nodeFunctionList)
38
1/2
✓ Branch 23 → 24 taken 15409 times.
✗ Branch 23 → 50 not taken.
15409 nodeFunctionList->push_back(manifestationPtr);
39 }
40
41
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 14432 times.
14432 if (!nodeFunctionList)
42 return manifestationPtr;
43
44
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 14432 times.
14432 assert(!nodeFunctionList->empty());
45 14432 return nodeFunctionList->front();
46 14436 }
47
48 /**
49 * Create definite functions from ambiguous ones, in regard to optional arguments.
50 *
51 * Example:
52 * int testFunc(string, int?, double?)
53 * gets
54 * int testFunc(string)
55 * int testFunc(string, int)
56 * int testFunc(string, int, double)
57 *
58 * This method also accepts functions, that are already definite, but does nothing to them.
59 *
60 * @param baseFunction Ambiguous base function
61 * @param manifestations Vector to store the definite manifestations
62 * @return True, if there were optional arguments found
63 */
64 14434 void FunctionManager::substantiateOptionalParams(const Function &baseFunction, std::vector<Function> &manifestations) {
65 // Handle the case of no parameters -> simply return the base function
66
2/2
✓ Branch 3 → 4 taken 3466 times.
✓ Branch 3 → 6 taken 10968 times.
14434 if (baseFunction.paramList.empty()) {
67
1/2
✓ Branch 4 → 5 taken 3466 times.
✗ Branch 4 → 39 not taken.
3466 manifestations.push_back(baseFunction);
68 3466 return;
69 }
70
71 10968 ParamList currentFunctionParamTypes;
72
1/2
✓ Branch 7 → 8 taken 10968 times.
✗ Branch 7 → 37 not taken.
10968 currentFunctionParamTypes.reserve(baseFunction.paramList.size());
73 10968 bool metFirstOptionalParam = false;
74
1/2
✓ Branch 8 → 9 taken 10968 times.
✗ Branch 8 → 37 not taken.
10968 Function manifestation = baseFunction;
75
76 // Loop over all parameters
77
2/2
✓ Branch 24 → 11 taken 17096 times.
✓ Branch 24 → 25 taken 10968 times.
28064 for (const auto &[qualType, isOptional] : baseFunction.paramList) {
78 // Check if we have a mandatory parameter
79
2/2
✓ Branch 12 → 13 taken 16119 times.
✓ Branch 12 → 15 taken 977 times.
17096 if (!isOptional) {
80
1/2
✓ Branch 13 → 14 taken 16119 times.
✗ Branch 13 → 32 not taken.
16119 currentFunctionParamTypes.push_back({qualType, /*optional=*/false});
81 16119 continue;
82 }
83
84 // Add substantiation without the optional parameter
85
2/2
✓ Branch 15 → 16 taken 971 times.
✓ Branch 15 → 19 taken 6 times.
977 if (!metFirstOptionalParam) {
86
1/2
✓ Branch 16 → 17 taken 971 times.
✗ Branch 16 → 34 not taken.
971 manifestation.paramList = currentFunctionParamTypes;
87
1/2
✓ Branch 17 → 18 taken 971 times.
✗ Branch 17 → 34 not taken.
971 manifestations.push_back(manifestation);
88 // Now we cannot accept mandatory parameters anymore
89 971 metFirstOptionalParam = true;
90 }
91
92 // Add substantiation with the optional parameter
93
1/2
✓ Branch 19 → 20 taken 977 times.
✗ Branch 19 → 33 not taken.
977 currentFunctionParamTypes.push_back({qualType, /*optional=*/false});
94
1/2
✓ Branch 20 → 21 taken 977 times.
✗ Branch 20 → 34 not taken.
977 manifestation.paramList = currentFunctionParamTypes;
95
1/2
✓ Branch 21 → 22 taken 977 times.
✗ Branch 21 → 34 not taken.
977 manifestations.push_back(manifestation);
96 }
97
98 // Ensure at least once manifestation
99
2/2
✓ Branch 26 → 27 taken 9997 times.
✓ Branch 26 → 28 taken 971 times.
10968 if (manifestations.empty())
100
1/2
✓ Branch 27 → 28 taken 9997 times.
✗ Branch 27 → 35 not taken.
9997 manifestations.push_back(baseFunction);
101 10968 }
102
103 6 Function FunctionManager::createMainFunction(SymbolTableEntry *entry, const QualTypeList &paramTypes, ASTNode *declNode) {
104 6 ParamList paramList;
105
2/2
✓ Branch 8 → 4 taken 2 times.
✓ Branch 8 → 9 taken 6 times.
8 for (const QualType &paramType : paramTypes)
106
1/2
✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 24 not taken.
2 paramList.push_back({paramType, false});
107
5/10
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 36 not taken.
✓ Branch 12 → 13 taken 6 times.
✗ Branch 12 → 33 not taken.
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 32 not taken.
✓ Branch 14 → 15 taken 6 times.
✗ Branch 14 → 31 not taken.
✓ Branch 16 → 17 taken 6 times.
✗ Branch 16 → 26 not taken.
12 return {MAIN_FUNCTION_NAME, entry, QualType(TY_DYN), QualType(TY_INT), paramList, {}, declNode};
108 6 }
109
110 18460 Function *FunctionManager::insertSubstantiation(Scope *insertScope, const Function &newManifestation, const ASTNode *declNode) {
111
2/4
✓ Branch 2 → 3 taken 18460 times.
✗ Branch 2 → 70 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 18460 times.
18460 assert(newManifestation.hasSubstantiatedParams());
112
113
1/2
✓ Branch 5 → 6 taken 18460 times.
✗ Branch 5 → 70 not taken.
18460 const std::string signature = newManifestation.getSignature(true, true, false);
114
115 // Check if the function exists already
116
5/8
✓ Branch 6 → 7 taken 18460 times.
✗ Branch 6 → 59 not taken.
✓ Branch 7 → 8 taken 18460 times.
✗ Branch 7 → 59 not taken.
✓ Branch 8 → 9 taken 18460 times.
✗ Branch 8 → 59 not taken.
✓ Branch 30 → 10 taken 296032 times.
✓ Branch 30 → 31 taken 18458 times.
314490 for (const auto &manifestations : insertScope->functions | std::views::values) {
117
3/4
✓ Branch 11 → 12 taken 296032 times.
✗ Branch 11 → 59 not taken.
✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 28 taken 296030 times.
296032 if (manifestations.contains(signature)) {
118
2/2
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 18 taken 1 time.
2 const SemanticErrorType errorType = newManifestation.isFunction() ? FUNCTION_DECLARED_TWICE : PROCEDURE_DECLARED_TWICE;
119
4/8
✓ Branch 20 → 21 taken 2 times.
✗ Branch 20 → 53 not taken.
✓ Branch 21 → 22 taken 2 times.
✗ Branch 21 → 51 not taken.
✓ Branch 22 → 23 taken 2 times.
✗ Branch 22 → 49 not taken.
✓ Branch 23 → 24 taken 2 times.
✗ Branch 23 → 47 not taken.
2 throw SemanticError(declNode, errorType, "'" + newManifestation.getSignature(true, false) + "' is declared twice");
120 }
121 }
122
123 // Retrieve the matching manifestation list of the scope
124
3/6
✓ Branch 31 → 32 taken 18458 times.
✗ Branch 31 → 65 not taken.
✓ Branch 32 → 33 taken 18458 times.
✗ Branch 32 → 62 not taken.
✓ Branch 33 → 34 taken 18458 times.
✗ Branch 33 → 60 not taken.
18458 const std::string fctId = newManifestation.name + ":" + declNode->codeLoc.toPrettyLineAndColumn();
125
2/4
✓ Branch 36 → 37 taken 18458 times.
✗ Branch 36 → 66 not taken.
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 39 taken 18458 times.
18458 assert(insertScope->functions.contains(fctId));
126
1/2
✓ Branch 39 → 40 taken 18458 times.
✗ Branch 39 → 66 not taken.
18458 FunctionManifestationList &manifestationList = insertScope->functions.at(fctId);
127
128 // Add substantiated function
129
1/2
✓ Branch 40 → 41 taken 18458 times.
✗ Branch 40 → 66 not taken.
18458 manifestationList.emplace(signature, newManifestation);
130
1/2
✓ Branch 41 → 42 taken 18458 times.
✗ Branch 41 → 66 not taken.
36916 return &manifestationList.at(signature);
131 18460 }
132
133 /**
134 * Checks if a function exists by matching it, but not setting it to used
135 *
136 * @param matchScope Scope to match against
137 * @param reqName Function name requirement
138 * @param reqThisType This type requirement
139 * @param reqArgs Argument requirement
140 * @param strictQualifierMatching Match argument and this type qualifiers strictly
141 * @return Found function or nullptr
142 */
143 13651 const Function *FunctionManager::lookup(Scope *matchScope, const std::string &reqName, const QualType &reqThisType,
144 const ArgList &reqArgs, bool strictQualifierMatching) {
145
2/4
✓ Branch 2 → 3 taken 13651 times.
✗ Branch 2 → 66 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 13651 times.
13651 assert(reqThisType.isOneOf({TY_DYN, TY_STRUCT}));
146
147 // Do cache lookup
148 13651 const uint64_t cacheKey = getCacheKey(matchScope, reqName, reqThisType, reqArgs, {});
149
3/4
✓ Branch 8 → 9 taken 13651 times.
✗ Branch 8 → 80 not taken.
✓ Branch 9 → 10 taken 3827 times.
✓ Branch 9 → 12 taken 9824 times.
13651 if (lookupCache.contains(cacheKey)) {
150 3827 lookupCacheHits++;
151
1/2
✓ Branch 10 → 11 taken 3827 times.
✗ Branch 10 → 80 not taken.
3827 return lookupCache.at(cacheKey);
152 }
153 9824 lookupCacheMisses++;
154
155 2899 const auto pred = [&](const Arg &arg) { return arg.first.hasAnyGenericParts(); };
156
5/8
✓ Branch 12 → 13 taken 9824 times.
✗ Branch 12 → 80 not taken.
✓ Branch 13 → 14 taken 9443 times.
✓ Branch 13 → 17 taken 381 times.
✓ Branch 14 → 15 taken 9443 times.
✗ Branch 14 → 80 not taken.
✓ Branch 15 → 16 taken 9443 times.
✗ Branch 15 → 17 not taken.
9824 const bool requestedFullySubstantiated = !reqThisType.hasAnyGenericParts() && std::ranges::none_of(reqArgs, pred);
157
158 // Copy the registry to prevent iterating over items, that are created within the loop
159
1/2
✓ Branch 18 → 19 taken 9824 times.
✗ Branch 18 → 80 not taken.
9824 const FunctionRegistry functionRegistry = matchScope->functions;
160 // Loop over function registry to find functions, that match the requirements of the call
161 9824 std::vector<const Function *> matches;
162
2/2
✓ Branch 55 → 21 taken 80618 times.
✓ Branch 55 → 56 taken 9824 times.
90442 for (const auto &[defCodeLocStr, m] : functionRegistry) {
163 // Copy the manifestation list to prevent iterating over items, that are created within the loop
164
1/2
✓ Branch 24 → 25 taken 80618 times.
✗ Branch 24 → 74 not taken.
80618 const FunctionManifestationList manifestations = m;
165
2/2
✓ Branch 51 → 27 taken 90904 times.
✓ Branch 51 → 52 taken 28774 times.
119678 for (const auto &[signature, presetFunction] : manifestations) {
166
2/4
✓ Branch 30 → 31 taken 90904 times.
✗ Branch 30 → 70 not taken.
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 33 taken 90904 times.
90904 assert(presetFunction.hasSubstantiatedParams()); // No optional params are allowed at this point
167
168 // - search for concrete fct: Only match against fully substantiated versions to prevent double matching of a function
169 // - search for generic fct: Only match against generic preset functions
170
3/4
✓ Branch 33 → 34 taken 90904 times.
✗ Branch 33 → 70 not taken.
✓ Branch 34 → 35 taken 32078 times.
✓ Branch 34 → 36 taken 58826 times.
90904 if (presetFunction.isFullySubstantiated() != requestedFullySubstantiated)
171 39060 continue;
172
173 // Copy the function to be able to substantiate types
174
1/2
✓ Branch 36 → 37 taken 58826 times.
✗ Branch 36 → 70 not taken.
58826 Function candidate = presetFunction;
175
176 // Create empty type mapping
177 58826 TypeMapping &typeMapping = candidate.typeMapping;
178
179 58826 bool forceSubstantiation = false;
180
1/2
✓ Branch 37 → 38 taken 58826 times.
✗ Branch 37 → 68 not taken.
58826 const MatchResult matchResult = matchManifestation(candidate, matchScope, reqName, reqThisType, reqArgs, typeMapping,
181 strictQualifierMatching, forceSubstantiation, nullptr);
182
2/2
✓ Branch 38 → 39 taken 50345 times.
✓ Branch 38 → 40 taken 8481 times.
58826 if (matchResult == MatchResult::SKIP_FUNCTION)
183 50345 break; // Leave the whole function
184
2/2
✓ Branch 40 → 41 taken 6982 times.
✓ Branch 40 → 42 taken 1499 times.
8481 if (matchResult == MatchResult::SKIP_MANIFESTATION)
185 6982 continue; // Leave this manifestation and try the next one
186
187 // Add to matches
188
3/6
✓ Branch 42 → 43 taken 1499 times.
✗ Branch 42 → 67 not taken.
✓ Branch 43 → 44 taken 1499 times.
✗ Branch 43 → 67 not taken.
✓ Branch 44 → 45 taken 1499 times.
✗ Branch 44 → 67 not taken.
1499 matches.push_back(&matchScope->functions.at(defCodeLocStr).at(signature));
189
190 1499 break; // Leave the whole manifestation list to not double-match the manifestation
191
2/2
✓ Branch 47 → 48 taken 6982 times.
✓ Branch 47 → 49 taken 51844 times.
58826 }
192 80618 }
193
194 // Return the very match or a nullptr
195
2/2
✓ Branch 57 → 58 taken 1499 times.
✓ Branch 57 → 60 taken 8325 times.
9824 return !matches.empty() ? matches.front() : nullptr;
196 9824 }
197
198 /**
199 * Check if there is a function in the scope, fulfilling all given requirements and if found, return it.
200 * If more than one function matches the requirement, an error gets thrown.
201 *
202 * @param matchScope Scope to match against
203 * @param reqName Function name requirement
204 * @param reqThisType This type requirement
205 * @param reqArgs Argument requirement
206 * @param templateTypeHints Template type requirement
207 * @param strictQualifierMatching Match argument and this type qualifiers strictly
208 * @param callNode Call AST node for printing error messages
209 * @return Matched function or nullptr
210 */
211 81553 Function *FunctionManager::match(Scope *matchScope, const std::string &reqName, const QualType &reqThisType,
212 const ArgList &reqArgs, const QualTypeList &templateTypeHints, bool strictQualifierMatching,
213 const ASTNode *callNode) {
214
2/4
✓ Branch 2 → 3 taken 81553 times.
✗ Branch 2 → 171 not taken.
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 81553 times.
81553 assert(reqThisType.isOneOf({TY_DYN, TY_STRUCT, TY_INTERFACE}));
215
216 // Do cache lookup
217 81553 const uint64_t cacheKey = getCacheKey(matchScope, reqName, reqThisType, reqArgs, templateTypeHints);
218
3/4
✓ Branch 6 → 7 taken 81553 times.
✗ Branch 6 → 219 not taken.
✓ Branch 7 → 8 taken 13094 times.
✓ Branch 7 → 10 taken 68459 times.
81553 if (lookupCache.contains(cacheKey)) {
219 13094 lookupCacheHits++;
220
1/2
✓ Branch 8 → 9 taken 13094 times.
✗ Branch 8 → 219 not taken.
13094 return lookupCache.at(cacheKey);
221 }
222 68459 lookupCacheMisses++;
223
224 // Copy the registry to prevent iterating over items, that are created within the loop
225
1/2
✓ Branch 10 → 11 taken 68459 times.
✗ Branch 10 → 219 not taken.
68459 FunctionRegistry functionRegistry = matchScope->functions;
226 // Loop over function registry to find functions, that match the requirements of the call
227 68459 std::vector<Function *> matches;
228
2/2
✓ Branch 138 → 13 taken 928760 times.
✓ Branch 138 → 139 taken 68458 times.
997218 for (const auto &[fctId, m] : functionRegistry) {
229 // Copy the manifestation list to prevent iterating over items, that are created within the loop
230
1/2
✓ Branch 16 → 17 taken 928760 times.
✗ Branch 16 → 200 not taken.
928760 const FunctionManifestationList manifestations = m;
231
2/2
✓ Branch 134 → 19 taken 939326 times.
✓ Branch 134 → 135 taken 50681 times.
990007 for (const auto &[signature, presetFunction] : manifestations) {
232
2/4
✓ Branch 22 → 23 taken 939326 times.
✗ Branch 22 → 196 not taken.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 939326 times.
939326 assert(presetFunction.hasSubstantiatedParams()); // No optional params are allowed at this point
233
234 // Skip generic substantiations to prevent double matching of a function
235
3/4
✓ Branch 25 → 26 taken 939326 times.
✗ Branch 25 → 196 not taken.
✓ Branch 26 → 27 taken 8335 times.
✓ Branch 26 → 28 taken 930991 times.
939326 if (presetFunction.isGenericSubstantiation())
236 61247 continue;
237
238 // Copy the function to be able to substantiate types
239
1/2
✓ Branch 28 → 29 taken 930991 times.
✗ Branch 28 → 196 not taken.
930991 Function candidate = presetFunction;
240
241 // Prepare type mapping, based on the given initial type mapping
242 930991 TypeMapping &typeMapping = candidate.typeMapping;
243 930991 typeMapping.clear();
244
2/2
✓ Branch 41 → 31 taken 41868 times.
✓ Branch 41 → 42 taken 930991 times.
972859 for (size_t i = 0; i < std::min(templateTypeHints.size(), candidate.templateTypes.size()); i++) {
245
2/4
✓ Branch 31 → 32 taken 41868 times.
✗ Branch 31 → 194 not taken.
✓ Branch 32 → 33 taken 41868 times.
✗ Branch 32 → 194 not taken.
41868 const std::string &typeName = candidate.templateTypes.at(i).getSubType();
246
1/2
✓ Branch 33 → 34 taken 41868 times.
✗ Branch 33 → 194 not taken.
41868 const QualType &templateType = templateTypeHints.at(i);
247
2/4
✓ Branch 34 → 35 taken 41868 times.
✗ Branch 34 → 174 not taken.
✓ Branch 35 → 36 taken 41868 times.
✗ Branch 35 → 172 not taken.
41868 typeMapping.insert({typeName, templateType});
248 }
249
250 930991 bool forceSubstantiation = false;
251
2/2
✓ Branch 42 → 43 taken 930990 times.
✓ Branch 42 → 194 taken 1 time.
930991 const MatchResult matchResult = matchManifestation(candidate, matchScope, reqName, reqThisType, reqArgs, typeMapping,
252 strictQualifierMatching, forceSubstantiation, callNode);
253
2/2
✓ Branch 43 → 44 taken 874651 times.
✓ Branch 43 → 45 taken 56339 times.
930990 if (matchResult == MatchResult::SKIP_FUNCTION)
254 874651 break; // Leave the whole function
255
2/2
✓ Branch 45 → 46 taken 46836 times.
✓ Branch 45 → 47 taken 9503 times.
56339 if (matchResult == MatchResult::SKIP_MANIFESTATION)
256 46836 continue; // Leave this manifestation and try the next one
257
258 // We found a match! -> Set the actual candidate and its entry to used
259 9503 candidate.used = true;
260 9503 candidate.entry->used = true;
261
262 // Check if the function is generic needs to be substantiated
263
6/6
✓ Branch 48 → 49 taken 6163 times.
✓ Branch 48 → 51 taken 3340 times.
✓ Branch 49 → 50 taken 6076 times.
✓ Branch 49 → 51 taken 87 times.
✓ Branch 52 → 53 taken 6076 times.
✓ Branch 52 → 65 taken 3427 times.
9503 if (presetFunction.templateTypes.empty() && !forceSubstantiation) {
264
5/10
✓ Branch 53 → 54 taken 6076 times.
✗ Branch 53 → 194 not taken.
✓ Branch 54 → 55 taken 6076 times.
✗ Branch 54 → 59 not taken.
✓ Branch 55 → 56 taken 6076 times.
✗ Branch 55 → 194 not taken.
✓ Branch 56 → 57 taken 6076 times.
✗ Branch 56 → 194 not taken.
✓ Branch 57 → 58 taken 6076 times.
✗ Branch 57 → 59 not taken.
6076 assert(matchScope->functions.contains(fctId) && matchScope->functions.at(fctId).contains(signature));
265
3/6
✓ Branch 60 → 61 taken 6076 times.
✗ Branch 60 → 175 not taken.
✓ Branch 61 → 62 taken 6076 times.
✗ Branch 61 → 175 not taken.
✓ Branch 62 → 63 taken 6076 times.
✗ Branch 62 → 175 not taken.
6076 matches.push_back(&matchScope->functions.at(fctId).at(signature));
266 6076 matches.back()->used = true;
267 6076 continue; // Match was successful -> match the next function
268 }
269
270 // Check if we already have this manifestation and can simply re-use it
271
1/2
✓ Branch 65 → 66 taken 3427 times.
✗ Branch 65 → 194 not taken.
3427 const std::string newSignature = candidate.getSignature(true, true, false);
272
4/6
✓ Branch 66 → 67 taken 3427 times.
✗ Branch 66 → 192 not taken.
✓ Branch 67 → 68 taken 3427 times.
✗ Branch 67 → 192 not taken.
✓ Branch 68 → 69 taken 378 times.
✓ Branch 68 → 74 taken 3049 times.
3427 if (matchScope->functions.at(fctId).contains(newSignature)) {
273
3/6
✓ Branch 69 → 70 taken 378 times.
✗ Branch 69 → 176 not taken.
✓ Branch 70 → 71 taken 378 times.
✗ Branch 70 → 176 not taken.
✓ Branch 71 → 72 taken 378 times.
✗ Branch 71 → 176 not taken.
378 matches.push_back(&matchScope->functions.at(fctId).at(newSignature));
274 378 matches.back()->used = true;
275 378 break; // Leave the whole manifestation list to not double-match the manifestation
276 }
277
278 // Insert the substantiated version if required
279
1/2
✓ Branch 74 → 75 taken 3049 times.
✗ Branch 74 → 192 not taken.
3049 Function *substantiatedFunction = insertSubstantiation(matchScope, candidate, presetFunction.declNode);
280
2/4
✓ Branch 75 → 76 taken 3049 times.
✗ Branch 75 → 192 not taken.
✓ Branch 76 → 77 taken 3049 times.
✗ Branch 76 → 192 not taken.
3049 substantiatedFunction->genericPreset = &matchScope->functions.at(fctId).at(signature);
281 3049 substantiatedFunction->alreadyTypeChecked = false;
282
2/4
✓ Branch 77 → 78 taken 3049 times.
✗ Branch 77 → 192 not taken.
✓ Branch 78 → 79 taken 3049 times.
✗ Branch 78 → 192 not taken.
3049 substantiatedFunction->declNode->getFctManifestations(reqName)->push_back(substantiatedFunction);
283
284 // Copy function entry
285
1/2
✓ Branch 79 → 80 taken 3049 times.
✗ Branch 79 → 192 not taken.
3049 const std::string newScopeName = substantiatedFunction->getScopeName();
286
1/2
✓ Branch 80 → 81 taken 3049 times.
✗ Branch 80 → 190 not taken.
3049 matchScope->lookupStrict(presetFunction.entry->name)->used = true;
287
1/2
✓ Branch 83 → 84 taken 3049 times.
✗ Branch 83 → 190 not taken.
3049 substantiatedFunction->entry = matchScope->symbolTable.copySymbol(presetFunction.entry->name, newScopeName);
288
1/2
✗ Branch 84 → 85 not taken.
✓ Branch 84 → 86 taken 3049 times.
3049 assert(substantiatedFunction->entry != nullptr);
289
290 // Copy function scope
291
1/2
✓ Branch 86 → 87 taken 3049 times.
✗ Branch 86 → 190 not taken.
3049 const std::string oldScopeName = presetFunction.getScopeName();
292
1/2
✓ Branch 87 → 88 taken 3049 times.
✗ Branch 87 → 188 not taken.
3049 Scope *childScope = matchScope->copyChildScope(oldScopeName, newScopeName);
293
1/2
✗ Branch 88 → 89 not taken.
✓ Branch 88 → 90 taken 3049 times.
3049 assert(childScope != nullptr);
294 3049 childScope->isGenericScope = false;
295 3049 substantiatedFunction->bodyScope = childScope;
296
297 // Insert symbols for generic type names with concrete types into the child block
298
2/2
✓ Branch 100 → 92 taken 4256 times.
✓ Branch 100 → 101 taken 3049 times.
7305 for (const auto &[typeName, concreteType] : substantiatedFunction->typeMapping)
299
2/4
✓ Branch 95 → 96 taken 4256 times.
✗ Branch 95 → 179 not taken.
✓ Branch 96 → 97 taken 4256 times.
✗ Branch 96 → 177 not taken.
4256 childScope->insertGenericType(typeName, GenericType(concreteType));
300
301 // Substantiate the 'this' entry in the new function scope
302
5/6
✓ Branch 104 → 105 taken 1892 times.
✓ Branch 104 → 108 taken 1157 times.
✓ Branch 106 → 107 taken 1892 times.
✗ Branch 106 → 108 not taken.
✓ Branch 109 → 110 taken 1892 times.
✓ Branch 109 → 123 taken 1157 times.
3049 if (presetFunction.isMethod() && !presetFunction.templateTypes.empty()) {
303
1/2
✓ Branch 112 → 113 taken 1892 times.
✗ Branch 112 → 183 not taken.
5676 SymbolTableEntry *thisEntry = childScope->lookupStrict(THIS_VARIABLE_NAME);
304
1/2
✗ Branch 118 → 119 not taken.
✓ Branch 118 → 120 taken 1892 times.
1892 assert(thisEntry != nullptr);
305
2/4
✓ Branch 120 → 121 taken 1892 times.
✗ Branch 120 → 187 not taken.
✓ Branch 121 → 122 taken 1892 times.
✗ Branch 121 → 187 not taken.
1892 thisEntry->updateType(candidate.thisType.toPtr(callNode), /*overwriteExistingType=*/true);
306 }
307
308 // Add to matched functions
309
1/2
✓ Branch 123 → 124 taken 3049 times.
✗ Branch 123 → 188 not taken.
3049 matches.push_back(substantiatedFunction);
310
311 3049 break; // Leave the whole manifestation list to not double-match the manifestation
312
2/2
✓ Branch 130 → 131 taken 52912 times.
✓ Branch 130 → 132 taken 878078 times.
934418 }
313 928760 }
314
315 // If no matches were found, return a nullptr
316
2/2
✓ Branch 140 → 141 taken 58956 times.
✓ Branch 140 → 142 taken 9502 times.
68458 if (matches.empty())
317 58956 return nullptr;
318
319 // Check if more than one function matches the requirements
320
2/2
✓ Branch 143 → 144 taken 1 time.
✓ Branch 143 → 163 taken 9501 times.
9502 if (matches.size() > 1) {
321
1/2
✓ Branch 144 → 145 taken 1 time.
✗ Branch 144 → 214 not taken.
1 std::stringstream errorMessage;
322
3/6
✓ Branch 145 → 146 taken 1 time.
✗ Branch 145 → 212 not taken.
✓ Branch 146 → 147 taken 1 time.
✗ Branch 146 → 212 not taken.
✓ Branch 147 → 148 taken 1 time.
✗ Branch 147 → 212 not taken.
1 errorMessage << "The function/procedure '" << reqName << "' is ambiguous. All of the following match the requested criteria:";
323
2/2
✓ Branch 157 → 150 taken 2 times.
✓ Branch 157 → 158 taken 1 time.
3 for (const Function *match : matches)
324
3/6
✓ Branch 151 → 152 taken 2 times.
✗ Branch 151 → 205 not taken.
✓ Branch 152 → 153 taken 2 times.
✗ Branch 152 → 204 not taken.
✓ Branch 153 → 154 taken 2 times.
✗ Branch 153 → 202 not taken.
2 errorMessage << "\n " << match->getSignature();
325
2/4
✓ Branch 159 → 160 taken 1 time.
✗ Branch 159 → 209 not taken.
✓ Branch 160 → 161 taken 1 time.
✗ Branch 160 → 206 not taken.
1 throw SemanticError(callNode, FUNCTION_AMBIGUITY, errorMessage.str());
326 1 }
327 9501 Function *matchedFunction = matches.front();
328
329 // Insert into cache
330
1/2
✓ Branch 164 → 165 taken 9501 times.
✗ Branch 164 → 215 not taken.
9501 lookupCache[cacheKey] = matchedFunction;
331
332 // Trigger revisit in type checker if required
333
1/2
✓ Branch 165 → 166 taken 9501 times.
✗ Branch 165 → 215 not taken.
9501 TypeChecker::requestRevisitIfRequired(matchedFunction);
334
335 // Return the very match
336 9501 return matchedFunction;
337 68461 }
338
339 989817 MatchResult FunctionManager::matchManifestation(Function &candidate, Scope *&matchScope, const std::string &reqName,
340 const QualType &reqThisType, const ArgList &reqArgs, TypeMapping &typeMapping,
341 bool strictQualifierMatching, bool &forceSubstantiation,
342 const ASTNode *callNode) {
343 // Check name requirement
344
2/2
✓ Branch 3 → 4 taken 924996 times.
✓ Branch 3 → 5 taken 64821 times.
989817 if (!matchName(candidate, reqName))
345 924996 return MatchResult::SKIP_FUNCTION; // Leave the whole manifestation list, because all have the same name
346
347 // Check 'this' type requirement
348
2/2
✓ Branch 6 → 7 taken 2 times.
✓ Branch 6 → 8 taken 64819 times.
64821 if (!matchThisType(candidate, reqThisType, typeMapping, strictQualifierMatching, callNode))
349 2 return MatchResult::SKIP_MANIFESTATION; // Leave this manifestation and try the next one
350
351 // Check arg types requirement
352
2/2
✓ Branch 9 → 10 taken 53815 times.
✓ Branch 9 → 11 taken 11003 times.
64819 if (!matchArgTypes(candidate, reqArgs, typeMapping, strictQualifierMatching, forceSubstantiation, callNode))
353 53815 return MatchResult::SKIP_MANIFESTATION; // Leave this manifestation and try the next one
354
355 // Check if there are unresolved generic types
356
2/2
✓ Branch 13 → 14 taken 1 time.
✓ Branch 13 → 15 taken 11002 times.
11003 if (typeMapping.size() < candidate.templateTypes.size())
357 1 return MatchResult::SKIP_MANIFESTATION; // Leave this manifestation and try the next one
358
359 // Substantiate return type
360 11002 substantiateReturnType(candidate, typeMapping, callNode);
361
362 // Set the match scope to the scope of the concrete substantiation
363 11002 const QualType &thisType = candidate.thisType;
364
2/2
✓ Branch 17 → 18 taken 6180 times.
✓ Branch 17 → 25 taken 4822 times.
11002 if (!thisType.is(TY_DYN)) {
365 // If we only have the generic struct scope, lookup the concrete manifestation scope
366
2/2
✓ Branch 18 → 19 taken 63 times.
✓ Branch 18 → 23 taken 6117 times.
6180 if (matchScope->isGenericScope) {
367 63 const Struct *spiceStruct = thisType.getStruct(candidate.declNode);
368
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 63 times.
63 assert(spiceStruct != nullptr);
369 63 matchScope = spiceStruct->scope;
370 }
371
1/2
✓ Branch 23 → 24 taken 6180 times.
✗ Branch 23 → 27 not taken.
6180 candidate.thisType = candidate.thisType.getWithBodyScope(matchScope);
372 }
373
374 11002 return MatchResult::MATCHED;
375 }
376
377 /**
378 * Checks if the matching candidate fulfills the name requirement
379 *
380 * @param candidate Matching candidate function
381 * @param reqName Requested function name
382 * @return Fulfilled or not
383 */
384 989817 bool FunctionManager::matchName(const Function &candidate, const std::string &reqName) { return candidate.name == reqName; }
385
386 /**
387 * Checks if the matching candidate fulfills the 'this' type requirement
388 *
389 * @param candidate Matching candidate function
390 * @param reqThisType Requested 'this' type
391 * @param typeMapping Concrete template type mapping
392 * @param strictQualifierMatching Match qualifiers strictly
393 * @param callNode Call AST node for printing error messages
394 * @return Fulfilled or not
395 */
396 64821 bool FunctionManager::matchThisType(Function &candidate, const QualType &reqThisType, TypeMapping &typeMapping,
397 bool strictQualifierMatching, const ASTNode *callNode) {
398 64821 QualType &candidateThisType = candidate.thisType;
399
400 // Shortcut for procedures
401
7/10
✓ Branch 2 → 3 taken 64821 times.
✗ Branch 2 → 23 not taken.
✓ Branch 3 → 4 taken 45065 times.
✓ Branch 3 → 7 taken 19756 times.
✓ Branch 4 → 5 taken 45065 times.
✗ Branch 4 → 23 not taken.
✓ Branch 5 → 6 taken 45065 times.
✗ Branch 5 → 7 not taken.
✓ Branch 8 → 9 taken 45065 times.
✓ Branch 8 → 10 taken 19756 times.
64821 if (candidateThisType.is(TY_DYN) && reqThisType.is(TY_DYN))
402 45065 return true;
403
404 // Give the type matcher a way to retrieve instances of GenericType by their name
405 42603 TypeMatcher::ResolverFct genericTypeResolver = [&](const std::string &genericTypeName) {
406 3091 return getGenericTypeOfCandidateByName(candidate, genericTypeName);
407 19756 };
408
409 // Check if the requested 'this' type matches the candidate 'this' type. The type mapping may be extended
410
3/4
✓ Branch 11 → 12 taken 19756 times.
✗ Branch 11 → 21 not taken.
✓ Branch 12 → 13 taken 2 times.
✓ Branch 12 → 14 taken 19754 times.
19756 if (!TypeMatcher::matchRequestedToCandidateType(candidateThisType, reqThisType, typeMapping, genericTypeResolver,
411 strictQualifierMatching))
412 2 return false;
413
414 // Substantiate the candidate param type, based on the type mapping
415
3/4
✓ Branch 14 → 15 taken 19754 times.
✗ Branch 14 → 21 not taken.
✓ Branch 15 → 16 taken 3224 times.
✓ Branch 15 → 17 taken 16530 times.
19754 if (candidateThisType.hasAnyGenericParts())
416
1/2
✓ Branch 16 → 17 taken 3224 times.
✗ Branch 16 → 21 not taken.
3224 TypeMatcher::substantiateTypeWithTypeMapping(candidateThisType, typeMapping, callNode);
417
418 19754 return true;
419 19756 }
420
421 /**
422 * Checks if the matching candidate fulfills the argument types requirement
423 *
424 * @param candidate Matching candidate function
425 * @param reqArgs Requested argument types
426 * @param typeMapping Concrete template type mapping
427 * @param strictQualifierMatching Match qualifiers strictly
428 * @param needsSubstantiation We want to create a substantiation after successfully matching
429 * @param callNode Call AST node for printing error messages
430 * @return Fulfilled or not
431 */
432 64819 bool FunctionManager::matchArgTypes(Function &candidate, const ArgList &reqArgs, TypeMapping &typeMapping,
433 bool strictQualifierMatching, bool &needsSubstantiation, const ASTNode *callNode) {
434 64819 std::vector<Param> &candidateParamList = candidate.paramList;
435
436 // If the number of arguments does not match with the number of params, the matching fails
437
6/6
✓ Branch 2 → 3 taken 64734 times.
✓ Branch 2 → 7 taken 85 times.
✓ Branch 5 → 6 taken 8234 times.
✓ Branch 5 → 7 taken 56500 times.
✓ Branch 8 → 9 taken 8234 times.
✓ Branch 8 → 10 taken 56585 times.
64819 if (!candidate.isVararg && reqArgs.size() != candidateParamList.size())
438 8234 return false;
439 // In the case of a vararg function, we only disallow fewer arguments than parameters
440
4/6
✓ Branch 10 → 11 taken 85 times.
✓ Branch 10 → 15 taken 56500 times.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 85 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 56585 times.
56585 if (candidate.isVararg && reqArgs.size() < candidateParamList.size())
441 return false;
442
443 // Give the type matcher a way to retrieve instances of GenericType by their name
444 119015 TypeMatcher::ResolverFct genericTypeResolver = [&](const std::string &genericTypeName) {
445 5845 return getGenericTypeOfCandidateByName(candidate, genericTypeName);
446 56585 };
447
448 // Loop over all parameters
449
2/2
✓ Branch 66 → 20 taken 62203 times.
✓ Branch 66 → 67 taken 11003 times.
73206 for (size_t i = 0; i < reqArgs.size(); i++) {
450 // In the case of a vararg function candidate, we can accept additional arguments, that are not defined in the candidate,
451 // but we need to modify the candidate param list to accept them
452
6/6
✓ Branch 20 → 21 taken 341 times.
✓ Branch 20 → 24 taken 61862 times.
✓ Branch 22 → 23 taken 89 times.
✓ Branch 22 → 24 taken 252 times.
✓ Branch 25 → 26 taken 89 times.
✓ Branch 25 → 29 taken 62114 times.
62203 if (candidate.isVararg && i >= candidateParamList.size()) {
453
2/4
✓ Branch 26 → 27 taken 89 times.
✗ Branch 26 → 71 not taken.
✓ Branch 27 → 28 taken 89 times.
✗ Branch 27 → 71 not taken.
89 candidateParamList.push_back(Param(reqArgs.at(i).first, false));
454 89 needsSubstantiation = true; // We need to modify the candidate param types
455 89 continue;
456 }
457
458 // Retrieve actual and requested types
459
2/4
✓ Branch 29 → 30 taken 62114 times.
✗ Branch 29 → 84 not taken.
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 62114 times.
62114 assert(!candidateParamList.at(i).isOptional);
460
1/2
✓ Branch 32 → 33 taken 62114 times.
✗ Branch 32 → 84 not taken.
62114 QualType &candidateType = candidateParamList.at(i).qualType;
461
1/2
✓ Branch 33 → 34 taken 62114 times.
✗ Branch 33 → 84 not taken.
62114 const auto &[requestedType, isArgTemporary] = reqArgs.at(i);
462
463 // Check if the requested param type matches the candidate param type. The type mapping may be extended
464
3/4
✓ Branch 36 → 37 taken 62114 times.
✗ Branch 36 → 84 not taken.
✓ Branch 37 → 38 taken 45581 times.
✓ Branch 37 → 39 taken 16533 times.
62114 if (!TypeMatcher::matchRequestedToCandidateType(candidateType, requestedType, typeMapping, genericTypeResolver,
465 strictQualifierMatching))
466 45581 return false;
467
468 // Substantiate the candidate param type, based on the type mapping
469
3/4
✓ Branch 39 → 40 taken 16533 times.
✗ Branch 39 → 84 not taken.
✓ Branch 40 → 41 taken 4810 times.
✓ Branch 40 → 42 taken 11723 times.
16533 if (candidateType.hasAnyGenericParts())
470
1/2
✓ Branch 41 → 42 taken 4810 times.
✗ Branch 41 → 84 not taken.
4810 TypeMatcher::substantiateTypeWithTypeMapping(candidateType, typeMapping, callNode);
471
472 // Check if we try to bind a non-ref temporary to a non-const ref parameter
473
3/4
✓ Branch 42 → 43 taken 16533 times.
✗ Branch 42 → 84 not taken.
✓ Branch 43 → 44 taken 1 time.
✓ Branch 43 → 54 taken 16532 times.
16533 if (!candidateType.canBind(requestedType, isArgTemporary)) {
474
1/2
✓ Branch 44 → 45 taken 1 time.
✗ Branch 44 → 53 not taken.
1 if (callNode)
475
2/4
✓ Branch 48 → 49 taken 1 time.
✗ Branch 48 → 75 not taken.
✓ Branch 49 → 50 taken 1 time.
✗ Branch 49 → 72 not taken.
3 throw SemanticError(callNode, TEMP_TO_NON_CONST_REF, "Temporary values can only be bound to const reference parameters");
476 return false;
477 }
478
479 // If we have a function/procedure type we need to take care of the information, if it takes captures
480
9/12
✓ Branch 54 → 55 taken 16532 times.
✗ Branch 54 → 81 not taken.
✓ Branch 55 → 56 taken 16532 times.
✗ Branch 55 → 81 not taken.
✓ Branch 56 → 57 taken 33 times.
✓ Branch 56 → 60 taken 16499 times.
✓ Branch 57 → 58 taken 33 times.
✗ Branch 57 → 81 not taken.
✓ Branch 58 → 59 taken 3 times.
✓ Branch 58 → 60 taken 30 times.
✓ Branch 61 → 62 taken 3 times.
✓ Branch 61 → 64 taken 16529 times.
16532 if (requestedType.getBase().isOneOf({TY_FUNCTION, TY_PROCEDURE}) && requestedType.hasLambdaCaptures()) {
481
1/2
✓ Branch 62 → 63 taken 3 times.
✗ Branch 62 → 83 not taken.
3 candidateType = candidateType.getWithLambdaCaptures();
482 3 needsSubstantiation = true;
483 }
484 }
485
486 11003 return true;
487 56585 }
488
489 /**
490 * Substantiates the candidate return type, based on the given type mapping
491 *
492 * @param candidate Matching candidate function
493 * @param typeMapping Concrete template type mapping
494 * @param callNode AST node for error messages
495 */
496 11002 void FunctionManager::substantiateReturnType(Function &candidate, const TypeMapping &typeMapping, const ASTNode *callNode) {
497
2/2
✓ Branch 3 → 4 taken 730 times.
✓ Branch 3 → 5 taken 10272 times.
11002 if (candidate.returnType.hasAnyGenericParts())
498 730 TypeMatcher::substantiateTypeWithTypeMapping(candidate.returnType, typeMapping, callNode);
499 11002 }
500
501 /**
502 * Searches the candidate template types for a generic type object with a certain name and return it
503 *
504 * @param candidate Matching candidate function
505 * @param templateTypeName Template type name
506 * @return Generic type object
507 */
508 8936 const GenericType *FunctionManager::getGenericTypeOfCandidateByName(const Function &candidate,
509 const std::string &templateTypeName) {
510
1/2
✓ Branch 11 → 4 taken 10369 times.
✗ Branch 11 → 12 not taken.
10369 for (const GenericType &templateType : candidate.templateTypes) {
511
3/4
✓ Branch 5 → 6 taken 10369 times.
✗ Branch 5 → 14 not taken.
✓ Branch 7 → 8 taken 8936 times.
✓ Branch 7 → 9 taken 1433 times.
10369 if (templateType.getSubType() == templateTypeName)
512 8936 return &templateType;
513 }
514 return nullptr;
515 }
516
517 /**
518 * Calculate the cache key for the function lookup cache
519 *
520 * @param scope Scope to match against
521 * @param name Function name requirement
522 * @param thisType This type requirement
523 * @param args Argument requirement
524 * @param templateTypes Template type requirement
525 * @return Cache key
526 */
527 95204 uint64_t FunctionManager::getCacheKey(const Scope *scope, const std::string &name, const QualType &thisType, const ArgList &args,
528 const QualTypeList &templateTypes) {
529 95204 uint64_t hash = 0;
530 95204 hashCombine64(hash, hashPointer(scope));
531 95204 hashCombine64(hash, std::hash<std::string>{}(name));
532 95204 hashCombine64(hash, std::hash<QualType>{}(thisType));
533
2/2
✓ Branch 19 → 10 taken 144675 times.
✓ Branch 19 → 20 taken 95204 times.
239879 for (const auto &[first, second] : args) {
534 144675 hashCombine64(hash, std::hash<QualType>{}(first));
535 144675 hashCombine64(hash, std::hash<bool>{}(second));
536 }
537 95204 hashCombine64(hash, hashVector(templateTypes));
538 95204 return hash;
539 }
540
541 /**
542 * Clear the lookup cache
543 */
544 458 void FunctionManager::cleanup() {
545 458 lookupCache.clear();
546 458 lookupCacheHits = 0;
547 458 lookupCacheMisses = 0;
548 458 }
549
550 /**
551 * Dump usage statistics for the lookup cache
552 */
553 223 std::string FunctionManager::dumpLookupCacheStatistics() {
554
1/2
✓ Branch 2 → 3 taken 223 times.
✗ Branch 2 → 22 not taken.
223 std::stringstream stats;
555
2/4
✓ Branch 3 → 4 taken 223 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 223 times.
✗ Branch 4 → 20 not taken.
223 stats << "FunctionManager lookup cache statistics:" << std::endl;
556
3/6
✓ Branch 5 → 6 taken 223 times.
✗ Branch 5 → 20 not taken.
✓ Branch 7 → 8 taken 223 times.
✗ Branch 7 → 20 not taken.
✓ Branch 8 → 9 taken 223 times.
✗ Branch 8 → 20 not taken.
223 stats << " lookup cache entries: " << lookupCache.size() << std::endl;
557
3/6
✓ Branch 9 → 10 taken 223 times.
✗ Branch 9 → 20 not taken.
✓ Branch 10 → 11 taken 223 times.
✗ Branch 10 → 20 not taken.
✓ Branch 11 → 12 taken 223 times.
✗ Branch 11 → 20 not taken.
223 stats << " lookup cache hits: " << lookupCacheHits << std::endl;
558
3/6
✓ Branch 12 → 13 taken 223 times.
✗ Branch 12 → 20 not taken.
✓ Branch 13 → 14 taken 223 times.
✗ Branch 13 → 20 not taken.
✓ Branch 14 → 15 taken 223 times.
✗ Branch 14 → 20 not taken.
223 stats << " lookup cache misses: " << lookupCacheMisses << std::endl;
559
1/2
✓ Branch 15 → 16 taken 223 times.
✗ Branch 15 → 20 not taken.
446 return stats.str();
560 223 }
561
562 } // namespace spice::compiler
563