Skip to content

Commit 53ec87e

Browse files
committed
consider callsites with nameds for interning
1 parent 3f54237 commit 53ec87e

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/core/callsite.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,54 @@ void MVM_callsite_try_intern(MVMThreadContext *tc, MVMCallsite **cs_ptr) {
66
MVMCallsiteInterns *interns = tc->instance->callsite_interns;
77
MVMCallsite *cs = *cs_ptr;
88
MVMint32 num_pos = cs->num_pos;
9-
MVMint32 i, found;
9+
MVMint32 num_flags = num_pos + (cs->arg_count - num_pos) / 2;
10+
MVMint32 i, j, found;
1011

11-
/* Can't intern anything with named or flattening, for now. */
12-
if (cs->arg_count != num_pos)
13-
return;
12+
/* Can't intern anything with flattening, for now. */
1413
if (cs->has_flattening)
1514
return;
1615

1716
/* Also can't intern past the max arity. */
18-
if (num_pos >= MVM_INTERN_ARITY_LIMIT)
17+
if (num_flags >= MVM_INTERN_ARITY_LIMIT)
18+
return;
19+
20+
if (num_flags > num_pos && !cs->arg_name)
1921
return;
2022

23+
for (j = 0; j < num_flags - num_pos; j++) {
24+
if (!cs->arg_name[j])
25+
return;
26+
}
27+
2128
/* Obtain mutex protecting interns store. */
2229
uv_mutex_lock(&tc->instance->mutex_callsite_interns);
2330

2431
/* Search for a match. */
2532
found = 0;
2633
for (i = 0; i < interns->num_by_arity[num_pos]; i++) {
27-
if (memcmp(interns->by_arity[num_pos][i]->arg_flags, cs->arg_flags, num_pos) == 0) {
34+
if (cs->arg_count != interns->by_arity[num_pos][i]->arg_count)
35+
continue;
36+
if (memcmp(interns->by_arity[num_pos][i]->arg_flags, cs->arg_flags, num_flags) == 0) {
37+
/* Now let's have a look at the named arguments. */
38+
for (j = 0; j < num_flags - num_pos; j++) {
39+
/* if any of the nameds are not known at this time, we skip this */
40+
if ( !interns->by_arity[num_pos][i]->arg_name || !interns->by_arity[num_pos][i]->arg_name[j]
41+
|| !MVM_string_equal(tc, cs->arg_name[j], interns->by_arity[num_pos][i]->arg_name[j])) {
42+
goto cancel;
43+
}
44+
}
2845
/* Got a match! Free the one we were passed and replace it with
2946
* the interned one. */
3047
if (num_pos)
3148
free(cs->arg_flags);
49+
if (num_flags > num_pos)
50+
free(cs->arg_name);
3251
free(cs);
3352
*cs_ptr = interns->by_arity[num_pos][i];
53+
if (num_flags > num_pos)
54+
printf("interned a callsite with %d nameds\n", num_flags - num_pos);
3455
found = 1;
35-
break;
56+
cancel: break;
3657
}
3758
}
3859

0 commit comments

Comments
 (0)