lib/GraphQL/Houtou.xs

filter: Statementstmt 71.1% 5298 / 7452 Branchbran 46.7% 3326 / 7118 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 59.1% 8624 / 14570 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/parser_core.h ↑ Summary src/vm_runtime.h »
1 #include "bootstrap.h"
2 #include "parser_core.h"
3 #include "parser_graphqlperl_runtime.h"
4 #include "parser_shared_ast.h"
5 #include "parser_ast_runtime.h"
6 #include "parser_ir_runtime.h"
7 #include "schema_compiler.h"
8 #include "validation.h"
9 static SV *gql_runtime_vm_empty_args_sv(pTHX);
10 static SV *gql_runtime_vm_named_coderef_sv(pTHX_ const char *name);
11 typedef struct gql_runtime_vm_async_adapter gql_runtime_vm_async_adapter_t;
12 static void gql_runtime_vm_async_adapter_destroy(pTHX_ gql_runtime_vm_async_adapter_t *adapter);
13 static int gql_runtime_vm_sv_is_pending_async_value(
14 pTHX_ const gql_runtime_vm_async_adapter_t *adapter, SV *value
15 );
16 #include "vm_runtime.h"
17  
18 static SV *gql_runtime_vm_global_empty_args_sv = NULL;
19 static SV *gql_runtime_vm_global_identity_callback_sv = NULL;
20 static HV *gql_runtime_vm_outcome_stash = NULL;
21 static HV *gql_runtime_vm_promise_xs_stash = NULL;
22 static HV *gql_runtime_vm_dataloader_ticket_stash = NULL;
23 static HV *gql_runtime_vm_dataloader_stash = NULL;
24  
25 /* Recycled resolve/reject callback pairs for armed pending entries. Each
26 * newXS + magic attach costs more than the entry bookkeeping it drives, so
27 * fired pairs park here (holding one refcount per CV) and the next arm
28 * reuses them with fresh ctx fields. Bounded; overflow pairs just die with
29 * their promise. Process-lifetime, like the identity callback above. */
30 #define GQL_VM_PENDING_CB_POOL_MAX 128
31 static SV *gql_runtime_vm_pending_cb_pool_resolve[GQL_VM_PENDING_CB_POOL_MAX];
32 static SV *gql_runtime_vm_pending_cb_pool_reject[GQL_VM_PENDING_CB_POOL_MAX];
33 static IV gql_runtime_vm_pending_cb_pool_count = 0;
34  
35 /* Promises on the hot path are exactly Promise::XS::Promise (the stash
36 * compare above gates them), so then() always resolves to the same CV;
37 * cache it and skip call_method's per-call method lookup. */
38 static CV *gql_runtime_vm_promise_xs_then_cv = NULL;
39 static int gql_runtime_vm_sv_is_promise_xs(pTHX_ SV *sv);
40  
41 struct gql_runtime_vm_async_adapter {
42 char *class_name;
43 HV *stash;
44 CV *then_cv;
45 SV *new_pending_cb;
46 SV *all_cb;
47 };
48  
49 /* NULL means synchronous execution. This static descriptor marks the built-in
50 * Promise::XS backend without allocating or retaining Perl callbacks. */
51 static gql_runtime_vm_async_adapter_t gql_runtime_vm_promise_xs_adapter;
52  
53 static gql_runtime_vm_async_adapter_t *
54 242 gql_runtime_vm_async_adapter_from_spec_sv(pTHX_ SV *spec)
55 {
56 HV *hv;
57 SV **class_svp;
58 SV **new_pending_svp;
59 SV **all_svp;
60 SV **then_svp;
61 STRLEN class_len;
62 const char *class_name;
63 gql_runtime_vm_async_adapter_t *adapter;
64  
65 242 ▶ if (!spec || !SvOK(spec)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!spec || !SvOK(spec)) { 242 0 242
if (!spec || !SvOK(spec)) { 221 21 242
66 221 return &gql_runtime_vm_promise_xs_adapter;
67 }
68 21 ▶ if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) { 21 0 21
if (!SvROK(spec) || SvTYPE(SvRV(spec)) != SVt_PVHV) { 0 21 21
69 0 croak("async adapter specification must be a hash reference");
70 }
71 21 hv = (HV *)SvRV(spec);
72 21 class_svp = hv_fetchs(hv, "class", 0);
73 21 new_pending_svp = hv_fetchs(hv, "new_pending", 0);
74 21 all_svp = hv_fetchs(hv, "all", 0);
75 21 then_svp = hv_fetchs(hv, "then", 0);
76 21 ▶ if (!class_svp || !SvOK(*class_svp)
Branch: 2 branches
BranchTrueFalseTotal
if (!class_svp || !SvOK(*class_svp) 21 0 21
if (!class_svp || !SvOK(*class_svp) 21 0 21
77 21 ▶ || !new_pending_svp || !SvROK(*new_pending_svp)
Branch: 2 branches
BranchTrueFalseTotal
|| !new_pending_svp || !SvROK(*new_pending_svp) 21 0 21
|| !new_pending_svp || !SvROK(*new_pending_svp) 21 0 21
78 21 ▶ || SvTYPE(SvRV(*new_pending_svp)) != SVt_PVCV
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*new_pending_svp)) != SVt_PVCV 21 0 21
79 21 ▶ || !all_svp || !SvROK(*all_svp)
Branch: 2 branches
BranchTrueFalseTotal
|| !all_svp || !SvROK(*all_svp) 21 0 21
|| !all_svp || !SvROK(*all_svp) 21 0 21
80 21 ▶ || SvTYPE(SvRV(*all_svp)) != SVt_PVCV
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*all_svp)) != SVt_PVCV 21 0 21
81 21 ▶ || !then_svp || !SvROK(*then_svp)
Branch: 2 branches
BranchTrueFalseTotal
|| !then_svp || !SvROK(*then_svp) 20 1 21
|| !then_svp || !SvROK(*then_svp) 20 0 20
82 20 ▶ || SvTYPE(SvRV(*then_svp)) != SVt_PVCV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*then_svp)) != SVt_PVCV) { 0 20 20
83 1 croak("async adapter requires class, new_pending, all, and then");
84 }
85 20 class_name = SvPV(*class_svp, class_len);
86 20 ▶ if (!class_len || strlen(class_name) != class_len) {
Branch: 2 branches
BranchTrueFalseTotal
if (!class_len || strlen(class_name) != class_len) { 20 0 20
if (!class_len || strlen(class_name) != class_len) { 0 20 20
87 0 croak("async adapter class must be a non-empty string without NUL bytes");
88 }
89 20 Newxz(adapter, 1, gql_runtime_vm_async_adapter_t);
90 20 adapter->class_name = savepvn(class_name, class_len);
91 20 adapter->stash = gv_stashpv(adapter->class_name, GV_ADD);
92 20 adapter->then_cv = (CV *)SvRV(*then_svp);
93 20 adapter->new_pending_cb = newSVsv(*new_pending_svp);
94 20 adapter->all_cb = newSVsv(*all_svp);
95 20 SvREFCNT_inc_simple_void_NN((SV *)adapter->then_cv);
96 20 return adapter;
97 }
98  
99 static void
100 242 gql_runtime_vm_async_adapter_destroy(pTHX_ gql_runtime_vm_async_adapter_t *adapter)
101 {
102 242 ▶ if (!adapter || adapter == &gql_runtime_vm_promise_xs_adapter) {
Branch: 2 branches
BranchTrueFalseTotal
if (!adapter || adapter == &gql_runtime_vm_promise_xs_adapter) { 242 0 242
if (!adapter || adapter == &gql_runtime_vm_promise_xs_adapter) { 222 20 242
103 222 return;
104 }
105 20 Safefree(adapter->class_name);
106 20 SvREFCNT_dec((SV *)adapter->then_cv);
107 20 SvREFCNT_dec(adapter->new_pending_cb);
108 20 SvREFCNT_dec(adapter->all_cb);
109 20 Safefree(adapter);
110 }
111  
112 typedef struct {
113 gql_runtime_vm_native_runtime_t *runtime;
114 } gql_runtime_vm_native_runtime_guard_t;
115  
116 static void
117 242 gql_runtime_vm_native_runtime_guard_cleanup(pTHX_ void *ptr)
118 {
119 242 gql_runtime_vm_native_runtime_guard_t *guard =
120 (gql_runtime_vm_native_runtime_guard_t *)ptr;
121 242 ▶ if (guard && guard->runtime) {
Branch: 2 branches
BranchTrueFalseTotal
if (guard && guard->runtime) { 242 0 242
if (guard && guard->runtime) { 1 241 242
122 1 gql_runtime_vm_native_runtime_destroy(guard->runtime);
123 }
124 242 }
125  
126 static int
127 14900 gql_runtime_vm_sv_is_adapter_promise(
128 pTHX_ const gql_runtime_vm_async_adapter_t *adapter, SV *sv
129 )
130 {
131 SV *rv;
132  
133 14900 ▶ if (gql_runtime_vm_sv_is_promise_xs(aTHX_ sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_promise_xs(aTHX_ sv)) { 313 14587 14900
134 313 return 1;
135 }
136 14587 ▶ if (adapter == &gql_runtime_vm_promise_xs_adapter) {
Branch: 1 branch
BranchTrueFalseTotal
if (adapter == &gql_runtime_vm_promise_xs_adapter) { 14559 28 14587
137 14559 return 0;
138 }
139 28 ▶ if (!adapter || !sv || !SvROK(sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!adapter || !sv || !SvROK(sv)) { 28 0 28
if (!adapter || !sv || !SvROK(sv)) { 28 0 28
if (!adapter || !sv || !SvROK(sv)) { 3 25 28
140 3 return 0;
141 }
142 25 rv = SvRV(sv);
143 25 ▶ if (!SvOBJECT(rv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOBJECT(rv)) { 1 24 25
144 1 return 0;
145 }
146 24 return SvSTASH(rv) == adapter->stash
147 24 ▶ || sv_derived_from(sv, adapter->class_name);
Branch: 2 branches
BranchTrueFalseTotal
|| sv_derived_from(sv, adapter->class_name); 0 24 24
|| sv_derived_from(sv, adapter->class_name); 0 0 0
148 }
149  
150 static CV *
151 117 gql_runtime_vm_promise_xs_then_cv_get(pTHX)
152 {
153 117 ▶ if (!gql_runtime_vm_promise_xs_then_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_promise_xs_then_cv) { 17 100 117
154 17 GV *gv = gv_fetchmethod_autoload(
155 gv_stashpvs("Promise::XS::Promise", GV_ADD), "then", 0
156 );
157 17 ▶ if (gv && GvCV(gv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (gv && GvCV(gv)) { 17 0 17
if (gv && GvCV(gv)) { 17 0 17
158 17 gql_runtime_vm_promise_xs_then_cv = GvCV(gv);
159 17 SvREFCNT_inc_simple_void_NN((SV *)gql_runtime_vm_promise_xs_then_cv);
160 }
161 }
162 117 return gql_runtime_vm_promise_xs_then_cv;
163 }
164  
165 /* Outcome handles are internal-only and blessed exactly into their class,
166 * so an exact stash-pointer compare replaces sv_derived_from's ISA hash
167 * lookups on the per-field hot path. */
168 static int
169 5306 gql_runtime_vm_sv_is_outcome(pTHX_ SV *sv)
170 {
171 SV *rv;
172 5306 ▶ if (!sv || !SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || !SvROK(sv)) { 5306 0 5306
if (!sv || !SvROK(sv)) { 3697 1609 5306
173 3697 return 0;
174 }
175 1609 rv = SvRV(sv);
176 1609 ▶ if (!SvOBJECT(rv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOBJECT(rv)) { 110 1499 1609
177 110 return 0;
178 }
179 1499 ▶ if (!gql_runtime_vm_outcome_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_outcome_stash) { 12 1487 1499
180 12 gql_runtime_vm_outcome_stash = gv_stashpvs("GraphQL::Houtou::Runtime::Outcome", GV_ADD);
181 }
182 1499 return SvSTASH(rv) == gql_runtime_vm_outcome_stash;
183 }
184  
185 /* Promise::XS constructors bless exactly into Promise::XS::Promise, so the
186 * stash compare answers the common case; blessed values of another class
187 * fall back to sv_derived_from to keep subclass semantics. */
188 static int
189 16499 gql_runtime_vm_sv_is_promise_xs(pTHX_ SV *sv)
190 {
191 SV *rv;
192 16499 ▶ if (!sv || !SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || !SvROK(sv)) { 16499 0 16499
if (!sv || !SvROK(sv)) { 2196 14303 16499
193 2196 return 0;
194 }
195 14303 rv = SvRV(sv);
196 14303 ▶ if (!SvOBJECT(rv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOBJECT(rv)) { 8250 6053 14303
197 8250 return 0;
198 }
199 6053 ▶ if (!gql_runtime_vm_promise_xs_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_promise_xs_stash) { 30 6023 6053
200 30 gql_runtime_vm_promise_xs_stash = gv_stashpvs("Promise::XS::Promise", GV_ADD);
201 }
202 6053 ▶ if (SvSTASH(rv) == gql_runtime_vm_promise_xs_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvSTASH(rv) == gql_runtime_vm_promise_xs_stash) { 544 5509 6053
203 544 return 1;
204 }
205 5509 return sv_derived_from(sv, "Promise::XS::Promise");
206 }
207  
208 static int
209 48758 gql_runtime_vm_sv_is_dataloader_ticket(pTHX_ SV *sv)
210 {
211 SV *rv;
212 48758 ▶ if (!sv || !SvROK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || !SvROK(sv)) { 48758 0 48758
if (!sv || !SvROK(sv)) { 8693 40065 48758
213 8693 return 0;
214 }
215 40065 rv = SvRV(sv);
216 40065 ▶ if (!SvOBJECT(rv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOBJECT(rv)) { 7089 32976 40065
217 7089 return 0;
218 }
219 32976 ▶ if (!gql_runtime_vm_dataloader_ticket_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_dataloader_ticket_stash) { 24 32952 32976
220 24 gql_runtime_vm_dataloader_ticket_stash =
221 24 gv_stashpvs("GraphQL::Houtou::DataLoader::Ticket", GV_ADD);
222 }
223 32976 return SvSTASH(rv) == gql_runtime_vm_dataloader_ticket_stash;
224 }
225  
226 static AV *
227 20776 gql_runtime_vm_dataloader_ticket_av(pTHX_ SV *ticket)
228 {
229 20776 ▶ if (!gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ ticket)
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ ticket) 20776 0 20776
230 20776 ▶ || SvTYPE(SvRV(ticket)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(ticket)) != SVt_PVAV) { 0 20776 20776
231 0 croak("invalid DataLoader ticket");
232 }
233 20776 return (AV *)SvRV(ticket);
234 }
235  
236 static IV
237 12856 gql_runtime_vm_dataloader_ticket_state(pTHX_ SV *ticket)
238 {
239 12856 AV *av = gql_runtime_vm_dataloader_ticket_av(aTHX_ ticket);
240 12856 SV **state = av_fetch(av, 0, 0);
241 12856 ▶ return state ? SvIV(*state) : 0;
Branch: 1 branch
BranchTrueFalseTotal
return state ? SvIV(*state) : 0; 12856 0 12856
242 }
243  
244 static SV *
245 36 gql_runtime_vm_dataloader_ticket_value(pTHX_ SV *ticket)
246 {
247 36 AV *av = gql_runtime_vm_dataloader_ticket_av(aTHX_ ticket);
248 36 SV **value = av_fetch(av, 1, 0);
249 36 ▶ return value ? *value : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
return value ? *value : &PL_sv_undef; 36 0 36
250 }
251  
252 static SV *
253 1351 gql_runtime_vm_dataloader_ticket_async_adapter(pTHX_ SV *ticket)
254 {
255 1351 AV *av = gql_runtime_vm_dataloader_ticket_av(aTHX_ ticket);
256 1351 SV **async_adapter = av_fetch(av, 3, 0);
257 1351 ▶ return async_adapter ? *async_adapter : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
return async_adapter ? *async_adapter : &PL_sv_undef; 0 1351 1351
258 }
259  
260 static SV *
261 3422 gql_runtime_vm_new_dataloader_ticket_sv(
262 pTHX_ IV state, SV *value, SV *async_adapter
263 )
264 {
265 3422 AV *av = newAV();
266 3422 av_store(av, 0, newSViv(state));
267 3422 ▶ av_store(av, 1, newSVsv(value ? value : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_store(av, 1, newSVsv(value ? value : &PL_sv_undef)); 3422 0 3422
268 3422 av_store(av, 2, newRV_noinc((SV *)newAV()));
269 3422 ▶ if (async_adapter && SvOK(async_adapter)) {
Branch: 2 branches
BranchTrueFalseTotal
if (async_adapter && SvOK(async_adapter)) { 3422 0 3422
if (async_adapter && SvOK(async_adapter)) { 0 3422 3422
270 0 av_store(av, 3, newSVsv(async_adapter));
271 }
272 3422 ▶ if (!gql_runtime_vm_dataloader_ticket_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_dataloader_ticket_stash) { 6 3416 3422
273 6 gql_runtime_vm_dataloader_ticket_stash =
274 6 gv_stashpvs("GraphQL::Houtou::DataLoader::Ticket", GV_ADD);
275 }
276 3422 return sv_bless(newRV_noinc((SV *)av), gql_runtime_vm_dataloader_ticket_stash);
277 }
278  
279 /*
280 * Declarative fields know that the selected value is a loader, so the
281 * reference implementation can stay entirely in XS instead of entering
282 * DataLoader::load and then returning to _enqueue_load_miss. Exact-stash
283 * matching deliberately preserves overridden load() semantics for
284 * subclasses, which continue through the ordinary method call.
285 */
286 static int
287 16 gql_runtime_vm_is_exact_dataloader(pTHX_ SV *loader)
288 {
289 SV *rv;
290 16 ▶ if (!loader || !SvROK(loader)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!loader || !SvROK(loader)) { 16 0 16
if (!loader || !SvROK(loader)) { 0 16 16
291 0 return 0;
292 }
293 16 rv = SvRV(loader);
294 16 ▶ if (!SvOBJECT(rv) || SvTYPE(rv) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOBJECT(rv) || SvTYPE(rv) != SVt_PVHV) { 16 0 16
if (!SvOBJECT(rv) || SvTYPE(rv) != SVt_PVHV) { 0 16 16
295 0 return 0;
296 }
297 16 ▶ if (!gql_runtime_vm_dataloader_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_dataloader_stash) { 1 15 16
298 1 gql_runtime_vm_dataloader_stash =
299 1 gv_stashpvs("GraphQL::Houtou::DataLoader", GV_ADD);
300 }
301 16 return SvSTASH(rv) == gql_runtime_vm_dataloader_stash;
302 }
303  
304 static SV *
305 13 gql_runtime_vm_dataloader_load_exact_sv(
306 pTHX_ SV *loader, SV *key, SV **error_out
307 )
308 {
309 HV *loader_hv;
310 SV **cache_enabled_svp;
311 SV **cache_key_cb_svp;
312 SV **promises_rv;
313 SV **queue_rv;
314 SV **async_adapter_svp;
315 13 HV *promises_hv = NULL;
316 AV *queue_av;
317 13 SV *cache_key_sv = NULL;
318 SV *ticket_sv;
319 AV *entry_av;
320 int cache_enabled;
321  
322 13 ▶ if (!key || !SvOK(key)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!key || !SvOK(key)) { 13 0 13
if (!key || !SvOK(key)) { 0 13 13
323 0 ▶ if (error_out && !*error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && !*error_out) { 0 0 0
if (error_out && !*error_out) { 0 0 0
324 0 *error_out =
325 0 newSVpvs("GraphQL::Houtou::DataLoader::load requires a defined key");
326 }
327 0 return NULL;
328 }
329 13 loader_hv = (HV *)SvRV(loader);
330 13 cache_enabled_svp = hv_fetch(loader_hv, "cache", 5, 0);
331 13 cache_key_cb_svp = hv_fetch(loader_hv, "cache_key", 9, 0);
332 13 ▶ cache_enabled = !cache_enabled_svp || SvTRUE(*cache_enabled_svp);
Branch: 2 branches
BranchTrueFalseTotal
cache_enabled = !cache_enabled_svp || SvTRUE(*cache_enabled_svp); 13 0 13
cache_enabled = !cache_enabled_svp || SvTRUE(*cache_enabled_svp); 13 0 13
333  
334 15 ▶ if (cache_enabled && cache_key_cb_svp && SvOK(*cache_key_cb_svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (cache_enabled && cache_key_cb_svp && SvOK(*cache_key_cb_svp)) { 13 0 13
if (cache_enabled && cache_key_cb_svp && SvOK(*cache_key_cb_svp)) { 13 0 13
if (cache_enabled && cache_key_cb_svp && SvOK(*cache_key_cb_svp)) { 2 11 13
335 2 dSP;
336 I32 count;
337 2 ENTER;
338 2 SAVETMPS;
339 2 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 2 0 2
340 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
341 2 ▶ XPUSHs(key);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(key); 0 2 2
342 2 PUTBACK;
343 2 count = call_sv(*cache_key_cb_svp, G_SCALAR | G_EVAL);
344 2 SPAGAIN;
345 2 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 2 0 2
if (SvTRUE(ERRSV)) { 0 2 2
346 0 ▶ if (error_out && !*error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && !*error_out) { 0 0 0
if (error_out && !*error_out) { 0 0 0
347 0 ▶ *error_out = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVsv(ERRSV); 0 0 0
348 }
349 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
350 2 ▶ } else if (count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (count == 1) { 2 0 2
351 2 cache_key_sv = newSVsv(POPs);
352 }
353 2 PUTBACK;
354 2 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2 0 2
355 2 LEAVE;
356 2 ▶ if (!cache_key_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!cache_key_sv) { 0 2 2
357 0 return NULL;
358 }
359 11 ▶ } else if (cache_enabled) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (cache_enabled) { 11 0 11
360 11 cache_key_sv = newSVsv(key);
361 }
362  
363 13 ▶ if (cache_enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if (cache_enabled) { 13 0 13
364 HE *cached_he;
365 13 promises_rv = hv_fetch(loader_hv, "_promises", 9, 0);
366 13 ▶ if (!promises_rv || !*promises_rv || !SvROK(*promises_rv)
Branch: 3 branches
BranchTrueFalseTotal
if (!promises_rv || !*promises_rv || !SvROK(*promises_rv) 13 0 13
if (!promises_rv || !*promises_rv || !SvROK(*promises_rv) 13 0 13
if (!promises_rv || !*promises_rv || !SvROK(*promises_rv) 13 0 13
367 13 ▶ || SvTYPE(SvRV(*promises_rv)) != SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*promises_rv)) != SVt_PVHV) { 0 13 13
368 0 SvREFCNT_dec(cache_key_sv);
369 0 ▶ if (error_out && !*error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && !*error_out) { 0 0 0
if (error_out && !*error_out) { 0 0 0
370 0 *error_out = newSVpvs("invalid DataLoader cache");
371 }
372 0 return NULL;
373 }
374 13 promises_hv = (HV *)SvRV(*promises_rv);
375 13 cached_he = hv_fetch_ent(promises_hv, cache_key_sv, 0, 0);
376 13 ▶ if (cached_he) {
Branch: 1 branch
BranchTrueFalseTotal
if (cached_he) { 2 11 13
377 2 SV *cached = newSVsv(HeVAL(cached_he));
378 2 SvREFCNT_dec(cache_key_sv);
379 2 return cached;
380 }
381 }
382  
383 11 queue_rv = hv_fetch(loader_hv, "_queue", 6, 0);
384 11 ▶ if (!queue_rv || !*queue_rv || !SvROK(*queue_rv)
Branch: 3 branches
BranchTrueFalseTotal
if (!queue_rv || !*queue_rv || !SvROK(*queue_rv) 11 0 11
if (!queue_rv || !*queue_rv || !SvROK(*queue_rv) 11 0 11
if (!queue_rv || !*queue_rv || !SvROK(*queue_rv) 11 0 11
385 11 ▶ || SvTYPE(SvRV(*queue_rv)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*queue_rv)) != SVt_PVAV) { 0 11 11
386 0 SvREFCNT_dec(cache_key_sv);
387 0 ▶ if (error_out && !*error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && !*error_out) { 0 0 0
if (error_out && !*error_out) { 0 0 0
388 0 *error_out = newSVpvs("invalid DataLoader storage");
389 }
390 0 return NULL;
391 }
392 11 queue_av = (AV *)SvRV(*queue_rv);
393 11 async_adapter_svp = hv_fetch(loader_hv, "_async_adapter", 14, 0);
394 11 ▶ ticket_sv = gql_runtime_vm_new_dataloader_ticket_sv(
Branch: 1 branch
BranchTrueFalseTotal
ticket_sv = gql_runtime_vm_new_dataloader_ticket_sv( 0 11 11
395 aTHX_ 0, &PL_sv_undef,
396 0 ▶ (async_adapter_svp && *async_adapter_svp)
Branch: 1 branch
BranchTrueFalseTotal
(async_adapter_svp && *async_adapter_svp) 0 0 0
397 ? *async_adapter_svp : &PL_sv_undef
398 );
399 11 entry_av = newAV();
400 11 av_push(entry_av, newSVsv(key));
401 11 av_push(entry_av, newSVsv(ticket_sv));
402 11 av_push(queue_av, newRV_noinc((SV *)entry_av));
403 11 ▶ if (cache_enabled) {
Branch: 1 branch
BranchTrueFalseTotal
if (cache_enabled) { 11 0 11
404 11 hv_store_ent(promises_hv, cache_key_sv, newSVsv(ticket_sv), 0);
405 11 SvREFCNT_dec(cache_key_sv);
406 }
407 11 return ticket_sv;
408 }
409  
410 /* Defined later (after gql_runtime_vm_xs_pending_callback/_reject_callback
411 * and their shared settle helpers exist) - it fast-paths the common case
412 * where callback is one of our own pending_callback_pair CVs. */
413 static void gql_runtime_vm_call_ticket_callback(pTHX_ SV *callback, SV *value);
414  
415 static void
416 3145 gql_runtime_vm_subscribe_dataloader_ticket(
417 pTHX_ SV *ticket, SV *resolve, SV *reject
418 )
419 {
420 3145 IV state = gql_runtime_vm_dataloader_ticket_state(aTHX_ ticket);
421 3145 ▶ if (state == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (state == 0) { 3128 17 3145
422 3128 AV *av = gql_runtime_vm_dataloader_ticket_av(aTHX_ ticket);
423 3128 SV **subscribers_rv = av_fetch(av, 2, 0);
424 AV *subscribers;
425 AV *pair;
426 3128 ▶ if (!subscribers_rv || !SvROK(*subscribers_rv)
Branch: 2 branches
BranchTrueFalseTotal
if (!subscribers_rv || !SvROK(*subscribers_rv) 3128 0 3128
if (!subscribers_rv || !SvROK(*subscribers_rv) 3128 0 3128
427 3128 ▶ || SvTYPE(SvRV(*subscribers_rv)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*subscribers_rv)) != SVt_PVAV) { 0 3128 3128
428 0 croak("invalid DataLoader ticket subscribers");
429 }
430 3128 subscribers = (AV *)SvRV(*subscribers_rv);
431 3128 pair = newAV();
432 3128 ▶ av_push(pair, newSVsv(resolve ? resolve : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_push(pair, newSVsv(resolve ? resolve : &PL_sv_undef)); 3128 0 3128
433 3128 ▶ av_push(pair, newSVsv(reject ? reject : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_push(pair, newSVsv(reject ? reject : &PL_sv_undef)); 3128 0 3128
434 3128 av_push(subscribers, newRV_noinc((SV *)pair));
435 3128 return;
436 }
437 17 ▶ if (state == 1 && resolve && SvOK(resolve)) {
Branch: 3 branches
BranchTrueFalseTotal
if (state == 1 && resolve && SvOK(resolve)) { 17 0 17
if (state == 1 && resolve && SvOK(resolve)) { 17 0 17
if (state == 1 && resolve && SvOK(resolve)) { 17 0 17
438 17 gql_runtime_vm_call_ticket_callback(
439 aTHX_ resolve, gql_runtime_vm_dataloader_ticket_value(aTHX_ ticket)
440 );
441 0 ▶ } else if (state == 2 && reject && SvOK(reject)) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (state == 2 && reject && SvOK(reject)) { 0 0 0
} else if (state == 2 && reject && SvOK(reject)) { 0 0 0
} else if (state == 2 && reject && SvOK(reject)) { 0 0 0
442 0 gql_runtime_vm_call_ticket_callback(
443 aTHX_ reject, gql_runtime_vm_dataloader_ticket_value(aTHX_ ticket)
444 );
445 }
446 }
447  
448 static void
449 3405 gql_runtime_vm_settle_dataloader_ticket(pTHX_ SV *ticket, IV state, SV *value)
450 {
451 3405 AV *av = gql_runtime_vm_dataloader_ticket_av(aTHX_ ticket);
452 SV **subscribers_rv;
453 AV *subscribers;
454 SSize_t i;
455 3405 ▶ if (gql_runtime_vm_dataloader_ticket_state(aTHX_ ticket) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_dataloader_ticket_state(aTHX_ ticket) != 0) { 1 3404 3405
456 1 return;
457 }
458 3404 subscribers_rv = av_fetch(av, 2, 0);
459 3404 ▶ if (!subscribers_rv || !SvROK(*subscribers_rv)
Branch: 2 branches
BranchTrueFalseTotal
if (!subscribers_rv || !SvROK(*subscribers_rv) 3404 0 3404
if (!subscribers_rv || !SvROK(*subscribers_rv) 3404 0 3404
460 3404 ▶ || SvTYPE(SvRV(*subscribers_rv)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*subscribers_rv)) != SVt_PVAV) { 0 3404 3404
461 0 croak("invalid DataLoader ticket subscribers");
462 }
463 3404 subscribers = (AV *)SvRV(*subscribers_rv);
464 3404 SvREFCNT_inc_simple_void_NN((SV *)subscribers);
465 3404 av_store(av, 0, newSViv(state));
466 3404 ▶ av_store(av, 1, newSVsv(value ? value : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_store(av, 1, newSVsv(value ? value : &PL_sv_undef)); 3404 0 3404
467 3404 av_store(av, 2, newRV_noinc((SV *)newAV()));
468 6523 ▶ for (i = 0; i <= av_top_index(subscribers); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_top_index(subscribers); i++) { 3119 3404 6523
469 3119 SV **pair_rv = av_fetch(subscribers, i, 0);
470 AV *pair;
471 SV **callback;
472 3119 ▶ if (!pair_rv || !SvROK(*pair_rv) || SvTYPE(SvRV(*pair_rv)) != SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!pair_rv || !SvROK(*pair_rv) || SvTYPE(SvRV(*pair_rv)) != SVt_PVAV) { 3119 0 3119
if (!pair_rv || !SvROK(*pair_rv) || SvTYPE(SvRV(*pair_rv)) != SVt_PVAV) { 3119 0 3119
if (!pair_rv || !SvROK(*pair_rv) || SvTYPE(SvRV(*pair_rv)) != SVt_PVAV) { 0 3119 3119
473 0 continue;
474 }
475 3119 pair = (AV *)SvRV(*pair_rv);
476 3119 callback = av_fetch(pair, state == 1 ? 0 : 1, 0);
477 3119 ▶ if (callback && SvOK(*callback)) {
Branch: 2 branches
BranchTrueFalseTotal
if (callback && SvOK(*callback)) { 3119 0 3119
if (callback && SvOK(*callback)) { 3119 0 3119
478 3119 gql_runtime_vm_call_ticket_callback(aTHX_ *callback, value);
479 }
480 }
481 3404 SvREFCNT_dec((SV *)subscribers);
482 }
483  
484 static int
485 1828 gql_runtime_vm_sv_is_pending_async_value(
486 pTHX_ const gql_runtime_vm_async_adapter_t *adapter, SV *value
487 )
488 {
489 1828 return gql_runtime_vm_sv_is_adapter_promise(aTHX_ adapter, value)
490 3594 ▶ || (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ value)
Branch: 2 branches
BranchTrueFalseTotal
|| (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ value) 1766 62 1828
|| (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ value) 1766 0 1766
491 1766 ▶ && gql_runtime_vm_dataloader_ticket_state(aTHX_ value) == 0);
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_dataloader_ticket_state(aTHX_ value) == 0); 1766 0 1766
492 }
493  
494 static SV *gql_runtime_vm_global_wrap_object_outcome_callback_sv = NULL;
495 static SV *gql_runtime_vm_global_wrap_list_outcome_callback_sv = NULL;
496 static SV *gql_runtime_vm_global_promise_xs_flatten_all_callback_sv = NULL;
497  
498 static SV *
499 2175 gql_runtime_vm_empty_args_sv(pTHX)
500 {
501 2175 ▶ if (!gql_runtime_vm_global_empty_args_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_global_empty_args_sv) { 0 2175 2175
502 0 gql_runtime_vm_global_empty_args_sv = newRV_noinc((SV *)newHV());
503 }
504 2175 return SvREFCNT_inc_simple_NN(gql_runtime_vm_global_empty_args_sv);
505 }
506  
507 static SV *
508 0 gql_runtime_vm_wrap_object_outcome_callback_sv(pTHX)
509 {
510 0 ▶ if (gql_runtime_vm_global_wrap_object_outcome_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_global_wrap_object_outcome_callback_sv) { 0 0 0
511 0 return SvREFCNT_inc_simple_NN(gql_runtime_vm_global_wrap_object_outcome_callback_sv);
512 }
513 0 return gql_runtime_vm_named_coderef_sv(
514 aTHX_ "GraphQL::Houtou::XS::VM::wrap_object_outcome_callback_xs"
515 );
516 }
517  
518 static SV *
519 0 gql_runtime_vm_identity_callback_sv(pTHX)
520 {
521 0 ▶ if (gql_runtime_vm_global_identity_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_global_identity_callback_sv) { 0 0 0
522 0 return SvREFCNT_inc_simple_NN(gql_runtime_vm_global_identity_callback_sv);
523 }
524 0 return gql_runtime_vm_named_coderef_sv(
525 aTHX_ "GraphQL::Houtou::XS::VM::identity_callback_xs"
526 );
527 }
528  
529 static SV *
530 0 gql_runtime_vm_promise_xs_flatten_all_callback_sv(pTHX)
531 {
532 0 ▶ if (gql_runtime_vm_global_promise_xs_flatten_all_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_global_promise_xs_flatten_all_callback_sv) { 0 0 0
533 0 return SvREFCNT_inc_simple_NN(gql_runtime_vm_global_promise_xs_flatten_all_callback_sv);
534 }
535 0 return gql_runtime_vm_named_coderef_sv(
536 aTHX_ "GraphQL::Houtou::XS::VM::promise_xs_flatten_all_callback_xs"
537 );
538 }
539  
540 static HV *
541 18993 gql_runtime_vm_expect_hashref(pTHX_ SV *sv, const char *what)
542 {
543 18993 ▶ if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) { 18993 0 18993
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) { 18993 0 18993
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) { 18993 0 18993
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) { 0 18993 18993
544 0 croak("%s must be a hash reference", what);
545 }
546 18993 return (HV *)SvRV(sv);
547 }
548  
549 static AV *
550 726 gql_runtime_vm_expect_arrayref(pTHX_ SV *sv, const char *what)
551 {
552 726 ▶ if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) { 726 0 726
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) { 726 0 726
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) { 726 0 726
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) { 0 726 726
553 0 croak("%s must be an array reference", what);
554 }
555 726 return (AV *)SvRV(sv);
556 }
557  
558 static SV *
559 16835 gql_runtime_vm_new_handle_sv(pTHX_ const char *pkg, void *ptr)
560 {
561 16835 SV *inner = newSVuv(PTR2UV(ptr));
562 16835 SV *rv = newRV_noinc(inner);
563 16835 return sv_bless(rv, gv_stashpv(pkg, GV_ADD));
564 }
565  
566 static SV *
567 1562 gql_runtime_vm_exec_state_materialize_response_sv(
568 pTHX_ gql_runtime_vm_exec_state_handle_t *s,
569 SV *data_sv
570 )
571 {
572 1562 HV *response_hv = newHV();
573 1562 ▶ hv_store(response_hv, "data", 4, data_sv ? newSVsv(data_sv) : newSV(0), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(response_hv, "data", 4, data_sv ? newSVsv(data_sv) : newSV(0), 0); 1562 0 1562
574 1562 ▶ if (s && s->writer && s->writer->error_record_count > 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (s && s->writer && s->writer->error_record_count > 0) { 1562 0 1562
if (s && s->writer && s->writer->error_record_count > 0) { 1562 0 1562
if (s && s->writer && s->writer->error_record_count > 0) { 22 1540 1562
575 22 hv_store(
576 response_hv,
577 "errors",
578 6,
579 gql_runtime_vm_writer_materialize_errors_sv(aTHX_ s->writer),
580 0
581 );
582 }
583 1562 return newRV_noinc((SV *)response_hv);
584 }
585  
586 static SV *
587 495 gql_runtime_vm_fast_response_sv(
588 pTHX_
589 SV *data_sv,
590 const gql_runtime_vm_writer_t *writer
591 )
592 {
593 495 HV *response_hv = newHV();
594 495 ▶ hv_store(response_hv, "data", 4, data_sv ? data_sv : newSV(0), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(response_hv, "data", 4, data_sv ? data_sv : newSV(0), 0); 5 490 495
595 495 ▶ if (writer && writer->error_record_count > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (writer && writer->error_record_count > 0) { 495 0 495
if (writer && writer->error_record_count > 0) { 93 402 495
596 93 hv_store(
597 response_hv,
598 "errors",
599 6,
600 gql_runtime_vm_writer_materialize_errors_sv(aTHX_ writer),
601 0
602 );
603 }
604 495 return newRV_noinc((SV *)response_hv);
605 }
606  
607 typedef struct {
608 UV refcount;
609 U8 arming;
610 SV *sync_response_sv;
611 /* Set only on the DataLoader-Ticket branch: a Ticket subscription never
612 * fires synchronously for a still-pending ticket (unlike Promise::XS
613 * then()), so the request-level result is always this deferred's
614 * promise, resolved later by the settle callback. NULL on the
615 * Promise::XS branch. */
616 SV *deferred_sv;
617 } gql_runtime_vm_fast_root_continuation_shared_t;
618  
619 typedef struct {
620 UV refcount;
621 gql_runtime_vm_block_frame_t *frame;
622 gql_runtime_vm_writer_t *writer;
623 SV *state_sv;
624 } gql_runtime_vm_pending_merge_t;
625  
626 typedef struct {
627 SV *state_sv;
628 gql_runtime_vm_block_frame_t *frame;
629 IV entry_index;
630 /* The resolve and reject arms of one then() share this ctx; the pair is
631 * pooled for reuse once either arm fires (a settled promise never fires
632 * the other). cv_refcnt counts the CVs still holding the ctx; the CV
633 * pointers are borrowed - the CVs' own refcounts govern their lifetime. */
634 SV *resolve_cv;
635 SV *reject_cv;
636 U8 cv_refcnt;
637 } gql_runtime_vm_pending_callback_ctx_t;
638  
639 typedef struct {
640 gql_runtime_vm_list_pending_t *pending;
641 SV *state_sv;
642 IV index;
643 } gql_runtime_vm_list_pending_callback_ctx_t;
644  
645  
646 typedef struct {
647 gql_runtime_vm_path_frame_t *path_frame;
648 } gql_runtime_vm_error_callback_ctx_t;
649  
650 typedef struct {
651 SV *state_sv;
652 gql_runtime_vm_path_frame_t *path_frame;
653 IV child_block_index;
654 /* For items of an abstract-typed list the member block is picked per
655 * item once it settles; both pointers are borrowed from the execution
656 * plan, which outlives the request. NULL for plain object lists. */
657 const gql_runtime_vm_native_op_t *op;
658 const gql_runtime_vm_native_slot_t *slot;
659 } gql_runtime_vm_list_item_child_ctx_t;
660  
661 typedef struct {
662 gql_runtime_vm_pending_merge_t *merge;
663 } gql_runtime_vm_finalize_callback_ctx_t;
664  
665 typedef struct {
666 SV *derived_ticket;
667 SV *callback_sv;
668 U8 reject_arm;
669 } gql_runtime_vm_ticket_chain_ctx_t;
670  
671 typedef struct {
672 SV *runtime_sv;
673 SV *program_sv;
674 SV *runtime_schema_sv;
675 SV *root_value_sv;
676 SV *context_sv;
677 SV *variables_sv;
678 gql_runtime_vm_native_runtime_t *runtime;
679 gql_runtime_vm_native_bundle_t *bundle;
680 IV block_index;
681 IV op_index;
682 gql_runtime_vm_fast_root_continuation_shared_t *shared;
683 /* The resolve and reject arms share this ctx, distinguished by which XS
684 * entry point (gql_runtime_vm_xs_fast_root_continuation_resolve_callback
685 * vs. ..._reject_callback) their CV was created with, not by a stored
686 * flag - mirroring gql_runtime_vm_pending_callback_ctx_t. cv_refcnt
687 * counts the two CVs still holding the ctx. */
688 U8 cv_refcnt;
689 } gql_runtime_vm_fast_root_continuation_ctx_t;
690  
691 /* Item 1 (Phase 9): captures a generic-executor response promise's eventual
692 * settlement into plain fields instead of a Perl _settle_result closure -
693 * see gql_runtime_vm_drive_promise_with_on_stall_sv. settled: 0 = pending,
694 * 1 = resolved, 2 = rejected (value holds the resolved value or rejection
695 * reason either way). cv_refcnt is shared three ways - the resolve CV, the
696 * reject CV, and the drive loop's own read of ctx after settlement - not
697 * just the CV pair (see gql_runtime_vm_settle_capture_ctx_release's doc
698 * comment for why the drive loop needs its own share here, unlike
699 * gql_runtime_vm_pending_callback_ctx_t). */
700 typedef struct {
701 SV *value;
702 U8 settled;
703 U8 cv_refcnt;
704 } gql_runtime_vm_settle_capture_ctx_t;
705  
706  
707 typedef struct {
708 SV *state_sv;
709 IV block_index;
710 IV next_op_index;
711 SV *source_sv;
712 gql_runtime_vm_path_frame_t *base_path_ptr;
713 gql_runtime_vm_block_frame_t *frame;
714 gql_runtime_vm_field_frame_t *saved_field_frame;
715 gql_runtime_vm_cursor_t cursor_snapshot;
716 } gql_runtime_vm_serial_mutation_ctx_t;
717  
718 static SV *gql_runtime_vm_exec_state_execute_block_sync_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, SV *block, IV block_index, SV *source, SV *base_path);
719 static gql_runtime_vm_outcome_t *gql_runtime_vm_exec_state_execute_current_op_sync_now(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s);
720 static SV *gql_runtime_vm_state_type_by_name_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s, SV *type_name_sv);
721 static gql_runtime_vm_native_runtime_t *gql_runtime_vm_native_runtime_from_runtime_schema_sv(pTHX_ SV *runtime_schema);
722 static gql_runtime_vm_native_runtime_t *gql_runtime_vm_exec_state_native_runtime(pTHX_ gql_runtime_vm_exec_state_handle_t *s);
723 static SV *gql_runtime_vm_exec_state_execute_block_async_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, IV block_index, SV *source, SV *base_path);
724 static SV *gql_runtime_vm_exec_state_execute_block_async_path_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, IV block_index, SV *source, gql_runtime_vm_path_frame_t *base_path_ptr, U8 return_pending_handle);
725 static SV *gql_runtime_vm_exec_state_resolve_current_value_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, SV *source_sv, gql_runtime_vm_path_frame_t *path_frame, SV **error_out);
726 static SV *gql_runtime_vm_exec_state_complete_async_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_path_frame_t *path_frame, IV block_index, IV slot_index, IV op_index, SV *resolved_sv, gql_runtime_vm_outcome_t **outcome_out);
727 static SV *gql_runtime_vm_exec_state_complete_current_native_async_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_path_frame_t *path_frame, const gql_runtime_vm_native_op_t *op, const gql_runtime_vm_native_slot_t *slot, SV *resolved_sv, gql_runtime_vm_outcome_t **outcome_out);
728 static SV *gql_runtime_vm_exec_state_execute_current_op_async_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_outcome_t **outcome_out);
729 static SV *gql_runtime_vm_apply_runtime_directives_nonfatal(pTHX_ gql_runtime_vm_exec_state_t *state, SV *source, SV *resolved, SV **error_out);
730 static CV *gql_runtime_vm_directive_runtime_apply_cv(pTHX);
731 static CV *gql_runtime_vm_directive_runtime_materialize_cv(pTHX);
732 static CV *gql_runtime_vm_directive_runtime_program_materialize_cv(pTHX);
733 static SV *gql_runtime_vm_new_lazy_info_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, SV *path_frame);
734 static SV *gql_runtime_vm_new_lazy_info_for_path_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_path_frame_t *path_frame);
735 static SV *gql_runtime_vm_new_outcome_handle_sv(pTHX_ U8 kind_code, SV *value, SV *error_records);
736 static SV *gql_runtime_vm_lookup_type_object_by_name_sv(pTHX_ SV *runtime_schema, const char *type_name);
737 static SV *gql_runtime_vm_lookup_slot_type_object_sv(pTHX_ const gql_runtime_vm_native_runtime_t *runtime, SV *runtime_schema, const gql_runtime_vm_native_slot_t *slot);
738 static SV *gql_runtime_vm_direct_slot_type_object_sv(const gql_runtime_vm_native_runtime_t *runtime, const gql_runtime_vm_native_slot_t *slot);
739 static SV *gql_runtime_vm_state_current_return_type_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s, SV *op_sv, SV *slot_sv);
740 static SV *gql_runtime_vm_state_return_type_for_slot_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s, const gql_runtime_vm_native_slot_t *slot);
741 static SV *gql_runtime_vm_exec_state_resolve_runtime_type_for_slot_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, const gql_runtime_vm_native_slot_t *slot, SV *resolved_sv, gql_runtime_vm_path_frame_t *path_frame, SV **error_out);
742 static SV *gql_runtime_vm_build_current_args_sv(pTHX_ gql_runtime_vm_exec_state_t *state);
743 static SV *gql_runtime_vm_build_current_one_arg_sv(pTHX_ gql_runtime_vm_exec_state_t *state);
744 static IV gql_runtime_vm_find_abstract_child_block_index(const gql_runtime_vm_native_op_t *op, const char *type_name);
745 static const char *gql_runtime_vm_type_name_from_sv(pTHX_ SV *type_sv);
746 static SV *gql_runtime_vm_snapshot_scalarish_value_sv(pTHX_ SV *value);
747 static gql_runtime_vm_path_frame_t *gql_runtime_vm_new_result_path_frame(pTHX_ gql_runtime_vm_path_frame_t *parent, const gql_runtime_vm_native_slot_t *slot);
748 static SV *gql_runtime_vm_new_error_callback_sv(pTHX_ gql_runtime_vm_path_frame_t *path_frame);
749 static SV *gql_runtime_vm_new_list_item_child_callback_sv(pTHX_ SV *state_sv, gql_runtime_vm_path_frame_t *path_frame, IV child_block_index, const gql_runtime_vm_native_op_t *op, const gql_runtime_vm_native_slot_t *slot);
750 static IV gql_runtime_vm_abstract_list_item_block_index(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, const gql_runtime_vm_native_op_t *op, const gql_runtime_vm_native_slot_t *slot, SV *item_sv, gql_runtime_vm_path_frame_t *item_path, SV **error_out);
751 static XS(gql_runtime_vm_xs_list_item_child_callback);
752 static gql_runtime_vm_pending_callback_ctx_t *gql_runtime_vm_new_pending_callback_pair(pTHX_ SV *state_sv, gql_runtime_vm_block_frame_t *frame, IV entry_index, SV **resolve_rv_out, SV **reject_rv_out);
753 static SV *gql_runtime_vm_new_finalize_callback_sv(pTHX_ gql_runtime_vm_pending_merge_t *merge);
754 static SV *gql_runtime_vm_call_then_promise_xs_sv(pTHX_ SV *promise_sv, SV *callback_sv, SV *error_callback_sv, gql_runtime_vm_path_frame_t *path_frame);
755 static SV *gql_runtime_vm_call_all_promise_xs_sv(pTHX_ AV *values_av, gql_runtime_vm_path_frame_t *path_frame);
756 static SV *gql_runtime_vm_call_then_adapter_sv(pTHX_ gql_runtime_vm_async_adapter_t *adapter, SV *promise_sv, SV *callback_sv, SV *error_callback_sv, gql_runtime_vm_path_frame_t *path_frame);
757 static SV *gql_runtime_vm_call_all_adapter_sv(pTHX_ gql_runtime_vm_async_adapter_t *adapter, AV *values_av, gql_runtime_vm_path_frame_t *path_frame);
758 static SV *gql_runtime_vm_call_callback_scalar_sv(pTHX_ SV *callback_sv, SV *arg_sv, gql_runtime_vm_path_frame_t *path_frame);
759 static SV *gql_runtime_vm_call_then_promise_for_state_sv(pTHX_ const gql_runtime_vm_exec_state_handle_t *s, SV *promise_sv, SV *callback_sv, SV *error_callback_sv, gql_runtime_vm_path_frame_t *path_frame);
760 static IV gql_runtime_vm_select_abstract_child_block_fast(pTHX_ gql_runtime_vm_exec_state_t *state, SV *value, SV **error_out);
761 static SV *gql_runtime_vm_response_json_from_native_sv(pTHX_ const gql_runtime_vm_writer_t *writer, const gql_runtime_vm_native_value_t *value);
762 static SV *gql_runtime_vm_response_json_from_data_sv(pTHX_ const gql_runtime_vm_writer_t *writer, SV *data_sv);
763 static SV *gql_runtime_vm_call_cb3_nonfatal(pTHX_ SV *cb, SV *arg0, SV *arg1, SV *arg2, SV **error_out);
764 static SV *gql_runtime_vm_call_accessor_nonfatal(pTHX_ SV *source, const gql_runtime_vm_native_slot_t *slot, SV **error_out);
765 static CV *gql_runtime_vm_accessor_method_cv(SV *source, const gql_runtime_vm_native_slot_t *slot);
766 static int gql_runtime_vm_slot_uses_native_fast_abi(const gql_runtime_vm_native_slot_t *slot);
767 static int gql_runtime_vm_slot_uses_native_no_args_abi(const gql_runtime_vm_native_slot_t *slot);
768 static int gql_runtime_vm_slot_uses_native_one_arg_abi(const gql_runtime_vm_native_slot_t *slot);
769 static int gql_runtime_vm_slot_uses_explicit_generic_fast_abi(const gql_runtime_vm_native_slot_t *slot);
770 static SV *gql_runtime_vm_slot_resolver_sv(const gql_runtime_vm_native_runtime_t *runtime, const gql_runtime_vm_native_slot_t *slot);
771 static SV *gql_runtime_vm_execute_block_fast_sv(pTHX_ gql_runtime_vm_exec_state_t *state, IV block_index, SV *source);
772 static void gql_runtime_vm_execute_block_fast_multi_sv(pTHX_ gql_runtime_vm_exec_state_t *state, IV block_index, SV *source, gql_runtime_vm_path_frame_t *parent_path_frame, SV **resolved_values, gql_runtime_vm_block_frame_t **frame_out, SV **state_sv_out, U8 *self_nulled_out);
773 static gql_runtime_vm_exec_state_handle_t *gql_runtime_vm_ensure_fast_lane_state_sv(pTHX_ gql_runtime_vm_exec_state_t *state, SV **state_sv_out);
774 static SV *gql_runtime_vm_execute_safe_child_block_fast_sv(pTHX_ gql_runtime_vm_exec_state_t *state, IV item_block_index, SV *item, gql_runtime_vm_path_frame_t *item_path_frame, U8 want_promise);
775 static SV *gql_runtime_vm_try_execute_fast_root_continuation_sv(
776 pTHX_ SV *runtime_sv, SV *program_sv,
777 gql_runtime_vm_native_runtime_t *runtime,
778 gql_runtime_vm_native_program_t *program,
779 SV *runtime_schema, SV *root_value, SV *context_value, SV *variables,
780 U8 json_mode, SV *on_stall_sv, U8 *handled_out
781 );
782 static SV *gql_runtime_vm_try_execute_plain_hash_block_fast_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s, IV block_index, SV *source, gql_runtime_vm_path_frame_t *path_frame);
783 static SV *gql_runtime_vm_fast_lane_guard_promise_sv(pTHX_ gql_runtime_vm_exec_state_t *state, SV *resolved, SV **error_out);
784  
785 /* Shared by the mid-lane detection sites and the top-level croak so the
786 * deferred error keeps the exact wording tests and users rely on. */
787 #define GQL_RUNTIME_VM_FAST_LANE_PROMISE_ERROR \
788 "a resolver returned a pending Promise::XS promise or DataLoader ticket in the synchronous fast lane; build the runtime with async => 1 (or pass on_stall) so requests start on the async lane"
789 static SV *gql_runtime_vm_promise_xs_new_deferred_sv(pTHX);
790 static SV *gql_runtime_vm_promise_xs_deferred_promise_sv(pTHX_ SV *deferred_sv);
791 static void gql_runtime_vm_promise_xs_deferred_resolve_sv(pTHX_ SV *deferred_sv, SV *value_sv);
792 static SV *gql_runtime_vm_adapter_new_deferred_sv(pTHX_ gql_runtime_vm_async_adapter_t *adapter);
793 static SV *gql_runtime_vm_adapter_deferred_promise_sv(pTHX_ gql_runtime_vm_async_adapter_t *adapter, SV *deferred_sv);
794 static void gql_runtime_vm_adapter_deferred_resolve_sv(pTHX_ gql_runtime_vm_async_adapter_t *adapter, SV *deferred_sv, SV *value_sv);
795 static void gql_runtime_vm_async_scheduler_enqueue_frame(gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_block_frame_t *frame);
796 static void gql_runtime_vm_async_scheduler_arm_frame(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_block_frame_t *frame);
797 static void gql_runtime_vm_async_scheduler_drain(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s);
798 static void gql_runtime_vm_record_nonnull_violation(pTHX_ gql_runtime_vm_writer_t *writer, const char *parent_type_name, const char *field_name, gql_runtime_vm_path_frame_t *path_frame);
799 static void gql_runtime_vm_async_scheduler_resolve_frame(pTHX_ gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_block_frame_t *frame);
800 static SV *gql_runtime_vm_exec_state_execute_block_serial_mutation_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, IV block_index, SV *source, gql_runtime_vm_path_frame_t *base_path_ptr);
801 static void gql_runtime_vm_execute_serial_mutation_steps(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_serial_mutation_ctx_t *ctx, U8 *all_sync_out, SV **sync_result_out);
802 static SV *gql_runtime_vm_new_serial_mutation_step_callback_sv(pTHX_ gql_runtime_vm_serial_mutation_ctx_t *ctx);
803 static XS(gql_runtime_vm_xs_serial_mutation_step_callback);
804 static void gql_runtime_vm_push_pending_block_frame(pTHX_ gql_runtime_vm_block_frame_t *frame, const char *result_name_pv, STRLEN result_name_len, gql_runtime_vm_path_frame_t *path_frame, gql_runtime_vm_block_frame_t *child_frame, IV block_index, IV slot_index, IV op_index);
805 static void gql_runtime_vm_push_pending_list_pending(pTHX_ gql_runtime_vm_block_frame_t *frame, const char *result_name_pv, STRLEN result_name_len, gql_runtime_vm_path_frame_t *path_frame, gql_runtime_vm_list_pending_t *list_pending, IV block_index, IV slot_index, IV op_index);
806 static void gql_runtime_vm_native_list_store_at(pTHX_ gql_runtime_vm_native_value_t *value, IV index, gql_runtime_vm_native_value_t *child);
807 static gql_runtime_vm_native_value_t *gql_runtime_vm_native_value_from_list_pending_sv(pTHX_ SV *value_sv);
808 static gql_runtime_vm_list_pending_t *gql_runtime_vm_expect_list_pending(pTHX_ SV *self);
809 static SV *gql_runtime_vm_wrap_list_pending_sv(pTHX_ gql_runtime_vm_list_pending_t *pending);
810 static int gql_runtime_vm_is_list_pending_value_sv(SV *value);
811 static SV *gql_runtime_vm_list_pending_handle_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, AV *values_av, gql_runtime_vm_path_frame_t *path_frame);
812 static XS(gql_runtime_vm_xs_pending_callback);
813 static XS(gql_runtime_vm_xs_pending_reject_callback);
814 static XS(gql_runtime_vm_xs_list_pending_callback);
815 static XS(gql_runtime_vm_xs_error_callback);
816 static XS(gql_runtime_vm_xs_finalize_callback);
817 static XS(gql_runtime_vm_xs_fast_root_continuation_resolve_callback);
818 static XS(gql_runtime_vm_xs_fast_root_continuation_reject_callback);
819  
820 static void
821 1600 gql_runtime_vm_cursor_incref(gql_runtime_vm_cursor_t *cursor)
822 {
823 1600 ▶ if (cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (cursor) { 1600 0 1600
824 1600 cursor->refcount++;
825 }
826 1600 }
827  
828 static void
829 3200 gql_runtime_vm_cursor_decref(pTHX_ gql_runtime_vm_cursor_t *cursor)
830 {
831 3200 ▶ if (!cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (!cursor) { 0 3200 3200
832 0 return;
833 }
834 3200 ▶ if (--cursor->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--cursor->refcount > 0) { 1600 1600 3200
835 1600 return;
836 }
837 1600 Safefree(cursor);
838 }
839  
840 static void
841 2919 gql_runtime_vm_free_field_frame(pTHX_ gql_runtime_vm_field_frame_t *frame)
842 {
843 2919 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 1600 1319 2919
844 1600 return;
845 }
846 1319 ▶ if (--frame->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--frame->refcount > 0) { 0 1319 1319
847 0 return;
848 }
849 1319 SvREFCNT_dec(frame->source);
850 1319 gql_runtime_vm_path_frame_decref(frame->path_frame);
851 1319 ▶ if (frame->resolved_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->resolved_value) { 0 1319 1319
852 0 SvREFCNT_dec(frame->resolved_value);
853 }
854 1319 gql_runtime_vm_outcome_decref(aTHX_ frame->outcome);
855 1319 ▶ if (frame->storage_is_stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->storage_is_stack) { 1319 0 1319
856 1319 Zero(frame, 1, gql_runtime_vm_field_frame_t);
857 1319 return;
858 }
859 0 Safefree(frame);
860 }
861  
862 static void
863 13584 gql_runtime_vm_free_block_frame(pTHX_ gql_runtime_vm_block_frame_t *frame)
864 {
865 13584 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 13584 13584
866 0 return;
867 }
868 13584 ▶ if (--frame->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--frame->refcount > 0) { 9503 4081 13584
869 9503 return;
870 }
871 4081 gql_runtime_vm_block_frame_live_count--;
872 4081 gql_runtime_vm_native_value_destroy(aTHX_ frame->values_value);
873 4081 gql_runtime_vm_block_frame_clear_pending(aTHX_ frame);
874 4081 ▶ if (frame->deferred_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->deferred_sv) { 4 4077 4081
875 4 SvREFCNT_dec(frame->deferred_sv);
876 }
877 4081 ▶ if (frame->promise_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->promise_sv) { 4 4077 4081
878 4 SvREFCNT_dec(frame->promise_sv);
879 }
880 4081 ▶ if (frame->parent_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->parent_frame) { 1269 2812 4081
881 1269 gql_runtime_vm_free_block_frame(aTHX_ frame->parent_frame);
882 }
883 4081 ▶ if (gql_runtime_vm_block_frame_pool_count < GQL_RUNTIME_VM_BLOCK_FRAME_POOL_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_block_frame_pool_count < GQL_RUNTIME_VM_BLOCK_FRAME_POOL_MAX) { 4081 0 4081
884 4081 frame->parent_frame = gql_runtime_vm_block_frame_pool_head;
885 4081 gql_runtime_vm_block_frame_pool_head = frame;
886 4081 gql_runtime_vm_block_frame_pool_count++;
887 4081 return;
888 }
889 0 Safefree(frame->pending_entries);
890 0 Safefree(frame);
891 }
892  
893 static void
894 1600 gql_runtime_vm_writer_incref(gql_runtime_vm_writer_t *writer)
895 {
896 1600 ▶ if (writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (writer) { 1600 0 1600
897 1600 writer->refcount++;
898 }
899 1600 }
900  
901 static void
902 3380 gql_runtime_vm_writer_decref(pTHX_ gql_runtime_vm_writer_t *writer)
903 {
904 3380 ▶ if (!writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (!writer) { 0 3380 3380
905 0 return;
906 }
907 3380 ▶ if (--writer->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--writer->refcount > 0) { 1600 1780 3380
908 1600 return;
909 }
910 1845 ▶ while (writer->error_record_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (writer->error_record_count > 0) { 65 1780 1845
911 65 gql_runtime_vm_error_record_decref(aTHX_ writer->error_records[--writer->error_record_count]);
912 }
913 1780 Safefree(writer->error_records);
914 1780 Safefree(writer);
915 }
916  
917 static void
918 0 gql_runtime_vm_pending_merge_incref(gql_runtime_vm_pending_merge_t *merge)
919 {
920 0 ▶ if (merge) {
Branch: 1 branch
BranchTrueFalseTotal
if (merge) { 0 0 0
921 0 merge->refcount++;
922 }
923 0 }
924  
925 static void
926 2805 gql_runtime_vm_list_pending_incref(gql_runtime_vm_list_pending_t *pending)
927 {
928 2805 ▶ if (pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (pending) { 2805 0 2805
929 2805 pending->refcount++;
930 }
931 2805 }
932  
933 static void
934 0 gql_runtime_vm_pending_merge_decref(pTHX_ gql_runtime_vm_pending_merge_t *merge)
935 {
936 0 ▶ if (!merge) {
Branch: 1 branch
BranchTrueFalseTotal
if (!merge) { 0 0 0
937 0 return;
938 }
939 0 ▶ if (--merge->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--merge->refcount > 0) { 0 0 0
940 0 return;
941 }
942 0 gql_runtime_vm_free_block_frame(aTHX_ merge->frame);
943 0 gql_runtime_vm_writer_decref(aTHX_ merge->writer);
944 0 ▶ if (merge->state_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (merge->state_sv) { 0 0 0
945 0 SvREFCNT_dec(merge->state_sv);
946 }
947 0 Safefree(merge);
948 }
949  
950 static void
951 3453 gql_runtime_vm_list_pending_decref(pTHX_ gql_runtime_vm_list_pending_t *pending)
952 {
953 3453 ▶ if (!pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (!pending) { 0 3453 3453
954 0 return;
955 }
956 3453 ▶ if (--pending->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--pending->refcount > 0) { 2805 648 3453
957 2805 return;
958 }
959 648 ▶ if (pending->owner_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (pending->owner_frame) { 648 0 648
960 648 gql_runtime_vm_free_block_frame(aTHX_ pending->owner_frame);
961 }
962 648 ▶ if (pending->values_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (pending->values_value) { 2 646 648
963 2 gql_runtime_vm_native_value_destroy(aTHX_ pending->values_value);
964 }
965 /* Every entry here should already be NULL by the time refcount reaches
966 * 0 (a still-linked child frame holds its own ref to pending, so
967 * pending could not have reached 0 refcount while one remains linked -
968 * see gql_runtime_vm_list_pending_link_child_frame/resolve_frame's
969 * parent_list_pending branch/cancel_frame_tree's LIST_PENDING_PTR
970 * recursion, all of which clear the slot before releasing their ref).
971 * Only the array itself needs freeing here. */
972 648 Safefree(pending->pending_child_frames);
973 648 Safefree(pending);
974 }
975  
976 static int
977 38 gql_runtime_vm_pending_callback_ctx_free(pTHX_ SV *sv, MAGIC *mg)
978 {
979 38 ▶ gql_runtime_vm_pending_callback_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_pending_callback_ctx_t *ctx = mg && mg->mg_ptr 38 0 38
980 ? INT2PTR(gql_runtime_vm_pending_callback_ctx_t *, mg->mg_ptr)
981 76 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 38 0 38
982 38 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 38 0 38
983 /* The ctx is shared by the pair's two CVs; members go with the last
984 * one (a recycle may have dropped them already - the fields are
985 * NULLed then). */
986 38 ▶ if (ctx->cv_refcnt > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->cv_refcnt > 0) { 38 0 38
987 38 ctx->cv_refcnt--;
988 }
989 38 ▶ if (ctx->cv_refcnt == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->cv_refcnt == 0) { 19 19 38
990 19 ▶ if (ctx->state_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state_sv) { 2 17 19
991 2 SvREFCNT_dec(ctx->state_sv);
992 }
993 19 ▶ if (ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { 2 17 19
994 2 gql_runtime_vm_free_block_frame(aTHX_ ctx->frame);
995 }
996 19 Safefree(ctx);
997 }
998 38 mg->mg_ptr = NULL;
999 }
1000 38 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 38 0 38
if (sv && SvTYPE(sv) == SVt_PVCV) { 38 0 38
1001 38 CvXSUBANY((CV *)sv).any_ptr = NULL;
1002 }
1003 38 return 0;
1004 }
1005  
1006 static int
1007 655 gql_runtime_vm_list_pending_callback_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1008 {
1009 655 ▶ gql_runtime_vm_list_pending_callback_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_list_pending_callback_ctx_t *ctx = mg && mg->mg_ptr 655 0 655
1010 ? INT2PTR(gql_runtime_vm_list_pending_callback_ctx_t *, mg->mg_ptr)
1011 1310 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 655 0 655
1012 655 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 655 0 655
1013 655 SvREFCNT_dec(ctx->state_sv);
1014 655 gql_runtime_vm_list_pending_decref(aTHX_ ctx->pending);
1015 655 Safefree(ctx);
1016 655 mg->mg_ptr = NULL;
1017 }
1018 655 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 655 0 655
if (sv && SvTYPE(sv) == SVt_PVCV) { 655 0 655
1019 655 CvXSUBANY((CV *)sv).any_ptr = NULL;
1020 }
1021 655 return 0;
1022 }
1023  
1024 /* Shared by the resolve/reject CVs' magic-free (below) and the drive loop
1025 * itself (gql_runtime_vm_drive_promise_with_on_stall_sv), which holds its
1026 * own share of cv_refcnt precisely because Promise::XS releases both
1027 * stored callbacks together as soon as one of them fires (confirmed via
1028 * ASan: without this third share the ctx was freed mid-settle, inside the
1029 * nested call_sv that fired the callback, while the drive loop's own
1030 * ctx->settled/ctx->value read a few frames up was still pending - a
1031 * use-after-free). Whichever of the three releases (resolve_cv, reject_cv,
1032 * the drive loop) happens last actually frees ctx. */
1033 static void
1034 6 gql_runtime_vm_settle_capture_ctx_release(pTHX_ gql_runtime_vm_settle_capture_ctx_t *ctx)
1035 {
1036 6 ▶ if (!ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ctx) { 0 6 6
1037 0 return;
1038 }
1039 6 ▶ if (ctx->cv_refcnt > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->cv_refcnt > 0) { 6 0 6
1040 6 ctx->cv_refcnt--;
1041 }
1042 6 ▶ if (ctx->cv_refcnt == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->cv_refcnt == 0) { 2 4 6
1043 2 ▶ if (ctx->value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->value) { 2 0 2
1044 2 SvREFCNT_dec(ctx->value);
1045 }
1046 2 Safefree(ctx);
1047 }
1048 }
1049  
1050 static int
1051 4 gql_runtime_vm_settle_capture_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1052 {
1053 4 ▶ gql_runtime_vm_settle_capture_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_settle_capture_ctx_t *ctx = mg && mg->mg_ptr 4 0 4
1054 ? INT2PTR(gql_runtime_vm_settle_capture_ctx_t *, mg->mg_ptr)
1055 8 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 4 0 4
1056 4 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 4 0 4
1057 4 gql_runtime_vm_settle_capture_ctx_release(aTHX_ ctx);
1058 4 mg->mg_ptr = NULL;
1059 }
1060 4 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 4 0 4
if (sv && SvTYPE(sv) == SVt_PVCV) { 4 0 4
1061 4 CvXSUBANY((CV *)sv).any_ptr = NULL;
1062 }
1063 4 return 0;
1064 }
1065  
1066 static int
1067 1301 gql_runtime_vm_error_callback_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1068 {
1069 1301 ▶ gql_runtime_vm_error_callback_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_error_callback_ctx_t *ctx = mg && mg->mg_ptr 1301 0 1301
1070 ? INT2PTR(gql_runtime_vm_error_callback_ctx_t *, mg->mg_ptr)
1071 2602 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 1301 0 1301
1072 1301 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 1301 0 1301
1073 1301 gql_runtime_vm_path_frame_decref(ctx->path_frame);
1074 1301 Safefree(ctx);
1075 1301 mg->mg_ptr = NULL;
1076 }
1077 1301 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 1301 0 1301
if (sv && SvTYPE(sv) == SVt_PVCV) { 1301 0 1301
1078 1301 CvXSUBANY((CV *)sv).any_ptr = NULL;
1079 }
1080 1301 return 0;
1081 }
1082  
1083 static int
1084 646 gql_runtime_vm_list_item_child_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1085 {
1086 646 ▶ gql_runtime_vm_list_item_child_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_list_item_child_ctx_t *ctx = mg && mg->mg_ptr 646 0 646
1087 ? INT2PTR(gql_runtime_vm_list_item_child_ctx_t *, mg->mg_ptr)
1088 1292 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 646 0 646
1089 646 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 646 0 646
1090 646 SvREFCNT_dec(ctx->state_sv);
1091 646 gql_runtime_vm_path_frame_decref(ctx->path_frame);
1092 646 Safefree(ctx);
1093 646 mg->mg_ptr = NULL;
1094 }
1095 646 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 646 0 646
if (sv && SvTYPE(sv) == SVt_PVCV) { 646 0 646
1096 646 CvXSUBANY((CV *)sv).any_ptr = NULL;
1097 }
1098 646 return 0;
1099 }
1100  
1101 static int
1102 0 gql_runtime_vm_finalize_callback_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1103 {
1104 0 ▶ gql_runtime_vm_finalize_callback_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_finalize_callback_ctx_t *ctx = mg && mg->mg_ptr 0 0 0
1105 ? INT2PTR(gql_runtime_vm_finalize_callback_ctx_t *, mg->mg_ptr)
1106 0 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 0 0 0
1107 0 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 0 0 0
1108 0 gql_runtime_vm_pending_merge_decref(aTHX_ ctx->merge);
1109 0 Safefree(ctx);
1110 0 mg->mg_ptr = NULL;
1111 }
1112 0 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 0 0 0
if (sv && SvTYPE(sv) == SVt_PVCV) { 0 0 0
1113 0 CvXSUBANY((CV *)sv).any_ptr = NULL;
1114 }
1115 0 return 0;
1116 }
1117  
1118 static int
1119 2708 gql_runtime_vm_ticket_chain_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1120 {
1121 2708 ▶ gql_runtime_vm_ticket_chain_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_ticket_chain_ctx_t *ctx = mg && mg->mg_ptr 2708 0 2708
1122 ? INT2PTR(gql_runtime_vm_ticket_chain_ctx_t *, mg->mg_ptr)
1123 5416 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 2708 0 2708
1124 2708 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 2708 0 2708
1125 2708 SvREFCNT_dec(ctx->derived_ticket);
1126 2708 SvREFCNT_dec(ctx->callback_sv);
1127 2708 Safefree(ctx);
1128 2708 mg->mg_ptr = NULL;
1129 }
1130 2708 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 2708 0 2708
if (sv && SvTYPE(sv) == SVt_PVCV) { 2708 0 2708
1131 2708 CvXSUBANY((CV *)sv).any_ptr = NULL;
1132 }
1133 2708 return 0;
1134 }
1135  
1136 static MGVTBL gql_runtime_vm_pending_callback_ctx_vtbl = {
1137 NULL,
1138 NULL,
1139 NULL,
1140 NULL,
1141 gql_runtime_vm_pending_callback_ctx_free
1142 #if PERL_VERSION_GE(5, 15, 0)
1143 ,NULL
1144 ,NULL
1145 ,NULL
1146 #endif
1147 };
1148  
1149 static MGVTBL gql_runtime_vm_list_pending_callback_ctx_vtbl = {
1150 NULL,
1151 NULL,
1152 NULL,
1153 NULL,
1154 gql_runtime_vm_list_pending_callback_ctx_free
1155 #if PERL_VERSION_GE(5, 15, 0)
1156 ,NULL
1157 ,NULL
1158 ,NULL
1159 #endif
1160 };
1161  
1162 static MGVTBL gql_runtime_vm_settle_capture_ctx_vtbl = {
1163 NULL,
1164 NULL,
1165 NULL,
1166 NULL,
1167 gql_runtime_vm_settle_capture_ctx_free
1168 #if PERL_VERSION_GE(5, 15, 0)
1169 ,NULL
1170 ,NULL
1171 ,NULL
1172 #endif
1173 };
1174  
1175 static MGVTBL gql_runtime_vm_error_callback_ctx_vtbl = {
1176 NULL,
1177 NULL,
1178 NULL,
1179 NULL,
1180 gql_runtime_vm_error_callback_ctx_free
1181 #if PERL_VERSION_GE(5, 15, 0)
1182 ,NULL
1183 ,NULL
1184 ,NULL
1185 #endif
1186 };
1187  
1188 static MGVTBL gql_runtime_vm_list_item_child_ctx_vtbl = {
1189 NULL,
1190 NULL,
1191 NULL,
1192 NULL,
1193 gql_runtime_vm_list_item_child_ctx_free
1194 #if PERL_VERSION_GE(5, 15, 0)
1195 ,NULL
1196 ,NULL
1197 ,NULL
1198 #endif
1199 };
1200  
1201 static MGVTBL gql_runtime_vm_finalize_callback_ctx_vtbl = {
1202 NULL,
1203 NULL,
1204 NULL,
1205 NULL,
1206 gql_runtime_vm_finalize_callback_ctx_free
1207 #if PERL_VERSION_GE(5, 15, 0)
1208 ,NULL
1209 ,NULL
1210 ,NULL
1211 #endif
1212 };
1213  
1214 static MGVTBL gql_runtime_vm_ticket_chain_ctx_vtbl = {
1215 NULL,
1216 NULL,
1217 NULL,
1218 NULL,
1219 gql_runtime_vm_ticket_chain_ctx_free
1220 #if PERL_VERSION_GE(5, 15, 0)
1221 ,NULL
1222 ,NULL
1223 ,NULL
1224 #endif
1225 };
1226  
1227 static int
1228 6 gql_runtime_vm_fast_root_continuation_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1229 {
1230 6 ▶ gql_runtime_vm_fast_root_continuation_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_fast_root_continuation_ctx_t *ctx = mg && mg->mg_ptr 6 0 6
1231 ? INT2PTR(gql_runtime_vm_fast_root_continuation_ctx_t *, mg->mg_ptr)
1232 12 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 6 0 6
1233 6 ▶ if (ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx) { 6 0 6
1234 /* The ctx is shared by the resolve/reject pair's two CVs; members go
1235 * with the last one, exactly like gql_runtime_vm_pending_callback_ctx_free. */
1236 6 ▶ if (ctx->cv_refcnt > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->cv_refcnt > 0) { 6 0 6
1237 6 ctx->cv_refcnt--;
1238 }
1239 6 ▶ if (ctx->cv_refcnt == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->cv_refcnt == 0) { 3 3 6
1240 3 SvREFCNT_dec(ctx->runtime_sv);
1241 3 SvREFCNT_dec(ctx->program_sv);
1242 3 SvREFCNT_dec(ctx->runtime_schema_sv);
1243 3 SvREFCNT_dec(ctx->root_value_sv);
1244 3 SvREFCNT_dec(ctx->context_sv);
1245 3 SvREFCNT_dec(ctx->variables_sv);
1246 3 ▶ if (ctx->shared && --ctx->shared->refcount == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->shared && --ctx->shared->refcount == 0) { 3 0 3
if (ctx->shared && --ctx->shared->refcount == 0) { 1 2 3
1247 1 SvREFCNT_dec(ctx->shared->sync_response_sv);
1248 1 SvREFCNT_dec(ctx->shared->deferred_sv);
1249 1 Safefree(ctx->shared);
1250 }
1251 3 Safefree(ctx);
1252 }
1253 6 mg->mg_ptr = NULL;
1254 }
1255 6 ▶ if (sv && SvTYPE(sv) == SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvTYPE(sv) == SVt_PVCV) { 6 0 6
if (sv && SvTYPE(sv) == SVt_PVCV) { 6 0 6
1256 6 CvXSUBANY((CV *)sv).any_ptr = NULL;
1257 }
1258 6 return 0;
1259 }
1260  
1261 static MGVTBL gql_runtime_vm_fast_root_continuation_ctx_vtbl = {
1262 NULL,
1263 NULL,
1264 NULL,
1265 NULL,
1266 gql_runtime_vm_fast_root_continuation_ctx_free
1267 #if PERL_VERSION_GE(5, 15, 0)
1268 ,NULL
1269 ,NULL
1270 ,NULL
1271 #endif
1272 };
1273  
1274 static int
1275 0 gql_runtime_vm_serial_mutation_ctx_free(pTHX_ SV *sv, MAGIC *mg)
1276 {
1277 0 ▶ gql_runtime_vm_serial_mutation_ctx_t *ctx = mg && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_serial_mutation_ctx_t *ctx = mg && mg->mg_ptr 0 0 0
1278 ? INT2PTR(gql_runtime_vm_serial_mutation_ctx_t *, mg->mg_ptr)
1279 0 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 0 0 0
1280 PERL_UNUSED_VAR(sv);
1281 0 ▶ if (!ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ctx) { 0 0 0
1282 0 return 0;
1283 }
1284 0 ▶ if (ctx->state_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state_sv) { 0 0 0
1285 0 SvREFCNT_dec(ctx->state_sv);
1286 0 ctx->state_sv = NULL;
1287 }
1288 0 ▶ if (ctx->source_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->source_sv) { 0 0 0
1289 0 SvREFCNT_dec(ctx->source_sv);
1290 0 ctx->source_sv = NULL;
1291 }
1292 0 ▶ if (ctx->base_path_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->base_path_ptr) { 0 0 0
1293 0 gql_runtime_vm_path_frame_decref(ctx->base_path_ptr);
1294 0 ctx->base_path_ptr = NULL;
1295 }
1296 0 ▶ if (ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { 0 0 0
1297 0 gql_runtime_vm_free_block_frame(aTHX_ ctx->frame);
1298 0 ctx->frame = NULL;
1299 }
1300 0 gql_runtime_vm_cursor_destroy_copy(aTHX_ &ctx->cursor_snapshot);
1301 0 Safefree(ctx);
1302 0 return 0;
1303 }
1304  
1305 static MGVTBL gql_runtime_vm_serial_mutation_ctx_vtbl = {
1306 NULL,
1307 NULL,
1308 NULL,
1309 NULL,
1310 gql_runtime_vm_serial_mutation_ctx_free
1311 #if PERL_VERSION_GE(5, 15, 0)
1312 ,NULL
1313 ,NULL
1314 ,NULL
1315 #endif
1316 };
1317  
1318 static void
1319 5514 gql_runtime_vm_attach_callback_magic_ptr(pTHX_ SV *sv, MGVTBL *vtbl, void *ptr)
1320 {
1321 MAGIC *mg;
1322  
1323 5514 ▶ if (!sv || !vtbl || !ptr) {
Branch: 3 branches
BranchTrueFalseTotal
if (!sv || !vtbl || !ptr) { 5514 0 5514
if (!sv || !vtbl || !ptr) { 5514 0 5514
if (!sv || !vtbl || !ptr) { 0 5514 5514
1324 0 return;
1325 }
1326  
1327 5514 sv_magicext(sv, NULL, PERL_MAGIC_ext, vtbl, NULL, 0);
1328 5514 mg = mg_findext(sv, PERL_MAGIC_ext, vtbl);
1329 5514 ▶ if (!mg) {
Branch: 1 branch
BranchTrueFalseTotal
if (!mg) { 0 5514 5514
1330 0 croak("failed to attach runtime callback state");
1331 }
1332 5514 mg->mg_ptr = PTR2IV(ptr) ? INT2PTR(char *, ptr) : NULL;
1333 }
1334  
1335 static SV *
1336 3600 gql_runtime_vm_wrap_block_frame_sv(pTHX_ gql_runtime_vm_block_frame_t *frame)
1337 {
1338 3600 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 3600 3600
1339 0 return newSVsv(&PL_sv_undef);
1340 }
1341 3600 frame->refcount++;
1342 3600 return gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::BlockFrame", frame);
1343 }
1344  
1345 static int
1346 11939 gql_runtime_vm_is_block_frame_value_sv(SV *value)
1347 {
1348 11939 ▶ return value && SvOK(value) && SvROK(value)
Branch: 2 branches
BranchTrueFalseTotal
return value && SvOK(value) && SvROK(value) 11928 11 11939
return value && SvOK(value) && SvROK(value) 7330 4598 11928
1349 23878 ▶ && sv_derived_from(value, "GraphQL::Houtou::Runtime::BlockFrame");
Branch: 2 branches
BranchTrueFalseTotal
&& sv_derived_from(value, "GraphQL::Houtou::Runtime::BlockFrame"); 11939 0 11939
&& sv_derived_from(value, "GraphQL::Houtou::Runtime::BlockFrame"); 3425 3905 7330
1350 }
1351  
1352 static SV *
1353 648 gql_runtime_vm_wrap_list_pending_sv(pTHX_ gql_runtime_vm_list_pending_t *pending)
1354 {
1355 648 ▶ if (!pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (!pending) { 0 648 648
1356 0 return newSVsv(&PL_sv_undef);
1357 }
1358 648 gql_runtime_vm_list_pending_incref(pending);
1359 648 return gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::ListPending", pending);
1360 }
1361  
1362 static int
1363 7 gql_runtime_vm_is_list_pending_value_sv(SV *value)
1364 {
1365 7 ▶ return value && SvOK(value) && SvROK(value)
Branch: 2 branches
BranchTrueFalseTotal
return value && SvOK(value) && SvROK(value) 7 0 7
return value && SvOK(value) && SvROK(value) 7 0 7
1366 14 ▶ && sv_derived_from(value, "GraphQL::Houtou::Runtime::ListPending");
Branch: 2 branches
BranchTrueFalseTotal
&& sv_derived_from(value, "GraphQL::Houtou::Runtime::ListPending"); 7 0 7
&& sv_derived_from(value, "GraphQL::Houtou::Runtime::ListPending"); 7 0 7
1367 }
1368  
1369 static void *
1370 18916 gql_runtime_vm_expect_handle_ptr(pTHX_ SV *self, const char *what)
1371 {
1372 SV *inner;
1373 18916 ▶ if (!self || !SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!self || !SvROK(self)) { 18916 0 18916
if (!self || !SvROK(self)) { 0 18916 18916
1374 0 croak("%s must be a handle reference", what);
1375 }
1376 18916 inner = SvRV(self);
1377 18916 ▶ if (!SvIOK(inner) || SvUV(inner) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvIOK(inner) || SvUV(inner) == 0) { 18916 0 18916
if (!SvIOK(inner) || SvUV(inner) == 0) { 0 18916 18916
1378 0 croak("%s handle is no longer valid", what);
1379 }
1380 18916 return INT2PTR(void *, SvUV(inner));
1381 }
1382  
1383 static gql_runtime_vm_cursor_t *
1384 0 gql_runtime_vm_expect_cursor(pTHX_ SV *self)
1385 {
1386 0 return (gql_runtime_vm_cursor_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "cursor");
1387 }
1388  
1389 static gql_runtime_vm_field_frame_t *
1390 0 gql_runtime_vm_expect_field_frame(pTHX_ SV *self)
1391 {
1392 0 return (gql_runtime_vm_field_frame_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "field frame");
1393 }
1394  
1395 static gql_runtime_vm_path_frame_t *
1396 0 gql_runtime_vm_expect_path_frame(pTHX_ SV *self)
1397 {
1398 0 return (gql_runtime_vm_path_frame_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "path frame");
1399 }
1400  
1401 static gql_runtime_vm_block_frame_t *
1402 2121 gql_runtime_vm_expect_block_frame(pTHX_ SV *self)
1403 {
1404 2121 return (gql_runtime_vm_block_frame_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "block frame");
1405 }
1406  
1407 static gql_runtime_vm_list_pending_t *
1408 648 gql_runtime_vm_expect_list_pending(pTHX_ SV *self)
1409 {
1410 648 return (gql_runtime_vm_list_pending_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "list pending");
1411 }
1412  
1413 static gql_runtime_vm_error_record_t *
1414 0 gql_runtime_vm_expect_error_record(pTHX_ SV *self)
1415 {
1416 0 return (gql_runtime_vm_error_record_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "error record");
1417 }
1418  
1419 static gql_runtime_vm_outcome_t *
1420 750 gql_runtime_vm_expect_outcome(pTHX_ SV *self)
1421 {
1422 750 return (gql_runtime_vm_outcome_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "outcome");
1423 }
1424  
1425 static gql_runtime_vm_writer_t *
1426 0 gql_runtime_vm_expect_writer(pTHX_ SV *self)
1427 {
1428 0 return (gql_runtime_vm_writer_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "writer");
1429 }
1430  
1431 static gql_runtime_vm_exec_state_handle_t *
1432 15397 gql_runtime_vm_expect_exec_state_handle(pTHX_ SV *self)
1433 {
1434 15397 return (gql_runtime_vm_exec_state_handle_t *)gql_runtime_vm_expect_handle_ptr(aTHX_ self, "exec state");
1435 }
1436  
1437 static gql_runtime_vm_native_runtime_t *gql_runtime_vm_exec_state_native_runtime(pTHX_ gql_runtime_vm_exec_state_handle_t *s);
1438  
1439  
1440 static SV *
1441 488 gql_runtime_vm_wrap_outcome_sv(pTHX_ gql_runtime_vm_outcome_t *outcome)
1442 {
1443 SV *inner;
1444 SV *rv;
1445  
1446 488 ▶ if (!outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (!outcome) { 0 488 488
1447 0 return newSVsv(&PL_sv_undef);
1448 }
1449 488 gql_runtime_vm_outcome_incref(outcome);
1450 /* Outcome handles are created once per field on the async lane; bless
1451 * against the cached stash instead of re-resolving the package name. */
1452 488 ▶ if (!gql_runtime_vm_outcome_stash) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_outcome_stash) { 14 474 488
1453 14 gql_runtime_vm_outcome_stash = gv_stashpvs("GraphQL::Houtou::Runtime::Outcome", GV_ADD);
1454 }
1455 488 inner = newSVuv(PTR2UV(outcome));
1456 488 rv = newRV_noinc(inner);
1457 488 return sv_bless(rv, gql_runtime_vm_outcome_stash);
1458 }
1459  
1460 static gql_runtime_vm_outcome_t *
1461 2510 gql_runtime_vm_new_outcome_from_owned_native_value_struct(
1462 pTHX_
1463 U8 kind_code,
1464 gql_runtime_vm_native_value_t *value
1465 )
1466 {
1467 gql_runtime_vm_outcome_t *outcome;
1468  
1469 2510 outcome = gql_runtime_vm_outcome_pool_get(aTHX);
1470 2510 outcome->refcount = 1;
1471 2510 outcome->kind_code = kind_code;
1472 2510 ▶ outcome->value = value ? value : gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
outcome->value = value ? value : gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef); 0 2510 2510
1473 2510 outcome->error_record_count = 0;
1474 2510 outcome->error_records = NULL;
1475  
1476 2510 return outcome;
1477 }
1478  
1479 static SV *
1480 351 gql_runtime_vm_new_outcome_from_owned_native_value_handle_sv(
1481 pTHX_
1482 U8 kind_code,
1483 gql_runtime_vm_native_value_t *value
1484 )
1485 {
1486 gql_runtime_vm_outcome_t *outcome =
1487 351 gql_runtime_vm_new_outcome_from_owned_native_value_struct(aTHX_ kind_code, value);
1488 351 SV *ret = gql_runtime_vm_wrap_outcome_sv(aTHX_ outcome);
1489 351 gql_runtime_vm_outcome_decref(aTHX_ outcome);
1490 351 return ret;
1491 }
1492  
1493 static SV *
1494 0 gql_runtime_vm_wrap_path_frame_sv(pTHX_ gql_runtime_vm_path_frame_t *path_frame)
1495 {
1496 0 ▶ if (!path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!path_frame) { 0 0 0
1497 0 return newSVsv(&PL_sv_undef);
1498 }
1499 0 path_frame->refcount++;
1500 0 return gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::PathFrame", path_frame);
1501 }
1502  
1503 static gql_runtime_vm_path_frame_t *
1504 4133 gql_runtime_vm_new_path_frame_struct(pTHX_ gql_runtime_vm_path_frame_t *parent, SV *key)
1505 {
1506 gql_runtime_vm_path_frame_t *frame;
1507 4133 frame = gql_runtime_vm_path_frame_pool_get(aTHX);
1508 4133 frame->refcount = 1;
1509 4133 ▶ if (parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (parent) { 4133 0 4133
1510 4133 frame->parent = parent;
1511 4133 frame->parent->refcount++;
1512 }
1513 4133 ▶ if (key && SvOK(key)) {
Branch: 2 branches
BranchTrueFalseTotal
if (key && SvOK(key)) { 4133 0 4133
if (key && SvOK(key)) { 4133 0 4133
1514 4133 ▶ if (SvIOK(key) && !SvROK(key)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(key) && !SvROK(key)) { 4133 0 4133
if (SvIOK(key) && !SvROK(key)) { 4133 0 4133
1515 4133 frame->key_kind = 1;
1516 4133 frame->key_iv = SvIV(key);
1517 } else {
1518 STRLEN len;
1519 0 const char *pv = SvPV(key, len);
1520 0 frame->key_kind = 2;
1521 0 Newx(frame->key_pv, len + 1, char);
1522 0 Copy(pv, frame->key_pv, len, char);
1523 0 frame->key_pv[len] = '\0';
1524 0 frame->key_pv_len = len;
1525 }
1526 }
1527 4133 return frame;
1528 }
1529  
1530 static gql_runtime_vm_path_frame_t *
1531 11640 gql_runtime_vm_new_path_frame_struct_pvn_borrowed(
1532 pTHX_
1533 gql_runtime_vm_path_frame_t *parent,
1534 const char *key_pv,
1535 STRLEN key_len
1536 )
1537 {
1538 gql_runtime_vm_path_frame_t *frame;
1539 11640 frame = gql_runtime_vm_path_frame_pool_get(aTHX);
1540 11640 frame->refcount = 1;
1541 11640 ▶ if (parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (parent) { 8377 3263 11640
1542 8377 frame->parent = parent;
1543 8377 frame->parent->refcount++;
1544 }
1545 11640 ▶ if (key_pv && key_len > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (key_pv && key_len > 0) { 11640 0 11640
if (key_pv && key_len > 0) { 11640 0 11640
1546 11640 frame->key_kind = 2;
1547 11640 frame->key_pv = (char *)key_pv;
1548 11640 frame->key_pv_len = key_len;
1549 11640 frame->key_pv_borrowed = 1;
1550 }
1551 11640 return frame;
1552 }
1553  
1554 static SV *
1555 0 gql_runtime_vm_new_path_frame_handle(pTHX_ SV *parent, SV *key)
1556 {
1557 0 gql_runtime_vm_path_frame_t *parent_ptr = NULL;
1558 gql_runtime_vm_path_frame_t *frame;
1559 0 ▶ if (parent && SvOK(parent) && SvROK(parent) && SvIOK(SvRV(parent)) && SvUV(SvRV(parent)) != 0) {
Branch: 5 branches
BranchTrueFalseTotal
if (parent && SvOK(parent) && SvROK(parent) && SvIOK(SvRV(parent)) && SvUV(SvRV(parent)) != 0) { 0 0 0
if (parent && SvOK(parent) && SvROK(parent) && SvIOK(SvRV(parent)) && SvUV(SvRV(parent)) != 0) { 0 0 0
if (parent && SvOK(parent) && SvROK(parent) && SvIOK(SvRV(parent)) && SvUV(SvRV(parent)) != 0) { 0 0 0
if (parent && SvOK(parent) && SvROK(parent) && SvIOK(SvRV(parent)) && SvUV(SvRV(parent)) != 0) { 0 0 0
if (parent && SvOK(parent) && SvROK(parent) && SvIOK(SvRV(parent)) && SvUV(SvRV(parent)) != 0) { 0 0 0
1560 0 parent_ptr = INT2PTR(gql_runtime_vm_path_frame_t *, SvUV(SvRV(parent)));
1561 }
1562 0 frame = gql_runtime_vm_new_path_frame_struct(aTHX_ parent_ptr, key);
1563 0 return gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::PathFrame", frame);
1564 }
1565  
1566 static gql_runtime_vm_block_frame_t *
1567 4081 gql_runtime_vm_new_block_frame_struct(pTHX)
1568 {
1569 gql_runtime_vm_block_frame_t *frame;
1570 4081 frame = gql_runtime_vm_block_frame_pool_get(aTHX);
1571 4081 frame->refcount = 1;
1572 4081 frame->values_value = gql_runtime_vm_new_native_value_object();
1573 4081 frame->pending_count = 0;
1574 4081 frame->pending_unresolved = 0;
1575 4081 frame->parent_frame = NULL;
1576 4081 frame->parent_entry_index = -1;
1577 4081 frame->deferred_sv = NULL;
1578 4081 frame->promise_sv = NULL;
1579 4081 frame->queued = 0;
1580 4081 frame->deferred_resolves_response = 0;
1581 4081 return frame;
1582 }
1583  
1584 static gql_runtime_vm_field_frame_t *
1585 0 gql_runtime_vm_new_field_frame_struct(pTHX_ SV *source, gql_runtime_vm_path_frame_t *path_frame)
1586 {
1587 gql_runtime_vm_field_frame_t *frame;
1588 0 Newxz(frame, 1, gql_runtime_vm_field_frame_t);
1589 0 frame->refcount = 1;
1590 0 ▶ frame->source = SvREFCNT_inc_simple_NN(source ? source : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
frame->source = SvREFCNT_inc_simple_NN(source ? source : &PL_sv_undef); 0 0 0
frame->source = SvREFCNT_inc_simple_NN(source ? source : &PL_sv_undef); 0 0 0
1591 0 ▶ if (path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (path_frame) { 0 0 0
1592 0 frame->path_frame = path_frame;
1593 0 frame->path_frame->refcount++;
1594 }
1595 0 frame->resolved_value = NULL;
1596 0 frame->outcome = NULL;
1597 0 frame->source_is_runtime_owned = 0;
1598 0 frame->storage_is_stack = 0;
1599 0 return frame;
1600 }
1601  
1602 static gql_runtime_vm_field_frame_t *
1603 1319 gql_runtime_vm_init_stack_field_frame(
1604 pTHX_
1605 gql_runtime_vm_field_frame_t *frame,
1606 SV *source,
1607 gql_runtime_vm_path_frame_t *path_frame
1608 )
1609 {
1610 1319 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 1319 1319
1611 0 return NULL;
1612 }
1613 1319 Zero(frame, 1, gql_runtime_vm_field_frame_t);
1614 1319 frame->refcount = 1;
1615 1319 frame->storage_is_stack = 1;
1616 1319 ▶ frame->source = SvREFCNT_inc_simple_NN(source ? source : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
frame->source = SvREFCNT_inc_simple_NN(source ? source : &PL_sv_undef); 1319 0 1319
frame->source = SvREFCNT_inc_simple_NN(source ? source : &PL_sv_undef); 1319 0 1319
1617 1319 ▶ if (path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (path_frame) { 1319 0 1319
1618 1319 frame->path_frame = path_frame;
1619 1319 frame->path_frame->refcount++;
1620 }
1621 1319 frame->source_is_runtime_owned = 0;
1622 1319 return frame;
1623 }
1624  
1625 /*
1626 * Croak-safety net for the stack-allocated field frames used by the block
1627 * execution loops. A die() escaping from resolver or input-coercion code
1628 * longjmps past the loops' normal restore, which would leave
1629 * state->field_frame pointing into a dead C stack frame; ExecState DESTROY
1630 * would later free garbage read from that dead stack (observed as
1631 * "Attempt to free unreferenced scalar ... during global destruction"
1632 * followed by SIGSEGV). The guard is registered on Perl's save stack, so it
1633 * fires during die unwinding while this C stack is still live: it releases
1634 * the in-flight frame and restores the saved one. The loops disarm it on
1635 * their normal exits.
1636 */
1637 typedef struct {
1638 gql_runtime_vm_exec_state_handle_t *state;
1639 gql_runtime_vm_field_frame_t *saved_field_frame;
1640 } gql_runtime_vm_field_frame_guard_t;
1641  
1642 static void
1643 450 gql_runtime_vm_field_frame_guard_fire(pTHX_ void *ptr)
1644 {
1645 450 gql_runtime_vm_field_frame_guard_t *guard = (gql_runtime_vm_field_frame_guard_t *)ptr;
1646 450 ▶ gql_runtime_vm_exec_state_handle_t *state = guard ? guard->state : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_exec_state_handle_t *state = guard ? guard->state : NULL; 450 0 450
1647 450 ▶ if (state) {
Branch: 1 branch
BranchTrueFalseTotal
if (state) { 2 448 450
1648 2 ▶ if (state->field_frame && state->field_frame != guard->saved_field_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->field_frame && state->field_frame != guard->saved_field_frame) { 0 2 2
if (state->field_frame && state->field_frame != guard->saved_field_frame) { 0 0 0
1649 0 gql_runtime_vm_free_field_frame(aTHX_ state->field_frame);
1650 }
1651 2 state->field_frame = guard->saved_field_frame;
1652 }
1653 450 Safefree(guard);
1654 450 }
1655  
1656 static gql_runtime_vm_field_frame_guard_t *
1657 450 gql_runtime_vm_arm_field_frame_guard(
1658 pTHX_
1659 gql_runtime_vm_exec_state_handle_t *state,
1660 gql_runtime_vm_field_frame_t *saved_field_frame
1661 )
1662 {
1663 gql_runtime_vm_field_frame_guard_t *guard;
1664 450 Newxz(guard, 1, gql_runtime_vm_field_frame_guard_t);
1665 450 guard->state = state;
1666 450 guard->saved_field_frame = saved_field_frame;
1667 450 SAVEDESTRUCTOR_X(gql_runtime_vm_field_frame_guard_fire, guard);
1668 450 return guard;
1669 }
1670  
1671 static void
1672 1319 gql_runtime_vm_leave_field_now(pTHX_ gql_runtime_vm_exec_state_handle_t *s)
1673 {
1674 1319 ▶ if (!s) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s) { 0 1319 1319
1675 0 return;
1676 }
1677 1319 gql_runtime_vm_free_field_frame(aTHX_ s->field_frame);
1678 1319 s->field_frame = NULL;
1679 }
1680  
1681 static gql_runtime_vm_outcome_t *
1682 554 gql_runtime_vm_new_error_outcome_struct_for_path(pTHX_ SV *message_sv, gql_runtime_vm_path_frame_t *path_frame)
1683 {
1684 554 ▶ SV *clean_message_sv = message_sv ? newSVsv(message_sv) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
SV *clean_message_sv = message_sv ? newSVsv(message_sv) : newSVsv(&PL_sv_undef); 554 0 554
1685 gql_runtime_vm_error_record_t *record;
1686 gql_runtime_vm_outcome_t *outcome;
1687  
1688 554 ▶ if (clean_message_sv && SvOK(clean_message_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (clean_message_sv && SvOK(clean_message_sv)) { 554 0 554
if (clean_message_sv && SvOK(clean_message_sv)) { 554 0 554
1689 STRLEN len;
1690 554 char *pv = SvPV(clean_message_sv, len);
1691 1008 ▶ while (len > 0 && (pv[len - 1] == '\n' || pv[len - 1] == '\r')) {
Branch: 3 branches
BranchTrueFalseTotal
while (len > 0 && (pv[len - 1] == '\n' || pv[len - 1] == '\r')) { 1008 0 1008
while (len > 0 && (pv[len - 1] == '\n' || pv[len - 1] == '\r')) { 454 554 1008
while (len > 0 && (pv[len - 1] == '\n' || pv[len - 1] == '\r')) { 0 554 554
1692 454 len--;
1693 }
1694 554 sv_setpvn(clean_message_sv, pv, len);
1695 }
1696  
1697 554 record = gql_runtime_vm_new_error_record_struct_for_path(aTHX_ clean_message_sv, path_frame);
1698 554 SvREFCNT_dec(clean_message_sv);
1699  
1700 554 outcome = gql_runtime_vm_outcome_pool_get(aTHX);
1701 554 outcome->refcount = 1;
1702 554 outcome->kind_code = GQL_VM_KIND_SCALAR;
1703 554 outcome->value = gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
1704 554 outcome->error_record_count = 1;
1705 554 Newxz(outcome->error_records, 1, gql_runtime_vm_error_record_t *);
1706 554 outcome->error_records[0] = record;
1707 554 return outcome;
1708 }
1709  
1710 static SV *
1711 12 gql_runtime_vm_new_error_outcome_for_path_sv(
1712 pTHX_
1713 SV *message_sv,
1714 gql_runtime_vm_path_frame_t *path_frame
1715 )
1716 {
1717 gql_runtime_vm_outcome_t *outcome =
1718 12 gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ message_sv, path_frame);
1719 12 SV *ret = gql_runtime_vm_wrap_outcome_sv(aTHX_ outcome);
1720 12 gql_runtime_vm_outcome_decref(aTHX_ outcome);
1721 12 return ret;
1722 }
1723  
1724 static void
1725 1240 gql_runtime_vm_consume_current_outcome_now(pTHX_ gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_outcome_t *outcome)
1726 {
1727 gql_runtime_vm_block_frame_t *frame;
1728 gql_runtime_vm_writer_t *writer;
1729 const gql_runtime_vm_native_slot_t *native_slot;
1730 1240 const char *result_name_pv = NULL;
1731  
1732 1240 ▶ if (!s || !outcome || !s->frame || !s->writer) {
Branch: 4 branches
BranchTrueFalseTotal
if (!s || !outcome || !s->frame || !s->writer) { 1240 0 1240
if (!s || !outcome || !s->frame || !s->writer) { 1240 0 1240
if (!s || !outcome || !s->frame || !s->writer) { 1240 0 1240
if (!s || !outcome || !s->frame || !s->writer) { 0 1240 1240
1733 0 gql_runtime_vm_leave_field_now(aTHX_ s);
1734 0 return;
1735 }
1736  
1737 1240 frame = s->frame;
1738 1240 writer = s->writer;
1739 /* Program slot, not effective slot: response keys carry the alias. */
1740 1240 ▶ native_slot = s->cursor ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
native_slot = s->cursor ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 1240 0 1240
1741 1240 ▶ if (native_slot && native_slot->result_name && *native_slot->result_name) {
Branch: 3 branches
BranchTrueFalseTotal
if (native_slot && native_slot->result_name && *native_slot->result_name) { 1240 0 1240
if (native_slot && native_slot->result_name && *native_slot->result_name) { 1240 0 1240
if (native_slot && native_slot->result_name && *native_slot->result_name) { 1240 0 1240
1742 1240 result_name_pv = native_slot->result_name;
1743 }
1744  
1745 /* No detour through field_frame->outcome: nothing reads it back, and
1746 * leave_field_now would drop the reference three lines later anyway.
1747 * Keeping the caller as sole owner also lets the consume below transfer
1748 * the native subtree instead of cloning it. */
1749 {
1750 /* Capture null-ness before consume transfers the value away. */
1751 1240 int vnull = gql_runtime_vm_native_value_is_null(outcome->value);
1752 1240 ▶ int carries = outcome->null_carries_error || outcome->error_record_count > 0;
Branch: 2 branches
BranchTrueFalseTotal
int carries = outcome->null_carries_error || outcome->error_record_count > 0; 1240 0 1240
int carries = outcome->null_carries_error || outcome->error_record_count > 0; 5 1235 1240
1753 1240 ▶ gql_runtime_vm_consume_outcome_native_object(
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_consume_outcome_native_object( 1240 0 1240
1754 aTHX_ frame->values_value,
1755 result_name_pv ? result_name_pv : "",
1756 result_name_pv ? 1 : 0,
1757 outcome,
1758 writer
1759 );
1760 /* Non-Null propagation (spec 6.4.4) for a synchronously completed
1761 * field: a null in a non-null position nulls this frame. */
1762 1240 ▶ if (vnull && native_slot && native_slot->return_type_kind_code == 8) {
Branch: 3 branches
BranchTrueFalseTotal
if (vnull && native_slot && native_slot->return_type_kind_code == 8) { 350 890 1240
if (vnull && native_slot && native_slot->return_type_kind_code == 8) { 350 0 350
if (vnull && native_slot && native_slot->return_type_kind_code == 8) { 1 349 350
1763 1 ▶ if (!carries) {
Branch: 1 branch
BranchTrueFalseTotal
if (!carries) { 1 0 1
1764 1 const gql_runtime_vm_native_block_t *parent_block =
1765 1 ▶ s->cursor ? gql_runtime_vm_cursor_current_native_block(s->cursor) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
s->cursor ? gql_runtime_vm_cursor_current_native_block(s->cursor) : NULL; 1 0 1
1766 1 gql_runtime_vm_record_nonnull_violation(
1767 aTHX_ writer,
1768 parent_block ? parent_block->type_name : NULL,
1769 1 ▶ native_slot->field_name,
Branch: 1 branch
BranchTrueFalseTotal
native_slot->field_name, 1 0 1
1770 1 ▶ s->field_frame ? s->field_frame->path_frame : NULL
Branch: 1 branch
BranchTrueFalseTotal
s->field_frame ? s->field_frame->path_frame : NULL 1 0 1
1771 );
1772 }
1773 1 frame->self_nulled = 1;
1774 }
1775 }
1776 1240 gql_runtime_vm_leave_field_now(aTHX_ s);
1777 }
1778  
1779 static void
1780 79 gql_runtime_vm_consume_current_result_now(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, SV *result_sv)
1781 {
1782 gql_runtime_vm_block_frame_t *frame;
1783 79 gql_runtime_vm_list_pending_t *list_pending = NULL;
1784 const gql_runtime_vm_native_slot_t *native_slot;
1785 79 gql_runtime_vm_block_frame_t *child_frame = NULL;
1786 79 const char *result_name_pv = NULL;
1787 79 STRLEN result_name_len = 0;
1788  
1789 79 ▶ if (!s) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s) { 0 79 79
1790 0 return;
1791 }
1792  
1793 79 ▶ if (result_sv && SvOK(result_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ result_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (result_sv && SvOK(result_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ result_sv)) { 79 0 79
if (result_sv && SvOK(result_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ result_sv)) { 24 55 79
if (result_sv && SvOK(result_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ result_sv)) { 0 24 24
1794 0 gql_runtime_vm_consume_current_outcome_now(aTHX_ s, gql_runtime_vm_expect_outcome(aTHX_ result_sv));
1795 0 return;
1796 }
1797  
1798 79 frame = s->frame;
1799 /* Program slot, not effective slot: pending entry keys carry the alias. */
1800 79 ▶ native_slot = s->cursor ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
native_slot = s->cursor ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 79 0 79
1801 79 ▶ if (native_slot && native_slot->result_name && *native_slot->result_name) {
Branch: 3 branches
BranchTrueFalseTotal
if (native_slot && native_slot->result_name && *native_slot->result_name) { 79 0 79
if (native_slot && native_slot->result_name && *native_slot->result_name) { 79 0 79
if (native_slot && native_slot->result_name && *native_slot->result_name) { 79 0 79
1802 79 result_name_pv = native_slot->result_name;
1803 79 result_name_len = (STRLEN)strlen(result_name_pv);
1804 }
1805 79 ▶ if (frame && result_name_pv && result_name_len > 0
Branch: 3 branches
BranchTrueFalseTotal
if (frame && result_name_pv && result_name_len > 0 79 0 79
if (frame && result_name_pv && result_name_len > 0 79 0 79
if (frame && result_name_pv && result_name_len > 0 79 0 79
1806 79 ▶ && result_sv && SvOK(result_sv)
Branch: 2 branches
BranchTrueFalseTotal
&& result_sv && SvOK(result_sv) 79 0 79
&& result_sv && SvOK(result_sv) 24 55 79
1807 24 ▶ && gql_runtime_vm_is_block_frame_value_sv(result_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_is_block_frame_value_sv(result_sv)) { 20 4 24
1808 20 child_frame = gql_runtime_vm_expect_block_frame(aTHX_ result_sv);
1809 20 gql_runtime_vm_push_pending_block_frame(
1810 aTHX_
1811 frame,
1812 result_name_pv,
1813 result_name_len,
1814 20 ▶ s->field_frame ? s->field_frame->path_frame : NULL,
Branch: 1 branch
BranchTrueFalseTotal
s->field_frame ? s->field_frame->path_frame : NULL, 20 0 20
1815 child_frame,
1816 20 ▶ s->cursor ? s->cursor->block_index : -1,
Branch: 1 branch
BranchTrueFalseTotal
s->cursor ? s->cursor->block_index : -1, 20 0 20
1817 20 ▶ s->cursor ? s->cursor->slot_index : -1,
Branch: 1 branch
BranchTrueFalseTotal
s->cursor ? s->cursor->slot_index : -1, 20 0 20
1818 20 ▶ s->cursor ? s->cursor->op_index : -1
Branch: 1 branch
BranchTrueFalseTotal
s->cursor ? s->cursor->op_index : -1 20 0 20
1819 );
1820 20 ▶ if (s->async_adapter != NULL
Branch: 1 branch
BranchTrueFalseTotal
if (s->async_adapter != NULL 20 0 20
1821 20 ▶ && child_frame
Branch: 1 branch
BranchTrueFalseTotal
&& child_frame 20 0 20
1822 20 ▶ && child_frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
&& child_frame->pending_unresolved == 0) { 1 19 20
1823 1 gql_runtime_vm_async_scheduler_enqueue_frame(s, child_frame);
1824 1 ▶ if (!s->async_scheduler_draining) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->async_scheduler_draining) { 1 0 1
1825 1 gql_runtime_vm_async_scheduler_drain(aTHX_ state_sv, s);
1826 }
1827 }
1828 20 gql_runtime_vm_leave_field_now(aTHX_ s);
1829 20 return;
1830 }
1831 59 ▶ if (frame && result_name_pv && result_name_len > 0
Branch: 3 branches
BranchTrueFalseTotal
if (frame && result_name_pv && result_name_len > 0 59 0 59
if (frame && result_name_pv && result_name_len > 0 59 0 59
if (frame && result_name_pv && result_name_len > 0 59 0 59
1832 59 ▶ && result_sv && SvOK(result_sv)
Branch: 2 branches
BranchTrueFalseTotal
&& result_sv && SvOK(result_sv) 59 0 59
&& result_sv && SvOK(result_sv) 4 55 59
1833 4 ▶ && gql_runtime_vm_is_list_pending_value_sv(result_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_is_list_pending_value_sv(result_sv)) { 4 0 4
1834 4 list_pending = gql_runtime_vm_expect_list_pending(aTHX_ result_sv);
1835 4 gql_runtime_vm_push_pending_list_pending(
1836 aTHX_
1837 frame,
1838 result_name_pv,
1839 result_name_len,
1840 4 ▶ s->field_frame ? s->field_frame->path_frame : NULL,
Branch: 1 branch
BranchTrueFalseTotal
s->field_frame ? s->field_frame->path_frame : NULL, 4 0 4
1841 list_pending,
1842 4 ▶ s->cursor ? s->cursor->block_index : -1,
Branch: 1 branch
BranchTrueFalseTotal
s->cursor ? s->cursor->block_index : -1, 4 0 4
1843 4 ▶ s->cursor ? s->cursor->slot_index : -1,
Branch: 1 branch
BranchTrueFalseTotal
s->cursor ? s->cursor->slot_index : -1, 4 0 4
1844 4 ▶ s->cursor ? s->cursor->op_index : -1
Branch: 1 branch
BranchTrueFalseTotal
s->cursor ? s->cursor->op_index : -1 4 0 4
1845 );
1846 4 gql_runtime_vm_leave_field_now(aTHX_ s);
1847 4 return;
1848 }
1849 55 ▶ if (frame && result_name_pv && result_name_len > 0 && result_sv && SvOK(result_sv)) {
Branch: 5 branches
BranchTrueFalseTotal
if (frame && result_name_pv && result_name_len > 0 && result_sv && SvOK(result_sv)) { 55 0 55
if (frame && result_name_pv && result_name_len > 0 && result_sv && SvOK(result_sv)) { 55 0 55
if (frame && result_name_pv && result_name_len > 0 && result_sv && SvOK(result_sv)) { 55 0 55
if (frame && result_name_pv && result_name_len > 0 && result_sv && SvOK(result_sv)) { 55 0 55
if (frame && result_name_pv && result_name_len > 0 && result_sv && SvOK(result_sv)) { 0 55 55
1850 0 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
1851 aTHX_ frame,
1852 result_name_pv,
1853 result_name_len,
1854 1,
1855 result_sv,
1856 GQL_VM_PENDING_PROMISE_SV,
1857 NULL,
1858 -1,
1859 -1,
1860 -1,
1861 0 s->async_adapter
1862 );
1863 }
1864 55 gql_runtime_vm_leave_field_now(aTHX_ s);
1865 }
1866  
1867 static SV *
1868 gql_runtime_vm_block_frame_finalize_sv(
1869 pTHX_
1870 gql_runtime_vm_block_frame_t *frame,
1871 gql_runtime_vm_async_adapter_t *async_adapter,
1872 gql_runtime_vm_writer_t *writer,
1873 SV *state_sv,
1874 U8 return_pending_handle
1875 );
1876  
1877 static SV *
1878 450 gql_runtime_vm_finalize_current_block_now(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, SV *snapshot, U8 return_pending_handle)
1879 {
1880 gql_runtime_vm_block_frame_t *frame;
1881 gql_runtime_vm_block_frame_t *completed_frame;
1882 SV *result;
1883 450 U8 scheduler_owned = 0;
1884  
1885 450 ▶ if (!s || !s->frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (!s || !s->frame) { 450 0 450
if (!s || !s->frame) { 0 450 450
1886 0 return newSVsv(&PL_sv_undef);
1887 }
1888  
1889 450 frame = s->frame;
1890 450 completed_frame = frame;
1891 450 ▶ if (s->async_adapter != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->async_adapter != NULL) { 450 0 450
1892 450 ▶ if (frame->pending_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_count > 0) { 66 384 450
1893 66 frame->deferred_resolves_response = (frame == s->response_frame) ? 1 : 0;
1894 66 scheduler_owned = 1;
1895 }
1896 450 result = gql_runtime_vm_block_frame_finalize_sv(
1897 aTHX_
1898 frame,
1899 s->async_adapter,
1900 s->writer,
1901 state_sv,
1902 return_pending_handle
1903 );
1904 } else {
1905 0 result = frame->self_nulled
1906 0 ? newSVsv(&PL_sv_undef)
1907 0 ▶ : gql_runtime_vm_native_value_materialize_sv(aTHX_ frame->values_value);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_native_value_materialize_sv(aTHX_ frame->values_value); 0 0 0
1908 }
1909  
1910 448 ▶ if (s->cursor && snapshot && SvOK(snapshot)) {
Branch: 3 branches
BranchTrueFalseTotal
if (s->cursor && snapshot && SvOK(snapshot)) { 448 0 448
if (s->cursor && snapshot && SvOK(snapshot)) { 448 0 448
if (s->cursor && snapshot && SvOK(snapshot)) { 0 448 448
1911 0 gql_runtime_vm_cursor_restore_sv(aTHX_ s->cursor, snapshot);
1912 }
1913  
1914 448 ▶ if (s->frame_stack_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack_count > 0) { 448 0 448
1915 448 s->frame_stack_count--;
1916 448 s->frame_stack[s->frame_stack_count] = NULL;
1917 }
1918 448 ▶ if (!scheduler_owned) {
Branch: 1 branch
BranchTrueFalseTotal
if (!scheduler_owned) { 384 64 448
1919 384 gql_runtime_vm_free_block_frame(aTHX_ completed_frame);
1920 }
1921 448 ▶ s->frame = s->frame_stack_count > 0 ? s->frame_stack[s->frame_stack_count - 1] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
s->frame = s->frame_stack_count > 0 ? s->frame_stack[s->frame_stack_count - 1] : NULL; 336 112 448
1922  
1923 448 return result;
1924 }
1925  
1926 static SV *
1927 4081 gql_runtime_vm_block_frame_finalize_sv(
1928 pTHX_
1929 gql_runtime_vm_block_frame_t *frame,
1930 gql_runtime_vm_async_adapter_t *async_adapter,
1931 gql_runtime_vm_writer_t *writer,
1932 SV *state_sv,
1933 U8 return_pending_handle
1934 )
1935 {
1936 IV i;
1937 AV *pending_av;
1938 SV *aggregate;
1939 gql_runtime_vm_block_frame_t next_pending;
1940 4081 gql_runtime_vm_exec_state_handle_t *exec_state =
1941 4081 ▶ (state_sv && SvOK(state_sv)) ? gql_runtime_vm_expect_exec_state_handle(aTHX_ state_sv) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
(state_sv && SvOK(state_sv)) ? gql_runtime_vm_expect_exec_state_handle(aTHX_ state_sv) : NULL; 4081 0 4081
(state_sv && SvOK(state_sv)) ? gql_runtime_vm_expect_exec_state_handle(aTHX_ state_sv) : NULL; 4081 0 4081
1942  
1943 /* return_pending_handle modes:
1944 * 0 - legacy: materialize an SV tree on sync completion, hand out the
1945 * frame promise when pendings remain (public exec-state API).
1946 * 1 - full handles: native outcome on sync completion, raw block-frame
1947 * handle when pendings remain.
1948 * 2 - native-first hot path: native outcome on sync completion (no
1949 * materialize/reconvert round trip), but still a promise when
1950 * pendings remain so the existing then-wrap machinery applies.
1951 * 3 - Phase 8: never build a Promise::XS deferred/promise pair, even for
1952 * the response frame (which modes 0-2 all force one for via
1953 * resolve_response). The caller drives completion itself (a C-level
1954 * on_stall loop) instead of registering then() on a returned
1955 * promise, and polls exec_state->completed_response_sv - the same
1956 * stash gql_runtime_vm_async_scheduler_resolve_frame's "no deferred
1957 * was ever created" branch already writes to when the response
1958 * settles without ever needing a promise. The raw block-frame
1959 * handle returned when pendings remain is not meant to be used by
1960 * the caller (arm_frame/enqueue below are what matter); it is
1961 * returned only because the same branch already builds it for mode
1962 * 1. */
1963 4081 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 4081 4081
1964 0 return newSVsv(&PL_sv_undef);
1965 }
1966 4081 ▶ if (frame->pending_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_count == 0) { 384 3697 4081
1967 /* Non-Null propagation: a violated frame completes as null (the
1968 * error is already recorded), not as its partial object. */
1969 384 ▶ if (frame->self_nulled) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->self_nulled) { 1 383 384
1970 1 ▶ if (return_pending_handle) {
Branch: 1 branch
BranchTrueFalseTotal
if (return_pending_handle) { 0 1 1
1971 gql_runtime_vm_outcome_t *o =
1972 0 gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef);
1973 SV *ret;
1974 0 o->null_carries_error = 1;
1975 0 ret = gql_runtime_vm_wrap_outcome_sv(aTHX_ o);
1976 0 gql_runtime_vm_outcome_decref(aTHX_ o);
1977 0 return ret;
1978 }
1979 1 return newSVsv(&PL_sv_undef);
1980 }
1981 383 ▶ if (return_pending_handle) {
Branch: 1 branch
BranchTrueFalseTotal
if (return_pending_handle) { 351 32 383
1982 351 SV *ret = gql_runtime_vm_new_outcome_from_owned_native_value_handle_sv(
1983 aTHX_
1984 GQL_VM_KIND_OBJECT,
1985 frame->values_value
1986 );
1987 351 frame->values_value = NULL;
1988 351 return ret;
1989 }
1990 32 return gql_runtime_vm_native_value_materialize_sv(aTHX_ frame->values_value);
1991 }
1992 3697 ▶ if (!async_adapter) {
Branch: 1 branch
BranchTrueFalseTotal
if (!async_adapter) { 0 3697 3697
1993 0 croak("pending async runtime blocks require an async adapter");
1994 }
1995 3697 ▶ if (exec_state) {
Branch: 1 branch
BranchTrueFalseTotal
if (exec_state) { 3697 0 3697
1996 SV *ret_sv;
1997 3697 U8 saved_draining = exec_state->async_scheduler_draining;
1998 3697 U8 resolve_response = frame->deferred_resolves_response ? 1 : 0;
1999 3697 U8 return_promise = (return_pending_handle == 3)
2000 ? 0
2001 3697 ▶ : ((resolve_response || return_pending_handle != 1) ? 1 : 0);
Branch: 3 branches
BranchTrueFalseTotal
: ((resolve_response || return_pending_handle != 1) ? 1 : 0); 2213 1484 3697
: ((resolve_response || return_pending_handle != 1) ? 1 : 0); 2130 83 2213
: ((resolve_response || return_pending_handle != 1) ? 1 : 0); 9 2121 2130
2002 3697 U8 armed = 0;
2003  
2004 /* Response frame at the top level: try to complete the request inside
2005 * this call before paying for the deferred. Arm first; if every
2006 * pending settled during arm (preresolved promises), drain now and
2007 * hand the parked response back directly - no deferred/promise pair,
2008 * no then(materialize) chain (resolve_frame stashes it on the exec
2009 * state). A drain that merely uncovers the next pending wave falls
2010 * through to the promise path below. Only the parentless response
2011 * frame may be armed before taking a reference: its resolve path
2012 * cannot free it while it still has pendings. */
2013 3697 ▶ if (resolve_response && !frame->deferred_sv && !saved_draining) {
Branch: 3 branches
BranchTrueFalseTotal
if (resolve_response && !frame->deferred_sv && !saved_draining) { 1567 2130 3697
if (resolve_response && !frame->deferred_sv && !saved_draining) { 1567 0 1567
if (resolve_response && !frame->deferred_sv && !saved_draining) { 1567 0 1567
2014 1567 exec_state->async_scheduler_draining = 1;
2015 1567 gql_runtime_vm_async_scheduler_arm_frame(aTHX_ state_sv, exec_state, frame);
2016 1567 exec_state->async_scheduler_draining = saved_draining;
2017 1567 armed = 1;
2018  
2019 1567 ▶ if (frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_unresolved == 0) { 25 1542 1567
2020 25 gql_runtime_vm_async_scheduler_enqueue_frame(exec_state, frame);
2021 25 gql_runtime_vm_async_scheduler_drain(aTHX_ state_sv, exec_state);
2022 25 ▶ if (exec_state->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (exec_state->completed_response_sv) { 25 0 25
2023 25 return newSVsv(&PL_sv_undef);
2024 }
2025 }
2026 }
2027  
2028 3672 ▶ if (return_promise && !frame->deferred_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (return_promise && !frame->deferred_sv) { 72 3600 3672
if (return_promise && !frame->deferred_sv) { 72 0 72
2029 72 frame->deferred_sv = gql_runtime_vm_adapter_new_deferred_sv(aTHX_ async_adapter);
2030 70 frame->promise_sv = gql_runtime_vm_adapter_deferred_promise_sv(
2031 aTHX_ async_adapter, frame->deferred_sv
2032 );
2033 }
2034 3670 ret_sv = return_promise
2035 70 ▶ ? (frame->promise_sv ? newSVsv(frame->promise_sv) : newSVsv(&PL_sv_undef))
Branch: 1 branch
BranchTrueFalseTotal
? (frame->promise_sv ? newSVsv(frame->promise_sv) : newSVsv(&PL_sv_undef)) 70 0 70
2036 3740 ▶ : gql_runtime_vm_wrap_block_frame_sv(aTHX_ frame);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_wrap_block_frame_sv(aTHX_ frame); 70 3600 3670
2037  
2038 3670 ▶ if (!armed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!armed) { 2130 1540 3670
2039 2130 exec_state->async_scheduler_draining = 1;
2040 2130 gql_runtime_vm_async_scheduler_arm_frame(aTHX_ state_sv, exec_state, frame);
2041 2130 exec_state->async_scheduler_draining = saved_draining;
2042 }
2043  
2044 3670 ▶ if (return_promise && frame->pending_unresolved == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (return_promise && frame->pending_unresolved == 0) { 70 3600 3670
if (return_promise && frame->pending_unresolved == 0) { 0 70 70
2045 0 gql_runtime_vm_async_scheduler_enqueue_frame(exec_state, frame);
2046 0 ▶ if (!exec_state->async_scheduler_draining) {
Branch: 1 branch
BranchTrueFalseTotal
if (!exec_state->async_scheduler_draining) { 0 0 0
2047 0 gql_runtime_vm_async_scheduler_drain(aTHX_ state_sv, exec_state);
2048 }
2049 }
2050 3670 return ret_sv;
2051 }
2052  
2053 0 Zero(&next_pending, 1, gql_runtime_vm_block_frame_t);
2054 0 ▶ for (i = 0; i < frame->pending_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < frame->pending_count; i++) { 0 0 0
2055 0 ▶ if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_OUTCOME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_OUTCOME_PTR) { 0 0 0
2056 0 gql_runtime_vm_consume_outcome_native_object(
2057 aTHX_
2058 frame->values_value,
2059 0 frame->pending_entries[i].result_name_pv,
2060 0 frame->pending_entries[i].result_name_pv_borrowed,
2061 0 frame->pending_entries[i].payload.outcome_ptr,
2062 writer
2063 );
2064 } else {
2065 0 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
2066 aTHX_
2067 &next_pending,
2068 0 frame->pending_entries[i].result_name_pv,
2069 0 frame->pending_entries[i].result_name_len,
2070 0 frame->pending_entries[i].result_name_pv_borrowed,
2071 0 frame->pending_entries[i].payload.promise_sv,
2072 0 frame->pending_entries[i].payload_kind,
2073 0 frame->pending_entries[i].path_frame,
2074 0 frame->pending_entries[i].block_index,
2075 0 frame->pending_entries[i].slot_index,
2076 0 frame->pending_entries[i].op_index,
2077 async_adapter
2078 );
2079 }
2080 }
2081 0 gql_runtime_vm_block_frame_clear_pending(aTHX_ frame);
2082 /* clear_pending retains the array for pooled reuse; this frame swaps in
2083 * the rebuilt one instead, so the old buffer must go now. */
2084 0 Safefree(frame->pending_entries);
2085 0 frame->pending_entries = next_pending.pending_entries;
2086 0 frame->pending_count = next_pending.pending_count;
2087 0 frame->pending_capacity = next_pending.pending_capacity;
2088  
2089 0 ▶ if (frame->pending_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_count == 0) { 0 0 0
2090 0 return gql_runtime_vm_native_value_materialize_sv(aTHX_ frame->values_value);
2091 }
2092  
2093 0 pending_av = newAV();
2094 0 ▶ for (i = 0; i < frame->pending_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < frame->pending_count; i++) { 0 0 0
2095 0 ▶ if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_SV
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_SV 0 0 0
2096 0 ▶ || frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV
Branch: 1 branch
BranchTrueFalseTotal
|| frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV 0 0 0
2097 0 ▶ || frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV) {
Branch: 1 branch
BranchTrueFalseTotal
|| frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV) { 0 0 0
2098 0 ▶ av_push(
Branch: 1 branch
BranchTrueFalseTotal
av_push( 0 0 0
2099 pending_av,
2100 newSVsv(
2101 frame->pending_entries[i].payload.promise_sv
2102 ? frame->pending_entries[i].payload.promise_sv
2103 : &PL_sv_undef
2104 )
2105 );
2106 } else {
2107 0 av_push(pending_av, newSVsv(&PL_sv_undef));
2108 }
2109 }
2110 0 aggregate = gql_runtime_vm_call_all_adapter_sv(
2111 aTHX_ async_adapter, pending_av, NULL
2112 );
2113 0 SvREFCNT_dec((SV *)pending_av);
2114  
2115 0 ▶ if (aggregate && SvOK(aggregate) && gql_runtime_vm_sv_is_outcome(aTHX_ aggregate)) {
Branch: 3 branches
BranchTrueFalseTotal
if (aggregate && SvOK(aggregate) && gql_runtime_vm_sv_is_outcome(aTHX_ aggregate)) { 0 0 0
if (aggregate && SvOK(aggregate) && gql_runtime_vm_sv_is_outcome(aTHX_ aggregate)) { 0 0 0
if (aggregate && SvOK(aggregate) && gql_runtime_vm_sv_is_outcome(aTHX_ aggregate)) { 0 0 0
2116 0 return aggregate;
2117 }
2118  
2119 {
2120 gql_runtime_vm_pending_merge_t *merge;
2121 SV *callback_sv;
2122 SV *retval;
2123  
2124 0 Newxz(merge, 1, gql_runtime_vm_pending_merge_t);
2125 0 merge->refcount = 1;
2126 0 merge->frame = frame;
2127 0 frame->refcount++;
2128 0 merge->writer = writer;
2129 0 gql_runtime_vm_writer_incref(writer);
2130 0 ▶ merge->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
merge->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL; 0 0 0
2131 0 callback_sv = gql_runtime_vm_new_finalize_callback_sv(aTHX_ merge);
2132 0 gql_runtime_vm_pending_merge_decref(aTHX_ merge);
2133  
2134 0 retval = gql_runtime_vm_call_then_adapter_sv(
2135 aTHX_ async_adapter, aggregate, callback_sv, NULL, NULL
2136 );
2137  
2138 0 SvREFCNT_dec(aggregate);
2139 0 SvREFCNT_dec(callback_sv);
2140 0 return retval;
2141 }
2142 }
2143  
2144 static SV *
2145 17153 gql_runtime_vm_fetch_hash_entry_sv(pTHX_ HV *hv, const char *key, I32 keylen)
2146 {
2147 17153 SV **svp = hv_fetch(hv, key, keylen, 0);
2148 17153 ▶ return (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
return (svp && SvOK(*svp)) ? *svp : NULL; 12565 4588 17153
return (svp && SvOK(*svp)) ? *svp : NULL; 12565 0 12565
2149 }
2150  
2151 static const char *
2152 152 gql_runtime_vm_fetch_hash_entry_pv(pTHX_ HV *hv, const char *key, I32 keylen)
2153 {
2154 152 SV *sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ hv, key, keylen);
2155 304 ▶ return sv ? SvPV_nolen(sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return sv ? SvPV_nolen(sv) : NULL; 152 0 152
2156 }
2157  
2158 static int
2159 117 gql_runtime_vm_is_promise_xs_value_sv(SV *value)
2160 {
2161 117 return gql_runtime_vm_sv_is_promise_xs(aTHX_ value);
2162 }
2163  
2164 static int
2165 4623 gql_runtime_vm_is_promise_value_for_state_sv(
2166 pTHX_
2167 const gql_runtime_vm_exec_state_handle_t *s,
2168 SV *value
2169 )
2170 {
2171 4623 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 4623 0 4623
if (!value || !SvOK(value)) { 353 4270 4623
2172 353 return 0;
2173 }
2174 4270 ▶ if (s && s->async_adapter != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if (s && s->async_adapter != NULL) { 4270 0 4270
if (s && s->async_adapter != NULL) { 4270 0 4270
2175 4270 return gql_runtime_vm_sv_is_adapter_promise(
2176 4270 aTHX_ s->async_adapter, value
2177 )
2178 6804 ▶ || (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ value)
Branch: 2 branches
BranchTrueFalseTotal
|| (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ value) 4077 193 4270
|| (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ value) 2534 1543 4077
2179 2534 ▶ && gql_runtime_vm_dataloader_ticket_state(aTHX_ value) == 0);
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_dataloader_ticket_state(aTHX_ value) == 0); 2534 0 2534
2180 }
2181 0 return 0;
2182 }
2183  
2184 static SV *
2185 1 gql_runtime_vm_call_callback_scalar_sv(
2186 pTHX_
2187 SV *callback_sv,
2188 SV *arg_sv,
2189 gql_runtime_vm_path_frame_t *path_frame
2190 )
2191 {
2192 1 dSP;
2193 1 SV *ret = NULL;
2194  
2195 1 ▶ if (!callback_sv || !SvOK(callback_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!callback_sv || !SvOK(callback_sv)) { 1 0 1
if (!callback_sv || !SvOK(callback_sv)) { 0 1 1
2196 0 return newSVsv(&PL_sv_undef);
2197 }
2198  
2199 1 ENTER;
2200 1 SAVETMPS;
2201 1 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 1 0 1
2202 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
2203 1 ▶ XPUSHs(arg_sv ? arg_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg_sv ? arg_sv : &PL_sv_undef); 0 1 1
XPUSHs(arg_sv ? arg_sv : &PL_sv_undef); 1 0 1
2204 1 PUTBACK;
2205 1 call_sv(callback_sv, G_SCALAR | G_EVAL);
2206 1 SPAGAIN;
2207 1 ▶ if (!SvTRUE(ERRSV) && SP > PL_stack_base) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 1 0 1
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 1 0 1
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 1 0 1
2208 1 SV *stack_ret = POPs;
2209 1 ▶ ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef); 1 0 1
2210 0 ▶ } else if (SP > PL_stack_base) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (SP > PL_stack_base) { 0 0 0
2211 0 (void)POPs;
2212 }
2213 1 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1 0 1
if (SvTRUE(ERRSV)) { 0 1 1
2214 0 ret = gql_runtime_vm_new_error_outcome_for_path_sv(
2215 aTHX_
2216 0 ▶ ERRSV,
Branch: 1 branch
BranchTrueFalseTotal
ERRSV, 0 0 0
2217 path_frame
2218 );
2219 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
2220 }
2221 1 PUTBACK;
2222 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1 0 1
2223 1 LEAVE;
2224  
2225 1 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 1 1
2226 }
2227  
2228 static SV *
2229 0 gql_runtime_vm_named_coderef_sv(pTHX_ const char *name)
2230 {
2231 0 ▶ CV *cv = name ? get_cv(name, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
CV *cv = name ? get_cv(name, 0) : NULL; 0 0 0
2232 0 ▶ return cv ? newRV_inc((SV *)cv) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return cv ? newRV_inc((SV *)cv) : newSVsv(&PL_sv_undef); 0 0 0
2233 }
2234  
2235 static void
2236 3718 gql_runtime_vm_async_scheduler_enqueue_frame(gql_runtime_vm_exec_state_handle_t *s, gql_runtime_vm_block_frame_t *frame)
2237 {
2238 3718 ▶ if (!s || !frame || frame->queued) {
Branch: 3 branches
BranchTrueFalseTotal
if (!s || !frame || frame->queued) { 3718 0 3718
if (!s || !frame || frame->queued) { 3718 0 3718
if (!s || !frame || frame->queued) { 33 3685 3718
2239 33 return;
2240 }
2241 3685 ▶ if (s->async_ready_frame_count == s->async_ready_frame_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->async_ready_frame_count == s->async_ready_frame_capacity) { 1550 2135 3685
2242 1550 ▶ IV new_cap = s->async_ready_frame_capacity ? s->async_ready_frame_capacity * 2 : 4;
Branch: 1 branch
BranchTrueFalseTotal
IV new_cap = s->async_ready_frame_capacity ? s->async_ready_frame_capacity * 2 : 4; 0 1550 1550
2243 1550 ▶ Renew(s->async_ready_frames, new_cap, gql_runtime_vm_block_frame_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(s->async_ready_frames, new_cap, gql_runtime_vm_block_frame_t *); 0 1550 1550
2244 1550 s->async_ready_frame_capacity = new_cap;
2245 }
2246 3685 s->async_ready_frames[s->async_ready_frame_count++] = frame;
2247 3685 frame->queued = 1;
2248 }
2249  
2250 static void
2251 8 gql_runtime_vm_async_pending_entry_store_outcome(
2252 pTHX_
2253 gql_runtime_vm_pending_entry_t *entry,
2254 SV *outcome_sv
2255 )
2256 {
2257 gql_runtime_vm_outcome_t *outcome_ptr;
2258  
2259 8 ▶ if (!entry || !outcome_sv || !SvOK(outcome_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!entry || !outcome_sv || !SvOK(outcome_sv)) { 8 0 8
if (!entry || !outcome_sv || !SvOK(outcome_sv)) { 8 0 8
if (!entry || !outcome_sv || !SvOK(outcome_sv)) { 0 8 8
2260 0 return;
2261 }
2262  
2263 8 outcome_ptr = gql_runtime_vm_expect_outcome(aTHX_ outcome_sv);
2264 8 gql_runtime_vm_outcome_incref(outcome_ptr);
2265  
2266 8 ▶ if (entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) { 0 8 8
2267 0 gql_runtime_vm_outcome_decref(aTHX_ entry->payload.outcome_ptr);
2268 8 ▶ } else if (entry->payload.promise_sv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload.promise_sv) { 8 0 8
2269 8 SvREFCNT_dec(entry->payload.promise_sv);
2270 }
2271  
2272 8 entry->payload_kind = GQL_VM_PENDING_OUTCOME_PTR;
2273 8 entry->payload.outcome_ptr = outcome_ptr;
2274 8 entry->state_code = GQL_VM_PENDING_STATE_READY_OUTCOME;
2275 }
2276  
2277 static void
2278 1263 gql_runtime_vm_async_pending_entry_store_outcome_ptr(
2279 pTHX_
2280 gql_runtime_vm_pending_entry_t *entry,
2281 gql_runtime_vm_outcome_t *outcome_ptr
2282 )
2283 {
2284 1263 ▶ if (!entry || !outcome_ptr) {
Branch: 2 branches
BranchTrueFalseTotal
if (!entry || !outcome_ptr) { 1263 0 1263
if (!entry || !outcome_ptr) { 0 1263 1263
2285 0 return;
2286 }
2287  
2288 1263 gql_runtime_vm_outcome_incref(outcome_ptr);
2289  
2290 1263 ▶ if (entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) { 0 1263 1263
2291 0 gql_runtime_vm_outcome_decref(aTHX_ entry->payload.outcome_ptr);
2292 1263 ▶ } else if (entry->payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR) { 1263 0 1263
2293 1263 gql_runtime_vm_free_block_frame(aTHX_ entry->payload.block_frame_ptr);
2294 0 ▶ } else if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR) { 0 0 0
2295 0 gql_runtime_vm_list_pending_decref(aTHX_ entry->payload.list_pending_ptr);
2296 0 ▶ } else if (entry->payload.promise_sv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload.promise_sv) { 0 0 0
2297 0 SvREFCNT_dec(entry->payload.promise_sv);
2298 }
2299  
2300 1263 entry->payload_kind = GQL_VM_PENDING_OUTCOME_PTR;
2301 1263 entry->payload.outcome_ptr = outcome_ptr;
2302 1263 entry->state_code = GQL_VM_PENDING_STATE_READY_OUTCOME;
2303 }
2304  
2305 static void
2306 1800 gql_runtime_vm_async_pending_entry_store_sv(
2307 pTHX_
2308 gql_runtime_vm_pending_entry_t *entry,
2309 SV *value_sv
2310 )
2311 {
2312 SV *copied_sv;
2313  
2314 1800 ▶ if (!entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (!entry) { 0 1800 1800
2315 0 return;
2316 }
2317  
2318 1800 ▶ copied_sv = gql_runtime_vm_snapshot_scalarish_value_sv(
Branch: 1 branch
BranchTrueFalseTotal
copied_sv = gql_runtime_vm_snapshot_scalarish_value_sv( 1800 0 1800
2319 aTHX_
2320 value_sv ? value_sv : &PL_sv_undef
2321 );
2322  
2323 1800 ▶ if (entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) { 0 1800 1800
2324 0 gql_runtime_vm_outcome_decref(aTHX_ entry->payload.outcome_ptr);
2325 1800 ▶ } else if (entry->payload.promise_sv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload.promise_sv) { 1800 0 1800
2326 1800 SvREFCNT_dec(entry->payload.promise_sv);
2327 }
2328  
2329 1800 entry->payload.promise_sv = copied_sv;
2330 1800 entry->state_code = GQL_VM_PENDING_STATE_READY_SV;
2331 }
2332  
2333 static void
2334 3012 gql_runtime_vm_native_list_store_at(
2335 pTHX_
2336 gql_runtime_vm_native_value_t *value,
2337 IV index,
2338 gql_runtime_vm_native_value_t *child
2339 )
2340 {
2341 gql_runtime_vm_native_list_t *list;
2342 IV i;
2343  
2344 3012 ▶ if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || index < 0 || !child) {
Branch: 4 branches
BranchTrueFalseTotal
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || index < 0 || !child) { 3012 0 3012
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || index < 0 || !child) { 3012 0 3012
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || index < 0 || !child) { 3012 0 3012
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || index < 0 || !child) { 0 3012 3012
2345 0 return;
2346 }
2347  
2348 3012 list = &value->list;
2349 3012 ▶ if (index >= list->capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (index >= list->capacity) { 45 2967 3012
2350 45 ▶ IV new_capacity = list->capacity ? list->capacity : 8;
Branch: 1 branch
BranchTrueFalseTotal
IV new_capacity = list->capacity ? list->capacity : 8; 0 45 45
2351 45 ▶ while (index >= new_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
while (index >= new_capacity) { 0 45 45
2352 0 new_capacity *= 2;
2353 }
2354 45 ▶ Renew(list->items, new_capacity, gql_runtime_vm_native_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(list->items, new_capacity, gql_runtime_vm_native_value_t *); 0 45 45
2355 405 ▶ for (i = list->capacity; i < new_capacity; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = list->capacity; i < new_capacity; i++) { 360 45 405
2356 360 list->items[i] = NULL;
2357 }
2358 45 list->capacity = new_capacity;
2359 }
2360  
2361 3012 ▶ if (list->items[index]) {
Branch: 1 branch
BranchTrueFalseTotal
if (list->items[index]) { 1503 1509 3012
2362 1503 gql_runtime_vm_native_value_destroy(aTHX_ list->items[index]);
2363 }
2364 3012 list->items[index] = child;
2365 3012 ▶ if (index >= list->count) {
Branch: 1 branch
BranchTrueFalseTotal
if (index >= list->count) { 1509 1503 3012
2366 1509 list->count = index + 1;
2367 }
2368 }
2369  
2370 static gql_runtime_vm_native_value_t *
2371 655 gql_runtime_vm_native_value_from_list_pending_sv(pTHX_ SV *value_sv)
2372 {
2373 655 ▶ if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) { 655 0 655
if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) { 652 3 655
if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) { 20 632 652
2374 20 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_expect_outcome(aTHX_ value_sv);
2375 20 ▶ return gql_runtime_vm_native_value_clone(aTHX_ outcome ? outcome->value : NULL);
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_native_value_clone(aTHX_ outcome ? outcome->value : NULL); 20 0 20
2376 }
2377 635 ▶ return gql_runtime_vm_native_value_from_sv(aTHX_ value_sv ? value_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_native_value_from_sv(aTHX_ value_sv ? value_sv : &PL_sv_undef); 635 0 635
2378 }
2379  
2380 /* Terminal conversion for freshly completed list items: the caller's AV
2381 * holds the only handle to each item outcome, so a sole-owner native
2382 * subtree is transferred rather than cloned. Promise resolution values go
2383 * through gql_runtime_vm_native_value_from_list_pending_sv instead - those
2384 * SVs can be aliased by the promise that produced them. */
2385 static gql_runtime_vm_native_value_t *
2386 293 gql_runtime_vm_native_value_take_completed_item_sv(pTHX_ SV *value_sv)
2387 {
2388 293 ▶ if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) { 293 0 293
if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) { 293 0 293
if (value_sv && SvOK(value_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ value_sv)) { 243 50 293
2389 243 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_expect_outcome(aTHX_ value_sv);
2390 243 ▶ if (outcome && outcome->refcount == 1 && outcome->value) {
Branch: 3 branches
BranchTrueFalseTotal
if (outcome && outcome->refcount == 1 && outcome->value) { 243 0 243
if (outcome && outcome->refcount == 1 && outcome->value) { 243 0 243
if (outcome && outcome->refcount == 1 && outcome->value) { 243 0 243
2391 243 gql_runtime_vm_native_value_t *taken = outcome->value;
2392 243 outcome->value = NULL;
2393 243 return taken;
2394 }
2395 0 ▶ return gql_runtime_vm_native_value_clone(aTHX_ outcome ? outcome->value : NULL);
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_native_value_clone(aTHX_ outcome ? outcome->value : NULL); 0 0 0
2396 }
2397 50 ▶ return gql_runtime_vm_native_value_from_sv(aTHX_ value_sv ? value_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_native_value_from_sv(aTHX_ value_sv ? value_sv : &PL_sv_undef); 50 0 50
2398 }
2399  
2400 static void
2401 1260 gql_runtime_vm_push_pending_block_frame(
2402 pTHX_
2403 gql_runtime_vm_block_frame_t *frame,
2404 const char *result_name_pv,
2405 STRLEN result_name_len,
2406 gql_runtime_vm_path_frame_t *path_frame,
2407 gql_runtime_vm_block_frame_t *child_frame,
2408 IV block_index,
2409 IV slot_index,
2410 IV op_index
2411 )
2412 {
2413 gql_runtime_vm_pending_entry_t *entry;
2414  
2415 1260 ▶ if (!frame || !child_frame || !result_name_pv || result_name_len == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (!frame || !child_frame || !result_name_pv || result_name_len == 0) { 1260 0 1260
if (!frame || !child_frame || !result_name_pv || result_name_len == 0) { 1260 0 1260
if (!frame || !child_frame || !result_name_pv || result_name_len == 0) { 1260 0 1260
if (!frame || !child_frame || !result_name_pv || result_name_len == 0) { 0 1260 1260
2416 0 return;
2417 }
2418  
2419 1260 entry = gql_runtime_vm_block_frame_push_pending_entry_with_meta(
2420 aTHX_
2421 frame,
2422 result_name_pv,
2423 result_name_len,
2424 1,
2425 path_frame,
2426 block_index,
2427 slot_index,
2428 op_index
2429 );
2430 1260 ▶ if (!entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (!entry) { 0 1260 1260
2431 0 return;
2432 }
2433  
2434 1260 entry->payload_kind = GQL_VM_PENDING_BLOCK_FRAME_PTR;
2435 1260 entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
2436 1260 entry->payload.block_frame_ptr = child_frame;
2437 1260 entry->payload.block_frame_ptr->refcount++;
2438 1260 frame->pending_unresolved++;
2439  
2440 1260 child_frame->parent_frame = frame;
2441 1260 child_frame->parent_frame->refcount++;
2442 1260 child_frame->parent_entry_index = frame->pending_count - 1;
2443 }
2444  
2445 static void
2446 645 gql_runtime_vm_push_pending_list_pending(
2447 pTHX_
2448 gql_runtime_vm_block_frame_t *frame,
2449 const char *result_name_pv,
2450 STRLEN result_name_len,
2451 gql_runtime_vm_path_frame_t *path_frame,
2452 gql_runtime_vm_list_pending_t *list_pending,
2453 IV block_index,
2454 IV slot_index,
2455 IV op_index
2456 )
2457 {
2458 gql_runtime_vm_pending_entry_t *entry;
2459  
2460 645 ▶ if (!frame || !list_pending || !result_name_pv || result_name_len == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (!frame || !list_pending || !result_name_pv || result_name_len == 0) { 645 0 645
if (!frame || !list_pending || !result_name_pv || result_name_len == 0) { 645 0 645
if (!frame || !list_pending || !result_name_pv || result_name_len == 0) { 645 0 645
if (!frame || !list_pending || !result_name_pv || result_name_len == 0) { 0 645 645
2461 0 return;
2462 }
2463  
2464 645 entry = gql_runtime_vm_block_frame_push_pending_entry_with_meta(
2465 aTHX_
2466 frame,
2467 result_name_pv,
2468 result_name_len,
2469 1,
2470 path_frame,
2471 block_index,
2472 slot_index,
2473 op_index
2474 );
2475 645 ▶ if (!entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (!entry) { 0 645 645
2476 0 return;
2477 }
2478  
2479 645 entry->payload_kind = GQL_VM_PENDING_LIST_PENDING_PTR;
2480 645 entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
2481 645 entry->payload.list_pending_ptr = list_pending;
2482 645 gql_runtime_vm_list_pending_incref(list_pending);
2483 645 frame->pending_unresolved++;
2484  
2485 645 ▶ if (list_pending->owner_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (list_pending->owner_frame) { 0 645 645
2486 0 gql_runtime_vm_free_block_frame(aTHX_ list_pending->owner_frame);
2487 }
2488 645 list_pending->owner_frame = frame;
2489 645 list_pending->owner_frame->refcount++;
2490 }
2491  
2492 /* Phase 11: link a suspending object/abstract list item's own child
2493 * block_frame_t directly into its list_pending slot, mirroring
2494 * gql_runtime_vm_push_pending_block_frame's two-directional refcounting
2495 * exactly (list_pending holds a ref to child_frame via
2496 * pending_child_frames[index]; child_frame holds a ref back to
2497 * list_pending via parent_list_pending) but targeting a list slot
2498 * instead of a parent frame's pending_entries array. Unlike
2499 * push_pending_block_frame, this does not touch pending_unresolved or
2500 * push a pending_entry - the caller (gql_runtime_vm_list_pending_handle_sv)
2501 * already accounts for this item in list_pending->unresolved_count the
2502 * same way it does for a promise-shaped item. */
2503 static void
2504 852 gql_runtime_vm_list_pending_link_child_frame(
2505 pTHX_
2506 gql_runtime_vm_list_pending_t *list_pending,
2507 IV index,
2508 gql_runtime_vm_block_frame_t *child_frame
2509 )
2510 {
2511 852 ▶ if (!list_pending || !child_frame || index < 0
Branch: 3 branches
BranchTrueFalseTotal
if (!list_pending || !child_frame || index < 0 852 0 852
if (!list_pending || !child_frame || index < 0 852 0 852
if (!list_pending || !child_frame || index < 0 852 0 852
2512 852 ▶ || index >= list_pending->pending_child_frame_count) {
Branch: 1 branch
BranchTrueFalseTotal
|| index >= list_pending->pending_child_frame_count) { 0 852 852
2513 0 return;
2514 }
2515 852 list_pending->pending_child_frames[index] = child_frame;
2516 852 child_frame->refcount++;
2517 852 gql_runtime_vm_list_pending_incref(list_pending);
2518 852 child_frame->parent_list_pending = list_pending;
2519 852 child_frame->parent_list_index = index;
2520 }
2521  
2522 static gql_runtime_vm_pending_callback_ctx_t *
2523 1827 gql_runtime_vm_new_pending_callback_pair(
2524 pTHX_
2525 SV *state_sv,
2526 gql_runtime_vm_block_frame_t *frame,
2527 IV entry_index,
2528 SV **resolve_rv_out,
2529 SV **reject_rv_out
2530 )
2531 {
2532 gql_runtime_vm_pending_callback_ctx_t *ctx;
2533  
2534 1827 ▶ if (gql_runtime_vm_pending_cb_pool_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_pending_cb_pool_count > 0) { 1730 97 1827
2535 1730 IV n = --gql_runtime_vm_pending_cb_pool_count;
2536 1730 SV *resolve_cv = gql_runtime_vm_pending_cb_pool_resolve[n];
2537 1730 SV *reject_cv = gql_runtime_vm_pending_cb_pool_reject[n];
2538  
2539 1730 gql_runtime_vm_pending_cb_pool_resolve[n] = NULL;
2540 1730 gql_runtime_vm_pending_cb_pool_reject[n] = NULL;
2541 1730 ctx = INT2PTR(
2542 gql_runtime_vm_pending_callback_ctx_t *,
2543 CvXSUBANY((CV *)resolve_cv).any_ptr
2544 );
2545 1730 ▶ ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL; 1730 0 1730
2546 1730 ctx->frame = frame;
2547 1730 ▶ if (ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { 1730 0 1730
2548 1730 ctx->frame->refcount++;
2549 }
2550 1730 ctx->entry_index = entry_index;
2551 /* The pool's CV refcounts transfer into the returned RVs. */
2552 1730 *resolve_rv_out = newRV_noinc(resolve_cv);
2553 1730 *reject_rv_out = newRV_noinc(reject_cv);
2554 1730 return ctx;
2555 }
2556  
2557 {
2558 CV *resolve_cv;
2559 CV *reject_cv;
2560  
2561 97 Newxz(ctx, 1, gql_runtime_vm_pending_callback_ctx_t);
2562 97 ▶ ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL; 97 0 97
2563 97 ctx->frame = frame;
2564 97 ▶ if (ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { 97 0 97
2565 97 ctx->frame->refcount++;
2566 }
2567 97 ctx->entry_index = entry_index;
2568 97 ctx->cv_refcnt = 2;
2569  
2570 97 resolve_cv = newXS(NULL, gql_runtime_vm_xs_pending_callback, __FILE__);
2571 97 CvXSUBANY(resolve_cv).any_ptr = ctx;
2572 97 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)resolve_cv, &gql_runtime_vm_pending_callback_ctx_vtbl, ctx);
2573 97 reject_cv = newXS(NULL, gql_runtime_vm_xs_pending_reject_callback, __FILE__);
2574 97 CvXSUBANY(reject_cv).any_ptr = ctx;
2575 97 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)reject_cv, &gql_runtime_vm_pending_callback_ctx_vtbl, ctx);
2576 97 ctx->resolve_cv = (SV *)resolve_cv;
2577 97 ctx->reject_cv = (SV *)reject_cv;
2578  
2579 97 *resolve_rv_out = newRV_noinc((SV *)resolve_cv);
2580 97 *reject_rv_out = newRV_noinc((SV *)reject_cv);
2581 97 return ctx;
2582 }
2583 }
2584  
2585 /* One arm fired: the promise has settled, so the other arm can never
2586 * fire. Drop the ctx's references now (parked callbacks must not keep the
2587 * exec state alive) and park the pair for the next arm to reuse. */
2588 static void
2589 1808 gql_runtime_vm_pending_callback_pair_recycle(
2590 pTHX_
2591 gql_runtime_vm_pending_callback_ctx_t *ctx
2592 )
2593 {
2594 1808 ▶ if (!ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ctx) { 0 1808 1808
2595 0 return;
2596 }
2597 1808 ▶ if (ctx->state_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state_sv) { 1808 0 1808
2598 1808 SvREFCNT_dec(ctx->state_sv);
2599 1808 ctx->state_sv = NULL;
2600 }
2601 1808 ▶ if (ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { 1808 0 1808
2602 1808 gql_runtime_vm_free_block_frame(aTHX_ ctx->frame);
2603 1808 ctx->frame = NULL;
2604 }
2605 1808 ctx->entry_index = -1;
2606 1808 ▶ if (ctx->resolve_cv && ctx->reject_cv && ctx->cv_refcnt == 2
Branch: 3 branches
BranchTrueFalseTotal
if (ctx->resolve_cv && ctx->reject_cv && ctx->cv_refcnt == 2 1808 0 1808
if (ctx->resolve_cv && ctx->reject_cv && ctx->cv_refcnt == 2 1808 0 1808
if (ctx->resolve_cv && ctx->reject_cv && ctx->cv_refcnt == 2 1808 0 1808
2607 1808 ▶ && gql_runtime_vm_pending_cb_pool_count < GQL_VM_PENDING_CB_POOL_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_pending_cb_pool_count < GQL_VM_PENDING_CB_POOL_MAX) { 1808 0 1808
2608 1808 gql_runtime_vm_pending_cb_pool_resolve[gql_runtime_vm_pending_cb_pool_count] =
2609 1808 SvREFCNT_inc_simple_NN(ctx->resolve_cv);
2610 1808 gql_runtime_vm_pending_cb_pool_reject[gql_runtime_vm_pending_cb_pool_count] =
2611 1808 SvREFCNT_inc_simple_NN(ctx->reject_cv);
2612 1808 gql_runtime_vm_pending_cb_pool_count++;
2613 }
2614 }
2615  
2616 /* Cancellation counterpart to gql_runtime_vm_pending_callback_pair_recycle:
2617 * an armed entry whose promise/ticket never settled (the request was
2618 * abandoned - on_stall died, or a stall was detected) still needs its
2619 * ctx's state_sv/frame references dropped, exactly like a normal settle
2620 * would, or they leak (a still-pending DataLoader Ticket's own subscriber
2621 * list - populated by gql_runtime_vm_subscribe_dataloader_ticket - holds
2622 * this ctx's resolve/reject CVs alive independent of anything the exec
2623 * state owns, since the ticket can outlive the request via the
2624 * DataLoader's own queue). Unlike recycle, this does NOT pool the CV
2625 * pair: the ticket/promise might still fire it later (a buggy caller
2626 * holding the loader past abandonment), and handing that live CV to an
2627 * unrelated future request would corrupt it. Left disarmed, the CV pair
2628 * is permanently inert instead - gql_runtime_vm_xs_pending_callback and
2629 * its reject counterpart already no-op once ctx->state_sv/ctx->frame are
2630 * NULL - trading the leak for a single bounded, harmless CV+ctx. */
2631 static void
2632 17 gql_runtime_vm_pending_callback_ctx_disarm(
2633 pTHX_
2634 gql_runtime_vm_pending_callback_ctx_t *ctx
2635 )
2636 {
2637 17 ▶ if (!ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ctx) { 0 17 17
2638 0 return;
2639 }
2640 17 ▶ if (ctx->state_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state_sv) { 17 0 17
2641 17 SvREFCNT_dec(ctx->state_sv);
2642 17 ctx->state_sv = NULL;
2643 }
2644 17 ▶ if (ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { 17 0 17
2645 17 gql_runtime_vm_free_block_frame(aTHX_ ctx->frame);
2646 17 ctx->frame = NULL;
2647 }
2648 17 ctx->entry_index = -1;
2649 }
2650  
2651 /* Shared by gql_runtime_vm_xs_list_pending_callback (a settled item that
2652 * arrived as a Promise::XS/Ticket) and
2653 * gql_runtime_vm_async_scheduler_resolve_frame's parent_list_pending
2654 * branch below (a settled item that was a raw linked child frame):
2655 * store the item's final native value and decrement unresolved_count.
2656 * Does not enqueue/drain owner_frame - callers differ on whether that's
2657 * safe/needed right here (a Promise::XS callback fires from outside any
2658 * active drain and must kick one off itself if owner_frame is now ready;
2659 * resolve_frame's branch runs from inside an active drain already and
2660 * only needs to enqueue, mirroring the existing parent_frame branch). */
2661 static void
2662 848 gql_runtime_vm_list_pending_store_item_value(
2663 pTHX_
2664 gql_runtime_vm_list_pending_t *pending,
2665 IV index,
2666 gql_runtime_vm_native_value_t *item_value
2667 )
2668 {
2669 848 gql_runtime_vm_native_list_store_at(aTHX_ pending->values_value, index, item_value);
2670 848 ▶ if (pending->unresolved_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (pending->unresolved_count > 0) { 848 0 848
2671 848 pending->unresolved_count--;
2672 }
2673 848 }
2674  
2675 static void
2676 3670 gql_runtime_vm_async_scheduler_resolve_frame(
2677 pTHX_
2678 gql_runtime_vm_exec_state_handle_t *s,
2679 gql_runtime_vm_block_frame_t *frame
2680 )
2681 {
2682 3670 SV *data_sv = NULL;
2683 SV *resolved_sv;
2684 IV i;
2685  
2686 3670 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 3670 3670
2687 0 return;
2688 }
2689  
2690 3670 ▶ if (s) {
Branch: 1 branch
BranchTrueFalseTotal
if (s) { 3670 0 3670
2691 3670 ▶ for (i = 0; i < s->async_ready_frame_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < s->async_ready_frame_count; i++) { 0 3670 3670
2692 0 ▶ if (s->async_ready_frames[i] == frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->async_ready_frames[i] == frame) { 0 0 0
2693 0 s->async_ready_frames[i] = NULL;
2694 }
2695 }
2696 }
2697 3670 frame->queued = 0;
2698  
2699 3670 ▶ if (frame->parent_frame && frame->parent_entry_index >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (frame->parent_frame && frame->parent_entry_index >= 0) { 1263 2407 3670
if (frame->parent_frame && frame->parent_entry_index >= 0) { 1263 0 1263
2700 1263 gql_runtime_vm_pending_entry_t *entry = NULL;
2701 1263 gql_runtime_vm_outcome_t *outcome = NULL;
2702  
2703 1263 ▶ if (frame->parent_entry_index < frame->parent_frame->pending_count) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->parent_entry_index < frame->parent_frame->pending_count) { 1263 0 1263
2704 1263 entry = &frame->parent_frame->pending_entries[frame->parent_entry_index];
2705 } else {
2706 /* Adoption re-pushes relink parent_entry_index, so this must not
2707 * happen; if it does, the child's result would vanish from the
2708 * response - make it loud instead of silent. */
2709 0 warn("GraphQL::Houtou: async child frame resolved with out-of-range parent entry index %" IVdf "; its result is dropped",
2710 frame->parent_entry_index);
2711 }
2712  
2713 1263 ▶ if (frame->self_nulled) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->self_nulled) { 3 1260 1263
2714 /* A non-null field of this frame was null: the frame resolves to
2715 * null (the originating error is already recorded), and the null
2716 * keeps propagating to this frame's own parent. */
2717 3 outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef);
2718 3 outcome->null_carries_error = 1;
2719 } else {
2720 1260 outcome = gql_runtime_vm_new_outcome_from_owned_native_value_struct(
2721 aTHX_
2722 GQL_VM_KIND_OBJECT,
2723 frame->values_value
2724 );
2725 1260 frame->values_value = NULL;
2726 }
2727  
2728 1263 ▶ if (entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry) { 1263 0 1263
2729 1263 gql_runtime_vm_async_pending_entry_store_outcome_ptr(aTHX_ entry, outcome);
2730 }
2731  
2732 1263 ▶ if (frame->parent_frame->pending_unresolved > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->parent_frame->pending_unresolved > 0) { 1263 0 1263
2733 1263 frame->parent_frame->pending_unresolved--;
2734 }
2735 1263 ▶ if (frame->parent_frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->parent_frame->pending_unresolved == 0) { 1263 0 1263
2736 /* A parent still on the exec stack is mid-block-loop; enqueuing it
2737 * now would let the drain resolve (and free) it under the loop's
2738 * feet. Its own finalize arms the READY entries and enqueues. */
2739 1263 U8 parent_executing = 0;
2740 1263 ▶ if (s) {
Branch: 1 branch
BranchTrueFalseTotal
if (s) { 1263 0 1263
2741 IV fi;
2742 1263 ▶ for (fi = 0; fi < s->frame_stack_count; fi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (fi = 0; fi < s->frame_stack_count; fi++) { 1 1262 1263
2743 1 ▶ if (s->frame_stack[fi] == frame->parent_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack[fi] == frame->parent_frame) { 1 0 1
2744 1 parent_executing = 1;
2745 1 break;
2746 }
2747 }
2748 }
2749 1263 ▶ if (!parent_executing) {
Branch: 1 branch
BranchTrueFalseTotal
if (!parent_executing) { 1262 1 1263
2750 1262 gql_runtime_vm_async_scheduler_enqueue_frame(s, frame->parent_frame);
2751 }
2752 }
2753  
2754 1263 gql_runtime_vm_outcome_decref(aTHX_ outcome);
2755 1263 gql_runtime_vm_free_block_frame(aTHX_ frame);
2756 1263 return;
2757 }
2758  
2759 2407 ▶ if (frame->parent_list_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->parent_list_pending) { 848 1559 2407
2760 /* Phase 11: this frame is a suspending list item's own child block,
2761 * linked directly into its list_pending slot
2762 * (gql_runtime_vm_list_pending_link_child_frame) instead of ever
2763 * having a Promise::XS built for it. Take its native value straight
2764 * across (no SV materialize/outcome-wrap round trip) - mirrors the
2765 * parent_frame branch above exactly, targeting a list slot instead
2766 * of a pending_entries array index. */
2767 848 gql_runtime_vm_list_pending_t *list_pending = frame->parent_list_pending;
2768 848 IV list_index = frame->parent_list_index;
2769 gql_runtime_vm_native_value_t *item_value;
2770  
2771 848 ▶ if (frame->self_nulled) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->self_nulled) { 1 847 848
2772 /* The original "Cannot return null" error is already recorded
2773 * (same comment as the parent_frame branch above); the item slot
2774 * itself just becomes null. */
2775 1 item_value = gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
2776 } else {
2777 847 item_value = frame->values_value;
2778 847 frame->values_value = NULL;
2779 }
2780  
2781 848 ▶ if (list_index >= 0 && list_index < list_pending->pending_child_frame_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (list_index >= 0 && list_index < list_pending->pending_child_frame_count) { 848 0 848
if (list_index >= 0 && list_index < list_pending->pending_child_frame_count) { 848 0 848
2782 /* Drop the reference gql_runtime_vm_list_pending_link_child_frame
2783 * took out on frame's behalf (pending_child_frames[index] holding
2784 * it) - mirrors gql_runtime_vm_async_pending_entry_store_outcome_ptr
2785 * dropping the BLOCK_FRAME_PTR entry's own held ref in the
2786 * parent_frame branch above. This is a SEPARATE reference from the
2787 * creation reference the explicit free_block_frame call below
2788 * drops - both are needed, exactly like that branch's two calls
2789 * (one inside store_outcome_ptr, one explicit at its tail). */
2790 848 list_pending->pending_child_frames[list_index] = NULL;
2791 848 gql_runtime_vm_free_block_frame(aTHX_ frame);
2792 }
2793 848 gql_runtime_vm_list_pending_store_item_value(aTHX_ list_pending, list_index, item_value);
2794  
2795 848 ▶ if (list_pending->unresolved_count == 0 && list_pending->owner_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (list_pending->unresolved_count == 0 && list_pending->owner_frame) { 421 427 848
if (list_pending->unresolved_count == 0 && list_pending->owner_frame) { 421 0 421
2796 /* Same "don't enqueue a frame still mid-block-loop on the exec
2797 * stack" guard as the parent_frame branch above - list_pending's
2798 * owner_frame can just as easily still be executing (this branch
2799 * can fire synchronously, from list_pending_handle_sv's own
2800 * immediate-settle check, while the owning block's op loop hasn't
2801 * returned yet). */
2802 421 U8 owner_executing = 0;
2803 421 ▶ if (s) {
Branch: 1 branch
BranchTrueFalseTotal
if (s) { 421 0 421
2804 IV fi;
2805 421 ▶ for (fi = 0; fi < s->frame_stack_count; fi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (fi = 0; fi < s->frame_stack_count; fi++) { 0 421 421
2806 0 ▶ if (s->frame_stack[fi] == list_pending->owner_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack[fi] == list_pending->owner_frame) { 0 0 0
2807 0 owner_executing = 1;
2808 0 break;
2809 }
2810 }
2811 }
2812 421 ▶ if (!owner_executing) {
Branch: 1 branch
BranchTrueFalseTotal
if (!owner_executing) { 421 0 421
2813 421 gql_runtime_vm_async_scheduler_enqueue_frame(s, list_pending->owner_frame);
2814 }
2815 }
2816  
2817 848 gql_runtime_vm_list_pending_decref(aTHX_ list_pending);
2818 848 gql_runtime_vm_free_block_frame(aTHX_ frame);
2819 848 return;
2820 }
2821  
2822 /* Non-Null propagation reached the operation root: data is null (spec
2823 * 6.4.4). Drop the partial object so both response tails emit null. */
2824 1559 ▶ if (frame->self_nulled && frame->values_value) {
Branch: 2 branches
BranchTrueFalseTotal
if (frame->self_nulled && frame->values_value) { 1 1558 1559
if (frame->self_nulled && frame->values_value) { 1 0 1
2825 1 gql_runtime_vm_native_value_destroy(aTHX_ frame->values_value);
2826 1 frame->values_value = NULL;
2827 }
2828  
2829 1559 ▶ if (frame->deferred_resolves_response && s->response_json_mode) {
Branch: 2 branches
BranchTrueFalseTotal
if (frame->deferred_resolves_response && s->response_json_mode) { 1550 9 1559
if (frame->deferred_resolves_response && s->response_json_mode) { 13 1537 1550
2830 13 resolved_sv = gql_runtime_vm_response_json_from_native_sv(
2831 13 aTHX_ s->writer, frame->values_value
2832 );
2833 } else {
2834 1546 data_sv = gql_runtime_vm_native_value_materialize_sv(aTHX_ frame->values_value);
2835 1546 resolved_sv = data_sv;
2836 1546 ▶ if (frame->deferred_resolves_response) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->deferred_resolves_response) { 1537 9 1546
2837 1537 resolved_sv = gql_runtime_vm_exec_state_materialize_response_sv(aTHX_ s, data_sv);
2838 1537 SvREFCNT_dec(data_sv);
2839 }
2840 }
2841  
2842 1559 ▶ if (frame->deferred_sv && SvOK(frame->deferred_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (frame->deferred_sv && SvOK(frame->deferred_sv)) { 66 1493 1559
if (frame->deferred_sv && SvOK(frame->deferred_sv)) { 66 0 66
2843 66 gql_runtime_vm_adapter_deferred_resolve_sv(
2844 aTHX_ s->async_adapter, frame->deferred_sv, resolved_sv
2845 );
2846 66 SvREFCNT_dec(resolved_sv);
2847 1493 ▶ } else if (frame->deferred_resolves_response) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (frame->deferred_resolves_response) { 1493 0 1493
2848 /* No deferred was ever created: the request is completing inside the
2849 * original execute call. Park the finished response (envelope or JSON
2850 * per json_mode) on the exec state for the entry point to return. */
2851 1493 ▶ if (s->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->completed_response_sv) { 0 1493 1493
2852 0 SvREFCNT_dec(s->completed_response_sv);
2853 }
2854 1493 s->completed_response_sv = resolved_sv;
2855 } else {
2856 0 SvREFCNT_dec(resolved_sv);
2857 }
2858 1559 ▶ if (frame->deferred_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->deferred_sv) { 66 1493 1559
2859 66 SvREFCNT_dec(frame->deferred_sv);
2860 66 frame->deferred_sv = NULL;
2861 }
2862 1559 ▶ if (s->response_frame == frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->response_frame == frame) { 1550 9 1559
2863 1550 s->response_frame = NULL;
2864 }
2865 1559 ▶ if (frame->promise_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->promise_sv) { 66 1493 1559
2866 66 SvREFCNT_dec(frame->promise_sv);
2867 66 frame->promise_sv = NULL;
2868 }
2869 1559 gql_runtime_vm_free_block_frame(aTHX_ frame);
2870 }
2871  
2872 static void
2873 3712 gql_runtime_vm_async_scheduler_arm_frame(
2874 pTHX_
2875 SV *state_sv,
2876 gql_runtime_vm_exec_state_handle_t *s,
2877 gql_runtime_vm_block_frame_t *frame
2878 )
2879 {
2880 IV i;
2881  
2882 3712 ▶ if (!s || !frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (!s || !frame) { 3712 0 3712
if (!s || !frame) { 0 3712 3712
2883 0 return;
2884 }
2885  
2886 3712 frame->pending_unresolved = 0;
2887 7459 ▶ for (i = 0; i < frame->pending_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < frame->pending_count; i++) { 3747 3712 7459
2888 3747 gql_runtime_vm_pending_entry_t *entry = &frame->pending_entries[i];
2889  
2890 3747 ▶ if (entry->state_code == GQL_VM_PENDING_STATE_WAITING_ARMED) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->state_code == GQL_VM_PENDING_STATE_WAITING_ARMED) { 1919 1828 3747
2891 1919 ▶ if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR 650 1269 1919
2892 650 ▶ && entry->payload.list_pending_ptr
Branch: 1 branch
BranchTrueFalseTotal
&& entry->payload.list_pending_ptr 650 0 650
2893 650 ▶ && entry->payload.list_pending_ptr->unresolved_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
&& entry->payload.list_pending_ptr->unresolved_count == 0) { 10 640 650
2894 10 continue;
2895 }
2896 1909 frame->pending_unresolved++;
2897 1909 continue;
2898 }
2899 1828 ▶ if (entry->state_code != GQL_VM_PENDING_STATE_WAITING_UNARMED) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->state_code != GQL_VM_PENDING_STATE_WAITING_UNARMED) { 1 1827 1828
2900 1 continue;
2901 }
2902  
2903 1827 entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
2904 1827 frame->pending_unresolved++;
2905  
2906 {
2907 SV *callback_sv;
2908 /* The reject arm settles the entry directly: promises land here
2909 * unnormalized (then_complete pushes the user promise itself), and
2910 * an outcome returned into the discarded derived promise would be
2911 * lost, deadlocking the frame. */
2912 SV *error_callback_sv;
2913 gql_runtime_vm_pending_callback_ctx_t *pair_ctx =
2914 1827 gql_runtime_vm_new_pending_callback_pair(
2915 aTHX_ state_sv, frame, i, &callback_sv, &error_callback_sv
2916 );
2917 SV *ret;
2918  
2919 /* Record the armed context so a process_frame re-push can retarget
2920 * its entry_index when this entry moves in the rebuilt array. */
2921 1827 entry->armed_resolve_ctx = pair_ctx;
2922 1827 entry->armed_reject_ctx = pair_ctx;
2923  
2924 1827 ▶ if (gql_runtime_vm_sv_is_dataloader_ticket(
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_dataloader_ticket( 1766 61 1827
2925 aTHX_ entry->payload.promise_sv
2926 )) {
2927 1766 gql_runtime_vm_subscribe_dataloader_ticket(
2928 aTHX_
2929 entry->payload.promise_sv,
2930 callback_sv,
2931 error_callback_sv
2932 );
2933 1766 ret = NULL;
2934 } else {
2935 61 ret = gql_runtime_vm_call_then_promise_for_state_sv(
2936 aTHX_
2937 s,
2938 entry->payload.promise_sv,
2939 callback_sv,
2940 error_callback_sv,
2941 entry->path_frame
2942 );
2943 }
2944  
2945 1827 SvREFCNT_dec(callback_sv);
2946 1827 SvREFCNT_dec(error_callback_sv);
2947  
2948 1827 ▶ if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) {
Branch: 3 branches
BranchTrueFalseTotal
if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) { 61 1766 1827
if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) { 61 0 61
if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) { 0 61 61
2949 0 gql_runtime_vm_async_pending_entry_store_outcome(aTHX_ entry, ret);
2950 0 ▶ if (frame->pending_unresolved > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_unresolved > 0) { 0 0 0
2951 0 frame->pending_unresolved--;
2952 }
2953 }
2954 1827 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 61 1766 1827
2955 61 SvREFCNT_dec(ret);
2956 }
2957 }
2958 }
2959 }
2960  
2961 /* Record the spec's "Cannot return null for non-nullable field
2962 * Parent.field." error at `path_frame` on the async lane's writer. */
2963 static void
2964 10 gql_runtime_vm_record_nonnull_violation(
2965 pTHX_
2966 gql_runtime_vm_writer_t *writer,
2967 const char *parent_type_name,
2968 const char *field_name,
2969 gql_runtime_vm_path_frame_t *path_frame
2970 )
2971 {
2972 SV *msg_sv;
2973 gql_runtime_vm_outcome_t *err;
2974 IV j;
2975  
2976 10 ▶ if (!writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (!writer) { 0 10 10
2977 0 return;
2978 }
2979 10 ▶ msg_sv = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
msg_sv = newSVpvf( 10 0 10
msg_sv = newSVpvf( 10 0 10
2980 "Cannot return null for non-nullable field %s.%s.",
2981 parent_type_name ? parent_type_name : "(unknown)",
2982 field_name ? field_name : "(unknown)"
2983 );
2984 10 err = gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ msg_sv, path_frame);
2985 10 SvREFCNT_dec(msg_sv);
2986 10 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 10 0 10
2987 20 ▶ for (j = 0; j < err->error_record_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < err->error_record_count; j++) { 10 10 20
2988 10 gql_runtime_vm_writer_push_error_record(writer, err->error_records[j]);
2989 }
2990 10 gql_runtime_vm_outcome_decref(aTHX_ err);
2991 }
2992 }
2993  
2994 /* Non-Null list items ([T!]) for a list settled through the list_pending
2995 * machinery: a null item nulls the whole list. Records one error per null
2996 * item (with the item index in its path) and converts the outcome to a
2997 * null that carries its error, so the field-level check below propagates
2998 * it without stacking another message. */
2999 static void
3000 646 gql_runtime_vm_outcome_enforce_list_item_nonnull(
3001 pTHX_
3002 gql_runtime_vm_exec_state_handle_t *s,
3003 const gql_runtime_vm_pending_entry_t *entry,
3004 gql_runtime_vm_outcome_t *outcome
3005 )
3006 {
3007 const gql_runtime_vm_native_block_t *block;
3008 const gql_runtime_vm_native_slot_t *slot;
3009 646 int violated = 0;
3010 IV i;
3011  
3012 646 ▶ if (!s || !s->native_program || !outcome || !outcome->value
Branch: 4 branches
BranchTrueFalseTotal
if (!s || !s->native_program || !outcome || !outcome->value 646 0 646
if (!s || !s->native_program || !outcome || !outcome->value 646 0 646
if (!s || !s->native_program || !outcome || !outcome->value 646 0 646
if (!s || !s->native_program || !outcome || !outcome->value 646 0 646
3013 646 ▶ || outcome->value->kind_code != GQL_VM_NATIVE_VALUE_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
|| outcome->value->kind_code != GQL_VM_NATIVE_VALUE_LIST) { 0 646 646
3014 0 return;
3015 }
3016 646 ▶ if (entry->block_index < 0 || entry->block_index >= s->native_program->block_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (entry->block_index < 0 || entry->block_index >= s->native_program->block_count) { 646 0 646
if (entry->block_index < 0 || entry->block_index >= s->native_program->block_count) { 0 646 646
3017 0 return;
3018 }
3019 646 block = &s->native_program->blocks[entry->block_index];
3020 646 ▶ if (entry->slot_index < 0 || entry->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (entry->slot_index < 0 || entry->slot_index >= block->slot_count) { 646 0 646
if (entry->slot_index < 0 || entry->slot_index >= block->slot_count) { 0 646 646
3021 0 return;
3022 }
3023 646 slot = &block->slots[entry->slot_index];
3024 646 ▶ if (!slot->item_non_null) {
Branch: 1 branch
BranchTrueFalseTotal
if (!slot->item_non_null) { 639 7 646
3025 639 return;
3026 }
3027  
3028 26 ▶ for (i = 0; i < outcome->value->list.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < outcome->value->list.count; i++) { 19 7 26
3029 19 ▶ if (!gql_runtime_vm_native_value_is_null(outcome->value->list.items[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_native_value_is_null(outcome->value->list.items[i])) { 17 2 19
3030 17 continue;
3031 }
3032 2 violated = 1;
3033 {
3034 2 SV *item_key = newSViv(i);
3035 gql_runtime_vm_path_frame_t *item_path =
3036 2 gql_runtime_vm_new_path_frame_struct(aTHX_ entry->path_frame, item_key);
3037 2 gql_runtime_vm_record_nonnull_violation(
3038 2 aTHX_ s->writer, block->type_name, slot->field_name, item_path
3039 );
3040 2 gql_runtime_vm_path_frame_decref(item_path);
3041 2 SvREFCNT_dec(item_key);
3042 }
3043 }
3044 7 ▶ if (violated) {
Branch: 1 branch
BranchTrueFalseTotal
if (violated) { 2 5 7
3045 2 gql_runtime_vm_native_value_destroy(aTHX_ outcome->value);
3046 2 outcome->value = NULL;
3047 2 outcome->kind_code = GQL_VM_KIND_SCALAR;
3048 2 outcome->null_carries_error = 1;
3049 }
3050 }
3051  
3052 /* Non-Null propagation for the async lane (spec 6.4.4). After a field
3053 * value is stored into `frame`, if the field position is non-null and the
3054 * value is null, record "Cannot return null" (unless the null already
3055 * carried an error) and mark the frame to resolve as null. `entry` locates
3056 * the field's slot in native_program->blocks and carries its response
3057 * path. */
3058 static void
3059 3705 gql_runtime_vm_frame_field_enforce_nonnull(
3060 pTHX_
3061 gql_runtime_vm_exec_state_handle_t *s,
3062 gql_runtime_vm_block_frame_t *frame,
3063 const gql_runtime_vm_pending_entry_t *entry,
3064 int value_is_null,
3065 int null_carries_error
3066 )
3067 {
3068 const gql_runtime_vm_native_block_t *block;
3069 const gql_runtime_vm_native_slot_t *slot;
3070  
3071 3705 ▶ if (!value_is_null || !s || !s->native_program || !frame) {
Branch: 4 branches
BranchTrueFalseTotal
if (!value_is_null || !s || !s->native_program || !frame) { 21 3684 3705
if (!value_is_null || !s || !s->native_program || !frame) { 21 0 21
if (!value_is_null || !s || !s->native_program || !frame) { 21 0 21
if (!value_is_null || !s || !s->native_program || !frame) { 0 21 21
3072 3684 return;
3073 }
3074 21 ▶ if (entry->block_index < 0 || entry->block_index >= s->native_program->block_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (entry->block_index < 0 || entry->block_index >= s->native_program->block_count) { 21 0 21
if (entry->block_index < 0 || entry->block_index >= s->native_program->block_count) { 0 21 21
3075 0 return;
3076 }
3077 21 block = &s->native_program->blocks[entry->block_index];
3078 21 ▶ if (entry->slot_index < 0 || entry->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (entry->slot_index < 0 || entry->slot_index >= block->slot_count) { 21 0 21
if (entry->slot_index < 0 || entry->slot_index >= block->slot_count) { 0 21 21
3079 0 return;
3080 }
3081 21 slot = &block->slots[entry->slot_index];
3082 21 ▶ if (slot->return_type_kind_code != 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (slot->return_type_kind_code != 8) { 16 5 21
3083 16 return;
3084 }
3085 5 ▶ if (!null_carries_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (!null_carries_error) { 5 0 5
3086 5 gql_runtime_vm_record_nonnull_violation(
3087 5 aTHX_ s->writer, block->type_name, slot->field_name, entry->path_frame
3088 );
3089 }
3090 5 frame->self_nulled = 1;
3091 }
3092  
3093 static void
3094 3685 gql_runtime_vm_async_scheduler_process_frame(
3095 pTHX_
3096 SV *state_sv,
3097 gql_runtime_vm_exec_state_handle_t *s,
3098 gql_runtime_vm_block_frame_t *frame
3099 )
3100 {
3101 3685 ▶ while (frame) {
Branch: 1 branch
BranchTrueFalseTotal
while (frame) { 3685 0 3685
3102 IV i;
3103 gql_runtime_vm_block_frame_t next_pending;
3104  
3105 3685 ▶ if (frame->pending_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_count == 0) { 0 3685 3685
3106 0 gql_runtime_vm_async_scheduler_resolve_frame(aTHX_ s, frame);
3107 3685 return;
3108 }
3109  
3110 3685 Zero(&next_pending, 1, gql_runtime_vm_block_frame_t);
3111 7405 ▶ for (i = 0; i < frame->pending_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < frame->pending_count; i++) { 3720 3685 7405
3112 3720 gql_runtime_vm_pending_entry_t *entry = &frame->pending_entries[i];
3113  
3114 3720 ▶ if (entry->state_code == GQL_VM_PENDING_STATE_WAITING_UNARMED
Branch: 1 branch
BranchTrueFalseTotal
if (entry->state_code == GQL_VM_PENDING_STATE_WAITING_UNARMED 3720 0 3720
3115 3720 ▶ || entry->state_code == GQL_VM_PENDING_STATE_WAITING_ARMED) {
Branch: 1 branch
BranchTrueFalseTotal
|| entry->state_code == GQL_VM_PENDING_STATE_WAITING_ARMED) { 649 3071 3720
3116 649 ▶ if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR 648 1 649
3117 648 ▶ && entry->payload.list_pending_ptr
Branch: 1 branch
BranchTrueFalseTotal
&& entry->payload.list_pending_ptr 648 0 648
3118 648 ▶ && entry->payload.list_pending_ptr->unresolved_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
&& entry->payload.list_pending_ptr->unresolved_count == 0) { 646 2 648
3119 /* ready list pending entries are consumed below */
3120 } else
3121 3 ▶ if (entry->payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR) { 0 3 3
3122 gql_runtime_vm_pending_entry_t *next_entry =
3123 0 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
3124 aTHX_
3125 &next_pending,
3126 0 entry->result_name_pv,
3127 entry->result_name_len,
3128 0 entry->result_name_pv_borrowed,
3129 entry->path_frame,
3130 entry->block_index,
3131 entry->slot_index,
3132 entry->op_index
3133 );
3134 0 next_entry->payload_kind = GQL_VM_PENDING_BLOCK_FRAME_PTR;
3135 0 next_entry->state_code = entry->state_code;
3136 0 next_entry->payload.block_frame_ptr = entry->payload.block_frame_ptr;
3137 0 next_entry->payload.block_frame_ptr->refcount++;
3138 0 next_entry->payload.block_frame_ptr->parent_entry_index = next_pending.pending_count - 1;
3139 3 ▶ } else if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR) { 2 1 3
3140 gql_runtime_vm_pending_entry_t *next_entry =
3141 2 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
3142 aTHX_
3143 &next_pending,
3144 2 entry->result_name_pv,
3145 entry->result_name_len,
3146 2 entry->result_name_pv_borrowed,
3147 entry->path_frame,
3148 entry->block_index,
3149 entry->slot_index,
3150 entry->op_index
3151 );
3152 2 next_entry->payload_kind = GQL_VM_PENDING_LIST_PENDING_PTR;
3153 2 next_entry->state_code = entry->state_code;
3154 2 next_entry->payload.list_pending_ptr = entry->payload.list_pending_ptr;
3155 2 gql_runtime_vm_list_pending_incref(next_entry->payload.list_pending_ptr);
3156 } else {
3157 gql_runtime_vm_pending_entry_t *moved;
3158 1 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
3159 aTHX_
3160 &next_pending,
3161 1 entry->result_name_pv,
3162 entry->result_name_len,
3163 1 entry->result_name_pv_borrowed,
3164 entry->payload.promise_sv,
3165 1 entry->payload_kind,
3166 entry->path_frame,
3167 entry->block_index,
3168 entry->slot_index,
3169 entry->op_index,
3170 1 s->async_adapter
3171 );
3172 1 moved = &next_pending.pending_entries[next_pending.pending_count - 1];
3173 1 moved->state_code = entry->state_code;
3174 /* An armed entry's then-callbacks hold its index by value; the
3175 * rebuilt array compacts consumed entries away, so retarget the
3176 * contexts or a later settle lands on a stale index and the
3177 * value is silently dropped (frame deadlocks). */
3178 1 moved->armed_resolve_ctx = entry->armed_resolve_ctx;
3179 1 moved->armed_reject_ctx = entry->armed_reject_ctx;
3180 1 ▶ if (moved->armed_resolve_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (moved->armed_resolve_ctx) { 1 0 1
3181 1 ((gql_runtime_vm_pending_callback_ctx_t *)moved->armed_resolve_ctx)->entry_index =
3182 1 next_pending.pending_count - 1;
3183 }
3184 1 ▶ if (moved->armed_reject_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (moved->armed_reject_ctx) { 1 0 1
3185 1 ((gql_runtime_vm_pending_callback_ctx_t *)moved->armed_reject_ctx)->entry_index =
3186 1 next_pending.pending_count - 1;
3187 }
3188 }
3189 649 ▶ if (!(entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR
Branch: 1 branch
BranchTrueFalseTotal
if (!(entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR 648 1 649
3190 648 ▶ && entry->payload.list_pending_ptr
Branch: 1 branch
BranchTrueFalseTotal
&& entry->payload.list_pending_ptr 648 0 648
3191 648 ▶ && entry->payload.list_pending_ptr->unresolved_count == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
&& entry->payload.list_pending_ptr->unresolved_count == 0)) { 2 646 648
3192 3 continue;
3193 }
3194 }
3195  
3196 3717 ▶ if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR) { 646 3071 3717
3197 gql_runtime_vm_outcome_t *outcome;
3198  
3199 646 ▶ if (!entry->payload.list_pending_ptr
Branch: 1 branch
BranchTrueFalseTotal
if (!entry->payload.list_pending_ptr 646 0 646
3200 646 ▶ || entry->payload.list_pending_ptr->unresolved_count > 0
Branch: 1 branch
BranchTrueFalseTotal
|| entry->payload.list_pending_ptr->unresolved_count > 0 646 0 646
3201 646 ▶ || !entry->payload.list_pending_ptr->values_value) {
Branch: 1 branch
BranchTrueFalseTotal
|| !entry->payload.list_pending_ptr->values_value) { 0 646 646
3202 gql_runtime_vm_pending_entry_t *next_entry =
3203 0 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
3204 aTHX_
3205 &next_pending,
3206 0 entry->result_name_pv,
3207 entry->result_name_len,
3208 0 entry->result_name_pv_borrowed,
3209 entry->path_frame,
3210 entry->block_index,
3211 entry->slot_index,
3212 entry->op_index
3213 );
3214 0 next_entry->payload_kind = GQL_VM_PENDING_LIST_PENDING_PTR;
3215 0 next_entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
3216 0 next_entry->payload.list_pending_ptr = entry->payload.list_pending_ptr;
3217 0 gql_runtime_vm_list_pending_incref(next_entry->payload.list_pending_ptr);
3218 0 continue;
3219 }
3220  
3221 646 outcome = gql_runtime_vm_new_outcome_from_owned_native_value_struct(
3222 aTHX_
3223 GQL_VM_KIND_LIST,
3224 646 entry->payload.list_pending_ptr->values_value
3225 );
3226 646 entry->payload.list_pending_ptr->values_value = NULL;
3227 646 gql_runtime_vm_outcome_enforce_list_item_nonnull(aTHX_ s, entry, outcome);
3228 {
3229 646 int vnull = gql_runtime_vm_native_value_is_null(outcome->value);
3230 646 ▶ int carries = outcome->null_carries_error || outcome->error_record_count > 0;
Branch: 2 branches
BranchTrueFalseTotal
int carries = outcome->null_carries_error || outcome->error_record_count > 0; 644 2 646
int carries = outcome->null_carries_error || outcome->error_record_count > 0; 0 644 644
3231 646 gql_runtime_vm_consume_outcome_native_object(
3232 aTHX_
3233 frame->values_value,
3234 646 entry->result_name_pv,
3235 646 entry->result_name_pv_borrowed,
3236 outcome,
3237 s->writer
3238 );
3239 646 gql_runtime_vm_frame_field_enforce_nonnull(aTHX_ s, frame, entry, vnull, carries);
3240 }
3241 646 gql_runtime_vm_outcome_decref(aTHX_ outcome);
3242 646 continue;
3243 }
3244  
3245 3071 ▶ if (entry->state_code == GQL_VM_PENDING_STATE_READY_OUTCOME
Branch: 1 branch
BranchTrueFalseTotal
if (entry->state_code == GQL_VM_PENDING_STATE_READY_OUTCOME 1800 1271 3071
3246 1800 ▶ || entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
|| entry->payload_kind == GQL_VM_PENDING_OUTCOME_PTR) { 0 1800 1800
3247 2542 int vnull = entry->payload.outcome_ptr
3248 1271 ▶ && gql_runtime_vm_native_value_is_null(entry->payload.outcome_ptr->value);
Branch: 2 branches
BranchTrueFalseTotal
&& gql_runtime_vm_native_value_is_null(entry->payload.outcome_ptr->value); 1271 0 1271
&& gql_runtime_vm_native_value_is_null(entry->payload.outcome_ptr->value); 11 1260 1271
3249 2542 int carries = entry->payload.outcome_ptr
3250 2539 ▶ && (entry->payload.outcome_ptr->null_carries_error
Branch: 2 branches
BranchTrueFalseTotal
&& (entry->payload.outcome_ptr->null_carries_error 1271 0 1271
&& (entry->payload.outcome_ptr->null_carries_error 1268 3 1271
3251 1268 ▶ || entry->payload.outcome_ptr->error_record_count > 0);
Branch: 1 branch
BranchTrueFalseTotal
|| entry->payload.outcome_ptr->error_record_count > 0); 8 1260 1268
3252 1271 gql_runtime_vm_consume_outcome_native_object(
3253 aTHX_
3254 frame->values_value,
3255 1271 entry->result_name_pv,
3256 1271 entry->result_name_pv_borrowed,
3257 entry->payload.outcome_ptr,
3258 s->writer
3259 );
3260 1271 gql_runtime_vm_frame_field_enforce_nonnull(aTHX_ s, frame, entry, vnull, carries);
3261 1271 continue;
3262 }
3263  
3264 1800 ▶ if (entry->payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV) { 1800 0 1800
3265 1800 gql_runtime_vm_outcome_t *completed_outcome = NULL;
3266 1800 SV *completed_sv = gql_runtime_vm_exec_state_complete_async_sv(
3267 aTHX_
3268 state_sv,
3269 s,
3270 entry->path_frame,
3271 entry->block_index,
3272 entry->slot_index,
3273 entry->op_index,
3274 entry->payload.promise_sv,
3275 &completed_outcome
3276 );
3277  
3278 1800 ▶ if (completed_outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed_outcome) { 1787 13 1800
3279 1787 int vnull = gql_runtime_vm_native_value_is_null(completed_outcome->value);
3280 3574 int carries = completed_outcome->null_carries_error
3281 1787 ▶ || completed_outcome->error_record_count > 0;
Branch: 2 branches
BranchTrueFalseTotal
|| completed_outcome->error_record_count > 0; 1786 1 1787
|| completed_outcome->error_record_count > 0; 0 1786 1786
3282 1787 gql_runtime_vm_consume_outcome_native_object(
3283 aTHX_
3284 frame->values_value,
3285 1787 entry->result_name_pv,
3286 1787 entry->result_name_pv_borrowed,
3287 completed_outcome,
3288 s->writer
3289 );
3290 1787 gql_runtime_vm_frame_field_enforce_nonnull(aTHX_ s, frame, entry, vnull, carries);
3291 1787 gql_runtime_vm_outcome_decref(aTHX_ completed_outcome);
3292 14 ▶ } else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) { 13 0 13
} else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) { 13 0 13
} else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) { 1 12 13
3293 1 gql_runtime_vm_outcome_t *co = gql_runtime_vm_expect_outcome(aTHX_ completed_sv);
3294 1 int vnull = gql_runtime_vm_native_value_is_null(co->value);
3295 1 ▶ int carries = co->null_carries_error || co->error_record_count > 0;
Branch: 2 branches
BranchTrueFalseTotal
int carries = co->null_carries_error || co->error_record_count > 0; 1 0 1
int carries = co->null_carries_error || co->error_record_count > 0; 1 0 1
3296 1 gql_runtime_vm_consume_outcome_native_object(
3297 aTHX_
3298 frame->values_value,
3299 1 entry->result_name_pv,
3300 1 entry->result_name_pv_borrowed,
3301 co,
3302 s->writer
3303 );
3304 1 gql_runtime_vm_frame_field_enforce_nonnull(aTHX_ s, frame, entry, vnull, carries);
3305 12 ▶ } else if (completed_sv && SvOK(completed_sv)
Branch: 2 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv) 12 0 12
} else if (completed_sv && SvOK(completed_sv) 12 0 12
3306 21 ▶ && gql_runtime_vm_is_block_frame_value_sv(completed_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_is_block_frame_value_sv(completed_sv)) { 9 3 12
3307 /* Mode 1: completion produced a pending child block. Link it into
3308 * the rebuilt pending array so the child's resolve_frame notifies
3309 * this frame directly - no promise in between. */
3310 gql_runtime_vm_block_frame_t *child_frame =
3311 9 gql_runtime_vm_expect_block_frame(aTHX_ completed_sv);
3312 gql_runtime_vm_pending_entry_t *next_entry =
3313 9 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
3314 aTHX_
3315 &next_pending,
3316 9 entry->result_name_pv,
3317 entry->result_name_len,
3318 9 entry->result_name_pv_borrowed,
3319 entry->path_frame,
3320 entry->block_index,
3321 entry->slot_index,
3322 entry->op_index
3323 );
3324 9 next_entry->payload_kind = GQL_VM_PENDING_BLOCK_FRAME_PTR;
3325 9 next_entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
3326 9 next_entry->payload.block_frame_ptr = child_frame;
3327 9 child_frame->refcount++;
3328 9 ▶ if (child_frame->parent_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_frame->parent_frame) { 0 9 9
3329 0 gql_runtime_vm_free_block_frame(aTHX_ child_frame->parent_frame);
3330 }
3331 9 child_frame->parent_frame = frame;
3332 9 frame->refcount++;
3333 9 child_frame->parent_entry_index = next_pending.pending_count - 1;
3334 9 ▶ if (child_frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_frame->pending_unresolved == 0) { 1 8 9
3335 1 gql_runtime_vm_async_scheduler_enqueue_frame(s, child_frame);
3336 }
3337 3 ▶ } else if (completed_sv && SvOK(completed_sv)
Branch: 2 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv) 3 0 3
} else if (completed_sv && SvOK(completed_sv) 3 0 3
3338 3 ▶ && gql_runtime_vm_is_list_pending_value_sv(completed_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_is_list_pending_value_sv(completed_sv)) { 3 0 3
3339 /* A late-resolving list field whose items pend again (child
3340 * blocks queueing loads) completes to a list-pending handle.
3341 * Adopt it like consume_current_result_now does; treating it as
3342 * a promise breaks the response. */
3343 gql_runtime_vm_list_pending_t *list_pending =
3344 3 gql_runtime_vm_expect_list_pending(aTHX_ completed_sv);
3345 gql_runtime_vm_pending_entry_t *next_entry =
3346 3 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
3347 aTHX_
3348 &next_pending,
3349 3 entry->result_name_pv,
3350 entry->result_name_len,
3351 3 entry->result_name_pv_borrowed,
3352 entry->path_frame,
3353 entry->block_index,
3354 entry->slot_index,
3355 entry->op_index
3356 );
3357 3 next_entry->payload_kind = GQL_VM_PENDING_LIST_PENDING_PTR;
3358 3 next_entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
3359 3 next_entry->payload.list_pending_ptr = list_pending;
3360 3 gql_runtime_vm_list_pending_incref(list_pending);
3361 3 ▶ if (list_pending->owner_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (list_pending->owner_frame) { 0 3 3
3362 0 gql_runtime_vm_free_block_frame(aTHX_ list_pending->owner_frame);
3363 }
3364 3 list_pending->owner_frame = frame;
3365 3 frame->refcount++;
3366 0 ▶ } else if (completed_sv && SvOK(completed_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv)) { 0 0 0
} else if (completed_sv && SvOK(completed_sv)) { 0 0 0
3367 0 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
3368 aTHX_
3369 &next_pending,
3370 0 entry->result_name_pv,
3371 entry->result_name_len,
3372 0 entry->result_name_pv_borrowed,
3373 completed_sv,
3374 GQL_VM_PENDING_PROMISE_SV,
3375 NULL,
3376 -1,
3377 -1,
3378 -1,
3379 0 s->async_adapter
3380 );
3381 }
3382 1800 ▶ if (completed_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed_sv) { 13 1787 1800
3383 13 SvREFCNT_dec(completed_sv);
3384 }
3385 1800 continue;
3386 }
3387  
3388 0 ▶ if (entry->payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV 0 0 0
3389 0 ▶ || entry->payload_kind == GQL_VM_PENDING_PROMISE_SV) {
Branch: 1 branch
BranchTrueFalseTotal
|| entry->payload_kind == GQL_VM_PENDING_PROMISE_SV) { 0 0 0
3390 0 ▶ int vnull = !entry->payload.promise_sv || !SvOK(entry->payload.promise_sv);
Branch: 2 branches
BranchTrueFalseTotal
int vnull = !entry->payload.promise_sv || !SvOK(entry->payload.promise_sv); 0 0 0
int vnull = !entry->payload.promise_sv || !SvOK(entry->payload.promise_sv); 0 0 0
3391 0 gql_runtime_vm_consume_value_native_object(
3392 aTHX_
3393 frame->values_value,
3394 0 entry->result_name_pv,
3395 0 entry->result_name_pv_borrowed,
3396 entry->payload.promise_sv
3397 );
3398 /* A settled leaf value: a plain null in a non-null position needs
3399 * the error (nothing produced one upstream). */
3400 0 gql_runtime_vm_frame_field_enforce_nonnull(aTHX_ s, frame, entry, vnull, 0);
3401 }
3402 }
3403  
3404 3685 gql_runtime_vm_block_frame_clear_pending(aTHX_ frame);
3405 /* clear_pending retains the array for pooled reuse; this frame swaps in
3406 * the rebuilt one instead, so the old buffer must go now. */
3407 3685 Safefree(frame->pending_entries);
3408 3685 frame->pending_entries = next_pending.pending_entries;
3409 3685 frame->pending_count = next_pending.pending_count;
3410 3685 frame->pending_capacity = next_pending.pending_capacity;
3411 3685 frame->pending_unresolved = 0;
3412  
3413 3685 ▶ if (frame->pending_count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_count == 0) { 3670 15 3685
3414 3670 gql_runtime_vm_async_scheduler_resolve_frame(aTHX_ s, frame);
3415 3670 return;
3416 }
3417  
3418 15 gql_runtime_vm_async_scheduler_arm_frame(aTHX_ state_sv, s, frame);
3419 15 ▶ if (frame->pending_unresolved > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_unresolved > 0) { 15 0 15
3420 15 return;
3421 }
3422 }
3423 }
3424  
3425 static void
3426 1996 gql_runtime_vm_async_scheduler_drain(
3427 pTHX_
3428 SV *state_sv,
3429 gql_runtime_vm_exec_state_handle_t *s
3430 )
3431 {
3432 1996 ▶ if (!s || s->async_scheduler_draining) {
Branch: 2 branches
BranchTrueFalseTotal
if (!s || s->async_scheduler_draining) { 1996 0 1996
if (!s || s->async_scheduler_draining) { 0 1996 1996
3433 0 return;
3434 }
3435  
3436 1996 s->async_scheduler_draining = 1;
3437 5681 ▶ while (s->async_ready_frame_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (s->async_ready_frame_count > 0) { 3685 1996 5681
3438 3685 gql_runtime_vm_block_frame_t *frame =
3439 3685 s->async_ready_frames[--s->async_ready_frame_count];
3440 3685 s->async_ready_frames[s->async_ready_frame_count] = NULL;
3441 3685 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 3685 3685
3442 0 continue;
3443 }
3444 3685 frame->queued = 0;
3445 3685 gql_runtime_vm_async_scheduler_process_frame(aTHX_ state_sv, s, frame);
3446 }
3447 1996 s->async_scheduler_draining = 0;
3448 }
3449  
3450 static SV *
3451 0 gql_runtime_vm_pending_merge_resolve_sv(pTHX_ gql_runtime_vm_pending_merge_t *state, SV *resolved)
3452 {
3453 0 AV *resolved_av = gql_runtime_vm_expect_arrayref(aTHX_ resolved, "resolved outcomes");
3454 SSize_t i;
3455 gql_runtime_vm_block_frame_t next_pending;
3456 0 U8 enqueued_ready_child = 0;
3457 0 gql_runtime_vm_exec_state_handle_t *exec_state =
3458 0 ▶ (state && state->state_sv) ? gql_runtime_vm_expect_exec_state_handle(aTHX_ state->state_sv) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
(state && state->state_sv) ? gql_runtime_vm_expect_exec_state_handle(aTHX_ state->state_sv) : NULL; 0 0 0
(state && state->state_sv) ? gql_runtime_vm_expect_exec_state_handle(aTHX_ state->state_sv) : NULL; 0 0 0
3459  
3460 0 Zero(&next_pending, 1, gql_runtime_vm_block_frame_t);
3461  
3462 0 ▶ for (i = 0; i <= av_len(resolved_av) && i < state->frame->pending_count; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i <= av_len(resolved_av) && i < state->frame->pending_count; i++) { 0 0 0
for (i = 0; i <= av_len(resolved_av) && i < state->frame->pending_count; i++) { 0 0 0
3463 0 SV **outcome_svp = av_fetch(resolved_av, i, 0);
3464 0 gql_runtime_vm_pending_entry_t *entry = &state->frame->pending_entries[i];
3465 0 ▶ SV *resolved_sv = (outcome_svp && *outcome_svp) ? *outcome_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *resolved_sv = (outcome_svp && *outcome_svp) ? *outcome_svp : &PL_sv_undef; 0 0 0
SV *resolved_sv = (outcome_svp && *outcome_svp) ? *outcome_svp : &PL_sv_undef; 0 0 0
3466  
3467 0 ▶ if (entry->payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV) { 0 0 0
3468 0 ▶ if (SvOK(resolved_sv) && !gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(resolved_sv) && !gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 0 0
if (SvOK(resolved_sv) && !gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 0 0
3469 0 gql_runtime_vm_consume_value_native_object(
3470 aTHX_
3471 0 state->frame->values_value,
3472 0 entry->result_name_pv,
3473 0 entry->result_name_pv_borrowed,
3474 resolved_sv
3475 );
3476 } else {
3477 0 gql_runtime_vm_consume_outcome_native_object(
3478 aTHX_
3479 0 state->frame->values_value,
3480 0 entry->result_name_pv,
3481 0 entry->result_name_pv_borrowed,
3482 gql_runtime_vm_expect_outcome(aTHX_ resolved_sv),
3483 state->writer
3484 );
3485 }
3486 0 ▶ } else if (entry->payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV) { 0 0 0
3487 0 ▶ if (SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 0 0
if (SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 0 0
3488 0 gql_runtime_vm_consume_outcome_native_object(
3489 aTHX_
3490 0 state->frame->values_value,
3491 0 entry->result_name_pv,
3492 0 entry->result_name_pv_borrowed,
3493 gql_runtime_vm_expect_outcome(aTHX_ resolved_sv),
3494 state->writer
3495 );
3496 } else {
3497 0 gql_runtime_vm_outcome_t *completed_outcome = NULL;
3498 SV *completed_sv;
3499  
3500 0 ▶ if (!exec_state || !state->state_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!exec_state || !state->state_sv) { 0 0 0
if (!exec_state || !state->state_sv) { 0 0 0
3501 0 croak("pending async completion requires an exec state");
3502 }
3503 0 completed_sv = gql_runtime_vm_exec_state_complete_async_sv(
3504 aTHX_
3505 state->state_sv,
3506 exec_state,
3507 entry->path_frame,
3508 entry->block_index,
3509 entry->slot_index,
3510 entry->op_index,
3511 resolved_sv,
3512 &completed_outcome
3513 );
3514 0 ▶ if (completed_outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed_outcome) { 0 0 0
3515 0 gql_runtime_vm_consume_outcome_native_object(
3516 aTHX_
3517 0 state->frame->values_value,
3518 0 entry->result_name_pv,
3519 0 entry->result_name_pv_borrowed,
3520 completed_outcome,
3521 state->writer
3522 );
3523 0 gql_runtime_vm_outcome_decref(aTHX_ completed_outcome);
3524 0 ▶ } else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) { 0 0 0
} else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) { 0 0 0
} else if (completed_sv && SvOK(completed_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ completed_sv)) { 0 0 0
3525 0 gql_runtime_vm_consume_outcome_native_object(
3526 aTHX_
3527 0 state->frame->values_value,
3528 0 entry->result_name_pv,
3529 0 entry->result_name_pv_borrowed,
3530 gql_runtime_vm_expect_outcome(aTHX_ completed_sv),
3531 state->writer
3532 );
3533 0 ▶ } else if (completed_sv && SvOK(completed_sv)
Branch: 2 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv) 0 0 0
} else if (completed_sv && SvOK(completed_sv) 0 0 0
3534 0 ▶ && gql_runtime_vm_is_block_frame_value_sv(completed_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_is_block_frame_value_sv(completed_sv)) { 0 0 0
3535 /* Mode 1: completion produced a pending child block; link it to
3536 * this frame like the scheduler's resolved-value branch does. */
3537 gql_runtime_vm_block_frame_t *child_frame =
3538 0 gql_runtime_vm_expect_block_frame(aTHX_ completed_sv);
3539 gql_runtime_vm_pending_entry_t *next_entry =
3540 0 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
3541 aTHX_
3542 &next_pending,
3543 0 entry->result_name_pv,
3544 entry->result_name_len,
3545 0 entry->result_name_pv_borrowed,
3546 entry->path_frame,
3547 entry->block_index,
3548 entry->slot_index,
3549 entry->op_index
3550 );
3551 0 next_entry->payload_kind = GQL_VM_PENDING_BLOCK_FRAME_PTR;
3552 0 next_entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
3553 0 next_entry->payload.block_frame_ptr = child_frame;
3554 0 child_frame->refcount++;
3555 0 ▶ if (child_frame->parent_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_frame->parent_frame) { 0 0 0
3556 0 gql_runtime_vm_free_block_frame(aTHX_ child_frame->parent_frame);
3557 }
3558 0 child_frame->parent_frame = state->frame;
3559 0 state->frame->refcount++;
3560 0 child_frame->parent_entry_index = next_pending.pending_count - 1;
3561 0 ▶ if (child_frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_frame->pending_unresolved == 0) { 0 0 0
3562 /* Drain happens after the pending swap below: resolve_frame
3563 * writes into the parent's installed entry array. */
3564 0 gql_runtime_vm_async_scheduler_enqueue_frame(exec_state, child_frame);
3565 0 enqueued_ready_child = 1;
3566 }
3567 0 ▶ } else if (completed_sv && SvOK(completed_sv)
Branch: 2 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv) 0 0 0
} else if (completed_sv && SvOK(completed_sv) 0 0 0
3568 0 ▶ && gql_runtime_vm_is_list_pending_value_sv(completed_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_is_list_pending_value_sv(completed_sv)) { 0 0 0
3569 /* Same adoption as the scheduler's resolved-value branch. */
3570 gql_runtime_vm_list_pending_t *list_pending =
3571 0 gql_runtime_vm_expect_list_pending(aTHX_ completed_sv);
3572 gql_runtime_vm_pending_entry_t *next_entry =
3573 0 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
3574 aTHX_
3575 &next_pending,
3576 0 entry->result_name_pv,
3577 entry->result_name_len,
3578 0 entry->result_name_pv_borrowed,
3579 entry->path_frame,
3580 entry->block_index,
3581 entry->slot_index,
3582 entry->op_index
3583 );
3584 0 next_entry->payload_kind = GQL_VM_PENDING_LIST_PENDING_PTR;
3585 0 next_entry->state_code = GQL_VM_PENDING_STATE_WAITING_ARMED;
3586 0 next_entry->payload.list_pending_ptr = list_pending;
3587 0 gql_runtime_vm_list_pending_incref(list_pending);
3588 0 ▶ if (list_pending->owner_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (list_pending->owner_frame) { 0 0 0
3589 0 gql_runtime_vm_free_block_frame(aTHX_ list_pending->owner_frame);
3590 }
3591 0 list_pending->owner_frame = state->frame;
3592 0 state->frame->refcount++;
3593 0 ▶ } else if (completed_sv && SvOK(completed_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (completed_sv && SvOK(completed_sv)) { 0 0 0
} else if (completed_sv && SvOK(completed_sv)) { 0 0 0
3594 0 ▶ gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_block_frame_push_pending_pvn_with_meta( 0 0 0
3595 aTHX_
3596 &next_pending,
3597 0 entry->result_name_pv,
3598 entry->result_name_len,
3599 0 entry->result_name_pv_borrowed,
3600 completed_sv,
3601 GQL_VM_PENDING_PROMISE_SV,
3602 NULL,
3603 -1,
3604 -1,
3605 -1,
3606 exec_state ? exec_state->async_adapter : NULL
3607 );
3608 }
3609 0 ▶ if (completed_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed_sv) { 0 0 0
3610 0 SvREFCNT_dec(completed_sv);
3611 }
3612 }
3613 0 ▶ } else if (entry->payload_kind == GQL_VM_PENDING_PROMISE_SV) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (entry->payload_kind == GQL_VM_PENDING_PROMISE_SV) { 0 0 0
3614 0 ▶ if (SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 0 0
if (SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 0 0
3615 0 gql_runtime_vm_consume_outcome_native_object(
3616 aTHX_
3617 0 state->frame->values_value,
3618 0 entry->result_name_pv,
3619 0 entry->result_name_pv_borrowed,
3620 gql_runtime_vm_expect_outcome(aTHX_ resolved_sv),
3621 state->writer
3622 );
3623 } else {
3624 0 gql_runtime_vm_consume_value_native_object(
3625 aTHX_
3626 0 state->frame->values_value,
3627 0 entry->result_name_pv,
3628 0 entry->result_name_pv_borrowed,
3629 resolved_sv
3630 );
3631 }
3632 }
3633 }
3634  
3635 0 gql_runtime_vm_block_frame_clear_pending(aTHX_ state->frame);
3636 /* clear_pending retains the array for pooled reuse; this frame swaps in
3637 * the rebuilt one instead, so the old buffer must go now. */
3638 0 Safefree(state->frame->pending_entries);
3639 0 state->frame->pending_entries = next_pending.pending_entries;
3640 0 state->frame->pending_count = next_pending.pending_count;
3641 0 state->frame->pending_capacity = next_pending.pending_capacity;
3642  
3643 0 ▶ if (enqueued_ready_child && exec_state && !exec_state->async_scheduler_draining) {
Branch: 3 branches
BranchTrueFalseTotal
if (enqueued_ready_child && exec_state && !exec_state->async_scheduler_draining) { 0 0 0
if (enqueued_ready_child && exec_state && !exec_state->async_scheduler_draining) { 0 0 0
if (enqueued_ready_child && exec_state && !exec_state->async_scheduler_draining) { 0 0 0
3644 0 gql_runtime_vm_async_scheduler_drain(aTHX_ state->state_sv, exec_state);
3645 }
3646  
3647 0 ▶ if (state->frame->pending_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->frame->pending_count > 0) { 0 0 0
3648 0 ▶ return gql_runtime_vm_block_frame_finalize_sv(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_block_frame_finalize_sv( 0 0 0
3649 aTHX_
3650 state->frame,
3651 0 ▶ (exec_state && exec_state->async_adapter != NULL)
Branch: 1 branch
BranchTrueFalseTotal
(exec_state && exec_state->async_adapter != NULL) 0 0 0
3652 ? exec_state->async_adapter
3653 : &gql_runtime_vm_promise_xs_adapter,
3654 state->writer,
3655 state->state_sv,
3656 0
3657 );
3658 }
3659 0 return gql_runtime_vm_native_value_materialize_sv(aTHX_ state->frame->values_value);
3660 }
3661  
3662 static SV *gql_runtime_vm_new_ticket_chain_callback_sv(
3663 pTHX_ SV *derived_ticket, SV *callback_sv, U8 reject_arm
3664 );
3665 static void gql_runtime_vm_resolve_dataloader_ticket_value(
3666 pTHX_ SV *derived_ticket, SV *result
3667 );
3668  
3669 1354 static XS(gql_runtime_vm_xs_ticket_chain_callback)
3670 {
3671 dVAR;
3672 1354 dXSARGS;
3673 1354 gql_runtime_vm_ticket_chain_ctx_t *ctx = INT2PTR(
3674 gql_runtime_vm_ticket_chain_ctx_t *,
3675 CvXSUBANY(cv).any_ptr
3676 );
3677 1354 ▶ SV *input = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *input = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 1354 0 1354
SV *input = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 1354 0 1354
3678 1354 SV *result = NULL;
3679  
3680 1354 ▶ if (!ctx || !ctx->derived_ticket) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ctx || !ctx->derived_ticket) { 1354 0 1354
if (!ctx || !ctx->derived_ticket) { 0 1354 1354
3681 0 XSRETURN_UNDEF;
3682 }
3683 1354 ▶ if (!ctx->callback_sv || !SvOK(ctx->callback_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ctx->callback_sv || !SvOK(ctx->callback_sv)) { 1354 0 1354
if (!ctx->callback_sv || !SvOK(ctx->callback_sv)) { 3 1351 1354
3684 3 ▶ if (ctx->reject_arm) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->reject_arm) { 1 2 3
3685 1 gql_runtime_vm_settle_dataloader_ticket(
3686 aTHX_ ctx->derived_ticket, 2, input
3687 );
3688 } else {
3689 2 gql_runtime_vm_resolve_dataloader_ticket_value(
3690 aTHX_ ctx->derived_ticket, input
3691 );
3692 }
3693 3 XSRETURN_UNDEF;
3694 }
3695  
3696 {
3697 1351 dSP;
3698 I32 count;
3699 1351 ENTER;
3700 1351 SAVETMPS;
3701 1351 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1351 1351
3702 1351 ▶ XPUSHs(input);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(input); 0 1351 1351
3703 1351 PUTBACK;
3704 1351 count = call_sv(ctx->callback_sv, G_SCALAR | G_EVAL);
3705 1351 SPAGAIN;
3706 1351 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1351 0 1351
if (SvTRUE(ERRSV)) { 1 1350 1351
3707 1 ▶ result = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
result = newSVsv(ERRSV); 1 0 1
3708 1 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 1 0 1
3709 1 PUTBACK;
3710 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1 0 1
3711 1 LEAVE;
3712 1 gql_runtime_vm_settle_dataloader_ticket(
3713 aTHX_ ctx->derived_ticket, 2, result
3714 );
3715 1 SvREFCNT_dec(result);
3716 1 XSRETURN_UNDEF;
3717 }
3718 1350 ▶ result = count > 0 ? newSVsv(POPs) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
result = count > 0 ? newSVsv(POPs) : newSVsv(&PL_sv_undef); 1350 0 1350
3719 1350 PUTBACK;
3720 1350 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 722 628 1350
3721 1350 LEAVE;
3722 }
3723  
3724 1350 gql_runtime_vm_resolve_dataloader_ticket_value(
3725 aTHX_ ctx->derived_ticket, result
3726 );
3727 1350 SvREFCNT_dec(result);
3728 1350 XSRETURN_UNDEF;
3729 }
3730  
3731 static void
3732 1352 gql_runtime_vm_resolve_dataloader_ticket_value(
3733 pTHX_ SV *derived_ticket, SV *result
3734 )
3735 {
3736 1352 ▶ if (result
Branch: 1 branch
BranchTrueFalseTotal
if (result 1352 0 1352
3737 1352 ▶ && SvROK(result)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(result) 16 1336 1352
3738 16 ▶ && SvROK(derived_ticket)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(derived_ticket) 16 0 16
3739 17 ▶ && SvRV(result) == SvRV(derived_ticket)) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvRV(result) == SvRV(derived_ticket)) { 1 15 16
3740 1 SV *reason = newSVpvs("DataLoader ticket cannot resolve to itself");
3741 1 gql_runtime_vm_settle_dataloader_ticket(
3742 aTHX_ derived_ticket, 2, reason
3743 );
3744 1 SvREFCNT_dec(reason);
3745 1351 ▶ } else if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ result)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ result)) { 1 1350 1351
3746 1 SV *resolve = gql_runtime_vm_new_ticket_chain_callback_sv(
3747 aTHX_ derived_ticket, &PL_sv_undef, 0
3748 );
3749 1 SV *reject = gql_runtime_vm_new_ticket_chain_callback_sv(
3750 aTHX_ derived_ticket, &PL_sv_undef, 1
3751 );
3752 1 gql_runtime_vm_subscribe_dataloader_ticket(aTHX_ result, resolve, reject);
3753 1 SvREFCNT_dec(resolve);
3754 1 SvREFCNT_dec(reject);
3755 1350 ▶ } else if (gql_runtime_vm_sv_is_promise_xs(aTHX_ result)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_sv_is_promise_xs(aTHX_ result)) { 2 1348 1350
3756 2 SV *resolve = gql_runtime_vm_new_ticket_chain_callback_sv(
3757 aTHX_ derived_ticket, &PL_sv_undef, 0
3758 );
3759 2 SV *reject = gql_runtime_vm_new_ticket_chain_callback_sv(
3760 aTHX_ derived_ticket, &PL_sv_undef, 1
3761 );
3762 2 SV *chain = gql_runtime_vm_call_then_promise_xs_sv(
3763 aTHX_ result, resolve, reject, NULL
3764 );
3765 2 SvREFCNT_dec(resolve);
3766 2 SvREFCNT_dec(reject);
3767 2 ▶ if (chain) {
Branch: 1 branch
BranchTrueFalseTotal
if (chain) { 2 0 2
3768 2 SvREFCNT_dec(chain);
3769 }
3770 } else {
3771 1348 gql_runtime_vm_settle_dataloader_ticket(
3772 aTHX_ derived_ticket, 1, result
3773 );
3774 }
3775 1352 }
3776  
3777 static SV *
3778 2708 gql_runtime_vm_new_ticket_chain_callback_sv(
3779 pTHX_ SV *derived_ticket, SV *callback_sv, U8 reject_arm
3780 )
3781 {
3782 CV *cv;
3783 gql_runtime_vm_ticket_chain_ctx_t *ctx;
3784 2708 Newxz(ctx, 1, gql_runtime_vm_ticket_chain_ctx_t);
3785 2708 ctx->derived_ticket = SvREFCNT_inc_simple_NN(derived_ticket);
3786 2708 ▶ ctx->callback_sv = newSVsv(callback_sv ? callback_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ctx->callback_sv = newSVsv(callback_sv ? callback_sv : &PL_sv_undef); 2708 0 2708
3787 2708 ctx->reject_arm = reject_arm;
3788 2708 cv = newXS(NULL, gql_runtime_vm_xs_ticket_chain_callback, __FILE__);
3789 2708 CvXSUBANY(cv).any_ptr = ctx;
3790 2708 gql_runtime_vm_attach_callback_magic_ptr(
3791 aTHX_ (SV *)cv, &gql_runtime_vm_ticket_chain_ctx_vtbl, ctx
3792 );
3793 2708 return newRV_noinc((SV *)cv);
3794 }
3795  
3796 static SV *
3797 1351 gql_runtime_vm_chain_dataloader_ticket(
3798 pTHX_ SV *ticket, SV *resolve_callback, SV *reject_callback
3799 )
3800 {
3801 1351 SV *derived = gql_runtime_vm_new_dataloader_ticket_sv(
3802 aTHX_ 0, &PL_sv_undef,
3803 gql_runtime_vm_dataloader_ticket_async_adapter(aTHX_ ticket)
3804 );
3805 1351 SV *resolve = gql_runtime_vm_new_ticket_chain_callback_sv(
3806 aTHX_ derived, resolve_callback, 0
3807 );
3808 1351 SV *reject = gql_runtime_vm_new_ticket_chain_callback_sv(
3809 aTHX_ derived, reject_callback, 1
3810 );
3811 1351 gql_runtime_vm_subscribe_dataloader_ticket(aTHX_ ticket, resolve, reject);
3812 1351 SvREFCNT_dec(resolve);
3813 1351 SvREFCNT_dec(reject);
3814 1351 return derived;
3815 }
3816  
3817 /* Shared resolve-arm settle logic for a single already-unpacked value -
3818 * used both by the XS entry point below (the items==1 case, and the
3819 * items>1 case after merging ST(0..) into one AV) and by
3820 * gql_runtime_vm_call_ticket_callback's direct-call fast path, which never
3821 * has more than one value to begin with. */
3822 static void
3823 1800 gql_runtime_vm_pending_callback_resolve_direct(
3824 pTHX_
3825 gql_runtime_vm_pending_callback_ctx_t *ctx,
3826 SV *resolved_sv
3827 )
3828 {
3829 gql_runtime_vm_exec_state_handle_t *state;
3830 gql_runtime_vm_pending_entry_t *entry;
3831  
3832 1800 ▶ if (!ctx || !ctx->state_sv || !ctx->frame) {
Branch: 3 branches
BranchTrueFalseTotal
if (!ctx || !ctx->state_sv || !ctx->frame) { 1800 0 1800
if (!ctx || !ctx->state_sv || !ctx->frame) { 1800 0 1800
if (!ctx || !ctx->state_sv || !ctx->frame) { 0 1800 1800
3833 0 return;
3834 }
3835 1800 state = gql_runtime_vm_expect_exec_state_handle(aTHX_ ctx->state_sv);
3836 1800 ▶ if (ctx->entry_index < 0 || ctx->entry_index >= ctx->frame->pending_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->entry_index < 0 || ctx->entry_index >= ctx->frame->pending_count) { 1800 0 1800
if (ctx->entry_index < 0 || ctx->entry_index >= ctx->frame->pending_count) { 0 1800 1800
3837 0 return;
3838 }
3839  
3840 1800 entry = &ctx->frame->pending_entries[ctx->entry_index];
3841 1800 ▶ if (resolved_sv && SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (resolved_sv && SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 1800 0 1800
if (resolved_sv && SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 1794 6 1800
if (resolved_sv && SvOK(resolved_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 1794 1794
3842 0 gql_runtime_vm_async_pending_entry_store_outcome(aTHX_ entry, resolved_sv);
3843 } else {
3844 1800 ▶ gql_runtime_vm_async_pending_entry_store_sv(aTHX_ entry, resolved_sv ? resolved_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_async_pending_entry_store_sv(aTHX_ entry, resolved_sv ? resolved_sv : &PL_sv_undef); 1800 0 1800
3845 }
3846  
3847 1800 ▶ if (ctx->frame->pending_unresolved > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame->pending_unresolved > 0) { 1800 0 1800
3848 1800 ctx->frame->pending_unresolved--;
3849 }
3850 1800 ▶ if (ctx->frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame->pending_unresolved == 0) { 1785 15 1800
3851 1785 gql_runtime_vm_async_scheduler_enqueue_frame(state, ctx->frame);
3852 1785 ▶ if (!state->async_scheduler_draining) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->async_scheduler_draining) { 1751 34 1785
3853 1751 gql_runtime_vm_async_scheduler_drain(aTHX_ ctx->state_sv, state);
3854 }
3855 }
3856 /* Last: nothing above may touch ctx once the pair is parked. */
3857 1800 gql_runtime_vm_pending_callback_pair_recycle(aTHX_ ctx);
3858 }
3859  
3860 /* Shared reject-arm settle logic, mirroring the resolve helper above. */
3861 static void
3862 8 gql_runtime_vm_pending_callback_reject_direct(
3863 pTHX_
3864 gql_runtime_vm_pending_callback_ctx_t *ctx,
3865 SV *reason_sv
3866 )
3867 {
3868 gql_runtime_vm_exec_state_handle_t *state;
3869 gql_runtime_vm_pending_entry_t *entry;
3870  
3871 8 ▶ if (!ctx || !ctx->state_sv || !ctx->frame) {
Branch: 3 branches
BranchTrueFalseTotal
if (!ctx || !ctx->state_sv || !ctx->frame) { 8 0 8
if (!ctx || !ctx->state_sv || !ctx->frame) { 8 0 8
if (!ctx || !ctx->state_sv || !ctx->frame) { 0 8 8
3872 0 return;
3873 }
3874 8 state = gql_runtime_vm_expect_exec_state_handle(aTHX_ ctx->state_sv);
3875 8 ▶ if (ctx->entry_index < 0 || ctx->entry_index >= ctx->frame->pending_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->entry_index < 0 || ctx->entry_index >= ctx->frame->pending_count) { 8 0 8
if (ctx->entry_index < 0 || ctx->entry_index >= ctx->frame->pending_count) { 0 8 8
3876 0 return;
3877 }
3878  
3879 8 entry = &ctx->frame->pending_entries[ctx->entry_index];
3880 8 ▶ if (reason_sv && SvOK(reason_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ reason_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (reason_sv && SvOK(reason_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ reason_sv)) { 8 0 8
if (reason_sv && SvOK(reason_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ reason_sv)) { 8 0 8
if (reason_sv && SvOK(reason_sv) && gql_runtime_vm_sv_is_outcome(aTHX_ reason_sv)) { 0 8 8
3881 0 gql_runtime_vm_async_pending_entry_store_outcome(aTHX_ entry, reason_sv);
3882 } else {
3883 8 ▶ SV *outcome_sv = gql_runtime_vm_new_error_outcome_for_path_sv(
Branch: 1 branch
BranchTrueFalseTotal
SV *outcome_sv = gql_runtime_vm_new_error_outcome_for_path_sv( 8 0 8
3884 aTHX_
3885 reason_sv ? reason_sv : &PL_sv_undef,
3886 entry->path_frame
3887 );
3888 8 gql_runtime_vm_async_pending_entry_store_outcome(aTHX_ entry, outcome_sv);
3889 8 SvREFCNT_dec(outcome_sv);
3890 }
3891  
3892 8 ▶ if (ctx->frame->pending_unresolved > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame->pending_unresolved > 0) { 8 0 8
3893 8 ctx->frame->pending_unresolved--;
3894 }
3895 8 ▶ if (ctx->frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame->pending_unresolved == 0) { 8 0 8
3896 8 gql_runtime_vm_async_scheduler_enqueue_frame(state, ctx->frame);
3897 8 ▶ if (!state->async_scheduler_draining) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->async_scheduler_draining) { 8 0 8
3898 8 gql_runtime_vm_async_scheduler_drain(aTHX_ ctx->state_sv, state);
3899 }
3900 }
3901 /* Last: nothing above may touch ctx once the pair is parked. */
3902 8 gql_runtime_vm_pending_callback_pair_recycle(aTHX_ ctx);
3903 }
3904  
3905 49 static XS(gql_runtime_vm_xs_pending_callback)
3906 {
3907 dVAR;
3908 49 dXSARGS;
3909 49 gql_runtime_vm_pending_callback_ctx_t *ctx = INT2PTR(
3910 gql_runtime_vm_pending_callback_ctx_t *,
3911 CvXSUBANY(cv).any_ptr
3912 );
3913 49 SV *resolved_sv = &PL_sv_undef;
3914 49 SV *tmp_resolved = NULL;
3915  
3916 49 ▶ if (items == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) { 49 0 49
3917 49 ▶ resolved_sv = ST(0) ? ST(0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
resolved_sv = ST(0) ? ST(0) : &PL_sv_undef; 49 0 49
3918 0 ▶ } else if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (items > 1) { 0 0 0
3919 0 AV *resolved_av = newAV();
3920 I32 i;
3921 0 ▶ for (i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) { 0 0 0
3922 0 ▶ av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef)); 0 0 0
3923 }
3924 0 tmp_resolved = newRV_noinc((SV *)resolved_av);
3925 0 resolved_sv = tmp_resolved;
3926 }
3927 49 gql_runtime_vm_pending_callback_resolve_direct(aTHX_ ctx, resolved_sv);
3928 49 ▶ if (tmp_resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_resolved) { 0 49 49
3929 0 SvREFCNT_dec(tmp_resolved);
3930 }
3931 49 XSRETURN_UNDEF;
3932 }
3933  
3934 /* Rejection arm for a directly-subscribed pending entry. The entry holds
3935 * the user promise itself (no normalizing then() in between), so the
3936 * rejection reason arrives raw here: convert it into an error outcome for
3937 * the entry's path and settle the entry exactly like the resolve arm. */
3938 2 static XS(gql_runtime_vm_xs_pending_reject_callback)
3939 {
3940 dVAR;
3941 2 dXSARGS;
3942 2 gql_runtime_vm_pending_callback_ctx_t *ctx = INT2PTR(
3943 gql_runtime_vm_pending_callback_ctx_t *,
3944 CvXSUBANY(cv).any_ptr
3945 );
3946 2 ▶ SV *reason_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *reason_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 2 0 2
SV *reason_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 2 0 2
3947  
3948 2 gql_runtime_vm_pending_callback_reject_direct(aTHX_ ctx, reason_sv);
3949 2 XSRETURN_UNDEF;
3950 }
3951  
3952 /* gql_runtime_vm_call_ticket_callback's real definition (forward-declared
3953 * near gql_runtime_vm_new_dataloader_ticket_sv): callback is almost always
3954 * one of our own pending_callback_pair CVs (gql_runtime_vm_new_pending_callback_pair,
3955 * subscribed via gql_runtime_vm_subscribe_dataloader_ticket/gql_runtime_vm_settle_dataloader_ticket),
3956 * so recognizing it and calling straight into the same settle helpers the
3957 * XS entry points above use skips the entire generic Perl calling
3958 * convention (ENTER/SAVETMPS/PUSHMARK/PUTBACK/call_sv/FREETMPS/LEAVE) for
3959 * the common case. DataLoader::Ticket also exposes _subscribe/_subscribe_native
3960 * to Perl directly, so a genuinely foreign callback is possible and must
3961 * still go through call_sv correctly. */
3962 static void
3963 3136 gql_runtime_vm_call_ticket_callback(pTHX_ SV *callback, SV *value)
3964 {
3965 3136 ▶ if (callback && SvROK(callback) && SvTYPE(SvRV(callback)) == SVt_PVCV) {
Branch: 3 branches
BranchTrueFalseTotal
if (callback && SvROK(callback) && SvTYPE(SvRV(callback)) == SVt_PVCV) { 3136 0 3136
if (callback && SvROK(callback) && SvTYPE(SvRV(callback)) == SVt_PVCV) { 3136 0 3136
if (callback && SvROK(callback) && SvTYPE(SvRV(callback)) == SVt_PVCV) { 3136 0 3136
3966 3136 CV *cv = (CV *)SvRV(callback);
3967 3136 ▶ if (CvISXSUB(cv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CvISXSUB(cv)) { 3109 27 3136
3968 gql_runtime_vm_pending_callback_ctx_t *ctx;
3969 3109 ▶ if (CvXSUB(cv) == gql_runtime_vm_xs_pending_callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (CvXSUB(cv) == gql_runtime_vm_xs_pending_callback) { 1751 1358 3109
3970 1751 ctx = INT2PTR(gql_runtime_vm_pending_callback_ctx_t *, CvXSUBANY(cv).any_ptr);
3971 1751 gql_runtime_vm_pending_callback_resolve_direct(aTHX_ ctx, value);
3972 1751 return;
3973 }
3974 1358 ▶ if (CvXSUB(cv) == gql_runtime_vm_xs_pending_reject_callback) {
Branch: 1 branch
BranchTrueFalseTotal
if (CvXSUB(cv) == gql_runtime_vm_xs_pending_reject_callback) { 6 1352 1358
3975 6 ctx = INT2PTR(gql_runtime_vm_pending_callback_ctx_t *, CvXSUBANY(cv).any_ptr);
3976 6 gql_runtime_vm_pending_callback_reject_direct(aTHX_ ctx, value);
3977 6 return;
3978 }
3979 }
3980 }
3981 {
3982 1379 dSP;
3983 1379 ENTER;
3984 1379 SAVETMPS;
3985 1379 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1379 1379
3986 1379 ▶ XPUSHs(value ? value : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(value ? value : &PL_sv_undef); 0 1379 1379
XPUSHs(value ? value : &PL_sv_undef); 1379 0 1379
3987 1379 PUTBACK;
3988 1379 call_sv(callback, G_VOID | G_DISCARD);
3989 1379 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 1379 1379
3990 1379 LEAVE;
3991 }
3992 }
3993  
3994 655 static XS(gql_runtime_vm_xs_list_pending_callback)
3995 {
3996 dVAR;
3997 655 dXSARGS;
3998 655 gql_runtime_vm_list_pending_callback_ctx_t *ctx = INT2PTR(
3999 gql_runtime_vm_list_pending_callback_ctx_t *,
4000 CvXSUBANY(cv).any_ptr
4001 );
4002 655 SV *resolved_sv = &PL_sv_undef;
4003 655 SV *tmp_resolved = NULL;
4004 655 gql_runtime_vm_exec_state_handle_t *state = NULL;
4005  
4006 655 ▶ if (!ctx || !ctx->pending || !ctx->pending->values_value || !ctx->state_sv) {
Branch: 4 branches
BranchTrueFalseTotal
if (!ctx || !ctx->pending || !ctx->pending->values_value || !ctx->state_sv) { 655 0 655
if (!ctx || !ctx->pending || !ctx->pending->values_value || !ctx->state_sv) { 655 0 655
if (!ctx || !ctx->pending || !ctx->pending->values_value || !ctx->state_sv) { 655 0 655
if (!ctx || !ctx->pending || !ctx->pending->values_value || !ctx->state_sv) { 0 655 655
4007 0 XSRETURN_UNDEF;
4008 }
4009  
4010 655 ▶ if (items == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) { 655 0 655
4011 655 ▶ resolved_sv = ST(0) ? ST(0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
resolved_sv = ST(0) ? ST(0) : &PL_sv_undef; 655 0 655
4012 0 ▶ } else if (items > 1) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (items > 1) { 0 0 0
4013 0 AV *resolved_av = newAV();
4014 I32 i;
4015 0 ▶ for (i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) { 0 0 0
4016 0 ▶ av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef)); 0 0 0
4017 }
4018 0 tmp_resolved = newRV_noinc((SV *)resolved_av);
4019 0 resolved_sv = tmp_resolved;
4020 }
4021 655 state = gql_runtime_vm_expect_exec_state_handle(aTHX_ ctx->state_sv);
4022 /* Outcomes carry error records (rejected items, failed child fields);
4023 * surface them in the response instead of collapsing to a silent null. */
4024 655 ▶ if (resolved_sv && SvOK(resolved_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (resolved_sv && SvOK(resolved_sv) 655 0 655
if (resolved_sv && SvOK(resolved_sv) 652 3 655
4025 652 ▶ && gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv) 20 632 652
4026 20 ▶ && state->writer) {
Branch: 1 branch
BranchTrueFalseTotal
&& state->writer) { 20 0 20
4027 20 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_expect_outcome(aTHX_ resolved_sv);
4028 IV j;
4029 23 ▶ for (j = 0; outcome && j < outcome->error_record_count; j++) {
Branch: 2 branches
BranchTrueFalseTotal
for (j = 0; outcome && j < outcome->error_record_count; j++) { 23 0 23
for (j = 0; outcome && j < outcome->error_record_count; j++) { 3 20 23
4030 3 gql_runtime_vm_writer_push_error_record(state->writer, outcome->error_records[j]);
4031 }
4032 }
4033  
4034 655 gql_runtime_vm_native_list_store_at(
4035 aTHX_
4036 655 ctx->pending->values_value,
4037 ctx->index,
4038 gql_runtime_vm_native_value_from_list_pending_sv(aTHX_ resolved_sv)
4039 );
4040 655 ▶ if (ctx->pending->unresolved_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->pending->unresolved_count > 0) { 655 0 655
4041 655 ctx->pending->unresolved_count--;
4042 }
4043 655 ▶ if (ctx->pending->unresolved_count == 0 && ctx->pending->owner_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->pending->unresolved_count == 0 && ctx->pending->owner_frame) { 225 430 655
if (ctx->pending->unresolved_count == 0 && ctx->pending->owner_frame) { 215 10 225
4044 215 gql_runtime_vm_async_scheduler_enqueue_frame(state, ctx->pending->owner_frame);
4045 215 ▶ if (!state->async_scheduler_draining) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->async_scheduler_draining) { 211 4 215
4046 211 gql_runtime_vm_async_scheduler_drain(aTHX_ ctx->state_sv, state);
4047 }
4048 }
4049  
4050 655 ▶ if (tmp_resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_resolved) { 0 655 655
4051 0 SvREFCNT_dec(tmp_resolved);
4052 }
4053 655 XSRETURN_UNDEF;
4054 }
4055  
4056 /* Then-callback for a list item that arrived as a promise: run the item's
4057 * child selection block once the item settles. Returning the child result
4058 * (a value, a nested promise - flattened by Promise::XS - or an error
4059 * Outcome) lets the ordinary list_pending machinery consume it. */
4060 644 static XS(gql_runtime_vm_xs_list_item_child_callback)
4061 {
4062 dVAR;
4063 644 dXSARGS;
4064 644 gql_runtime_vm_list_item_child_ctx_t *ctx = INT2PTR(
4065 gql_runtime_vm_list_item_child_ctx_t *,
4066 CvXSUBANY(cv).any_ptr
4067 );
4068 644 ▶ SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 644 0 644
SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 644 0 644
4069 644 SV *ret = NULL;
4070 gql_runtime_vm_exec_state_handle_t *s;
4071  
4072 644 ▶ if (!ctx || !ctx->state_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ctx || !ctx->state_sv) { 644 0 644
if (!ctx || !ctx->state_sv) { 0 644 644
4073 0 XSRETURN_UNDEF;
4074 }
4075 644 s = gql_runtime_vm_expect_exec_state_handle(aTHX_ ctx->state_sv);
4076  
4077 644 ▶ if (!resolved_sv || !SvOK(resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved_sv || !SvOK(resolved_sv)) { 644 0 644
if (!resolved_sv || !SvOK(resolved_sv)) { 3 641 644
4078 3 ret = newSVsv(&PL_sv_undef);
4079 641 ▶ } else if (gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_sv_is_outcome(aTHX_ resolved_sv)) { 0 641 641
4080 0 ret = newSVsv(resolved_sv);
4081 } else {
4082 641 IV item_block_index = ctx->child_block_index;
4083  
4084 641 ▶ if (item_block_index < 0 && ctx->op) {
Branch: 2 branches
BranchTrueFalseTotal
if (item_block_index < 0 && ctx->op) { 629 12 641
if (item_block_index < 0 && ctx->op) { 5 624 629
4085 /* Abstract-typed list: the member block depends on the settled
4086 * value, so it is picked here rather than at subscription time. */
4087 5 SV *type_error_sv = NULL;
4088 5 item_block_index = gql_runtime_vm_abstract_list_item_block_index(
4089 aTHX_
4090 ctx->state_sv,
4091 s,
4092 ctx->op,
4093 ctx->slot,
4094 resolved_sv,
4095 ctx->path_frame,
4096 &type_error_sv
4097 );
4098 5 ▶ if (type_error_sv && SvOK(type_error_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (type_error_sv && SvOK(type_error_sv)) { 0 5 5
if (type_error_sv && SvOK(type_error_sv)) { 0 0 0
4099 0 ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ type_error_sv, ctx->path_frame);
4100 0 SvREFCNT_dec(type_error_sv);
4101 0 ST(0) = sv_2mortal(ret);
4102 0 XSRETURN(1);
4103 }
4104 }
4105 1265 ▶ if (item_block_index < 0 && !ctx->op && ctx->slot) {
Branch: 3 branches
BranchTrueFalseTotal
if (item_block_index < 0 && !ctx->op && ctx->slot) { 624 17 641
if (item_block_index < 0 && !ctx->op && ctx->slot) { 624 0 624
if (item_block_index < 0 && !ctx->op && ctx->slot) { 624 0 624
4106 /* Leaf list item settled from a promise: result coercion against
4107 * the inner type (armed with a slot but no op / block index). */
4108 624 SV *leaf_error = NULL;
4109 624 ret = gql_runtime_vm_serialize_leaf_sv(
4110 624 aTHX_ gql_runtime_vm_exec_state_native_runtime(aTHX_ s), ctx->slot, resolved_sv, &leaf_error
4111 );
4112 624 ▶ if (leaf_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_error) { 1 623 624
4113 1 ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ leaf_error, ctx->path_frame);
4114 1 SvREFCNT_dec(leaf_error);
4115 }
4116 17 ▶ } else if (item_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (item_block_index < 0) { 0 17 17
4117 0 ret = newSVsv(resolved_sv);
4118 } else {
4119 /* Mode 2: sync completion yields a native outcome; the list_pending
4120 * consumer converts outcomes without materializing. */
4121 17 ret = gql_runtime_vm_exec_state_execute_block_async_path_sv(
4122 aTHX_
4123 ctx->state_sv,
4124 s,
4125 item_block_index,
4126 resolved_sv,
4127 ctx->path_frame,
4128 2
4129 );
4130 }
4131 }
4132  
4133 644 ▶ ST(0) = sv_2mortal(ret ? ret : newSVsv(&PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = sv_2mortal(ret ? ret : newSVsv(&PL_sv_undef)); 0 644 644
4134 644 XSRETURN(1);
4135 }
4136  
4137 2 static XS(gql_runtime_vm_xs_error_callback)
4138 {
4139 dVAR;
4140 2 dXSARGS;
4141 2 gql_runtime_vm_error_callback_ctx_t *ctx = INT2PTR(
4142 gql_runtime_vm_error_callback_ctx_t *,
4143 CvXSUBANY(cv).any_ptr
4144 );
4145 2 ▶ SV *error_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *error_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 2 0 2
SV *error_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 2 0 2
4146 2 ▶ SV *ret = gql_runtime_vm_new_error_outcome_for_path_sv(
Branch: 1 branch
BranchTrueFalseTotal
SV *ret = gql_runtime_vm_new_error_outcome_for_path_sv( 2 0 2
4147 aTHX_
4148 error_sv,
4149 ctx ? ctx->path_frame : NULL
4150 );
4151  
4152 2 ▶ ST(0) = sv_2mortal(ret ? ret : newSVsv(&PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = sv_2mortal(ret ? ret : newSVsv(&PL_sv_undef)); 0 2 2
4153 2 XSRETURN(1);
4154 }
4155  
4156 0 static XS(gql_runtime_vm_xs_finalize_callback)
4157 {
4158 dVAR;
4159 0 dXSARGS;
4160 0 gql_runtime_vm_finalize_callback_ctx_t *ctx = INT2PTR(
4161 gql_runtime_vm_finalize_callback_ctx_t *,
4162 CvXSUBANY(cv).any_ptr
4163 );
4164 0 SV *resolved_sv = &PL_sv_undef;
4165 0 SV *tmp_resolved = NULL;
4166 SV *ret;
4167  
4168 0 ▶ if (!ctx || !ctx->merge) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ctx || !ctx->merge) { 0 0 0
if (!ctx || !ctx->merge) { 0 0 0
4169 0 XSRETURN_UNDEF;
4170 }
4171  
4172 0 ▶ if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
4173 0 resolved_sv = ST(0);
4174 } else {
4175 0 AV *resolved_av = newAV();
4176 I32 i;
4177 0 ▶ for (i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) { 0 0 0
4178 0 ▶ av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef)); 0 0 0
4179 }
4180 0 tmp_resolved = newRV_noinc((SV *)resolved_av);
4181 0 resolved_sv = tmp_resolved;
4182 }
4183  
4184 0 ret = gql_runtime_vm_pending_merge_resolve_sv(aTHX_ ctx->merge, resolved_sv);
4185 0 ▶ if (tmp_resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_resolved) { 0 0 0
4186 0 SvREFCNT_dec(tmp_resolved);
4187 }
4188  
4189 0 ▶ ST(0) = sv_2mortal(ret ? ret : newSVsv(&PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = sv_2mortal(ret ? ret : newSVsv(&PL_sv_undef)); 0 0 0
4190 0 XSRETURN(1);
4191 }
4192  
4193 static SV *
4194 1301 gql_runtime_vm_new_error_callback_sv(pTHX_ gql_runtime_vm_path_frame_t *path_frame)
4195 {
4196 CV *cv;
4197 SV *rv;
4198 gql_runtime_vm_error_callback_ctx_t *ctx;
4199  
4200 1301 Newxz(ctx, 1, gql_runtime_vm_error_callback_ctx_t);
4201 1301 ctx->path_frame = path_frame;
4202 1301 ▶ if (ctx->path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->path_frame) { 1301 0 1301
4203 1301 ctx->path_frame->refcount++;
4204 }
4205  
4206 1301 cv = newXS(NULL, gql_runtime_vm_xs_error_callback, __FILE__);
4207 1301 CvXSUBANY(cv).any_ptr = ctx;
4208 1301 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)cv, &gql_runtime_vm_error_callback_ctx_vtbl, ctx);
4209 1301 rv = newRV_noinc((SV *)cv);
4210 1301 return rv;
4211 }
4212  
4213 static SV *
4214 646 gql_runtime_vm_new_list_item_child_callback_sv(
4215 pTHX_
4216 SV *state_sv,
4217 gql_runtime_vm_path_frame_t *path_frame,
4218 IV child_block_index,
4219 const gql_runtime_vm_native_op_t *op,
4220 const gql_runtime_vm_native_slot_t *slot
4221 )
4222 {
4223 CV *cv;
4224 SV *rv;
4225 gql_runtime_vm_list_item_child_ctx_t *ctx;
4226  
4227 646 Newxz(ctx, 1, gql_runtime_vm_list_item_child_ctx_t);
4228 646 ▶ ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL; 646 0 646
4229 646 ctx->path_frame = path_frame;
4230 646 ▶ if (ctx->path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->path_frame) { 646 0 646
4231 646 ctx->path_frame->refcount++;
4232 }
4233 646 ctx->child_block_index = child_block_index;
4234 646 ctx->op = op;
4235 646 ctx->slot = slot;
4236  
4237 646 cv = newXS(NULL, gql_runtime_vm_xs_list_item_child_callback, __FILE__);
4238 646 CvXSUBANY(cv).any_ptr = ctx;
4239 646 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)cv, &gql_runtime_vm_list_item_child_ctx_vtbl, ctx);
4240 646 rv = newRV_noinc((SV *)cv);
4241 646 return rv;
4242 }
4243  
4244 static SV *
4245 0 gql_runtime_vm_new_finalize_callback_sv(pTHX_ gql_runtime_vm_pending_merge_t *merge)
4246 {
4247 CV *cv;
4248 SV *rv;
4249 gql_runtime_vm_finalize_callback_ctx_t *ctx;
4250  
4251 0 Newxz(ctx, 1, gql_runtime_vm_finalize_callback_ctx_t);
4252 0 ctx->merge = merge;
4253 0 gql_runtime_vm_pending_merge_incref(merge);
4254  
4255 0 cv = newXS(NULL, gql_runtime_vm_xs_finalize_callback, __FILE__);
4256 0 CvXSUBANY(cv).any_ptr = ctx;
4257 0 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)cv, &gql_runtime_vm_finalize_callback_ctx_vtbl, ctx);
4258 0 rv = newRV_noinc((SV *)cv);
4259 0 return rv;
4260 }
4261  
4262 static SV *
4263 0 gql_runtime_vm_new_outcome_handle_sv(pTHX_ U8 kind_code, SV *value, SV *error_records)
4264 {
4265 0 ▶ gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(
Branch: 2 branches
BranchTrueFalseTotal
gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct( 0 0 0
gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct( 0 0 0
4266 aTHX_
4267 kind_code,
4268 value ? value : &PL_sv_undef,
4269 error_records ? error_records : &PL_sv_undef
4270 );
4271 0 SV *ret = gql_runtime_vm_wrap_outcome_sv(aTHX_ outcome);
4272 0 gql_runtime_vm_outcome_decref(aTHX_ outcome);
4273 0 return ret;
4274 }
4275  
4276 /* Sync-completion results for callers that consume outcome structs directly
4277 * (outcome_out != NULL): hand over a caller-owned struct and skip the
4278 * bless-then-DESTROY round trip of an SV handle, which the block execution
4279 * loops otherwise pay once per field. */
4280 static SV *
4281 2676 gql_runtime_vm_sync_outcome_result_sv(
4282 pTHX_
4283 U8 kind_code,
4284 SV *value,
4285 gql_runtime_vm_outcome_t **outcome_out
4286 )
4287 {
4288 2676 ▶ if (outcome_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out) { 2676 0 2676
4289 2676 ▶ *outcome_out = gql_runtime_vm_new_outcome_struct(
Branch: 1 branch
BranchTrueFalseTotal
*outcome_out = gql_runtime_vm_new_outcome_struct( 2676 0 2676
4290 aTHX_
4291 kind_code,
4292 value ? value : &PL_sv_undef,
4293 &PL_sv_undef
4294 );
4295 2676 return NULL;
4296 }
4297 0 return gql_runtime_vm_new_outcome_handle_sv(aTHX_ kind_code, value, &PL_sv_undef);
4298 }
4299  
4300 /* Passthrough for a value that is already a wrapped outcome handle SV. */
4301 static SV *
4302 216 gql_runtime_vm_outcome_result_from_handle_sv(
4303 pTHX_
4304 SV *handle_sv,
4305 gql_runtime_vm_outcome_t **outcome_out
4306 )
4307 {
4308 216 ▶ if (outcome_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out) { 216 0 216
4309 216 *outcome_out = gql_runtime_vm_expect_outcome(aTHX_ handle_sv);
4310 216 gql_runtime_vm_outcome_incref(*outcome_out);
4311 216 SvREFCNT_dec(handle_sv);
4312 216 return NULL;
4313 }
4314 0 return handle_sv;
4315 }
4316  
4317 static SV *
4318 117 gql_runtime_vm_call_then_promise_xs_sv(
4319 pTHX_
4320 SV *promise_sv,
4321 SV *callback_sv,
4322 SV *error_callback_sv,
4323 gql_runtime_vm_path_frame_t *path_frame
4324 )
4325 {
4326 117 dSP;
4327 117 SV *ret = NULL;
4328 117 SV *stack_ret = NULL;
4329  
4330 117 ▶ if (!promise_sv || !SvOK(promise_sv) || !gql_runtime_vm_is_promise_xs_value_sv(promise_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!promise_sv || !SvOK(promise_sv) || !gql_runtime_vm_is_promise_xs_value_sv(promise_sv)) { 117 0 117
if (!promise_sv || !SvOK(promise_sv) || !gql_runtime_vm_is_promise_xs_value_sv(promise_sv)) { 117 0 117
if (!promise_sv || !SvOK(promise_sv) || !gql_runtime_vm_is_promise_xs_value_sv(promise_sv)) { 0 117 117
4331 0 ▶ return gql_runtime_vm_call_callback_scalar_sv(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_call_callback_scalar_sv( 0 0 0
4332 aTHX_
4333 callback_sv,
4334 promise_sv ? promise_sv : &PL_sv_undef,
4335 path_frame
4336 );
4337 }
4338  
4339 117 ENTER;
4340 117 SAVETMPS;
4341 117 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 117 0 117
4342 117 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 117 117
4343 117 ▶ XPUSHs(promise_sv ? promise_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(promise_sv ? promise_sv : &PL_sv_undef); 0 117 117
XPUSHs(promise_sv ? promise_sv : &PL_sv_undef); 117 0 117
4344 117 ▶ XPUSHs(callback_sv ? callback_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(callback_sv ? callback_sv : &PL_sv_undef); 0 117 117
XPUSHs(callback_sv ? callback_sv : &PL_sv_undef); 117 0 117
4345 117 ▶ if (error_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_callback_sv) { 117 0 117
4346 117 ▶ XPUSHs(error_callback_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(error_callback_sv); 0 117 117
4347 }
4348 117 PUTBACK;
4349 {
4350 117 CV *then_cv = gql_runtime_vm_promise_xs_then_cv_get(aTHX);
4351 117 ▶ if (then_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (then_cv) { 117 0 117
4352 117 call_sv((SV *)then_cv, G_SCALAR | G_EVAL);
4353 } else {
4354 0 call_method("then", G_SCALAR | G_EVAL);
4355 }
4356 }
4357 117 SPAGAIN;
4358 117 ▶ if (SP > PL_stack_base) {
Branch: 1 branch
BranchTrueFalseTotal
if (SP > PL_stack_base) { 117 0 117
4359 117 stack_ret = POPs;
4360 }
4361 117 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 117 0 117
if (SvTRUE(ERRSV)) { 0 117 117
4362 0 ret = gql_runtime_vm_new_error_outcome_for_path_sv(
4363 aTHX_
4364 0 ▶ ERRSV,
Branch: 1 branch
BranchTrueFalseTotal
ERRSV, 0 0 0
4365 path_frame
4366 );
4367 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4368 117 ▶ } else if (stack_ret) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (stack_ret) { 117 0 117
4369 117 ▶ ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef); 117 0 117
4370 }
4371 117 PUTBACK;
4372 117 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 117 0 117
4373 117 LEAVE;
4374  
4375 117 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 117 117
4376 }
4377  
4378 static SV *
4379 132 gql_runtime_vm_call_then_adapter_sv(
4380 pTHX_
4381 gql_runtime_vm_async_adapter_t *adapter,
4382 SV *promise_sv,
4383 SV *callback_sv,
4384 SV *error_callback_sv,
4385 gql_runtime_vm_path_frame_t *path_frame
4386 )
4387 {
4388 132 dSP;
4389 132 SV *ret = NULL;
4390 132 SV *stack_ret = NULL;
4391 I32 count;
4392  
4393 132 ▶ if (gql_runtime_vm_sv_is_promise_xs(aTHX_ promise_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_promise_xs(aTHX_ promise_sv)) { 112 20 132
4394 112 return gql_runtime_vm_call_then_promise_xs_sv(
4395 aTHX_ promise_sv, callback_sv, error_callback_sv, path_frame
4396 );
4397 }
4398 20 ▶ if (!gql_runtime_vm_sv_is_adapter_promise(aTHX_ adapter, promise_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_is_adapter_promise(aTHX_ adapter, promise_sv)) { 1 19 20
4399 1 ▶ return gql_runtime_vm_call_callback_scalar_sv(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_call_callback_scalar_sv( 1 0 1
4400 aTHX_ callback_sv, promise_sv ? promise_sv : &PL_sv_undef, path_frame
4401 );
4402 }
4403 19 ▶ if (!adapter || !adapter->then_cv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!adapter || !adapter->then_cv) { 19 0 19
if (!adapter || !adapter->then_cv) { 0 19 19
4404 0 croak("invalid async adapter");
4405 }
4406  
4407 19 ENTER;
4408 19 SAVETMPS;
4409 19 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 19 0 19
4410 19 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 19 19
4411 19 ▶ XPUSHs(promise_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(promise_sv); 0 19 19
4412 19 ▶ XPUSHs(callback_sv ? callback_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(callback_sv ? callback_sv : &PL_sv_undef); 0 19 19
XPUSHs(callback_sv ? callback_sv : &PL_sv_undef); 19 0 19
4413 19 ▶ if (error_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_callback_sv) { 2 17 19
4414 2 ▶ XPUSHs(error_callback_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(error_callback_sv); 0 2 2
4415 }
4416 19 PUTBACK;
4417 19 count = call_sv((SV *)adapter->then_cv, G_SCALAR | G_EVAL);
4418 19 SPAGAIN;
4419 19 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 19 0 19
4420 19 stack_ret = POPs;
4421 }
4422 19 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 19 0 19
if (SvTRUE(ERRSV)) { 0 19 19
4423 0 ▶ ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ ERRSV, path_frame);
Branch: 1 branch
BranchTrueFalseTotal
ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ ERRSV, path_frame); 0 0 0
4424 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4425 19 ▶ } else if (stack_ret) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (stack_ret) { 19 0 19
4426 19 ret = newSVsv(stack_ret);
4427 }
4428 19 PUTBACK;
4429 19 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 19 0 19
4430 19 LEAVE;
4431 19 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 19 19
4432 }
4433  
4434 static SV *
4435 0 gql_runtime_vm_adapter_error_sv(pTHX_ SV *outcome_sv)
4436 {
4437 gql_runtime_vm_outcome_t *outcome =
4438 0 gql_runtime_vm_expect_outcome(aTHX_ outcome_sv);
4439 0 SV *error_sv = newSVpv("async adapter then failed", 0);
4440 0 ▶ if (outcome->error_record_count > 0
Branch: 1 branch
BranchTrueFalseTotal
if (outcome->error_record_count > 0 0 0 0
4441 0 ▶ && outcome->error_records[0]
Branch: 1 branch
BranchTrueFalseTotal
&& outcome->error_records[0] 0 0 0
4442 0 ▶ && outcome->error_records[0]->message_pv) {
Branch: 1 branch
BranchTrueFalseTotal
&& outcome->error_records[0]->message_pv) { 0 0 0
4443 0 sv_setpv(error_sv, outcome->error_records[0]->message_pv);
4444 0 ▶ if (outcome->error_records[0]->message_pv_is_utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome->error_records[0]->message_pv_is_utf8) { 0 0 0
4445 0 SvUTF8_on(error_sv);
4446 }
4447 }
4448 0 return error_sv;
4449 }
4450  
4451 static SV *
4452 0 gql_runtime_vm_call_all_promise_xs_sv(
4453 pTHX_
4454 AV *values_av,
4455 gql_runtime_vm_path_frame_t *path_frame
4456 )
4457 {
4458 0 dSP;
4459 0 SV *aggregate = NULL;
4460 0 SV *flatten_callback_sv = NULL;
4461 0 SV *ret = NULL;
4462 SSize_t i;
4463  
4464 0 ENTER;
4465 0 SAVETMPS;
4466 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4467 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
4468 0 ▶ for (i = 0; values_av && i <= av_len(values_av); i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; values_av && i <= av_len(values_av); i++) { 0 0 0
for (i = 0; values_av && i <= av_len(values_av); i++) { 0 0 0
4469 0 SV **svp = av_fetch(values_av, i, 0);
4470 0 ▶ XPUSHs((svp && *svp) ? *svp : &PL_sv_undef);
Branch: 3 branches
BranchTrueFalseTotal
XPUSHs((svp && *svp) ? *svp : &PL_sv_undef); 0 0 0
XPUSHs((svp && *svp) ? *svp : &PL_sv_undef); 0 0 0
XPUSHs((svp && *svp) ? *svp : &PL_sv_undef); 0 0 0
4471 }
4472 0 PUTBACK;
4473 0 call_pv("Promise::XS::all", G_SCALAR | G_EVAL);
4474 0 SPAGAIN;
4475 0 ▶ if (!SvTRUE(ERRSV) && SP > PL_stack_base) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 0 0 0
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 0 0 0
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 0 0 0
4476 0 aggregate = POPs;
4477 0 ▶ aggregate = aggregate ? newSVsv(aggregate) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
aggregate = aggregate ? newSVsv(aggregate) : newSVsv(&PL_sv_undef); 0 0 0
4478 0 ▶ } else if (SP > PL_stack_base) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (SP > PL_stack_base) { 0 0 0
4479 0 (void)POPs;
4480 }
4481 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
4482 0 ret = gql_runtime_vm_new_error_outcome_for_path_sv(
4483 aTHX_
4484 0 ▶ ERRSV,
Branch: 1 branch
BranchTrueFalseTotal
ERRSV, 0 0 0
4485 path_frame
4486 );
4487 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4488 }
4489 0 PUTBACK;
4490 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
4491 0 LEAVE;
4492  
4493 0 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 0 0 0
4494 0 return ret;
4495 }
4496 0 ▶ if (!aggregate) {
Branch: 1 branch
BranchTrueFalseTotal
if (!aggregate) { 0 0 0
4497 0 return newSVsv(&PL_sv_undef);
4498 }
4499  
4500 0 flatten_callback_sv = gql_runtime_vm_promise_xs_flatten_all_callback_sv(aTHX);
4501 0 ret = gql_runtime_vm_call_then_promise_xs_sv(
4502 aTHX_
4503 aggregate,
4504 flatten_callback_sv,
4505 NULL,
4506 path_frame
4507 );
4508 0 SvREFCNT_dec(flatten_callback_sv);
4509 0 SvREFCNT_dec(aggregate);
4510  
4511 0 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 0 0
4512 }
4513  
4514 static SV *
4515 0 gql_runtime_vm_call_all_adapter_sv(
4516 pTHX_
4517 gql_runtime_vm_async_adapter_t *adapter,
4518 AV *values_av,
4519 gql_runtime_vm_path_frame_t *path_frame
4520 )
4521 {
4522 0 dSP;
4523 0 SV *ret = NULL;
4524 SV *values_rv;
4525 I32 count;
4526  
4527 0 ▶ if (adapter == &gql_runtime_vm_promise_xs_adapter) {
Branch: 1 branch
BranchTrueFalseTotal
if (adapter == &gql_runtime_vm_promise_xs_adapter) { 0 0 0
4528 0 return gql_runtime_vm_call_all_promise_xs_sv(aTHX_ values_av, path_frame);
4529 }
4530 0 ▶ if (!adapter || !adapter->all_cb) {
Branch: 2 branches
BranchTrueFalseTotal
if (!adapter || !adapter->all_cb) { 0 0 0
if (!adapter || !adapter->all_cb) { 0 0 0
4531 0 croak("async adapter has no all callback");
4532 }
4533 0 values_rv = newRV_inc((SV *)values_av);
4534 0 ENTER;
4535 0 SAVETMPS;
4536 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4537 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
4538 0 ▶ XPUSHs(sv_2mortal(values_rv));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(values_rv)); 0 0 0
4539 0 PUTBACK;
4540 0 count = call_sv(adapter->all_cb, G_SCALAR | G_EVAL);
4541 0 SPAGAIN;
4542 0 ▶ if (!SvTRUE(ERRSV) && count > 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) { 0 0 0
if (!SvTRUE(ERRSV) && count > 0) { 0 0 0
if (!SvTRUE(ERRSV) && count > 0) { 0 0 0
4543 0 ret = newSVsv(POPs);
4544 0 ▶ } else if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (count > 0) { 0 0 0
4545 0 (void)POPs;
4546 }
4547 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
4548 0 ▶ ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ ERRSV, path_frame);
Branch: 1 branch
BranchTrueFalseTotal
ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ ERRSV, path_frame); 0 0 0
4549 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4550 }
4551 0 PUTBACK;
4552 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
4553 0 LEAVE;
4554 0 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 0 0
4555 }
4556  
4557 static SV *
4558 70 gql_runtime_vm_promise_xs_new_deferred_sv(pTHX)
4559 {
4560 70 dSP;
4561 70 SV *ret = NULL;
4562  
4563 70 ENTER;
4564 70 SAVETMPS;
4565 70 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 70 0 70
4566 70 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 70 70
4567 70 PUTBACK;
4568 {
4569 static CV *deferred_cv = NULL;
4570 70 ▶ if (!deferred_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!deferred_cv) { 8 62 70
4571 8 deferred_cv = get_cv("Promise::XS::deferred", 0);
4572 8 ▶ if (deferred_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (deferred_cv) { 8 0 8
4573 8 SvREFCNT_inc_simple_void_NN((SV *)deferred_cv);
4574 }
4575 }
4576 70 ▶ if (deferred_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (deferred_cv) { 70 0 70
4577 70 call_sv((SV *)deferred_cv, G_SCALAR | G_EVAL);
4578 } else {
4579 0 call_pv("Promise::XS::deferred", G_SCALAR | G_EVAL);
4580 }
4581 }
4582 70 SPAGAIN;
4583 70 ▶ if (!SvTRUE(ERRSV) && SP > PL_stack_base) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 70 0 70
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 70 0 70
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 70 0 70
4584 70 SV *stack_ret = POPs;
4585 70 ▶ ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef); 70 0 70
4586 0 ▶ } else if (SP > PL_stack_base) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (SP > PL_stack_base) { 0 0 0
4587 0 (void)POPs;
4588 }
4589 70 PUTBACK;
4590 70 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 70 0 70
4591 70 LEAVE;
4592  
4593 70 ▶ if (!ret || !SvOK(ret)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ret || !SvOK(ret)) { 70 0 70
if (!ret || !SvOK(ret)) { 0 70 70
4594 0 croak("failed to create Promise::XS deferred");
4595 }
4596 70 return ret;
4597 }
4598  
4599 static SV *
4600 70 gql_runtime_vm_promise_xs_deferred_promise_sv(pTHX_ SV *deferred_sv)
4601 {
4602 70 dSP;
4603 70 SV *ret = NULL;
4604  
4605 70 ▶ if (!deferred_sv || !SvOK(deferred_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!deferred_sv || !SvOK(deferred_sv)) { 70 0 70
if (!deferred_sv || !SvOK(deferred_sv)) { 0 70 70
4606 0 return newSVsv(&PL_sv_undef);
4607 }
4608  
4609 70 ENTER;
4610 70 SAVETMPS;
4611 70 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 70 0 70
4612 70 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 70 70
4613 70 ▶ XPUSHs(deferred_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(deferred_sv); 0 70 70
4614 70 PUTBACK;
4615 70 call_method("promise", G_SCALAR | G_EVAL);
4616 70 SPAGAIN;
4617 70 ▶ if (!SvTRUE(ERRSV) && SP > PL_stack_base) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 70 0 70
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 70 0 70
if (!SvTRUE(ERRSV) && SP > PL_stack_base) { 70 0 70
4618 70 SV *stack_ret = POPs;
4619 70 ▶ ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ret = stack_ret ? newSVsv(stack_ret) : newSVsv(&PL_sv_undef); 70 0 70
4620 0 ▶ } else if (SP > PL_stack_base) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (SP > PL_stack_base) { 0 0 0
4621 0 (void)POPs;
4622 }
4623 70 PUTBACK;
4624 70 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 70 0 70
4625 70 LEAVE;
4626  
4627 70 ▶ if (!ret || !SvOK(ret)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ret || !SvOK(ret)) { 70 0 70
if (!ret || !SvOK(ret)) { 0 70 70
4628 0 croak("failed to fetch Promise::XS deferred promise");
4629 }
4630 70 return ret;
4631 }
4632  
4633 static void
4634 66 gql_runtime_vm_promise_xs_deferred_resolve_sv(pTHX_ SV *deferred_sv, SV *value_sv)
4635 {
4636 66 dSP;
4637  
4638 66 ▶ if (!deferred_sv || !SvOK(deferred_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!deferred_sv || !SvOK(deferred_sv)) { 66 0 66
if (!deferred_sv || !SvOK(deferred_sv)) { 0 66 66
4639 0 return;
4640 }
4641  
4642 66 ENTER;
4643 66 SAVETMPS;
4644 66 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 66 0 66
4645 66 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 66 66
4646 66 ▶ XPUSHs(deferred_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(deferred_sv); 0 66 66
4647 66 ▶ XPUSHs(value_sv ? value_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(value_sv ? value_sv : &PL_sv_undef); 0 66 66
XPUSHs(value_sv ? value_sv : &PL_sv_undef); 66 0 66
4648 66 PUTBACK;
4649 66 call_pv("GraphQL::Houtou::Promise::PromiseXS::resolve_deferred_xs", G_VOID | G_EVAL);
4650 66 SPAGAIN;
4651 66 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 66 0 66
if (SvTRUE(ERRSV)) { 0 66 66
4652 0 ▶ SV *error_sv = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *error_sv = newSVsv(ERRSV); 0 0 0
4653 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4654 0 PUTBACK;
4655 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
4656 0 LEAVE;
4657 0 croak("failed to resolve Promise::XS deferred: %s", SvPV_nolen(error_sv));
4658 }
4659 66 PUTBACK;
4660 66 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 66 66
4661 66 LEAVE;
4662 }
4663  
4664 static SV *
4665 72 gql_runtime_vm_adapter_new_deferred_sv(pTHX_ gql_runtime_vm_async_adapter_t *adapter)
4666 {
4667 72 dSP;
4668 72 SV *ret = NULL;
4669 I32 count;
4670  
4671 72 ▶ if (adapter == &gql_runtime_vm_promise_xs_adapter) {
Branch: 1 branch
BranchTrueFalseTotal
if (adapter == &gql_runtime_vm_promise_xs_adapter) { 70 2 72
4672 70 return gql_runtime_vm_promise_xs_new_deferred_sv(aTHX);
4673 }
4674 2 ▶ if (!adapter || !adapter->new_pending_cb) {
Branch: 2 branches
BranchTrueFalseTotal
if (!adapter || !adapter->new_pending_cb) { 2 0 2
if (!adapter || !adapter->new_pending_cb) { 0 2 2
4675 0 croak("invalid async adapter pending factory");
4676 }
4677 2 ENTER;
4678 2 SAVETMPS;
4679 2 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 2 0 2
4680 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
4681 2 PUTBACK;
4682 2 count = call_sv(adapter->new_pending_cb, G_SCALAR | G_EVAL);
4683 2 SPAGAIN;
4684 2 ▶ if (!SvTRUE(ERRSV) && count > 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(ERRSV) && count > 0) { 2 0 2
if (!SvTRUE(ERRSV) && count > 0) { 2 0 2
if (!SvTRUE(ERRSV) && count > 0) { 2 0 2
4685 2 ret = newSVsv(POPs);
4686 0 ▶ } else if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (count > 0) { 0 0 0
4687 0 (void)POPs;
4688 }
4689 2 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 2 0 2
if (SvTRUE(ERRSV)) { 0 2 2
4690 0 SV *error_sv = newSVpvs("async adapter pending factory failed: ");
4691 0 ▶ sv_catsv(error_sv, ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
sv_catsv(error_sv, ERRSV); 0 0 0
4692 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4693 0 PUTBACK;
4694 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
4695 0 LEAVE;
4696 0 croak_sv(sv_2mortal(error_sv));
4697 }
4698 2 PUTBACK;
4699 2 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2 0 2
4700 2 LEAVE;
4701 2 ▶ if (!ret || !SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV
Branch: 3 branches
BranchTrueFalseTotal
if (!ret || !SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV 2 0 2
if (!ret || !SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV 2 0 2
if (!ret || !SvROK(ret) || SvTYPE(SvRV(ret)) != SVt_PVAV 2 0 2
4702 2 ▶ || av_count((AV *)SvRV(ret)) < 2) {
Branch: 1 branch
BranchTrueFalseTotal
|| av_count((AV *)SvRV(ret)) < 2) { 0 2 2
4703 0 ▶ if (ret) SvREFCNT_dec(ret);
Branch: 1 branch
BranchTrueFalseTotal
if (ret) SvREFCNT_dec(ret); 0 0 0
4704 0 croak("async adapter pending factory must return [promise, resolve]");
4705 }
4706 {
4707 2 AV *deferred_av = (AV *)SvRV(ret);
4708 2 SV **promise_svp = av_fetch(deferred_av, 0, 0);
4709 2 SV **resolve_svp = av_fetch(deferred_av, 1, 0);
4710 2 ▶ if (!promise_svp
Branch: 1 branch
BranchTrueFalseTotal
if (!promise_svp 2 0 2
4711 2 ▶ || !gql_runtime_vm_sv_is_adapter_promise(aTHX_ adapter, *promise_svp)
Branch: 1 branch
BranchTrueFalseTotal
|| !gql_runtime_vm_sv_is_adapter_promise(aTHX_ adapter, *promise_svp) 1 1 2
4712 1 ▶ || !resolve_svp || !SvROK(*resolve_svp)
Branch: 2 branches
BranchTrueFalseTotal
|| !resolve_svp || !SvROK(*resolve_svp) 1 0 1
|| !resolve_svp || !SvROK(*resolve_svp) 0 1 1
4713 0 ▶ || SvTYPE(SvRV(*resolve_svp)) != SVt_PVCV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*resolve_svp)) != SVt_PVCV) { 0 0 0
4714 2 SvREFCNT_dec(ret);
4715 2 croak("async adapter pending factory must return [promise, resolve coderef]");
4716 }
4717 }
4718 0 return ret;
4719 }
4720  
4721 static SV *
4722 70 gql_runtime_vm_adapter_deferred_promise_sv(
4723 pTHX_ gql_runtime_vm_async_adapter_t *adapter, SV *deferred_sv
4724 )
4725 {
4726 SV **svp;
4727 70 ▶ if (adapter == &gql_runtime_vm_promise_xs_adapter) {
Branch: 1 branch
BranchTrueFalseTotal
if (adapter == &gql_runtime_vm_promise_xs_adapter) { 70 0 70
4728 70 return gql_runtime_vm_promise_xs_deferred_promise_sv(aTHX_ deferred_sv);
4729 }
4730 0 svp = av_fetch((AV *)SvRV(deferred_sv), 0, 0);
4731 0 ▶ return newSVsv((svp && *svp) ? *svp : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
return newSVsv((svp && *svp) ? *svp : &PL_sv_undef); 0 0 0
return newSVsv((svp && *svp) ? *svp : &PL_sv_undef); 0 0 0
4732 }
4733  
4734 static void
4735 66 gql_runtime_vm_adapter_deferred_resolve_sv(
4736 pTHX_ gql_runtime_vm_async_adapter_t *adapter, SV *deferred_sv, SV *value_sv
4737 )
4738 {
4739 SV **cb_svp;
4740 66 dSP;
4741 66 ▶ if (adapter == &gql_runtime_vm_promise_xs_adapter) {
Branch: 1 branch
BranchTrueFalseTotal
if (adapter == &gql_runtime_vm_promise_xs_adapter) { 66 0 66
4742 66 gql_runtime_vm_promise_xs_deferred_resolve_sv(aTHX_ deferred_sv, value_sv);
4743 66 return;
4744 }
4745 0 cb_svp = av_fetch((AV *)SvRV(deferred_sv), 1, 0);
4746 0 ▶ if (!cb_svp || !*cb_svp || !SvOK(*cb_svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!cb_svp || !*cb_svp || !SvOK(*cb_svp)) { 0 0 0
if (!cb_svp || !*cb_svp || !SvOK(*cb_svp)) { 0 0 0
if (!cb_svp || !*cb_svp || !SvOK(*cb_svp)) { 0 0 0
4747 0 croak("invalid async adapter resolve callback");
4748 }
4749 0 ENTER;
4750 0 SAVETMPS;
4751 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4752 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
4753 0 ▶ XPUSHs(value_sv ? value_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(value_sv ? value_sv : &PL_sv_undef); 0 0 0
XPUSHs(value_sv ? value_sv : &PL_sv_undef); 0 0 0
4754 0 PUTBACK;
4755 0 call_sv(*cb_svp, G_VOID | G_DISCARD | G_EVAL);
4756 0 SPAGAIN;
4757 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
4758 0 SV *error_sv = newSVpvs("async adapter resolve failed: ");
4759 0 ▶ sv_catsv(error_sv, ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
sv_catsv(error_sv, ERRSV); 0 0 0
4760 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
4761 0 PUTBACK;
4762 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
4763 0 LEAVE;
4764 0 croak_sv(sv_2mortal(error_sv));
4765 }
4766 0 PUTBACK;
4767 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
4768 0 LEAVE;
4769 }
4770  
4771 static SV *
4772 655 gql_runtime_vm_new_list_pending_callback_sv(
4773 pTHX_
4774 SV *state_sv,
4775 gql_runtime_vm_list_pending_t *pending,
4776 IV index
4777 )
4778 {
4779 CV *cv;
4780 SV *rv;
4781 gql_runtime_vm_list_pending_callback_ctx_t *ctx;
4782  
4783 655 Newxz(ctx, 1, gql_runtime_vm_list_pending_callback_ctx_t);
4784 655 ctx->pending = pending;
4785 655 ▶ ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ctx->state_sv = state_sv ? SvREFCNT_inc_simple_NN(state_sv) : NULL; 655 0 655
4786 655 gql_runtime_vm_list_pending_incref(pending);
4787 655 ctx->index = index;
4788  
4789 655 cv = newXS(NULL, gql_runtime_vm_xs_list_pending_callback, __FILE__);
4790 655 CvXSUBANY(cv).any_ptr = ctx;
4791 655 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)cv, &gql_runtime_vm_list_pending_callback_ctx_vtbl, ctx);
4792 655 rv = newRV_noinc((SV *)cv);
4793 655 return rv;
4794 }
4795  
4796 static SV *
4797 648 gql_runtime_vm_list_pending_handle_sv(
4798 pTHX_
4799 SV *state_sv,
4800 gql_runtime_vm_exec_state_handle_t *s,
4801 AV *values_av,
4802 gql_runtime_vm_path_frame_t *path_frame
4803 )
4804 {
4805 gql_runtime_vm_list_pending_t *pending;
4806 SSize_t i;
4807  
4808 648 ▶ if (!values_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (!values_av) { 0 648 648
4809 0 return gql_runtime_vm_new_outcome_from_owned_native_value_handle_sv(
4810 aTHX_
4811 GQL_VM_KIND_LIST,
4812 gql_runtime_vm_new_native_value_list()
4813 );
4814 }
4815  
4816 648 Newxz(pending, 1, gql_runtime_vm_list_pending_t);
4817 648 pending->refcount = 1;
4818 648 pending->owner_frame = NULL;
4819 648 pending->values_value = gql_runtime_vm_new_native_value_list();
4820 648 pending->unresolved_count = 0;
4821 648 pending->pending_child_frame_count = av_len(values_av) + 1;
4822 648 ▶ Newxz(pending->pending_child_frames, pending->pending_child_frame_count, gql_runtime_vm_block_frame_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(pending->pending_child_frames, pending->pending_child_frame_count, gql_runtime_vm_block_frame_t *); 0 648 648
4823  
4824 2157 ▶ for (i = 0; i <= av_len(values_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(values_av); i++) { 1509 648 2157
4825 1509 SV **svp = av_fetch(values_av, i, 0);
4826 1509 ▶ SV *value_sv = (svp && *svp) ? *svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *value_sv = (svp && *svp) ? *svp : &PL_sv_undef; 1509 0 1509
SV *value_sv = (svp && *svp) ? *svp : &PL_sv_undef; 1509 0 1509
4827  
4828 1509 ▶ if (gql_runtime_vm_is_block_frame_value_sv(value_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_block_frame_value_sv(value_sv) 657 852 1509
4829 657 ▶ || gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
|| gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, value_sv)) { 655 2 657
4830 1507 pending->unresolved_count++;
4831 1507 gql_runtime_vm_native_list_store_at(
4832 aTHX_
4833 pending->values_value,
4834 i,
4835 gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef)
4836 );
4837 } else {
4838 /* Freshly completed sync item: the values AV is its sole owner. */
4839 2 gql_runtime_vm_native_list_store_at(
4840 aTHX_
4841 pending->values_value,
4842 i,
4843 gql_runtime_vm_native_value_take_completed_item_sv(aTHX_ value_sv)
4844 );
4845 }
4846 }
4847  
4848 2157 ▶ for (i = 0; i <= av_len(values_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(values_av); i++) { 1509 648 2157
4849 1509 SV **svp = av_fetch(values_av, i, 0);
4850 1509 ▶ SV *value_sv = (svp && *svp) ? *svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *value_sv = (svp && *svp) ? *svp : &PL_sv_undef; 1509 0 1509
SV *value_sv = (svp && *svp) ? *svp : &PL_sv_undef; 1509 0 1509
4851  
4852 1509 ▶ if (gql_runtime_vm_is_block_frame_value_sv(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_block_frame_value_sv(value_sv)) { 852 657 1509
4853 /* Phase 11: this item's own child block suspended
4854 * (gql_runtime_vm_execute_safe_child_block_fast_sv, called with
4855 * want_promise=0 at the list-item site too now) - link the raw
4856 * frame directly instead of ever building a Promise::XS for it.
4857 * If it already settled synchronously by the time we get here
4858 * (mirrors the object/abstract-field call site's own immediate-
4859 * settle check), enqueue+drain right away; otherwise
4860 * gql_runtime_vm_async_scheduler_resolve_frame's parent_list_pending
4861 * branch notices when it settles later. */
4862 852 gql_runtime_vm_block_frame_t *child_frame = gql_runtime_vm_expect_block_frame(aTHX_ value_sv);
4863 852 gql_runtime_vm_list_pending_link_child_frame(aTHX_ pending, i, child_frame);
4864 852 ▶ if (child_frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_frame->pending_unresolved == 0) { 0 852 852
4865 0 gql_runtime_vm_async_scheduler_enqueue_frame(s, child_frame);
4866 0 ▶ if (!s->async_scheduler_draining) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->async_scheduler_draining) { 0 0 0
4867 0 gql_runtime_vm_async_scheduler_drain(aTHX_ state_sv, s);
4868 }
4869 }
4870 657 ▶ } else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, value_sv)) { 655 2 657
4871 655 SV *callback_sv = gql_runtime_vm_new_list_pending_callback_sv(aTHX_ state_sv, pending, i);
4872 655 SV *error_callback_sv = gql_runtime_vm_new_error_callback_sv(aTHX_ path_frame);
4873 SV *ret;
4874  
4875 655 ret = gql_runtime_vm_call_then_promise_for_state_sv(
4876 aTHX_
4877 s,
4878 value_sv,
4879 callback_sv,
4880 error_callback_sv,
4881 path_frame
4882 );
4883  
4884 655 SvREFCNT_dec(callback_sv);
4885 655 SvREFCNT_dec(error_callback_sv);
4886  
4887 655 ▶ if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) {
Branch: 3 branches
BranchTrueFalseTotal
if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) { 655 0 655
if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) { 655 0 655
if (ret && SvOK(ret) && gql_runtime_vm_sv_is_outcome(aTHX_ ret)) { 0 655 655
4888 0 gql_runtime_vm_native_list_store_at(
4889 aTHX_
4890 pending->values_value,
4891 i,
4892 gql_runtime_vm_native_value_from_list_pending_sv(aTHX_ ret)
4893 );
4894 0 pending->unresolved_count--;
4895 }
4896 655 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 655 0 655
4897 655 SvREFCNT_dec(ret);
4898 }
4899 }
4900 }
4901 {
4902 648 SV *ret = gql_runtime_vm_wrap_list_pending_sv(aTHX_ pending);
4903 648 gql_runtime_vm_list_pending_decref(aTHX_ pending);
4904 648 return ret;
4905 }
4906 }
4907  
4908 static SV *
4909 1362 gql_runtime_vm_call_then_promise_for_state_sv(
4910 pTHX_
4911 const gql_runtime_vm_exec_state_handle_t *s,
4912 SV *promise_sv,
4913 SV *callback_sv,
4914 SV *error_callback_sv,
4915 gql_runtime_vm_path_frame_t *path_frame
4916 )
4917 {
4918 1362 ▶ if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ promise_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ promise_sv)) { 1256 106 1362
4919 1256 dSP;
4920 1256 SV *ret = NULL;
4921 1256 ENTER;
4922 1256 SAVETMPS;
4923 1256 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1256 1256
4924 1256 ▶ XPUSHs(promise_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(promise_sv); 0 1256 1256
4925 1256 ▶ XPUSHs(callback_sv ? callback_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(callback_sv ? callback_sv : &PL_sv_undef); 0 1256 1256
XPUSHs(callback_sv ? callback_sv : &PL_sv_undef); 1256 0 1256
4926 1256 ▶ XPUSHs(error_callback_sv ? error_callback_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(error_callback_sv ? error_callback_sv : &PL_sv_undef); 0 1256 1256
XPUSHs(error_callback_sv ? error_callback_sv : &PL_sv_undef); 1256 0 1256
4927 1256 PUTBACK;
4928 1256 call_method("_subscribe", G_SCALAR);
4929 1256 SPAGAIN;
4930 1256 ret = newSVsv(POPs);
4931 1256 PUTBACK;
4932 1256 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1256 0 1256
4933 1256 LEAVE;
4934 1256 return ret;
4935 }
4936 106 ▶ if (s && s->async_adapter != NULL) {
Branch: 2 branches
BranchTrueFalseTotal
if (s && s->async_adapter != NULL) { 106 0 106
if (s && s->async_adapter != NULL) { 106 0 106
4937 106 return gql_runtime_vm_call_then_adapter_sv(
4938 aTHX_
4939 106 s->async_adapter,
4940 promise_sv,
4941 callback_sv,
4942 error_callback_sv,
4943 path_frame
4944 );
4945 }
4946 0 croak("async runtime requires an async adapter");
4947 }
4948  
4949 static SV *
4950 0 gql_runtime_vm_exec_state_resolve_runtime_type_current_sv(
4951 pTHX_
4952 SV *state_sv,
4953 gql_runtime_vm_exec_state_handle_t *s,
4954 SV *resolved_sv,
4955 gql_runtime_vm_path_frame_t *path_frame,
4956 SV **error_out
4957 )
4958 {
4959 0 ▶ const gql_runtime_vm_native_slot_t *slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
const gql_runtime_vm_native_slot_t *slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 0 0 0
const gql_runtime_vm_native_slot_t *slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 0 0 0
4960 0 return gql_runtime_vm_exec_state_resolve_runtime_type_for_slot_sv(
4961 aTHX_
4962 state_sv,
4963 s,
4964 slot,
4965 resolved_sv,
4966 path_frame,
4967 error_out
4968 );
4969 }
4970  
4971 static SV *
4972 40 gql_runtime_vm_exec_state_resolve_runtime_type_for_slot_sv(
4973 pTHX_
4974 SV *state_sv,
4975 gql_runtime_vm_exec_state_handle_t *s,
4976 const gql_runtime_vm_native_slot_t *slot,
4977 SV *resolved_sv,
4978 gql_runtime_vm_path_frame_t *path_frame,
4979 SV **error_out
4980 )
4981 {
4982 40 const gql_runtime_vm_native_runtime_t *runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
4983 40 SV *abstract_type_sv = gql_runtime_vm_state_return_type_for_slot_sv(aTHX_ s, slot);
4984 40 SV *info_sv = NULL;
4985 HV *schema_hv;
4986 SV *runtime_cache_sv;
4987 SV *runtime_type_sv;
4988  
4989 40 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 40 0 40
4990 40 *error_out = NULL;
4991 }
4992  
4993 40 slot = gql_runtime_vm_effective_slot(runtime, slot);
4994 40 ▶ if (!slot || !slot->return_type_name || !*slot->return_type_name) {
Branch: 3 branches
BranchTrueFalseTotal
if (!slot || !slot->return_type_name || !*slot->return_type_name) { 40 0 40
if (!slot || !slot->return_type_name || !*slot->return_type_name) { 40 0 40
if (!slot || !slot->return_type_name || !*slot->return_type_name) { 0 40 40
4995 0 return NULL;
4996 }
4997  
4998 40 info_sv = gql_runtime_vm_new_lazy_info_for_path_sv(aTHX_ state_sv, s, path_frame);
4999 40 schema_hv = gql_runtime_vm_expect_hashref(aTHX_ s->runtime_schema, "runtime schema");
5000 40 runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "runtime_cache", 13);
5001 40 runtime_type_sv = gql_runtime_vm_resolve_runtime_type_for_abstract_sv(
5002 aTHX_
5003 runtime_cache_sv,
5004 40 slot->return_type_name,
5005 resolved_sv,
5006 s->context,
5007 info_sv,
5008 abstract_type_sv,
5009 error_out
5010 );
5011 40 SvREFCNT_dec(info_sv);
5012  
5013 40 return runtime_type_sv;
5014 }
5015  
5016 /* Pick the member block for one item of an abstract-typed list. Returns
5017 * -1 without an error only for null items; a present item that fails to
5018 * resolve to a member type sets *error_out (field error per the spec). */
5019 static IV
5020 39 gql_runtime_vm_abstract_list_item_block_index(
5021 pTHX_
5022 SV *state_sv,
5023 gql_runtime_vm_exec_state_handle_t *s,
5024 const gql_runtime_vm_native_op_t *op,
5025 const gql_runtime_vm_native_slot_t *slot,
5026 SV *item_sv,
5027 gql_runtime_vm_path_frame_t *item_path,
5028 SV **error_out
5029 )
5030 {
5031 SV *runtime_type_sv;
5032 39 IV child_block_index = -1;
5033  
5034 39 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 39 0 39
5035 39 *error_out = NULL;
5036 }
5037 39 ▶ if (!item_sv || !SvOK(item_sv) || !op || op->abstract_child_count <= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (!item_sv || !SvOK(item_sv) || !op || op->abstract_child_count <= 0) { 39 0 39
if (!item_sv || !SvOK(item_sv) || !op || op->abstract_child_count <= 0) { 39 0 39
if (!item_sv || !SvOK(item_sv) || !op || op->abstract_child_count <= 0) { 39 0 39
if (!item_sv || !SvOK(item_sv) || !op || op->abstract_child_count <= 0) { 0 39 39
5038 0 return -1;
5039 }
5040  
5041 39 runtime_type_sv = gql_runtime_vm_exec_state_resolve_runtime_type_for_slot_sv(
5042 aTHX_
5043 state_sv,
5044 s,
5045 slot,
5046 item_sv,
5047 item_path,
5048 error_out
5049 );
5050 39 ▶ if (error_out && *error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && *error_out) { 39 0 39
if (error_out && *error_out) { 0 39 39
5051 0 ▶ if (runtime_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_type_sv) { 0 0 0
5052 0 SvREFCNT_dec(runtime_type_sv);
5053 }
5054 0 return -1;
5055 }
5056 39 ▶ if (runtime_type_sv && SvOK(runtime_type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime_type_sv && SvOK(runtime_type_sv)) { 39 0 39
if (runtime_type_sv && SvOK(runtime_type_sv)) { 39 0 39
5057 39 child_block_index = gql_runtime_vm_find_abstract_child_block_index(
5058 op,
5059 gql_runtime_vm_type_name_from_sv(aTHX_ runtime_type_sv)
5060 );
5061 }
5062 39 ▶ if (runtime_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_type_sv) { 39 0 39
5063 39 SvREFCNT_dec(runtime_type_sv);
5064 }
5065 /* A present item whose member type cannot be resolved is a field error
5066 * (the -1/no-error return is reserved for null items). */
5067 39 ▶ if (child_block_index < 0 && error_out && !*error_out) {
Branch: 3 branches
BranchTrueFalseTotal
if (child_block_index < 0 && error_out && !*error_out) { 0 39 39
if (child_block_index < 0 && error_out && !*error_out) { 0 0 0
if (child_block_index < 0 && error_out && !*error_out) { 0 0 0
5068 0 ▶ *error_out = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
*error_out = newSVpvf( 0 0 0
*error_out = newSVpvf( 0 0 0
5069 "Abstract type %s must resolve to an Object type at runtime",
5070 slot && slot->return_type_name ? slot->return_type_name : "(unknown)"
5071 );
5072 }
5073 39 return child_block_index;
5074 }
5075  
5076 /*
5077 * Promise settlement commonly exposes a list of plain database rows. When
5078 * the child selection is only default scalar hash reads, executing it through
5079 * the resumable async frame machinery adds bookkeeping without adding any
5080 * suspension point. Prove that narrow shape before entering the sync fast
5081 * lane: rejecting references also excludes callable properties and promises.
5082 */
5083 static SV *
5084 496 gql_runtime_vm_try_execute_plain_hash_block_fast_sv(
5085 pTHX_
5086 gql_runtime_vm_exec_state_handle_t *s,
5087 IV block_index,
5088 SV *source,
5089 gql_runtime_vm_path_frame_t *path_frame
5090 )
5091 {
5092 gql_runtime_vm_native_runtime_t *runtime;
5093 gql_runtime_vm_native_bundle_t *bundle;
5094 gql_runtime_vm_native_block_t *block;
5095 HV *source_hv;
5096 IV i;
5097 gql_runtime_vm_native_value_t *object_value;
5098 gql_runtime_vm_outcome_t *outcome;
5099 SV *ret;
5100  
5101 496 ▶ if (!s || !s->native_program || !source || !SvOK(source)
Branch: 4 branches
BranchTrueFalseTotal
if (!s || !s->native_program || !source || !SvOK(source) 496 0 496
if (!s || !s->native_program || !source || !SvOK(source) 496 0 496
if (!s || !s->native_program || !source || !SvOK(source) 496 0 496
if (!s || !s->native_program || !source || !SvOK(source) 496 0 496
5102 496 ▶ || !SvROK(source) || SvTYPE(SvRV(source)) != SVt_PVHV
Branch: 2 branches
BranchTrueFalseTotal
|| !SvROK(source) || SvTYPE(SvRV(source)) != SVt_PVHV 496 0 496
|| !SvROK(source) || SvTYPE(SvRV(source)) != SVt_PVHV 496 0 496
5103 496 ▶ || sv_isobject(source)) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_isobject(source)) { 180 316 496
5104 180 return NULL;
5105 }
5106  
5107 316 runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
5108 316 bundle = gql_runtime_vm_native_program_cached_bundle(aTHX_ runtime, s->native_program);
5109 316 ▶ if (!runtime || !bundle || block_index < 0 || block_index >= bundle->block_count) {
Branch: 4 branches
BranchTrueFalseTotal
if (!runtime || !bundle || block_index < 0 || block_index >= bundle->block_count) { 316 0 316
if (!runtime || !bundle || block_index < 0 || block_index >= bundle->block_count) { 316 0 316
if (!runtime || !bundle || block_index < 0 || block_index >= bundle->block_count) { 316 0 316
if (!runtime || !bundle || block_index < 0 || block_index >= bundle->block_count) { 0 316 316
5110 0 return NULL;
5111 }
5112  
5113 316 block = &bundle->blocks[block_index];
5114 316 source_hv = (HV *)SvRV(source);
5115 316 ▶ if (block->plain_hash_projection_state == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (block->plain_hash_projection_state == 0) { 125 191 316
5116 125 block->plain_hash_projection_state = 2;
5117 194 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 153 41 194
5118 153 const gql_runtime_vm_native_op_t *op = &block->ops[i];
5119 const gql_runtime_vm_native_slot_t *slot;
5120 153 IV leaf_kind = GQL_VM_LEAF_NONE;
5121  
5122 153 ▶ if (op->slot_index < 0 || op->slot_index >= block->slot_count
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= block->slot_count 153 0 153
if (op->slot_index < 0 || op->slot_index >= block->slot_count 153 0 153
5123 153 ▶ || op->resolve_code != GQL_VM_RESOLVE_DEFAULT
Branch: 1 branch
BranchTrueFalseTotal
|| op->resolve_code != GQL_VM_RESOLVE_DEFAULT 109 44 153
5124 109 ▶ || op->complete_code != GQL_VM_COMPLETE_GENERIC
Branch: 1 branch
BranchTrueFalseTotal
|| op->complete_code != GQL_VM_COMPLETE_GENERIC 70 39 109
5125 70 ▶ || op->child_block_index >= 0 || op->abstract_child_count > 0
Branch: 2 branches
BranchTrueFalseTotal
|| op->child_block_index >= 0 || op->abstract_child_count > 0 70 0 70
|| op->child_block_index >= 0 || op->abstract_child_count > 0 70 0 70
5126 70 ▶ || op->has_directives || op->has_runtime_directives
Branch: 2 branches
BranchTrueFalseTotal
|| op->has_directives || op->has_runtime_directives 70 0 70
|| op->has_directives || op->has_runtime_directives 69 1 70
5127 69 ▶ || op->runtime_directives_sv) {
Branch: 1 branch
BranchTrueFalseTotal
|| op->runtime_directives_sv) { 0 69 69
5128 84 block->plain_hash_projection_state = 1;
5129 84 break;
5130 }
5131 69 slot = gql_runtime_vm_effective_slot(
5132 69 runtime, &block->slots[op->slot_index]
5133 );
5134 69 ▶ if (!slot || slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT
Branch: 2 branches
BranchTrueFalseTotal
if (!slot || slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT 69 0 69
if (!slot || slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT 69 0 69
5135 69 ▶ || (slot->accessor_name && slot->accessor_name_len)
Branch: 2 branches
BranchTrueFalseTotal
|| (slot->accessor_name && slot->accessor_name_len) 0 69 69
|| (slot->accessor_name && slot->accessor_name_len) 0 0 0
5136 69 ▶ || gql_runtime_vm_slot_resolver_sv(runtime, slot)) {
Branch: 1 branch
BranchTrueFalseTotal
|| gql_runtime_vm_slot_resolver_sv(runtime, slot)) { 0 69 69
5137 0 block->plain_hash_projection_state = 1;
5138 0 break;
5139 }
5140 69 ▶ if (runtime->callback_catalog
Branch: 1 branch
BranchTrueFalseTotal
if (runtime->callback_catalog 69 0 69
5141 69 ▶ && runtime->callback_catalog->slot_leaf_kinds
Branch: 1 branch
BranchTrueFalseTotal
&& runtime->callback_catalog->slot_leaf_kinds 69 0 69
5142 69 ▶ && slot->schema_slot_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index >= 0 69 0 69
5143 69 ▶ && slot->schema_slot_index < runtime->runtime_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index < runtime->runtime_slot_count) { 69 0 69
5144 69 leaf_kind = runtime->callback_catalog
5145 69 ->slot_leaf_kinds[slot->schema_slot_index];
5146 }
5147 69 ▶ if (leaf_kind == GQL_VM_LEAF_CUSTOM) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_kind == GQL_VM_LEAF_CUSTOM) { 0 69 69
5148 0 block->plain_hash_projection_state = 1;
5149 0 break;
5150 }
5151 }
5152 }
5153 316 ▶ if (block->plain_hash_projection_state != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (block->plain_hash_projection_state != 2) { 191 125 316
5154 191 return NULL;
5155 }
5156  
5157 273 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 148 125 273
5158 148 const gql_runtime_vm_native_op_t *op = &block->ops[i];
5159 const gql_runtime_vm_native_slot_t *slot =
5160 148 gql_runtime_vm_effective_slot(
5161 148 runtime, &block->slots[op->slot_index]
5162 );
5163 SV **value_svp;
5164 148 value_svp = hv_fetch(
5165 source_hv,
5166 slot->field_name,
5167 (I32)slot->field_name_len,
5168 0
5169 );
5170 148 ▶ if (value_svp && *value_svp && SvROK(*value_svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (value_svp && *value_svp && SvROK(*value_svp)) { 146 2 148
if (value_svp && *value_svp && SvROK(*value_svp)) { 146 0 146
if (value_svp && *value_svp && SvROK(*value_svp)) { 0 146 146
5171 0 return NULL;
5172 }
5173 }
5174  
5175 125 object_value = gql_runtime_vm_new_native_value_object();
5176 271 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 148 123 271
5177 148 const gql_runtime_vm_native_op_t *op = &block->ops[i];
5178 148 const gql_runtime_vm_native_slot_t *plan_slot = &block->slots[op->slot_index];
5179 const gql_runtime_vm_native_slot_t *slot =
5180 148 gql_runtime_vm_effective_slot(runtime, plan_slot);
5181 148 SV **value_svp = hv_fetch(
5182 source_hv,
5183 slot->field_name,
5184 (I32)slot->field_name_len,
5185 0
5186 );
5187 148 ▶ SV *value_sv = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *value_sv = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef; 146 2 148
SV *value_sv = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef; 146 0 146
5188 SV *serialized;
5189 148 SV *error_sv = NULL;
5190 148 int carries_error = 0;
5191  
5192 148 ▶ if (slot->field_name && strEQ(slot->field_name, "__typename")) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot->field_name && strEQ(slot->field_name, "__typename")) { 148 0 148
if (slot->field_name && strEQ(slot->field_name, "__typename")) { 1 147 148
5193 1 ▶ value_sv = block->type_name ? sv_2mortal(newSVpv(block->type_name, 0)) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
value_sv = block->type_name ? sv_2mortal(newSVpv(block->type_name, 0)) : &PL_sv_undef; 1 0 1
5194 }
5195 148 serialized = gql_runtime_vm_serialize_leaf_sv(
5196 aTHX_ runtime, slot, value_sv, &error_sv
5197 );
5198 148 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 148 148
5199 gql_runtime_vm_path_frame_t *field_path =
5200 0 gql_runtime_vm_new_result_path_frame(aTHX_ path_frame, plan_slot);
5201 gql_runtime_vm_outcome_t *error_outcome =
5202 0 gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ error_sv, field_path);
5203 IV j;
5204 0 ▶ for (j = 0; s->writer && j < error_outcome->error_record_count; j++) {
Branch: 2 branches
BranchTrueFalseTotal
for (j = 0; s->writer && j < error_outcome->error_record_count; j++) { 0 0 0
for (j = 0; s->writer && j < error_outcome->error_record_count; j++) { 0 0 0
5205 0 gql_runtime_vm_writer_push_error_record(s->writer, error_outcome->error_records[j]);
5206 }
5207 0 gql_runtime_vm_outcome_decref(aTHX_ error_outcome);
5208 0 gql_runtime_vm_path_frame_decref(field_path);
5209 0 SvREFCNT_dec(error_sv);
5210 0 ▶ if (serialized) {
Branch: 1 branch
BranchTrueFalseTotal
if (serialized) { 0 0 0
5211 0 SvREFCNT_dec(serialized);
5212 }
5213 0 serialized = newSVsv(&PL_sv_undef);
5214 0 carries_error = 1;
5215 }
5216  
5217 148 ▶ if ((!serialized || !SvOK(serialized)) && slot->return_type_kind_code == 8) {
Branch: 3 branches
BranchTrueFalseTotal
if ((!serialized || !SvOK(serialized)) && slot->return_type_kind_code == 8) { 148 0 148
if ((!serialized || !SvOK(serialized)) && slot->return_type_kind_code == 8) { 7 141 148
if ((!serialized || !SvOK(serialized)) && slot->return_type_kind_code == 8) { 2 5 7
5218 2 ▶ if (!carries_error && s->writer) {
Branch: 2 branches
BranchTrueFalseTotal
if (!carries_error && s->writer) { 2 0 2
if (!carries_error && s->writer) { 2 0 2
5219 gql_runtime_vm_path_frame_t *field_path =
5220 2 gql_runtime_vm_new_result_path_frame(aTHX_ path_frame, plan_slot);
5221 2 gql_runtime_vm_record_nonnull_violation(
5222 2 aTHX_ s->writer, block->type_name, slot->field_name, field_path
5223 );
5224 2 gql_runtime_vm_path_frame_decref(field_path);
5225 }
5226 2 ▶ if (serialized) {
Branch: 1 branch
BranchTrueFalseTotal
if (serialized) { 2 0 2
5227 2 SvREFCNT_dec(serialized);
5228 }
5229 2 gql_runtime_vm_native_value_destroy(aTHX_ object_value);
5230 2 outcome = gql_runtime_vm_new_outcome_struct(
5231 aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef
5232 );
5233 2 outcome->null_carries_error = 1;
5234 2 ret = gql_runtime_vm_wrap_outcome_sv(aTHX_ outcome);
5235 2 gql_runtime_vm_outcome_decref(aTHX_ outcome);
5236 2 return ret;
5237 }
5238  
5239 146 ▶ gql_runtime_vm_native_object_store(
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_object_store( 146 0 146
5240 aTHX_
5241 object_value,
5242 146 plan_slot->result_name,
5243 1,
5244 gql_runtime_vm_native_value_from_sv(
5245 aTHX_ serialized ? serialized : &PL_sv_undef
5246 )
5247 );
5248 146 ▶ if (serialized) {
Branch: 1 branch
BranchTrueFalseTotal
if (serialized) { 146 0 146
5249 146 SvREFCNT_dec(serialized);
5250 }
5251 }
5252  
5253 123 outcome = gql_runtime_vm_new_outcome_from_owned_native_value_struct(
5254 aTHX_ GQL_VM_KIND_OBJECT, object_value
5255 );
5256 123 ret = gql_runtime_vm_wrap_outcome_sv(aTHX_ outcome);
5257 123 gql_runtime_vm_outcome_decref(aTHX_ outcome);
5258 123 return ret;
5259 }
5260  
5261 static SV *
5262 3277 gql_runtime_vm_exec_state_complete_current_native_async_sv(
5263 pTHX_
5264 SV *state_sv,
5265 gql_runtime_vm_exec_state_handle_t *s,
5266 gql_runtime_vm_path_frame_t *path_frame,
5267 const gql_runtime_vm_native_op_t *op,
5268 const gql_runtime_vm_native_slot_t *slot,
5269 SV *resolved_sv,
5270 gql_runtime_vm_outcome_t **outcome_out
5271 )
5272 {
5273 3277 const gql_runtime_vm_native_runtime_t *runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
5274 3277 ▶ IV complete_code = op ? op->complete_code : 0;
Branch: 1 branch
BranchTrueFalseTotal
IV complete_code = op ? op->complete_code : 0; 3277 0 3277
5275  
5276 3277 slot = gql_runtime_vm_effective_slot(runtime, slot);
5277  
5278 3277 switch (complete_code) {
5279 303 case GQL_VM_COMPLETE_OBJECT:
5280 {
5281 303 ▶ IV child_block_index = op ? op->child_block_index : -1;
Branch: 1 branch
BranchTrueFalseTotal
IV child_block_index = op ? op->child_block_index : -1; 303 0 303
5282 SV *child_value;
5283  
5284 303 ▶ if (!resolved_sv || !SvOK(resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved_sv || !SvOK(resolved_sv)) { 303 0 303
if (!resolved_sv || !SvOK(resolved_sv)) { 59 244 303
5285 59 return gql_runtime_vm_sync_outcome_result_sv(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, outcome_out);
5286 }
5287 244 ▶ if (child_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index < 0) { 0 244 244
5288 0 return gql_runtime_vm_sync_outcome_result_sv(aTHX_ GQL_VM_KIND_SCALAR, resolved_sv, outcome_out);
5289 }
5290  
5291 /*
5292 * A loader commonly settles to a plain row hash whose selected
5293 * children are only default scalar reads. The list-completion path
5294 * already proves and executes that shape without a resumable child
5295 * frame; apply the same narrow fast path when the pending value is
5296 * the object field itself.
5297 */
5298 244 child_value = gql_runtime_vm_try_execute_plain_hash_block_fast_sv(
5299 aTHX_ s, child_block_index, resolved_sv, path_frame
5300 );
5301 244 ▶ if (child_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_value) { 44 200 244
5302 44 return gql_runtime_vm_outcome_result_from_handle_sv(
5303 aTHX_ child_value, outcome_out
5304 );
5305 }
5306  
5307 /* Mode 1: a synchronously completed child comes back as a native
5308 * outcome (returned as-is below) and a pending child as a raw
5309 * block-frame handle - no Promise::XS deferred/promise pair. Every
5310 * consumer of this value (consume_current_result_now, the scheduler's
5311 * resolved-value branch, pending merge) links handles into the
5312 * parent frame directly. */
5313 200 child_value = gql_runtime_vm_exec_state_execute_block_async_path_sv(
5314 aTHX_
5315 state_sv,
5316 s,
5317 child_block_index,
5318 resolved_sv,
5319 path_frame,
5320 1
5321 );
5322 200 ▶ if (gql_runtime_vm_is_block_frame_value_sv(child_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_block_frame_value_sv(child_value)) { 29 171 200
5323 29 return child_value;
5324 }
5325 171 ▶ if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) {
Branch: 3 branches
BranchTrueFalseTotal
if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) { 171 0 171
if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) { 171 0 171
if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) { 171 0 171
5326 171 return gql_runtime_vm_outcome_result_from_handle_sv(aTHX_ child_value, outcome_out);
5327 }
5328 0 ▶ if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, child_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, child_value)) { 0 0 0
5329 0 SV *callback_sv = gql_runtime_vm_wrap_object_outcome_callback_sv(aTHX);
5330 0 SV *ret = gql_runtime_vm_call_then_promise_for_state_sv(
5331 aTHX_
5332 s,
5333 child_value,
5334 callback_sv,
5335 NULL,
5336 path_frame
5337 );
5338 0 SvREFCNT_dec(callback_sv);
5339 0 SvREFCNT_dec(child_value);
5340 0 return ret;
5341 }
5342  
5343 {
5344 0 SV *ret = gql_runtime_vm_sync_outcome_result_sv(aTHX_ GQL_VM_KIND_OBJECT, child_value, outcome_out);
5345 0 SvREFCNT_dec(child_value);
5346 0 return ret;
5347 }
5348 }
5349 422 case GQL_VM_COMPLETE_LIST:
5350 {
5351 422 ▶ IV child_block_index = op ? op->child_block_index : -1;
Branch: 1 branch
BranchTrueFalseTotal
IV child_block_index = op ? op->child_block_index : -1; 422 0 422
5352 422 ▶ int abstract_items = (child_block_index < 0 && op && op->abstract_child_count > 0);
Branch: 3 branches
BranchTrueFalseTotal
int abstract_items = (child_block_index < 0 && op && op->abstract_child_count > 0); 245 177 422
int abstract_items = (child_block_index < 0 && op && op->abstract_child_count > 0); 245 0 245
int abstract_items = (child_block_index < 0 && op && op->abstract_child_count > 0); 13 232 245
5353 AV *items_av;
5354 AV *resolved_items_av;
5355 SSize_t i;
5356 422 int has_promise = 0;
5357  
5358 422 ▶ if (!resolved_sv || !SvOK(resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved_sv || !SvOK(resolved_sv)) { 422 0 422
if (!resolved_sv || !SvOK(resolved_sv)) { 67 355 422
5359 67 return gql_runtime_vm_sync_outcome_result_sv(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, outcome_out);
5360 }
5361 355 ▶ if (!SvROK(resolved_sv) || SvTYPE(SvRV(resolved_sv)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(resolved_sv) || SvTYPE(SvRV(resolved_sv)) != SVt_PVAV) { 355 0 355
if (!SvROK(resolved_sv) || SvTYPE(SvRV(resolved_sv)) != SVt_PVAV) { 0 355 355
5362 /* Non-list resolver result for a list field: field error + null,
5363 * never the raw value (same contract as the fast lanes). */
5364 0 SV *msg_sv = newSVpvs("list value must be an array reference");
5365 0 SV *ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ msg_sv, path_frame);
5366 0 SvREFCNT_dec(msg_sv);
5367 0 return ret;
5368 }
5369  
5370 355 items_av = (AV *)SvRV(resolved_sv);
5371 355 resolved_items_av = newAV();
5372 1302 ▶ for (i = 0; i <= av_len(items_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(items_av); i++) { 947 355 1302
5373 947 SV **item_svp = av_fetch(items_av, i, 0);
5374 947 ▶ SV *item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef; 947 0 947
SV *item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef; 947 0 947
5375 SV *item_result;
5376  
5377 1218 ▶ if (child_block_index >= 0 || abstract_items) {
Branch: 2 branches
BranchTrueFalseTotal
if (child_block_index >= 0 || abstract_items) { 715 232 947
if (child_block_index >= 0 || abstract_items) { 39 676 715
5378 271 SV *item_key = newSViv(i);
5379 gql_runtime_vm_path_frame_t *item_path =
5380 271 gql_runtime_vm_new_path_frame_struct(aTHX_ path_frame, item_key);
5381 271 ▶ if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, item_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, item_sv)) { 19 252 271
5382 /* The item itself is a promise (per-item loader shape). Defer
5383 * the child selection block until it settles; the derived
5384 * promise below resolves to the completed child value. For
5385 * abstract items the member block is picked at settle time. */
5386 19 ▶ SV *child_cb = gql_runtime_vm_new_list_item_child_callback_sv(
Branch: 2 branches
BranchTrueFalseTotal
SV *child_cb = gql_runtime_vm_new_list_item_child_callback_sv( 5 14 19
SV *child_cb = gql_runtime_vm_new_list_item_child_callback_sv( 5 14 19
5387 aTHX_ state_sv, item_path, child_block_index,
5388 abstract_items ? op : NULL,
5389 abstract_items ? slot : NULL
5390 );
5391 19 SV *error_cb = gql_runtime_vm_new_error_callback_sv(aTHX_ item_path);
5392 19 item_result = gql_runtime_vm_call_then_promise_for_state_sv(
5393 aTHX_ s, item_sv, child_cb, error_cb, item_path
5394 );
5395 19 SvREFCNT_dec(child_cb);
5396 19 SvREFCNT_dec(error_cb);
5397 } else {
5398 /* A null item completes as null: keep the block index at -1 so
5399 * it falls into the raw-value branch below. */
5400 252 ▶ IV item_block_index = SvOK(item_sv) ? child_block_index : -1;
Branch: 1 branch
BranchTrueFalseTotal
IV item_block_index = SvOK(item_sv) ? child_block_index : -1; 252 0 252
5401 252 SV *type_error_sv = NULL;
5402  
5403 252 ▶ if (abstract_items && SvOK(item_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (abstract_items && SvOK(item_sv)) { 34 218 252
if (abstract_items && SvOK(item_sv)) { 34 0 34
5404 34 item_block_index = gql_runtime_vm_abstract_list_item_block_index(
5405 aTHX_ state_sv, s, op, slot, item_sv, item_path, &type_error_sv
5406 );
5407 }
5408 252 ▶ if (type_error_sv && SvOK(type_error_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (type_error_sv && SvOK(type_error_sv)) { 0 252 252
if (type_error_sv && SvOK(type_error_sv)) { 0 0 0
5409 0 item_result = gql_runtime_vm_new_error_outcome_for_path_sv(
5410 aTHX_ type_error_sv, item_path
5411 );
5412 0 SvREFCNT_dec(type_error_sv);
5413 252 ▶ } else if (item_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (item_block_index < 0) { 0 252 252
5414 /* No matching member (or a null item): complete the raw
5415 * value, mirroring COMPLETE_ABSTRACT's fallback. */
5416 0 item_result = newSVsv(item_sv);
5417 } else {
5418 /* Mode 2: sync items come back as native outcomes (assembled
5419 * into the list natively below), pending items as promises
5420 * (routed through the list_pending machinery). */
5421 252 item_result = gql_runtime_vm_try_execute_plain_hash_block_fast_sv(
5422 aTHX_ s, item_block_index, item_sv, item_path
5423 );
5424 252 ▶ if (!item_result) {
Branch: 1 branch
BranchTrueFalseTotal
if (!item_result) { 171 81 252
5425 171 item_result = gql_runtime_vm_exec_state_execute_block_async_path_sv(
5426 aTHX_
5427 state_sv,
5428 s,
5429 item_block_index,
5430 item_sv,
5431 item_path,
5432 2
5433 );
5434 }
5435 }
5436 }
5437 271 gql_runtime_vm_path_frame_decref(item_path);
5438 271 SvREFCNT_dec(item_key);
5439 676 ▶ } else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, item_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, item_sv)) { 627 49 676
5440 /* Leaf list with a per-item promise: defer result coercion to
5441 * settle time (the list-item callback with block index -1 and a
5442 * slot but no op runs serialize_leaf_sv on the settled value). */
5443 627 SV *item_key = newSViv(i);
5444 gql_runtime_vm_path_frame_t *item_path =
5445 627 gql_runtime_vm_new_path_frame_struct(aTHX_ path_frame, item_key);
5446 627 SV *child_cb = gql_runtime_vm_new_list_item_child_callback_sv(
5447 aTHX_ state_sv, item_path, -1, NULL, slot
5448 );
5449 627 SV *error_cb = gql_runtime_vm_new_error_callback_sv(aTHX_ item_path);
5450 627 item_result = gql_runtime_vm_call_then_promise_for_state_sv(
5451 aTHX_ s, item_sv, child_cb, error_cb, item_path
5452 );
5453 627 SvREFCNT_dec(child_cb);
5454 627 SvREFCNT_dec(error_cb);
5455 627 gql_runtime_vm_path_frame_decref(item_path);
5456 627 SvREFCNT_dec(item_key);
5457 } else {
5458 /* Leaf list item: result coercion against the inner type. */
5459 49 SV *leaf_error = NULL;
5460 49 item_result = gql_runtime_vm_serialize_leaf_sv(
5461 49 aTHX_ gql_runtime_vm_exec_state_native_runtime(aTHX_ s), slot, item_sv, &leaf_error
5462 );
5463 49 ▶ if (leaf_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_error) { 0 49 49
5464 0 SV *item_key = newSViv(i);
5465 gql_runtime_vm_path_frame_t *item_path =
5466 0 gql_runtime_vm_new_path_frame_struct(aTHX_ path_frame, item_key);
5467 0 item_result = gql_runtime_vm_new_error_outcome_for_path_sv(
5468 aTHX_ leaf_error, item_path
5469 );
5470 0 SvREFCNT_dec(leaf_error);
5471 0 gql_runtime_vm_path_frame_decref(item_path);
5472 0 SvREFCNT_dec(item_key);
5473 }
5474 }
5475  
5476 947 ▶ if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, item_result)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, item_result)) { 655 292 947
5477 655 has_promise = 1;
5478 }
5479 947 av_push(resolved_items_av, item_result);
5480 }
5481  
5482 355 ▶ if (has_promise) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_promise) { 225 130 355
5483 225 SV *ret = gql_runtime_vm_list_pending_handle_sv(
5484 aTHX_
5485 state_sv,
5486 s,
5487 resolved_items_av,
5488 path_frame
5489 );
5490 225 SvREFCNT_dec((SV *)resolved_items_av);
5491 225 return ret;
5492 }
5493  
5494 {
5495 /* All items completed synchronously (native outcomes or plain
5496 * scalars): assemble the native list directly instead of wrapping
5497 * the SV array and reconverting it. */
5498 130 gql_runtime_vm_native_value_t *list_value = gql_runtime_vm_new_native_value_list();
5499 130 int item_null_violation = 0;
5500 421 ▶ for (i = 0; i <= av_len(resolved_items_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(resolved_items_av); i++) { 291 130 421
5501 291 SV **item_svp = av_fetch(resolved_items_av, i, 0);
5502 291 ▶ SV *completed_item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *completed_item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef; 291 0 291
SV *completed_item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef; 291 0 291
5503 gql_runtime_vm_native_value_t *item_native;
5504 /* Outcomes carry error records (unresolvable member types);
5505 * surface them before the value is flattened into the list,
5506 * mirroring the list_pending settle path. */
5507 291 ▶ if (SvOK(completed_item_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(completed_item_sv) 291 0 291
5508 291 ▶ && gql_runtime_vm_sv_is_outcome(aTHX_ completed_item_sv)
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_sv_is_outcome(aTHX_ completed_item_sv) 242 49 291
5509 242 ▶ && s->writer) {
Branch: 1 branch
BranchTrueFalseTotal
&& s->writer) { 242 0 242
5510 gql_runtime_vm_outcome_t *item_outcome =
5511 242 gql_runtime_vm_expect_outcome(aTHX_ completed_item_sv);
5512 IV k;
5513 242 ▶ for (k = 0; item_outcome && k < item_outcome->error_record_count; k++) {
Branch: 2 branches
BranchTrueFalseTotal
for (k = 0; item_outcome && k < item_outcome->error_record_count; k++) { 242 0 242
for (k = 0; item_outcome && k < item_outcome->error_record_count; k++) { 0 242 242
5514 0 gql_runtime_vm_writer_push_error_record(s->writer, item_outcome->error_records[k]);
5515 }
5516 }
5517 291 item_native = gql_runtime_vm_native_value_take_completed_item_sv(aTHX_ completed_item_sv);
5518  
5519 /* Non-Null list items ([T!]): a null item nulls the whole list.
5520 * The item's own error (if any) is already surfaced above; add
5521 * "Cannot return null" only when the null carries no error. */
5522 291 ▶ if (slot->item_non_null && gql_runtime_vm_native_value_is_null(item_native)) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot->item_non_null && gql_runtime_vm_native_value_is_null(item_native)) { 210 81 291
if (slot->item_non_null && gql_runtime_vm_native_value_is_null(item_native)) { 0 210 210
5523 0 int carries = SvOK(completed_item_sv)
5524 0 ▶ && gql_runtime_vm_sv_is_outcome(aTHX_ completed_item_sv)
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_sv_is_outcome(aTHX_ completed_item_sv) 0 0 0
5525 0 ▶ && (gql_runtime_vm_expect_outcome(aTHX_ completed_item_sv)->null_carries_error
Branch: 2 branches
BranchTrueFalseTotal
&& (gql_runtime_vm_expect_outcome(aTHX_ completed_item_sv)->null_carries_error 0 0 0
&& (gql_runtime_vm_expect_outcome(aTHX_ completed_item_sv)->null_carries_error 0 0 0
5526 0 ▶ || gql_runtime_vm_expect_outcome(aTHX_ completed_item_sv)->error_record_count > 0);
Branch: 1 branch
BranchTrueFalseTotal
|| gql_runtime_vm_expect_outcome(aTHX_ completed_item_sv)->error_record_count > 0); 0 0 0
5527 0 ▶ if (!carries && s->writer) {
Branch: 2 branches
BranchTrueFalseTotal
if (!carries && s->writer) { 0 0 0
if (!carries && s->writer) { 0 0 0
5528 0 const gql_runtime_vm_native_block_t *parent_block =
5529 0 ▶ (s && s->cursor) ? gql_runtime_vm_cursor_current_native_block(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
(s && s->cursor) ? gql_runtime_vm_cursor_current_native_block(s->cursor) : NULL; 0 0 0
(s && s->cursor) ? gql_runtime_vm_cursor_current_native_block(s->cursor) : NULL; 0 0 0
5530 0 SV *item_key = newSViv(i);
5531 gql_runtime_vm_path_frame_t *item_path =
5532 0 gql_runtime_vm_new_path_frame_struct(aTHX_ path_frame, item_key);
5533 0 ▶ SV *msg_sv = newSVpvf(
Branch: 4 branches
BranchTrueFalseTotal
SV *msg_sv = newSVpvf( 0 0 0
SV *msg_sv = newSVpvf( 0 0 0
SV *msg_sv = newSVpvf( 0 0 0
SV *msg_sv = newSVpvf( 0 0 0
5534 "Cannot return null for non-nullable field %s.%s.",
5535 parent_block && parent_block->type_name ? parent_block->type_name : "(unknown)",
5536 slot && slot->field_name ? slot->field_name : "(unknown)"
5537 );
5538 0 gql_runtime_vm_outcome_t *err = gql_runtime_vm_new_error_outcome_struct_for_path(
5539 aTHX_ msg_sv, item_path
5540 );
5541 IV k;
5542 0 ▶ for (k = 0; err && k < err->error_record_count; k++) {
Branch: 2 branches
BranchTrueFalseTotal
for (k = 0; err && k < err->error_record_count; k++) { 0 0 0
for (k = 0; err && k < err->error_record_count; k++) { 0 0 0
5543 0 gql_runtime_vm_writer_push_error_record(s->writer, err->error_records[k]);
5544 }
5545 0 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 0 0 0
5546 0 gql_runtime_vm_outcome_decref(aTHX_ err);
5547 }
5548 0 SvREFCNT_dec(msg_sv);
5549 0 gql_runtime_vm_path_frame_decref(item_path);
5550 0 SvREFCNT_dec(item_key);
5551 }
5552 0 item_null_violation = 1;
5553 }
5554 291 gql_runtime_vm_native_list_push(list_value, item_native);
5555 }
5556 130 SvREFCNT_dec((SV *)resolved_items_av);
5557 130 ▶ if (item_null_violation) {
Branch: 1 branch
BranchTrueFalseTotal
if (item_null_violation) { 0 130 130
5558 /* The whole list nulls; the null carries its error upward. */
5559 gql_runtime_vm_outcome_t *o =
5560 0 gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef);
5561 0 o->null_carries_error = 1;
5562 0 gql_runtime_vm_native_value_destroy(aTHX_ list_value);
5563 0 ▶ if (outcome_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out) { 0 0 0
5564 0 *outcome_out = o;
5565 0 return NULL;
5566 }
5567 {
5568 0 SV *ret = gql_runtime_vm_wrap_outcome_sv(aTHX_ o);
5569 0 gql_runtime_vm_outcome_decref(aTHX_ o);
5570 0 return ret;
5571 }
5572 }
5573 130 ▶ if (outcome_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out) { 130 0 130
5574 130 *outcome_out = gql_runtime_vm_new_outcome_from_owned_native_value_struct(
5575 aTHX_ GQL_VM_KIND_LIST, list_value
5576 );
5577 130 return NULL;
5578 }
5579 0 return gql_runtime_vm_new_outcome_from_owned_native_value_handle_sv(
5580 aTHX_ GQL_VM_KIND_LIST, list_value
5581 );
5582 }
5583 }
5584 1 case GQL_VM_COMPLETE_ABSTRACT:
5585 {
5586 1 SV *runtime_error_sv = NULL;
5587 SV *runtime_type_sv;
5588 1 IV child_block_index = -1;
5589  
5590 1 ▶ if (!resolved_sv || !SvOK(resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved_sv || !SvOK(resolved_sv)) { 1 0 1
if (!resolved_sv || !SvOK(resolved_sv)) { 0 1 1
5591 0 return gql_runtime_vm_sync_outcome_result_sv(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, outcome_out);
5592 }
5593  
5594 1 runtime_type_sv = gql_runtime_vm_exec_state_resolve_runtime_type_for_slot_sv(
5595 aTHX_
5596 state_sv,
5597 s,
5598 slot,
5599 resolved_sv,
5600 path_frame,
5601 &runtime_error_sv
5602 );
5603 1 ▶ if (runtime_error_sv && SvOK(runtime_error_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime_error_sv && SvOK(runtime_error_sv)) { 0 1 1
if (runtime_error_sv && SvOK(runtime_error_sv)) { 0 0 0
5604 0 SV *ret = gql_runtime_vm_new_error_outcome_for_path_sv(
5605 aTHX_
5606 runtime_error_sv,
5607 path_frame
5608 );
5609 0 SvREFCNT_dec(runtime_error_sv);
5610 0 return ret;
5611 }
5612 1 ▶ if (runtime_type_sv && SvOK(runtime_type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime_type_sv && SvOK(runtime_type_sv)) { 1 0 1
if (runtime_type_sv && SvOK(runtime_type_sv)) { 1 0 1
5613 1 child_block_index = gql_runtime_vm_find_abstract_child_block_index(
5614 op,
5615 gql_runtime_vm_type_name_from_sv(aTHX_ runtime_type_sv)
5616 );
5617 }
5618 1 ▶ if (runtime_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_type_sv) { 1 0 1
5619 1 SvREFCNT_dec(runtime_type_sv);
5620 }
5621 1 ▶ if (child_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index < 0) { 0 1 1
5622 /* Unresolvable member type: field error + null, never the raw
5623 * source value (same contract as the fast lanes). */
5624 0 ▶ SV *msg_sv = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
SV *msg_sv = newSVpvf( 0 0 0
SV *msg_sv = newSVpvf( 0 0 0
5625 "Abstract type %s must resolve to an Object type at runtime",
5626 slot && slot->return_type_name ? slot->return_type_name : "(unknown)"
5627 );
5628 0 SV *ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ msg_sv, path_frame);
5629 0 SvREFCNT_dec(msg_sv);
5630 0 return ret;
5631 }
5632  
5633 {
5634 /* Mode 1: same contract as the COMPLETE_OBJECT child above. */
5635 1 SV *child_value = gql_runtime_vm_exec_state_execute_block_async_path_sv(
5636 aTHX_
5637 state_sv,
5638 s,
5639 child_block_index,
5640 resolved_sv,
5641 path_frame,
5642 1
5643 );
5644 1 ▶ if (gql_runtime_vm_is_block_frame_value_sv(child_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_block_frame_value_sv(child_value)) { 0 1 1
5645 0 return child_value;
5646 }
5647 1 ▶ if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) {
Branch: 3 branches
BranchTrueFalseTotal
if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) { 1 0 1
if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) { 1 0 1
if (child_value && SvOK(child_value) && gql_runtime_vm_sv_is_outcome(aTHX_ child_value)) { 1 0 1
5648 1 return gql_runtime_vm_outcome_result_from_handle_sv(aTHX_ child_value, outcome_out);
5649 }
5650 0 ▶ if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, child_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, child_value)) { 0 0 0
5651 0 SV *callback_sv = gql_runtime_vm_wrap_object_outcome_callback_sv(aTHX);
5652 0 SV *ret = gql_runtime_vm_call_then_promise_for_state_sv(
5653 aTHX_
5654 s,
5655 child_value,
5656 callback_sv,
5657 NULL,
5658 path_frame
5659 );
5660 0 SvREFCNT_dec(callback_sv);
5661 0 SvREFCNT_dec(child_value);
5662 0 return ret;
5663 }
5664  
5665 {
5666 0 SV *ret = gql_runtime_vm_sync_outcome_result_sv(aTHX_ GQL_VM_KIND_OBJECT, child_value, outcome_out);
5667 0 SvREFCNT_dec(child_value);
5668 0 return ret;
5669 }
5670 }
5671 }
5672 2551 case GQL_VM_COMPLETE_GENERIC:
5673 default:
5674 {
5675 /* Leaf result coercion; a failure is a field error + null. */
5676 2551 SV *leaf_error = NULL;
5677 2551 SV *serialized = gql_runtime_vm_serialize_leaf_sv(
5678 aTHX_ runtime, slot, resolved_sv, &leaf_error
5679 );
5680 2551 ▶ if (leaf_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_error) { 1 2550 2551
5681 1 SV *ret = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ leaf_error, path_frame);
5682 1 SvREFCNT_dec(leaf_error);
5683 1 return ret;
5684 }
5685 {
5686 2550 SV *ret = gql_runtime_vm_sync_outcome_result_sv(aTHX_ GQL_VM_KIND_SCALAR, serialized, outcome_out);
5687 2550 SvREFCNT_dec(serialized);
5688 2550 return ret;
5689 }
5690 }
5691 }
5692 }
5693  
5694 static SV *
5695 0 gql_runtime_vm_state_current_return_type_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s, SV *op_sv, SV *slot_sv)
5696 {
5697 const gql_runtime_vm_native_slot_t *native_slot;
5698 SV *type_name_sv;
5699  
5700 0 ▶ native_slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
native_slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 0 0 0
native_slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 0 0 0
5701 0 ▶ if (native_slot) {
Branch: 1 branch
BranchTrueFalseTotal
if (native_slot) { 0 0 0
5702 0 return gql_runtime_vm_state_return_type_for_slot_sv(aTHX_ s, native_slot);
5703 }
5704  
5705 0 type_name_sv = gql_runtime_vm_op_slot_sv(aTHX_ op_sv, 8);
5706 0 ▶ if (!type_name_sv || !SvOK(type_name_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!type_name_sv || !SvOK(type_name_sv)) { 0 0 0
if (!type_name_sv || !SvOK(type_name_sv)) { 0 0 0
5707 0 return NULL;
5708 }
5709  
5710 0 return gql_runtime_vm_state_type_by_name_sv(aTHX_ s, type_name_sv);
5711 }
5712  
5713 static SV *
5714 40 gql_runtime_vm_state_return_type_for_slot_sv(
5715 pTHX_
5716 gql_runtime_vm_exec_state_handle_t *s,
5717 const gql_runtime_vm_native_slot_t *slot
5718 )
5719 {
5720 40 const gql_runtime_vm_native_runtime_t *runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
5721 SV *type_name_sv;
5722  
5723 40 slot = gql_runtime_vm_effective_slot(runtime, slot);
5724 40 ▶ if (!slot || !slot->return_type_name || !*slot->return_type_name) {
Branch: 3 branches
BranchTrueFalseTotal
if (!slot || !slot->return_type_name || !*slot->return_type_name) { 40 0 40
if (!slot || !slot->return_type_name || !*slot->return_type_name) { 40 0 40
if (!slot || !slot->return_type_name || !*slot->return_type_name) { 0 40 40
5725 0 return NULL;
5726 }
5727  
5728 40 type_name_sv = sv_2mortal(newSVpv(slot->return_type_name, 0));
5729 40 return gql_runtime_vm_state_type_by_name_sv(aTHX_ s, type_name_sv);
5730 }
5731  
5732 static SV *
5733 1319 gql_runtime_vm_state_current_resolver_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s)
5734 {
5735 const gql_runtime_vm_native_runtime_t *runtime;
5736 const gql_runtime_vm_native_slot_t *slot;
5737  
5738 1319 runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
5739 1319 ▶ slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 1319 0 1319
slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 1319 0 1319
5740  
5741 1319 ▶ if (!runtime || !runtime->callback_catalog || !slot) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime || !runtime->callback_catalog || !slot) { 1319 0 1319
if (!runtime || !runtime->callback_catalog || !slot) { 1319 0 1319
if (!runtime || !runtime->callback_catalog || !slot) { 0 1319 1319
5742 0 return NULL;
5743 }
5744 1319 ▶ if (!runtime->callback_catalog->slot_resolvers) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime->callback_catalog->slot_resolvers) { 0 1319 1319
5745 0 return NULL;
5746 }
5747 1319 ▶ if (slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 1319 0 1319
if (slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 0 1319 1319
5748 0 return NULL;
5749 }
5750 1319 return runtime->callback_catalog->slot_resolvers[slot->schema_slot_index];
5751 }
5752  
5753 static SV *
5754 40 gql_runtime_vm_state_type_by_name_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s, SV *type_name_sv)
5755 {
5756 SV *runtime_schema_sv;
5757 HV *schema_hv;
5758 SV *runtime_cache_sv;
5759 HV *runtime_cache_hv;
5760 SV *name2type_sv;
5761 HE *he;
5762  
5763 40 ▶ if (!type_name_sv || !SvOK(type_name_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!type_name_sv || !SvOK(type_name_sv)) { 40 0 40
if (!type_name_sv || !SvOK(type_name_sv)) { 0 40 40
5764 0 return NULL;
5765 }
5766  
5767 40 ▶ runtime_schema_sv = s ? s->runtime_schema : NULL;
Branch: 1 branch
BranchTrueFalseTotal
runtime_schema_sv = s ? s->runtime_schema : NULL; 40 0 40
5768 40 ▶ if (!runtime_schema_sv || !SvOK(runtime_schema_sv) || !SvROK(runtime_schema_sv) || SvTYPE(SvRV(runtime_schema_sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!runtime_schema_sv || !SvOK(runtime_schema_sv) || !SvROK(runtime_schema_sv) || SvTYPE(SvRV(runtime_schema_sv)) != SVt_PVHV) { 40 0 40
if (!runtime_schema_sv || !SvOK(runtime_schema_sv) || !SvROK(runtime_schema_sv) || SvTYPE(SvRV(runtime_schema_sv)) != SVt_PVHV) { 40 0 40
if (!runtime_schema_sv || !SvOK(runtime_schema_sv) || !SvROK(runtime_schema_sv) || SvTYPE(SvRV(runtime_schema_sv)) != SVt_PVHV) { 40 0 40
if (!runtime_schema_sv || !SvOK(runtime_schema_sv) || !SvROK(runtime_schema_sv) || SvTYPE(SvRV(runtime_schema_sv)) != SVt_PVHV) { 0 40 40
5769 0 return NULL;
5770 }
5771 40 schema_hv = (HV *)SvRV(runtime_schema_sv);
5772 40 runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "runtime_cache", 13);
5773 40 ▶ if (!runtime_cache_sv || !SvOK(runtime_cache_sv) || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!runtime_cache_sv || !SvOK(runtime_cache_sv) || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) { 40 0 40
if (!runtime_cache_sv || !SvOK(runtime_cache_sv) || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) { 40 0 40
if (!runtime_cache_sv || !SvOK(runtime_cache_sv) || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) { 40 0 40
if (!runtime_cache_sv || !SvOK(runtime_cache_sv) || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) { 0 40 40
5774 0 return NULL;
5775 }
5776 40 runtime_cache_hv = (HV *)SvRV(runtime_cache_sv);
5777 40 name2type_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "name2type", 9);
5778 40 ▶ if (!name2type_sv || !SvOK(name2type_sv) || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!name2type_sv || !SvOK(name2type_sv) || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 40 0 40
if (!name2type_sv || !SvOK(name2type_sv) || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 40 0 40
if (!name2type_sv || !SvOK(name2type_sv) || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 40 0 40
if (!name2type_sv || !SvOK(name2type_sv) || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 0 40 40
5779 0 return NULL;
5780 }
5781 40 he = hv_fetch_ent((HV *)SvRV(name2type_sv), type_name_sv, 0, 0);
5782 40 ▶ return he ? HeVAL(he) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return he ? HeVAL(he) : NULL; 40 0 40
5783 }
5784  
5785 static IV
5786 0 gql_runtime_vm_program_find_block_index_sv(pTHX_ SV *program_sv, SV *block_sv)
5787 {
5788 AV *program_av;
5789 SV **blocks_svp;
5790 AV *blocks_av;
5791 IV i;
5792  
5793 0 ▶ if (!program_sv || !SvOK(program_sv) || !SvROK(program_sv) || SvTYPE(SvRV(program_sv)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!program_sv || !SvOK(program_sv) || !SvROK(program_sv) || SvTYPE(SvRV(program_sv)) != SVt_PVAV) { 0 0 0
if (!program_sv || !SvOK(program_sv) || !SvROK(program_sv) || SvTYPE(SvRV(program_sv)) != SVt_PVAV) { 0 0 0
if (!program_sv || !SvOK(program_sv) || !SvROK(program_sv) || SvTYPE(SvRV(program_sv)) != SVt_PVAV) { 0 0 0
if (!program_sv || !SvOK(program_sv) || !SvROK(program_sv) || SvTYPE(SvRV(program_sv)) != SVt_PVAV) { 0 0 0
5794 0 return -1;
5795 }
5796 0 ▶ if (!block_sv || !SvOK(block_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!block_sv || !SvOK(block_sv)) { 0 0 0
if (!block_sv || !SvOK(block_sv)) { 0 0 0
5797 0 return -1;
5798 }
5799 0 ▶ if (!SvROK(block_sv) && looks_like_number(block_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(block_sv) && looks_like_number(block_sv)) { 0 0 0
if (!SvROK(block_sv) && looks_like_number(block_sv)) { 0 0 0
5800 0 return SvIV(block_sv);
5801 }
5802  
5803 0 program_av = (AV *)SvRV(program_sv);
5804 0 blocks_svp = av_fetch(program_av, 4, 0);
5805 0 ▶ if (!blocks_svp || !*blocks_svp || !SvOK(*blocks_svp) || !SvROK(*blocks_svp) || SvTYPE(SvRV(*blocks_svp)) != SVt_PVAV) {
Branch: 5 branches
BranchTrueFalseTotal
if (!blocks_svp || !*blocks_svp || !SvOK(*blocks_svp) || !SvROK(*blocks_svp) || SvTYPE(SvRV(*blocks_svp)) != SVt_PVAV) { 0 0 0
if (!blocks_svp || !*blocks_svp || !SvOK(*blocks_svp) || !SvROK(*blocks_svp) || SvTYPE(SvRV(*blocks_svp)) != SVt_PVAV) { 0 0 0
if (!blocks_svp || !*blocks_svp || !SvOK(*blocks_svp) || !SvROK(*blocks_svp) || SvTYPE(SvRV(*blocks_svp)) != SVt_PVAV) { 0 0 0
if (!blocks_svp || !*blocks_svp || !SvOK(*blocks_svp) || !SvROK(*blocks_svp) || SvTYPE(SvRV(*blocks_svp)) != SVt_PVAV) { 0 0 0
if (!blocks_svp || !*blocks_svp || !SvOK(*blocks_svp) || !SvROK(*blocks_svp) || SvTYPE(SvRV(*blocks_svp)) != SVt_PVAV) { 0 0 0
5806 0 return -1;
5807 }
5808 0 blocks_av = (AV *)SvRV(*blocks_svp);
5809 0 ▶ for (i = 0; i <= av_len(blocks_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(blocks_av); i++) { 0 0 0
5810 0 SV **svp = av_fetch(blocks_av, i, 0);
5811 0 ▶ if (svp && *svp && sv_eq(*svp, block_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (svp && *svp && sv_eq(*svp, block_sv)) { 0 0 0
if (svp && *svp && sv_eq(*svp, block_sv)) { 0 0 0
if (svp && *svp && sv_eq(*svp, block_sv)) { 0 0 0
5812 0 return i;
5813 }
5814 }
5815 0 return -1;
5816 }
5817  
5818 static IV
5819 0 gql_runtime_vm_block_index_from_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *s, SV *block_sv)
5820 {
5821 0 ▶ if (block_sv && SvOK(block_sv) && !SvROK(block_sv) && looks_like_number(block_sv)) {
Branch: 4 branches
BranchTrueFalseTotal
if (block_sv && SvOK(block_sv) && !SvROK(block_sv) && looks_like_number(block_sv)) { 0 0 0
if (block_sv && SvOK(block_sv) && !SvROK(block_sv) && looks_like_number(block_sv)) { 0 0 0
if (block_sv && SvOK(block_sv) && !SvROK(block_sv) && looks_like_number(block_sv)) { 0 0 0
if (block_sv && SvOK(block_sv) && !SvROK(block_sv) && looks_like_number(block_sv)) { 0 0 0
5822 0 return SvIV(block_sv);
5823 }
5824 0 ▶ return gql_runtime_vm_program_find_block_index_sv(aTHX_ s ? s->program : NULL, block_sv);
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_program_find_block_index_sv(aTHX_ s ? s->program : NULL, block_sv); 0 0 0
5825 }
5826  
5827 static char *
5828 98 gql_runtime_vm_copy_cstr(const char *src)
5829 {
5830 STRLEN len;
5831 char *dst;
5832 98 ▶ if (!src) {
Branch: 1 branch
BranchTrueFalseTotal
if (!src) { 0 98 98
5833 0 return NULL;
5834 }
5835 98 len = (STRLEN)strlen(src);
5836 98 Newx(dst, len + 1, char);
5837 98 Copy(src, dst, len, char);
5838 98 dst[len] = '\0';
5839 98 return dst;
5840 }
5841  
5842 static SV *
5843 2162 gql_runtime_vm_lazy_info_materialize_hash_sv(pTHX_ gql_runtime_vm_lazy_info_t *info)
5844 {
5845 HV *info_hv;
5846 2162 SV *runtime_cache_sv = &PL_sv_undef;
5847 2162 SV *schema_sv = &PL_sv_undef;
5848 2162 SV *parent_type_sv = NULL;
5849 2162 SV *return_type_sv = NULL;
5850 2162 SV *path_sv = &PL_sv_undef;
5851  
5852 2162 ▶ if (!info) {
Branch: 1 branch
BranchTrueFalseTotal
if (!info) { 0 2162 2162
5853 0 return newRV_noinc((SV *)newHV());
5854 }
5855 2162 ▶ if (info->materialized_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (info->materialized_sv) { 68 2094 2162
5856 68 return newSVsv(info->materialized_sv);
5857 }
5858  
5859 2094 info_hv = newHV();
5860  
5861 2094 ▶ if (info->field_name_sv && SvOK(info->field_name_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (info->field_name_sv && SvOK(info->field_name_sv)) { 2094 0 2094
if (info->field_name_sv && SvOK(info->field_name_sv)) { 2094 0 2094
5862 2094 hv_store(info_hv, "field_name", 10, newSVsv(info->field_name_sv), 0);
5863 0 ▶ } else if (info->field_name_pv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (info->field_name_pv) { 0 0 0
5864 0 hv_store(info_hv, "field_name", 10, newSVpv(info->field_name_pv, 0), 0);
5865 }
5866  
5867 2094 return_type_sv = info->return_type_sv;
5868 2094 ▶ if (!return_type_sv && info->runtime_schema && info->return_type_name_pv) {
Branch: 3 branches
BranchTrueFalseTotal
if (!return_type_sv && info->runtime_schema && info->return_type_name_pv) { 0 2094 2094
if (!return_type_sv && info->runtime_schema && info->return_type_name_pv) { 0 0 0
if (!return_type_sv && info->runtime_schema && info->return_type_name_pv) { 0 0 0
5869 0 return_type_sv = gql_runtime_vm_lookup_type_object_by_name_sv(
5870 aTHX_ info->runtime_schema,
5871 0 info->return_type_name_pv
5872 );
5873 }
5874 2094 ▶ if (return_type_sv && SvOK(return_type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (return_type_sv && SvOK(return_type_sv)) { 2094 0 2094
if (return_type_sv && SvOK(return_type_sv)) { 2094 0 2094
5875 2094 hv_store(info_hv, "return_type", 11, newSVsv(return_type_sv), 0);
5876 0 ▶ } else if (info->return_type_name_pv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (info->return_type_name_pv) { 0 0 0
5877 0 hv_store(info_hv, "return_type_name", 16, newSVpv(info->return_type_name_pv, 0), 0);
5878 }
5879  
5880 2094 parent_type_sv = info->parent_type_sv;
5881 2094 ▶ if (!parent_type_sv && info->runtime_schema && info->parent_type_name_pv) {
Branch: 3 branches
BranchTrueFalseTotal
if (!parent_type_sv && info->runtime_schema && info->parent_type_name_pv) { 42 2052 2094
if (!parent_type_sv && info->runtime_schema && info->parent_type_name_pv) { 42 0 42
if (!parent_type_sv && info->runtime_schema && info->parent_type_name_pv) { 42 0 42
5882 42 parent_type_sv = gql_runtime_vm_lookup_type_object_by_name_sv(
5883 aTHX_ info->runtime_schema,
5884 42 info->parent_type_name_pv
5885 );
5886 }
5887 2094 ▶ if (parent_type_sv && SvOK(parent_type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (parent_type_sv && SvOK(parent_type_sv)) { 2094 0 2094
if (parent_type_sv && SvOK(parent_type_sv)) { 2094 0 2094
5888 2094 hv_store(info_hv, "parent_type", 11, newSVsv(parent_type_sv), 0);
5889 0 ▶ } else if (info->parent_type_name_pv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (info->parent_type_name_pv) { 0 0 0
5890 0 hv_store(info_hv, "parent_type_name", 16, newSVpv(info->parent_type_name_pv, 0), 0);
5891 }
5892  
5893 2094 ▶ if (info->path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (info->path_frame) { 2083 11 2094
5894 2083 path_sv = gql_runtime_vm_path_frame_to_path_sv(aTHX_ info->path_frame);
5895 }
5896 2094 ▶ hv_store(info_hv, "path", 4, path_sv ? path_sv : newSVsv(&PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(info_hv, "path", 4, path_sv ? path_sv : newSVsv(&PL_sv_undef), 0); 0 2094 2094
5897  
5898 2094 hv_store(info_hv, "field_nodes", 11, newSVsv(&PL_sv_undef), 0);
5899 2094 ▶ hv_store(info_hv, "context_value", 13, newSVsv(info->context_value ? info->context_value : &PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(info_hv, "context_value", 13, newSVsv(info->context_value ? info->context_value : &PL_sv_undef), 0); 2094 0 2094
5900 2094 ▶ hv_store(info_hv, "root_value", 10, newSVsv(info->root_value ? info->root_value : &PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(info_hv, "root_value", 10, newSVsv(info->root_value ? info->root_value : &PL_sv_undef), 0); 2094 0 2094
5901 2094 ▶ hv_store(info_hv, "variable_values", 15, newSVsv(info->variable_values ? info->variable_values : &PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(info_hv, "variable_values", 15, newSVsv(info->variable_values ? info->variable_values : &PL_sv_undef), 0); 2094 0 2094
5902 2094 ▶ hv_store(info_hv, "operation", 9, newSVsv(info->operation ? info->operation : &PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(info_hv, "operation", 9, newSVsv(info->operation ? info->operation : &PL_sv_undef), 0); 2094 0 2094
5903 2094 ▶ hv_store(info_hv, "runtime_schema", 14, newSVsv(info->runtime_schema ? info->runtime_schema : &PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(info_hv, "runtime_schema", 14, newSVsv(info->runtime_schema ? info->runtime_schema : &PL_sv_undef), 0); 2094 0 2094
5904 2094 ▶ hv_store(info_hv, "directives", 10, newSVsv(info->directives ? info->directives : &PL_sv_undef), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(info_hv, "directives", 10, newSVsv(info->directives ? info->directives : &PL_sv_undef), 0); 2094 0 2094
5905 2094 hv_store(info_hv, "block_index", 11, newSViv(info->block_index), 0);
5906 2094 hv_store(info_hv, "op_index", 8, newSViv(info->op_index), 0);
5907  
5908 2094 ▶ if (info->runtime_schema
Branch: 1 branch
BranchTrueFalseTotal
if (info->runtime_schema 2094 0 2094
5909 2094 ▶ && SvROK(info->runtime_schema)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(info->runtime_schema) 2094 0 2094
5910 2094 ▶ && SvTYPE(SvRV(info->runtime_schema)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(info->runtime_schema)) == SVt_PVHV) { 2094 0 2094
5911 2094 HV *runtime_schema_hv = (HV *)SvRV(info->runtime_schema);
5912 SV *sv;
5913  
5914 2094 sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_schema_hv, "runtime_cache", 13);
5915 2094 ▶ if (sv && SvOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvOK(sv)) { 2094 0 2094
if (sv && SvOK(sv)) { 2094 0 2094
5916 2094 runtime_cache_sv = sv;
5917 }
5918 2094 sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_schema_hv, "schema", 6);
5919 2094 ▶ if (sv && SvOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv && SvOK(sv)) { 2094 0 2094
if (sv && SvOK(sv)) { 2094 0 2094
5920 2094 schema_sv = sv;
5921 }
5922 }
5923  
5924 2094 hv_store(info_hv, "runtime_cache", 13, newSVsv(runtime_cache_sv), 0);
5925 2094 hv_store(info_hv, "schema", 6, newSVsv(schema_sv), 0);
5926  
5927 2094 info->materialized_sv = newRV_noinc((SV *)info_hv);
5928 2094 return newSVsv(info->materialized_sv);
5929 }
5930  
5931 static void
5932 10987 gql_runtime_vm_lazy_info_decref(pTHX_ gql_runtime_vm_lazy_info_t *info)
5933 {
5934 10987 ▶ if (!info) {
Branch: 1 branch
BranchTrueFalseTotal
if (!info) { 0 10987 10987
5935 0 return;
5936 }
5937 10987 ▶ if (--info->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--info->refcount > 0) { 0 10987 10987
5938 0 return;
5939 }
5940  
5941 10987 SvREFCNT_dec(info->field_name_sv);
5942 /* field_name_pv/parent_type_name_pv/return_type_name_pv are borrowed
5943 * from the compiled native program/schema (see new_lazy_info_handle_sv)
5944 * - not owned, so not freed here. */
5945 10987 SvREFCNT_dec(info->parent_type_sv);
5946 10987 SvREFCNT_dec(info->return_type_sv);
5947 10987 gql_runtime_vm_path_frame_decref(info->path_frame);
5948 10987 SvREFCNT_dec(info->context_value);
5949 10987 SvREFCNT_dec(info->root_value);
5950 10987 SvREFCNT_dec(info->variable_values);
5951 10987 SvREFCNT_dec(info->operation);
5952 10987 SvREFCNT_dec(info->runtime_schema);
5953 10987 SvREFCNT_dec(info->directives);
5954 10987 SvREFCNT_dec(info->materialized_sv);
5955 10987 gql_runtime_vm_lazy_info_live_count--;
5956 10987 ▶ if (gql_runtime_vm_lazy_info_pool_count < GQL_RUNTIME_VM_LAZY_INFO_POOL_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_lazy_info_pool_count < GQL_RUNTIME_VM_LAZY_INFO_POOL_MAX) { 10498 489 10987
5957 10498 info->pool_next = gql_runtime_vm_lazy_info_pool_head;
5958 10498 gql_runtime_vm_lazy_info_pool_head = info;
5959 10498 gql_runtime_vm_lazy_info_pool_count++;
5960 } else {
5961 489 Safefree(info);
5962 }
5963 }
5964  
5965 static SV *
5966 10987 gql_runtime_vm_new_lazy_info_handle_sv(
5967 pTHX_
5968 SV *field_name_sv,
5969 const char *field_name_pv,
5970 SV *parent_type_sv,
5971 const char *parent_type_name_pv,
5972 const char *return_type_name_pv,
5973 SV *return_type_sv,
5974 gql_runtime_vm_path_frame_t *path_frame,
5975 SV *context_value,
5976 SV *root_value,
5977 SV *variable_values,
5978 SV *operation,
5979 SV *runtime_schema,
5980 SV *directives,
5981 IV block_index,
5982 IV op_index
5983 )
5984 {
5985 gql_runtime_vm_lazy_info_t *info;
5986  
5987 10987 info = gql_runtime_vm_lazy_info_pool_get(aTHX);
5988 10987 info->refcount = 1;
5989 10987 ▶ info->field_name_sv = field_name_sv ? SvREFCNT_inc_simple_NN(field_name_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->field_name_sv = field_name_sv ? SvREFCNT_inc_simple_NN(field_name_sv) : NULL; 10987 0 10987
5990 /* Both callers (new_lazy_info_for_path_sv, new_callback_info_sv) always
5991 * source these three strings from slot->field_name/block->type_name/
5992 * slot->return_type_name - fields of the compiled native program, which
5993 * outlives every request. Borrowing instead of copy_cstr-duplicating them
5994 * avoids a Newx+Copy (and matching Safefree) on every single call. */
5995 10987 info->field_name_pv = (char *)field_name_pv;
5996 10987 ▶ info->parent_type_sv = parent_type_sv ? SvREFCNT_inc_simple_NN(parent_type_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->parent_type_sv = parent_type_sv ? SvREFCNT_inc_simple_NN(parent_type_sv) : NULL; 3376 7611 10987
5997 10987 info->parent_type_name_pv = (char *)parent_type_name_pv;
5998 10987 info->return_type_name_pv = (char *)return_type_name_pv;
5999 10987 ▶ info->return_type_sv = return_type_sv ? SvREFCNT_inc_simple_NN(return_type_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->return_type_sv = return_type_sv ? SvREFCNT_inc_simple_NN(return_type_sv) : NULL; 10987 0 10987
6000 10987 ▶ if (path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (path_frame) { 10965 22 10987
6001 10965 path_frame->refcount++;
6002 }
6003 10987 info->path_frame = path_frame;
6004 10987 ▶ info->context_value = context_value ? SvREFCNT_inc_simple_NN(context_value) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->context_value = context_value ? SvREFCNT_inc_simple_NN(context_value) : NULL; 10987 0 10987
6005 10987 ▶ info->root_value = root_value ? SvREFCNT_inc_simple_NN(root_value) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->root_value = root_value ? SvREFCNT_inc_simple_NN(root_value) : NULL; 10987 0 10987
6006 10987 ▶ info->variable_values = variable_values ? SvREFCNT_inc_simple_NN(variable_values) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->variable_values = variable_values ? SvREFCNT_inc_simple_NN(variable_values) : NULL; 10987 0 10987
6007 10987 ▶ info->operation = operation ? SvREFCNT_inc_simple_NN(operation) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->operation = operation ? SvREFCNT_inc_simple_NN(operation) : NULL; 10987 0 10987
6008 10987 ▶ info->runtime_schema = runtime_schema ? SvREFCNT_inc_simple_NN(runtime_schema) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->runtime_schema = runtime_schema ? SvREFCNT_inc_simple_NN(runtime_schema) : NULL; 10987 0 10987
6009 10987 ▶ info->directives = directives ? SvREFCNT_inc_simple_NN(directives) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
info->directives = directives ? SvREFCNT_inc_simple_NN(directives) : NULL; 10987 0 10987
6010 10987 info->block_index = block_index;
6011 10987 info->op_index = op_index;
6012  
6013 10987 return gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::LazyInfo", info);
6014 }
6015  
6016 static SV *
6017 1024 gql_runtime_vm_new_lazy_info_for_path_sv(
6018 pTHX_
6019 SV *state_sv,
6020 gql_runtime_vm_exec_state_handle_t *s,
6021 gql_runtime_vm_path_frame_t *path_ptr
6022 )
6023 {
6024 1024 ▶ const gql_runtime_vm_native_block_t *block = (s && s->cursor)
Branch: 1 branch
BranchTrueFalseTotal
const gql_runtime_vm_native_block_t *block = (s && s->cursor) 1024 0 1024
6025 1024 ? gql_runtime_vm_cursor_current_native_block(s->cursor)
6026 1024 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 1024 0 1024
6027 1024 ▶ const gql_runtime_vm_native_slot_t *slot = (s && s->cursor)
Branch: 1 branch
BranchTrueFalseTotal
const gql_runtime_vm_native_slot_t *slot = (s && s->cursor) 1024 0 1024
6028 1024 ? gql_runtime_vm_cursor_current_native_slot(s->cursor)
6029 1024 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 1024 0 1024
6030 1024 const gql_runtime_vm_native_runtime_t *runtime = s
6031 1024 ? gql_runtime_vm_exec_state_native_runtime(aTHX_ s)
6032 1024 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 1024 0 1024
6033 1024 ▶ gql_runtime_vm_native_callback_catalog_t *catalog = runtime ? runtime->callback_catalog : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_callback_catalog_t *catalog = runtime ? runtime->callback_catalog : NULL; 1024 0 1024
6034 1024 SV *return_type_sv = NULL;
6035 1024 SV *field_name_sv = NULL;
6036  
6037 PERL_UNUSED_ARG(state_sv);
6038 1024 ▶ if (!path_ptr && s && s->field_frame) {
Branch: 3 branches
BranchTrueFalseTotal
if (!path_ptr && s && s->field_frame) { 0 1024 1024
if (!path_ptr && s && s->field_frame) { 0 0 0
if (!path_ptr && s && s->field_frame) { 0 0 0
6039 0 path_ptr = s->field_frame->path_frame;
6040 }
6041 1024 ▶ if (runtime && slot) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime && slot) { 1024 0 1024
if (runtime && slot) { 1024 0 1024
6042 1024 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
6043 }
6044 1024 ▶ if (catalog
Branch: 1 branch
BranchTrueFalseTotal
if (catalog 1024 0 1024
6045 1024 ▶ && catalog->slot_field_names
Branch: 1 branch
BranchTrueFalseTotal
&& catalog->slot_field_names 1024 0 1024
6046 1024 ▶ && slot
Branch: 1 branch
BranchTrueFalseTotal
&& slot 1024 0 1024
6047 1024 ▶ && slot->schema_slot_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index >= 0 1024 0 1024
6048 1024 ▶ && slot->schema_slot_index < runtime->runtime_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index < runtime->runtime_slot_count) { 1024 0 1024
6049 1024 field_name_sv = catalog->slot_field_names[slot->schema_slot_index];
6050 }
6051  
6052 3072 ▶ return gql_runtime_vm_new_lazy_info_handle_sv(
Branch: 11 branches
BranchTrueFalseTotal
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
return gql_runtime_vm_new_lazy_info_handle_sv( 1024 0 1024
6053 aTHX_
6054 field_name_sv,
6055 slot ? slot->field_name : NULL,
6056 block ? block->type_object_sv : NULL,
6057 block ? block->type_name : NULL,
6058 slot ? slot->return_type_name : NULL,
6059 return_type_sv,
6060 path_ptr,
6061 s ? s->context : &PL_sv_undef,
6062 s ? s->root_value : &PL_sv_undef,
6063 s ? s->variables : &PL_sv_undef,
6064 s ? s->program : &PL_sv_undef,
6065 s ? s->runtime_schema : &PL_sv_undef,
6066 &PL_sv_undef,
6067 1024 ▶ (s && s->cursor) ? s->cursor->block_index : -1,
Branch: 1 branch
BranchTrueFalseTotal
(s && s->cursor) ? s->cursor->block_index : -1, 1024 0 1024
6068 1024 ▶ (s && s->cursor) ? s->cursor->op_index : -1
Branch: 1 branch
BranchTrueFalseTotal
(s && s->cursor) ? s->cursor->op_index : -1 1024 0 1024
6069 );
6070 }
6071  
6072 static SV *
6073 0 gql_runtime_vm_new_lazy_info_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, SV *path_frame)
6074 {
6075 0 gql_runtime_vm_path_frame_t *path_ptr = NULL;
6076  
6077 0 ▶ if (path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) {
Branch: 5 branches
BranchTrueFalseTotal
if (path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) { 0 0 0
if (path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) { 0 0 0
if (path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) { 0 0 0
if (path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) { 0 0 0
if (path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) { 0 0 0
6078 0 path_ptr = INT2PTR(gql_runtime_vm_path_frame_t *, SvUV(SvRV(path_frame)));
6079 }
6080  
6081 0 return gql_runtime_vm_new_lazy_info_for_path_sv(aTHX_ state_sv, s, path_ptr);
6082 }
6083  
6084 static SV *
6085 gql_runtime_vm_runtime_schema_exec_struct_sv(pTHX_ SV *runtime_schema);
6086  
6087 static SV *
6088 988 gql_runtime_vm_state_resolve_args_sv(pTHX_ SV *state_sv)
6089 {
6090 988 gql_runtime_vm_exec_state_handle_t *s = gql_runtime_vm_expect_exec_state_handle(aTHX_ state_sv);
6091 988 const gql_runtime_vm_native_runtime_t *runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
6092 988 ▶ const gql_runtime_vm_native_slot_t *slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
const gql_runtime_vm_native_slot_t *slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 988 0 988
const gql_runtime_vm_native_slot_t *slot = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 988 0 988
6093 988 ▶ const gql_runtime_vm_native_op_t *op = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
const gql_runtime_vm_native_op_t *op = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL; 988 0 988
const gql_runtime_vm_native_op_t *op = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL; 988 0 988
6094 988 ▶ HV *variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables");
Branch: 2 branches
BranchTrueFalseTotal
HV *variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables"); 988 0 988
HV *variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables"); 988 0 988
6095 SV *args_sv;
6096  
6097 988 ▶ if (!runtime || !slot || !op) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime || !slot || !op) { 988 0 988
if (!runtime || !slot || !op) { 988 0 988
if (!runtime || !slot || !op) { 0 988 988
6098 0 ▶ return newSVsv(s && s->empty_args ? s->empty_args : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
return newSVsv(s && s->empty_args ? s->empty_args : &PL_sv_undef); 0 0 0
return newSVsv(s && s->empty_args ? s->empty_args : &PL_sv_undef); 0 0 0
6099 }
6100  
6101 988 args_sv = gql_runtime_vm_specialize_arg_payload_sv(
6102 aTHX_ runtime, slot, op, variables_hv, NULL, 0, NULL
6103 );
6104 988 ▶ return args_sv ? args_sv : newSVsv(s && s->empty_args ? s->empty_args : &PL_sv_undef);
Branch: 3 branches
BranchTrueFalseTotal
return args_sv ? args_sv : newSVsv(s && s->empty_args ? s->empty_args : &PL_sv_undef); 851 137 988
return args_sv ? args_sv : newSVsv(s && s->empty_args ? s->empty_args : &PL_sv_undef); 851 0 851
return args_sv ? args_sv : newSVsv(s && s->empty_args ? s->empty_args : &PL_sv_undef); 851 0 851
6105 }
6106  
6107 static int
6108 1319 gql_runtime_vm_should_execute_op_now(pTHX_ gql_runtime_vm_exec_state_handle_t *s, SV *op_sv)
6109 {
6110 1319 ▶ const gql_runtime_vm_native_op_t *native_op = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
const gql_runtime_vm_native_op_t *native_op = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL; 1319 0 1319
const gql_runtime_vm_native_op_t *native_op = (s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL; 1319 0 1319
6111 1319 ▶ if (native_op) {
Branch: 1 branch
BranchTrueFalseTotal
if (native_op) { 1319 0 1319
6112 1319 ▶ HV *variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables");
Branch: 2 branches
BranchTrueFalseTotal
HV *variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables"); 1319 0 1319
HV *variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables"); 1319 0 1319
6113 1319 ▶ if (native_op->directives_mode_code == 0 || !native_op->has_directives || !native_op->directives_payload_native) {
Branch: 3 branches
BranchTrueFalseTotal
if (native_op->directives_mode_code == 0 || !native_op->has_directives || !native_op->directives_payload_native) { 0 1319 1319
if (native_op->directives_mode_code == 0 || !native_op->has_directives || !native_op->directives_payload_native) { 0 0 0
if (native_op->directives_mode_code == 0 || !native_op->has_directives || !native_op->directives_payload_native) { 0 0 0
6114 1319 return 1;
6115 }
6116 0 return gql_runtime_vm_evaluate_runtime_guards_native(
6117 0 aTHX_ native_op->directives_payload_native, variables_hv, NULL, 0
6118 0 ) ? 1 : 0;
6119 }
6120  
6121 SV *mode_sv;
6122 SV *guards_sv;
6123 HV *variables_hv;
6124 const char *mode;
6125  
6126 0 ▶ if (!op_sv || !SvOK(op_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op_sv || !SvOK(op_sv)) { 0 0 0
if (!op_sv || !SvOK(op_sv)) { 0 0 0
6127 0 return 0;
6128 }
6129  
6130 0 mode_sv = gql_runtime_vm_op_slot_sv(aTHX_ op_sv, 16);
6131 0 ▶ mode = mode_sv ? SvPV_nolen(mode_sv) : "NONE";
Branch: 1 branch
BranchTrueFalseTotal
mode = mode_sv ? SvPV_nolen(mode_sv) : "NONE"; 0 0 0
6132 0 ▶ if (!mode || strEQ(mode, "NONE")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!mode || strEQ(mode, "NONE")) { 0 0 0
if (!mode || strEQ(mode, "NONE")) { 0 0 0
6133 0 return 1;
6134 }
6135  
6136 0 guards_sv = gql_runtime_vm_op_slot_sv(aTHX_ op_sv, 17);
6137 0 ▶ if (!guards_sv || !SvOK(guards_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!guards_sv || !SvOK(guards_sv)) { 0 0 0
if (!guards_sv || !SvOK(guards_sv)) { 0 0 0
6138 0 return 1;
6139 }
6140  
6141 0 ▶ variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables");
Branch: 2 branches
BranchTrueFalseTotal
variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables"); 0 0 0
variables_hv = gql_runtime_vm_expect_hashref(aTHX_ s && s->variables ? s->variables : &PL_sv_undef, "variables"); 0 0 0
6142 0 return gql_runtime_vm_evaluate_runtime_guards_hv(aTHX_ guards_sv, variables_hv) ? 1 : 0;
6143 }
6144  
6145 static SV *
6146 0 gql_runtime_vm_call_resolver_sv(pTHX_ SV *resolver_sv, SV *source_sv, SV *args_sv, SV *context_sv, SV *info_sv, SV *return_type_sv, SV **error_out)
6147 {
6148 0 dSP;
6149 0 SV *result = NULL;
6150 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
6151 0 *error_out = NULL;
6152 }
6153 0 ▶ if (!resolver_sv || !SvOK(resolver_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolver_sv || !SvOK(resolver_sv)) { 0 0 0
if (!resolver_sv || !SvOK(resolver_sv)) { 0 0 0
6154 0 return newSVsv(&PL_sv_undef);
6155 }
6156  
6157 0 ENTER;
6158 0 SAVETMPS;
6159 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
6160 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
6161 0 ▶ XPUSHs(source_sv ? source_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(source_sv ? source_sv : &PL_sv_undef); 0 0 0
XPUSHs(source_sv ? source_sv : &PL_sv_undef); 0 0 0
6162 0 ▶ XPUSHs(args_sv ? args_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(args_sv ? args_sv : &PL_sv_undef); 0 0 0
XPUSHs(args_sv ? args_sv : &PL_sv_undef); 0 0 0
6163 0 ▶ XPUSHs(context_sv ? context_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(context_sv ? context_sv : &PL_sv_undef); 0 0 0
XPUSHs(context_sv ? context_sv : &PL_sv_undef); 0 0 0
6164 0 ▶ XPUSHs(info_sv ? info_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(info_sv ? info_sv : &PL_sv_undef); 0 0 0
XPUSHs(info_sv ? info_sv : &PL_sv_undef); 0 0 0
6165 0 ▶ XPUSHs(return_type_sv ? return_type_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(return_type_sv ? return_type_sv : &PL_sv_undef); 0 0 0
XPUSHs(return_type_sv ? return_type_sv : &PL_sv_undef); 0 0 0
6166 0 PUTBACK;
6167  
6168 0 ▶ if (call_sv(resolver_sv, G_SCALAR | G_EVAL) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (call_sv(resolver_sv, G_SCALAR | G_EVAL) > 0) { 0 0 0
6169 0 SPAGAIN;
6170 0 ▶ result = (SP > PL_stack_base) ? POPs : NULL;
Branch: 1 branch
BranchTrueFalseTotal
result = (SP > PL_stack_base) ? POPs : NULL; 0 0 0
6171 0 ▶ result = result ? newSVsv(result) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
result = result ? newSVsv(result) : newSVsv(&PL_sv_undef); 0 0 0
6172 0 PUTBACK;
6173 }
6174  
6175 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
6176 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
6177 0 ▶ *error_out = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVsv(ERRSV); 0 0 0
6178 }
6179 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
6180 0 result = NULL;
6181 }
6182  
6183 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
6184 0 LEAVE;
6185 0 ▶ return result ? result : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return result ? result : newSVsv(&PL_sv_undef); 0 0 0
6186 }
6187  
6188 static SV *
6189 20 gql_runtime_vm_call_default_property_sv(
6190 pTHX_ SV *callback_sv, SV *args_sv, SV *context_sv, SV *info_sv, SV **error_out
6191 )
6192 {
6193 20 dSP;
6194 20 SV *result = NULL;
6195 int count;
6196 20 ▶ int overloaded = callback_sv && SvROK(callback_sv)
Branch: 1 branch
BranchTrueFalseTotal
int overloaded = callback_sv && SvROK(callback_sv) 20 0 20
6197 40 ▶ && SvTYPE(SvRV(callback_sv)) != SVt_PVCV && SvOBJECT(SvRV(callback_sv));
Branch: 3 branches
BranchTrueFalseTotal
&& SvTYPE(SvRV(callback_sv)) != SVt_PVCV && SvOBJECT(SvRV(callback_sv)); 20 0 20
&& SvTYPE(SvRV(callback_sv)) != SVt_PVCV && SvOBJECT(SvRV(callback_sv)); 1 19 20
&& SvTYPE(SvRV(callback_sv)) != SVt_PVCV && SvOBJECT(SvRV(callback_sv)); 1 0 1
6198  
6199 20 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 20 0 20
6200 20 *error_out = NULL;
6201 }
6202 20 ENTER;
6203 20 SAVETMPS;
6204 20 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 20 0 20
6205 20 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 20 20
6206 20 ▶ if (overloaded) {
Branch: 1 branch
BranchTrueFalseTotal
if (overloaded) { 1 19 20
6207 1 ▶ XPUSHs(callback_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(callback_sv); 0 1 1
6208 }
6209 20 ▶ XPUSHs(args_sv ? args_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(args_sv ? args_sv : &PL_sv_undef); 0 20 20
XPUSHs(args_sv ? args_sv : &PL_sv_undef); 20 0 20
6210 20 ▶ XPUSHs(context_sv ? context_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(context_sv ? context_sv : &PL_sv_undef); 0 20 20
XPUSHs(context_sv ? context_sv : &PL_sv_undef); 20 0 20
6211 20 ▶ XPUSHs(info_sv ? info_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(info_sv ? info_sv : &PL_sv_undef); 0 20 20
XPUSHs(info_sv ? info_sv : &PL_sv_undef); 20 0 20
6212 20 PUTBACK;
6213 40 ▶ count = overloaded
Branch: 1 branch
BranchTrueFalseTotal
count = overloaded 1 19 20
6214 1 ? call_pv(
6215 "GraphQL::Houtou::Runtime::DirectiveRuntime::_resolve_default_property_value",
6216 G_SCALAR | G_EVAL
6217 )
6218 19 : call_sv(callback_sv, G_SCALAR | G_EVAL);
6219 20 SPAGAIN;
6220 20 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 20 0 20
if (SvTRUE(ERRSV)) { 1 19 20
6221 1 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 1 0 1
6222 1 ▶ *error_out = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVsv(ERRSV); 1 0 1
6223 }
6224 1 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 1 0 1
6225 19 ▶ } else if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (count > 0) { 19 0 19
6226 19 result = newSVsv(POPs);
6227 }
6228 20 PUTBACK;
6229 20 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 20 0 20
6230 20 LEAVE;
6231 20 ▶ return result ? result : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return result ? result : newSVsv(&PL_sv_undef); 1 19 20
6232 }
6233  
6234 static CV *
6235 1005 gql_runtime_vm_default_method_cv(SV *source_sv, const char *field_name)
6236 {
6237 GV *method_gv;
6238 1005 ▶ if (!source_sv || !SvROK(source_sv) || !SvOBJECT(SvRV(source_sv))
Branch: 3 branches
BranchTrueFalseTotal
if (!source_sv || !SvROK(source_sv) || !SvOBJECT(SvRV(source_sv)) 1005 0 1005
if (!source_sv || !SvROK(source_sv) || !SvOBJECT(SvRV(source_sv)) 1005 0 1005
if (!source_sv || !SvROK(source_sv) || !SvOBJECT(SvRV(source_sv)) 16 989 1005
6239 16 ▶ || !field_name || !*field_name) {
Branch: 2 branches
BranchTrueFalseTotal
|| !field_name || !*field_name) { 16 0 16
|| !field_name || !*field_name) { 0 16 16
6240 989 return NULL;
6241 }
6242 16 method_gv = gv_fetchmethod_autoload(SvSTASH(SvRV(source_sv)), field_name, 0);
6243 16 ▶ return method_gv ? GvCV(method_gv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return method_gv ? GvCV(method_gv) : NULL; 15 1 16
6244 }
6245  
6246 static int
6247 972 gql_runtime_vm_is_callable_property_candidate(pTHX_ SV *value_sv)
6248 {
6249 972 ▶ if (!value_sv || !SvROK(value_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value_sv || !SvROK(value_sv)) { 972 0 972
if (!value_sv || !SvROK(value_sv)) { 758 214 972
6250 758 return 0;
6251 }
6252 214 ▶ if (SvTYPE(SvRV(value_sv)) == SVt_PVCV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(SvRV(value_sv)) == SVt_PVCV) { 19 195 214
6253 19 return 1;
6254 }
6255 /* Perl_amagic_applies is not exported by older supported Perls. Treat a
6256 * blessed magical value as a rare candidate and let the Perl helper decide
6257 * whether it implements &{}; real CVs remain entirely on the native path.
6258 * If schemas commonly return objects with unrelated overloads (for example
6259 * stringified date objects), a future optimization may cache the public
6260 * overload::Method result by stash to avoid repeated Perl round trips. */
6261 195 ▶ return SvOBJECT(SvRV(value_sv)) && SvAMAGIC(value_sv) ? 1 : 0;
Branch: 4 branches
BranchTrueFalseTotal
return SvOBJECT(SvRV(value_sv)) && SvAMAGIC(value_sv) ? 1 : 0; 118 77 195
return SvOBJECT(SvRV(value_sv)) && SvAMAGIC(value_sv) ? 1 : 0; 118 0 118
return SvOBJECT(SvRV(value_sv)) && SvAMAGIC(value_sv) ? 1 : 0; 118 0 118
return SvOBJECT(SvRV(value_sv)) && SvAMAGIC(value_sv) ? 1 : 0; 1 117 118
6262 }
6263  
6264 static SV *
6265 0 gql_runtime_vm_exec_state_execute_block_sync_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, SV *block, IV block_index, SV *source, SV *base_path)
6266 {
6267 gql_runtime_vm_cursor_t snapshot;
6268 gql_runtime_vm_field_frame_t *saved_field_frame;
6269 gql_runtime_vm_field_frame_t stack_field_frame;
6270 gql_runtime_vm_field_frame_guard_t *field_frame_guard;
6271 0 gql_runtime_vm_path_frame_t *base_path_ptr = NULL;
6272 0 const gql_runtime_vm_native_block_t *block_ptr = NULL;
6273  
6274 0 Zero(&snapshot, 1, gql_runtime_vm_cursor_t);
6275 0 Zero(&stack_field_frame, 1, gql_runtime_vm_field_frame_t);
6276 0 ▶ if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) {
Branch: 5 branches
BranchTrueFalseTotal
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
6277 0 base_path_ptr = INT2PTR(gql_runtime_vm_path_frame_t *, SvUV(SvRV(base_path)));
6278 }
6279 0 ▶ saved_field_frame = s ? s->field_frame : NULL;
Branch: 1 branch
BranchTrueFalseTotal
saved_field_frame = s ? s->field_frame : NULL; 0 0 0
6280 0 ▶ gql_runtime_vm_cursor_snapshot_copy(aTHX_ &snapshot, (s && s->cursor) ? s->cursor : NULL);
Branch: 2 branches
BranchTrueFalseTotal
gql_runtime_vm_cursor_snapshot_copy(aTHX_ &snapshot, (s && s->cursor) ? s->cursor : NULL); 0 0 0
gql_runtime_vm_cursor_snapshot_copy(aTHX_ &snapshot, (s && s->cursor) ? s->cursor : NULL); 0 0 0
6281 0 ▶ if (s->cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->cursor) { 0 0 0
6282 0 gql_runtime_vm_cursor_t *dst = s->cursor;
6283 0 ▶ dst->block_index = block_index >= 0 ? block_index : gql_runtime_vm_block_index_from_sv(aTHX_ s, block);
Branch: 1 branch
BranchTrueFalseTotal
dst->block_index = block_index >= 0 ? block_index : gql_runtime_vm_block_index_from_sv(aTHX_ s, block); 0 0 0
6284 0 dst->slot_index = 0;
6285 0 dst->op_index = -1;
6286 0 block_ptr = gql_runtime_vm_cursor_current_native_block(dst);
6287 }
6288 0 ▶ if (!block_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block_ptr) { 0 0 0
6289 0 return newSVsv(&PL_sv_undef);
6290 }
6291 0 field_frame_guard = gql_runtime_vm_arm_field_frame_guard(aTHX_ s, saved_field_frame);
6292  
6293 0 ▶ if (s->frame_stack_count == s->frame_stack_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack_count == s->frame_stack_capacity) { 0 0 0
6294 0 ▶ IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4;
Branch: 1 branch
BranchTrueFalseTotal
IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4; 0 0 0
6295 0 ▶ Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *); 0 0 0
6296 0 s->frame_stack_capacity = new_cap;
6297 }
6298 0 s->frame_stack[s->frame_stack_count++] = gql_runtime_vm_new_block_frame_struct(aTHX);
6299 0 s->frame = s->frame_stack[s->frame_stack_count - 1];
6300 0 ▶ if (!s->response_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->response_frame) { 0 0 0
6301 0 s->response_frame = s->frame;
6302 }
6303  
6304 0 while (1) {
6305 gql_runtime_vm_cursor_t *dst;
6306 IV next_index;
6307 const gql_runtime_vm_native_slot_t *slot;
6308 gql_runtime_vm_outcome_t *outcome;
6309  
6310 0 ▶ if (!s->cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->cursor) { 0 0 0
6311 0 break;
6312 }
6313 0 dst = s->cursor;
6314 0 block_ptr = gql_runtime_vm_cursor_current_native_block(dst);
6315 0 ▶ if (!block_ptr) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!block_ptr) break; 0 0 0
6316 0 next_index = dst->op_index + 1;
6317 0 ▶ if (next_index >= block_ptr->op_count) {
Branch: 1 branch
BranchTrueFalseTotal
if (next_index >= block_ptr->op_count) { 0 0 0
6318 0 dst->op_index = next_index;
6319 0 dst->slot_index = 0;
6320 0 break;
6321 }
6322 0 dst->op_index = next_index;
6323 0 dst->slot_index = block_ptr->ops[next_index].slot_index;
6324 /* Program slot, not effective slot: the result path frame below
6325 * must carry the per-op result name (field alias). */
6326 0 slot = gql_runtime_vm_cursor_current_native_slot(dst);
6327  
6328 0 ▶ if (!gql_runtime_vm_should_execute_op_now(aTHX_ s, NULL)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_should_execute_op_now(aTHX_ s, NULL)) { 0 0 0
6329 0 continue;
6330 }
6331  
6332 {
6333 0 gql_runtime_vm_path_frame_t *path_frame = gql_runtime_vm_new_result_path_frame(
6334 aTHX_
6335 base_path_ptr,
6336 slot
6337 );
6338 0 ▶ if (s->field_frame && s->field_frame != saved_field_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (s->field_frame && s->field_frame != saved_field_frame) { 0 0 0
if (s->field_frame && s->field_frame != saved_field_frame) { 0 0 0
6339 0 gql_runtime_vm_free_field_frame(aTHX_ s->field_frame);
6340 }
6341 0 s->field_frame = gql_runtime_vm_init_stack_field_frame(
6342 aTHX_
6343 &stack_field_frame,
6344 source,
6345 path_frame
6346 );
6347 0 gql_runtime_vm_path_frame_decref(path_frame);
6348 }
6349 0 outcome = gql_runtime_vm_exec_state_execute_current_op_sync_now(aTHX_ state_sv, s);
6350 0 gql_runtime_vm_consume_current_outcome_now(aTHX_ s, outcome);
6351 0 gql_runtime_vm_outcome_decref(aTHX_ outcome);
6352 }
6353  
6354 {
6355 0 SV *result = newSVsv(&PL_sv_undef);
6356 0 ▶ if (s && s->frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (s && s->frame) { 0 0 0
if (s && s->frame) { 0 0 0
6357 0 gql_runtime_vm_block_frame_t *completed_frame = s->frame;
6358 0 result = gql_runtime_vm_native_value_materialize_sv(aTHX_ s->frame->values_value);
6359 0 ▶ if (s->frame_stack_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack_count > 0) { 0 0 0
6360 0 s->frame_stack_count--;
6361 }
6362 0 ▶ s->frame = s->frame_stack_count > 0 ? s->frame_stack[s->frame_stack_count - 1] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
s->frame = s->frame_stack_count > 0 ? s->frame_stack[s->frame_stack_count - 1] : NULL; 0 0 0
6363 0 gql_runtime_vm_free_block_frame(aTHX_ completed_frame);
6364 }
6365 0 ▶ if (s && s->cursor) {
Branch: 2 branches
BranchTrueFalseTotal
if (s && s->cursor) { 0 0 0
if (s && s->cursor) { 0 0 0
6366 0 gql_runtime_vm_cursor_restore_copy(aTHX_ s->cursor, &snapshot);
6367 }
6368 0 gql_runtime_vm_cursor_destroy_copy(aTHX_ &snapshot);
6369 0 ▶ if (s->field_frame && s->field_frame != saved_field_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (s->field_frame && s->field_frame != saved_field_frame) { 0 0 0
if (s->field_frame && s->field_frame != saved_field_frame) { 0 0 0
6370 0 gql_runtime_vm_free_field_frame(aTHX_ s->field_frame);
6371 }
6372 0 s->field_frame = saved_field_frame;
6373 0 field_frame_guard->state = NULL;
6374 0 return result;
6375 }
6376 }
6377  
6378 static SV *
6379 0 gql_runtime_vm_new_serial_mutation_step_callback_sv(pTHX_ gql_runtime_vm_serial_mutation_ctx_t *ctx)
6380 {
6381 CV *cv;
6382 SV *rv;
6383  
6384 0 cv = newXS(NULL, gql_runtime_vm_xs_serial_mutation_step_callback, __FILE__);
6385 0 CvXSUBANY(cv).any_ptr = ctx;
6386 0 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)cv, &gql_runtime_vm_serial_mutation_ctx_vtbl, ctx);
6387 0 rv = newRV_noinc((SV *)cv);
6388 0 return rv;
6389 }
6390  
6391 /*
6392 * Execute mutation root field ops from ctx->next_op_index in serial order.
6393 *
6394 * For each op: if the resolver returns a Promise, chain the next step via
6395 * .then() and return immediately (*all_sync_out = 0). If all ops are sync,
6396 * finalize the block and set *sync_result_out to the materialized data value
6397 * (*all_sync_out = 1).
6398 *
6399 * Caller must push ctx->frame onto s->frame_stack before calling and must
6400 * NOT pop it on serial break (the continuation callback re-pushes it).
6401 */
6402 static void
6403 5 gql_runtime_vm_execute_serial_mutation_steps(
6404 pTHX_
6405 SV *state_sv,
6406 gql_runtime_vm_exec_state_handle_t *s,
6407 gql_runtime_vm_serial_mutation_ctx_t *ctx,
6408 U8 *all_sync_out,
6409 SV **sync_result_out
6410 )
6411 {
6412 5 const gql_runtime_vm_native_block_t *block_ptr = NULL;
6413 gql_runtime_vm_field_frame_t stack_field_frame;
6414 gql_runtime_vm_field_frame_guard_t *field_frame_guard;
6415  
6416 5 *all_sync_out = 1;
6417 5 *sync_result_out = NULL;
6418  
6419 5 Zero(&stack_field_frame, 1, gql_runtime_vm_field_frame_t);
6420 5 field_frame_guard = gql_runtime_vm_arm_field_frame_guard(aTHX_ s, ctx->saved_field_frame);
6421  
6422 5 ▶ if (s->cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->cursor) { 5 0 5
6423 5 s->cursor->block_index = ctx->block_index;
6424 5 block_ptr = gql_runtime_vm_cursor_current_native_block(s->cursor);
6425 }
6426 5 ▶ if (!block_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block_ptr) { 0 5 5
6427 0 goto done_all_sync;
6428 }
6429  
6430 18 ▶ while (ctx->next_op_index < block_ptr->op_count) {
Branch: 1 branch
BranchTrueFalseTotal
while (ctx->next_op_index < block_ptr->op_count) { 13 5 18
6431 13 IV op_index = ctx->next_op_index;
6432 const gql_runtime_vm_native_slot_t *slot;
6433 gql_runtime_vm_path_frame_t *path_frame;
6434 13 gql_runtime_vm_outcome_t *outcome = NULL;
6435 SV *result_sv;
6436 U8 result_is_promise;
6437  
6438 13 s->cursor->op_index = op_index;
6439 13 s->cursor->slot_index = block_ptr->ops[op_index].slot_index;
6440 /* Program slot, not effective slot: the result path frame below
6441 * must carry the per-op result name (field alias). */
6442 13 slot = gql_runtime_vm_cursor_current_native_slot(s->cursor);
6443  
6444 13 ▶ if (!gql_runtime_vm_should_execute_op_now(aTHX_ s, NULL)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_should_execute_op_now(aTHX_ s, NULL)) { 0 13 13
6445 0 ctx->next_op_index++;
6446 6 continue;
6447 }
6448  
6449 13 path_frame = gql_runtime_vm_new_result_path_frame(aTHX_ ctx->base_path_ptr, slot);
6450 13 ▶ if (s->field_frame && s->field_frame != ctx->saved_field_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (s->field_frame && s->field_frame != ctx->saved_field_frame) { 0 13 13
if (s->field_frame && s->field_frame != ctx->saved_field_frame) { 0 0 0
6451 0 gql_runtime_vm_free_field_frame(aTHX_ s->field_frame);
6452 }
6453 13 s->field_frame = gql_runtime_vm_init_stack_field_frame(
6454 aTHX_ &stack_field_frame, ctx->source_sv, path_frame
6455 );
6456 13 gql_runtime_vm_path_frame_decref(path_frame);
6457  
6458 13 result_sv = gql_runtime_vm_exec_state_execute_current_op_async_sv(
6459 aTHX_ state_sv, s, &outcome
6460 );
6461  
6462 13 ▶ if (outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome) { 6 7 13
6463 6 gql_runtime_vm_consume_current_outcome_now(aTHX_ s, outcome);
6464 6 gql_runtime_vm_outcome_decref(aTHX_ outcome);
6465 6 ctx->next_op_index++;
6466 6 continue;
6467 }
6468  
6469 7 result_is_promise = gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, result_sv);
6470 7 gql_runtime_vm_consume_current_result_now(aTHX_ state_sv, s, result_sv);
6471  
6472 7 ▶ if (result_is_promise) {
Branch: 1 branch
BranchTrueFalseTotal
if (result_is_promise) { 0 7 7
6473 0 IV last_entry = ctx->frame->pending_count - 1;
6474 0 SV *pending_promise = NULL;
6475  
6476 0 ▶ if (last_entry >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (last_entry >= 0 0 0 0
6477 0 ▶ && (ctx->frame->pending_entries[last_entry].payload_kind == GQL_VM_PENDING_PROMISE_SV
Branch: 1 branch
BranchTrueFalseTotal
&& (ctx->frame->pending_entries[last_entry].payload_kind == GQL_VM_PENDING_PROMISE_SV 0 0 0
6478 0 ▶ || ctx->frame->pending_entries[last_entry].payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV)) {
Branch: 1 branch
BranchTrueFalseTotal
|| ctx->frame->pending_entries[last_entry].payload_kind == GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV)) { 0 0 0
6479 0 pending_promise = ctx->frame->pending_entries[last_entry].payload.promise_sv;
6480 }
6481  
6482 0 ctx->next_op_index = op_index + 1;
6483 0 *all_sync_out = 0;
6484  
6485 /* Lazily create the outer deferred on first async result */
6486 0 ▶ if (!ctx->frame->deferred_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ctx->frame->deferred_sv) { 0 0 0
6487 0 ctx->frame->deferred_sv = gql_runtime_vm_adapter_new_deferred_sv(
6488 aTHX_ s->async_adapter
6489 );
6490 0 ctx->frame->promise_sv = gql_runtime_vm_adapter_deferred_promise_sv(
6491 0 aTHX_ s->async_adapter, ctx->frame->deferred_sv
6492 );
6493 0 ctx->frame->deferred_resolves_response = (ctx->frame == s->response_frame) ? 1 : 0;
6494 }
6495  
6496 0 ▶ if (pending_promise && SvOK(pending_promise)) {
Branch: 2 branches
BranchTrueFalseTotal
if (pending_promise && SvOK(pending_promise)) { 0 0 0
if (pending_promise && SvOK(pending_promise)) { 0 0 0
6497 0 SV *continuation = gql_runtime_vm_new_serial_mutation_step_callback_sv(aTHX_ ctx);
6498 0 SV *chain = gql_runtime_vm_call_then_promise_for_state_sv(
6499 aTHX_ s, pending_promise, continuation, NULL, NULL
6500 );
6501 0 SvREFCNT_dec(continuation);
6502 0 ▶ if (chain) {
Branch: 1 branch
BranchTrueFalseTotal
if (chain) { 0 0 0
6503 0 SvREFCNT_dec(chain);
6504 }
6505 }
6506  
6507 0 SvREFCNT_dec(result_sv);
6508  
6509 /* Pop ctx->frame from frame_stack; continuation re-pushes it */
6510 0 ▶ if (s->frame_stack_count > 0
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack_count > 0 0 0 0
6511 0 ▶ && s->frame_stack[s->frame_stack_count - 1] == ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
&& s->frame_stack[s->frame_stack_count - 1] == ctx->frame) { 0 0 0
6512 0 s->frame_stack[s->frame_stack_count - 1] = NULL;
6513 0 s->frame_stack_count--;
6514 0 s->frame = s->frame_stack_count > 0
6515 0 ▶ ? s->frame_stack[s->frame_stack_count - 1] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? s->frame_stack[s->frame_stack_count - 1] : NULL; 0 0 0
6516 }
6517 0 field_frame_guard->state = NULL;
6518 0 return;
6519 }
6520  
6521 7 SvREFCNT_dec(result_sv);
6522 7 ctx->next_op_index++;
6523 }
6524  
6525 5 done_all_sync:
6526 {
6527 5 SV *result = gql_runtime_vm_finalize_current_block_now(
6528 aTHX_ state_sv, s, &PL_sv_undef, 0
6529 );
6530 5 ▶ if (s->cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->cursor) { 5 0 5
6531 5 gql_runtime_vm_cursor_restore_copy(aTHX_ s->cursor, &ctx->cursor_snapshot);
6532 }
6533 5 gql_runtime_vm_cursor_destroy_copy(aTHX_ &ctx->cursor_snapshot);
6534 5 Zero(&ctx->cursor_snapshot, 1, gql_runtime_vm_cursor_t);
6535 5 ▶ if (s->field_frame && s->field_frame != ctx->saved_field_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (s->field_frame && s->field_frame != ctx->saved_field_frame) { 0 5 5
if (s->field_frame && s->field_frame != ctx->saved_field_frame) { 0 0 0
6536 0 gql_runtime_vm_free_field_frame(aTHX_ s->field_frame);
6537 }
6538 5 s->field_frame = ctx->saved_field_frame;
6539 5 field_frame_guard->state = NULL;
6540 5 *sync_result_out = result;
6541 }
6542 }
6543  
6544 0 static XS(gql_runtime_vm_xs_serial_mutation_step_callback)
6545 {
6546 dVAR;
6547 0 dXSARGS;
6548 0 gql_runtime_vm_serial_mutation_ctx_t *ctx = INT2PTR(
6549 gql_runtime_vm_serial_mutation_ctx_t *,
6550 CvXSUBANY(cv).any_ptr
6551 );
6552 gql_runtime_vm_exec_state_handle_t *s;
6553 U8 all_sync;
6554 0 SV *sync_result = NULL;
6555  
6556 PERL_UNUSED_VAR(items);
6557  
6558 0 ▶ if (!ctx || !ctx->state_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ctx || !ctx->state_sv) { 0 0 0
if (!ctx || !ctx->state_sv) { 0 0 0
6559 0 XSRETURN_UNDEF;
6560 }
6561  
6562 0 s = gql_runtime_vm_expect_exec_state_handle(aTHX_ ctx->state_sv);
6563  
6564 /* Re-push ctx->frame onto frame_stack so s->frame is correct */
6565 0 ▶ if (ctx->frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { 0 0 0
6566 0 ▶ if (s->frame_stack_count == s->frame_stack_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack_count == s->frame_stack_capacity) { 0 0 0
6567 0 ▶ IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4;
Branch: 1 branch
BranchTrueFalseTotal
IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4; 0 0 0
6568 0 ▶ Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *); 0 0 0
6569 0 s->frame_stack_capacity = new_cap;
6570 }
6571 0 s->frame_stack[s->frame_stack_count++] = ctx->frame;
6572 0 ▶ if (!s->response_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->response_frame) { 0 0 0
6573 0 s->response_frame = ctx->frame;
6574 }
6575 0 s->frame = ctx->frame;
6576 }
6577  
6578 0 gql_runtime_vm_execute_serial_mutation_steps(
6579 aTHX_ ctx->state_sv, s, ctx, &all_sync, &sync_result
6580 );
6581  
6582 0 ▶ if (all_sync && sync_result) {
Branch: 2 branches
BranchTrueFalseTotal
if (all_sync && sync_result) { 0 0 0
if (all_sync && sync_result) { 0 0 0
6583 /* All remaining ops were sync; deferred was pre-created, resolve it now */
6584 0 ▶ if (ctx->frame && ctx->frame->deferred_sv && SvOK(ctx->frame->deferred_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (ctx->frame && ctx->frame->deferred_sv && SvOK(ctx->frame->deferred_sv)) { 0 0 0
if (ctx->frame && ctx->frame->deferred_sv && SvOK(ctx->frame->deferred_sv)) { 0 0 0
if (ctx->frame && ctx->frame->deferred_sv && SvOK(ctx->frame->deferred_sv)) { 0 0 0
6585 0 SV *response = gql_runtime_vm_fast_response_sv(aTHX_ sync_result, s->writer);
6586 0 gql_runtime_vm_adapter_deferred_resolve_sv(
6587 0 aTHX_ s->async_adapter, ctx->frame->deferred_sv, response
6588 );
6589 0 SvREFCNT_dec(response);
6590 }
6591 0 SvREFCNT_dec(sync_result);
6592 }
6593  
6594 0 XSRETURN_UNDEF;
6595 }
6596  
6597 static SV *
6598 5 gql_runtime_vm_exec_state_execute_block_serial_mutation_sv(
6599 pTHX_
6600 SV *state_sv,
6601 gql_runtime_vm_exec_state_handle_t *s,
6602 IV block_index,
6603 SV *source,
6604 gql_runtime_vm_path_frame_t *base_path_ptr
6605 )
6606 {
6607 gql_runtime_vm_serial_mutation_ctx_t *ctx;
6608 gql_runtime_vm_block_frame_t *frame;
6609 SV *outer_promise;
6610 U8 all_sync;
6611 5 SV *sync_result = NULL;
6612  
6613 /* Build the serial context */
6614 5 Newxz(ctx, 1, gql_runtime_vm_serial_mutation_ctx_t);
6615 5 ctx->state_sv = SvREFCNT_inc_simple_NN(state_sv);
6616 5 ctx->block_index = block_index;
6617 5 ctx->next_op_index = 0;
6618 5 ▶ ctx->source_sv = source ? SvREFCNT_inc_simple_NN(source) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ctx->source_sv = source ? SvREFCNT_inc_simple_NN(source) : NULL; 5 0 5
6619 5 ctx->base_path_ptr = base_path_ptr;
6620 5 ▶ if (ctx->base_path_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->base_path_ptr) { 0 5 5
6621 0 ctx->base_path_ptr->refcount++;
6622 }
6623 5 ctx->saved_field_frame = s->field_frame;
6624 10 ▶ gql_runtime_vm_cursor_snapshot_copy(aTHX_ &ctx->cursor_snapshot,
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_cursor_snapshot_copy(aTHX_ &ctx->cursor_snapshot, 5 0 5
6625 5 ▶ (s && s->cursor) ? s->cursor : NULL);
Branch: 1 branch
BranchTrueFalseTotal
(s && s->cursor) ? s->cursor : NULL); 5 0 5
6626  
6627 /* Create the accumulator frame; deferred is created lazily on first async result */
6628 5 frame = gql_runtime_vm_new_block_frame_struct(aTHX);
6629 5 ctx->frame = frame;
6630 5 ctx->frame->refcount++; /* ctx holds an extra ref */
6631  
6632 /* Push the frame onto the exec-state frame stack */
6633 5 ▶ if (s->frame_stack_count == s->frame_stack_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack_count == s->frame_stack_capacity) { 5 0 5
6634 5 ▶ IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4;
Branch: 1 branch
BranchTrueFalseTotal
IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4; 0 5 5
6635 5 ▶ Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *); 0 5 5
6636 5 s->frame_stack_capacity = new_cap;
6637 }
6638 5 s->frame_stack[s->frame_stack_count++] = frame;
6639 5 ▶ if (!s->response_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->response_frame) { 5 0 5
6640 5 s->response_frame = frame;
6641 }
6642 5 s->frame = frame;
6643  
6644 /* Run the first batch of serial steps */
6645 5 gql_runtime_vm_execute_serial_mutation_steps(
6646 aTHX_ state_sv, s, ctx, &all_sync, &sync_result
6647 );
6648  
6649 /* Release the ctx ref held by this scope */
6650 5 ▶ if (all_sync) {
Branch: 1 branch
BranchTrueFalseTotal
if (all_sync) { 5 0 5
6651 /* No callbacks were created – free ctx manually */
6652 5 ▶ if (ctx->state_sv) { SvREFCNT_dec(ctx->state_sv); }
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->state_sv) { SvREFCNT_dec(ctx->state_sv); } 5 0 5
6653 5 ▶ if (ctx->source_sv) { SvREFCNT_dec(ctx->source_sv); }
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->source_sv) { SvREFCNT_dec(ctx->source_sv); } 5 0 5
6654 5 ▶ if (ctx->base_path_ptr) { gql_runtime_vm_path_frame_decref(ctx->base_path_ptr); }
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->base_path_ptr) { gql_runtime_vm_path_frame_decref(ctx->base_path_ptr); } 0 5 5
6655 5 ▶ if (ctx->frame) { gql_runtime_vm_free_block_frame(aTHX_ ctx->frame); }
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->frame) { gql_runtime_vm_free_block_frame(aTHX_ ctx->frame); } 5 0 5
6656 5 gql_runtime_vm_cursor_destroy_copy(aTHX_ &ctx->cursor_snapshot);
6657 5 Safefree(ctx);
6658 /* Return data SV directly; caller wraps with materialize_response_sv */
6659 5 ▶ return sync_result ? sync_result : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return sync_result ? sync_result : newSVsv(&PL_sv_undef); 0 5 5
6660 }
6661 /* else: ctx is owned by the continuation callback CVs via magic */
6662  
6663 /* Return the deferred's promise (created lazily in execute_serial_mutation_steps) */
6664 0 ▶ outer_promise = frame->promise_sv ? newSVsv(frame->promise_sv) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
outer_promise = frame->promise_sv ? newSVsv(frame->promise_sv) : newSVsv(&PL_sv_undef); 0 0 0
6665 0 return outer_promise;
6666 }
6667  
6668 static SV *
6669 61 gql_runtime_vm_exec_state_execute_block_async_sv(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s, IV block_index, SV *source, SV *base_path)
6670 {
6671 61 gql_runtime_vm_path_frame_t *base_path_ptr = NULL;
6672  
6673 61 ▶ if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) {
Branch: 5 branches
BranchTrueFalseTotal
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 61 0 61
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 61 61
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
if (base_path && SvOK(base_path) && SvROK(base_path) && SvIOK(SvRV(base_path)) && SvUV(SvRV(base_path)) != 0) { 0 0 0
6674 0 base_path_ptr = INT2PTR(gql_runtime_vm_path_frame_t *, SvUV(SvRV(base_path)));
6675 }
6676  
6677 61 return gql_runtime_vm_exec_state_execute_block_async_path_sv(
6678 aTHX_ state_sv, s, block_index, source, base_path_ptr, 0
6679 );
6680 }
6681  
6682 static SV *
6683 450 gql_runtime_vm_exec_state_execute_block_async_path_sv(
6684 pTHX_
6685 SV *state_sv,
6686 gql_runtime_vm_exec_state_handle_t *s,
6687 IV block_index,
6688 SV *source,
6689 gql_runtime_vm_path_frame_t *base_path_ptr,
6690 U8 return_pending_handle
6691 )
6692 {
6693 gql_runtime_vm_cursor_t snapshot;
6694 gql_runtime_vm_field_frame_t *saved_field_frame;
6695 gql_runtime_vm_field_frame_t stack_field_frame;
6696 gql_runtime_vm_field_frame_guard_t *field_frame_guard;
6697 450 const gql_runtime_vm_native_block_t *block_ptr = NULL;
6698  
6699 /* Dispatch to serial executor for mutation root blocks */
6700 450 ▶ if (s && s->cursor && s->cursor->native_program
Branch: 3 branches
BranchTrueFalseTotal
if (s && s->cursor && s->cursor->native_program 450 0 450
if (s && s->cursor && s->cursor->native_program 450 0 450
if (s && s->cursor && s->cursor->native_program 450 0 450
6701 450 ▶ && s->cursor->native_program->operation_type_code == GQL_VM_OPTYPE_MUTATION
Branch: 1 branch
BranchTrueFalseTotal
&& s->cursor->native_program->operation_type_code == GQL_VM_OPTYPE_MUTATION 5 445 450
6702 5 ▶ && block_index == s->cursor->native_program->root_block_index
Branch: 1 branch
BranchTrueFalseTotal
&& block_index == s->cursor->native_program->root_block_index 5 0 5
6703 5 ▶ && s->async_adapter != NULL
Branch: 1 branch
BranchTrueFalseTotal
&& s->async_adapter != NULL 5 0 5
6704 5 ▶ && return_pending_handle == 0) {
Branch: 1 branch
BranchTrueFalseTotal
&& return_pending_handle == 0) { 5 0 5
6705 5 return gql_runtime_vm_exec_state_execute_block_serial_mutation_sv(
6706 aTHX_ state_sv, s, block_index, source, base_path_ptr
6707 );
6708 }
6709  
6710 445 Zero(&snapshot, 1, gql_runtime_vm_cursor_t);
6711 445 Zero(&stack_field_frame, 1, gql_runtime_vm_field_frame_t);
6712 445 ▶ saved_field_frame = s ? s->field_frame : NULL;
Branch: 1 branch
BranchTrueFalseTotal
saved_field_frame = s ? s->field_frame : NULL; 445 0 445
6713 445 ▶ gql_runtime_vm_cursor_snapshot_copy(aTHX_ &snapshot, (s && s->cursor) ? s->cursor : NULL);
Branch: 2 branches
BranchTrueFalseTotal
gql_runtime_vm_cursor_snapshot_copy(aTHX_ &snapshot, (s && s->cursor) ? s->cursor : NULL); 445 0 445
gql_runtime_vm_cursor_snapshot_copy(aTHX_ &snapshot, (s && s->cursor) ? s->cursor : NULL); 445 0 445
6714 445 ▶ if (s->cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->cursor) { 445 0 445
6715 445 gql_runtime_vm_cursor_t *dst = s->cursor;
6716 445 dst->block_index = block_index;
6717 445 dst->slot_index = 0;
6718 445 dst->op_index = -1;
6719 445 block_ptr = gql_runtime_vm_cursor_current_native_block(dst);
6720 }
6721 445 ▶ if (!block_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block_ptr) { 0 445 445
6722 0 return newSVsv(&PL_sv_undef);
6723 }
6724 445 field_frame_guard = gql_runtime_vm_arm_field_frame_guard(aTHX_ s, saved_field_frame);
6725  
6726 445 ▶ if (s->frame_stack_count == s->frame_stack_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->frame_stack_count == s->frame_stack_capacity) { 89 356 445
6727 89 ▶ IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4;
Branch: 1 branch
BranchTrueFalseTotal
IV new_cap = s->frame_stack_capacity ? s->frame_stack_capacity * 2 : 4; 10 79 89
6728 89 ▶ Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(s->frame_stack, new_cap, gql_runtime_vm_block_frame_t *); 0 89 89
6729 89 s->frame_stack_capacity = new_cap;
6730 }
6731 445 s->frame_stack[s->frame_stack_count++] = gql_runtime_vm_new_block_frame_struct(aTHX);
6732 445 s->frame = s->frame_stack[s->frame_stack_count - 1];
6733 445 ▶ if (!s->response_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->response_frame) { 59 386 445
6734 59 s->response_frame = s->frame;
6735 }
6736  
6737 1306 while (1) {
6738 gql_runtime_vm_cursor_t *dst;
6739 IV next_index;
6740 const gql_runtime_vm_native_slot_t *slot;
6741  
6742 1751 ▶ if (!s->cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s->cursor) { 0 1751 1751
6743 0 break;
6744 }
6745 1751 dst = s->cursor;
6746 1751 block_ptr = gql_runtime_vm_cursor_current_native_block(dst);
6747 1751 ▶ if (!block_ptr) break;
Branch: 1 branch
BranchTrueFalseTotal
if (!block_ptr) break; 0 1751 1751
6748 1751 next_index = dst->op_index + 1;
6749 1751 ▶ if (next_index >= block_ptr->op_count) {
Branch: 1 branch
BranchTrueFalseTotal
if (next_index >= block_ptr->op_count) { 445 1306 1751
6750 445 dst->op_index = next_index;
6751 445 dst->slot_index = 0;
6752 445 break;
6753 }
6754 1306 dst->op_index = next_index;
6755 1306 dst->slot_index = block_ptr->ops[next_index].slot_index;
6756 /* Program slot, not effective slot: the result path frame below
6757 * must carry the per-op result name (field alias). */
6758 1306 slot = gql_runtime_vm_cursor_current_native_slot(dst);
6759  
6760 1306 ▶ if (!gql_runtime_vm_should_execute_op_now(aTHX_ s, NULL)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_should_execute_op_now(aTHX_ s, NULL)) { 0 1306 1306
6761 0 continue;
6762 }
6763  
6764 {
6765 1306 gql_runtime_vm_path_frame_t *path_frame = gql_runtime_vm_new_result_path_frame(
6766 aTHX_
6767 base_path_ptr,
6768 slot
6769 );
6770 1306 gql_runtime_vm_outcome_t *outcome = NULL;
6771 SV *result_sv;
6772  
6773 1306 ▶ if (s->field_frame && s->field_frame != saved_field_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (s->field_frame && s->field_frame != saved_field_frame) { 332 974 1306
if (s->field_frame && s->field_frame != saved_field_frame) { 0 332 332
6774 0 gql_runtime_vm_free_field_frame(aTHX_ s->field_frame);
6775 }
6776 1306 s->field_frame = gql_runtime_vm_init_stack_field_frame(
6777 aTHX_
6778 &stack_field_frame,
6779 source,
6780 path_frame
6781 );
6782 1306 gql_runtime_vm_path_frame_decref(path_frame);
6783  
6784 1306 result_sv = gql_runtime_vm_exec_state_execute_current_op_async_sv(
6785 aTHX_
6786 state_sv,
6787 s,
6788 &outcome
6789 );
6790 1306 ▶ if (outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome) { 1234 72 1306
6791 1234 gql_runtime_vm_consume_current_outcome_now(aTHX_ s, outcome);
6792 1234 gql_runtime_vm_outcome_decref(aTHX_ outcome);
6793 } else {
6794 72 gql_runtime_vm_consume_current_result_now(aTHX_ state_sv, s, result_sv);
6795 72 ▶ if (result_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (result_sv) { 72 0 72
6796 72 SvREFCNT_dec(result_sv);
6797 }
6798 }
6799 }
6800 }
6801  
6802 {
6803 445 SV *result = gql_runtime_vm_finalize_current_block_now(aTHX_ state_sv, s, &PL_sv_undef, return_pending_handle);
6804 443 ▶ if (s && s->cursor) {
Branch: 2 branches
BranchTrueFalseTotal
if (s && s->cursor) { 443 0 443
if (s && s->cursor) { 443 0 443
6805 443 gql_runtime_vm_cursor_restore_copy(aTHX_ s->cursor, &snapshot);
6806 }
6807 443 gql_runtime_vm_cursor_destroy_copy(aTHX_ &snapshot);
6808 443 ▶ if (s->field_frame && s->field_frame != saved_field_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (s->field_frame && s->field_frame != saved_field_frame) { 0 443 443
if (s->field_frame && s->field_frame != saved_field_frame) { 0 0 0
6809 0 gql_runtime_vm_free_field_frame(aTHX_ s->field_frame);
6810 }
6811 443 s->field_frame = saved_field_frame;
6812 443 field_frame_guard->state = NULL;
6813 443 return result;
6814 }
6815 }
6816  
6817 static gql_runtime_vm_outcome_t *
6818 0 gql_runtime_vm_exec_state_execute_current_op_sync_now(pTHX_ SV *state_sv, gql_runtime_vm_exec_state_handle_t *s)
6819 {
6820 const gql_runtime_vm_native_block_t *block;
6821 const gql_runtime_vm_native_op_t *op;
6822 const gql_runtime_vm_native_slot_t *slot;
6823 SV *source_sv;
6824 0 SV *resolved_sv = NULL;
6825 0 SV *error_sv = NULL;
6826 IV resolve_code;
6827 IV complete_code;
6828  
6829 0 ▶ if (!s || !s->cursor || !s->field_frame) {
Branch: 3 branches
BranchTrueFalseTotal
if (!s || !s->cursor || !s->field_frame) { 0 0 0
if (!s || !s->cursor || !s->field_frame) { 0 0 0
if (!s || !s->cursor || !s->field_frame) { 0 0 0
6830 0 return gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef);
6831 }
6832  
6833 0 block = gql_runtime_vm_cursor_current_native_block(s->cursor);
6834 0 op = gql_runtime_vm_cursor_current_native_op(s->cursor);
6835 0 slot = gql_runtime_vm_cursor_current_native_slot(s->cursor);
6836 0 source_sv = s->field_frame->source;
6837 0 ▶ resolve_code = op ? op->resolve_code : 0;
Branch: 1 branch
BranchTrueFalseTotal
resolve_code = op ? op->resolve_code : 0; 0 0 0
6838 0 ▶ complete_code = op ? op->complete_code : 0;
Branch: 1 branch
BranchTrueFalseTotal
complete_code = op ? op->complete_code : 0; 0 0 0
6839  
6840 0 ▶ switch (resolve_code) {
Branch: 1 branch
BranchTrueFalseTotal
switch (resolve_code) { 0 0 0
6841 0 case GQL_VM_RESOLVE_DEFAULT:
6842 case GQL_VM_RESOLVE_EXPLICIT:
6843 {
6844 0 ▶ const char *field_name = slot ? slot->field_name : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *field_name = slot ? slot->field_name : ""; 0 0 0
6845 0 ▶ SV *field_name_sv = field_name ? newSVpv(field_name, 0) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
SV *field_name_sv = field_name ? newSVpv(field_name, 0) : newSVsv(&PL_sv_undef); 0 0 0
6846 0 SV *resolver_sv = gql_runtime_vm_state_current_resolver_sv(aTHX_ s);
6847 0 ▶ if (field_name && strEQ(field_name, "__typename")) {
Branch: 2 branches
BranchTrueFalseTotal
if (field_name && strEQ(field_name, "__typename")) { 0 0 0
if (field_name && strEQ(field_name, "__typename")) { 0 0 0
6848 0 ▶ resolved_sv = (block && block->type_name && *block->type_name)
Branch: 2 branches
BranchTrueFalseTotal
resolved_sv = (block && block->type_name && *block->type_name) 0 0 0
resolved_sv = (block && block->type_name && *block->type_name) 0 0 0
6849 0 ? newSVpv(block->type_name, 0)
6850 0 ▶ : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
: newSVsv(&PL_sv_undef); 0 0 0
6851 0 ▶ } else if (slot && slot->accessor_name && slot->accessor_name_len) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (slot && slot->accessor_name && slot->accessor_name_len) { 0 0 0
} else if (slot && slot->accessor_name && slot->accessor_name_len) { 0 0 0
} else if (slot && slot->accessor_name && slot->accessor_name_len) { 0 0 0
6852 0 resolved_sv = gql_runtime_vm_call_accessor_nonfatal(
6853 aTHX_ source_sv, slot, &error_sv
6854 );
6855 0 ▶ } else if (resolver_sv && SvOK(resolver_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (resolver_sv && SvOK(resolver_sv)) { 0 0 0
} else if (resolver_sv && SvOK(resolver_sv)) { 0 0 0
6856 0 SV *args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
6857 0 SV *info_sv = gql_runtime_vm_new_lazy_info_sv(aTHX_ state_sv, s, NULL);
6858 0 SV *return_type_sv = gql_runtime_vm_state_current_return_type_sv(aTHX_ s, NULL, NULL);
6859 0 resolved_sv = gql_runtime_vm_call_resolver_sv(
6860 aTHX_ resolver_sv, source_sv, args_sv, s->context, info_sv, return_type_sv, &error_sv
6861 );
6862 0 SvREFCNT_dec(args_sv);
6863 0 SvREFCNT_dec(info_sv);
6864 } else {
6865 0 CV *method_cv = gql_runtime_vm_default_method_cv(source_sv, field_name);
6866 0 ▶ if (method_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (method_cv) { 0 0 0
6867 0 SV *args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
6868 0 SV *info_sv = gql_runtime_vm_new_lazy_info_sv(aTHX_ state_sv, s, NULL);
6869 0 resolved_sv = gql_runtime_vm_call_cb4_nonfatal(
6870 aTHX_ (SV *)method_cv, source_sv, args_sv, s->context, info_sv, &error_sv
6871 );
6872 0 SvREFCNT_dec(args_sv);
6873 0 SvREFCNT_dec(info_sv);
6874 0 ▶ } else if (source_sv && SvOK(source_sv) && SvROK(source_sv)
Branch: 3 branches
BranchTrueFalseTotal
} else if (source_sv && SvOK(source_sv) && SvROK(source_sv) 0 0 0
} else if (source_sv && SvOK(source_sv) && SvROK(source_sv) 0 0 0
} else if (source_sv && SvOK(source_sv) && SvROK(source_sv) 0 0 0
6875 0 ▶ && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) {
Branch: 3 branches
BranchTrueFalseTotal
&& SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 0 0 0
&& SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 0 0 0
&& SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 0 0 0
6876 0 HE *he = hv_fetch_ent((HV *)SvRV(source_sv), field_name_sv, 0, 0);
6877 0 ▶ SV *value_sv = he ? HeVAL(he) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *value_sv = he ? HeVAL(he) : &PL_sv_undef; 0 0 0
6878 0 ▶ if (gql_runtime_vm_is_callable_property_candidate(aTHX_ value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_callable_property_candidate(aTHX_ value_sv)) { 0 0 0
6879 0 SV *args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
6880 0 SV *info_sv = gql_runtime_vm_new_lazy_info_sv(aTHX_ state_sv, s, NULL);
6881 0 resolved_sv = gql_runtime_vm_call_default_property_sv(
6882 aTHX_ value_sv, args_sv, s->context, info_sv, &error_sv
6883 );
6884 0 SvREFCNT_dec(args_sv);
6885 0 SvREFCNT_dec(info_sv);
6886 } else {
6887 0 resolved_sv = newSVsv(value_sv);
6888 }
6889 } else {
6890 0 resolved_sv = newSVsv(&PL_sv_undef);
6891 }
6892 }
6893 0 SvREFCNT_dec(field_name_sv);
6894 0 break;
6895 }
6896 0 default:
6897 0 resolved_sv = newSVsv(&PL_sv_undef);
6898 0 break;
6899 }
6900  
6901 0 ▶ if (error_sv && SvOK(error_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_sv && SvOK(error_sv)) { 0 0 0
if (error_sv && SvOK(error_sv)) { 0 0 0
6902 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ error_sv, s->field_frame->path_frame);
6903 0 SvREFCNT_dec(error_sv);
6904 0 ▶ if (resolved_sv) SvREFCNT_dec(resolved_sv);
Branch: 1 branch
BranchTrueFalseTotal
if (resolved_sv) SvREFCNT_dec(resolved_sv); 0 0 0
6905 0 return outcome;
6906 }
6907  
6908 0 switch (complete_code) {
6909 0 case GQL_VM_COMPLETE_OBJECT:
6910 {
6911 0 IV child_block_index = -1;
6912 0 ▶ if (!resolved_sv || !SvOK(resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved_sv || !SvOK(resolved_sv)) { 0 0 0
if (!resolved_sv || !SvOK(resolved_sv)) { 0 0 0
6913 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef);
6914 0 SvREFCNT_dec(resolved_sv);
6915 0 return outcome;
6916 }
6917 0 ▶ if (op) {
Branch: 1 branch
BranchTrueFalseTotal
if (op) { 0 0 0
6918 0 child_block_index = op->child_block_index;
6919 }
6920 0 ▶ if (child_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index < 0) { 0 0 0
6921 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, resolved_sv, &PL_sv_undef);
6922 0 SvREFCNT_dec(resolved_sv);
6923 0 return outcome;
6924 }
6925 {
6926 0 SV *base_path_sv = gql_runtime_vm_wrap_path_frame_sv(aTHX_ s->field_frame->path_frame);
6927 0 SV *child_value = gql_runtime_vm_exec_state_execute_block_sync_sv(aTHX_ state_sv, s, &PL_sv_undef, child_block_index, resolved_sv, base_path_sv);
6928 0 SvREFCNT_dec(base_path_sv);
6929 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_OBJECT, child_value, &PL_sv_undef);
6930 0 SvREFCNT_dec(child_value);
6931 0 SvREFCNT_dec(resolved_sv);
6932 0 return outcome;
6933 }
6934 }
6935 0 case GQL_VM_COMPLETE_LIST:
6936 {
6937 0 IV child_block_index = -1;
6938 AV *items_av;
6939 AV *resolved_items_av;
6940 SSize_t i;
6941 0 ▶ if (!resolved_sv || !SvOK(resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved_sv || !SvOK(resolved_sv)) { 0 0 0
if (!resolved_sv || !SvOK(resolved_sv)) { 0 0 0
6942 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef);
6943 0 SvREFCNT_dec(resolved_sv);
6944 0 return outcome;
6945 }
6946 0 ▶ if (!SvROK(resolved_sv) || SvTYPE(SvRV(resolved_sv)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(resolved_sv) || SvTYPE(SvRV(resolved_sv)) != SVt_PVAV) { 0 0 0
if (!SvROK(resolved_sv) || SvTYPE(SvRV(resolved_sv)) != SVt_PVAV) { 0 0 0
6947 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, resolved_sv, &PL_sv_undef);
6948 0 SvREFCNT_dec(resolved_sv);
6949 0 return outcome;
6950 }
6951 0 ▶ if (op) {
Branch: 1 branch
BranchTrueFalseTotal
if (op) { 0 0 0
6952 0 child_block_index = op->child_block_index;
6953 }
6954 0 items_av = (AV *)SvRV(resolved_sv);
6955 0 resolved_items_av = newAV();
6956 0 ▶ for (i = 0; i <= av_len(items_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(items_av); i++) { 0 0 0
6957 0 SV **item_svp = av_fetch(items_av, i, 0);
6958 0 ▶ SV *item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef; 0 0 0
SV *item_sv = (item_svp && *item_svp) ? *item_svp : &PL_sv_undef; 0 0 0
6959 0 ▶ if (child_block_index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index >= 0) { 0 0 0
6960 0 SV *item_key = newSViv(i);
6961 0 SV *base_path_sv = gql_runtime_vm_wrap_path_frame_sv(aTHX_ s->field_frame->path_frame);
6962 0 SV *item_path = gql_runtime_vm_new_path_frame_handle(aTHX_ base_path_sv, item_key);
6963 0 SV *child_value = gql_runtime_vm_exec_state_execute_block_sync_sv(aTHX_ state_sv, s, &PL_sv_undef, child_block_index, item_sv, item_path);
6964 0 av_push(resolved_items_av, child_value);
6965 0 SvREFCNT_dec(base_path_sv);
6966 0 SvREFCNT_dec(item_key);
6967 0 SvREFCNT_dec(item_path);
6968 } else {
6969 0 av_push(resolved_items_av, newSVsv(item_sv));
6970 }
6971 }
6972 {
6973 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_LIST, newRV_noinc((SV *)resolved_items_av), &PL_sv_undef);
6974 0 SvREFCNT_dec(resolved_sv);
6975 0 return outcome;
6976 }
6977 }
6978 0 case GQL_VM_COMPLETE_ABSTRACT:
6979 {
6980 0 SV *runtime_error_sv = NULL;
6981 SV *runtime_type_sv;
6982 0 IV child_block_index = -1;
6983 0 ▶ if (!resolved_sv || !SvOK(resolved_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved_sv || !SvOK(resolved_sv)) { 0 0 0
if (!resolved_sv || !SvOK(resolved_sv)) { 0 0 0
6984 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, &PL_sv_undef, &PL_sv_undef);
6985 0 SvREFCNT_dec(resolved_sv);
6986 0 return outcome;
6987 }
6988 0 runtime_type_sv = gql_runtime_vm_exec_state_resolve_runtime_type_current_sv(
6989 aTHX_
6990 state_sv,
6991 s,
6992 resolved_sv,
6993 NULL,
6994 &runtime_error_sv
6995 );
6996 0 ▶ if (runtime_error_sv && SvOK(runtime_error_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime_error_sv && SvOK(runtime_error_sv)) { 0 0 0
if (runtime_error_sv && SvOK(runtime_error_sv)) { 0 0 0
6997 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ runtime_error_sv, s->field_frame->path_frame);
6998 0 SvREFCNT_dec(runtime_error_sv);
6999 0 SvREFCNT_dec(resolved_sv);
7000 0 return outcome;
7001 }
7002 0 ▶ if (!runtime_type_sv || !SvOK(runtime_type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime_type_sv || !SvOK(runtime_type_sv)) { 0 0 0
if (!runtime_type_sv || !SvOK(runtime_type_sv)) { 0 0 0
7003 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, resolved_sv, &PL_sv_undef);
7004 0 SvREFCNT_dec(resolved_sv);
7005 0 ▶ if (runtime_type_sv) SvREFCNT_dec(runtime_type_sv);
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_type_sv) SvREFCNT_dec(runtime_type_sv); 0 0 0
7006 0 return outcome;
7007 }
7008 0 child_block_index = gql_runtime_vm_find_abstract_child_block_index(
7009 op,
7010 gql_runtime_vm_type_name_from_sv(aTHX_ runtime_type_sv)
7011 );
7012 0 ▶ if (child_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index < 0) { 0 0 0
7013 0 SvREFCNT_dec(runtime_type_sv);
7014 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, resolved_sv, &PL_sv_undef);
7015 0 SvREFCNT_dec(resolved_sv);
7016 0 return outcome;
7017 }
7018 0 SvREFCNT_dec(runtime_type_sv);
7019 {
7020 0 SV *base_path_sv = gql_runtime_vm_wrap_path_frame_sv(aTHX_ s->field_frame->path_frame);
7021 0 SV *child_value = gql_runtime_vm_exec_state_execute_block_sync_sv(aTHX_ state_sv, s, &PL_sv_undef, child_block_index, resolved_sv, base_path_sv);
7022 0 SvREFCNT_dec(base_path_sv);
7023 0 gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_OBJECT, child_value, &PL_sv_undef);
7024 0 SvREFCNT_dec(child_value);
7025 0 SvREFCNT_dec(resolved_sv);
7026 0 return outcome;
7027 }
7028 }
7029 0 case GQL_VM_COMPLETE_GENERIC:
7030 default:
7031 {
7032 0 ▶ gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, resolved_sv ? resolved_sv : &PL_sv_undef, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_outcome_t *outcome = gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, resolved_sv ? resolved_sv : &PL_sv_undef, &PL_sv_undef); 0 0 0
7033 0 SvREFCNT_dec(resolved_sv);
7034 0 return outcome;
7035 }
7036 }
7037 }
7038  
7039 static SV *
7040 1319 gql_runtime_vm_exec_state_resolve_current_value_sv(
7041 pTHX_
7042 SV *state_sv,
7043 gql_runtime_vm_exec_state_handle_t *s,
7044 SV *source_sv,
7045 gql_runtime_vm_path_frame_t *path_frame,
7046 SV **error_out
7047 )
7048 {
7049 const gql_runtime_vm_native_runtime_t *runtime;
7050 const gql_runtime_vm_native_block_t *block;
7051 const gql_runtime_vm_native_slot_t *slot;
7052 const char *field_name;
7053 SV *resolver_sv;
7054 1319 SV *resolved_sv = NULL;
7055 1319 SV *field_name_sv = NULL;
7056  
7057 1319 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 1319 0 1319
7058 1319 *error_out = NULL;
7059 }
7060  
7061 1319 ▶ if (!s || !s->cursor) {
Branch: 2 branches
BranchTrueFalseTotal
if (!s || !s->cursor) { 1319 0 1319
if (!s || !s->cursor) { 0 1319 1319
7062 0 return newSVsv(&PL_sv_undef);
7063 }
7064  
7065 1319 runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
7066 1319 block = gql_runtime_vm_cursor_current_native_block(s->cursor);
7067 1319 slot = gql_runtime_vm_cursor_current_native_slot(s->cursor);
7068 1319 slot = gql_runtime_vm_effective_slot(runtime, slot);
7069 1319 ▶ field_name = slot ? slot->field_name : "";
Branch: 1 branch
BranchTrueFalseTotal
field_name = slot ? slot->field_name : ""; 1319 0 1319
7070 1319 resolver_sv = gql_runtime_vm_state_current_resolver_sv(aTHX_ s);
7071  
7072 1319 ▶ if (field_name && strEQ(field_name, "__typename")) {
Branch: 2 branches
BranchTrueFalseTotal
if (field_name && strEQ(field_name, "__typename")) { 1319 0 1319
if (field_name && strEQ(field_name, "__typename")) { 3 1316 1319
7073 3 ▶ return (block && block->type_name && *block->type_name)
Branch: 2 branches
BranchTrueFalseTotal
return (block && block->type_name && *block->type_name) 3 0 3
return (block && block->type_name && *block->type_name) 3 0 3
7074 3 ? newSVpv(block->type_name, 0)
7075 6 ▶ : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
: newSVsv(&PL_sv_undef); 3 0 3
7076 }
7077  
7078 1316 ▶ if (slot && slot->accessor_name && slot->accessor_name_len) {
Branch: 3 branches
BranchTrueFalseTotal
if (slot && slot->accessor_name && slot->accessor_name_len) { 1316 0 1316
if (slot && slot->accessor_name && slot->accessor_name_len) { 1 1315 1316
if (slot && slot->accessor_name && slot->accessor_name_len) { 1 0 1
7079 1 return gql_runtime_vm_call_accessor_nonfatal(
7080 aTHX_ source_sv, slot, error_out
7081 );
7082 }
7083  
7084 1315 ▶ if (resolver_sv && SvOK(resolver_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (resolver_sv && SvOK(resolver_sv)) { 989 326 1315
if (resolver_sv && SvOK(resolver_sv)) { 989 0 989
7085 989 SV *args_sv = NULL;
7086 989 SV *return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
7087  
7088 989 ▶ if (gql_runtime_vm_slot_uses_native_no_args_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_no_args_abi(slot)) { 1 988 989
7089 1 ▶ resolved_sv = gql_runtime_vm_call_cb3_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
resolved_sv = gql_runtime_vm_call_cb3_nonfatal( 1 0 1
7090 aTHX_
7091 resolver_sv,
7092 source_sv,
7093 s->context,
7094 return_type_sv ? return_type_sv : &PL_sv_undef,
7095 error_out
7096 );
7097 988 ▶ } else if (gql_runtime_vm_slot_uses_native_one_arg_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_slot_uses_native_one_arg_abi(slot)) { 2 986 988
7098 2 SV *args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
7099 2 ▶ HV *args_hv = (args_sv && SvROK(args_sv) && SvTYPE(SvRV(args_sv)) == SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
HV *args_hv = (args_sv && SvROK(args_sv) && SvTYPE(SvRV(args_sv)) == SVt_PVHV) 2 0 2
HV *args_hv = (args_sv && SvROK(args_sv) && SvTYPE(SvRV(args_sv)) == SVt_PVHV) 2 0 2
7100 ? (HV *)SvRV(args_sv)
7101 4 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 2 0 2
7102 2 const gql_runtime_vm_native_arg_def_t *arg_def =
7103 2 ▶ (slot && slot->arg_def_count == 1) ? &slot->arg_defs[0] : NULL;
Branch: 2 branches
BranchTrueFalseTotal
(slot && slot->arg_def_count == 1) ? &slot->arg_defs[0] : NULL; 2 0 2
(slot && slot->arg_def_count == 1) ? &slot->arg_defs[0] : NULL; 2 0 2
7104 2 ▶ SV **value_svp = (args_hv && arg_def)
Branch: 1 branch
BranchTrueFalseTotal
SV **value_svp = (args_hv && arg_def) 2 0 2
7105 2 ? hv_fetch(args_hv, arg_def->name, (I32)strlen(arg_def->name), 0)
7106 2 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 2 0 2
7107 4 ▶ resolved_sv = gql_runtime_vm_call_cb4_nonfatal(
Branch: 2 branches
BranchTrueFalseTotal
resolved_sv = gql_runtime_vm_call_cb4_nonfatal( 2 0 2
resolved_sv = gql_runtime_vm_call_cb4_nonfatal( 2 0 2
7108 aTHX_
7109 resolver_sv,
7110 source_sv,
7111 2 ▶ (value_svp && *value_svp) ? *value_svp : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
(value_svp && *value_svp) ? *value_svp : &PL_sv_undef, 2 0 2
7112 s->context,
7113 return_type_sv ? return_type_sv : &PL_sv_undef,
7114 error_out
7115 );
7116 986 ▶ } else if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) { 2 984 986
7117 2 args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
7118 2 ▶ resolved_sv = gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
resolved_sv = gql_runtime_vm_call_cb4_nonfatal( 2 0 2
7119 aTHX_
7120 resolver_sv,
7121 source_sv,
7122 args_sv,
7123 s->context,
7124 return_type_sv ? return_type_sv : &PL_sv_undef,
7125 error_out
7126 );
7127 } else {
7128 984 args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
7129 984 SV *info_sv = gql_runtime_vm_new_lazy_info_for_path_sv(aTHX_ state_sv, s, path_frame);
7130  
7131 984 ▶ if (!return_type_sv && !gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!return_type_sv && !gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 984 984
if (!return_type_sv && !gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 0 0
7132 0 return_type_sv = gql_runtime_vm_state_current_return_type_sv(aTHX_ s, NULL, NULL);
7133 }
7134 984 ▶ if (!return_type_sv && gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!return_type_sv && gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 984 984
if (!return_type_sv && gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 0 0
7135 0 croak("native VM slot type object is missing for explicit generic callback");
7136 }
7137  
7138 984 ▶ resolved_sv = gql_runtime_vm_call_cb5_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
resolved_sv = gql_runtime_vm_call_cb5_nonfatal( 984 0 984
7139 aTHX_
7140 resolver_sv,
7141 source_sv,
7142 args_sv,
7143 s->context,
7144 info_sv,
7145 return_type_sv ? return_type_sv : &PL_sv_undef,
7146 error_out
7147 );
7148 984 SvREFCNT_dec(info_sv);
7149 }
7150  
7151 989 SvREFCNT_dec(args_sv);
7152 989 ▶ return resolved_sv ? resolved_sv : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return resolved_sv ? resolved_sv : newSVsv(&PL_sv_undef); 0 989 989
7153 }
7154  
7155 {
7156 326 CV *method_cv = gql_runtime_vm_default_method_cv(source_sv, field_name);
7157 326 ▶ if (method_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (method_cv) { 0 326 326
7158 0 SV *args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
7159 0 SV *info_sv = gql_runtime_vm_new_lazy_info_for_path_sv(aTHX_ state_sv, s, path_frame);
7160 0 resolved_sv = gql_runtime_vm_call_cb4_nonfatal(
7161 aTHX_ (SV *)method_cv, source_sv, args_sv, s->context, info_sv, error_out
7162 );
7163 0 SvREFCNT_dec(args_sv);
7164 0 SvREFCNT_dec(info_sv);
7165 0 ▶ return resolved_sv ? resolved_sv : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return resolved_sv ? resolved_sv : newSVsv(&PL_sv_undef); 0 0 0
7166 }
7167 }
7168  
7169 /* Default resolver: share the source hash value instead of copying it.
7170 * Scalar leaves are copied into the native tree immediately after (or
7171 * newSVsv'd by the scalar-fallback path), and hash/array refs are only
7172 * read as child sources, so no caller mutates the shared SV. Avoiding
7173 * the key-SV allocation and the value copy matters: this runs once per
7174 * field on the async lane. */
7175 PERL_UNUSED_VAR(field_name_sv);
7176 326 ▶ if (source_sv && SvOK(source_sv) && SvROK(source_sv) && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) {
Branch: 6 branches
BranchTrueFalseTotal
if (source_sv && SvOK(source_sv) && SvROK(source_sv) && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 326 0 326
if (source_sv && SvOK(source_sv) && SvROK(source_sv) && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 326 0 326
if (source_sv && SvOK(source_sv) && SvROK(source_sv) && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 326 0 326
if (source_sv && SvOK(source_sv) && SvROK(source_sv) && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 326 0 326
if (source_sv && SvOK(source_sv) && SvROK(source_sv) && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 326 0 326
if (source_sv && SvOK(source_sv) && SvROK(source_sv) && SvTYPE(SvRV(source_sv)) == SVt_PVHV && field_name && *field_name) { 326 0 326
7177 326 SV **valp = hv_fetch((HV *)SvRV(source_sv), field_name, (I32)strlen(field_name), 0);
7178 326 ▶ if (valp && *valp) {
Branch: 2 branches
BranchTrueFalseTotal
if (valp && *valp) { 314 12 326
if (valp && *valp) { 314 0 314
7179 314 ▶ if (gql_runtime_vm_is_callable_property_candidate(aTHX_ *valp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_callable_property_candidate(aTHX_ *valp)) { 0 314 314
7180 0 SV *args_sv = gql_runtime_vm_state_resolve_args_sv(aTHX_ state_sv);
7181 0 SV *info_sv = gql_runtime_vm_new_lazy_info_for_path_sv(aTHX_ state_sv, s, path_frame);
7182 0 resolved_sv = gql_runtime_vm_call_default_property_sv(
7183 aTHX_ *valp, args_sv, s->context, info_sv, error_out
7184 );
7185 0 SvREFCNT_dec(args_sv);
7186 0 SvREFCNT_dec(info_sv);
7187 0 ▶ return resolved_sv ? resolved_sv : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return resolved_sv ? resolved_sv : newSVsv(&PL_sv_undef); 0 0 0
7188 }
7189 314 return SvREFCNT_inc_simple_NN(*valp);
7190 }
7191 }
7192 12 resolved_sv = newSVsv(&PL_sv_undef);
7193 12 return resolved_sv;
7194 }
7195  
7196 static SV *
7197 3059 gql_runtime_vm_exec_state_complete_async_sv(
7198 pTHX_
7199 SV *state_sv,
7200 gql_runtime_vm_exec_state_handle_t *s,
7201 gql_runtime_vm_path_frame_t *path_ptr,
7202 IV block_index,
7203 IV slot_index,
7204 IV op_index,
7205 SV *resolved_sv,
7206 gql_runtime_vm_outcome_t **outcome_out
7207 )
7208 {
7209 const gql_runtime_vm_native_runtime_t *runtime;
7210 const gql_runtime_vm_native_block_t *block;
7211 const gql_runtime_vm_native_op_t *op;
7212 const gql_runtime_vm_native_slot_t *slot;
7213 3059 SV *result_sv = NULL;
7214  
7215 3059 ▶ if (!s || !s->native_program) {
Branch: 2 branches
BranchTrueFalseTotal
if (!s || !s->native_program) { 3059 0 3059
if (!s || !s->native_program) { 0 3059 3059
7216 0 return newSVsv(&PL_sv_undef);
7217 }
7218 3059 runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
7219 3059 ▶ if (block_index < 0 || block_index >= s->native_program->block_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (block_index < 0 || block_index >= s->native_program->block_count) { 3059 0 3059
if (block_index < 0 || block_index >= s->native_program->block_count) { 0 3059 3059
7220 0 return newSVsv(&PL_sv_undef);
7221 }
7222 3059 block = &s->native_program->blocks[block_index];
7223 3059 ▶ if (op_index < 0 || op_index >= block->op_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (op_index < 0 || op_index >= block->op_count) { 3059 0 3059
if (op_index < 0 || op_index >= block->op_count) { 0 3059 3059
7224 0 return newSVsv(&PL_sv_undef);
7225 }
7226 3059 op = &block->ops[op_index];
7227 3059 ▶ if (slot_index < 0 || slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot_index < 0 || slot_index >= block->slot_count) { 3059 0 3059
if (slot_index < 0 || slot_index >= block->slot_count) { 0 3059 3059
7228 0 return newSVsv(&PL_sv_undef);
7229 }
7230 3059 slot = gql_runtime_vm_effective_slot(runtime, &block->slots[slot_index]);
7231  
7232 3059 result_sv = gql_runtime_vm_exec_state_complete_current_native_async_sv(
7233 aTHX_ state_sv,
7234 s,
7235 path_ptr,
7236 op,
7237 slot,
7238 resolved_sv,
7239 outcome_out
7240 );
7241  
7242 3059 ▶ if (outcome_out && *outcome_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (outcome_out && *outcome_out) { 3059 0 3059
if (outcome_out && *outcome_out) { 3022 37 3059
7243 3022 return NULL;
7244 }
7245 37 ▶ return result_sv ? result_sv : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return result_sv ? result_sv : newSVsv(&PL_sv_undef); 0 37 37
7246 }
7247  
7248 static SV *
7249 55 gql_runtime_vm_then_complete_current_sv(
7250 pTHX_
7251 SV *state_sv,
7252 gql_runtime_vm_exec_state_handle_t *s,
7253 SV *promise_sv,
7254 gql_runtime_vm_path_frame_t *path_frame,
7255 IV block_index,
7256 IV slot_index,
7257 IV op_index
7258 )
7259 {
7260 55 const gql_runtime_vm_native_op_t *op =
7261 55 ▶ (s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
(s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL; 55 0 55
(s && s->cursor) ? gql_runtime_vm_cursor_current_native_op(s->cursor) : NULL; 55 0 55
7262 /* Program slot, not effective slot: pending entry keys carry the alias. */
7263 55 const gql_runtime_vm_native_slot_t *slot =
7264 55 ▶ (s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
(s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 55 0 55
(s && s->cursor) ? gql_runtime_vm_cursor_current_native_slot(s->cursor) : NULL; 55 0 55
7265 55 ▶ const char *result_name_pv = (slot && slot->result_name && *slot->result_name) ? slot->result_name : NULL;
Branch: 3 branches
BranchTrueFalseTotal
const char *result_name_pv = (slot && slot->result_name && *slot->result_name) ? slot->result_name : NULL; 55 0 55
const char *result_name_pv = (slot && slot->result_name && *slot->result_name) ? slot->result_name : NULL; 55 0 55
const char *result_name_pv = (slot && slot->result_name && *slot->result_name) ? slot->result_name : NULL; 55 0 55
7266 55 ▶ STRLEN result_name_len = result_name_pv ? (STRLEN)strlen(result_name_pv) : 0;
Branch: 1 branch
BranchTrueFalseTotal
STRLEN result_name_len = result_name_pv ? (STRLEN)strlen(result_name_pv) : 0; 55 0 55
7267 55 ▶ IV complete_code = op ? op->complete_code : GQL_VM_COMPLETE_GENERIC;
Branch: 1 branch
BranchTrueFalseTotal
IV complete_code = op ? op->complete_code : GQL_VM_COMPLETE_GENERIC; 55 0 55
7268 SV *callback_sv;
7269 SV *error_callback_sv;
7270 55 SV *ret = NULL;
7271  
7272 /* Direct subscription: park the user promise itself as the pending
7273 * entry; arm_frame then()s it once with the resolve/reject arms writing
7274 * straight into the entry. Skips one then(), one derived promise and
7275 * one error CV per user promise. */
7276 55 ▶ if (op && s && s->frame && result_name_pv && result_name_len > 0) {
Branch: 5 branches
BranchTrueFalseTotal
if (op && s && s->frame && result_name_pv && result_name_len > 0) { 55 0 55
if (op && s && s->frame && result_name_pv && result_name_len > 0) { 55 0 55
if (op && s && s->frame && result_name_pv && result_name_len > 0) { 55 0 55
if (op && s && s->frame && result_name_pv && result_name_len > 0) { 55 0 55
if (op && s && s->frame && result_name_pv && result_name_len > 0) { 55 0 55
7277 55 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
7278 aTHX_
7279 s->frame,
7280 result_name_pv,
7281 result_name_len,
7282 1,
7283 promise_sv,
7284 /* GENERIC_VALUE_SV stores the settled value without running
7285 * completion, so leaf-typed slots park as RESOLVED_VALUE_SV to get
7286 * result coercion at settle time. */
7287 complete_code == GQL_VM_COMPLETE_GENERIC
7288 54 ▶ && gql_runtime_vm_slot_leaf_kind(
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_slot_leaf_kind( 0 27 27
7289 27 gql_runtime_vm_exec_state_native_runtime(aTHX_ s),
7290 gql_runtime_vm_effective_slot(
7291 27 gql_runtime_vm_exec_state_native_runtime(aTHX_ s), slot
7292 )
7293 ) == GQL_VM_LEAF_NONE
7294 ? GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV
7295 : GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV,
7296 path_frame,
7297 block_index,
7298 slot_index,
7299 op_index,
7300 55 ▶ s->async_adapter
Branch: 1 branch
BranchTrueFalseTotal
s->async_adapter 27 28 55
7301 );
7302 55 return newSVsv(&PL_sv_undef);
7303 }
7304  
7305 0 callback_sv = gql_runtime_vm_identity_callback_sv(aTHX);
7306 0 error_callback_sv = gql_runtime_vm_new_error_callback_sv(aTHX_ path_frame);
7307  
7308 0 ret = gql_runtime_vm_call_then_promise_for_state_sv(
7309 aTHX_
7310 s,
7311 promise_sv,
7312 callback_sv,
7313 error_callback_sv,
7314 path_frame
7315 );
7316  
7317 0 ▶ if (callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (callback_sv) { 0 0 0
7318 0 SvREFCNT_dec(callback_sv);
7319 }
7320 0 ▶ if (error_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_callback_sv) { 0 0 0
7321 0 SvREFCNT_dec(error_callback_sv);
7322 }
7323  
7324 0 ▶ if (ret
Branch: 1 branch
BranchTrueFalseTotal
if (ret 0 0 0
7325 0 ▶ && SvOK(ret)
Branch: 1 branch
BranchTrueFalseTotal
&& SvOK(ret) 0 0 0
7326 0 ▶ && !gql_runtime_vm_sv_is_outcome(aTHX_ ret)
Branch: 1 branch
BranchTrueFalseTotal
&& !gql_runtime_vm_sv_is_outcome(aTHX_ ret) 0 0 0
7327 0 ▶ && !gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, ret)) {
Branch: 1 branch
BranchTrueFalseTotal
&& !gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, ret)) { 0 0 0
7328 SV *completed_sv;
7329  
7330 0 ▶ if (complete_code == GQL_VM_COMPLETE_GENERIC) {
Branch: 1 branch
BranchTrueFalseTotal
if (complete_code == GQL_VM_COMPLETE_GENERIC) { 0 0 0
7331 0 completed_sv = gql_runtime_vm_new_outcome_handle_sv(
7332 aTHX_
7333 GQL_VM_KIND_SCALAR,
7334 ret,
7335 &PL_sv_undef
7336 );
7337 } else {
7338 0 completed_sv = gql_runtime_vm_exec_state_complete_async_sv(
7339 aTHX_
7340 state_sv,
7341 s,
7342 path_frame,
7343 block_index,
7344 slot_index,
7345 op_index,
7346 ret,
7347 NULL
7348 );
7349 }
7350 0 SvREFCNT_dec(ret);
7351 0 ▶ return completed_sv ? completed_sv : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return completed_sv ? completed_sv : newSVsv(&PL_sv_undef); 0 0 0
7352 }
7353  
7354 0 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 0 0
7355 }
7356  
7357 static SV *
7358 1319 gql_runtime_vm_exec_state_execute_current_op_async_sv(
7359 pTHX_
7360 SV *state_sv,
7361 gql_runtime_vm_exec_state_handle_t *s,
7362 gql_runtime_vm_outcome_t **outcome_out
7363 )
7364 {
7365 1319 gql_runtime_vm_path_frame_t *path_frame = NULL;
7366 1319 SV *resolved_sv = NULL;
7367 1319 SV *error_sv = NULL;
7368 1319 SV *result_sv = NULL;
7369  
7370 1319 ▶ if (outcome_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out) { 1319 0 1319
7371 1319 *outcome_out = NULL;
7372 }
7373 1319 ▶ if (!s || !s->field_frame || !s->cursor) {
Branch: 3 branches
BranchTrueFalseTotal
if (!s || !s->field_frame || !s->cursor) { 1319 0 1319
if (!s || !s->field_frame || !s->cursor) { 1319 0 1319
if (!s || !s->field_frame || !s->cursor) { 0 1319 1319
7374 0 return newSVsv(&PL_sv_undef);
7375 }
7376  
7377 1319 path_frame = s->field_frame->path_frame;
7378 1319 resolved_sv = gql_runtime_vm_exec_state_resolve_current_value_sv(
7379 aTHX_
7380 state_sv,
7381 s,
7382 1319 s->field_frame->source,
7383 path_frame,
7384 &error_sv
7385 );
7386 1319 ▶ if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ resolved_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ resolved_sv)) { 26 1293 1319
7387 26 IV ticket_state = gql_runtime_vm_dataloader_ticket_state(aTHX_ resolved_sv);
7388 26 ▶ if (ticket_state == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ticket_state == 1) { 4 22 26
7389 4 SV *value_sv = newSVsv(
7390 gql_runtime_vm_dataloader_ticket_value(aTHX_ resolved_sv)
7391 );
7392 4 SvREFCNT_dec(resolved_sv);
7393 4 resolved_sv = value_sv;
7394 22 ▶ } else if (ticket_state == 2) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (ticket_state == 2) { 0 22 22
7395 0 error_sv = newSVsv(
7396 gql_runtime_vm_dataloader_ticket_value(aTHX_ resolved_sv)
7397 );
7398 0 SvREFCNT_dec(resolved_sv);
7399 0 resolved_sv = newSVsv(&PL_sv_undef);
7400 }
7401 }
7402 1319 ▶ if (error_sv && SvOK(error_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_sv && SvOK(error_sv)) { 5 1314 1319
if (error_sv && SvOK(error_sv)) { 5 0 5
7403 5 ▶ if (outcome_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out) { 5 0 5
7404 5 *outcome_out = gql_runtime_vm_new_error_outcome_struct_for_path(
7405 aTHX_
7406 error_sv,
7407 path_frame
7408 );
7409 } else {
7410 0 result_sv = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ error_sv, path_frame);
7411 }
7412 5 SvREFCNT_dec(error_sv);
7413 5 goto done_async_current_op;
7414 }
7415  
7416 1314 ▶ if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, resolved_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, resolved_sv)) { 55 1259 1314
7417 55 result_sv = gql_runtime_vm_then_complete_current_sv(
7418 aTHX_
7419 state_sv,
7420 s,
7421 resolved_sv,
7422 path_frame,
7423 55 s->cursor->block_index,
7424 55 s->cursor->slot_index,
7425 55 s->cursor->op_index
7426 );
7427 55 goto done_async_current_op;
7428 }
7429  
7430 1259 ▶ if (s->cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->cursor) { 1259 0 1259
7431 1259 const gql_runtime_vm_native_block_t *block = gql_runtime_vm_cursor_current_native_block(s->cursor);
7432 1259 const gql_runtime_vm_native_op_t *op = gql_runtime_vm_cursor_current_native_op(s->cursor);
7433 1259 ▶ if (block && op && (op->has_runtime_directives || op->runtime_directives_sv)) {
Branch: 4 branches
BranchTrueFalseTotal
if (block && op && (op->has_runtime_directives || op->runtime_directives_sv)) { 1259 0 1259
if (block && op && (op->has_runtime_directives || op->runtime_directives_sv)) { 1259 0 1259
if (block && op && (op->has_runtime_directives || op->runtime_directives_sv)) { 1257 2 1259
if (block && op && (op->has_runtime_directives || op->runtime_directives_sv)) { 0 1257 1257
7434 4 SV *applied_sv = gql_runtime_vm_apply_runtime_directives_nonfatal(
7435 aTHX_
7436 8 &(gql_runtime_vm_exec_state_t) {
7437 2 .runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s),
7438 2 ▶ .bundle = s->native_program ? gql_runtime_vm_native_program_cached_bundle(aTHX_ gql_runtime_vm_exec_state_native_runtime(aTHX_ s), s->native_program) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
.bundle = s->native_program ? gql_runtime_vm_native_program_cached_bundle(aTHX_ gql_runtime_vm_exec_state_native_runtime(aTHX_ s), s->native_program) : NULL, 2 0 2
7439 2 .callback_ctx = &(gql_runtime_vm_callback_context_t) {
7440 2 .runtime_schema = s->runtime_schema,
7441 2 .program = s->program,
7442 2 .context = s->context,
7443 2 .variables = s->variables,
7444 2 .root_value = s->root_value,
7445 },
7446 .path_frame = path_frame,
7447 2 .empty_args_sv = s->empty_args,
7448 2 .writer = s->writer,
7449 .block = block,
7450 .op = op,
7451 2 .slot = gql_runtime_vm_effective_slot(gql_runtime_vm_exec_state_native_runtime(aTHX_ s), gql_runtime_vm_cursor_current_native_slot(s->cursor)),
7452 2 .block_index = s->cursor->block_index,
7453 2 .op_index = s->cursor->op_index,
7454 },
7455 2 s->field_frame->source,
7456 resolved_sv,
7457 &error_sv
7458 );
7459 2 ▶ if (error_sv && SvOK(error_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_sv && SvOK(error_sv)) { 0 2 2
if (error_sv && SvOK(error_sv)) { 0 0 0
7460 0 SvREFCNT_dec(applied_sv);
7461 0 ▶ if (outcome_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out) { 0 0 0
7462 0 *outcome_out = gql_runtime_vm_new_error_outcome_struct_for_path(
7463 aTHX_
7464 error_sv,
7465 path_frame
7466 );
7467 } else {
7468 0 result_sv = gql_runtime_vm_new_error_outcome_for_path_sv(aTHX_ error_sv, path_frame);
7469 }
7470 0 SvREFCNT_dec(error_sv);
7471 0 goto done_async_current_op;
7472 }
7473 2 SvREFCNT_dec(resolved_sv);
7474 2 resolved_sv = applied_sv;
7475 }
7476 }
7477  
7478 1259 result_sv = gql_runtime_vm_exec_state_complete_async_sv(
7479 aTHX_
7480 state_sv,
7481 s,
7482 path_frame,
7483 1259 s->cursor->block_index,
7484 1259 s->cursor->slot_index,
7485 1259 s->cursor->op_index,
7486 resolved_sv,
7487 outcome_out
7488 );
7489 /* Fallback for completion paths that still hand back a wrapped outcome
7490 * handle SV despite outcome_out (e.g. error outcomes built deeper down). */
7491 1259 ▶ if (outcome_out
Branch: 1 branch
BranchTrueFalseTotal
if (outcome_out 0 1259 1259
7492 1259 ▶ && !*outcome_out
Branch: 1 branch
BranchTrueFalseTotal
&& !*outcome_out 1235 24 1259
7493 24 ▶ && result_sv
Branch: 1 branch
BranchTrueFalseTotal
&& result_sv 0 24 24
7494 24 ▶ && SvOK(result_sv)
Branch: 1 branch
BranchTrueFalseTotal
&& SvOK(result_sv) 0 24 24
7495 24 ▶ && gql_runtime_vm_sv_is_outcome(aTHX_ result_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_sv_is_outcome(aTHX_ result_sv)) { 24 0 24
7496 0 *outcome_out = gql_runtime_vm_expect_outcome(aTHX_ result_sv);
7497 0 gql_runtime_vm_outcome_incref(*outcome_out);
7498 0 SvREFCNT_dec(result_sv);
7499 0 result_sv = NULL;
7500 }
7501  
7502 1259 done_async_current_op:
7503 1319 ▶ if (resolved_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolved_sv) { 1319 0 1319
7504 1319 SvREFCNT_dec(resolved_sv);
7505 }
7506 1319 ▶ if (outcome_out && *outcome_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (outcome_out && *outcome_out) { 1319 0 1319
if (outcome_out && *outcome_out) { 1240 79 1319
7507 /* The outcome struct is the result; no SV (not even undef) to return,
7508 * so the callers' loops skip a per-field SV allocation. */
7509 1240 ▶ if (result_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (result_sv) { 0 1240 1240
7510 0 SvREFCNT_dec(result_sv);
7511 }
7512 1240 return NULL;
7513 }
7514 79 ▶ return result_sv ? result_sv : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return result_sv ? result_sv : newSVsv(&PL_sv_undef); 0 79 79
7515 }
7516  
7517 static HV *
7518 309 gql_runtime_vm_fetch_runtime_cache_hv(pTHX_ SV *runtime_schema)
7519 {
7520 HV *schema_hv;
7521 SV *runtime_cache_sv;
7522  
7523 309 schema_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_schema, "runtime schema");
7524 309 runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "runtime_cache", 13);
7525 return runtime_cache_sv
7526 309 ? gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime schema runtime_cache")
7527 618 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 309 0 309
7528 }
7529  
7530 static SV *
7531 242 gql_runtime_vm_runtime_schema_exec_struct_sv(pTHX_ SV *runtime_schema)
7532 {
7533 HV *schema_hv;
7534 SV *catalog_sv;
7535 SV *exec_struct_sv;
7536 242 dSP;
7537  
7538 242 schema_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_schema, "runtime schema");
7539 242 catalog_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "slot_catalog_exec", 17);
7540 242 ▶ if (catalog_sv && SvOK(catalog_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog_sv && SvOK(catalog_sv)) { 242 0 242
if (catalog_sv && SvOK(catalog_sv)) { 242 0 242
7541 242 return NULL;
7542 }
7543  
7544 0 ENTER;
7545 0 SAVETMPS;
7546 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
7547 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
7548 0 ▶ XPUSHs(runtime_schema ? runtime_schema : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(runtime_schema ? runtime_schema : &PL_sv_undef); 0 0 0
XPUSHs(runtime_schema ? runtime_schema : &PL_sv_undef); 0 0 0
7549 0 PUTBACK;
7550 0 ▶ if (call_method("to_native_exec_struct", G_SCALAR | G_EVAL) != 1 || SvTRUE(ERRSV)) {
Branch: 3 branches
BranchTrueFalseTotal
if (call_method("to_native_exec_struct", G_SCALAR | G_EVAL) != 1 || SvTRUE(ERRSV)) { 0 0 0
if (call_method("to_native_exec_struct", G_SCALAR | G_EVAL) != 1 || SvTRUE(ERRSV)) { 0 0 0
if (call_method("to_native_exec_struct", G_SCALAR | G_EVAL) != 1 || SvTRUE(ERRSV)) { 0 0 0
7551 0 (void)POPs;
7552 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
7553 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
7554 0 LEAVE;
7555 0 return NULL;
7556 }
7557 0 SPAGAIN;
7558 0 ▶ exec_struct_sv = (SP > PL_stack_base) ? POPs : NULL;
Branch: 1 branch
BranchTrueFalseTotal
exec_struct_sv = (SP > PL_stack_base) ? POPs : NULL; 0 0 0
7559 0 ▶ exec_struct_sv = exec_struct_sv ? newSVsv(exec_struct_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
exec_struct_sv = exec_struct_sv ? newSVsv(exec_struct_sv) : NULL; 0 0 0
7560 0 PUTBACK;
7561 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
7562 0 LEAVE;
7563 0 return exec_struct_sv;
7564 }
7565  
7566 static const char *
7567 gql_runtime_vm_type_name_from_sv(pTHX_ SV *type_sv);
7568  
7569 static char *
7570 20 gql_runtime_vm_copy_loader_name_sv(pTHX_ SV *name_sv, STRLEN *len_out)
7571 {
7572 20 STRLEN len = 0;
7573 const char *pv;
7574 char *copy;
7575 20 ▶ if (!name_sv || !SvOK(name_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!name_sv || !SvOK(name_sv)) { 20 0 20
if (!name_sv || !SvOK(name_sv)) { 0 20 20
7576 0 return NULL;
7577 }
7578 20 pv = SvPV(name_sv, len);
7579 20 copy = savepvn(pv, len);
7580 20 ▶ if (len_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (len_out) { 20 0 20
7581 20 *len_out = len;
7582 }
7583 20 return copy;
7584 }
7585  
7586 static void
7587 11 gql_runtime_vm_compile_loader_key_spec(
7588 pTHX_
7589 HV *key_hv,
7590 U8 *kind_out,
7591 char **name_out,
7592 STRLEN *name_len_out
7593 )
7594 {
7595 11 SV *source_key_sv = gql_runtime_vm_fetch_hash_entry_sv(
7596 aTHX_ key_hv, "source_key", 10
7597 );
7598 11 SV *argument_sv = gql_runtime_vm_fetch_hash_entry_sv(
7599 aTHX_ key_hv, "argument", 8
7600 );
7601 11 ▶ if (source_key_sv && SvOK(source_key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (source_key_sv && SvOK(source_key_sv)) { 6 5 11
if (source_key_sv && SvOK(source_key_sv)) { 6 0 6
7602 6 *kind_out = 1;
7603 6 *name_out = gql_runtime_vm_copy_loader_name_sv(
7604 aTHX_ source_key_sv, name_len_out
7605 );
7606 5 ▶ } else if (argument_sv && SvOK(argument_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (argument_sv && SvOK(argument_sv)) { 5 0 5
} else if (argument_sv && SvOK(argument_sv)) { 5 0 5
7607 5 *kind_out = 2;
7608 5 *name_out = gql_runtime_vm_copy_loader_name_sv(
7609 aTHX_ argument_sv, name_len_out
7610 );
7611 }
7612 11 }
7613  
7614 static gql_runtime_vm_native_loader_spec_t *
7615 9 gql_runtime_vm_compile_loader_spec(pTHX_ SV *loader_spec_sv)
7616 {
7617 HV *spec_hv;
7618 SV *context_key_sv;
7619 SV *router_sv;
7620 SV *key_sv;
7621 gql_runtime_vm_native_loader_spec_t *compiled;
7622  
7623 9 ▶ if (!loader_spec_sv || !SvOK(loader_spec_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!loader_spec_sv || !SvOK(loader_spec_sv)) { 9 0 9
if (!loader_spec_sv || !SvOK(loader_spec_sv)) { 0 9 9
7624 0 return NULL;
7625 }
7626 9 spec_hv = gql_runtime_vm_expect_hashref(
7627 aTHX_ loader_spec_sv, "declarative loader specification"
7628 );
7629 9 context_key_sv = gql_runtime_vm_fetch_hash_entry_sv(
7630 aTHX_ spec_hv, "context_key", 11
7631 );
7632 9 router_sv = gql_runtime_vm_fetch_hash_entry_sv(
7633 aTHX_ spec_hv, "router", 6
7634 );
7635 9 key_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ spec_hv, "key", 3);
7636  
7637 9 Newxz(compiled, 1, gql_runtime_vm_native_loader_spec_t);
7638 9 compiled->key_arg_index = -1;
7639 9 compiled->route_key_arg_index = -1;
7640 9 ▶ if (context_key_sv && SvOK(context_key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (context_key_sv && SvOK(context_key_sv)) { 7 2 9
if (context_key_sv && SvOK(context_key_sv)) { 7 0 7
7641 7 compiled->context_key = gql_runtime_vm_copy_loader_name_sv(
7642 aTHX_ context_key_sv, &compiled->context_key_len
7643 );
7644 2 ▶ } else if (router_sv && SvOK(router_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (router_sv && SvOK(router_sv)) { 2 0 2
} else if (router_sv && SvOK(router_sv)) { 2 0 2
7645 2 HV *router_hv = gql_runtime_vm_expect_hashref(
7646 aTHX_ router_sv, "declarative loader router specification"
7647 );
7648 2 SV *router_context_key_sv = gql_runtime_vm_fetch_hash_entry_sv(
7649 aTHX_ router_hv, "context_key", 11
7650 );
7651 2 SV *route_key_sv = gql_runtime_vm_fetch_hash_entry_sv(
7652 aTHX_ router_hv, "route_key", 9
7653 );
7654 2 compiled->uses_router = 1;
7655 2 compiled->context_key = gql_runtime_vm_copy_loader_name_sv(
7656 aTHX_ router_context_key_sv, &compiled->context_key_len
7657 );
7658 2 ▶ if (route_key_sv && SvOK(route_key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (route_key_sv && SvOK(route_key_sv)) { 2 0 2
if (route_key_sv && SvOK(route_key_sv)) { 2 0 2
7659 2 gql_runtime_vm_compile_loader_key_spec(
7660 aTHX_
7661 gql_runtime_vm_expect_hashref(
7662 aTHX_ route_key_sv, "declarative loader route key"
7663 ),
7664 &compiled->route_key_kind,
7665 &compiled->route_key_name,
7666 &compiled->route_key_name_len
7667 );
7668 }
7669 }
7670 9 ▶ if (key_sv && SvOK(key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (key_sv && SvOK(key_sv)) { 9 0 9
if (key_sv && SvOK(key_sv)) { 9 0 9
7671 9 gql_runtime_vm_compile_loader_key_spec(
7672 aTHX_
7673 gql_runtime_vm_expect_hashref(
7674 aTHX_ key_sv, "declarative loader key"
7675 ),
7676 &compiled->key_kind,
7677 &compiled->key_name,
7678 &compiled->key_name_len
7679 );
7680 }
7681 9 return compiled;
7682 }
7683  
7684 static IV
7685 3 gql_runtime_vm_find_loader_arg_index(
7686 const gql_runtime_vm_native_slot_t *slot,
7687 const char *name,
7688 STRLEN name_len
7689 )
7690 {
7691 IV i;
7692 3 ▶ if (!slot || !name) {
Branch: 2 branches
BranchTrueFalseTotal
if (!slot || !name) { 3 0 3
if (!slot || !name) { 0 3 3
7693 0 return -1;
7694 }
7695 3 ▶ for (i = 0; i < slot->arg_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < slot->arg_def_count; i++) { 3 0 3
7696 3 const char *arg_name = slot->arg_defs[i].name;
7697 3 ▶ if (arg_name
Branch: 1 branch
BranchTrueFalseTotal
if (arg_name 3 0 3
7698 3 ▶ && strlen(arg_name) == name_len
Branch: 1 branch
BranchTrueFalseTotal
&& strlen(arg_name) == name_len 3 0 3
7699 3 ▶ && memEQ(arg_name, name, name_len)) {
Branch: 1 branch
BranchTrueFalseTotal
&& memEQ(arg_name, name, name_len)) { 3 0 3
7700 3 return i;
7701 }
7702 }
7703 0 return -1;
7704 }
7705  
7706 static gql_runtime_vm_native_runtime_t *
7707 242 gql_runtime_vm_native_runtime_from_runtime_schema_sv(pTHX_ SV *runtime_schema)
7708 {
7709 gql_runtime_vm_native_runtime_t *runtime;
7710 HV *schema_hv;
7711 SV *exec_struct_sv;
7712 SV *catalog_sv;
7713 SV *resolver_catalog_sv;
7714 SV *loader_spec_catalog_sv;
7715 AV *catalog_av;
7716 AV *resolver_catalog_av;
7717 AV *loader_spec_catalog_av;
7718 SV *runtime_cache_sv;
7719 IV i;
7720  
7721 242 exec_struct_sv = gql_runtime_vm_runtime_schema_exec_struct_sv(aTHX_ runtime_schema);
7722 242 schema_hv = exec_struct_sv
7723 0 ? gql_runtime_vm_expect_hashref(aTHX_ exec_struct_sv, "runtime exec schema")
7724 242 ▶ : gql_runtime_vm_expect_hashref(aTHX_ runtime_schema, "runtime schema");
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_expect_hashref(aTHX_ runtime_schema, "runtime schema"); 0 242 242
7725 242 catalog_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "slot_catalog_exec", 17);
7726 242 ▶ if (!catalog_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!catalog_sv) { 0 242 242
7727 0 catalog_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "slot_catalog", 12);
7728 }
7729 242 ▶ if (!catalog_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!catalog_sv) { 0 242 242
7730 0 ▶ if (exec_struct_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (exec_struct_sv) { 0 0 0
7731 0 SvREFCNT_dec(exec_struct_sv);
7732 }
7733 0 croak("runtime schema is missing slot_catalog");
7734 }
7735 242 catalog_av = gql_runtime_vm_expect_arrayref(aTHX_ catalog_sv, "runtime schema slot_catalog");
7736 242 resolver_catalog_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "slot_resolvers", 14);
7737 242 ▶ resolver_catalog_av = (resolver_catalog_sv && SvOK(resolver_catalog_sv))
Branch: 1 branch
BranchTrueFalseTotal
resolver_catalog_av = (resolver_catalog_sv && SvOK(resolver_catalog_sv)) 242 0 242
7738 242 ? gql_runtime_vm_expect_arrayref(aTHX_ resolver_catalog_sv, "runtime schema slot_resolvers")
7739 242 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 242 0 242
7740 242 loader_spec_catalog_sv = gql_runtime_vm_fetch_hash_entry_sv(
7741 aTHX_ schema_hv, "slot_loader_specs", 17
7742 );
7743 242 ▶ loader_spec_catalog_av = (loader_spec_catalog_sv && SvOK(loader_spec_catalog_sv))
Branch: 1 branch
BranchTrueFalseTotal
loader_spec_catalog_av = (loader_spec_catalog_sv && SvOK(loader_spec_catalog_sv)) 242 0 242
7744 242 ? gql_runtime_vm_expect_arrayref(
7745 aTHX_ loader_spec_catalog_sv, "runtime schema slot_loader_specs"
7746 )
7747 242 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 242 0 242
7748  
7749 242 Newxz(runtime, 1, gql_runtime_vm_native_runtime_t);
7750 242 runtime->async_adapter = &gql_runtime_vm_promise_xs_adapter;
7751 242 Newxz(runtime->callback_catalog, 1, gql_runtime_vm_native_callback_catalog_t);
7752 242 ▶ runtime->callback_catalog->runtime_schema = newSVsv(runtime_schema ? runtime_schema : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
runtime->callback_catalog->runtime_schema = newSVsv(runtime_schema ? runtime_schema : &PL_sv_undef); 242 0 242
7753 242 runtime->runtime_slot_count = av_count(catalog_av);
7754 242 ▶ if (runtime->runtime_slot_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime->runtime_slot_count > 0) { 242 0 242
7755 242 ▶ Newxz(runtime->runtime_slots, runtime->runtime_slot_count, gql_runtime_vm_native_slot_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->runtime_slots, runtime->runtime_slot_count, gql_runtime_vm_native_slot_t); 0 242 242
7756 242 ▶ Newxz(runtime->callback_catalog->slot_field_names, runtime->runtime_slot_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_field_names, runtime->runtime_slot_count, SV *); 0 242 242
7757 242 ▶ Newxz(runtime->callback_catalog->slot_resolvers, runtime->runtime_slot_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_resolvers, runtime->runtime_slot_count, SV *); 0 242 242
7758 242 ▶ Newxz(runtime->callback_catalog->slot_loader_specs, runtime->runtime_slot_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_loader_specs, runtime->runtime_slot_count, SV *); 0 242 242
7759 242 ▶ Newxz(runtime->callback_catalog->slot_native_loader_specs, runtime->runtime_slot_count, gql_runtime_vm_native_loader_spec_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_native_loader_specs, runtime->runtime_slot_count, gql_runtime_vm_native_loader_spec_t *); 0 242 242
7760 242 ▶ Newxz(runtime->callback_catalog->slot_type_objects, runtime->runtime_slot_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_type_objects, runtime->runtime_slot_count, SV *); 0 242 242
7761 242 ▶ Newxz(runtime->callback_catalog->slot_tag_resolvers, runtime->runtime_slot_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_tag_resolvers, runtime->runtime_slot_count, SV *); 0 242 242
7762 242 ▶ Newxz(runtime->callback_catalog->slot_resolve_types, runtime->runtime_slot_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_resolve_types, runtime->runtime_slot_count, SV *); 0 242 242
7763 242 ▶ Newxz(runtime->callback_catalog->slot_tag_entries, runtime->runtime_slot_count, gql_runtime_vm_native_tag_entry_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_tag_entries, runtime->runtime_slot_count, gql_runtime_vm_native_tag_entry_t *); 0 242 242
7764 242 ▶ Newxz(runtime->callback_catalog->slot_tag_entry_counts, runtime->runtime_slot_count, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_tag_entry_counts, runtime->runtime_slot_count, IV); 0 242 242
7765 242 ▶ Newxz(runtime->callback_catalog->slot_possible_type_entries, runtime->runtime_slot_count, gql_runtime_vm_native_possible_type_entry_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_possible_type_entries, runtime->runtime_slot_count, gql_runtime_vm_native_possible_type_entry_t *); 0 242 242
7766 242 ▶ Newxz(runtime->callback_catalog->slot_possible_type_entry_counts, runtime->runtime_slot_count, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_possible_type_entry_counts, runtime->runtime_slot_count, IV); 0 242 242
7767 242 ▶ Newxz(runtime->callback_catalog->slot_leaf_kinds, runtime->runtime_slot_count, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_leaf_kinds, runtime->runtime_slot_count, IV); 0 242 242
7768 242 ▶ Newxz(runtime->callback_catalog->slot_leaf_payloads, runtime->runtime_slot_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_leaf_payloads, runtime->runtime_slot_count, SV *); 0 242 242
7769 13344 ▶ for (i = 0; i < runtime->runtime_slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < runtime->runtime_slot_count; i++) { 13102 242 13344
7770 13102 SV **slot_svp = av_fetch(catalog_av, i, 0);
7771 HV *slot_hv;
7772 SV *resolver_sv;
7773 13102 ▶ if (!slot_svp || !SvOK(*slot_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!slot_svp || !SvOK(*slot_svp)) { 13102 0 13102
if (!slot_svp || !SvOK(*slot_svp)) { 0 13102 13102
7774 0 ▶ if (exec_struct_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (exec_struct_sv) { 0 0 0
7775 0 SvREFCNT_dec(exec_struct_sv);
7776 }
7777 0 gql_runtime_vm_native_runtime_destroy(runtime);
7778 0 croak("runtime schema slot_catalog entry %ld is missing", (long)i);
7779 }
7780 13102 ▶ if (!gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &runtime->runtime_slots[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &runtime->runtime_slots[i])) { 0 13102 13102
7781 0 ▶ if (exec_struct_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (exec_struct_sv) { 0 0 0
7782 0 SvREFCNT_dec(exec_struct_sv);
7783 }
7784 0 gql_runtime_vm_native_runtime_destroy(runtime);
7785 0 croak("runtime schema slot_catalog entry %ld is invalid", (long)i);
7786 }
7787 13102 slot_hv = gql_runtime_vm_expect_hashref(aTHX_ *slot_svp, "runtime slot");
7788 13102 resolver_sv = NULL;
7789 13102 ▶ if (resolver_catalog_av && i <= (IV)av_count(resolver_catalog_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (resolver_catalog_av && i <= (IV)av_count(resolver_catalog_av)) { 13102 0 13102
if (resolver_catalog_av && i <= (IV)av_count(resolver_catalog_av)) { 13102 0 13102
7790 13102 SV **resolver_svp = av_fetch(resolver_catalog_av, i, 0);
7791 13102 ▶ if (resolver_svp && SvOK(*resolver_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (resolver_svp && SvOK(*resolver_svp)) { 13102 0 13102
if (resolver_svp && SvOK(*resolver_svp)) { 8534 4568 13102
7792 8534 resolver_sv = *resolver_svp;
7793 }
7794 }
7795 13102 ▶ if (!resolver_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!resolver_sv) { 4568 8534 13102
7796 4568 resolver_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ slot_hv, "resolve", 7);
7797 }
7798 13102 ▶ if (resolver_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolver_sv) { 8534 4568 13102
7799 8534 runtime->callback_catalog->slot_resolvers[i] = newSVsv(resolver_sv);
7800 }
7801 13102 ▶ if (loader_spec_catalog_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (loader_spec_catalog_av) { 13102 0 13102
7802 13102 SV **loader_spec_svp = av_fetch(loader_spec_catalog_av, i, 0);
7803 13102 ▶ if (loader_spec_svp && SvOK(*loader_spec_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (loader_spec_svp && SvOK(*loader_spec_svp)) { 13102 0 13102
if (loader_spec_svp && SvOK(*loader_spec_svp)) { 9 13093 13102
7804 18 runtime->callback_catalog->slot_loader_specs[i] =
7805 9 newSVsv(*loader_spec_svp);
7806 18 runtime->callback_catalog->slot_native_loader_specs[i] =
7807 9 gql_runtime_vm_compile_loader_spec(aTHX_ *loader_spec_svp);
7808 9 ▶ if (runtime->callback_catalog->slot_native_loader_specs[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime->callback_catalog->slot_native_loader_specs[i]) { 9 0 9
7809 9 gql_runtime_vm_native_loader_spec_t *native_loader =
7810 9 runtime->callback_catalog->slot_native_loader_specs[i];
7811 /* Direct materialization deliberately stays on the one-argument
7812 * shape. With multiple definitions, CoerceArgumentValues must
7813 * still visit every argument (including custom scalars and
7814 * missing Non-Null values), even when the loader only consumes
7815 * one of them. That shape retains the full args-HV path. */
7816 9 ▶ if (native_loader->key_kind == 2
Branch: 1 branch
BranchTrueFalseTotal
if (native_loader->key_kind == 2 4 5 9
7817 4 ▶ && runtime->runtime_slots[i].arg_def_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
&& runtime->runtime_slots[i].arg_def_count == 1) { 3 1 4
7818 3 native_loader->key_arg_index = gql_runtime_vm_find_loader_arg_index(
7819 3 &runtime->runtime_slots[i],
7820 3 native_loader->key_name,
7821 native_loader->key_name_len
7822 );
7823 }
7824 9 ▶ if (native_loader->route_key_kind == 2
Branch: 1 branch
BranchTrueFalseTotal
if (native_loader->route_key_kind == 2 1 8 9
7825 1 ▶ && runtime->runtime_slots[i].arg_def_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
&& runtime->runtime_slots[i].arg_def_count == 1) { 0 1 1
7826 0 native_loader->route_key_arg_index = gql_runtime_vm_find_loader_arg_index(
7827 0 &runtime->runtime_slots[i],
7828 0 native_loader->route_key_name,
7829 native_loader->route_key_name_len
7830 );
7831 }
7832 }
7833 }
7834 }
7835 13102 ▶ if (runtime->runtime_slots[i].field_name && *runtime->runtime_slots[i].field_name) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime->runtime_slots[i].field_name && *runtime->runtime_slots[i].field_name) { 13102 0 13102
if (runtime->runtime_slots[i].field_name && *runtime->runtime_slots[i].field_name) { 13102 0 13102
7836 13102 runtime->callback_catalog->slot_field_names[i] = newSVpv(runtime->runtime_slots[i].field_name, 0);
7837 }
7838 }
7839 }
7840  
7841 242 runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "runtime_cache", 13);
7842 242 ▶ if (runtime_cache_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_cache_sv) { 242 0 242
7843 242 HV *runtime_cache_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime schema runtime_cache");
7844 242 HV *name2type_hv = NULL;
7845 242 HV *tag_resolver_map_hv = NULL;
7846 242 HV *runtime_tag_map_hv = NULL;
7847 242 HV *resolve_type_map_hv = NULL;
7848 242 HV *possible_types_hv = NULL;
7849 242 HV *is_type_of_map_hv = NULL;
7850 242 HV *leaf_kind_map_hv = NULL;
7851 242 HV *enum_values_map_hv = NULL;
7852 242 HV *serialize_map_hv = NULL;
7853  
7854 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "name2type", 9))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "name2type", 9))) { 242 0 242
7855 242 name2type_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache name2type");
7856 }
7857 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "tag_resolver_map", 16))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "tag_resolver_map", 16))) { 242 0 242
7858 242 tag_resolver_map_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache tag_resolver_map");
7859 }
7860 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "runtime_tag_map", 15))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "runtime_tag_map", 15))) { 242 0 242
7861 242 runtime_tag_map_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache runtime_tag_map");
7862 }
7863 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "resolve_type_map", 16))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "resolve_type_map", 16))) { 242 0 242
7864 242 resolve_type_map_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache resolve_type_map");
7865 }
7866 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "possible_types", 14))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "possible_types", 14))) { 242 0 242
7867 242 possible_types_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache possible_types");
7868 }
7869 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "is_type_of_map", 14))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "is_type_of_map", 14))) { 242 0 242
7870 242 is_type_of_map_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache is_type_of_map");
7871 }
7872 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "leaf_kind_map", 13))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "leaf_kind_map", 13))) { 242 0 242
7873 242 leaf_kind_map_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache leaf_kind_map");
7874 }
7875 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "enum_values_map", 15))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "enum_values_map", 15))) { 242 0 242
7876 242 enum_values_map_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache enum_values_map");
7877 }
7878 242 ▶ if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "serialize_map", 13))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "serialize_map", 13))) { 242 0 242
7879 242 serialize_map_hv = gql_runtime_vm_expect_hashref(aTHX_ runtime_cache_sv, "runtime_cache serialize_map");
7880 }
7881  
7882 242 ▶ if (runtime->runtime_slot_count > 0 && name2type_hv) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime->runtime_slot_count > 0 && name2type_hv) { 242 0 242
if (runtime->runtime_slot_count > 0 && name2type_hv) { 242 0 242
7883 13344 ▶ for (i = 0; i < runtime->runtime_slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < runtime->runtime_slot_count; i++) { 13102 242 13344
7884 13102 const char *return_type_name = runtime->runtime_slots[i].return_type_name;
7885 13102 gql_runtime_vm_native_slot_t *slot = &runtime->runtime_slots[i];
7886 IV arg_index;
7887 SV **type_svp;
7888 13102 ▶ if (!return_type_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!return_type_name) { 0 13102 13102
7889 0 goto finalize_arg_defs;
7890 }
7891 13102 type_svp = hv_fetch(name2type_hv, return_type_name, (I32)strlen(return_type_name), 0);
7892 13102 ▶ if (type_svp && SvOK(*type_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (type_svp && SvOK(*type_svp)) { 13102 0 13102
if (type_svp && SvOK(*type_svp)) { 13102 0 13102
7893 13102 runtime->callback_catalog->slot_type_objects[i] = newSVsv(*type_svp);
7894 }
7895 13102 ▶ if (tag_resolver_map_hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_resolver_map_hv) { 13102 0 13102
7896 13102 SV **svp = hv_fetch(tag_resolver_map_hv, return_type_name, (I32)strlen(return_type_name), 0);
7897 13102 ▶ if (svp && SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) { 28 13074 13102
if (svp && SvOK(*svp)) { 28 0 28
7898 28 runtime->callback_catalog->slot_tag_resolvers[i] = newSVsv(*svp);
7899 }
7900 }
7901 13102 ▶ if (leaf_kind_map_hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_kind_map_hv) { 13102 0 13102
7902 13102 SV **svp = hv_fetch(leaf_kind_map_hv, return_type_name, (I32)strlen(return_type_name), 0);
7903 13102 ▶ if (svp && SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) { 8471 4631 13102
if (svp && SvOK(*svp)) { 8471 0 8471
7904 8471 IV leaf_kind = SvIV(*svp);
7905 8471 runtime->callback_catalog->slot_leaf_kinds[i] = leaf_kind;
7906 8974 ▶ if (leaf_kind == GQL_VM_LEAF_ENUM && enum_values_map_hv) {
Branch: 2 branches
BranchTrueFalseTotal
if (leaf_kind == GQL_VM_LEAF_ENUM && enum_values_map_hv) { 503 7968 8471
if (leaf_kind == GQL_VM_LEAF_ENUM && enum_values_map_hv) { 503 0 503
7907 503 SV **payload_svp = hv_fetch(enum_values_map_hv, return_type_name, (I32)strlen(return_type_name), 0);
7908 503 ▶ if (payload_svp && SvOK(*payload_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (payload_svp && SvOK(*payload_svp)) { 503 0 503
if (payload_svp && SvOK(*payload_svp)) { 503 0 503
7909 503 runtime->callback_catalog->slot_leaf_payloads[i] = newSVsv(*payload_svp);
7910 }
7911 7968 ▶ } else if (leaf_kind == GQL_VM_LEAF_CUSTOM && serialize_map_hv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (leaf_kind == GQL_VM_LEAF_CUSTOM && serialize_map_hv) { 15 7953 7968
} else if (leaf_kind == GQL_VM_LEAF_CUSTOM && serialize_map_hv) { 15 0 15
7912 15 SV **payload_svp = hv_fetch(serialize_map_hv, return_type_name, (I32)strlen(return_type_name), 0);
7913 15 ▶ if (payload_svp && SvOK(*payload_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (payload_svp && SvOK(*payload_svp)) { 15 0 15
if (payload_svp && SvOK(*payload_svp)) { 15 0 15
7914 15 runtime->callback_catalog->slot_leaf_payloads[i] = newSVsv(*payload_svp);
7915 }
7916 }
7917 }
7918 }
7919 13102 ▶ if (runtime_tag_map_hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_tag_map_hv) { 13102 0 13102
7920 13102 SV **svp = hv_fetch(runtime_tag_map_hv, return_type_name, (I32)strlen(return_type_name), 0);
7921 13102 ▶ if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 28 13074 13102
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 28 0 28
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 28 0 28
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 28 0 28
7922 28 HV *tag_map_hv = (HV *)SvRV(*svp);
7923 28 IV count = hv_iterinit(tag_map_hv);
7924 28 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 28 0 28
7925 HE *he;
7926 28 IV j = 0;
7927 28 ▶ Newxz(runtime->callback_catalog->slot_tag_entries[i], count, gql_runtime_vm_native_tag_entry_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_tag_entries[i], count, gql_runtime_vm_native_tag_entry_t); 0 28 28
7928 28 runtime->callback_catalog->slot_tag_entry_counts[i] = count;
7929 28 hv_iterinit(tag_map_hv);
7930 77 ▶ while ((he = hv_iternext(tag_map_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(tag_map_hv))) { 49 28 77
7931 49 SV *val = HeVAL(he);
7932 49 const char *tag_name = HeKEY(he);
7933 49 ▶ const char *type_name = (val && SvOK(val)) ? gql_runtime_vm_type_name_from_sv(aTHX_ val) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
const char *type_name = (val && SvOK(val)) ? gql_runtime_vm_type_name_from_sv(aTHX_ val) : NULL; 49 0 49
const char *type_name = (val && SvOK(val)) ? gql_runtime_vm_type_name_from_sv(aTHX_ val) : NULL; 49 0 49
7934 49 runtime->callback_catalog->slot_tag_entries[i][j].tag_name = gql_runtime_vm_copy_cstr(tag_name);
7935 49 runtime->callback_catalog->slot_tag_entries[i][j].type_name = gql_runtime_vm_copy_cstr(type_name);
7936 49 j++;
7937 }
7938 }
7939 }
7940 }
7941 13102 ▶ if (resolve_type_map_hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolve_type_map_hv) { 13102 0 13102
7942 13102 SV **svp = hv_fetch(resolve_type_map_hv, return_type_name, (I32)strlen(return_type_name), 0);
7943 13102 ▶ if (svp && SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) { 9 13093 13102
if (svp && SvOK(*svp)) { 9 0 9
7944 9 runtime->callback_catalog->slot_resolve_types[i] = newSVsv(*svp);
7945 }
7946 }
7947 13102 ▶ if (possible_types_hv && is_type_of_map_hv) {
Branch: 2 branches
BranchTrueFalseTotal
if (possible_types_hv && is_type_of_map_hv) { 0 13102 13102
if (possible_types_hv && is_type_of_map_hv) { 0 13102 13102
7948 13102 SV **svp = hv_fetch(possible_types_hv, return_type_name, (I32)strlen(return_type_name), 0);
7949 13102 ▶ if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) { 13064 38 13102
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) { 0 38 38
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) { 0 38 38
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVAV) { 0 38 38
7950 38 AV *possible_types_av = (AV *)SvRV(*svp);
7951 38 IV count = av_count(possible_types_av);
7952 38 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 0 38 38
7953 IV j;
7954 38 ▶ Newxz(runtime->callback_catalog->slot_possible_type_entries[i], count, gql_runtime_vm_native_possible_type_entry_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(runtime->callback_catalog->slot_possible_type_entries[i], count, gql_runtime_vm_native_possible_type_entry_t); 0 38 38
7955 38 runtime->callback_catalog->slot_possible_type_entry_counts[i] = count;
7956 101 ▶ for (j = 0; j < count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < count; j++) { 63 38 101
7957 63 SV **type_entry_svp = av_fetch(possible_types_av, j, 0);
7958 SV *type_sv;
7959 const char *type_name;
7960 SV **cb_svp;
7961 63 ▶ if (!type_entry_svp || !SvOK(*type_entry_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!type_entry_svp || !SvOK(*type_entry_svp)) { 63 0 63
if (!type_entry_svp || !SvOK(*type_entry_svp)) { 0 63 63
7962 0 continue;
7963 }
7964 63 type_sv = *type_entry_svp;
7965 63 type_name = gql_runtime_vm_type_name_from_sv(aTHX_ type_sv);
7966 63 ▶ if (!type_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!type_name) { 0 63 63
7967 0 continue;
7968 }
7969 63 cb_svp = hv_fetch(is_type_of_map_hv, type_name, (I32)strlen(type_name), 0);
7970 63 ▶ if (!cb_svp || !SvOK(*cb_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!cb_svp || !SvOK(*cb_svp)) { 0 63 63
if (!cb_svp || !SvOK(*cb_svp)) { 0 0 0
7971 63 continue;
7972 }
7973 0 runtime->callback_catalog->slot_possible_type_entries[i][j].type_name = gql_runtime_vm_copy_cstr(type_name);
7974 0 runtime->callback_catalog->slot_possible_type_entries[i][j].type_sv = newSVsv(type_sv);
7975 0 runtime->callback_catalog->slot_possible_type_entries[i][j].is_type_of_cb = newSVsv(*cb_svp);
7976 }
7977 }
7978 }
7979 }
7980 13102 finalize_arg_defs:
7981 13102 ▶ if (slot->callback_abi_code != GQL_VM_CALLBACK_ABI_DEFAULT
Branch: 1 branch
BranchTrueFalseTotal
if (slot->callback_abi_code != GQL_VM_CALLBACK_ABI_DEFAULT 8534 4568 13102
7982 8534 ▶ && (!runtime->callback_catalog->slot_type_objects[i]
Branch: 1 branch
BranchTrueFalseTotal
&& (!runtime->callback_catalog->slot_type_objects[i] 8534 0 8534
7983 8534 ▶ || !SvOK(runtime->callback_catalog->slot_type_objects[i]))) {
Branch: 1 branch
BranchTrueFalseTotal
|| !SvOK(runtime->callback_catalog->slot_type_objects[i]))) { 0 8534 8534
7984 0 ▶ if (exec_struct_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (exec_struct_sv) { 0 0 0
7985 0 SvREFCNT_dec(exec_struct_sv);
7986 }
7987 0 gql_runtime_vm_native_runtime_destroy(runtime);
7988 0 croak(
7989 "runtime schema slot_catalog entry %ld is missing direct slot_type_object for callback ABI %ld",
7990 (long)i,
7991 (long)slot->callback_abi_code
7992 );
7993 }
7994 14987 ▶ for (arg_index = 0; arg_index < slot->arg_def_count; arg_index++) {
Branch: 1 branch
BranchTrueFalseTotal
for (arg_index = 0; arg_index < slot->arg_def_count; arg_index++) { 1885 13102 14987
7995 1885 gql_runtime_vm_finalize_native_arg_def(aTHX_ runtime_schema, &slot->arg_defs[arg_index]);
7996 }
7997 }
7998 }
7999 }
8000  
8001 242 ▶ if (exec_struct_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (exec_struct_sv) { 0 242 242
8002 0 SvREFCNT_dec(exec_struct_sv);
8003 }
8004  
8005 242 return runtime;
8006 }
8007  
8008 static gql_runtime_vm_native_runtime_t *
8009 12115 gql_runtime_vm_exec_state_native_runtime(pTHX_ gql_runtime_vm_exec_state_handle_t *s)
8010 {
8011 12115 ▶ if (!s) {
Branch: 1 branch
BranchTrueFalseTotal
if (!s) { 0 12115 12115
8012 0 return NULL;
8013 }
8014 12115 ▶ if (!s->native_runtime && s->runtime_schema && SvOK(s->runtime_schema)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!s->native_runtime && s->runtime_schema && SvOK(s->runtime_schema)) { 0 12115 12115
if (!s->native_runtime && s->runtime_schema && SvOK(s->runtime_schema)) { 0 0 0
if (!s->native_runtime && s->runtime_schema && SvOK(s->runtime_schema)) { 0 0 0
8015 0 s->native_runtime = gql_runtime_vm_native_runtime_from_runtime_schema_sv(aTHX_ s->runtime_schema);
8016 }
8017 12115 return s->native_runtime;
8018 }
8019  
8020 static gql_runtime_vm_cursor_t *
8021 1600 gql_runtime_vm_new_cursor_struct_for_program(
8022 pTHX_
8023 gql_runtime_vm_native_program_t *program,
8024 IV block_index,
8025 IV slot_index,
8026 IV op_index
8027 )
8028 {
8029 gql_runtime_vm_cursor_t *cursor;
8030  
8031 1600 Newxz(cursor, 1, gql_runtime_vm_cursor_t);
8032 1600 cursor->refcount = 1;
8033 1600 cursor->native_program = program;
8034 1600 cursor->block_index = block_index;
8035 1600 cursor->slot_index = slot_index;
8036 1600 cursor->op_index = op_index;
8037 1600 return cursor;
8038 }
8039  
8040 static SV *
8041 1600 gql_runtime_vm_new_exec_state_handle_sv(
8042 pTHX_
8043 const char *pkg,
8044 SV *runtime_schema,
8045 SV *program,
8046 gql_runtime_vm_cursor_t *cursor,
8047 gql_runtime_vm_writer_t *writer,
8048 SV *context,
8049 SV *variables,
8050 SV *root_value,
8051 SV *empty_args
8052 )
8053 {
8054 gql_runtime_vm_exec_state_handle_t *state;
8055  
8056 1600 Newxz(state, 1, gql_runtime_vm_exec_state_handle_t);
8057 1600 ▶ state->runtime_schema = newSVsv(runtime_schema ? runtime_schema : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
state->runtime_schema = newSVsv(runtime_schema ? runtime_schema : &PL_sv_undef); 1600 0 1600
8058 1600 ▶ state->program = newSVsv(program ? program : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
state->program = newSVsv(program ? program : &PL_sv_undef); 1600 0 1600
8059 1600 state->native_runtime = NULL;
8060 1600 state->native_runtime_owner_sv = NULL;
8061 1600 state->native_runtime_is_borrowed = 0;
8062 1600 state->cursor = cursor;
8063 1600 gql_runtime_vm_cursor_incref(state->cursor);
8064 1600 ▶ state->native_program = state->cursor ? state->cursor->native_program : NULL;
Branch: 1 branch
BranchTrueFalseTotal
state->native_program = state->cursor ? state->cursor->native_program : NULL; 1600 0 1600
8065 1600 state->frame = NULL;
8066 1600 state->frame_stack_count = 0;
8067 1600 state->frame_stack_capacity = 0;
8068 1600 state->frame_stack = NULL;
8069 1600 state->field_frame = NULL;
8070 1600 state->writer = writer;
8071 1600 gql_runtime_vm_writer_incref(state->writer);
8072 1600 ▶ state->context = newSVsv(context ? context : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
state->context = newSVsv(context ? context : &PL_sv_undef); 1600 0 1600
8073 1600 ▶ state->variables = newSVsv(variables ? variables : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
state->variables = newSVsv(variables ? variables : &PL_sv_undef); 1600 0 1600
8074 1600 ▶ state->root_value = newSVsv(root_value ? root_value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
state->root_value = newSVsv(root_value ? root_value : &PL_sv_undef); 1600 0 1600
8075 1600 state->async_adapter = &gql_runtime_vm_promise_xs_adapter;
8076 1539 ▶ state->empty_args = (empty_args && SvOK(empty_args))
Branch: 1 branch
BranchTrueFalseTotal
state->empty_args = (empty_args && SvOK(empty_args)) 1539 0 1539
8077 1539 ? newSVsv(empty_args)
8078 1600 ▶ : gql_runtime_vm_empty_args_sv(aTHX);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_empty_args_sv(aTHX); 1539 61 1600
8079 1600 state->async_ready_frame_count = 0;
8080 1600 state->async_ready_frame_capacity = 0;
8081 1600 state->async_ready_frames = NULL;
8082 1600 state->async_scheduler_draining = 0;
8083 1600 return gql_runtime_vm_new_handle_sv(aTHX_ pkg, state);
8084 }
8085  
8086 /*
8087 * R5 leak 2: a request abandoned while promises are pending frees nothing,
8088 * because the live structures form a reference cycle:
8089 *
8090 * block frame --(pending entry holds the resolver's promise)-->
8091 * promise --(then callbacks)--> armed callback ctx --(strong state_sv)-->
8092 * exec state --(frame_stack / response frame)--> block frame
8093 *
8094 * The response promise handed to the Perl driver carries this magic (a
8095 * strong ref to the exec state) so the driver can break the cycle when it
8096 * gives up on the request (deadlocked stall, missing on_stall): clearing
8097 * the pending entries drops the promise references, which frees the armed
8098 * callback pairs, which releases their exec-state references - the
8099 * ordinary DESTROY chain then reclaims every frame. A callback that still
8100 * fires later (a loader settling after abandonment) hits the entry-index
8101 * bounds check against the cleared pending array and no-ops.
8102 */
8103 static MGVTBL gql_runtime_vm_response_state_magic_vtbl;
8104  
8105 static void
8106 61 gql_runtime_vm_attach_response_state_magic(pTHX_ SV *promise_rv, SV *state_sv)
8107 {
8108 61 ▶ if (!promise_rv || !SvROK(promise_rv) || !state_sv) {
Branch: 3 branches
BranchTrueFalseTotal
if (!promise_rv || !SvROK(promise_rv) || !state_sv) { 61 0 61
if (!promise_rv || !SvROK(promise_rv) || !state_sv) { 61 0 61
if (!promise_rv || !SvROK(promise_rv) || !state_sv) { 0 61 61
8109 0 return;
8110 }
8111 /* sv_magicext increments state_sv's refcount (MGf_REFCOUNTED). */
8112 61 sv_magicext(SvRV(promise_rv), state_sv, PERL_MAGIC_ext,
8113 &gql_runtime_vm_response_state_magic_vtbl, NULL, 0);
8114 }
8115  
8116 /* Cancel a suspended frame and its pending subtree, depth-first. A
8117 * BLOCK_FRAME_PTR payload is a suspended child that still owns its
8118 * allocation reference (resolve_frame, which would have released it, never
8119 * ran), so each child gets one extra release beyond the entry reference
8120 * that clear_pending drops. Entries form a tree, so the recursion
8121 * terminates. An OBJECT/ABSTRACT field's own suspended child block (Phase
8122 * 5/6/7: gql_runtime_vm_execute_safe_child_block_fast_sv,
8123 * gql_runtime_vm_push_pending_block_frame) is pushed as exactly this same
8124 * BLOCK_FRAME_PTR shape, so it needs no special handling here.
8125 *
8126 * Any armed entry (promise or DataLoader ticket alike - arm_frame sets
8127 * armed_resolve_ctx/armed_reject_ctx to the same pair_ctx regardless of
8128 * payload kind) is disarmed here too, before clear_pending drops our own
8129 * promise_sv reference: see gql_runtime_vm_pending_callback_ctx_disarm's
8130 * comment for why cancellation cannot just recycle the pair like a normal
8131 * settle does.
8132 *
8133 * Phase 11: a GQL_VM_PENDING_LIST_PENDING_PTR entry's list_pending may now
8134 * itself hold raw child block_frame_t pointers
8135 * (gql_runtime_vm_list_pending_link_child_frame, one per still-suspended
8136 * list item) instead of everything being Promise::XS-mediated. clear_pending
8137 * only drops the entry's own reference to the list_pending as a whole; each
8138 * linked child frame needs the same two-release treatment
8139 * gql_runtime_vm_async_scheduler_resolve_frame's parent_list_pending branch
8140 * gives a normally-settling one (one release for the link's own hold on the
8141 * child frame, one gql_runtime_vm_list_pending_decref for the child's own
8142 * hold on list_pending) before recursing into it, or both frame and
8143 * list_pending leak. */
8144 static void
8145 25 gql_runtime_vm_cancel_frame_tree(pTHX_ gql_runtime_vm_block_frame_t *frame)
8146 {
8147 IV i;
8148 25 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 25 25
8149 0 return;
8150 }
8151 50 ▶ for (i = 0; i < frame->pending_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < frame->pending_count; i++) { 25 25 50
8152 25 ▶ if (frame->pending_entries[i].armed_resolve_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_entries[i].armed_resolve_ctx) { 17 8 25
8153 17 gql_runtime_vm_pending_callback_ctx_disarm(
8154 aTHX_
8155 17 (gql_runtime_vm_pending_callback_ctx_t *)frame->pending_entries[i].armed_resolve_ctx
8156 );
8157 }
8158 25 ▶ if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR 6 19 25
8159 12 ▶ && frame->pending_entries[i].payload.block_frame_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
&& frame->pending_entries[i].payload.block_frame_ptr) { 6 0 6
8160 6 gql_runtime_vm_block_frame_t *child =
8161 6 frame->pending_entries[i].payload.block_frame_ptr;
8162 6 gql_runtime_vm_cancel_frame_tree(aTHX_ child);
8163 6 gql_runtime_vm_free_block_frame(aTHX_ child);
8164 19 ▶ } else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR
Branch: 1 branch
BranchTrueFalseTotal
} else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_LIST_PENDING_PTR 2 17 19
8165 2 ▶ && frame->pending_entries[i].payload.list_pending_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
&& frame->pending_entries[i].payload.list_pending_ptr) { 2 0 2
8166 2 gql_runtime_vm_list_pending_t *list_pending =
8167 2 frame->pending_entries[i].payload.list_pending_ptr;
8168 IV ci;
8169 6 ▶ for (ci = 0; ci < list_pending->pending_child_frame_count; ci++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ci = 0; ci < list_pending->pending_child_frame_count; ci++) { 4 2 6
8170 4 gql_runtime_vm_block_frame_t *child = list_pending->pending_child_frames[ci];
8171 4 ▶ if (!child) {
Branch: 1 branch
BranchTrueFalseTotal
if (!child) { 0 4 4
8172 0 continue;
8173 }
8174 4 list_pending->pending_child_frames[ci] = NULL;
8175 4 gql_runtime_vm_cancel_frame_tree(aTHX_ child);
8176 /* Two releases, matching resolve_frame's parent_list_pending
8177 * branch exactly (clear_pending's own LIST_PENDING_PTR handling,
8178 * below, only drops the *entry's* reference to list_pending as a
8179 * whole - it has no visibility into pending_child_frames[], so it
8180 * cannot provide either of these the way it does for a
8181 * BLOCK_FRAME_PTR entry's single child): one for the link's own
8182 * hold on child (gql_runtime_vm_list_pending_link_child_frame's
8183 * refcount++), one for child's original creation reference. */
8184 4 gql_runtime_vm_free_block_frame(aTHX_ child);
8185 4 gql_runtime_vm_list_pending_decref(aTHX_ list_pending);
8186 4 gql_runtime_vm_free_block_frame(aTHX_ child);
8187 }
8188 }
8189 }
8190 25 gql_runtime_vm_block_frame_clear_pending(aTHX_ frame);
8191 }
8192  
8193 /* Core of gql_runtime_vm_cancel_pending_response_sv, factored out so a
8194 * caller that already holds the exec_state_handle_t directly (Phase 8's
8195 * C-level on_stall drive loop, which never attaches the response-state
8196 * magic in the first place since it never builds a promise - see
8197 * finalize_sv mode 3) can cancel the same way without unwrapping a
8198 * promise's magic first. */
8199 static void
8200 15 gql_runtime_vm_cancel_exec_state_sv(pTHX_ gql_runtime_vm_exec_state_handle_t *state)
8201 {
8202 IV i;
8203  
8204 15 ▶ if (!state) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state) { 0 15 15
8205 0 return;
8206 }
8207 15 ▶ if (state->response_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->response_frame) { 15 0 15
8208 15 gql_runtime_vm_cancel_frame_tree(aTHX_ state->response_frame);
8209 }
8210 15 ▶ if (state->frame && state->frame != state->response_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->frame && state->frame != state->response_frame) { 0 15 15
if (state->frame && state->frame != state->response_frame) { 0 0 0
8211 0 gql_runtime_vm_cancel_frame_tree(aTHX_ state->frame);
8212 }
8213 15 ▶ for (i = 0; i < state->frame_stack_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < state->frame_stack_count; i++) { 0 15 15
8214 0 ▶ if (state->frame_stack[i] && state->frame_stack[i] != state->response_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->frame_stack[i] && state->frame_stack[i] != state->response_frame) { 0 0 0
if (state->frame_stack[i] && state->frame_stack[i] != state->response_frame) { 0 0 0
8215 0 gql_runtime_vm_cancel_frame_tree(aTHX_ state->frame_stack[i]);
8216 }
8217 }
8218 /* Request-scoped user data can close a second cycle around the exec
8219 * state (context -> DataLoader -> queued deferred -> promise -> armed
8220 * callback -> exec state -> context), so a cancelled request drops
8221 * these references too. Cancelled continuations no-op before touching
8222 * any of them, and ExecState DESTROY's SvREFCNT_dec is NULL-safe. */
8223 15 SvREFCNT_dec(state->context);
8224 15 state->context = NULL;
8225 15 SvREFCNT_dec(state->root_value);
8226 15 state->root_value = NULL;
8227 15 SvREFCNT_dec(state->variables);
8228 15 state->variables = NULL;
8229 }
8230  
8231 static void
8232 4 gql_runtime_vm_cancel_pending_response_sv(pTHX_ SV *promise_rv)
8233 {
8234 MAGIC *mg;
8235  
8236 4 ▶ if (!promise_rv || !SvROK(promise_rv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!promise_rv || !SvROK(promise_rv)) { 4 0 4
if (!promise_rv || !SvROK(promise_rv)) { 0 4 4
8237 0 return;
8238 }
8239 4 mg = mg_findext(SvRV(promise_rv), PERL_MAGIC_ext,
8240 &gql_runtime_vm_response_state_magic_vtbl);
8241 4 ▶ if (!mg || !mg->mg_obj) {
Branch: 2 branches
BranchTrueFalseTotal
if (!mg || !mg->mg_obj) { 4 0 4
if (!mg || !mg->mg_obj) { 0 4 4
8242 0 return;
8243 }
8244 4 gql_runtime_vm_cancel_exec_state_sv(aTHX_ gql_runtime_vm_expect_exec_state_handle(aTHX_ mg->mg_obj));
8245 /* Drop the magic so the promise no longer pins the exec state. */
8246 4 sv_unmagicext(SvRV(promise_rv), PERL_MAGIC_ext,
8247 &gql_runtime_vm_response_state_magic_vtbl);
8248 }
8249  
8250 /* Phase 8: call the caller's on_stall closure once, the same batching
8251 * contract gql_runtime_vm's Perl-level _settle_result documents (must
8252 * return a true dispatch count to report progress). Every user-callback
8253 * invocation in this file uses G_EVAL (see gql_runtime_vm_call_cb3_nonfatal
8254 * and friends) so a die() here is caught as a scalar return + ERRSV, never
8255 * a raw longjmp through this C frame - matching that established idiom
8256 * lets on_stall die safely without reintroducing the R5/PR21 class of
8257 * dead-C-stack-pointer bugs t/34_exec_state_croak_safety.t guards against.
8258 * On a caught die, state_to_cancel is cancelled (the same reference-cycle
8259 * teardown gql_runtime_vm_cancel_pending_response_sv does) before
8260 * re-raising via croak_sv, mirroring the nonfatal callback helpers'
8261 * "catch, decide, then croak" structure exactly (no manual FREETMPS/LEAVE
8262 * before the croak - Perl's own unwind pops the save stack for us). */
8263 static int
8264 1481 gql_runtime_vm_call_on_stall_once(
8265 pTHX_
8266 gql_runtime_vm_exec_state_handle_t *state_to_cancel,
8267 SV *on_stall_sv
8268 )
8269 {
8270 1481 dSP;
8271 I32 count;
8272 1481 int progressed = 0;
8273  
8274 1481 ENTER;
8275 1481 SAVETMPS;
8276 1481 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1481 1481
8277 1481 PUTBACK;
8278 1481 count = call_sv(on_stall_sv, G_SCALAR | G_EVAL);
8279 1481 SPAGAIN;
8280 1481 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1481 0 1481
if (SvTRUE(ERRSV)) { 4 1477 1481
8281 4 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 4 0 4
8282 4 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 4 0 4
8283 4 gql_runtime_vm_cancel_exec_state_sv(aTHX_ state_to_cancel);
8284 4 croak_sv(err);
8285 }
8286 1477 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 1477 0 1477
8287 /* POPs has the side effect of decrementing sp; binding it to a plain
8288 * variable first (instead of writing SvTRUE(POPs) directly) avoids
8289 * handing a self-mutating expression to a macro that may reference its
8290 * argument more than once - some Perl versions' SvTRUE expansion does,
8291 * which silently walked sp past the real stack contents here (found via
8292 * a real SIGSEGV on Perl 5.24, unreproducible on 5.44 where SvTRUE
8293 * happens to evaluate its argument only once). */
8294 1477 SV *result_sv = POPs;
8295 1477 ▶ if (SvTRUE(result_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(result_sv)) { 1466 11 1477
8296 1466 progressed = 1;
8297 }
8298 }
8299 1477 PUTBACK;
8300 1477 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1477 0 1477
8301 1477 LEAVE;
8302 1477 return progressed;
8303 }
8304  
8305 /* Drives a response frame armed via finalize_sv mode 3 (never wrapped in a
8306 * Promise::XS - see that mode's doc comment) to completion by calling
8307 * on_stall directly from C instead of returning a promise for a Perl-level
8308 * _settle_result to drive. Mirrors _settle_result's exact contract and
8309 * wording (stall message, cancel-then-croak) so behavior is unchanged from
8310 * the caller's perspective - only the promise/then() round trip is gone. */
8311 static SV *
8312 1479 gql_runtime_vm_drive_with_on_stall_sv(
8313 pTHX_
8314 gql_runtime_vm_exec_state_handle_t *state,
8315 SV *on_stall_sv
8316 )
8317 {
8318 1479 ▶ while (!state->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
while (!state->completed_response_sv) { 1479 0 1479
8319 1479 int progressed = gql_runtime_vm_call_on_stall_once(aTHX_ state, on_stall_sv);
8320 1475 ▶ if (state->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->completed_response_sv) { 1468 7 1475
8321 1468 break;
8322 }
8323 7 ▶ if (!progressed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!progressed) { 7 0 7
8324 7 gql_runtime_vm_cancel_exec_state_sv(aTHX_ state);
8325 7 croak(
8326 "GraphQL execution stalled: promises are pending but on_stall made no progress"
8327 " (a resolver returned a promise that no registered loader will resolve)\n"
8328 );
8329 }
8330 }
8331 1468 return SvREFCNT_inc_simple_NN(state->completed_response_sv);
8332 }
8333  
8334 2 static XS(gql_runtime_vm_xs_settle_capture_resolve_callback)
8335 {
8336 dVAR;
8337 2 dXSARGS;
8338 2 gql_runtime_vm_settle_capture_ctx_t *ctx = INT2PTR(
8339 gql_runtime_vm_settle_capture_ctx_t *,
8340 CvXSUBANY(cv).any_ptr
8341 );
8342 2 ▶ if (ctx && !ctx->settled) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx && !ctx->settled) { 2 0 2
if (ctx && !ctx->settled) { 2 0 2
8343 2 ▶ SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 2 0 2
SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 2 0 2
8344 2 ctx->value = newSVsv(resolved_sv);
8345 2 ctx->settled = 1;
8346 }
8347 2 XSRETURN_UNDEF;
8348 }
8349  
8350 0 static XS(gql_runtime_vm_xs_settle_capture_reject_callback)
8351 {
8352 dVAR;
8353 0 dXSARGS;
8354 0 gql_runtime_vm_settle_capture_ctx_t *ctx = INT2PTR(
8355 gql_runtime_vm_settle_capture_ctx_t *,
8356 CvXSUBANY(cv).any_ptr
8357 );
8358 0 ▶ if (ctx && !ctx->settled) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx && !ctx->settled) { 0 0 0
if (ctx && !ctx->settled) { 0 0 0
8359 0 ▶ SV *reason_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *reason_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 0 0 0
SV *reason_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 0 0 0
8360 0 ctx->value = newSVsv(reason_sv);
8361 0 ctx->settled = 2;
8362 }
8363 0 XSRETURN_UNDEF;
8364 }
8365  
8366 static gql_runtime_vm_settle_capture_ctx_t *
8367 2 gql_runtime_vm_new_settle_capture_pair(pTHX_ SV **resolve_rv_out, SV **reject_rv_out)
8368 {
8369 gql_runtime_vm_settle_capture_ctx_t *ctx;
8370 CV *resolve_cv;
8371 CV *reject_cv;
8372  
8373 2 Newxz(ctx, 1, gql_runtime_vm_settle_capture_ctx_t);
8374 /* 3 shares: the resolve CV, the reject CV, and the caller's own promised
8375 * release once it is done reading ctx after the loop settles - see
8376 * gql_runtime_vm_settle_capture_ctx_release's doc comment. */
8377 2 ctx->cv_refcnt = 3;
8378  
8379 2 resolve_cv = newXS(NULL, gql_runtime_vm_xs_settle_capture_resolve_callback, __FILE__);
8380 2 CvXSUBANY(resolve_cv).any_ptr = ctx;
8381 2 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)resolve_cv, &gql_runtime_vm_settle_capture_ctx_vtbl, ctx);
8382 2 reject_cv = newXS(NULL, gql_runtime_vm_xs_settle_capture_reject_callback, __FILE__);
8383 2 CvXSUBANY(reject_cv).any_ptr = ctx;
8384 2 gql_runtime_vm_attach_callback_magic_ptr(aTHX_ (SV *)reject_cv, &gql_runtime_vm_settle_capture_ctx_vtbl, ctx);
8385  
8386 2 *resolve_rv_out = newRV_noinc((SV *)resolve_cv);
8387 2 *reject_rv_out = newRV_noinc((SV *)reject_cv);
8388 2 return ctx;
8389 }
8390  
8391 /* Item 1 (Phase 9): drives a genuine Promise::XS response the generic
8392 * executor built (a shape the fast lane does not cover - runtime
8393 * directives present, or the nesting-depth guard exceeded) to completion
8394 * from C, instead of returning it for a Perl-level _settle_result to
8395 * drive. Unlike gql_runtime_vm_drive_with_on_stall_sv, the generic
8396 * executor itself is unchanged and still builds a real Promise::XS for
8397 * its response - this only changes who drains it, registering a plain
8398 * then() via gql_runtime_vm_call_then_promise_xs_sv and polling the
8399 * capture ctx instead of state->completed_response_sv. Mirrors
8400 * _settle_result's exact contract and wording (stall message,
8401 * cancel-then-croak, rejection re-raised as-is) so behavior is unchanged
8402 * from the caller's perspective. state_to_cancel is the exec state the
8403 * response promise's own magic already carries (see
8404 * gql_runtime_vm_attach_response_state_magic), reused here so on_stall
8405 * dying cancels it exactly like the fast-lane path does. */
8406 static SV *
8407 2 gql_runtime_vm_drive_promise_with_on_stall_sv(
8408 pTHX_
8409 SV *promise_rv,
8410 SV *on_stall_sv,
8411 gql_runtime_vm_exec_state_handle_t *state_to_cancel
8412 )
8413 {
8414 gql_runtime_vm_settle_capture_ctx_t *ctx;
8415 2 SV *resolve_rv = NULL;
8416 2 SV *reject_rv = NULL;
8417 SV *chain;
8418 SV *ret;
8419  
8420 2 ctx = gql_runtime_vm_new_settle_capture_pair(aTHX_ &resolve_rv, &reject_rv);
8421 2 chain = gql_runtime_vm_call_then_adapter_sv(
8422 aTHX_ state_to_cancel->async_adapter,
8423 promise_rv,
8424 resolve_rv,
8425 reject_rv,
8426 NULL
8427 );
8428 2 ▶ if (chain && SvOK(chain) && gql_runtime_vm_sv_is_outcome(aTHX_ chain)) {
Branch: 3 branches
BranchTrueFalseTotal
if (chain && SvOK(chain) && gql_runtime_vm_sv_is_outcome(aTHX_ chain)) { 2 0 2
if (chain && SvOK(chain) && gql_runtime_vm_sv_is_outcome(aTHX_ chain)) { 2 0 2
if (chain && SvOK(chain) && gql_runtime_vm_sv_is_outcome(aTHX_ chain)) { 0 2 2
8429 0 SV *error_sv = gql_runtime_vm_adapter_error_sv(aTHX_ chain);
8430 0 gql_runtime_vm_cancel_pending_response_sv(aTHX_ promise_rv);
8431 0 SvREFCNT_dec(chain);
8432 0 SvREFCNT_dec(resolve_rv);
8433 0 SvREFCNT_dec(reject_rv);
8434 0 gql_runtime_vm_settle_capture_ctx_release(aTHX_ ctx);
8435 0 croak_sv(sv_2mortal(error_sv));
8436 }
8437 2 SvREFCNT_dec(chain);
8438 2 SvREFCNT_dec(resolve_rv);
8439 2 SvREFCNT_dec(reject_rv);
8440  
8441 2 ▶ while (!ctx->settled) {
Branch: 1 branch
BranchTrueFalseTotal
while (!ctx->settled) { 2 0 2
8442 2 int progressed = gql_runtime_vm_call_on_stall_once(aTHX_ state_to_cancel, on_stall_sv);
8443 2 ▶ if (ctx->settled) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->settled) { 2 0 2
8444 2 break;
8445 }
8446 0 ▶ if (!progressed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!progressed) { 0 0 0
8447 0 gql_runtime_vm_cancel_pending_response_sv(aTHX_ promise_rv);
8448 0 gql_runtime_vm_settle_capture_ctx_release(aTHX_ ctx);
8449 0 croak(
8450 "GraphQL execution stalled: promises are pending but on_stall made no progress"
8451 " (a resolver returned a promise that no registered loader will resolve)\n"
8452 );
8453 }
8454 }
8455  
8456 /* ctx->value is read into a local before releasing the drive loop's own
8457 * share (which may be the last share, freeing ctx and ctx->value along
8458 * with it - see gql_runtime_vm_settle_capture_ctx_release). */
8459 2 ▶ ret = ctx->value ? SvREFCNT_inc_simple_NN(ctx->value) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ret = ctx->value ? SvREFCNT_inc_simple_NN(ctx->value) : newSVsv(&PL_sv_undef); 2 0 2
8460 2 ▶ if (ctx->settled == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->settled == 2) { 0 2 2
8461 0 gql_runtime_vm_settle_capture_ctx_release(aTHX_ ctx);
8462 0 croak_sv(ret);
8463 }
8464 2 gql_runtime_vm_settle_capture_ctx_release(aTHX_ ctx);
8465 2 return ret;
8466 }
8467  
8468 static SV *
8469 301 gql_runtime_vm_execute_native_program_auto_impl_sv(
8470 pTHX_
8471 SV *runtime_sv,
8472 SV *program_sv,
8473 SV *root_value,
8474 SV *context_value,
8475 SV *variables,
8476 U8 json_mode
8477 )
8478 {
8479 gql_runtime_vm_native_runtime_t *runtime;
8480 gql_runtime_vm_native_program_t *program;
8481 301 gql_runtime_vm_cursor_t *cursor = NULL;
8482 301 gql_runtime_vm_writer_t *writer = NULL;
8483 301 gql_runtime_vm_exec_state_handle_t *state = NULL;
8484 301 HV *provided_hv = NULL;
8485 301 SV *runtime_schema_sv = &PL_sv_undef;
8486 301 SV *prepared_variables_sv = NULL;
8487 301 SV *state_sv = NULL;
8488 301 SV *data_sv = NULL;
8489 301 SV *effective_root = root_value;
8490 301 SV *ret = NULL;
8491 301 U8 fast_root_handled = 0;
8492  
8493 301 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 301 0 301
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 301 0 301
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 301 301
8494 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
8495 }
8496  
8497 301 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
8498 301 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 301 301
8499 0 croak("native VM runtime handle is no longer valid");
8500 }
8501  
8502 301 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
8503 301 ▶ if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 301 0 301
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 66 235 301
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 66 0 66
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 66 0 66
8504 66 provided_hv = (HV *)SvRV(variables);
8505 }
8506  
8507 301 ▶ if (runtime->callback_catalog && runtime->callback_catalog->runtime_schema) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime->callback_catalog && runtime->callback_catalog->runtime_schema) { 301 0 301
if (runtime->callback_catalog && runtime->callback_catalog->runtime_schema) { 301 0 301
8508 301 runtime_schema_sv = runtime->callback_catalog->runtime_schema;
8509 }
8510 /* Everything owned before execution is mortal (or dropped once the exec
8511 * state holds its own reference) so a die() escaping from resolvers or
8512 * input coercion cannot leak the request state. */
8513 301 prepared_variables_sv = sv_2mortal(gql_runtime_vm_prepare_program_variables_sv(
8514 aTHX_
8515 runtime_schema_sv,
8516 program,
8517 provided_hv
8518 ));
8519  
8520 301 ret = gql_runtime_vm_try_execute_fast_root_continuation_sv(
8521 aTHX_
8522 runtime_sv,
8523 program_sv,
8524 runtime,
8525 program,
8526 runtime_schema_sv,
8527 root_value,
8528 context_value,
8529 prepared_variables_sv,
8530 json_mode,
8531 NULL,
8532 &fast_root_handled
8533 );
8534 293 ▶ if (fast_root_handled) {
Branch: 1 branch
BranchTrueFalseTotal
if (fast_root_handled) { 232 61 293
8535 232 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 232 232
8536 }
8537  
8538 61 cursor = gql_runtime_vm_new_cursor_struct_for_program(
8539 aTHX_
8540 program,
8541 program->root_block_index,
8542 0,
8543 0
8544 );
8545 61 writer = gql_runtime_vm_new_writer_struct(aTHX);
8546 61 state_sv = sv_2mortal(gql_runtime_vm_new_exec_state_handle_sv(
8547 aTHX_
8548 "GraphQL::Houtou::Runtime::ExecState",
8549 runtime_schema_sv,
8550 program_sv,
8551 cursor,
8552 writer,
8553 context_value,
8554 prepared_variables_sv,
8555 root_value,
8556 NULL
8557 ));
8558 61 state = gql_runtime_vm_expect_exec_state_handle(aTHX_ state_sv);
8559 61 state->native_runtime = runtime;
8560 61 state->native_runtime_is_borrowed = 1;
8561 61 state->native_runtime_owner_sv = newSVsv(runtime_sv);
8562 61 state->async_adapter = runtime->async_adapter;
8563 61 state->response_json_mode = json_mode;
8564 /* The exec state holds its own cursor/writer references now. */
8565 61 gql_runtime_vm_cursor_decref(aTHX_ cursor);
8566 61 cursor = NULL;
8567 61 gql_runtime_vm_writer_decref(aTHX_ writer);
8568 61 writer = NULL;
8569  
8570 61 ▶ if (!effective_root || !SvOK(effective_root)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!effective_root || !SvOK(effective_root)) { 61 0 61
if (!effective_root || !SvOK(effective_root)) { 61 0 61
8571 61 effective_root = state->root_value;
8572 }
8573 61 data_sv = gql_runtime_vm_exec_state_execute_block_async_sv(
8574 aTHX_
8575 state_sv,
8576 state,
8577 program->root_block_index,
8578 effective_root,
8579 &PL_sv_undef
8580 );
8581 59 ▶ if (state->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->completed_response_sv) { 15 44 59
8582 /* The request finished inside this call without a deferred; the
8583 * parked value is already the finished envelope (or JSON bytes). */
8584 15 ret = state->completed_response_sv;
8585 15 state->completed_response_sv = NULL;
8586 15 SvREFCNT_dec(data_sv);
8587 44 ▶ } else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ state, data_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ state, data_sv)) { 11 33 44
8588 /* A genuinely pending response: let the Perl driver reach the exec
8589 * state for cancellation (see the magic's comment block). */
8590 11 gql_runtime_vm_attach_response_state_magic(aTHX_ data_sv, state_sv);
8591 11 ret = data_sv;
8592 33 ▶ } else if (json_mode) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (json_mode) { 8 25 33
8593 8 ret = gql_runtime_vm_response_json_from_data_sv(aTHX_ state->writer, data_sv);
8594 8 SvREFCNT_dec(data_sv);
8595 } else {
8596 25 ret = gql_runtime_vm_exec_state_materialize_response_sv(aTHX_ state, data_sv);
8597 25 SvREFCNT_dec(data_sv);
8598 }
8599  
8600 /* state_sv / prepared_variables_sv are mortal; cursor and writer refs
8601 * were handed to the exec state above. */
8602 59 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 59 59
8603 }
8604  
8605 static SV *
8606 273 gql_runtime_vm_execute_native_program_auto_sv(
8607 pTHX_
8608 SV *runtime_sv,
8609 SV *program_sv,
8610 SV *root_value,
8611 SV *context_value,
8612 SV *variables
8613 )
8614 {
8615 273 return gql_runtime_vm_execute_native_program_auto_impl_sv(
8616 aTHX_ runtime_sv, program_sv, root_value, context_value, variables, 0
8617 );
8618 }
8619  
8620 static SV *
8621 25 gql_runtime_vm_execute_native_program_auto_json_sv(
8622 pTHX_
8623 SV *runtime_sv,
8624 SV *program_sv,
8625 SV *root_value,
8626 SV *context_value,
8627 SV *variables
8628 )
8629 {
8630 25 return gql_runtime_vm_execute_native_program_auto_impl_sv(
8631 aTHX_ runtime_sv, program_sv, root_value, context_value, variables, 1
8632 );
8633 }
8634  
8635 /* Phase 8: on_stall-driven entry point. Tries the fast lane first, passing
8636 * on_stall_sv through so a genuinely pending response drives to completion
8637 * right here in C (gql_runtime_vm_drive_with_on_stall_sv) instead of
8638 * returning a Promise::XS for a Perl-level _settle_result to drive -
8639 * eliminating that promise's deferred/then/resolve round trip entirely for
8640 * every shape the fast lane already covers (Phase 3-7's eligibility work).
8641 * If the fast lane does not handle this shape (runtime directives present,
8642 * the nesting-depth guard exceeded, json_mode, ...), falls back to the
8643 * generic executor completely unchanged. Item 1 (Phase 9): if that
8644 * fallback genuinely suspends, drive its response promise from here too
8645 * (gql_runtime_vm_drive_promise_with_on_stall_sv) instead of handing it
8646 * back to Perl's _settle_result - the generic executor still builds a
8647 * real Promise::XS internally, so this shape does not get the fast lane's
8648 * full saving, but it does skip the outer Perl-level then()/while-loop
8649 * round trip. */
8650 static SV *
8651 1490 gql_runtime_vm_execute_native_program_auto_with_on_stall_sv(
8652 pTHX_
8653 SV *runtime_sv,
8654 SV *program_sv,
8655 SV *root_value,
8656 SV *context_value,
8657 SV *variables,
8658 SV *on_stall_sv
8659 )
8660 {
8661 gql_runtime_vm_native_runtime_t *runtime;
8662 gql_runtime_vm_native_program_t *program;
8663 1490 HV *provided_hv = NULL;
8664 1490 SV *runtime_schema_sv = &PL_sv_undef;
8665 SV *prepared_variables_sv;
8666 SV *ret;
8667 1490 U8 fast_root_handled = 0;
8668  
8669 1490 ▶ if (!on_stall_sv || !SvOK(on_stall_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!on_stall_sv || !SvOK(on_stall_sv)) { 1490 0 1490
if (!on_stall_sv || !SvOK(on_stall_sv)) { 0 1490 1490
8670 0 return gql_runtime_vm_execute_native_program_auto_impl_sv(
8671 aTHX_ runtime_sv, program_sv, root_value, context_value, variables, 0
8672 );
8673 }
8674 1490 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 1490 0 1490
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 1490 0 1490
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 1490 1490
8675 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
8676 }
8677 1490 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
8678 1490 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 1490 1490
8679 0 croak("native VM runtime handle is no longer valid");
8680 }
8681 1490 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
8682 1490 ▶ if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 1490 0 1490
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 1446 44 1490
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 1446 0 1446
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 1446 0 1446
8683 1446 provided_hv = (HV *)SvRV(variables);
8684 }
8685 1490 ▶ if (runtime->callback_catalog && runtime->callback_catalog->runtime_schema) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime->callback_catalog && runtime->callback_catalog->runtime_schema) { 1490 0 1490
if (runtime->callback_catalog && runtime->callback_catalog->runtime_schema) { 1490 0 1490
8686 1490 runtime_schema_sv = runtime->callback_catalog->runtime_schema;
8687 }
8688 1490 prepared_variables_sv = sv_2mortal(gql_runtime_vm_prepare_program_variables_sv(
8689 aTHX_ runtime_schema_sv, program, provided_hv
8690 ));
8691  
8692 1490 ret = gql_runtime_vm_try_execute_fast_root_continuation_sv(
8693 aTHX_
8694 runtime_sv,
8695 program_sv,
8696 runtime,
8697 program,
8698 runtime_schema_sv,
8699 root_value,
8700 context_value,
8701 prepared_variables_sv,
8702 0,
8703 on_stall_sv,
8704 &fast_root_handled
8705 );
8706 1479 ▶ if (fast_root_handled) {
Branch: 1 branch
BranchTrueFalseTotal
if (fast_root_handled) { 1476 3 1479
8707 1476 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 1476 1476
8708 }
8709 3 ret = gql_runtime_vm_execute_native_program_auto_impl_sv(
8710 aTHX_ runtime_sv, program_sv, root_value, context_value, variables, 0
8711 );
8712 3 ▶ if (ret && SvROK(ret)) {
Branch: 2 branches
BranchTrueFalseTotal
if (ret && SvROK(ret)) { 3 0 3
if (ret && SvROK(ret)) { 3 0 3
8713 3 MAGIC *mg = mg_findext(SvRV(ret), PERL_MAGIC_ext, &gql_runtime_vm_response_state_magic_vtbl);
8714 3 ▶ if (mg && mg->mg_obj) {
Branch: 2 branches
BranchTrueFalseTotal
if (mg && mg->mg_obj) { 2 1 3
if (mg && mg->mg_obj) { 2 0 2
8715 2 SV *driven = gql_runtime_vm_drive_promise_with_on_stall_sv(
8716 aTHX_
8717 ret,
8718 on_stall_sv,
8719 gql_runtime_vm_expect_exec_state_handle(aTHX_ mg->mg_obj)
8720 );
8721 2 SvREFCNT_dec(ret);
8722 2 return driven;
8723 }
8724 }
8725 1 return ret;
8726 }
8727  
8728 static CV *
8729 7 gql_runtime_vm_accessor_method_cv(SV *source, const gql_runtime_vm_native_slot_t *slot)
8730 {
8731 7 gql_runtime_vm_native_slot_t *mutable_slot =
8732 (gql_runtime_vm_native_slot_t *)slot;
8733 HV *stash;
8734 GV *method_gv;
8735 CV *method_cv;
8736  
8737 7 ▶ if (!source || !SvROK(source) || !SvOBJECT(SvRV(source))
Branch: 3 branches
BranchTrueFalseTotal
if (!source || !SvROK(source) || !SvOBJECT(SvRV(source)) 7 0 7
if (!source || !SvROK(source) || !SvOBJECT(SvRV(source)) 7 0 7
if (!source || !SvROK(source) || !SvOBJECT(SvRV(source)) 7 0 7
8738 7 ▶ || !slot || !slot->accessor_name || !slot->accessor_name_len) {
Branch: 3 branches
BranchTrueFalseTotal
|| !slot || !slot->accessor_name || !slot->accessor_name_len) { 7 0 7
|| !slot || !slot->accessor_name || !slot->accessor_name_len) { 7 0 7
|| !slot || !slot->accessor_name || !slot->accessor_name_len) { 0 7 7
8739 0 return NULL;
8740 }
8741 7 stash = SvSTASH(SvRV(source));
8742 7 ▶ if (slot->accessor_cache_initialized
Branch: 1 branch
BranchTrueFalseTotal
if (slot->accessor_cache_initialized 1 6 7
8743 1 ▶ && slot->accessor_cache_stash == stash
Branch: 1 branch
BranchTrueFalseTotal
&& slot->accessor_cache_stash == stash 1 0 1
8744 1 ▶ && slot->accessor_cache_generation == PL_sub_generation) {
Branch: 1 branch
BranchTrueFalseTotal
&& slot->accessor_cache_generation == PL_sub_generation) { 1 0 1
8745 1 ▶ return slot->accessor_cache_gv ? GvCV(slot->accessor_cache_gv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return slot->accessor_cache_gv ? GvCV(slot->accessor_cache_gv) : NULL; 1 0 1
8746 }
8747  
8748 6 method_gv = gv_fetchmethod_autoload(stash, slot->accessor_name, 0);
8749 6 ▶ method_cv = method_gv ? GvCV(method_gv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
method_cv = method_gv ? GvCV(method_gv) : NULL; 6 0 6
8750 6 mutable_slot->accessor_cache_stash = stash;
8751 6 mutable_slot->accessor_cache_gv = method_gv;
8752 6 mutable_slot->accessor_cache_generation = PL_sub_generation;
8753 6 mutable_slot->accessor_cache_initialized = 1;
8754 6 return method_cv;
8755 }
8756  
8757 static SV *
8758 7 gql_runtime_vm_call_accessor_nonfatal(
8759 pTHX_
8760 SV *source,
8761 const gql_runtime_vm_native_slot_t *slot,
8762 SV **error_out
8763 )
8764 {
8765 7 dSP;
8766 CV *method_cv;
8767 7 SV *ret = NULL;
8768 int count;
8769  
8770 7 ▶ if (!slot || !slot->accessor_name || !slot->accessor_name_len) {
Branch: 3 branches
BranchTrueFalseTotal
if (!slot || !slot->accessor_name || !slot->accessor_name_len) { 7 0 7
if (!slot || !slot->accessor_name || !slot->accessor_name_len) { 7 0 7
if (!slot || !slot->accessor_name || !slot->accessor_name_len) { 0 7 7
8771 0 return newSVsv(&PL_sv_undef);
8772 }
8773 7 method_cv = gql_runtime_vm_accessor_method_cv(source, slot);
8774 7 ▶ if (!method_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!method_cv) { 0 7 7
8775 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
8776 0 *error_out = newSVpvf(
8777 "accessor method '%s' is not available on the source object",
8778 slot->accessor_name
8779 );
8780 }
8781 0 return newSVsv(&PL_sv_undef);
8782 }
8783  
8784 7 ENTER;
8785 7 SAVETMPS;
8786 7 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 7 0 7
8787 7 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 7 7
8788 7 ▶ XPUSHs(source ? source : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(source ? source : &PL_sv_undef); 0 7 7
XPUSHs(source ? source : &PL_sv_undef); 7 0 7
8789 7 PUTBACK;
8790 7 count = call_sv((SV *)method_cv, G_SCALAR | G_EVAL);
8791 7 SPAGAIN;
8792 7 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 7 0 7
if (SvTRUE(ERRSV)) { 1 6 7
8793 1 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 1 0 1
8794 1 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 1 0 1
8795 1 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 1 0 1
8796 1 *error_out = err;
8797 1 err = NULL;
8798 }
8799 1 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 0 1 1
8800 0 croak_sv(err);
8801 }
8802 }
8803 7 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 7 0 7
8804 7 ret = newSVsv(POPs);
8805 }
8806 7 PUTBACK;
8807 7 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 7 0 7
8808 7 LEAVE;
8809 7 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 7 7
8810 }
8811  
8812 static SV *
8813 2 gql_runtime_vm_call_cb3_nonfatal(pTHX_ SV *cb, SV *arg0, SV *arg1, SV *arg2, SV **error_out)
8814 {
8815 2 dSP;
8816 2 SV *ret = NULL;
8817 int count;
8818  
8819 2 ENTER;
8820 2 SAVETMPS;
8821 2 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 2 0 2
8822 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
8823 2 ▶ XPUSHs(arg0 ? arg0 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg0 ? arg0 : &PL_sv_undef); 0 2 2
XPUSHs(arg0 ? arg0 : &PL_sv_undef); 2 0 2
8824 2 ▶ XPUSHs(arg1 ? arg1 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg1 ? arg1 : &PL_sv_undef); 0 2 2
XPUSHs(arg1 ? arg1 : &PL_sv_undef); 2 0 2
8825 2 ▶ XPUSHs(arg2 ? arg2 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg2 ? arg2 : &PL_sv_undef); 0 2 2
XPUSHs(arg2 ? arg2 : &PL_sv_undef); 2 0 2
8826 2 PUTBACK;
8827 2 count = call_sv(cb, G_SCALAR | G_EVAL);
8828 2 SPAGAIN;
8829 2 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 2 0 2
if (SvTRUE(ERRSV)) { 0 2 2
8830 0 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 0 0 0
8831 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
8832 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
8833 0 *error_out = err;
8834 0 err = NULL;
8835 }
8836 0 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 0 0 0
8837 0 croak_sv(err);
8838 }
8839 }
8840 2 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 2 0 2
8841 2 ret = newSVsv(POPs);
8842 }
8843 2 PUTBACK;
8844 2 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2 0 2
8845 2 LEAVE;
8846 2 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 2 2
8847 }
8848  
8849 static SV *
8850 172 gql_runtime_vm_call_cb4_nonfatal(pTHX_ SV *cb, SV *arg0, SV *arg1, SV *arg2, SV *arg3, SV **error_out)
8851 {
8852 172 dSP;
8853 172 SV *ret = NULL;
8854 int count;
8855  
8856 172 ENTER;
8857 172 SAVETMPS;
8858 172 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 172 0 172
8859 172 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 172 172
8860 172 ▶ XPUSHs(arg0 ? arg0 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg0 ? arg0 : &PL_sv_undef); 0 172 172
XPUSHs(arg0 ? arg0 : &PL_sv_undef); 172 0 172
8861 172 ▶ XPUSHs(arg1 ? arg1 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg1 ? arg1 : &PL_sv_undef); 0 172 172
XPUSHs(arg1 ? arg1 : &PL_sv_undef); 172 0 172
8862 172 ▶ XPUSHs(arg2 ? arg2 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg2 ? arg2 : &PL_sv_undef); 0 172 172
XPUSHs(arg2 ? arg2 : &PL_sv_undef); 172 0 172
8863 172 ▶ XPUSHs(arg3 ? arg3 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg3 ? arg3 : &PL_sv_undef); 0 172 172
XPUSHs(arg3 ? arg3 : &PL_sv_undef); 172 0 172
8864 172 PUTBACK;
8865 172 count = call_sv(cb, G_SCALAR | G_EVAL);
8866 172 SPAGAIN;
8867 172 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 172 0 172
if (SvTRUE(ERRSV)) { 1 171 172
8868 1 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 1 0 1
8869 1 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 1 0 1
8870 1 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 1 0 1
8871 1 *error_out = err;
8872 1 err = NULL;
8873 }
8874 1 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 0 1 1
8875 0 croak_sv(err);
8876 }
8877 }
8878 172 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 172 0 172
8879 172 ret = newSVsv(POPs);
8880 }
8881 172 PUTBACK;
8882 172 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 172 0 172
8883 172 LEAVE;
8884 172 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 172 172
8885 }
8886  
8887 static SV *
8888 10807 gql_runtime_vm_call_cb5_nonfatal(pTHX_ SV *cb, SV *arg0, SV *arg1, SV *arg2, SV *arg3, SV *arg4, SV **error_out)
8889 {
8890 10807 dSP;
8891 10807 SV *ret = NULL;
8892 int count;
8893  
8894 10807 ENTER;
8895 10807 SAVETMPS;
8896 10807 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 10807 0 10807
8897 10807 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 10807 10807
8898 10807 ▶ XPUSHs(arg0 ? arg0 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg0 ? arg0 : &PL_sv_undef); 0 10807 10807
XPUSHs(arg0 ? arg0 : &PL_sv_undef); 10807 0 10807
8899 10807 ▶ XPUSHs(arg1 ? arg1 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg1 ? arg1 : &PL_sv_undef); 0 10807 10807
XPUSHs(arg1 ? arg1 : &PL_sv_undef); 10807 0 10807
8900 10807 ▶ XPUSHs(arg2 ? arg2 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg2 ? arg2 : &PL_sv_undef); 0 10807 10807
XPUSHs(arg2 ? arg2 : &PL_sv_undef); 10807 0 10807
8901 10807 ▶ XPUSHs(arg3 ? arg3 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg3 ? arg3 : &PL_sv_undef); 0 10807 10807
XPUSHs(arg3 ? arg3 : &PL_sv_undef); 10807 0 10807
8902 10807 ▶ XPUSHs(arg4 ? arg4 : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(arg4 ? arg4 : &PL_sv_undef); 0 10807 10807
XPUSHs(arg4 ? arg4 : &PL_sv_undef); 10807 0 10807
8903 10807 PUTBACK;
8904 10807 count = call_sv(cb, G_SCALAR | G_EVAL);
8905 10807 SPAGAIN;
8906 10807 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 10807 0 10807
if (SvTRUE(ERRSV)) { 443 10364 10807
8907 443 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 443 0 443
8908 443 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 443 0 443
8909 443 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 443 0 443
8910 443 *error_out = err;
8911 443 err = NULL;
8912 }
8913 443 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 0 443 443
8914 0 croak_sv(err);
8915 }
8916 }
8917 10807 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 10807 0 10807
8918 10807 ret = newSVsv(POPs);
8919 }
8920 10807 PUTBACK;
8921 10807 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 10807 0 10807
8922 10807 LEAVE;
8923 10807 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 10807 10807
8924 }
8925  
8926 static SV *
8927 2 gql_runtime_vm_cached_cv(pTHX_ const char *name)
8928 {
8929 2 ▶ STRLEN len = name ? strlen(name) : 0;
Branch: 1 branch
BranchTrueFalseTotal
STRLEN len = name ? strlen(name) : 0; 2 0 2
8930 2 ▶ return name ? (SV *)get_cvn_flags(name, len, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return name ? (SV *)get_cvn_flags(name, len, 0) : NULL; 2 0 2
8931 }
8932  
8933 static CV *
8934 5 gql_runtime_vm_directive_runtime_apply_cv(pTHX)
8935 {
8936 static CV *cv = NULL;
8937 5 ▶ if (!cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!cv) { 2 3 5
8938 2 cv = (CV *)gql_runtime_vm_cached_cv(aTHX_ "GraphQL::Houtou::Runtime::DirectiveRuntime::apply_runtime_directives");
8939 }
8940 5 return cv;
8941 }
8942  
8943 static CV *
8944 0 gql_runtime_vm_directive_runtime_materialize_cv(pTHX)
8945 {
8946 static CV *cv = NULL;
8947 0 ▶ if (!cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!cv) { 0 0 0
8948 0 cv = (CV *)gql_runtime_vm_cached_cv(aTHX_ "GraphQL::Houtou::Runtime::DirectiveRuntime::materialize_runtime_directives");
8949 }
8950 0 return cv;
8951 }
8952  
8953 static CV *
8954 0 gql_runtime_vm_directive_runtime_program_materialize_cv(pTHX)
8955 {
8956 static CV *cv = NULL;
8957 0 ▶ if (!cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!cv) { 0 0 0
8958 0 cv = (CV *)gql_runtime_vm_cached_cv(aTHX_ "GraphQL::Houtou::Runtime::DirectiveRuntime::materialize_program_runtime_directives");
8959 }
8960 0 return cv;
8961 }
8962  
8963 static SV *
8964 0 gql_runtime_vm_materialize_runtime_directives_sv(pTHX_ SV *payload, SV *variables)
8965 {
8966 0 dSP;
8967 0 SV *ret = NULL;
8968 int count;
8969  
8970 0 ▶ if (!payload || !SvOK(payload)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!payload || !SvOK(payload)) { 0 0 0
if (!payload || !SvOK(payload)) { 0 0 0
8971 0 return newRV_noinc((SV *)newAV());
8972 }
8973  
8974 0 ENTER;
8975 0 SAVETMPS;
8976 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
8977 0 ▶ XPUSHs(payload);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(payload); 0 0 0
8978 0 ▶ XPUSHs(variables ? variables : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(variables ? variables : &PL_sv_undef); 0 0 0
XPUSHs(variables ? variables : &PL_sv_undef); 0 0 0
8979 0 PUTBACK;
8980 0 count = call_sv((SV *)gql_runtime_vm_directive_runtime_materialize_cv(aTHX), G_SCALAR | G_EVAL);
8981 0 SPAGAIN;
8982 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
8983 0 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 0 0 0
8984 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
8985 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
8986 0 LEAVE;
8987 0 croak_sv(err);
8988 }
8989 0 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 0 0 0
8990 0 ret = newSVsv(POPs);
8991 }
8992 0 PUTBACK;
8993 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
8994 0 LEAVE;
8995 0 ▶ return ret ? ret : newRV_noinc((SV *)newAV());
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newRV_noinc((SV *)newAV()); 0 0 0
8996 }
8997  
8998 static SV *
8999 0 gql_runtime_vm_program_runtime_directives_sv(
9000 pTHX_
9001 SV *program,
9002 IV block_index,
9003 IV op_index,
9004 SV *variables
9005 )
9006 {
9007 0 dSP;
9008 0 SV *ret = NULL;
9009 int count;
9010  
9011 0 ▶ if (!program || !SvOK(program) || block_index < 0 || op_index < 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (!program || !SvOK(program) || block_index < 0 || op_index < 0) { 0 0 0
if (!program || !SvOK(program) || block_index < 0 || op_index < 0) { 0 0 0
if (!program || !SvOK(program) || block_index < 0 || op_index < 0) { 0 0 0
if (!program || !SvOK(program) || block_index < 0 || op_index < 0) { 0 0 0
9012 0 return newRV_noinc((SV *)newAV());
9013 }
9014  
9015 0 ENTER;
9016 0 SAVETMPS;
9017 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
9018 0 ▶ XPUSHs(program);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(program); 0 0 0
9019 0 ▶ XPUSHs(sv_2mortal(newSViv(block_index)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(block_index))); 0 0 0
9020 0 ▶ XPUSHs(sv_2mortal(newSViv(op_index)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(op_index))); 0 0 0
9021 0 ▶ XPUSHs(variables ? variables : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(variables ? variables : &PL_sv_undef); 0 0 0
XPUSHs(variables ? variables : &PL_sv_undef); 0 0 0
9022 0 PUTBACK;
9023 0 count = call_sv((SV *)gql_runtime_vm_directive_runtime_program_materialize_cv(aTHX), G_SCALAR | G_EVAL);
9024 0 SPAGAIN;
9025 0 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 0 0 0
if (SvTRUE(ERRSV)) { 0 0 0
9026 0 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 0 0 0
9027 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
9028 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
9029 0 LEAVE;
9030 0 croak_sv(err);
9031 }
9032 0 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 0 0 0
9033 0 ret = newSVsv(POPs);
9034 }
9035 0 PUTBACK;
9036 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
9037 0 LEAVE;
9038 0 ▶ return ret ? ret : newRV_noinc((SV *)newAV());
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newRV_noinc((SV *)newAV()); 0 0 0
9039 }
9040  
9041 static SV *
9042 5 gql_runtime_vm_apply_runtime_directives_nonfatal(
9043 pTHX_
9044 gql_runtime_vm_exec_state_t *state,
9045 SV *source,
9046 SV *resolved,
9047 SV **error_out
9048 )
9049 {
9050 5 dSP;
9051 5 SV *ret = NULL;
9052 5 SV *runtime_schema_sv = &PL_sv_undef;
9053 5 SV *context_sv = &PL_sv_undef;
9054 5 SV *return_type_sv = NULL;
9055 5 SV *args_sv = NULL;
9056 5 SV *info_sv = NULL;
9057 int count;
9058  
9059 5 ▶ if (!state || !state->op || (!state->op->has_runtime_directives && !state->op->runtime_directives_sv)) {
Branch: 4 branches
BranchTrueFalseTotal
if (!state || !state->op || (!state->op->has_runtime_directives && !state->op->runtime_directives_sv)) { 5 0 5
if (!state || !state->op || (!state->op->has_runtime_directives && !state->op->runtime_directives_sv)) { 5 0 5
if (!state || !state->op || (!state->op->has_runtime_directives && !state->op->runtime_directives_sv)) { 0 5 5
if (!state || !state->op || (!state->op->has_runtime_directives && !state->op->runtime_directives_sv)) { 0 0 0
9060 0 ▶ return newSVsv(resolved ? resolved : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return newSVsv(resolved ? resolved : &PL_sv_undef); 0 0 0
9061 }
9062  
9063 5 ▶ if (state->callback_ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->callback_ctx) { 5 0 5
9064 5 ▶ if (state->callback_ctx->runtime_schema && SvOK(state->callback_ctx->runtime_schema)) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->callback_ctx->runtime_schema && SvOK(state->callback_ctx->runtime_schema)) { 5 0 5
if (state->callback_ctx->runtime_schema && SvOK(state->callback_ctx->runtime_schema)) { 5 0 5
9065 5 runtime_schema_sv = state->callback_ctx->runtime_schema;
9066 }
9067 5 ▶ if (state->callback_ctx->context && SvOK(state->callback_ctx->context)) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->callback_ctx->context && SvOK(state->callback_ctx->context)) { 5 0 5
if (state->callback_ctx->context && SvOK(state->callback_ctx->context)) { 0 5 5
9068 0 context_sv = state->callback_ctx->context;
9069 }
9070 }
9071 5 ▶ if (runtime_schema_sv == &PL_sv_undef
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_schema_sv == &PL_sv_undef 0 5 5
9072 0 ▶ && state->runtime
Branch: 1 branch
BranchTrueFalseTotal
&& state->runtime 0 0 0
9073 0 ▶ && state->runtime->callback_catalog
Branch: 1 branch
BranchTrueFalseTotal
&& state->runtime->callback_catalog 0 0 0
9074 0 ▶ && state->runtime->callback_catalog->runtime_schema
Branch: 1 branch
BranchTrueFalseTotal
&& state->runtime->callback_catalog->runtime_schema 0 0 0
9075 0 ▶ && SvOK(state->runtime->callback_catalog->runtime_schema)) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvOK(state->runtime->callback_catalog->runtime_schema)) { 0 0 0
9076 0 runtime_schema_sv = state->runtime->callback_catalog->runtime_schema;
9077 }
9078  
9079 5 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(state->runtime, state->slot);
9080 5 ▶ if (!return_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!return_type_sv) { 0 5 5
9081 0 return_type_sv = gql_runtime_vm_lookup_slot_type_object_sv(
9082 aTHX_
9083 0 state->runtime,
9084 runtime_schema_sv,
9085 state->slot
9086 );
9087 }
9088  
9089 5 ENTER;
9090 5 SAVETMPS;
9091 5 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 5 0 5
9092 5 args_sv = gql_runtime_vm_build_current_args_sv(aTHX_ state);
9093 5 ▶ if (!args_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!args_sv) { 0 5 5
9094 /* Argument coercion failed and armed the deferred croak channel:
9095 * skip the directive application, the response is discarded anyway. */
9096 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
9097 0 LEAVE;
9098 0 ▶ return newSVsv(resolved ? resolved : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return newSVsv(resolved ? resolved : &PL_sv_undef); 0 0 0
9099 }
9100 5 args_sv = sv_2mortal(args_sv);
9101 5 info_sv = sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state));
9102 5 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 5 5
9103 5 ▶ XPUSHs(runtime_schema_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(runtime_schema_sv); 0 5 5
9104 5 ▶ XPUSHs(source ? source : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(source ? source : &PL_sv_undef); 0 5 5
XPUSHs(source ? source : &PL_sv_undef); 5 0 5
9105 5 ▶ XPUSHs(args_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(args_sv); 0 5 5
9106 5 ▶ XPUSHs(context_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(context_sv); 0 5 5
9107 5 ▶ XPUSHs(info_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(info_sv); 0 5 5
9108 5 ▶ XPUSHs(return_type_sv ? return_type_sv : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(return_type_sv ? return_type_sv : &PL_sv_undef); 0 5 5
XPUSHs(return_type_sv ? return_type_sv : &PL_sv_undef); 5 0 5
9109 5 ▶ XPUSHs(resolved ? resolved : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(resolved ? resolved : &PL_sv_undef); 0 5 5
XPUSHs(resolved ? resolved : &PL_sv_undef); 5 0 5
9110 5 PUTBACK;
9111 5 count = call_sv((SV *)gql_runtime_vm_directive_runtime_apply_cv(aTHX), G_SCALAR | G_EVAL);
9112 5 SPAGAIN;
9113 5 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 5 0 5
if (SvTRUE(ERRSV)) { 0 5 5
9114 0 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 0 0 0
9115 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
9116 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
9117 0 *error_out = err;
9118 0 err = NULL;
9119 }
9120 0 ▶ if (err) {
Branch: 1 branch
BranchTrueFalseTotal
if (err) { 0 0 0
9121 0 croak_sv(err);
9122 }
9123 }
9124 5 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 5 0 5
9125 5 ret = newSVsv(POPs);
9126 }
9127 5 PUTBACK;
9128 5 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 5 0 5
9129 5 LEAVE;
9130 5 ▶ return ret ? ret : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return ret ? ret : newSVsv(&PL_sv_undef); 0 5 5
9131 }
9132  
9133 static int
9134 12824 gql_runtime_vm_slot_uses_native_fast_abi(const gql_runtime_vm_native_slot_t *slot)
9135 {
9136 return slot
9137 25549 ▶ && (slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE
Branch: 2 branches
BranchTrueFalseTotal
&& (slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE 12824 0 12824
&& (slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE 12725 99 12824
9138 12725 ▶ || slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS
Branch: 1 branch
BranchTrueFalseTotal
|| slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS 12724 1 12725
9139 12724 ▶ || slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG);
Branch: 1 branch
BranchTrueFalseTotal
|| slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG); 4 12720 12724
9140 }
9141  
9142 static int
9143 10864 gql_runtime_vm_slot_uses_native_no_args_abi(const gql_runtime_vm_native_slot_t *slot)
9144 {
9145 return slot
9146 10864 ▶ && slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS;
Branch: 2 branches
BranchTrueFalseTotal
&& slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS; 10864 0 10864
&& slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS; 2 10862 10864
9147 }
9148  
9149 static int
9150 10862 gql_runtime_vm_slot_uses_native_one_arg_abi(const gql_runtime_vm_native_slot_t *slot)
9151 {
9152 return slot
9153 10862 ▶ && slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG;
Branch: 2 branches
BranchTrueFalseTotal
&& slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG; 10862 0 10862
&& slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG; 6 10856 10862
9154 }
9155  
9156 static int
9157 0 gql_runtime_vm_slot_uses_explicit_generic_fast_abi(const gql_runtime_vm_native_slot_t *slot)
9158 {
9159 0 ▶ return slot && slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_GENERIC;
Branch: 2 branches
BranchTrueFalseTotal
return slot && slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_GENERIC; 0 0 0
return slot && slot->callback_abi_code == GQL_VM_CALLBACK_ABI_EXPLICIT_GENERIC; 0 0 0
9160 }
9161  
9162 static SV *
9163 382 gql_runtime_vm_slot_resolver_sv(
9164 const gql_runtime_vm_native_runtime_t *runtime,
9165 const gql_runtime_vm_native_slot_t *slot
9166 )
9167 {
9168 382 ▶ if (!runtime || !slot) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime || !slot) { 382 0 382
if (!runtime || !slot) { 0 382 382
9169 0 return NULL;
9170 }
9171 382 ▶ if (slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 382 0 382
if (slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 0 382 382
9172 0 return NULL;
9173 }
9174 382 ▶ if (!runtime->callback_catalog || !runtime->callback_catalog->slot_resolvers) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime->callback_catalog || !runtime->callback_catalog->slot_resolvers) { 382 0 382
if (!runtime->callback_catalog || !runtime->callback_catalog->slot_resolvers) { 0 382 382
9175 0 return NULL;
9176 }
9177 382 return runtime->callback_catalog->slot_resolvers[slot->schema_slot_index];
9178 }
9179  
9180 static gql_runtime_vm_path_frame_t *
9181 11640 gql_runtime_vm_new_result_path_frame(
9182 pTHX_
9183 gql_runtime_vm_path_frame_t *parent,
9184 const gql_runtime_vm_native_slot_t *slot
9185 )
9186 {
9187 11640 ▶ if (slot && slot->result_name) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot && slot->result_name) { 11640 0 11640
if (slot && slot->result_name) { 11640 0 11640
9188 11640 return gql_runtime_vm_new_path_frame_struct_pvn_borrowed(
9189 aTHX_
9190 parent,
9191 11640 slot->result_name,
9192 11640 slot->result_name_len
9193 );
9194 }
9195 0 return gql_runtime_vm_new_path_frame_struct(aTHX_ parent, &PL_sv_undef);
9196 }
9197  
9198 static int
9199 1658 gql_runtime_vm_slot_can_delay_field_path(
9200 const gql_runtime_vm_native_runtime_t *runtime,
9201 const gql_runtime_vm_native_slot_t *slot,
9202 const gql_runtime_vm_native_op_t *op
9203 )
9204 {
9205 1658 ▶ if (!slot || !op) {
Branch: 2 branches
BranchTrueFalseTotal
if (!slot || !op) { 1658 0 1658
if (!slot || !op) { 0 1658 1658
9206 0 return 0;
9207 }
9208 1658 ▶ if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) { 45 1613 1658
9209 45 return 1;
9210 }
9211 1613 ▶ if (op->complete_code == GQL_VM_COMPLETE_ABSTRACT) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->complete_code == GQL_VM_COMPLETE_ABSTRACT) { 16 1597 1613
9212 16 return 0;
9213 }
9214 1597 ▶ if (slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT) {
Branch: 1 branch
BranchTrueFalseTotal
if (slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT) { 1287 310 1597
9215 1287 return 0;
9216 }
9217 310 return gql_runtime_vm_slot_resolver_sv(runtime, slot) ? 0 : 1;
9218 }
9219  
9220 static SV *
9221 309 gql_runtime_vm_lookup_type_object_by_name_sv(pTHX_ SV *runtime_schema, const char *type_name)
9222 {
9223 HV *runtime_cache_hv;
9224 SV *name2type_sv;
9225 HV *name2type_hv;
9226 SV **svp;
9227  
9228 309 ▶ if (!runtime_schema || !SvOK(runtime_schema) || !type_name || !*type_name) {
Branch: 4 branches
BranchTrueFalseTotal
if (!runtime_schema || !SvOK(runtime_schema) || !type_name || !*type_name) { 309 0 309
if (!runtime_schema || !SvOK(runtime_schema) || !type_name || !*type_name) { 309 0 309
if (!runtime_schema || !SvOK(runtime_schema) || !type_name || !*type_name) { 309 0 309
if (!runtime_schema || !SvOK(runtime_schema) || !type_name || !*type_name) { 0 309 309
9229 0 return NULL;
9230 }
9231 309 runtime_cache_hv = gql_runtime_vm_fetch_runtime_cache_hv(aTHX_ runtime_schema);
9232 309 ▶ if (!runtime_cache_hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime_cache_hv) { 0 309 309
9233 0 return NULL;
9234 }
9235 309 name2type_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "name2type", 9);
9236 309 ▶ if (!name2type_sv || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!name2type_sv || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 309 0 309
if (!name2type_sv || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 309 0 309
if (!name2type_sv || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 0 309 309
9237 0 return NULL;
9238 }
9239 309 name2type_hv = (HV *)SvRV(name2type_sv);
9240 309 svp = hv_fetch(name2type_hv, type_name, (I32)strlen(type_name), 0);
9241 309 ▶ return (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
return (svp && SvOK(*svp)) ? *svp : NULL; 309 0 309
return (svp && SvOK(*svp)) ? *svp : NULL; 309 0 309
9242 }
9243  
9244 static void
9245 395 gql_runtime_vm_prepare_bundle_block_type_objects(
9246 pTHX_
9247 SV *runtime_schema,
9248 gql_runtime_vm_native_bundle_t *bundle
9249 )
9250 {
9251 IV i;
9252  
9253 395 ▶ if (!runtime_schema || !SvOK(runtime_schema) || !bundle || !bundle->blocks) {
Branch: 4 branches
BranchTrueFalseTotal
if (!runtime_schema || !SvOK(runtime_schema) || !bundle || !bundle->blocks) { 395 0 395
if (!runtime_schema || !SvOK(runtime_schema) || !bundle || !bundle->blocks) { 395 0 395
if (!runtime_schema || !SvOK(runtime_schema) || !bundle || !bundle->blocks) { 395 0 395
if (!runtime_schema || !SvOK(runtime_schema) || !bundle || !bundle->blocks) { 0 395 395
9254 0 return;
9255 }
9256  
9257 395 ▶ if (bundle->prepared_runtime_schema == runtime_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->prepared_runtime_schema == runtime_schema) { 274 121 395
9258 274 return;
9259 }
9260  
9261 121 ▶ if (bundle->prepared_runtime_schema && bundle->prepared_runtime_schema != runtime_schema) {
Branch: 2 branches
BranchTrueFalseTotal
if (bundle->prepared_runtime_schema && bundle->prepared_runtime_schema != runtime_schema) { 0 121 121
if (bundle->prepared_runtime_schema && bundle->prepared_runtime_schema != runtime_schema) { 0 0 0
9262 0 ▶ for (i = 0; i < bundle->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bundle->block_count; i++) { 0 0 0
9263 0 gql_runtime_vm_native_block_t *block = &bundle->blocks[i];
9264 0 ▶ if (block->type_object_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (block->type_object_sv) { 0 0 0
9265 0 SvREFCNT_dec(block->type_object_sv);
9266 0 block->type_object_sv = NULL;
9267 }
9268 }
9269 0 SvREFCNT_dec(bundle->prepared_runtime_schema);
9270 0 bundle->prepared_runtime_schema = NULL;
9271 }
9272  
9273 388 ▶ for (i = 0; i < bundle->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bundle->block_count; i++) { 267 121 388
9274 267 gql_runtime_vm_native_block_t *block = &bundle->blocks[i];
9275 SV *type_sv;
9276  
9277 267 ▶ if (block->type_object_sv || !block->type_name || !*block->type_name) {
Branch: 3 branches
BranchTrueFalseTotal
if (block->type_object_sv || !block->type_name || !*block->type_name) { 267 0 267
if (block->type_object_sv || !block->type_name || !*block->type_name) { 267 0 267
if (block->type_object_sv || !block->type_name || !*block->type_name) { 0 267 267
9278 0 continue;
9279 }
9280 267 type_sv = gql_runtime_vm_lookup_type_object_by_name_sv(aTHX_ runtime_schema, block->type_name);
9281 267 ▶ if (type_sv && SvOK(type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (type_sv && SvOK(type_sv)) { 267 0 267
if (type_sv && SvOK(type_sv)) { 267 0 267
9282 267 block->type_object_sv = SvREFCNT_inc_simple_NN(type_sv);
9283 }
9284 }
9285  
9286 121 bundle->prepared_runtime_schema = SvREFCNT_inc_simple_NN(runtime_schema);
9287 }
9288  
9289 static SV *
9290 0 gql_runtime_vm_lookup_slot_type_object_sv(
9291 pTHX_
9292 const gql_runtime_vm_native_runtime_t *runtime,
9293 SV *runtime_schema,
9294 const gql_runtime_vm_native_slot_t *slot
9295 )
9296 {
9297 IV slot_index;
9298  
9299 0 ▶ if (!runtime || !slot) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime || !slot) { 0 0 0
if (!runtime || !slot) { 0 0 0
9300 0 return NULL;
9301 }
9302  
9303 0 slot_index = slot->schema_slot_index;
9304 0 ▶ if (slot_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (slot_index >= 0 0 0 0
9305 0 ▶ && slot_index < runtime->runtime_slot_count
Branch: 1 branch
BranchTrueFalseTotal
&& slot_index < runtime->runtime_slot_count 0 0 0
9306 0 ▶ && runtime->callback_catalog
Branch: 1 branch
BranchTrueFalseTotal
&& runtime->callback_catalog 0 0 0
9307 0 ▶ && runtime->callback_catalog->slot_type_objects
Branch: 1 branch
BranchTrueFalseTotal
&& runtime->callback_catalog->slot_type_objects 0 0 0
9308 0 ▶ && runtime->callback_catalog->slot_type_objects[slot_index]
Branch: 1 branch
BranchTrueFalseTotal
&& runtime->callback_catalog->slot_type_objects[slot_index] 0 0 0
9309 0 ▶ && SvOK(runtime->callback_catalog->slot_type_objects[slot_index])) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvOK(runtime->callback_catalog->slot_type_objects[slot_index])) { 0 0 0
9310 0 return runtime->callback_catalog->slot_type_objects[slot_index];
9311 }
9312  
9313 0 ▶ if (slot->return_type_name && *slot->return_type_name) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot->return_type_name && *slot->return_type_name) { 0 0 0
if (slot->return_type_name && *slot->return_type_name) { 0 0 0
9314 0 return gql_runtime_vm_lookup_type_object_by_name_sv(
9315 aTHX_ runtime_schema,
9316 0 slot->return_type_name
9317 );
9318 }
9319  
9320 0 return NULL;
9321 }
9322  
9323 static SV *
9324 9967 gql_runtime_vm_callback_variables_sv(
9325 pTHX_ gql_runtime_vm_callback_context_t *ctx
9326 )
9327 {
9328 HV *variables_hv;
9329 IV i;
9330  
9331 9967 ▶ if (!ctx) {
Branch: 1 branch
BranchTrueFalseTotal
if (!ctx) { 0 9967 9967
9332 0 return &PL_sv_undef;
9333 }
9334 9967 ▶ if (ctx->variables
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->variables 9967 0 9967
9335 9967 ▶ && SvROK(ctx->variables)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(ctx->variables) 9848 119 9967
9336 9848 ▶ && SvTYPE(SvRV(ctx->variables)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(ctx->variables)) == SVt_PVHV) { 6605 3243 9848
9337 6605 return ctx->variables;
9338 }
9339 3362 ▶ if (ctx->materialized_variables) {
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->materialized_variables) { 3000 362 3362
9340 3000 return ctx->materialized_variables;
9341 }
9342  
9343 362 variables_hv = newHV();
9344 362 ▶ if (ctx->native_program && ctx->variable_slots) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->native_program && ctx->variable_slots) { 324 38 362
if (ctx->native_program && ctx->variable_slots) { 248 76 324
9345 707 ▶ for (i = 0; i < ctx->native_program->variable_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ctx->native_program->variable_def_count; i++) { 459 248 707
9346 459 const gql_runtime_vm_native_arg_def_t *arg_def =
9347 459 &ctx->native_program->variable_defs[i];
9348 459 ▶ SV *value = i < ctx->variable_slot_count ? ctx->variable_slots[i] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *value = i < ctx->variable_slot_count ? ctx->variable_slots[i] : NULL; 459 0 459
9349 459 ▶ if (!arg_def->name || !value) {
Branch: 2 branches
BranchTrueFalseTotal
if (!arg_def->name || !value) { 459 0 459
if (!arg_def->name || !value) { 2 457 459
9350 2 continue;
9351 }
9352 457 hv_store(
9353 variables_hv,
9354 arg_def->name,
9355 (I32)strlen(arg_def->name),
9356 newSVsv(value),
9357 0
9358 );
9359 }
9360 }
9361 362 ▶ if (ctx->provided_variables
Branch: 1 branch
BranchTrueFalseTotal
if (ctx->provided_variables 324 38 362
9362 324 ▶ && SvROK(ctx->provided_variables)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(ctx->provided_variables) 324 0 324
9363 324 ▶ && SvTYPE(SvRV(ctx->provided_variables)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(ctx->provided_variables)) == SVt_PVHV) { 324 0 324
9364 324 HV *provided_hv = (HV *)SvRV(ctx->provided_variables);
9365 HE *he;
9366 324 hv_iterinit(provided_hv);
9367 782 ▶ while ((he = hv_iternext(provided_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(provided_hv))) { 458 324 782
9368 458 SV *key_sv = hv_iterkeysv(he);
9369 458 SV *value_sv = hv_iterval(provided_hv, he);
9370 458 STRLEN key_len = 0;
9371 const char *key_pv;
9372 458 ▶ if (!key_sv || !SvOK(key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!key_sv || !SvOK(key_sv)) { 458 0 458
if (!key_sv || !SvOK(key_sv)) { 0 458 458
9373 0 continue;
9374 }
9375 458 key_pv = SvPV(key_sv, key_len);
9376 458 ▶ if (!hv_exists(variables_hv, key_pv, (I32)key_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_exists(variables_hv, key_pv, (I32)key_len)) { 2 456 458
9377 2 hv_store(variables_hv, key_pv, (I32)key_len, newSVsv(value_sv), 0);
9378 }
9379 }
9380 }
9381 362 ctx->materialized_variables = newRV_noinc((SV *)variables_hv);
9382 362 return ctx->materialized_variables;
9383 }
9384  
9385 static int
9386 5030 gql_runtime_vm_args_payload_needs_variables_hv(
9387 const gql_runtime_vm_native_args_payload_t *payload
9388 )
9389 {
9390 IV i;
9391 5030 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 5030 5030
9392 0 return 0;
9393 }
9394 10061 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 5035 5026 10061
9395 5035 const gql_runtime_vm_native_dynamic_value_t *value =
9396 5035 ▶ payload->values ? payload->values[i] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
payload->values ? payload->values[i] : NULL; 5035 0 5035
9397 5035 ▶ if (value
Branch: 1 branch
BranchTrueFalseTotal
if (value 5035 0 5035
9398 5035 ▶ && (value->kind_code != GQL_VM_DYNAMIC_VARIABLE
Branch: 1 branch
BranchTrueFalseTotal
&& (value->kind_code != GQL_VM_DYNAMIC_VARIABLE 5031 4 5035
9399 5031 ▶ || value->variable_index < 0)) {
Branch: 1 branch
BranchTrueFalseTotal
|| value->variable_index < 0)) { 0 5031 5031
9400 4 return 1;
9401 }
9402 }
9403 5026 return 0;
9404 }
9405  
9406 static SV *
9407 315 gql_runtime_vm_execute_bundle_fast_response_with_slots_sv(
9408 pTHX_
9409 gql_runtime_vm_native_runtime_t *runtime,
9410 SV *runtime_schema,
9411 gql_runtime_vm_native_bundle_t *bundle,
9412 SV *root_value,
9413 SV *context_value,
9414 SV *variables,
9415 SV **variable_slots,
9416 IV variable_slot_count,
9417 gql_runtime_vm_native_program_t *native_program,
9418 SV *provided_variables
9419 )
9420 {
9421 gql_runtime_vm_exec_state_t state;
9422 gql_runtime_vm_callback_context_t callback_ctx;
9423 gql_runtime_vm_writer_t writer_storage;
9424 SV *data_sv;
9425 SV *empty_args_sv;
9426 SV *response_sv;
9427  
9428 315 Zero(&state, 1, gql_runtime_vm_exec_state_t);
9429 315 Zero(&callback_ctx, 1, gql_runtime_vm_callback_context_t);
9430  
9431 315 state.runtime = runtime;
9432 315 state.bundle = bundle;
9433 315 ▶ callback_ctx.runtime_schema = runtime_schema ? runtime_schema : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
callback_ctx.runtime_schema = runtime_schema ? runtime_schema : &PL_sv_undef; 315 0 315
9434 315 callback_ctx.root_value = root_value;
9435 315 callback_ctx.context = context_value;
9436 315 callback_ctx.variables = variables;
9437 315 callback_ctx.variable_slots = variable_slots;
9438 315 callback_ctx.variable_slot_count = variable_slot_count;
9439 315 callback_ctx.native_program = native_program;
9440 315 callback_ctx.provided_variables = provided_variables;
9441 315 state.callback_ctx = &callback_ctx;
9442 315 gql_runtime_vm_prepare_bundle_block_type_objects(aTHX_ callback_ctx.runtime_schema, bundle);
9443  
9444 315 gql_runtime_vm_init_writer_struct(&writer_storage);
9445 315 state.writer = &writer_storage;
9446 315 state.path_frame = NULL;
9447 315 empty_args_sv = gql_runtime_vm_empty_args_sv(aTHX);
9448 315 state.empty_args_sv = empty_args_sv;
9449  
9450 315 data_sv = gql_runtime_vm_execute_block_fast_sv(
9451 aTHX_
9452 &state,
9453 bundle->root_block_index,
9454 root_value
9455 );
9456  
9457 315 response_sv = gql_runtime_vm_fast_response_sv(aTHX_ data_sv, &writer_storage);
9458 315 SvREFCNT_dec(empty_args_sv);
9459 315 gql_runtime_vm_clear_writer_struct(aTHX_ &writer_storage);
9460 315 SvREFCNT_dec(callback_ctx.materialized_variables);
9461 315 ▶ if (state.fast_lane_deferred_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state.fast_lane_deferred_croak_sv) { 9 306 315
9462 /* Deferred from mid-lane so the path frame chain unwound normally. */
9463 9 SvREFCNT_dec(response_sv);
9464 9 croak_sv(sv_2mortal(state.fast_lane_deferred_croak_sv));
9465 }
9466 306 return response_sv;
9467 }
9468  
9469 static SV *
9470 31 gql_runtime_vm_execute_bundle_fast_response_sv(
9471 pTHX_
9472 gql_runtime_vm_native_runtime_t *runtime,
9473 SV *runtime_schema,
9474 gql_runtime_vm_native_bundle_t *bundle,
9475 SV *root_value,
9476 SV *context_value,
9477 SV *variables
9478 )
9479 {
9480 31 return gql_runtime_vm_execute_bundle_fast_response_with_slots_sv(
9481 aTHX_
9482 runtime,
9483 runtime_schema,
9484 bundle,
9485 root_value,
9486 context_value,
9487 variables,
9488 NULL,
9489 0,
9490 NULL,
9491 NULL
9492 );
9493 }
9494  
9495 static SV *
9496 21958 gql_runtime_vm_direct_slot_type_object_sv(
9497 const gql_runtime_vm_native_runtime_t *runtime,
9498 const gql_runtime_vm_native_slot_t *slot
9499 )
9500 {
9501 IV slot_index;
9502  
9503 21958 ▶ if (!runtime || !slot) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime || !slot) { 21958 0 21958
if (!runtime || !slot) { 0 21958 21958
9504 0 return NULL;
9505 }
9506 21958 slot_index = slot->schema_slot_index;
9507 21958 ▶ if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 21958 0 21958
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 0 21958 21958
9508 0 return NULL;
9509 }
9510 21958 ▶ if (!runtime->callback_catalog || !runtime->callback_catalog->slot_type_objects) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime->callback_catalog || !runtime->callback_catalog->slot_type_objects) { 21958 0 21958
if (!runtime->callback_catalog || !runtime->callback_catalog->slot_type_objects) { 0 21958 21958
9511 0 return NULL;
9512 }
9513 21958 ▶ if (!runtime->callback_catalog->slot_type_objects[slot_index]
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime->callback_catalog->slot_type_objects[slot_index] 21958 0 21958
9514 21958 ▶ || !SvOK(runtime->callback_catalog->slot_type_objects[slot_index])) {
Branch: 1 branch
BranchTrueFalseTotal
|| !SvOK(runtime->callback_catalog->slot_type_objects[slot_index])) { 0 21958 21958
9515 0 return NULL;
9516 }
9517 21958 return runtime->callback_catalog->slot_type_objects[slot_index];
9518 }
9519  
9520 static SV *
9521 9963 gql_runtime_vm_new_callback_info_sv(pTHX_ const gql_runtime_vm_exec_state_t *state)
9522 {
9523 SV *return_type_sv;
9524 9963 SV *directives_sv = NULL;
9525 9963 ▶ gql_runtime_vm_callback_context_t *ctx = state ? state->callback_ctx : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_callback_context_t *ctx = state ? state->callback_ctx : NULL; 9963 0 9963
9526 9963 ▶ const gql_runtime_vm_native_slot_t *slot = state ? state->slot : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const gql_runtime_vm_native_slot_t *slot = state ? state->slot : NULL; 9963 0 9963
9527 9963 ▶ const gql_runtime_vm_native_op_t *op = state ? state->op : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const gql_runtime_vm_native_op_t *op = state ? state->op : NULL; 9963 0 9963
9528 9963 ▶ const gql_runtime_vm_native_block_t *block = state ? state->block : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const gql_runtime_vm_native_block_t *block = state ? state->block : NULL; 9963 0 9963
9529 9963 gql_runtime_vm_native_callback_catalog_t *catalog =
9530 9963 ▶ (state && state->runtime) ? state->runtime->callback_catalog : NULL;
Branch: 2 branches
BranchTrueFalseTotal
(state && state->runtime) ? state->runtime->callback_catalog : NULL; 9963 0 9963
(state && state->runtime) ? state->runtime->callback_catalog : NULL; 9963 0 9963
9531 9963 SV *field_name_sv = NULL;
9532 9963 SV *variables_sv = ctx
9533 9963 ? gql_runtime_vm_callback_variables_sv(aTHX_ ctx)
9534 9963 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 9963 0 9963
9535  
9536 9963 ▶ if (!state) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state) { 0 9963 9963
9537 0 return newRV_noinc((SV *)newHV());
9538 }
9539  
9540 9963 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(state->runtime, slot);
9541 9963 ▶ if (!return_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!return_type_sv) { 0 9963 9963
9542 0 ▶ return_type_sv = gql_runtime_vm_lookup_slot_type_object_sv(
Branch: 1 branch
BranchTrueFalseTotal
return_type_sv = gql_runtime_vm_lookup_slot_type_object_sv( 0 0 0
9543 aTHX_
9544 0 state->runtime,
9545 ctx ? ctx->runtime_schema : &PL_sv_undef,
9546 slot
9547 );
9548 }
9549 9963 ▶ if (catalog
Branch: 1 branch
BranchTrueFalseTotal
if (catalog 9963 0 9963
9550 9963 ▶ && catalog->slot_field_names
Branch: 1 branch
BranchTrueFalseTotal
&& catalog->slot_field_names 9963 0 9963
9551 9963 ▶ && slot
Branch: 1 branch
BranchTrueFalseTotal
&& slot 9963 0 9963
9552 9963 ▶ && slot->schema_slot_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index >= 0 9963 0 9963
9553 9963 ▶ && slot->schema_slot_index < state->runtime->runtime_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index < state->runtime->runtime_slot_count) { 9963 0 9963
9554 9963 field_name_sv = catalog->slot_field_names[slot->schema_slot_index];
9555 }
9556 9963 ▶ if (op
Branch: 1 branch
BranchTrueFalseTotal
if (op 9963 0 9963
9557 9963 ▶ && op->runtime_directives_sv
Branch: 1 branch
BranchTrueFalseTotal
&& op->runtime_directives_sv 7 9956 9963
9558 7 ▶ && op->runtime_directives_mode_code == GQL_VM_ARGS_STATIC) {
Branch: 1 branch
BranchTrueFalseTotal
&& op->runtime_directives_mode_code == GQL_VM_ARGS_STATIC) { 7 0 7
9559 7 directives_sv = newSVsv(op->runtime_directives_sv);
9560 9956 ▶ } else if (ctx && ctx->program && state->block_index >= 0 && state->op_index >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
} else if (ctx && ctx->program && state->block_index >= 0 && state->op_index >= 0) { 9956 0 9956
} else if (ctx && ctx->program && state->block_index >= 0 && state->op_index >= 0) { 0 9956 9956
} else if (ctx && ctx->program && state->block_index >= 0 && state->op_index >= 0) { 0 0 0
} else if (ctx && ctx->program && state->block_index >= 0 && state->op_index >= 0) { 0 0 0
9561 0 directives_sv = gql_runtime_vm_program_runtime_directives_sv(
9562 aTHX_
9563 ctx->program,
9564 0 state->block_index,
9565 0 state->op_index,
9566 variables_sv
9567 );
9568 9956 ▶ } else if (op && op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (op && op->runtime_directives_sv) { 9956 0 9956
} else if (op && op->runtime_directives_sv) { 0 9956 9956
9569 0 directives_sv = gql_runtime_vm_materialize_runtime_directives_sv(
9570 aTHX_
9571 0 op->runtime_directives_sv,
9572 variables_sv
9573 );
9574 }
9575  
9576 59778 ▶ return gql_runtime_vm_new_lazy_info_handle_sv(
Branch: 7 branches
BranchTrueFalseTotal
return gql_runtime_vm_new_lazy_info_handle_sv( 9963 0 9963
return gql_runtime_vm_new_lazy_info_handle_sv( 9963 0 9963
return gql_runtime_vm_new_lazy_info_handle_sv( 9963 0 9963
return gql_runtime_vm_new_lazy_info_handle_sv( 9963 0 9963
return gql_runtime_vm_new_lazy_info_handle_sv( 9963 0 9963
return gql_runtime_vm_new_lazy_info_handle_sv( 9963 0 9963
return gql_runtime_vm_new_lazy_info_handle_sv( 9963 0 9963
9577 aTHX_
9578 field_name_sv,
9579 slot ? slot->field_name : NULL,
9580 block ? block->type_object_sv : NULL,
9581 block ? block->type_name : NULL,
9582 slot ? slot->return_type_name : NULL,
9583 return_type_sv,
9584 9963 ▶ state->path_frame,
Branch: 1 branch
BranchTrueFalseTotal
state->path_frame, 9963 0 9963
9585 9963 ▶ (ctx && ctx->context) ? ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
(ctx && ctx->context) ? ctx->context : &PL_sv_undef, 9963 0 9963
9586 9963 ▶ (ctx && ctx->root_value) ? ctx->root_value : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
(ctx && ctx->root_value) ? ctx->root_value : &PL_sv_undef, 9963 0 9963
9587 variables_sv,
9588 9963 ▶ (ctx && ctx->program) ? ctx->program : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
(ctx && ctx->program) ? ctx->program : &PL_sv_undef, 2 9961 9963
9589 9963 ▶ (ctx && ctx->runtime_schema) ? ctx->runtime_schema : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
(ctx && ctx->runtime_schema) ? ctx->runtime_schema : &PL_sv_undef, 9963 0 9963
9590 7 directives_sv ? sv_2mortal(directives_sv) : &PL_sv_undef,
9591 9963 state->block_index,
9592 9963 ▶ state->op_index
Branch: 1 branch
BranchTrueFalseTotal
state->op_index 7 9956 9963
9593 );
9594 }
9595  
9596 static IV
9597 144 gql_runtime_vm_find_abstract_child_block_index(const gql_runtime_vm_native_op_t *op, const char *type_name)
9598 {
9599 IV i;
9600 144 ▶ if (!op || !type_name) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op || !type_name) { 144 0 144
if (!op || !type_name) { 12 132 144
9601 12 return -1;
9602 }
9603 132 ▶ if (op->abstract_child_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->abstract_child_count == 1) { 28 104 132
9604 28 ▶ if (op->abstract_child_names
Branch: 1 branch
BranchTrueFalseTotal
if (op->abstract_child_names 28 0 28
9605 28 ▶ && op->abstract_child_names[0]
Branch: 1 branch
BranchTrueFalseTotal
&& op->abstract_child_names[0] 28 0 28
9606 28 ▶ && strEQ(op->abstract_child_names[0], type_name)) {
Branch: 1 branch
BranchTrueFalseTotal
&& strEQ(op->abstract_child_names[0], type_name)) { 28 0 28
9607 28 ▶ return op->abstract_child_indexes ? op->abstract_child_indexes[0] : -1;
Branch: 1 branch
BranchTrueFalseTotal
return op->abstract_child_indexes ? op->abstract_child_indexes[0] : -1; 28 0 28
9608 }
9609 0 return -1;
9610 }
9611 153 ▶ for (i = 0; i < op->abstract_child_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < op->abstract_child_count; i++) { 153 0 153
9612 153 ▶ if (op->abstract_child_names[i] && strEQ(op->abstract_child_names[i], type_name)) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->abstract_child_names[i] && strEQ(op->abstract_child_names[i], type_name)) { 153 0 153
if (op->abstract_child_names[i] && strEQ(op->abstract_child_names[i], type_name)) { 104 49 153
9613 104 return op->abstract_child_indexes[i];
9614 }
9615 }
9616 0 return -1;
9617 }
9618  
9619 static const char *
9620 155 gql_runtime_vm_type_name_from_sv(pTHX_ SV *type_sv)
9621 {
9622 155 ▶ if (!type_sv || !SvOK(type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!type_sv || !SvOK(type_sv)) { 155 0 155
if (!type_sv || !SvOK(type_sv)) { 0 155 155
9623 0 return NULL;
9624 }
9625 155 ▶ if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV) { 152 3 155
if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV) { 152 0 152
9626 152 HV *hv = (HV *)SvRV(type_sv);
9627 152 return gql_runtime_vm_fetch_hash_entry_pv(aTHX_ hv, "name", 4);
9628 }
9629 6 ▶ return SvPOK(type_sv) ? SvPV_nolen(type_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return SvPOK(type_sv) ? SvPV_nolen(type_sv) : NULL; 3 0 3
9630 }
9631  
9632 static SV *
9633 644 gql_runtime_vm_clone_value_sv(pTHX_ SV *value)
9634 {
9635 644 ▶ return newSVsv(value ? value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return newSVsv(value ? value : &PL_sv_undef); 644 0 644
9636 }
9637  
9638 /*
9639 * Async pending paths store callback values beyond the current Perl stack.
9640 * Keep these on the conservative clone path until the scheduler carries
9641 * stronger ownership provenance for every stored value.
9642 */
9643 static SV *
9644 1800 gql_runtime_vm_snapshot_scalarish_value_sv(pTHX_ SV *value)
9645 {
9646 1800 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 1800 0 1800
if (!value || !SvOK(value)) { 6 1794 1800
9647 6 return newSVsv(&PL_sv_undef);
9648 }
9649 1794 return newSVsv(value);
9650 }
9651  
9652 static SV *
9653 0 gql_runtime_vm_clone_args_payload_sv(pTHX_ SV *value)
9654 {
9655 0 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 0 0
9656 0 return newSVsv(&PL_sv_undef);
9657 }
9658 0 ▶ if (!SvROK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(value)) { 0 0 0
9659 0 return newSVsv(value);
9660 }
9661  
9662 0 switch (SvTYPE(SvRV(value))) {
9663 0 case SVt_PVHV: {
9664 0 HV *src_hv = (HV *)SvRV(value);
9665 0 HV *dst_hv = newHV();
9666 HE *he;
9667 0 hv_iterinit(src_hv);
9668 0 ▶ while ((he = hv_iternext(src_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(src_hv))) { 0 0 0
9669 0 SV *keysv = hv_iterkeysv(he);
9670 0 SV *val = HeVAL(he);
9671 0 hv_store_ent(dst_hv, keysv, gql_runtime_vm_clone_args_payload_sv(aTHX_ val), 0);
9672 }
9673 0 return newRV_noinc((SV *)dst_hv);
9674 }
9675 0 case SVt_PVAV: {
9676 0 AV *src_av = (AV *)SvRV(value);
9677 0 AV *dst_av = newAV();
9678 IV i;
9679 0 ▶ av_extend(dst_av, av_count(src_av) > 0 ? av_count(src_av) - 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
av_extend(dst_av, av_count(src_av) > 0 ? av_count(src_av) - 1 : 0); 0 0 0
9680 0 ▶ for (i = 0; i < (IV)av_count(src_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (IV)av_count(src_av); i++) { 0 0 0
9681 0 SV **item_svp = av_fetch(src_av, i, 0);
9682 0 ▶ av_store(dst_av, i, gql_runtime_vm_clone_args_payload_sv(aTHX_ (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef));
Branch: 2 branches
BranchTrueFalseTotal
av_store(dst_av, i, gql_runtime_vm_clone_args_payload_sv(aTHX_ (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef)); 0 0 0
av_store(dst_av, i, gql_runtime_vm_clone_args_payload_sv(aTHX_ (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef)); 0 0 0
9683 }
9684 0 return newRV_noinc((SV *)dst_av);
9685 }
9686 0 default:
9687 0 return newSVsv(value);
9688 }
9689 }
9690  
9691 static SV *
9692 9911 gql_runtime_vm_build_current_args_sv(pTHX_ gql_runtime_vm_exec_state_t *state)
9693 {
9694 9911 const gql_runtime_vm_native_op_t *op = state->op;
9695 9911 const gql_runtime_vm_native_slot_t *slot = state->slot;
9696 9911 gql_runtime_vm_native_runtime_t *runtime = state->runtime;
9697 9911 gql_runtime_vm_callback_context_t *callback_ctx = state->callback_ctx;
9698 9911 HV *variables_hv = NULL;
9699 9911 ▶ SV *variables_sv = callback_ctx ? callback_ctx->variables : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *variables_sv = callback_ctx ? callback_ctx->variables : NULL; 9911 0 9911
9700 SV *specialized_sv;
9701 9911 ▶ if (!op) {
Branch: 1 branch
BranchTrueFalseTotal
if (!op) { 0 9911 9911
9702 0 ▶ if (state && state->empty_args_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state && state->empty_args_sv) { 0 0 0
if (state && state->empty_args_sv) { 0 0 0
9703 0 SvREFCNT_inc(state->empty_args_sv);
9704 0 return state->empty_args_sv;
9705 }
9706 0 return newRV_noinc((SV *)newHV());
9707 }
9708 9911 ▶ if (!op->has_args && (!slot || slot->arg_def_count == 0)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!op->has_args && (!slot || slot->arg_def_count == 0)) { 4629 5282 9911
if (!op->has_args && (!slot || slot->arg_def_count == 0)) { 4629 0 4629
if (!op->has_args && (!slot || slot->arg_def_count == 0)) { 4629 0 4629
9709 4629 ▶ if (state && state->empty_args_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state && state->empty_args_sv) { 4629 0 4629
if (state && state->empty_args_sv) { 4629 0 4629
9710 4629 SvREFCNT_inc(state->empty_args_sv);
9711 4629 return state->empty_args_sv;
9712 }
9713 0 return newRV_noinc((SV *)newHV());
9714 }
9715 5282 ▶ if (callback_ctx
Branch: 1 branch
BranchTrueFalseTotal
if (callback_ctx 5282 0 5282
9716 5282 ▶ && op->args_mode_code == GQL_VM_ARGS_DYNAMIC
Branch: 1 branch
BranchTrueFalseTotal
&& op->args_mode_code == GQL_VM_ARGS_DYNAMIC 5026 256 5282
9717 5026 ▶ && gql_runtime_vm_args_payload_needs_variables_hv(op->args_payload_native)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_args_payload_needs_variables_hv(op->args_payload_native)) { 4 5022 5026
9718 4 variables_sv = gql_runtime_vm_callback_variables_sv(aTHX_ callback_ctx);
9719 }
9720 5282 ▶ if (variables_sv
Branch: 1 branch
BranchTrueFalseTotal
if (variables_sv 5282 0 5282
9721 5282 ▶ && SvROK(variables_sv)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(variables_sv) 5272 10 5282
9722 5272 ▶ && SvTYPE(SvRV(variables_sv)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(variables_sv)) == SVt_PVHV) { 2868 2404 5272
9723 2868 variables_hv = (HV *)SvRV(variables_sv);
9724 }
9725 5282 ▶ if (slot && (slot->arg_def_count > 0 || op->has_args)) {
Branch: 3 branches
BranchTrueFalseTotal
if (slot && (slot->arg_def_count > 0 || op->has_args)) { 5282 0 5282
if (slot && (slot->arg_def_count > 0 || op->has_args)) { 0 5282 5282
if (slot && (slot->arg_def_count > 0 || op->has_args)) { 0 0 0
9726 5282 ▶ if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) { 208 5074 5282
if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) { 208 0 208
9727 208 ▶ if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) { 8 200 208
9728 8 return gql_runtime_vm_native_args_payload_materialize_cached_sv(aTHX_ op->args_payload_native);
9729 }
9730 200 return gql_runtime_vm_native_args_payload_materialize_sv(aTHX_ op->args_payload_native);
9731 }
9732 {
9733 5074 SV *coercion_croak_sv = NULL;
9734 5074 ▶ specialized_sv = gql_runtime_vm_specialize_arg_payload_sv(
Branch: 3 branches
BranchTrueFalseTotal
specialized_sv = gql_runtime_vm_specialize_arg_payload_sv( 5074 0 5074
specialized_sv = gql_runtime_vm_specialize_arg_payload_sv( 5074 0 5074
specialized_sv = gql_runtime_vm_specialize_arg_payload_sv( 5074 0 5074
9735 aTHX_ runtime, slot, op, variables_hv,
9736 callback_ctx ? callback_ctx->variable_slots : NULL,
9737 callback_ctx ? callback_ctx->variable_slot_count : 0,
9738 state ? &coercion_croak_sv : NULL
9739 );
9740 5074 ▶ if (coercion_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (coercion_croak_sv) { 3 5071 5074
9741 /* Request-time argument coercion failed (e.g. a null non-null
9742 * variable). Route it to the deferred croak channel and return
9743 * NULL so the caller skips the resolver; the top-level entry
9744 * re-raises it after the lane unwound its path frames. */
9745 3 ▶ if (!state->fast_lane_deferred_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->fast_lane_deferred_croak_sv) { 3 0 3
9746 3 state->fast_lane_deferred_croak_sv = coercion_croak_sv;
9747 } else {
9748 0 SvREFCNT_dec(coercion_croak_sv);
9749 }
9750 3 return NULL;
9751 }
9752 }
9753 5071 ▶ if (specialized_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (specialized_sv) { 5033 38 5071
9754 5033 return specialized_sv;
9755 }
9756 38 ▶ if (state && state->empty_args_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state && state->empty_args_sv) { 38 0 38
if (state && state->empty_args_sv) { 38 0 38
9757 38 SvREFCNT_inc(state->empty_args_sv);
9758 38 return state->empty_args_sv;
9759 }
9760 0 return newRV_noinc((SV *)newHV());
9761 }
9762 0 ▶ if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) { 0 0 0
if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) { 0 0 0
9763 0 ▶ if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) { 0 0 0
9764 0 return gql_runtime_vm_native_args_payload_materialize_cached_sv(aTHX_ op->args_payload_native);
9765 }
9766 0 return gql_runtime_vm_native_args_payload_materialize_sv(aTHX_ op->args_payload_native);
9767 }
9768 0 ▶ if (state && state->empty_args_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state && state->empty_args_sv) { 0 0 0
if (state && state->empty_args_sv) { 0 0 0
9769 0 SvREFCNT_inc(state->empty_args_sv);
9770 0 return state->empty_args_sv;
9771 }
9772 0 return newRV_noinc((SV *)newHV());
9773 }
9774  
9775 static SV *
9776 7 gql_runtime_vm_build_current_one_arg_sv(
9777 pTHX_ gql_runtime_vm_exec_state_t *state
9778 )
9779 {
9780 7 const gql_runtime_vm_native_op_t *op = state->op;
9781 7 const gql_runtime_vm_native_slot_t *slot = state->slot;
9782 7 gql_runtime_vm_callback_context_t *callback_ctx = state->callback_ctx;
9783 7 ▶ SV *variables_sv = callback_ctx ? callback_ctx->variables : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *variables_sv = callback_ctx ? callback_ctx->variables : NULL; 7 0 7
9784 7 HV *variables_hv = NULL;
9785 7 SV *coercion_croak_sv = NULL;
9786 SV *value;
9787  
9788 7 ▶ if (!op || !slot || slot->arg_def_count != 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (!op || !slot || slot->arg_def_count != 1) { 7 0 7
if (!op || !slot || slot->arg_def_count != 1) { 7 0 7
if (!op || !slot || slot->arg_def_count != 1) { 0 7 7
9789 0 return newSVsv(&PL_sv_undef);
9790 }
9791 7 ▶ if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) { 2 5 7
if (op->args_mode_code == GQL_VM_ARGS_STATIC && op->args_payload_native) { 2 0 2
9792 2 return gql_runtime_vm_native_args_payload_materialize_one_arg_cached_sv(
9793 2 aTHX_ op->args_payload_native
9794 );
9795 }
9796 5 ▶ if (callback_ctx
Branch: 1 branch
BranchTrueFalseTotal
if (callback_ctx 5 0 5
9797 5 ▶ && op->args_mode_code == GQL_VM_ARGS_DYNAMIC
Branch: 1 branch
BranchTrueFalseTotal
&& op->args_mode_code == GQL_VM_ARGS_DYNAMIC 4 1 5
9798 4 ▶ && gql_runtime_vm_args_payload_needs_variables_hv(op->args_payload_native)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_args_payload_needs_variables_hv(op->args_payload_native)) { 0 4 4
9799 0 variables_sv = gql_runtime_vm_callback_variables_sv(aTHX_ callback_ctx);
9800 }
9801 5 ▶ if (variables_sv
Branch: 1 branch
BranchTrueFalseTotal
if (variables_sv 5 0 5
9802 5 ▶ && SvROK(variables_sv)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(variables_sv) 5 0 5
9803 5 ▶ && SvTYPE(SvRV(variables_sv)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(variables_sv)) == SVt_PVHV) { 3 2 5
9804 3 variables_hv = (HV *)SvRV(variables_sv);
9805 }
9806 5 ▶ value = gql_runtime_vm_specialize_one_arg_sv(
Branch: 2 branches
BranchTrueFalseTotal
value = gql_runtime_vm_specialize_one_arg_sv( 5 0 5
value = gql_runtime_vm_specialize_one_arg_sv( 5 0 5
9807 aTHX_
9808 5 state->runtime,
9809 slot,
9810 op,
9811 variables_hv,
9812 callback_ctx ? callback_ctx->variable_slots : NULL,
9813 callback_ctx ? callback_ctx->variable_slot_count : 0,
9814 &coercion_croak_sv
9815 );
9816 5 ▶ if (coercion_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (coercion_croak_sv) { 0 5 5
9817 0 ▶ if (!state->fast_lane_deferred_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->fast_lane_deferred_croak_sv) { 0 0 0
9818 0 state->fast_lane_deferred_croak_sv = coercion_croak_sv;
9819 } else {
9820 0 SvREFCNT_dec(coercion_croak_sv);
9821 }
9822 0 return NULL;
9823 }
9824 5 ▶ return value ? value : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return value ? value : newSVsv(&PL_sv_undef); 0 5 5
9825 }
9826  
9827 static SV *
9828 704 gql_runtime_vm_resolve_current_field_default_fast_sv(
9829 pTHX_
9830 gql_runtime_vm_exec_state_t *state,
9831 SV *source,
9832 SV **error_out
9833 )
9834 {
9835 SV *resolver_sv;
9836 704 SV *return_type_sv = NULL;
9837 704 gql_runtime_vm_native_runtime_t *runtime = state->runtime;
9838 704 const gql_runtime_vm_native_slot_t *slot = state->slot;
9839  
9840 704 ▶ if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 704 0 704
if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 704 0 704
if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 0 704 704
9841 0 croak("native VM schema slot index %ld is invalid", (long)slot->schema_slot_index);
9842 }
9843 704 ▶ resolver_sv = (runtime->callback_catalog && runtime->callback_catalog->slot_resolvers)
Branch: 1 branch
BranchTrueFalseTotal
resolver_sv = (runtime->callback_catalog && runtime->callback_catalog->slot_resolvers) 704 0 704
9844 704 ? runtime->callback_catalog->slot_resolvers[slot->schema_slot_index]
9845 1408 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 704 0 704
9846  
9847 704 ▶ if (resolver_sv && SvOK(resolver_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (resolver_sv && SvOK(resolver_sv)) { 0 704 704
if (resolver_sv && SvOK(resolver_sv)) { 0 0 0
9848 0 SV *args = NULL;
9849  
9850 0 ▶ if (gql_runtime_vm_slot_uses_native_no_args_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_no_args_abi(slot)) { 0 0 0
9851 0 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
9852 0 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv( 0 0 0
9853 aTHX_ state,
9854 gql_runtime_vm_call_cb3_nonfatal(
9855 aTHX_
9856 resolver_sv,
9857 source,
9858 0 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 0 0 0
9859 return_type_sv ? return_type_sv : &PL_sv_undef,
9860 error_out
9861 ),
9862 error_out
9863 );
9864 }
9865 0 ▶ if (gql_runtime_vm_slot_uses_native_one_arg_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_one_arg_abi(slot)) { 0 0 0
9866 0 SV *value = gql_runtime_vm_build_current_one_arg_sv(aTHX_ state);
9867 0 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 0 0
9868 0 return newSVsv(&PL_sv_undef);
9869 }
9870 0 value = sv_2mortal(value);
9871 0 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
9872 0 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal( 0 0 0
9873 aTHX_
9874 resolver_sv,
9875 source,
9876 value,
9877 0 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 0 0 0
9878 return_type_sv ? return_type_sv : &PL_sv_undef,
9879 error_out
9880 ), error_out);
9881 }
9882 0 args = gql_runtime_vm_build_current_args_sv(aTHX_ state);
9883 0 ▶ if (!args) {
Branch: 1 branch
BranchTrueFalseTotal
if (!args) { 0 0 0
9884 /* Argument coercion failed and armed the deferred croak channel:
9885 * skip the resolver and complete the field as null. */
9886 0 return newSVsv(&PL_sv_undef);
9887 }
9888 0 args = sv_2mortal(args);
9889  
9890 0 ▶ if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) { 0 0 0
9891 0 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
9892 0 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal( 0 0 0
9893 aTHX_
9894 resolver_sv,
9895 source,
9896 args,
9897 0 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 0 0 0
9898 return_type_sv ? return_type_sv : &PL_sv_undef,
9899 error_out
9900 ), error_out);
9901 }
9902  
9903 0 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
9904 0 ▶ if (!return_type_sv && !gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!return_type_sv && !gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 0 0
if (!return_type_sv && !gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 0 0
9905 0 return_type_sv = gql_runtime_vm_lookup_slot_type_object_sv(
9906 aTHX_ runtime,
9907 0 ▶ state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef, 0 0 0
9908 slot
9909 );
9910 }
9911 0 ▶ if (!return_type_sv && gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!return_type_sv && gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 0 0
if (!return_type_sv && gql_runtime_vm_slot_uses_explicit_generic_fast_abi(slot)) { 0 0 0
9912 0 croak("native VM slot type object is missing for explicit generic callback");
9913 }
9914  
9915 0 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb5_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb5_nonfatal( 0 0 0
9916 aTHX_
9917 resolver_sv,
9918 source,
9919 args,
9920 0 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 0 0 0
9921 sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state)),
9922 return_type_sv ? return_type_sv : &PL_sv_undef,
9923 error_out
9924 ), error_out);
9925 }
9926  
9927 704 ▶ if (slot->field_name
Branch: 1 branch
BranchTrueFalseTotal
if (slot->field_name 704 0 704
9928 704 ▶ && slot->field_name_len == (STRLEN)sizeof("__typename") - 1
Branch: 1 branch
BranchTrueFalseTotal
&& slot->field_name_len == (STRLEN)sizeof("__typename") - 1 25 679 704
9929 25 ▶ && memEQ(slot->field_name, "__typename", sizeof("__typename") - 1)) {
Branch: 1 branch
BranchTrueFalseTotal
&& memEQ(slot->field_name, "__typename", sizeof("__typename") - 1)) { 19 6 25
9930 19 ▶ return newSVpv((state->block && state->block->type_name) ? state->block->type_name : "", 0);
Branch: 2 branches
BranchTrueFalseTotal
return newSVpv((state->block && state->block->type_name) ? state->block->type_name : "", 0); 19 0 19
return newSVpv((state->block && state->block->type_name) ? state->block->type_name : "", 0); 19 0 19
9931 }
9932  
9933 685 ▶ if (slot->accessor_name && slot->accessor_name_len) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot->accessor_name && slot->accessor_name_len) { 6 679 685
if (slot->accessor_name && slot->accessor_name_len) { 6 0 6
9934 6 return gql_runtime_vm_fast_lane_guard_promise_sv(
9935 aTHX_ state,
9936 gql_runtime_vm_call_accessor_nonfatal(aTHX_ source, slot, error_out),
9937 error_out
9938 );
9939 }
9940  
9941 {
9942 679 CV *method_cv = gql_runtime_vm_default_method_cv(source, slot->field_name);
9943 679 ▶ if (method_cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (method_cv) { 15 664 679
9944 15 SV *args = gql_runtime_vm_build_current_args_sv(aTHX_ state);
9945 SV *info;
9946 SV *resolved;
9947 15 ▶ if (!args) {
Branch: 1 branch
BranchTrueFalseTotal
if (!args) { 0 15 15
9948 0 return newSVsv(&PL_sv_undef);
9949 }
9950 15 args = sv_2mortal(args);
9951 15 info = sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state));
9952 15 resolved = gql_runtime_vm_call_cb4_nonfatal(
9953 aTHX_ (SV *)method_cv, source, args,
9954 15 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 15 0 15
9955 info, error_out
9956 );
9957 15 return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, resolved, error_out);
9958 }
9959 }
9960  
9961 664 ▶ if (source && SvROK(source) && SvTYPE(SvRV(source)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (source && SvROK(source) && SvTYPE(SvRV(source)) == SVt_PVHV) { 664 0 664
if (source && SvROK(source) && SvTYPE(SvRV(source)) == SVt_PVHV) { 664 0 664
if (source && SvROK(source) && SvTYPE(SvRV(source)) == SVt_PVHV) { 664 0 664
9962 664 HV *source_hv = (HV *)SvRV(source);
9963 664 SV **value_svp = hv_fetch(source_hv, slot->field_name, (I32)slot->field_name_len, 0);
9964 664 ▶ if (value_svp && gql_runtime_vm_is_callable_property_candidate(aTHX_ *value_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (value_svp && gql_runtime_vm_is_callable_property_candidate(aTHX_ *value_svp)) { 658 6 664
if (value_svp && gql_runtime_vm_is_callable_property_candidate(aTHX_ *value_svp)) { 20 638 658
9965 20 SV *args = gql_runtime_vm_build_current_args_sv(aTHX_ state);
9966 SV *info;
9967 SV *resolved;
9968 20 ▶ if (!args) {
Branch: 1 branch
BranchTrueFalseTotal
if (!args) { 0 20 20
9969 0 return newSVsv(&PL_sv_undef);
9970 }
9971 20 args = sv_2mortal(args);
9972 20 info = sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state));
9973 20 resolved = gql_runtime_vm_call_default_property_sv(
9974 aTHX_ *value_svp, args,
9975 20 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 20 0 20
9976 info, error_out
9977 );
9978 20 return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, resolved, error_out);
9979 }
9980 644 ▶ return gql_runtime_vm_clone_value_sv(aTHX_ (value_svp && SvOK(*value_svp)) ? *value_svp : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
return gql_runtime_vm_clone_value_sv(aTHX_ (value_svp && SvOK(*value_svp)) ? *value_svp : &PL_sv_undef); 638 6 644
return gql_runtime_vm_clone_value_sv(aTHX_ (value_svp && SvOK(*value_svp)) ? *value_svp : &PL_sv_undef); 593 45 638
9981 }
9982  
9983 0 return newSVsv(&PL_sv_undef);
9984 }
9985  
9986  
9987 static SV *
9988 9927 gql_runtime_vm_fast_lane_guard_promise_sv(
9989 pTHX_ gql_runtime_vm_exec_state_t *state, SV *resolved, SV **error_out
9990 )
9991 {
9992 /* A DataLoader Ticket is settle-once and notifies subscribers
9993 * synchronously (no derived-object churn like Promise::XS::then), so an
9994 * already-settled Ticket is unwrapped in place regardless of lane - this
9995 * never touches the suspension channel, matching the unwrap done for the
9996 * generic async path (see the ticket_state handling around the async
9997 * current-op resolver). Only a genuinely pending Ticket (state 0) needs
9998 * the same suspend-or-croak treatment as a Promise below. */
9999 9927 ▶ if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ resolved)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ resolved)) { 1749 8178 9927
10000 1749 IV ticket_state = gql_runtime_vm_dataloader_ticket_state(aTHX_ resolved);
10001 1749 ▶ if (ticket_state == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (ticket_state == 1) { 4 1745 1749
10002 4 SV *value_sv = newSVsv(gql_runtime_vm_dataloader_ticket_value(aTHX_ resolved));
10003 4 SvREFCNT_dec(resolved);
10004 4 return value_sv;
10005 }
10006 1745 ▶ if (ticket_state == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (ticket_state == 2) { 0 1745 1745
10007 0 ▶ if (error_out && !*error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && !*error_out) { 0 0 0
if (error_out && !*error_out) { 0 0 0
10008 0 *error_out = newSVsv(gql_runtime_vm_dataloader_ticket_value(aTHX_ resolved));
10009 }
10010 0 SvREFCNT_dec(resolved);
10011 0 return newSVsv(&PL_sv_undef);
10012 }
10013 /* ticket_state == 0: fall through to the pending/suspend handling
10014 * below, shared with the Promise::XS case. */
10015 8178 ▶ } else if (!resolved
Branch: 1 branch
BranchTrueFalseTotal
} else if (!resolved 8178 0 8178
10016 8178 ▶ || !SvROK(resolved)
Branch: 1 branch
BranchTrueFalseTotal
|| !SvROK(resolved) 2561 5617 8178
10017 2561 ▶ || !SvOBJECT(SvRV(resolved))
Branch: 1 branch
BranchTrueFalseTotal
|| !SvOBJECT(SvRV(resolved)) 112 2449 2561
10018 112 ▶ || !state
Branch: 1 branch
BranchTrueFalseTotal
|| !state 112 0 112
10019 112 ▶ || !state->runtime
Branch: 1 branch
BranchTrueFalseTotal
|| !state->runtime 112 0 112
10020 112 ▶ || !gql_runtime_vm_sv_is_adapter_promise(
Branch: 1 branch
BranchTrueFalseTotal
|| !gql_runtime_vm_sv_is_adapter_promise( 71 41 112
10021 112 aTHX_ state->runtime->async_adapter, resolved
10022 )) {
10023 8137 return resolved;
10024 }
10025  
10026 /* The sync fast lanes cannot suspend, so a promise/ticket-returning
10027 * resolver is a routing misconfiguration: async schemas declare
10028 * themselves with async => 1 on the runtime (or pass on_stall per
10029 * request). Croaking from mid-lane would leak the live path frame chain
10030 * (each recursion level holds one reference the unwind never releases -
10031 * R5 leak 3), so this completes the field as null, records the deferred
10032 * croak, and the top-level entry raises it after the lane unwound
10033 * normally. */
10034 1786 ▶ if (state && state->fast_lane_can_suspend) {
Branch: 2 branches
BranchTrueFalseTotal
if (state && state->fast_lane_can_suspend) { 1786 0 1786
if (state && state->fast_lane_can_suspend) { 1775 11 1786
10035 1775 ▶ if (!state->fast_lane_suspended_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->fast_lane_suspended_sv) { 1775 0 1775
10036 1775 state->fast_lane_suspended_sv = resolved;
10037 } else {
10038 0 SvREFCNT_dec(resolved);
10039 }
10040 1775 return NULL;
10041 }
10042 11 SvREFCNT_dec(resolved);
10043 11 ▶ if (state && !state->fast_lane_deferred_croak_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state && !state->fast_lane_deferred_croak_sv) { 11 0 11
if (state && !state->fast_lane_deferred_croak_sv) { 11 0 11
10044 11 state->fast_lane_deferred_croak_sv =
10045 11 newSVpv(GQL_RUNTIME_VM_FAST_LANE_PROMISE_ERROR, 0);
10046 }
10047 11 return newSVsv(&PL_sv_undef);
10048 }
10049  
10050 static SV *
10051 9889 gql_runtime_vm_resolve_current_field_explicit_fast_sv(
10052 pTHX_
10053 gql_runtime_vm_exec_state_t *state,
10054 SV *source,
10055 SV **error_out
10056 )
10057 {
10058 SV *resolver_sv;
10059 9889 SV *return_type_sv = NULL;
10060 9889 gql_runtime_vm_native_runtime_t *runtime = state->runtime;
10061 9889 const gql_runtime_vm_native_slot_t *slot = state->slot;
10062 9889 gql_runtime_vm_native_loader_spec_t *loader_spec = NULL;
10063  
10064 9889 ▶ if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 9889 0 9889
if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 9889 0 9889
if (!runtime || slot->schema_slot_index < 0 || slot->schema_slot_index >= runtime->runtime_slot_count) { 0 9889 9889
10065 0 croak("native VM schema slot index %ld is invalid", (long)slot->schema_slot_index);
10066 }
10067 9889 ▶ if (runtime->callback_catalog
Branch: 1 branch
BranchTrueFalseTotal
if (runtime->callback_catalog 9889 0 9889
10068 9889 ▶ && runtime->callback_catalog->slot_native_loader_specs) {
Branch: 1 branch
BranchTrueFalseTotal
&& runtime->callback_catalog->slot_native_loader_specs) { 9889 0 9889
10069 9889 loader_spec = runtime->callback_catalog
10070 9889 ->slot_native_loader_specs[slot->schema_slot_index];
10071 }
10072 9889 ▶ if (loader_spec) {
Branch: 1 branch
BranchTrueFalseTotal
if (loader_spec) { 14 9875 9889
10073 28 SV *context_sv = state->callback_ctx
10074 14 ▶ ? state->callback_ctx->context : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
? state->callback_ctx->context : &PL_sv_undef; 14 0 14
10075 14 ▶ HV *context_hv = (context_sv && SvROK(context_sv)
Branch: 1 branch
BranchTrueFalseTotal
HV *context_hv = (context_sv && SvROK(context_sv) 14 0 14
10076 14 ▶ && SvTYPE(SvRV(context_sv)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(context_sv)) == SVt_PVHV) 14 0 14
10077 28 ▶ ? (HV *)SvRV(context_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(context_sv) : NULL; 14 0 14
10078 14 SV *loader_sv = NULL;
10079 14 SV *key_sv = NULL;
10080 14 SV *owned_key_sv = NULL;
10081 14 SV *owned_route_key_sv = NULL;
10082 14 SV *args_sv = NULL;
10083 14 SV *ret = NULL;
10084  
10085 14 ▶ if (!context_hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!context_hv) { 0 14 14
10086 0 ▶ if (error_out && !*error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && !*error_out) { 0 0 0
if (error_out && !*error_out) { 0 0 0
10087 0 *error_out = newSVpvs(
10088 "declarative loader requires a hash reference request context"
10089 );
10090 }
10091 0 return newSVsv(&PL_sv_undef);
10092 }
10093  
10094 14 ▶ if (!loader_spec->uses_router) {
Branch: 1 branch
BranchTrueFalseTotal
if (!loader_spec->uses_router) { 10 4 14
10095 10 SV **loader_svp = hv_fetch(
10096 context_hv,
10097 loader_spec->context_key,
10098 (I32)loader_spec->context_key_len,
10099 0
10100 );
10101 10 ▶ loader_sv = (loader_svp && SvOK(*loader_svp)) ? *loader_svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
loader_sv = (loader_svp && SvOK(*loader_svp)) ? *loader_svp : NULL; 10 0 10
loader_sv = (loader_svp && SvOK(*loader_svp)) ? *loader_svp : NULL; 10 0 10
10102 10 ▶ if (!loader_sv && error_out && !*error_out) {
Branch: 3 branches
BranchTrueFalseTotal
if (!loader_sv && error_out && !*error_out) { 0 10 10
if (!loader_sv && error_out && !*error_out) { 0 0 0
if (!loader_sv && error_out && !*error_out) { 0 0 0
10103 0 *error_out = newSVpvf(
10104 "loader '%.*s' is not available in the request context",
10105 (int)loader_spec->context_key_len, loader_spec->context_key
10106 );
10107 }
10108 } else {
10109 4 SV *router_sv = NULL;
10110 4 SV *route_key_sv = NULL;
10111 {
10112 4 SV **router_svp = hv_fetch(
10113 context_hv,
10114 loader_spec->context_key,
10115 (I32)loader_spec->context_key_len,
10116 0
10117 );
10118 4 ▶ router_sv = (router_svp && SvOK(*router_svp)) ? *router_svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
router_sv = (router_svp && SvOK(*router_svp)) ? *router_svp : NULL; 4 0 4
router_sv = (router_svp && SvOK(*router_svp)) ? *router_svp : NULL; 4 0 4
10119 }
10120 4 ▶ if (loader_spec->route_key_kind == 1
Branch: 1 branch
BranchTrueFalseTotal
if (loader_spec->route_key_kind == 1 3 1 4
10121 3 ▶ && source && SvROK(source)
Branch: 2 branches
BranchTrueFalseTotal
&& source && SvROK(source) 3 0 3
&& source && SvROK(source) 3 0 3
10122 3 ▶ && SvTYPE(SvRV(source)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(source)) == SVt_PVHV) { 3 0 3
10123 3 SV **svp = hv_fetch(
10124 (HV *)SvRV(source),
10125 loader_spec->route_key_name,
10126 (I32)loader_spec->route_key_name_len,
10127 0
10128 );
10129 3 ▶ route_key_sv = (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
route_key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 3 0 3
route_key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 3 0 3
10130 1 ▶ } else if (loader_spec->route_key_kind == 2) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (loader_spec->route_key_kind == 2) { 1 0 1
10131 1 ▶ if (loader_spec->route_key_arg_index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (loader_spec->route_key_arg_index >= 0) { 0 1 1
10132 owned_route_key_sv =
10133 0 gql_runtime_vm_build_current_one_arg_sv(aTHX_ state);
10134 0 ▶ route_key_sv = (owned_route_key_sv && SvOK(owned_route_key_sv))
Branch: 1 branch
BranchTrueFalseTotal
route_key_sv = (owned_route_key_sv && SvOK(owned_route_key_sv)) 0 0 0
10135 0 ▶ ? owned_route_key_sv : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? owned_route_key_sv : NULL; 0 0 0
10136 } else {
10137 1 args_sv = gql_runtime_vm_build_current_args_sv(aTHX_ state);
10138 1 ▶ if (args_sv && SvROK(args_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (args_sv && SvROK(args_sv) 1 0 1
if (args_sv && SvROK(args_sv) 1 0 1
10139 1 ▶ && SvTYPE(SvRV(args_sv)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(args_sv)) == SVt_PVHV) { 1 0 1
10140 1 SV **svp = hv_fetch(
10141 (HV *)SvRV(args_sv),
10142 loader_spec->route_key_name,
10143 (I32)loader_spec->route_key_name_len,
10144 0
10145 );
10146 1 ▶ route_key_sv = (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
route_key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 1 0 1
route_key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 1 0 1
10147 }
10148 }
10149 }
10150 4 ▶ if (router_sv && SvROK(router_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (router_sv && SvROK(router_sv) 4 0 4
if (router_sv && SvROK(router_sv) 4 0 4
10151 4 ▶ && SvTYPE(SvRV(router_sv)) == SVt_PVHV
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(router_sv)) == SVt_PVHV 4 0 4
10152 4 ▶ && route_key_sv && SvOK(route_key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
&& route_key_sv && SvOK(route_key_sv)) { 4 0 4
&& route_key_sv && SvOK(route_key_sv)) { 4 0 4
10153 STRLEN route_key_len;
10154 4 const char *route_key = SvPV(route_key_sv, route_key_len);
10155 4 SV **loader_svp = hv_fetch(
10156 (HV *)SvRV(router_sv), route_key, (I32)route_key_len, 0
10157 );
10158 4 ▶ loader_sv = (loader_svp && SvOK(*loader_svp)) ? *loader_svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
loader_sv = (loader_svp && SvOK(*loader_svp)) ? *loader_svp : NULL; 4 0 4
loader_sv = (loader_svp && SvOK(*loader_svp)) ? *loader_svp : NULL; 4 0 4
10159 }
10160 4 ▶ if (!loader_sv && error_out && !*error_out) {
Branch: 3 branches
BranchTrueFalseTotal
if (!loader_sv && error_out && !*error_out) { 0 4 4
if (!loader_sv && error_out && !*error_out) { 0 0 0
if (!loader_sv && error_out && !*error_out) { 0 0 0
10161 0 *error_out = newSVpvs(
10162 "declarative loader route is not registered"
10163 );
10164 }
10165 }
10166  
10167 14 ▶ if (loader_spec->key_kind == 1
Branch: 1 branch
BranchTrueFalseTotal
if (loader_spec->key_kind == 1 10 4 14
10168 10 ▶ && source && SvROK(source)
Branch: 2 branches
BranchTrueFalseTotal
&& source && SvROK(source) 10 0 10
&& source && SvROK(source) 10 0 10
10169 10 ▶ && SvTYPE(SvRV(source)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(source)) == SVt_PVHV) { 10 0 10
10170 10 SV **svp = hv_fetch(
10171 (HV *)SvRV(source),
10172 loader_spec->key_name,
10173 (I32)loader_spec->key_name_len,
10174 0
10175 );
10176 10 ▶ key_sv = (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 10 0 10
key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 10 0 10
10177 4 ▶ } else if (loader_spec->key_kind == 2) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (loader_spec->key_kind == 2) { 4 0 4
10178 4 ▶ if (loader_spec->key_arg_index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (loader_spec->key_arg_index >= 0) { 3 1 4
10179 3 ▶ if (owned_route_key_sv
Branch: 1 branch
BranchTrueFalseTotal
if (owned_route_key_sv 0 3 3
10180 0 ▶ && loader_spec->key_arg_index == loader_spec->route_key_arg_index) {
Branch: 1 branch
BranchTrueFalseTotal
&& loader_spec->key_arg_index == loader_spec->route_key_arg_index) { 0 0 0
10181 0 ▶ key_sv = SvOK(owned_route_key_sv) ? owned_route_key_sv : NULL;
Branch: 1 branch
BranchTrueFalseTotal
key_sv = SvOK(owned_route_key_sv) ? owned_route_key_sv : NULL; 0 0 0
10182 } else {
10183 3 owned_key_sv = gql_runtime_vm_build_current_one_arg_sv(aTHX_ state);
10184 6 ▶ key_sv = (owned_key_sv && SvOK(owned_key_sv))
Branch: 1 branch
BranchTrueFalseTotal
key_sv = (owned_key_sv && SvOK(owned_key_sv)) 3 0 3
10185 6 ▶ ? owned_key_sv : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? owned_key_sv : NULL; 3 0 3
10186 }
10187 } else {
10188 1 ▶ if (!args_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!args_sv) { 0 1 1
10189 0 args_sv = gql_runtime_vm_build_current_args_sv(aTHX_ state);
10190 }
10191 1 ▶ if (args_sv && SvROK(args_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (args_sv && SvROK(args_sv) 1 0 1
if (args_sv && SvROK(args_sv) 1 0 1
10192 1 ▶ && SvTYPE(SvRV(args_sv)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(args_sv)) == SVt_PVHV) { 1 0 1
10193 1 SV **svp = hv_fetch(
10194 (HV *)SvRV(args_sv),
10195 loader_spec->key_name,
10196 (I32)loader_spec->key_name_len,
10197 0
10198 );
10199 1 ▶ key_sv = (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 1 0 1
key_sv = (svp && SvOK(*svp)) ? *svp : NULL; 1 0 1
10200 }
10201 }
10202 }
10203  
10204 14 ▶ if (!key_sv && error_out && !*error_out) {
Branch: 3 branches
BranchTrueFalseTotal
if (!key_sv && error_out && !*error_out) { 0 14 14
if (!key_sv && error_out && !*error_out) { 0 0 0
if (!key_sv && error_out && !*error_out) { 0 0 0
10205 0 *error_out = newSVpvs("declarative loader key is undefined");
10206 }
10207 14 ▶ if (loader_sv && key_sv
Branch: 2 branches
BranchTrueFalseTotal
if (loader_sv && key_sv 14 0 14
if (loader_sv && key_sv 14 0 14
10208 14 ▶ && gql_runtime_vm_is_exact_dataloader(aTHX_ loader_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_is_exact_dataloader(aTHX_ loader_sv)) { 13 1 14
10209 13 ret = gql_runtime_vm_dataloader_load_exact_sv(
10210 aTHX_ loader_sv, key_sv, error_out
10211 );
10212 1 ▶ } else if (loader_sv && key_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (loader_sv && key_sv) { 1 0 1
} else if (loader_sv && key_sv) { 1 0 1
10213 1 dSP;
10214 int count;
10215 1 ENTER;
10216 1 SAVETMPS;
10217 1 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 1 0 1
10218 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
10219 1 ▶ XPUSHs(loader_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(loader_sv); 0 1 1
10220 1 ▶ XPUSHs(key_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(key_sv); 0 1 1
10221 1 PUTBACK;
10222 1 count = call_method("load", G_SCALAR | G_EVAL);
10223 1 SPAGAIN;
10224 1 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1 0 1
if (SvTRUE(ERRSV)) { 0 1 1
10225 0 ▶ if (error_out && !*error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && !*error_out) { 0 0 0
if (error_out && !*error_out) { 0 0 0
10226 0 ▶ *error_out = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVsv(ERRSV); 0 0 0
10227 }
10228 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
10229 1 ▶ } else if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (count > 0) { 1 0 1
10230 1 ret = newSVsv(POPs);
10231 }
10232 1 PUTBACK;
10233 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1 0 1
10234 1 LEAVE;
10235 }
10236 14 ▶ if (args_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (args_sv) { 1 13 14
10237 1 SvREFCNT_dec(args_sv);
10238 }
10239 14 SvREFCNT_dec(owned_key_sv);
10240 14 SvREFCNT_dec(owned_route_key_sv);
10241 14 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv( 0 14 14
10242 0 aTHX_ state, ret ? ret : newSVsv(&PL_sv_undef), error_out
10243 );
10244 }
10245 9875 ▶ resolver_sv = (runtime->callback_catalog && runtime->callback_catalog->slot_resolvers)
Branch: 1 branch
BranchTrueFalseTotal
resolver_sv = (runtime->callback_catalog && runtime->callback_catalog->slot_resolvers) 9875 0 9875
10246 9875 ? runtime->callback_catalog->slot_resolvers[slot->schema_slot_index]
10247 19750 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 9875 0 9875
10248  
10249 9875 ▶ if (!resolver_sv || !SvOK(resolver_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolver_sv || !SvOK(resolver_sv)) { 9875 0 9875
if (!resolver_sv || !SvOK(resolver_sv)) { 0 9875 9875
10250 0 return gql_runtime_vm_clone_value_sv(aTHX_ &PL_sv_undef);
10251 }
10252  
10253 9875 ▶ if (gql_runtime_vm_slot_uses_native_no_args_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_no_args_abi(slot)) { 1 9874 9875
10254 1 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
10255 2 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv( 1 0 1
10256 aTHX_ state,
10257 gql_runtime_vm_call_cb3_nonfatal(
10258 aTHX_
10259 resolver_sv,
10260 source,
10261 1 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 1 0 1
10262 return_type_sv ? return_type_sv : &PL_sv_undef,
10263 error_out
10264 ),
10265 error_out
10266 );
10267 }
10268 9874 ▶ if (gql_runtime_vm_slot_uses_native_one_arg_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_one_arg_abi(slot)) { 4 9870 9874
10269 4 SV *value = gql_runtime_vm_build_current_one_arg_sv(aTHX_ state);
10270 4 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 4 4
10271 0 return newSVsv(&PL_sv_undef);
10272 }
10273 4 value = sv_2mortal(value);
10274 4 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
10275 8 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal( 4 0 4
10276 aTHX_
10277 resolver_sv,
10278 source,
10279 value,
10280 4 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 4 0 4
10281 return_type_sv ? return_type_sv : &PL_sv_undef,
10282 error_out
10283 ), error_out);
10284 }
10285  
10286 {
10287 9870 SV *args = gql_runtime_vm_build_current_args_sv(aTHX_ state);
10288 9870 ▶ if (!args) {
Branch: 1 branch
BranchTrueFalseTotal
if (!args) { 3 9867 9870
10289 /* Argument coercion failed and armed the deferred croak channel:
10290 * skip the resolver and complete the field as null. */
10291 3 return newSVsv(&PL_sv_undef);
10292 }
10293 9867 args = sv_2mortal(args);
10294  
10295 9867 ▶ if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_slot_uses_native_fast_abi(slot)) { 44 9823 9867
10296 44 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
10297 88 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb4_nonfatal( 44 0 44
10298 aTHX_
10299 resolver_sv,
10300 source,
10301 args,
10302 44 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 44 0 44
10303 return_type_sv ? return_type_sv : &PL_sv_undef,
10304 error_out
10305 ), error_out);
10306 }
10307  
10308 9823 return_type_sv = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
10309 9823 ▶ if (!return_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!return_type_sv) { 0 9823 9823
10310 0 return_type_sv = gql_runtime_vm_lookup_slot_type_object_sv(
10311 aTHX_ runtime,
10312 0 ▶ state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef, 0 0 0
10313 slot
10314 );
10315 }
10316  
10317 19646 ▶ return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb5_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_fast_lane_guard_promise_sv(aTHX_ state, gql_runtime_vm_call_cb5_nonfatal( 9823 0 9823
10318 aTHX_
10319 resolver_sv,
10320 source,
10321 args,
10322 9823 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 9823 0 9823
10323 sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state)),
10324 return_type_sv ? return_type_sv : &PL_sv_undef,
10325 error_out
10326 ), error_out);
10327 }
10328 }
10329  
10330 static IV
10331 10593 gql_runtime_vm_dispatch_index_from_opcode(IV opcode_code)
10332 {
10333 10593 switch (opcode_code) {
10334 593 case GQL_VM_OPCODE(GQL_VM_RESOLVE_DEFAULT, GQL_VM_COMPLETE_GENERIC): return 0;
10335 101 case GQL_VM_OPCODE(GQL_VM_RESOLVE_DEFAULT, GQL_VM_COMPLETE_OBJECT): return 1;
10336 10 case GQL_VM_OPCODE(GQL_VM_RESOLVE_DEFAULT, GQL_VM_COMPLETE_LIST): return 2;
10337 0 case GQL_VM_OPCODE(GQL_VM_RESOLVE_DEFAULT, GQL_VM_COMPLETE_ABSTRACT): return 3;
10338 7172 case GQL_VM_OPCODE(GQL_VM_RESOLVE_EXPLICIT, GQL_VM_COMPLETE_GENERIC): return 4;
10339 1539 case GQL_VM_OPCODE(GQL_VM_RESOLVE_EXPLICIT, GQL_VM_COMPLETE_OBJECT): return 5;
10340 1132 case GQL_VM_OPCODE(GQL_VM_RESOLVE_EXPLICIT, GQL_VM_COMPLETE_LIST): return 6;
10341 46 case GQL_VM_OPCODE(GQL_VM_RESOLVE_EXPLICIT, GQL_VM_COMPLETE_ABSTRACT): return 7;
10342 0 default: return -1;
10343 }
10344 }
10345  
10346 /*
10347 * Shared abstract dispatch for the sync fast lanes: resolve the concrete
10348 * runtime type for `value` (tag resolver / resolve_type / possible types)
10349 * and return the matching abstract child block index, or -1.
10350 */
10351 static IV
10352 105 gql_runtime_vm_select_abstract_child_block_fast_core(
10353 pTHX_
10354 gql_runtime_vm_exec_state_t *state,
10355 SV *value,
10356 SV **error_out
10357 )
10358 {
10359 105 IV child_block_index = -1;
10360 105 gql_runtime_vm_native_runtime_t *runtime = state->runtime;
10361 105 const gql_runtime_vm_native_slot_t *slot = state->slot;
10362 105 const gql_runtime_vm_native_op_t *op = state->op;
10363 105 ▶ gql_runtime_vm_native_callback_catalog_t *catalog = runtime ? runtime->callback_catalog : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_callback_catalog_t *catalog = runtime ? runtime->callback_catalog : NULL; 105 0 105
10364 IV slot_index;
10365 105 SV *info_sv = NULL;
10366 105 SV *abstract_type = NULL;
10367 105 int use_native_fast_abi = gql_runtime_vm_slot_uses_native_fast_abi(slot);
10368  
10369 105 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 105 105
10370 0 return -1;
10371 }
10372 105 slot_index = slot->schema_slot_index;
10373 105 ▶ if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 105 0 105
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 0 105 105
10374 0 return -1;
10375 }
10376  
10377 105 ▶ if (op->dispatch_family_code == GQL_VM_DISPATCH_TAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->dispatch_family_code == GQL_VM_DISPATCH_TAG) { 105 0 105
10378 105 ▶ SV *tag_resolver = (catalog && catalog->slot_tag_resolvers)
Branch: 1 branch
BranchTrueFalseTotal
SV *tag_resolver = (catalog && catalog->slot_tag_resolvers) 105 0 105
10379 105 ? catalog->slot_tag_resolvers[slot_index]
10380 210 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 105 0 105
10381 SV *tag_sv;
10382 105 const char *type_name = NULL;
10383  
10384 105 ▶ if (tag_resolver
Branch: 1 branch
BranchTrueFalseTotal
if (tag_resolver 101 4 105
10385 101 ▶ && catalog
Branch: 1 branch
BranchTrueFalseTotal
&& catalog 101 0 101
10386 101 ▶ && catalog->slot_tag_entries
Branch: 1 branch
BranchTrueFalseTotal
&& catalog->slot_tag_entries 101 0 101
10387 101 ▶ && catalog->slot_tag_entry_counts
Branch: 1 branch
BranchTrueFalseTotal
&& catalog->slot_tag_entry_counts 101 0 101
10388 101 ▶ && catalog->slot_tag_entry_counts[slot_index] > 0) {
Branch: 1 branch
BranchTrueFalseTotal
&& catalog->slot_tag_entry_counts[slot_index] > 0) { 101 0 101
10389 101 abstract_type = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
10390 101 ▶ if (!abstract_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (!abstract_type) { 0 101 101
10391 0 abstract_type = gql_runtime_vm_lookup_slot_type_object_sv(
10392 aTHX_
10393 runtime,
10394 0 ▶ state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef, 0 0 0
10395 slot
10396 );
10397 }
10398 101 ▶ if (use_native_fast_abi) {
Branch: 1 branch
BranchTrueFalseTotal
if (use_native_fast_abi) { 5 96 101
10399 10 ▶ tag_sv = gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
tag_sv = gql_runtime_vm_call_cb4_nonfatal( 5 0 5
10400 aTHX_
10401 tag_resolver,
10402 value,
10403 5 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 5 0 5
10404 abstract_type ? abstract_type : &PL_sv_undef,
10405 &PL_sv_undef,
10406 error_out
10407 );
10408 } else {
10409 96 ▶ if (!info_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!info_sv) { 96 0 96
10410 96 info_sv = sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state));
10411 }
10412 192 ▶ tag_sv = gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
tag_sv = gql_runtime_vm_call_cb4_nonfatal( 96 0 96
10413 aTHX_
10414 tag_resolver,
10415 value,
10416 96 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 96 0 96
10417 info_sv,
10418 abstract_type ? abstract_type : &PL_sv_undef,
10419 error_out
10420 );
10421 }
10422 101 ▶ if (error_out && *error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && *error_out) { 101 0 101
if (error_out && *error_out) { 0 101 101
10423 0 return -1;
10424 }
10425 101 type_name = gql_runtime_vm_find_tagged_type_name(runtime, slot_index, tag_sv);
10426 101 child_block_index = gql_runtime_vm_find_abstract_child_block_index(op, type_name);
10427 101 SvREFCNT_dec(tag_sv);
10428 }
10429 }
10430  
10431 105 ▶ if (child_block_index < 0
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index < 0 16 89 105
10432 16 ▶ && (op->dispatch_family_code == GQL_VM_DISPATCH_RESOLVE_TYPE
Branch: 1 branch
BranchTrueFalseTotal
&& (op->dispatch_family_code == GQL_VM_DISPATCH_RESOLVE_TYPE 16 0 16
10433 16 ▶ || op->dispatch_family_code == GQL_VM_DISPATCH_TAG)) {
Branch: 1 branch
BranchTrueFalseTotal
|| op->dispatch_family_code == GQL_VM_DISPATCH_TAG)) { 16 0 16
10434 16 ▶ SV *resolve_type = (catalog && catalog->slot_resolve_types)
Branch: 1 branch
BranchTrueFalseTotal
SV *resolve_type = (catalog && catalog->slot_resolve_types) 16 0 16
10435 16 ? catalog->slot_resolve_types[slot_index]
10436 32 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 16 0 16
10437 SV *type_sv;
10438 16 const char *type_name = NULL;
10439  
10440 16 ▶ if (!resolve_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (!resolve_type) { 12 4 16
10441 12 return -1;
10442 }
10443 4 ▶ if (!abstract_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (!abstract_type) { 4 0 4
10444 4 abstract_type = gql_runtime_vm_direct_slot_type_object_sv(runtime, slot);
10445 }
10446 4 ▶ if (!abstract_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (!abstract_type) { 0 4 4
10447 0 abstract_type = gql_runtime_vm_lookup_slot_type_object_sv(
10448 aTHX_
10449 runtime,
10450 0 ▶ state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->runtime_schema : &PL_sv_undef, 0 0 0
10451 slot
10452 );
10453 }
10454 4 ▶ if (use_native_fast_abi) {
Branch: 1 branch
BranchTrueFalseTotal
if (use_native_fast_abi) { 0 4 4
10455 0 ▶ type_sv = gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
type_sv = gql_runtime_vm_call_cb4_nonfatal( 0 0 0
10456 aTHX_
10457 resolve_type,
10458 value,
10459 0 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 0 0 0
10460 &PL_sv_undef,
10461 abstract_type ? abstract_type : &PL_sv_undef,
10462 error_out
10463 );
10464 } else {
10465 4 ▶ if (!info_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!info_sv) { 4 0 4
10466 4 info_sv = sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state));
10467 }
10468 8 ▶ type_sv = gql_runtime_vm_call_cb4_nonfatal(
Branch: 1 branch
BranchTrueFalseTotal
type_sv = gql_runtime_vm_call_cb4_nonfatal( 4 0 4
10469 aTHX_
10470 resolve_type,
10471 value,
10472 4 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 4 0 4
10473 info_sv,
10474 abstract_type ? abstract_type : &PL_sv_undef,
10475 error_out
10476 );
10477 }
10478 4 ▶ if (error_out && *error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && *error_out) { 4 0 4
if (error_out && *error_out) { 1 3 4
10479 1 return -1;
10480 }
10481 3 type_name = gql_runtime_vm_type_name_from_sv(aTHX_ type_sv);
10482 3 child_block_index = gql_runtime_vm_find_abstract_child_block_index(op, type_name);
10483 3 SvREFCNT_dec(type_sv);
10484 }
10485  
10486 92 ▶ if (child_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index < 0) { 0 92 92
10487 0 ▶ if (!use_native_fast_abi && !info_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!use_native_fast_abi && !info_sv) { 0 0 0
if (!use_native_fast_abi && !info_sv) { 0 0 0
10488 0 info_sv = sv_2mortal(gql_runtime_vm_new_callback_info_sv(aTHX_ state));
10489 }
10490 gql_runtime_vm_native_possible_type_entry_t *entry =
10491 0 ▶ gql_runtime_vm_find_matching_possible_type(
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_find_matching_possible_type( 0 0 0
10492 aTHX_
10493 runtime,
10494 slot_index,
10495 value,
10496 0 ▶ state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef,
Branch: 1 branch
BranchTrueFalseTotal
state->callback_ctx ? state->callback_ctx->context : &PL_sv_undef, 0 0 0
10497 use_native_fast_abi ? NULL : info_sv,
10498 error_out
10499 );
10500 0 ▶ if (error_out && *error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && *error_out) { 0 0 0
if (error_out && *error_out) { 0 0 0
10501 0 return -1;
10502 }
10503 0 ▶ if (entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry) { 0 0 0
10504 0 ▶ if (op->abstract_child_count == 1
Branch: 1 branch
BranchTrueFalseTotal
if (op->abstract_child_count == 1 0 0 0
10505 0 ▶ && op->abstract_child_names
Branch: 1 branch
BranchTrueFalseTotal
&& op->abstract_child_names 0 0 0
10506 0 ▶ && op->abstract_child_names[0]
Branch: 1 branch
BranchTrueFalseTotal
&& op->abstract_child_names[0] 0 0 0
10507 0 ▶ && entry->type_name
Branch: 1 branch
BranchTrueFalseTotal
&& entry->type_name 0 0 0
10508 0 ▶ && strEQ(op->abstract_child_names[0], entry->type_name)) {
Branch: 1 branch
BranchTrueFalseTotal
&& strEQ(op->abstract_child_names[0], entry->type_name)) { 0 0 0
10509 0 ▶ child_block_index = op->abstract_child_indexes ? op->abstract_child_indexes[0] : -1;
Branch: 1 branch
BranchTrueFalseTotal
child_block_index = op->abstract_child_indexes ? op->abstract_child_indexes[0] : -1; 0 0 0
10510 } else {
10511 0 child_block_index = gql_runtime_vm_find_abstract_child_block_index(op, entry->type_name);
10512 }
10513 }
10514 }
10515  
10516 92 return child_block_index;
10517 }
10518  
10519 /* Failing to resolve a member type is a field error per the spec: the
10520 * callers null the field/item and record the error, never leak the raw
10521 * source value. The wrapper guarantees the error regardless of which
10522 * early return in the core produced the -1. */
10523 static IV
10524 105 gql_runtime_vm_select_abstract_child_block_fast(
10525 pTHX_
10526 gql_runtime_vm_exec_state_t *state,
10527 SV *value,
10528 SV **error_out
10529 )
10530 {
10531 105 const gql_runtime_vm_native_slot_t *slot = state->slot;
10532 105 IV child_block_index = gql_runtime_vm_select_abstract_child_block_fast_core(
10533 aTHX_ state, value, error_out
10534 );
10535 105 ▶ if (child_block_index < 0 && error_out && !*error_out) {
Branch: 3 branches
BranchTrueFalseTotal
if (child_block_index < 0 && error_out && !*error_out) { 13 92 105
if (child_block_index < 0 && error_out && !*error_out) { 13 0 13
if (child_block_index < 0 && error_out && !*error_out) { 12 1 13
10536 12 ▶ *error_out = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
*error_out = newSVpvf( 12 0 12
*error_out = newSVpvf( 12 0 12
10537 "Abstract type %s must resolve to an Object type at runtime",
10538 slot && slot->return_type_name ? slot->return_type_name : "(unknown)"
10539 );
10540 }
10541 105 return child_block_index;
10542 }
10543  
10544 static SV *
10545 39 gql_runtime_vm_complete_current_abstract_fast_sv(
10546 pTHX_
10547 gql_runtime_vm_exec_state_t *state,
10548 SV *value,
10549 SV **error_out
10550 )
10551 {
10552 IV child_block_index;
10553 /* A null abstract value completes as null without consulting the
10554 * tag/resolve_type dispatch (mirrors the async lane). */
10555 39 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 39 0 39
if (!value || !SvOK(value)) { 4 35 39
10556 4 return newSVsv(&PL_sv_undef);
10557 }
10558 35 child_block_index = gql_runtime_vm_select_abstract_child_block_fast(
10559 aTHX_ state, value, error_out
10560 );
10561 35 ▶ if (error_out && *error_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (error_out && *error_out) { 35 0 35
if (error_out && *error_out) { 4 31 35
10562 4 return NULL;
10563 }
10564 31 ▶ if (child_block_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_block_index < 0) { 0 31 31
10565 0 return newSVsv(&PL_sv_undef);
10566 }
10567 {
10568 /* Phase 6: field-path bookkeeping (reuse state->path_frame if the
10569 * caller already made it the current field's path, else build one),
10570 * passed explicitly to the sibling-preserving safe wrapper instead of
10571 * threading it implicitly through state the way the old (now removed)
10572 * abort-on-suspend child-block dispatcher used to. */
10573 62 gql_runtime_vm_path_frame_t *field_path = state->path_frame_is_current_field
10574 ? state->path_frame
10575 31 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ state->path_frame, state->slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ state->path_frame, state->slot); 28 3 31
10576 31 SV *ret = gql_runtime_vm_execute_safe_child_block_fast_sv(
10577 aTHX_ state, child_block_index, value, field_path, 0
10578 );
10579 31 ▶ if (!state->path_frame_is_current_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->path_frame_is_current_field) { 3 28 31
10580 3 gql_runtime_vm_path_frame_decref(field_path);
10581 }
10582 31 return ret;
10583 }
10584 }
10585  
10586 static SV *
10587 4791 gql_runtime_vm_complete_current_generic_fast_sv(
10588 pTHX_
10589 gql_runtime_vm_exec_state_t *state,
10590 SV *value,
10591 SV **error_out
10592 )
10593 {
10594 /*
10595 * Leaf result coercion: serialize_leaf_sv returns an owned SV (the input
10596 * with an extra ref when it already conforms, matching this lane's
10597 * ownership-transfer contract; the dispatch loop drops the original
10598 * "resolved" ref after completion). A coercion failure sets *error_out
10599 * and the loop records a field error + null.
10600 */
10601 4791 return gql_runtime_vm_serialize_leaf_sv(aTHX_ state->runtime, state->slot, value, error_out);
10602 }
10603  
10604 static SV *
10605 1397 gql_runtime_vm_complete_current_object_fast_sv(pTHX_ gql_runtime_vm_exec_state_t *state, SV *value)
10606 {
10607 1397 const gql_runtime_vm_native_op_t *op = state->op;
10608 1397 ▶ if (op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) { 1397 0 1397
if (op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) { 1397 0 1397
10609 /* A null resolved value completes as null; the selection block only
10610 * runs over a present source (mirrors the async lane). */
10611 1397 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 1397 0 1397
if (!value || !SvOK(value)) { 9 1388 1397
10612 9 return newSVsv(&PL_sv_undef);
10613 }
10614 {
10615 /* Phase 6: see the matching comment in
10616 * gql_runtime_vm_complete_current_abstract_fast_sv. */
10617 2776 gql_runtime_vm_path_frame_t *field_path = state->path_frame_is_current_field
10618 ? state->path_frame
10619 1388 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ state->path_frame, state->slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ state->path_frame, state->slot); 1382 6 1388
10620 1388 SV *ret = gql_runtime_vm_execute_safe_child_block_fast_sv(
10621 1388 aTHX_ state, op->child_block_index, value, field_path, 0
10622 );
10623 1388 ▶ if (!state->path_frame_is_current_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->path_frame_is_current_field) { 6 1382 1388
10624 6 gql_runtime_vm_path_frame_decref(field_path);
10625 }
10626 1388 return ret;
10627 }
10628 }
10629 0 return gql_runtime_vm_clone_value_sv(aTHX_ value);
10630 }
10631  
10632 /* Record a field error at `path` on the fast lanes' shared writer (the
10633 * envelope/JSON response tails render writer records into the errors
10634 * array). Copies error_sv; the caller keeps ownership. */
10635 static void
10636 484 gql_runtime_vm_fast_lane_record_error_for_path(
10637 pTHX_
10638 gql_runtime_vm_exec_state_t *state,
10639 SV *error_sv,
10640 gql_runtime_vm_path_frame_t *path
10641 )
10642 {
10643 gql_runtime_vm_outcome_t *outcome =
10644 484 gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ error_sv, path);
10645 484 ▶ if (state->writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->writer) { 484 0 484
10646 IV j;
10647 968 ▶ for (j = 0; j < outcome->error_record_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < outcome->error_record_count; j++) { 484 484 968
10648 484 gql_runtime_vm_writer_push_error_record(state->writer, outcome->error_records[j]);
10649 }
10650 }
10651 484 gql_runtime_vm_outcome_decref(aTHX_ outcome);
10652 484 }
10653  
10654 /* Phase 5/6: drop-in replacement for both gql_runtime_vm_execute_block_fast_sv
10655 * (at the object/abstract list-item call site) and
10656 * gql_runtime_vm_execute_child_block_fast_sv (at the plain OBJECT/ABSTRACT
10657 * field child-block call sites, Phase 6) - the two functions it replaces
10658 * are themselves identical in contract (the latter is a thin path-frame
10659 * wrapper around the former), so one safe implementation covers both.
10660 * Returns the exact same shapes those functions do - NULL for a definite
10661 * non-null violation with nothing async in flight (the caller's existing
10662 * item_had_error/null handling is unchanged), or an owned plain hashref SV
10663 * when every field in the child block resolved synchronously - PLUS one
10664 * new shape those functions could never produce: a genuine Promise::XS
10665 * when a field inside the child block suspended (or a non-null violation
10666 * happened after an earlier sibling in the SAME block already suspended -
10667 * the frame's self_nulled flag carries that through to settle time). Every
10668 * existing caller already treats such a promise correctly (a non-null
10669 * check against a blessed reference is false, so it does not fire early),
10670 * so no other change is needed beyond swapping the call - this is exactly
10671 * how Phase 6 reuses this same function one or more levels deeper than
10672 * Phase 5's list-item call site, recursively, for as many nested object/
10673 * abstract fields as gql_runtime_vm_fast_lane_list_item_block_is_eligible
10674 * allows.
10675 *
10676 * want_promise selects what a genuinely pending result looks like: 1 (the
10677 * list-item call site) asks gql_runtime_vm_block_frame_finalize_sv for its
10678 * promise-producing mode, since Layer 2's list_pending aggregation expects
10679 * a Promise::XS-shaped per-item value; 0 (every other call site - a plain
10680 * OBJECT/ABSTRACT field, at any depth, root included) asks for its raw
10681 * block-frame-handle mode instead (Phase 7), which skips the deferred_sv/
10682 * promise_sv pair and the arm/drain call entirely when nothing needs it
10683 * yet - the caller then threads the frame straight into its own pending
10684 * tree via gql_runtime_vm_push_pending_block_frame, the same raw frame-to-
10685 * frame linkage the generic executor's own gql_runtime_vm_consume_current_result_now
10686 * already uses for this exact shape (and which gql_runtime_vm_cancel_frame_tree
10687 * already knows how to cancel, unlike a bespoke Promise::XS wrapper). */
10688 static SV *
10689 4469 gql_runtime_vm_execute_safe_child_block_fast_sv(
10690 pTHX_
10691 gql_runtime_vm_exec_state_t *state,
10692 IV item_block_index,
10693 SV *item,
10694 gql_runtime_vm_path_frame_t *item_path_frame,
10695 U8 want_promise
10696 )
10697 {
10698 4469 gql_runtime_vm_native_block_t *block = &state->bundle->blocks[item_block_index];
10699 SV **resolved_values;
10700 4469 gql_runtime_vm_block_frame_t *frame = NULL;
10701 4469 SV *state_sv = NULL;
10702 4469 U8 self_nulled = 0;
10703 SV *ret;
10704 IV i;
10705  
10706 4469 ▶ Newxz(resolved_values, block->op_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(resolved_values, block->op_count, SV *); 0 4469 4469
10707 4469 gql_runtime_vm_execute_block_fast_multi_sv(
10708 aTHX_ state, item_block_index, item, item_path_frame,
10709 resolved_values, &frame, &state_sv, &self_nulled
10710 );
10711  
10712 4469 ▶ if (self_nulled) {
Branch: 1 branch
BranchTrueFalseTotal
if (self_nulled) { 18 4451 4469
10713 /* A definite non-null violation with no earlier sibling suspension:
10714 * nothing async is in flight, so there is nothing to wait for -
10715 * discard whatever earlier siblings resolved and return NULL exactly
10716 * like gql_runtime_vm_execute_block_fast_sv would have. */
10717 45 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 27 18 45
10718 27 ▶ if (resolved_values[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolved_values[i]) { 0 27 27
10719 0 SvREFCNT_dec(resolved_values[i]);
10720 }
10721 }
10722 18 Safefree(resolved_values);
10723 18 return NULL;
10724 }
10725  
10726 4451 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 2359 2092 4451
10727 /* Fully synchronous: build the same plain hashref
10728 * gql_runtime_vm_execute_block_fast_sv builds today - zero added cost
10729 * for the common case, unchanged output shape. */
10730 2359 HV *data_hv = newHV();
10731 4898 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 2539 2359 4898
10732 gql_runtime_vm_native_slot_t *slot;
10733 2539 ▶ if (!resolved_values[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (!resolved_values[i]) { 2 2537 2539
10734 2 continue;
10735 }
10736 2537 slot = &block->slots[block->ops[i].slot_index];
10737 2537 hv_store(data_hv, slot->result_name, (I32)slot->result_name_len, resolved_values[i], 0);
10738 }
10739 2359 Safefree(resolved_values);
10740 2359 return newRV_noinc((SV *)data_hv);
10741 }
10742  
10743 /* Something inside this item's own child block suspended (or self_nulled
10744 * on the frame, per above). Fold every resolved sibling into the frame's
10745 * native value tree, same as the root loop, then finalize right here:
10746 * frame is only ever created once something is genuinely pending, so
10747 * this always takes block_frame_finalize_sv's pending branch (mode 1 or
10748 * 2 per want_promise), never its sync-outcome branch. */
10749 5846 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 3754 2092 5846
10750 gql_runtime_vm_native_slot_t *slot;
10751 3754 ▶ if (!resolved_values[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (!resolved_values[i]) { 2099 1655 3754
10752 2099 continue;
10753 }
10754 1655 slot = &block->slots[block->ops[i].slot_index];
10755 3310 gql_runtime_vm_native_object_store(
10756 1655 aTHX_ frame->values_value, slot->result_name, 1,
10757 1655 gql_runtime_vm_new_native_value_scalar(aTHX_ resolved_values[i])
10758 );
10759 1655 SvREFCNT_dec(resolved_values[i]);
10760 }
10761 2092 Safefree(resolved_values);
10762  
10763 2092 ▶ ret = gql_runtime_vm_block_frame_finalize_sv(
Branch: 1 branch
BranchTrueFalseTotal
ret = gql_runtime_vm_block_frame_finalize_sv( 0 2092 2092
10764 2092 aTHX_ frame, state->runtime->async_adapter, state->writer, state_sv,
10765 want_promise ? 2 : 1
10766 );
10767 2092 return ret;
10768 }
10769  
10770 /* A deliberately narrow executor-owned DataLoader batch. The ordinary
10771 * declarative path still creates one Ticket and one resumable frame per
10772 * row. For a single root object-list whose item has exactly one nullable
10773 * declarative loader field, all keys are already visible at once, so an
10774 * opted-in cacheless loader can call its batch function directly and run
10775 * the loaded object's scalar-only child block synchronously. */
10776 static SV *
10777 717 gql_runtime_vm_try_complete_declarative_batch_plan_list_fast_sv(
10778 pTHX_ gql_runtime_vm_exec_state_t *state, AV *in_av, int *handled_out
10779 )
10780 {
10781 gql_runtime_vm_native_block_t *item_block;
10782 gql_runtime_vm_native_block_t *loaded_block;
10783 const gql_runtime_vm_native_op_t *loader_op;
10784 const gql_runtime_vm_native_slot_t *plan_slot;
10785 const gql_runtime_vm_native_slot_t *loader_slot;
10786 gql_runtime_vm_native_loader_spec_t *loader_spec;
10787 HV *context_hv;
10788 HV *loader_hv;
10789 SV **svp;
10790 SV *loader_sv;
10791 SV *batch_sv;
10792 AV *keys_av;
10793 717 AV *values_av = NULL;
10794 717 SV *batch_error = NULL;
10795 AV *out_av;
10796 gql_runtime_vm_path_frame_t *saved_path;
10797 int saved_path_is_current;
10798 gql_runtime_vm_path_frame_t *list_path;
10799 IV count;
10800 IV i;
10801  
10802 717 *handled_out = 0;
10803 717 ▶ if (!state || !state->runtime || !state->bundle || !state->callback_ctx
Branch: 4 branches
BranchTrueFalseTotal
if (!state || !state->runtime || !state->bundle || !state->callback_ctx 717 0 717
if (!state || !state->runtime || !state->bundle || !state->callback_ctx 717 0 717
if (!state || !state->runtime || !state->bundle || !state->callback_ctx 717 0 717
if (!state || !state->runtime || !state->bundle || !state->callback_ctx 717 0 717
10804 717 ▶ || state->block_index != state->fast_lane_root_block_index
Branch: 1 branch
BranchTrueFalseTotal
|| state->block_index != state->fast_lane_root_block_index 662 55 717
10805 662 ▶ || !state->block || state->block->op_count != 1
Branch: 2 branches
BranchTrueFalseTotal
|| !state->block || state->block->op_count != 1 662 0 662
|| !state->block || state->block->op_count != 1 440 222 662
10806 440 ▶ || !state->op || state->op->child_block_index < 0
Branch: 2 branches
BranchTrueFalseTotal
|| !state->op || state->op->child_block_index < 0 440 0 440
|| !state->op || state->op->child_block_index < 0 430 10 440
10807 430 ▶ || state->op->abstract_child_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
|| state->op->abstract_child_count > 0) { 0 430 430
10808 287 return NULL;
10809 }
10810 430 item_block = &state->bundle->blocks[state->op->child_block_index];
10811 430 ▶ if (item_block->op_count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (item_block->op_count != 1) { 421 9 430
10812 421 return NULL;
10813 }
10814 9 loader_op = &item_block->ops[0];
10815 9 ▶ if (loader_op->slot_index < 0 || loader_op->slot_index >= item_block->slot_count
Branch: 2 branches
BranchTrueFalseTotal
if (loader_op->slot_index < 0 || loader_op->slot_index >= item_block->slot_count 9 0 9
if (loader_op->slot_index < 0 || loader_op->slot_index >= item_block->slot_count 9 0 9
10816 9 ▶ || loader_op->complete_code != GQL_VM_COMPLETE_OBJECT
Branch: 1 branch
BranchTrueFalseTotal
|| loader_op->complete_code != GQL_VM_COMPLETE_OBJECT 3 6 9
10817 3 ▶ || loader_op->child_block_index < 0
Branch: 1 branch
BranchTrueFalseTotal
|| loader_op->child_block_index < 0 3 0 3
10818 3 ▶ || loader_op->abstract_child_count > 0
Branch: 1 branch
BranchTrueFalseTotal
|| loader_op->abstract_child_count > 0 3 0 3
10819 3 ▶ || loader_op->has_directives || loader_op->has_runtime_directives
Branch: 2 branches
BranchTrueFalseTotal
|| loader_op->has_directives || loader_op->has_runtime_directives 3 0 3
|| loader_op->has_directives || loader_op->has_runtime_directives 3 0 3
10820 3 ▶ || loader_op->runtime_directives_sv) {
Branch: 1 branch
BranchTrueFalseTotal
|| loader_op->runtime_directives_sv) { 0 3 3
10821 6 return NULL;
10822 }
10823 3 plan_slot = &item_block->slots[loader_op->slot_index];
10824 3 loader_slot = gql_runtime_vm_effective_slot(state->runtime, plan_slot);
10825 3 ▶ if (!loader_slot || loader_slot->return_type_kind_code == 8
Branch: 2 branches
BranchTrueFalseTotal
if (!loader_slot || loader_slot->return_type_kind_code == 8 3 0 3
if (!loader_slot || loader_slot->return_type_kind_code == 8 3 0 3
10826 3 ▶ || loader_slot->has_args || loader_slot->arg_def_count > 0
Branch: 2 branches
BranchTrueFalseTotal
|| loader_slot->has_args || loader_slot->arg_def_count > 0 3 0 3
|| loader_slot->has_args || loader_slot->arg_def_count > 0 3 0 3
10827 3 ▶ || !state->runtime->callback_catalog
Branch: 1 branch
BranchTrueFalseTotal
|| !state->runtime->callback_catalog 3 0 3
10828 3 ▶ || !state->runtime->callback_catalog->slot_native_loader_specs
Branch: 1 branch
BranchTrueFalseTotal
|| !state->runtime->callback_catalog->slot_native_loader_specs 3 0 3
10829 3 ▶ || loader_slot->schema_slot_index < 0
Branch: 1 branch
BranchTrueFalseTotal
|| loader_slot->schema_slot_index < 0 3 0 3
10830 3 ▶ || loader_slot->schema_slot_index >= state->runtime->runtime_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
|| loader_slot->schema_slot_index >= state->runtime->runtime_slot_count) { 0 3 3
10831 0 return NULL;
10832 }
10833 3 loader_spec = state->runtime->callback_catalog
10834 3 ->slot_native_loader_specs[loader_slot->schema_slot_index];
10835 3 ▶ if (!loader_spec || loader_spec->uses_router || loader_spec->key_kind != 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (!loader_spec || loader_spec->uses_router || loader_spec->key_kind != 1) { 2 1 3
if (!loader_spec || loader_spec->uses_router || loader_spec->key_kind != 1) { 2 0 2
if (!loader_spec || loader_spec->uses_router || loader_spec->key_kind != 1) { 0 2 2
10836 1 return NULL;
10837 }
10838  
10839 2 loaded_block = &state->bundle->blocks[loader_op->child_block_index];
10840 5 ▶ for (i = 0; i < loaded_block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < loaded_block->op_count; i++) { 3 2 5
10841 3 const gql_runtime_vm_native_op_t *op = &loaded_block->ops[i];
10842 const gql_runtime_vm_native_slot_t *slot;
10843 3 IV leaf_kind = GQL_VM_LEAF_NONE;
10844 3 ▶ if (op->slot_index < 0 || op->slot_index >= loaded_block->slot_count
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= loaded_block->slot_count 3 0 3
if (op->slot_index < 0 || op->slot_index >= loaded_block->slot_count 3 0 3
10845 3 ▶ || op->resolve_code != GQL_VM_RESOLVE_DEFAULT
Branch: 1 branch
BranchTrueFalseTotal
|| op->resolve_code != GQL_VM_RESOLVE_DEFAULT 3 0 3
10846 3 ▶ || op->complete_code != GQL_VM_COMPLETE_GENERIC
Branch: 1 branch
BranchTrueFalseTotal
|| op->complete_code != GQL_VM_COMPLETE_GENERIC 3 0 3
10847 3 ▶ || op->child_block_index >= 0 || op->abstract_child_count > 0
Branch: 2 branches
BranchTrueFalseTotal
|| op->child_block_index >= 0 || op->abstract_child_count > 0 3 0 3
|| op->child_block_index >= 0 || op->abstract_child_count > 0 3 0 3
10848 3 ▶ || op->has_directives || op->has_runtime_directives
Branch: 2 branches
BranchTrueFalseTotal
|| op->has_directives || op->has_runtime_directives 3 0 3
|| op->has_directives || op->has_runtime_directives 3 0 3
10849 3 ▶ || op->runtime_directives_sv) {
Branch: 1 branch
BranchTrueFalseTotal
|| op->runtime_directives_sv) { 0 3 3
10850 0 return NULL;
10851 }
10852 3 slot = gql_runtime_vm_effective_slot(
10853 3 state->runtime, &loaded_block->slots[op->slot_index]
10854 );
10855 3 ▶ if (!slot || slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT
Branch: 2 branches
BranchTrueFalseTotal
if (!slot || slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT 3 0 3
if (!slot || slot->resolver_shape_code != GQL_VM_RESOLVE_DEFAULT 3 0 3
10856 3 ▶ || (slot->accessor_name && slot->accessor_name_len)
Branch: 2 branches
BranchTrueFalseTotal
|| (slot->accessor_name && slot->accessor_name_len) 0 3 3
|| (slot->accessor_name && slot->accessor_name_len) 0 0 0
10857 3 ▶ || gql_runtime_vm_slot_resolver_sv(state->runtime, slot)) {
Branch: 1 branch
BranchTrueFalseTotal
|| gql_runtime_vm_slot_resolver_sv(state->runtime, slot)) { 0 3 3
10858 0 return NULL;
10859 }
10860 3 ▶ if (state->runtime->callback_catalog->slot_leaf_kinds
Branch: 1 branch
BranchTrueFalseTotal
if (state->runtime->callback_catalog->slot_leaf_kinds 3 0 3
10861 3 ▶ && slot->schema_slot_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index >= 0 3 0 3
10862 3 ▶ && slot->schema_slot_index < state->runtime->runtime_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
&& slot->schema_slot_index < state->runtime->runtime_slot_count) { 3 0 3
10863 3 leaf_kind = state->runtime->callback_catalog
10864 3 ->slot_leaf_kinds[slot->schema_slot_index];
10865 }
10866 3 ▶ if (leaf_kind == GQL_VM_LEAF_CUSTOM) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_kind == GQL_VM_LEAF_CUSTOM) { 0 3 3
10867 0 return NULL;
10868 }
10869 }
10870  
10871 2 ▶ if (!state->callback_ctx->context
Branch: 1 branch
BranchTrueFalseTotal
if (!state->callback_ctx->context 2 0 2
10872 2 ▶ || !SvROK(state->callback_ctx->context)
Branch: 1 branch
BranchTrueFalseTotal
|| !SvROK(state->callback_ctx->context) 2 0 2
10873 2 ▶ || SvTYPE(SvRV(state->callback_ctx->context)) != SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(state->callback_ctx->context)) != SVt_PVHV) { 0 2 2
10874 0 return NULL;
10875 }
10876 2 context_hv = (HV *)SvRV(state->callback_ctx->context);
10877 2 svp = hv_fetch(
10878 context_hv, loader_spec->context_key, (I32)loader_spec->context_key_len, 0
10879 );
10880 2 ▶ loader_sv = (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
loader_sv = (svp && SvOK(*svp)) ? *svp : NULL; 2 0 2
loader_sv = (svp && SvOK(*svp)) ? *svp : NULL; 2 0 2
10881 2 ▶ if (!loader_sv || !gql_runtime_vm_is_exact_dataloader(aTHX_ loader_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!loader_sv || !gql_runtime_vm_is_exact_dataloader(aTHX_ loader_sv)) { 2 0 2
if (!loader_sv || !gql_runtime_vm_is_exact_dataloader(aTHX_ loader_sv)) { 0 2 2
10882 0 return NULL;
10883 }
10884 2 loader_hv = (HV *)SvRV(loader_sv);
10885 2 svp = hv_fetch(loader_hv, "_batch_plan", 11, 0);
10886 2 ▶ if (!svp || !SvTRUE(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvTRUE(*svp)) { 2 0 2
if (!svp || !SvTRUE(*svp)) { 1 1 2
10887 1 return NULL;
10888 }
10889 1 svp = hv_fetch(loader_hv, "cache", 5, 0);
10890 1 ▶ if (!svp || SvTRUE(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || SvTRUE(*svp)) { 1 0 1
if (!svp || SvTRUE(*svp)) { 0 1 1
10891 0 return NULL;
10892 }
10893 1 svp = hv_fetch(loader_hv, "max_batch_size", 14, 0);
10894 1 ▶ if (svp && SvIV(*svp) > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvIV(*svp) > 0) { 1 0 1
if (svp && SvIV(*svp) > 0) { 0 1 1
10895 0 return NULL;
10896 }
10897 1 svp = hv_fetch(loader_hv, "_queue", 6, 0);
10898 1 ▶ if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVAV
Branch: 3 branches
BranchTrueFalseTotal
if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVAV 1 0 1
if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVAV 1 0 1
if (!svp || !SvROK(*svp) || SvTYPE(SvRV(*svp)) != SVt_PVAV 1 0 1
10899 1 ▶ || av_count((AV *)SvRV(*svp)) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
|| av_count((AV *)SvRV(*svp)) != 0) { 0 1 1
10900 0 return NULL;
10901 }
10902 1 svp = hv_fetch(loader_hv, "batch", 5, 0);
10903 1 ▶ batch_sv = (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVCV)
Branch: 2 branches
BranchTrueFalseTotal
batch_sv = (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVCV) 1 0 1
batch_sv = (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVCV) 1 0 1
10904 2 ▶ ? *svp : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? *svp : NULL; 1 0 1
10905 1 ▶ if (!batch_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!batch_sv) { 0 1 1
10906 0 return NULL;
10907 }
10908  
10909 1 count = (IV)av_count(in_av);
10910 1 ▶ if (count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count == 0) { 0 1 1
10911 0 *handled_out = 1;
10912 0 return newRV_noinc((SV *)newAV());
10913 }
10914 1 keys_av = newAV();
10915 1 av_extend(keys_av, count > 0 ? count - 1 : 0);
10916 4 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 3 1 4
10917 3 SV **item_svp = av_fetch(in_av, i, 0);
10918 3 ▶ SV *item = (item_svp && *item_svp) ? *item_svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
SV *item = (item_svp && *item_svp) ? *item_svp : NULL; 3 0 3
SV *item = (item_svp && *item_svp) ? *item_svp : NULL; 3 0 3
10919 SV **key_svp;
10920 3 ▶ if (!item || !SvOK(item) || !SvROK(item)
Branch: 3 branches
BranchTrueFalseTotal
if (!item || !SvOK(item) || !SvROK(item) 3 0 3
if (!item || !SvOK(item) || !SvROK(item) 3 0 3
if (!item || !SvOK(item) || !SvROK(item) 3 0 3
10921 3 ▶ || SvTYPE(SvRV(item)) != SVt_PVHV || sv_isobject(item)) {
Branch: 2 branches
BranchTrueFalseTotal
|| SvTYPE(SvRV(item)) != SVt_PVHV || sv_isobject(item)) { 3 0 3
|| SvTYPE(SvRV(item)) != SVt_PVHV || sv_isobject(item)) { 0 3 3
10922 0 SvREFCNT_dec((SV *)keys_av);
10923 0 return NULL;
10924 }
10925 3 key_svp = hv_fetch(
10926 (HV *)SvRV(item), loader_spec->key_name, (I32)loader_spec->key_name_len, 0
10927 );
10928 3 ▶ if (!key_svp || !SvOK(*key_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!key_svp || !SvOK(*key_svp)) { 3 0 3
if (!key_svp || !SvOK(*key_svp)) { 0 3 3
10929 0 SvREFCNT_dec((SV *)keys_av);
10930 0 return NULL;
10931 }
10932 3 av_push(keys_av, newSVsv(*key_svp));
10933 }
10934  
10935 {
10936 1 dSP;
10937 I32 callback_count;
10938 1 ENTER;
10939 1 SAVETMPS;
10940 1 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 1 0 1
10941 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
10942 1 ▶ XPUSHs(sv_2mortal(newRV_noinc((SV *)keys_av)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_noinc((SV *)keys_av))); 0 1 1
10943 1 PUTBACK;
10944 1 callback_count = call_sv(batch_sv, G_SCALAR | G_EVAL);
10945 1 SPAGAIN;
10946 1 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1 0 1
if (SvTRUE(ERRSV)) { 0 1 1
10947 0 ▶ batch_error = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
batch_error = newSVsv(ERRSV); 0 0 0
10948 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
10949 1 ▶ } else if (callback_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (callback_count == 1) { 1 0 1
10950 1 SV *values_sv = POPs;
10951 1 ▶ if (values_sv && SvROK(values_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (values_sv && SvROK(values_sv) 1 0 1
if (values_sv && SvROK(values_sv) 1 0 1
10952 1 ▶ && SvTYPE(SvRV(values_sv)) == SVt_PVAV
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(values_sv)) == SVt_PVAV 1 0 1
10953 1 ▶ && (IV)av_count((AV *)SvRV(values_sv)) == count) {
Branch: 1 branch
BranchTrueFalseTotal
&& (IV)av_count((AV *)SvRV(values_sv)) == count) { 1 0 1
10954 1 values_av = (AV *)SvREFCNT_inc(SvRV(values_sv));
10955 } else {
10956 0 batch_error = newSVpvs(
10957 "DataLoader batch function must return an arrayref with one entry per key\n"
10958 );
10959 }
10960 } else {
10961 0 batch_error = newSVpvs(
10962 "DataLoader batch function must return an arrayref with one entry per key\n"
10963 );
10964 }
10965 1 PUTBACK;
10966 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1 0 1
10967 1 LEAVE;
10968 }
10969  
10970 1 out_av = newAV();
10971 1 av_extend(out_av, count > 0 ? count - 1 : 0);
10972 1 saved_path = state->path_frame;
10973 1 saved_path_is_current = state->path_frame_is_current_field;
10974 1 list_path = saved_path_is_current
10975 ? saved_path
10976 1 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ saved_path, state->slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ saved_path, state->slot); 0 1 1
10977  
10978 4 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 3 1 4
10979 3 SV *item_key = newSViv(i);
10980 gql_runtime_vm_path_frame_t *item_path =
10981 3 gql_runtime_vm_new_path_frame_struct(aTHX_ list_path, item_key);
10982 gql_runtime_vm_path_frame_t *loader_path =
10983 3 gql_runtime_vm_new_result_path_frame(aTHX_ item_path, plan_slot);
10984 3 HV *row_hv = newHV();
10985 3 SV *completed = NULL;
10986 3 SV *error_sv = batch_error;
10987 3 SV *loaded_value = &PL_sv_undef;
10988 3 SvREFCNT_dec(item_key);
10989  
10990 3 ▶ if (!error_sv && values_av) {
Branch: 2 branches
BranchTrueFalseTotal
if (!error_sv && values_av) { 3 0 3
if (!error_sv && values_av) { 3 0 3
10991 3 SV **value_svp = av_fetch(values_av, i, 0);
10992 3 ▶ loaded_value = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
loaded_value = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef; 3 0 3
loaded_value = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef; 3 0 3
10993 3 ▶ if (sv_isobject(loaded_value)
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(loaded_value) 1 2 3
10994 1 ▶ && sv_derived_from(loaded_value, "GraphQL::Houtou::DataLoader::Error")) {
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from(loaded_value, "GraphQL::Houtou::DataLoader::Error")) { 1 0 1
10995 2 SV **message_svp = SvROK(loaded_value)
10996 1 ▶ && SvTYPE(SvRV(loaded_value)) == SVt_PVHV
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(loaded_value)) == SVt_PVHV 1 0 1
10997 2 ▶ ? hv_fetch((HV *)SvRV(loaded_value), "message", 7, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? hv_fetch((HV *)SvRV(loaded_value), "message", 7, 0) : NULL; 1 0 1
10998 1 ▶ error_sv = (message_svp && *message_svp) ? *message_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
error_sv = (message_svp && *message_svp) ? *message_svp : &PL_sv_undef; 1 0 1
error_sv = (message_svp && *message_svp) ? *message_svp : &PL_sv_undef; 1 0 1
10999 }
11000 }
11001 3 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 1 2 3
11002 1 gql_runtime_vm_fast_lane_record_error_for_path(
11003 aTHX_ state, error_sv, loader_path
11004 );
11005 1 completed = newSVsv(&PL_sv_undef);
11006 2 ▶ } else if (!loaded_value || !SvOK(loaded_value)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (!loaded_value || !SvOK(loaded_value)) { 2 0 2
} else if (!loaded_value || !SvOK(loaded_value)) { 0 2 2
11007 0 completed = newSVsv(&PL_sv_undef);
11008 } else {
11009 4 int plain = SvROK(loaded_value)
11010 2 ▶ && SvTYPE(SvRV(loaded_value)) == SVt_PVHV
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(loaded_value)) == SVt_PVHV 2 0 2
11011 4 ▶ && !sv_isobject(loaded_value);
Branch: 2 branches
BranchTrueFalseTotal
&& !sv_isobject(loaded_value); 2 0 2
&& !sv_isobject(loaded_value); 2 0 2
11012 IV li;
11013 4 ▶ for (li = 0; plain && li < loaded_block->op_count; li++) {
Branch: 2 branches
BranchTrueFalseTotal
for (li = 0; plain && li < loaded_block->op_count; li++) { 4 0 4
for (li = 0; plain && li < loaded_block->op_count; li++) { 2 2 4
11014 2 const gql_runtime_vm_native_slot_t *slot = gql_runtime_vm_effective_slot(
11015 2 state->runtime,
11016 2 &loaded_block->slots[loaded_block->ops[li].slot_index]
11017 );
11018 2 SV **value_svp = hv_fetch(
11019 (HV *)SvRV(loaded_value), slot->field_name, (I32)slot->field_name_len, 0
11020 );
11021 2 ▶ if (value_svp && *value_svp && SvROK(*value_svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (value_svp && *value_svp && SvROK(*value_svp)) { 2 0 2
if (value_svp && *value_svp && SvROK(*value_svp)) { 2 0 2
if (value_svp && *value_svp && SvROK(*value_svp)) { 0 2 2
11022 0 plain = 0;
11023 }
11024 }
11025 2 ▶ if (!plain) {
Branch: 1 branch
BranchTrueFalseTotal
if (!plain) { 0 2 2
11026 0 SV *msg = newSVpvs(
11027 "DataLoader batch_plan requires plain hash rows with scalar selected values"
11028 );
11029 0 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg, loader_path);
11030 0 SvREFCNT_dec(msg);
11031 0 completed = newSVsv(&PL_sv_undef);
11032 } else {
11033 2 state->path_frame = loader_path;
11034 2 state->path_frame_is_current_field = 1;
11035 2 completed = gql_runtime_vm_execute_block_fast_sv(
11036 2 aTHX_ state, loader_op->child_block_index, loaded_value
11037 );
11038 2 state->path_frame = saved_path;
11039 2 state->path_frame_is_current_field = saved_path_is_current;
11040 2 ▶ if (!completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!completed) { 0 2 2
11041 0 completed = newSVsv(&PL_sv_undef);
11042 0 state->null_carries_error = 0;
11043 }
11044 }
11045 }
11046 3 hv_store(
11047 row_hv, plan_slot->result_name, (I32)plan_slot->result_name_len,
11048 completed, 0
11049 );
11050 3 av_store(out_av, i, newRV_noinc((SV *)row_hv));
11051 3 gql_runtime_vm_path_frame_decref(loader_path);
11052 3 gql_runtime_vm_path_frame_decref(item_path);
11053 }
11054 1 state->path_frame = saved_path;
11055 1 state->path_frame_is_current_field = saved_path_is_current;
11056 1 ▶ if (!saved_path_is_current) {
Branch: 1 branch
BranchTrueFalseTotal
if (!saved_path_is_current) { 0 1 1
11057 0 gql_runtime_vm_path_frame_decref(list_path);
11058 }
11059 1 SvREFCNT_dec((SV *)values_av);
11060 1 SvREFCNT_dec(batch_error);
11061 1 *handled_out = 1;
11062 1 return newRV_noinc((SV *)out_av);
11063 }
11064  
11065 static SV *
11066 950 gql_runtime_vm_complete_current_list_fast_sv(pTHX_ gql_runtime_vm_exec_state_t *state, SV *value)
11067 {
11068 950 const gql_runtime_vm_native_op_t *op = state->op;
11069 950 ▶ if (op->complete_code == GQL_VM_COMPLETE_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->complete_code == GQL_VM_COMPLETE_LIST) { 950 0 950
11070 AV *in_av;
11071 AV *out_av;
11072 IV i;
11073 950 ▶ gql_runtime_vm_path_frame_t *saved_path_frame = state ? state->path_frame : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_path_frame_t *saved_path_frame = state ? state->path_frame : NULL; 950 0 950
11074 950 gql_runtime_vm_path_frame_t *field_path = NULL;
11075 950 gql_runtime_vm_path_frame_t *base_path = NULL;
11076 950 int has_child_block = op->child_block_index >= 0;
11077  
11078 950 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 950 0 950
if (!value || !SvOK(value)) { 0 950 950
11079 0 return newSVsv(&PL_sv_undef);
11080 }
11081 950 ▶ if (!SvROK(value) || SvTYPE(SvRV(value)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(value) || SvTYPE(SvRV(value)) != SVt_PVAV) { 947 3 950
if (!SvROK(value) || SvTYPE(SvRV(value)) != SVt_PVAV) { 0 947 947
11082 /* Non-list resolver result for a list field: field error + null,
11083 * matching the async lane (never croak the whole request). */
11084 3 SV *msg_sv = newSVpvs("list value must be an array reference");
11085 6 gql_runtime_vm_path_frame_t *error_path = state->path_frame_is_current_field
11086 ? state->path_frame
11087 3 ▶ : (field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot));
Branch: 1 branch
BranchTrueFalseTotal
: (field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot)); 3 0 3
11088 3 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg_sv, error_path);
11089 3 SvREFCNT_dec(msg_sv);
11090 3 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 0 3 3
11091 0 gql_runtime_vm_path_frame_decref(field_path);
11092 }
11093 3 return newSVsv(&PL_sv_undef);
11094 }
11095 947 in_av = (AV *)SvRV(value);
11096 947 ▶ if (state->fast_lane_can_suspend) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_can_suspend) { 717 230 947
11097 717 int batch_plan_handled = 0;
11098 SV *batch_plan_result =
11099 717 gql_runtime_vm_try_complete_declarative_batch_plan_list_fast_sv(
11100 aTHX_ state, in_av, &batch_plan_handled
11101 );
11102 717 ▶ if (batch_plan_handled) {
Branch: 1 branch
BranchTrueFalseTotal
if (batch_plan_handled) { 1 716 717
11103 1 return batch_plan_result;
11104 }
11105 }
11106 946 ▶ if (state->fast_lane_can_suspend) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_can_suspend) { 716 230 946
11107 /* Field-level suspension (the resolver call itself pending) is
11108 * already handled by gql_runtime_vm_fast_lane_guard_promise_sv before
11109 * this function ever runs; this is the resolver having settled to an
11110 * array whose items are still pending, a second, later suspension
11111 * point the fast lane cannot complete inline. Stash the raw,
11112 * not-yet-item-completed array and let the continuation owner (the
11113 * multi-sibling root loop) promote to the real async machinery -
11114 * once any item has run through the leaf coercion below there is no
11115 * safe way back, so this check must happen before that loop starts. */
11116 716 IV pending_count = av_count(in_av);
11117 IV pi;
11118 716 int any_pending = 0;
11119 1736 ▶ for (pi = 0; pi < pending_count; pi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (pi = 0; pi < pending_count; pi++) { 1238 498 1736
11120 1238 SV **pending_svp = av_fetch(in_av, pi, 0);
11121 1238 ▶ SV *pending_item = (pending_svp && SvOK(*pending_svp)) ? *pending_svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
SV *pending_item = (pending_svp && SvOK(*pending_svp)) ? *pending_svp : NULL; 1238 0 1238
SV *pending_item = (pending_svp && SvOK(*pending_svp)) ? *pending_svp : NULL; 1233 5 1238
11122 1238 ▶ if (pending_item
Branch: 1 branch
BranchTrueFalseTotal
if (pending_item 1233 5 1238
11123 1233 ▶ && (gql_runtime_vm_sv_is_adapter_promise(
Branch: 1 branch
BranchTrueFalseTotal
&& (gql_runtime_vm_sv_is_adapter_promise( 1226 7 1233
11124 1233 aTHX_ state->runtime->async_adapter, pending_item
11125 )
11126 1226 ▶ || (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ pending_item)
Branch: 1 branch
BranchTrueFalseTotal
|| (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ pending_item) 211 1015 1226
11127 211 ▶ && gql_runtime_vm_dataloader_ticket_state(aTHX_ pending_item) == 0))) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_dataloader_ticket_state(aTHX_ pending_item) == 0))) { 211 0 211
11128 218 any_pending = 1;
11129 218 break;
11130 }
11131 }
11132 716 ▶ if (any_pending) {
Branch: 1 branch
BranchTrueFalseTotal
if (any_pending) { 218 498 716
11133 218 state->fast_lane_list_pending_source_sv = newSVsv(value);
11134 218 return newSVsv(&PL_sv_undef);
11135 }
11136 }
11137 728 out_av = newAV();
11138 728 ▶ av_extend(out_av, av_count(in_av) > 0 ? av_count(in_av) - 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
av_extend(out_av, av_count(in_av) > 0 ? av_count(in_av) - 1 : 0); 726 2 728
11139 728 ▶ if (has_child_block || op->abstract_child_count > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (has_child_block || op->abstract_child_count > 0) { 41 687 728
if (has_child_block || op->abstract_child_count > 0) { 22 19 41
11140 /* Base the per-item index frames on the field frame; when the
11141 * dispatch loop already pushed it (eager path) reuse that frame
11142 * instead of stacking a duplicate segment. */
11143 709 ▶ if (!state->path_frame_is_current_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->path_frame_is_current_field) { 0 709 709
11144 0 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot);
11145 0 state->path_frame = field_path;
11146 }
11147 709 base_path = state->path_frame;
11148 }
11149 3833 ▶ for (i = 0; i < (IV)av_count(in_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (IV)av_count(in_av); i++) { 3111 722 3833
11150 3111 SV **item_svp = av_fetch(in_av, i, 0);
11151 3111 ▶ SV *item = (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *item = (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef; 3111 0 3111
SV *item = (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef; 3098 13 3111
11152 SV *completed;
11153 3111 SV *sel_error = NULL;
11154 3111 gql_runtime_vm_path_frame_t *item_path = NULL;
11155 IV item_block_index;
11156 3111 ▶ if (gql_runtime_vm_sv_is_adapter_promise(
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_adapter_promise( 3107 4 3111
11157 3111 aTHX_ state->runtime->async_adapter, item
11158 )
11159 3107 ▶ || (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ item)
Branch: 1 branch
BranchTrueFalseTotal
|| (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ item) 0 3107 3107
11160 0 ▶ && gql_runtime_vm_dataloader_ticket_state(aTHX_ item) == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_dataloader_ticket_state(aTHX_ item) == 0)) { 0 0 0
11161 /* Promise/pending-Ticket list item on the strict sync lane (the
11162 * fast_lane_can_suspend pre-scan above already routed the
11163 * suspendable-lane case elsewhere): complete it as null and record
11164 * the deferred croak; the top-level entry raises it after cleanup.
11165 * The item SV is borrowed from the resolver's array, so no decref.
11166 * A fulfilled Ticket (state 1) is not a suspension at all and
11167 * falls through unchanged to the leaf branch below. */
11168 4 ▶ if (!state->fast_lane_deferred_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->fast_lane_deferred_croak_sv) { 2 2 4
11169 2 state->fast_lane_deferred_croak_sv =
11170 2 newSVpv(GQL_RUNTIME_VM_FAST_LANE_PROMISE_ERROR, 0);
11171 }
11172 4 item = &PL_sv_undef;
11173 }
11174 3111 ▶ item_block_index = (has_child_block && SvOK(item)) ? op->child_block_index : -1;
Branch: 2 branches
BranchTrueFalseTotal
item_block_index = (has_child_block && SvOK(item)) ? op->child_block_index : -1; 3001 110 3111
item_block_index = (has_child_block && SvOK(item)) ? op->child_block_index : -1; 2996 5 3001
11175 3111 ▶ if (base_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (base_path) { 3061 50 3111
11176 3061 SV *item_key = newSViv(i);
11177 3061 item_path = gql_runtime_vm_new_path_frame_struct(aTHX_ base_path, item_key);
11178 3061 SvREFCNT_dec(item_key);
11179 3061 state->path_frame = item_path;
11180 }
11181 3111 ▶ if (item_block_index < 0 && op->abstract_child_count > 0 && SvOK(item)) {
Branch: 3 branches
BranchTrueFalseTotal
if (item_block_index < 0 && op->abstract_child_count > 0 && SvOK(item)) { 115 2996 3111
if (item_block_index < 0 && op->abstract_child_count > 0 && SvOK(item)) { 60 55 115
if (item_block_index < 0 && op->abstract_child_count > 0 && SvOK(item)) { 57 3 60
11182 /* List of an interface/union: pick the member block per item. */
11183 57 item_block_index = gql_runtime_vm_select_abstract_child_block_fast(
11184 aTHX_ state, item, &sel_error
11185 );
11186 }
11187 3111 int item_had_error = 0;
11188 3111 ▶ if (sel_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (sel_error) { 3 3108 3111
11189 /* Unresolvable member type: field error + null item. */
11190 3 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, sel_error, item_path);
11191 3 SvREFCNT_dec(sel_error);
11192 3 completed = newSVsv(&PL_sv_undef);
11193 3 item_had_error = 1;
11194 3108 ▶ } else if (item_block_index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (item_block_index >= 0) { 3050 58 3108
11195 3050 completed = gql_runtime_vm_execute_safe_child_block_fast_sv(
11196 /* Phase 11: want_promise=0 - a genuine suspension now comes back
11197 * as a raw block_frame_t handle
11198 * (gql_runtime_vm_is_block_frame_value_sv), not a Promise::XS;
11199 * gql_runtime_vm_list_pending_handle_sv links it directly. */
11200 aTHX_ state, item_block_index, item, item_path, 0
11201 );
11202 3050 ▶ if (!completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!completed) { 3 3047 3050
11203 /* The item block nulled itself (non-null propagation) with
11204 * nothing async in flight - a genuine suspension inside the
11205 * item's own child block instead comes back as a raw
11206 * block_frame_t handle (never NULL), handled by the
11207 * item_non_null/av_store code
11208 * below exactly like any other already-known value. */
11209 3 item_had_error = state->null_carries_error;
11210 3 state->null_carries_error = 0;
11211 }
11212 } else {
11213 /* Leaf list item: result coercion against the inner type
11214 * (slot->return_type_name is the list's inner name). Errors get
11215 * a lazily built field+index path since leaf lists skip the
11216 * per-item frames. */
11217 58 SV *leaf_error = NULL;
11218 58 completed = gql_runtime_vm_serialize_leaf_sv(
11219 58 aTHX_ state->runtime, state->slot, item, &leaf_error
11220 );
11221 58 ▶ if (leaf_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_error) { 6 52 58
11222 6 gql_runtime_vm_path_frame_t *error_path = item_path;
11223 6 gql_runtime_vm_path_frame_t *lazy_field = NULL;
11224 6 gql_runtime_vm_path_frame_t *lazy_item = NULL;
11225 6 ▶ if (!error_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error_path) { 6 0 6
11226 6 SV *item_key = newSViv(i);
11227 12 lazy_field = state->path_frame_is_current_field
11228 ? NULL
11229 6 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot); 0 6 6
11230 6 ▶ lazy_item = gql_runtime_vm_new_path_frame_struct(
Branch: 1 branch
BranchTrueFalseTotal
lazy_item = gql_runtime_vm_new_path_frame_struct( 6 0 6
11231 aTHX_ lazy_field ? lazy_field : state->path_frame, item_key
11232 );
11233 6 SvREFCNT_dec(item_key);
11234 6 error_path = lazy_item;
11235 }
11236 6 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, leaf_error, error_path);
11237 6 SvREFCNT_dec(leaf_error);
11238 6 ▶ if (lazy_item) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_item) { 6 0 6
11239 6 gql_runtime_vm_path_frame_decref(lazy_item);
11240 }
11241 6 ▶ if (lazy_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_field) { 0 6 6
11242 0 gql_runtime_vm_path_frame_decref(lazy_field);
11243 }
11244 6 completed = newSVsv(&PL_sv_undef);
11245 6 item_had_error = 1;
11246 }
11247 }
11248  
11249 /* Non-Null list items ([T!]): a null item nulls the whole list
11250 * (spec 6.4.4); whether the null then travels further is the
11251 * enclosing field check's call (return_type_kind_code == 8). */
11252 3111 ▶ if (state->slot->item_non_null && (!completed || !SvOK(completed))) {
Branch: 3 branches
BranchTrueFalseTotal
if (state->slot->item_non_null && (!completed || !SvOK(completed))) { 48 3063 3111
if (state->slot->item_non_null && (!completed || !SvOK(completed))) { 45 3 48
if (state->slot->item_non_null && (!completed || !SvOK(completed))) { 3 42 45
11253 6 ▶ if (!item_had_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (!item_had_error) { 3 3 6
11254 3 ▶ SV *msg_sv = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
SV *msg_sv = newSVpvf( 3 0 3
SV *msg_sv = newSVpvf( 3 0 3
11255 "Cannot return null for non-nullable field %s.%s.",
11256 state->block->type_name ? state->block->type_name : "(unknown)",
11257 state->slot->field_name ? state->slot->field_name : "(unknown)"
11258 );
11259 3 gql_runtime_vm_path_frame_t *error_path = item_path;
11260 3 gql_runtime_vm_path_frame_t *lazy_field = NULL;
11261 3 gql_runtime_vm_path_frame_t *lazy_item = NULL;
11262 3 ▶ if (!error_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error_path) { 3 0 3
11263 3 SV *item_key = newSViv(i);
11264 6 lazy_field = state->path_frame_is_current_field
11265 ? NULL
11266 3 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot); 0 3 3
11267 3 ▶ lazy_item = gql_runtime_vm_new_path_frame_struct(
Branch: 1 branch
BranchTrueFalseTotal
lazy_item = gql_runtime_vm_new_path_frame_struct( 3 0 3
11268 aTHX_ lazy_field ? lazy_field : state->path_frame, item_key
11269 );
11270 3 SvREFCNT_dec(item_key);
11271 3 error_path = lazy_item;
11272 }
11273 3 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg_sv, error_path);
11274 3 SvREFCNT_dec(msg_sv);
11275 3 ▶ if (lazy_item) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_item) { 3 0 3
11276 3 gql_runtime_vm_path_frame_decref(lazy_item);
11277 }
11278 3 ▶ if (lazy_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_field) { 0 3 3
11279 0 gql_runtime_vm_path_frame_decref(lazy_field);
11280 }
11281 }
11282 6 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 3 3 6
11283 3 SvREFCNT_dec(completed);
11284 }
11285 6 ▶ if (item_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (item_path) { 3 3 6
11286 3 state->path_frame = base_path;
11287 3 gql_runtime_vm_path_frame_decref(item_path);
11288 }
11289 6 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 0 6 6
11290 0 state->path_frame = saved_path_frame;
11291 0 gql_runtime_vm_path_frame_decref(field_path);
11292 }
11293 6 SvREFCNT_dec((SV *)out_av);
11294 6 state->null_carries_error = 1;
11295 6 return newSVsv(&PL_sv_undef);
11296 }
11297 3105 ▶ if (!completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!completed) { 0 3105 3105
11298 0 completed = newSVsv(&PL_sv_undef);
11299 }
11300 3105 ▶ if (item_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (item_path) { 3058 47 3105
11301 3058 state->path_frame = base_path;
11302 3058 gql_runtime_vm_path_frame_decref(item_path);
11303 }
11304 3105 av_store(out_av, i, completed);
11305 }
11306 722 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 0 722 722
11307 0 state->path_frame = saved_path_frame;
11308 0 gql_runtime_vm_path_frame_decref(field_path);
11309 }
11310 722 ▶ if (base_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (base_path) { 706 16 722
11311 /* Phase 5: an object/abstract item may have come back as a genuine
11312 * Promise::XS (gql_runtime_vm_execute_safe_child_block_fast_sv,
11313 * above) instead of an already-final value. Every item that reached
11314 * this point already did its own exactly-once-safe work (this is
11315 * NOT the raw, not-yet-item-completed array the leaf pre-scan above
11316 * stashes), so there is nothing left to delegate to Layer 1 -
11317 * gql_runtime_vm_list_pending_handle_sv's own promise detection
11318 * subscribes directly to any such item. Phase 11: a suspending
11319 * item's own child block now comes back as a raw block_frame_t
11320 * handle instead (want_promise=0 above), which
11321 * list_pending_handle_sv also recognizes and links directly. */
11322 IV pi;
11323 706 int any_promise = 0;
11324 2911 ▶ for (pi = 0; pi <= av_len(out_av); pi++) {
Branch: 1 branch
BranchTrueFalseTotal
for (pi = 0; pi <= av_len(out_av); pi++) { 2628 283 2911
11325 2628 SV **item_svp = av_fetch(out_av, pi, 0);
11326 2628 ▶ if (item_svp && *item_svp
Branch: 2 branches
BranchTrueFalseTotal
if (item_svp && *item_svp 2628 0 2628
if (item_svp && *item_svp 2628 0 2628
11327 2628 ▶ && (gql_runtime_vm_sv_is_adapter_promise(
Branch: 1 branch
BranchTrueFalseTotal
&& (gql_runtime_vm_sv_is_adapter_promise( 2628 0 2628
11328 2628 aTHX_ state->runtime->async_adapter, *item_svp
11329 )
11330 2628 ▶ || gql_runtime_vm_is_block_frame_value_sv(*item_svp))) {
Branch: 1 branch
BranchTrueFalseTotal
|| gql_runtime_vm_is_block_frame_value_sv(*item_svp))) { 423 2205 2628
11331 423 any_promise = 1;
11332 423 break;
11333 }
11334 }
11335 706 ▶ if (any_promise) {
Branch: 1 branch
BranchTrueFalseTotal
if (any_promise) { 423 283 706
11336 SV *state_sv;
11337 gql_runtime_vm_exec_state_handle_t *sched_state =
11338 423 gql_runtime_vm_ensure_fast_lane_state_sv(aTHX_ state, &state_sv);
11339 423 state->fast_lane_list_pending_result_sv = gql_runtime_vm_list_pending_handle_sv(
11340 aTHX_ state_sv, sched_state, out_av, base_path
11341 );
11342 423 SvREFCNT_dec((SV *)out_av);
11343 423 return newSVsv(&PL_sv_undef);
11344 }
11345 }
11346 299 return newRV_noinc((SV *)out_av);
11347 }
11348 0 return gql_runtime_vm_clone_value_sv(aTHX_ value);
11349 }
11350  
11351 /* Resume boundary for sync-first execution. `value` is an already resolved
11352 * field value, so callers resuming a continuation must not invoke the
11353 * resolver again. Runtime directives are applied before this boundary. */
11354 static SV *
11355 7177 gql_runtime_vm_complete_resolved_current_fast_sv(
11356 pTHX_
11357 gql_runtime_vm_exec_state_t *state,
11358 SV *value,
11359 SV **error_out
11360 )
11361 {
11362 7177 switch (state->op->complete_code) {
11363 1397 case GQL_VM_COMPLETE_OBJECT:
11364 1397 return gql_runtime_vm_complete_current_object_fast_sv(
11365 aTHX_ state, value
11366 );
11367 950 case GQL_VM_COMPLETE_LIST:
11368 950 return gql_runtime_vm_complete_current_list_fast_sv(
11369 aTHX_ state, value
11370 );
11371 39 case GQL_VM_COMPLETE_ABSTRACT:
11372 39 return gql_runtime_vm_complete_current_abstract_fast_sv(
11373 aTHX_ state, value, error_out
11374 );
11375 4791 case GQL_VM_COMPLETE_GENERIC:
11376 default:
11377 4791 return gql_runtime_vm_complete_current_generic_fast_sv(
11378 aTHX_ state, value, error_out
11379 );
11380 }
11381 }
11382  
11383 static SV *
11384 9378 gql_runtime_vm_execute_current_op_fast_sv(
11385 pTHX_
11386 gql_runtime_vm_exec_state_t *state,
11387 SV *source,
11388 SV **error_sv_out
11389 )
11390 {
11391 9378 SV *resolved = NULL;
11392 9378 SV *completed = NULL;
11393 9378 SV *error_sv = NULL;
11394 9378 IV dispatch_index = gql_runtime_vm_dispatch_index_from_opcode(state->op->opcode_code);
11395  
11396 #if defined(__GNUC__) || defined(__clang__)
11397 static void *dispatch_table[] = {
11398 &&OP_DEFAULT_GENERIC,
11399 &&OP_DEFAULT_OBJECT,
11400 &&OP_DEFAULT_LIST,
11401 &&OP_DEFAULT_ABSTRACT,
11402 &&OP_EXPLICIT_GENERIC,
11403 &&OP_EXPLICIT_OBJECT,
11404 &&OP_EXPLICIT_LIST,
11405 &&OP_EXPLICIT_ABSTRACT
11406 };
11407 #endif
11408  
11409 9378 ▶ if (dispatch_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (dispatch_index < 0) { 0 9378 9378
11410 0 croak("native VM opcode_code %ld is unsupported", (long)state->op->opcode_code);
11411 }
11412  
11413 #if defined(__GNUC__) || defined(__clang__)
11414 9378 goto *dispatch_table[dispatch_index];
11415 365 OP_DEFAULT_GENERIC:
11416 365 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11417 365 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 2 363 365
11418 363 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 2 361 363
11419 361 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 361 0 361
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 361 361
11420 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11421 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11422 0 SvREFCNT_dec(resolved);
11423 0 resolved = applied;
11424 }
11425 361 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11426 361 goto DISPATCH_DONE;
11427 36 OP_DEFAULT_OBJECT:
11428 36 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11429 36 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 0 36 36
11430 36 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 36 36
11431 36 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 36 0 36
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 36 36
11432 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11433 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11434 0 SvREFCNT_dec(resolved);
11435 0 resolved = applied;
11436 }
11437 36 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11438 36 goto DISPATCH_DONE;
11439 10 OP_DEFAULT_LIST:
11440 10 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11441 10 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 0 10 10
11442 10 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 10 10
11443 10 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 10 0 10
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 10 10
11444 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11445 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11446 0 SvREFCNT_dec(resolved);
11447 0 resolved = applied;
11448 }
11449 10 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11450 10 goto DISPATCH_DONE;
11451 0 OP_DEFAULT_ABSTRACT:
11452 0 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11453 0 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 0 0 0
11454 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11455 0 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 0 0
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 0 0
11456 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11457 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11458 0 SvREFCNT_dec(resolved);
11459 0 resolved = applied;
11460 }
11461 0 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11462 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11463 0 goto DISPATCH_DONE;
11464 6573 OP_EXPLICIT_GENERIC:
11465 6573 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11466 6573 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 1723 4850 6573
11467 4850 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 423 4427 4850
11468 4427 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 4424 3 4427
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 4424 4424
11469 3 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11470 3 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 3 3
11471 3 SvREFCNT_dec(resolved);
11472 3 resolved = applied;
11473 }
11474 4427 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11475 4427 goto DISPATCH_DONE;
11476 1404 OP_EXPLICIT_OBJECT:
11477 1404 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11478 1404 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 42 1362 1404
11479 1362 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 1 1361 1362
11480 1361 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 1361 0 1361
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 1361 1361
11481 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11482 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11483 0 SvREFCNT_dec(resolved);
11484 0 resolved = applied;
11485 }
11486 1361 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11487 1361 goto DISPATCH_DONE;
11488 951 OP_EXPLICIT_LIST:
11489 951 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11490 951 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 8 943 951
11491 943 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 3 940 943
11492 940 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 940 0 940
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 940 940
11493 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11494 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11495 0 SvREFCNT_dec(resolved);
11496 0 resolved = applied;
11497 }
11498 940 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11499 940 goto DISPATCH_DONE;
11500 39 OP_EXPLICIT_ABSTRACT:
11501 39 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11502 39 ▶ if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED;
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) goto DISPATCH_SUSPENDED; 0 39 39
11503 39 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 39 39
11504 39 ▶ if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 39 0 39
if (state->op->has_runtime_directives || state->op->runtime_directives_sv) { 0 39 39
11505 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11506 0 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 0 0 0
11507 0 SvREFCNT_dec(resolved);
11508 0 resolved = applied;
11509 }
11510 39 completed = gql_runtime_vm_complete_resolved_current_fast_sv(aTHX_ state, resolved, &error_sv);
11511 39 ▶ if (error_sv) goto DISPATCH_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) goto DISPATCH_ERROR; 4 35 39
11512 35 goto DISPATCH_DONE;
11513 7170 DISPATCH_DONE:
11514 7170 goto DISPATCH_FINISH;
11515 1775 DISPATCH_SUSPENDED:
11516 1775 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 1775 1775
11517 0 SvREFCNT_dec(error_sv);
11518 }
11519 1775 return NULL;
11520 #else
11521 switch (dispatch_index) {
11522 case 0:
11523 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11524 if (state->fast_lane_suspended_sv) break;
11525 if (error_sv) break;
11526 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11527 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11528 if (error_sv) break;
11529 SvREFCNT_dec(resolved);
11530 resolved = applied;
11531 }
11532 completed = gql_runtime_vm_complete_current_generic_fast_sv(aTHX_ state, resolved, &error_sv);
11533 break;
11534 case 1:
11535 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11536 if (state->fast_lane_suspended_sv) break;
11537 if (error_sv) break;
11538 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11539 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11540 if (error_sv) break;
11541 SvREFCNT_dec(resolved);
11542 resolved = applied;
11543 }
11544 completed = gql_runtime_vm_complete_current_object_fast_sv(aTHX_ state, resolved);
11545 break;
11546 case 2:
11547 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11548 if (state->fast_lane_suspended_sv) break;
11549 if (error_sv) break;
11550 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11551 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11552 if (error_sv) break;
11553 SvREFCNT_dec(resolved);
11554 resolved = applied;
11555 }
11556 completed = gql_runtime_vm_complete_current_list_fast_sv(aTHX_ state, resolved);
11557 break;
11558 case 3:
11559 resolved = gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
11560 if (state->fast_lane_suspended_sv) break;
11561 if (error_sv) break;
11562 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11563 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11564 if (error_sv) break;
11565 SvREFCNT_dec(resolved);
11566 resolved = applied;
11567 }
11568 completed = gql_runtime_vm_complete_current_abstract_fast_sv(aTHX_ state, resolved, &error_sv);
11569 break;
11570 case 4:
11571 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11572 if (state->fast_lane_suspended_sv) break;
11573 if (error_sv) break;
11574 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11575 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11576 if (error_sv) break;
11577 SvREFCNT_dec(resolved);
11578 resolved = applied;
11579 }
11580 completed = gql_runtime_vm_complete_current_generic_fast_sv(aTHX_ state, resolved, &error_sv);
11581 break;
11582 case 5:
11583 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11584 if (state->fast_lane_suspended_sv) break;
11585 if (error_sv) break;
11586 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11587 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11588 if (error_sv) break;
11589 SvREFCNT_dec(resolved);
11590 resolved = applied;
11591 }
11592 completed = gql_runtime_vm_complete_current_object_fast_sv(aTHX_ state, resolved);
11593 break;
11594 case 6:
11595 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11596 if (state->fast_lane_suspended_sv) break;
11597 if (error_sv) break;
11598 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11599 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11600 if (error_sv) break;
11601 SvREFCNT_dec(resolved);
11602 resolved = applied;
11603 }
11604 completed = gql_runtime_vm_complete_current_list_fast_sv(aTHX_ state, resolved);
11605 break;
11606 case 7:
11607 resolved = gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv);
11608 if (state->fast_lane_suspended_sv) break;
11609 if (error_sv) break;
11610 if (state->op->has_runtime_directives || state->op->runtime_directives_sv) {
11611 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
11612 if (error_sv) break;
11613 SvREFCNT_dec(resolved);
11614 resolved = applied;
11615 }
11616 completed = gql_runtime_vm_complete_current_abstract_fast_sv(aTHX_ state, resolved, &error_sv);
11617 break;
11618 }
11619 #endif
11620  
11621 7170 DISPATCH_FINISH:
11622 7170 ▶ if (state->fast_lane_suspended_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) { 0 7170 7170
11623 0 ▶ if (resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolved) { 0 0 0
11624 0 SvREFCNT_dec(resolved);
11625 }
11626 0 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 0 0 0
11627 0 SvREFCNT_dec(completed);
11628 }
11629 0 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 0 0
11630 0 SvREFCNT_dec(error_sv);
11631 }
11632 0 return NULL;
11633 }
11634 7170 ▶ if (resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolved) { 7170 0 7170
11635 7170 SvREFCNT_dec(resolved);
11636 }
11637 7170 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 17 7153 7170
11638 17 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 0 17 17
11639 0 SvREFCNT_dec(completed);
11640 }
11641 17 ▶ if (error_sv_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv_out) { 17 0 17
11642 17 *error_sv_out = error_sv;
11643 17 error_sv = NULL;
11644 }
11645 17 SvREFCNT_dec(error_sv);
11646 17 return NULL;
11647 }
11648 7153 ▶ return completed ? completed : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return completed ? completed : newSVsv(&PL_sv_undef); 15 7138 7153
11649  
11650 #if defined(__GNUC__) || defined(__clang__)
11651 433 DISPATCH_ERROR:
11652 433 ▶ if (resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolved) { 433 0 433
11653 433 SvREFCNT_dec(resolved);
11654 433 resolved = NULL;
11655 }
11656 433 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 0 433 433
11657 0 SvREFCNT_dec(completed);
11658 0 completed = NULL;
11659 }
11660 433 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 433 0 433
11661 433 ▶ if (error_sv_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv_out) { 433 0 433
11662 433 *error_sv_out = error_sv;
11663 433 error_sv = NULL;
11664 }
11665 433 SvREFCNT_dec(error_sv);
11666 }
11667 433 return NULL;
11668 #endif
11669 }
11670  
11671 static int
11672 10601 gql_runtime_vm_should_execute_current_op_fast(pTHX_ gql_runtime_vm_exec_state_t *state)
11673 {
11674 10601 ▶ const gql_runtime_vm_native_op_t *op = state ? state->op : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const gql_runtime_vm_native_op_t *op = state ? state->op : NULL; 10601 0 10601
11675 10601 ▶ gql_runtime_vm_callback_context_t *ctx = state ? state->callback_ctx : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_callback_context_t *ctx = state ? state->callback_ctx : NULL; 10601 0 10601
11676 10601 HV *variables_hv = NULL;
11677 SV *variables_sv;
11678  
11679 10601 ▶ if (!op
Branch: 1 branch
BranchTrueFalseTotal
if (!op 10601 0 10601
11680 10601 ▶ || !op->has_directives
Branch: 1 branch
BranchTrueFalseTotal
|| !op->has_directives 15 10586 10601
11681 15 ▶ || op->directives_mode_code == GQL_VM_ARGS_NONE
Branch: 1 branch
BranchTrueFalseTotal
|| op->directives_mode_code == GQL_VM_ARGS_NONE 15 0 15
11682 15 ▶ || !op->directives_payload_native) {
Branch: 1 branch
BranchTrueFalseTotal
|| !op->directives_payload_native) { 0 15 15
11683 10586 return 1;
11684 }
11685 15 ▶ variables_sv = ctx ? ctx->variables : NULL;
Branch: 1 branch
BranchTrueFalseTotal
variables_sv = ctx ? ctx->variables : NULL; 15 0 15
11686 15 ▶ if (variables_sv
Branch: 1 branch
BranchTrueFalseTotal
if (variables_sv 15 0 15
11687 15 ▶ && SvROK(variables_sv)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(variables_sv) 15 0 15
11688 15 ▶ && SvTYPE(SvRV(variables_sv)) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(variables_sv)) == SVt_PVHV) { 6 9 15
11689 6 variables_hv = (HV *)SvRV(variables_sv);
11690 }
11691 15 ▶ return gql_runtime_vm_evaluate_runtime_guards_native(
Branch: 2 branches
BranchTrueFalseTotal
return gql_runtime_vm_evaluate_runtime_guards_native( 15 0 15
return gql_runtime_vm_evaluate_runtime_guards_native( 15 0 15
11692 aTHX_
11693 15 op->directives_payload_native,
11694 variables_hv,
11695 ctx ? ctx->variable_slots : NULL,
11696 ctx ? ctx->variable_slot_count : 0
11697 );
11698 }
11699  
11700 static SV *
11701 385 gql_runtime_vm_execute_block_fast_sv(pTHX_ gql_runtime_vm_exec_state_t *state, IV block_index, SV *source)
11702 {
11703 gql_runtime_vm_native_block_t *block;
11704 HV *data_hv;
11705 IV i;
11706 385 gql_runtime_vm_native_block_t *saved_block = (gql_runtime_vm_native_block_t *)state->block;
11707 385 const gql_runtime_vm_native_op_t *saved_op = state->op;
11708 385 const gql_runtime_vm_native_slot_t *saved_slot = state->slot;
11709 385 gql_runtime_vm_path_frame_t *saved_path_frame = state->path_frame;
11710 385 int saved_path_is_current_field = state->path_frame_is_current_field;
11711 385 IV saved_block_index = state->block_index;
11712 385 IV saved_op_index = state->op_index;
11713  
11714 385 ▶ if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) {
Branch: 3 branches
BranchTrueFalseTotal
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 385 0 385
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 385 0 385
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 0 385 385
11715 0 croak("native VM block index %ld is invalid", (long)block_index);
11716 }
11717  
11718 385 block = &state->bundle->blocks[block_index];
11719 385 state->block = block;
11720 385 state->block_index = block_index;
11721 385 data_hv = newHV();
11722  
11723 821 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 444 377 821
11724 444 gql_runtime_vm_native_op_t *op = &block->ops[i];
11725 gql_runtime_vm_native_slot_t *slot;
11726 SV *completed;
11727 444 SV *error_sv = NULL;
11728 444 gql_runtime_vm_outcome_t *error_outcome = NULL;
11729 444 gql_runtime_vm_path_frame_t *field_path = NULL;
11730 int eager_path_frame;
11731  
11732 444 ▶ if (op->slot_index < 0 || op->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 444 0 444
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 0 444 444
11733 0 croak("native VM op slot_index %ld is invalid in block %ld", (long)op->slot_index, (long)block_index);
11734 }
11735 444 slot = &block->slots[op->slot_index];
11736 444 state->op = op;
11737 444 state->slot = slot;
11738 444 state->op_index = i;
11739  
11740 444 ▶ if (!gql_runtime_vm_should_execute_current_op_fast(aTHX_ state)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_should_execute_current_op_fast(aTHX_ state)) { 1 443 444
11741 1 continue;
11742 }
11743  
11744 443 eager_path_frame = !gql_runtime_vm_slot_can_delay_field_path(state->runtime, slot, op);
11745  
11746 443 ▶ if (eager_path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (eager_path_frame) { 381 62 443
11747 381 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot);
11748 381 state->path_frame = field_path;
11749 381 state->path_frame_is_current_field = 1;
11750 } else {
11751 62 state->path_frame = saved_path_frame;
11752 62 state->path_frame_is_current_field = 0;
11753 }
11754  
11755 443 completed = gql_runtime_vm_execute_current_op_fast_sv(aTHX_ state, source, &error_sv);
11756 443 state->path_frame = saved_path_frame;
11757 443 state->path_frame_is_current_field = saved_path_is_current_field;
11758  
11759 443 ▶ if (state->fast_lane_suspended_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) { 3 440 443
11760 3 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 1 2 3
11761 1 gql_runtime_vm_path_frame_decref(field_path);
11762 }
11763 3 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 0 3 3
11764 0 SvREFCNT_dec(completed);
11765 }
11766 3 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 3 3
11767 0 SvREFCNT_dec(error_sv);
11768 }
11769 3 SvREFCNT_dec((SV *)data_hv);
11770 3 state->block = saved_block;
11771 3 state->op = saved_op;
11772 3 state->slot = saved_slot;
11773 3 state->path_frame = saved_path_frame;
11774 3 state->path_frame_is_current_field = saved_path_is_current_field;
11775 3 state->block_index = saved_block_index;
11776 3 state->op_index = saved_op_index;
11777 8 return NULL;
11778 }
11779  
11780 440 ▶ if (!eager_path_frame && error_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!eager_path_frame && error_sv) { 60 380 440
if (!eager_path_frame && error_sv) { 1 59 60
11781 1 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot);
11782 1 error_outcome = gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ error_sv, field_path);
11783 1 SvREFCNT_dec(error_sv);
11784 1 error_sv = NULL;
11785 439 ▶ } else if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (error_sv) { 17 422 439
11786 17 error_outcome = gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ error_sv, field_path);
11787 17 SvREFCNT_dec(error_sv);
11788 17 error_sv = NULL;
11789 }
11790  
11791 440 ▶ if (error_outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_outcome) { 18 422 440
11792 18 ▶ if (state->writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->writer) { 18 0 18
11793 IV j;
11794 36 ▶ for (j = 0; j < error_outcome->error_record_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < error_outcome->error_record_count; j++) { 18 18 36
11795 18 gql_runtime_vm_writer_push_error_record(state->writer, error_outcome->error_records[j]);
11796 }
11797 }
11798 18 gql_runtime_vm_outcome_decref(aTHX_ error_outcome);
11799 18 error_outcome = NULL;
11800 18 completed = newSVsv(&PL_sv_undef);
11801 /* The null below carries this field error. */
11802 18 state->null_carries_error = 1;
11803 }
11804  
11805 /* Non-Null propagation (spec 6.4.4): a null in a non-null position
11806 * nulls this block. Add the "Cannot return null" error only when the
11807 * null did not already come with one (a field error above, or a
11808 * propagated child null). */
11809 440 ▶ if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) {
Branch: 3 branches
BranchTrueFalseTotal
if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) { 440 0 440
if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) { 46 394 440
if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) { 5 41 46
11810 5 ▶ if (!state->null_carries_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->null_carries_error) { 2 3 5
11811 2 ▶ SV *msg_sv = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
SV *msg_sv = newSVpvf( 2 0 2
SV *msg_sv = newSVpvf( 2 0 2
11812 "Cannot return null for non-nullable field %s.%s.",
11813 block->type_name ? block->type_name : "(unknown)",
11814 slot->field_name ? slot->field_name : "(unknown)"
11815 );
11816 2 gql_runtime_vm_path_frame_t *error_path = field_path
11817 ? field_path
11818 2 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot); 0 2 2
11819 2 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg_sv, error_path);
11820 2 SvREFCNT_dec(msg_sv);
11821 2 ▶ if (error_path != field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_path != field_path) { 0 2 2
11822 0 gql_runtime_vm_path_frame_decref(error_path);
11823 }
11824 }
11825 5 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 5 0 5
11826 5 gql_runtime_vm_path_frame_decref(field_path);
11827 }
11828 5 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 5 0 5
11829 5 SvREFCNT_dec(completed);
11830 }
11831 5 SvREFCNT_dec((SV *)data_hv);
11832 5 state->block = saved_block;
11833 5 state->op = saved_op;
11834 5 state->slot = saved_slot;
11835 5 state->path_frame = saved_path_frame;
11836 5 state->path_frame_is_current_field = saved_path_is_current_field;
11837 5 state->block_index = saved_block_index;
11838 5 state->op_index = saved_op_index;
11839 5 state->null_carries_error = 1;
11840 5 return NULL;
11841 }
11842 435 state->null_carries_error = 0;
11843  
11844 435 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 376 59 435
11845 376 gql_runtime_vm_path_frame_decref(field_path);
11846 376 field_path = NULL;
11847 }
11848 435 ▶ if (!completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!completed) { 0 435 435
11849 0 completed = newSVsv(&PL_sv_undef);
11850 }
11851 435 hv_store(data_hv, slot->result_name, (I32)slot->result_name_len, completed, 0);
11852 }
11853  
11854 377 state->block = saved_block;
11855 377 state->op = saved_op;
11856 377 state->slot = saved_slot;
11857 377 state->path_frame = saved_path_frame;
11858 377 state->path_frame_is_current_field = saved_path_is_current_field;
11859 377 state->block_index = saved_block_index;
11860 377 state->op_index = saved_op_index;
11861  
11862 377 return newRV_noinc((SV *)data_hv);
11863 }
11864  
11865 /* Root-block loop for the multi-sibling fast continuation. Unlike
11866 * gql_runtime_vm_execute_block_fast_sv (shared with the plain-hash-block
11867 * fast path and list item completion, where any suspension aborts the
11868 * whole block), a suspension here must not throw away sibling fields
11869 * already resolved earlier in the same loop or skip fields still to come:
11870 * the caller only reaches this function once every op in the block has
11871 * already passed the fast-root-continuation eligibility guard (leaf,
11872 * nullable, no directives, no child block, and stable bundle/native_program
11873 * op indices), so every suspended op can be parked as a
11874 * GQL_VM_PENDING_PROMISE_(GENERIC|RESOLVED)_VALUE_SV pending entry on a
11875 * lazily-created block_frame_t and the loop simply continues. *frame_out
11876 * stays NULL when nothing suspended (the fully-synchronous, zero-tax
11877 * case).
11878 *
11879 * resolved_values is a caller-owned, block->op_count-sized, zeroed array;
11880 * this function stores one owned SV reference per op that resolved
11881 * without suspending (NULL for a suspended or should-execute-skipped op),
11882 * indexed by op position. The caller - not this function - decides how to
11883 * turn that into either a plain data_hv (the all-synchronous case) or
11884 * frame->values_value (the promoted case): every value here is already a
11885 * final, fully-coerced Perl scalar, so building an intermediate HV only to
11886 * immediately walk and reconvert it via gql_runtime_vm_native_value_from_sv
11887 * would redundantly re-copy each already plan-owned field name and pay
11888 * hv_iterinit/hv_iternext traversal on top of the hv_store this loop would
11889 * otherwise do - pure overhead the promoted path doesn't need. */
11890 /* Lazily builds the one request-scoped exec_state_handle_t a suspended fast
11891 * root continuation needs, and memoizes it on state->fast_lane_root_state_sv
11892 * so it is built at most once per request regardless of which of the
11893 * several suspension channels (field-level, leaf item-level list pending,
11894 * object/abstract item-level list pending - Phase 5, or a nested field deep
11895 * inside an object list item's own child block) triggers construction
11896 * first. This handle is not tied to any one block_frame_t: response_frame
11897 * is deliberately left for the caller to assign, since only the root per-op
11898 * loop owns the true root frame and must (re)assign it every time it
11899 * lazily creates or already holds that frame, regardless of construction
11900 * order. Building the handle more than once would double-incref the writer
11901 * and construct two handles for the same request. */
11902 static gql_runtime_vm_exec_state_handle_t *
11903 5615 gql_runtime_vm_ensure_fast_lane_state_sv(
11904 pTHX_
11905 gql_runtime_vm_exec_state_t *state,
11906 SV **state_sv_out
11907 )
11908 {
11909 5615 ▶ if (!state->fast_lane_root_state_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->fast_lane_root_state_sv) { 1539 4076 5615
11910 1539 gql_runtime_vm_cursor_t *cursor = gql_runtime_vm_new_cursor_struct_for_program(
11911 1539 aTHX_ state->callback_ctx->native_program, state->fast_lane_root_block_index, 0, 0
11912 );
11913 1539 SV *sched_state_sv = sv_2mortal(gql_runtime_vm_new_exec_state_handle_sv(
11914 aTHX_ "GraphQL::Houtou::Runtime::ExecState",
11915 state->callback_ctx->runtime_schema, state->program_sv, cursor, state->writer,
11916 state->callback_ctx->context, state->callback_ctx->variables,
11917 state->callback_ctx->root_value, state->empty_args_sv
11918 ));
11919 gql_runtime_vm_exec_state_handle_t *sched_state =
11920 1539 gql_runtime_vm_expect_exec_state_handle(aTHX_ sched_state_sv);
11921 1539 gql_runtime_vm_cursor_decref(aTHX_ cursor);
11922 1539 sched_state->native_runtime = state->runtime;
11923 1539 sched_state->native_runtime_is_borrowed = 1;
11924 3078 sched_state->native_runtime_owner_sv = state->runtime_handle_sv
11925 1539 ? newSVsv(state->runtime_handle_sv)
11926 1539 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 1539 0 1539
11927 1539 sched_state->async_adapter = state->runtime->async_adapter;
11928 1539 state->fast_lane_root_state_sv = sched_state_sv;
11929 }
11930 5615 *state_sv_out = state->fast_lane_root_state_sv;
11931 5615 return gql_runtime_vm_expect_exec_state_handle(aTHX_ state->fast_lane_root_state_sv);
11932 }
11933  
11934 /* Shared sync-first multi-op loop: runs every op in a block, preserving
11935 * already-resolved siblings when a later op suspends instead of aborting
11936 * the whole block (unlike gql_runtime_vm_execute_block_fast_sv). Used both
11937 * for the root block (parent_path_frame == NULL, non-null propagation is
11938 * dead code there since the eligibility guard already excludes non-null
11939 * root ops) and, since Phase 5, for an object/abstract list item's own
11940 * child block (parent_path_frame == that item's own path_frame, non-null
11941 * propagation is live: a nested field with return_type_kind_code == 8 that
11942 * resolves null must null the whole item per spec 6.4.4).
11943 *
11944 * A non-null violation on an op that arrives AFTER an earlier sibling in
11945 * the SAME block already suspended (frame != NULL, meaning Layer 1/2 may
11946 * already have live .then() subscriptions registered against that frame)
11947 * cannot simply discard the frame - there is no way to unsubscribe a
11948 * Promise::XS callback. Instead it sets frame->self_nulled, an existing
11949 * mechanism gql_runtime_vm_block_frame_finalize_sv/resolve_frame already
11950 * honor: once every pending entry eventually settles, the frame completes
11951 * as null (with the error already recorded) regardless of what it
11952 * accumulated. If nothing had suspended yet (frame == NULL), there is
11953 * nothing async in flight and the loop can return NULL immediately, same
11954 * as gql_runtime_vm_execute_block_fast_sv's existing contract - signaled
11955 * via *self_nulled_out with *frame_out left NULL; the caller must then
11956 * decref every already-stored resolved_values[] entry itself. */
11957 static void
11958 6120 gql_runtime_vm_execute_block_fast_multi_sv(
11959 pTHX_
11960 gql_runtime_vm_exec_state_t *state,
11961 IV block_index,
11962 SV *source,
11963 gql_runtime_vm_path_frame_t *parent_path_frame,
11964 SV **resolved_values,
11965 gql_runtime_vm_block_frame_t **frame_out,
11966 SV **state_sv_out,
11967 U8 *self_nulled_out
11968 )
11969 {
11970 gql_runtime_vm_native_block_t *block;
11971 IV i;
11972 6120 gql_runtime_vm_block_frame_t *frame = NULL;
11973 6120 SV *sched_state_sv = NULL;
11974 6120 gql_runtime_vm_native_block_t *saved_block = (gql_runtime_vm_native_block_t *)state->block;
11975 6120 const gql_runtime_vm_native_op_t *saved_op = state->op;
11976 6120 const gql_runtime_vm_native_slot_t *saved_slot = state->slot;
11977 6120 gql_runtime_vm_path_frame_t *saved_path_frame = state->path_frame;
11978 6120 int saved_path_is_current_field = state->path_frame_is_current_field;
11979 6120 IV saved_block_index = state->block_index;
11980 6120 IV saved_op_index = state->op_index;
11981  
11982 6120 *frame_out = NULL;
11983 6120 *state_sv_out = NULL;
11984 6120 *self_nulled_out = 0;
11985  
11986 6120 ▶ if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) {
Branch: 3 branches
BranchTrueFalseTotal
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 6120 0 6120
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 6120 0 6120
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 0 6120 6120
11987 0 croak("native VM block index %ld is invalid", (long)block_index);
11988 }
11989  
11990 6120 block = &state->bundle->blocks[block_index];
11991 6120 state->block = block;
11992 6120 state->block_index = block_index;
11993  
11994 15044 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 8942 6102 15044
11995 8942 gql_runtime_vm_native_op_t *op = &block->ops[i];
11996 gql_runtime_vm_native_slot_t *slot;
11997 SV *completed;
11998 8942 SV *error_sv = NULL;
11999 gql_runtime_vm_path_frame_t *field_path;
12000  
12001 8942 ▶ if (op->slot_index < 0 || op->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 8942 0 8942
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 0 8942 8942
12002 0 croak("native VM op slot_index %ld is invalid in block %ld", (long)op->slot_index, (long)block_index);
12003 }
12004 8942 slot = &block->slots[op->slot_index];
12005 8942 state->op = op;
12006 8942 state->slot = slot;
12007 8942 state->op_index = i;
12008  
12009 8942 ▶ if (!gql_runtime_vm_should_execute_current_op_fast(aTHX_ state)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_should_execute_current_op_fast(aTHX_ state)) { 7 8935 8942
12010 3660 continue;
12011 }
12012  
12013 /* A suspended op needs a real, refcounted path_frame that survives
12014 * past this call, so always build one eagerly (matching the root-only
12015 * predecessor of this function; item child blocks need this too, since
12016 * an item field can suspend exactly like a root field can). */
12017 8935 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ parent_path_frame, slot);
12018 8935 state->path_frame = field_path;
12019 8935 state->path_frame_is_current_field = 1;
12020  
12021 8935 completed = gql_runtime_vm_execute_current_op_fast_sv(aTHX_ state, source, &error_sv);
12022 8935 state->path_frame = NULL;
12023 8935 state->path_frame_is_current_field = 0;
12024  
12025 8935 ▶ if (state->fast_lane_suspended_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_suspended_sv) { 1772 7163 8935
12026 1772 SV *promise_sv = state->fast_lane_suspended_sv;
12027 U8 payload_kind;
12028 1772 state->fast_lane_suspended_sv = NULL;
12029 1772 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 0 1772 1772
12030 0 SvREFCNT_dec(completed);
12031 }
12032 1772 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 1772 1772
12033 0 SvREFCNT_dec(error_sv);
12034 }
12035 1772 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 1759 13 1772
12036 1759 frame = gql_runtime_vm_new_block_frame_struct(aTHX);
12037 }
12038 /* The root caller defers building sched_state_sv to its own tail
12039 * (only field-level suspension ever needed it there, and only after
12040 * the loop). A child block wrapper
12041 * (gql_runtime_vm_execute_safe_child_block_fast_sv) instead
12042 * finalizes its frame immediately, right after this function
12043 * returns, so it needs a real state_sv NOW - ensuring it here is a
12044 * no-op cost-wise for the root case (the frame is already being
12045 * built this same branch either way), so do it unconditionally
12046 * rather than threading a "do we need it now" flag through. */
12047 1772 gql_runtime_vm_ensure_fast_lane_state_sv(aTHX_ state, &sched_state_sv);
12048 /* Mirrors gql_runtime_vm_then_complete_current_sv's choice exactly
12049 * (Phase 3/4 dropped the complete_code check here, which happened to
12050 * still choose correctly only because that eligibility guard never
12051 * let a non-leaf LIST reach this branch - Phase 5 does, and a GENERIC-
12052 * only check on leaf_kind is wrong for it): a built-in scalar/enum
12053 * leaf on a plain GENERIC op just needs result coercion once the
12054 * value settles (RESOLVED_VALUE_SV); a custom scalar on a GENERIC op
12055 * is stored as-is (GENERIC_VALUE_SV). Any other complete_code (LIST,
12056 * including a list of objects/abstract items) always needs full
12057 * re-completion through gql_runtime_vm_exec_state_complete_async_sv,
12058 * i.e. RESOLVED_VALUE_SV, regardless of leaf_kind. */
12059 3494 ▶ payload_kind = (op->complete_code == GQL_VM_COMPLETE_GENERIC
Branch: 1 branch
BranchTrueFalseTotal
payload_kind = (op->complete_code == GQL_VM_COMPLETE_GENERIC 1722 50 1772
12060 1722 ▶ && gql_runtime_vm_slot_leaf_kind(state->runtime, slot) == GQL_VM_LEAF_NONE)
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_slot_leaf_kind(state->runtime, slot) == GQL_VM_LEAF_NONE) 0 1722 1722
12061 ? GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV
12062 : GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV;
12063 1772 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
12064 1772 aTHX_ frame, slot->result_name, slot->result_name_len, 1,
12065 promise_sv, payload_kind, field_path, block_index, op->slot_index, i,
12066 1772 state->runtime->async_adapter
12067 );
12068 1772 SvREFCNT_dec(promise_sv);
12069 1772 gql_runtime_vm_path_frame_decref(field_path);
12070 1772 continue;
12071 }
12072  
12073 7163 ▶ if (state->fast_lane_list_pending_source_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_list_pending_source_sv) { 218 6945 7163
12074 /* A list field resolved synchronously to an array, but one or more
12075 * items inside it are still pending (a Promise::XS or a not-yet-
12076 * settled DataLoader Ticket) - a suspension the fast lane cannot
12077 * complete itself. Delegate to the same two-layer list_pending
12078 * machinery the generic async executor uses (Layer 1: per-item
12079 * settle callback; Layer 2: aggregate + notify owner frame once
12080 * every item has settled), reusing gql_runtime_vm_exec_state_complete_current_native_async_sv
12081 * rather than re-implementing it, and adopt the result the same way
12082 * a resumed field's list-pending completion is adopted elsewhere
12083 * (see the GQL_VM_PENDING_LIST_PENDING_PTR handling in the generic
12084 * scheduler). This is the first point in the whole request where a
12085 * real exec_state_handle_t is required, so it is built here, lazily,
12086 * on first need - not unconditionally up front. */
12087 218 SV *raw_items_sv = state->fast_lane_list_pending_source_sv;
12088 218 gql_runtime_vm_outcome_t *outcome_ignored = NULL;
12089 SV *list_pending_sv;
12090 gql_runtime_vm_list_pending_t *list_pending;
12091 gql_runtime_vm_exec_state_handle_t *sched_state;
12092 218 state->fast_lane_list_pending_source_sv = NULL;
12093 218 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 218 0 218
12094 218 SvREFCNT_dec(completed);
12095 }
12096 218 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 218 218
12097 0 SvREFCNT_dec(error_sv);
12098 }
12099 218 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 211 7 218
12100 211 frame = gql_runtime_vm_new_block_frame_struct(aTHX);
12101 }
12102 218 sched_state = gql_runtime_vm_ensure_fast_lane_state_sv(aTHX_ state, &sched_state_sv);
12103 218 list_pending_sv = gql_runtime_vm_exec_state_complete_current_native_async_sv(
12104 aTHX_ sched_state_sv, sched_state, field_path, op, slot,
12105 raw_items_sv, &outcome_ignored
12106 );
12107 218 SvREFCNT_dec(raw_items_sv);
12108 218 list_pending = gql_runtime_vm_expect_list_pending(aTHX_ list_pending_sv);
12109 218 gql_runtime_vm_push_pending_list_pending(
12110 218 aTHX_ frame, slot->result_name, slot->result_name_len, field_path,
12111 list_pending, block_index, op->slot_index, i
12112 );
12113 218 SvREFCNT_dec(list_pending_sv);
12114 218 gql_runtime_vm_path_frame_decref(field_path);
12115 218 continue;
12116 }
12117  
12118 6945 ▶ if (state->fast_lane_list_pending_result_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->fast_lane_list_pending_result_sv) { 423 6522 6945
12119 /* Phase 5: an object/abstract list item's own child block already
12120 * ran through this same sync-first machinery one level down (see
12121 * gql_runtime_vm_complete_current_list_fast_sv), and the resulting
12122 * list_pending handle is already fully built - unlike the leaf-only
12123 * channel above, there is nothing left to delegate here, just adopt
12124 * it the same way. */
12125 423 SV *list_pending_sv = state->fast_lane_list_pending_result_sv;
12126 gql_runtime_vm_list_pending_t *list_pending;
12127 423 state->fast_lane_list_pending_result_sv = NULL;
12128 423 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 423 0 423
12129 423 SvREFCNT_dec(completed);
12130 }
12131 423 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 423 423
12132 0 SvREFCNT_dec(error_sv);
12133 }
12134 423 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 423 0 423
12135 423 frame = gql_runtime_vm_new_block_frame_struct(aTHX);
12136 }
12137 423 gql_runtime_vm_ensure_fast_lane_state_sv(aTHX_ state, &sched_state_sv);
12138 423 list_pending = gql_runtime_vm_expect_list_pending(aTHX_ list_pending_sv);
12139 423 gql_runtime_vm_push_pending_list_pending(
12140 423 aTHX_ frame, slot->result_name, slot->result_name_len, field_path,
12141 list_pending, block_index, op->slot_index, i
12142 );
12143 423 SvREFCNT_dec(list_pending_sv);
12144 423 gql_runtime_vm_path_frame_decref(field_path);
12145 423 continue;
12146 }
12147  
12148 6522 ▶ if (completed && SvOK(completed) && gql_runtime_vm_is_block_frame_value_sv(completed)) {
Branch: 3 branches
BranchTrueFalseTotal
if (completed && SvOK(completed) && gql_runtime_vm_is_block_frame_value_sv(completed)) { 6090 432 6522
if (completed && SvOK(completed) && gql_runtime_vm_is_block_frame_value_sv(completed)) { 6056 34 6090
if (completed && SvOK(completed) && gql_runtime_vm_is_block_frame_value_sv(completed)) { 1240 4816 6056
12149 /* Phase 6/7: this op's own COMPLETION (not its resolver) produced a
12150 * child block_frame_t still pending - an OBJECT/ABSTRACT field whose
12151 * own child block suspended (gql_runtime_vm_execute_safe_child_block_fast_sv,
12152 * called with want_promise=0 here), discovered only after
12153 * gql_runtime_vm_execute_current_op_fast_sv already returned, unlike
12154 * fast_lane_suspended_sv (set before completion ever runs, for a
12155 * resolver that itself returned a pending value). Phase 6 originally
12156 * wrapped this in a fresh Promise::XS and parked it as a plain
12157 * promise-kind pending entry; that cost an extra deferred/promise
12158 * pair (and, once reused at the root - Phase 7 - a second one on top
12159 * of that) for no benefit outside the list-item case that actually
12160 * needs a Promise::XS-shaped value. gql_runtime_vm_push_pending_block_frame
12161 * threads the raw frame in directly instead, mirroring exactly what
12162 * the generic executor's own gql_runtime_vm_consume_current_result_now
12163 * already does for this shape - no extra Promise::XS, and
12164 * gql_runtime_vm_cancel_frame_tree already knows how to cancel a
12165 * BLOCK_FRAME_PTR child on a deadlocked abandonment. */
12166 1240 gql_runtime_vm_block_frame_t *child_frame = gql_runtime_vm_expect_block_frame(aTHX_ completed);
12167 gql_runtime_vm_exec_state_handle_t *sched_state;
12168 1240 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 1240 1240
12169 0 SvREFCNT_dec(error_sv);
12170 0 error_sv = NULL;
12171 }
12172 1240 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 1238 2 1240
12173 1238 frame = gql_runtime_vm_new_block_frame_struct(aTHX);
12174 }
12175 /* Unconditional, matching every other channel above: this frame's own
12176 * finalize (in gql_runtime_vm_execute_safe_child_block_fast_sv, for
12177 * the item/field this block belongs to) runs before returning to
12178 * whatever caller ultimately needs state_sv - a call gated behind the
12179 * "settled immediately" branch below would leave *state_sv_out NULL
12180 * whenever child_frame is still genuinely pending (the common case),
12181 * silently routing finalize through its legacy no-exec-state
12182 * fallback instead of the real arm/drain machinery this child_frame
12183 * is already armed against. */
12184 1240 gql_runtime_vm_ensure_fast_lane_state_sv(aTHX_ state, &sched_state_sv);
12185 1240 gql_runtime_vm_push_pending_block_frame(
12186 1240 aTHX_ frame, slot->result_name, slot->result_name_len, field_path,
12187 child_frame, block_index, op->slot_index, i
12188 );
12189 1240 ▶ if (child_frame->pending_unresolved == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (child_frame->pending_unresolved == 0) { 0 1240 1240
12190 0 sched_state = gql_runtime_vm_ensure_fast_lane_state_sv(aTHX_ state, &sched_state_sv);
12191 0 gql_runtime_vm_async_scheduler_enqueue_frame(sched_state, child_frame);
12192 0 ▶ if (!sched_state->async_scheduler_draining) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sched_state->async_scheduler_draining) { 0 0 0
12193 0 gql_runtime_vm_async_scheduler_drain(aTHX_ sched_state_sv, sched_state);
12194 }
12195 }
12196 1240 SvREFCNT_dec(completed);
12197 1240 gql_runtime_vm_path_frame_decref(field_path);
12198 1240 continue;
12199 }
12200  
12201 5282 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 432 4850 5282
12202 432 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, error_sv, field_path);
12203 432 SvREFCNT_dec(error_sv);
12204 432 ▶ completed = completed ? completed : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
completed = completed ? completed : newSVsv(&PL_sv_undef); 432 0 432
12205 /* The null above already carries this field's own error (a coercion
12206 * or resolver error, not a non-null violation) - matching
12207 * gql_runtime_vm_execute_block_fast_sv's own error_outcome handling.
12208 * Without this, the non-null check just below would record a SECOND,
12209 * redundant "Cannot return null" error on top of the real one. This
12210 * was dead code for the root block (root ops are never non-null per
12211 * the eligibility guard) until Phase 5/6 made it live for item/
12212 * object child blocks - caught by t/50_nonnull_propagation.t once a
12213 * nested (non-list) object field's own coercion failure became
12214 * reachable through gql_runtime_vm_execute_safe_child_block_fast_sv. */
12215 432 state->null_carries_error = 1;
12216 }
12217  
12218 /* Non-Null propagation (spec 6.4.4): dead code for the root block (the
12219 * eligibility guard already excludes non-null root ops), live for an
12220 * item's own child block. See the function doc comment for why a
12221 * frame that already exists here cannot simply be discarded. */
12222 5282 ▶ if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) {
Branch: 3 branches
BranchTrueFalseTotal
if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) { 5282 0 5282
if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) { 466 4816 5282
if ((!completed || !SvOK(completed)) && slot->return_type_kind_code == 8) { 18 448 466
12223 18 ▶ if (!state->null_carries_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->null_carries_error) { 9 9 18
12224 9 ▶ SV *msg_sv = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
SV *msg_sv = newSVpvf( 9 0 9
SV *msg_sv = newSVpvf( 9 0 9
12225 "Cannot return null for non-nullable field %s.%s.",
12226 block->type_name ? block->type_name : "(unknown)",
12227 slot->field_name ? slot->field_name : "(unknown)"
12228 );
12229 9 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg_sv, field_path);
12230 9 SvREFCNT_dec(msg_sv);
12231 }
12232 18 ▶ if (completed) {
Branch: 1 branch
BranchTrueFalseTotal
if (completed) { 18 0 18
12233 18 SvREFCNT_dec(completed);
12234 }
12235 18 gql_runtime_vm_path_frame_decref(field_path);
12236 18 state->null_carries_error = 1;
12237 18 ▶ if (frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame) { 0 18 18
12238 0 frame->self_nulled = 1;
12239 } else {
12240 18 *self_nulled_out = 1;
12241 }
12242 18 break;
12243 }
12244 5264 state->null_carries_error = 0;
12245  
12246 5264 gql_runtime_vm_path_frame_decref(field_path);
12247 5264 ▶ resolved_values[i] = completed ? completed : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
resolved_values[i] = completed ? completed : newSVsv(&PL_sv_undef); 0 5264 5264
12248 }
12249  
12250 6120 state->block = saved_block;
12251 6120 state->op = saved_op;
12252 6120 state->slot = saved_slot;
12253 6120 state->path_frame = saved_path_frame;
12254 6120 state->path_frame_is_current_field = saved_path_is_current_field;
12255 6120 state->block_index = saved_block_index;
12256 6120 state->op_index = saved_op_index;
12257  
12258 6120 *frame_out = frame;
12259 6120 *state_sv_out = sched_state_sv;
12260 6120 }
12261  
12262 static gql_runtime_vm_fast_root_continuation_ctx_t *
12263 3 gql_runtime_vm_new_fast_root_continuation_ctx(
12264 pTHX_
12265 SV *runtime_sv,
12266 SV *program_sv,
12267 SV *runtime_schema_sv,
12268 SV *root_value_sv,
12269 SV *context_sv,
12270 SV *variables_sv,
12271 gql_runtime_vm_native_runtime_t *runtime,
12272 gql_runtime_vm_native_bundle_t *bundle,
12273 IV block_index,
12274 IV op_index,
12275 gql_runtime_vm_fast_root_continuation_shared_t *shared
12276 )
12277 {
12278 gql_runtime_vm_fast_root_continuation_ctx_t *ctx;
12279 3 Newxz(ctx, 1, gql_runtime_vm_fast_root_continuation_ctx_t);
12280 3 ▶ ctx->runtime_sv = newSVsv(runtime_sv ? runtime_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ctx->runtime_sv = newSVsv(runtime_sv ? runtime_sv : &PL_sv_undef); 3 0 3
12281 3 ▶ ctx->program_sv = newSVsv(program_sv ? program_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ctx->program_sv = newSVsv(program_sv ? program_sv : &PL_sv_undef); 3 0 3
12282 3 ▶ ctx->runtime_schema_sv = newSVsv(runtime_schema_sv ? runtime_schema_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ctx->runtime_schema_sv = newSVsv(runtime_schema_sv ? runtime_schema_sv : &PL_sv_undef); 3 0 3
12283 3 ▶ ctx->root_value_sv = newSVsv(root_value_sv ? root_value_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ctx->root_value_sv = newSVsv(root_value_sv ? root_value_sv : &PL_sv_undef); 3 0 3
12284 3 ▶ ctx->context_sv = newSVsv(context_sv ? context_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ctx->context_sv = newSVsv(context_sv ? context_sv : &PL_sv_undef); 3 0 3
12285 3 ▶ ctx->variables_sv = newSVsv(variables_sv ? variables_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
ctx->variables_sv = newSVsv(variables_sv ? variables_sv : &PL_sv_undef); 3 0 3
12286 3 ctx->runtime = runtime;
12287 3 ctx->bundle = bundle;
12288 3 ctx->block_index = block_index;
12289 3 ctx->op_index = op_index;
12290 3 ctx->shared = shared;
12291 3 ctx->cv_refcnt = 2;
12292 3 ▶ if (shared) {
Branch: 1 branch
BranchTrueFalseTotal
if (shared) { 3 0 3
12293 3 shared->refcount++;
12294 }
12295 3 return ctx;
12296 }
12297  
12298 /* One ctx, one allocation, shared by both arms of the pair - the resolve
12299 * and reject CVs are distinguished by which XS entry point they wrap, not
12300 * by a flag stored on the shared ctx (mirroring
12301 * gql_runtime_vm_new_pending_callback_pair). */
12302 static void
12303 3 gql_runtime_vm_new_fast_root_continuation_callback_pair_sv(
12304 pTHX_
12305 gql_runtime_vm_fast_root_continuation_ctx_t *ctx,
12306 SV **resolve_rv_out,
12307 SV **reject_rv_out
12308 )
12309 {
12310 3 CV *resolve_cv = newXS(
12311 NULL, gql_runtime_vm_xs_fast_root_continuation_resolve_callback, __FILE__
12312 );
12313 3 CV *reject_cv = newXS(
12314 NULL, gql_runtime_vm_xs_fast_root_continuation_reject_callback, __FILE__
12315 );
12316 3 CvXSUBANY(resolve_cv).any_ptr = ctx;
12317 3 CvXSUBANY(reject_cv).any_ptr = ctx;
12318 3 gql_runtime_vm_attach_callback_magic_ptr(
12319 aTHX_ (SV *)resolve_cv, &gql_runtime_vm_fast_root_continuation_ctx_vtbl, ctx
12320 );
12321 3 gql_runtime_vm_attach_callback_magic_ptr(
12322 aTHX_ (SV *)reject_cv, &gql_runtime_vm_fast_root_continuation_ctx_vtbl, ctx
12323 );
12324 3 *resolve_rv_out = newRV_noinc((SV *)resolve_cv);
12325 3 *reject_rv_out = newRV_noinc((SV *)reject_cv);
12326 3 }
12327  
12328 /* Shared settle body for both arms; reject_arm is passed in directly by
12329 * the caller rather than read off ctx, since ctx is common to both arms.
12330 * Returns NULL (bounds-check failure on a stale/corrupt ctx) or an owned
12331 * response SV the caller must hand back via ST(0)/XSRETURN. */
12332 static SV *
12333 3 gql_runtime_vm_fast_root_continuation_settle_sv(
12334 pTHX_
12335 gql_runtime_vm_fast_root_continuation_ctx_t *ctx,
12336 SV *value,
12337 U8 reject_arm
12338 )
12339 {
12340 gql_runtime_vm_exec_state_t state;
12341 gql_runtime_vm_callback_context_t callback_ctx;
12342 gql_runtime_vm_writer_t writer;
12343 gql_runtime_vm_native_block_t *block;
12344 const gql_runtime_vm_native_op_t *op;
12345 const gql_runtime_vm_native_slot_t *slot;
12346 gql_runtime_vm_path_frame_t *field_path;
12347 3 SV *completed = NULL;
12348 3 SV *error_sv = NULL;
12349 SV *data_sv;
12350 SV *response_sv;
12351 HV *data_hv;
12352  
12353 3 ▶ if (!ctx || !ctx->bundle
Branch: 2 branches
BranchTrueFalseTotal
if (!ctx || !ctx->bundle 3 0 3
if (!ctx || !ctx->bundle 3 0 3
12354 3 ▶ || ctx->block_index < 0 || ctx->block_index >= ctx->bundle->block_count) {
Branch: 2 branches
BranchTrueFalseTotal
|| ctx->block_index < 0 || ctx->block_index >= ctx->bundle->block_count) { 3 0 3
|| ctx->block_index < 0 || ctx->block_index >= ctx->bundle->block_count) { 0 3 3
12355 0 return NULL;
12356 }
12357 3 block = &ctx->bundle->blocks[ctx->block_index];
12358 3 ▶ if (ctx->op_index < 0 || ctx->op_index >= block->op_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->op_index < 0 || ctx->op_index >= block->op_count) { 3 0 3
if (ctx->op_index < 0 || ctx->op_index >= block->op_count) { 0 3 3
12359 0 return NULL;
12360 }
12361 3 op = &block->ops[ctx->op_index];
12362 3 ▶ if (op->slot_index < 0 || op->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 3 0 3
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 0 3 3
12363 0 return NULL;
12364 }
12365 3 slot = &block->slots[op->slot_index];
12366  
12367 3 Zero(&state, 1, gql_runtime_vm_exec_state_t);
12368 3 Zero(&callback_ctx, 1, gql_runtime_vm_callback_context_t);
12369 3 gql_runtime_vm_init_writer_struct(&writer);
12370 3 state.runtime = ctx->runtime;
12371 3 state.runtime_handle_sv = ctx->runtime_sv;
12372 3 state.bundle = ctx->bundle;
12373 3 state.callback_ctx = &callback_ctx;
12374 3 state.writer = &writer;
12375 3 state.block = block;
12376 3 state.op = op;
12377 3 state.slot = slot;
12378 3 state.block_index = ctx->block_index;
12379 3 state.op_index = ctx->op_index;
12380 3 callback_ctx.runtime_schema = ctx->runtime_schema_sv;
12381 3 callback_ctx.context = ctx->context_sv;
12382 3 callback_ctx.variables = ctx->variables_sv;
12383 3 callback_ctx.root_value = ctx->root_value_sv;
12384  
12385 3 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ NULL, slot);
12386 3 state.path_frame = field_path;
12387 3 state.path_frame_is_current_field = 1;
12388 3 ▶ if (reject_arm) {
Branch: 1 branch
BranchTrueFalseTotal
if (reject_arm) { 0 3 3
12389 0 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ &state, value, field_path);
12390 0 completed = newSVsv(&PL_sv_undef);
12391 } else {
12392 3 completed = gql_runtime_vm_complete_resolved_current_fast_sv(
12393 aTHX_ &state, value, &error_sv
12394 );
12395 3 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 0 3 3
12396 0 gql_runtime_vm_fast_lane_record_error_for_path(
12397 aTHX_ &state, error_sv, field_path
12398 );
12399 0 SvREFCNT_dec(error_sv);
12400 0 SvREFCNT_dec(completed);
12401 0 completed = newSVsv(&PL_sv_undef);
12402 }
12403 }
12404 3 gql_runtime_vm_path_frame_decref(field_path);
12405 3 data_hv = newHV();
12406 3 ▶ hv_store(
Branch: 1 branch
BranchTrueFalseTotal
hv_store( 0 3 3
12407 data_hv,
12408 slot->result_name,
12409 (I32)slot->result_name_len,
12410 completed ? completed : newSVsv(&PL_sv_undef),
12411 0
12412 );
12413 3 data_sv = newRV_noinc((SV *)data_hv);
12414 3 response_sv = gql_runtime_vm_fast_response_sv(aTHX_ data_sv, &writer);
12415 3 gql_runtime_vm_clear_writer_struct(aTHX_ &writer);
12416 3 SvREFCNT_dec(callback_ctx.materialized_variables);
12417 3 ▶ if (ctx->shared && ctx->shared->deferred_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (ctx->shared && ctx->shared->deferred_sv) { 3 0 3
if (ctx->shared && ctx->shared->deferred_sv) { 0 3 3
12418 /* Ticket subscribers are invoked with G_VOID|G_DISCARD (see
12419 * gql_runtime_vm_call_ticket_callback), so the caller's ST(0)/XSRETURN
12420 * is never read by that caller - the deferred must be resolved here
12421 * as a side effect instead. */
12422 0 gql_runtime_vm_promise_xs_deferred_resolve_sv(
12423 0 aTHX_ ctx->shared->deferred_sv, response_sv
12424 );
12425 }
12426 3 ▶ if (ctx->shared && ctx->shared->arming && !ctx->shared->sync_response_sv) {
Branch: 3 branches
BranchTrueFalseTotal
if (ctx->shared && ctx->shared->arming && !ctx->shared->sync_response_sv) { 3 0 3
if (ctx->shared && ctx->shared->arming && !ctx->shared->sync_response_sv) { 2 1 3
if (ctx->shared && ctx->shared->arming && !ctx->shared->sync_response_sv) { 2 0 2
12427 2 ctx->shared->sync_response_sv = newSVsv(response_sv);
12428 }
12429 3 return response_sv;
12430 }
12431  
12432 3 static XS(gql_runtime_vm_xs_fast_root_continuation_resolve_callback)
12433 {
12434 dVAR;
12435 3 dXSARGS;
12436 3 gql_runtime_vm_fast_root_continuation_ctx_t *ctx = INT2PTR(
12437 gql_runtime_vm_fast_root_continuation_ctx_t *, CvXSUBANY(cv).any_ptr
12438 );
12439 3 ▶ SV *value = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *value = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 3 0 3
SV *value = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 3 0 3
12440 3 SV *response_sv = gql_runtime_vm_fast_root_continuation_settle_sv(
12441 aTHX_ ctx, value, 0
12442 );
12443 3 ▶ if (!response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!response_sv) { 0 3 3
12444 0 XSRETURN_UNDEF;
12445 }
12446 3 ST(0) = sv_2mortal(response_sv);
12447 3 XSRETURN(1);
12448 }
12449  
12450 0 static XS(gql_runtime_vm_xs_fast_root_continuation_reject_callback)
12451 {
12452 dVAR;
12453 0 dXSARGS;
12454 0 gql_runtime_vm_fast_root_continuation_ctx_t *ctx = INT2PTR(
12455 gql_runtime_vm_fast_root_continuation_ctx_t *, CvXSUBANY(cv).any_ptr
12456 );
12457 0 ▶ SV *value = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *value = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 0 0 0
SV *value = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 0 0 0
12458 0 SV *response_sv = gql_runtime_vm_fast_root_continuation_settle_sv(
12459 aTHX_ ctx, value, 1
12460 );
12461 0 ▶ if (!response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!response_sv) { 0 0 0
12462 0 XSRETURN_UNDEF;
12463 }
12464 0 ST(0) = sv_2mortal(response_sv);
12465 0 XSRETURN(1);
12466 }
12467  
12468 /* Phase 5/6 eligibility: an object/abstract list item's own child block
12469 * (and, recursively, any further object/abstract field nested inside it -
12470 * Phase 6) must itself be a "flat-or-nested-eligible" block, matching the
12471 * same restrictions the root loop already applies to root ops (no runtime
12472 * directives, stable bundle/native_program op indices) - except non-null
12473 * (return_type_kind_code == 8) IS allowed here, since
12474 * gql_runtime_vm_execute_block_fast_multi_sv handles that correctly
12475 * (unlike the root loop, where it stays dead code). A nested OBJECT/
12476 * ABSTRACT field now recurses into ITS OWN child block(s) via this same
12477 * function, since gql_runtime_vm_execute_safe_child_block_fast_sv (Phase 6)
12478 * is exactly-once-safe at any depth. Phase 7 reuses this same function to
12479 * validate a single (non-list) root object/abstract field's own child
12480 * block too (`{ user { name } }`) - the root op loop below now accepts
12481 * COMPLETE_OBJECT/COMPLETE_ABSTRACT root ops and calls this function on
12482 * their child_block_index/abstract_child_indexes exactly like a list
12483 * item's does.
12484 *
12485 * depth is a purely defensive recursion-depth guard, not a correctness
12486 * requirement: compiled blocks mirror the query document's (finite,
12487 * validation-guaranteed acyclic) selection-set tree, not the schema's type
12488 * graph, so a self-referential schema type (e.g. Character.friends:
12489 * [Character]) cannot make this recursion non-terminating - only a
12490 * pathologically deep query literal could, and GQL_VM_FAST_LANE_MAX_NESTING_DEPTH
12491 * exists solely to fail closed (fall back) rather than risk a stack
12492 * overflow on such an input. */
12493 #define GQL_VM_FAST_LANE_MAX_NESTING_DEPTH 16
12494  
12495 static int
12496 1850 gql_runtime_vm_fast_lane_list_item_block_is_eligible(
12497 gql_runtime_vm_native_bundle_t *bundle,
12498 gql_runtime_vm_native_program_t *program,
12499 IV block_index,
12500 IV depth
12501 )
12502 {
12503 gql_runtime_vm_native_block_t *block;
12504 IV i;
12505  
12506 1850 ▶ if (depth > GQL_VM_FAST_LANE_MAX_NESTING_DEPTH) {
Branch: 1 branch
BranchTrueFalseTotal
if (depth > GQL_VM_FAST_LANE_MAX_NESTING_DEPTH) { 4 1846 1850
12507 4 return 0;
12508 }
12509 1846 ▶ if (block_index < 0 || block_index >= bundle->block_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (block_index < 0 || block_index >= bundle->block_count) { 1846 0 1846
if (block_index < 0 || block_index >= bundle->block_count) { 0 1846 1846
12510 0 return 0;
12511 }
12512 1846 block = &bundle->blocks[block_index];
12513 1846 ▶ if (block_index >= program->block_count
Branch: 1 branch
BranchTrueFalseTotal
if (block_index >= program->block_count 1846 0 1846
12514 1846 ▶ || block->op_count != program->blocks[block_index].op_count) {
Branch: 1 branch
BranchTrueFalseTotal
|| block->op_count != program->blocks[block_index].op_count) { 0 1846 1846
12515 0 return 0;
12516 }
12517 4826 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 3049 1777 4826
12518 3049 gql_runtime_vm_native_op_t *op = &block->ops[i];
12519 3049 ▶ if (op->slot_index < 0 || op->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 3049 0 3049
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 0 3049 3049
12520 0 return 0;
12521 }
12522 3049 ▶ if ((op->complete_code != GQL_VM_COMPLETE_GENERIC
Branch: 1 branch
BranchTrueFalseTotal
if ((op->complete_code != GQL_VM_COMPLETE_GENERIC 817 2232 3049
12523 817 ▶ && op->complete_code != GQL_VM_COMPLETE_LIST
Branch: 1 branch
BranchTrueFalseTotal
&& op->complete_code != GQL_VM_COMPLETE_LIST 736 81 817
12524 736 ▶ && op->complete_code != GQL_VM_COMPLETE_OBJECT
Branch: 1 branch
BranchTrueFalseTotal
&& op->complete_code != GQL_VM_COMPLETE_OBJECT 1 735 736
12525 1 ▶ && op->complete_code != GQL_VM_COMPLETE_ABSTRACT)
Branch: 1 branch
BranchTrueFalseTotal
&& op->complete_code != GQL_VM_COMPLETE_ABSTRACT) 1 0 1
12526 3049 ▶ || op->has_runtime_directives || op->runtime_directives_sv) {
Branch: 2 branches
BranchTrueFalseTotal
|| op->has_runtime_directives || op->runtime_directives_sv) { 3048 1 3049
|| op->has_runtime_directives || op->runtime_directives_sv) { 0 3048 3048
12527 1 return 0;
12528 }
12529 3048 ▶ if (op->child_block_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (op->child_block_index >= 0 772 2276 3048
12530 772 ▶ && !gql_runtime_vm_fast_lane_list_item_block_is_eligible(
Branch: 1 branch
BranchTrueFalseTotal
&& !gql_runtime_vm_fast_lane_list_item_block_is_eligible( 68 704 772
12531 bundle, program, op->child_block_index, depth + 1
12532 )) {
12533 68 return 0;
12534 }
12535 2980 ▶ if (op->abstract_child_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->abstract_child_count > 0) { 35 2945 2980
12536 IV ai;
12537 105 ▶ for (ai = 0; ai < op->abstract_child_count; ai++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ai = 0; ai < op->abstract_child_count; ai++) { 70 35 105
12538 70 ▶ if (!gql_runtime_vm_fast_lane_list_item_block_is_eligible(
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fast_lane_list_item_block_is_eligible( 0 70 70
12539 70 bundle, program, op->abstract_child_indexes[ai], depth + 1
12540 )) {
12541 0 return 0;
12542 }
12543 }
12544 }
12545 }
12546 1777 return 1;
12547 }
12548  
12549 static SV *
12550 1791 gql_runtime_vm_try_execute_fast_root_continuation_sv(
12551 pTHX_
12552 SV *runtime_sv,
12553 SV *program_sv,
12554 gql_runtime_vm_native_runtime_t *runtime,
12555 gql_runtime_vm_native_program_t *program,
12556 SV *runtime_schema,
12557 SV *root_value,
12558 SV *context_value,
12559 SV *variables,
12560 U8 json_mode,
12561 SV *on_stall_sv,
12562 U8 *handled_out
12563 )
12564 {
12565 gql_runtime_vm_native_bundle_t *bundle;
12566 gql_runtime_vm_native_block_t *block;
12567 gql_runtime_vm_exec_state_t state;
12568 gql_runtime_vm_callback_context_t callback_ctx;
12569 gql_runtime_vm_writer_t *writer;
12570 SV *empty_args_sv;
12571 SV *data_sv;
12572 SV *promise_sv;
12573 SV *resolve_callback_sv;
12574 SV *reject_callback_sv;
12575 SV *ret;
12576 gql_runtime_vm_fast_root_continuation_shared_t *shared;
12577 1791 gql_runtime_vm_block_frame_t *frame = NULL;
12578 1791 SV *promoted_state_sv = NULL;
12579 IV i;
12580  
12581 1791 *handled_out = 0;
12582 /* The continuation lane calls Promise::XS internals directly; adapters use
12583 * the generic async executor until they provide an equivalent fast ABI. */
12584 1791 ▶ if (runtime->async_adapter != &gql_runtime_vm_promise_xs_adapter) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime->async_adapter != &gql_runtime_vm_promise_xs_adapter) { 3 1788 1791
12585 3 return NULL;
12586 }
12587 1788 ▶ if (json_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if (json_mode) { 25 1763 1788
12588 25 return NULL;
12589 }
12590 1763 bundle = gql_runtime_vm_native_program_cached_bundle(aTHX_ runtime, program);
12591 1755 ▶ if (!bundle || bundle->root_block_index < 0
Branch: 2 branches
BranchTrueFalseTotal
if (!bundle || bundle->root_block_index < 0 1755 0 1755
if (!bundle || bundle->root_block_index < 0 1755 0 1755
12592 1755 ▶ || bundle->root_block_index >= bundle->block_count) {
Branch: 1 branch
BranchTrueFalseTotal
|| bundle->root_block_index >= bundle->block_count) { 0 1755 1755
12593 0 return NULL;
12594 }
12595 1755 block = &bundle->blocks[bundle->root_block_index];
12596 1755 ▶ if (block->op_count < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (block->op_count < 1) { 2 1753 1755
12597 2 return NULL;
12598 }
12599 /* Bundle prep (gql_runtime_vm_prepare_cached_bundle_in_place) can delete
12600 * ops whose static directive evaluates to false, shifting every later
12601 * op's bundle-relative index away from its native_program-relative
12602 * index. A block-level op_count match is a cheap, sufficient proof that
12603 * nothing in this block was deleted, so the op_index recorded below for
12604 * a suspended field is safe to hand to gql_runtime_vm_exec_state_complete_async_sv
12605 * later, which looks the field up against the raw native_program, not
12606 * the bundle. */
12607 1753 ▶ if (bundle->root_block_index >= program->block_count
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->root_block_index >= program->block_count 1753 0 1753
12608 1753 ▶ || block->op_count != program->blocks[bundle->root_block_index].op_count) {
Branch: 1 branch
BranchTrueFalseTotal
|| block->op_count != program->blocks[bundle->root_block_index].op_count) { 0 1753 1753
12609 0 return NULL;
12610 }
12611 4457 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 2738 1719 4457
12612 2738 gql_runtime_vm_native_op_t *op = &block->ops[i];
12613 gql_runtime_vm_native_slot_t *slot;
12614 2738 ▶ if (op->slot_index < 0 || op->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 2738 0 2738
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 0 2738 2738
12615 0 return NULL;
12616 }
12617 2738 slot = &block->slots[op->slot_index];
12618 /* Phase 7: a root op may now be a single (non-list) object/abstract
12619 * field too (e.g. `{ user { name } }`) - execute_block_fast_multi_sv
12620 * already handles GQL_VM_COMPLETE_OBJECT/ABSTRACT ops generically
12621 * (Phase 5/6 exercise this same per-op loop from list items and
12622 * nested fields), so only the child block itself needs the same
12623 * recursive eligibility check list items already require. Root
12624 * non-null (return_type_kind_code == 8) stays rejected regardless of
12625 * complete_code - that is a separate, still out-of-scope item. */
12626 2738 ▶ if ((op->complete_code != GQL_VM_COMPLETE_GENERIC
Branch: 1 branch
BranchTrueFalseTotal
if ((op->complete_code != GQL_VM_COMPLETE_GENERIC 1216 1522 2738
12627 1216 ▶ && op->complete_code != GQL_VM_COMPLETE_LIST
Branch: 1 branch
BranchTrueFalseTotal
&& op->complete_code != GQL_VM_COMPLETE_LIST 549 667 1216
12628 549 ▶ && op->complete_code != GQL_VM_COMPLETE_OBJECT
Branch: 1 branch
BranchTrueFalseTotal
&& op->complete_code != GQL_VM_COMPLETE_OBJECT 26 523 549
12629 26 ▶ && op->complete_code != GQL_VM_COMPLETE_ABSTRACT)
Branch: 1 branch
BranchTrueFalseTotal
&& op->complete_code != GQL_VM_COMPLETE_ABSTRACT) 26 0 26
12630 2738 ▶ || op->has_runtime_directives || op->runtime_directives_sv
Branch: 2 branches
BranchTrueFalseTotal
|| op->has_runtime_directives || op->runtime_directives_sv 2737 1 2738
|| op->has_runtime_directives || op->runtime_directives_sv 2737 0 2737
12631 2737 ▶ || slot->return_type_kind_code == 8) {
Branch: 1 branch
BranchTrueFalseTotal
|| slot->return_type_kind_code == 8) { 28 2709 2737
12632 29 return NULL;
12633 }
12634 2709 ▶ if (op->child_block_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (op->child_block_index >= 0 952 1757 2709
12635 952 ▶ && !gql_runtime_vm_fast_lane_list_item_block_is_eligible(
Branch: 1 branch
BranchTrueFalseTotal
&& !gql_runtime_vm_fast_lane_list_item_block_is_eligible( 5 947 952
12636 bundle, program, op->child_block_index, 0
12637 )) {
12638 5 return NULL;
12639 }
12640 2704 ▶ if (op->abstract_child_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->abstract_child_count > 0) { 32 2672 2704
12641 IV ai;
12642 88 ▶ for (ai = 0; ai < op->abstract_child_count; ai++) {
Branch: 1 branch
BranchTrueFalseTotal
for (ai = 0; ai < op->abstract_child_count; ai++) { 56 32 88
12643 56 ▶ if (!gql_runtime_vm_fast_lane_list_item_block_is_eligible(
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fast_lane_list_item_block_is_eligible( 0 56 56
12644 56 bundle, program, op->abstract_child_indexes[ai], 0
12645 )) {
12646 0 return NULL;
12647 }
12648 }
12649 }
12650 }
12651  
12652 1719 Zero(&state, 1, gql_runtime_vm_exec_state_t);
12653 1719 Zero(&callback_ctx, 1, gql_runtime_vm_callback_context_t);
12654 1719 writer = gql_runtime_vm_new_writer_struct(aTHX);
12655 1719 state.runtime = runtime;
12656 1719 state.runtime_handle_sv = runtime_sv;
12657 1719 state.bundle = bundle;
12658 1719 state.callback_ctx = &callback_ctx;
12659 1719 state.writer = writer;
12660 1719 state.fast_lane_can_suspend = 1;
12661 1719 state.program_sv = program_sv;
12662 1719 state.fast_lane_root_block_index = bundle->root_block_index;
12663 1719 ▶ callback_ctx.runtime_schema = runtime_schema ? runtime_schema : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
callback_ctx.runtime_schema = runtime_schema ? runtime_schema : &PL_sv_undef; 1719 0 1719
12664 1719 callback_ctx.context = context_value;
12665 1719 callback_ctx.variables = variables;
12666 1719 callback_ctx.root_value = root_value;
12667 1719 callback_ctx.native_program = program;
12668 1719 state.empty_args_sv = empty_args_sv = gql_runtime_vm_empty_args_sv(aTHX);
12669  
12670 1719 ▶ if (!on_stall_sv && block->op_count == 1 && block->ops[0].complete_code == GQL_VM_COMPLETE_GENERIC) {
Branch: 3 branches
BranchTrueFalseTotal
if (!on_stall_sv && block->op_count == 1 && block->ops[0].complete_code == GQL_VM_COMPLETE_GENERIC) { 232 1487 1719
if (!on_stall_sv && block->op_count == 1 && block->ops[0].complete_code == GQL_VM_COMPLETE_GENERIC) { 145 87 232
if (!on_stall_sv && block->op_count == 1 && block->ops[0].complete_code == GQL_VM_COMPLETE_GENERIC) { 68 77 145
12671 /* Single field: keep the light direct-construction resume (no
12672 * block_frame_t/exec_state_handle_t at all). Phase 2 measured this to
12673 * be ~7%/~2.6% cheaper than routing a lone suspension through the
12674 * generic scheduler - only worth paying for once N > 1 siblings can
12675 * amortize the block_frame_t/exec_state_handle_t cost (see
12676 * docs/future-performance-investigation-ja.md §14.17). A lone LIST op
12677 * falls through to the shared multi path below instead: item-level
12678 * list pending needs the real exec_state_handle_t machinery Phase 4
12679 * adds there, so there is no cheap direct-construction variant for it.
12680 * Phase 8: this shortcut builds its own lightweight Promise::XS-based
12681 * continuation (gql_runtime_vm_fast_root_continuation_shared_t) that
12682 * predates and does not know about the C-level on_stall drive loop, so
12683 * skip it entirely when on_stall_sv is given - the multi-op path below
12684 * (which does know about it) handles op_count == 1 just fine, just
12685 * without this shortcut's extra ~7% saving for that narrower case. */
12686 68 data_sv = gql_runtime_vm_execute_block_fast_sv(
12687 aTHX_ &state, bundle->root_block_index, root_value
12688 );
12689 68 ▶ if (!state.fast_lane_suspended_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state.fast_lane_suspended_sv) { 65 3 68
12690 65 ret = gql_runtime_vm_fast_response_sv(aTHX_ data_sv, writer);
12691 65 gql_runtime_vm_writer_decref(aTHX_ writer);
12692 65 SvREFCNT_dec(callback_ctx.materialized_variables);
12693 65 SvREFCNT_dec(empty_args_sv);
12694 65 *handled_out = 1;
12695 65 return ret;
12696 }
12697  
12698 3 promise_sv = state.fast_lane_suspended_sv;
12699 3 state.fast_lane_suspended_sv = NULL;
12700 3 Newxz(shared, 1, gql_runtime_vm_fast_root_continuation_shared_t);
12701 3 shared->refcount = 1;
12702 3 gql_runtime_vm_new_fast_root_continuation_callback_pair_sv(
12703 aTHX_
12704 gql_runtime_vm_new_fast_root_continuation_ctx(
12705 aTHX_ runtime_sv, program_sv, runtime_schema, root_value, context_value,
12706 variables, runtime, bundle, bundle->root_block_index, 0, shared
12707 ),
12708 &resolve_callback_sv, &reject_callback_sv
12709 );
12710 3 ▶ if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ promise_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ promise_sv)) { 0 3 3
12711 /* The guard already filtered out a settled Ticket (state 1/2), so
12712 * this is genuinely pending: gql_runtime_vm_subscribe_dataloader_ticket
12713 * never fires synchronously in that case (unlike Promise::XS
12714 * then()), so the request-level result is always the fresh
12715 * deferred's promise - subscribe directly to the ticket's C-level
12716 * notification instead of bridging through the slower Perl-method
12717 * _subscribe path. */
12718 0 shared->deferred_sv = gql_runtime_vm_promise_xs_new_deferred_sv(aTHX);
12719 0 ret = gql_runtime_vm_promise_xs_deferred_promise_sv(aTHX_ shared->deferred_sv);
12720 0 gql_runtime_vm_subscribe_dataloader_ticket(
12721 aTHX_ promise_sv, resolve_callback_sv, reject_callback_sv
12722 );
12723 } else {
12724 3 shared->arming = 1;
12725 3 ret = gql_runtime_vm_call_then_promise_xs_sv(
12726 aTHX_ promise_sv, resolve_callback_sv, reject_callback_sv, NULL
12727 );
12728 3 shared->arming = 0;
12729 3 ▶ if (shared->sync_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (shared->sync_response_sv) { 2 1 3
12730 2 SV *sync_response_sv = shared->sync_response_sv;
12731 2 shared->sync_response_sv = NULL;
12732 2 SvREFCNT_dec(ret);
12733 2 ret = sync_response_sv;
12734 }
12735 }
12736 3 SvREFCNT_dec(resolve_callback_sv);
12737 3 SvREFCNT_dec(reject_callback_sv);
12738 3 SvREFCNT_dec(promise_sv);
12739 3 gql_runtime_vm_writer_decref(aTHX_ writer);
12740 3 SvREFCNT_dec(callback_ctx.materialized_variables);
12741 3 SvREFCNT_dec(empty_args_sv);
12742 3 ▶ if (--shared->refcount == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--shared->refcount == 0) { 2 1 3
12743 2 SvREFCNT_dec(shared->sync_response_sv);
12744 2 SvREFCNT_dec(shared->deferred_sv);
12745 2 Safefree(shared);
12746 }
12747 3 *handled_out = 1;
12748 3 return ret;
12749 }
12750  
12751 {
12752 SV **resolved_values;
12753 1651 U8 self_nulled_ignored = 0;
12754 1651 ▶ Newxz(resolved_values, block->op_count, SV *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(resolved_values, block->op_count, SV *); 0 1651 1651
12755 /* self_nulled_ignored can never be set here: the eligibility guard
12756 * above already rejects any non-null root op (slot->return_type_kind_code
12757 * == 8), so the non-null propagation branch of the shared loop is dead
12758 * code for the root block. */
12759 1651 gql_runtime_vm_execute_block_fast_multi_sv(
12760 aTHX_ &state, bundle->root_block_index, root_value, NULL,
12761 resolved_values, &frame, &promoted_state_sv, &self_nulled_ignored
12762 );
12763  
12764 1651 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 112 1539 1651
12765 /* Fully synchronous: build the plain response hash directly from the
12766 * per-op array. No native_value_t ever gets built on this path. */
12767 112 HV *data_hv = newHV();
12768 520 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 408 112 520
12769 gql_runtime_vm_native_slot_t *slot;
12770 408 ▶ if (!resolved_values[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (!resolved_values[i]) { 0 408 408
12771 0 continue;
12772 }
12773 408 slot = &block->slots[block->ops[i].slot_index];
12774 408 hv_store(data_hv, slot->result_name, (I32)slot->result_name_len, resolved_values[i], 0);
12775 }
12776 112 Safefree(resolved_values);
12777 112 data_sv = newRV_noinc((SV *)data_hv);
12778 112 ret = gql_runtime_vm_fast_response_sv(aTHX_ data_sv, writer);
12779 112 gql_runtime_vm_writer_decref(aTHX_ writer);
12780 112 SvREFCNT_dec(callback_ctx.materialized_variables);
12781 112 SvREFCNT_dec(empty_args_sv);
12782 112 *handled_out = 1;
12783 112 return ret;
12784 }
12785  
12786 /* At least one sibling suspended: fold every sibling that DID resolve
12787 * (whether before or after the first suspension) directly into the
12788 * frame's native value tree - skipping the intermediate HV entirely,
12789 * since every value here is already a final Perl scalar and every name
12790 * is already a plan-owned string safe to borrow, unlike
12791 * gql_runtime_vm_native_value_from_sv's generic HV-walking path, which
12792 * would re-copy each name and pay hv_iterinit/hv_iternext traversal for
12793 * no benefit here - then hand off to the same finalize/arm/drain
12794 * machinery the generic async executor's own root frame uses
12795 * (gql_runtime_vm_block_frame_finalize_sv), instead of hand-rolling
12796 * completion here as the single-field continuation does: with N
12797 * siblings that could settle back-to-back, this needs the same
12798 * async_scheduler_draining-guarded arm ordering the generic lane
12799 * already relies on. */
12800 3762 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 2223 1539 3762
12801 gql_runtime_vm_native_slot_t *slot;
12802 2223 ▶ if (!resolved_values[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (!resolved_values[i]) { 1559 664 2223
12803 1559 continue;
12804 }
12805 664 slot = &block->slots[block->ops[i].slot_index];
12806 1328 gql_runtime_vm_native_object_store(
12807 664 aTHX_ frame->values_value, slot->result_name, 1,
12808 664 gql_runtime_vm_new_native_value_scalar(aTHX_ resolved_values[i])
12809 );
12810 664 SvREFCNT_dec(resolved_values[i]);
12811 }
12812 1539 Safefree(resolved_values);
12813 }
12814 1539 frame->deferred_resolves_response = 1;
12815  
12816 {
12817 /* An item-level list pending detected mid-loop (or a nested suspension
12818 * even deeper, inside an object list item's own child block) may have
12819 * already promoted to a real exec_state_handle_t (see
12820 * gql_runtime_vm_ensure_fast_lane_state_sv); reuse it instead of
12821 * building a second one for the same request. */
12822 SV *sched_state_sv;
12823 gql_runtime_vm_exec_state_handle_t *sched_state =
12824 1539 gql_runtime_vm_ensure_fast_lane_state_sv(aTHX_ &state, &sched_state_sv);
12825 1539 sched_state->response_frame = frame;
12826 1539 gql_runtime_vm_writer_decref(aTHX_ writer);
12827  
12828 1539 ▶ ret = gql_runtime_vm_block_frame_finalize_sv(
Branch: 1 branch
BranchTrueFalseTotal
ret = gql_runtime_vm_block_frame_finalize_sv( 1484 55 1539
12829 aTHX_ frame, sched_state->async_adapter, sched_state->writer,
12830 sched_state_sv, on_stall_sv ? 3 : 0
12831 );
12832 1539 ▶ if (sched_state->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (sched_state->completed_response_sv) { 10 1529 1539
12833 10 SvREFCNT_dec(ret);
12834 10 ret = SvREFCNT_inc_simple_NN(sched_state->completed_response_sv);
12835 1529 ▶ } else if (on_stall_sv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (on_stall_sv) { 1479 50 1529
12836 /* Phase 8: genuinely pending, and mode 3 above means finalize never
12837 * built a promise for it (ret is just a throwaway raw block-frame
12838 * handle) - drive it to completion right here instead of handing
12839 * anything back for the caller to await. */
12840 1479 SvREFCNT_dec(ret);
12841 1479 ret = gql_runtime_vm_drive_with_on_stall_sv(aTHX_ sched_state, on_stall_sv);
12842 50 ▶ } else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ sched_state, ret)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ sched_state, ret)) { 50 0 50
12843 /* A genuinely pending response built through the real exec_state_handle_t
12844 * machinery forms the same reference cycle the generic executor's own
12845 * root frame does (see gql_runtime_vm_cancel_pending_response_sv's R5
12846 * leak 2 comment) - this call site just never attached the magic that
12847 * lets the Perl driver break it on a deadlocked stall. Every shape that
12848 * reaches this block (multi-sibling root, root list, object/abstract
12849 * root list, and now Phase 7's single root object/abstract field) needs
12850 * it equally; the omission was simply never reached by a genuine
12851 * deadlock in the existing regression coverage until a single root
12852 * object field with a never-settling nested promise exposed it. */
12853 50 gql_runtime_vm_attach_response_state_magic(aTHX_ ret, sched_state_sv);
12854 }
12855 }
12856  
12857 1528 SvREFCNT_dec(callback_ctx.materialized_variables);
12858 1528 SvREFCNT_dec(empty_args_sv);
12859 1528 *handled_out = 1;
12860 1528 return ret;
12861 }
12862  
12863 /*
12864 * Direct-JSON variant of the sync fast lane. Instead of materializing the
12865 * response as Perl hashes/arrays and encoding afterwards, the block loop
12866 * appends JSON bytes straight into an output SV. Field order follows op
12867 * order, i.e. the query's field order. Output is UTF-8 encoded octets.
12868 */
12869  
12870 static int gql_runtime_vm_execute_block_fast_json(pTHX_ gql_runtime_vm_exec_state_t *state, IV block_index, SV *source, SV *out);
12871  
12872 static void
12873 677 gql_runtime_vm_json_cat_string(pTHX_ SV *out, const char *pv, STRLEN len)
12874 {
12875 STRLEN i;
12876 677 STRLEN run_start = 0;
12877  
12878 677 sv_catpvs(out, "\"");
12879 11245 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 10568 677 11245
12880 10568 const unsigned char c = (unsigned char)pv[i];
12881 10568 const char *escape = NULL;
12882 char ubuf[8];
12883  
12884 10568 switch (c) {
12885 10 case '"': escape = "\\\""; break;
12886 0 case '\\': escape = "\\\\"; break;
12887 0 case '\b': escape = "\\b"; break;
12888 0 case '\f': escape = "\\f"; break;
12889 7 case '\n': escape = "\\n"; break;
12890 0 case '\r': escape = "\\r"; break;
12891 3 case '\t': escape = "\\t"; break;
12892 10548 default:
12893 10548 ▶ if (c < 0x20) {
Branch: 1 branch
BranchTrueFalseTotal
if (c < 0x20) { 0 10548 10548
12894 0 my_snprintf(ubuf, sizeof(ubuf), "\\u%04x", (unsigned int)c);
12895 0 escape = ubuf;
12896 }
12897 10548 break;
12898 }
12899 10568 ▶ if (escape) {
Branch: 1 branch
BranchTrueFalseTotal
if (escape) { 20 10548 10568
12900 20 ▶ if (i > run_start) {
Branch: 1 branch
BranchTrueFalseTotal
if (i > run_start) { 11 9 20
12901 11 sv_catpvn(out, pv + run_start, i - run_start);
12902 }
12903 20 sv_catpv(out, escape);
12904 20 run_start = i + 1;
12905 }
12906 }
12907 677 ▶ if (len > run_start) {
Branch: 1 branch
BranchTrueFalseTotal
if (len > run_start) { 676 1 677
12908 676 sv_catpvn(out, pv + run_start, len - run_start);
12909 }
12910 677 sv_catpvs(out, "\"");
12911 677 }
12912  
12913 static void
12914 4 gql_runtime_vm_json_cat_nv(pTHX_ SV *out, NV nv)
12915 {
12916 4 ▶ if (Perl_isnan(nv) || Perl_isinf(nv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Perl_isnan(nv) || Perl_isinf(nv)) { 4 0 4
if (Perl_isnan(nv) || Perl_isinf(nv)) { 0 4 4
12917 0 sv_catpvs(out, "null");
12918 0 return;
12919 }
12920  
12921 /* Perl's formatter understands the configured NV type, including
12922 * __float128 in USE_QUADMATH builds. Gconvert may pass an NV through the
12923 * platform printf family as a double, which turns valid quadmath values
12924 * into undefined output. */
12925 4 sv_catpvf(out, "%.*" NVgf, NV_DIG, nv);
12926 }
12927  
12928 static void
12929 850 gql_runtime_vm_json_cat_scalar(pTHX_ gql_runtime_vm_exec_state_t *state, SV *out, SV *value)
12930 {
12931 850 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 850 0 850
if (!value || !SvOK(value)) { 251 599 850
12932 251 sv_catpvs(out, "null");
12933 251 return;
12934 }
12935 599 ▶ if (SvROK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(value)) { 0 599 599
12936 0 SV *inner = SvRV(value);
12937 0 ▶ if (sv_isobject(value)
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(value) 0 0 0
12938 0 ▶ && (sv_derived_from(value, "JSON::PP::Boolean")
Branch: 1 branch
BranchTrueFalseTotal
&& (sv_derived_from(value, "JSON::PP::Boolean") 0 0 0
12939 0 ▶ || sv_derived_from(value, "Types::Serialiser::Boolean"))) {
Branch: 1 branch
BranchTrueFalseTotal
|| sv_derived_from(value, "Types::Serialiser::Boolean"))) { 0 0 0
12940 0 ▶ sv_catpv(out, SvTRUE(inner) ? "true" : "false");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, SvTRUE(inner) ? "true" : "false"); 0 0 0
12941 0 return;
12942 }
12943 0 ▶ if (!SvOBJECT(inner) && SvIOK(inner) && (SvIV(inner) == 0 || SvIV(inner) == 1)) {
Branch: 4 branches
BranchTrueFalseTotal
if (!SvOBJECT(inner) && SvIOK(inner) && (SvIV(inner) == 0 || SvIV(inner) == 1)) { 0 0 0
if (!SvOBJECT(inner) && SvIOK(inner) && (SvIV(inner) == 0 || SvIV(inner) == 1)) { 0 0 0
if (!SvOBJECT(inner) && SvIOK(inner) && (SvIV(inner) == 0 || SvIV(inner) == 1)) { 0 0 0
if (!SvOBJECT(inner) && SvIOK(inner) && (SvIV(inner) == 0 || SvIV(inner) == 1)) { 0 0 0
12944 /* \0 / \1 boolean convention */
12945 0 ▶ sv_catpv(out, SvIV(inner) ? "true" : "false");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, SvIV(inner) ? "true" : "false"); 0 0 0
12946 0 return;
12947 }
12948 0 ▶ if (sv_isobject(value)
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(value) 0 0 0
12949 0 ▶ && ((state && state->runtime
Branch: 2 branches
BranchTrueFalseTotal
&& ((state && state->runtime 0 0 0
&& ((state && state->runtime 0 0 0
12950 0 ▶ && gql_runtime_vm_sv_is_adapter_promise(
Branch: 1 branch
BranchTrueFalseTotal
&& gql_runtime_vm_sv_is_adapter_promise( 0 0 0
12951 0 aTHX_ state->runtime->async_adapter, value
12952 ))
12953 0 ▶ || (!state && gql_runtime_vm_sv_is_promise_xs(aTHX_ value)))) {
Branch: 2 branches
BranchTrueFalseTotal
|| (!state && gql_runtime_vm_sv_is_promise_xs(aTHX_ value)))) { 0 0 0
|| (!state && gql_runtime_vm_sv_is_promise_xs(aTHX_ value)))) { 0 0 0
12954 /* A promise that slipped past the resolve/item guards (e.g. inside
12955 * a source hash). On the fast lanes, defer the croak so the live
12956 * path frame chain unwinds; the native-value writer (async tail,
12957 * state == NULL) never sees promises, so croaking there is safe. */
12958 0 ▶ if (state) {
Branch: 1 branch
BranchTrueFalseTotal
if (state) { 0 0 0
12959 0 ▶ if (!state->fast_lane_deferred_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->fast_lane_deferred_croak_sv) { 0 0 0
12960 0 state->fast_lane_deferred_croak_sv =
12961 0 newSVpv(GQL_RUNTIME_VM_FAST_LANE_PROMISE_ERROR, 0);
12962 }
12963 0 sv_catpvs(out, "null");
12964 0 return;
12965 }
12966 0 croak("%s", GQL_RUNTIME_VM_FAST_LANE_PROMISE_ERROR);
12967 }
12968 /* Unexpected reference in a leaf position: stringify. */
12969 {
12970 STRLEN len;
12971 0 const char *pv = SvPVutf8(value, len);
12972 0 gql_runtime_vm_json_cat_string(aTHX_ out, pv, len);
12973 }
12974 0 return;
12975 }
12976 599 ▶ if (SvPOKp(value) && !SvIOKp(value) && !SvNOKp(value)) {
Branch: 3 branches
BranchTrueFalseTotal
if (SvPOKp(value) && !SvIOKp(value) && !SvNOKp(value)) { 551 48 599
if (SvPOKp(value) && !SvIOKp(value) && !SvNOKp(value)) { 551 0 551
if (SvPOKp(value) && !SvIOKp(value) && !SvNOKp(value)) { 551 0 551
12977 STRLEN len;
12978 551 const char *pv = SvPVutf8(value, len);
12979 551 gql_runtime_vm_json_cat_string(aTHX_ out, pv, len);
12980 551 return;
12981 }
12982 48 ▶ if (SvIOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOKp(value)) { 44 4 48
12983 44 ▶ if (SvIsUV(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIsUV(value)) { 0 44 44
12984 0 sv_catpvf(out, "%" UVuf, (UV)SvUV(value));
12985 } else {
12986 44 sv_catpvf(out, "%" IVdf, (IV)SvIV(value));
12987 }
12988 44 return;
12989 }
12990 4 ▶ if (SvNOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOKp(value)) { 4 0 4
12991 4 gql_runtime_vm_json_cat_nv(aTHX_ out, SvNV(value));
12992 4 return;
12993 }
12994 {
12995 STRLEN len;
12996 0 const char *pv = SvPVutf8(value, len);
12997 0 gql_runtime_vm_json_cat_string(aTHX_ out, pv, len);
12998 }
12999 }
13000  
13001 /* Returns 1 when the block nulled itself over a non-null violation; the
13002 * callee has already truncated its own bytes from `out` and the caller
13003 * writes "null" or keeps propagating. */
13004 static int
13005 132 gql_runtime_vm_execute_child_block_fast_json(
13006 pTHX_
13007 gql_runtime_vm_exec_state_t *state,
13008 IV block_index,
13009 SV *source,
13010 SV *out
13011 )
13012 {
13013 132 ▶ gql_runtime_vm_path_frame_t *saved_path_frame = state ? state->path_frame : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_path_frame_t *saved_path_frame = state ? state->path_frame : NULL; 132 0 132
13014 132 ▶ int saved_path_is_current_field = state ? state->path_frame_is_current_field : 0;
Branch: 1 branch
BranchTrueFalseTotal
int saved_path_is_current_field = state ? state->path_frame_is_current_field : 0; 132 0 132
13015 gql_runtime_vm_path_frame_t *field_path;
13016 int propagated;
13017  
13018 132 ▶ if (!state) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state) { 0 132 132
13019 0 sv_catpvs(out, "null");
13020 0 return 0;
13021 }
13022  
13023 132 ▶ if (state->path_frame_is_current_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->path_frame_is_current_field) { 67 65 132
13024 67 field_path = NULL;
13025 } else {
13026 65 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot);
13027 65 state->path_frame = field_path;
13028 65 state->path_frame_is_current_field = 1;
13029 }
13030 132 propagated = gql_runtime_vm_execute_block_fast_json(aTHX_ state, block_index, source, out);
13031 132 state->path_frame = saved_path_frame;
13032 132 state->path_frame_is_current_field = saved_path_is_current_field;
13033 132 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 65 67 132
13034 65 gql_runtime_vm_path_frame_decref(field_path);
13035 }
13036 132 return propagated;
13037 }
13038  
13039 /* Returns 1 when a non-null list item ([T!]) was null: the list's bytes
13040 * are truncated from `out` and the caller emits null / propagates. */
13041 static int
13042 181 gql_runtime_vm_complete_current_list_fast_json(
13043 pTHX_
13044 gql_runtime_vm_exec_state_t *state,
13045 SV *value,
13046 SV *out
13047 )
13048 {
13049 181 const gql_runtime_vm_native_op_t *op = state->op;
13050  
13051 181 ▶ if (op->complete_code != GQL_VM_COMPLETE_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->complete_code != GQL_VM_COMPLETE_LIST) { 0 181 181
13052 0 gql_runtime_vm_json_cat_scalar(aTHX_ state, out, value);
13053 0 return 0;
13054 }
13055 181 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 181 0 181
if (!value || !SvOK(value)) { 61 120 181
13056 61 sv_catpvs(out, "null");
13057 61 return 0;
13058 }
13059 120 ▶ if (!SvROK(value) || SvTYPE(SvRV(value)) != SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(value) || SvTYPE(SvRV(value)) != SVt_PVAV) { 117 3 120
if (!SvROK(value) || SvTYPE(SvRV(value)) != SVt_PVAV) { 0 117 117
13060 /* Non-list resolver result for a list field: field error + null,
13061 * matching the async lane (never croak the whole request). */
13062 3 gql_runtime_vm_path_frame_t *field_path = NULL;
13063 gql_runtime_vm_path_frame_t *error_path;
13064 3 SV *msg_sv = newSVpvs("list value must be an array reference");
13065 6 error_path = state->path_frame_is_current_field
13066 ? state->path_frame
13067 3 ▶ : (field_path = gql_runtime_vm_new_result_path_frame(aTHX_ state->path_frame, state->slot));
Branch: 1 branch
BranchTrueFalseTotal
: (field_path = gql_runtime_vm_new_result_path_frame(aTHX_ state->path_frame, state->slot)); 3 0 3
13068 3 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg_sv, error_path);
13069 3 SvREFCNT_dec(msg_sv);
13070 3 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 0 3 3
13071 0 gql_runtime_vm_path_frame_decref(field_path);
13072 }
13073 3 sv_catpvs(out, "null");
13074 3 state->null_carries_error = 1;
13075 3 return 0;
13076 }
13077 {
13078 117 AV *in_av = (AV *)SvRV(value);
13079 117 ▶ gql_runtime_vm_path_frame_t *saved_path_frame = state ? state->path_frame : NULL;
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_path_frame_t *saved_path_frame = state ? state->path_frame : NULL; 117 0 117
13080 117 gql_runtime_vm_path_frame_t *field_path = NULL;
13081 117 gql_runtime_vm_path_frame_t *base_path = NULL;
13082 117 int has_child_block = op->child_block_index >= 0;
13083 117 ▶ int has_abstract_items = (!has_child_block && op->abstract_child_count > 0);
Branch: 2 branches
BranchTrueFalseTotal
int has_abstract_items = (!has_child_block && op->abstract_child_count > 0); 23 94 117
int has_abstract_items = (!has_child_block && op->abstract_child_count > 0); 6 17 23
13084 117 STRLEN list_start = SvCUR(out);
13085 IV i;
13086  
13087 117 ▶ if (has_child_block || has_abstract_items) {
Branch: 2 branches
BranchTrueFalseTotal
if (has_child_block || has_abstract_items) { 23 94 117
if (has_child_block || has_abstract_items) { 6 17 23
13088 /* Base the per-item index frames on the field frame; when the
13089 * dispatch loop already pushed it (eager path) reuse that frame
13090 * instead of stacking a duplicate segment. */
13091 100 ▶ if (!state->path_frame_is_current_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->path_frame_is_current_field) { 0 100 100
13092 0 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot);
13093 0 state->path_frame = field_path;
13094 }
13095 100 base_path = state->path_frame;
13096 }
13097 117 sv_catpvs(out, "[");
13098 306 ▶ for (i = 0; i < (IV)av_count(in_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (IV)av_count(in_av); i++) { 195 111 306
13099 195 SV **item_svp = av_fetch(in_av, i, 0);
13100 195 ▶ SV *item = (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *item = (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef; 195 0 195
SV *item = (item_svp && SvOK(*item_svp)) ? *item_svp : &PL_sv_undef; 182 13 195
13101 195 gql_runtime_vm_path_frame_t *item_path = NULL;
13102 STRLEN item_start;
13103 195 int item_had_error = 0;
13104 195 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 132 63 195
13105 132 sv_catpvs(out, ",");
13106 }
13107 195 item_start = SvCUR(out);
13108 195 ▶ if (gql_runtime_vm_sv_is_adapter_promise(
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_is_adapter_promise( 4 191 195
13109 195 aTHX_ state->runtime->async_adapter, item
13110 )) {
13111 /* Promise list item on the sync lane: complete it as null and
13112 * record the deferred croak; the top-level entry raises it after
13113 * cleanup. The item SV is borrowed from the resolver's array,
13114 * so no decref. */
13115 4 ▶ if (!state->fast_lane_deferred_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->fast_lane_deferred_croak_sv) { 2 2 4
13116 2 state->fast_lane_deferred_croak_sv =
13117 2 newSVpv(GQL_RUNTIME_VM_FAST_LANE_PROMISE_ERROR, 0);
13118 }
13119 4 item = &PL_sv_undef;
13120 }
13121 195 ▶ if (base_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (base_path) { 153 42 195
13122 153 SV *item_key = newSViv(i);
13123 153 item_path = gql_runtime_vm_new_path_frame_struct(aTHX_ base_path, item_key);
13124 153 SvREFCNT_dec(item_key);
13125 153 state->path_frame = item_path;
13126 }
13127 204 ▶ if (has_abstract_items && SvOK(item)) {
Branch: 2 branches
BranchTrueFalseTotal
if (has_abstract_items && SvOK(item)) { 12 183 195
if (has_abstract_items && SvOK(item)) { 9 3 12
13128 /* List of an interface/union: pick the member block per item. */
13129 9 SV *sel_error = NULL;
13130 9 IV item_block_index = gql_runtime_vm_select_abstract_child_block_fast(
13131 aTHX_ state, item, &sel_error
13132 );
13133 9 ▶ if (sel_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (sel_error) { 3 6 9
13134 /* Unresolvable member type: field error + null item. */
13135 3 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, sel_error, item_path);
13136 3 SvREFCNT_dec(sel_error);
13137 3 sv_catpvs(out, "null");
13138 3 item_had_error = 1;
13139 6 ▶ } else if (item_block_index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (item_block_index >= 0) { 6 0 6
13140 6 ▶ if (gql_runtime_vm_execute_block_fast_json(aTHX_ state, item_block_index, item, out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_execute_block_fast_json(aTHX_ state, item_block_index, item, out)) { 0 6 6
13141 0 sv_catpvs(out, "null");
13142 0 item_had_error = 1;
13143 }
13144 } else {
13145 0 sv_catpvs(out, "null");
13146 }
13147 186 ▶ } else if (has_abstract_items) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (has_abstract_items) { 3 183 186
13148 3 sv_catpvs(out, "null");
13149 183 ▶ } else if (has_child_block && SvOK(item)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (has_child_block && SvOK(item)) { 141 42 183
} else if (has_child_block && SvOK(item)) { 136 5 141
13150 139 ▶ if (gql_runtime_vm_execute_block_fast_json(aTHX_ state, op->child_block_index, item, out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_execute_block_fast_json(aTHX_ state, op->child_block_index, item, out)) { 3 133 136
13151 3 sv_catpvs(out, "null");
13152 3 item_had_error = 1;
13153 }
13154 47 ▶ } else if (has_child_block) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (has_child_block) { 5 42 47
13155 5 sv_catpvs(out, "null");
13156 } else {
13157 /* Leaf list item: result coercion against the inner type before
13158 * serialization; a failure is a per-item field error + null. */
13159 42 SV *leaf_error = NULL;
13160 42 SV *serialized = gql_runtime_vm_serialize_leaf_sv(
13161 42 aTHX_ state->runtime, state->slot, item, &leaf_error
13162 );
13163 42 ▶ if (leaf_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_error) { 4 38 42
13164 4 gql_runtime_vm_path_frame_t *error_path = item_path;
13165 4 gql_runtime_vm_path_frame_t *lazy_field = NULL;
13166 4 gql_runtime_vm_path_frame_t *lazy_item = NULL;
13167 4 ▶ if (!error_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error_path) { 4 0 4
13168 4 SV *item_key = newSViv(i);
13169 8 lazy_field = state->path_frame_is_current_field
13170 ? NULL
13171 4 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot); 0 4 4
13172 4 ▶ lazy_item = gql_runtime_vm_new_path_frame_struct(
Branch: 1 branch
BranchTrueFalseTotal
lazy_item = gql_runtime_vm_new_path_frame_struct( 4 0 4
13173 aTHX_ lazy_field ? lazy_field : state->path_frame, item_key
13174 );
13175 4 SvREFCNT_dec(item_key);
13176 4 error_path = lazy_item;
13177 }
13178 4 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, leaf_error, error_path);
13179 4 SvREFCNT_dec(leaf_error);
13180 4 ▶ if (lazy_item) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_item) { 4 0 4
13181 4 gql_runtime_vm_path_frame_decref(lazy_item);
13182 }
13183 4 ▶ if (lazy_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_field) { 0 4 4
13184 0 gql_runtime_vm_path_frame_decref(lazy_field);
13185 }
13186 4 sv_catpvs(out, "null");
13187 4 item_had_error = 1;
13188 38 ▶ } else if (SvOK(serialized) && !SvROK(serialized)
Branch: 2 branches
BranchTrueFalseTotal
} else if (SvOK(serialized) && !SvROK(serialized) 29 9 38
} else if (SvOK(serialized) && !SvROK(serialized) 29 0 29
13189 29 ▶ && state->slot && state->slot->return_type_name
Branch: 2 branches
BranchTrueFalseTotal
&& state->slot && state->slot->return_type_name 29 0 29
&& state->slot && state->slot->return_type_name 29 0 29
13190 29 ▶ && strEQ(state->slot->return_type_name, "Boolean")) {
Branch: 1 branch
BranchTrueFalseTotal
&& strEQ(state->slot->return_type_name, "Boolean")) { 0 29 29
13191 0 ▶ sv_catpv(out, SvTRUE(serialized) ? "true" : "false");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, SvTRUE(serialized) ? "true" : "false"); 0 0 0
13192 } else {
13193 38 gql_runtime_vm_json_cat_scalar(aTHX_ state, out, serialized);
13194 }
13195 42 ▶ if (serialized) {
Branch: 1 branch
BranchTrueFalseTotal
if (serialized) { 38 4 42
13196 38 SvREFCNT_dec(serialized);
13197 }
13198 }
13199  
13200 /* Non-Null list items ([T!]): a null item nulls the whole list. */
13201 195 ▶ if (state->slot->item_non_null
Branch: 1 branch
BranchTrueFalseTotal
if (state->slot->item_non_null 139 56 195
13202 139 ▶ && SvCUR(out) - item_start == 4
Branch: 1 branch
BranchTrueFalseTotal
&& SvCUR(out) - item_start == 4 6 133 139
13203 6 ▶ && memEQ(SvPVX(out) + item_start, "null", 4)) {
Branch: 1 branch
BranchTrueFalseTotal
&& memEQ(SvPVX(out) + item_start, "null", 4)) { 6 0 6
13204 6 ▶ if (!item_had_error && !state->null_carries_error) {
Branch: 2 branches
BranchTrueFalseTotal
if (!item_had_error && !state->null_carries_error) { 3 3 6
if (!item_had_error && !state->null_carries_error) { 3 0 3
13205 3 ▶ SV *msg_sv = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
SV *msg_sv = newSVpvf( 3 0 3
SV *msg_sv = newSVpvf( 3 0 3
13206 "Cannot return null for non-nullable field %s.%s.",
13207 state->block->type_name ? state->block->type_name : "(unknown)",
13208 state->slot->field_name ? state->slot->field_name : "(unknown)"
13209 );
13210 3 gql_runtime_vm_path_frame_t *error_path = item_path;
13211 3 gql_runtime_vm_path_frame_t *lazy_field = NULL;
13212 3 gql_runtime_vm_path_frame_t *lazy_item = NULL;
13213 3 ▶ if (!error_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error_path) { 3 0 3
13214 3 SV *item_key = newSViv(i);
13215 6 lazy_field = state->path_frame_is_current_field
13216 ? NULL
13217 3 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, state->slot); 0 3 3
13218 3 ▶ lazy_item = gql_runtime_vm_new_path_frame_struct(
Branch: 1 branch
BranchTrueFalseTotal
lazy_item = gql_runtime_vm_new_path_frame_struct( 3 0 3
13219 aTHX_ lazy_field ? lazy_field : state->path_frame, item_key
13220 );
13221 3 SvREFCNT_dec(item_key);
13222 3 error_path = lazy_item;
13223 }
13224 3 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg_sv, error_path);
13225 3 SvREFCNT_dec(msg_sv);
13226 3 ▶ if (lazy_item) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_item) { 3 0 3
13227 3 gql_runtime_vm_path_frame_decref(lazy_item);
13228 }
13229 3 ▶ if (lazy_field) {
Branch: 1 branch
BranchTrueFalseTotal
if (lazy_field) { 0 3 3
13230 0 gql_runtime_vm_path_frame_decref(lazy_field);
13231 }
13232 }
13233 6 ▶ if (item_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (item_path) { 3 3 6
13234 3 state->path_frame = base_path;
13235 3 gql_runtime_vm_path_frame_decref(item_path);
13236 }
13237 6 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 0 6 6
13238 0 state->path_frame = saved_path_frame;
13239 0 gql_runtime_vm_path_frame_decref(field_path);
13240 }
13241 6 SvCUR_set(out, list_start);
13242 6 state->null_carries_error = 1;
13243 6 return 1;
13244 }
13245 189 state->null_carries_error = 0;
13246 189 ▶ if (item_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (item_path) { 150 39 189
13247 150 state->path_frame = base_path;
13248 150 gql_runtime_vm_path_frame_decref(item_path);
13249 }
13250 }
13251 111 sv_catpvs(out, "]");
13252 111 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 0 111 111
13253 0 state->path_frame = saved_path_frame;
13254 0 gql_runtime_vm_path_frame_decref(field_path);
13255 }
13256 }
13257 111 return 0;
13258 }
13259  
13260 static int
13261 354 gql_runtime_vm_execute_block_fast_json(pTHX_ gql_runtime_vm_exec_state_t *state, IV block_index, SV *source, SV *out)
13262 {
13263 gql_runtime_vm_native_block_t *block;
13264 IV i;
13265 354 STRLEN block_start = SvCUR(out);
13266 354 gql_runtime_vm_native_block_t *saved_block = (gql_runtime_vm_native_block_t *)state->block;
13267 354 const gql_runtime_vm_native_op_t *saved_op = state->op;
13268 354 const gql_runtime_vm_native_slot_t *saved_slot = state->slot;
13269 354 gql_runtime_vm_path_frame_t *saved_path_frame = state->path_frame;
13270 354 int saved_path_is_current_field = state->path_frame_is_current_field;
13271 354 IV saved_block_index = state->block_index;
13272 354 IV saved_op_index = state->op_index;
13273  
13274 354 ▶ if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) {
Branch: 3 branches
BranchTrueFalseTotal
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 354 0 354
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 354 0 354
if (!state->bundle || block_index < 0 || block_index >= state->bundle->block_count) { 0 354 354
13275 0 croak("native VM block index %ld is invalid", (long)block_index);
13276 }
13277  
13278 354 block = &state->bundle->blocks[block_index];
13279 354 state->block = block;
13280 354 state->block_index = block_index;
13281 354 sv_catpvs(out, "{");
13282  
13283 1548 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 1215 333 1548
13284 1215 gql_runtime_vm_native_op_t *op = &block->ops[i];
13285 gql_runtime_vm_native_slot_t *slot;
13286 1215 SV *resolved = NULL;
13287 1215 SV *error_sv = NULL;
13288 1215 gql_runtime_vm_outcome_t *error_outcome = NULL;
13289 1215 gql_runtime_vm_path_frame_t *field_path = NULL;
13290 int eager_path_frame;
13291 IV dispatch_index;
13292 IV family;
13293 STRLEN value_start;
13294  
13295 1215 ▶ if (op->slot_index < 0 || op->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 1215 0 1215
if (op->slot_index < 0 || op->slot_index >= block->slot_count) { 0 1215 1215
13296 0 croak("native VM op slot_index %ld is invalid in block %ld", (long)op->slot_index, (long)block_index);
13297 }
13298 1215 slot = &block->slots[op->slot_index];
13299 1215 state->op = op;
13300 1215 state->slot = slot;
13301 1215 state->op_index = i;
13302  
13303 1215 ▶ if (!gql_runtime_vm_should_execute_current_op_fast(aTHX_ state)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_should_execute_current_op_fast(aTHX_ state)) { 0 1215 1215
13304 0 continue;
13305 }
13306  
13307 1215 dispatch_index = gql_runtime_vm_dispatch_index_from_opcode(op->opcode_code);
13308 1215 ▶ if (dispatch_index < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (dispatch_index < 0) { 0 1215 1215
13309 0 croak("native VM opcode_code %ld is unsupported", (long)op->opcode_code);
13310 }
13311 1215 family = dispatch_index % 4;
13312  
13313 1215 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 861 354 1215
13314 861 sv_catpvs(out, ",");
13315 }
13316 1215 sv_catpvs(out, "\"");
13317 1215 sv_catpvn(out, slot->result_name, slot->result_name_len);
13318 1215 sv_catpvs(out, "\":");
13319 1215 value_start = SvCUR(out);
13320  
13321 1215 eager_path_frame = !gql_runtime_vm_slot_can_delay_field_path(state->runtime, slot, op);
13322 1215 ▶ if (eager_path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (eager_path_frame) { 922 293 1215
13323 922 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot);
13324 922 state->path_frame = field_path;
13325 922 state->path_frame_is_current_field = 1;
13326 } else {
13327 293 state->path_frame = saved_path_frame;
13328 293 state->path_frame_is_current_field = 0;
13329 }
13330  
13331 1215 resolved = (dispatch_index >= 4)
13332 922 ? gql_runtime_vm_resolve_current_field_explicit_fast_sv(aTHX_ state, source, &error_sv)
13333 1215 ▶ : gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_resolve_current_field_default_fast_sv(aTHX_ state, source, &error_sv); 922 293 1215
13334 1215 ▶ if (!error_sv && (op->has_runtime_directives || op->runtime_directives_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!error_sv && (op->has_runtime_directives || op->runtime_directives_sv)) { 1204 11 1215
if (!error_sv && (op->has_runtime_directives || op->runtime_directives_sv)) { 1204 0 1204
if (!error_sv && (op->has_runtime_directives || op->runtime_directives_sv)) { 0 1204 1204
13335 0 SV *applied = gql_runtime_vm_apply_runtime_directives_nonfatal(aTHX_ state, source, resolved, &error_sv);
13336 0 ▶ if (!error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error_sv) { 0 0 0
13337 0 SvREFCNT_dec(resolved);
13338 0 resolved = applied;
13339 0 ▶ } else if (applied) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (applied) { 0 0 0
13340 0 SvREFCNT_dec(applied);
13341 }
13342 }
13343  
13344 1215 ▶ if (!error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error_sv) { 1204 11 1215
13345 1204 switch (family) {
13346 816 case 0: /* GENERIC */
13347 {
13348 /* Leaf result coercion before serialization; a failure becomes
13349 * a field error + null via the shared error_sv tail. */
13350 816 SV *serialized = gql_runtime_vm_serialize_leaf_sv(
13351 816 aTHX_ state->runtime, slot, resolved, &error_sv
13352 );
13353 816 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 11 805 816
13354 /* The shared error tail records the field error and emits the
13355 * null for this field. */
13356 11 break;
13357 }
13358 805 ▶ if (serialized && SvOK(serialized) && !SvROK(serialized)
Branch: 3 branches
BranchTrueFalseTotal
if (serialized && SvOK(serialized) && !SvROK(serialized) 805 0 805
if (serialized && SvOK(serialized) && !SvROK(serialized) 564 241 805
if (serialized && SvOK(serialized) && !SvROK(serialized) 564 0 564
13359 564 ▶ && slot->return_type_name && strEQ(slot->return_type_name, "Boolean")) {
Branch: 2 branches
BranchTrueFalseTotal
&& slot->return_type_name && strEQ(slot->return_type_name, "Boolean")) { 564 0 564
&& slot->return_type_name && strEQ(slot->return_type_name, "Boolean")) { 97 467 564
13360 /* Boolean-typed leaves serialize as JSON booleans even when the
13361 * resolver returned a plain 0/1. */
13362 97 ▶ sv_catpv(out, SvTRUE(serialized) ? "true" : "false");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, SvTRUE(serialized) ? "true" : "false"); 4 93 97
13363 } else {
13364 708 gql_runtime_vm_json_cat_scalar(aTHX_ state, out, serialized);
13365 }
13366 805 SvREFCNT_dec(serialized);
13367 805 break;
13368 }
13369 200 case 1: /* OBJECT */
13370 200 ▶ if (resolved && SvOK(resolved) && op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) {
Branch: 4 branches
BranchTrueFalseTotal
if (resolved && SvOK(resolved) && op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) { 200 0 200
if (resolved && SvOK(resolved) && op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) { 131 69 200
if (resolved && SvOK(resolved) && op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) { 131 0 131
if (resolved && SvOK(resolved) && op->complete_code == GQL_VM_COMPLETE_OBJECT && op->child_block_index >= 0) { 131 0 131
13371 146 ▶ if (gql_runtime_vm_execute_child_block_fast_json(aTHX_ state, op->child_block_index, resolved, out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_execute_child_block_fast_json(aTHX_ state, op->child_block_index, resolved, out)) { 15 116 131
13372 15 sv_catpvs(out, "null");
13373 }
13374 69 ▶ } else if (resolved && SvOK(resolved)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (resolved && SvOK(resolved)) { 69 0 69
} else if (resolved && SvOK(resolved)) { 0 69 69
13375 0 gql_runtime_vm_json_cat_scalar(aTHX_ state, out, resolved);
13376 } else {
13377 69 sv_catpvs(out, "null");
13378 }
13379 200 break;
13380 181 case 2: /* LIST */
13381 181 ▶ if (gql_runtime_vm_complete_current_list_fast_json(aTHX_ state, resolved, out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_complete_current_list_fast_json(aTHX_ state, resolved, out)) { 6 175 181
13382 6 sv_catpvs(out, "null");
13383 }
13384 181 break;
13385 7 case 3: /* ABSTRACT */
13386 default:
13387 7 ▶ if (!resolved || !SvOK(resolved)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!resolved || !SvOK(resolved)) { 7 0 7
if (!resolved || !SvOK(resolved)) { 3 4 7
13388 3 sv_catpvs(out, "null");
13389 } else {
13390 4 IV abstract_child_block_index = gql_runtime_vm_select_abstract_child_block_fast(
13391 aTHX_ state, resolved, &error_sv
13392 );
13393 4 ▶ if (!error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!error_sv) { 1 3 4
13394 1 ▶ if (abstract_child_block_index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (abstract_child_block_index >= 0) { 1 0 1
13395 1 ▶ if (gql_runtime_vm_execute_child_block_fast_json(aTHX_ state, abstract_child_block_index, resolved, out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_execute_child_block_fast_json(aTHX_ state, abstract_child_block_index, resolved, out)) { 0 1 1
13396 0 sv_catpvs(out, "null");
13397 }
13398 } else {
13399 0 sv_catpvs(out, "null");
13400 }
13401 }
13402 }
13403 7 break;
13404 }
13405 }
13406  
13407 1215 state->path_frame = saved_path_frame;
13408 1215 state->path_frame_is_current_field = saved_path_is_current_field;
13409  
13410 1215 ▶ if (error_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_sv) { 25 1190 1215
13411 25 ▶ if (!eager_path_frame && !field_path) {
Branch: 2 branches
BranchTrueFalseTotal
if (!eager_path_frame && !field_path) { 0 25 25
if (!eager_path_frame && !field_path) { 0 0 0
13412 0 field_path = gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot);
13413 }
13414 25 error_outcome = gql_runtime_vm_new_error_outcome_struct_for_path(aTHX_ error_sv, field_path);
13415 25 SvREFCNT_dec(error_sv);
13416 25 error_sv = NULL;
13417 }
13418 1215 ▶ if (error_outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_outcome) { 25 1190 1215
13419 25 ▶ if (state->writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->writer) { 25 0 25
13420 IV j;
13421 50 ▶ for (j = 0; j < error_outcome->error_record_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < error_outcome->error_record_count; j++) { 25 25 50
13422 25 gql_runtime_vm_writer_push_error_record(state->writer, error_outcome->error_records[j]);
13423 }
13424 }
13425 25 gql_runtime_vm_outcome_decref(aTHX_ error_outcome);
13426 25 error_outcome = NULL;
13427 25 sv_catpvs(out, "null");
13428 /* The null just emitted carries this field error. */
13429 25 state->null_carries_error = 1;
13430 }
13431 1215 ▶ if (resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolved) { 1215 0 1215
13432 1215 SvREFCNT_dec(resolved);
13433 1215 resolved = NULL;
13434 }
13435  
13436 /* Non-Null propagation (spec 6.4.4): a null value in a non-null
13437 * position nulls this block. The emitted value region being exactly
13438 * the token "null" identifies a null field value. */
13439 1215 ▶ if (slot->return_type_kind_code == 8
Branch: 1 branch
BranchTrueFalseTotal
if (slot->return_type_kind_code == 8 454 761 1215
13440 454 ▶ && SvCUR(out) - value_start == 4
Branch: 1 branch
BranchTrueFalseTotal
&& SvCUR(out) - value_start == 4 25 429 454
13441 25 ▶ && memEQ(SvPVX(out) + value_start, "null", 4)) {
Branch: 1 branch
BranchTrueFalseTotal
&& memEQ(SvPVX(out) + value_start, "null", 4)) { 21 4 25
13442 21 ▶ if (!state->null_carries_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (!state->null_carries_error) { 12 9 21
13443 12 ▶ SV *msg_sv = newSVpvf(
Branch: 2 branches
BranchTrueFalseTotal
SV *msg_sv = newSVpvf( 12 0 12
SV *msg_sv = newSVpvf( 12 0 12
13444 "Cannot return null for non-nullable field %s.%s.",
13445 block->type_name ? block->type_name : "(unknown)",
13446 slot->field_name ? slot->field_name : "(unknown)"
13447 );
13448 12 gql_runtime_vm_path_frame_t *error_path = field_path
13449 ? field_path
13450 12 ▶ : gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_new_result_path_frame(aTHX_ saved_path_frame, slot); 0 12 12
13451 12 gql_runtime_vm_fast_lane_record_error_for_path(aTHX_ state, msg_sv, error_path);
13452 12 SvREFCNT_dec(msg_sv);
13453 12 ▶ if (error_path != field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_path != field_path) { 0 12 12
13454 0 gql_runtime_vm_path_frame_decref(error_path);
13455 }
13456 }
13457 21 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 21 0 21
13458 21 gql_runtime_vm_path_frame_decref(field_path);
13459 }
13460 21 SvCUR_set(out, block_start);
13461 21 state->block = saved_block;
13462 21 state->op = saved_op;
13463 21 state->slot = saved_slot;
13464 21 state->path_frame = saved_path_frame;
13465 21 state->path_frame_is_current_field = saved_path_is_current_field;
13466 21 state->block_index = saved_block_index;
13467 21 state->op_index = saved_op_index;
13468 21 state->null_carries_error = 1;
13469 21 return 1;
13470 }
13471 1194 state->null_carries_error = 0;
13472  
13473 1194 ▶ if (field_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (field_path) { 901 293 1194
13474 901 gql_runtime_vm_path_frame_decref(field_path);
13475 901 field_path = NULL;
13476 }
13477 }
13478  
13479 333 sv_catpvs(out, "}");
13480  
13481 333 state->block = saved_block;
13482 333 state->op = saved_op;
13483 333 state->slot = saved_slot;
13484 333 state->path_frame = saved_path_frame;
13485 333 state->path_frame_is_current_field = saved_path_is_current_field;
13486 333 state->block_index = saved_block_index;
13487 333 state->op_index = saved_op_index;
13488 333 return 0;
13489 }
13490  
13491 static void
13492 39 gql_runtime_vm_json_cat_errors(pTHX_ SV *out, const gql_runtime_vm_writer_t *writer)
13493 {
13494 IV i;
13495  
13496 39 sv_catpvs(out, "[");
13497 91 ▶ for (i = 0; writer && i < writer->error_record_count; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; writer && i < writer->error_record_count; i++) { 91 0 91
for (i = 0; writer && i < writer->error_record_count; i++) { 52 39 91
13498 52 const gql_runtime_vm_error_record_t *record = writer->error_records[i];
13499 52 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 13 39 52
13500 13 sv_catpvs(out, ",");
13501 }
13502 52 sv_catpvs(out, "{\"message\":");
13503 52 ▶ if (record && record->message_pv) {
Branch: 2 branches
BranchTrueFalseTotal
if (record && record->message_pv) { 52 0 52
if (record && record->message_pv) { 52 0 52
13504 52 gql_runtime_vm_json_cat_string(aTHX_ out, record->message_pv, strlen(record->message_pv));
13505 } else {
13506 0 sv_catpvs(out, "null");
13507 }
13508 52 ▶ if (record && record->path_frame) {
Branch: 2 branches
BranchTrueFalseTotal
if (record && record->path_frame) { 52 0 52
if (record && record->path_frame) { 52 0 52
13509 52 SV *path_sv = gql_runtime_vm_path_frame_to_path_sv(aTHX_ record->path_frame);
13510 52 ▶ if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV
Branch: 4 branches
BranchTrueFalseTotal
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV 52 0 52
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV 52 0 52
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV 52 0 52
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV 52 0 52
13511 52 ▶ && av_count((AV *)SvRV(path_sv)) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
&& av_count((AV *)SvRV(path_sv)) > 0) { 52 0 52
13512 52 AV *path_av = (AV *)SvRV(path_sv);
13513 IV j;
13514 52 sv_catpvs(out, ",\"path\":[");
13515 147 ▶ for (j = 0; j < (IV)av_count(path_av); j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < (IV)av_count(path_av); j++) { 95 52 147
13516 95 SV **item_svp = av_fetch(path_av, j, 0);
13517 95 ▶ if (j) {
Branch: 1 branch
BranchTrueFalseTotal
if (j) { 43 52 95
13518 43 sv_catpvs(out, ",");
13519 }
13520 95 ▶ gql_runtime_vm_json_cat_scalar(aTHX_ NULL, out, item_svp ? *item_svp : NULL);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_json_cat_scalar(aTHX_ NULL, out, item_svp ? *item_svp : NULL); 95 0 95
13521 }
13522 52 sv_catpvs(out, "]");
13523 }
13524 52 ▶ if (path_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (path_sv) { 52 0 52
13525 52 SvREFCNT_dec(path_sv);
13526 }
13527 }
13528 52 sv_catpvs(out, "}");
13529 }
13530 39 sv_catpvs(out, "]");
13531 39 }
13532  
13533 /*
13534 * Async direct-JSON tail: serialize a completed native value tree (the
13535 * response frame's values at resolve time) straight to JSON bytes. The
13536 * native tree preserves insertion order, so sync-resolved fields appear
13537 * first and late-resolved fields follow in completion order (JSON object
13538 * member order carries no meaning). Scalars carry no GraphQL type info, so
13539 * Boolean-typed leaves render as the resolver returned them (0/1),
13540 * matching execute() + JSON encode of the async envelope.
13541 */
13542 static void
13543 57 gql_runtime_vm_native_value_cat_json(pTHX_ SV *out, const gql_runtime_vm_native_value_t *value)
13544 {
13545 IV i;
13546  
13547 57 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 57 57
13548 0 sv_catpvs(out, "null");
13549 0 return;
13550 }
13551 57 switch (value->kind_code) {
13552 28 case GQL_VM_NATIVE_VALUE_OBJECT:
13553 28 sv_catpvs(out, "{");
13554 70 ▶ for (i = 0; i < value->object.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object.count; i++) { 42 28 70
13555 42 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 14 28 42
13556 14 sv_catpvs(out, ",");
13557 }
13558 42 gql_runtime_vm_json_cat_string(
13559 aTHX_ out,
13560 42 ▶ value->object.names[i] ? value->object.names[i] : "",
Branch: 1 branch
BranchTrueFalseTotal
value->object.names[i] ? value->object.names[i] : "", 42 0 42
13561 42 ▶ value->object.names[i] ? strlen(value->object.names[i]) : 0
Branch: 1 branch
BranchTrueFalseTotal
value->object.names[i] ? strlen(value->object.names[i]) : 0 42 0 42
13562 );
13563 42 sv_catpvs(out, ":");
13564 42 gql_runtime_vm_native_value_cat_json(aTHX_ out, value->object.values[i]);
13565 }
13566 28 sv_catpvs(out, "}");
13567 28 return;
13568 1 case GQL_VM_NATIVE_VALUE_LIST:
13569 1 sv_catpvs(out, "[");
13570 3 ▶ for (i = 0; i < value->list.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list.count; i++) { 2 1 3
13571 2 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 1 1 2
13572 1 sv_catpvs(out, ",");
13573 }
13574 2 gql_runtime_vm_native_value_cat_json(aTHX_ out, value->list.items[i]);
13575 }
13576 1 sv_catpvs(out, "]");
13577 1 return;
13578 28 case GQL_VM_NATIVE_VALUE_SCALAR:
13579 default:
13580 28 switch (value->scalar_kind_code) {
13581 1 case GQL_VM_NATIVE_SCALAR_UNDEF:
13582 1 sv_catpvs(out, "null");
13583 1 return;
13584 4 case GQL_VM_NATIVE_SCALAR_IV:
13585 4 sv_catpvf(out, "%" IVdf, value->scalar_iv);
13586 4 return;
13587 0 case GQL_VM_NATIVE_SCALAR_NV:
13588 0 gql_runtime_vm_json_cat_nv(aTHX_ out, value->scalar_nv);
13589 0 return;
13590 23 case GQL_VM_NATIVE_SCALAR_PV:
13591 23 gql_runtime_vm_json_cat_string(
13592 aTHX_ out,
13593 23 value->scalar_pv ? value->scalar_pv : "",
13594 23 ▶ value->scalar_pv_len
Branch: 1 branch
BranchTrueFalseTotal
value->scalar_pv_len 23 0 23
13595 );
13596 23 return;
13597 0 case GQL_VM_NATIVE_SCALAR_FALLBACK_SV:
13598 default:
13599 0 gql_runtime_vm_json_cat_scalar(aTHX_ NULL, out, value->scalar_fallback_sv);
13600 0 return;
13601 }
13602 }
13603 }
13604  
13605 /* Materialized SV data (hash key order is not preserved, matching the
13606 * envelope execute() returns for the same request). */
13607 static void
13608 17 gql_runtime_vm_json_cat_sv_data(pTHX_ SV *out, SV *value)
13609 {
13610 17 ▶ if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV && !SvOBJECT(SvRV(value))) {
Branch: 4 branches
BranchTrueFalseTotal
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV && !SvOBJECT(SvRV(value))) { 17 0 17
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV && !SvOBJECT(SvRV(value))) { 8 9 17
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV && !SvOBJECT(SvRV(value))) { 8 0 8
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV && !SvOBJECT(SvRV(value))) { 8 0 8
13611 8 HV *hv = (HV *)SvRV(value);
13612 HE *he;
13613 8 int first = 1;
13614  
13615 8 sv_catpvs(out, "{");
13616 8 hv_iterinit(hv);
13617 17 ▶ while ((he = hv_iternext(hv)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(hv)) != NULL) { 9 8 17
13618 9 SV *key_sv = hv_iterkeysv(he);
13619 9 STRLEN key_len = 0;
13620 9 const char *key_pv = SvPVutf8(key_sv, key_len);
13621  
13622 9 ▶ if (!first) {
Branch: 1 branch
BranchTrueFalseTotal
if (!first) { 1 8 9
13623 1 sv_catpvs(out, ",");
13624 }
13625 9 first = 0;
13626 9 gql_runtime_vm_json_cat_string(aTHX_ out, key_pv, key_len);
13627 9 sv_catpvs(out, ":");
13628 9 gql_runtime_vm_json_cat_sv_data(aTHX_ out, hv_iterval(hv, he));
13629 }
13630 8 sv_catpvs(out, "}");
13631 8 return;
13632 }
13633 9 ▶ if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV && !SvOBJECT(SvRV(value))) {
Branch: 4 branches
BranchTrueFalseTotal
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV && !SvOBJECT(SvRV(value))) { 9 0 9
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV && !SvOBJECT(SvRV(value))) { 0 9 9
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV && !SvOBJECT(SvRV(value))) { 0 0 0
if (value && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV && !SvOBJECT(SvRV(value))) { 0 0 0
13634 0 AV *av = (AV *)SvRV(value);
13635 SSize_t i;
13636  
13637 0 sv_catpvs(out, "[");
13638 0 ▶ for (i = 0; i < (IV)av_count(av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < (IV)av_count(av); i++) { 0 0 0
13639 0 SV **svp = av_fetch(av, i, 0);
13640 0 ▶ if (i) {
Branch: 1 branch
BranchTrueFalseTotal
if (i) { 0 0 0
13641 0 sv_catpvs(out, ",");
13642 }
13643 0 ▶ gql_runtime_vm_json_cat_sv_data(aTHX_ out, (svp && *svp) ? *svp : NULL);
Branch: 2 branches
BranchTrueFalseTotal
gql_runtime_vm_json_cat_sv_data(aTHX_ out, (svp && *svp) ? *svp : NULL); 0 0 0
gql_runtime_vm_json_cat_sv_data(aTHX_ out, (svp && *svp) ? *svp : NULL); 0 0 0
13644 }
13645 0 sv_catpvs(out, "]");
13646 0 return;
13647 }
13648 9 gql_runtime_vm_json_cat_scalar(aTHX_ NULL, out, value);
13649 }
13650  
13651 static SV *
13652 13 gql_runtime_vm_response_json_from_native_sv(pTHX_ const gql_runtime_vm_writer_t *writer, const gql_runtime_vm_native_value_t *value)
13653 {
13654 13 SV *out = newSV(1024);
13655  
13656 13 sv_setpvs(out, "{\"data\":");
13657 13 gql_runtime_vm_native_value_cat_json(aTHX_ out, value);
13658 13 ▶ if (writer && writer->error_record_count > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (writer && writer->error_record_count > 0) { 13 0 13
if (writer && writer->error_record_count > 0) { 1 12 13
13659 1 sv_catpvs(out, ",\"errors\":");
13660 1 gql_runtime_vm_json_cat_errors(aTHX_ out, writer);
13661 }
13662 13 sv_catpvs(out, "}");
13663 13 return out;
13664 }
13665  
13666 static SV *
13667 8 gql_runtime_vm_response_json_from_data_sv(pTHX_ const gql_runtime_vm_writer_t *writer, SV *data_sv)
13668 {
13669 8 SV *out = newSV(1024);
13670  
13671 8 sv_setpvs(out, "{\"data\":");
13672 8 gql_runtime_vm_json_cat_sv_data(aTHX_ out, data_sv);
13673 8 ▶ if (writer && writer->error_record_count > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (writer && writer->error_record_count > 0) { 8 0 8
if (writer && writer->error_record_count > 0) { 1 7 8
13674 1 sv_catpvs(out, ",\"errors\":");
13675 1 gql_runtime_vm_json_cat_errors(aTHX_ out, writer);
13676 }
13677 8 sv_catpvs(out, "}");
13678 8 return out;
13679 }
13680  
13681 static SV *
13682 80 gql_runtime_vm_execute_bundle_fast_response_json_with_slots(
13683 pTHX_
13684 gql_runtime_vm_native_runtime_t *runtime,
13685 SV *runtime_schema,
13686 gql_runtime_vm_native_bundle_t *bundle,
13687 SV *root_value,
13688 SV *context_value,
13689 SV *variables,
13690 SV **variable_slots,
13691 IV variable_slot_count,
13692 gql_runtime_vm_native_program_t *native_program,
13693 SV *provided_variables
13694 )
13695 {
13696 gql_runtime_vm_exec_state_t state;
13697 gql_runtime_vm_callback_context_t callback_ctx;
13698 gql_runtime_vm_writer_t writer_storage;
13699 SV *empty_args_sv;
13700 SV *out;
13701  
13702 80 Zero(&state, 1, gql_runtime_vm_exec_state_t);
13703 80 Zero(&callback_ctx, 1, gql_runtime_vm_callback_context_t);
13704  
13705 80 state.runtime = runtime;
13706 80 state.bundle = bundle;
13707 80 ▶ callback_ctx.runtime_schema = runtime_schema ? runtime_schema : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
callback_ctx.runtime_schema = runtime_schema ? runtime_schema : &PL_sv_undef; 80 0 80
13708 80 callback_ctx.root_value = root_value;
13709 80 callback_ctx.context = context_value;
13710 80 callback_ctx.variables = variables;
13711 80 callback_ctx.variable_slots = variable_slots;
13712 80 callback_ctx.variable_slot_count = variable_slot_count;
13713 80 callback_ctx.native_program = native_program;
13714 80 callback_ctx.provided_variables = provided_variables;
13715 80 state.callback_ctx = &callback_ctx;
13716 80 gql_runtime_vm_prepare_bundle_block_type_objects(aTHX_ callback_ctx.runtime_schema, bundle);
13717  
13718 80 gql_runtime_vm_init_writer_struct(&writer_storage);
13719 80 state.writer = &writer_storage;
13720 80 state.path_frame = NULL;
13721 80 empty_args_sv = gql_runtime_vm_empty_args_sv(aTHX);
13722 80 state.empty_args_sv = empty_args_sv;
13723  
13724 80 out = newSV(1024);
13725 80 sv_setpvs(out, "{\"data\":");
13726  
13727 80 ▶ if (gql_runtime_vm_execute_block_fast_json(
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_execute_block_fast_json( 3 77 80
13728 aTHX_
13729 &state,
13730 bundle->root_block_index,
13731 root_value,
13732 out
13733 )) {
13734 /* Non-null propagation reached the root: data is null. */
13735 3 sv_catpvs(out, "null");
13736 }
13737  
13738 80 ▶ if (writer_storage.error_record_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (writer_storage.error_record_count > 0) { 37 43 80
13739 37 sv_catpvs(out, ",\"errors\":");
13740 37 gql_runtime_vm_json_cat_errors(aTHX_ out, &writer_storage);
13741 }
13742 80 sv_catpvs(out, "}");
13743  
13744 80 SvREFCNT_dec(empty_args_sv);
13745 80 gql_runtime_vm_clear_writer_struct(aTHX_ &writer_storage);
13746 80 SvREFCNT_dec(callback_ctx.materialized_variables);
13747 80 ▶ if (state.fast_lane_deferred_croak_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (state.fast_lane_deferred_croak_sv) { 9 71 80
13748 /* Deferred from mid-lane so the path frame chain unwound normally. */
13749 9 SvREFCNT_dec(out);
13750 9 croak_sv(sv_2mortal(state.fast_lane_deferred_croak_sv));
13751 }
13752 71 return out;
13753 }
13754  
13755 static SV *
13756 18 gql_runtime_vm_execute_bundle_fast_response_json(
13757 pTHX_
13758 gql_runtime_vm_native_runtime_t *runtime,
13759 SV *runtime_schema,
13760 gql_runtime_vm_native_bundle_t *bundle,
13761 SV *root_value,
13762 SV *context_value,
13763 SV *variables
13764 )
13765 {
13766 18 return gql_runtime_vm_execute_bundle_fast_response_json_with_slots(
13767 aTHX_
13768 runtime,
13769 runtime_schema,
13770 bundle,
13771 root_value,
13772 context_value,
13773 variables,
13774 NULL,
13775 0,
13776 NULL,
13777 NULL
13778 );
13779 }
13780  
13781  
13782 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::XS::Parser
13783  
13784 SV *
13785 parse_xs(source, no_location = &PL_sv_undef)
13786 SV *source
13787 SV *no_location
13788 CODE:
13789 955 RETVAL = gql_parse_document(aTHX_ source, no_location);
13790 OUTPUT:
13791 RETVAL
13792  
13793 SV *
13794 _parse_with_diagnostics_xs(source)
13795 SV *source
13796 CODE:
13797 {
13798 59 AV *errors_av = newAV();
13799 59 AV *result_av = newAV();
13800 59 av_push(result_av, gql_parse_document_for_validation(
13801 aTHX_ source, &PL_sv_undef, errors_av
13802 ));
13803 58 av_push(result_av, newRV_noinc((SV *)errors_av));
13804 58 RETVAL = newRV_noinc((SV *)result_av);
13805 }
13806 OUTPUT:
13807 RETVAL
13808  
13809 SV *
13810 _materialize_arguments_xs(state, ptr)
13811 SV *state
13812 UV ptr
13813 CODE:
13814 {
13815 0 RETVAL = newRV_noinc((SV *)gql_parser_materialize_lazy_array(
13816 aTHX_ state,
13817 ptr,
13818 GQLJS_LAZY_ARRAY_ARGUMENTS
13819 ));
13820 }
13821 OUTPUT:
13822 RETVAL
13823  
13824 SV *
13825 _materialize_directives_xs(state, ptr)
13826 SV *state
13827 UV ptr
13828 CODE:
13829 {
13830 0 RETVAL = newRV_noinc((SV *)gql_parser_materialize_lazy_array(
13831 aTHX_ state,
13832 ptr,
13833 GQLJS_LAZY_ARRAY_DIRECTIVES
13834 ));
13835 }
13836 OUTPUT:
13837 RETVAL
13838  
13839 SV *
13840 _materialize_variable_definitions_xs(state, ptr)
13841 SV *state
13842 UV ptr
13843 CODE:
13844 {
13845 0 RETVAL = newRV_noinc((SV *)gql_parser_materialize_lazy_array(
13846 aTHX_ state,
13847 ptr,
13848 GQLJS_LAZY_ARRAY_VARIABLE_DEFINITIONS
13849 ));
13850 }
13851 OUTPUT:
13852 RETVAL
13853  
13854 SV *
13855 _materialize_object_fields_xs(state, ptr)
13856 SV *state
13857 UV ptr
13858 CODE:
13859 {
13860 0 RETVAL = newRV_noinc((SV *)gql_parser_materialize_lazy_array(
13861 aTHX_ state,
13862 ptr,
13863 GQLJS_LAZY_ARRAY_OBJECT_FIELDS
13864 ));
13865 }
13866 OUTPUT:
13867 RETVAL
13868  
13869 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::XS::LazyState
13870  
13871 void
13872 DESTROY(self)
13873 SV *self
13874 CODE:
13875 0 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 0 0 0
if (self && SvROK(self)) { 0 0 0
13876 0 SV *inner_sv = SvRV(self);
13877 0 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
13878 0 gql_parser_lazy_state_t *state = INT2PTR(gql_parser_lazy_state_t *, SvUV(inner_sv));
13879 0 sv_setuv(inner_sv, 0);
13880 0 gql_parser_lazy_state_destroy(state);
13881 }
13882 }
13883  
13884 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::XS::Parser
13885  
13886 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::XS::SchemaCompiler
13887  
13888 SV *
13889 compile_schema_xs(schema)
13890 SV *schema
13891 CODE:
13892 0 RETVAL = gql_schema_compile_schema(aTHX_ schema);
13893 OUTPUT:
13894 RETVAL
13895  
13896 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::XS::Validation
13897  
13898 SV *
13899 validate_xs(schema, document, options = NULL)
13900 SV *schema
13901 SV *document
13902 SV *options
13903 CODE:
13904 487 RETVAL = gql_validation_validate(aTHX_ schema, document, options);
13905 OUTPUT:
13906 RETVAL
13907  
13908 SV *
13909 check_cost_xs(schema, document, options)
13910 SV *schema
13911 SV *document
13912 SV *options
13913 CODE:
13914 447 RETVAL = gql_validation_check_cost(aTHX_ schema, document, options);
13915 OUTPUT:
13916 RETVAL
13917  
13918 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::XS::VM
13919  
13920 BOOT:
13921 {
13922 /* XS handle classes wrap raw C pointers; duplicating them across
13923 * ithreads would double-free. CLONE_SKIP makes ithread clones drop
13924 * them (become undef) instead. ithreads are otherwise unsupported. */
13925 static const char *const gql_handle_classes[] = {
13926 "GraphQL::Houtou::Runtime::ExecState",
13927 "GraphQL::Houtou::Runtime::Cursor",
13928 "GraphQL::Houtou::Runtime::Writer",
13929 "GraphQL::Houtou::Runtime::Outcome",
13930 "GraphQL::Houtou::Runtime::FieldFrame",
13931 "GraphQL::Houtou::Runtime::BlockFrame",
13932 "GraphQL::Houtou::Runtime::PathFrame",
13933 "GraphQL::Houtou::Runtime::ErrorRecord",
13934 "GraphQL::Houtou::Runtime::LazyInfo",
13935 "GraphQL::Houtou::Runtime::ListPending",
13936 "GraphQL::Houtou::Runtime::PendingMerge",
13937 "GraphQL::Houtou::Runtime::NativeProgram",
13938 "GraphQL::Houtou::Runtime::NativeBundle",
13939 "GraphQL::Houtou::Runtime::NativeRuntime",
13940 "GraphQL::Houtou::XS::LazyState",
13941 };
13942 size_t gql_handle_class_index;
13943 86 for (gql_handle_class_index = 0;
13944 1376 ▶ gql_handle_class_index < sizeof(gql_handle_classes) / sizeof(gql_handle_classes[0]);
Branch: 1 branch
BranchTrueFalseTotal
gql_handle_class_index < sizeof(gql_handle_classes) / sizeof(gql_handle_classes[0]); 1290 86 1376
13945 1290 gql_handle_class_index++) {
13946 1290 HV *stash = gv_stashpv(gql_handle_classes[gql_handle_class_index], GV_ADD);
13947 1290 newCONSTSUB(stash, "CLONE_SKIP", newSViv(1));
13948 }
13949 }
13950 86 ▶ if (!gql_runtime_vm_global_empty_args_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_global_empty_args_sv) { 86 0 86
13951 86 gql_runtime_vm_global_empty_args_sv = newRV_noinc((SV *)newHV());
13952 }
13953 86 ▶ if (!gql_runtime_vm_global_identity_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_global_identity_callback_sv) { 86 0 86
13954 86 CV *cv = get_cv("GraphQL::Houtou::XS::VM::identity_callback_xs", 0);
13955 86 ▶ if (cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (cv) { 86 0 86
13956 86 gql_runtime_vm_global_identity_callback_sv = newRV_inc((SV *)cv);
13957 }
13958 }
13959 86 ▶ if (!gql_runtime_vm_global_wrap_object_outcome_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_global_wrap_object_outcome_callback_sv) { 86 0 86
13960 86 CV *cv = get_cv("GraphQL::Houtou::XS::VM::wrap_object_outcome_callback_xs", 0);
13961 86 ▶ if (cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (cv) { 86 0 86
13962 86 gql_runtime_vm_global_wrap_object_outcome_callback_sv = newRV_inc((SV *)cv);
13963 }
13964 }
13965 86 ▶ if (!gql_runtime_vm_global_wrap_list_outcome_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_global_wrap_list_outcome_callback_sv) { 86 0 86
13966 86 CV *cv = get_cv("GraphQL::Houtou::XS::VM::wrap_list_outcome_callback_xs", 0);
13967 86 ▶ if (cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (cv) { 86 0 86
13968 86 gql_runtime_vm_global_wrap_list_outcome_callback_sv = newRV_inc((SV *)cv);
13969 }
13970 }
13971 86 ▶ if (!gql_runtime_vm_global_promise_xs_flatten_all_callback_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_global_promise_xs_flatten_all_callback_sv) { 86 0 86
13972 86 CV *cv = get_cv("GraphQL::Houtou::XS::VM::promise_xs_flatten_all_callback_xs", 0);
13973 86 ▶ if (cv) {
Branch: 1 branch
BranchTrueFalseTotal
if (cv) { 86 0 86
13974 86 gql_runtime_vm_global_promise_xs_flatten_all_callback_sv = newRV_inc((SV *)cv);
13975 }
13976 }
13977  
13978 SV *
13979 native_codes_xs()
13980 CODE:
13981 {
13982 2 HV *hv = newHV();
13983 2 hv_store(hv, "resolve_default", 15, newSViv(GQL_VM_RESOLVE_DEFAULT), 0);
13984 2 hv_store(hv, "resolve_explicit", 16, newSViv(GQL_VM_RESOLVE_EXPLICIT), 0);
13985 2 hv_store(hv, "complete_generic", 16, newSViv(GQL_VM_COMPLETE_GENERIC), 0);
13986 2 hv_store(hv, "complete_object", 15, newSViv(GQL_VM_COMPLETE_OBJECT), 0);
13987 2 hv_store(hv, "complete_list", 13, newSViv(GQL_VM_COMPLETE_LIST), 0);
13988 2 hv_store(hv, "complete_abstract", 17, newSViv(GQL_VM_COMPLETE_ABSTRACT), 0);
13989 2 hv_store(hv, "family_generic", 14, newSViv(GQL_VM_FAMILY_GENERIC), 0);
13990 2 hv_store(hv, "family_object", 13, newSViv(GQL_VM_FAMILY_OBJECT), 0);
13991 2 hv_store(hv, "family_list", 11, newSViv(GQL_VM_FAMILY_LIST), 0);
13992 2 hv_store(hv, "family_abstract", 15, newSViv(GQL_VM_FAMILY_ABSTRACT), 0);
13993 2 hv_store(hv, "dispatch_generic", 16, newSViv(GQL_VM_DISPATCH_GENERIC), 0);
13994 2 hv_store(hv, "dispatch_resolve_type", 21, newSViv(GQL_VM_DISPATCH_RESOLVE_TYPE), 0);
13995 2 hv_store(hv, "dispatch_tag", 12, newSViv(GQL_VM_DISPATCH_TAG), 0);
13996 2 hv_store(hv, "dispatch_possible_types", 23, newSViv(GQL_VM_DISPATCH_POSSIBLE_TYPES), 0);
13997 2 hv_store(hv, "kind_scalar", 11, newSViv(GQL_VM_KIND_SCALAR), 0);
13998 2 hv_store(hv, "kind_object", 11, newSViv(GQL_VM_KIND_OBJECT), 0);
13999 2 hv_store(hv, "kind_list", 9, newSViv(GQL_VM_KIND_LIST), 0);
14000 2 hv_store(hv, "kind_interface", 14, newSViv(GQL_VM_KIND_INTERFACE), 0);
14001 2 hv_store(hv, "kind_union", 10, newSViv(GQL_VM_KIND_UNION), 0);
14002 2 hv_store(hv, "kind_enum", 9, newSViv(GQL_VM_KIND_ENUM), 0);
14003 2 hv_store(hv, "kind_input_object", 17, newSViv(GQL_VM_KIND_INPUT_OBJECT), 0);
14004 2 hv_store(hv, "kind_non_null", 13, newSViv(GQL_VM_KIND_NON_NULL), 0);
14005 2 hv_store(hv, "optype_query", 12, newSViv(GQL_VM_OPTYPE_QUERY), 0);
14006 2 hv_store(hv, "optype_mutation", 15, newSViv(GQL_VM_OPTYPE_MUTATION), 0);
14007 2 hv_store(hv, "optype_subscription", 18, newSViv(GQL_VM_OPTYPE_SUBSCRIPTION), 0);
14008 2 RETVAL = newRV_noinc((SV *)hv);
14009 }
14010 OUTPUT:
14011 RETVAL
14012  
14013 void
14014 cancel_pending_response_xs(promise)
14015 SV *promise
14016 CODE:
14017 4 gql_runtime_vm_cancel_pending_response_sv(aTHX_ promise);
14018  
14019 int
14020 runtime_value_is_async_xs(runtime_sv, value)
14021 SV *runtime_sv
14022 SV *value
14023 CODE:
14024 {
14025 gql_runtime_vm_native_runtime_t *runtime;
14026 1501 ▶ if (!runtime_sv || !SvROK(runtime_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) 1501 0 1501
if (!runtime_sv || !SvROK(runtime_sv) 1501 0 1501
14027 1501 ▶ || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 1501 1501
14028 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
14029 }
14030 1501 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
14031 1501 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 1501 1501
14032 0 croak("native VM runtime handle is no longer valid");
14033 }
14034 1501 RETVAL = gql_runtime_vm_sv_is_adapter_promise(
14035 1501 aTHX_ runtime->async_adapter, value
14036 );
14037 }
14038 OUTPUT:
14039 RETVAL
14040  
14041 SV *
14042 runtime_then_async_xs(runtime_sv, promise, on_done, on_fail = &PL_sv_undef)
14043 SV *runtime_sv
14044 SV *promise
14045 SV *on_done
14046 SV *on_fail
14047 CODE:
14048 {
14049 gql_runtime_vm_native_runtime_t *runtime;
14050 24 ▶ if (!runtime_sv || !SvROK(runtime_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) 24 0 24
if (!runtime_sv || !SvROK(runtime_sv) 24 0 24
14051 24 ▶ || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 24 24
14052 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
14053 }
14054 24 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
14055 24 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 24 24
14056 0 croak("native VM runtime handle is no longer valid");
14057 }
14058 48 ▶ RETVAL = gql_runtime_vm_call_then_adapter_sv(
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = gql_runtime_vm_call_then_adapter_sv( 24 0 24
14059 aTHX_ runtime->async_adapter, promise, on_done,
14060 24 ▶ (on_fail && SvOK(on_fail)) ? on_fail : NULL, NULL
Branch: 1 branch
BranchTrueFalseTotal
(on_fail && SvOK(on_fail)) ? on_fail : NULL, NULL 6 18 24
14061 );
14062 24 ▶ if (RETVAL && SvOK(RETVAL) && gql_runtime_vm_sv_is_outcome(aTHX_ RETVAL)) {
Branch: 3 branches
BranchTrueFalseTotal
if (RETVAL && SvOK(RETVAL) && gql_runtime_vm_sv_is_outcome(aTHX_ RETVAL)) { 24 0 24
if (RETVAL && SvOK(RETVAL) && gql_runtime_vm_sv_is_outcome(aTHX_ RETVAL)) { 24 0 24
if (RETVAL && SvOK(RETVAL) && gql_runtime_vm_sv_is_outcome(aTHX_ RETVAL)) { 0 24 24
14063 0 SV *error_sv = gql_runtime_vm_adapter_error_sv(aTHX_ RETVAL);
14064 0 SvREFCNT_dec(RETVAL);
14065 0 croak_sv(sv_2mortal(error_sv));
14066 }
14067 }
14068 OUTPUT:
14069 RETVAL
14070  
14071 SV *
14072 debug_frame_live_counts_xs()
14073 CODE:
14074 {
14075 /* Leak instrumentation (R5): frames handed out minus frames released.
14076 * Both counts must be zero whenever no request is executing and no
14077 * promise is pending; a positive residue is an orphaned frame. */
14078 37 HV *hv = newHV();
14079 37 hv_store(hv, "block_frame", 11, newSViv(gql_runtime_vm_block_frame_live_count), 0);
14080 37 hv_store(hv, "path_frame", 10, newSViv(gql_runtime_vm_path_frame_live_count), 0);
14081 37 hv_store(hv, "lazy_info", 9, newSViv(gql_runtime_vm_lazy_info_live_count), 0);
14082 37 RETVAL = newRV_noinc((SV *)hv);
14083 }
14084 OUTPUT:
14085 RETVAL
14086  
14087 SV *
14088 load_native_bundle_xs(descriptor)
14089 SV *descriptor
14090 CODE:
14091 {
14092 gql_runtime_vm_native_bundle_t *bundle =
14093 27 gql_runtime_vm_native_bundle_from_sv(aTHX_ descriptor);
14094 27 SV *inner = newSVuv(PTR2UV(bundle));
14095 27 RETVAL = newRV_noinc(inner);
14096 27 sv_bless(RETVAL, gv_stashpv("GraphQL::Houtou::Runtime::NativeBundle", GV_ADD));
14097 }
14098 OUTPUT:
14099 RETVAL
14100  
14101 SV *
14102 load_native_bundle_parts_xs(runtime_descriptor, program_descriptor)
14103 SV *runtime_descriptor
14104 SV *program_descriptor
14105 CODE:
14106 {
14107 gql_runtime_vm_native_bundle_t *bundle =
14108 0 gql_runtime_vm_native_bundle_from_runtime_and_program_sv(
14109 aTHX_ runtime_descriptor, program_descriptor
14110 );
14111 0 SV *inner = newSVuv(PTR2UV(bundle));
14112 0 RETVAL = newRV_noinc(inner);
14113 0 sv_bless(RETVAL, gv_stashpv("GraphQL::Houtou::Runtime::NativeBundle", GV_ADD));
14114 }
14115 OUTPUT:
14116 RETVAL
14117  
14118 SV *
14119 native_bundle_summary_xs(bundle_sv)
14120 SV *bundle_sv
14121 CODE:
14122 {
14123 gql_runtime_vm_native_bundle_t *bundle;
14124 HV *hv;
14125 AV *dispatch_codes;
14126 IV i;
14127  
14128 1 ▶ if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 1 0 1
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 1 0 1
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 0 1 1
14129 0 croak("expected a GraphQL::Houtou::Runtime::NativeBundle");
14130 }
14131 1 bundle = INT2PTR(gql_runtime_vm_native_bundle_t *, SvUV(SvRV(bundle_sv)));
14132 1 ▶ if (!bundle) {
Branch: 1 branch
BranchTrueFalseTotal
if (!bundle) { 0 1 1
14133 0 croak("native VM bundle handle is no longer valid");
14134 }
14135  
14136 1 hv = newHV();
14137 1 hv_store(hv, "runtime_slot_count", 18, newSViv(bundle->runtime_slot_count), 0);
14138 1 hv_store(hv, "block_count", 11, newSViv(bundle->block_count), 0);
14139 1 hv_store(hv, "root_block_index", 16, newSViv(bundle->root_block_index), 0);
14140 1 hv_store(hv, "operation_type_code", 19, newSViv(bundle->operation_type_code), 0);
14141  
14142 1 ▶ if (bundle->root_block_index >= 0 && bundle->root_block_index < bundle->block_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (bundle->root_block_index >= 0 && bundle->root_block_index < bundle->block_count) { 1 0 1
if (bundle->root_block_index >= 0 && bundle->root_block_index < bundle->block_count) { 1 0 1
14143 1 gql_runtime_vm_native_block_t *root = &bundle->blocks[bundle->root_block_index];
14144 1 hv_store(hv, "root_family_code", 16, newSViv(root->family_code), 0);
14145 1 hv_store(hv, "root_slot_count", 15, newSViv(root->slot_count), 0);
14146 1 hv_store(hv, "root_op_count", 13, newSViv(root->op_count), 0);
14147  
14148 1 dispatch_codes = newAV();
14149 1 av_extend(dispatch_codes, root->op_count > 0 ? root->op_count - 1 : 0);
14150 3 ▶ for (i = 0; i < root->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < root->op_count; i++) { 2 1 3
14151 2 av_store(dispatch_codes, i, newSViv(root->ops[i].dispatch_family_code));
14152 }
14153 1 hv_store(hv, "root_dispatch_family_codes", 26, newRV_noinc((SV *)dispatch_codes), 0);
14154 }
14155  
14156 1 RETVAL = newRV_noinc((SV *)hv);
14157 }
14158 OUTPUT:
14159 RETVAL
14160  
14161 SV *
14162 load_native_program_xs(program_descriptor)
14163 SV *program_descriptor
14164 CODE:
14165 {
14166 gql_runtime_vm_native_program_t *program =
14167 439 gql_runtime_vm_native_program_from_sv(aTHX_ program_descriptor);
14168 439 SV *inner = newSVuv(PTR2UV(program));
14169 439 RETVAL = newRV_noinc(inner);
14170 439 sv_bless(RETVAL, gv_stashpv("GraphQL::Houtou::Runtime::NativeProgram", GV_ADD));
14171 }
14172 OUTPUT:
14173 RETVAL
14174  
14175 SV *
14176 native_program_descriptor_xs(program_sv)
14177 SV *program_sv
14178 CODE:
14179 {
14180 gql_runtime_vm_native_program_t *program =
14181 78 gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
14182 78 RETVAL = gql_runtime_vm_native_program_to_compact_sv(aTHX_ program);
14183 }
14184 OUTPUT:
14185 RETVAL
14186  
14187 SV *
14188 native_program_prepare_variables_xs(runtime_schema, program_sv, provided = &PL_sv_undef)
14189 SV *runtime_schema
14190 SV *program_sv
14191 SV *provided
14192 CODE:
14193 {
14194 gql_runtime_vm_native_program_t *program =
14195 41 gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
14196 41 HV *provided_hv = NULL;
14197 41 ▶ if (provided && SvOK(provided) && SvROK(provided) && SvTYPE(SvRV(provided)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (provided && SvOK(provided) && SvROK(provided) && SvTYPE(SvRV(provided)) == SVt_PVHV) { 41 0 41
if (provided && SvOK(provided) && SvROK(provided) && SvTYPE(SvRV(provided)) == SVt_PVHV) { 41 0 41
if (provided && SvOK(provided) && SvROK(provided) && SvTYPE(SvRV(provided)) == SVt_PVHV) { 41 0 41
if (provided && SvOK(provided) && SvROK(provided) && SvTYPE(SvRV(provided)) == SVt_PVHV) { 41 0 41
14198 41 provided_hv = (HV *)SvRV(provided);
14199 }
14200 41 RETVAL = gql_runtime_vm_prepare_program_variables_sv(
14201 aTHX_ runtime_schema,
14202 program,
14203 provided_hv
14204 );
14205 }
14206 OUTPUT:
14207 RETVAL
14208  
14209 IV
14210 native_program_root_block_index_xs(program_sv)
14211 SV *program_sv
14212 CODE:
14213 {
14214 gql_runtime_vm_native_program_t *program =
14215 0 gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
14216 0 ▶ RETVAL = program->root_block_index;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = program->root_block_index; 0 0 0
14217 }
14218 OUTPUT:
14219 RETVAL
14220  
14221 IV
14222 native_program_needs_variable_specialization_xs(program_sv)
14223 SV *program_sv
14224 CODE:
14225 {
14226 gql_runtime_vm_native_program_t *program =
14227 362 gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
14228 362 RETVAL = gql_runtime_vm_program_needs_variable_specialization(program);
14229 }
14230 OUTPUT:
14231 RETVAL
14232  
14233 SV *
14234 specialize_native_program_xs(runtime_sv, program_descriptor, variables = &PL_sv_undef)
14235 SV *runtime_sv
14236 SV *program_descriptor
14237 SV *variables
14238 CODE:
14239 {
14240 gql_runtime_vm_native_runtime_t *runtime;
14241 gql_runtime_vm_native_program_t *program;
14242 41 HV *variables_hv = NULL;
14243 SV *inner;
14244  
14245 41 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 41 0 41
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 41 0 41
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 41 41
14246 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
14247 }
14248 41 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
14249 41 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 41 41
14250 0 croak("native VM runtime handle is no longer valid");
14251 }
14252 41 ▶ if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 41 0 41
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 41 0 41
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 41 0 41
if (variables && SvOK(variables) && SvROK(variables) && SvTYPE(SvRV(variables)) == SVt_PVHV) { 41 0 41
14253 41 variables_hv = (HV *)SvRV(variables);
14254 }
14255  
14256 41 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_descriptor);
14257 41 ▶ if (program_descriptor && SvROK(program_descriptor) && sv_derived_from(program_descriptor, "GraphQL::Houtou::Runtime::NativeProgram")) {
Branch: 3 branches
BranchTrueFalseTotal
if (program_descriptor && SvROK(program_descriptor) && sv_derived_from(program_descriptor, "GraphQL::Houtou::Runtime::NativeProgram")) { 41 0 41
if (program_descriptor && SvROK(program_descriptor) && sv_derived_from(program_descriptor, "GraphQL::Houtou::Runtime::NativeProgram")) { 41 0 41
if (program_descriptor && SvROK(program_descriptor) && sv_derived_from(program_descriptor, "GraphQL::Houtou::Runtime::NativeProgram")) { 41 0 41
14258 41 program = gql_runtime_vm_clone_native_program(aTHX_ program);
14259 }
14260 41 gql_runtime_vm_specialize_native_program_in_place(aTHX_ runtime, program, variables_hv);
14261  
14262 41 inner = newSVuv(PTR2UV(program));
14263 41 RETVAL = newRV_noinc(inner);
14264 41 sv_bless(RETVAL, gv_stashpv("GraphQL::Houtou::Runtime::NativeProgram", GV_ADD));
14265 }
14266 OUTPUT:
14267 RETVAL
14268  
14269 SV *
14270 load_native_bundle_from_handles_xs(runtime_sv, program_sv)
14271 SV *runtime_sv
14272 SV *program_sv
14273 CODE:
14274 {
14275 gql_runtime_vm_native_runtime_t *runtime;
14276 gql_runtime_vm_native_program_t *program;
14277 gql_runtime_vm_native_bundle_t *bundle;
14278 1 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 1 0 1
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 1 0 1
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 1 1
14279 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
14280 }
14281 1 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
14282 1 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 1 1
14283 0 croak("native VM runtime handle is no longer valid");
14284 }
14285 1 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
14286 1 bundle = gql_runtime_vm_native_bundle_from_runtime_and_program_handles(runtime, program);
14287 1 SV *inner = newSVuv(PTR2UV(bundle));
14288 1 RETVAL = newRV_noinc(inner);
14289 1 sv_bless(RETVAL, gv_stashpv("GraphQL::Houtou::Runtime::NativeBundle", GV_ADD));
14290 }
14291 OUTPUT:
14292 RETVAL
14293  
14294 SV *
14295 native_program_summary_xs(program_sv)
14296 SV *program_sv
14297 CODE:
14298 {
14299 gql_runtime_vm_native_program_t *program;
14300 HV *hv;
14301 5 ▶ if (!program_sv || !SvROK(program_sv) || !sv_derived_from(program_sv, "GraphQL::Houtou::Runtime::NativeProgram")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!program_sv || !SvROK(program_sv) || !sv_derived_from(program_sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 5 0 5
if (!program_sv || !SvROK(program_sv) || !sv_derived_from(program_sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 5 0 5
if (!program_sv || !SvROK(program_sv) || !sv_derived_from(program_sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 0 5 5
14302 0 croak("expected a GraphQL::Houtou::Runtime::NativeProgram");
14303 }
14304 5 program = INT2PTR(gql_runtime_vm_native_program_t *, SvUV(SvRV(program_sv)));
14305 5 ▶ if (!program) {
Branch: 1 branch
BranchTrueFalseTotal
if (!program) { 0 5 5
14306 0 croak("native VM program handle is no longer valid");
14307 }
14308 5 hv = newHV();
14309 5 hv_store(hv, "block_count", 11, newSViv(program->block_count), 0);
14310 5 hv_store(hv, "root_block_index", 16, newSViv(program->root_block_index), 0);
14311 5 hv_store(hv, "operation_type_code", 19, newSViv(program->operation_type_code), 0);
14312 5 RETVAL = newRV_noinc((SV *)hv);
14313 }
14314 OUTPUT:
14315 RETVAL
14316  
14317 SV *
14318 load_native_runtime_xs(runtime_schema, adapter_spec = &PL_sv_undef)
14319 SV *runtime_schema
14320 SV *adapter_spec
14321 CODE:
14322 {
14323 gql_runtime_vm_native_runtime_t *runtime;
14324 gql_runtime_vm_native_runtime_guard_t guard;
14325 SV *inner;
14326 242 runtime = gql_runtime_vm_native_runtime_from_runtime_schema_sv(aTHX_ runtime_schema);
14327 242 guard.runtime = runtime;
14328 242 ENTER;
14329 242 SAVEDESTRUCTOR_X(gql_runtime_vm_native_runtime_guard_cleanup, &guard);
14330 242 runtime->async_adapter = gql_runtime_vm_async_adapter_from_spec_sv(aTHX_ adapter_spec);
14331 241 inner = newSVuv(PTR2UV(runtime));
14332 241 RETVAL = newRV_noinc(inner);
14333 241 sv_bless(RETVAL, gv_stashpv("GraphQL::Houtou::Runtime::NativeRuntime", GV_ADD));
14334 241 guard.runtime = NULL;
14335 241 LEAVE;
14336 }
14337 OUTPUT:
14338 RETVAL
14339  
14340 SV *
14341 native_runtime_summary_xs(runtime_sv)
14342 SV *runtime_sv
14343 CODE:
14344 {
14345 gql_runtime_vm_native_runtime_t *runtime;
14346 HV *hv;
14347  
14348 1 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 1 0 1
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 1 0 1
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 1 1
14349 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
14350 }
14351 1 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
14352 1 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 1 1
14353 0 croak("native VM runtime handle is no longer valid");
14354 }
14355  
14356 1 hv = newHV();
14357 1 hv_store(hv, "runtime_slot_count", 18, newSViv(runtime->runtime_slot_count), 0);
14358 1 ▶ hv_store(hv, "has_slot_type_objects", 21, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_type_objects ? 1 : 0), 0);
Branch: 2 branches
BranchTrueFalseTotal
hv_store(hv, "has_slot_type_objects", 21, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_type_objects ? 1 : 0), 0); 1 0 1
hv_store(hv, "has_slot_type_objects", 21, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_type_objects ? 1 : 0), 0); 1 0 1
14359 1 ▶ hv_store(hv, "has_tag_dispatch_tables", 23, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_tag_entries ? 1 : 0), 0);
Branch: 2 branches
BranchTrueFalseTotal
hv_store(hv, "has_tag_dispatch_tables", 23, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_tag_entries ? 1 : 0), 0); 1 0 1
hv_store(hv, "has_tag_dispatch_tables", 23, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_tag_entries ? 1 : 0), 0); 1 0 1
14360 1 ▶ hv_store(hv, "has_possible_type_entries", 25, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_possible_type_entries ? 1 : 0), 0);
Branch: 2 branches
BranchTrueFalseTotal
hv_store(hv, "has_possible_type_entries", 25, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_possible_type_entries ? 1 : 0), 0); 1 0 1
hv_store(hv, "has_possible_type_entries", 25, newSViv(runtime->callback_catalog && runtime->callback_catalog->slot_possible_type_entries ? 1 : 0), 0); 1 0 1
14361 1 RETVAL = newRV_noinc((SV *)hv);
14362 }
14363 OUTPUT:
14364 RETVAL
14365  
14366 int
14367 program_native_eligible_xs(program, has_promise = 0)
14368 SV *program
14369 int has_promise
14370 CODE:
14371 37 RETVAL = gql_runtime_vm_program_is_native_eligible_sv(aTHX_ program, has_promise);
14372 OUTPUT:
14373 RETVAL
14374  
14375 void
14376 resolve_runtime_type_xs(dispatch, runtime_cache, value, context, info, abstract_type)
14377 SV *dispatch
14378 SV *runtime_cache
14379 SV *value
14380 SV *context
14381 SV *info
14382 SV *abstract_type
14383 PPCODE:
14384 {
14385 0 SV *error = NULL;
14386 0 SV *runtime_type = gql_runtime_vm_resolve_runtime_type_sv(
14387 aTHX_ dispatch, runtime_cache, value, context, info, abstract_type, &error
14388 );
14389 0 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 0 0
14390 0 ▶ PUSHs(sv_2mortal(runtime_type ? runtime_type : newSV(0)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(sv_2mortal(runtime_type ? runtime_type : newSV(0))); 0 0 0
14391 0 ▶ PUSHs(sv_2mortal(error ? error : newSV(0)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(sv_2mortal(error ? error : newSV(0))); 0 0 0
14392 }
14393  
14394 void
14395 resolve_runtime_type_for_abstract_xs(runtime_cache, abstract_name, value, context, info, abstract_type)
14396 SV *runtime_cache
14397 SV *abstract_name
14398 SV *value
14399 SV *context
14400 SV *info
14401 SV *abstract_type
14402 PPCODE:
14403 {
14404 0 SV *error = NULL;
14405 0 STRLEN abstract_name_len = 0;
14406 0 ▶ const char *abstract_name_pv = (abstract_name && SvOK(abstract_name))
Branch: 1 branch
BranchTrueFalseTotal
const char *abstract_name_pv = (abstract_name && SvOK(abstract_name)) 0 0 0
14407 0 ? SvPV(abstract_name, abstract_name_len)
14408 0 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 0 0 0
14409 0 SV *runtime_type = gql_runtime_vm_resolve_runtime_type_for_abstract_sv(
14410 aTHX_ runtime_cache, abstract_name_pv, value, context, info, abstract_type, &error
14411 );
14412 0 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 0 0
14413 0 ▶ PUSHs(sv_2mortal(runtime_type ? runtime_type : newSV(0)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(sv_2mortal(runtime_type ? runtime_type : newSV(0))); 0 0 0
14414 0 ▶ PUSHs(sv_2mortal(error ? error : newSV(0)));
Branch: 1 branch
BranchTrueFalseTotal
PUSHs(sv_2mortal(error ? error : newSV(0))); 0 0 0
14415 }
14416  
14417 SV *
14418 outcome_scalar_xs(value, error_records = &PL_sv_undef)
14419 SV *value
14420 SV *error_records
14421 CODE:
14422 0 RETVAL = gql_runtime_vm_new_handle_sv(
14423 aTHX_
14424 "GraphQL::Houtou::Runtime::Outcome",
14425 0 gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_SCALAR, value, error_records)
14426 );
14427 OUTPUT:
14428 RETVAL
14429  
14430 SV *
14431 outcome_object_xs(value, error_records = &PL_sv_undef)
14432 SV *value
14433 SV *error_records
14434 CODE:
14435 0 RETVAL = gql_runtime_vm_new_handle_sv(
14436 aTHX_
14437 "GraphQL::Houtou::Runtime::Outcome",
14438 0 gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_OBJECT, value, error_records)
14439 );
14440 OUTPUT:
14441 RETVAL
14442  
14443 SV *
14444 outcome_list_xs(value, error_records = &PL_sv_undef)
14445 SV *value
14446 SV *error_records
14447 CODE:
14448 0 RETVAL = gql_runtime_vm_new_handle_sv(
14449 aTHX_
14450 "GraphQL::Houtou::Runtime::Outcome",
14451 0 gql_runtime_vm_new_outcome_struct(aTHX_ GQL_VM_KIND_LIST, value, error_records)
14452 );
14453 OUTPUT:
14454 RETVAL
14455  
14456 SV *
14457 wrap_object_outcome_callback_xs(...)
14458 CODE:
14459 {
14460 0 ▶ SV *value = items > 0 ? ST(0) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *value = items > 0 ? ST(0) : &PL_sv_undef; 0 0 0
14461 0 RETVAL = gql_runtime_vm_new_outcome_handle_sv(
14462 aTHX_
14463 GQL_VM_KIND_OBJECT,
14464 value,
14465 &PL_sv_undef
14466 );
14467 }
14468 OUTPUT:
14469 RETVAL
14470  
14471 SV *
14472 wrap_list_outcome_callback_xs(...)
14473 PREINIT:
14474 AV *resolved_av;
14475 I32 i;
14476 CODE:
14477 {
14478 0 resolved_av = newAV();
14479 0 ▶ if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
if (items == 1 && ST(0) && SvROK(ST(0)) && SvTYPE(SvRV(ST(0))) == SVt_PVAV) { 0 0 0
14480 0 AV *source_av = (AV *)SvRV(ST(0));
14481 0 SSize_t max = av_len(source_av);
14482 0 ▶ for (i = 0; i <= max; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= max; i++) { 0 0 0
14483 0 SV **svp = av_fetch(source_av, i, 0);
14484 0 ▶ av_push(resolved_av, newSVsv((svp && *svp) ? *svp : &PL_sv_undef));
Branch: 2 branches
BranchTrueFalseTotal
av_push(resolved_av, newSVsv((svp && *svp) ? *svp : &PL_sv_undef)); 0 0 0
av_push(resolved_av, newSVsv((svp && *svp) ? *svp : &PL_sv_undef)); 0 0 0
14485 }
14486 } else {
14487 0 ▶ for (i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) { 0 0 0
14488 0 ▶ av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef));
Branch: 1 branch
BranchTrueFalseTotal
av_push(resolved_av, newSVsv(ST(i) ? ST(i) : &PL_sv_undef)); 0 0 0
14489 }
14490 }
14491 {
14492 0 SV *list_sv = newRV_noinc((SV *)resolved_av);
14493 0 RETVAL = gql_runtime_vm_new_outcome_handle_sv(
14494 aTHX_
14495 GQL_VM_KIND_LIST,
14496 list_sv,
14497 &PL_sv_undef
14498 );
14499 0 SvREFCNT_dec(list_sv);
14500 }
14501 }
14502 OUTPUT:
14503 RETVAL
14504  
14505 SV *
14506 promise_xs_flatten_all_callback_xs(...)
14507 PREINIT:
14508 AV *flattened_av;
14509 I32 i;
14510 CODE:
14511 {
14512 0 flattened_av = newAV();
14513 0 ▶ for (i = 0; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) { 0 0 0
14514 0 ▶ SV *row_sv = ST(i) ? ST(i) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *row_sv = ST(i) ? ST(i) : &PL_sv_undef; 0 0 0
14515 0 ▶ if (row_sv && SvROK(row_sv) && SvTYPE(SvRV(row_sv)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
if (row_sv && SvROK(row_sv) && SvTYPE(SvRV(row_sv)) == SVt_PVAV) { 0 0 0
if (row_sv && SvROK(row_sv) && SvTYPE(SvRV(row_sv)) == SVt_PVAV) { 0 0 0
if (row_sv && SvROK(row_sv) && SvTYPE(SvRV(row_sv)) == SVt_PVAV) { 0 0 0
14516 0 AV *row_av = (AV *)SvRV(row_sv);
14517 0 ▶ if (av_len(row_av) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(row_av) == 0) { 0 0 0
14518 0 SV **item_svp = av_fetch(row_av, 0, 0);
14519 0 ▶ av_push(flattened_av, newSVsv((item_svp && *item_svp) ? *item_svp : &PL_sv_undef));
Branch: 2 branches
BranchTrueFalseTotal
av_push(flattened_av, newSVsv((item_svp && *item_svp) ? *item_svp : &PL_sv_undef)); 0 0 0
av_push(flattened_av, newSVsv((item_svp && *item_svp) ? *item_svp : &PL_sv_undef)); 0 0 0
14520 } else {
14521 0 av_push(flattened_av, newSVsv(row_sv));
14522 }
14523 } else {
14524 0 av_push(flattened_av, newSVsv(row_sv));
14525 }
14526 }
14527 0 RETVAL = newRV_noinc((SV *)flattened_av);
14528 }
14529 OUTPUT:
14530 RETVAL
14531  
14532 SV *
14533 identity_callback_xs(...)
14534 CODE:
14535 {
14536 0 ▶ SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 0 0 0
SV *resolved_sv = items > 0 && ST(0) ? ST(0) : &PL_sv_undef; 0 0 0
14537 0 SvREFCNT_inc_simple_NN(resolved_sv);
14538 0 RETVAL = resolved_sv;
14539 }
14540 OUTPUT:
14541 RETVAL
14542  
14543 SV *
14544 writer_new_xs(class)
14545 SV *class
14546 CODE:
14547 PERL_UNUSED_ARG(class);
14548 0 RETVAL = gql_runtime_vm_new_handle_sv(
14549 aTHX_
14550 "GraphQL::Houtou::Runtime::Writer",
14551 0 gql_runtime_vm_new_writer_struct(aTHX)
14552 );
14553 OUTPUT:
14554 RETVAL
14555  
14556 void
14557 consume_outcome_xs(writer, data, result_name, outcome)
14558 SV *writer
14559 SV *data
14560 SV *result_name
14561 SV *outcome
14562 PPCODE:
14563 {
14564 0 HV *data_hv = NULL;
14565 0 gql_runtime_vm_writer_t *writer_state = gql_runtime_vm_expect_writer(aTHX_ writer);
14566 0 gql_runtime_vm_outcome_t *outcome_state = gql_runtime_vm_expect_outcome(aTHX_ outcome);
14567 0 ▶ if (data && SvOK(data) && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (data && SvOK(data) && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) { 0 0 0
if (data && SvOK(data) && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) { 0 0 0
if (data && SvOK(data) && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) { 0 0 0
if (data && SvOK(data) && SvROK(data) && SvTYPE(SvRV(data)) == SVt_PVHV) { 0 0 0
14568 0 data_hv = (HV *)SvRV(data);
14569 }
14570 0 gql_runtime_vm_consume_outcome_struct(aTHX_ data_hv, result_name, outcome_state, writer_state);
14571 }
14572  
14573 SV *
14574 outcome_kind_xs(outcome)
14575 SV *outcome
14576 CODE:
14577 0 RETVAL = gql_runtime_vm_outcome_kind_sv(aTHX_ gql_runtime_vm_expect_outcome(aTHX_ outcome));
14578 OUTPUT:
14579 RETVAL
14580  
14581 SV *
14582 outcome_value_xs(outcome)
14583 SV *outcome
14584 CODE:
14585 {
14586 0 gql_runtime_vm_outcome_t *state = gql_runtime_vm_expect_outcome(aTHX_ outcome);
14587 0 ▶ RETVAL = state->value ? gql_runtime_vm_native_value_materialize_sv(aTHX_ state->value) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = state->value ? gql_runtime_vm_native_value_materialize_sv(aTHX_ state->value) : newSV(0); 0 0 0
14588 }
14589 OUTPUT:
14590 RETVAL
14591  
14592 SV *
14593 outcome_error_records_xs(outcome)
14594 SV *outcome
14595 CODE:
14596 {
14597 0 gql_runtime_vm_outcome_t *state = gql_runtime_vm_expect_outcome(aTHX_ outcome);
14598 0 AV *ret = newAV();
14599 IV i;
14600 0 ▶ for (i = 0; i < state->error_record_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < state->error_record_count; i++) { 0 0 0
14601 0 gql_runtime_vm_error_record_incref(state->error_records[i]);
14602 0 av_push(ret, gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::ErrorRecord", state->error_records[i]));
14603 }
14604 0 RETVAL = newRV_noinc((SV *)ret);
14605 }
14606 OUTPUT:
14607 RETVAL
14608  
14609 SV *
14610 writer_error_records_xs(writer)
14611 SV *writer
14612 CODE:
14613 {
14614 0 gql_runtime_vm_writer_t *state = gql_runtime_vm_expect_writer(aTHX_ writer);
14615 0 AV *ret = newAV();
14616 IV i;
14617 0 ▶ for (i = 0; i < state->error_record_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < state->error_record_count; i++) { 0 0 0
14618 0 gql_runtime_vm_error_record_incref(state->error_records[i]);
14619 0 av_push(ret, gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::ErrorRecord", state->error_records[i]));
14620 }
14621 0 RETVAL = newRV_noinc((SV *)ret);
14622 }
14623 OUTPUT:
14624 RETVAL
14625  
14626 SV *
14627 cursor_new_xs(class, block, native_program = &PL_sv_undef, block_index = -1, slot_index = 0, op_index = 0, current_slot = &PL_sv_undef, current_op = &PL_sv_undef)
14628 SV *class
14629 SV *block
14630 SV *native_program
14631 IV block_index
14632 IV slot_index
14633 IV op_index
14634 SV *current_slot
14635 SV *current_op
14636 CODE:
14637 {
14638 gql_runtime_vm_cursor_t *cursor;
14639 0 const char *pkg = SvPV_nolen(class);
14640 (void)current_slot;
14641 (void)current_op;
14642 0 Newxz(cursor, 1, gql_runtime_vm_cursor_t);
14643 0 cursor->refcount = 1;
14644 0 ▶ cursor->native_program = (native_program && SvOK(native_program))
Branch: 1 branch
BranchTrueFalseTotal
cursor->native_program = (native_program && SvOK(native_program)) 0 0 0
14645 0 ? gql_runtime_vm_native_program_from_sv(aTHX_ native_program)
14646 0 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 0 0 0
14647 0 ▶ if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) {
Branch: 5 branches
BranchTrueFalseTotal
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
14648 0 block_index = SvIV(block);
14649 }
14650 0 cursor->block_index = block_index;
14651 (void)block;
14652 0 cursor->slot_index = slot_index;
14653 0 cursor->op_index = op_index;
14654 0 RETVAL = gql_runtime_vm_new_handle_sv(aTHX_ pkg, cursor);
14655 }
14656 OUTPUT:
14657 RETVAL
14658  
14659 SV *
14660 cursor_snapshot_xs(cursor)
14661 SV *cursor
14662 CODE:
14663 0 RETVAL = gql_runtime_vm_cursor_snapshot_sv(aTHX_ cursor);
14664 OUTPUT:
14665 RETVAL
14666  
14667 void
14668 cursor_restore_xs(cursor, snapshot)
14669 SV *cursor
14670 SV *snapshot
14671 CODE:
14672 {
14673 0 gql_runtime_vm_cursor_t *dst = gql_runtime_vm_expect_cursor(aTHX_ cursor);
14674 0 gql_runtime_vm_cursor_restore_sv(aTHX_ dst, snapshot);
14675 }
14676  
14677 void
14678 cursor_enter_block_xs(cursor, block, block_index = -1)
14679 SV *cursor
14680 SV *block
14681 IV block_index
14682 CODE:
14683 {
14684 0 gql_runtime_vm_cursor_t *dst = gql_runtime_vm_expect_cursor(aTHX_ cursor);
14685 0 ▶ if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) {
Branch: 5 branches
BranchTrueFalseTotal
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
if (block_index < 0 && block && SvOK(block) && !SvROK(block) && SvIOK(block)) { 0 0 0
14686 0 block_index = SvIV(block);
14687 }
14688 (void)block;
14689 0 dst->block_index = block_index;
14690 0 dst->slot_index = 0;
14691 0 dst->op_index = -1;
14692 }
14693  
14694 void
14695 cursor_set_current_op_xs(cursor, op, index = -2147483647)
14696 SV *cursor
14697 SV *op
14698 IV index
14699 CODE:
14700 {
14701 0 gql_runtime_vm_cursor_t *dst = gql_runtime_vm_expect_cursor(aTHX_ cursor);
14702 (void)op;
14703 0 ▶ if (index != -2147483647) {
Branch: 1 branch
BranchTrueFalseTotal
if (index != -2147483647) { 0 0 0
14704 0 dst->op_index = index;
14705 }
14706 }
14707  
14708 SV *
14709 cursor_advance_op_xs(cursor)
14710 SV *cursor
14711 CODE:
14712 {
14713 0 gql_runtime_vm_cursor_t *dst = gql_runtime_vm_expect_cursor(aTHX_ cursor);
14714 const gql_runtime_vm_native_block_t *block;
14715 const gql_runtime_vm_native_op_t *op;
14716 IV next_index;
14717 0 block = gql_runtime_vm_cursor_current_native_block(dst);
14718 0 ▶ if (!block) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block) { 0 0 0
14719 0 RETVAL = &PL_sv_undef;
14720 0 goto done_cursor_advance;
14721 }
14722 0 next_index = dst->op_index + 1;
14723 0 ▶ if (next_index >= block->op_count) {
Branch: 1 branch
BranchTrueFalseTotal
if (next_index >= block->op_count) { 0 0 0
14724 0 dst->op_index = next_index;
14725 0 RETVAL = &PL_sv_undef;
14726 0 goto done_cursor_advance;
14727 }
14728 0 dst->op_index = next_index;
14729 0 op = &block->ops[next_index];
14730 0 ▶ dst->slot_index = op ? op->slot_index : 0;
Branch: 1 branch
BranchTrueFalseTotal
dst->slot_index = op ? op->slot_index : 0; 0 0 0
14731 0 RETVAL = newSViv(next_index);
14732 0 done_cursor_advance:
14733 ;
14734 }
14735 OUTPUT:
14736 RETVAL
14737  
14738 SV *
14739 cursor_block_xs(cursor)
14740 SV *cursor
14741 CODE:
14742 {
14743 PERL_UNUSED_ARG(cursor);
14744 0 RETVAL = newSVsv(&PL_sv_undef);
14745 }
14746 OUTPUT:
14747 RETVAL
14748  
14749 IV
14750 cursor_slot_index_xs(cursor)
14751 SV *cursor
14752 CODE:
14753 0 ▶ RETVAL = gql_runtime_vm_expect_cursor(aTHX_ cursor)->slot_index;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = gql_runtime_vm_expect_cursor(aTHX_ cursor)->slot_index; 0 0 0
14754 OUTPUT:
14755 RETVAL
14756  
14757 IV
14758 cursor_op_index_xs(cursor)
14759 SV *cursor
14760 CODE:
14761 0 ▶ RETVAL = gql_runtime_vm_expect_cursor(aTHX_ cursor)->op_index;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = gql_runtime_vm_expect_cursor(aTHX_ cursor)->op_index; 0 0 0
14762 OUTPUT:
14763 RETVAL
14764  
14765 SV *
14766 cursor_current_slot_xs(cursor)
14767 SV *cursor
14768 CODE:
14769 {
14770 PERL_UNUSED_ARG(cursor);
14771 0 RETVAL = newSVsv(&PL_sv_undef);
14772 }
14773 OUTPUT:
14774 RETVAL
14775  
14776 SV *
14777 cursor_current_op_xs(cursor)
14778 SV *cursor
14779 CODE:
14780 {
14781 PERL_UNUSED_ARG(cursor);
14782 0 RETVAL = newSVsv(&PL_sv_undef);
14783 }
14784 OUTPUT:
14785 RETVAL
14786  
14787 SV *
14788 field_frame_new_xs(class, source = &PL_sv_undef, path_frame = &PL_sv_undef, resolved_value = &PL_sv_undef, outcome = &PL_sv_undef)
14789 SV *class
14790 SV *source
14791 SV *path_frame
14792 SV *resolved_value
14793 SV *outcome
14794 CODE:
14795 {
14796 gql_runtime_vm_field_frame_t *frame;
14797 0 const char *pkg = SvPV_nolen(class);
14798 0 ▶ frame = gql_runtime_vm_new_field_frame_struct(
Branch: 1 branch
BranchTrueFalseTotal
frame = gql_runtime_vm_new_field_frame_struct( 0 0 0
14799 aTHX_
14800 source,
14801 0 ▶ (path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0)
Branch: 4 branches
BranchTrueFalseTotal
(path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) 0 0 0
(path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) 0 0 0
(path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) 0 0 0
(path_frame && SvOK(path_frame) && SvROK(path_frame) && SvIOK(SvRV(path_frame)) && SvUV(SvRV(path_frame)) != 0) 0 0 0
14802 0 ? INT2PTR(gql_runtime_vm_path_frame_t *, SvUV(SvRV(path_frame)))
14803 : NULL
14804 );
14805 0 ▶ frame->resolved_value = newSVsv(resolved_value ? resolved_value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
frame->resolved_value = newSVsv(resolved_value ? resolved_value : &PL_sv_undef); 0 0 0
14806 0 ▶ if (outcome && SvOK(outcome)) {
Branch: 2 branches
BranchTrueFalseTotal
if (outcome && SvOK(outcome)) { 0 0 0
if (outcome && SvOK(outcome)) { 0 0 0
14807 0 frame->outcome = gql_runtime_vm_expect_outcome(aTHX_ outcome);
14808 0 gql_runtime_vm_outcome_incref(frame->outcome);
14809 }
14810 0 RETVAL = gql_runtime_vm_new_handle_sv(aTHX_ pkg, frame);
14811 }
14812 OUTPUT:
14813 RETVAL
14814  
14815 void
14816 field_frame_set_resolved_value_xs(frame, value)
14817 SV *frame
14818 SV *value
14819 CODE:
14820 {
14821 0 gql_runtime_vm_field_frame_t *state = gql_runtime_vm_expect_field_frame(aTHX_ frame);
14822 0 ▶ if (state->resolved_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->resolved_value) { 0 0 0
14823 0 SvREFCNT_dec(state->resolved_value);
14824 }
14825 0 ▶ state->resolved_value = newSVsv(value ? value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
state->resolved_value = newSVsv(value ? value : &PL_sv_undef); 0 0 0
14826 }
14827  
14828 void
14829 field_frame_set_outcome_xs(frame, outcome)
14830 SV *frame
14831 SV *outcome
14832 CODE:
14833 {
14834 0 gql_runtime_vm_field_frame_t *state = gql_runtime_vm_expect_field_frame(aTHX_ frame);
14835 0 gql_runtime_vm_outcome_decref(aTHX_ state->outcome);
14836 0 state->outcome = NULL;
14837 0 ▶ if (outcome && SvOK(outcome)) {
Branch: 2 branches
BranchTrueFalseTotal
if (outcome && SvOK(outcome)) { 0 0 0
if (outcome && SvOK(outcome)) { 0 0 0
14838 0 state->outcome = gql_runtime_vm_expect_outcome(aTHX_ outcome);
14839 0 gql_runtime_vm_outcome_incref(state->outcome);
14840 }
14841 }
14842  
14843 SV *
14844 field_frame_source_xs(frame)
14845 SV *frame
14846 CODE:
14847 {
14848 0 gql_runtime_vm_field_frame_t *state = gql_runtime_vm_expect_field_frame(aTHX_ frame);
14849 0 ▶ RETVAL = newSVsv(state->source ? state->source : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVsv(state->source ? state->source : &PL_sv_undef); 0 0 0
14850 }
14851 OUTPUT:
14852 RETVAL
14853  
14854 SV *
14855 field_frame_path_frame_xs(frame)
14856 SV *frame
14857 CODE:
14858 {
14859 0 gql_runtime_vm_field_frame_t *state = gql_runtime_vm_expect_field_frame(aTHX_ frame);
14860 0 ▶ if (state->path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->path_frame) { 0 0 0
14861 0 state->path_frame->refcount++;
14862 0 RETVAL = gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::PathFrame", state->path_frame);
14863 } else {
14864 0 RETVAL = newSVsv(&PL_sv_undef);
14865 }
14866 }
14867 OUTPUT:
14868 RETVAL
14869  
14870 SV *
14871 field_frame_resolved_value_xs(frame)
14872 SV *frame
14873 CODE:
14874 {
14875 0 gql_runtime_vm_field_frame_t *state = gql_runtime_vm_expect_field_frame(aTHX_ frame);
14876 0 ▶ RETVAL = newSVsv(state->resolved_value ? state->resolved_value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVsv(state->resolved_value ? state->resolved_value : &PL_sv_undef); 0 0 0
14877 }
14878 OUTPUT:
14879 RETVAL
14880  
14881 SV *
14882 field_frame_outcome_xs(frame)
14883 SV *frame
14884 CODE:
14885 {
14886 0 gql_runtime_vm_field_frame_t *state = gql_runtime_vm_expect_field_frame(aTHX_ frame);
14887 0 RETVAL = gql_runtime_vm_wrap_outcome_sv(aTHX_ state->outcome);
14888 }
14889 OUTPUT:
14890 RETVAL
14891  
14892 SV *
14893 path_frame_new_xs(class, parent = &PL_sv_undef, key = &PL_sv_undef)
14894 SV *class
14895 SV *parent
14896 SV *key
14897 CODE:
14898 {
14899 PERL_UNUSED_ARG(class);
14900 0 RETVAL = gql_runtime_vm_new_path_frame_handle(aTHX_ parent, key);
14901 }
14902 OUTPUT:
14903 RETVAL
14904  
14905 SV *
14906 path_frame_materialize_path_xs(path_frame)
14907 SV *path_frame
14908 CODE:
14909 {
14910 0 gql_runtime_vm_path_frame_t *frame = gql_runtime_vm_expect_path_frame(aTHX_ path_frame);
14911 0 RETVAL = gql_runtime_vm_path_frame_to_path_sv(aTHX_ frame);
14912 }
14913 OUTPUT:
14914 RETVAL
14915  
14916 SV *
14917 path_frame_parent_xs(path_frame)
14918 SV *path_frame
14919 CODE:
14920 {
14921 0 gql_runtime_vm_path_frame_t *state = gql_runtime_vm_expect_path_frame(aTHX_ path_frame);
14922 0 ▶ if (state->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->parent) { 0 0 0
14923 0 state->parent->refcount++;
14924 0 RETVAL = gql_runtime_vm_new_handle_sv(aTHX_ "GraphQL::Houtou::Runtime::PathFrame", state->parent);
14925 } else {
14926 0 RETVAL = newSVsv(&PL_sv_undef);
14927 }
14928 }
14929 OUTPUT:
14930 RETVAL
14931  
14932 SV *
14933 path_frame_key_xs(path_frame)
14934 SV *path_frame
14935 CODE:
14936 {
14937 0 gql_runtime_vm_path_frame_t *state = gql_runtime_vm_expect_path_frame(aTHX_ path_frame);
14938 0 RETVAL = gql_runtime_vm_path_frame_key_sv(aTHX_ state);
14939 }
14940 OUTPUT:
14941 RETVAL
14942  
14943 SV *
14944 lazy_info_hashref_xs(info_sv)
14945 SV *info_sv
14946 CODE:
14947 {
14948 gql_runtime_vm_lazy_info_t *info;
14949  
14950 2162 ▶ if (!info_sv || !SvROK(info_sv) || !sv_derived_from(info_sv, "GraphQL::Houtou::Runtime::LazyInfo")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!info_sv || !SvROK(info_sv) || !sv_derived_from(info_sv, "GraphQL::Houtou::Runtime::LazyInfo")) { 2162 0 2162
if (!info_sv || !SvROK(info_sv) || !sv_derived_from(info_sv, "GraphQL::Houtou::Runtime::LazyInfo")) { 2162 0 2162
if (!info_sv || !SvROK(info_sv) || !sv_derived_from(info_sv, "GraphQL::Houtou::Runtime::LazyInfo")) { 0 2162 2162
14951 0 croak("expected a GraphQL::Houtou::Runtime::LazyInfo");
14952 }
14953 2162 info = INT2PTR(gql_runtime_vm_lazy_info_t *, SvUV(SvRV(info_sv)));
14954 2162 ▶ if (!info) {
Branch: 1 branch
BranchTrueFalseTotal
if (!info) { 0 2162 2162
14955 0 croak("lazy info handle is no longer valid");
14956 }
14957 2162 RETVAL = gql_runtime_vm_lazy_info_materialize_hash_sv(aTHX_ info);
14958 }
14959 OUTPUT:
14960 RETVAL
14961  
14962 SV *
14963 block_frame_new_xs(class, values = &PL_sv_undef, pending_names = &PL_sv_undef, pending_outcomes = &PL_sv_undef)
14964 SV *class
14965 SV *values
14966 SV *pending_names
14967 SV *pending_outcomes
14968 CODE:
14969 {
14970 gql_runtime_vm_block_frame_t *frame;
14971 0 const char *pkg = SvPV_nolen(class);
14972 0 frame = gql_runtime_vm_new_block_frame_struct(aTHX);
14973 0 ▶ if (values && SvOK(values) && SvROK(values) && SvTYPE(SvRV(values)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (values && SvOK(values) && SvROK(values) && SvTYPE(SvRV(values)) == SVt_PVHV) { 0 0 0
if (values && SvOK(values) && SvROK(values) && SvTYPE(SvRV(values)) == SVt_PVHV) { 0 0 0
if (values && SvOK(values) && SvROK(values) && SvTYPE(SvRV(values)) == SVt_PVHV) { 0 0 0
if (values && SvOK(values) && SvROK(values) && SvTYPE(SvRV(values)) == SVt_PVHV) { 0 0 0
14974 0 gql_runtime_vm_native_value_destroy(aTHX_ frame->values_value);
14975 0 frame->values_value = gql_runtime_vm_native_value_from_sv(aTHX_ values);
14976 }
14977 0 ▶ if (pending_names && SvOK(pending_names) && SvROK(pending_names) && SvTYPE(SvRV(pending_names)) == SVt_PVAV &&
Branch: 5 branches
BranchTrueFalseTotal
if (pending_names && SvOK(pending_names) && SvROK(pending_names) && SvTYPE(SvRV(pending_names)) == SVt_PVAV && 0 0 0
if (pending_names && SvOK(pending_names) && SvROK(pending_names) && SvTYPE(SvRV(pending_names)) == SVt_PVAV && 0 0 0
if (pending_names && SvOK(pending_names) && SvROK(pending_names) && SvTYPE(SvRV(pending_names)) == SVt_PVAV && 0 0 0
if (pending_names && SvOK(pending_names) && SvROK(pending_names) && SvTYPE(SvRV(pending_names)) == SVt_PVAV && 0 0 0
if (pending_names && SvOK(pending_names) && SvROK(pending_names) && SvTYPE(SvRV(pending_names)) == SVt_PVAV && 0 0 0
14978 0 ▶ pending_outcomes && SvOK(pending_outcomes) && SvROK(pending_outcomes) && SvTYPE(SvRV(pending_outcomes)) == SVt_PVAV) {
Branch: 3 branches
BranchTrueFalseTotal
pending_outcomes && SvOK(pending_outcomes) && SvROK(pending_outcomes) && SvTYPE(SvRV(pending_outcomes)) == SVt_PVAV) { 0 0 0
pending_outcomes && SvOK(pending_outcomes) && SvROK(pending_outcomes) && SvTYPE(SvRV(pending_outcomes)) == SVt_PVAV) { 0 0 0
pending_outcomes && SvOK(pending_outcomes) && SvROK(pending_outcomes) && SvTYPE(SvRV(pending_outcomes)) == SVt_PVAV) { 0 0 0
14979 0 AV *names_av = (AV *)SvRV(pending_names);
14980 0 AV *outcomes_av = (AV *)SvRV(pending_outcomes);
14981 SSize_t i;
14982 0 ▶ for (i = 0; i <= av_len(names_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(names_av); i++) { 0 0 0
14983 0 SV **name_svp = av_fetch(names_av, i, 0);
14984 0 SV **outcome_svp = av_fetch(outcomes_av, i, 0);
14985 0 ▶ if (name_svp && *name_svp && outcome_svp && *outcome_svp && SvOK(*outcome_svp)) {
Branch: 5 branches
BranchTrueFalseTotal
if (name_svp && *name_svp && outcome_svp && *outcome_svp && SvOK(*outcome_svp)) { 0 0 0
if (name_svp && *name_svp && outcome_svp && *outcome_svp && SvOK(*outcome_svp)) { 0 0 0
if (name_svp && *name_svp && outcome_svp && *outcome_svp && SvOK(*outcome_svp)) { 0 0 0
if (name_svp && *name_svp && outcome_svp && *outcome_svp && SvOK(*outcome_svp)) { 0 0 0
if (name_svp && *name_svp && outcome_svp && *outcome_svp && SvOK(*outcome_svp)) { 0 0 0
14986 0 gql_runtime_vm_block_frame_push_pending(aTHX_ frame, *name_svp, *outcome_svp);
14987 }
14988 }
14989 }
14990 0 RETVAL = gql_runtime_vm_new_handle_sv(aTHX_ pkg, frame);
14991 }
14992 OUTPUT:
14993 RETVAL
14994  
14995 void
14996 block_frame_add_pending_xs(frame, result_name, outcome)
14997 SV *frame
14998 SV *result_name
14999 SV *outcome
15000 PPCODE:
15001 {
15002 0 gql_runtime_vm_block_frame_t *state = gql_runtime_vm_expect_block_frame(aTHX_ frame);
15003 0 gql_runtime_vm_block_frame_push_pending(aTHX_ state, result_name, outcome);
15004 }
15005  
15006 void
15007 block_frame_consume_outcome_xs(frame, writer, result_name, outcome)
15008 SV *frame
15009 SV *writer
15010 SV *result_name
15011 SV *outcome
15012 CODE:
15013 {
15014 0 gql_runtime_vm_block_frame_t *state = gql_runtime_vm_expect_block_frame(aTHX_ frame);
15015 gql_runtime_vm_writer_t *writer_state;
15016 0 STRLEN result_name_len = 0;
15017 0 const char *result_name_pv = NULL;
15018 0 ▶ if (!outcome || !SvOK(outcome)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!outcome || !SvOK(outcome)) { 0 0 0
if (!outcome || !SvOK(outcome)) { 0 0 0
15019 0 XSRETURN_EMPTY;
15020 }
15021 0 writer_state = gql_runtime_vm_expect_writer(aTHX_ writer);
15022 0 ▶ result_name_pv = (result_name && SvOK(result_name)) ? SvPV(result_name, result_name_len) : "";
Branch: 2 branches
BranchTrueFalseTotal
result_name_pv = (result_name && SvOK(result_name)) ? SvPV(result_name, result_name_len) : ""; 0 0 0
result_name_pv = (result_name && SvOK(result_name)) ? SvPV(result_name, result_name_len) : ""; 0 0 0
15023 0 gql_runtime_vm_consume_outcome_native_object(
15024 aTHX_
15025 state->values_value,
15026 result_name_pv,
15027 0,
15028 gql_runtime_vm_expect_outcome(aTHX_ outcome),
15029 writer_state
15030 );
15031 }
15032  
15033 SV *
15034 block_frame_values_xs(frame)
15035 SV *frame
15036 CODE:
15037 {
15038 0 gql_runtime_vm_block_frame_t *state = gql_runtime_vm_expect_block_frame(aTHX_ frame);
15039 0 RETVAL = gql_runtime_vm_native_value_materialize_sv(aTHX_ state->values_value);
15040 }
15041 OUTPUT:
15042 RETVAL
15043  
15044 SV *
15045 block_frame_finalize_xs(frame, writer)
15046 SV *frame
15047 SV *writer
15048 CODE:
15049 {
15050 0 gql_runtime_vm_block_frame_t *state = gql_runtime_vm_expect_block_frame(aTHX_ frame);
15051 0 gql_runtime_vm_writer_t *writer_state = gql_runtime_vm_expect_writer(aTHX_ writer);
15052 0 RETVAL = gql_runtime_vm_block_frame_finalize_sv(
15053 aTHX_
15054 state,
15055 &gql_runtime_vm_promise_xs_adapter,
15056 writer_state,
15057 &PL_sv_undef,
15058 0
15059 );
15060 }
15061 OUTPUT:
15062 RETVAL
15063  
15064 IV
15065 block_frame_has_pending_xs(frame)
15066 SV *frame
15067 CODE:
15068 {
15069 0 gql_runtime_vm_block_frame_t *state = gql_runtime_vm_expect_block_frame(aTHX_ frame);
15070 0 ▶ RETVAL = state->pending_count > 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = state->pending_count > 0 ? 1 : 0; 0 0 0
15071 }
15072 OUTPUT:
15073 RETVAL
15074  
15075 SV *
15076 block_frame_merge_pending_xs(frame, writer, resolved)
15077 SV *frame
15078 SV *writer
15079 SV *resolved
15080 CODE:
15081 {
15082 0 gql_runtime_vm_block_frame_t *state = gql_runtime_vm_expect_block_frame(aTHX_ frame);
15083 0 gql_runtime_vm_writer_t *writer_state = gql_runtime_vm_expect_writer(aTHX_ writer);
15084 0 AV *resolved_av = gql_runtime_vm_expect_arrayref(aTHX_ resolved, "resolved outcomes");
15085 SSize_t i;
15086  
15087 0 ▶ for (i = 0; i <= av_len(resolved_av) && i < state->pending_count; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i <= av_len(resolved_av) && i < state->pending_count; i++) { 0 0 0
for (i = 0; i <= av_len(resolved_av) && i < state->pending_count; i++) { 0 0 0
15088 0 SV **outcome_svp = av_fetch(resolved_av, i, 0);
15089 0 ▶ if (outcome_svp && *outcome_svp) {
Branch: 2 branches
BranchTrueFalseTotal
if (outcome_svp && *outcome_svp) { 0 0 0
if (outcome_svp && *outcome_svp) { 0 0 0
15090 0 gql_runtime_vm_consume_outcome_native_object(
15091 aTHX_
15092 state->values_value,
15093 0 state->pending_entries[i].result_name_pv,
15094 0 state->pending_entries[i].result_name_pv_borrowed,
15095 gql_runtime_vm_expect_outcome(aTHX_ *outcome_svp),
15096 writer_state
15097 );
15098 }
15099 }
15100  
15101 0 RETVAL = gql_runtime_vm_native_value_materialize_sv(aTHX_ state->values_value);
15102 }
15103 OUTPUT:
15104 RETVAL
15105  
15106 SV *
15107 exec_state_new_xs(class, runtime_schema, program, cursor, writer, context = &PL_sv_undef, variables = &PL_sv_undef, root_value = &PL_sv_undef, empty_args = &PL_sv_undef)
15108 SV *class
15109 SV *runtime_schema
15110 SV *program
15111 SV *cursor
15112 SV *writer
15113 SV *context
15114 SV *variables
15115 SV *root_value
15116 SV *empty_args
15117 CODE:
15118 {
15119 0 const char *pkg = SvPV_nolen(class);
15120 0 ▶ RETVAL = gql_runtime_vm_new_exec_state_handle_sv(
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = gql_runtime_vm_new_exec_state_handle_sv( 0 0 0
RETVAL = gql_runtime_vm_new_exec_state_handle_sv( 0 0 0
15121 aTHX_
15122 pkg,
15123 runtime_schema,
15124 program,
15125 0 ▶ (cursor && SvOK(cursor)) ? gql_runtime_vm_expect_cursor(aTHX_ cursor) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
(cursor && SvOK(cursor)) ? gql_runtime_vm_expect_cursor(aTHX_ cursor) : NULL, 0 0 0
15126 0 ▶ (writer && SvOK(writer)) ? gql_runtime_vm_expect_writer(aTHX_ writer) : NULL,
Branch: 1 branch
BranchTrueFalseTotal
(writer && SvOK(writer)) ? gql_runtime_vm_expect_writer(aTHX_ writer) : NULL, 0 0 0
15127 context,
15128 variables,
15129 root_value,
15130 empty_args
15131 );
15132 }
15133 OUTPUT:
15134 RETVAL
15135  
15136 SV *
15137 exec_state_execute_block_async_xs(state, block_index, source = &PL_sv_undef, base_path = &PL_sv_undef)
15138 SV *state
15139 IV block_index
15140 SV *source
15141 SV *base_path
15142 CODE:
15143 {
15144 0 gql_runtime_vm_exec_state_handle_t *s = gql_runtime_vm_expect_exec_state_handle(aTHX_ state);
15145 0 RETVAL = gql_runtime_vm_exec_state_execute_block_async_sv(aTHX_ state, s, block_index, source, base_path);
15146 0 ▶ if (s->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->completed_response_sv) { 0 0 0
15147 /* Response frame completed without a deferred; hand back the
15148 * parked envelope the promise would have resolved with. */
15149 0 SvREFCNT_dec(RETVAL);
15150 0 RETVAL = s->completed_response_sv;
15151 0 s->completed_response_sv = NULL;
15152 }
15153 }
15154 OUTPUT:
15155 RETVAL
15156  
15157 SV *
15158 exec_state_run_program_xs(state, root_value = &PL_sv_undef)
15159 SV *state
15160 SV *root_value
15161 CODE:
15162 {
15163 0 gql_runtime_vm_exec_state_handle_t *s = gql_runtime_vm_expect_exec_state_handle(aTHX_ state);
15164 0 SV *effective_root = root_value;
15165 gql_runtime_vm_native_runtime_t *runtime;
15166 gql_runtime_vm_native_bundle_t *bundle;
15167 SV *runtime_schema_sv;
15168 SV *variables_sv;
15169 SV *context_sv;
15170  
15171 0 ▶ if (!s->cursor || !s->cursor->native_program) {
Branch: 2 branches
BranchTrueFalseTotal
if (!s->cursor || !s->cursor->native_program) { 0 0 0
if (!s->cursor || !s->cursor->native_program) { 0 0 0
15172 0 croak("exec state cursor must hold a native program");
15173 }
15174 0 ▶ if (!effective_root || !SvOK(effective_root)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!effective_root || !SvOK(effective_root)) { 0 0 0
if (!effective_root || !SvOK(effective_root)) { 0 0 0
15175 0 effective_root = s->root_value;
15176 }
15177 0 runtime = gql_runtime_vm_exec_state_native_runtime(aTHX_ s);
15178 0 runtime_schema_sv =
15179 0 ▶ (s->runtime_schema && SvOK(s->runtime_schema))
Branch: 1 branch
BranchTrueFalseTotal
(s->runtime_schema && SvOK(s->runtime_schema)) 0 0 0
15180 ? s->runtime_schema
15181 0 ▶ : (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema
Branch: 3 branches
BranchTrueFalseTotal
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 0 0 0
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 0 0 0
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 0 0 0
15182 0 ? runtime->callback_catalog->runtime_schema
15183 0 ▶ : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef); 0 0 0
15184 0 ▶ variables_sv = (s->variables && SvOK(s->variables)) ? s->variables : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
variables_sv = (s->variables && SvOK(s->variables)) ? s->variables : &PL_sv_undef; 0 0 0
variables_sv = (s->variables && SvOK(s->variables)) ? s->variables : &PL_sv_undef; 0 0 0
15185 0 ▶ context_sv = (s->context && SvOK(s->context)) ? s->context : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
context_sv = (s->context && SvOK(s->context)) ? s->context : &PL_sv_undef; 0 0 0
context_sv = (s->context && SvOK(s->context)) ? s->context : &PL_sv_undef; 0 0 0
15186 0 bundle = gql_runtime_vm_native_program_cached_bundle(
15187 aTHX_
15188 runtime,
15189 0 s->cursor->native_program
15190 );
15191 0 RETVAL = gql_runtime_vm_execute_bundle_fast_response_sv(
15192 aTHX_
15193 runtime,
15194 runtime_schema_sv,
15195 bundle,
15196 effective_root,
15197 context_sv,
15198 variables_sv
15199 );
15200 }
15201 OUTPUT:
15202 RETVAL
15203  
15204 SV *
15205 exec_state_run_program_async_xs(state, root_value = &PL_sv_undef)
15206 SV *state
15207 SV *root_value
15208 CODE:
15209 {
15210 0 gql_runtime_vm_exec_state_handle_t *s = gql_runtime_vm_expect_exec_state_handle(aTHX_ state);
15211 0 SV *effective_root = root_value;
15212 SV *data_sv;
15213 0 IV root_block_index = -1;
15214  
15215 0 ▶ if (!s->cursor || !s->cursor->native_program) {
Branch: 2 branches
BranchTrueFalseTotal
if (!s->cursor || !s->cursor->native_program) { 0 0 0
if (!s->cursor || !s->cursor->native_program) { 0 0 0
15216 0 croak("exec state cursor must hold a native program");
15217 }
15218 0 root_block_index = s->cursor->native_program->root_block_index;
15219 0 ▶ if (!effective_root || !SvOK(effective_root)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!effective_root || !SvOK(effective_root)) { 0 0 0
if (!effective_root || !SvOK(effective_root)) { 0 0 0
15220 0 effective_root = s->root_value;
15221 }
15222  
15223 0 data_sv = gql_runtime_vm_exec_state_execute_block_async_sv(
15224 aTHX_
15225 state,
15226 s,
15227 root_block_index,
15228 effective_root,
15229 &PL_sv_undef
15230 );
15231 0 ▶ if (s->completed_response_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (s->completed_response_sv) { 0 0 0
15232 /* Response frame completed without a deferred; the parked value
15233 * is already the finished envelope. */
15234 0 RETVAL = s->completed_response_sv;
15235 0 s->completed_response_sv = NULL;
15236 0 SvREFCNT_dec(data_sv);
15237 0 ▶ } else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, data_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (gql_runtime_vm_is_promise_value_for_state_sv(aTHX_ s, data_sv)) { 0 0 0
15238 0 RETVAL = data_sv;
15239 } else {
15240 0 RETVAL = gql_runtime_vm_exec_state_materialize_response_sv(aTHX_ s, data_sv);
15241 0 SvREFCNT_dec(data_sv);
15242 }
15243 }
15244 OUTPUT:
15245 RETVAL
15246  
15247 SV *
15248 exec_state_materialize_response_xs(state, data = &PL_sv_undef)
15249 SV *state
15250 SV *data
15251 CODE:
15252 {
15253 0 gql_runtime_vm_exec_state_handle_t *s = gql_runtime_vm_expect_exec_state_handle(aTHX_ state);
15254 0 RETVAL = gql_runtime_vm_exec_state_materialize_response_sv(aTHX_ s, data);
15255 }
15256 OUTPUT:
15257 RETVAL
15258  
15259 SV *
15260 execute_native_bundle_xs(runtime_schema, bundle_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15261 SV *runtime_schema
15262 SV *bundle_sv
15263 SV *root_value
15264 SV *context_value
15265 SV *variables
15266 CODE:
15267 {
15268 gql_runtime_vm_native_bundle_t *bundle;
15269 28 gql_runtime_vm_native_runtime_t *runtime = NULL;
15270 28 int owns_runtime = 0;
15271 SV *runtime_schema_sv;
15272  
15273 28 ▶ if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 28 0 28
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 28 0 28
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 0 28 28
15274 0 croak("expected a GraphQL::Houtou::Runtime::NativeBundle");
15275 }
15276 28 bundle = INT2PTR(gql_runtime_vm_native_bundle_t *, SvUV(SvRV(bundle_sv)));
15277 28 ▶ if (!bundle) {
Branch: 1 branch
BranchTrueFalseTotal
if (!bundle) { 0 28 28
15278 0 croak("native VM bundle handle is no longer valid");
15279 }
15280  
15281 28 ▶ if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) { 28 0 28
if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) { 28 0 28
if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) { 28 0 28
15282 28 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_schema)));
15283 28 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 28 28
15284 0 croak("native VM runtime handle is no longer valid");
15285 }
15286 } else {
15287 0 runtime = gql_runtime_vm_native_runtime_from_runtime_schema_sv(aTHX_ runtime_schema);
15288 0 owns_runtime = 1;
15289 }
15290  
15291 28 ▶ runtime_schema_sv = (runtime_schema && !sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime"))
Branch: 1 branch
BranchTrueFalseTotal
runtime_schema_sv = (runtime_schema && !sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) 28 0 28
15292 ? runtime_schema
15293 84 ▶ : (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema
Branch: 3 branches
BranchTrueFalseTotal
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 28 0 28
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 28 0 28
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 28 0 28
15294 28 ? runtime->callback_catalog->runtime_schema
15295 56 ▶ : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef); 28 0 28
15296 28 RETVAL = gql_runtime_vm_execute_bundle_fast_response_sv(
15297 aTHX_
15298 runtime,
15299 runtime_schema_sv,
15300 bundle,
15301 root_value,
15302 context_value,
15303 variables
15304 );
15305 28 ▶ if (owns_runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (owns_runtime) { 0 28 28
15306 0 gql_runtime_vm_native_runtime_destroy(runtime);
15307 }
15308 }
15309 OUTPUT:
15310 RETVAL
15311  
15312 SV *
15313 execute_native_program_xs(runtime_schema, runtime_descriptor, program_descriptor, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15314 SV *runtime_schema
15315 SV *runtime_descriptor
15316 SV *program_descriptor
15317 SV *root_value
15318 SV *context_value
15319 SV *variables
15320 CODE:
15321 {
15322 gql_runtime_vm_native_bundle_t *bundle;
15323 0 gql_runtime_vm_native_runtime_t *runtime = NULL;
15324 0 int owns_runtime = 0;
15325 SV *runtime_schema_sv;
15326  
15327 0 bundle = gql_runtime_vm_native_bundle_from_runtime_and_program_sv(
15328 aTHX_ runtime_descriptor, program_descriptor
15329 );
15330  
15331 0 ▶ if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 0 0
if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 0 0
if (runtime_schema && SvROK(runtime_schema) && sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 0 0
15332 0 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_schema)));
15333 0 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 0 0
15334 0 gql_runtime_vm_native_bundle_destroy(bundle);
15335 0 croak("native VM runtime handle is no longer valid");
15336 }
15337 } else {
15338 0 runtime = gql_runtime_vm_native_runtime_from_runtime_schema_sv(aTHX_ runtime_schema);
15339 0 owns_runtime = 1;
15340 }
15341  
15342 0 ▶ runtime_schema_sv = (runtime_schema && !sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime"))
Branch: 1 branch
BranchTrueFalseTotal
runtime_schema_sv = (runtime_schema && !sv_derived_from(runtime_schema, "GraphQL::Houtou::Runtime::NativeRuntime")) 0 0 0
15343 ? runtime_schema
15344 0 ▶ : (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema
Branch: 3 branches
BranchTrueFalseTotal
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 0 0 0
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 0 0 0
: (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema 0 0 0
15345 0 ? runtime->callback_catalog->runtime_schema
15346 0 ▶ : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef); 0 0 0
15347 0 RETVAL = gql_runtime_vm_execute_bundle_fast_response_sv(
15348 aTHX_
15349 runtime,
15350 runtime_schema_sv,
15351 bundle,
15352 root_value,
15353 context_value,
15354 variables
15355 );
15356 0 gql_runtime_vm_native_bundle_destroy(bundle);
15357 0 ▶ if (owns_runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (owns_runtime) { 0 0 0
15358 0 gql_runtime_vm_native_runtime_destroy(runtime);
15359 }
15360 }
15361 OUTPUT:
15362 RETVAL
15363  
15364 SV *
15365 execute_native_program_handle_xs(runtime_sv, program_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15366 SV *runtime_sv
15367 SV *program_sv
15368 SV *root_value
15369 SV *context_value
15370 SV *variables
15371 CODE:
15372 {
15373 gql_runtime_vm_native_runtime_t *runtime;
15374 gql_runtime_vm_native_program_t *program;
15375 gql_runtime_vm_native_bundle_t *bundle;
15376 SV *runtime_schema_sv;
15377  
15378 3 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 3 0 3
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 3 0 3
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 3 3
15379 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
15380 }
15381 3 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
15382 3 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 3 3
15383 0 croak("native VM runtime handle is no longer valid");
15384 }
15385 3 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
15386 3 bundle = gql_runtime_vm_native_program_cached_bundle(aTHX_ runtime, program);
15387 3 ▶ runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema)
Branch: 2 branches
BranchTrueFalseTotal
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 3 0 3
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 3 0 3
15388 3 ? runtime->callback_catalog->runtime_schema
15389 6 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 3 0 3
15390 3 RETVAL = gql_runtime_vm_execute_bundle_fast_response_sv(
15391 aTHX_
15392 runtime,
15393 runtime_schema_sv,
15394 bundle,
15395 root_value,
15396 context_value,
15397 variables
15398 );
15399 }
15400 OUTPUT:
15401 RETVAL
15402  
15403 SV *
15404 execute_native_program_prepared_fast_xs(runtime_sv, program_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15405 SV *runtime_sv
15406 SV *program_sv
15407 SV *root_value
15408 SV *context_value
15409 SV *variables
15410 CODE:
15411 {
15412 gql_runtime_vm_native_runtime_t *runtime;
15413 gql_runtime_vm_native_program_t *program;
15414 gql_runtime_vm_native_bundle_t *bundle;
15415 SV *runtime_schema_sv;
15416 SV *prepared_variables_sv;
15417 296 HV *provided_hv = NULL;
15418 SV *variable_slots[8];
15419 IV variable_slot_count;
15420  
15421 296 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 296 0 296
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 296 0 296
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 296 296
15422 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
15423 }
15424 296 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
15425 296 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 296 296
15426 0 croak("native VM runtime handle is no longer valid");
15427 }
15428 296 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
15429 296 bundle = gql_runtime_vm_native_program_cached_bundle(aTHX_ runtime, program);
15430 296 ▶ runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema)
Branch: 2 branches
BranchTrueFalseTotal
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 296 0 296
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 296 0 296
15431 296 ? runtime->callback_catalog->runtime_schema
15432 592 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 296 0 296
15433 296 ▶ if (variables && SvOK(variables)) {
Branch: 2 branches
BranchTrueFalseTotal
if (variables && SvOK(variables)) { 296 0 296
if (variables && SvOK(variables)) { 296 0 296
15434 296 ▶ if (!SvROK(variables) || SvTYPE(SvRV(variables)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(variables) || SvTYPE(SvRV(variables)) != SVt_PVHV) { 296 0 296
if (!SvROK(variables) || SvTYPE(SvRV(variables)) != SVt_PVHV) { 0 296 296
15435 0 croak("variables must be a hash reference");
15436 }
15437 296 provided_hv = (HV *)SvRV(variables);
15438 }
15439 296 Zero(variable_slots, 8, SV *);
15440 592 variable_slot_count = program->variable_def_count <= 8
15441 ? program->variable_def_count
15442 296 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
: 0; 296 0 296
15443 /*
15444 * Keep variable coercion and the sync fast lane inside one XSUB.
15445 * The prepared HV is request-local and never needs to cross back
15446 * through Perl before execution consumes it.
15447 */
15448 296 ▶ prepared_variables_sv = sv_2mortal(gql_runtime_vm_prepare_program_variables_into_slots_sv(
Branch: 1 branch
BranchTrueFalseTotal
prepared_variables_sv = sv_2mortal(gql_runtime_vm_prepare_program_variables_into_slots_sv( 270 26 296
15449 aTHX_
15450 runtime_schema_sv,
15451 program,
15452 provided_hv,
15453 variable_slot_count ? variable_slots : NULL,
15454 variable_slot_count,
15455 program->variable_def_count <= 8 ? 1 : 0
15456 ));
15457 284 ▶ RETVAL = gql_runtime_vm_execute_bundle_fast_response_with_slots_sv(
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = gql_runtime_vm_execute_bundle_fast_response_with_slots_sv( 258 26 284
15458 aTHX_
15459 runtime,
15460 runtime_schema_sv,
15461 bundle,
15462 root_value,
15463 context_value,
15464 prepared_variables_sv,
15465 variable_slot_count ? variable_slots : NULL,
15466 variable_slot_count,
15467 program,
15468 variables
15469 );
15470 }
15471 OUTPUT:
15472 RETVAL
15473  
15474 SV *
15475 execute_native_program_to_json_xs(runtime_sv, program_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15476 SV *runtime_sv
15477 SV *program_sv
15478 SV *root_value
15479 SV *context_value
15480 SV *variables
15481 CODE:
15482 {
15483 gql_runtime_vm_native_runtime_t *runtime;
15484 gql_runtime_vm_native_program_t *program;
15485 gql_runtime_vm_native_bundle_t *bundle;
15486 SV *runtime_schema_sv;
15487  
15488 0 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 0 0
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 0 0
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 0 0
15489 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
15490 }
15491 0 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
15492 0 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 0 0
15493 0 croak("native VM runtime handle is no longer valid");
15494 }
15495 0 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
15496 0 bundle = gql_runtime_vm_native_program_cached_bundle(aTHX_ runtime, program);
15497 0 ▶ runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema)
Branch: 2 branches
BranchTrueFalseTotal
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 0 0 0
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 0 0 0
15498 0 ? runtime->callback_catalog->runtime_schema
15499 0 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 0 0 0
15500 0 RETVAL = gql_runtime_vm_execute_bundle_fast_response_json(
15501 aTHX_
15502 runtime,
15503 runtime_schema_sv,
15504 bundle,
15505 root_value,
15506 context_value,
15507 variables
15508 );
15509 }
15510 OUTPUT:
15511 RETVAL
15512  
15513 SV *
15514 execute_native_program_prepared_fast_to_json_xs(runtime_sv, program_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15515 SV *runtime_sv
15516 SV *program_sv
15517 SV *root_value
15518 SV *context_value
15519 SV *variables
15520 CODE:
15521 {
15522 gql_runtime_vm_native_runtime_t *runtime;
15523 gql_runtime_vm_native_program_t *program;
15524 gql_runtime_vm_native_bundle_t *bundle;
15525 SV *runtime_schema_sv;
15526 SV *prepared_variables_sv;
15527 63 HV *provided_hv = NULL;
15528 SV *variable_slots[8];
15529 IV variable_slot_count;
15530  
15531 63 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 63 0 63
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 63 0 63
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 63 63
15532 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
15533 }
15534 63 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
15535 63 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 63 63
15536 0 croak("native VM runtime handle is no longer valid");
15537 }
15538 63 program = gql_runtime_vm_native_program_from_sv(aTHX_ program_sv);
15539 63 bundle = gql_runtime_vm_native_program_cached_bundle(aTHX_ runtime, program);
15540 63 ▶ runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema)
Branch: 2 branches
BranchTrueFalseTotal
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 63 0 63
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 63 0 63
15541 63 ? runtime->callback_catalog->runtime_schema
15542 126 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 63 0 63
15543 63 ▶ if (variables && SvOK(variables)) {
Branch: 2 branches
BranchTrueFalseTotal
if (variables && SvOK(variables)) { 63 0 63
if (variables && SvOK(variables)) { 63 0 63
15544 63 ▶ if (!SvROK(variables) || SvTYPE(SvRV(variables)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(variables) || SvTYPE(SvRV(variables)) != SVt_PVHV) { 63 0 63
if (!SvROK(variables) || SvTYPE(SvRV(variables)) != SVt_PVHV) { 0 63 63
15545 0 croak("variables must be a hash reference");
15546 }
15547 63 provided_hv = (HV *)SvRV(variables);
15548 }
15549 63 Zero(variable_slots, 8, SV *);
15550 126 variable_slot_count = program->variable_def_count <= 8
15551 ? program->variable_def_count
15552 63 ▶ : 0;
Branch: 1 branch
BranchTrueFalseTotal
: 0; 63 0 63
15553 63 ▶ prepared_variables_sv = sv_2mortal(gql_runtime_vm_prepare_program_variables_into_slots_sv(
Branch: 1 branch
BranchTrueFalseTotal
prepared_variables_sv = sv_2mortal(gql_runtime_vm_prepare_program_variables_into_slots_sv( 8 55 63
15554 aTHX_
15555 runtime_schema_sv,
15556 program,
15557 provided_hv,
15558 variable_slot_count ? variable_slots : NULL,
15559 variable_slot_count,
15560 program->variable_def_count <= 8 ? 1 : 0
15561 ));
15562 62 ▶ RETVAL = gql_runtime_vm_execute_bundle_fast_response_json_with_slots(
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = gql_runtime_vm_execute_bundle_fast_response_json_with_slots( 7 55 62
15563 aTHX_
15564 runtime,
15565 runtime_schema_sv,
15566 bundle,
15567 root_value,
15568 context_value,
15569 prepared_variables_sv,
15570 variable_slot_count ? variable_slots : NULL,
15571 variable_slot_count,
15572 program,
15573 variables
15574 );
15575 }
15576 OUTPUT:
15577 RETVAL
15578  
15579 SV *
15580 execute_native_bundle_to_json_xs(runtime_sv, bundle_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15581 SV *runtime_sv
15582 SV *bundle_sv
15583 SV *root_value
15584 SV *context_value
15585 SV *variables
15586 CODE:
15587 {
15588 gql_runtime_vm_native_bundle_t *bundle;
15589 gql_runtime_vm_native_runtime_t *runtime;
15590 SV *runtime_schema_sv;
15591  
15592 18 ▶ if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 18 0 18
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 18 0 18
if (!runtime_sv || !SvROK(runtime_sv) || !sv_derived_from(runtime_sv, "GraphQL::Houtou::Runtime::NativeRuntime")) { 0 18 18
15593 0 croak("expected a GraphQL::Houtou::Runtime::NativeRuntime");
15594 }
15595 18 runtime = INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(SvRV(runtime_sv)));
15596 18 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 18 18
15597 0 croak("native VM runtime handle is no longer valid");
15598 }
15599 18 ▶ if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) {
Branch: 3 branches
BranchTrueFalseTotal
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 18 0 18
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 18 0 18
if (!bundle_sv || !SvROK(bundle_sv) || !sv_derived_from(bundle_sv, "GraphQL::Houtou::Runtime::NativeBundle")) { 0 18 18
15600 0 croak("expected a GraphQL::Houtou::Runtime::NativeBundle");
15601 }
15602 18 bundle = INT2PTR(gql_runtime_vm_native_bundle_t *, SvUV(SvRV(bundle_sv)));
15603 18 ▶ if (!bundle) {
Branch: 1 branch
BranchTrueFalseTotal
if (!bundle) { 0 18 18
15604 0 croak("native VM bundle handle is no longer valid");
15605 }
15606 18 ▶ runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema)
Branch: 2 branches
BranchTrueFalseTotal
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 18 0 18
runtime_schema_sv = (runtime && runtime->callback_catalog && runtime->callback_catalog->runtime_schema) 18 0 18
15607 18 ? runtime->callback_catalog->runtime_schema
15608 36 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 18 0 18
15609 18 RETVAL = gql_runtime_vm_execute_bundle_fast_response_json(
15610 aTHX_
15611 runtime,
15612 runtime_schema_sv,
15613 bundle,
15614 root_value,
15615 context_value,
15616 variables
15617 );
15618 }
15619 OUTPUT:
15620 RETVAL
15621  
15622 SV *
15623 execute_native_program_auto_xs(runtime_sv, program_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15624 SV *runtime_sv
15625 SV *program_sv
15626 SV *root_value
15627 SV *context_value
15628 SV *variables
15629 CODE:
15630 {
15631 77 RETVAL = gql_runtime_vm_execute_native_program_auto_sv(
15632 aTHX_
15633 runtime_sv,
15634 program_sv,
15635 root_value,
15636 context_value,
15637 variables
15638 );
15639 }
15640 OUTPUT:
15641 RETVAL
15642  
15643 SV *
15644 execute_native_program_auto_with_on_stall_xs(runtime_sv, program_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef, on_stall_sv = &PL_sv_undef)
15645 SV *runtime_sv
15646 SV *program_sv
15647 SV *root_value
15648 SV *context_value
15649 SV *variables
15650 SV *on_stall_sv
15651 CODE:
15652 {
15653 1490 RETVAL = gql_runtime_vm_execute_native_program_auto_with_on_stall_sv(
15654 aTHX_
15655 runtime_sv,
15656 program_sv,
15657 root_value,
15658 context_value,
15659 variables,
15660 on_stall_sv
15661 );
15662 }
15663 OUTPUT:
15664 RETVAL
15665  
15666 SV *
15667 execute_native_program_auto_simple_xs(runtime_sv, program_sv)
15668 SV *runtime_sv
15669 SV *program_sv
15670 CODE:
15671 {
15672 196 RETVAL = gql_runtime_vm_execute_native_program_auto_sv(
15673 aTHX_
15674 runtime_sv,
15675 program_sv,
15676 &PL_sv_undef,
15677 &PL_sv_undef,
15678 &PL_sv_undef
15679 );
15680 }
15681 OUTPUT:
15682 RETVAL
15683  
15684 SV *
15685 execute_native_program_auto_to_json_xs(runtime_sv, program_sv, root_value = &PL_sv_undef, context_value = &PL_sv_undef, variables = &PL_sv_undef)
15686 SV *runtime_sv
15687 SV *program_sv
15688 SV *root_value
15689 SV *context_value
15690 SV *variables
15691 CODE:
15692 {
15693 25 RETVAL = gql_runtime_vm_execute_native_program_auto_json_sv(
15694 aTHX_
15695 runtime_sv,
15696 program_sv,
15697 root_value,
15698 context_value,
15699 variables
15700 );
15701 }
15702 OUTPUT:
15703 RETVAL
15704  
15705 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::DataLoader
15706  
15707 SV *
15708 _enqueue_load_miss(self, key, cache_key, cache)
15709 SV *self
15710 SV *key
15711 SV *cache_key
15712 bool cache
15713 PREINIT:
15714 HV *loader_hv;
15715 SV **queue_rv;
15716 SV **promises_rv;
15717 SV **async_adapter_svp;
15718 AV *queue_av;
15719 HV *promises_hv;
15720 SV *ticket_sv;
15721 AV *entry_av;
15722 CODE:
15723 2017 ▶ if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) { 2017 0 2017
if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) { 2017 0 2017
if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV) { 0 2017 2017
15724 0 croak("invalid DataLoader");
15725 }
15726 2017 loader_hv = (HV *)SvRV(self);
15727 2017 queue_rv = hv_fetch(loader_hv, "_queue", 6, 0);
15728 2017 ▶ if (!queue_rv || !*queue_rv || !SvROK(*queue_rv)
Branch: 3 branches
BranchTrueFalseTotal
if (!queue_rv || !*queue_rv || !SvROK(*queue_rv) 2017 0 2017
if (!queue_rv || !*queue_rv || !SvROK(*queue_rv) 2017 0 2017
if (!queue_rv || !*queue_rv || !SvROK(*queue_rv) 2017 0 2017
15729 2017 ▶ || SvTYPE(SvRV(*queue_rv)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*queue_rv)) != SVt_PVAV) { 0 2017 2017
15730 0 croak("invalid DataLoader storage");
15731 }
15732 2017 queue_av = (AV *)SvRV(*queue_rv);
15733 2017 promises_hv = NULL;
15734 2017 ▶ if (cache) {
Branch: 1 branch
BranchTrueFalseTotal
if (cache) { 1965 52 2017
15735 1965 promises_rv = hv_fetch(loader_hv, "_promises", 9, 0);
15736 1965 ▶ if (!promises_rv || !*promises_rv || !SvROK(*promises_rv)
Branch: 3 branches
BranchTrueFalseTotal
if (!promises_rv || !*promises_rv || !SvROK(*promises_rv) 1965 0 1965
if (!promises_rv || !*promises_rv || !SvROK(*promises_rv) 1965 0 1965
if (!promises_rv || !*promises_rv || !SvROK(*promises_rv) 1965 0 1965
15737 1965 ▶ || SvTYPE(SvRV(*promises_rv)) != SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*promises_rv)) != SVt_PVHV) { 0 1965 1965
15738 0 croak("invalid DataLoader cache");
15739 }
15740 1965 promises_hv = (HV *)SvRV(*promises_rv);
15741 }
15742  
15743 2017 async_adapter_svp = hv_fetch(loader_hv, "_async_adapter", 14, 0);
15744 2017 ▶ ticket_sv = gql_runtime_vm_new_dataloader_ticket_sv(
Branch: 1 branch
BranchTrueFalseTotal
ticket_sv = gql_runtime_vm_new_dataloader_ticket_sv( 0 2017 2017
15745 aTHX_ 0, &PL_sv_undef,
15746 0 ▶ (async_adapter_svp && *async_adapter_svp)
Branch: 1 branch
BranchTrueFalseTotal
(async_adapter_svp && *async_adapter_svp) 0 0 0
15747 ? *async_adapter_svp : &PL_sv_undef
15748 );
15749 2017 entry_av = newAV();
15750 2017 av_push(entry_av, newSVsv(key));
15751 2017 av_push(entry_av, newSVsv(ticket_sv));
15752 2017 av_push(queue_av, newRV_noinc((SV *)entry_av));
15753 2017 ▶ if (cache) {
Branch: 1 branch
BranchTrueFalseTotal
if (cache) { 1965 52 2017
15754 1965 hv_store_ent(promises_hv, cache_key, newSVsv(ticket_sv), 0);
15755 }
15756 2017 RETVAL = ticket_sv;
15757 OUTPUT:
15758 RETVAL
15759  
15760 IV
15761 _dispatch_queue(self, queue_sv)
15762 SV *self
15763 SV *queue_sv
15764 PREINIT:
15765 HV *loader_hv;
15766 SV **batch_svp;
15767 SV **max_svp;
15768 AV *queue_av;
15769 Size_t queue_count;
15770 Size_t offset;
15771 Size_t chunk_count;
15772 IV max_batch_size;
15773 IV dispatched;
15774 CODE:
15775 1497 ▶ if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV
Branch: 3 branches
BranchTrueFalseTotal
if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV 1497 0 1497
if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV 1497 0 1497
if (!self || !SvROK(self) || SvTYPE(SvRV(self)) != SVt_PVHV 1497 0 1497
15776 1497 ▶ || !queue_sv || !SvROK(queue_sv)
Branch: 2 branches
BranchTrueFalseTotal
|| !queue_sv || !SvROK(queue_sv) 1497 0 1497
|| !queue_sv || !SvROK(queue_sv) 1497 0 1497
15777 1497 ▶ || SvTYPE(SvRV(queue_sv)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(queue_sv)) != SVt_PVAV) { 0 1497 1497
15778 0 croak("invalid DataLoader dispatch state");
15779 }
15780 1497 loader_hv = (HV *)SvRV(self);
15781 1497 batch_svp = hv_fetch(loader_hv, "batch", 5, 0);
15782 1497 max_svp = hv_fetch(loader_hv, "max_batch_size", 14, 0);
15783 1497 ▶ if (!batch_svp || !*batch_svp || !SvROK(*batch_svp)
Branch: 3 branches
BranchTrueFalseTotal
if (!batch_svp || !*batch_svp || !SvROK(*batch_svp) 1497 0 1497
if (!batch_svp || !*batch_svp || !SvROK(*batch_svp) 1497 0 1497
if (!batch_svp || !*batch_svp || !SvROK(*batch_svp) 1497 0 1497
15784 1497 ▶ || SvTYPE(SvRV(*batch_svp)) != SVt_PVCV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*batch_svp)) != SVt_PVCV) { 0 1497 1497
15785 0 croak("invalid DataLoader batch function");
15786 }
15787 1497 ▶ max_batch_size = (max_svp && *max_svp) ? SvIV(*max_svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
max_batch_size = (max_svp && *max_svp) ? SvIV(*max_svp) : 0; 1497 0 1497
max_batch_size = (max_svp && *max_svp) ? SvIV(*max_svp) : 0; 1497 0 1497
15788 1497 queue_av = (AV *)SvRV(queue_sv);
15789 1497 queue_count = av_count(queue_av);
15790 1497 dispatched = 0;
15791  
15792 2996 ▶ for (offset = 0; offset < queue_count; offset += chunk_count) {
Branch: 1 branch
BranchTrueFalseTotal
for (offset = 0; offset < queue_count; offset += chunk_count) { 1499 1497 2996
15793 AV *keys_av;
15794 SV *values_sv;
15795 SV *reason_sv;
15796 Size_t i;
15797 I32 callback_count;
15798  
15799 1499 chunk_count = queue_count - offset;
15800 1499 ▶ if (max_batch_size > 0 && (Size_t)max_batch_size < chunk_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (max_batch_size > 0 && (Size_t)max_batch_size < chunk_count) { 3 1496 1499
if (max_batch_size > 0 && (Size_t)max_batch_size < chunk_count) { 2 1 3
15801 2 chunk_count = (Size_t)max_batch_size;
15802 }
15803 1499 keys_av = newAV();
15804 1499 av_extend(keys_av, (SSize_t)chunk_count - 1);
15805 3516 ▶ for (i = 0; i < chunk_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < chunk_count; i++) { 2017 1499 3516
15806 2017 SV **entry_svp = av_fetch(queue_av, (SSize_t)(offset + i), 0);
15807 AV *entry_av;
15808 SV **key_svp;
15809 2017 ▶ if (!entry_svp || !*entry_svp || !SvROK(*entry_svp)
Branch: 3 branches
BranchTrueFalseTotal
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 2017 0 2017
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 2017 0 2017
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 2017 0 2017
15810 2017 ▶ || SvTYPE(SvRV(*entry_svp)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*entry_svp)) != SVt_PVAV) { 0 2017 2017
15811 0 SvREFCNT_dec((SV *)keys_av);
15812 0 croak("invalid DataLoader queue entry at index %ld", (long)(offset + i));
15813 }
15814 2017 entry_av = (AV *)SvRV(*entry_svp);
15815 2017 key_svp = av_fetch(entry_av, 0, 0);
15816 2017 ▶ av_push(keys_av, newSVsv(
Branch: 2 branches
BranchTrueFalseTotal
av_push(keys_av, newSVsv( 2017 0 2017
av_push(keys_av, newSVsv( 2017 0 2017
15817 (key_svp && *key_svp) ? *key_svp : &PL_sv_undef
15818 ));
15819 }
15820  
15821 1499 values_sv = NULL;
15822 1499 reason_sv = NULL;
15823 {
15824 1499 dSP;
15825 1499 ENTER;
15826 1499 SAVETMPS;
15827 1499 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1499 1499
15828 1499 ▶ XPUSHs(sv_2mortal(newRV_noinc((SV *)keys_av)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_noinc((SV *)keys_av))); 0 1499 1499
15829 1499 PUTBACK;
15830 1499 callback_count = call_sv(*batch_svp, G_SCALAR | G_EVAL);
15831 1499 SPAGAIN;
15832 1499 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 1499 0 1499
if (SvTRUE(ERRSV)) { 3 1496 1499
15833 3 ▶ reason_sv = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
reason_sv = newSVsv(ERRSV); 3 0 3
15834 3 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 3 0 3
15835 1496 ▶ } else if (callback_count == 1) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (callback_count == 1) { 1496 0 1496
15836 1496 values_sv = newSVsv(POPs);
15837 }
15838 1499 PUTBACK;
15839 1499 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1499 0 1499
15840 1499 LEAVE;
15841 }
15842  
15843 1499 ▶ if (!reason_sv
Branch: 1 branch
BranchTrueFalseTotal
if (!reason_sv 1496 3 1499
15844 1496 ▶ && (!values_sv || !SvROK(values_sv)
Branch: 2 branches
BranchTrueFalseTotal
&& (!values_sv || !SvROK(values_sv) 1496 0 1496
&& (!values_sv || !SvROK(values_sv) 1496 0 1496
15845 1496 ▶ || SvTYPE(SvRV(values_sv)) != SVt_PVAV
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(values_sv)) != SVt_PVAV 1496 0 1496
15846 1496 ▶ || av_count((AV *)SvRV(values_sv)) != chunk_count)) {
Branch: 1 branch
BranchTrueFalseTotal
|| av_count((AV *)SvRV(values_sv)) != chunk_count)) { 0 1496 1496
15847 0 reason_sv = newSVpvs(
15848 "DataLoader batch function must return an arrayref with one entry per key\n"
15849 );
15850 }
15851  
15852 3516 ▶ for (i = 0; i < chunk_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < chunk_count; i++) { 2017 1499 3516
15853 2017 SV **entry_svp = av_fetch(queue_av, (SSize_t)(offset + i), 0);
15854 2017 AV *entry_av = (AV *)SvRV(*entry_svp);
15855 2017 SV **ticket_svp = av_fetch(entry_av, 1, 0);
15856 2017 ▶ if (!ticket_svp || !*ticket_svp
Branch: 2 branches
BranchTrueFalseTotal
if (!ticket_svp || !*ticket_svp 2017 0 2017
if (!ticket_svp || !*ticket_svp 2017 0 2017
15857 2017 ▶ || !gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ *ticket_svp)) {
Branch: 1 branch
BranchTrueFalseTotal
|| !gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ *ticket_svp)) { 0 2017 2017
15858 0 SvREFCNT_dec(values_sv);
15859 0 SvREFCNT_dec(reason_sv);
15860 0 croak("invalid DataLoader ticket at index %ld", (long)(offset + i));
15861 }
15862 2017 ▶ if (reason_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (reason_sv) { 3 2014 2017
15863 3 gql_runtime_vm_settle_dataloader_ticket(
15864 aTHX_ *ticket_svp, 2, reason_sv
15865 );
15866 } else {
15867 2014 AV *values_av = (AV *)SvRV(values_sv);
15868 2014 SV **value_svp = av_fetch(values_av, (SSize_t)i, 0);
15869 2014 ▶ SV *value_sv = (value_svp && *value_svp)
Branch: 1 branch
BranchTrueFalseTotal
SV *value_sv = (value_svp && *value_svp) 2014 0 2014
15870 ? *value_svp
15871 4028 ▶ : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
: &PL_sv_undef; 2014 0 2014
15872 2014 ▶ if (sv_isobject(value_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(value_sv) 6 2008 2014
15873 6 ▶ && sv_derived_from(
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from( 6 0 6
15874 value_sv, "GraphQL::Houtou::DataLoader::Error"
15875 6 )) {
15876 6 SV *entry_reason_sv = &PL_sv_undef;
15877 6 ▶ if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) { 6 0 6
if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) { 6 0 6
15878 6 SV **message_svp = hv_fetch(
15879 (HV *)SvRV(value_sv), "message", 7, 0
15880 );
15881 6 ▶ if (message_svp && *message_svp) {
Branch: 2 branches
BranchTrueFalseTotal
if (message_svp && *message_svp) { 6 0 6
if (message_svp && *message_svp) { 6 0 6
15882 6 entry_reason_sv = *message_svp;
15883 }
15884 }
15885 6 gql_runtime_vm_settle_dataloader_ticket(
15886 aTHX_ *ticket_svp, 2, entry_reason_sv
15887 );
15888 } else {
15889 2008 gql_runtime_vm_settle_dataloader_ticket(
15890 aTHX_ *ticket_svp, 1, value_sv
15891 );
15892 }
15893 }
15894 }
15895 1499 dispatched += (IV)chunk_count;
15896 1499 SvREFCNT_dec(values_sv);
15897 1499 SvREFCNT_dec(reason_sv);
15898 }
15899 1497 ▶ RETVAL = dispatched;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = dispatched; 1487 10 1497
15900 OUTPUT:
15901 RETVAL
15902  
15903 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::DataLoader::Ticket
15904  
15905 SV *
15906 new(class, async_adapter = &PL_sv_undef)
15907 SV *class
15908 SV *async_adapter
15909 CODE:
15910 (void)class;
15911 36 RETVAL = gql_runtime_vm_new_dataloader_ticket_sv(
15912 aTHX_ 0, &PL_sv_undef, async_adapter
15913 );
15914 OUTPUT:
15915 RETVAL
15916  
15917 SV *
15918 resolved(class, value, async_adapter = &PL_sv_undef)
15919 SV *class
15920 SV *value
15921 SV *async_adapter
15922 CODE:
15923 (void)class;
15924 7 RETVAL = gql_runtime_vm_new_dataloader_ticket_sv(
15925 aTHX_ 1, value, async_adapter
15926 );
15927 OUTPUT:
15928 RETVAL
15929  
15930 SV *
15931 _resolve(self, value)
15932 SV *self
15933 SV *value
15934 CODE:
15935 34 gql_runtime_vm_settle_dataloader_ticket(aTHX_ self, 1, value);
15936 34 RETVAL = self;
15937 34 SvREFCNT_inc_simple_void_NN(RETVAL);
15938 OUTPUT:
15939 RETVAL
15940  
15941 SV *
15942 _reject(self, reason)
15943 SV *self
15944 SV *reason
15945 CODE:
15946 3 gql_runtime_vm_settle_dataloader_ticket(aTHX_ self, 2, reason);
15947 3 RETVAL = self;
15948 3 SvREFCNT_inc_simple_void_NN(RETVAL);
15949 OUTPUT:
15950 RETVAL
15951  
15952 IV
15953 _settle_batch(class, entries_sv, values_sv)
15954 SV *class
15955 SV *entries_sv
15956 SV *values_sv
15957 PREINIT:
15958 AV *entries_av;
15959 AV *values_av;
15960 Size_t count;
15961 Size_t i;
15962 CODE:
15963 (void)class;
15964 0 ▶ if (!entries_sv || !SvROK(entries_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (!entries_sv || !SvROK(entries_sv) 0 0 0
if (!entries_sv || !SvROK(entries_sv) 0 0 0
15965 0 ▶ || SvTYPE(SvRV(entries_sv)) != SVt_PVAV
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(entries_sv)) != SVt_PVAV 0 0 0
15966 0 ▶ || !values_sv || !SvROK(values_sv)
Branch: 2 branches
BranchTrueFalseTotal
|| !values_sv || !SvROK(values_sv) 0 0 0
|| !values_sv || !SvROK(values_sv) 0 0 0
15967 0 ▶ || SvTYPE(SvRV(values_sv)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(values_sv)) != SVt_PVAV) { 0 0 0
15968 0 croak("DataLoader ticket batch settlement requires array references");
15969 }
15970 0 entries_av = (AV *)SvRV(entries_sv);
15971 0 values_av = (AV *)SvRV(values_sv);
15972 0 count = av_count(entries_av);
15973 0 ▶ if (av_count(values_av) != count) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_count(values_av) != count) { 0 0 0
15974 0 croak("DataLoader ticket batch settlement length mismatch");
15975 }
15976 0 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 0 0 0
15977 0 SV **entry_svp = av_fetch(entries_av, i, 0);
15978 0 SV **value_svp = av_fetch(values_av, i, 0);
15979 0 ▶ SV *value_sv = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
SV *value_sv = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef; 0 0 0
SV *value_sv = (value_svp && *value_svp) ? *value_svp : &PL_sv_undef; 0 0 0
15980 AV *entry_av;
15981 SV **ticket_svp;
15982  
15983 0 ▶ if (!entry_svp || !*entry_svp || !SvROK(*entry_svp)
Branch: 3 branches
BranchTrueFalseTotal
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 0 0 0
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 0 0 0
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 0 0 0
15984 0 ▶ || SvTYPE(SvRV(*entry_svp)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*entry_svp)) != SVt_PVAV) { 0 0 0
15985 0 croak("invalid DataLoader queue entry at index %ld", (long)i);
15986 }
15987 0 entry_av = (AV *)SvRV(*entry_svp);
15988 0 ticket_svp = av_fetch(entry_av, 1, 0);
15989 0 ▶ if (!ticket_svp || !*ticket_svp
Branch: 2 branches
BranchTrueFalseTotal
if (!ticket_svp || !*ticket_svp 0 0 0
if (!ticket_svp || !*ticket_svp 0 0 0
15990 0 ▶ || !gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ *ticket_svp)) {
Branch: 1 branch
BranchTrueFalseTotal
|| !gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ *ticket_svp)) { 0 0 0
15991 0 croak("invalid DataLoader ticket at index %ld", (long)i);
15992 }
15993  
15994 0 ▶ if (sv_isobject(value_sv)
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(value_sv) 0 0 0
15995 0 ▶ && sv_derived_from(value_sv, "GraphQL::Houtou::DataLoader::Error")) {
Branch: 1 branch
BranchTrueFalseTotal
&& sv_derived_from(value_sv, "GraphQL::Houtou::DataLoader::Error")) { 0 0 0
15996 0 SV *reason_sv = &PL_sv_undef;
15997 0 ▶ if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) { 0 0 0
if (SvROK(value_sv) && SvTYPE(SvRV(value_sv)) == SVt_PVHV) { 0 0 0
15998 0 SV **message_svp = hv_fetch((HV *)SvRV(value_sv), "message", 7, 0);
15999 0 ▶ if (message_svp && *message_svp) {
Branch: 2 branches
BranchTrueFalseTotal
if (message_svp && *message_svp) { 0 0 0
if (message_svp && *message_svp) { 0 0 0
16000 0 reason_sv = *message_svp;
16001 }
16002 }
16003 0 gql_runtime_vm_settle_dataloader_ticket(
16004 aTHX_ *ticket_svp, 2, reason_sv
16005 );
16006 } else {
16007 0 gql_runtime_vm_settle_dataloader_ticket(
16008 aTHX_ *ticket_svp, 1, value_sv
16009 );
16010 }
16011 }
16012 0 ▶ RETVAL = (IV)count;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)count; 0 0 0
16013 OUTPUT:
16014 RETVAL
16015  
16016 IV
16017 _reject_batch(class, entries_sv, reason_sv)
16018 SV *class
16019 SV *entries_sv
16020 SV *reason_sv
16021 PREINIT:
16022 AV *entries_av;
16023 Size_t count;
16024 Size_t i;
16025 CODE:
16026 (void)class;
16027 0 ▶ if (!entries_sv || !SvROK(entries_sv)
Branch: 2 branches
BranchTrueFalseTotal
if (!entries_sv || !SvROK(entries_sv) 0 0 0
if (!entries_sv || !SvROK(entries_sv) 0 0 0
16028 0 ▶ || SvTYPE(SvRV(entries_sv)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(entries_sv)) != SVt_PVAV) { 0 0 0
16029 0 croak("DataLoader ticket batch rejection requires an array reference");
16030 }
16031 0 entries_av = (AV *)SvRV(entries_sv);
16032 0 count = av_count(entries_av);
16033 0 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 0 0 0
16034 0 SV **entry_svp = av_fetch(entries_av, i, 0);
16035 AV *entry_av;
16036 SV **ticket_svp;
16037  
16038 0 ▶ if (!entry_svp || !*entry_svp || !SvROK(*entry_svp)
Branch: 3 branches
BranchTrueFalseTotal
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 0 0 0
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 0 0 0
if (!entry_svp || !*entry_svp || !SvROK(*entry_svp) 0 0 0
16039 0 ▶ || SvTYPE(SvRV(*entry_svp)) != SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
|| SvTYPE(SvRV(*entry_svp)) != SVt_PVAV) { 0 0 0
16040 0 croak("invalid DataLoader queue entry at index %ld", (long)i);
16041 }
16042 0 entry_av = (AV *)SvRV(*entry_svp);
16043 0 ticket_svp = av_fetch(entry_av, 1, 0);
16044 0 ▶ if (!ticket_svp || !*ticket_svp
Branch: 2 branches
BranchTrueFalseTotal
if (!ticket_svp || !*ticket_svp 0 0 0
if (!ticket_svp || !*ticket_svp 0 0 0
16045 0 ▶ || !gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ *ticket_svp)) {
Branch: 1 branch
BranchTrueFalseTotal
|| !gql_runtime_vm_sv_is_dataloader_ticket(aTHX_ *ticket_svp)) { 0 0 0
16046 0 croak("invalid DataLoader ticket at index %ld", (long)i);
16047 }
16048 0 gql_runtime_vm_settle_dataloader_ticket(
16049 aTHX_ *ticket_svp, 2, reason_sv
16050 );
16051 }
16052 0 ▶ RETVAL = (IV)count;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (IV)count; 0 0 0
16053 OUTPUT:
16054 RETVAL
16055  
16056 void
16057 _subscribe_native(self, resolve, reject)
16058 SV *self
16059 SV *resolve
16060 SV *reject
16061 CODE:
16062 27 gql_runtime_vm_subscribe_dataloader_ticket(aTHX_ self, resolve, reject);
16063  
16064 SV *
16065 _subscribe(self, resolve, reject)
16066 SV *self
16067 SV *resolve
16068 SV *reject
16069 CODE:
16070 1351 RETVAL = gql_runtime_vm_chain_dataloader_ticket(
16071 aTHX_ self, resolve, reject
16072 );
16073 OUTPUT:
16074 RETVAL
16075  
16076 bool
16077 AWAIT_IS_READY(self)
16078 SV *self
16079 CODE:
16080 8 ▶ RETVAL = gql_runtime_vm_dataloader_ticket_state(aTHX_ self) != 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = gql_runtime_vm_dataloader_ticket_state(aTHX_ self) != 0; 6 2 8
16081 OUTPUT:
16082 RETVAL
16083  
16084 SV *
16085 AWAIT_GET(self)
16086 SV *self
16087 PREINIT:
16088 IV state;
16089 CODE:
16090 12 state = gql_runtime_vm_dataloader_ticket_state(aTHX_ self);
16091 12 ▶ if (state == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (state == 0) { 1 11 12
16092 1 croak("DataLoader ticket is not ready");
16093 }
16094 11 ▶ if (state == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (state == 2) { 4 7 11
16095 4 croak_sv(gql_runtime_vm_dataloader_ticket_value(aTHX_ self));
16096 }
16097 7 RETVAL = newSVsv(gql_runtime_vm_dataloader_ticket_value(aTHX_ self));
16098 OUTPUT:
16099 RETVAL
16100  
16101 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::Cursor
16102  
16103 void
16104 DESTROY(self)
16105 SV *self
16106 CODE:
16107 0 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 0 0 0
if (self && SvROK(self)) { 0 0 0
16108 0 SV *inner_sv = SvRV(self);
16109 0 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
16110 0 gql_runtime_vm_cursor_t *cursor = INT2PTR(gql_runtime_vm_cursor_t *, SvUV(inner_sv));
16111 0 sv_setuv(inner_sv, 0);
16112 0 gql_runtime_vm_cursor_decref(aTHX_ cursor);
16113 }
16114 }
16115  
16116 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::FieldFrame
16117  
16118 void
16119 DESTROY(self)
16120 SV *self
16121 CODE:
16122 0 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 0 0 0
if (self && SvROK(self)) { 0 0 0
16123 0 SV *inner_sv = SvRV(self);
16124 0 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
16125 0 gql_runtime_vm_field_frame_t *frame = INT2PTR(gql_runtime_vm_field_frame_t *, SvUV(inner_sv));
16126 0 sv_setuv(inner_sv, 0);
16127 0 gql_runtime_vm_free_field_frame(aTHX_ frame);
16128 }
16129 }
16130  
16131 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::LazyInfo
16132  
16133 void
16134 DESTROY(self)
16135 SV *self
16136 CODE:
16137 10987 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 10987 0 10987
if (self && SvROK(self)) { 10987 0 10987
16138 10987 SV *inner_sv = SvRV(self);
16139 10987 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 10987 0 10987
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 10987 0 10987
16140 10987 gql_runtime_vm_lazy_info_t *info = INT2PTR(gql_runtime_vm_lazy_info_t *, SvUV(inner_sv));
16141 10987 sv_setuv(inner_sv, 0);
16142 10987 gql_runtime_vm_lazy_info_decref(aTHX_ info);
16143 }
16144 }
16145  
16146 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::PathFrame
16147  
16148 void
16149 DESTROY(self)
16150 SV *self
16151 CODE:
16152 0 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 0 0 0
if (self && SvROK(self)) { 0 0 0
16153 0 SV *inner_sv = SvRV(self);
16154 0 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
16155 0 gql_runtime_vm_path_frame_t *frame = INT2PTR(gql_runtime_vm_path_frame_t *, SvUV(inner_sv));
16156 0 sv_setuv(inner_sv, 0);
16157 0 gql_runtime_vm_path_frame_decref(frame);
16158 }
16159 }
16160  
16161 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::BlockFrame
16162  
16163 void
16164 DESTROY(self)
16165 SV *self
16166 CODE:
16167 3600 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 3600 0 3600
if (self && SvROK(self)) { 3600 0 3600
16168 3600 SV *inner_sv = SvRV(self);
16169 3600 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 3600 0 3600
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 3600 0 3600
16170 3600 gql_runtime_vm_block_frame_t *frame = INT2PTR(gql_runtime_vm_block_frame_t *, SvUV(inner_sv));
16171 3600 sv_setuv(inner_sv, 0);
16172 3600 gql_runtime_vm_free_block_frame(aTHX_ frame);
16173 }
16174 }
16175  
16176 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::ListPending
16177  
16178 void
16179 DESTROY(self)
16180 SV *self
16181 CODE:
16182 648 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 648 0 648
if (self && SvROK(self)) { 648 0 648
16183 648 SV *inner_sv = SvRV(self);
16184 648 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 648 0 648
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 648 0 648
16185 648 gql_runtime_vm_list_pending_t *pending = INT2PTR(gql_runtime_vm_list_pending_t *, SvUV(inner_sv));
16186 648 sv_setuv(inner_sv, 0);
16187 648 gql_runtime_vm_list_pending_decref(aTHX_ pending);
16188 }
16189 }
16190  
16191 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::ErrorRecord
16192  
16193 void
16194 DESTROY(self)
16195 SV *self
16196 CODE:
16197 0 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 0 0 0
if (self && SvROK(self)) { 0 0 0
16198 0 SV *inner_sv = SvRV(self);
16199 0 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
16200 0 gql_runtime_vm_error_record_t *record = INT2PTR(gql_runtime_vm_error_record_t *, SvUV(inner_sv));
16201 0 sv_setuv(inner_sv, 0);
16202 0 gql_runtime_vm_error_record_decref(aTHX_ record);
16203 }
16204 }
16205  
16206 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::Outcome
16207  
16208 void
16209 DESTROY(self)
16210 SV *self
16211 CODE:
16212 488 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 488 0 488
if (self && SvROK(self)) { 488 0 488
16213 488 SV *inner_sv = SvRV(self);
16214 488 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 488 0 488
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 488 0 488
16215 488 gql_runtime_vm_outcome_t *outcome = INT2PTR(gql_runtime_vm_outcome_t *, SvUV(inner_sv));
16216 488 sv_setuv(inner_sv, 0);
16217 488 gql_runtime_vm_outcome_decref(aTHX_ outcome);
16218 }
16219 }
16220  
16221 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::Writer
16222  
16223 void
16224 DESTROY(self)
16225 SV *self
16226 CODE:
16227 0 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 0 0 0
if (self && SvROK(self)) { 0 0 0
16228 0 SV *inner_sv = SvRV(self);
16229 0 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
16230 0 gql_runtime_vm_writer_t *writer = INT2PTR(gql_runtime_vm_writer_t *, SvUV(inner_sv));
16231 0 sv_setuv(inner_sv, 0);
16232 0 gql_runtime_vm_writer_decref(aTHX_ writer);
16233 }
16234 }
16235  
16236 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::PendingMerge
16237  
16238 void
16239 DESTROY(self)
16240 SV *self
16241 CODE:
16242 0 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 0 0 0
if (self && SvROK(self)) { 0 0 0
16243 0 SV *inner_sv = SvRV(self);
16244 0 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 0 0 0
16245 0 gql_runtime_vm_pending_merge_t *merge = INT2PTR(gql_runtime_vm_pending_merge_t *, SvUV(inner_sv));
16246 0 sv_setuv(inner_sv, 0);
16247 0 gql_runtime_vm_pending_merge_decref(aTHX_ merge);
16248 }
16249 }
16250  
16251 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::ExecState
16252  
16253 void
16254 DESTROY(self)
16255 SV *self
16256 CODE:
16257 1600 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 1600 0 1600
if (self && SvROK(self)) { 1600 0 1600
16258 1600 SV *inner_sv = SvRV(self);
16259 1600 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 1600 0 1600
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 1600 0 1600
16260 1600 gql_runtime_vm_exec_state_handle_t *state = INT2PTR(gql_runtime_vm_exec_state_handle_t *, SvUV(inner_sv));
16261 1600 sv_setuv(inner_sv, 0);
16262 1600 SvREFCNT_dec(state->runtime_schema);
16263 1600 SvREFCNT_dec(state->program);
16264 1600 ▶ if (state->native_runtime && !state->native_runtime_is_borrowed) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->native_runtime && !state->native_runtime_is_borrowed) { 1600 0 1600
if (state->native_runtime && !state->native_runtime_is_borrowed) { 0 1600 1600
16265 0 gql_runtime_vm_native_runtime_destroy(state->native_runtime);
16266 }
16267 1600 gql_runtime_vm_cursor_decref(aTHX_ state->cursor);
16268 /* A suspended response frame lives only in response_frame: the
16269 * scheduler popped it off frame_stack, and resolve_frame (which
16270 * pairs the field's NULLing with releasing the allocation
16271 * reference) never ran for an abandoned request. Release that
16272 * reference here - unless the frame is still on the stack, whose
16273 * teardown below owns it (R5 leak 2). */
16274 1600 ▶ if (state->response_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (state->response_frame) { 50 1550 1600
16275 IV rf_i;
16276 50 int rf_on_stack = (state->frame == state->response_frame);
16277 50 ▶ for (rf_i = 0; !rf_on_stack && rf_i < state->frame_stack_count; rf_i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (rf_i = 0; !rf_on_stack && rf_i < state->frame_stack_count; rf_i++) { 48 2 50
for (rf_i = 0; !rf_on_stack && rf_i < state->frame_stack_count; rf_i++) { 0 48 48
16278 0 rf_on_stack = (state->frame_stack[rf_i] == state->response_frame);
16279 }
16280 50 ▶ if (!rf_on_stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (!rf_on_stack) { 48 2 50
16281 48 gql_runtime_vm_free_block_frame(aTHX_ state->response_frame);
16282 }
16283 50 state->response_frame = NULL;
16284 }
16285 1600 ▶ if (state->frame && state->frame_stack_count == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (state->frame && state->frame_stack_count == 0) { 2 1598 1600
if (state->frame && state->frame_stack_count == 0) { 0 2 2
16286 0 gql_runtime_vm_free_block_frame(aTHX_ state->frame);
16287 }
16288 1602 ▶ while (state->frame_stack_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (state->frame_stack_count > 0) { 2 1600 1602
16289 2 gql_runtime_vm_free_block_frame(aTHX_ state->frame_stack[--state->frame_stack_count]);
16290 2 state->frame_stack[state->frame_stack_count] = NULL;
16291 }
16292 1600 Safefree(state->frame_stack);
16293 1600 Safefree(state->async_ready_frames);
16294 1600 state->frame = NULL;
16295 1600 gql_runtime_vm_free_field_frame(aTHX_ state->field_frame);
16296 1600 state->field_frame = NULL;
16297 1600 gql_runtime_vm_writer_decref(aTHX_ state->writer);
16298 1600 SvREFCNT_dec(state->context);
16299 1600 SvREFCNT_dec(state->variables);
16300 1600 SvREFCNT_dec(state->root_value);
16301 1600 SvREFCNT_dec(state->empty_args);
16302 1600 SvREFCNT_dec(state->completed_response_sv);
16303 1600 SvREFCNT_dec(state->native_runtime_owner_sv);
16304 1600 Safefree(state);
16305 }
16306 }
16307  
16308 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::NativeBundle
16309  
16310 void
16311 DESTROY(self)
16312 SV *self
16313 CODE:
16314 28 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 28 0 28
if (self && SvROK(self)) { 28 0 28
16315 28 SV *inner_sv = SvRV(self);
16316 28 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 28 0 28
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 28 0 28
16317 28 gql_runtime_vm_native_bundle_t *bundle =
16318 28 INT2PTR(gql_runtime_vm_native_bundle_t *, SvUV(inner_sv));
16319 28 sv_setuv(inner_sv, 0);
16320 28 gql_runtime_vm_native_bundle_destroy(bundle);
16321 }
16322 }
16323  
16324 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::NativeProgram
16325  
16326 void
16327 DESTROY(self)
16328 SV *self
16329 CODE:
16330 480 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 480 0 480
if (self && SvROK(self)) { 480 0 480
16331 480 SV *inner_sv = SvRV(self);
16332 480 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 480 0 480
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 480 0 480
16333 480 gql_runtime_vm_native_program_t *program =
16334 480 INT2PTR(gql_runtime_vm_native_program_t *, SvUV(inner_sv));
16335 480 sv_setuv(inner_sv, 0);
16336 480 gql_runtime_vm_native_program_destroy(program);
16337 }
16338 }
16339  
16340 MODULE = GraphQL::Houtou PACKAGE = GraphQL::Houtou::Runtime::NativeRuntime
16341  
16342 void
16343 DESTROY(self)
16344 SV *self
16345 CODE:
16346 488 ▶ if (self && SvROK(self)) {
Branch: 2 branches
BranchTrueFalseTotal
if (self && SvROK(self)) { 488 0 488
if (self && SvROK(self)) { 488 0 488
16347 488 SV *inner_sv = SvRV(self);
16348 488 ▶ if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 241 247 488
if (SvIOK(inner_sv) && SvUV(inner_sv) != 0) { 241 0 241
16349 241 gql_runtime_vm_native_runtime_t *runtime =
16350 241 INT2PTR(gql_runtime_vm_native_runtime_t *, SvUV(inner_sv));
16351 241 sv_setuv(inner_sv, 0);
16352 241 gql_runtime_vm_native_runtime_destroy(runtime);
16353 }
16354 }
« src/parser_core.h ↑ Summary src/vm_runtime.h »