src/vm_runtime.h

filter: Statementstmt 71.2% 2224 / 3120 Branchbran 49.1% 1480 / 3012 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 60.4% 3704 / 6132 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/GraphQL/Houtou.xs ↑ Summary src/parser_shared_ast.h »
1 #ifndef GQL_RUNTIME_VM_H
2 #define GQL_RUNTIME_VM_H
3  
4 #include <stdlib.h>
5  
6 enum {
7 GQL_VM_RESOLVE_DEFAULT = 1,
8 GQL_VM_RESOLVE_EXPLICIT = 2
9 };
10  
11 enum {
12 GQL_VM_COMPLETE_GENERIC = 1,
13 GQL_VM_COMPLETE_OBJECT = 2,
14 GQL_VM_COMPLETE_LIST = 3,
15 GQL_VM_COMPLETE_ABSTRACT = 4
16 };
17  
18 enum {
19 GQL_VM_FAMILY_GENERIC = 1,
20 GQL_VM_FAMILY_OBJECT = 2,
21 GQL_VM_FAMILY_LIST = 3,
22 GQL_VM_FAMILY_ABSTRACT = 4
23 };
24  
25 enum {
26 GQL_VM_DISPATCH_GENERIC = 1,
27 GQL_VM_DISPATCH_RESOLVE_TYPE = 2,
28 GQL_VM_DISPATCH_TAG = 3,
29 GQL_VM_DISPATCH_POSSIBLE_TYPES = 4
30 };
31  
32 enum {
33 GQL_VM_ARGS_NONE = 0,
34 GQL_VM_ARGS_STATIC = 1,
35 GQL_VM_ARGS_DYNAMIC = 2
36 };
37  
38 enum {
39 GQL_VM_KIND_UNKNOWN = 0,
40 GQL_VM_KIND_SCALAR = 1,
41 GQL_VM_KIND_OBJECT = 2,
42 GQL_VM_KIND_LIST = 3,
43 GQL_VM_KIND_INTERFACE = 4,
44 GQL_VM_KIND_UNION = 5,
45 GQL_VM_KIND_ENUM = 6,
46 GQL_VM_KIND_INPUT_OBJECT = 7,
47 GQL_VM_KIND_NON_NULL = 8
48 };
49  
50 enum {
51 GQL_VM_OPTYPE_QUERY = 1,
52 GQL_VM_OPTYPE_MUTATION = 2,
53 GQL_VM_OPTYPE_SUBSCRIPTION = 3
54 };
55  
56 enum {
57 GQL_VM_GUARD_INCLUDE = 1,
58 GQL_VM_GUARD_SKIP = 2
59 };
60  
61 enum {
62 GQL_VM_CALLBACK_ABI_DEFAULT = 1,
63 GQL_VM_CALLBACK_ABI_EXPLICIT_GENERIC = 2,
64 GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE = 3,
65 GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS = 4,
66 GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG = 5
67 };
68  
69 enum {
70 GQL_VM_DYNAMIC_UNDEF = 0,
71 GQL_VM_DYNAMIC_SCALAR = 1,
72 GQL_VM_DYNAMIC_VARIABLE = 2,
73 GQL_VM_DYNAMIC_LIST = 3,
74 GQL_VM_DYNAMIC_OBJECT = 4
75 };
76  
77 #define GQL_VM_OPCODE(resolve_code, complete_code) (((resolve_code) * 16) + (complete_code))
78  
79 typedef struct gql_runtime_vm_native_value gql_runtime_vm_native_value_t;
80 typedef struct gql_runtime_vm_native_dynamic_value gql_runtime_vm_native_dynamic_value_t;
81 typedef struct gql_runtime_vm_list_pending_t gql_runtime_vm_list_pending_t;
82  
83 typedef struct {
84 char *name;
85 SV *type_def_sv;
86 SV *input_type_sv;
87 U8 has_default;
88 /* Lazily cached isa(NonNull) of input_type_sv so the missing-variable
89 * check costs no method lookup per request: 0 unknown, 1 non-null,
90 * 2 nullable. Newxz zero-fill leaves fresh defs at "unknown". */
91 U8 input_type_nonnull_state;
92 SV *default_value_sv;
93 gql_runtime_vm_native_value_t *default_native_value;
94 } gql_runtime_vm_native_arg_def_t;
95  
96 typedef struct {
97 IV count;
98 char **names;
99 gql_runtime_vm_native_dynamic_value_t **values;
100 SV *static_args_sv;
101 SV *static_one_arg_sv;
102 } gql_runtime_vm_native_args_payload_t;
103  
104 typedef struct {
105 IV kind_code;
106 gql_runtime_vm_native_dynamic_value_t *if_expr;
107 } gql_runtime_vm_native_guard_t;
108  
109 typedef struct {
110 IV count;
111 gql_runtime_vm_native_guard_t *guards;
112 } gql_runtime_vm_native_directives_payload_t;
113  
114 typedef struct {
115 char *field_name;
116 STRLEN field_name_len;
117 char *result_name;
118 STRLEN result_name_len;
119 char *return_type_name;
120 char *accessor_name;
121 STRLEN accessor_name_len;
122 HV *accessor_cache_stash;
123 GV *accessor_cache_gv;
124 U32 accessor_cache_generation;
125 U8 accessor_cache_initialized;
126 IV schema_slot_index;
127 IV resolver_shape_code;
128 IV resolver_mode_code;
129 IV callback_abi_code;
130 IV completion_family_code;
131 IV dispatch_family_code;
132 IV return_type_kind_code;
133 IV arg_def_count;
134 gql_runtime_vm_native_arg_def_t *arg_defs;
135 U8 has_args;
136 U8 has_directives;
137 /* Non-Null propagation (spec 6.4.4): return_type_kind_code == 8 marks
138 * the field position itself non-null; item_non_null marks a list
139 * field's item positions ([T!]). */
140 U8 item_non_null;
141 } gql_runtime_vm_native_slot_t;
142  
143 typedef struct {
144 char *tag_name;
145 char *type_name;
146 } gql_runtime_vm_native_tag_entry_t;
147  
148 typedef struct {
149 char *type_name;
150 SV *type_sv;
151 SV *is_type_of_cb;
152 } gql_runtime_vm_native_possible_type_entry_t;
153  
154 /* Leaf result coercion kinds, shared with Schema::prepare_runtime's
155 * leaf_kind_map. 0 = not a leaf type (or unknown: no coercion). */
156 #define GQL_VM_LEAF_NONE 0
157 #define GQL_VM_LEAF_INT 1
158 #define GQL_VM_LEAF_FLOAT 2
159 #define GQL_VM_LEAF_STRING 3
160 #define GQL_VM_LEAF_BOOLEAN 4
161 #define GQL_VM_LEAF_ID 5
162 #define GQL_VM_LEAF_ENUM 6
163 #define GQL_VM_LEAF_CUSTOM 7
164  
165 typedef struct {
166 char *context_key;
167 STRLEN context_key_len;
168 char *key_name;
169 STRLEN key_name_len;
170 IV key_arg_index;
171 char *route_key_name;
172 STRLEN route_key_name_len;
173 IV route_key_arg_index;
174 /* 1 = source hash key, 2 = GraphQL argument. */
175 U8 key_kind;
176 U8 route_key_kind;
177 U8 uses_router;
178 } gql_runtime_vm_native_loader_spec_t;
179  
180 typedef struct {
181 SV *runtime_schema;
182 SV **slot_field_names;
183 SV **slot_resolvers;
184 SV **slot_loader_specs;
185 gql_runtime_vm_native_loader_spec_t **slot_native_loader_specs;
186 SV **slot_type_objects;
187 SV **slot_tag_resolvers;
188 SV **slot_resolve_types;
189 gql_runtime_vm_native_tag_entry_t **slot_tag_entries;
190 IV *slot_tag_entry_counts;
191 gql_runtime_vm_native_possible_type_entry_t **slot_possible_type_entries;
192 IV *slot_possible_type_entry_counts;
193 /* Leaf result coercion per slot: kind code, and for ENUM the
194 * value-to-name HV ref / for CUSTOM the serialize CV. */
195 IV *slot_leaf_kinds;
196 SV **slot_leaf_payloads;
197 } gql_runtime_vm_native_callback_catalog_t;
198  
199 typedef struct {
200 char **abstract_child_names;
201 IV *abstract_child_indexes;
202 IV opcode_code;
203 IV resolve_code;
204 IV complete_code;
205 IV dispatch_family_code;
206 IV slot_index;
207 IV child_block_index;
208 IV abstract_child_count;
209 IV args_mode_code;
210 IV directives_mode_code;
211 IV args_payload_index;
212 IV directives_payload_index;
213 gql_runtime_vm_native_args_payload_t *args_payload_native;
214 gql_runtime_vm_native_directives_payload_t *directives_payload_native;
215 U8 has_args;
216 U8 has_directives;
217 IV runtime_directives_mode_code;
218 SV *runtime_directives_sv;
219 U8 has_runtime_directives;
220 } gql_runtime_vm_native_op_t;
221  
222 typedef struct {
223 IV family_code;
224 /* 0 = unchecked, 1 = ineligible, 2 = structurally eligible for the
225 * plain-hash scalar projection fast path. Runtime source values are
226 * still checked per row. */
227 U8 plain_hash_projection_state;
228 char *type_name;
229 SV *type_object_sv;
230 IV slot_count;
231 IV op_count;
232 gql_runtime_vm_native_slot_t *slots;
233 gql_runtime_vm_native_op_t *ops;
234 } gql_runtime_vm_native_block_t;
235  
236 typedef struct {
237 IV runtime_slot_count;
238 gql_runtime_vm_native_slot_t *runtime_slots;
239 gql_runtime_vm_native_callback_catalog_t *callback_catalog;
240 gql_runtime_vm_async_adapter_t *async_adapter;
241 } gql_runtime_vm_native_runtime_t;
242  
243 typedef struct {
244 IV operation_type_code;
245 IV root_block_index;
246 IV runtime_slot_count;
247 IV block_count;
248 U8 owns_runtime_slots;
249 U8 owns_blocks;
250 SV *prepared_runtime_schema;
251 gql_runtime_vm_native_slot_t *runtime_slots;
252 gql_runtime_vm_native_block_t *blocks;
253 } gql_runtime_vm_native_bundle_t;
254  
255 typedef struct {
256 IV version;
257 char *operation_name;
258 IV operation_type_code;
259 IV root_block_index;
260 IV variable_def_count;
261 IV block_count;
262 IV args_payload_count;
263 IV directives_payload_count;
264 gql_runtime_vm_native_arg_def_t *variable_defs;
265 gql_runtime_vm_native_block_t *blocks;
266 gql_runtime_vm_native_args_payload_t **args_payloads;
267 gql_runtime_vm_native_directives_payload_t **directives_payloads;
268 gql_runtime_vm_native_runtime_t *cached_bundle_runtime;
269 gql_runtime_vm_native_bundle_t *cached_bundle;
270 /* 0 = not computed yet, 1 = no, 2 = yes: whether any op carries custom
271 * runtime directives that require per-request program specialization.
272 * Built-in include/skip guards are evaluated in the fused execution lane.
273 * Zero-init via Newxz means "not computed". */
274 IV needs_variable_specialization;
275 } gql_runtime_vm_native_program_t;
276  
277 typedef struct gql_runtime_vm_path_frame gql_runtime_vm_path_frame_t;
278 typedef struct gql_runtime_vm_outcome gql_runtime_vm_outcome_t;
279 typedef struct gql_runtime_vm_cursor_t gql_runtime_vm_cursor_t;
280 typedef struct gql_runtime_vm_field_frame_t gql_runtime_vm_field_frame_t;
281 typedef struct gql_runtime_vm_block_frame_t gql_runtime_vm_block_frame_t;
282 typedef struct gql_runtime_vm_writer_t gql_runtime_vm_writer_t;
283 typedef struct gql_runtime_vm_pending_entry_t gql_runtime_vm_pending_entry_t;
284 typedef struct gql_runtime_vm_callback_context gql_runtime_vm_callback_context_t;
285 typedef struct gql_runtime_vm_lazy_info gql_runtime_vm_lazy_info_t;
286  
287 struct gql_runtime_vm_callback_context {
288 SV *runtime_schema;
289 SV *program;
290 SV *context;
291 SV *variables;
292 SV *root_value;
293 /* Request-local prepared variables in native program definition order.
294 * Fused sync lanes borrow this array from their XSUB stack. */
295 SV **variable_slots;
296 IV variable_slot_count;
297 gql_runtime_vm_native_program_t *native_program;
298 SV *provided_variables;
299 /* Owned only when an AV-backed slot request has to expose the legacy
300 * prepared variables HashRef to generic callbacks or nested values. */
301 SV *materialized_variables;
302 };
303  
304 typedef struct {
305 gql_runtime_vm_native_runtime_t *runtime;
306 SV *runtime_handle_sv;
307 gql_runtime_vm_native_bundle_t *bundle;
308 gql_runtime_vm_callback_context_t *callback_ctx;
309 gql_runtime_vm_path_frame_t *path_frame;
310 int path_frame_is_current_field;
311 SV *empty_args_sv;
312 /* The request's program SV (the Perl-visible handle wrapping
313 * callback_ctx->native_program) and the true root block index, needed
314 * only when the fast lane must lazily promote to a real
315 * exec_state_handle_t (see gql_runtime_vm_ensure_fast_lane_state_sv) -
316 * stored here (rather than threaded through every intervening function
317 * signature) so a promotion trigger point nested arbitrarily deep in the
318 * dispatch chain (e.g. inside an object list item's own child block,
319 * where block_index above has already been overwritten with the ITEM's
320 * own block index) can still reach the true root block index. Set once,
321 * never overwritten, unlike block_index. */
322 SV *program_sv;
323 IV fast_lane_root_block_index;
324 gql_runtime_vm_writer_t *writer;
325 const gql_runtime_vm_native_block_t *block;
326 const gql_runtime_vm_native_op_t *op;
327 const gql_runtime_vm_native_slot_t *slot;
328 IV block_index;
329 IV op_index;
330 /* Non-Null propagation scratch: set when a block/list just nulled
331 * itself over a non-null violation (the field error is already
332 * recorded), consumed by the enclosing field/item check so propagation
333 * does not add one error per level. */
334 U8 null_carries_error;
335 /* Sync-first suspension channel. Disabled on the strict sync lanes.
336 * When enabled, a promise-returning resolver transfers the owned promise
337 * SV here and the fast block loop unwinds without completing or storing
338 * the current field. A continuation owner must take and clear the SV
339 * before destroying this state. */
340 U8 fast_lane_can_suspend;
341 SV *fast_lane_suspended_sv;
342 /* Deferred croak channel for the sync fast lanes: croaking from inside
343 * the lane longjmps past the recursion that owns the live path frame
344 * chain and leaks it. Detection sites (promise-returning resolver,
345 * request-time argument coercion failure) store the first error here
346 * instead - a plain string croaks as an exception, a blessed
347 * GraphQL::Houtou::Error becomes a request-error envelope at the Perl
348 * boundary - and the top-level entry croak_sv()s it after cleanup. */
349 SV *fast_lane_deferred_croak_sv;
350 /* Item-level suspension channel for a list field, parallel to
351 * fast_lane_suspended_sv: when a list field's own resolver result
352 * settles to an array whose items are still pending (rather than the
353 * field's own call being pending), gql_runtime_vm_complete_current_list_fast_sv
354 * stashes the raw, not-yet-item-completed array here instead of
355 * completing (or, on the strict sync lanes, deferred-croaking) each item
356 * in place - a continuation owner must take and clear this before
357 * destroying this state, same contract as fast_lane_suspended_sv. */
358 SV *fast_lane_list_pending_source_sv;
359 /* Request-scoped exec_state_handle_t SV, shared between field-level
360 * suspension, leaf item-level list pending (fast_lane_list_pending_source_sv)
361 * and object/abstract item-level list pending (Phase 5,
362 * fast_lane_list_pending_result_sv below): a suspension discovered deep
363 * inside an item's own child block (nested under
364 * gql_runtime_vm_complete_current_list_fast_sv) needs this same handle to
365 * finalize that item's own child block_frame, without constructing a
366 * second, redundant handle for the same request. Built at most once per
367 * request; the owning root frame's response_frame pointer is kept in
368 * sync by whichever caller (always the root per-op loop) owns the root
369 * block_frame_t itself - this field only ever holds the handle SV. */
370 SV *fast_lane_root_state_sv;
371 /* Result of the object/abstract list item loop already having done the
372 * safe, exactly-once-preserving per-item work (unlike
373 * fast_lane_list_pending_source_sv, which stashes a raw, not-yet-
374 * item-completed array for the plain-leaf case): a list_pending handle
375 * (gql_runtime_vm_list_pending_handle_sv's return) built directly from an
376 * item array whose sync items are already final values and whose
377 * suspended items are already per-item Promise::XS promises. A
378 * continuation owner must take and clear this before destroying this
379 * state, same contract as fast_lane_suspended_sv. */
380 SV *fast_lane_list_pending_result_sv;
381 } gql_runtime_vm_exec_state_t;
382  
383 enum {
384 GQL_VM_NATIVE_VALUE_UNDEF = 0,
385 GQL_VM_NATIVE_VALUE_SCALAR = 1,
386 GQL_VM_NATIVE_VALUE_OBJECT = 2,
387 GQL_VM_NATIVE_VALUE_LIST = 3
388 };
389  
390 enum {
391 GQL_VM_NATIVE_SCALAR_UNDEF = 0,
392 GQL_VM_NATIVE_SCALAR_IV = 1,
393 GQL_VM_NATIVE_SCALAR_NV = 2,
394 GQL_VM_NATIVE_SCALAR_PV = 3,
395 GQL_VM_NATIVE_SCALAR_FALLBACK_SV = 4
396 };
397  
398 typedef struct {
399 char **names;
400 /* Parallel to names: 1 marks a field name borrowed from the execution
401 * plan (plan strings outlive every value of the request), 0 an owned
402 * savepv copy that destroy must free. */
403 U8 *names_borrowed;
404 gql_runtime_vm_native_value_t **values;
405 IV count;
406 IV capacity;
407 } gql_runtime_vm_native_object_t;
408  
409 typedef struct {
410 gql_runtime_vm_native_value_t **items;
411 IV count;
412 IV capacity;
413 } gql_runtime_vm_native_list_t;
414  
415 struct gql_runtime_vm_native_value {
416 U8 kind_code;
417 U8 scalar_kind_code;
418 /* Whether scalar_pv holds UTF-8-flagged text (SvUTF8 on the source SV)
419 * rather than an unflagged byte/Latin-1 string; materialize_sv restores
420 * the flag from this so a resolver's wide-character string survives the
421 * round trip through this tree unchanged. */
422 U8 scalar_pv_is_utf8;
423 IV scalar_iv;
424 NV scalar_nv;
425 char *scalar_pv;
426 STRLEN scalar_pv_len;
427 SV *scalar_fallback_sv;
428 gql_runtime_vm_native_object_t object;
429 gql_runtime_vm_native_list_t list;
430 gql_runtime_vm_native_value_t *pool_next;
431 };
432  
433 struct gql_runtime_vm_native_dynamic_value {
434 U8 kind_code;
435 U8 scalar_kind_code;
436 /* Whether scalar_pv holds UTF-8-flagged text (SvUTF8 on the source SV),
437 * mirroring gql_runtime_vm_native_value::scalar_pv_is_utf8 - this struct
438 * caches a query's STATIC argument literals (compiled once, reused
439 * across requests), so a literal string argument containing raw
440 * (non-escaped) multibyte characters needs the same flag tracking or it
441 * loses its UTF8-ness on every materialize. */
442 U8 scalar_pv_is_utf8;
443 IV scalar_iv;
444 NV scalar_nv;
445 char *scalar_pv;
446 STRLEN scalar_pv_len;
447 char *variable_name;
448 /* Index in native_program->variable_defs; -1 means name lookup fallback. */
449 IV variable_index;
450 IV object_count;
451 char **object_names;
452 gql_runtime_vm_native_dynamic_value_t **object_values;
453 IV list_count;
454 gql_runtime_vm_native_dynamic_value_t **list_values;
455 };
456  
457 typedef struct {
458 SV *runtime_schema;
459 SV *program;
460 gql_runtime_vm_native_runtime_t *native_runtime;
461 SV *native_runtime_owner_sv;
462 U8 native_runtime_is_borrowed;
463 gql_runtime_vm_native_program_t *native_program;
464 gql_runtime_vm_cursor_t *cursor;
465 gql_runtime_vm_block_frame_t *frame;
466 IV frame_stack_count;
467 IV frame_stack_capacity;
468 gql_runtime_vm_block_frame_t **frame_stack;
469 gql_runtime_vm_field_frame_t *field_frame;
470 gql_runtime_vm_writer_t *writer;
471 SV *context;
472 SV *variables;
473 SV *root_value;
474 gql_runtime_vm_async_adapter_t *async_adapter;
475 SV *empty_args;
476 IV async_ready_frame_count;
477 IV async_ready_frame_capacity;
478 gql_runtime_vm_block_frame_t **async_ready_frames;
479 U8 async_scheduler_draining;
480 /* The first block frame pushed for the request. Only this frame's
481 * deferred resolves the response envelope; child frames finalized during
482 * late promise continuations may momentarily be the only stack entry,
483 * so frame_stack_count is not a safe root signal. */
484 gql_runtime_vm_block_frame_t *response_frame;
485 /* When set, the response frame resolves its deferred with UTF-8 JSON
486 * bytes (rendered from the native value tree) instead of the Perl
487 * envelope hash. */
488 U8 response_json_mode;
489 /* Set by resolve_frame when the response frame completes without a
490 * deferred: the request finished inside the original execute call, so
491 * the execute entry point hands this back directly instead of routing
492 * the response through a deferred/promise pair. */
493 SV *completed_response_sv;
494 } gql_runtime_vm_exec_state_handle_t;
495  
496 struct gql_runtime_vm_cursor_t {
497 UV refcount;
498 gql_runtime_vm_native_program_t *native_program;
499 IV block_index;
500 IV slot_index;
501 IV op_index;
502 };
503  
504 struct gql_runtime_vm_field_frame_t {
505 UV refcount;
506 SV *source;
507 gql_runtime_vm_path_frame_t *path_frame;
508 SV *resolved_value;
509 gql_runtime_vm_outcome_t *outcome;
510 U8 source_is_runtime_owned;
511 U8 storage_is_stack;
512 };
513  
514 struct gql_runtime_vm_path_frame {
515 UV refcount;
516 struct gql_runtime_vm_path_frame *parent;
517 IV key_kind;
518 IV key_iv;
519 char *key_pv;
520 STRLEN key_pv_len;
521 U8 key_pv_borrowed;
522 };
523  
524 typedef struct {
525 UV refcount;
526 char *message_pv;
527 /* Whether message_pv holds UTF-8-flagged text (SvUTF8 on the source
528 * message SV), mirroring gql_runtime_vm_native_value::scalar_pv_is_utf8
529 * - without this, every field error message (from a resolver/serialize
530 * die, or a validation failure) silently lost its UTF8 flag on the way
531 * into the response's errors array, even though message_pv's bytes were
532 * already the correct UTF-8 encoding. */
533 U8 message_pv_is_utf8;
534 gql_runtime_vm_path_frame_t *path_frame;
535 } gql_runtime_vm_error_record_t;
536  
537 struct gql_runtime_vm_list_pending_t {
538 UV refcount;
539 gql_runtime_vm_block_frame_t *owner_frame;
540 gql_runtime_vm_native_value_t *values_value;
541 IV unresolved_count;
542 /* Phase 11: raw child block_frame_t linkage for a suspending
543 * object/abstract list item (mirrors block_frame_t's own parent_frame
544 * linkage - see block_frame_t::parent_list_pending below). Same length
545 * as the list; NULL except at slots holding a still-suspended child
546 * frame. Needed so gql_runtime_vm_cancel_frame_tree can find and
547 * recursively cancel these children on an abandoned request - nothing
548 * else keeps a reachable pointer to them, unlike the Promise::XS-
549 * mediated path this replaces (there, Promise::XS's own held reference
550 * was enough for cancel_frame_tree's ordinary decref-only handling). */
551 gql_runtime_vm_block_frame_t **pending_child_frames;
552 IV pending_child_frame_count;
553 };
554  
555 struct gql_runtime_vm_block_frame_t {
556 UV refcount;
557 gql_runtime_vm_native_value_t *values_value;
558 IV pending_count;
559 IV pending_capacity;
560 IV pending_unresolved;
561 gql_runtime_vm_pending_entry_t *pending_entries;
562 gql_runtime_vm_block_frame_t *parent_frame;
563 IV parent_entry_index;
564 /* Phase 11: alternate parent kind for a suspending object/abstract list
565 * item's child frame - a list_pending slot instead of another frame's
566 * pending_entries array. Mutually exclusive with parent_frame/
567 * parent_entry_index (a frame has at most one kind of parent); set by
568 * the new list-item linkage function, consumed by
569 * gql_runtime_vm_async_scheduler_resolve_frame's matching branch. */
570 gql_runtime_vm_list_pending_t *parent_list_pending;
571 IV parent_list_index;
572 SV *deferred_sv;
573 SV *promise_sv;
574 U8 queued;
575 U8 deferred_resolves_response;
576 /* Non-Null propagation (spec 6.4.4): set when one of this frame's
577 * non-null fields resolved to null. The frame then resolves to null
578 * instead of its object; the originating "Cannot return null" error is
579 * already recorded, so the null propagates without stacking errors. */
580 U8 self_nulled;
581 };
582  
583 enum {
584 GQL_VM_PENDING_PROMISE_SV = 1,
585 GQL_VM_PENDING_OUTCOME_PTR = 2,
586 GQL_VM_PENDING_PROMISE_GENERIC_VALUE_SV = 3,
587 GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV = 4,
588 GQL_VM_PENDING_BLOCK_FRAME_PTR = 5,
589 GQL_VM_PENDING_LIST_PENDING_PTR = 6,
590 };
591  
592 enum {
593 GQL_VM_PENDING_STATE_WAITING_UNARMED = 1,
594 GQL_VM_PENDING_STATE_WAITING_ARMED = 2,
595 GQL_VM_PENDING_STATE_READY_SV = 3,
596 GQL_VM_PENDING_STATE_READY_OUTCOME = 4
597 };
598  
599 struct gql_runtime_vm_pending_entry_t {
600 char *result_name_pv;
601 STRLEN result_name_len;
602 gql_runtime_vm_path_frame_t *path_frame;
603 IV block_index;
604 IV slot_index;
605 IV op_index;
606 /* Armed then-callback contexts (resolve/reject arms) hold this entry's
607 * index by value; when process_frame re-pushes a still-waiting entry
608 * into the rebuilt pending array its index shifts, and these borrowed
609 * pointers (owned by the callback CVs) let the move retarget them.
610 * A settle through a stale index is silently dropped by the callbacks'
611 * bounds check, deadlocking the frame. */
612 void *armed_resolve_ctx;
613 void *armed_reject_ctx;
614 U8 result_name_pv_borrowed;
615 U8 payload_kind;
616 U8 state_code;
617 union {
618 SV *promise_sv;
619 gql_runtime_vm_outcome_t *outcome_ptr;
620 gql_runtime_vm_block_frame_t *block_frame_ptr;
621 gql_runtime_vm_list_pending_t *list_pending_ptr;
622 } payload;
623 };
624  
625 struct gql_runtime_vm_outcome {
626 UV refcount;
627 U8 kind_code;
628 gql_runtime_vm_native_value_t *value;
629 IV error_record_count;
630 gql_runtime_vm_error_record_t **error_records;
631 struct gql_runtime_vm_outcome *pool_next;
632 /* Non-Null propagation: set on a null outcome whose originating
633 * "Cannot return null" (or field) error is already recorded, so a
634 * parent nulling itself over this value adds no further error. */
635 U8 null_carries_error;
636 };
637  
638 struct gql_runtime_vm_writer_t {
639 UV refcount;
640 IV error_record_count;
641 IV error_record_capacity;
642 gql_runtime_vm_error_record_t **error_records;
643 };
644  
645 struct gql_runtime_vm_lazy_info {
646 struct gql_runtime_vm_lazy_info *pool_next;
647 UV refcount;
648 SV *field_name_sv;
649 char *field_name_pv;
650 SV *parent_type_sv;
651 char *parent_type_name_pv;
652 char *return_type_name_pv;
653 SV *return_type_sv;
654 gql_runtime_vm_path_frame_t *path_frame;
655 SV *context_value;
656 SV *root_value;
657 SV *variable_values;
658 SV *operation;
659 SV *runtime_schema;
660 SV *directives;
661 IV block_index;
662 IV op_index;
663 SV *materialized_sv;
664 };
665  
666 static AV *gql_runtime_vm_expect_op_array(pTHX_ SV *op_sv);
667 static SV *gql_runtime_vm_op_slot_sv(pTHX_ SV *op_sv, IV index);
668 static const gql_runtime_vm_native_block_t *gql_runtime_vm_cursor_current_native_block(const gql_runtime_vm_cursor_t *cursor);
669 static const gql_runtime_vm_native_op_t *gql_runtime_vm_cursor_current_native_op(const gql_runtime_vm_cursor_t *cursor);
670 static const gql_runtime_vm_native_slot_t *gql_runtime_vm_cursor_current_native_slot(const gql_runtime_vm_cursor_t *cursor);
671 static SV *gql_runtime_vm_new_handle_sv(pTHX_ const char *pkg, void *ptr);
672 static SV *gql_runtime_vm_fetch_hash_entry_sv(pTHX_ HV *hv, const char *key, I32 keylen);
673 static gql_runtime_vm_cursor_t *gql_runtime_vm_expect_cursor(pTHX_ SV *self);
674 static gql_runtime_vm_error_record_t *gql_runtime_vm_expect_error_record(pTHX_ SV *self);
675 static gql_runtime_vm_outcome_t *gql_runtime_vm_expect_outcome(pTHX_ SV *self);
676 static void gql_runtime_vm_free_block_frame(pTHX_ gql_runtime_vm_block_frame_t *frame);
677 static void gql_runtime_vm_error_record_incref(gql_runtime_vm_error_record_t *record);
678 static void gql_runtime_vm_error_record_decref(pTHX_ gql_runtime_vm_error_record_t *record);
679 static void gql_runtime_vm_outcome_incref(gql_runtime_vm_outcome_t *outcome);
680 static void gql_runtime_vm_outcome_decref(pTHX_ gql_runtime_vm_outcome_t *outcome);
681 static void gql_runtime_vm_list_pending_decref(pTHX_ gql_runtime_vm_list_pending_t *pending);
682 static void gql_runtime_vm_writer_push_error_record(gql_runtime_vm_writer_t *writer, gql_runtime_vm_error_record_t *record);
683 static void gql_runtime_vm_block_frame_push_pending_pvn(
684 pTHX_
685 gql_runtime_vm_block_frame_t *frame,
686 const char *result_name_pv,
687 STRLEN result_name_len,
688 SV *outcome
689 );
690 static void gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
691 pTHX_
692 gql_runtime_vm_block_frame_t *frame,
693 const char *result_name_pv,
694 STRLEN result_name_len,
695 U8 result_name_pv_borrowed,
696 SV *outcome,
697 U8 payload_kind,
698 gql_runtime_vm_path_frame_t *path_frame,
699 IV block_index,
700 IV slot_index,
701 IV op_index,
702 const gql_runtime_vm_async_adapter_t *async_adapter
703 );
704 static gql_runtime_vm_pending_entry_t *gql_runtime_vm_block_frame_push_pending_entry_with_meta(
705 pTHX_
706 gql_runtime_vm_block_frame_t *frame,
707 const char *result_name_pv,
708 STRLEN result_name_len,
709 U8 result_name_pv_borrowed,
710 gql_runtime_vm_path_frame_t *path_frame,
711 IV block_index,
712 IV slot_index,
713 IV op_index
714 );
715 static void gql_runtime_vm_block_frame_push_pending(pTHX_ gql_runtime_vm_block_frame_t *frame, SV *result_name, SV *outcome);
716 static void gql_runtime_vm_block_frame_clear_pending(pTHX_ gql_runtime_vm_block_frame_t *frame);
717 static void gql_runtime_vm_path_frame_decref(gql_runtime_vm_path_frame_t *frame);
718 static SV *gql_runtime_vm_call_cb4_nonfatal(pTHX_ SV *cb, SV *arg0, SV *arg1, SV *arg2, SV *arg3, SV **error_out);
719 static SV *gql_runtime_vm_call_cb5_nonfatal(pTHX_ SV *cb, SV *arg0, SV *arg1, SV *arg2, SV *arg3, SV *arg4, SV **error_out);
720 static SV *gql_runtime_vm_new_callback_info_sv(pTHX_ const gql_runtime_vm_exec_state_t *state);
721 static gql_runtime_vm_native_value_t *gql_runtime_vm_new_native_value_scalar(pTHX_ SV *value);
722 static gql_runtime_vm_native_value_t *gql_runtime_vm_new_native_value_object(void);
723 static gql_runtime_vm_native_value_t *gql_runtime_vm_new_native_value_list(void);
724 static void gql_runtime_vm_native_object_store(pTHX_ gql_runtime_vm_native_value_t *value, const char *name, U8 name_borrowed, gql_runtime_vm_native_value_t *child);
725 static void gql_runtime_vm_native_list_push(gql_runtime_vm_native_value_t *value, gql_runtime_vm_native_value_t *child);
726 static void gql_runtime_vm_native_value_destroy(pTHX_ gql_runtime_vm_native_value_t *value);
727 static SV *gql_runtime_vm_native_value_materialize_sv(pTHX_ gql_runtime_vm_native_value_t *value);
728 static gql_runtime_vm_native_value_t *gql_runtime_vm_native_value_from_sv(pTHX_ SV *value);
729 static gql_runtime_vm_native_value_t *gql_runtime_vm_native_value_clone(pTHX_ const gql_runtime_vm_native_value_t *value);
730 static gql_runtime_vm_native_dynamic_value_t *gql_runtime_vm_native_dynamic_value_from_sv(pTHX_ SV *value);
731 static gql_runtime_vm_native_dynamic_value_t *gql_runtime_vm_native_dynamic_value_from_native_value(
732 pTHX_ const gql_runtime_vm_native_value_t *value
733 );
734 static gql_runtime_vm_native_dynamic_value_t *gql_runtime_vm_native_dynamic_value_clone(
735 pTHX_ const gql_runtime_vm_native_dynamic_value_t *value
736 );
737 static void gql_runtime_vm_native_dynamic_value_destroy(
738 pTHX_ gql_runtime_vm_native_dynamic_value_t *value
739 );
740 static SV *gql_runtime_vm_native_dynamic_value_materialize_sv(
741 pTHX_ const gql_runtime_vm_native_dynamic_value_t *value,
742 HV *variables
743 );
744 static void gql_runtime_vm_bind_dynamic_value_variables(
745 gql_runtime_vm_native_dynamic_value_t *value,
746 const gql_runtime_vm_native_arg_def_t *variable_defs,
747 IV variable_def_count
748 );
749 static int gql_runtime_vm_native_dynamic_value_truthy(
750 pTHX_ const gql_runtime_vm_native_dynamic_value_t *value,
751 HV *variables,
752 SV **variable_slots,
753 IV variable_slot_count
754 );
755 static const gql_runtime_vm_native_dynamic_value_t *gql_runtime_vm_native_args_payload_lookup_value(
756 const gql_runtime_vm_native_args_payload_t *payload,
757 const char *arg_name,
758 IV hint_index
759 );
760 static gql_runtime_vm_native_args_payload_t *gql_runtime_vm_native_args_payload_from_hv(pTHX_ HV *hv);
761 static gql_runtime_vm_native_args_payload_t *gql_runtime_vm_native_args_payload_clone(
762 pTHX_ const gql_runtime_vm_native_args_payload_t *payload
763 );
764 static void gql_runtime_vm_native_args_payload_destroy(pTHX_ gql_runtime_vm_native_args_payload_t *payload);
765 static SV *gql_runtime_vm_native_args_payload_materialize_sv(
766 pTHX_ const gql_runtime_vm_native_args_payload_t *payload
767 );
768 static SV *gql_runtime_vm_native_args_payload_materialize_cached_sv(
769 pTHX_ gql_runtime_vm_native_args_payload_t *payload
770 );
771 static SV *gql_runtime_vm_native_args_payload_materialize_one_arg_cached_sv(
772 pTHX_ gql_runtime_vm_native_args_payload_t *payload
773 );
774 static gql_runtime_vm_native_directives_payload_t *gql_runtime_vm_native_directives_payload_from_sv(
775 pTHX_ SV *guards_sv
776 );
777 static gql_runtime_vm_native_directives_payload_t *gql_runtime_vm_native_directives_payload_clone(
778 pTHX_ const gql_runtime_vm_native_directives_payload_t *payload
779 );
780 static void gql_runtime_vm_native_directives_payload_destroy(
781 pTHX_ gql_runtime_vm_native_directives_payload_t *payload
782 );
783 static int gql_runtime_vm_evaluate_runtime_guards_native(
784 pTHX_ const gql_runtime_vm_native_directives_payload_t *payload,
785 HV *variables,
786 SV **variable_slots,
787 IV variable_slot_count
788 );
789 static gql_runtime_vm_native_args_payload_t *gql_runtime_vm_specialize_arg_payload_native(
790 pTHX_
791 const gql_runtime_vm_native_runtime_t *runtime,
792 const gql_runtime_vm_native_slot_t *slot,
793 const gql_runtime_vm_native_op_t *op,
794 HV *variables_hv
795 );
796 static IV gql_runtime_vm_infer_callback_abi_code(IV resolver_shape_code, IV resolver_mode_code);
797 static const gql_runtime_vm_native_slot_t *gql_runtime_vm_effective_slot(
798 const gql_runtime_vm_native_runtime_t *runtime,
799 const gql_runtime_vm_native_slot_t *slot
800 );
801 static int gql_runtime_vm_sv_to_hv(pTHX_ SV *sv, HV **out);
802 static int gql_runtime_vm_sv_to_av(pTHX_ SV *sv, AV **out);
803 static void gql_runtime_vm_free_native_arg_defs(pTHX_ gql_runtime_vm_native_arg_def_t *arg_defs, IV count);
804  
805 static AV *
806 0 gql_runtime_vm_expect_op_array(pTHX_ SV *op_sv)
807 {
808 0 ▶ if (!op_sv || !SvOK(op_sv) || !SvROK(op_sv) || SvTYPE(SvRV(op_sv)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!op_sv || !SvOK(op_sv) || !SvROK(op_sv) || SvTYPE(SvRV(op_sv)) != SVt_PVAV) { 0 0 0
if (!op_sv || !SvOK(op_sv) || !SvROK(op_sv) || SvTYPE(SvRV(op_sv)) != SVt_PVAV) { 0 0 0
if (!op_sv || !SvOK(op_sv) || !SvROK(op_sv) || SvTYPE(SvRV(op_sv)) != SVt_PVAV) { 0 0 0
if (!op_sv || !SvOK(op_sv) || !SvROK(op_sv) || SvTYPE(SvRV(op_sv)) != SVt_PVAV) { 0 0 0
809 0 return NULL;
810 }
811 0 return (AV *)SvRV(op_sv);
812 }
813  
814 static SV *
815 0 gql_runtime_vm_op_slot_sv(pTHX_ SV *op_sv, IV index)
816 {
817 0 AV *op_av = gql_runtime_vm_expect_op_array(aTHX_ op_sv);
818 SV **svp;
819  
820 0 ▶ if (!op_av) {
Branch: 1 branch
BranchTrueFalseTotal
if (!op_av) { 0 0 0
821 0 return NULL;
822 }
823  
824 0 svp = av_fetch(op_av, index, 0);
825 0 ▶ return (svp && SvOK(*svp)) ? *svp : NULL;
Branch: 2 branches
BranchTrueFalseTotal
return (svp && SvOK(*svp)) ? *svp : NULL; 0 0 0
return (svp && SvOK(*svp)) ? *svp : NULL; 0 0 0
826 }
827  
828 static const gql_runtime_vm_native_block_t *
829 16770 gql_runtime_vm_cursor_current_native_block(const gql_runtime_vm_cursor_t *cursor)
830 {
831 16770 ▶ if (!cursor || !cursor->native_program) {
Branch: 2 branches
BranchTrueFalseTotal
if (!cursor || !cursor->native_program) { 16770 0 16770
if (!cursor || !cursor->native_program) { 0 16770 16770
832 0 return NULL;
833 }
834 16770 ▶ if (cursor->block_index < 0 || cursor->block_index >= cursor->native_program->block_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (cursor->block_index < 0 || cursor->block_index >= cursor->native_program->block_count) { 16770 0 16770
if (cursor->block_index < 0 || cursor->block_index >= cursor->native_program->block_count) { 0 16770 16770
835 0 return NULL;
836 }
837 16770 return &cursor->native_program->blocks[cursor->block_index];
838 }
839  
840 static const gql_runtime_vm_native_op_t *
841 3621 gql_runtime_vm_cursor_current_native_op(const gql_runtime_vm_cursor_t *cursor)
842 {
843 3621 const gql_runtime_vm_native_block_t *block = gql_runtime_vm_cursor_current_native_block(cursor);
844 3621 ▶ if (!block) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block) { 0 3621 3621
845 0 return NULL;
846 }
847 3621 ▶ if (cursor->op_index < 0 || cursor->op_index >= block->op_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (cursor->op_index < 0 || cursor->op_index >= block->op_count) { 3621 0 3621
if (cursor->op_index < 0 || cursor->op_index >= block->op_count) { 0 3621 3621
848 0 return NULL;
849 }
850 3621 return &block->ops[cursor->op_index];
851 }
852  
853 static const gql_runtime_vm_native_slot_t *
854 7345 gql_runtime_vm_cursor_current_native_slot(const gql_runtime_vm_cursor_t *cursor)
855 {
856 7345 const gql_runtime_vm_native_block_t *block = gql_runtime_vm_cursor_current_native_block(cursor);
857 7345 ▶ if (!block) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block) { 0 7345 7345
858 0 return NULL;
859 }
860 7345 ▶ if (cursor->slot_index < 0 || cursor->slot_index >= block->slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (cursor->slot_index < 0 || cursor->slot_index >= block->slot_count) { 7345 0 7345
if (cursor->slot_index < 0 || cursor->slot_index >= block->slot_count) { 0 7345 7345
861 0 return NULL;
862 }
863 7345 return &block->slots[cursor->slot_index];
864 }
865  
866 /*
867 * Free-list pool for native value nodes. The async lane allocates and
868 * destroys one node per response field plus one per object/list container,
869 * which made calloc/free the top self-time cost in profiles. Released nodes
870 * park here with their object/list backing arrays intact (count reset,
871 * capacity retained), so a reused container node also skips the Renew
872 * doubling ramp. Nodes hold no SVs while pooled; the pool is process-global
873 * like the cached stashes and is capped so idle memory stays bounded.
874 */
875 #define GQL_RUNTIME_VM_NATIVE_VALUE_POOL_MAX 4096
876 static gql_runtime_vm_native_value_t *gql_runtime_vm_native_value_pool_head = NULL;
877 static IV gql_runtime_vm_native_value_pool_count = 0;
878  
879 /* Outcome and path-frame structs are allocated once per field on the async
880 * lane; they recycle through the same kind of capped free lists. Reused
881 * structs are zeroed so the constructors keep their Newxz assumptions. */
882 #define GQL_RUNTIME_VM_OUTCOME_POOL_MAX 1024
883 static gql_runtime_vm_outcome_t *gql_runtime_vm_outcome_pool_head = NULL;
884 static IV gql_runtime_vm_outcome_pool_count = 0;
885  
886 #define GQL_RUNTIME_VM_PATH_FRAME_POOL_MAX 1024
887 static gql_runtime_vm_path_frame_t *gql_runtime_vm_path_frame_pool_head = NULL;
888 static IV gql_runtime_vm_path_frame_pool_count = 0;
889  
890 #define GQL_RUNTIME_VM_BLOCK_FRAME_POOL_MAX 256
891 static gql_runtime_vm_block_frame_t *gql_runtime_vm_block_frame_pool_head = NULL;
892 static IV gql_runtime_vm_block_frame_pool_count = 0;
893  
894 /* LazyInfo instances are mortal/short-lived per resolver call - a small
895 * cap matching block_frame's order of magnitude is plenty of working set. */
896 #define GQL_RUNTIME_VM_LAZY_INFO_POOL_MAX 256
897 static gql_runtime_vm_lazy_info_t *gql_runtime_vm_lazy_info_pool_head = NULL;
898 static IV gql_runtime_vm_lazy_info_pool_count = 0;
899  
900 /* Leak instrumentation: frames handed out minus frames released (a pooled
901 * frame counts as released). A quiescent process must read zero; a positive
902 * residue after a request fully completed is an orphaned frame. Exposed via
903 * GraphQL::Houtou::XS::VM::debug_frame_live_counts_xs. */
904 static IV gql_runtime_vm_path_frame_live_count = 0;
905 static IV gql_runtime_vm_block_frame_live_count = 0;
906 static IV gql_runtime_vm_lazy_info_live_count = 0;
907  
908 static gql_runtime_vm_block_frame_t *
909 4081 gql_runtime_vm_block_frame_pool_get(pTHX)
910 {
911 /* Pooled block frames chain through their (dead) parent_frame pointer and
912 * keep their pending_entries array so refills skip the Renew ramp. */
913 4081 gql_runtime_vm_block_frame_t *ret = gql_runtime_vm_block_frame_pool_head;
914 4081 gql_runtime_vm_block_frame_live_count++;
915 4081 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 3914 167 4081
916 3914 gql_runtime_vm_pending_entry_t *entries = ret->pending_entries;
917 3914 IV capacity = ret->pending_capacity;
918 3914 gql_runtime_vm_block_frame_pool_head = ret->parent_frame;
919 3914 gql_runtime_vm_block_frame_pool_count--;
920 3914 Zero(ret, 1, gql_runtime_vm_block_frame_t);
921 3914 ret->pending_entries = entries;
922 3914 ret->pending_capacity = capacity;
923 3914 return ret;
924 }
925 167 Newxz(ret, 1, gql_runtime_vm_block_frame_t);
926 167 return ret;
927 }
928  
929 static gql_runtime_vm_outcome_t *
930 5745 gql_runtime_vm_outcome_pool_get(pTHX)
931 {
932 5745 gql_runtime_vm_outcome_t *ret = gql_runtime_vm_outcome_pool_head;
933 5745 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 5649 96 5745
934 5649 gql_runtime_vm_outcome_pool_head = ret->pool_next;
935 5649 gql_runtime_vm_outcome_pool_count--;
936 5649 Zero(ret, 1, gql_runtime_vm_outcome_t);
937 5649 return ret;
938 }
939 96 Newxz(ret, 1, gql_runtime_vm_outcome_t);
940 96 return ret;
941 }
942  
943 static gql_runtime_vm_path_frame_t *
944 15773 gql_runtime_vm_path_frame_pool_get(pTHX)
945 {
946 /* Pooled path frames chain through their (dead) parent pointer. */
947 15773 gql_runtime_vm_path_frame_t *ret = gql_runtime_vm_path_frame_pool_head;
948 15773 gql_runtime_vm_path_frame_live_count++;
949 15773 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 14294 1479 15773
950 14294 gql_runtime_vm_path_frame_pool_head = ret->parent;
951 14294 gql_runtime_vm_path_frame_pool_count--;
952 14294 Zero(ret, 1, gql_runtime_vm_path_frame_t);
953 14294 return ret;
954 }
955 1479 Newxz(ret, 1, gql_runtime_vm_path_frame_t);
956 1479 return ret;
957 }
958  
959 static gql_runtime_vm_lazy_info_t *
960 10987 gql_runtime_vm_lazy_info_pool_get(pTHX)
961 {
962 10987 gql_runtime_vm_lazy_info_t *ret = gql_runtime_vm_lazy_info_pool_head;
963 10987 gql_runtime_vm_lazy_info_live_count++;
964 10987 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 9839 1148 10987
965 9839 gql_runtime_vm_lazy_info_pool_head = ret->pool_next;
966 9839 gql_runtime_vm_lazy_info_pool_count--;
967 9839 Zero(ret, 1, gql_runtime_vm_lazy_info_t);
968 9839 return ret;
969 }
970 1148 Newxz(ret, 1, gql_runtime_vm_lazy_info_t);
971 1148 return ret;
972 }
973  
974 static gql_runtime_vm_native_value_t *
975 16116 gql_runtime_vm_native_value_pool_get(U8 kind_code)
976 {
977 16116 gql_runtime_vm_native_value_t *ret = gql_runtime_vm_native_value_pool_head;
978 16116 ▶ if (ret) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret) { 12805 3311 16116
979 12805 gql_runtime_vm_native_value_pool_head = ret->pool_next;
980 12805 gql_runtime_vm_native_value_pool_count--;
981 12805 ret->pool_next = NULL;
982 12805 ret->kind_code = kind_code;
983 12805 return ret;
984 }
985 3311 Newxz(ret, 1, gql_runtime_vm_native_value_t);
986 3311 ret->kind_code = kind_code;
987 3311 return ret;
988 }
989  
990 static gql_runtime_vm_native_value_t *
991 11068 gql_runtime_vm_new_native_value_scalar(pTHX_ SV *value)
992 {
993 gql_runtime_vm_native_value_t *ret;
994 11068 ret = gql_runtime_vm_native_value_pool_get(GQL_VM_NATIVE_VALUE_SCALAR);
995 11068 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_UNDEF;
996 11068 ret->scalar_pv_is_utf8 = 0;
997 11068 ret->scalar_iv = 0;
998 11068 ret->scalar_nv = 0.0;
999 11068 ret->scalar_pv = NULL;
1000 11068 ret->scalar_pv_len = 0;
1001 11068 ret->scalar_fallback_sv = NULL;
1002 11068 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 11068 0 11068
if (!value || !SvOK(value)) { 4342 6726 11068
1003 4342 return ret;
1004 }
1005 6726 ▶ if (SvROK(value) || SvMAGICAL(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(value) || SvMAGICAL(value)) { 6726 0 6726
if (SvROK(value) || SvMAGICAL(value)) { 0 6726 6726
1006 0 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_FALLBACK_SV;
1007 0 ret->scalar_fallback_sv = newSVsv(value);
1008 0 return ret;
1009 }
1010 6726 ▶ if (SvPOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOKp(value)) { 5369 1357 6726
1011 5369 STRLEN len = 0;
1012 5369 const char *pv = SvPV(value, len);
1013 5369 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_PV;
1014 5369 ret->scalar_pv = savepvn(pv, len);
1015 5369 ret->scalar_pv_len = len;
1016 5369 ret->scalar_pv_is_utf8 = SvUTF8(value) ? 1 : 0;
1017 5369 return ret;
1018 }
1019 1357 ▶ if (SvIOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOKp(value)) { 1357 0 1357
1020 1357 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_IV;
1021 1357 ret->scalar_iv = SvIV(value);
1022 1357 return ret;
1023 }
1024 0 ▶ if (SvNOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOKp(value)) { 0 0 0
1025 0 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_NV;
1026 0 ret->scalar_nv = SvNV(value);
1027 0 return ret;
1028 }
1029 0 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_FALLBACK_SV;
1030 0 ret->scalar_fallback_sv = newSVsv(value);
1031 0 return ret;
1032 }
1033  
1034 static gql_runtime_vm_native_value_t *
1035 4262 gql_runtime_vm_new_native_value_object(void)
1036 {
1037 4262 return gql_runtime_vm_native_value_pool_get(GQL_VM_NATIVE_VALUE_OBJECT);
1038 }
1039  
1040 static gql_runtime_vm_native_value_t *
1041 786 gql_runtime_vm_new_native_value_list(void)
1042 {
1043 786 return gql_runtime_vm_native_value_pool_get(GQL_VM_NATIVE_VALUE_LIST);
1044 }
1045  
1046 static void
1047 7491 gql_runtime_vm_native_object_store(pTHX_ gql_runtime_vm_native_value_t *value, const char *name, U8 name_borrowed, gql_runtime_vm_native_value_t *child)
1048 {
1049 gql_runtime_vm_native_object_t *object;
1050 7491 ▶ if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !name || !child) {
Branch: 4 branches
BranchTrueFalseTotal
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !name || !child) { 7491 0 7491
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !name || !child) { 7491 0 7491
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !name || !child) { 7491 0 7491
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !name || !child) { 0 7491 7491
1051 0 return;
1052 }
1053 7491 object = &value->object;
1054 7491 ▶ if (object->count == object->capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (object->count == object->capacity) { 639 6852 7491
1055 639 ▶ IV new_capacity = object->capacity ? object->capacity * 2 : 8;
Branch: 1 branch
BranchTrueFalseTotal
IV new_capacity = object->capacity ? object->capacity * 2 : 8; 17 622 639
1056 639 ▶ Renew(object->names, new_capacity, char *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(object->names, new_capacity, char *); 0 639 639
1057 639 Renew(object->names_borrowed, new_capacity, U8);
1058 639 ▶ Renew(object->values, new_capacity, gql_runtime_vm_native_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(object->values, new_capacity, gql_runtime_vm_native_value_t *); 0 639 639
1059 639 object->capacity = new_capacity;
1060 }
1061 7491 ▶ object->names[object->count] = name_borrowed ? (char *)name : savepv(name);
Branch: 1 branch
BranchTrueFalseTotal
object->names[object->count] = name_borrowed ? (char *)name : savepv(name); 48 7443 7491
1062 7491 object->names_borrowed[object->count] = name_borrowed ? 1 : 0;
1063 7491 object->values[object->count] = child;
1064 7491 object->count++;
1065 }
1066  
1067 static void
1068 317 gql_runtime_vm_native_list_push(gql_runtime_vm_native_value_t *value, gql_runtime_vm_native_value_t *child)
1069 {
1070 gql_runtime_vm_native_list_t *list;
1071 IV i;
1072 317 ▶ if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || !child) {
Branch: 3 branches
BranchTrueFalseTotal
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || !child) { 317 0 317
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || !child) { 317 0 317
if (!value || value->kind_code != GQL_VM_NATIVE_VALUE_LIST || !child) { 0 317 317
1073 0 return;
1074 }
1075 317 list = &value->list;
1076 317 ▶ if (list->count == list->capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (list->count == list->capacity) { 98 219 317
1077 98 ▶ IV new_capacity = list->capacity ? list->capacity * 2 : 8;
Branch: 1 branch
BranchTrueFalseTotal
IV new_capacity = list->capacity ? list->capacity * 2 : 8; 7 91 98
1078 98 ▶ 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 98 98
1079 /* Entries at or beyond count must be NULL: destroy only clears up to
1080 * count before pooling the value, and a pooled reuse via the sparse
1081 * native_list_store_at treats any non-NULL slot as a live child to
1082 * destroy - an uninitialized slot there is a wild pointer. */
1083 898 ▶ for (i = list->capacity; i < new_capacity; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = list->capacity; i < new_capacity; i++) { 800 98 898
1084 800 list->items[i] = NULL;
1085 }
1086 98 list->capacity = new_capacity;
1087 }
1088 317 list->items[list->count] = child;
1089 317 list->count++;
1090 }
1091  
1092 static void
1093 23763 gql_runtime_vm_native_value_destroy(pTHX_ gql_runtime_vm_native_value_t *value)
1094 {
1095 IV i;
1096 23763 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 7647 16116 23763
1097 7647 return;
1098 }
1099 16116 switch (value->kind_code) {
1100 11068 case GQL_VM_NATIVE_VALUE_SCALAR:
1101 11068 switch (value->scalar_kind_code) {
1102 5404 case GQL_VM_NATIVE_SCALAR_PV:
1103 5404 Safefree(value->scalar_pv);
1104 5404 break;
1105 0 case GQL_VM_NATIVE_SCALAR_FALLBACK_SV:
1106 0 SvREFCNT_dec(value->scalar_fallback_sv);
1107 0 break;
1108 5664 default:
1109 5664 break;
1110 }
1111 11068 break;
1112 4262 case GQL_VM_NATIVE_VALUE_OBJECT:
1113 /* Slots must go back to NULL: the retained arrays are reused with the
1114 * invariant that entries at or beyond count are empty (sparse
1115 * store_at fills rely on it to detect real overwrites). */
1116 11753 ▶ for (i = 0; i < value->object.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object.count; i++) { 7491 4262 11753
1117 7491 ▶ if (!value->object.names_borrowed || !value->object.names_borrowed[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value->object.names_borrowed || !value->object.names_borrowed[i]) { 7491 0 7491
if (!value->object.names_borrowed || !value->object.names_borrowed[i]) { 48 7443 7491
1118 48 Safefree(value->object.names[i]);
1119 }
1120 7491 value->object.names[i] = NULL;
1121 7491 gql_runtime_vm_native_value_destroy(aTHX_ value->object.values[i]);
1122 7491 value->object.values[i] = NULL;
1123 }
1124 4262 value->object.count = 0;
1125 4262 break;
1126 786 case GQL_VM_NATIVE_VALUE_LIST:
1127 2612 ▶ for (i = 0; i < value->list.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list.count; i++) { 1826 786 2612
1128 1826 gql_runtime_vm_native_value_destroy(aTHX_ value->list.items[i]);
1129 1826 value->list.items[i] = NULL;
1130 }
1131 786 value->list.count = 0;
1132 786 break;
1133 }
1134 16116 value->scalar_kind_code = GQL_VM_NATIVE_SCALAR_UNDEF;
1135 16116 value->scalar_pv_is_utf8 = 0;
1136 16116 value->scalar_pv = NULL;
1137 16116 value->scalar_pv_len = 0;
1138 16116 value->scalar_fallback_sv = NULL;
1139 16116 ▶ if (gql_runtime_vm_native_value_pool_count < GQL_RUNTIME_VM_NATIVE_VALUE_POOL_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_native_value_pool_count < GQL_RUNTIME_VM_NATIVE_VALUE_POOL_MAX) { 16116 0 16116
1140 16116 value->pool_next = gql_runtime_vm_native_value_pool_head;
1141 16116 gql_runtime_vm_native_value_pool_head = value;
1142 16116 gql_runtime_vm_native_value_pool_count++;
1143 16116 return;
1144 }
1145 0 Safefree(value->object.names);
1146 0 Safefree(value->object.names_borrowed);
1147 0 Safefree(value->object.values);
1148 0 Safefree(value->list.items);
1149 0 Safefree(value);
1150 }
1151  
1152 static SV *
1153 10823 gql_runtime_vm_native_value_materialize_sv(pTHX_ gql_runtime_vm_native_value_t *value)
1154 {
1155 IV i;
1156 10823 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 1 10822 10823
1157 1 return newSVsv(&PL_sv_undef);
1158 }
1159 10822 switch (value->kind_code) {
1160 4181 case GQL_VM_NATIVE_VALUE_OBJECT: {
1161 4181 HV *hv = newHV();
1162 11576 ▶ for (i = 0; i < value->object.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object.count; i++) { 7395 4181 11576
1163 7395 hv_store(
1164 hv,
1165 value->object.names[i],
1166 (I32)strlen(value->object.names[i]),
1167 gql_runtime_vm_native_value_materialize_sv(aTHX_ value->object.values[i]),
1168 0
1169 );
1170 }
1171 4181 return newRV_noinc((SV *)hv);
1172 }
1173 781 case GQL_VM_NATIVE_VALUE_LIST: {
1174 781 AV *av = newAV();
1175 781 av_extend(av, value->list.count > 0 ? value->list.count - 1 : 0);
1176 2596 ▶ for (i = 0; i < value->list.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list.count; i++) { 1815 781 2596
1177 1815 av_store(av, i, gql_runtime_vm_native_value_materialize_sv(aTHX_ value->list.items[i]));
1178 }
1179 781 return newRV_noinc((SV *)av);
1180 }
1181 5860 case GQL_VM_NATIVE_VALUE_SCALAR:
1182 default:
1183 5860 switch (value->scalar_kind_code) {
1184 376 case GQL_VM_NATIVE_SCALAR_UNDEF:
1185 376 return newSVsv(&PL_sv_undef);
1186 157 case GQL_VM_NATIVE_SCALAR_IV:
1187 157 return newSViv(value->scalar_iv);
1188 0 case GQL_VM_NATIVE_SCALAR_NV:
1189 0 return newSVnv(value->scalar_nv);
1190 5327 case GQL_VM_NATIVE_SCALAR_PV: {
1191 5327 ▶ SV *pv_sv = newSVpvn(value->scalar_pv ? value->scalar_pv : "", value->scalar_pv_len);
Branch: 1 branch
BranchTrueFalseTotal
SV *pv_sv = newSVpvn(value->scalar_pv ? value->scalar_pv : "", value->scalar_pv_len); 5327 0 5327
1192 5327 ▶ if (value->scalar_pv_is_utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if (value->scalar_pv_is_utf8) { 8 5319 5327
1193 8 SvUTF8_on(pv_sv);
1194 }
1195 5327 return pv_sv;
1196 }
1197 0 case GQL_VM_NATIVE_SCALAR_FALLBACK_SV:
1198 default:
1199 0 ▶ return value->scalar_fallback_sv ? newSVsv(value->scalar_fallback_sv) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return value->scalar_fallback_sv ? newSVsv(value->scalar_fallback_sv) : newSVsv(&PL_sv_undef); 0 0 0
1200 }
1201 }
1202 }
1203  
1204 static gql_runtime_vm_native_value_t *
1205 2138 gql_runtime_vm_native_value_from_sv(pTHX_ SV *value)
1206 {
1207 SSize_t i;
1208 2138 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 2138 0 2138
if (!value || !SvOK(value)) { 8 2130 2138
1209 8 return gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
1210 }
1211 2130 ▶ if (SvROK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(value)) { 47 2083 2130
1212 47 SV *rv = SvRV(value);
1213 47 ▶ if (SvTYPE(rv) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(rv) == SVt_PVHV) { 39 8 47
1214 39 HV *hv = (HV *)rv;
1215 HE *he;
1216 39 gql_runtime_vm_native_value_t *ret = gql_runtime_vm_new_native_value_object();
1217 39 hv_iterinit(hv);
1218 87 ▶ while ((he = hv_iternext(hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(hv))) { 48 39 87
1219 48 SV *key_sv = hv_iterkeysv(he);
1220 48 SV *val_sv = hv_iterval(hv, he);
1221 48 STRLEN key_len = 0;
1222 96 ▶ const char *key_pv = key_sv ? SvPV(key_sv, key_len) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *key_pv = key_sv ? SvPV(key_sv, key_len) : ""; 48 0 48
1223 /* store copies non-borrowed names itself (SvPV is NUL-terminated). */
1224 48 gql_runtime_vm_native_object_store(aTHX_ ret, key_pv, 0, gql_runtime_vm_native_value_from_sv(aTHX_ val_sv));
1225 }
1226 39 return ret;
1227 }
1228 8 ▶ if (SvTYPE(rv) == SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(rv) == SVt_PVAV) { 8 0 8
1229 8 AV *av = (AV *)rv;
1230 8 gql_runtime_vm_native_value_t *ret = gql_runtime_vm_new_native_value_list();
1231 34 ▶ for (i = 0; i <= av_len(av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(av); i++) { 26 8 34
1232 26 SV **svp = av_fetch(av, i, 0);
1233 26 ▶ gql_runtime_vm_native_list_push(ret, gql_runtime_vm_native_value_from_sv(aTHX_ (svp && *svp) ? *svp : &PL_sv_undef));
Branch: 2 branches
BranchTrueFalseTotal
gql_runtime_vm_native_list_push(ret, gql_runtime_vm_native_value_from_sv(aTHX_ (svp && *svp) ? *svp : &PL_sv_undef)); 26 0 26
gql_runtime_vm_native_list_push(ret, gql_runtime_vm_native_value_from_sv(aTHX_ (svp && *svp) ? *svp : &PL_sv_undef)); 26 0 26
1234 }
1235 8 return ret;
1236 }
1237 }
1238 2083 return gql_runtime_vm_new_native_value_scalar(aTHX_ value);
1239 }
1240  
1241 static gql_runtime_vm_native_value_t *
1242 1930 gql_runtime_vm_native_value_clone(pTHX_ const gql_runtime_vm_native_value_t *value)
1243 {
1244 IV i;
1245 gql_runtime_vm_native_value_t *ret;
1246 1930 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 1930 1930
1247 0 return gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
1248 }
1249 1930 switch (value->kind_code) {
1250 17 case GQL_VM_NATIVE_VALUE_OBJECT:
1251 17 ret = gql_runtime_vm_new_native_value_object();
1252 50 ▶ for (i = 0; i < value->object.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object.count; i++) { 33 17 50
1253 0 gql_runtime_vm_native_object_store(
1254 aTHX_ ret,
1255 33 value->object.names[i],
1256 /* Plan-borrowed names stay borrowed: clones never outlive the
1257 * request, and the plan outlives it. */
1258 33 ▶ value->object.names_borrowed ? value->object.names_borrowed[i] : 0,
Branch: 1 branch
BranchTrueFalseTotal
value->object.names_borrowed ? value->object.names_borrowed[i] : 0, 33 0 33
1259 33 gql_runtime_vm_native_value_clone(aTHX_ value->object.values[i])
1260 );
1261 }
1262 17 return ret;
1263 0 case GQL_VM_NATIVE_VALUE_LIST:
1264 0 ret = gql_runtime_vm_new_native_value_list();
1265 0 ▶ for (i = 0; i < value->list.count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list.count; i++) { 0 0 0
1266 0 gql_runtime_vm_native_list_push(
1267 ret,
1268 0 gql_runtime_vm_native_value_clone(aTHX_ value->list.items[i])
1269 );
1270 }
1271 0 return ret;
1272 1913 case GQL_VM_NATIVE_VALUE_SCALAR:
1273 default:
1274 1913 switch (value->scalar_kind_code) {
1275 3 case GQL_VM_NATIVE_SCALAR_UNDEF:
1276 3 return gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
1277 1875 case GQL_VM_NATIVE_SCALAR_IV:
1278 1875 ret = gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
1279 1875 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_IV;
1280 1875 ret->scalar_iv = value->scalar_iv;
1281 1875 return ret;
1282 0 case GQL_VM_NATIVE_SCALAR_NV:
1283 0 ret = gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
1284 0 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_NV;
1285 0 ret->scalar_nv = value->scalar_nv;
1286 0 return ret;
1287 35 case GQL_VM_NATIVE_SCALAR_PV:
1288 35 ret = gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
1289 35 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_PV;
1290 35 ▶ if (value->scalar_pv && value->scalar_pv_len) {
Branch: 2 branches
BranchTrueFalseTotal
if (value->scalar_pv && value->scalar_pv_len) { 35 0 35
if (value->scalar_pv && value->scalar_pv_len) { 35 0 35
1291 35 ret->scalar_pv = savepvn(value->scalar_pv, value->scalar_pv_len);
1292 35 ret->scalar_pv_len = value->scalar_pv_len;
1293 35 ret->scalar_pv_is_utf8 = value->scalar_pv_is_utf8;
1294 }
1295 35 return ret;
1296 0 case GQL_VM_NATIVE_SCALAR_FALLBACK_SV:
1297 default:
1298 0 ▶ return gql_runtime_vm_new_native_value_scalar(aTHX_ value->scalar_fallback_sv ? value->scalar_fallback_sv : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_new_native_value_scalar(aTHX_ value->scalar_fallback_sv ? value->scalar_fallback_sv : &PL_sv_undef); 0 0 0
1299 }
1300 }
1301 }
1302  
1303 static gql_runtime_vm_native_dynamic_value_t *
1304 428 gql_runtime_vm_native_dynamic_value_from_sv(pTHX_ SV *value)
1305 {
1306 gql_runtime_vm_native_dynamic_value_t *ret;
1307 428 STRLEN len = 0;
1308  
1309 428 Newxz(ret, 1, gql_runtime_vm_native_dynamic_value_t);
1310 428 ret->kind_code = GQL_VM_DYNAMIC_UNDEF;
1311 428 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_UNDEF;
1312 428 ret->variable_index = -1;
1313  
1314 428 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 428 0 428
if (!value || !SvOK(value)) { 3 425 428
1315 3 return ret;
1316 }
1317  
1318 425 ▶ if (SvROK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(value)) { 171 254 425
1319 171 SV *inner = SvRV(value);
1320 171 ▶ if (SvTYPE(inner) == SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(inner) == SVt_PVAV) { 4 167 171
1321 4 AV *av = (AV *)inner;
1322 IV i;
1323 4 ret->kind_code = GQL_VM_DYNAMIC_LIST;
1324 4 ret->list_count = av_len(av) + 1;
1325 4 ▶ if (ret->list_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret->list_count > 0) { 4 0 4
1326 4 ▶ Newxz(ret->list_values, ret->list_count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->list_values, ret->list_count, gql_runtime_vm_native_dynamic_value_t *); 0 4 4
1327 14 ▶ for (i = 0; i < ret->list_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ret->list_count; i++) { 10 4 14
1328 10 SV **svp = av_fetch(av, i, 0);
1329 10 ▶ ret->list_values[i] = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ (svp && SvOK(*svp)) ? *svp : &PL_sv_undef);
Branch: 2 branches
BranchTrueFalseTotal
ret->list_values[i] = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ (svp && SvOK(*svp)) ? *svp : &PL_sv_undef); 10 0 10
ret->list_values[i] = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ (svp && SvOK(*svp)) ? *svp : &PL_sv_undef); 10 0 10
1330 }
1331 }
1332 4 return ret;
1333 }
1334 167 ▶ if (SvTYPE(inner) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(inner) == SVt_PVHV) { 21 146 167
1335 21 HV *hv = (HV *)inner;
1336 HE *he;
1337 21 ▶ IV count = HvUSEDKEYS(hv);
Branch: 1 branch
BranchTrueFalseTotal
IV count = HvUSEDKEYS(hv); 0 21 21
1338 21 ret->kind_code = GQL_VM_DYNAMIC_OBJECT;
1339 21 ret->object_count = count;
1340 21 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 21 0 21
1341 21 IV i = 0;
1342 21 ▶ Newxz(ret->object_names, count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->object_names, count, char *); 0 21 21
1343 21 ▶ Newxz(ret->object_values, count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->object_values, count, gql_runtime_vm_native_dynamic_value_t *); 0 21 21
1344 21 hv_iterinit(hv);
1345 47 ▶ while ((he = hv_iternext(hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(hv))) { 26 21 47
1346 26 SV *key_sv = hv_iterkeysv(he);
1347 26 SV *val_sv = hv_iterval(hv, he);
1348 26 const char *key_pv = SvPV(key_sv, len);
1349 26 ret->object_names[i] = savepvn(key_pv, len);
1350 26 ret->object_values[i] = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ val_sv);
1351 26 i++;
1352 }
1353 21 ret->object_count = i;
1354 }
1355 21 return ret;
1356 }
1357 146 ▶ if (SvTYPE(inner) == SVt_PV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(inner) == SVt_PV) { 146 0 146
1358 146 const char *name = SvPV(inner, len);
1359 146 ret->kind_code = GQL_VM_DYNAMIC_VARIABLE;
1360 146 ret->variable_name = savepvn(name, len);
1361 146 return ret;
1362 }
1363 }
1364  
1365 254 ret->kind_code = GQL_VM_DYNAMIC_SCALAR;
1366 254 ▶ if (SvPOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOKp(value)) { 196 58 254
1367 196 const char *pv = SvPV(value, len);
1368 196 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_PV;
1369 196 ret->scalar_pv = savepvn(pv, len);
1370 196 ret->scalar_pv_len = len;
1371 196 ret->scalar_pv_is_utf8 = SvUTF8(value) ? 1 : 0;
1372 196 return ret;
1373 }
1374 58 ▶ if (SvIOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOKp(value)) { 58 0 58
1375 58 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_IV;
1376 58 ret->scalar_iv = SvIV(value);
1377 58 return ret;
1378 }
1379 0 ▶ if (SvNOKp(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOKp(value)) { 0 0 0
1380 0 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_NV;
1381 0 ret->scalar_nv = SvNV(value);
1382 0 return ret;
1383 }
1384 0 return ret;
1385 }
1386  
1387 static gql_runtime_vm_native_dynamic_value_t *
1388 1 gql_runtime_vm_native_dynamic_value_from_native_value(
1389 pTHX_ const gql_runtime_vm_native_value_t *value
1390 )
1391 {
1392 gql_runtime_vm_native_dynamic_value_t *ret;
1393 IV i;
1394  
1395 1 Newxz(ret, 1, gql_runtime_vm_native_dynamic_value_t);
1396 1 ret->kind_code = GQL_VM_DYNAMIC_UNDEF;
1397 1 ret->scalar_kind_code = GQL_VM_NATIVE_SCALAR_UNDEF;
1398 1 ret->variable_index = -1;
1399  
1400 1 ▶ if (!value || value->kind_code == GQL_VM_NATIVE_VALUE_UNDEF) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || value->kind_code == GQL_VM_NATIVE_VALUE_UNDEF) { 1 0 1
if (!value || value->kind_code == GQL_VM_NATIVE_VALUE_UNDEF) { 0 1 1
1401 0 return ret;
1402 }
1403  
1404 1 switch (value->kind_code) {
1405 0 case GQL_VM_NATIVE_VALUE_OBJECT:
1406 0 ret->kind_code = GQL_VM_DYNAMIC_OBJECT;
1407 0 ret->object_count = value->object.count;
1408 0 ▶ if (ret->object_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret->object_count > 0) { 0 0 0
1409 0 ▶ Newxz(ret->object_names, ret->object_count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->object_names, ret->object_count, char *); 0 0 0
1410 0 ▶ Newxz(ret->object_values, ret->object_count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->object_values, ret->object_count, gql_runtime_vm_native_dynamic_value_t *); 0 0 0
1411 0 ▶ for (i = 0; i < ret->object_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ret->object_count; i++) { 0 0 0
1412 0 ▶ if (value->object.names && value->object.names[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (value->object.names && value->object.names[i]) { 0 0 0
if (value->object.names && value->object.names[i]) { 0 0 0
1413 0 ret->object_names[i] = savepv(value->object.names[i]);
1414 }
1415 0 ret->object_values[i] = gql_runtime_vm_native_dynamic_value_from_native_value(
1416 0 ▶ aTHX_ value->object.values ? value->object.values[i] : NULL
Branch: 1 branch
BranchTrueFalseTotal
aTHX_ value->object.values ? value->object.values[i] : NULL 0 0 0
1417 );
1418 }
1419 }
1420 0 return ret;
1421 0 case GQL_VM_NATIVE_VALUE_LIST:
1422 0 ret->kind_code = GQL_VM_DYNAMIC_LIST;
1423 0 ret->list_count = value->list.count;
1424 0 ▶ if (ret->list_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret->list_count > 0) { 0 0 0
1425 0 ▶ Newxz(ret->list_values, ret->list_count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->list_values, ret->list_count, gql_runtime_vm_native_dynamic_value_t *); 0 0 0
1426 0 ▶ for (i = 0; i < ret->list_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < ret->list_count; i++) { 0 0 0
1427 0 ret->list_values[i] = gql_runtime_vm_native_dynamic_value_from_native_value(
1428 0 ▶ aTHX_ value->list.items ? value->list.items[i] : NULL
Branch: 1 branch
BranchTrueFalseTotal
aTHX_ value->list.items ? value->list.items[i] : NULL 0 0 0
1429 );
1430 }
1431 }
1432 0 return ret;
1433 1 case GQL_VM_NATIVE_VALUE_SCALAR:
1434 default:
1435 1 ret->kind_code = GQL_VM_DYNAMIC_SCALAR;
1436 1 ret->scalar_kind_code = value->scalar_kind_code;
1437 1 ret->scalar_iv = value->scalar_iv;
1438 1 ret->scalar_nv = value->scalar_nv;
1439 1 ▶ if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV && value->scalar_pv) {
Branch: 2 branches
BranchTrueFalseTotal
if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV && value->scalar_pv) { 0 1 1
if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV && value->scalar_pv) { 0 0 0
1440 0 ret->scalar_pv = savepvn(value->scalar_pv, value->scalar_pv_len);
1441 0 ret->scalar_pv_len = value->scalar_pv_len;
1442 0 ret->scalar_pv_is_utf8 = value->scalar_pv_is_utf8;
1443 1 ▶ } else if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_FALLBACK_SV && value->scalar_fallback_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_FALLBACK_SV && value->scalar_fallback_sv) { 0 1 1
} else if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_FALLBACK_SV && value->scalar_fallback_sv) { 0 0 0
1444 0 gql_runtime_vm_native_dynamic_value_destroy(aTHX_ ret);
1445 0 return gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ value->scalar_fallback_sv);
1446 }
1447 1 return ret;
1448 }
1449 }
1450  
1451 static gql_runtime_vm_native_dynamic_value_t *
1452 591 gql_runtime_vm_native_dynamic_value_clone(
1453 pTHX_ const gql_runtime_vm_native_dynamic_value_t *value
1454 )
1455 {
1456 gql_runtime_vm_native_dynamic_value_t *ret;
1457 IV i;
1458  
1459 591 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 591 591
1460 0 return NULL;
1461 }
1462 591 Newxz(ret, 1, gql_runtime_vm_native_dynamic_value_t);
1463 591 *ret = *value;
1464 591 ret->scalar_pv = NULL;
1465 591 ret->variable_name = NULL;
1466 591 ret->object_names = NULL;
1467 591 ret->object_values = NULL;
1468 591 ret->list_values = NULL;
1469  
1470 591 ▶ if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV && value->scalar_pv) {
Branch: 2 branches
BranchTrueFalseTotal
if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV && value->scalar_pv) { 184 407 591
if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV && value->scalar_pv) { 184 0 184
1471 184 ret->scalar_pv = savepvn(value->scalar_pv, value->scalar_pv_len);
1472 }
1473 591 ▶ if (value->kind_code == GQL_VM_DYNAMIC_VARIABLE && value->variable_name) {
Branch: 2 branches
BranchTrueFalseTotal
if (value->kind_code == GQL_VM_DYNAMIC_VARIABLE && value->variable_name) { 299 292 591
if (value->kind_code == GQL_VM_DYNAMIC_VARIABLE && value->variable_name) { 299 0 299
1474 299 ret->variable_name = savepv(value->variable_name);
1475 }
1476 591 ▶ if (value->kind_code == GQL_VM_DYNAMIC_OBJECT && value->object_count > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (value->kind_code == GQL_VM_DYNAMIC_OBJECT && value->object_count > 0) { 31 560 591
if (value->kind_code == GQL_VM_DYNAMIC_OBJECT && value->object_count > 0) { 31 0 31
1477 31 ▶ Newxz(ret->object_names, value->object_count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->object_names, value->object_count, char *); 0 31 31
1478 31 ▶ Newxz(ret->object_values, value->object_count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->object_values, value->object_count, gql_runtime_vm_native_dynamic_value_t *); 0 31 31
1479 66 ▶ for (i = 0; i < value->object_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object_count; i++) { 35 31 66
1480 35 ▶ ret->object_names[i] = value->object_names[i] ? savepv(value->object_names[i]) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
ret->object_names[i] = value->object_names[i] ? savepv(value->object_names[i]) : NULL; 35 0 35
1481 35 ret->object_values[i] = gql_runtime_vm_native_dynamic_value_clone(aTHX_ value->object_values[i]);
1482 }
1483 }
1484 591 ▶ if (value->kind_code == GQL_VM_DYNAMIC_LIST && value->list_count > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (value->kind_code == GQL_VM_DYNAMIC_LIST && value->list_count > 0) { 4 587 591
if (value->kind_code == GQL_VM_DYNAMIC_LIST && value->list_count > 0) { 4 0 4
1485 4 ▶ Newxz(ret->list_values, value->list_count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->list_values, value->list_count, gql_runtime_vm_native_dynamic_value_t *); 0 4 4
1486 14 ▶ for (i = 0; i < value->list_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list_count; i++) { 10 4 14
1487 10 ret->list_values[i] = gql_runtime_vm_native_dynamic_value_clone(aTHX_ value->list_values[i]);
1488 }
1489 }
1490 591 return ret;
1491 }
1492  
1493 static void
1494 296 gql_runtime_vm_bind_dynamic_value_variables(
1495 gql_runtime_vm_native_dynamic_value_t *value,
1496 const gql_runtime_vm_native_arg_def_t *variable_defs,
1497 IV variable_def_count
1498 )
1499 {
1500 IV i;
1501  
1502 296 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 296 296
1503 0 return;
1504 }
1505 296 ▶ if (value->kind_code == GQL_VM_DYNAMIC_VARIABLE) {
Branch: 1 branch
BranchTrueFalseTotal
if (value->kind_code == GQL_VM_DYNAMIC_VARIABLE) { 151 145 296
1506 151 value->variable_index = -1;
1507 151 ▶ if (!value->variable_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value->variable_name) { 0 151 151
1508 0 return;
1509 }
1510 186 ▶ for (i = 0; i < variable_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < variable_def_count; i++) { 186 0 186
1511 186 ▶ if (variable_defs[i].name && strEQ(variable_defs[i].name, value->variable_name)) {
Branch: 2 branches
BranchTrueFalseTotal
if (variable_defs[i].name && strEQ(variable_defs[i].name, value->variable_name)) { 186 0 186
if (variable_defs[i].name && strEQ(variable_defs[i].name, value->variable_name)) { 151 35 186
1512 151 value->variable_index = i;
1513 151 return;
1514 }
1515 }
1516 0 return;
1517 }
1518 145 ▶ if (value->kind_code == GQL_VM_DYNAMIC_OBJECT) {
Branch: 1 branch
BranchTrueFalseTotal
if (value->kind_code == GQL_VM_DYNAMIC_OBJECT) { 13 132 145
1519 28 ▶ for (i = 0; i < value->object_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object_count; i++) { 15 13 28
1520 15 gql_runtime_vm_bind_dynamic_value_variables(
1521 15 ▶ value->object_values ? value->object_values[i] : NULL,
Branch: 1 branch
BranchTrueFalseTotal
value->object_values ? value->object_values[i] : NULL, 15 0 15
1522 variable_defs,
1523 variable_def_count
1524 );
1525 }
1526 132 ▶ } else if (value->kind_code == GQL_VM_DYNAMIC_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (value->kind_code == GQL_VM_DYNAMIC_LIST) { 2 130 132
1527 7 ▶ for (i = 0; i < value->list_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list_count; i++) { 5 2 7
1528 5 gql_runtime_vm_bind_dynamic_value_variables(
1529 5 ▶ value->list_values ? value->list_values[i] : NULL,
Branch: 1 branch
BranchTrueFalseTotal
value->list_values ? value->list_values[i] : NULL, 5 0 5
1530 variable_defs,
1531 variable_def_count
1532 );
1533 }
1534 }
1535 }
1536  
1537 static void
1538 1020 gql_runtime_vm_native_dynamic_value_destroy(
1539 pTHX_ gql_runtime_vm_native_dynamic_value_t *value
1540 )
1541 {
1542 IV i;
1543  
1544 1020 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 0 1020 1020
1545 0 return;
1546 }
1547 1020 ▶ if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV) {
Branch: 1 branch
BranchTrueFalseTotal
if (value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_PV) { 380 640 1020
1548 380 Safefree(value->scalar_pv);
1549 }
1550 1020 Safefree(value->variable_name);
1551 1020 ▶ if (value->kind_code == GQL_VM_DYNAMIC_OBJECT) {
Branch: 1 branch
BranchTrueFalseTotal
if (value->kind_code == GQL_VM_DYNAMIC_OBJECT) { 52 968 1020
1552 113 ▶ for (i = 0; i < value->object_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object_count; i++) { 61 52 113
1553 61 ▶ Safefree(value->object_names ? value->object_names[i] : NULL);
Branch: 1 branch
BranchTrueFalseTotal
Safefree(value->object_names ? value->object_names[i] : NULL); 61 0 61
1554 61 ▶ gql_runtime_vm_native_dynamic_value_destroy(aTHX_ value->object_values ? value->object_values[i] : NULL);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_dynamic_value_destroy(aTHX_ value->object_values ? value->object_values[i] : NULL); 61 0 61
1555 }
1556 52 Safefree(value->object_names);
1557 52 Safefree(value->object_values);
1558 968 ▶ } else if (value->kind_code == GQL_VM_DYNAMIC_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (value->kind_code == GQL_VM_DYNAMIC_LIST) { 8 960 968
1559 28 ▶ for (i = 0; i < value->list_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list_count; i++) { 20 8 28
1560 20 ▶ gql_runtime_vm_native_dynamic_value_destroy(aTHX_ value->list_values ? value->list_values[i] : NULL);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_dynamic_value_destroy(aTHX_ value->list_values ? value->list_values[i] : NULL); 20 0 20
1561 }
1562 8 Safefree(value->list_values);
1563 }
1564 1020 Safefree(value);
1565 }
1566  
1567 static SV *
1568 526 gql_runtime_vm_native_dynamic_value_materialize_sv(
1569 pTHX_ const gql_runtime_vm_native_dynamic_value_t *value,
1570 HV *variables
1571 )
1572 {
1573 IV i;
1574  
1575 526 ▶ if (!value || value->kind_code == GQL_VM_DYNAMIC_UNDEF) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || value->kind_code == GQL_VM_DYNAMIC_UNDEF) { 526 0 526
if (!value || value->kind_code == GQL_VM_DYNAMIC_UNDEF) { 2 524 526
1576 2 return newSV(0);
1577 }
1578  
1579 524 switch (value->kind_code) {
1580 4 case GQL_VM_DYNAMIC_VARIABLE: {
1581 3 ▶ SV **svp = (variables && value->variable_name)
Branch: 1 branch
BranchTrueFalseTotal
SV **svp = (variables && value->variable_name) 3 0 3
1582 3 ? hv_fetch(variables, value->variable_name, (I32)strlen(value->variable_name), 0)
1583 4 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 3 1 4
1584 4 ▶ return (svp && SvOK(*svp)) ? newSVsv(*svp) : newSV(0);
Branch: 2 branches
BranchTrueFalseTotal
return (svp && SvOK(*svp)) ? newSVsv(*svp) : newSV(0); 2 2 4
return (svp && SvOK(*svp)) ? newSVsv(*svp) : newSV(0); 2 0 2
1585 }
1586 4 case GQL_VM_DYNAMIC_LIST: {
1587 4 AV *av = newAV();
1588 14 ▶ for (i = 0; i < value->list_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->list_count; i++) { 10 4 14
1589 10 av_push(av, gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ value->list_values[i], variables));
1590 }
1591 4 return newRV_noinc((SV *)av);
1592 }
1593 27 case GQL_VM_DYNAMIC_OBJECT: {
1594 27 HV *hv = newHV();
1595 59 ▶ for (i = 0; i < value->object_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < value->object_count; i++) { 32 27 59
1596 32 ▶ if (!value->object_names || !value->object_names[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value->object_names || !value->object_names[i]) { 32 0 32
if (!value->object_names || !value->object_names[i]) { 0 32 32
1597 0 continue;
1598 }
1599 32 hv_store(
1600 hv,
1601 value->object_names[i],
1602 (I32)strlen(value->object_names[i]),
1603 gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ value->object_values[i], variables),
1604 0
1605 );
1606 }
1607 27 return newRV_noinc((SV *)hv);
1608 }
1609 489 case GQL_VM_DYNAMIC_SCALAR:
1610 default:
1611 489 switch (value->scalar_kind_code) {
1612 277 case GQL_VM_NATIVE_SCALAR_IV:
1613 277 return newSViv(value->scalar_iv);
1614 0 case GQL_VM_NATIVE_SCALAR_NV:
1615 0 return newSVnv(value->scalar_nv);
1616 212 case GQL_VM_NATIVE_SCALAR_PV: {
1617 212 ▶ SV *pv_sv = newSVpvn(value->scalar_pv ? value->scalar_pv : "", value->scalar_pv_len);
Branch: 1 branch
BranchTrueFalseTotal
SV *pv_sv = newSVpvn(value->scalar_pv ? value->scalar_pv : "", value->scalar_pv_len); 212 0 212
1618 212 ▶ if (value->scalar_pv_is_utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if (value->scalar_pv_is_utf8) { 23 189 212
1619 23 SvUTF8_on(pv_sv);
1620 }
1621 212 return pv_sv;
1622 }
1623 0 default:
1624 0 return newSV(0);
1625 }
1626 }
1627 }
1628  
1629 static int
1630 15 gql_runtime_vm_native_dynamic_value_truthy(
1631 pTHX_ const gql_runtime_vm_native_dynamic_value_t *value,
1632 HV *variables,
1633 SV **variable_slots,
1634 IV variable_slot_count
1635 )
1636 {
1637 15 ▶ if (!value || value->kind_code == GQL_VM_DYNAMIC_UNDEF) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || value->kind_code == GQL_VM_DYNAMIC_UNDEF) { 15 0 15
if (!value || value->kind_code == GQL_VM_DYNAMIC_UNDEF) { 0 15 15
1638 0 return 0;
1639 }
1640  
1641 15 switch (value->kind_code) {
1642 15 case GQL_VM_DYNAMIC_VARIABLE: {
1643 15 ▶ if (variable_slots
Branch: 1 branch
BranchTrueFalseTotal
if (variable_slots 9 6 15
1644 9 ▶ && value->variable_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
&& value->variable_index >= 0 9 0 9
1645 9 ▶ && value->variable_index < variable_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
&& value->variable_index < variable_slot_count) { 9 0 9
1646 9 SV *slot_value = variable_slots[value->variable_index];
1647 9 ▶ return (slot_value && SvOK(slot_value) && SvTRUE(slot_value)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
return (slot_value && SvOK(slot_value) && SvTRUE(slot_value)) ? 1 : 0; 9 0 9
return (slot_value && SvOK(slot_value) && SvTRUE(slot_value)) ? 1 : 0; 9 0 9
return (slot_value && SvOK(slot_value) && SvTRUE(slot_value)) ? 1 : 0; 6 3 9
1648 }
1649 6 ▶ SV **svp = (variables && value->variable_name)
Branch: 1 branch
BranchTrueFalseTotal
SV **svp = (variables && value->variable_name) 6 0 6
1650 6 ? hv_fetch(variables, value->variable_name, (I32)strlen(value->variable_name), 0)
1651 6 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 6 0 6
1652 6 ▶ return (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
return (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 6 0 6
return (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 6 0 6
return (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 6 0 6
1653 }
1654 0 case GQL_VM_DYNAMIC_LIST:
1655 case GQL_VM_DYNAMIC_OBJECT:
1656 0 return 1;
1657 0 case GQL_VM_DYNAMIC_SCALAR:
1658 default:
1659 0 switch (value->scalar_kind_code) {
1660 0 case GQL_VM_NATIVE_SCALAR_IV:
1661 0 return value->scalar_iv ? 1 : 0;
1662 0 case GQL_VM_NATIVE_SCALAR_NV:
1663 0 return value->scalar_nv != 0.0 ? 1 : 0;
1664 0 case GQL_VM_NATIVE_SCALAR_PV:
1665 0 ▶ if (!value->scalar_pv || value->scalar_pv_len == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value->scalar_pv || value->scalar_pv_len == 0) { 0 0 0
if (!value->scalar_pv || value->scalar_pv_len == 0) { 0 0 0
1666 0 return 0;
1667 }
1668 0 ▶ if (value->scalar_pv_len == 1 && value->scalar_pv[0] == '0') {
Branch: 2 branches
BranchTrueFalseTotal
if (value->scalar_pv_len == 1 && value->scalar_pv[0] == '0') { 0 0 0
if (value->scalar_pv_len == 1 && value->scalar_pv[0] == '0') { 0 0 0
1669 0 return 0;
1670 }
1671 0 return 1;
1672 0 case GQL_VM_NATIVE_SCALAR_UNDEF:
1673 default:
1674 0 return 0;
1675 }
1676 }
1677 }
1678  
1679 static const gql_runtime_vm_native_dynamic_value_t *
1680 5490 gql_runtime_vm_native_args_payload_lookup_value(
1681 const gql_runtime_vm_native_args_payload_t *payload,
1682 const char *arg_name,
1683 IV hint_index
1684 )
1685 {
1686 IV j;
1687  
1688 5490 ▶ if (!payload || !arg_name) {
Branch: 2 branches
BranchTrueFalseTotal
if (!payload || !arg_name) { 5357 133 5490
if (!payload || !arg_name) { 0 5357 5357
1689 133 return NULL;
1690 }
1691  
1692 5357 ▶ if (hint_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (hint_index >= 0 5357 0 5357
1693 5357 ▶ && hint_index < payload->count
Branch: 1 branch
BranchTrueFalseTotal
&& hint_index < payload->count 5294 63 5357
1694 5294 ▶ && payload->names
Branch: 1 branch
BranchTrueFalseTotal
&& payload->names 5294 0 5294
1695 5294 ▶ && payload->names[hint_index]
Branch: 1 branch
BranchTrueFalseTotal
&& payload->names[hint_index] 5294 0 5294
1696 5294 ▶ && strEQ(payload->names[hint_index], arg_name)) {
Branch: 1 branch
BranchTrueFalseTotal
&& strEQ(payload->names[hint_index], arg_name)) { 5262 32 5294
1697 5262 ▶ return payload->values ? payload->values[hint_index] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return payload->values ? payload->values[hint_index] : NULL; 5262 0 5262
1698 }
1699  
1700 181 ▶ for (j = 0; j < payload->count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < payload->count; j++) { 118 63 181
1701 118 ▶ if (payload->names && payload->names[j] && strEQ(payload->names[j], arg_name)) {
Branch: 3 branches
BranchTrueFalseTotal
if (payload->names && payload->names[j] && strEQ(payload->names[j], arg_name)) { 118 0 118
if (payload->names && payload->names[j] && strEQ(payload->names[j], arg_name)) { 118 0 118
if (payload->names && payload->names[j] && strEQ(payload->names[j], arg_name)) { 32 86 118
1702 32 ▶ return payload->values ? payload->values[j] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return payload->values ? payload->values[j] : NULL; 32 0 32
1703 }
1704 }
1705  
1706 63 return NULL;
1707 }
1708  
1709 static gql_runtime_vm_native_args_payload_t *
1710 254 gql_runtime_vm_native_args_payload_from_hv(pTHX_ HV *hv)
1711 {
1712 HE *he;
1713 gql_runtime_vm_native_args_payload_t *payload;
1714 254 IV count = 0;
1715  
1716 254 ▶ if (!hv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!hv) { 0 254 254
1717 0 return NULL;
1718 }
1719  
1720 254 Newxz(payload, 1, gql_runtime_vm_native_args_payload_t);
1721 254 ▶ count = HvUSEDKEYS(hv);
Branch: 1 branch
BranchTrueFalseTotal
count = HvUSEDKEYS(hv); 0 254 254
1722 254 payload->count = count;
1723 254 ▶ if (count <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count <= 0) { 0 254 254
1724 0 return payload;
1725 }
1726  
1727 254 ▶ Newxz(payload->names, count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(payload->names, count, char *); 0 254 254
1728 254 ▶ Newxz(payload->values, count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(payload->values, count, gql_runtime_vm_native_dynamic_value_t *); 0 254 254
1729  
1730 254 hv_iterinit(hv);
1731 254 count = 0;
1732 517 ▶ while ((he = hv_iternext(hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(hv))) { 263 254 517
1733 263 SV *key_sv = hv_iterkeysv(he);
1734 263 SV *val_sv = hv_iterval(hv, he);
1735 263 STRLEN key_len = 0;
1736 526 ▶ const char *key_pv = key_sv ? SvPV(key_sv, key_len) : "";
Branch: 1 branch
BranchTrueFalseTotal
const char *key_pv = key_sv ? SvPV(key_sv, key_len) : ""; 263 0 263
1737 263 payload->names[count] = savepvn(key_pv, key_len);
1738 263 payload->values[count] = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ val_sv);
1739 263 count++;
1740 }
1741 254 payload->count = count;
1742 254 return payload;
1743 }
1744  
1745 static gql_runtime_vm_native_args_payload_t *
1746 500 gql_runtime_vm_native_args_payload_clone(
1747 pTHX_ const gql_runtime_vm_native_args_payload_t *payload
1748 )
1749 {
1750 gql_runtime_vm_native_args_payload_t *copy;
1751 IV i;
1752  
1753 500 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 500 500
1754 0 return NULL;
1755 }
1756  
1757 500 Newxz(copy, 1, gql_runtime_vm_native_args_payload_t);
1758 500 copy->count = payload->count;
1759 500 ▶ if (copy->count <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (copy->count <= 0) { 0 500 500
1760 0 return copy;
1761 }
1762  
1763 500 ▶ Newxz(copy->names, copy->count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(copy->names, copy->count, char *); 0 500 500
1764 500 ▶ Newxz(copy->values, copy->count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(copy->values, copy->count, gql_runtime_vm_native_dynamic_value_t *); 0 500 500
1765 1018 ▶ for (i = 0; i < copy->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < copy->count; i++) { 518 500 1018
1766 518 ▶ copy->names[i] = payload->names[i] ? savepv(payload->names[i]) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
copy->names[i] = payload->names[i] ? savepv(payload->names[i]) : NULL; 518 0 518
1767 518 copy->values[i] = gql_runtime_vm_native_dynamic_value_clone(aTHX_ payload->values[i]);
1768 }
1769 500 return copy;
1770 }
1771  
1772 static void
1773 4487 gql_runtime_vm_native_args_payload_destroy(pTHX_ gql_runtime_vm_native_args_payload_t *payload)
1774 {
1775 IV i;
1776 4487 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 3613 874 4487
1777 3613 return;
1778 }
1779 1773 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 899 874 1773
1780 899 ▶ Safefree(payload->names ? payload->names[i] : NULL);
Branch: 1 branch
BranchTrueFalseTotal
Safefree(payload->names ? payload->names[i] : NULL); 899 0 899
1781 899 ▶ gql_runtime_vm_native_dynamic_value_destroy(aTHX_ payload->values ? payload->values[i] : NULL);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_dynamic_value_destroy(aTHX_ payload->values ? payload->values[i] : NULL); 899 0 899
1782 }
1783 874 ▶ if (payload->static_args_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (payload->static_args_sv) { 7 867 874
1784 7 SvREFCNT_dec(payload->static_args_sv);
1785 }
1786 874 ▶ if (payload->static_one_arg_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (payload->static_one_arg_sv) { 2 872 874
1787 2 SvREFCNT_dec(payload->static_one_arg_sv);
1788 }
1789 874 Safefree(payload->names);
1790 874 Safefree(payload->values);
1791 874 Safefree(payload);
1792 }
1793  
1794 static SV *
1795 220 gql_runtime_vm_native_args_payload_materialize_sv(
1796 pTHX_ const gql_runtime_vm_native_args_payload_t *payload
1797 )
1798 {
1799 HV *hv;
1800 IV i;
1801  
1802 220 hv = newHV();
1803 220 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 220 220
1804 0 return newRV_noinc((SV *)hv);
1805 }
1806  
1807 444 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 224 220 444
1808 224 ▶ if (!payload->names || !payload->names[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (!payload->names || !payload->names[i]) { 224 0 224
if (!payload->names || !payload->names[i]) { 0 224 224
1809 0 continue;
1810 }
1811 224 ▶ hv_store(
Branch: 1 branch
BranchTrueFalseTotal
hv_store( 224 0 224
1812 hv,
1813 payload->names[i],
1814 (I32)strlen(payload->names[i]),
1815 gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ payload->values ? payload->values[i] : NULL, NULL),
1816 0
1817 );
1818 }
1819  
1820 220 return newRV_noinc((SV *)hv);
1821 }
1822  
1823 static SV *
1824 8 gql_runtime_vm_native_args_payload_materialize_cached_sv(
1825 pTHX_ gql_runtime_vm_native_args_payload_t *payload
1826 )
1827 {
1828 HV *hv;
1829 IV i;
1830  
1831 8 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 8 8
1832 0 return newRV_noinc((SV *)newHV());
1833 }
1834  
1835 8 ▶ if (payload->static_args_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (payload->static_args_sv) { 1 7 8
1836 1 return SvREFCNT_inc_simple_NN(payload->static_args_sv);
1837 }
1838  
1839 7 hv = newHV();
1840 14 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 7 7 14
1841 7 ▶ if (!payload->names || !payload->names[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (!payload->names || !payload->names[i]) { 7 0 7
if (!payload->names || !payload->names[i]) { 0 7 7
1842 0 continue;
1843 }
1844 7 ▶ hv_store(
Branch: 1 branch
BranchTrueFalseTotal
hv_store( 7 0 7
1845 hv,
1846 payload->names[i],
1847 (I32)strlen(payload->names[i]),
1848 gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ payload->values ? payload->values[i] : NULL, NULL),
1849 0
1850 );
1851 }
1852  
1853 7 payload->static_args_sv = newRV_noinc((SV *)hv);
1854 7 return SvREFCNT_inc_simple_NN(payload->static_args_sv);
1855 }
1856  
1857 static SV *
1858 2 gql_runtime_vm_native_args_payload_materialize_one_arg_cached_sv(
1859 pTHX_ gql_runtime_vm_native_args_payload_t *payload
1860 )
1861 {
1862 2 ▶ if (!payload || payload->count <= 0 || !payload->values || !payload->values[0]) {
Branch: 4 branches
BranchTrueFalseTotal
if (!payload || payload->count <= 0 || !payload->values || !payload->values[0]) { 2 0 2
if (!payload || payload->count <= 0 || !payload->values || !payload->values[0]) { 2 0 2
if (!payload || payload->count <= 0 || !payload->values || !payload->values[0]) { 2 0 2
if (!payload || payload->count <= 0 || !payload->values || !payload->values[0]) { 0 2 2
1863 0 return newSVsv(&PL_sv_undef);
1864 }
1865 2 ▶ if (!payload->static_one_arg_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload->static_one_arg_sv) { 2 0 2
1866 2 payload->static_one_arg_sv =
1867 2 gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ payload->values[0], NULL);
1868 }
1869 2 return SvREFCNT_inc_simple_NN(payload->static_one_arg_sv);
1870 }
1871  
1872 static SV *
1873 0 gql_runtime_vm_native_directives_payload_materialize_sv(
1874 pTHX_ const gql_runtime_vm_native_directives_payload_t *payload
1875 )
1876 {
1877 AV *av;
1878 IV i;
1879  
1880 0 av = newAV();
1881 0 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 0 0
1882 0 return newRV_noinc((SV *)av);
1883 }
1884  
1885 0 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 0 0 0
1886 0 HV *hv = newHV();
1887 0 HV *args_hv = newHV();
1888 SV *args_sv;
1889 0 gql_runtime_vm_native_guard_t *guard = &payload->guards[i];
1890 0 ▶ const char *name = (guard->kind_code == GQL_VM_GUARD_SKIP) ? "skip" : "include";
Branch: 1 branch
BranchTrueFalseTotal
const char *name = (guard->kind_code == GQL_VM_GUARD_SKIP) ? "skip" : "include"; 0 0 0
1891  
1892 0 hv_store(hv, "name", 4, newSVpv(name, 0), 0);
1893 0 hv_store(
1894 args_hv,
1895 "if",
1896 2,
1897 gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ guard->if_expr, NULL),
1898 0
1899 );
1900 0 args_sv = newRV_noinc((SV *)args_hv);
1901 0 hv_store(
1902 hv,
1903 "arguments",
1904 9,
1905 args_sv,
1906 0
1907 );
1908 0 av_push(av, newRV_noinc((SV *)hv));
1909 }
1910  
1911 0 return newRV_noinc((SV *)av);
1912 }
1913  
1914 static SV *
1915 224 gql_runtime_vm_native_slot_to_compact_sv(
1916 pTHX_ const gql_runtime_vm_native_slot_t *slot
1917 )
1918 {
1919 224 AV *av = newAV();
1920 224 AV *arg_defs_av = newAV();
1921 IV i;
1922  
1923 224 ▶ av_push(av, newSVpv(slot->field_name ? slot->field_name : "", 0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, newSVpv(slot->field_name ? slot->field_name : "", 0)); 224 0 224
1924 224 ▶ av_push(av, newSVpv(slot->result_name ? slot->result_name : "", 0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, newSVpv(slot->result_name ? slot->result_name : "", 0)); 224 0 224
1925 224 ▶ av_push(av, newSVpv(slot->return_type_name ? slot->return_type_name : "", 0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, newSVpv(slot->return_type_name ? slot->return_type_name : "", 0)); 224 0 224
1926 224 av_push(av, newSViv(slot->schema_slot_index));
1927 224 av_push(av, newSViv(slot->resolver_shape_code));
1928 224 av_push(av, newSViv(slot->completion_family_code));
1929 224 av_push(av, newSViv(slot->dispatch_family_code));
1930 224 av_push(av, newSViv(slot->return_type_kind_code));
1931 224 av_push(av, newSViv(slot->has_args ? 1 : 0));
1932 224 av_push(av, newSViv(slot->has_directives ? 1 : 0));
1933 224 av_push(av, newSViv(slot->resolver_mode_code));
1934  
1935 236 ▶ for (i = 0; i < slot->arg_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < slot->arg_def_count; i++) { 12 224 236
1936 12 AV *arg_def_av = newAV();
1937 12 gql_runtime_vm_native_arg_def_t *arg_def = &slot->arg_defs[i];
1938 12 ▶ av_push(arg_def_av, newSVpv(arg_def->name ? arg_def->name : "", 0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(arg_def_av, newSVpv(arg_def->name ? arg_def->name : "", 0)); 12 0 12
1939 12 ▶ av_push(arg_def_av, arg_def->type_def_sv ? newSVsv(arg_def->type_def_sv) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(arg_def_av, arg_def->type_def_sv ? newSVsv(arg_def->type_def_sv) : newSV(0)); 12 0 12
1940 12 av_push(arg_def_av, newSViv(arg_def->has_default ? 1 : 0));
1941 12 ▶ if (arg_def->has_default) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg_def->has_default) { 0 12 12
1942 0 SV *default_sv = arg_def->default_native_value
1943 0 ? gql_runtime_vm_native_value_materialize_sv(aTHX_ arg_def->default_native_value)
1944 0 ▶ : (arg_def->default_value_sv ? newSVsv(arg_def->default_value_sv) : newSV(0));
Branch: 2 branches
BranchTrueFalseTotal
: (arg_def->default_value_sv ? newSVsv(arg_def->default_value_sv) : newSV(0)); 0 0 0
: (arg_def->default_value_sv ? newSVsv(arg_def->default_value_sv) : newSV(0)); 0 0 0
1945 0 av_push(arg_def_av, default_sv);
1946 } else {
1947 12 av_push(arg_def_av, newSV(0));
1948 }
1949 12 av_push(arg_defs_av, newRV_noinc((SV *)arg_def_av));
1950 }
1951 224 av_push(av, newRV_noinc((SV *)arg_defs_av));
1952 224 av_push(av, newSViv(slot->callback_abi_code));
1953 224 av_push(av, newSViv(slot->item_non_null ? 1 : 0));
1954 224 ▶ av_push(av, slot->accessor_name
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, slot->accessor_name 0 224 224
1955 ? newSVpvn(slot->accessor_name, slot->accessor_name_len)
1956 : newSV(0));
1957  
1958 224 return newRV_noinc((SV *)av);
1959 }
1960  
1961 static SV *
1962 224 gql_runtime_vm_native_op_to_compact_sv(
1963 pTHX_ const gql_runtime_vm_native_block_t *block,
1964 const gql_runtime_vm_native_op_t *op
1965 )
1966 {
1967 224 AV *av = newAV();
1968 224 HV *abstract_children_hv = newHV();
1969 IV i;
1970 224 const gql_runtime_vm_native_slot_t *slot = NULL;
1971  
1972 224 ▶ if (block && op && op->slot_index >= 0 && op->slot_index < block->slot_count) {
Branch: 4 branches
BranchTrueFalseTotal
if (block && op && op->slot_index >= 0 && op->slot_index < block->slot_count) { 224 0 224
if (block && op && op->slot_index >= 0 && op->slot_index < block->slot_count) { 224 0 224
if (block && op && op->slot_index >= 0 && op->slot_index < block->slot_count) { 224 0 224
if (block && op && op->slot_index >= 0 && op->slot_index < block->slot_count) { 224 0 224
1973 224 slot = &block->slots[op->slot_index];
1974 }
1975  
1976 224 av_push(av, newSViv(op->opcode_code));
1977 224 av_push(av, newSViv(op->resolve_code));
1978 224 av_push(av, newSViv(op->complete_code));
1979 224 av_push(av, newSViv(op->dispatch_family_code));
1980 224 av_push(av, newSViv(op->slot_index));
1981 224 av_push(av, newSViv(op->child_block_index));
1982  
1983 248 ▶ for (i = 0; i < op->abstract_child_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < op->abstract_child_count; i++) { 24 224 248
1984 24 ▶ const char *name = op->abstract_child_names ? op->abstract_child_names[i] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const char *name = op->abstract_child_names ? op->abstract_child_names[i] : NULL; 24 0 24
1985 24 ▶ if (!name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!name) { 0 24 24
1986 0 continue;
1987 }
1988 24 ▶ hv_store(
Branch: 1 branch
BranchTrueFalseTotal
hv_store( 24 0 24
1989 abstract_children_hv,
1990 name,
1991 (I32)strlen(name),
1992 newSViv(op->abstract_child_indexes ? op->abstract_child_indexes[i] : -1),
1993 0
1994 );
1995 }
1996 224 av_push(av, newRV_noinc((SV *)abstract_children_hv));
1997 224 av_push(av, newSViv(op->args_mode_code));
1998 224 av_push(av, newSViv(-1));
1999 224 ▶ av_push(av, op->args_payload_native
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, op->args_payload_native 12 212 224
2000 ? gql_runtime_vm_native_args_payload_materialize_sv(aTHX_ op->args_payload_native)
2001 : newSV(0));
2002 224 av_push(av, newSViv(op->has_args ? 1 : 0));
2003 224 av_push(av, newSViv(op->directives_mode_code));
2004 224 av_push(av, newSViv(-1));
2005 224 ▶ av_push(av, op->directives_payload_native
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, op->directives_payload_native 0 224 224
2006 ? gql_runtime_vm_native_directives_payload_materialize_sv(aTHX_ op->directives_payload_native)
2007 : newSV(0));
2008 224 av_push(av, newSViv(op->has_directives ? 1 : 0));
2009 224 ▶ av_push(av, newSVpv((slot && slot->field_name) ? slot->field_name : "", 0));
Branch: 2 branches
BranchTrueFalseTotal
av_push(av, newSVpv((slot && slot->field_name) ? slot->field_name : "", 0)); 224 0 224
av_push(av, newSVpv((slot && slot->field_name) ? slot->field_name : "", 0)); 224 0 224
2010 224 ▶ av_push(av, newSVpv((slot && slot->result_name) ? slot->result_name : "", 0));
Branch: 2 branches
BranchTrueFalseTotal
av_push(av, newSVpv((slot && slot->result_name) ? slot->result_name : "", 0)); 224 0 224
av_push(av, newSVpv((slot && slot->result_name) ? slot->result_name : "", 0)); 224 0 224
2011 224 ▶ av_push(av, newSVpv((slot && slot->return_type_name) ? slot->return_type_name : "", 0));
Branch: 2 branches
BranchTrueFalseTotal
av_push(av, newSVpv((slot && slot->return_type_name) ? slot->return_type_name : "", 0)); 224 0 224
av_push(av, newSVpv((slot && slot->return_type_name) ? slot->return_type_name : "", 0)); 224 0 224
2012 224 av_push(av, newSViv(op->runtime_directives_mode_code));
2013 224 ▶ av_push(av, op->runtime_directives_sv ? newSVsv(op->runtime_directives_sv) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, op->runtime_directives_sv ? newSVsv(op->runtime_directives_sv) : newSV(0)); 5 219 224
2014 224 av_push(av, newSViv(op->has_runtime_directives ? 1 : 0));
2015  
2016 224 return newRV_noinc((SV *)av);
2017 }
2018  
2019 static SV *
2020 146 gql_runtime_vm_native_block_to_compact_sv(
2021 pTHX_ const gql_runtime_vm_native_block_t *block
2022 )
2023 {
2024 146 AV *slots_av = newAV();
2025 146 AV *ops_av = newAV();
2026 146 AV *av = newAV();
2027 IV i;
2028  
2029 146 av_push(av, newSV(0));
2030 146 ▶ av_push(av, newSVpv(block->type_name ? block->type_name : "", 0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(av, newSVpv(block->type_name ? block->type_name : "", 0)); 146 0 146
2031 146 av_push(av, newSViv(block->family_code));
2032  
2033 370 ▶ for (i = 0; i < block->slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->slot_count; i++) { 224 146 370
2034 224 av_push(slots_av, gql_runtime_vm_native_slot_to_compact_sv(aTHX_ &block->slots[i]));
2035 }
2036 146 av_push(av, newRV_noinc((SV *)slots_av));
2037  
2038 370 ▶ for (i = 0; i < block->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < block->op_count; i++) { 224 146 370
2039 224 av_push(ops_av, gql_runtime_vm_native_op_to_compact_sv(aTHX_ block, &block->ops[i]));
2040 }
2041 146 av_push(av, newRV_noinc((SV *)ops_av));
2042  
2043 146 return newRV_noinc((SV *)av);
2044 }
2045  
2046 static SV *
2047 78 gql_runtime_vm_native_arg_defs_to_hash_sv(
2048 pTHX_ const gql_runtime_vm_native_arg_def_t *arg_defs,
2049 IV arg_def_count
2050 )
2051 {
2052 78 HV *hv = newHV();
2053 IV i;
2054  
2055 85 ▶ for (i = 0; i < arg_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < arg_def_count; i++) { 7 78 85
2056 7 const gql_runtime_vm_native_arg_def_t *arg_def = &arg_defs[i];
2057 7 HV *arg_def_hv = newHV();
2058  
2059 7 ▶ if (!arg_def->name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!arg_def->name) { 0 7 7
2060 0 continue;
2061 }
2062  
2063 7 ▶ hv_store(arg_def_hv, "type", 4, arg_def->type_def_sv ? newSVsv(arg_def->type_def_sv) : newSV(0), 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(arg_def_hv, "type", 4, arg_def->type_def_sv ? newSVsv(arg_def->type_def_sv) : newSV(0), 0); 7 0 7
2064 7 hv_store(arg_def_hv, "has_default", 11, newSViv(arg_def->has_default ? 1 : 0), 0);
2065 7 ▶ if (arg_def->has_default) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg_def->has_default) { 2 5 7
2066 4 SV *default_sv = arg_def->default_native_value
2067 1 ? gql_runtime_vm_native_value_materialize_sv(aTHX_ arg_def->default_native_value)
2068 2 ▶ : (arg_def->default_value_sv ? newSVsv(arg_def->default_value_sv) : newSV(0));
Branch: 2 branches
BranchTrueFalseTotal
: (arg_def->default_value_sv ? newSVsv(arg_def->default_value_sv) : newSV(0)); 1 1 2
: (arg_def->default_value_sv ? newSVsv(arg_def->default_value_sv) : newSV(0)); 1 0 1
2069 2 hv_store(arg_def_hv, "default_value", 13, default_sv, 0);
2070 }
2071  
2072 7 hv_store(
2073 hv,
2074 arg_def->name,
2075 (I32)strlen(arg_def->name),
2076 newRV_noinc((SV *)arg_def_hv),
2077 0
2078 );
2079 }
2080  
2081 78 return newRV_noinc((SV *)hv);
2082 }
2083  
2084 static SV *
2085 78 gql_runtime_vm_native_program_to_compact_sv(
2086 pTHX_ const gql_runtime_vm_native_program_t *program
2087 )
2088 {
2089 78 HV *hv = newHV();
2090 78 AV *blocks_av = newAV();
2091 78 AV *args_payloads_av = newAV();
2092 78 AV *directives_payloads_av = newAV();
2093 IV i;
2094  
2095 78 hv_store(hv, "version", 7, newSViv(program->version > 0 ? program->version : 1), 0);
2096 78 hv_store(hv, "operation_type_code", 19, newSViv(program->operation_type_code), 0);
2097 78 ▶ hv_store(
Branch: 1 branch
BranchTrueFalseTotal
hv_store( 7 71 78
2098 hv,
2099 "operation_name",
2100 14,
2101 program->operation_name ? newSVpv(program->operation_name, 0) : newSV(0),
2102 0
2103 );
2104 78 hv_store(hv, "root_block_index", 16, newSViv(program->root_block_index), 0);
2105 78 hv_store(
2106 hv,
2107 "variable_defs",
2108 13,
2109 gql_runtime_vm_native_arg_defs_to_hash_sv(aTHX_ program->variable_defs, program->variable_def_count),
2110 0
2111 );
2112  
2113 86 ▶ for (i = 0; i < program->args_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->args_payload_count; i++) { 8 78 86
2114 8 ▶ av_push(
Branch: 2 branches
BranchTrueFalseTotal
av_push( 8 0 8
av_push( 8 0 8
2115 args_payloads_av,
2116 program->args_payloads && program->args_payloads[i]
2117 ? gql_runtime_vm_native_args_payload_materialize_sv(aTHX_ program->args_payloads[i])
2118 : newSV(0)
2119 );
2120 }
2121 78 hv_store(hv, "args_payloads_compact", 21, newRV_noinc((SV *)args_payloads_av), 0);
2122  
2123 78 ▶ for (i = 0; i < program->directives_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->directives_payload_count; i++) { 0 78 78
2124 0 ▶ av_push(
Branch: 2 branches
BranchTrueFalseTotal
av_push( 0 0 0
av_push( 0 0 0
2125 directives_payloads_av,
2126 program->directives_payloads && program->directives_payloads[i]
2127 ? gql_runtime_vm_native_directives_payload_materialize_sv(aTHX_ program->directives_payloads[i])
2128 : newSV(0)
2129 );
2130 }
2131 78 hv_store(hv, "directives_payloads_compact", 27, newRV_noinc((SV *)directives_payloads_av), 0);
2132  
2133 224 ▶ for (i = 0; i < program->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->block_count; i++) { 146 78 224
2134 146 av_push(blocks_av, gql_runtime_vm_native_block_to_compact_sv(aTHX_ &program->blocks[i]));
2135 }
2136 78 hv_store(hv, "blocks_compact", 14, newRV_noinc((SV *)blocks_av), 0);
2137  
2138 78 return newRV_noinc((SV *)hv);
2139 }
2140  
2141 static gql_runtime_vm_native_directives_payload_t *
2142 12 gql_runtime_vm_native_directives_payload_from_sv(pTHX_ SV *guards_sv)
2143 {
2144 AV *guards_av;
2145 gql_runtime_vm_native_directives_payload_t *payload;
2146 IV i;
2147  
2148 12 ▶ if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 12 0 12
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 12 0 12
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 12 0 12
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 0 12 12
2149 0 return NULL;
2150 }
2151  
2152 12 guards_av = (AV *)SvRV(guards_sv);
2153 12 Newxz(payload, 1, gql_runtime_vm_native_directives_payload_t);
2154 12 payload->count = av_len(guards_av) + 1;
2155 12 ▶ if (payload->count <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (payload->count <= 0) { 0 12 12
2156 0 return payload;
2157 }
2158 12 ▶ Newxz(payload->guards, payload->count, gql_runtime_vm_native_guard_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(payload->guards, payload->count, gql_runtime_vm_native_guard_t); 0 12 12
2159  
2160 24 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 12 12 24
2161 12 SV **directive_svp = av_fetch(guards_av, i, 0);
2162 HV *directive_hv;
2163 SV **name_svp;
2164 SV **arguments_svp;
2165 HV *arguments_hv;
2166 SV **if_svp;
2167 12 STRLEN name_len = 0;
2168 const char *name;
2169  
2170 12 ▶ if (!directive_svp || !SvOK(*directive_svp) || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!directive_svp || !SvOK(*directive_svp) || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) { 12 0 12
if (!directive_svp || !SvOK(*directive_svp) || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) { 12 0 12
if (!directive_svp || !SvOK(*directive_svp) || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) { 12 0 12
if (!directive_svp || !SvOK(*directive_svp) || !SvROK(*directive_svp) || SvTYPE(SvRV(*directive_svp)) != SVt_PVHV) { 0 12 12
2171 0 continue;
2172 }
2173 12 directive_hv = (HV *)SvRV(*directive_svp);
2174 12 name_svp = hv_fetch(directive_hv, "name", 4, 0);
2175 12 arguments_svp = hv_fetch(directive_hv, "arguments", 9, 0);
2176 12 ▶ if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp) || !SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) {
Branch: 6 branches
BranchTrueFalseTotal
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp) || !SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 12 0 12
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp) || !SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 12 0 12
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp) || !SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 12 0 12
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp) || !SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 12 0 12
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp) || !SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 12 0 12
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp) || !SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 0 12 12
2177 0 continue;
2178 }
2179 12 arguments_hv = (HV *)SvRV(*arguments_svp);
2180 12 if_svp = hv_fetch(arguments_hv, "if", 2, 0);
2181 12 ▶ if (!if_svp || !SvOK(*if_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!if_svp || !SvOK(*if_svp)) { 12 0 12
if (!if_svp || !SvOK(*if_svp)) { 0 12 12
2182 0 continue;
2183 }
2184 12 name = SvPV(*name_svp, name_len);
2185 12 ▶ if (name_len == 4 && memEQ(name, "skip", 4)) {
Branch: 2 branches
BranchTrueFalseTotal
if (name_len == 4 && memEQ(name, "skip", 4)) { 6 6 12
if (name_len == 4 && memEQ(name, "skip", 4)) { 6 0 6
2186 6 payload->guards[i].kind_code = GQL_VM_GUARD_SKIP;
2187 } else {
2188 6 payload->guards[i].kind_code = GQL_VM_GUARD_INCLUDE;
2189 }
2190 12 payload->guards[i].if_expr = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ *if_svp);
2191 }
2192  
2193 12 return payload;
2194 }
2195  
2196 static gql_runtime_vm_native_directives_payload_t *
2197 28 gql_runtime_vm_native_directives_payload_clone(
2198 pTHX_ const gql_runtime_vm_native_directives_payload_t *payload
2199 )
2200 {
2201 gql_runtime_vm_native_directives_payload_t *copy;
2202 IV i;
2203  
2204 28 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 28 28
2205 0 return NULL;
2206 }
2207 28 Newxz(copy, 1, gql_runtime_vm_native_directives_payload_t);
2208 28 copy->count = payload->count;
2209 28 ▶ if (copy->count <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (copy->count <= 0) { 0 28 28
2210 0 return copy;
2211 }
2212 28 ▶ Newxz(copy->guards, copy->count, gql_runtime_vm_native_guard_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(copy->guards, copy->count, gql_runtime_vm_native_guard_t); 0 28 28
2213 56 ▶ for (i = 0; i < copy->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < copy->count; i++) { 28 28 56
2214 28 copy->guards[i].kind_code = payload->guards[i].kind_code;
2215 28 copy->guards[i].if_expr = gql_runtime_vm_native_dynamic_value_clone(aTHX_ payload->guards[i].if_expr);
2216 }
2217 28 return copy;
2218 }
2219  
2220 static void
2221 4133 gql_runtime_vm_native_directives_payload_destroy(
2222 pTHX_ gql_runtime_vm_native_directives_payload_t *payload
2223 )
2224 {
2225 IV i;
2226  
2227 4133 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 4093 40 4133
2228 4093 return;
2229 }
2230 80 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 40 40 80
2231 40 ▶ gql_runtime_vm_native_dynamic_value_destroy(aTHX_ payload->guards ? payload->guards[i].if_expr : NULL);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_dynamic_value_destroy(aTHX_ payload->guards ? payload->guards[i].if_expr : NULL); 40 0 40
2232 }
2233 40 Safefree(payload->guards);
2234 40 Safefree(payload);
2235 }
2236  
2237 static int
2238 15 gql_runtime_vm_evaluate_runtime_guards_native(
2239 pTHX_ const gql_runtime_vm_native_directives_payload_t *payload,
2240 HV *variables,
2241 SV **variable_slots,
2242 IV variable_slot_count
2243 )
2244 {
2245 IV i;
2246  
2247 15 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 15 15
2248 0 return 1;
2249 }
2250 22 ▶ for (i = 0; i < payload->count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < payload->count; i++) { 15 7 22
2251 15 const gql_runtime_vm_native_guard_t *guard = &payload->guards[i];
2252 15 int bool_value = gql_runtime_vm_native_dynamic_value_truthy(
2253 15 aTHX_ guard->if_expr, variables, variable_slots, variable_slot_count
2254 );
2255 15 ▶ if (guard->kind_code == GQL_VM_GUARD_SKIP && bool_value) {
Branch: 2 branches
BranchTrueFalseTotal
if (guard->kind_code == GQL_VM_GUARD_SKIP && bool_value) { 7 8 15
if (guard->kind_code == GQL_VM_GUARD_SKIP && bool_value) { 6 1 7
2256 6 return 0;
2257 }
2258 9 ▶ if (guard->kind_code == GQL_VM_GUARD_INCLUDE && !bool_value) {
Branch: 2 branches
BranchTrueFalseTotal
if (guard->kind_code == GQL_VM_GUARD_INCLUDE && !bool_value) { 8 1 9
if (guard->kind_code == GQL_VM_GUARD_INCLUDE && !bool_value) { 2 6 8
2259 2 return 0;
2260 }
2261 }
2262 7 return 1;
2263 }
2264  
2265 static IV
2266 0 gql_runtime_vm_infer_callback_abi_code(IV resolver_shape_code, IV resolver_mode_code)
2267 {
2268 0 ▶ if (resolver_mode_code == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolver_mode_code == 4) { 0 0 0
2269 0 return GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG;
2270 }
2271 0 ▶ if (resolver_mode_code == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolver_mode_code == 3) { 0 0 0
2272 0 return GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS;
2273 }
2274 0 ▶ if (resolver_mode_code == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolver_mode_code == 2) { 0 0 0
2275 0 return GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE;
2276 }
2277 0 ▶ if (resolver_shape_code == GQL_VM_RESOLVE_EXPLICIT) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolver_shape_code == GQL_VM_RESOLVE_EXPLICIT) { 0 0 0
2278 0 return GQL_VM_CALLBACK_ABI_EXPLICIT_GENERIC;
2279 }
2280 0 return GQL_VM_CALLBACK_ABI_DEFAULT;
2281 }
2282  
2283 static const gql_runtime_vm_native_slot_t *
2284 14324 gql_runtime_vm_effective_slot(
2285 const gql_runtime_vm_native_runtime_t *runtime,
2286 const gql_runtime_vm_native_slot_t *slot
2287 )
2288 {
2289 14324 ▶ if (!runtime || !slot) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime || !slot) { 14324 0 14324
if (!runtime || !slot) { 0 14324 14324
2290 0 return slot;
2291 }
2292 14324 ▶ 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) { 14324 0 14324
if (slot->schema_slot_index >= 0 && slot->schema_slot_index < runtime->runtime_slot_count) { 14324 0 14324
2293 14324 return &runtime->runtime_slots[slot->schema_slot_index];
2294 }
2295 0 return slot;
2296 }
2297  
2298 static SV *
2299 0 gql_runtime_vm_new_cursor_handle(pTHX_ const char *pkg, gql_runtime_vm_cursor_t *cursor)
2300 {
2301 0 return gql_runtime_vm_new_handle_sv(aTHX_ pkg, cursor);
2302 }
2303  
2304 static void
2305 554 gql_runtime_vm_error_record_incref(gql_runtime_vm_error_record_t *record)
2306 {
2307 554 ▶ if (record) {
Branch: 1 branch
BranchTrueFalseTotal
if (record) { 554 0 554
2308 554 record->refcount++;
2309 }
2310 554 }
2311  
2312 static const char *
2313 101 gql_runtime_vm_find_tagged_type_name(
2314 const gql_runtime_vm_native_runtime_t *runtime,
2315 IV slot_index,
2316 SV *tag_sv
2317 )
2318 {
2319 IV i;
2320 101 STRLEN tag_len = 0;
2321 101 const char *tag_name = NULL;
2322 gql_runtime_vm_native_tag_entry_t *entries;
2323 IV count;
2324 gql_runtime_vm_native_callback_catalog_t *catalog;
2325  
2326 101 ▶ if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count || !tag_sv || !SvOK(tag_sv)) {
Branch: 5 branches
BranchTrueFalseTotal
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count || !tag_sv || !SvOK(tag_sv)) { 101 0 101
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count || !tag_sv || !SvOK(tag_sv)) { 101 0 101
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count || !tag_sv || !SvOK(tag_sv)) { 101 0 101
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count || !tag_sv || !SvOK(tag_sv)) { 101 0 101
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count || !tag_sv || !SvOK(tag_sv)) { 0 101 101
2327 0 return NULL;
2328 }
2329 101 catalog = runtime->callback_catalog;
2330 101 ▶ if (!catalog || !catalog->slot_tag_entries || !catalog->slot_tag_entry_counts) {
Branch: 3 branches
BranchTrueFalseTotal
if (!catalog || !catalog->slot_tag_entries || !catalog->slot_tag_entry_counts) { 101 0 101
if (!catalog || !catalog->slot_tag_entries || !catalog->slot_tag_entry_counts) { 101 0 101
if (!catalog || !catalog->slot_tag_entries || !catalog->slot_tag_entry_counts) { 0 101 101
2331 0 return NULL;
2332 }
2333 101 entries = catalog->slot_tag_entries[slot_index];
2334 101 count = catalog->slot_tag_entry_counts[slot_index];
2335 101 ▶ if (!entries || count <= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!entries || count <= 0) { 101 0 101
if (!entries || count <= 0) { 0 101 101
2336 0 return NULL;
2337 }
2338 101 tag_name = SvPV(tag_sv, tag_len);
2339 101 ▶ if (!tag_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!tag_name) { 0 101 101
2340 0 return NULL;
2341 }
2342 154 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 142 12 154
2343 142 const char *candidate = entries[i].tag_name;
2344 142 ▶ if (candidate && strlen(candidate) == (size_t)tag_len && memcmp(candidate, tag_name, (size_t)tag_len) == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (candidate && strlen(candidate) == (size_t)tag_len && memcmp(candidate, tag_name, (size_t)tag_len) == 0) { 142 0 142
if (candidate && strlen(candidate) == (size_t)tag_len && memcmp(candidate, tag_name, (size_t)tag_len) == 0) { 124 18 142
if (candidate && strlen(candidate) == (size_t)tag_len && memcmp(candidate, tag_name, (size_t)tag_len) == 0) { 89 35 124
2345 89 return entries[i].type_name;
2346 }
2347 }
2348 12 return NULL;
2349 }
2350  
2351 static gql_runtime_vm_native_possible_type_entry_t *
2352 0 gql_runtime_vm_find_matching_possible_type(
2353 pTHX_
2354 const gql_runtime_vm_native_runtime_t *runtime,
2355 IV slot_index,
2356 SV *value,
2357 SV *context,
2358 SV *info,
2359 SV **error_out
2360 )
2361 {
2362 IV i;
2363 gql_runtime_vm_native_possible_type_entry_t *entries;
2364 IV count;
2365 gql_runtime_vm_native_callback_catalog_t *catalog;
2366  
2367 0 ▶ if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 0 0 0
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 0 0 0
if (!runtime || slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 0 0 0
2368 0 return NULL;
2369 }
2370 0 catalog = runtime->callback_catalog;
2371 0 ▶ if (!catalog || !catalog->slot_possible_type_entries || !catalog->slot_possible_type_entry_counts) {
Branch: 3 branches
BranchTrueFalseTotal
if (!catalog || !catalog->slot_possible_type_entries || !catalog->slot_possible_type_entry_counts) { 0 0 0
if (!catalog || !catalog->slot_possible_type_entries || !catalog->slot_possible_type_entry_counts) { 0 0 0
if (!catalog || !catalog->slot_possible_type_entries || !catalog->slot_possible_type_entry_counts) { 0 0 0
2372 0 return NULL;
2373 }
2374 0 entries = catalog->slot_possible_type_entries[slot_index];
2375 0 count = catalog->slot_possible_type_entry_counts[slot_index];
2376 0 ▶ if (!entries || count <= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!entries || count <= 0) { 0 0 0
if (!entries || count <= 0) { 0 0 0
2377 0 return NULL;
2378 }
2379  
2380 0 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 0 0 0
2381 SV *ok_sv;
2382 0 ▶ if (!entries[i].type_sv || !entries[i].is_type_of_cb) {
Branch: 2 branches
BranchTrueFalseTotal
if (!entries[i].type_sv || !entries[i].is_type_of_cb) { 0 0 0
if (!entries[i].type_sv || !entries[i].is_type_of_cb) { 0 0 0
2383 0 continue;
2384 }
2385 0 ok_sv = gql_runtime_vm_call_cb4_nonfatal(
2386 aTHX_
2387 0 entries[i].is_type_of_cb,
2388 value,
2389 context,
2390 info ? info : &PL_sv_undef,
2391 0 ▶ entries[i].type_sv,
Branch: 1 branch
BranchTrueFalseTotal
entries[i].type_sv, 0 0 0
2392 error_out
2393 );
2394 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
2395 0 return NULL;
2396 }
2397 0 ▶ if (SvTRUE(ok_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(ok_sv)) { 0 0 0
2398 0 SvREFCNT_dec(ok_sv);
2399 0 return &entries[i];
2400 }
2401 0 SvREFCNT_dec(ok_sv);
2402 }
2403  
2404 0 return NULL;
2405 }
2406  
2407 static void
2408 1108 gql_runtime_vm_error_record_decref(pTHX_ gql_runtime_vm_error_record_t *record)
2409 {
2410 1108 ▶ if (!record) {
Branch: 1 branch
BranchTrueFalseTotal
if (!record) { 0 1108 1108
2411 0 return;
2412 }
2413 1108 ▶ if (record->refcount > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (record->refcount > 1) { 554 554 1108
2414 554 record->refcount--;
2415 554 return;
2416 }
2417 554 ▶ if (record->message_pv) {
Branch: 1 branch
BranchTrueFalseTotal
if (record->message_pv) { 554 0 554
2418 554 Safefree(record->message_pv);
2419 }
2420 554 gql_runtime_vm_path_frame_decref(record->path_frame);
2421 554 Safefree(record);
2422 }
2423  
2424 static void
2425 1975 gql_runtime_vm_outcome_incref(gql_runtime_vm_outcome_t *outcome)
2426 {
2427 1975 ▶ if (outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome) { 1975 0 1975
2428 1975 outcome->refcount++;
2429 }
2430 1975 }
2431  
2432 static void
2433 9039 gql_runtime_vm_outcome_decref(pTHX_ gql_runtime_vm_outcome_t *outcome)
2434 {
2435 IV i;
2436 9039 ▶ if (!outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (!outcome) { 1319 7720 9039
2437 1319 return;
2438 }
2439 7720 ▶ if (outcome->refcount > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome->refcount > 1) { 1975 5745 7720
2440 1975 outcome->refcount--;
2441 1975 return;
2442 }
2443 5745 gql_runtime_vm_native_value_destroy(aTHX_ outcome->value);
2444 6299 ▶ for (i = 0; i < outcome->error_record_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < outcome->error_record_count; i++) { 554 5745 6299
2445 554 gql_runtime_vm_error_record_decref(aTHX_ outcome->error_records[i]);
2446 }
2447 5745 Safefree(outcome->error_records);
2448 5745 ▶ if (gql_runtime_vm_outcome_pool_count < GQL_RUNTIME_VM_OUTCOME_POOL_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_outcome_pool_count < GQL_RUNTIME_VM_OUTCOME_POOL_MAX) { 5745 0 5745
2449 5745 outcome->pool_next = gql_runtime_vm_outcome_pool_head;
2450 5745 gql_runtime_vm_outcome_pool_head = outcome;
2451 5745 gql_runtime_vm_outcome_pool_count++;
2452 5745 return;
2453 }
2454 0 Safefree(outcome);
2455 }
2456  
2457 static void
2458 554 gql_runtime_vm_writer_push_error_record(gql_runtime_vm_writer_t *writer, gql_runtime_vm_error_record_t *record)
2459 {
2460 554 ▶ if (!writer || !record) {
Branch: 2 branches
BranchTrueFalseTotal
if (!writer || !record) { 554 0 554
if (!writer || !record) { 0 554 554
2461 0 return;
2462 }
2463 554 ▶ if (writer->error_record_count == writer->error_record_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (writer->error_record_count == writer->error_record_capacity) { 239 315 554
2464 239 ▶ writer->error_record_capacity = writer->error_record_capacity ? writer->error_record_capacity * 2 : 4;
Branch: 1 branch
BranchTrueFalseTotal
writer->error_record_capacity = writer->error_record_capacity ? writer->error_record_capacity * 2 : 4; 85 154 239
2465 239 ▶ Renew(writer->error_records, writer->error_record_capacity, gql_runtime_vm_error_record_t *);
Branch: 1 branch
BranchTrueFalseTotal
Renew(writer->error_records, writer->error_record_capacity, gql_runtime_vm_error_record_t *); 0 239 239
2466 }
2467 554 gql_runtime_vm_error_record_incref(record);
2468 554 writer->error_records[writer->error_record_count++] = record;
2469 }
2470  
2471 static void
2472 0 gql_runtime_vm_block_frame_push_pending_pvn(
2473 pTHX_
2474 gql_runtime_vm_block_frame_t *frame,
2475 const char *result_name_pv,
2476 STRLEN result_name_len,
2477 SV *outcome
2478 )
2479 {
2480 0 U8 payload_kind = GQL_VM_PENDING_PROMISE_SV;
2481  
2482 0 ▶ if (outcome && SvOK(outcome) && sv_derived_from(outcome, "GraphQL::Houtou::Runtime::Outcome")) {
Branch: 3 branches
BranchTrueFalseTotal
if (outcome && SvOK(outcome) && sv_derived_from(outcome, "GraphQL::Houtou::Runtime::Outcome")) { 0 0 0
if (outcome && SvOK(outcome) && sv_derived_from(outcome, "GraphQL::Houtou::Runtime::Outcome")) { 0 0 0
if (outcome && SvOK(outcome) && sv_derived_from(outcome, "GraphQL::Houtou::Runtime::Outcome")) { 0 0 0
2483 0 payload_kind = GQL_VM_PENDING_OUTCOME_PTR;
2484 }
2485  
2486 0 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
2487 aTHX_
2488 frame,
2489 result_name_pv,
2490 result_name_len,
2491 0,
2492 outcome,
2493 payload_kind,
2494 NULL,
2495 -1,
2496 -1,
2497 -1,
2498 NULL
2499 );
2500 0 }
2501  
2502 static void
2503 1828 gql_runtime_vm_block_frame_push_pending_pvn_with_meta(
2504 pTHX_
2505 gql_runtime_vm_block_frame_t *frame,
2506 const char *result_name_pv,
2507 STRLEN result_name_len,
2508 U8 result_name_pv_borrowed,
2509 SV *outcome,
2510 U8 payload_kind,
2511 gql_runtime_vm_path_frame_t *path_frame,
2512 IV block_index,
2513 IV slot_index,
2514 IV op_index,
2515 const gql_runtime_vm_async_adapter_t *async_adapter
2516 )
2517 {
2518 1828 gql_runtime_vm_pending_entry_t *entry = NULL;
2519  
2520 1828 ▶ if (!frame || !result_name_pv || result_name_len == 0 || !outcome) {
Branch: 4 branches
BranchTrueFalseTotal
if (!frame || !result_name_pv || result_name_len == 0 || !outcome) { 1828 0 1828
if (!frame || !result_name_pv || result_name_len == 0 || !outcome) { 1828 0 1828
if (!frame || !result_name_pv || result_name_len == 0 || !outcome) { 1828 0 1828
if (!frame || !result_name_pv || result_name_len == 0 || !outcome) { 0 1828 1828
2521 0 return;
2522 }
2523  
2524 1828 entry = gql_runtime_vm_block_frame_push_pending_entry_with_meta(
2525 aTHX_
2526 frame,
2527 result_name_pv,
2528 result_name_len,
2529 result_name_pv_borrowed,
2530 path_frame,
2531 block_index,
2532 slot_index,
2533 op_index
2534 );
2535 1828 ▶ if (!entry) {
Branch: 1 branch
BranchTrueFalseTotal
if (!entry) { 0 1828 1828
2536 0 return;
2537 }
2538  
2539 1828 ▶ if (payload_kind == GQL_VM_PENDING_OUTCOME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
if (payload_kind == GQL_VM_PENDING_OUTCOME_PTR) { 0 1828 1828
2540 0 entry->payload_kind = GQL_VM_PENDING_OUTCOME_PTR;
2541 0 entry->state_code = GQL_VM_PENDING_STATE_READY_OUTCOME;
2542 0 entry->payload.outcome_ptr = gql_runtime_vm_expect_outcome(aTHX_ outcome);
2543 0 gql_runtime_vm_outcome_incref(entry->payload.outcome_ptr);
2544 } else {
2545 1828 entry->payload_kind = payload_kind;
2546 1828 entry->payload.promise_sv = newSVsv(outcome);
2547 1828 ▶ entry->state_code = gql_runtime_vm_sv_is_pending_async_value(
Branch: 1 branch
BranchTrueFalseTotal
entry->state_code = gql_runtime_vm_sv_is_pending_async_value( 1828 0 1828
2548 aTHX_ async_adapter, outcome
2549 ) ? GQL_VM_PENDING_STATE_WAITING_UNARMED : GQL_VM_PENDING_STATE_READY_SV;
2550 }
2551 }
2552  
2553 static gql_runtime_vm_pending_entry_t *
2554 3747 gql_runtime_vm_block_frame_push_pending_entry_with_meta(
2555 pTHX_
2556 gql_runtime_vm_block_frame_t *frame,
2557 const char *result_name_pv,
2558 STRLEN result_name_len,
2559 U8 result_name_pv_borrowed,
2560 gql_runtime_vm_path_frame_t *path_frame,
2561 IV block_index,
2562 IV slot_index,
2563 IV op_index
2564 )
2565 {
2566 3747 gql_runtime_vm_pending_entry_t *entry = NULL;
2567  
2568 3747 ▶ if (!frame || !result_name_pv || result_name_len == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (!frame || !result_name_pv || result_name_len == 0) { 3747 0 3747
if (!frame || !result_name_pv || result_name_len == 0) { 3747 0 3747
if (!frame || !result_name_pv || result_name_len == 0) { 0 3747 3747
2569 0 return NULL;
2570 }
2571  
2572 3747 ▶ if (frame->pending_count == frame->pending_capacity) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->pending_count == frame->pending_capacity) { 3688 59 3747
2573 3688 ▶ frame->pending_capacity = frame->pending_capacity ? frame->pending_capacity * 2 : 4;
Branch: 1 branch
BranchTrueFalseTotal
frame->pending_capacity = frame->pending_capacity ? frame->pending_capacity * 2 : 4; 1 3687 3688
2574 3688 ▶ Renew(frame->pending_entries, frame->pending_capacity, gql_runtime_vm_pending_entry_t);
Branch: 1 branch
BranchTrueFalseTotal
Renew(frame->pending_entries, frame->pending_capacity, gql_runtime_vm_pending_entry_t); 0 3688 3688
2575 }
2576  
2577 3747 entry = &frame->pending_entries[frame->pending_count];
2578 3747 entry->result_name_pv = result_name_pv_borrowed
2579 ? (char *)result_name_pv
2580 3747 ▶ : savepvn(result_name_pv, result_name_len);
Branch: 1 branch
BranchTrueFalseTotal
: savepvn(result_name_pv, result_name_len); 0 3747 3747
2581 3747 entry->result_name_len = result_name_len;
2582 3747 entry->path_frame = path_frame;
2583 3747 ▶ if (entry->path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (entry->path_frame) { 3747 0 3747
2584 3747 entry->path_frame->refcount++;
2585 }
2586 3747 entry->block_index = block_index;
2587 3747 entry->slot_index = slot_index;
2588 3747 entry->op_index = op_index;
2589 3747 entry->result_name_pv_borrowed = result_name_pv_borrowed ? 1 : 0;
2590 3747 entry->armed_resolve_ctx = NULL;
2591 3747 entry->armed_reject_ctx = NULL;
2592 3747 entry->payload.promise_sv = NULL;
2593 3747 entry->payload_kind = 0;
2594 3747 entry->state_code = 0;
2595 3747 frame->pending_count++;
2596 3747 return entry;
2597 }
2598  
2599 static void
2600 0 gql_runtime_vm_block_frame_push_pending(pTHX_ gql_runtime_vm_block_frame_t *frame, SV *result_name, SV *outcome)
2601 {
2602 0 STRLEN result_name_len = 0;
2603 0 const char *result_name_pv = NULL;
2604 0 ▶ if (!frame || !result_name || !outcome) {
Branch: 3 branches
BranchTrueFalseTotal
if (!frame || !result_name || !outcome) { 0 0 0
if (!frame || !result_name || !outcome) { 0 0 0
if (!frame || !result_name || !outcome) { 0 0 0
2605 0 return;
2606 }
2607 0 result_name_pv = SvPV(result_name, result_name_len);
2608 0 gql_runtime_vm_block_frame_push_pending_pvn(
2609 aTHX_ frame,
2610 result_name_pv,
2611 result_name_len,
2612 outcome
2613 );
2614 }
2615  
2616 static void
2617 7791 gql_runtime_vm_block_frame_clear_pending(pTHX_ gql_runtime_vm_block_frame_t *frame)
2618 {
2619 IV i;
2620 7791 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 7791 7791
2621 0 return;
2622 }
2623 11538 ▶ for (i = 0; i < frame->pending_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < frame->pending_count; i++) { 3747 7791 11538
2624 3747 ▶ if (!frame->pending_entries[i].result_name_pv_borrowed) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame->pending_entries[i].result_name_pv_borrowed) { 0 3747 3747
2625 0 Safefree(frame->pending_entries[i].result_name_pv);
2626 }
2627 3747 gql_runtime_vm_path_frame_decref(frame->pending_entries[i].path_frame);
2628 3747 ▶ 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) { 1271 2476 3747
2629 1271 gql_runtime_vm_outcome_decref(aTHX_ frame->pending_entries[i].payload.outcome_ptr);
2630 2476 ▶ } else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_BLOCK_FRAME_PTR) { 6 2470 2476
2631 6 gql_runtime_vm_free_block_frame(aTHX_ frame->pending_entries[i].payload.block_frame_ptr);
2632 2470 ▶ } 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) { 650 1820 2470
2633 650 gql_runtime_vm_list_pending_decref(aTHX_ frame->pending_entries[i].payload.list_pending_ptr);
2634 1820 ▶ } else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_SV
Branch: 1 branch
BranchTrueFalseTotal
} else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_SV 1820 0 1820
2635 1820 ▶ || 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 1820 1820
2636 0 SvREFCNT_dec(frame->pending_entries[i].payload.promise_sv);
2637 1820 ▶ } else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (frame->pending_entries[i].payload_kind == GQL_VM_PENDING_PROMISE_RESOLVED_VALUE_SV) { 1820 0 1820
2638 1820 SvREFCNT_dec(frame->pending_entries[i].payload.promise_sv);
2639 }
2640 }
2641 /* The entries array (and its capacity) is retained for reuse; block
2642 * frames recycle through a pool and re-fill it without a Renew ramp.
2643 * gql_runtime_vm_free_block_frame frees it when a frame really dies. */
2644 7791 frame->pending_count = 0;
2645 7791 frame->pending_unresolved = 0;
2646 }
2647  
2648 static SV *
2649 0 gql_runtime_vm_cursor_snapshot_sv(pTHX_ SV *cursor_sv)
2650 {
2651 gql_runtime_vm_cursor_t *cursor;
2652 gql_runtime_vm_cursor_t *snapshot;
2653  
2654 0 ▶ if (!cursor_sv || !SvOK(cursor_sv) || !SvROK(cursor_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!cursor_sv || !SvOK(cursor_sv) || !SvROK(cursor_sv)) { 0 0 0
if (!cursor_sv || !SvOK(cursor_sv) || !SvROK(cursor_sv)) { 0 0 0
if (!cursor_sv || !SvOK(cursor_sv) || !SvROK(cursor_sv)) { 0 0 0
2655 0 return newSVsv(&PL_sv_undef);
2656 }
2657  
2658 0 cursor = gql_runtime_vm_expect_cursor(aTHX_ cursor_sv);
2659 0 Newxz(snapshot, 1, gql_runtime_vm_cursor_t);
2660 0 snapshot->native_program = cursor->native_program;
2661 0 snapshot->block_index = cursor->block_index;
2662 0 snapshot->slot_index = cursor->slot_index;
2663 0 snapshot->op_index = cursor->op_index;
2664  
2665 0 return gql_runtime_vm_new_cursor_handle(aTHX_ "GraphQL::Houtou::Runtime::Cursor", snapshot);
2666 }
2667  
2668 static void
2669 450 gql_runtime_vm_cursor_snapshot_copy(pTHX_ gql_runtime_vm_cursor_t *dst, const gql_runtime_vm_cursor_t *src)
2670 {
2671 450 ▶ if (!dst) {
Branch: 1 branch
BranchTrueFalseTotal
if (!dst) { 0 450 450
2672 0 return;
2673 }
2674 450 Zero(dst, 1, gql_runtime_vm_cursor_t);
2675 450 ▶ if (!src) {
Branch: 1 branch
BranchTrueFalseTotal
if (!src) { 0 450 450
2676 0 dst->native_program = NULL;
2677 0 dst->block_index = -1;
2678 0 return;
2679 }
2680 450 dst->native_program = src->native_program;
2681 450 dst->block_index = src->block_index;
2682 450 dst->slot_index = src->slot_index;
2683 450 dst->op_index = src->op_index;
2684 }
2685  
2686 static void
2687 453 gql_runtime_vm_cursor_destroy_copy(pTHX_ gql_runtime_vm_cursor_t *cursor)
2688 {
2689 453 ▶ if (!cursor) {
Branch: 1 branch
BranchTrueFalseTotal
if (!cursor) { 0 453 453
2690 0 return;
2691 }
2692 453 Zero(cursor, 1, gql_runtime_vm_cursor_t);
2693 }
2694  
2695 static void
2696 448 gql_runtime_vm_cursor_restore_copy(pTHX_ gql_runtime_vm_cursor_t *dst, const gql_runtime_vm_cursor_t *src)
2697 {
2698 /* Unlike snapshot_copy this restores into a LIVE cursor, so it must only
2699 * touch the navigation fields. Reusing snapshot_copy here used to
2700 * Zero(dst) first, wiping the live refcount; the next decref then
2701 * underflowed the unsigned count and the cursor struct leaked on every
2702 * exec-state request. */
2703 448 ▶ if (!dst) {
Branch: 1 branch
BranchTrueFalseTotal
if (!dst) { 0 448 448
2704 0 return;
2705 }
2706 448 ▶ if (!src) {
Branch: 1 branch
BranchTrueFalseTotal
if (!src) { 0 448 448
2707 0 dst->native_program = NULL;
2708 0 dst->block_index = -1;
2709 0 dst->slot_index = 0;
2710 0 dst->op_index = 0;
2711 0 return;
2712 }
2713 448 dst->native_program = src->native_program;
2714 448 dst->block_index = src->block_index;
2715 448 dst->slot_index = src->slot_index;
2716 448 dst->op_index = src->op_index;
2717 }
2718  
2719 static void
2720 0 gql_runtime_vm_cursor_restore_sv(pTHX_ gql_runtime_vm_cursor_t *dst, SV *snapshot_sv)
2721 {
2722 gql_runtime_vm_cursor_t *src;
2723  
2724 0 ▶ if (!dst || !snapshot_sv || !SvOK(snapshot_sv) || !SvROK(snapshot_sv)) {
Branch: 4 branches
BranchTrueFalseTotal
if (!dst || !snapshot_sv || !SvOK(snapshot_sv) || !SvROK(snapshot_sv)) { 0 0 0
if (!dst || !snapshot_sv || !SvOK(snapshot_sv) || !SvROK(snapshot_sv)) { 0 0 0
if (!dst || !snapshot_sv || !SvOK(snapshot_sv) || !SvROK(snapshot_sv)) { 0 0 0
if (!dst || !snapshot_sv || !SvOK(snapshot_sv) || !SvROK(snapshot_sv)) { 0 0 0
2725 0 return;
2726 }
2727  
2728 0 src = gql_runtime_vm_expect_cursor(aTHX_ snapshot_sv);
2729 0 gql_runtime_vm_cursor_snapshot_copy(aTHX_ dst, src);
2730 }
2731  
2732 /* Returns a borrowed AV, or NULL when no error records were provided. */
2733 static AV *
2734 2681 gql_runtime_vm_expect_error_records_av(pTHX_ SV *error_records)
2735 {
2736 2681 ▶ if (error_records && SvOK(error_records) && SvROK(error_records) && SvTYPE(SvRV(error_records)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (error_records && SvOK(error_records) && SvROK(error_records) && SvTYPE(SvRV(error_records)) == SVt_PVAV) { 2681 0 2681
if (error_records && SvOK(error_records) && SvROK(error_records) && SvTYPE(SvRV(error_records)) == SVt_PVAV) { 0 2681 2681
if (error_records && SvOK(error_records) && SvROK(error_records) && SvTYPE(SvRV(error_records)) == SVt_PVAV) { 0 0 0
if (error_records && SvOK(error_records) && SvROK(error_records) && SvTYPE(SvRV(error_records)) == SVt_PVAV) { 0 0 0
2737 0 return (AV *)SvRV(error_records);
2738 }
2739 2681 return NULL;
2740 }
2741  
2742 static gql_runtime_vm_error_record_t *
2743 554 gql_runtime_vm_new_error_record_struct_for_path(
2744 pTHX_
2745 SV *message,
2746 gql_runtime_vm_path_frame_t *path_frame
2747 )
2748 {
2749 gql_runtime_vm_error_record_t *record;
2750 554 STRLEN len = 0;
2751 554 const char *pv = NULL;
2752  
2753 554 Newxz(record, 1, gql_runtime_vm_error_record_t);
2754 554 record->refcount = 1;
2755 554 ▶ if (message && SvOK(message)) {
Branch: 2 branches
BranchTrueFalseTotal
if (message && SvOK(message)) { 554 0 554
if (message && SvOK(message)) { 554 0 554
2756 554 pv = SvPV(message, len);
2757 554 Newxz(record->message_pv, len + 1, char);
2758 554 Copy(pv, record->message_pv, len, char);
2759 554 record->message_pv[len] = '\0';
2760 554 record->message_pv_is_utf8 = SvUTF8(message) ? 1 : 0;
2761 }
2762 554 ▶ if (path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (path_frame) { 554 0 554
2763 554 record->path_frame = path_frame;
2764 554 record->path_frame->refcount++;
2765 } else {
2766 0 record->path_frame = NULL;
2767 }
2768 554 return record;
2769 }
2770  
2771 static SV *
2772 7650 gql_runtime_vm_path_frame_key_sv(pTHX_ const gql_runtime_vm_path_frame_t *frame)
2773 {
2774 7650 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 0 7650 7650
2775 0 return newSV(0);
2776 }
2777 7650 ▶ if (frame->key_kind == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->key_kind == 1) { 2490 5160 7650
2778 2490 return newSViv(frame->key_iv);
2779 }
2780 5160 ▶ if (frame->key_pv) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->key_pv) { 5160 0 5160
2781 5160 return newSVpvn(frame->key_pv, frame->key_pv_len);
2782 }
2783 0 return newSV(0);
2784 }
2785  
2786 static void
2787 50100 gql_runtime_vm_path_frame_decref(gql_runtime_vm_path_frame_t *frame)
2788 {
2789 50100 ▶ if (!frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frame) { 3285 46815 50100
2790 3285 return;
2791 }
2792 46815 ▶ if (frame->refcount > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->refcount > 0) { 46815 0 46815
2793 46815 frame->refcount--;
2794 }
2795 46815 ▶ if (frame->refcount == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame->refcount == 0) { 15773 31042 46815
2796 15773 gql_runtime_vm_path_frame_t *parent = frame->parent;
2797 15773 gql_runtime_vm_path_frame_live_count--;
2798 15773 ▶ if (frame->key_pv && !frame->key_pv_borrowed) {
Branch: 2 branches
BranchTrueFalseTotal
if (frame->key_pv && !frame->key_pv_borrowed) { 11640 4133 15773
if (frame->key_pv && !frame->key_pv_borrowed) { 0 11640 11640
2799 0 Safefree(frame->key_pv);
2800 }
2801 15773 ▶ if (gql_runtime_vm_path_frame_pool_count < GQL_RUNTIME_VM_PATH_FRAME_POOL_MAX) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_path_frame_pool_count < GQL_RUNTIME_VM_PATH_FRAME_POOL_MAX) { 15773 0 15773
2802 15773 frame->parent = gql_runtime_vm_path_frame_pool_head;
2803 15773 gql_runtime_vm_path_frame_pool_head = frame;
2804 15773 gql_runtime_vm_path_frame_pool_count++;
2805 } else {
2806 0 Safefree(frame);
2807 }
2808 15773 gql_runtime_vm_path_frame_decref(parent);
2809 }
2810 }
2811  
2812 static SV *
2813 2637 gql_runtime_vm_path_frame_to_path_sv(pTHX_ gql_runtime_vm_path_frame_t *path_frame)
2814 {
2815 2637 AV *segments = newAV();
2816 2637 AV *path_av = newAV();
2817 2637 gql_runtime_vm_path_frame_t *cursor = path_frame;
2818 SSize_t i;
2819  
2820 10287 ▶ while (cursor) {
Branch: 1 branch
BranchTrueFalseTotal
while (cursor) { 7650 2637 10287
2821 7650 av_push(segments, gql_runtime_vm_path_frame_key_sv(aTHX_ cursor));
2822 7650 cursor = cursor->parent;
2823 }
2824  
2825 10287 ▶ for (i = av_len(segments); i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = av_len(segments); i >= 0; i--) { 7650 2637 10287
2826 7650 SV **svp = av_fetch(segments, i, 0);
2827 7650 ▶ if (svp && *svp) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && *svp) { 7650 0 7650
if (svp && *svp) { 7650 0 7650
2828 7650 av_push(path_av, newSVsv(*svp));
2829 }
2830 }
2831  
2832 2637 SvREFCNT_dec((SV *)segments);
2833 2637 return newRV_noinc((SV *)path_av);
2834 }
2835  
2836 static SV *
2837 502 gql_runtime_vm_error_record_to_error_sv(pTHX_ const gql_runtime_vm_error_record_t *record)
2838 {
2839 502 HV *error_hv = newHV();
2840 502 SV *path_sv = NULL;
2841  
2842 502 ▶ if (!record) {
Branch: 1 branch
BranchTrueFalseTotal
if (!record) { 0 502 502
2843 0 return newRV_noinc((SV *)error_hv);
2844 }
2845  
2846 502 ▶ if (record->message_pv) {
Branch: 1 branch
BranchTrueFalseTotal
if (record->message_pv) { 502 0 502
2847 502 SV *message_sv = newSVpv(record->message_pv, 0);
2848 502 ▶ if (record->message_pv_is_utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if (record->message_pv_is_utf8) { 1 501 502
2849 1 SvUTF8_on(message_sv);
2850 }
2851 502 hv_store(error_hv, "message", 7, message_sv, 0);
2852 } else {
2853 0 hv_store(error_hv, "message", 7, newSVsv(&PL_sv_undef), 0);
2854 }
2855  
2856 502 ▶ if (record->path_frame) {
Branch: 1 branch
BranchTrueFalseTotal
if (record->path_frame) { 502 0 502
2857 502 path_sv = gql_runtime_vm_path_frame_to_path_sv(aTHX_ record->path_frame);
2858 502 ▶ if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV && av_count((AV *)SvRV(path_sv)) > 0) {
Branch: 5 branches
BranchTrueFalseTotal
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV && av_count((AV *)SvRV(path_sv)) > 0) { 502 0 502
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV && av_count((AV *)SvRV(path_sv)) > 0) { 502 0 502
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV && av_count((AV *)SvRV(path_sv)) > 0) { 502 0 502
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV && av_count((AV *)SvRV(path_sv)) > 0) { 502 0 502
if (path_sv && SvOK(path_sv) && SvROK(path_sv) && SvTYPE(SvRV(path_sv)) == SVt_PVAV && av_count((AV *)SvRV(path_sv)) > 0) { 502 0 502
2859 502 hv_store(error_hv, "path", 4, path_sv, 0);
2860 502 path_sv = NULL;
2861 }
2862 }
2863  
2864 502 ▶ if (path_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (path_sv) { 0 502 502
2865 0 SvREFCNT_dec(path_sv);
2866 }
2867  
2868 502 return newRV_noinc((SV *)error_hv);
2869 }
2870  
2871 /* Completed child selections arrive as plain hash/array trees (nested
2872 * objects and lists of the response). Convert those recursively so the
2873 * native tree keeps their structure; anything else - scalars and blessed
2874 * leaves (custom scalar objects, boolean objects) - stays a scalar node
2875 * for the shared scalar serializer. A shallow scalar wrap here turns a
2876 * nested hashref into the string "HASH(0x...)" on the JSON lane. */
2877 static gql_runtime_vm_native_value_t *
2878 0 gql_runtime_vm_native_value_from_completed_sv(pTHX_ SV *value)
2879 {
2880 0 ▶ if (value && SvOK(value) && SvROK(value) && !sv_isobject(value)
Branch: 4 branches
BranchTrueFalseTotal
if (value && SvOK(value) && SvROK(value) && !sv_isobject(value) 0 0 0
if (value && SvOK(value) && SvROK(value) && !sv_isobject(value) 0 0 0
if (value && SvOK(value) && SvROK(value) && !sv_isobject(value) 0 0 0
if (value && SvOK(value) && SvROK(value) && !sv_isobject(value) 0 0 0
2881 0 ▶ && (SvTYPE(SvRV(value)) == SVt_PVHV || SvTYPE(SvRV(value)) == SVt_PVAV)) {
Branch: 2 branches
BranchTrueFalseTotal
&& (SvTYPE(SvRV(value)) == SVt_PVHV || SvTYPE(SvRV(value)) == SVt_PVAV)) { 0 0 0
&& (SvTYPE(SvRV(value)) == SVt_PVHV || SvTYPE(SvRV(value)) == SVt_PVAV)) { 0 0 0
2882 0 return gql_runtime_vm_native_value_from_sv(aTHX_ value);
2883 }
2884 0 ▶ return gql_runtime_vm_new_native_value_scalar(aTHX_ value ? value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
return gql_runtime_vm_new_native_value_scalar(aTHX_ value ? value : &PL_sv_undef); 0 0 0
2885 }
2886  
2887 static gql_runtime_vm_outcome_t *
2888 2681 gql_runtime_vm_new_outcome_struct(pTHX_ U8 kind_code, SV *value, SV *error_records)
2889 {
2890 gql_runtime_vm_outcome_t *outcome;
2891 2681 AV *errors_av = gql_runtime_vm_expect_error_records_av(aTHX_ error_records);
2892 SSize_t i;
2893  
2894 2681 outcome = gql_runtime_vm_outcome_pool_get(aTHX);
2895 2681 outcome->refcount = 1;
2896 2681 outcome->kind_code = kind_code;
2897 2681 switch (kind_code) {
2898 0 case GQL_VM_KIND_OBJECT:
2899 0 ▶ if (value && SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (value && SvOK(value)) { 0 0 0
if (value && SvOK(value)) { 0 0 0
2900 0 ▶ if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV) { 0 0 0
if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVHV) { 0 0 0
2901 0 HV *src_hv = (HV *)SvRV(value);
2902 HE *he;
2903 0 outcome->value = gql_runtime_vm_new_native_value_object();
2904 0 hv_iterinit(src_hv);
2905 0 ▶ while ((he = hv_iternext(src_hv)) != NULL) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(src_hv)) != NULL) { 0 0 0
2906 0 SV *key_sv = hv_iterkeysv(he);
2907 0 SV *val_sv = hv_iterval(src_hv, he);
2908 0 STRLEN key_len = 0;
2909 0 const char *key_pv = SvPV(key_sv, key_len);
2910 0 gql_runtime_vm_native_object_store(
2911 aTHX_
2912 outcome->value,
2913 key_pv,
2914 0,
2915 gql_runtime_vm_native_value_from_completed_sv(aTHX_ val_sv)
2916 );
2917 }
2918 } else {
2919 0 outcome->value = gql_runtime_vm_new_native_value_scalar(aTHX_ value);
2920 }
2921 } else {
2922 0 outcome->value = gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef);
2923 }
2924 0 break;
2925 0 case GQL_VM_KIND_LIST:
2926 0 ▶ if (value && SvOK(value) && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (value && SvOK(value) && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV) { 0 0 0
if (value && SvOK(value) && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV) { 0 0 0
if (value && SvOK(value) && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV) { 0 0 0
if (value && SvOK(value) && SvROK(value) && SvTYPE(SvRV(value)) == SVt_PVAV) { 0 0 0
2927 0 AV *src_av = (AV *)SvRV(value);
2928 0 SSize_t max = av_len(src_av);
2929 0 outcome->value = gql_runtime_vm_new_native_value_list();
2930 0 ▶ for (i = 0; i <= max; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= max; i++) { 0 0 0
2931 0 SV **svp = av_fetch(src_av, i, 0);
2932 0 ▶ gql_runtime_vm_native_list_push(
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_list_push( 0 0 0
2933 outcome->value,
2934 0 ▶ gql_runtime_vm_native_value_from_completed_sv(aTHX_ (svp && *svp) ? *svp : &PL_sv_undef)
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_value_from_completed_sv(aTHX_ (svp && *svp) ? *svp : &PL_sv_undef) 0 0 0
2935 );
2936 }
2937 } else {
2938 0 ▶ outcome->value = gql_runtime_vm_new_native_value_scalar(aTHX_ value ? value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
outcome->value = gql_runtime_vm_new_native_value_scalar(aTHX_ value ? value : &PL_sv_undef); 0 0 0
2939 }
2940 0 break;
2941 2681 case GQL_VM_KIND_SCALAR:
2942 default:
2943 2681 ▶ outcome->value = gql_runtime_vm_new_native_value_scalar(aTHX_ value ? value : &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
outcome->value = gql_runtime_vm_new_native_value_scalar(aTHX_ value ? value : &PL_sv_undef); 2681 0 2681
2944 2681 break;
2945 }
2946 2681 ▶ outcome->error_record_count = errors_av ? av_count(errors_av) : 0;
Branch: 1 branch
BranchTrueFalseTotal
outcome->error_record_count = errors_av ? av_count(errors_av) : 0; 0 2681 2681
2947 2681 ▶ if (outcome->error_record_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (outcome->error_record_count > 0) { 0 2681 2681
2948 0 ▶ Newxz(outcome->error_records, outcome->error_record_count, gql_runtime_vm_error_record_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(outcome->error_records, outcome->error_record_count, gql_runtime_vm_error_record_t *); 0 0 0
2949 0 ▶ for (i = 0; i < outcome->error_record_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < outcome->error_record_count; i++) { 0 0 0
2950 0 SV **svp = av_fetch(errors_av, i, 0);
2951 0 ▶ if (svp && *svp && SvOK(*svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (svp && *svp && SvOK(*svp)) { 0 0 0
if (svp && *svp && SvOK(*svp)) { 0 0 0
if (svp && *svp && SvOK(*svp)) { 0 0 0
2952 0 gql_runtime_vm_error_record_t *record = gql_runtime_vm_expect_error_record(aTHX_ *svp);
2953 0 gql_runtime_vm_error_record_incref(record);
2954 0 outcome->error_records[i] = record;
2955 }
2956 }
2957 }
2958  
2959 2681 return outcome;
2960 }
2961  
2962 static SV *
2963 0 gql_runtime_vm_outcome_kind_sv(pTHX_ const gql_runtime_vm_outcome_t *outcome)
2964 {
2965 0 ▶ if (!outcome) {
Branch: 1 branch
BranchTrueFalseTotal
if (!outcome) { 0 0 0
2966 0 return newSVpvs("");
2967 }
2968 0 switch (outcome->kind_code) {
2969 0 case GQL_VM_KIND_SCALAR:
2970 0 return newSVpvs("SCALAR");
2971 0 case GQL_VM_KIND_OBJECT:
2972 0 return newSVpvs("OBJECT");
2973 0 case GQL_VM_KIND_LIST:
2974 0 return newSVpvs("LIST");
2975 0 default:
2976 0 return newSVpvs("");
2977 }
2978 }
2979  
2980 static gql_runtime_vm_writer_t *
2981 1780 gql_runtime_vm_new_writer_struct(pTHX)
2982 {
2983 gql_runtime_vm_writer_t *writer;
2984  
2985 1780 Newxz(writer, 1, gql_runtime_vm_writer_t);
2986 1780 writer->refcount = 1;
2987 1780 return writer;
2988 }
2989  
2990 static void
2991 398 gql_runtime_vm_init_writer_struct(gql_runtime_vm_writer_t *writer)
2992 {
2993 398 ▶ if (!writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (!writer) { 0 398 398
2994 0 return;
2995 }
2996 398 Zero(writer, 1, gql_runtime_vm_writer_t);
2997 398 writer->refcount = 1;
2998 }
2999  
3000 static void
3001 398 gql_runtime_vm_clear_writer_struct(pTHX_ gql_runtime_vm_writer_t *writer)
3002 {
3003 398 ▶ if (!writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (!writer) { 0 398 398
3004 0 return;
3005 }
3006 887 ▶ while (writer->error_record_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (writer->error_record_count > 0) { 489 398 887
3007 489 gql_runtime_vm_error_record_decref(aTHX_ writer->error_records[--writer->error_record_count]);
3008 }
3009 398 Safefree(writer->error_records);
3010 398 Zero(writer, 1, gql_runtime_vm_writer_t);
3011 }
3012  
3013 static void
3014 0 gql_runtime_vm_consume_outcome_struct(pTHX_ HV *data_hv, SV *result_name_sv, const gql_runtime_vm_outcome_t *outcome, gql_runtime_vm_writer_t *writer)
3015 {
3016 IV i;
3017  
3018 0 ▶ if (!data_hv || !result_name_sv || !outcome) {
Branch: 3 branches
BranchTrueFalseTotal
if (!data_hv || !result_name_sv || !outcome) { 0 0 0
if (!data_hv || !result_name_sv || !outcome) { 0 0 0
if (!data_hv || !result_name_sv || !outcome) { 0 0 0
3019 0 return;
3020 }
3021  
3022 0 ▶ hv_store_ent(
Branch: 1 branch
BranchTrueFalseTotal
hv_store_ent( 0 0 0
3023 data_hv,
3024 result_name_sv,
3025 outcome->value ? gql_runtime_vm_native_value_materialize_sv(aTHX_ outcome->value) : newSV(0),
3026 0
3027 );
3028  
3029 0 ▶ if (!writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (!writer) { 0 0 0
3030 0 return;
3031 }
3032  
3033 0 ▶ for (i = 0; i < outcome->error_record_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < outcome->error_record_count; i++) { 0 0 0
3034 0 gql_runtime_vm_writer_push_error_record(writer, outcome->error_records[i]);
3035 }
3036 }
3037  
3038 static void
3039 4945 gql_runtime_vm_consume_outcome_native_object(
3040 pTHX_
3041 gql_runtime_vm_native_value_t *data_value,
3042 const char *result_name_pv,
3043 U8 result_name_borrowed,
3044 gql_runtime_vm_outcome_t *outcome,
3045 gql_runtime_vm_writer_t *writer
3046 )
3047 {
3048 IV i;
3049  
3050 4945 ▶ if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv || !outcome) {
Branch: 4 branches
BranchTrueFalseTotal
if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv || !outcome) { 4945 0 4945
if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv || !outcome) { 4945 0 4945
if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv || !outcome) { 4945 0 4945
if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv || !outcome) { 0 4945 4945
3051 0 return;
3052 }
3053  
3054 /* Consuming is the outcome's terminal use: when the caller is the sole
3055 * owner, transfer the native subtree instead of deep-cloning it (the
3056 * clone was immediately followed by destroying the original). Shared
3057 * outcomes (refcount > 1, e.g. still referenced by a pending entry
3058 * elsewhere) keep the defensive clone. */
3059 4945 ▶ if (outcome->refcount == 1 && outcome->value) {
Branch: 2 branches
BranchTrueFalseTotal
if (outcome->refcount == 1 && outcome->value) { 4945 0 4945
if (outcome->refcount == 1 && outcome->value) { 4943 2 4945
3060 4943 gql_runtime_vm_native_object_store(aTHX_ data_value, result_name_pv, result_name_borrowed, outcome->value);
3061 4943 outcome->value = NULL;
3062 } else {
3063 2 gql_runtime_vm_native_object_store(
3064 aTHX_ data_value,
3065 result_name_pv,
3066 result_name_borrowed,
3067 2 ▶ outcome->value ? gql_runtime_vm_native_value_clone(aTHX_ outcome->value)
Branch: 1 branch
BranchTrueFalseTotal
outcome->value ? gql_runtime_vm_native_value_clone(aTHX_ outcome->value) 0 2 2
3068 2 : gql_runtime_vm_new_native_value_scalar(aTHX_ &PL_sv_undef)
3069 );
3070 }
3071  
3072 4945 ▶ if (!writer) {
Branch: 1 branch
BranchTrueFalseTotal
if (!writer) { 0 4945 4945
3073 0 return;
3074 }
3075  
3076 4959 ▶ for (i = 0; i < outcome->error_record_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < outcome->error_record_count; i++) { 14 4945 4959
3077 14 gql_runtime_vm_writer_push_error_record(writer, outcome->error_records[i]);
3078 }
3079 }
3080  
3081 /* A completed native value counts as null when it is absent or a scalar
3082 * undef. Object/list values are never null here (an empty list is not a
3083 * null). Used by Non-Null propagation on the async lane. */
3084 static int
3085 5174 gql_runtime_vm_native_value_is_null(const gql_runtime_vm_native_value_t *value)
3086 {
3087 5174 ▶ if (!value) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value) { 2 5172 5174
3088 2 return 1;
3089 }
3090 5172 return value->kind_code == GQL_VM_NATIVE_VALUE_SCALAR
3091 5172 ▶ && value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_UNDEF;
Branch: 2 branches
BranchTrueFalseTotal
&& value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_UNDEF; 2741 2431 5172
&& value->scalar_kind_code == GQL_VM_NATIVE_SCALAR_UNDEF; 371 2370 2741
3092 }
3093  
3094 static void
3095 0 gql_runtime_vm_consume_value_native_object(
3096 pTHX_
3097 gql_runtime_vm_native_value_t *data_value,
3098 const char *result_name_pv,
3099 U8 result_name_borrowed,
3100 SV *value_sv
3101 )
3102 {
3103 0 ▶ if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv) {
Branch: 3 branches
BranchTrueFalseTotal
if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv) { 0 0 0
if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv) { 0 0 0
if (!data_value || data_value->kind_code != GQL_VM_NATIVE_VALUE_OBJECT || !result_name_pv) { 0 0 0
3104 0 return;
3105 }
3106  
3107 0 ▶ gql_runtime_vm_native_object_store(
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_native_object_store( 0 0 0
3108 aTHX_
3109 data_value,
3110 result_name_pv,
3111 result_name_borrowed,
3112 gql_runtime_vm_native_value_from_sv(aTHX_ value_sv ? value_sv : &PL_sv_undef)
3113 );
3114 }
3115  
3116 static SV *
3117 115 gql_runtime_vm_writer_materialize_errors_sv(pTHX_ const gql_runtime_vm_writer_t *writer)
3118 {
3119 AV *errors_av;
3120 IV i;
3121  
3122 115 ▶ if (!writer || writer->error_record_count == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!writer || writer->error_record_count == 0) { 115 0 115
if (!writer || writer->error_record_count == 0) { 0 115 115
3123 0 return NULL;
3124 }
3125  
3126 115 errors_av = newAV();
3127 617 ▶ for (i = 0; i < writer->error_record_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < writer->error_record_count; i++) { 502 115 617
3128 502 av_push(errors_av, gql_runtime_vm_error_record_to_error_sv(aTHX_ writer->error_records[i]));
3129 }
3130  
3131 115 return newRV_noinc((SV *)errors_av);
3132 }
3133  
3134 static SV *
3135 240 gql_runtime_vm_dispatch_hash_fetch(pTHX_ SV *dispatch_sv, const char *key, STRLEN key_len)
3136 {
3137 HV *hv;
3138 SV **svp;
3139 240 ▶ if (!dispatch_sv || !SvOK(dispatch_sv) || !SvROK(dispatch_sv) || SvTYPE(SvRV(dispatch_sv)) != SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!dispatch_sv || !SvOK(dispatch_sv) || !SvROK(dispatch_sv) || SvTYPE(SvRV(dispatch_sv)) != SVt_PVHV) { 240 0 240
if (!dispatch_sv || !SvOK(dispatch_sv) || !SvROK(dispatch_sv) || SvTYPE(SvRV(dispatch_sv)) != SVt_PVHV) { 240 0 240
if (!dispatch_sv || !SvOK(dispatch_sv) || !SvROK(dispatch_sv) || SvTYPE(SvRV(dispatch_sv)) != SVt_PVHV) { 240 0 240
if (!dispatch_sv || !SvOK(dispatch_sv) || !SvROK(dispatch_sv) || SvTYPE(SvRV(dispatch_sv)) != SVt_PVHV) { 0 240 240
3140 0 return NULL;
3141 }
3142 240 hv = (HV *)SvRV(dispatch_sv);
3143 240 svp = hv_fetch(hv, key, (I32)key_len, 0);
3144 240 ▶ return svp ? *svp : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return svp ? *svp : NULL; 240 0 240
3145 }
3146  
3147 static SV *
3148 200 gql_runtime_vm_hash_lookup_ent_sv(pTHX_ SV *hv_sv, SV *key_sv)
3149 {
3150 HE *he;
3151 HV *hv;
3152 200 ▶ if (!hv_sv || !SvOK(hv_sv) || !SvROK(hv_sv) || SvTYPE(SvRV(hv_sv)) != SVt_PVHV || !key_sv) {
Branch: 5 branches
BranchTrueFalseTotal
if (!hv_sv || !SvOK(hv_sv) || !SvROK(hv_sv) || SvTYPE(SvRV(hv_sv)) != SVt_PVHV || !key_sv) { 200 0 200
if (!hv_sv || !SvOK(hv_sv) || !SvROK(hv_sv) || SvTYPE(SvRV(hv_sv)) != SVt_PVHV || !key_sv) { 200 0 200
if (!hv_sv || !SvOK(hv_sv) || !SvROK(hv_sv) || SvTYPE(SvRV(hv_sv)) != SVt_PVHV || !key_sv) { 200 0 200
if (!hv_sv || !SvOK(hv_sv) || !SvROK(hv_sv) || SvTYPE(SvRV(hv_sv)) != SVt_PVHV || !key_sv) { 200 0 200
if (!hv_sv || !SvOK(hv_sv) || !SvROK(hv_sv) || SvTYPE(SvRV(hv_sv)) != SVt_PVHV || !key_sv) { 0 200 200
3153 0 return NULL;
3154 }
3155 200 hv = (HV *)SvRV(hv_sv);
3156 200 he = hv_fetch_ent(hv, key_sv, 0, 0);
3157 200 ▶ return he ? HeVAL(he) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return he ? HeVAL(he) : NULL; 158 42 200
3158 }
3159  
3160 static SV *
3161 40 gql_runtime_vm_call_cb_scalar(pTHX_ SV *cb, SV *value, SV *context, SV *info, SV *type_like, SV **error_out)
3162 {
3163 40 dSP;
3164 40 SV *result = NULL;
3165 40 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 40 0 40
3166 40 *error_out = NULL;
3167 }
3168 40 ▶ if (!cb || !SvOK(cb)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!cb || !SvOK(cb)) { 40 0 40
if (!cb || !SvOK(cb)) { 0 40 40
3169 0 return NULL;
3170 }
3171  
3172 40 ENTER;
3173 40 SAVETMPS;
3174 40 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 40 0 40
3175 40 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 40 40
3176 40 ▶ XPUSHs(sv_2mortal(newSVsv(value ? value : &PL_sv_undef)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(value ? value : &PL_sv_undef))); 0 40 40
XPUSHs(sv_2mortal(newSVsv(value ? value : &PL_sv_undef))); 40 0 40
3177 40 ▶ XPUSHs(sv_2mortal(newSVsv(context ? context : &PL_sv_undef)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(context ? context : &PL_sv_undef))); 0 40 40
XPUSHs(sv_2mortal(newSVsv(context ? context : &PL_sv_undef))); 40 0 40
3178 40 ▶ XPUSHs(sv_2mortal(newSVsv(info ? info : &PL_sv_undef)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(info ? info : &PL_sv_undef))); 0 40 40
XPUSHs(sv_2mortal(newSVsv(info ? info : &PL_sv_undef))); 40 0 40
3179 40 ▶ XPUSHs(sv_2mortal(newSVsv(type_like ? type_like : &PL_sv_undef)));
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(type_like ? type_like : &PL_sv_undef))); 0 40 40
XPUSHs(sv_2mortal(newSVsv(type_like ? type_like : &PL_sv_undef))); 40 0 40
3180 40 PUTBACK;
3181  
3182 40 ▶ if (call_sv(cb, G_SCALAR | G_EVAL) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (call_sv(cb, G_SCALAR | G_EVAL) > 0) { 40 0 40
3183 40 SPAGAIN;
3184 40 result = POPs;
3185 40 ▶ result = result ? newSVsv(result) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
result = result ? newSVsv(result) : NULL; 40 0 40
3186 40 PUTBACK;
3187 }
3188  
3189 40 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 40 0 40
if (SvTRUE(ERRSV)) { 0 40 40
3190 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
3191 0 ▶ *error_out = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVsv(ERRSV); 0 0 0
3192 }
3193 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
3194 0 result = NULL;
3195 }
3196  
3197 40 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 40 0 40
3198 40 LEAVE;
3199 40 return result;
3200 }
3201  
3202 static SV *
3203 0 gql_runtime_vm_resolve_runtime_type_sv(
3204 pTHX_
3205 SV *dispatch_sv,
3206 SV *cache_sv,
3207 SV *value,
3208 SV *context,
3209 SV *info,
3210 SV *abstract_type,
3211 SV **error_out
3212 )
3213 {
3214 SV *tag_resolver;
3215 SV *tag_map_sv;
3216 SV *resolve_type;
3217 SV *name2type_sv;
3218 SV *possible_types_sv;
3219 SV *is_type_of_map_sv;
3220 0 SV *tmp_error = NULL;
3221 0 SV *resolved = NULL;
3222  
3223 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
3224 0 *error_out = NULL;
3225 }
3226  
3227 0 tag_resolver = gql_runtime_vm_dispatch_hash_fetch(aTHX_ dispatch_sv, "tag_resolver", 12);
3228 0 tag_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ dispatch_sv, "tag_map", 7);
3229 0 resolve_type = gql_runtime_vm_dispatch_hash_fetch(aTHX_ dispatch_sv, "resolve_type", 12);
3230 0 name2type_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ dispatch_sv, "name2type", 9);
3231 0 possible_types_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ dispatch_sv, "possible_types", 14);
3232 0 is_type_of_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ dispatch_sv, "is_type_of_map", 14);
3233  
3234 0 ▶ if (!name2type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!name2type_sv) { 0 0 0
3235 0 name2type_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "name2type", 9);
3236 }
3237 0 ▶ if (!possible_types_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!possible_types_sv) { 0 0 0
3238 0 SV *possible_types_map = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "possible_types", 14);
3239 0 SV *abstract_name = gql_runtime_vm_dispatch_hash_fetch(aTHX_ dispatch_sv, "abstract_name", 13);
3240 0 possible_types_sv = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ possible_types_map, abstract_name);
3241 }
3242 0 ▶ if (!is_type_of_map_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!is_type_of_map_sv) { 0 0 0
3243 0 is_type_of_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "is_type_of_map", 14);
3244 }
3245  
3246 0 ▶ if (tag_resolver) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_resolver) { 0 0 0
3247 0 SV *tag = gql_runtime_vm_call_cb_scalar(aTHX_ tag_resolver, value, context, info, abstract_type, &tmp_error);
3248 0 ▶ if (tmp_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_error) { 0 0 0
3249 0 ▶ if (error_out) *error_out = tmp_error;
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) *error_out = tmp_error; 0 0 0
3250 0 return NULL;
3251 }
3252 0 ▶ if (tag && SvOK(tag)) {
Branch: 2 branches
BranchTrueFalseTotal
if (tag && SvOK(tag)) { 0 0 0
if (tag && SvOK(tag)) { 0 0 0
3253 0 SV *mapped = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ tag_map_sv, tag);
3254 0 SvREFCNT_dec(tag);
3255 0 ▶ if (mapped && SvOK(mapped)) {
Branch: 2 branches
BranchTrueFalseTotal
if (mapped && SvOK(mapped)) { 0 0 0
if (mapped && SvOK(mapped)) { 0 0 0
3256 0 return newSVsv(mapped);
3257 }
3258 0 ▶ } else if (tag) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (tag) { 0 0 0
3259 0 SvREFCNT_dec(tag);
3260 }
3261 }
3262  
3263 0 ▶ if (resolve_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolve_type) { 0 0 0
3264 0 resolved = gql_runtime_vm_call_cb_scalar(aTHX_ resolve_type, value, context, info, abstract_type, &tmp_error);
3265 0 ▶ if (tmp_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_error) { 0 0 0
3266 0 ▶ if (error_out) *error_out = tmp_error;
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) *error_out = tmp_error; 0 0 0
3267 0 return NULL;
3268 }
3269 0 ▶ if (resolved && SvOK(resolved)) {
Branch: 2 branches
BranchTrueFalseTotal
if (resolved && SvOK(resolved)) { 0 0 0
if (resolved && SvOK(resolved)) { 0 0 0
3270 0 ▶ if (SvROK(resolved)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(resolved)) { 0 0 0
3271 0 return resolved;
3272 }
3273 else {
3274 0 SV *mapped = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ name2type_sv, resolved);
3275 0 SvREFCNT_dec(resolved);
3276 0 ▶ return mapped && SvOK(mapped) ? newSVsv(mapped) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
return mapped && SvOK(mapped) ? newSVsv(mapped) : NULL; 0 0 0
return mapped && SvOK(mapped) ? newSVsv(mapped) : NULL; 0 0 0
3277 }
3278 0 ▶ } else if (resolved) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (resolved) { 0 0 0
3279 0 SvREFCNT_dec(resolved);
3280 }
3281 }
3282  
3283 0 ▶ if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
3284 0 AV *possible_types_av = (AV *)SvRV(possible_types_sv);
3285 SSize_t i;
3286 0 ▶ for (i = 0; i <= av_len(possible_types_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(possible_types_av); i++) { 0 0 0
3287 0 SV **type_svp = av_fetch(possible_types_av, i, 0);
3288 SV *type_sv;
3289 SV *type_name_sv;
3290 SV *cb;
3291 SV *matched;
3292 0 ▶ if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) { 0 0 0
if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) { 0 0 0
if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) { 0 0 0
3293 0 continue;
3294 }
3295 0 type_name_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ type_sv, "name", 4);
3296 0 ▶ if (!type_name_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!type_name_sv) { 0 0 0
3297 0 dSP;
3298 0 ENTER;
3299 0 SAVETMPS;
3300 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
3301 0 ▶ XPUSHs(sv_2mortal(newSVsv(type_sv)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(type_sv))); 0 0 0
3302 0 PUTBACK;
3303 0 ▶ if (call_method("name", G_SCALAR) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("name", G_SCALAR) > 0) { 0 0 0
3304 0 SPAGAIN;
3305 0 type_name_sv = POPs;
3306 0 ▶ type_name_sv = type_name_sv ? newSVsv(type_name_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
type_name_sv = type_name_sv ? newSVsv(type_name_sv) : NULL; 0 0 0
3307 0 PUTBACK;
3308 }
3309 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
3310 0 LEAVE;
3311 } else {
3312 0 type_name_sv = newSVsv(type_name_sv);
3313 }
3314 0 cb = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ is_type_of_map_sv, type_name_sv);
3315 0 SvREFCNT_dec(type_name_sv);
3316 0 ▶ if (!cb || !SvOK(cb)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!cb || !SvOK(cb)) { 0 0 0
if (!cb || !SvOK(cb)) { 0 0 0
3317 0 continue;
3318 }
3319 0 matched = gql_runtime_vm_call_cb_scalar(aTHX_ cb, value, context, info, type_sv, &tmp_error);
3320 0 ▶ if (tmp_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_error) { 0 0 0
3321 0 ▶ if (error_out) *error_out = tmp_error;
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) *error_out = tmp_error; 0 0 0
3322 0 return NULL;
3323 }
3324 0 ▶ if (matched && SvTRUE(matched)) {
Branch: 2 branches
BranchTrueFalseTotal
if (matched && SvTRUE(matched)) { 0 0 0
if (matched && SvTRUE(matched)) { 0 0 0
3325 0 SvREFCNT_dec(matched);
3326 0 return newSVsv(type_sv);
3327 }
3328 0 ▶ if (matched) {
Branch: 1 branch
BranchTrueFalseTotal
if (matched) { 0 0 0
3329 0 SvREFCNT_dec(matched);
3330 }
3331 }
3332 }
3333  
3334 0 return NULL;
3335 }
3336  
3337 static SV *
3338 40 gql_runtime_vm_resolve_runtime_type_for_abstract_sv(
3339 pTHX_
3340 SV *cache_sv,
3341 const char *abstract_name,
3342 SV *value,
3343 SV *context,
3344 SV *info,
3345 SV *abstract_type,
3346 SV **error_out
3347 )
3348 {
3349 40 SV *tag_resolver = NULL;
3350 40 SV *tag_map_sv = NULL;
3351 40 SV *resolve_type = NULL;
3352 40 SV *name2type_sv = NULL;
3353 40 SV *possible_types_sv = NULL;
3354 40 SV *is_type_of_map_sv = NULL;
3355 40 SV *tmp_error = NULL;
3356 40 SV *resolved = NULL;
3357  
3358 40 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 40 0 40
3359 40 *error_out = NULL;
3360 }
3361  
3362 40 ▶ if (!cache_sv || !SvOK(cache_sv) || !SvROK(cache_sv) || SvTYPE(SvRV(cache_sv)) != SVt_PVHV || !abstract_name) {
Branch: 5 branches
BranchTrueFalseTotal
if (!cache_sv || !SvOK(cache_sv) || !SvROK(cache_sv) || SvTYPE(SvRV(cache_sv)) != SVt_PVHV || !abstract_name) { 40 0 40
if (!cache_sv || !SvOK(cache_sv) || !SvROK(cache_sv) || SvTYPE(SvRV(cache_sv)) != SVt_PVHV || !abstract_name) { 40 0 40
if (!cache_sv || !SvOK(cache_sv) || !SvROK(cache_sv) || SvTYPE(SvRV(cache_sv)) != SVt_PVHV || !abstract_name) { 40 0 40
if (!cache_sv || !SvOK(cache_sv) || !SvROK(cache_sv) || SvTYPE(SvRV(cache_sv)) != SVt_PVHV || !abstract_name) { 40 0 40
if (!cache_sv || !SvOK(cache_sv) || !SvROK(cache_sv) || SvTYPE(SvRV(cache_sv)) != SVt_PVHV || !abstract_name) { 0 40 40
3363 0 return NULL;
3364 }
3365  
3366 {
3367 40 SV *abstract_name_sv = newSVpv(abstract_name, 0);
3368 40 SV *tag_resolver_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "tag_resolver_map", 16);
3369 40 SV *runtime_tag_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "runtime_tag_map", 15);
3370 40 SV *resolve_type_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "resolve_type_map", 16);
3371 40 SV *possible_types_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "possible_types", 14);
3372  
3373 40 name2type_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "name2type", 9);
3374 40 is_type_of_map_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ cache_sv, "is_type_of_map", 14);
3375  
3376 40 ▶ if (tag_resolver_map_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_resolver_map_sv) { 40 0 40
3377 40 tag_resolver = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ tag_resolver_map_sv, abstract_name_sv);
3378 }
3379 40 ▶ if (runtime_tag_map_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime_tag_map_sv) { 40 0 40
3380 40 tag_map_sv = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ runtime_tag_map_sv, abstract_name_sv);
3381 }
3382 40 ▶ if (resolve_type_map_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolve_type_map_sv) { 40 0 40
3383 40 resolve_type = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ resolve_type_map_sv, abstract_name_sv);
3384 }
3385 40 ▶ if (possible_types_map_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (possible_types_map_sv) { 40 0 40
3386 40 possible_types_sv = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ possible_types_map_sv, abstract_name_sv);
3387 }
3388  
3389 40 SvREFCNT_dec(abstract_name_sv);
3390 }
3391  
3392 40 ▶ if (tag_resolver) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_resolver) { 38 2 40
3393 38 SV *tag = gql_runtime_vm_call_cb_scalar(aTHX_ tag_resolver, value, context, info, abstract_type, &tmp_error);
3394 38 ▶ if (tmp_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_error) { 0 38 38
3395 0 ▶ if (error_out) *error_out = tmp_error;
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) *error_out = tmp_error; 0 0 0
3396 0 return NULL;
3397 }
3398 38 ▶ if (tag && SvOK(tag)) {
Branch: 2 branches
BranchTrueFalseTotal
if (tag && SvOK(tag)) { 38 0 38
if (tag && SvOK(tag)) { 38 0 38
3399 38 SV *mapped = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ tag_map_sv, tag);
3400 38 SvREFCNT_dec(tag);
3401 38 ▶ if (mapped && SvOK(mapped)) {
Branch: 2 branches
BranchTrueFalseTotal
if (mapped && SvOK(mapped)) { 38 0 38
if (mapped && SvOK(mapped)) { 38 0 38
3402 38 return newSVsv(mapped);
3403 }
3404 0 ▶ } else if (tag) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (tag) { 0 0 0
3405 0 SvREFCNT_dec(tag);
3406 }
3407 }
3408  
3409 2 ▶ if (resolve_type) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolve_type) { 2 0 2
3410 2 resolved = gql_runtime_vm_call_cb_scalar(aTHX_ resolve_type, value, context, info, abstract_type, &tmp_error);
3411 2 ▶ if (tmp_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_error) { 0 2 2
3412 0 ▶ if (error_out) *error_out = tmp_error;
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) *error_out = tmp_error; 0 0 0
3413 0 return NULL;
3414 }
3415 2 ▶ if (resolved && SvOK(resolved)) {
Branch: 2 branches
BranchTrueFalseTotal
if (resolved && SvOK(resolved)) { 2 0 2
if (resolved && SvOK(resolved)) { 2 0 2
3416 2 ▶ if (SvROK(resolved)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(resolved)) { 0 2 2
3417 0 return resolved;
3418 }
3419 else {
3420 2 SV *mapped = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ name2type_sv, resolved);
3421 2 SvREFCNT_dec(resolved);
3422 2 ▶ return mapped && SvOK(mapped) ? newSVsv(mapped) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
return mapped && SvOK(mapped) ? newSVsv(mapped) : NULL; 2 0 2
return mapped && SvOK(mapped) ? newSVsv(mapped) : NULL; 2 0 2
3423 }
3424 0 ▶ } else if (resolved) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (resolved) { 0 0 0
3425 0 SvREFCNT_dec(resolved);
3426 }
3427 }
3428  
3429 0 ▶ if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
if (possible_types_sv && SvOK(possible_types_sv) && SvROK(possible_types_sv) && SvTYPE(SvRV(possible_types_sv)) == SVt_PVAV) { 0 0 0
3430 0 AV *possible_types_av = (AV *)SvRV(possible_types_sv);
3431 SSize_t i;
3432 0 ▶ for (i = 0; i <= av_len(possible_types_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(possible_types_av); i++) { 0 0 0
3433 0 SV **type_svp = av_fetch(possible_types_av, i, 0);
3434 SV *type_sv;
3435 SV *type_name_sv;
3436 SV *cb;
3437 SV *matched;
3438 0 ▶ if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) { 0 0 0
if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) { 0 0 0
if (!type_svp || !(type_sv = *type_svp) || !SvOK(type_sv)) { 0 0 0
3439 0 continue;
3440 }
3441 0 type_name_sv = gql_runtime_vm_dispatch_hash_fetch(aTHX_ type_sv, "name", 4);
3442 0 ▶ if (!type_name_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!type_name_sv) { 0 0 0
3443 0 dSP;
3444 0 ENTER;
3445 0 SAVETMPS;
3446 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
3447 0 ▶ XPUSHs(sv_2mortal(newSVsv(type_sv)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(type_sv))); 0 0 0
3448 0 PUTBACK;
3449 0 ▶ if (call_method("name", G_SCALAR) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("name", G_SCALAR) > 0) { 0 0 0
3450 0 SPAGAIN;
3451 0 type_name_sv = POPs;
3452 0 ▶ type_name_sv = type_name_sv ? newSVsv(type_name_sv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
type_name_sv = type_name_sv ? newSVsv(type_name_sv) : NULL; 0 0 0
3453 0 PUTBACK;
3454 }
3455 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
3456 0 LEAVE;
3457 } else {
3458 0 type_name_sv = newSVsv(type_name_sv);
3459 }
3460 0 cb = gql_runtime_vm_hash_lookup_ent_sv(aTHX_ is_type_of_map_sv, type_name_sv);
3461 0 SvREFCNT_dec(type_name_sv);
3462 0 ▶ if (!cb || !SvOK(cb)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!cb || !SvOK(cb)) { 0 0 0
if (!cb || !SvOK(cb)) { 0 0 0
3463 0 continue;
3464 }
3465 0 matched = gql_runtime_vm_call_cb_scalar(aTHX_ cb, value, context, info, type_sv, &tmp_error);
3466 0 ▶ if (tmp_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (tmp_error) { 0 0 0
3467 0 ▶ if (error_out) *error_out = tmp_error;
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) *error_out = tmp_error; 0 0 0
3468 0 return NULL;
3469 }
3470 0 ▶ if (matched && SvTRUE(matched)) {
Branch: 2 branches
BranchTrueFalseTotal
if (matched && SvTRUE(matched)) { 0 0 0
if (matched && SvTRUE(matched)) { 0 0 0
3471 0 SvREFCNT_dec(matched);
3472 0 return newSVsv(type_sv);
3473 }
3474 0 ▶ if (matched) {
Branch: 1 branch
BranchTrueFalseTotal
if (matched) { 0 0 0
3475 0 SvREFCNT_dec(matched);
3476 }
3477 }
3478 }
3479  
3480 0 return NULL;
3481 }
3482  
3483 static SV *
3484 0 gql_runtime_vm_materialize_dynamic_value_sv(pTHX_ SV *value, HV *variables)
3485 {
3486 SV *inner;
3487  
3488 0 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 0 0 0
if (!value || !SvOK(value)) { 0 0 0
3489 0 return newSV(0);
3490 }
3491  
3492 0 ▶ if (!SvROK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(value)) { 0 0 0
3493 0 return newSVsv(value);
3494 }
3495  
3496 0 inner = SvRV(value);
3497  
3498 0 ▶ if (SvTYPE(inner) == SVt_PVAV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(inner) == SVt_PVAV) { 0 0 0
3499 0 AV *src = (AV *)inner;
3500 0 AV *dst = newAV();
3501 0 SSize_t max = av_len(src);
3502 SSize_t i;
3503 0 av_extend(dst, max);
3504 0 ▶ for (i = 0; i <= max; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= max; i++) { 0 0 0
3505 0 SV **svp = av_fetch(src, i, 0);
3506 0 ▶ av_store(dst, i, gql_runtime_vm_materialize_dynamic_value_sv(
Branch: 1 branch
BranchTrueFalseTotal
av_store(dst, i, gql_runtime_vm_materialize_dynamic_value_sv( 0 0 0
3507 aTHX_
3508 (svp ? *svp : &PL_sv_undef),
3509 variables
3510 ));
3511 }
3512 0 return newRV_noinc((SV *)dst);
3513 }
3514  
3515 0 ▶ if (SvTYPE(inner) == SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(inner) == SVt_PVHV) { 0 0 0
3516 0 HV *src = (HV *)inner;
3517 0 HV *dst = newHV();
3518 HE *he;
3519 0 (void)hv_iterinit(src);
3520 0 ▶ while ((he = hv_iternext(src))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(src))) { 0 0 0
3521 0 ▶ SV *key_sv = HeSVKEY_force(he);
Branch: 2 branches
BranchTrueFalseTotal
SV *key_sv = HeSVKEY_force(he); 0 0 0
SV *key_sv = HeSVKEY_force(he); 0 0 0
3522 0 SV *val_sv = HeVAL(he);
3523 0 hv_store_ent(
3524 dst,
3525 newSVsv(key_sv),
3526 gql_runtime_vm_materialize_dynamic_value_sv(aTHX_ val_sv, variables),
3527 0
3528 );
3529 }
3530 0 return newRV_noinc((SV *)dst);
3531 }
3532  
3533 0 ▶ if (SvROK(inner)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(inner)) { 0 0 0
3534 0 return newSVsv(SvRV(inner));
3535 }
3536  
3537 0 ▶ if (variables) {
Branch: 1 branch
BranchTrueFalseTotal
if (variables) { 0 0 0
3538 STRLEN len;
3539 0 const char *name = SvPV(inner, len);
3540 0 SV **svp = hv_fetch(variables, name, (I32)len, 0);
3541 0 ▶ return svp ? newSVsv(*svp) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
return svp ? newSVsv(*svp) : newSV(0); 0 0 0
3542 }
3543  
3544 0 return newSV(0);
3545 }
3546  
3547 static int
3548 0 gql_runtime_vm_evaluate_runtime_guards_hv(pTHX_ SV *guards_sv, HV *variables)
3549 {
3550 AV *guards_av;
3551 SSize_t i;
3552  
3553 0 ▶ if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 0 0 0
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 0 0 0
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 0 0 0
if (!guards_sv || !SvOK(guards_sv) || !SvROK(guards_sv) || SvTYPE(SvRV(guards_sv)) != SVt_PVAV) { 0 0 0
3554 0 return 1;
3555 }
3556  
3557 0 guards_av = (AV *)SvRV(guards_sv);
3558 0 ▶ for (i = 0; i <= av_len(guards_av); i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= av_len(guards_av); i++) { 0 0 0
3559 0 SV **directive_svp = av_fetch(guards_av, i, 0);
3560 SV *directive_sv;
3561 HV *directive_hv;
3562 SV **name_svp;
3563 SV **arguments_svp;
3564 HV *arguments_hv;
3565 SV **if_svp;
3566 SV *if_value_sv;
3567 int bool_value;
3568 STRLEN name_len;
3569 const char *name;
3570  
3571 0 ▶ if (!directive_svp || !(directive_sv = *directive_svp) || !SvOK(directive_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!directive_svp || !(directive_sv = *directive_svp) || !SvOK(directive_sv)) { 0 0 0
if (!directive_svp || !(directive_sv = *directive_svp) || !SvOK(directive_sv)) { 0 0 0
if (!directive_svp || !(directive_sv = *directive_svp) || !SvOK(directive_sv)) { 0 0 0
3572 0 continue;
3573 }
3574 0 ▶ if (!SvROK(directive_sv) || SvTYPE(SvRV(directive_sv)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(directive_sv) || SvTYPE(SvRV(directive_sv)) != SVt_PVHV) { 0 0 0
if (!SvROK(directive_sv) || SvTYPE(SvRV(directive_sv)) != SVt_PVHV) { 0 0 0
3575 0 continue;
3576 }
3577 0 directive_hv = (HV *)SvRV(directive_sv);
3578 0 name_svp = hv_fetch(directive_hv, "name", 4, 0);
3579 0 arguments_svp = hv_fetch(directive_hv, "arguments", 9, 0);
3580 0 ▶ if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp)) {
Branch: 4 branches
BranchTrueFalseTotal
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp)) { 0 0 0
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp)) { 0 0 0
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp)) { 0 0 0
if (!name_svp || !SvOK(*name_svp) || !arguments_svp || !SvOK(*arguments_svp)) { 0 0 0
3581 0 continue;
3582 }
3583 0 ▶ if (!SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 0 0 0
if (!SvROK(*arguments_svp) || SvTYPE(SvRV(*arguments_svp)) != SVt_PVHV) { 0 0 0
3584 0 continue;
3585 }
3586 0 arguments_hv = (HV *)SvRV(*arguments_svp);
3587 0 if_svp = hv_fetch(arguments_hv, "if", 2, 0);
3588 0 ▶ if (!if_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!if_svp) { 0 0 0
3589 0 continue;
3590 }
3591  
3592 0 if_value_sv = gql_runtime_vm_materialize_dynamic_value_sv(
3593 aTHX_
3594 *if_svp,
3595 variables
3596 );
3597 0 bool_value = SvTRUE(if_value_sv) ? 1 : 0;
3598 0 SvREFCNT_dec(if_value_sv);
3599  
3600 0 name = SvPV(*name_svp, name_len);
3601 0 ▶ if (name_len == 4 && memEQ(name, "skip", 4) && bool_value) {
Branch: 3 branches
BranchTrueFalseTotal
if (name_len == 4 && memEQ(name, "skip", 4) && bool_value) { 0 0 0
if (name_len == 4 && memEQ(name, "skip", 4) && bool_value) { 0 0 0
if (name_len == 4 && memEQ(name, "skip", 4) && bool_value) { 0 0 0
3602 0 return 0;
3603 }
3604 0 ▶ if (name_len == 7 && memEQ(name, "include", 7) && !bool_value) {
Branch: 3 branches
BranchTrueFalseTotal
if (name_len == 7 && memEQ(name, "include", 7) && !bool_value) { 0 0 0
if (name_len == 7 && memEQ(name, "include", 7) && !bool_value) { 0 0 0
if (name_len == 7 && memEQ(name, "include", 7) && !bool_value) { 0 0 0
3605 0 return 0;
3606 }
3607 }
3608  
3609 0 return 1;
3610 }
3611  
3612 /* Free an op's abstract-child member-name table. abstract_child_names is a
3613 * char** whose entries are individually allocated by parse/clone, so the
3614 * destroy paths must free each string, not just the array. Valgrind found
3615 * these leaking - bounded by the program cache, so the
3616 * RSS soak never saw them). */
3617 static void
3618 4121 gql_runtime_vm_free_op_abstract_child_names(pTHX_ gql_runtime_vm_native_op_t *op)
3619 {
3620 IV i;
3621 4121 ▶ if (op->abstract_child_names) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->abstract_child_names) { 179 3942 4121
3622 490 ▶ for (i = 0; i < op->abstract_child_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < op->abstract_child_count; i++) { 311 179 490
3623 311 Safefree(op->abstract_child_names[i]);
3624 }
3625 }
3626 4121 Safefree(op->abstract_child_names);
3627 4121 op->abstract_child_names = NULL;
3628 4121 }
3629  
3630 static void
3631 513 gql_runtime_vm_native_bundle_destroy(gql_runtime_vm_native_bundle_t *bundle)
3632 {
3633 IV i;
3634 IV j;
3635 513 ▶ if (!bundle) {
Branch: 1 branch
BranchTrueFalseTotal
if (!bundle) { 115 398 513
3636 115 return;
3637 }
3638 398 ▶ if (bundle->runtime_slots) {
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->runtime_slots) { 398 0 398
3639 398 ▶ if (bundle->owns_runtime_slots) {
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->owns_runtime_slots) { 398 0 398
3640 26519 ▶ for (i = 0; i < bundle->runtime_slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bundle->runtime_slot_count; i++) { 26121 398 26519
3641 26121 Safefree(bundle->runtime_slots[i].field_name);
3642 26121 Safefree(bundle->runtime_slots[i].result_name);
3643 26121 Safefree(bundle->runtime_slots[i].return_type_name);
3644 26121 Safefree(bundle->runtime_slots[i].accessor_name);
3645 26121 gql_runtime_vm_free_native_arg_defs(aTHX_ bundle->runtime_slots[i].arg_defs, bundle->runtime_slots[i].arg_def_count);
3646 }
3647 }
3648 }
3649 398 Safefree(bundle->runtime_slots);
3650 398 ▶ if (bundle->blocks && bundle->owns_blocks) {
Branch: 2 branches
BranchTrueFalseTotal
if (bundle->blocks && bundle->owns_blocks) { 398 0 398
if (bundle->blocks && bundle->owns_blocks) { 398 0 398
3651 1434 ▶ for (i = 0; i < bundle->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bundle->block_count; i++) { 1036 398 1434
3652 1036 Safefree(bundle->blocks[i].type_name);
3653 1036 SvREFCNT_dec(bundle->blocks[i].type_object_sv);
3654 1036 ▶ if (bundle->blocks[i].slots) {
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->blocks[i].slots) { 1034 2 1036
3655 2990 ▶ for (j = 0; j < bundle->blocks[i].slot_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < bundle->blocks[i].slot_count; j++) { 1956 1034 2990
3656 1956 Safefree(bundle->blocks[i].slots[j].field_name);
3657 1956 Safefree(bundle->blocks[i].slots[j].result_name);
3658 1956 Safefree(bundle->blocks[i].slots[j].return_type_name);
3659 1956 Safefree(bundle->blocks[i].slots[j].accessor_name);
3660 1956 gql_runtime_vm_free_native_arg_defs(aTHX_ bundle->blocks[i].slots[j].arg_defs, bundle->blocks[i].slots[j].arg_def_count);
3661 }
3662 }
3663 1036 ▶ if (bundle->blocks[i].ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->blocks[i].ops) { 1034 2 1036
3664 2990 ▶ for (j = 0; j < bundle->blocks[i].op_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < bundle->blocks[i].op_count; j++) { 1956 1034 2990
3665 1956 gql_runtime_vm_free_op_abstract_child_names(aTHX_ &bundle->blocks[i].ops[j]);
3666 1956 Safefree(bundle->blocks[i].ops[j].abstract_child_indexes);
3667 1956 gql_runtime_vm_native_args_payload_destroy(aTHX_ bundle->blocks[i].ops[j].args_payload_native);
3668 1956 gql_runtime_vm_native_directives_payload_destroy(aTHX_ bundle->blocks[i].ops[j].directives_payload_native);
3669 1956 SvREFCNT_dec(bundle->blocks[i].ops[j].runtime_directives_sv);
3670 }
3671 }
3672 1036 Safefree(bundle->blocks[i].slots);
3673 1036 Safefree(bundle->blocks[i].ops);
3674 }
3675 }
3676 398 Safefree(bundle->blocks);
3677 398 SvREFCNT_dec(bundle->prepared_runtime_schema);
3678 398 Safefree(bundle);
3679 }
3680  
3681 static IV
3682 362 gql_runtime_vm_program_needs_variable_specialization(gql_runtime_vm_native_program_t *program)
3683 {
3684 IV i;
3685 IV j;
3686 362 ▶ if (!program) {
Branch: 1 branch
BranchTrueFalseTotal
if (!program) { 0 362 362
3687 0 return 0;
3688 }
3689 362 ▶ if (program->needs_variable_specialization) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->needs_variable_specialization) { 266 96 362
3690 266 return program->needs_variable_specialization == 2 ? 1 : 0;
3691 }
3692 96 program->needs_variable_specialization = 1;
3693 314 ▶ for (i = 0; i < program->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->block_count; i++) { 220 94 314
3694 220 gql_runtime_vm_native_block_t *block = &program->blocks[i];
3695 220 ▶ if (!block->ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block->ops) { 0 220 220
3696 0 continue;
3697 }
3698 654 ▶ for (j = 0; j < block->op_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < block->op_count; j++) { 436 218 654
3699 436 gql_runtime_vm_native_op_t *op = &block->ops[j];
3700 436 ▶ if (op->has_runtime_directives) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->has_runtime_directives) { 2 434 436
3701 2 program->needs_variable_specialization = 2;
3702 2 return 1;
3703 }
3704 }
3705 }
3706 94 return 0;
3707 }
3708  
3709 static void
3710 480 gql_runtime_vm_native_program_destroy(gql_runtime_vm_native_program_t *program)
3711 {
3712 IV i;
3713 IV j;
3714 480 ▶ if (!program) {
Branch: 1 branch
BranchTrueFalseTotal
if (!program) { 0 480 480
3715 0 return;
3716 }
3717 480 Safefree(program->operation_name);
3718 480 gql_runtime_vm_free_native_arg_defs(aTHX_ program->variable_defs, program->variable_def_count);
3719 480 ▶ if (program->blocks) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->blocks) { 480 0 480
3720 1660 ▶ for (i = 0; i < program->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->block_count; i++) { 1180 480 1660
3721 1180 Safefree(program->blocks[i].type_name);
3722 1180 SvREFCNT_dec(program->blocks[i].type_object_sv);
3723 1180 ▶ if (program->blocks[i].slots) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->blocks[i].slots) { 1178 2 1180
3724 3343 ▶ for (j = 0; j < program->blocks[i].slot_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < program->blocks[i].slot_count; j++) { 2165 1178 3343
3725 2165 Safefree(program->blocks[i].slots[j].field_name);
3726 2165 Safefree(program->blocks[i].slots[j].result_name);
3727 2165 Safefree(program->blocks[i].slots[j].return_type_name);
3728 2165 Safefree(program->blocks[i].slots[j].accessor_name);
3729 2165 gql_runtime_vm_free_native_arg_defs(aTHX_ program->blocks[i].slots[j].arg_defs, program->blocks[i].slots[j].arg_def_count);
3730 }
3731 }
3732 1180 ▶ if (program->blocks[i].ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->blocks[i].ops) { 1178 2 1180
3733 3343 ▶ for (j = 0; j < program->blocks[i].op_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < program->blocks[i].op_count; j++) { 2165 1178 3343
3734 2165 gql_runtime_vm_free_op_abstract_child_names(aTHX_ &program->blocks[i].ops[j]);
3735 2165 Safefree(program->blocks[i].ops[j].abstract_child_indexes);
3736 2165 gql_runtime_vm_native_args_payload_destroy(aTHX_ program->blocks[i].ops[j].args_payload_native);
3737 2165 gql_runtime_vm_native_directives_payload_destroy(aTHX_ program->blocks[i].ops[j].directives_payload_native);
3738 2165 SvREFCNT_dec(program->blocks[i].ops[j].runtime_directives_sv);
3739 }
3740 }
3741 1180 Safefree(program->blocks[i].slots);
3742 1180 Safefree(program->blocks[i].ops);
3743 }
3744 }
3745 480 ▶ if (program->args_payloads) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->args_payloads) { 204 276 480
3746 446 ▶ for (i = 0; i < program->args_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->args_payload_count; i++) { 242 204 446
3747 242 gql_runtime_vm_native_args_payload_destroy(aTHX_ program->args_payloads[i]);
3748 }
3749 }
3750 480 ▶ if (program->directives_payloads) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->directives_payloads) { 11 469 480
3751 23 ▶ for (i = 0; i < program->directives_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->directives_payload_count; i++) { 12 11 23
3752 12 gql_runtime_vm_native_directives_payload_destroy(aTHX_ program->directives_payloads[i]);
3753 }
3754 }
3755 480 gql_runtime_vm_native_bundle_destroy(program->cached_bundle);
3756 480 Safefree(program->args_payloads);
3757 480 Safefree(program->directives_payloads);
3758 480 Safefree(program->blocks);
3759 480 Safefree(program);
3760 }
3761  
3762 static void
3763 242 gql_runtime_vm_native_runtime_destroy(gql_runtime_vm_native_runtime_t *runtime)
3764 {
3765 IV i;
3766 242 ▶ if (!runtime) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime) { 0 242 242
3767 0 return;
3768 }
3769 242 gql_runtime_vm_async_adapter_destroy(aTHX_ runtime->async_adapter);
3770 242 ▶ if (runtime->runtime_slots) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime->runtime_slots) { 242 0 242
3771 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
3772 13102 Safefree(runtime->runtime_slots[i].field_name);
3773 13102 Safefree(runtime->runtime_slots[i].result_name);
3774 13102 Safefree(runtime->runtime_slots[i].return_type_name);
3775 13102 Safefree(runtime->runtime_slots[i].accessor_name);
3776 13102 gql_runtime_vm_free_native_arg_defs(aTHX_ runtime->runtime_slots[i].arg_defs, runtime->runtime_slots[i].arg_def_count);
3777 }
3778 }
3779 242 Safefree(runtime->runtime_slots);
3780 242 ▶ if (runtime->callback_catalog && runtime->callback_catalog->slot_resolvers) {
Branch: 2 branches
BranchTrueFalseTotal
if (runtime->callback_catalog && runtime->callback_catalog->slot_resolvers) { 242 0 242
if (runtime->callback_catalog && runtime->callback_catalog->slot_resolvers) { 242 0 242
3781 242 gql_runtime_vm_native_callback_catalog_t *catalog = runtime->callback_catalog;
3782 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
3783 13102 ▶ if (catalog->slot_field_names && catalog->slot_field_names[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_field_names && catalog->slot_field_names[i]) { 13102 0 13102
if (catalog->slot_field_names && catalog->slot_field_names[i]) { 13102 0 13102
3784 13102 SvREFCNT_dec(catalog->slot_field_names[i]);
3785 }
3786 13102 ▶ if (catalog->slot_resolvers[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (catalog->slot_resolvers[i]) { 8534 4568 13102
3787 8534 SvREFCNT_dec(catalog->slot_resolvers[i]);
3788 }
3789 13102 ▶ if (catalog->slot_loader_specs && catalog->slot_loader_specs[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_loader_specs && catalog->slot_loader_specs[i]) { 13102 0 13102
if (catalog->slot_loader_specs && catalog->slot_loader_specs[i]) { 9 13093 13102
3790 9 SvREFCNT_dec(catalog->slot_loader_specs[i]);
3791 }
3792 13102 ▶ if (catalog->slot_native_loader_specs
Branch: 1 branch
BranchTrueFalseTotal
if (catalog->slot_native_loader_specs 13102 0 13102
3793 13102 ▶ && catalog->slot_native_loader_specs[i]) {
Branch: 1 branch
BranchTrueFalseTotal
&& catalog->slot_native_loader_specs[i]) { 9 13093 13102
3794 9 gql_runtime_vm_native_loader_spec_t *loader_spec =
3795 9 catalog->slot_native_loader_specs[i];
3796 9 Safefree(loader_spec->context_key);
3797 9 Safefree(loader_spec->key_name);
3798 9 Safefree(loader_spec->route_key_name);
3799 9 Safefree(loader_spec);
3800 }
3801 13102 ▶ if (catalog->slot_type_objects && catalog->slot_type_objects[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_type_objects && catalog->slot_type_objects[i]) { 13102 0 13102
if (catalog->slot_type_objects && catalog->slot_type_objects[i]) { 13102 0 13102
3802 13102 SvREFCNT_dec(catalog->slot_type_objects[i]);
3803 }
3804 13102 ▶ if (catalog->slot_tag_resolvers && catalog->slot_tag_resolvers[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_tag_resolvers && catalog->slot_tag_resolvers[i]) { 13102 0 13102
if (catalog->slot_tag_resolvers && catalog->slot_tag_resolvers[i]) { 28 13074 13102
3805 28 SvREFCNT_dec(catalog->slot_tag_resolvers[i]);
3806 }
3807 13102 ▶ if (catalog->slot_resolve_types && catalog->slot_resolve_types[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_resolve_types && catalog->slot_resolve_types[i]) { 13102 0 13102
if (catalog->slot_resolve_types && catalog->slot_resolve_types[i]) { 9 13093 13102
3808 9 SvREFCNT_dec(catalog->slot_resolve_types[i]);
3809 }
3810 13102 ▶ if (catalog->slot_leaf_payloads && catalog->slot_leaf_payloads[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_leaf_payloads && catalog->slot_leaf_payloads[i]) { 13102 0 13102
if (catalog->slot_leaf_payloads && catalog->slot_leaf_payloads[i]) { 518 12584 13102
3811 518 SvREFCNT_dec(catalog->slot_leaf_payloads[i]);
3812 }
3813 13102 ▶ if (catalog->slot_tag_entries && catalog->slot_tag_entries[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_tag_entries && catalog->slot_tag_entries[i]) { 13102 0 13102
if (catalog->slot_tag_entries && catalog->slot_tag_entries[i]) { 28 13074 13102
3814 IV j;
3815 77 ▶ for (j = 0; j < catalog->slot_tag_entry_counts[i]; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < catalog->slot_tag_entry_counts[i]; j++) { 49 28 77
3816 49 Safefree(catalog->slot_tag_entries[i][j].tag_name);
3817 49 Safefree(catalog->slot_tag_entries[i][j].type_name);
3818 }
3819 28 Safefree(catalog->slot_tag_entries[i]);
3820 }
3821 13102 ▶ if (catalog->slot_possible_type_entries && catalog->slot_possible_type_entries[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (catalog->slot_possible_type_entries && catalog->slot_possible_type_entries[i]) { 13102 0 13102
if (catalog->slot_possible_type_entries && catalog->slot_possible_type_entries[i]) { 38 13064 13102
3822 IV j;
3823 101 ▶ for (j = 0; j < catalog->slot_possible_type_entry_counts[i]; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < catalog->slot_possible_type_entry_counts[i]; j++) { 63 38 101
3824 63 Safefree(catalog->slot_possible_type_entries[i][j].type_name);
3825 63 SvREFCNT_dec(catalog->slot_possible_type_entries[i][j].type_sv);
3826 63 SvREFCNT_dec(catalog->slot_possible_type_entries[i][j].is_type_of_cb);
3827 }
3828 38 Safefree(catalog->slot_possible_type_entries[i]);
3829 }
3830 }
3831 242 Safefree(catalog->slot_field_names);
3832 242 Safefree(catalog->slot_resolvers);
3833 242 Safefree(catalog->slot_loader_specs);
3834 242 Safefree(catalog->slot_native_loader_specs);
3835 242 Safefree(catalog->slot_type_objects);
3836 242 Safefree(catalog->slot_tag_resolvers);
3837 242 Safefree(catalog->slot_tag_entries);
3838 242 Safefree(catalog->slot_tag_entry_counts);
3839 242 Safefree(catalog->slot_resolve_types);
3840 242 Safefree(catalog->slot_possible_type_entries);
3841 242 Safefree(catalog->slot_possible_type_entry_counts);
3842 242 Safefree(catalog->slot_leaf_kinds);
3843 242 Safefree(catalog->slot_leaf_payloads);
3844 242 ▶ if (catalog->runtime_schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (catalog->runtime_schema) { 242 0 242
3845 242 SvREFCNT_dec(catalog->runtime_schema);
3846 }
3847 242 Safefree(catalog);
3848 }
3849 242 Safefree(runtime);
3850 }
3851  
3852 static int
3853 52408 gql_runtime_vm_fetch_hv_string(pTHX_ HV *hv, const char *key, I32 keylen, char **out)
3854 {
3855 52408 SV **svp = hv_fetch(hv, key, keylen, 0);
3856 STRLEN len;
3857 const char *pv;
3858 52408 ▶ if (!svp || !SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) { 52408 0 52408
if (!svp || !SvOK(*svp)) { 13098 39310 52408
3859 13098 return 0;
3860 }
3861 39310 pv = SvPV(*svp, len);
3862 39310 Newxz(*out, len + 1, char);
3863 39310 Copy(pv, *out, len, char);
3864 39310 (*out)[len] = '\0';
3865 39310 return 1;
3866 }
3867  
3868 static void
3869 43824 gql_runtime_vm_free_native_arg_defs(pTHX_ gql_runtime_vm_native_arg_def_t *arg_defs, IV count)
3870 {
3871 IV i;
3872 43824 ▶ if (!arg_defs) {
Branch: 1 branch
BranchTrueFalseTotal
if (!arg_defs) { 38101 5723 43824
3873 38101 return;
3874 }
3875 13173 ▶ for (i = 0; i < count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) { 7450 5723 13173
3876 7450 Safefree(arg_defs[i].name);
3877 7450 ▶ if (arg_defs[i].type_def_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg_defs[i].type_def_sv) { 7450 0 7450
3878 7450 SvREFCNT_dec(arg_defs[i].type_def_sv);
3879 }
3880 7450 ▶ if (arg_defs[i].input_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg_defs[i].input_type_sv) { 6455 995 7450
3881 6455 SvREFCNT_dec(arg_defs[i].input_type_sv);
3882 }
3883 7450 ▶ if (arg_defs[i].default_value_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg_defs[i].default_value_sv) { 3316 4134 7450
3884 3316 SvREFCNT_dec(arg_defs[i].default_value_sv);
3885 }
3886 7450 ▶ if (arg_defs[i].default_native_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg_defs[i].default_native_value) { 3110 4340 7450
3887 3110 gql_runtime_vm_native_value_destroy(aTHX_ arg_defs[i].default_native_value);
3888 }
3889 }
3890 5723 Safefree(arg_defs);
3891 }
3892  
3893 static int
3894 17174 gql_runtime_vm_parse_native_arg_defs(pTHX_ SV *sv, gql_runtime_vm_native_arg_def_t **out_defs, IV *out_count)
3895 {
3896 AV *defs_av;
3897 HV *defs_hv;
3898 IV i;
3899 17174 *out_defs = NULL;
3900 17174 *out_count = 0;
3901 17174 ▶ if (!sv || !SvOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || !SvOK(sv)) { 17174 0 17174
if (!sv || !SvOK(sv)) { 0 17174 17174
3902 0 return 1;
3903 }
3904 17174 ▶ if (gql_runtime_vm_sv_to_hv(aTHX_ sv, &defs_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_to_hv(aTHX_ sv, &defs_hv)) { 439 16735 17174
3905 HE *he;
3906 439 IV count = hv_iterinit(defs_hv);
3907 439 ▶ if (count <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count <= 0) { 318 121 439
3908 318 return 1;
3909 }
3910 121 ▶ Newxz(*out_defs, count, gql_runtime_vm_native_arg_def_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(*out_defs, count, gql_runtime_vm_native_arg_def_t); 0 121 121
3911 121 *out_count = count;
3912 121 i = 0;
3913 274 ▶ while ((he = hv_iternext(defs_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(defs_hv))) { 153 121 274
3914 153 SV *value_sv = hv_iterval(defs_hv, he);
3915 153 SV *key_sv = hv_iterkeysv(he);
3916 153 HV *def_hv = NULL;
3917 SV **svp;
3918 153 gql_runtime_vm_native_arg_def_t *def = &(*out_defs)[i++];
3919  
3920 153 ▶ if (key_sv && SvOK(key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (key_sv && SvOK(key_sv)) { 153 0 153
if (key_sv && SvOK(key_sv)) { 153 0 153
3921 STRLEN len;
3922 153 const char *pv = SvPV(key_sv, len);
3923 153 Newxz(def->name, len + 1, char);
3924 153 Copy(pv, def->name, len, char);
3925 153 def->name[len] = '\0';
3926 }
3927  
3928 153 ▶ if (!value_sv || !gql_runtime_vm_sv_to_hv(aTHX_ value_sv, &def_hv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value_sv || !gql_runtime_vm_sv_to_hv(aTHX_ value_sv, &def_hv)) { 153 0 153
if (!value_sv || !gql_runtime_vm_sv_to_hv(aTHX_ value_sv, &def_hv)) { 0 153 153
3929 0 gql_runtime_vm_free_native_arg_defs(aTHX_ *out_defs, *out_count);
3930 0 *out_defs = NULL;
3931 0 *out_count = 0;
3932 0 croak("native VM slot arg_defs hash entry must be a hash reference");
3933 }
3934  
3935 153 svp = hv_fetch(def_hv, "type", 4, 0);
3936 153 ▶ def->type_def_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
def->type_def_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 153 0 153
def->type_def_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 153 0 153
3937  
3938 153 svp = hv_fetch(def_hv, "has_default", 11, 0);
3939 153 ▶ def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 153 0 153
def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 153 0 153
def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 12 141 153
3940  
3941 153 svp = hv_fetch(def_hv, "default_value", 13, 0);
3942 153 ▶ def->default_value_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
def->default_value_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 149 4 153
def->default_value_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 12 137 149
3943 }
3944 121 return 1;
3945 }
3946 16735 ▶ if (!gql_runtime_vm_sv_to_av(aTHX_ sv, &defs_av)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_av(aTHX_ sv, &defs_av)) { 0 16735 16735
3947 0 croak("native VM slot arg_defs must be an array reference or hash reference");
3948 }
3949 16735 *out_count = av_count(defs_av);
3950 16735 ▶ if (*out_count <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (*out_count <= 0) { 14552 2183 16735
3951 14552 *out_count = 0;
3952 14552 return 1;
3953 }
3954 2183 ▶ Newxz(*out_defs, *out_count, gql_runtime_vm_native_arg_def_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(*out_defs, *out_count, gql_runtime_vm_native_arg_def_t); 0 2183 2183
3955 4656 ▶ for (i = 0; i < *out_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < *out_count; i++) { 2473 2183 4656
3956 2473 SV **entry_svp = av_fetch(defs_av, i, 0);
3957 AV *entry_av;
3958 SV **svp;
3959 gql_runtime_vm_native_arg_def_t *def;
3960 2473 ▶ if (!entry_svp || !gql_runtime_vm_sv_to_av(aTHX_ *entry_svp, &entry_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!entry_svp || !gql_runtime_vm_sv_to_av(aTHX_ *entry_svp, &entry_av)) { 2473 0 2473
if (!entry_svp || !gql_runtime_vm_sv_to_av(aTHX_ *entry_svp, &entry_av)) { 0 2473 2473
3961 0 gql_runtime_vm_free_native_arg_defs(aTHX_ *out_defs, *out_count);
3962 0 *out_defs = NULL;
3963 0 *out_count = 0;
3964 0 croak("native VM slot arg_defs entry must be an array reference");
3965 }
3966 2473 def = &(*out_defs)[i];
3967 2473 svp = av_fetch(entry_av, 0, 0);
3968 2473 ▶ if (!svp || !SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) { 2473 0 2473
if (!svp || !SvOK(*svp)) { 0 2473 2473
3969 0 gql_runtime_vm_free_native_arg_defs(aTHX_ *out_defs, *out_count);
3970 0 *out_defs = NULL;
3971 0 *out_count = 0;
3972 0 croak("native VM slot arg_defs entry is missing name");
3973 }
3974 {
3975 STRLEN len;
3976 2473 const char *pv = SvPV(*svp, len);
3977 2473 Newxz(def->name, len + 1, char);
3978 2473 Copy(pv, def->name, len, char);
3979 2473 def->name[len] = '\0';
3980 }
3981 2473 svp = av_fetch(entry_av, 1, 0);
3982 2473 ▶ def->type_def_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
def->type_def_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 2473 0 2473
def->type_def_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 2473 0 2473
3983 2473 svp = av_fetch(entry_av, 2, 0);
3984 2473 ▶ def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2473 0 2473
def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2473 0 2473
def->has_default = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 1393 1080 2473
3985 2473 svp = av_fetch(entry_av, 3, 0);
3986 2473 ▶ def->default_value_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
def->default_value_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 2473 0 2473
def->default_value_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 1393 1080 2473
3987 }
3988 2183 return 1;
3989 }
3990  
3991 static int
3992 118850 gql_runtime_vm_fetch_hv_iv(pTHX_ HV *hv, const char *key, I32 keylen, IV *out)
3993 {
3994 118850 SV **svp = hv_fetch(hv, key, keylen, 0);
3995 118850 ▶ if (!svp || !SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) { 118850 0 118850
if (!svp || !SvOK(*svp)) { 0 118850 118850
3996 0 return 0;
3997 }
3998 118850 *out = SvIV(*svp);
3999 118850 return 1;
4000 }
4001  
4002 static int
4003 26204 gql_runtime_vm_fetch_hv_bool(pTHX_ HV *hv, const char *key, I32 keylen, U8 *out)
4004 {
4005 26204 IV value = 0;
4006 26204 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, key, keylen, &value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, key, keylen, &value)) { 0 26204 26204
4007 0 return 0;
4008 }
4009 26204 *out = value ? 1 : 0;
4010 26204 return 1;
4011 }
4012  
4013 static int
4014 30949 gql_runtime_vm_sv_to_hv(pTHX_ SV *sv, HV **out)
4015 {
4016 30949 ▶ 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) { 30949 0 30949
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) { 30949 0 30949
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) { 30949 0 30949
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV) { 16735 14214 30949
4017 16735 return 0;
4018 }
4019 14214 *out = (HV *)SvRV(sv);
4020 14214 return 1;
4021 }
4022  
4023 static int
4024 44397 gql_runtime_vm_sv_to_av(pTHX_ SV *sv, AV **out)
4025 {
4026 44397 ▶ 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) { 44397 0 44397
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) { 44397 0 44397
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) { 44397 0 44397
if (!sv || !SvOK(sv) || !SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVAV) { 13102 31295 44397
4027 13102 return 0;
4028 }
4029 31295 *out = (AV *)SvRV(sv);
4030 31295 return 1;
4031 }
4032  
4033 static int
4034 16735 gql_runtime_vm_parse_native_slot(pTHX_ SV *sv, gql_runtime_vm_native_slot_t *out)
4035 {
4036 HV *hv;
4037 AV *av;
4038 SV **svp;
4039 16735 ▶ if (gql_runtime_vm_sv_to_av(aTHX_ sv, &av)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_to_av(aTHX_ sv, &av)) { 3633 13102 16735
4040 3633 svp = av_fetch(av, 0, 0);
4041 3633 ▶ if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing field_name");
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing field_name"); 3633 0 3633
if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing field_name"); 0 3633 3633
4042 {
4043 STRLEN len;
4044 3633 const char *pv = SvPV(*svp, len);
4045 3633 Newxz(out->field_name, len + 1, char);
4046 3633 Copy(pv, out->field_name, len, char);
4047 3633 out->field_name[len] = '\0';
4048 3633 out->field_name_len = len;
4049 }
4050 3633 svp = av_fetch(av, 1, 0);
4051 3633 ▶ if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing result_name");
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing result_name"); 3633 0 3633
if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing result_name"); 0 3633 3633
4052 {
4053 STRLEN len;
4054 3633 const char *pv = SvPV(*svp, len);
4055 3633 Newxz(out->result_name, len + 1, char);
4056 3633 Copy(pv, out->result_name, len, char);
4057 3633 out->result_name[len] = '\0';
4058 3633 out->result_name_len = len;
4059 }
4060 3633 svp = av_fetch(av, 2, 0);
4061 3633 ▶ if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing return_type_name");
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing return_type_name"); 3633 0 3633
if (!svp || !SvOK(*svp)) croak("native VM slot entry is missing return_type_name"); 0 3633 3633
4062 {
4063 STRLEN len;
4064 3633 const char *pv = SvPV(*svp, len);
4065 3633 Newxz(out->return_type_name, len + 1, char);
4066 3633 Copy(pv, out->return_type_name, len, char);
4067 3633 out->return_type_name[len] = '\0';
4068 }
4069 3633 svp = av_fetch(av, 3, 0);
4070 3633 ▶ out->schema_slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->schema_slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 3633 0 3633
out->schema_slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 3633 0 3633
4071 3633 svp = av_fetch(av, 4, 0);
4072 3633 ▶ out->resolver_shape_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->resolver_shape_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
out->resolver_shape_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
4073 3633 svp = av_fetch(av, 5, 0);
4074 3633 ▶ out->completion_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->completion_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
out->completion_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
4075 3633 svp = av_fetch(av, 6, 0);
4076 3633 ▶ out->dispatch_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->dispatch_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
out->dispatch_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
4077 3633 svp = av_fetch(av, 7, 0);
4078 3633 ▶ out->return_type_kind_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->return_type_kind_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
out->return_type_kind_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
4079 3633 svp = av_fetch(av, 8, 0);
4080 3633 ▶ out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 3633 0 3633
out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 3633 0 3633
out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 475 3158 3633
4081 3633 svp = av_fetch(av, 9, 0);
4082 3633 ▶ out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 3633 0 3633
out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 3633 0 3633
out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 1 3632 3633
4083 3633 svp = av_fetch(av, 10, 0);
4084 3633 ▶ out->resolver_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->resolver_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
out->resolver_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 3633 0 3633
4085 3633 svp = av_fetch(av, 11, 0);
4086 3633 ▶ gql_runtime_vm_parse_native_arg_defs(aTHX_ (svp ? *svp : NULL), &out->arg_defs, &out->arg_def_count);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_parse_native_arg_defs(aTHX_ (svp ? *svp : NULL), &out->arg_defs, &out->arg_def_count); 3633 0 3633
4087 3633 svp = av_fetch(av, 12, 0);
4088 3633 ▶ out->callback_abi_code = (svp && SvOK(*svp))
Branch: 1 branch
BranchTrueFalseTotal
out->callback_abi_code = (svp && SvOK(*svp)) 3633 0 3633
4089 3633 ? SvIV(*svp)
4090 3633 ▶ : gql_runtime_vm_infer_callback_abi_code(out->resolver_shape_code, out->resolver_mode_code);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_infer_callback_abi_code(out->resolver_shape_code, out->resolver_mode_code); 3633 0 3633
4091 3633 svp = av_fetch(av, 13, 0);
4092 3633 ▶ out->item_non_null = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->item_non_null = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 3633 0 3633
out->item_non_null = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 3633 0 3633
out->item_non_null = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 345 3288 3633
4093 3633 svp = av_fetch(av, 14, 0);
4094 3633 ▶ if (svp && SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) { 3633 0 3633
if (svp && SvOK(*svp)) { 6 3627 3633
4095 STRLEN len;
4096 6 const char *pv = SvPV(*svp, len);
4097 6 Newxz(out->accessor_name, len + 1, char);
4098 6 Copy(pv, out->accessor_name, len, char);
4099 6 out->accessor_name[len] = '\0';
4100 6 out->accessor_name_len = len;
4101 }
4102 3633 return 1;
4103 }
4104 13102 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &hv)) { 0 13102 13102
4105 0 croak("native VM slot entry must be a hash reference");
4106 }
4107 13102 ▶ if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "field_name", 10, &out->field_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "field_name", 10, &out->field_name)) { 0 13102 13102
4108 0 croak("native VM slot entry is missing field_name");
4109 }
4110 13102 ▶ out->field_name_len = out->field_name ? strlen(out->field_name) : 0;
Branch: 1 branch
BranchTrueFalseTotal
out->field_name_len = out->field_name ? strlen(out->field_name) : 0; 13102 0 13102
4111 13102 ▶ if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "result_name", 11, &out->result_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "result_name", 11, &out->result_name)) { 0 13102 13102
4112 0 croak("native VM slot entry is missing result_name");
4113 }
4114 13102 ▶ out->result_name_len = out->result_name ? strlen(out->result_name) : 0;
Branch: 1 branch
BranchTrueFalseTotal
out->result_name_len = out->result_name ? strlen(out->result_name) : 0; 13102 0 13102
4115 13102 ▶ if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "return_type_name", 16, &out->return_type_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "return_type_name", 16, &out->return_type_name)) { 0 13102 13102
4116 0 croak("native VM slot entry is missing return_type_name");
4117 }
4118 13102 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "schema_slot_index", 17, &out->schema_slot_index)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "schema_slot_index", 17, &out->schema_slot_index)) { 0 13102 13102
4119 0 croak("native VM slot entry is missing schema_slot_index");
4120 }
4121 13102 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "resolver_shape_code", 19, &out->resolver_shape_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "resolver_shape_code", 19, &out->resolver_shape_code)) { 0 13102 13102
4122 0 croak("native VM slot entry is missing resolver_shape_code");
4123 }
4124 13102 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "resolver_mode_code", 18, &out->resolver_mode_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "resolver_mode_code", 18, &out->resolver_mode_code)) { 0 13102 13102
4125 0 croak("native VM slot entry is missing resolver_mode_code");
4126 }
4127 13102 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "completion_family_code", 22, &out->completion_family_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "completion_family_code", 22, &out->completion_family_code)) { 0 13102 13102
4128 0 croak("native VM slot entry is missing completion_family_code");
4129 }
4130 13102 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "dispatch_family_code", 20, &out->dispatch_family_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "dispatch_family_code", 20, &out->dispatch_family_code)) { 0 13102 13102
4131 0 croak("native VM slot entry is missing dispatch_family_code");
4132 }
4133 13102 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "return_type_kind_code", 21, &out->return_type_kind_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "return_type_kind_code", 21, &out->return_type_kind_code)) { 0 13102 13102
4134 0 croak("native VM slot entry is missing return_type_kind_code");
4135 }
4136 13102 ▶ if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_args", 8, &out->has_args)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_args", 8, &out->has_args)) { 0 13102 13102
4137 0 croak("native VM slot entry is missing has_args");
4138 }
4139 13102 ▶ if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_directives", 14, &out->has_directives)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_directives", 14, &out->has_directives)) { 0 13102 13102
4140 0 croak("native VM slot entry is missing has_directives");
4141 }
4142 13102 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "callback_abi_code", 17, &out->callback_abi_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "callback_abi_code", 17, &out->callback_abi_code)) { 0 13102 13102
4143 0 out->callback_abi_code = gql_runtime_vm_infer_callback_abi_code(
4144 out->resolver_shape_code,
4145 out->resolver_mode_code
4146 );
4147 }
4148 {
4149 13102 SV **item_nn_svp = hv_fetch(hv, "item_non_null", 13, 0);
4150 13102 ▶ out->item_non_null = (item_nn_svp && SvOK(*item_nn_svp) && SvTRUE(*item_nn_svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->item_non_null = (item_nn_svp && SvOK(*item_nn_svp) && SvTRUE(*item_nn_svp)) ? 1 : 0; 13102 0 13102
out->item_non_null = (item_nn_svp && SvOK(*item_nn_svp) && SvTRUE(*item_nn_svp)) ? 1 : 0; 13102 0 13102
out->item_non_null = (item_nn_svp && SvOK(*item_nn_svp) && SvTRUE(*item_nn_svp)) ? 1 : 0; 2445 10657 13102
4151 }
4152 13102 ▶ if (gql_runtime_vm_fetch_hv_string(aTHX_ hv, "accessor", 8, &out->accessor_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_fetch_hv_string(aTHX_ hv, "accessor", 8, &out->accessor_name)) { 4 13098 13102
4153 4 out->accessor_name_len = strlen(out->accessor_name);
4154 }
4155 13102 svp = hv_fetch(hv, "arg_defs", 8, 0);
4156 13102 ▶ gql_runtime_vm_parse_native_arg_defs(aTHX_ (svp ? *svp : NULL), &out->arg_defs, &out->arg_def_count);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_parse_native_arg_defs(aTHX_ (svp ? *svp : NULL), &out->arg_defs, &out->arg_def_count); 13102 0 13102
4157 13102 return 1;
4158 }
4159  
4160 static void
4161 26609 gql_runtime_vm_clone_native_slot(
4162 pTHX_
4163 const gql_runtime_vm_native_slot_t *src,
4164 gql_runtime_vm_native_slot_t *dst
4165 )
4166 {
4167 26609 Zero(dst, 1, gql_runtime_vm_native_slot_t);
4168 26609 dst->schema_slot_index = src->schema_slot_index;
4169 26609 dst->resolver_shape_code = src->resolver_shape_code;
4170 26609 dst->resolver_mode_code = src->resolver_mode_code;
4171 26609 dst->callback_abi_code = src->callback_abi_code;
4172 26609 dst->completion_family_code = src->completion_family_code;
4173 26609 dst->dispatch_family_code = src->dispatch_family_code;
4174 26609 dst->return_type_kind_code = src->return_type_kind_code;
4175 26609 dst->arg_def_count = src->arg_def_count;
4176 26609 dst->has_args = src->has_args;
4177 26609 dst->has_directives = src->has_directives;
4178 26609 dst->item_non_null = src->item_non_null;
4179 26609 ▶ if (src->field_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->field_name) { 26609 0 26609
4180 26609 ▶ STRLEN len = src->field_name_len ? src->field_name_len : strlen(src->field_name);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN len = src->field_name_len ? src->field_name_len : strlen(src->field_name); 26609 0 26609
4181 26609 Newxz(dst->field_name, len + 1, char);
4182 26609 Copy(src->field_name, dst->field_name, len, char);
4183 26609 dst->field_name[len] = '\0';
4184 26609 dst->field_name_len = len;
4185 }
4186 26609 ▶ if (src->result_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->result_name) { 26609 0 26609
4187 26609 ▶ STRLEN len = src->result_name_len ? src->result_name_len : strlen(src->result_name);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN len = src->result_name_len ? src->result_name_len : strlen(src->result_name); 26609 0 26609
4188 26609 Newxz(dst->result_name, len + 1, char);
4189 26609 Copy(src->result_name, dst->result_name, len, char);
4190 26609 dst->result_name[len] = '\0';
4191 26609 dst->result_name_len = len;
4192 }
4193 26609 ▶ if (src->return_type_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->return_type_name) { 26609 0 26609
4194 26609 STRLEN len = strlen(src->return_type_name);
4195 26609 Newxz(dst->return_type_name, len + 1, char);
4196 26609 Copy(src->return_type_name, dst->return_type_name, len, char);
4197 26609 dst->return_type_name[len] = '\0';
4198 }
4199 26609 ▶ if (src->accessor_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->accessor_name) { 14 26595 26609
4200 28 STRLEN len = src->accessor_name_len
4201 ? src->accessor_name_len
4202 14 ▶ : strlen(src->accessor_name);
Branch: 1 branch
BranchTrueFalseTotal
: strlen(src->accessor_name); 14 0 14
4203 14 Newxz(dst->accessor_name, len + 1, char);
4204 14 Copy(src->accessor_name, dst->accessor_name, len, char);
4205 14 dst->accessor_name[len] = '\0';
4206 14 dst->accessor_name_len = len;
4207 }
4208 26609 ▶ if (src->arg_def_count > 0 && src->arg_defs) {
Branch: 2 branches
BranchTrueFalseTotal
if (src->arg_def_count > 0 && src->arg_defs) { 3414 23195 26609
if (src->arg_def_count > 0 && src->arg_defs) { 3414 0 3414
4209 IV i;
4210 3414 ▶ Newxz(dst->arg_defs, src->arg_def_count, gql_runtime_vm_native_arg_def_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->arg_defs, src->arg_def_count, gql_runtime_vm_native_arg_def_t); 0 3414 3414
4211 8233 ▶ for (i = 0; i < src->arg_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->arg_def_count; i++) { 4819 3414 8233
4212 4819 gql_runtime_vm_native_arg_def_t *src_def = &src->arg_defs[i];
4213 4819 gql_runtime_vm_native_arg_def_t *dst_def = &dst->arg_defs[i];
4214 4819 dst_def->has_default = src_def->has_default;
4215 4819 dst_def->input_type_nonnull_state = src_def->input_type_nonnull_state;
4216 4819 ▶ if (src_def->name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->name) { 4819 0 4819
4217 4819 STRLEN len = strlen(src_def->name);
4218 4819 Newxz(dst_def->name, len + 1, char);
4219 4819 Copy(src_def->name, dst_def->name, len, char);
4220 4819 dst_def->name[len] = '\0';
4221 }
4222 4819 ▶ if (src_def->type_def_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->type_def_sv) { 4819 0 4819
4223 4819 dst_def->type_def_sv = newSVsv(src_def->type_def_sv);
4224 }
4225 4819 ▶ if (src_def->input_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->input_type_sv) { 4417 402 4819
4226 4417 dst_def->input_type_sv = newSVsv(src_def->input_type_sv);
4227 }
4228 4819 ▶ if (src_def->default_value_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->default_value_sv) { 1910 2909 4819
4229 1910 dst_def->default_value_sv = newSVsv(src_def->default_value_sv);
4230 }
4231 4819 ▶ if (src_def->default_native_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->default_native_value) { 1876 2943 4819
4232 1876 dst_def->default_native_value = gql_runtime_vm_native_value_clone(aTHX_ src_def->default_native_value);
4233 }
4234 }
4235 }
4236 26609 }
4237  
4238 static void
4239 1985 gql_runtime_vm_clone_native_op(
4240 pTHX_
4241 const gql_runtime_vm_native_op_t *src,
4242 gql_runtime_vm_native_op_t *dst
4243 )
4244 {
4245 IV i;
4246 1985 Zero(dst, 1, gql_runtime_vm_native_op_t);
4247 1985 *dst = *src;
4248 1985 dst->abstract_child_names = NULL;
4249 1985 dst->abstract_child_indexes = NULL;
4250 1985 dst->args_payload_native = NULL;
4251 1985 dst->directives_payload_native = NULL;
4252 1985 ▶ if (src->abstract_child_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->abstract_child_count > 0) { 83 1902 1985
4253 83 ▶ Newxz(dst->abstract_child_names, src->abstract_child_count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->abstract_child_names, src->abstract_child_count, char *); 0 83 83
4254 83 ▶ Newxz(dst->abstract_child_indexes, src->abstract_child_count, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->abstract_child_indexes, src->abstract_child_count, IV); 0 83 83
4255 232 ▶ for (i = 0; i < src->abstract_child_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->abstract_child_count; i++) { 149 83 232
4256 149 dst->abstract_child_indexes[i] = src->abstract_child_indexes[i];
4257 149 ▶ if (src->abstract_child_names && src->abstract_child_names[i]) {
Branch: 2 branches
BranchTrueFalseTotal
if (src->abstract_child_names && src->abstract_child_names[i]) { 149 0 149
if (src->abstract_child_names && src->abstract_child_names[i]) { 149 0 149
4258 149 STRLEN len = strlen(src->abstract_child_names[i]);
4259 149 Newxz(dst->abstract_child_names[i], len + 1, char);
4260 149 Copy(src->abstract_child_names[i], dst->abstract_child_names[i], len, char);
4261 149 dst->abstract_child_names[i][len] = '\0';
4262 }
4263 }
4264 }
4265 1985 ▶ if (src->args_payload_native) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->args_payload_native) { 249 1736 1985
4266 249 dst->args_payload_native = gql_runtime_vm_native_args_payload_clone(aTHX_ src->args_payload_native);
4267 }
4268 1985 ▶ if (src->directives_payload_native) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->directives_payload_native) { 14 1971 1985
4269 14 dst->directives_payload_native = gql_runtime_vm_native_directives_payload_clone(aTHX_ src->directives_payload_native);
4270 }
4271 1985 ▶ if (src->runtime_directives_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->runtime_directives_sv) { 9 1976 1985
4272 9 dst->runtime_directives_sv = newSVsv(src->runtime_directives_sv);
4273 }
4274 1985 }
4275  
4276 static void
4277 1060 gql_runtime_vm_clone_native_block(
4278 pTHX_
4279 const gql_runtime_vm_native_block_t *src,
4280 gql_runtime_vm_native_block_t *dst
4281 )
4282 {
4283 IV i;
4284 1060 Zero(dst, 1, gql_runtime_vm_native_block_t);
4285 1060 dst->family_code = src->family_code;
4286 1060 dst->slot_count = src->slot_count;
4287 1060 dst->op_count = src->op_count;
4288 1060 ▶ if (src->type_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->type_name) { 1060 0 1060
4289 1060 STRLEN len = strlen(src->type_name);
4290 1060 Newxz(dst->type_name, len + 1, char);
4291 1060 Copy(src->type_name, dst->type_name, len, char);
4292 1060 dst->type_name[len] = '\0';
4293 }
4294 1060 ▶ if (src->slot_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->slot_count > 0) { 1058 2 1060
4295 1058 ▶ Newxz(dst->slots, src->slot_count, gql_runtime_vm_native_slot_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->slots, src->slot_count, gql_runtime_vm_native_slot_t); 0 1058 1058
4296 3043 ▶ for (i = 0; i < src->slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->slot_count; i++) { 1985 1058 3043
4297 1985 gql_runtime_vm_clone_native_slot(aTHX_ &src->slots[i], &dst->slots[i]);
4298 }
4299 }
4300 1060 ▶ if (src->op_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->op_count > 0) { 1058 2 1060
4301 1058 ▶ Newxz(dst->ops, src->op_count, gql_runtime_vm_native_op_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->ops, src->op_count, gql_runtime_vm_native_op_t); 0 1058 1058
4302 3043 ▶ for (i = 0; i < src->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->op_count; i++) { 1985 1058 3043
4303 1985 gql_runtime_vm_clone_native_op(aTHX_ &src->ops[i], &dst->ops[i]);
4304 }
4305 }
4306 1060 }
4307  
4308 static int
4309 2136 gql_runtime_vm_parse_native_op(pTHX_ SV *sv, gql_runtime_vm_native_op_t *out)
4310 {
4311 HV *hv;
4312 AV *av;
4313 HV *children_hv;
4314 HE *he;
4315 SV **svp;
4316 IV idx;
4317 2136 ▶ if (gql_runtime_vm_sv_to_av(aTHX_ sv, &av)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_to_av(aTHX_ sv, &av)) { 2136 0 2136
4318 2136 svp = av_fetch(av, 0, 0);
4319 2136 ▶ out->opcode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->opcode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
out->opcode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
4320 2136 svp = av_fetch(av, 1, 0);
4321 2136 ▶ out->resolve_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->resolve_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
out->resolve_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
4322 2136 svp = av_fetch(av, 2, 0);
4323 2136 ▶ out->complete_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->complete_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
out->complete_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
4324 2136 svp = av_fetch(av, 3, 0);
4325 2136 ▶ out->dispatch_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
out->dispatch_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
out->dispatch_family_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 2136 0 2136
4326 2136 svp = av_fetch(av, 4, 0);
4327 2136 ▶ out->slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 2136 0 2136
out->slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 2136 0 2136
4328 2136 svp = av_fetch(av, 5, 0);
4329 2136 ▶ out->child_block_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->child_block_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 2136 0 2136
out->child_block_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 692 1444 2136
4330 2136 svp = av_fetch(av, 6, 0);
4331 2136 ▶ 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) { 2136 0 2136
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 2136 0 2136
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 2136 0 2136
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 2136 0 2136
4332 2136 children_hv = (HV *)SvRV(*svp);
4333 2136 out->abstract_child_count = hv_iterinit(children_hv);
4334 2136 ▶ if (out->abstract_child_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (out->abstract_child_count > 0) { 96 2040 2136
4335 96 ▶ Newxz(out->abstract_child_names, out->abstract_child_count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->abstract_child_names, out->abstract_child_count, char *); 0 96 96
4336 96 ▶ Newxz(out->abstract_child_indexes, out->abstract_child_count, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->abstract_child_indexes, out->abstract_child_count, IV); 0 96 96
4337 96 idx = 0;
4338 96 hv_iterinit(children_hv);
4339 258 ▶ while ((he = hv_iternext(children_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(children_hv))) { 162 96 258
4340 STRLEN keylen;
4341 162 ▶ const char *key = HePV(he, keylen);
Branch: 1 branch
BranchTrueFalseTotal
const char *key = HePV(he, keylen); 0 162 162
4342 162 SV *val = HeVAL(he);
4343 162 Newxz(out->abstract_child_names[idx], keylen + 1, char);
4344 162 Copy(key, out->abstract_child_names[idx], keylen, char);
4345 162 out->abstract_child_names[idx][keylen] = '\0';
4346 162 ▶ out->abstract_child_indexes[idx] = (val && SvOK(val)) ? SvIV(val) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->abstract_child_indexes[idx] = (val && SvOK(val)) ? SvIV(val) : -1; 162 0 162
out->abstract_child_indexes[idx] = (val && SvOK(val)) ? SvIV(val) : -1; 162 0 162
4347 162 idx++;
4348 }
4349 }
4350 } else {
4351 0 out->abstract_child_count = 0;
4352 0 out->abstract_child_names = NULL;
4353 0 out->abstract_child_indexes = NULL;
4354 }
4355 2136 svp = av_fetch(av, 7, 0);
4356 2136 ▶ out->args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE;
Branch: 2 branches
BranchTrueFalseTotal
out->args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 2136 0 2136
out->args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 2136 0 2136
4357 2136 svp = av_fetch(av, 8, 0);
4358 2136 ▶ out->args_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->args_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 2136 0 2136
out->args_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 451 1685 2136
4359 2136 svp = av_fetch(av, 9, 0);
4360 2136 out->args_payload_native =
4361 2136 ▶ (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
(svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) 12 2124 2136
(svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) 12 0 12
(svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) 12 0 12
4362 12 ? gql_runtime_vm_native_args_payload_from_hv(aTHX_ (HV *)SvRV(*svp))
4363 4260 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 2136 0 2136
4364 2136 svp = av_fetch(av, 10, 0);
4365 2136 ▶ out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2136 0 2136
out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2136 0 2136
out->has_args = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 301 1835 2136
4366 2136 svp = av_fetch(av, 11, 0);
4367 2136 ▶ out->directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE;
Branch: 2 branches
BranchTrueFalseTotal
out->directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 2136 0 2136
out->directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 2136 0 2136
4368 2136 svp = av_fetch(av, 12, 0);
4369 2136 ▶ out->directives_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->directives_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 2136 0 2136
out->directives_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 218 1918 2136
4370 2136 svp = av_fetch(av, 13, 0);
4371 2136 ▶ out->directives_payload_native = (svp && SvOK(*svp))
Branch: 1 branch
BranchTrueFalseTotal
out->directives_payload_native = (svp && SvOK(*svp)) 0 2136 2136
4372 0 ? gql_runtime_vm_native_directives_payload_from_sv(aTHX_ *svp)
4373 4272 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 2136 0 2136
4374 2136 svp = av_fetch(av, 14, 0);
4375 2136 ▶ out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2136 0 2136
out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2136 0 2136
out->has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 14 2122 2136
4376 2136 svp = av_fetch(av, 18, 0);
4377 2136 ▶ out->runtime_directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE;
Branch: 2 branches
BranchTrueFalseTotal
out->runtime_directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 2136 0 2136
out->runtime_directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 2136 0 2136
4378 2136 svp = av_fetch(av, 19, 0);
4379 2136 ▶ out->runtime_directives_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
out->runtime_directives_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 2136 0 2136
out->runtime_directives_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 8 2128 2136
4380 2136 svp = av_fetch(av, 20, 0);
4381 2136 ▶ out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2136 0 2136
out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 2136 0 2136
out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 8 2128 2136
4382 2136 return 1;
4383 }
4384 0 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &hv)) { 0 0 0
4385 0 croak("native VM op entry must be a hash reference");
4386 }
4387 0 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "opcode_code", 11, &out->opcode_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "opcode_code", 11, &out->opcode_code)) { 0 0 0
4388 0 croak("native VM op entry is missing opcode_code");
4389 }
4390 0 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "resolve_code", 12, &out->resolve_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "resolve_code", 12, &out->resolve_code)) { 0 0 0
4391 0 croak("native VM op entry is missing resolve_code");
4392 }
4393 0 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "complete_code", 13, &out->complete_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "complete_code", 13, &out->complete_code)) { 0 0 0
4394 0 croak("native VM op entry is missing complete_code");
4395 }
4396 0 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "dispatch_family_code", 20, &out->dispatch_family_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "dispatch_family_code", 20, &out->dispatch_family_code)) { 0 0 0
4397 0 croak("native VM op entry is missing dispatch_family_code");
4398 }
4399 0 svp = hv_fetch(hv, "slot_index", 10, 0);
4400 0 ▶ out->slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
out->slot_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
4401 0 svp = hv_fetch(hv, "child_block_index", 17, 0);
4402 0 ▶ out->child_block_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->child_block_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
out->child_block_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
4403 0 ▶ if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_args", 8, &out->has_args)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_args", 8, &out->has_args)) { 0 0 0
4404 0 croak("native VM op entry is missing has_args");
4405 }
4406 0 ▶ if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_directives", 14, &out->has_directives)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_bool(aTHX_ hv, "has_directives", 14, &out->has_directives)) { 0 0 0
4407 0 croak("native VM op entry is missing has_directives");
4408 }
4409 0 svp = hv_fetch(hv, "runtime_directives_mode_code", 28, 0);
4410 0 ▶ out->runtime_directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE;
Branch: 2 branches
BranchTrueFalseTotal
out->runtime_directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
out->runtime_directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
4411 0 svp = hv_fetch(hv, "runtime_directives_payload", 26, 0);
4412 0 ▶ out->runtime_directives_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL;
Branch: 2 branches
BranchTrueFalseTotal
out->runtime_directives_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 0 0 0
out->runtime_directives_sv = (svp && SvOK(*svp)) ? newSVsv(*svp) : NULL; 0 0 0
4413 0 svp = hv_fetch(hv, "has_runtime_directives", 22, 0);
4414 0 ▶ out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 0 0 0
out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 0 0 0
out->has_runtime_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 0 0 0
4415 0 svp = hv_fetch(hv, "directives_mode_code", 20, 0);
4416 0 ▶ out->directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE;
Branch: 2 branches
BranchTrueFalseTotal
out->directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
out->directives_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
4417 0 svp = hv_fetch(hv, "abstract_child_block_indexes", 28, 0);
4418 0 ▶ 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) { 0 0 0
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
4419 0 children_hv = (HV *)SvRV(*svp);
4420 0 out->abstract_child_count = hv_iterinit(children_hv);
4421 0 ▶ if (out->abstract_child_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (out->abstract_child_count > 0) { 0 0 0
4422 0 ▶ Newxz(out->abstract_child_names, out->abstract_child_count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->abstract_child_names, out->abstract_child_count, char *); 0 0 0
4423 0 ▶ Newxz(out->abstract_child_indexes, out->abstract_child_count, IV);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->abstract_child_indexes, out->abstract_child_count, IV); 0 0 0
4424 0 idx = 0;
4425 0 hv_iterinit(children_hv);
4426 0 ▶ while ((he = hv_iternext(children_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(children_hv))) { 0 0 0
4427 STRLEN keylen;
4428 0 ▶ const char *key = HePV(he, keylen);
Branch: 1 branch
BranchTrueFalseTotal
const char *key = HePV(he, keylen); 0 0 0
4429 0 SV *val = HeVAL(he);
4430 0 Newxz(out->abstract_child_names[idx], keylen + 1, char);
4431 0 Copy(key, out->abstract_child_names[idx], keylen, char);
4432 0 out->abstract_child_names[idx][keylen] = '\0';
4433 0 ▶ out->abstract_child_indexes[idx] = (val && SvOK(val)) ? SvIV(val) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->abstract_child_indexes[idx] = (val && SvOK(val)) ? SvIV(val) : -1; 0 0 0
out->abstract_child_indexes[idx] = (val && SvOK(val)) ? SvIV(val) : -1; 0 0 0
4434 0 idx++;
4435 }
4436 }
4437 } else {
4438 0 out->abstract_child_count = 0;
4439 0 out->abstract_child_names = NULL;
4440 0 out->abstract_child_indexes = NULL;
4441 }
4442 0 svp = hv_fetch(hv, "args_mode_code", 14, 0);
4443 0 ▶ out->args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE;
Branch: 2 branches
BranchTrueFalseTotal
out->args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
out->args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
4444 0 svp = hv_fetch(hv, "args_payload_index", 18, 0);
4445 0 ▶ out->args_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->args_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
out->args_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
4446 0 svp = hv_fetch(hv, "args_payload", 12, 0);
4447 0 out->args_payload_native =
4448 0 ▶ (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
(svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) 0 0 0
(svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) 0 0 0
(svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) 0 0 0
4449 0 ? gql_runtime_vm_native_args_payload_from_hv(aTHX_ (HV *)SvRV(*svp))
4450 0 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 0 0 0
4451 0 svp = hv_fetch(hv, "directives_payload_index", 24, 0);
4452 0 ▶ out->directives_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1;
Branch: 2 branches
BranchTrueFalseTotal
out->directives_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
out->directives_payload_index = (svp && SvOK(*svp)) ? SvIV(*svp) : -1; 0 0 0
4453 0 svp = hv_fetch(hv, "directives_payload", 18, 0);
4454 0 ▶ out->directives_payload_native = (svp && SvOK(*svp))
Branch: 1 branch
BranchTrueFalseTotal
out->directives_payload_native = (svp && SvOK(*svp)) 0 0 0
4455 0 ? gql_runtime_vm_native_directives_payload_from_sv(aTHX_ *svp)
4456 0 ▶ : NULL;
Branch: 1 branch
BranchTrueFalseTotal
: NULL; 0 0 0
4457 0 return 1;
4458 }
4459  
4460 static void
4461 439 gql_runtime_vm_parse_native_program_payload_catalogs(
4462 pTHX_
4463 HV *program_hv,
4464 gql_runtime_vm_native_program_t *program
4465 )
4466 {
4467 AV *payloads_av;
4468 IV i;
4469 SV **svp;
4470  
4471 439 svp = hv_fetch(program_hv, "args_payloads_compact", 21, 0);
4472 439 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 439 0 439
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 0 439 439
4473 0 svp = hv_fetch(program_hv, "args_payloads", 13, 0);
4474 }
4475 439 ▶ if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 439 0 439
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 439 0 439
4476 439 program->args_payload_count = av_len(payloads_av) + 1;
4477 439 ▶ if (program->args_payload_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->args_payload_count > 0) { 200 239 439
4478 200 ▶ Newxz(program->args_payloads, program->args_payload_count, gql_runtime_vm_native_args_payload_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(program->args_payloads, program->args_payload_count, gql_runtime_vm_native_args_payload_t *); 0 200 200
4479 438 ▶ for (i = 0; i < program->args_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->args_payload_count; i++) { 238 200 438
4480 238 SV **payload_svp = av_fetch(payloads_av, i, 0);
4481 238 ▶ if (!payload_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload_svp) { 0 238 238
4482 0 gql_runtime_vm_native_program_destroy(program);
4483 0 croak("native VM args payload entry %ld is missing", (long)i);
4484 }
4485 238 ▶ if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 238 0 238
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 238 0 238
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 238 0 238
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 238 0 238
4486 238 program->args_payloads[i] =
4487 238 gql_runtime_vm_native_args_payload_from_hv(aTHX_ (HV *)SvRV(*payload_svp));
4488 }
4489 }
4490 }
4491 }
4492  
4493 439 svp = hv_fetch(program_hv, "directives_payloads_compact", 27, 0);
4494 439 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 439 0 439
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 0 439 439
4495 0 svp = hv_fetch(program_hv, "directives_payloads", 19, 0);
4496 }
4497 439 ▶ if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 439 0 439
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 439 0 439
4498 439 program->directives_payload_count = av_len(payloads_av) + 1;
4499 439 ▶ if (program->directives_payload_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->directives_payload_count > 0) { 11 428 439
4500 11 ▶ Newxz(program->directives_payloads, program->directives_payload_count, gql_runtime_vm_native_directives_payload_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(program->directives_payloads, program->directives_payload_count, gql_runtime_vm_native_directives_payload_t *); 0 11 11
4501 23 ▶ for (i = 0; i < program->directives_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->directives_payload_count; i++) { 12 11 23
4502 12 SV **payload_svp = av_fetch(payloads_av, i, 0);
4503 12 ▶ if (!payload_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload_svp) { 0 12 12
4504 0 gql_runtime_vm_native_program_destroy(program);
4505 0 croak("native VM directives payload entry %ld is missing", (long)i);
4506 }
4507 12 ▶ if (*payload_svp && SvOK(*payload_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (*payload_svp && SvOK(*payload_svp)) { 12 0 12
if (*payload_svp && SvOK(*payload_svp)) { 12 0 12
4508 12 program->directives_payloads[i] =
4509 12 gql_runtime_vm_native_directives_payload_from_sv(aTHX_ *payload_svp);
4510 }
4511 }
4512 }
4513 }
4514 439 }
4515  
4516 static void
4517 27 gql_runtime_vm_free_native_payload_catalogs(
4518 pTHX_
4519 gql_runtime_vm_native_args_payload_t **args_payloads,
4520 IV args_payload_count,
4521 gql_runtime_vm_native_directives_payload_t **directives_payloads,
4522 IV directives_payload_count
4523 )
4524 {
4525 IV i;
4526 27 ▶ if (args_payloads) {
Branch: 1 branch
BranchTrueFalseTotal
if (args_payloads) { 4 23 27
4527 8 ▶ for (i = 0; i < args_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < args_payload_count; i++) { 4 4 8
4528 4 gql_runtime_vm_native_args_payload_destroy(aTHX_ args_payloads[i]);
4529 }
4530 }
4531 27 ▶ if (directives_payloads) {
Branch: 1 branch
BranchTrueFalseTotal
if (directives_payloads) { 0 27 27
4532 0 ▶ for (i = 0; i < directives_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < directives_payload_count; i++) { 0 0 0
4533 0 gql_runtime_vm_native_directives_payload_destroy(aTHX_ directives_payloads[i]);
4534 }
4535 }
4536 27 Safefree(args_payloads);
4537 27 Safefree(directives_payloads);
4538 27 }
4539  
4540 static void
4541 27 gql_runtime_vm_parse_native_payload_catalogs(
4542 pTHX_
4543 HV *program_hv,
4544 gql_runtime_vm_native_args_payload_t ***args_payloads_out,
4545 IV *args_payload_count_out,
4546 gql_runtime_vm_native_directives_payload_t ***directives_payloads_out,
4547 IV *directives_payload_count_out
4548 )
4549 {
4550 AV *payloads_av;
4551 IV i;
4552 SV **svp;
4553  
4554 27 *args_payloads_out = NULL;
4555 27 *args_payload_count_out = 0;
4556 27 *directives_payloads_out = NULL;
4557 27 *directives_payload_count_out = 0;
4558  
4559 27 svp = hv_fetch(program_hv, "args_payloads_compact", 21, 0);
4560 27 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 27 0 27
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 0 27 27
4561 0 svp = hv_fetch(program_hv, "args_payloads", 13, 0);
4562 }
4563 27 ▶ if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 27 0 27
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 27 0 27
4564 27 *args_payload_count_out = av_len(payloads_av) + 1;
4565 27 ▶ if (*args_payload_count_out > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (*args_payload_count_out > 0) { 4 23 27
4566 4 ▶ Newxz(*args_payloads_out, *args_payload_count_out, gql_runtime_vm_native_args_payload_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(*args_payloads_out, *args_payload_count_out, gql_runtime_vm_native_args_payload_t *); 0 4 4
4567 8 ▶ for (i = 0; i < *args_payload_count_out; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < *args_payload_count_out; i++) { 4 4 8
4568 4 SV **payload_svp = av_fetch(payloads_av, i, 0);
4569 4 ▶ if (!payload_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload_svp) { 0 4 4
4570 0 gql_runtime_vm_free_native_payload_catalogs(
4571 aTHX_ *args_payloads_out,
4572 *args_payload_count_out,
4573 *directives_payloads_out,
4574 *directives_payload_count_out
4575 );
4576 0 croak("native VM args payload entry %ld is missing", (long)i);
4577 }
4578 4 ▶ if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 4 0 4
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 4 0 4
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 4 0 4
if (*payload_svp && SvOK(*payload_svp) && SvROK(*payload_svp) && SvTYPE(SvRV(*payload_svp)) == SVt_PVHV) { 4 0 4
4579 4 (*args_payloads_out)[i] =
4580 4 gql_runtime_vm_native_args_payload_from_hv(aTHX_ (HV *)SvRV(*payload_svp));
4581 }
4582 }
4583 }
4584 }
4585  
4586 27 svp = hv_fetch(program_hv, "directives_payloads_compact", 27, 0);
4587 27 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 27 0 27
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 0 27 27
4588 0 svp = hv_fetch(program_hv, "directives_payloads", 19, 0);
4589 }
4590 27 ▶ if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 27 0 27
if (svp && gql_runtime_vm_sv_to_av(aTHX_ *svp, &payloads_av)) { 27 0 27
4591 27 *directives_payload_count_out = av_len(payloads_av) + 1;
4592 27 ▶ if (*directives_payload_count_out > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (*directives_payload_count_out > 0) { 0 27 27
4593 0 ▶ Newxz(*directives_payloads_out, *directives_payload_count_out, gql_runtime_vm_native_directives_payload_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(*directives_payloads_out, *directives_payload_count_out, gql_runtime_vm_native_directives_payload_t *); 0 0 0
4594 0 ▶ for (i = 0; i < *directives_payload_count_out; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < *directives_payload_count_out; i++) { 0 0 0
4595 0 SV **payload_svp = av_fetch(payloads_av, i, 0);
4596 0 ▶ if (!payload_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload_svp) { 0 0 0
4597 0 gql_runtime_vm_free_native_payload_catalogs(
4598 aTHX_ *args_payloads_out,
4599 *args_payload_count_out,
4600 *directives_payloads_out,
4601 *directives_payload_count_out
4602 );
4603 0 croak("native VM directives payload entry %ld is missing", (long)i);
4604 }
4605 0 ▶ if (*payload_svp && SvOK(*payload_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (*payload_svp && SvOK(*payload_svp)) { 0 0 0
if (*payload_svp && SvOK(*payload_svp)) { 0 0 0
4606 0 (*directives_payloads_out)[i] =
4607 0 gql_runtime_vm_native_directives_payload_from_sv(aTHX_ *payload_svp);
4608 }
4609 }
4610 }
4611 }
4612 27 }
4613  
4614 static int
4615 1156 gql_runtime_vm_parse_native_block(pTHX_ SV *sv, gql_runtime_vm_native_block_t *out)
4616 {
4617 HV *hv;
4618 AV *av;
4619 AV *slots_av;
4620 AV *ops_av;
4621 IV i;
4622 SV **svp;
4623 1156 ▶ if (gql_runtime_vm_sv_to_av(aTHX_ sv, &av)) {
Branch: 1 branch
BranchTrueFalseTotal
if (gql_runtime_vm_sv_to_av(aTHX_ sv, &av)) { 1156 0 1156
4624 /* index 0 is the block name; the native block keeps only type_name. */
4625 1156 SV **type_svp = av_fetch(av, 1, 0);
4626 1156 SV **family_svp = av_fetch(av, 2, 0);
4627 1156 SV **slots_svp = av_fetch(av, 3, 0);
4628 1156 SV **ops_svp = av_fetch(av, 4, 0);
4629 1156 ▶ if (!family_svp || !SvOK(*family_svp)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!family_svp || !SvOK(*family_svp)) return 0; 1156 0 1156
if (!family_svp || !SvOK(*family_svp)) return 0; 0 1156 1156
4630 1156 ▶ if (!type_svp || !SvOK(*type_svp)) croak("native VM block entry is missing type_name");
Branch: 2 branches
BranchTrueFalseTotal
if (!type_svp || !SvOK(*type_svp)) croak("native VM block entry is missing type_name"); 1156 0 1156
if (!type_svp || !SvOK(*type_svp)) croak("native VM block entry is missing type_name"); 0 1156 1156
4631 1156 out->family_code = SvIV(*family_svp);
4632 {
4633 STRLEN len;
4634 1156 const char *pv = SvPV(*type_svp, len);
4635 1156 Newxz(out->type_name, len + 1, char);
4636 1156 Copy(pv, out->type_name, len, char);
4637 1156 out->type_name[len] = '\0';
4638 }
4639 1156 ▶ if (!slots_svp || !gql_runtime_vm_sv_to_av(aTHX_ *slots_svp, &slots_av)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!slots_svp || !gql_runtime_vm_sv_to_av(aTHX_ *slots_svp, &slots_av)) return 0; 1156 0 1156
if (!slots_svp || !gql_runtime_vm_sv_to_av(aTHX_ *slots_svp, &slots_av)) return 0; 0 1156 1156
4640 1156 ▶ if (!ops_svp || !gql_runtime_vm_sv_to_av(aTHX_ *ops_svp, &ops_av)) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!ops_svp || !gql_runtime_vm_sv_to_av(aTHX_ *ops_svp, &ops_av)) return 0; 1156 0 1156
if (!ops_svp || !gql_runtime_vm_sv_to_av(aTHX_ *ops_svp, &ops_av)) return 0; 0 1156 1156
4641 1156 out->slot_count = av_count(slots_av);
4642 1156 out->op_count = av_count(ops_av);
4643 1156 out->slots = NULL;
4644 1156 out->ops = NULL;
4645 1156 ▶ if (out->slot_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (out->slot_count > 0) { 1154 2 1156
4646 1154 ▶ Newxz(out->slots, out->slot_count, gql_runtime_vm_native_slot_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->slots, out->slot_count, gql_runtime_vm_native_slot_t); 0 1154 1154
4647 3290 ▶ for (i = 0; i < out->slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < out->slot_count; i++) { 2136 1154 3290
4648 2136 SV **slot_svp = av_fetch(slots_av, i, 0);
4649 2136 ▶ if (!slot_svp || !gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &out->slots[i])) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!slot_svp || !gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &out->slots[i])) return 0; 2136 0 2136
if (!slot_svp || !gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &out->slots[i])) return 0; 0 2136 2136
4650 }
4651 }
4652 1156 ▶ if (out->op_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (out->op_count > 0) { 1154 2 1156
4653 1154 ▶ Newxz(out->ops, out->op_count, gql_runtime_vm_native_op_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->ops, out->op_count, gql_runtime_vm_native_op_t); 0 1154 1154
4654 3290 ▶ for (i = 0; i < out->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < out->op_count; i++) { 2136 1154 3290
4655 2136 SV **op_svp = av_fetch(ops_av, i, 0);
4656 2136 ▶ if (!op_svp || !gql_runtime_vm_parse_native_op(aTHX_ *op_svp, &out->ops[i])) return 0;
Branch: 2 branches
BranchTrueFalseTotal
if (!op_svp || !gql_runtime_vm_parse_native_op(aTHX_ *op_svp, &out->ops[i])) return 0; 2136 0 2136
if (!op_svp || !gql_runtime_vm_parse_native_op(aTHX_ *op_svp, &out->ops[i])) return 0; 0 2136 2136
4657 }
4658 }
4659 1156 return 1;
4660 }
4661 0 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &hv)) { 0 0 0
4662 0 return 0;
4663 }
4664 0 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "family_code", 11, &out->family_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ hv, "family_code", 11, &out->family_code)) { 0 0 0
4665 0 return 0;
4666 }
4667 0 ▶ if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "type_name", 9, &out->type_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_string(aTHX_ hv, "type_name", 9, &out->type_name)) { 0 0 0
4668 0 croak("native VM block entry is missing type_name");
4669 }
4670 0 svp = hv_fetch(hv, "slots", 5, 0);
4671 0 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &slots_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &slots_av)) { 0 0 0
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &slots_av)) { 0 0 0
4672 0 return 0;
4673 }
4674 0 svp = hv_fetch(hv, "ops", 3, 0);
4675 0 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &ops_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &ops_av)) { 0 0 0
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &ops_av)) { 0 0 0
4676 0 return 0;
4677 }
4678 0 out->slot_count = av_count(slots_av);
4679 0 out->op_count = av_count(ops_av);
4680 0 out->slots = NULL;
4681 0 out->ops = NULL;
4682 0 ▶ if (out->slot_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (out->slot_count > 0) { 0 0 0
4683 0 ▶ Newxz(out->slots, out->slot_count, gql_runtime_vm_native_slot_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->slots, out->slot_count, gql_runtime_vm_native_slot_t); 0 0 0
4684 0 ▶ for (i = 0; i < out->slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < out->slot_count; i++) { 0 0 0
4685 0 SV **slot_svp = av_fetch(slots_av, i, 0);
4686 0 ▶ if (!slot_svp || !gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &out->slots[i])) {
Branch: 2 branches
BranchTrueFalseTotal
if (!slot_svp || !gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &out->slots[i])) { 0 0 0
if (!slot_svp || !gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &out->slots[i])) { 0 0 0
4687 0 return 0;
4688 }
4689 }
4690 }
4691 0 ▶ if (out->op_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (out->op_count > 0) { 0 0 0
4692 0 ▶ Newxz(out->ops, out->op_count, gql_runtime_vm_native_op_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(out->ops, out->op_count, gql_runtime_vm_native_op_t); 0 0 0
4693 0 ▶ for (i = 0; i < out->op_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < out->op_count; i++) { 0 0 0
4694 0 SV **op_svp = av_fetch(ops_av, i, 0);
4695 0 ▶ if (!op_svp || !gql_runtime_vm_parse_native_op(aTHX_ *op_svp, &out->ops[i])) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op_svp || !gql_runtime_vm_parse_native_op(aTHX_ *op_svp, &out->ops[i])) { 0 0 0
if (!op_svp || !gql_runtime_vm_parse_native_op(aTHX_ *op_svp, &out->ops[i])) { 0 0 0
4696 0 return 0;
4697 }
4698 }
4699 }
4700 0 return 1;
4701 }
4702  
4703 static gql_runtime_vm_native_bundle_t *
4704 27 gql_runtime_vm_native_bundle_from_runtime_and_program_sv(pTHX_ SV *runtime_sv, SV *program_sv)
4705 {
4706 HV *runtime_hv;
4707 HV *program_hv;
4708 AV *runtime_slots_av;
4709 AV *blocks_av;
4710 27 gql_runtime_vm_native_args_payload_t **args_payloads = NULL;
4711 27 gql_runtime_vm_native_directives_payload_t **directives_payloads = NULL;
4712 27 IV args_payload_count = 0;
4713 27 IV directives_payload_count = 0;
4714 IV i;
4715 IV j;
4716 SV **svp;
4717 gql_runtime_vm_native_bundle_t *bundle;
4718  
4719 27 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ runtime_sv, &runtime_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ runtime_sv, &runtime_hv)) { 0 27 27
4720 0 croak("native VM runtime descriptor must be a hash reference");
4721 }
4722 27 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ program_sv, &program_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ program_sv, &program_hv)) { 0 27 27
4723 0 croak("native VM program descriptor must be a hash reference");
4724 }
4725  
4726 27 Newxz(bundle, 1, gql_runtime_vm_native_bundle_t);
4727  
4728 27 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "operation_type_code", 19, &bundle->operation_type_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "operation_type_code", 19, &bundle->operation_type_code)) { 0 27 27
4729 0 gql_runtime_vm_native_bundle_destroy(bundle);
4730 0 croak("native VM program descriptor is missing operation_type_code");
4731 }
4732 27 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "root_block_index", 16, &bundle->root_block_index)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "root_block_index", 16, &bundle->root_block_index)) { 0 27 27
4733 0 gql_runtime_vm_native_bundle_destroy(bundle);
4734 0 croak("native VM program descriptor is missing root_block_index");
4735 }
4736  
4737 27 gql_runtime_vm_parse_native_payload_catalogs(
4738 aTHX_
4739 program_hv,
4740 &args_payloads,
4741 &args_payload_count,
4742 &directives_payloads,
4743 &directives_payload_count
4744 );
4745  
4746 27 svp = hv_fetch(runtime_hv, "slot_catalog_exec", 17, 0);
4747 27 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) { 0 27 27
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) { 0 0 0
4748 27 svp = hv_fetch(runtime_hv, "slot_catalog_compact", 20, 0);
4749 }
4750 27 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) { 27 0 27
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) { 0 27 27
4751 0 svp = hv_fetch(runtime_hv, "slot_catalog", 12, 0);
4752 }
4753 27 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) { 27 0 27
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &runtime_slots_av)) { 0 27 27
4754 0 gql_runtime_vm_native_bundle_destroy(bundle);
4755 0 croak("native VM runtime descriptor is missing slot_catalog");
4756 }
4757 27 bundle->runtime_slot_count = av_count(runtime_slots_av);
4758 27 ▶ if (bundle->runtime_slot_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->runtime_slot_count > 0) { 27 0 27
4759 27 bundle->owns_runtime_slots = 1;
4760 27 ▶ Newxz(bundle->runtime_slots, bundle->runtime_slot_count, gql_runtime_vm_native_slot_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(bundle->runtime_slots, bundle->runtime_slot_count, gql_runtime_vm_native_slot_t); 0 27 27
4761 1524 ▶ for (i = 0; i < bundle->runtime_slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bundle->runtime_slot_count; i++) { 1497 27 1524
4762 1497 SV **slot_svp = av_fetch(runtime_slots_av, i, 0);
4763 1497 ▶ if (!slot_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!slot_svp) { 0 1497 1497
4764 0 gql_runtime_vm_native_bundle_destroy(bundle);
4765 0 croak("native VM runtime slot entry %ld is missing", (long)i);
4766 }
4767 1497 ▶ if (!gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &bundle->runtime_slots[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_parse_native_slot(aTHX_ *slot_svp, &bundle->runtime_slots[i])) { 0 1497 1497
4768 0 gql_runtime_vm_native_bundle_destroy(bundle);
4769 0 croak("native VM runtime slot entry %ld is invalid", (long)i);
4770 }
4771 }
4772 }
4773  
4774 27 svp = hv_fetch(program_hv, "blocks_compact", 14, 0);
4775 27 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 27 0 27
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 27 27
4776 0 svp = hv_fetch(program_hv, "blocks", 6, 0);
4777 }
4778 27 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 27 0 27
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 27 27
4779 0 gql_runtime_vm_free_native_payload_catalogs(
4780 aTHX_ args_payloads,
4781 args_payload_count,
4782 directives_payloads,
4783 directives_payload_count
4784 );
4785 0 gql_runtime_vm_native_bundle_destroy(bundle);
4786 0 croak("native VM program descriptor is missing blocks");
4787 }
4788 27 bundle->block_count = av_count(blocks_av);
4789 27 ▶ if (bundle->block_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (bundle->block_count > 0) { 27 0 27
4790 27 bundle->owns_blocks = 1;
4791 27 ▶ Newxz(bundle->blocks, bundle->block_count, gql_runtime_vm_native_block_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(bundle->blocks, bundle->block_count, gql_runtime_vm_native_block_t); 0 27 27
4792 78 ▶ for (i = 0; i < bundle->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bundle->block_count; i++) { 51 27 78
4793 51 SV **block_svp = av_fetch(blocks_av, i, 0);
4794 51 ▶ if (!block_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block_svp) { 0 51 51
4795 0 gql_runtime_vm_free_native_payload_catalogs(
4796 aTHX_ args_payloads,
4797 args_payload_count,
4798 directives_payloads,
4799 directives_payload_count
4800 );
4801 0 gql_runtime_vm_native_bundle_destroy(bundle);
4802 0 croak("native VM block entry %ld is missing", (long)i);
4803 }
4804 51 ▶ if (!gql_runtime_vm_parse_native_block(aTHX_ *block_svp, &bundle->blocks[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_parse_native_block(aTHX_ *block_svp, &bundle->blocks[i])) { 0 51 51
4805 0 gql_runtime_vm_free_native_payload_catalogs(
4806 aTHX_ args_payloads,
4807 args_payload_count,
4808 directives_payloads,
4809 directives_payload_count
4810 );
4811 0 gql_runtime_vm_native_bundle_destroy(bundle);
4812 0 croak("native VM block entry %ld is invalid", (long)i);
4813 }
4814 136 ▶ for (j = 0; j < bundle->blocks[i].op_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < bundle->blocks[i].op_count; j++) { 85 51 136
4815 85 gql_runtime_vm_native_op_t *op = &bundle->blocks[i].ops[j];
4816 85 ▶ if (!op->args_payload_native && op->args_payload_index >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op->args_payload_native && op->args_payload_index >= 0) { 79 6 85
if (!op->args_payload_native && op->args_payload_index >= 0) { 0 79 79
4817 0 ▶ if (op->args_payload_index >= args_payload_count ||
Branch: 1 branch
BranchTrueFalseTotal
if (op->args_payload_index >= args_payload_count || 0 0 0
4818 0 ▶ !args_payloads ||
Branch: 1 branch
BranchTrueFalseTotal
!args_payloads || 0 0 0
4819 0 ▶ !args_payloads[op->args_payload_index]) {
Branch: 1 branch
BranchTrueFalseTotal
!args_payloads[op->args_payload_index]) { 0 0 0
4820 0 gql_runtime_vm_free_native_payload_catalogs(
4821 aTHX_ args_payloads,
4822 args_payload_count,
4823 directives_payloads,
4824 directives_payload_count
4825 );
4826 0 gql_runtime_vm_native_bundle_destroy(bundle);
4827 0 croak("native VM args payload index %ld is invalid", (long)op->args_payload_index);
4828 }
4829 0 op->args_payload_native =
4830 0 gql_runtime_vm_native_args_payload_clone(aTHX_ args_payloads[op->args_payload_index]);
4831 }
4832 85 ▶ if (!op->directives_payload_native && op->directives_payload_index >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op->directives_payload_native && op->directives_payload_index >= 0) { 85 0 85
if (!op->directives_payload_native && op->directives_payload_index >= 0) { 0 85 85
4833 0 ▶ if (op->directives_payload_index >= directives_payload_count ||
Branch: 1 branch
BranchTrueFalseTotal
if (op->directives_payload_index >= directives_payload_count || 0 0 0
4834 0 ▶ !directives_payloads ||
Branch: 1 branch
BranchTrueFalseTotal
!directives_payloads || 0 0 0
4835 0 ▶ !directives_payloads[op->directives_payload_index]) {
Branch: 1 branch
BranchTrueFalseTotal
!directives_payloads[op->directives_payload_index]) { 0 0 0
4836 0 gql_runtime_vm_free_native_payload_catalogs(
4837 aTHX_ args_payloads,
4838 args_payload_count,
4839 directives_payloads,
4840 directives_payload_count
4841 );
4842 0 gql_runtime_vm_native_bundle_destroy(bundle);
4843 0 croak("native VM directives payload index %ld is invalid", (long)op->directives_payload_index);
4844 }
4845 0 op->directives_payload_native =
4846 0 gql_runtime_vm_native_directives_payload_clone(aTHX_ directives_payloads[op->directives_payload_index]);
4847 }
4848 }
4849 }
4850 }
4851  
4852 27 gql_runtime_vm_free_native_payload_catalogs(
4853 aTHX_ args_payloads,
4854 args_payload_count,
4855 directives_payloads,
4856 directives_payload_count
4857 );
4858  
4859 27 return bundle;
4860 }
4861  
4862 static gql_runtime_vm_native_program_t *
4863 3115 gql_runtime_vm_native_program_from_sv(pTHX_ SV *sv)
4864 {
4865 HV *program_hv;
4866 AV *blocks_av;
4867 IV i;
4868 IV j;
4869 SV **svp;
4870 gql_runtime_vm_native_program_t *program;
4871  
4872 3115 ▶ if (sv && SvROK(sv) && sv_derived_from(sv, "GraphQL::Houtou::Runtime::NativeProgram")) {
Branch: 3 branches
BranchTrueFalseTotal
if (sv && SvROK(sv) && sv_derived_from(sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 3115 0 3115
if (sv && SvROK(sv) && sv_derived_from(sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 3115 0 3115
if (sv && SvROK(sv) && sv_derived_from(sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 2676 439 3115
4873 2676 gql_runtime_vm_native_program_t *existing =
4874 2676 INT2PTR(gql_runtime_vm_native_program_t *, SvUV(SvRV(sv)));
4875 2676 ▶ if (!existing) {
Branch: 1 branch
BranchTrueFalseTotal
if (!existing) { 0 2676 2676
4876 0 croak("native VM program handle is no longer valid");
4877 }
4878 2676 return existing;
4879 }
4880  
4881 439 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &program_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &program_hv)) { 0 439 439
4882 0 croak("native VM program descriptor must be a hash reference");
4883 }
4884  
4885 439 Newxz(program, 1, gql_runtime_vm_native_program_t);
4886 439 svp = hv_fetch(program_hv, "version", 7, 0);
4887 439 ▶ program->version = (svp && SvOK(*svp)) ? SvIV(*svp) : 1;
Branch: 2 branches
BranchTrueFalseTotal
program->version = (svp && SvOK(*svp)) ? SvIV(*svp) : 1; 439 0 439
program->version = (svp && SvOK(*svp)) ? SvIV(*svp) : 1; 439 0 439
4888 439 svp = hv_fetch(program_hv, "operation_name", 14, 0);
4889 439 ▶ if (svp && SvOK(*svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) { 439 0 439
if (svp && SvOK(*svp)) { 130 309 439
4890 STRLEN len;
4891 130 const char *pv = SvPV(*svp, len);
4892 130 Newxz(program->operation_name, len + 1, char);
4893 130 Copy(pv, program->operation_name, len, char);
4894 130 program->operation_name[len] = '\0';
4895 }
4896 439 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "operation_type_code", 19, &program->operation_type_code)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "operation_type_code", 19, &program->operation_type_code)) { 0 439 439
4897 0 gql_runtime_vm_native_program_destroy(program);
4898 0 croak("native VM program descriptor is missing operation_type_code");
4899 }
4900 439 ▶ if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "root_block_index", 16, &program->root_block_index)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_fetch_hv_iv(aTHX_ program_hv, "root_block_index", 16, &program->root_block_index)) { 0 439 439
4901 0 gql_runtime_vm_native_program_destroy(program);
4902 0 croak("native VM program descriptor is missing root_block_index");
4903 }
4904 439 svp = hv_fetch(program_hv, "variable_defs", 13, 0);
4905 439 ▶ gql_runtime_vm_parse_native_arg_defs(aTHX_ (svp ? *svp : NULL), &program->variable_defs, &program->variable_def_count);
Branch: 1 branch
BranchTrueFalseTotal
gql_runtime_vm_parse_native_arg_defs(aTHX_ (svp ? *svp : NULL), &program->variable_defs, &program->variable_def_count); 439 0 439
4906  
4907 439 gql_runtime_vm_parse_native_program_payload_catalogs(aTHX_ program_hv, program);
4908  
4909 439 svp = hv_fetch(program_hv, "blocks_compact", 14, 0);
4910 439 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 439 0 439
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 439 439
4911 0 svp = hv_fetch(program_hv, "blocks", 6, 0);
4912 }
4913 439 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 439 0 439
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 439 439
4914 0 gql_runtime_vm_native_program_destroy(program);
4915 0 croak("native VM program descriptor is missing blocks");
4916 }
4917  
4918 439 program->block_count = av_count(blocks_av);
4919 439 ▶ if (program->block_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->block_count > 0) { 439 0 439
4920 439 ▶ Newxz(program->blocks, program->block_count, gql_runtime_vm_native_block_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(program->blocks, program->block_count, gql_runtime_vm_native_block_t); 0 439 439
4921 1544 ▶ for (i = 0; i < program->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->block_count; i++) { 1105 439 1544
4922 1105 SV **block_svp = av_fetch(blocks_av, i, 0);
4923 1105 ▶ if (!block_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!block_svp) { 0 1105 1105
4924 0 gql_runtime_vm_native_program_destroy(program);
4925 0 croak("native VM block entry %ld is missing", (long)i);
4926 }
4927 1105 ▶ if (!gql_runtime_vm_parse_native_block(aTHX_ *block_svp, &program->blocks[i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_parse_native_block(aTHX_ *block_svp, &program->blocks[i])) { 0 1105 1105
4928 0 gql_runtime_vm_native_program_destroy(program);
4929 0 croak("native VM block entry %ld is invalid", (long)i);
4930 }
4931 3156 ▶ for (j = 0; j < program->blocks[i].op_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < program->blocks[i].op_count; j++) { 2051 1105 3156
4932 2051 gql_runtime_vm_native_op_t *op = &program->blocks[i].ops[j];
4933 2051 ▶ if (!op->args_payload_native && op->args_payload_index >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op->args_payload_native && op->args_payload_index >= 0) { 2045 6 2051
if (!op->args_payload_native && op->args_payload_index >= 0) { 247 1798 2045
4934 247 ▶ if (op->args_payload_index >= program->args_payload_count ||
Branch: 1 branch
BranchTrueFalseTotal
if (op->args_payload_index >= program->args_payload_count || 247 0 247
4935 247 ▶ !program->args_payloads ||
Branch: 1 branch
BranchTrueFalseTotal
!program->args_payloads || 247 0 247
4936 247 ▶ !program->args_payloads[op->args_payload_index]) {
Branch: 1 branch
BranchTrueFalseTotal
!program->args_payloads[op->args_payload_index]) { 0 247 247
4937 0 gql_runtime_vm_native_program_destroy(program);
4938 0 croak("native VM args payload index %ld is invalid", (long)op->args_payload_index);
4939 }
4940 247 op->args_payload_native =
4941 247 gql_runtime_vm_native_args_payload_clone(aTHX_ program->args_payloads[op->args_payload_index]);
4942 }
4943 2051 ▶ if (!op->directives_payload_native && op->directives_payload_index >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op->directives_payload_native && op->directives_payload_index >= 0) { 2051 0 2051
if (!op->directives_payload_native && op->directives_payload_index >= 0) { 14 2037 2051
4944 14 ▶ if (op->directives_payload_index >= program->directives_payload_count ||
Branch: 1 branch
BranchTrueFalseTotal
if (op->directives_payload_index >= program->directives_payload_count || 14 0 14
4945 14 ▶ !program->directives_payloads ||
Branch: 1 branch
BranchTrueFalseTotal
!program->directives_payloads || 14 0 14
4946 14 ▶ !program->directives_payloads[op->directives_payload_index]) {
Branch: 1 branch
BranchTrueFalseTotal
!program->directives_payloads[op->directives_payload_index]) { 0 14 14
4947 0 gql_runtime_vm_native_program_destroy(program);
4948 0 croak("native VM directives payload index %ld is invalid", (long)op->directives_payload_index);
4949 }
4950 14 op->directives_payload_native =
4951 14 gql_runtime_vm_native_directives_payload_clone(aTHX_ program->directives_payloads[op->directives_payload_index]);
4952 }
4953 }
4954 }
4955 }
4956  
4957 /* Resolve variable names in executable payloads once. The descriptor
4958 * remains name-bearing for round trips, while request execution can use
4959 * the compact variable definition index. */
4960 1544 ▶ for (i = 0; i < program->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->block_count; i++) { 1105 439 1544
4961 1105 gql_runtime_vm_native_block_t *block = &program->blocks[i];
4962 3156 ▶ for (j = 0; j < block->op_count; j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < block->op_count; j++) { 2051 1105 3156
4963 2051 gql_runtime_vm_native_op_t *op = &block->ops[j];
4964 IV k;
4965 2051 ▶ if (op->args_payload_native) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->args_payload_native) { 253 1798 2051
4966 515 ▶ for (k = 0; k < op->args_payload_native->count; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < op->args_payload_native->count; k++) { 262 253 515
4967 262 gql_runtime_vm_bind_dynamic_value_variables(
4968 262 op->args_payload_native->values
4969 262 ? op->args_payload_native->values[k]
4970 : NULL,
4971 262 ▶ program->variable_defs,
Branch: 1 branch
BranchTrueFalseTotal
program->variable_defs, 262 0 262
4972 program->variable_def_count
4973 );
4974 }
4975 }
4976 2051 ▶ if (op->directives_payload_native) {
Branch: 1 branch
BranchTrueFalseTotal
if (op->directives_payload_native) { 14 2037 2051
4977 28 ▶ for (k = 0; k < op->directives_payload_native->count; k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k < op->directives_payload_native->count; k++) { 14 14 28
4978 14 gql_runtime_vm_bind_dynamic_value_variables(
4979 14 op->directives_payload_native->guards
4980 14 ? op->directives_payload_native->guards[k].if_expr
4981 : NULL,
4982 14 ▶ program->variable_defs,
Branch: 1 branch
BranchTrueFalseTotal
program->variable_defs, 14 0 14
4983 program->variable_def_count
4984 );
4985 }
4986 }
4987 }
4988 }
4989  
4990 439 return program;
4991 }
4992  
4993 static gql_runtime_vm_native_bundle_t *
4994 371 gql_runtime_vm_native_bundle_from_runtime_and_program_handles(
4995 gql_runtime_vm_native_runtime_t *runtime,
4996 gql_runtime_vm_native_program_t *program
4997 )
4998 {
4999 gql_runtime_vm_native_bundle_t *bundle;
5000 IV i;
5001 371 ▶ if (!runtime || !program) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime || !program) { 371 0 371
if (!runtime || !program) { 0 371 371
5002 0 croak("native runtime and native program handles are required");
5003 }
5004  
5005 371 Newxz(bundle, 1, gql_runtime_vm_native_bundle_t);
5006 371 bundle->operation_type_code = program->operation_type_code;
5007 371 bundle->root_block_index = program->root_block_index;
5008 371 bundle->runtime_slot_count = runtime->runtime_slot_count;
5009 371 bundle->owns_runtime_slots = 1;
5010 371 bundle->runtime_slots = NULL;
5011 371 ▶ if (runtime->runtime_slot_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (runtime->runtime_slot_count > 0) { 371 0 371
5012 371 ▶ Newxz(bundle->runtime_slots, runtime->runtime_slot_count, gql_runtime_vm_native_slot_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(bundle->runtime_slots, runtime->runtime_slot_count, gql_runtime_vm_native_slot_t); 0 371 371
5013 24995 ▶ for (i = 0; i < runtime->runtime_slot_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < runtime->runtime_slot_count; i++) { 24624 371 24995
5014 24624 gql_runtime_vm_clone_native_slot(aTHX_ &runtime->runtime_slots[i], &bundle->runtime_slots[i]);
5015 }
5016 }
5017 371 bundle->block_count = program->block_count;
5018 371 ▶ if (program->block_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->block_count > 0) { 371 0 371
5019 371 bundle->owns_blocks = 1;
5020 371 ▶ Newxz(bundle->blocks, program->block_count, gql_runtime_vm_native_block_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(bundle->blocks, program->block_count, gql_runtime_vm_native_block_t); 0 371 371
5021 1356 ▶ for (i = 0; i < program->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->block_count; i++) { 985 371 1356
5022 985 gql_runtime_vm_clone_native_block(aTHX_ &program->blocks[i], &bundle->blocks[i]);
5023 }
5024 }
5025 371 return bundle;
5026 }
5027  
5028 static void
5029 370 gql_runtime_vm_prepare_cached_bundle_in_place(
5030 pTHX_
5031 gql_runtime_vm_native_runtime_t *runtime,
5032 gql_runtime_vm_native_bundle_t *bundle
5033 )
5034 {
5035 IV i;
5036  
5037 370 ▶ if (!runtime || !bundle || !bundle->blocks) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime || !bundle || !bundle->blocks) { 370 0 370
if (!runtime || !bundle || !bundle->blocks) { 370 0 370
if (!runtime || !bundle || !bundle->blocks) { 0 370 370
5038 0 return;
5039 }
5040  
5041 1346 ▶ for (i = 0; i < bundle->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < bundle->block_count; i++) { 984 362 1346
5042 984 gql_runtime_vm_native_block_t *block = &bundle->blocks[i];
5043 IV read_index;
5044 984 IV write_index = 0;
5045  
5046 2846 ▶ for (read_index = 0; read_index < block->op_count; read_index++) {
Branch: 1 branch
BranchTrueFalseTotal
for (read_index = 0; read_index < block->op_count; read_index++) { 1870 976 2846
5047 1870 gql_runtime_vm_native_op_t *op = &block->ops[read_index];
5048 1870 const gql_runtime_vm_native_slot_t *slot = NULL;
5049 1870 int keep = 1;
5050  
5051 1870 ▶ 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) { 1870 0 1870
if (op->slot_index >= 0 && op->slot_index < block->slot_count) { 1870 0 1870
5052 1870 slot = &block->slots[op->slot_index];
5053 }
5054  
5055 1870 ▶ if (op->has_directives && op->directives_mode_code == GQL_VM_ARGS_STATIC) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->has_directives && op->directives_mode_code == GQL_VM_ARGS_STATIC) { 14 1856 1870
if (op->has_directives && op->directives_mode_code == GQL_VM_ARGS_STATIC) { 0 14 14
5056 0 ▶ if (!gql_runtime_vm_evaluate_runtime_guards_native(
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_evaluate_runtime_guards_native( 0 0 0
5057 aTHX_
5058 0 op->directives_payload_native,
5059 NULL,
5060 NULL,
5061 0
5062 )) {
5063 0 keep = 0;
5064 } else {
5065 0 op->has_directives = 0;
5066 0 op->directives_mode_code = GQL_VM_ARGS_NONE;
5067 0 gql_runtime_vm_native_directives_payload_destroy(aTHX_ op->directives_payload_native);
5068 0 op->directives_payload_native = NULL;
5069 }
5070 }
5071  
5072 1870 ▶ if (keep
Branch: 1 branch
BranchTrueFalseTotal
if (keep 1870 0 1870
5073 1870 ▶ && slot
Branch: 1 branch
BranchTrueFalseTotal
&& slot 1870 0 1870
5074 1870 ▶ && op->args_mode_code == GQL_VM_ARGS_STATIC
Branch: 1 branch
BranchTrueFalseTotal
&& op->args_mode_code == GQL_VM_ARGS_STATIC 114 1756 1870
5075 114 ▶ && (slot->arg_def_count > 0 || op->has_args)) {
Branch: 2 branches
BranchTrueFalseTotal
&& (slot->arg_def_count > 0 || op->has_args)) { 0 114 114
&& (slot->arg_def_count > 0 || op->has_args)) { 0 0 0
5076 gql_runtime_vm_native_args_payload_t *specialized_payload =
5077 114 gql_runtime_vm_specialize_arg_payload_native(aTHX_ runtime, slot, op, NULL);
5078 106 gql_runtime_vm_native_args_payload_destroy(aTHX_ op->args_payload_native);
5079 106 op->args_payload_native = NULL;
5080 106 ▶ if (specialized_payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (specialized_payload) { 106 0 106
5081 106 op->args_payload_native = specialized_payload;
5082 106 op->args_mode_code = GQL_VM_ARGS_STATIC;
5083 106 op->has_args = 1;
5084 } else {
5085 0 op->args_mode_code = GQL_VM_ARGS_NONE;
5086 0 op->has_args = 0;
5087 }
5088 }
5089  
5090 1862 ▶ if (!keep) {
Branch: 1 branch
BranchTrueFalseTotal
if (!keep) { 0 1862 1862
5091 0 gql_runtime_vm_native_args_payload_destroy(aTHX_ op->args_payload_native);
5092 0 op->args_payload_native = NULL;
5093 0 gql_runtime_vm_native_directives_payload_destroy(aTHX_ op->directives_payload_native);
5094 0 op->directives_payload_native = NULL;
5095 0 SvREFCNT_dec(op->runtime_directives_sv);
5096 0 op->runtime_directives_sv = NULL;
5097 0 continue;
5098 }
5099  
5100 1862 ▶ if (write_index != read_index) {
Branch: 1 branch
BranchTrueFalseTotal
if (write_index != read_index) { 0 1862 1862
5101 0 block->ops[write_index] = *op;
5102 0 Zero(op, 1, gql_runtime_vm_native_op_t);
5103 }
5104 1862 write_index++;
5105 }
5106  
5107 976 block->op_count = write_index;
5108 }
5109 }
5110  
5111 static gql_runtime_vm_native_bundle_t *
5112 2443 gql_runtime_vm_native_program_cached_bundle(
5113 pTHX_
5114 gql_runtime_vm_native_runtime_t *runtime,
5115 gql_runtime_vm_native_program_t *program
5116 )
5117 {
5118 2443 ▶ if (!runtime || !program) {
Branch: 2 branches
BranchTrueFalseTotal
if (!runtime || !program) { 2443 0 2443
if (!runtime || !program) { 0 2443 2443
5119 0 croak("native runtime and native program handles are required");
5120 }
5121  
5122 2443 ▶ if (program->cached_bundle && program->cached_bundle_runtime == runtime) {
Branch: 2 branches
BranchTrueFalseTotal
if (program->cached_bundle && program->cached_bundle_runtime == runtime) { 2078 365 2443
if (program->cached_bundle && program->cached_bundle_runtime == runtime) { 2073 5 2078
5123 2073 return program->cached_bundle;
5124 }
5125  
5126 370 ▶ if (program->cached_bundle) {
Branch: 1 branch
BranchTrueFalseTotal
if (program->cached_bundle) { 5 365 370
5127 5 gql_runtime_vm_native_bundle_destroy(program->cached_bundle);
5128 5 program->cached_bundle = NULL;
5129 5 program->cached_bundle_runtime = NULL;
5130 }
5131  
5132 370 program->cached_bundle =
5133 370 gql_runtime_vm_native_bundle_from_runtime_and_program_handles(runtime, program);
5134 370 gql_runtime_vm_prepare_cached_bundle_in_place(aTHX_ runtime, program->cached_bundle);
5135 362 program->cached_bundle_runtime = runtime;
5136 362 return program->cached_bundle;
5137 }
5138  
5139 static gql_runtime_vm_native_bundle_t *
5140 27 gql_runtime_vm_native_bundle_from_sv(pTHX_ SV *sv)
5141 {
5142 HV *bundle_hv;
5143 SV **runtime_svp;
5144 SV **program_svp;
5145  
5146 27 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &bundle_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ sv, &bundle_hv)) { 0 27 27
5147 0 croak("native VM bundle descriptor must be a hash reference");
5148 }
5149  
5150 27 runtime_svp = hv_fetch(bundle_hv, "runtime", 7, 0);
5151 27 ▶ if (!runtime_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!runtime_svp) { 0 27 27
5152 0 croak("native VM bundle descriptor is missing runtime");
5153 }
5154 27 program_svp = hv_fetch(bundle_hv, "program", 7, 0);
5155 27 ▶ if (!program_svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (!program_svp) { 0 27 27
5156 0 croak("native VM bundle descriptor is missing program");
5157 }
5158  
5159 27 return gql_runtime_vm_native_bundle_from_runtime_and_program_sv(
5160 aTHX_ *runtime_svp, *program_svp
5161 );
5162 }
5163  
5164 static int
5165 37 gql_runtime_vm_program_is_native_eligible_sv(pTHX_ SV *program_sv, int has_promise)
5166 {
5167 HV *program_hv;
5168 AV *blocks_av;
5169 IV i, j, k;
5170 SV **svp;
5171  
5172 37 ▶ if (has_promise) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_promise) { 0 37 37
5173 0 return 0;
5174 }
5175 37 ▶ 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")) { 37 0 37
if (program_sv && SvROK(program_sv) && sv_derived_from(program_sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 37 0 37
if (program_sv && SvROK(program_sv) && sv_derived_from(program_sv, "GraphQL::Houtou::Runtime::NativeProgram")) { 37 0 37
5176 37 gql_runtime_vm_native_program_t *program =
5177 37 INT2PTR(gql_runtime_vm_native_program_t *, SvUV(SvRV(program_sv)));
5178 37 return program ? 1 : 0;
5179 }
5180 0 ▶ if (!gql_runtime_vm_sv_to_hv(aTHX_ program_sv, &program_hv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_sv_to_hv(aTHX_ program_sv, &program_hv)) { 0 0 0
5181 0 return 0;
5182 }
5183  
5184 0 svp = hv_fetch(program_hv, "variable_defs", 13, 0);
5185 0 ▶ 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) { 0 0 0
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
if (svp && SvOK(*svp) && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
5186 0 HV *defs_hv = (HV *)SvRV(*svp);
5187 0 ▶ if (HvUSEDKEYS(defs_hv) > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (HvUSEDKEYS(defs_hv) > 0) { 0 0 0
if (HvUSEDKEYS(defs_hv) > 0) { 0 0 0
5188 0 return 0;
5189 }
5190 }
5191  
5192 0 svp = hv_fetch(program_hv, "blocks_compact", 14, 0);
5193 0 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 0 0
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 0 0
5194 0 svp = hv_fetch(program_hv, "blocks", 6, 0);
5195 }
5196 0 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 0 0
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &blocks_av)) { 0 0 0
5197 0 return 0;
5198 }
5199  
5200 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
5201 0 SV **block_svp = av_fetch(blocks_av, i, 0);
5202 AV *block_av;
5203 AV *slots_av;
5204 AV *ops_av;
5205 0 ▶ if (!block_svp || !gql_runtime_vm_sv_to_av(aTHX_ *block_svp, &block_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!block_svp || !gql_runtime_vm_sv_to_av(aTHX_ *block_svp, &block_av)) { 0 0 0
if (!block_svp || !gql_runtime_vm_sv_to_av(aTHX_ *block_svp, &block_av)) { 0 0 0
5206 0 return 0;
5207 }
5208  
5209 0 svp = av_fetch(block_av, 3, 0);
5210 0 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &slots_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &slots_av)) { 0 0 0
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &slots_av)) { 0 0 0
5211 0 return 0;
5212 }
5213 0 ▶ for (j = 0; j <= av_len(slots_av); j++) {
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j <= av_len(slots_av); j++) { 0 0 0
5214 0 SV **slot_svp = av_fetch(slots_av, j, 0);
5215 AV *slot_av;
5216 IV resolver_shape_code;
5217 IV resolver_mode_code;
5218 IV callback_abi_code;
5219 0 ▶ if (!slot_svp || !gql_runtime_vm_sv_to_av(aTHX_ *slot_svp, &slot_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!slot_svp || !gql_runtime_vm_sv_to_av(aTHX_ *slot_svp, &slot_av)) { 0 0 0
if (!slot_svp || !gql_runtime_vm_sv_to_av(aTHX_ *slot_svp, &slot_av)) { 0 0 0
5220 0 return 0;
5221 }
5222 0 svp = av_fetch(slot_av, 4, 0);
5223 0 ▶ resolver_shape_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
resolver_shape_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 0 0 0
resolver_shape_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 0 0 0
5224 0 svp = av_fetch(slot_av, 10, 0);
5225 0 ▶ resolver_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0;
Branch: 2 branches
BranchTrueFalseTotal
resolver_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 0 0 0
resolver_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : 0; 0 0 0
5226 0 svp = av_fetch(slot_av, 12, 0);
5227 0 ▶ callback_abi_code = (svp && SvOK(*svp))
Branch: 1 branch
BranchTrueFalseTotal
callback_abi_code = (svp && SvOK(*svp)) 0 0 0
5228 0 ? SvIV(*svp)
5229 0 ▶ : gql_runtime_vm_infer_callback_abi_code(resolver_shape_code, resolver_mode_code);
Branch: 1 branch
BranchTrueFalseTotal
: gql_runtime_vm_infer_callback_abi_code(resolver_shape_code, resolver_mode_code); 0 0 0
5230 0 ▶ if (resolver_shape_code != GQL_VM_RESOLVE_DEFAULT) {
Branch: 1 branch
BranchTrueFalseTotal
if (resolver_shape_code != GQL_VM_RESOLVE_DEFAULT) { 0 0 0
5231 0 ▶ if (resolver_shape_code != GQL_VM_RESOLVE_EXPLICIT
Branch: 1 branch
BranchTrueFalseTotal
if (resolver_shape_code != GQL_VM_RESOLVE_EXPLICIT 0 0 0
5232 0 ▶ || (callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_GENERIC
Branch: 1 branch
BranchTrueFalseTotal
|| (callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_GENERIC 0 0 0
5233 0 ▶ && callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE
Branch: 1 branch
BranchTrueFalseTotal
&& callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE 0 0 0
5234 0 ▶ && callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS
Branch: 1 branch
BranchTrueFalseTotal
&& callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_NO_ARGS 0 0 0
5235 0 ▶ && callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG)) {
Branch: 1 branch
BranchTrueFalseTotal
&& callback_abi_code != GQL_VM_CALLBACK_ABI_EXPLICIT_NATIVE_ONE_ARG)) { 0 0 0
5236 0 return 0;
5237 }
5238 }
5239 }
5240  
5241 0 svp = av_fetch(block_av, 4, 0);
5242 0 ▶ if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &ops_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &ops_av)) { 0 0 0
if (!svp || !gql_runtime_vm_sv_to_av(aTHX_ *svp, &ops_av)) { 0 0 0
5243 0 return 0;
5244 }
5245 0 ▶ for (k = 0; k <= av_len(ops_av); k++) {
Branch: 1 branch
BranchTrueFalseTotal
for (k = 0; k <= av_len(ops_av); k++) { 0 0 0
5246 0 SV **op_svp = av_fetch(ops_av, k, 0);
5247 AV *op_av;
5248 IV args_mode_code;
5249 int has_directives;
5250 0 ▶ if (!op_svp || !gql_runtime_vm_sv_to_av(aTHX_ *op_svp, &op_av)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!op_svp || !gql_runtime_vm_sv_to_av(aTHX_ *op_svp, &op_av)) { 0 0 0
if (!op_svp || !gql_runtime_vm_sv_to_av(aTHX_ *op_svp, &op_av)) { 0 0 0
5251 0 return 0;
5252 }
5253 0 svp = av_fetch(op_av, 7, 0);
5254 0 ▶ args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE;
Branch: 2 branches
BranchTrueFalseTotal
args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
args_mode_code = (svp && SvOK(*svp)) ? SvIV(*svp) : GQL_VM_ARGS_NONE; 0 0 0
5255 0 svp = av_fetch(op_av, 12, 0);
5256 0 ▶ has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0;
Branch: 3 branches
BranchTrueFalseTotal
has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 0 0 0
has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 0 0 0
has_directives = (svp && SvOK(*svp) && SvTRUE(*svp)) ? 1 : 0; 0 0 0
5257 0 ▶ if (args_mode_code != GQL_VM_ARGS_NONE && args_mode_code != GQL_VM_ARGS_STATIC) {
Branch: 2 branches
BranchTrueFalseTotal
if (args_mode_code != GQL_VM_ARGS_NONE && args_mode_code != GQL_VM_ARGS_STATIC) { 0 0 0
if (args_mode_code != GQL_VM_ARGS_NONE && args_mode_code != GQL_VM_ARGS_STATIC) { 0 0 0
5258 0 return 0;
5259 }
5260 0 ▶ if (has_directives) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_directives) { 0 0 0
5261 0 return 0;
5262 }
5263 }
5264 }
5265  
5266 0 return 1;
5267 }
5268  
5269 static gql_runtime_vm_native_program_t *
5270 41 gql_runtime_vm_clone_native_program(pTHX_ gql_runtime_vm_native_program_t *src)
5271 {
5272 gql_runtime_vm_native_program_t *dst;
5273 IV i;
5274 41 ▶ if (!src) {
Branch: 1 branch
BranchTrueFalseTotal
if (!src) { 0 41 41
5275 0 return NULL;
5276 }
5277 41 Newxz(dst, 1, gql_runtime_vm_native_program_t);
5278 41 dst->version = src->version;
5279 41 dst->operation_type_code = src->operation_type_code;
5280 41 dst->root_block_index = src->root_block_index;
5281 41 dst->variable_def_count = src->variable_def_count;
5282 41 dst->block_count = src->block_count;
5283 41 dst->args_payload_count = src->args_payload_count;
5284 41 dst->directives_payload_count = src->directives_payload_count;
5285 41 ▶ if (src->operation_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->operation_name) { 5 36 41
5286 5 STRLEN len = strlen(src->operation_name);
5287 5 Newxz(dst->operation_name, len + 1, char);
5288 5 Copy(src->operation_name, dst->operation_name, len, char);
5289 5 dst->operation_name[len] = '\0';
5290 }
5291 41 ▶ if (src->variable_def_count > 0 && src->variable_defs) {
Branch: 2 branches
BranchTrueFalseTotal
if (src->variable_def_count > 0 && src->variable_defs) { 5 36 41
if (src->variable_def_count > 0 && src->variable_defs) { 5 0 5
5292 5 ▶ Newxz(dst->variable_defs, src->variable_def_count, gql_runtime_vm_native_arg_def_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->variable_defs, src->variable_def_count, gql_runtime_vm_native_arg_def_t); 0 5 5
5293 10 ▶ for (i = 0; i < src->variable_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->variable_def_count; i++) { 5 5 10
5294 5 gql_runtime_vm_native_arg_def_t *src_def = &src->variable_defs[i];
5295 5 gql_runtime_vm_native_arg_def_t *dst_def = &dst->variable_defs[i];
5296 5 dst_def->has_default = src_def->has_default;
5297 5 dst_def->input_type_nonnull_state = src_def->input_type_nonnull_state;
5298 5 ▶ if (src_def->name) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->name) { 5 0 5
5299 5 STRLEN len = strlen(src_def->name);
5300 5 Newxz(dst_def->name, len + 1, char);
5301 5 Copy(src_def->name, dst_def->name, len, char);
5302 5 dst_def->name[len] = '\0';
5303 }
5304 5 ▶ if (src_def->type_def_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->type_def_sv) { 5 0 5
5305 5 dst_def->type_def_sv = newSVsv(src_def->type_def_sv);
5306 }
5307 5 ▶ if (src_def->input_type_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->input_type_sv) { 5 0 5
5308 5 dst_def->input_type_sv = newSVsv(src_def->input_type_sv);
5309 }
5310 5 ▶ if (src_def->default_value_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->default_value_sv) { 1 4 5
5311 1 dst_def->default_value_sv = newSVsv(src_def->default_value_sv);
5312 }
5313 5 ▶ if (src_def->default_native_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_def->default_native_value) { 1 4 5
5314 1 dst_def->default_native_value = gql_runtime_vm_native_value_clone(aTHX_ src_def->default_native_value);
5315 }
5316 }
5317 }
5318 41 ▶ if (src->args_payload_count > 0 && src->args_payloads) {
Branch: 2 branches
BranchTrueFalseTotal
if (src->args_payload_count > 0 && src->args_payloads) { 4 37 41
if (src->args_payload_count > 0 && src->args_payloads) { 4 0 4
5319 4 ▶ Newxz(dst->args_payloads, src->args_payload_count, gql_runtime_vm_native_args_payload_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->args_payloads, src->args_payload_count, gql_runtime_vm_native_args_payload_t *); 0 4 4
5320 8 ▶ for (i = 0; i < src->args_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->args_payload_count; i++) { 4 4 8
5321 4 ▶ if (src->args_payloads[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->args_payloads[i]) { 4 0 4
5322 4 dst->args_payloads[i] = gql_runtime_vm_native_args_payload_clone(aTHX_ src->args_payloads[i]);
5323 }
5324 }
5325 }
5326 41 ▶ if (src->directives_payload_count > 0 && src->directives_payloads) {
Branch: 2 branches
BranchTrueFalseTotal
if (src->directives_payload_count > 0 && src->directives_payloads) { 0 41 41
if (src->directives_payload_count > 0 && src->directives_payloads) { 0 0 0
5327 0 ▶ Newxz(dst->directives_payloads, src->directives_payload_count, gql_runtime_vm_native_directives_payload_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->directives_payloads, src->directives_payload_count, gql_runtime_vm_native_directives_payload_t *); 0 0 0
5328 0 ▶ for (i = 0; i < src->directives_payload_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->directives_payload_count; i++) { 0 0 0
5329 0 ▶ if (src->directives_payloads[i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->directives_payloads[i]) { 0 0 0
5330 0 dst->directives_payloads[i] = gql_runtime_vm_native_directives_payload_clone(aTHX_ src->directives_payloads[i]);
5331 }
5332 }
5333 }
5334 41 ▶ if (src->block_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (src->block_count > 0) { 41 0 41
5335 41 ▶ Newxz(dst->blocks, src->block_count, gql_runtime_vm_native_block_t);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(dst->blocks, src->block_count, gql_runtime_vm_native_block_t); 0 41 41
5336 116 ▶ for (i = 0; i < src->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < src->block_count; i++) { 75 41 116
5337 75 gql_runtime_vm_clone_native_block(aTHX_ &src->blocks[i], &dst->blocks[i]);
5338 }
5339 }
5340 41 return dst;
5341 }
5342  
5343 static SV *
5344 2033 gql_runtime_vm_lookup_input_type_by_typedef_sv(pTHX_ SV *runtime_schema, SV *typedef_sv)
5345 {
5346 2033 dSP;
5347 SV *runtime_cache_sv;
5348 SV *name2type_sv;
5349 HV *schema_hv;
5350 HV *runtime_cache_hv;
5351 2033 SV *result = NULL;
5352 int count;
5353  
5354 2033 ▶ if (!runtime_schema || !SvROK(runtime_schema) || SvTYPE(SvRV(runtime_schema)) != SVt_PVHV || !typedef_sv || !SvOK(typedef_sv)) {
Branch: 5 branches
BranchTrueFalseTotal
if (!runtime_schema || !SvROK(runtime_schema) || SvTYPE(SvRV(runtime_schema)) != SVt_PVHV || !typedef_sv || !SvOK(typedef_sv)) { 2033 0 2033
if (!runtime_schema || !SvROK(runtime_schema) || SvTYPE(SvRV(runtime_schema)) != SVt_PVHV || !typedef_sv || !SvOK(typedef_sv)) { 2033 0 2033
if (!runtime_schema || !SvROK(runtime_schema) || SvTYPE(SvRV(runtime_schema)) != SVt_PVHV || !typedef_sv || !SvOK(typedef_sv)) { 2033 0 2033
if (!runtime_schema || !SvROK(runtime_schema) || SvTYPE(SvRV(runtime_schema)) != SVt_PVHV || !typedef_sv || !SvOK(typedef_sv)) { 2033 0 2033
if (!runtime_schema || !SvROK(runtime_schema) || SvTYPE(SvRV(runtime_schema)) != SVt_PVHV || !typedef_sv || !SvOK(typedef_sv)) { 0 2033 2033
5355 0 return NULL;
5356 }
5357 2033 schema_hv = (HV *)SvRV(runtime_schema);
5358 2033 runtime_cache_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ schema_hv, "runtime_cache", 13);
5359 2033 ▶ if (!runtime_cache_sv || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime_cache_sv || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) { 2033 0 2033
if (!runtime_cache_sv || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) { 2033 0 2033
if (!runtime_cache_sv || !SvROK(runtime_cache_sv) || SvTYPE(SvRV(runtime_cache_sv)) != SVt_PVHV) { 0 2033 2033
5360 0 return NULL;
5361 }
5362 2033 runtime_cache_hv = (HV *)SvRV(runtime_cache_sv);
5363 2033 name2type_sv = gql_runtime_vm_fetch_hash_entry_sv(aTHX_ runtime_cache_hv, "name2type", 9);
5364 2033 ▶ 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) { 2033 0 2033
if (!name2type_sv || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 2033 0 2033
if (!name2type_sv || !SvROK(name2type_sv) || SvTYPE(SvRV(name2type_sv)) != SVt_PVHV) { 0 2033 2033
5365 0 return NULL;
5366 }
5367  
5368 2033 ENTER;
5369 2033 SAVETMPS;
5370 2033 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 2033 0 2033
5371 2033 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2033 2033
5372 2033 ▶ XPUSHs(typedef_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(typedef_sv); 0 2033 2033
5373 2033 ▶ XPUSHs(name2type_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(name2type_sv); 0 2033 2033
5374 2033 PUTBACK;
5375 2033 count = call_pv("GraphQL::Houtou::Schema::lookup_type", G_SCALAR | G_EVAL);
5376 2033 SPAGAIN;
5377 2033 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 2033 0 2033
if (SvTRUE(ERRSV)) { 0 2033 2033
5378 0 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 0 0 0
5379 0 PUTBACK;
5380 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
5381 0 LEAVE;
5382 0 croak_sv(err);
5383 }
5384 2033 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 2033 0 2033
5385 2033 result = newSVsv(POPs);
5386 }
5387 2033 PUTBACK;
5388 2033 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2033 0 2033
5389 2033 LEAVE;
5390 2033 return result;
5391 }
5392  
5393 /* Leaf coercion kind for a slot, or GQL_VM_LEAF_NONE when the runtime
5394 * carries no leaf metadata (descriptor-inflated) or the slot's return
5395 * type is not a leaf. */
5396 static IV
5397 1749 gql_runtime_vm_slot_leaf_kind(
5398 const gql_runtime_vm_native_runtime_t *runtime,
5399 const gql_runtime_vm_native_slot_t *slot
5400 )
5401 {
5402 IV slot_index;
5403 1749 ▶ if (!runtime || !slot || !runtime->callback_catalog
Branch: 3 branches
BranchTrueFalseTotal
if (!runtime || !slot || !runtime->callback_catalog 1749 0 1749
if (!runtime || !slot || !runtime->callback_catalog 1749 0 1749
if (!runtime || !slot || !runtime->callback_catalog 1749 0 1749
5404 1749 ▶ || !runtime->callback_catalog->slot_leaf_kinds) {
Branch: 1 branch
BranchTrueFalseTotal
|| !runtime->callback_catalog->slot_leaf_kinds) { 0 1749 1749
5405 0 return GQL_VM_LEAF_NONE;
5406 }
5407 1749 slot_index = slot->schema_slot_index;
5408 1749 ▶ if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 1749 0 1749
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 0 1749 1749
5409 0 return GQL_VM_LEAF_NONE;
5410 }
5411 1749 return runtime->callback_catalog->slot_leaf_kinds[slot_index];
5412 }
5413  
5414 /*
5415 * Leaf result coercion (spec 6.4.3 value completion for leaf types).
5416 * Checks/serializes a resolver's output value against the field's leaf
5417 * type. Returns an OWNED SV with the coerced value on success (which may
5418 * be the input with an extra refcount when it already conforms). On a
5419 * coercion failure returns NULL and sets *error_out to an owned message
5420 * SV; the caller nulls the field and records a field error. Slots whose
5421 * return type carries no leaf metadata (objects, unions, descriptor-only
5422 * runtimes) pass the value through untouched.
5423 *
5424 * Perl note: scalars are untyped, so the builtin checks are value-based
5425 * (grok_number), not SV-flag-based - a resolver returning "5" for an Int
5426 * serializes as 5, matching graphql-js's coercing serializers.
5427 */
5428 static SV *
5429 9079 gql_runtime_vm_serialize_leaf_sv(
5430 pTHX_
5431 const gql_runtime_vm_native_runtime_t *runtime,
5432 const gql_runtime_vm_native_slot_t *slot,
5433 SV *value,
5434 SV **error_out
5435 )
5436 {
5437 9079 const gql_runtime_vm_native_callback_catalog_t *catalog =
5438 9079 ▶ runtime ? runtime->callback_catalog : NULL;
Branch: 1 branch
BranchTrueFalseTotal
runtime ? runtime->callback_catalog : NULL; 9079 0 9079
5439 IV slot_index;
5440 IV leaf_kind;
5441 SV *payload;
5442  
5443 9079 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 9079 0 9079
5444 9079 *error_out = NULL;
5445 }
5446 9079 ▶ if (!value || !SvOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value || !SvOK(value)) { 9079 0 9079
if (!value || !SvOK(value)) { 524 8555 9079
5447 524 return newSVsv(&PL_sv_undef);
5448 }
5449 8555 ▶ if (!catalog || !catalog->slot_leaf_kinds || !slot) {
Branch: 3 branches
BranchTrueFalseTotal
if (!catalog || !catalog->slot_leaf_kinds || !slot) { 8555 0 8555
if (!catalog || !catalog->slot_leaf_kinds || !slot) { 8555 0 8555
if (!catalog || !catalog->slot_leaf_kinds || !slot) { 0 8555 8555
5450 0 SvREFCNT_inc_simple_NN(value);
5451 0 return value;
5452 }
5453 8555 slot_index = slot->schema_slot_index;
5454 8555 ▶ if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 8555 0 8555
if (slot_index < 0 || slot_index >= runtime->runtime_slot_count) { 0 8555 8555
5455 0 SvREFCNT_inc_simple_NN(value);
5456 0 return value;
5457 }
5458 8555 leaf_kind = catalog->slot_leaf_kinds[slot_index];
5459 8555 ▶ if (leaf_kind == GQL_VM_LEAF_NONE) {
Branch: 1 branch
BranchTrueFalseTotal
if (leaf_kind == GQL_VM_LEAF_NONE) { 0 8555 8555
5460 0 SvREFCNT_inc_simple_NN(value);
5461 0 return value;
5462 }
5463 8555 ▶ payload = catalog->slot_leaf_payloads ? catalog->slot_leaf_payloads[slot_index] : NULL;
Branch: 1 branch
BranchTrueFalseTotal
payload = catalog->slot_leaf_payloads ? catalog->slot_leaf_payloads[slot_index] : NULL; 8555 0 8555
5464  
5465 8555 switch (leaf_kind) {
5466 105 case GQL_VM_LEAF_INT:
5467 {
5468 /* Fast path: an IV in int32 range passes as-is. */
5469 105 ▶ if (SvIOK(value) && !SvPOK(value) && !SvNOK(value)) {
Branch: 3 branches
BranchTrueFalseTotal
if (SvIOK(value) && !SvPOK(value) && !SvNOK(value)) { 66 39 105
if (SvIOK(value) && !SvPOK(value) && !SvNOK(value)) { 66 0 66
if (SvIOK(value) && !SvPOK(value) && !SvNOK(value)) { 66 0 66
5470 66 IV iv = SvIV(value);
5471 66 ▶ if (iv >= -2147483648LL && iv <= 2147483647LL) {
Branch: 2 branches
BranchTrueFalseTotal
if (iv >= -2147483648LL && iv <= 2147483647LL) { 66 0 66
if (iv >= -2147483648LL && iv <= 2147483647LL) { 66 0 66
5472 66 SvREFCNT_inc_simple_NN(value);
5473 66 return value;
5474 }
5475 }
5476 39 ▶ if (!SvROK(value) && looks_like_number(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(value) && looks_like_number(value)) { 39 0 39
if (!SvROK(value) && looks_like_number(value)) { 21 18 39
5477 21 NV nv = SvNV(value);
5478 21 ▶ if (nv == (NV)(IV)nv && nv >= -2147483648.0 && nv <= 2147483647.0) {
Branch: 3 branches
BranchTrueFalseTotal
if (nv == (NV)(IV)nv && nv >= -2147483648.0 && nv <= 2147483647.0) { 16 5 21
if (nv == (NV)(IV)nv && nv >= -2147483648.0 && nv <= 2147483647.0) { 16 0 16
if (nv == (NV)(IV)nv && nv >= -2147483648.0 && nv <= 2147483647.0) { 11 5 16
5479 11 return newSViv((IV)nv);
5480 }
5481 }
5482 28 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 28 0 28
5483 56 ▶ *error_out = newSVpvf("Int cannot represent non-integer value: %s",
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVpvf("Int cannot represent non-integer value: %s", 28 0 28
5484 SvROK(value) ? "(reference)" : SvPV_nolen(value));
5485 }
5486 28 return NULL;
5487 }
5488 8 case GQL_VM_LEAF_FLOAT:
5489 {
5490 8 ▶ if (SvNIOK(value) && !SvPOK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvNIOK(value) && !SvPOK(value)) { 3 5 8
if (SvNIOK(value) && !SvPOK(value)) { 3 0 3
5491 3 SvREFCNT_inc_simple_NN(value);
5492 3 return value;
5493 }
5494 5 ▶ if (!SvROK(value) && looks_like_number(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(value) && looks_like_number(value)) { 5 0 5
if (!SvROK(value) && looks_like_number(value)) { 5 0 5
5495 5 return newSVnv(SvNV(value));
5496 }
5497 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
5498 0 ▶ *error_out = newSVpvf("Float cannot represent non-numeric value: %s",
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVpvf("Float cannot represent non-numeric value: %s", 0 0 0
5499 SvROK(value) ? "(reference)" : SvPV_nolen(value));
5500 }
5501 0 return NULL;
5502 }
5503 7851 case GQL_VM_LEAF_STRING:
5504 case GQL_VM_LEAF_ID:
5505 {
5506 7851 ▶ const char *type_label = leaf_kind == GQL_VM_LEAF_ID ? "ID" : "String";
Branch: 1 branch
BranchTrueFalseTotal
const char *type_label = leaf_kind == GQL_VM_LEAF_ID ? "ID" : "String"; 41 7810 7851
5507 7851 ▶ if (SvPOK(value) && !SvROK(value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvPOK(value) && !SvROK(value)) { 7846 5 7851
if (SvPOK(value) && !SvROK(value)) { 7846 0 7846
5508 7846 SvREFCNT_inc_simple_NN(value);
5509 7846 return value;
5510 }
5511 5 ▶ if (!SvROK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(value)) { 5 0 5
5512 /* Numbers (and dualvars) stringify; the copy pins the PV
5513 * representation so the JSON lanes emit a string. */
5514 STRLEN len;
5515 5 const char *pv = SvPV(value, len);
5516 5 return newSVpvn_utf8(pv, len, SvUTF8(value) ? 1 : 0);
5517 }
5518 0 ▶ if (sv_isobject(value) && sv_derived_from(value, "JSON::PP::Boolean")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(value) && sv_derived_from(value, "JSON::PP::Boolean")) { 0 0 0
if (sv_isobject(value) && sv_derived_from(value, "JSON::PP::Boolean")) { 0 0 0
5519 0 ▶ return newSVpv(SvTRUE(value) ? "true" : "false", 0);
Branch: 1 branch
BranchTrueFalseTotal
return newSVpv(SvTRUE(value) ? "true" : "false", 0); 0 0 0
5520 }
5521 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
5522 0 *error_out = newSVpvf("%s cannot represent a reference value", type_label);
5523 }
5524 0 return NULL;
5525 }
5526 253 case GQL_VM_LEAF_BOOLEAN:
5527 {
5528 /* Perl has no boolean type: any non-reference scalar coerces by
5529 * truthiness (JSON bool objects included). */
5530 253 ▶ if (!SvROK(value) || (sv_isobject(value) && sv_derived_from(value, "JSON::PP::Boolean"))) {
Branch: 3 branches
BranchTrueFalseTotal
if (!SvROK(value) || (sv_isobject(value) && sv_derived_from(value, "JSON::PP::Boolean"))) { 0 253 253
if (!SvROK(value) || (sv_isobject(value) && sv_derived_from(value, "JSON::PP::Boolean"))) { 0 0 0
if (!SvROK(value) || (sv_isobject(value) && sv_derived_from(value, "JSON::PP::Boolean"))) { 0 0 0
5531 253 return newSViv(SvTRUE(value) ? 1 : 0);
5532 }
5533 0 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 0 0 0
5534 0 *error_out = newSVpvs("Boolean cannot represent a reference value");
5535 }
5536 0 return NULL;
5537 }
5538 328 case GQL_VM_LEAF_ENUM:
5539 {
5540 /* payload maps internal values to enum names (identity for the
5541 * default declaration shape). */
5542 328 ▶ if (!SvROK(value) && payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV) {
Branch: 4 branches
BranchTrueFalseTotal
if (!SvROK(value) && payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV) { 328 0 328
if (!SvROK(value) && payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV) { 328 0 328
if (!SvROK(value) && payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV) { 328 0 328
if (!SvROK(value) && payload && SvROK(payload) && SvTYPE(SvRV(payload)) == SVt_PVHV) { 328 0 328
5543 STRLEN klen;
5544 328 const char *kpv = SvPV(value, klen);
5545 328 SV **name_svp = hv_fetch((HV *)SvRV(payload), kpv, (I32)klen, 0);
5546 328 ▶ if (name_svp && SvOK(*name_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (name_svp && SvOK(*name_svp)) { 318 10 328
if (name_svp && SvOK(*name_svp)) { 318 0 318
5547 318 return newSVsv(*name_svp);
5548 }
5549 }
5550 10 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 10 0 10
5551 20 ▶ *error_out = newSVpvf("Enum '%s' cannot represent value: %s",
Branch: 2 branches
BranchTrueFalseTotal
*error_out = newSVpvf("Enum '%s' cannot represent value: %s", 10 0 10
*error_out = newSVpvf("Enum '%s' cannot represent value: %s", 10 0 10
5552 slot->return_type_name ? slot->return_type_name : "(unknown)",
5553 SvROK(value) ? "(reference)" : SvPV_nolen(value));
5554 }
5555 10 return NULL;
5556 }
5557 10 case GQL_VM_LEAF_CUSTOM:
5558 {
5559 10 dSP;
5560 int count;
5561 10 SV *result = NULL;
5562 10 ▶ if (!payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (!payload) { 0 10 10
5563 0 SvREFCNT_inc_simple_NN(value);
5564 0 return value;
5565 }
5566 10 ENTER;
5567 10 SAVETMPS;
5568 10 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 10 0 10
5569 10 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 10 10
5570 10 ▶ XPUSHs(value);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(value); 0 10 10
5571 10 PUTBACK;
5572 10 count = call_sv(payload, G_SCALAR | G_EVAL);
5573 10 SPAGAIN;
5574 10 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 10 0 10
if (SvTRUE(ERRSV)) { 2 8 10
5575 2 ▶ if (error_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (error_out) { 2 0 2
5576 2 ▶ *error_out = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
*error_out = newSVsv(ERRSV); 2 0 2
5577 }
5578 2 PUTBACK;
5579 2 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2 0 2
5580 2 LEAVE;
5581 2 return NULL;
5582 }
5583 8 ▶ result = count > 0 ? newSVsv(POPs) : newSVsv(&PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
result = count > 0 ? newSVsv(POPs) : newSVsv(&PL_sv_undef); 8 0 8
5584 8 PUTBACK;
5585 8 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 8 0 8
5586 8 LEAVE;
5587 8 return result;
5588 }
5589 0 default:
5590 0 SvREFCNT_inc_simple_NN(value);
5591 0 return value;
5592 }
5593 }
5594  
5595 static SV *
5596 4310 gql_runtime_vm_coerce_input_value_sv(pTHX_ SV *type_sv, SV *value_sv, SV **croak_out)
5597 {
5598 4310 dSP;
5599 4310 SV *result = NULL;
5600 int count;
5601  
5602 4310 ▶ if (!value_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!value_sv) { 0 4310 4310
5603 0 return newSV(0);
5604 }
5605 4310 ▶ if (!type_sv || !SvOK(type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!type_sv || !SvOK(type_sv)) { 4310 0 4310
if (!type_sv || !SvOK(type_sv)) { 0 4310 4310
5606 0 return newSVsv(value_sv);
5607 }
5608  
5609 /* Built-in scalar fast path: Type::Scalar carries _builtin_kind for the
5610 * five specced scalars, and graphql_to_perl short-circuits parse_value
5611 * for them anyway. Handle the unambiguous plain-SV shapes here and skip
5612 * the per-coercion call_method; anything we cannot decide exactly
5613 * (magic, refs, string-y numbers, JSON booleans) falls through to the
5614 * Perl path, which validates and dies with the same messages. */
5615 4310 ▶ if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV && !SvMAGICAL(SvRV(type_sv))) {
Branch: 3 branches
BranchTrueFalseTotal
if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV && !SvMAGICAL(SvRV(type_sv))) { 4310 0 4310
if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV && !SvMAGICAL(SvRV(type_sv))) { 4310 0 4310
if (SvROK(type_sv) && SvTYPE(SvRV(type_sv)) == SVt_PVHV && !SvMAGICAL(SvRV(type_sv))) { 4310 0 4310
5616 4310 SV **kindp = hv_fetchs((HV *)SvRV(type_sv), "_builtin_kind", 0);
5617 4310 ▶ if (kindp && *kindp && SvPOK(*kindp) && !SvROK(value_sv) && !SvMAGICAL(value_sv)) {
Branch: 5 branches
BranchTrueFalseTotal
if (kindp && *kindp && SvPOK(*kindp) && !SvROK(value_sv) && !SvMAGICAL(value_sv)) { 3369 941 4310
if (kindp && *kindp && SvPOK(*kindp) && !SvROK(value_sv) && !SvMAGICAL(value_sv)) { 3369 0 3369
if (kindp && *kindp && SvPOK(*kindp) && !SvROK(value_sv) && !SvMAGICAL(value_sv)) { 3368 1 3369
if (kindp && *kindp && SvPOK(*kindp) && !SvROK(value_sv) && !SvMAGICAL(value_sv)) { 3368 0 3368
if (kindp && *kindp && SvPOK(*kindp) && !SvROK(value_sv) && !SvMAGICAL(value_sv)) { 3368 0 3368
5618 3368 const char *kind = SvPVX(*kindp);
5619 3368 STRLEN klen = SvCUR(*kindp);
5620 3368 ▶ if (!SvOK(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(value_sv)) { 4 3364 3368
5621 4 return newSV(0);
5622 }
5623 3364 ▶ if ((klen == 6 && memcmp(kind, "String", 6) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if ((klen == 6 && memcmp(kind, "String", 6) == 0) 1965 1399 3364
if ((klen == 6 && memcmp(kind, "String", 6) == 0) 0 1965 1965
5624 1399 ▶ || (klen == 2 && memcmp(kind, "ID", 2) == 0)) {
Branch: 2 branches
BranchTrueFalseTotal
|| (klen == 2 && memcmp(kind, "ID", 2) == 0)) { 38 1361 1399
|| (klen == 2 && memcmp(kind, "ID", 2) == 0)) { 38 0 38
5625 /* Any defined non-ref value is accepted and passed through. */
5626 2003 return newSVsv(value_sv);
5627 }
5628 1361 ▶ if (klen == 3 && memcmp(kind, "Int", 3) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) {
Branch: 5 branches
BranchTrueFalseTotal
if (klen == 3 && memcmp(kind, "Int", 3) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 17 1344 1361
if (klen == 3 && memcmp(kind, "Int", 3) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 17 0 17
if (klen == 3 && memcmp(kind, "Int", 3) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 13 4 17
if (klen == 3 && memcmp(kind, "Int", 3) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 13 0 13
if (klen == 3 && memcmp(kind, "Int", 3) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 13 0 13
5629 13 IV v = SvIV(value_sv);
5630 13 ▶ if (v >= -2147483648LL && v <= 2147483647LL) {
Branch: 2 branches
BranchTrueFalseTotal
if (v >= -2147483648LL && v <= 2147483647LL) { 13 0 13
if (v >= -2147483648LL && v <= 2147483647LL) { 13 0 13
5631 13 return newSViv(v);
5632 }
5633 /* Out-of-range: fall through so the Perl path raises "Not an Int." */
5634 1348 ▶ } else if (klen == 5 && memcmp(kind, "Float", 5) == 0 && !SvPOK(value_sv)) {
Branch: 3 branches
BranchTrueFalseTotal
} else if (klen == 5 && memcmp(kind, "Float", 5) == 0 && !SvPOK(value_sv)) { 0 1348 1348
} else if (klen == 5 && memcmp(kind, "Float", 5) == 0 && !SvPOK(value_sv)) { 0 0 0
} else if (klen == 5 && memcmp(kind, "Float", 5) == 0 && !SvPOK(value_sv)) { 0 0 0
5635 0 ▶ if (SvIOK(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvIOK(value_sv)) { 0 0 0
5636 0 return newSViv(SvIV(value_sv));
5637 }
5638 0 ▶ if (SvNOK(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvNOK(value_sv)) { 0 0 0
5639 0 return newSVnv(SvNV(value_sv));
5640 }
5641 1348 ▶ } else if (klen == 7 && memcmp(kind, "Boolean", 7) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) {
Branch: 5 branches
BranchTrueFalseTotal
} else if (klen == 7 && memcmp(kind, "Boolean", 7) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 1344 4 1348
} else if (klen == 7 && memcmp(kind, "Boolean", 7) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 1344 0 1344
} else if (klen == 7 && memcmp(kind, "Boolean", 7) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 1344 0 1344
} else if (klen == 7 && memcmp(kind, "Boolean", 7) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 1344 0 1344
} else if (klen == 7 && memcmp(kind, "Boolean", 7) == 0 && SvIOK(value_sv) && !SvPOK(value_sv) && !SvNOK(value_sv)) { 1344 0 1344
5642 1344 IV v = SvIV(value_sv);
5643 1344 ▶ if (v == 0 || v == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (v == 0 || v == 1) { 122 1222 1344
if (v == 0 || v == 1) { 122 0 122
5644 1344 return newSViv(v);
5645 }
5646 /* Other numbers: fall through so the Perl path raises the error. */
5647 }
5648 }
5649 }
5650  
5651 946 ENTER;
5652 946 SAVETMPS;
5653 946 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 946 0 946
5654 946 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 946 946
5655 946 ▶ XPUSHs(type_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(type_sv); 0 946 946
5656 946 ▶ XPUSHs(value_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(value_sv); 0 946 946
5657 946 PUTBACK;
5658 946 count = call_method("graphql_to_perl", G_SCALAR | G_EVAL);
5659 946 SPAGAIN;
5660 946 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 946 0 946
if (SvTRUE(ERRSV)) { 21 925 946
5661 21 ▶ SV *err = newSVsv(ERRSV);
Branch: 1 branch
BranchTrueFalseTotal
SV *err = newSVsv(ERRSV); 21 0 21
5662 21 PUTBACK;
5663 21 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 21 0 21
5664 21 LEAVE;
5665 /* Input coercion failures are GraphQL request errors (bad variables
5666 * or literals from the client), so they surface as
5667 * GraphQL::Houtou::Error: the execute_document boundary turns blessed
5668 * Houtou errors into an errors-only response envelope and lets any
5669 * other die (a config or internal error) propagate. graphql_to_perl
5670 * raises plain strings; wrap them, keep already-blessed errors. */
5671 21 ▶ if (!sv_isobject(err)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(err)) { 21 0 21
5672 21 HV *error_hv = newHV();
5673 21 SV *message_sv = newSVsv(err);
5674 STRLEN message_len;
5675 21 char *message_pv = SvPV(message_sv, message_len);
5676 /* Trailing newline is die()'s "no location suffix" convention, not
5677 * part of the GraphQL error message. */
5678 42 ▶ while (message_len > 0 && message_pv[message_len - 1] == '\n') {
Branch: 2 branches
BranchTrueFalseTotal
while (message_len > 0 && message_pv[message_len - 1] == '\n') { 42 0 42
while (message_len > 0 && message_pv[message_len - 1] == '\n') { 21 21 42
5679 21 SvCUR_set(message_sv, --message_len);
5680 }
5681 21 (void)hv_stores(error_hv, "message", message_sv);
5682 21 SvREFCNT_dec(err);
5683 21 err = newRV_noinc((SV *)error_hv);
5684 21 sv_bless(err, gv_stashpvs("GraphQL::Houtou::Error", GV_ADD));
5685 }
5686 /* With croak_out the caller defers the croak (the sync fast lanes
5687 * must unwind their path frame chain first); otherwise croak here.
5688 * Mortalize onto the caller's tmps so the copy is reclaimed during
5689 * die unwinding instead of leaking once per coercion failure. */
5690 21 ▶ if (croak_out) {
Branch: 1 branch
BranchTrueFalseTotal
if (croak_out) { 13 8 21
5691 13 *croak_out = err;
5692 13 return newSV(0);
5693 }
5694 8 croak_sv(sv_2mortal(err));
5695 }
5696 925 ▶ if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (count > 0) { 925 0 925
5697 925 result = newSVsv(POPs);
5698 } else {
5699 0 result = newSV(0);
5700 }
5701 925 PUTBACK;
5702 925 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 925 0 925
5703 925 LEAVE;
5704 925 return result;
5705 }
5706  
5707 static void
5708 4722 gql_runtime_vm_finalize_native_arg_def(
5709 pTHX_
5710 SV *runtime_schema,
5711 gql_runtime_vm_native_arg_def_t *arg_def
5712 )
5713 {
5714 4722 ▶ if (!arg_def) {
Branch: 1 branch
BranchTrueFalseTotal
if (!arg_def) { 0 4722 4722
5715 0 return;
5716 }
5717  
5718 4722 ▶ if (arg_def->type_def_sv && !arg_def->input_type_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (arg_def->type_def_sv && !arg_def->input_type_sv) { 4722 0 4722
if (arg_def->type_def_sv && !arg_def->input_type_sv) { 2033 2689 4722
5719 2033 arg_def->input_type_sv = gql_runtime_vm_lookup_input_type_by_typedef_sv(
5720 aTHX_ runtime_schema, arg_def->type_def_sv
5721 );
5722 }
5723 4722 ▶ if (arg_def->has_default
Branch: 1 branch
BranchTrueFalseTotal
if (arg_def->has_default 1235 3487 4722
5724 1235 ▶ && arg_def->default_value_sv
Branch: 1 branch
BranchTrueFalseTotal
&& arg_def->default_value_sv 1235 0 1235
5725 1235 ▶ && arg_def->input_type_sv
Branch: 1 branch
BranchTrueFalseTotal
&& arg_def->input_type_sv 1235 0 1235
5726 1235 ▶ && !arg_def->default_native_value) {
Branch: 1 branch
BranchTrueFalseTotal
&& !arg_def->default_native_value) { 1233 2 1235
5727 /* Mortal so a croak from coercion cannot leak the copies. */
5728 1233 SV *default_raw_sv = sv_2mortal(newSVsv(arg_def->default_value_sv));
5729 1233 SV *default_coerced_sv = sv_2mortal(gql_runtime_vm_coerce_input_value_sv(
5730 aTHX_ arg_def->input_type_sv, default_raw_sv, NULL
5731 ));
5732 1233 arg_def->default_native_value = gql_runtime_vm_native_value_from_sv(aTHX_ default_coerced_sv);
5733 }
5734 }
5735  
5736 /* Bounded, human-readable rendering of a provided variable value for
5737 * request-error messages. Strings are quoted and escaped, JSON booleans
5738 * render as true/false, other references keep the house "(reference)"
5739 * placeholder, and long strings are truncated on a UTF-8 boundary so a
5740 * hostile variable cannot bloat the error envelope. */
5741 #define GQL_RUNTIME_VM_VARIABLE_DESC_MAX_BYTES 64
5742 static SV *
5743 10 gql_runtime_vm_variable_value_desc_sv(pTHX_ SV *value_sv)
5744 {
5745 SV *desc_sv;
5746 const char *pv;
5747 STRLEN len;
5748 STRLEN i;
5749 10 int truncated = 0;
5750  
5751 10 ▶ if (!value_sv || !SvOK(value_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!value_sv || !SvOK(value_sv)) { 10 0 10
if (!value_sv || !SvOK(value_sv)) { 1 9 10
5752 1 return newSVpvs("null");
5753 }
5754 9 ▶ if (SvROK(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(value_sv)) { 5 4 9
5755 5 ▶ if (sv_isobject(value_sv) && sv_derived_from(value_sv, "JSON::PP::Boolean")) {
Branch: 2 branches
BranchTrueFalseTotal
if (sv_isobject(value_sv) && sv_derived_from(value_sv, "JSON::PP::Boolean")) { 0 5 5
if (sv_isobject(value_sv) && sv_derived_from(value_sv, "JSON::PP::Boolean")) { 0 0 0
5756 0 ▶ return SvTRUE(SvRV(value_sv)) ? newSVpvs("true") : newSVpvs("false");
Branch: 1 branch
BranchTrueFalseTotal
return SvTRUE(SvRV(value_sv)) ? newSVpvs("true") : newSVpvs("false"); 0 0 0
5757 }
5758 5 return newSVpvs("(reference)");
5759 }
5760 4 ▶ if (!SvPOK(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvPOK(value_sv)) { 0 4 4
5761 /* Plain IV/NV: Perl's stringification is already the message shape. */
5762 0 return newSVsv(value_sv);
5763 }
5764  
5765 4 pv = SvPV(value_sv, len);
5766 4 ▶ if (len > GQL_RUNTIME_VM_VARIABLE_DESC_MAX_BYTES) {
Branch: 1 branch
BranchTrueFalseTotal
if (len > GQL_RUNTIME_VM_VARIABLE_DESC_MAX_BYTES) { 2 2 4
5767 2 len = GQL_RUNTIME_VM_VARIABLE_DESC_MAX_BYTES;
5768 2 ▶ if (SvUTF8(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(value_sv)) { 1 1 2
5769 /* Do not cut a multi-byte sequence: back off continuation bytes. */
5770 2 ▶ while (len > 0 && (((const U8 *)pv)[len] & 0xC0) == 0x80) {
Branch: 2 branches
BranchTrueFalseTotal
while (len > 0 && (((const U8 *)pv)[len] & 0xC0) == 0x80) { 2 0 2
while (len > 0 && (((const U8 *)pv)[len] & 0xC0) == 0x80) { 1 1 2
5771 1 len--;
5772 }
5773 }
5774 2 truncated = 1;
5775 }
5776 4 desc_sv = newSVpvs("\"");
5777 139 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 135 4 139
5778 135 const char c = pv[i];
5779 135 ▶ if (c == '"' || c == '\\') {
Branch: 2 branches
BranchTrueFalseTotal
if (c == '"' || c == '\\') { 134 1 135
if (c == '"' || c == '\\') { 1 133 134
5780 2 sv_catpvs(desc_sv, "\\");
5781 2 sv_catpvn(desc_sv, &c, 1);
5782 133 ▶ } else if ((U8)c < 0x20) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ((U8)c < 0x20) { 0 133 133
5783 0 sv_catpvs(desc_sv, " ");
5784 } else {
5785 133 sv_catpvn(desc_sv, &c, 1);
5786 }
5787 }
5788 4 ▶ if (truncated) {
Branch: 1 branch
BranchTrueFalseTotal
if (truncated) { 2 2 4
5789 2 sv_catpvs(desc_sv, "...");
5790 }
5791 4 sv_catpvs(desc_sv, "\"");
5792 4 ▶ if (SvUTF8(value_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvUTF8(value_sv)) { 1 3 4
5793 1 SvUTF8_on(desc_sv);
5794 }
5795 4 return desc_sv;
5796 }
5797  
5798 /* Prepend "Variable \"$name\" got invalid value <desc>; " to a Houtou
5799 * request-error message so clients can tell which variable failed input
5800 * coercion. Custom blessed errors that are not plain Houtou error hashes
5801 * are left untouched to preserve their contract. */
5802 static void
5803 10 gql_runtime_vm_variable_error_prepend_context(
5804 pTHX_ SV *err_sv, const char *name, SV *raw_sv
5805 )
5806 {
5807 HV *err_hv;
5808 SV **msgp;
5809 SV *desc_sv;
5810 SV *message_sv;
5811  
5812 10 ▶ if (!err_sv || !name || !SvROK(err_sv) || SvTYPE(SvRV(err_sv)) != SVt_PVHV
Branch: 4 branches
BranchTrueFalseTotal
if (!err_sv || !name || !SvROK(err_sv) || SvTYPE(SvRV(err_sv)) != SVt_PVHV 10 0 10
if (!err_sv || !name || !SvROK(err_sv) || SvTYPE(SvRV(err_sv)) != SVt_PVHV 10 0 10
if (!err_sv || !name || !SvROK(err_sv) || SvTYPE(SvRV(err_sv)) != SVt_PVHV 10 0 10
if (!err_sv || !name || !SvROK(err_sv) || SvTYPE(SvRV(err_sv)) != SVt_PVHV 10 0 10
5813 10 ▶ || !sv_derived_from(err_sv, "GraphQL::Houtou::Error")) {
Branch: 1 branch
BranchTrueFalseTotal
|| !sv_derived_from(err_sv, "GraphQL::Houtou::Error")) { 0 10 10
5814 0 return;
5815 }
5816 10 err_hv = (HV *)SvRV(err_sv);
5817 10 msgp = hv_fetchs(err_hv, "message", 0);
5818 10 ▶ if (!msgp || !*msgp || !SvOK(*msgp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (!msgp || !*msgp || !SvOK(*msgp)) { 10 0 10
if (!msgp || !*msgp || !SvOK(*msgp)) { 10 0 10
if (!msgp || !*msgp || !SvOK(*msgp)) { 0 10 10
5819 0 return;
5820 }
5821 10 desc_sv = gql_runtime_vm_variable_value_desc_sv(aTHX_ raw_sv);
5822 10 message_sv = newSVpvf(
5823 "Variable \"$%s\" got invalid value %" SVf "; %" SVf,
5824 name, SVfARG(desc_sv), SVfARG(*msgp)
5825 );
5826 10 SvREFCNT_dec(desc_sv);
5827 10 (void)hv_stores(err_hv, "message", message_sv);
5828 }
5829  
5830 /* Request error for a Non-Null variable with no value and no default,
5831 * raised while coercing variables (spec CoerceVariableValues) instead of
5832 * later inside argument specialization, so the message can carry the
5833 * variable name and declared type. */
5834 static SV *
5835 3 gql_runtime_vm_missing_variable_error_sv(pTHX_ SV *type_sv, const char *name)
5836 {
5837 3 dSP;
5838 3 SV *type_str_sv = NULL;
5839 SV *message_sv;
5840 HV *error_hv;
5841 SV *err;
5842 int count;
5843  
5844 3 ENTER;
5845 3 SAVETMPS;
5846 3 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 3 0 3
5847 3 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 3 3
5848 3 ▶ XPUSHs(type_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(type_sv); 0 3 3
5849 3 PUTBACK;
5850 3 count = call_method("to_string", G_SCALAR | G_EVAL);
5851 3 SPAGAIN;
5852 3 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 3 0 3
if (SvTRUE(ERRSV)) { 0 3 3
5853 0 ▶ sv_setsv(ERRSV, &PL_sv_undef);
Branch: 1 branch
BranchTrueFalseTotal
sv_setsv(ERRSV, &PL_sv_undef); 0 0 0
5854 3 ▶ } else if (count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (count > 0) { 3 0 3
5855 3 type_str_sv = newSVsv(POPs);
5856 }
5857 3 PUTBACK;
5858 3 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 3 0 3
5859 3 LEAVE;
5860  
5861 3 ▶ if (type_str_sv && SvOK(type_str_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (type_str_sv && SvOK(type_str_sv)) { 3 0 3
if (type_str_sv && SvOK(type_str_sv)) { 3 0 3
5862 3 message_sv = newSVpvf(
5863 "Variable \"$%s\" of required type \"%" SVf "\" was not provided.",
5864 name, SVfARG(type_str_sv)
5865 );
5866 } else {
5867 0 message_sv = newSVpvf("Variable \"$%s\" of required type was not provided.", name);
5868 }
5869 3 SvREFCNT_dec(type_str_sv);
5870  
5871 3 error_hv = newHV();
5872 3 (void)hv_stores(error_hv, "message", message_sv);
5873 3 err = newRV_noinc((SV *)error_hv);
5874 3 sv_bless(err, gv_stashpvs("GraphQL::Houtou::Error", GV_ADD));
5875 3 return err;
5876 }
5877  
5878 static SV *
5879 2191 gql_runtime_vm_prepare_program_variables_into_slots_sv(
5880 pTHX_
5881 SV *runtime_schema,
5882 gql_runtime_vm_native_program_t *program,
5883 HV *provided_hv,
5884 SV **variable_slots,
5885 IV variable_slot_capacity,
5886 U8 slots_only
5887 )
5888 {
5889 2191 HV *coerced_hv = NULL;
5890 2191 AV *coerced_av = NULL;
5891 SV *coerced_rv;
5892 IV i;
5893  
5894 2191 ▶ if (slots_only) {
Branch: 1 branch
BranchTrueFalseTotal
if (slots_only) { 359 1832 2191
5895 359 coerced_av = newAV();
5896 359 ▶ if (program && program->variable_def_count > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (program && program->variable_def_count > 0) { 359 0 359
if (program && program->variable_def_count > 0) { 278 81 359
5897 278 av_extend(coerced_av, program->variable_def_count - 1);
5898 }
5899 359 coerced_rv = sv_2mortal(newRV_noinc((SV *)coerced_av));
5900 } else {
5901 1832 coerced_hv = newHV();
5902 1832 coerced_rv = sv_2mortal(newRV_noinc((SV *)coerced_hv));
5903 }
5904 /* The mortal owner reclaims every value stored so far if coercion
5905 * croaks. In slots-only mode the AV is the request-scoped value owner;
5906 * variable_slots merely borrows its entries. */
5907  
5908 5015 ▶ for (i = 0; program && i < program->variable_def_count; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; program && i < program->variable_def_count; i++) { 5015 0 5015
for (i = 0; program && i < program->variable_def_count; i++) { 2837 2178 5015
5909 2837 gql_runtime_vm_native_arg_def_t *arg_def = &program->variable_defs[i];
5910 2837 STRLEN name_len = 0;
5911 2837 SV *raw_sv = NULL;
5912 2837 SV *coerced_sv = NULL;
5913 2837 U8 has_value = 0;
5914  
5915 2837 ▶ if (!arg_def->name) {
Branch: 1 branch
BranchTrueFalseTotal
if (!arg_def->name) { 0 2837 2837
5916 0 continue;
5917 }
5918  
5919 2837 name_len = strlen(arg_def->name);
5920 2837 gql_runtime_vm_finalize_native_arg_def(aTHX_ runtime_schema, arg_def);
5921  
5922 2837 ▶ if (provided_hv && hv_exists(provided_hv, arg_def->name, (I32)name_len)) {
Branch: 2 branches
BranchTrueFalseTotal
if (provided_hv && hv_exists(provided_hv, arg_def->name, (I32)name_len)) { 2832 5 2837
if (provided_hv && hv_exists(provided_hv, arg_def->name, (I32)name_len)) { 2823 9 2832
5923 2823 SV **provided_svp = hv_fetch(provided_hv, arg_def->name, (I32)name_len, 0);
5924 /*
5925 * Borrow the input HV's value for the duration of coercion. The
5926 * provided variables hash outlives this call and the coercer returns
5927 * a separately owned SV, so cloning the raw scalar here only adds a
5928 * request-time allocation/refcount round trip.
5929 */
5930 2823 ▶ raw_sv = provided_svp ? *provided_svp : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
raw_sv = provided_svp ? *provided_svp : &PL_sv_undef; 2823 0 2823
5931 2823 has_value = 1;
5932 14 ▶ } else if (arg_def->has_default && arg_def->default_native_value) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_native_value) { 7 7 14
} else if (arg_def->has_default && arg_def->default_native_value) { 7 0 7
5933 7 coerced_sv = gql_runtime_vm_native_value_materialize_sv(aTHX_ arg_def->default_native_value);
5934 7 ▶ } else if (arg_def->has_default && arg_def->default_value_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 7 7
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
5935 0 raw_sv = sv_2mortal(newSVsv(arg_def->default_value_sv));
5936 }
5937  
5938 2837 ▶ if (!has_value && !raw_sv && !coerced_sv) {
Branch: 3 branches
BranchTrueFalseTotal
if (!has_value && !raw_sv && !coerced_sv) { 14 2823 2837
if (!has_value && !raw_sv && !coerced_sv) { 14 0 14
if (!has_value && !raw_sv && !coerced_sv) { 7 7 14
5939 7 ▶ if (arg_def->input_type_nonnull_state == 0
Branch: 1 branch
BranchTrueFalseTotal
if (arg_def->input_type_nonnull_state == 0 7 0 7
5940 7 ▶ && arg_def->input_type_sv && SvOK(arg_def->input_type_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
&& arg_def->input_type_sv && SvOK(arg_def->input_type_sv)) { 7 0 7
&& arg_def->input_type_sv && SvOK(arg_def->input_type_sv)) { 7 0 7
5941 7 ▶ arg_def->input_type_nonnull_state = sv_derived_from(
Branch: 1 branch
BranchTrueFalseTotal
arg_def->input_type_nonnull_state = sv_derived_from( 3 4 7
5942 arg_def->input_type_sv, "GraphQL::Houtou::Type::NonNull"
5943 ) ? 1 : 2;
5944 }
5945 7 ▶ if (arg_def->input_type_nonnull_state == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (arg_def->input_type_nonnull_state == 1) { 3 4 7
5946 3 croak_sv(sv_2mortal(gql_runtime_vm_missing_variable_error_sv(
5947 aTHX_ arg_def->input_type_sv, arg_def->name
5948 )));
5949 }
5950 4 continue;
5951 }
5952  
5953 2830 ▶ if (!coerced_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!coerced_sv) { 2823 7 2830
5954 2823 SV *coerce_err = NULL;
5955 2823 coerced_sv = gql_runtime_vm_coerce_input_value_sv(
5956 aTHX_ arg_def->input_type_sv, raw_sv, &coerce_err
5957 );
5958 2823 ▶ if (coerce_err) {
Branch: 1 branch
BranchTrueFalseTotal
if (coerce_err) { 10 2813 2823
5959 /* The placeholder undef from the deferred-croak contract. */
5960 10 SvREFCNT_dec(coerced_sv);
5961 /* Only client-provided values get the "got invalid value" context;
5962 * a failing default keeps the raw coercion message (defaults are
5963 * already validated against their declared types at build time). */
5964 10 ▶ if (has_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_value) { 10 0 10
5965 10 gql_runtime_vm_variable_error_prepend_context(
5966 10 aTHX_ coerce_err, arg_def->name, raw_sv
5967 );
5968 }
5969 10 croak_sv(sv_2mortal(coerce_err));
5970 }
5971 }
5972 2820 ▶ if (slots_only) {
Branch: 1 branch
BranchTrueFalseTotal
if (slots_only) { 474 2346 2820
5973 474 av_store(coerced_av, i, coerced_sv);
5974 } else {
5975 2346 hv_store(coerced_hv, arg_def->name, (I32)name_len, coerced_sv, 0);
5976 }
5977 2820 ▶ if (variable_slots && i < variable_slot_capacity) {
Branch: 2 branches
BranchTrueFalseTotal
if (variable_slots && i < variable_slot_capacity) { 474 2346 2820
if (variable_slots && i < variable_slot_capacity) { 474 0 474
5978 /* Borrowed from coerced_hv/coerced_av for the request. */
5979 474 variable_slots[i] = coerced_sv;
5980 }
5981 }
5982  
5983 2178 ▶ if (!slots_only && provided_hv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!slots_only && provided_hv) { 1832 346 2178
if (!slots_only && provided_hv) { 1553 279 1832
5984 HE *he;
5985 1553 hv_iterinit(provided_hv);
5986 3896 ▶ while ((he = hv_iternext(provided_hv))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(provided_hv))) { 2343 1553 3896
5987 2343 SV *key_sv = hv_iterkeysv(he);
5988 2343 SV *value_sv = hv_iterval(provided_hv, he);
5989 2343 STRLEN key_len = 0;
5990 const char *key_pv;
5991  
5992 2343 ▶ if (!key_sv || !SvOK(key_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!key_sv || !SvOK(key_sv)) { 2343 0 2343
if (!key_sv || !SvOK(key_sv)) { 0 2343 2343
5993 2343 continue;
5994 }
5995 2343 key_pv = SvPV(key_sv, key_len);
5996 2343 ▶ if (hv_exists(coerced_hv, key_pv, (I32)key_len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(coerced_hv, key_pv, (I32)key_len)) { 2343 0 2343
5997 2343 continue;
5998 }
5999 0 hv_store(coerced_hv, key_pv, (I32)key_len, newSVsv(value_sv), 0);
6000 }
6001 }
6002  
6003 2178 return SvREFCNT_inc_simple_NN(coerced_rv);
6004 }
6005  
6006 static SV *
6007 1832 gql_runtime_vm_prepare_program_variables_sv(
6008 pTHX_
6009 SV *runtime_schema,
6010 gql_runtime_vm_native_program_t *program,
6011 HV *provided_hv
6012 )
6013 {
6014 1832 return gql_runtime_vm_prepare_program_variables_into_slots_sv(
6015 aTHX_
6016 runtime_schema,
6017 program,
6018 provided_hv,
6019 NULL,
6020 0,
6021 0
6022 );
6023 }
6024  
6025 static SV *
6026 5 gql_runtime_vm_specialize_one_arg_sv(
6027 pTHX_
6028 const gql_runtime_vm_native_runtime_t *runtime,
6029 const gql_runtime_vm_native_slot_t *slot,
6030 const gql_runtime_vm_native_op_t *op,
6031 HV *variables_hv,
6032 SV **variable_slots,
6033 IV variable_slot_count,
6034 SV **croak_out
6035 )
6036 {
6037 const gql_runtime_vm_native_slot_t *effective_slot =
6038 5 gql_runtime_vm_effective_slot(runtime, slot);
6039 5 const gql_runtime_vm_native_args_payload_t *payload =
6040 5 ▶ op ? op->args_payload_native : NULL;
Branch: 1 branch
BranchTrueFalseTotal
op ? op->args_payload_native : NULL; 5 0 5
6041 const gql_runtime_vm_native_arg_def_t *arg_def;
6042 const gql_runtime_vm_native_dynamic_value_t *raw_value;
6043 5 SV *raw_sv = NULL;
6044 SV *coerced_sv;
6045  
6046 5 ▶ if (!effective_slot || effective_slot->arg_def_count != 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (!effective_slot || effective_slot->arg_def_count != 1) { 5 0 5
if (!effective_slot || effective_slot->arg_def_count != 1) { 0 5 5
6047 0 return newSVsv(&PL_sv_undef);
6048 }
6049 5 arg_def = &effective_slot->arg_defs[0];
6050 5 raw_value = gql_runtime_vm_native_args_payload_lookup_value(
6051 5 payload, arg_def->name, 0
6052 );
6053  
6054 5 ▶ if (raw_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (raw_value) { 4 1 5
6055 4 ▶ if (op
Branch: 1 branch
BranchTrueFalseTotal
if (op 4 0 4
6056 4 ▶ && op->args_mode_code == GQL_VM_ARGS_DYNAMIC
Branch: 1 branch
BranchTrueFalseTotal
&& op->args_mode_code == GQL_VM_ARGS_DYNAMIC 4 0 4
6057 4 ▶ && raw_value->kind_code == GQL_VM_DYNAMIC_VARIABLE
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->kind_code == GQL_VM_DYNAMIC_VARIABLE 4 0 4
6058 4 ▶ && raw_value->variable_name) {
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->variable_name) { 4 0 4
6059 4 SV **prepared_svp = NULL;
6060 4 ▶ if (raw_value->variable_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (raw_value->variable_index >= 0 4 0 4
6061 4 ▶ && variable_slots
Branch: 1 branch
BranchTrueFalseTotal
&& variable_slots 2 2 4
6062 2 ▶ && raw_value->variable_index < variable_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->variable_index < variable_slot_count) { 2 0 2
6063 2 prepared_svp = &variable_slots[raw_value->variable_index];
6064 2 ▶ } else if (variables_hv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (variables_hv) { 2 0 2
6065 2 prepared_svp = hv_fetch(
6066 variables_hv,
6067 raw_value->variable_name,
6068 (I32)strlen(raw_value->variable_name),
6069 0
6070 );
6071 }
6072 4 ▶ if (prepared_svp && *prepared_svp) {
Branch: 2 branches
BranchTrueFalseTotal
if (prepared_svp && *prepared_svp) { 3 1 4
if (prepared_svp && *prepared_svp) { 3 0 3
6073 3 ▶ if (SvOK(*prepared_svp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(*prepared_svp)) { 2 1 3
6074 2 return newSVsv(*prepared_svp);
6075 }
6076 /* An explicitly provided null remains null and must not activate
6077 * the argument default. It still passes through argument coercion
6078 * so an invalid nullable-variable/non-null-argument combination is
6079 * rejected when validation was deliberately skipped. */
6080 1 raw_sv = sv_2mortal(newSVsv(*prepared_svp));
6081 } else {
6082 /* A variable reference whose variable was not provided behaves as
6083 * an absent argument. CoerceArgumentValues applies the field
6084 * argument default in this case. */
6085 1 ▶ if (arg_def->has_default && arg_def->default_native_value) {
Branch: 2 branches
BranchTrueFalseTotal
if (arg_def->has_default && arg_def->default_native_value) { 1 0 1
if (arg_def->has_default && arg_def->default_native_value) { 1 0 1
6086 1 return gql_runtime_vm_native_value_materialize_sv(
6087 1 aTHX_ arg_def->default_native_value
6088 );
6089 }
6090 0 ▶ if (arg_def->has_default && arg_def->default_value_sv) {
Branch: 2 branches
BranchTrueFalseTotal
if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
6091 0 raw_sv = sv_2mortal(newSVsv(arg_def->default_value_sv));
6092 } else {
6093 0 return newSVsv(&PL_sv_undef);
6094 }
6095 }
6096 }
6097 1 ▶ if (!raw_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!raw_sv) { 0 1 1
6098 0 ▶ raw_sv = sv_2mortal(gql_runtime_vm_native_dynamic_value_materialize_sv(
Branch: 2 branches
BranchTrueFalseTotal
raw_sv = sv_2mortal(gql_runtime_vm_native_dynamic_value_materialize_sv( 0 0 0
raw_sv = sv_2mortal(gql_runtime_vm_native_dynamic_value_materialize_sv( 0 0 0
6099 aTHX_ raw_value,
6100 (op && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) ? variables_hv : NULL
6101 ));
6102 }
6103 1 ▶ } else if (arg_def->has_default && arg_def->default_native_value) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_native_value) { 1 0 1
} else if (arg_def->has_default && arg_def->default_native_value) { 1 0 1
6104 1 return gql_runtime_vm_native_value_materialize_sv(
6105 1 aTHX_ arg_def->default_native_value
6106 );
6107 0 ▶ } else if (arg_def->has_default && arg_def->default_value_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
6108 0 raw_sv = sv_2mortal(newSVsv(arg_def->default_value_sv));
6109 } else {
6110 0 return newSVsv(&PL_sv_undef);
6111 }
6112  
6113 1 coerced_sv = gql_runtime_vm_coerce_input_value_sv(
6114 1 aTHX_ arg_def->input_type_sv, raw_sv, croak_out
6115 );
6116 1 ▶ if (croak_out && *croak_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (croak_out && *croak_out) { 1 0 1
if (croak_out && *croak_out) { 0 1 1
6117 0 SvREFCNT_dec(coerced_sv);
6118 0 return NULL;
6119 }
6120 1 return coerced_sv;
6121 }
6122  
6123 static SV *
6124 6062 gql_runtime_vm_specialize_arg_payload_sv(
6125 pTHX_
6126 const gql_runtime_vm_native_runtime_t *runtime,
6127 const gql_runtime_vm_native_slot_t *slot,
6128 const gql_runtime_vm_native_op_t *op,
6129 HV *variables_hv,
6130 SV **variable_slots,
6131 IV variable_slot_count,
6132 SV **croak_out
6133 )
6134 {
6135 HV *coerced_hv;
6136 SV *coerced_rv;
6137 6062 const gql_runtime_vm_native_args_payload_t *payload = op->args_payload_native;
6138 6062 const gql_runtime_vm_native_slot_t *effective_slot = gql_runtime_vm_effective_slot(runtime, slot);
6139 IV i;
6140  
6141 6062 coerced_hv = newHV();
6142 /* Owned by a mortal wrapper so a croak from coercion below reclaims the
6143 * hash during die unwinding. */
6144 6062 coerced_rv = sv_2mortal(newRV_noinc((SV *)coerced_hv));
6145 11386 ▶ for (i = 0; effective_slot && i < effective_slot->arg_def_count; i++) {
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; effective_slot && i < effective_slot->arg_def_count; i++) { 11386 0 11386
for (i = 0; effective_slot && i < effective_slot->arg_def_count; i++) { 5327 6059 11386
6146 5327 const gql_runtime_vm_native_arg_def_t *arg_def = &effective_slot->arg_defs[i];
6147 5327 SV *raw_sv = NULL;
6148 5327 SV *coerced_sv = NULL;
6149 5327 const gql_runtime_vm_native_dynamic_value_t *raw_value = NULL;
6150  
6151 5327 raw_value = gql_runtime_vm_native_args_payload_lookup_value(payload, arg_def->name, i);
6152  
6153 5327 ▶ if (raw_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (raw_value) { 5165 162 5327
6154 /*
6155 * A top-level variable reference already points at the result of
6156 * CoerceVariableValues. GraphQL's CoerceArgumentValues consumes that
6157 * prepared value directly; coercing it again here is both redundant
6158 * and observable for custom input coercers. Keep nested variable
6159 * references on the materialize/coerce path because the surrounding
6160 * list or input-object literal still has to be coerced as a whole.
6161 */
6162 5165 ▶ if (op->args_mode_code == GQL_VM_ARGS_DYNAMIC
Branch: 1 branch
BranchTrueFalseTotal
if (op->args_mode_code == GQL_VM_ARGS_DYNAMIC 5042 123 5165
6163 5042 ▶ && raw_value->kind_code == GQL_VM_DYNAMIC_VARIABLE
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->kind_code == GQL_VM_DYNAMIC_VARIABLE 5038 4 5042
6164 5038 ▶ && raw_value->variable_name) {
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->variable_name) { 5038 0 5038
6165 5038 SV **prepared_svp = NULL;
6166 5038 ▶ if (raw_value->variable_index >= 0
Branch: 1 branch
BranchTrueFalseTotal
if (raw_value->variable_index >= 0 5038 0 5038
6167 5038 ▶ && variable_slots
Branch: 1 branch
BranchTrueFalseTotal
&& variable_slots 2295 2743 5038
6168 2295 ▶ && raw_value->variable_index < variable_slot_count) {
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->variable_index < variable_slot_count) { 2295 0 2295
6169 2295 prepared_svp = &variable_slots[raw_value->variable_index];
6170 2743 ▶ } else if (variables_hv) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (variables_hv) { 2743 0 2743
6171 2743 prepared_svp = hv_fetch(
6172 variables_hv,
6173 raw_value->variable_name,
6174 (I32)strlen(raw_value->variable_name),
6175 0
6176 );
6177 }
6178 5038 ▶ if (prepared_svp && *prepared_svp) {
Branch: 2 branches
BranchTrueFalseTotal
if (prepared_svp && *prepared_svp) { 5037 1 5038
if (prepared_svp && *prepared_svp) { 5036 1 5037
6179 /*
6180 * A non-null prepared variable is already argument-coerced. Null
6181 * still passes through coercion so an invalid nullable-variable /
6182 * non-null-argument combination fails when validation was skipped.
6183 */
6184 5036 ▶ if (SvOK(*prepared_svp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(*prepared_svp)) { 5034 2 5036
6185 5034 hv_store(
6186 coerced_hv,
6187 arg_def->name,
6188 (I32)strlen(arg_def->name),
6189 newSVsv(*prepared_svp),
6190 0
6191 );
6192 5034 continue;
6193 }
6194 2 raw_sv = sv_2mortal(newSVsv(*prepared_svp));
6195 } else {
6196 /* An omitted variable makes the argument absent, allowing the
6197 * field argument default to apply. */
6198 2 ▶ if (arg_def->has_default && arg_def->default_native_value) {
Branch: 2 branches
BranchTrueFalseTotal
if (arg_def->has_default && arg_def->default_native_value) { 1 1 2
if (arg_def->has_default && arg_def->default_native_value) { 1 0 1
6199 1 coerced_sv = gql_runtime_vm_native_value_materialize_sv(
6200 1 aTHX_ arg_def->default_native_value
6201 );
6202 1 hv_store(
6203 coerced_hv,
6204 arg_def->name,
6205 (I32)strlen(arg_def->name),
6206 coerced_sv,
6207 0
6208 );
6209 1 ▶ } else if (arg_def->has_default && arg_def->default_value_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 1 1
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
6210 0 raw_sv = sv_2mortal(newSVsv(arg_def->default_value_sv));
6211 } else {
6212 1 continue;
6213 }
6214 }
6215 }
6216 130 ▶ if (!raw_sv && !coerced_sv && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) {
Branch: 3 branches
BranchTrueFalseTotal
if (!raw_sv && !coerced_sv && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) { 128 2 130
if (!raw_sv && !coerced_sv && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) { 127 1 128
if (!raw_sv && !coerced_sv && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) { 4 123 127
6217 4 raw_sv = sv_2mortal(gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ raw_value, variables_hv));
6218 126 ▶ } else if (!raw_sv && !coerced_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (!raw_sv && !coerced_sv) { 124 2 126
} else if (!raw_sv && !coerced_sv) { 123 1 124
6219 123 raw_sv = sv_2mortal(gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ raw_value, NULL));
6220 }
6221 130 ▶ if (coerced_sv) {
Branch: 1 branch
BranchTrueFalseTotal
if (coerced_sv) { 1 129 130
6222 1 continue;
6223 }
6224 162 ▶ } else if (arg_def->has_default && arg_def->default_native_value) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_native_value) { 24 138 162
} else if (arg_def->has_default && arg_def->default_native_value) { 24 0 24
6225 24 coerced_sv = gql_runtime_vm_native_value_materialize_sv(aTHX_ arg_def->default_native_value);
6226 24 hv_store(coerced_hv, arg_def->name, (I32)strlen(arg_def->name), coerced_sv, 0);
6227 24 continue;
6228 138 ▶ } else if (arg_def->has_default && arg_def->default_value_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 138 138
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
6229 0 raw_sv = sv_2mortal(newSVsv(arg_def->default_value_sv));
6230 } else {
6231 138 continue;
6232 }
6233  
6234 129 coerced_sv = gql_runtime_vm_coerce_input_value_sv(aTHX_ arg_def->input_type_sv, raw_sv, croak_out);
6235 129 ▶ if (croak_out && *croak_out) {
Branch: 2 branches
BranchTrueFalseTotal
if (croak_out && *croak_out) { 6 123 129
if (croak_out && *croak_out) { 3 3 6
6236 /* Deferred coercion failure: the partial hash is reclaimed by its
6237 * mortal wrapper; the caller routes the error to the state's
6238 * deferred croak channel. */
6239 3 SvREFCNT_dec(coerced_sv);
6240 3 return NULL;
6241 }
6242 126 hv_store(coerced_hv, arg_def->name, (I32)strlen(arg_def->name), coerced_sv, 0);
6243 }
6244  
6245 6059 ▶ if (HvUSEDKEYS(coerced_hv) == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (HvUSEDKEYS(coerced_hv) == 0) { 0 6059 6059
if (HvUSEDKEYS(coerced_hv) == 0) { 889 5170 6059
6246 889 return NULL;
6247 }
6248 5170 return SvREFCNT_inc_simple_NN(coerced_rv);
6249 }
6250  
6251 /*
6252 * Croak-safety net for a partially built native args payload: coercion can
6253 * die mid-loop, and the longjmp would otherwise leak the payload skeleton
6254 * plus everything specialized so far. Registered on Perl's save stack; the
6255 * builder disarms it by clearing the payload slot on its normal exits.
6256 */
6257 static void
6258 120 gql_runtime_vm_args_payload_guard_fire(pTHX_ void *ptr)
6259 {
6260 120 gql_runtime_vm_native_args_payload_t **payload_slot =
6261 (gql_runtime_vm_native_args_payload_t **)ptr;
6262 120 ▶ if (payload_slot) {
Branch: 1 branch
BranchTrueFalseTotal
if (payload_slot) { 120 0 120
6263 120 ▶ if (*payload_slot) {
Branch: 1 branch
BranchTrueFalseTotal
if (*payload_slot) { 8 112 120
6264 8 gql_runtime_vm_native_args_payload_destroy(aTHX_ *payload_slot);
6265 }
6266 120 Safefree(payload_slot);
6267 }
6268 120 }
6269  
6270 static gql_runtime_vm_native_args_payload_t *
6271 120 gql_runtime_vm_specialize_arg_payload_native(
6272 pTHX_
6273 const gql_runtime_vm_native_runtime_t *runtime,
6274 const gql_runtime_vm_native_slot_t *slot,
6275 const gql_runtime_vm_native_op_t *op,
6276 HV *variables_hv
6277 )
6278 {
6279 120 ▶ const gql_runtime_vm_native_args_payload_t *payload = op ? op->args_payload_native : NULL;
Branch: 1 branch
BranchTrueFalseTotal
const gql_runtime_vm_native_args_payload_t *payload = op ? op->args_payload_native : NULL; 120 0 120
6280 120 const gql_runtime_vm_native_slot_t *effective_slot = gql_runtime_vm_effective_slot(runtime, slot);
6281 gql_runtime_vm_native_args_payload_t *ret;
6282 gql_runtime_vm_native_args_payload_t **payload_guard;
6283 IV i;
6284  
6285 120 ▶ if (!effective_slot || effective_slot->arg_def_count <= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (!effective_slot || effective_slot->arg_def_count <= 0) { 120 0 120
if (!effective_slot || effective_slot->arg_def_count <= 0) { 0 120 120
6286 0 return NULL;
6287 }
6288  
6289 120 Newxz(ret, 1, gql_runtime_vm_native_args_payload_t);
6290 120 ▶ Newxz(ret->names, effective_slot->arg_def_count, char *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->names, effective_slot->arg_def_count, char *); 0 120 120
6291 120 ▶ Newxz(ret->values, effective_slot->arg_def_count, gql_runtime_vm_native_dynamic_value_t *);
Branch: 1 branch
BranchTrueFalseTotal
Newxz(ret->values, effective_slot->arg_def_count, gql_runtime_vm_native_dynamic_value_t *); 0 120 120
6292 120 Newxz(payload_guard, 1, gql_runtime_vm_native_args_payload_t *);
6293 120 *payload_guard = ret;
6294 120 SAVEDESTRUCTOR_X(gql_runtime_vm_args_payload_guard_fire, payload_guard);
6295  
6296 270 ▶ for (i = 0; i < effective_slot->arg_def_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < effective_slot->arg_def_count; i++) { 158 112 270
6297 158 const gql_runtime_vm_native_arg_def_t *arg_def = &effective_slot->arg_defs[i];
6298 const gql_runtime_vm_native_dynamic_value_t *raw_value =
6299 158 gql_runtime_vm_native_args_payload_lookup_value(payload, arg_def->name, i);
6300 158 gql_runtime_vm_native_dynamic_value_t *coerced_value = NULL;
6301  
6302 158 ▶ if (raw_value) {
Branch: 1 branch
BranchTrueFalseTotal
if (raw_value) { 125 33 158
6303 125 SV *raw_sv = NULL;
6304 SV *coerced_sv;
6305 125 ▶ if (op
Branch: 1 branch
BranchTrueFalseTotal
if (op 125 0 125
6306 125 ▶ && op->args_mode_code == GQL_VM_ARGS_DYNAMIC
Branch: 1 branch
BranchTrueFalseTotal
&& op->args_mode_code == GQL_VM_ARGS_DYNAMIC 1 124 125
6307 1 ▶ && raw_value->kind_code == GQL_VM_DYNAMIC_VARIABLE
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->kind_code == GQL_VM_DYNAMIC_VARIABLE 1 0 1
6308 1 ▶ && raw_value->variable_name
Branch: 1 branch
BranchTrueFalseTotal
&& raw_value->variable_name 1 0 1
6309 1 ▶ && variables_hv) {
Branch: 1 branch
BranchTrueFalseTotal
&& variables_hv) { 1 0 1
6310 1 SV **prepared_svp = hv_fetch(
6311 variables_hv,
6312 raw_value->variable_name,
6313 (I32)strlen(raw_value->variable_name),
6314 0
6315 );
6316 1 ▶ if (prepared_svp && *prepared_svp && SvOK(*prepared_svp)) {
Branch: 3 branches
BranchTrueFalseTotal
if (prepared_svp && *prepared_svp && SvOK(*prepared_svp)) { 1 0 1
if (prepared_svp && *prepared_svp && SvOK(*prepared_svp)) { 1 0 1
if (prepared_svp && *prepared_svp && SvOK(*prepared_svp)) { 1 0 1
6317 1 coerced_value = gql_runtime_vm_native_dynamic_value_from_sv(
6318 aTHX_ *prepared_svp
6319 );
6320 1 ret->names[ret->count] = savepv(arg_def->name);
6321 1 ret->values[ret->count] = coerced_value;
6322 1 ret->count++;
6323 1 continue;
6324 }
6325 }
6326 124 ▶ if (op && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) {
Branch: 2 branches
BranchTrueFalseTotal
if (op && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) { 124 0 124
if (op && op->args_mode_code == GQL_VM_ARGS_DYNAMIC) { 0 124 124
6327 0 raw_sv = sv_2mortal(gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ raw_value, variables_hv));
6328 } else {
6329 124 raw_sv = sv_2mortal(gql_runtime_vm_native_dynamic_value_materialize_sv(aTHX_ raw_value, NULL));
6330 }
6331 124 coerced_sv = sv_2mortal(gql_runtime_vm_coerce_input_value_sv(aTHX_ arg_def->input_type_sv, raw_sv, NULL));
6332 116 coerced_value = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ coerced_sv);
6333 33 ▶ } else if (arg_def->has_default && arg_def->default_native_value) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_native_value) { 1 32 33
} else if (arg_def->has_default && arg_def->default_native_value) { 1 0 1
6334 1 coerced_value = gql_runtime_vm_native_dynamic_value_from_native_value(
6335 1 aTHX_ arg_def->default_native_value
6336 );
6337 32 ▶ } else if (arg_def->has_default && arg_def->default_value_sv) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 32 32
} else if (arg_def->has_default && arg_def->default_value_sv) { 0 0 0
6338 0 SV *raw_sv = sv_2mortal(newSVsv(arg_def->default_value_sv));
6339 0 SV *coerced_sv = sv_2mortal(gql_runtime_vm_coerce_input_value_sv(aTHX_ arg_def->input_type_sv, raw_sv, NULL));
6340 0 coerced_value = gql_runtime_vm_native_dynamic_value_from_sv(aTHX_ coerced_sv);
6341 } else {
6342 32 continue;
6343 }
6344  
6345 117 ret->names[ret->count] = savepv(arg_def->name);
6346 117 ret->values[ret->count] = coerced_value;
6347 117 ret->count++;
6348 }
6349  
6350 112 *payload_guard = NULL;
6351  
6352 112 ▶ if (ret->count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ret->count == 0) { 0 112 112
6353 0 gql_runtime_vm_native_args_payload_destroy(aTHX_ ret);
6354 0 return NULL;
6355 }
6356  
6357 112 return ret;
6358 }
6359  
6360 static void
6361 41 gql_runtime_vm_specialize_native_program_in_place(
6362 pTHX_
6363 gql_runtime_vm_native_runtime_t *runtime,
6364 gql_runtime_vm_native_program_t *program,
6365 HV *variables_hv
6366 )
6367 {
6368 IV i;
6369  
6370 41 ▶ if (!program) {
Branch: 1 branch
BranchTrueFalseTotal
if (!program) { 0 41 41
6371 0 return;
6372 }
6373  
6374 116 ▶ for (i = 0; i < program->block_count; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < program->block_count; i++) { 75 41 116
6375 75 gql_runtime_vm_native_block_t *block = &program->blocks[i];
6376 IV read_index;
6377 75 IV write_index = 0;
6378  
6379 189 ▶ for (read_index = 0; read_index < block->op_count; read_index++) {
Branch: 1 branch
BranchTrueFalseTotal
for (read_index = 0; read_index < block->op_count; read_index++) { 114 75 189
6380 114 gql_runtime_vm_native_op_t *op = &block->ops[read_index];
6381 114 const gql_runtime_vm_native_slot_t *slot = NULL;
6382 114 int keep = 1;
6383  
6384 114 ▶ 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) { 114 0 114
if (op->slot_index >= 0 && op->slot_index < block->slot_count) { 114 0 114
6385 114 slot = &block->slots[op->slot_index];
6386 }
6387  
6388 114 ▶ if (op->has_directives && op->directives_mode_code == GQL_VM_ARGS_DYNAMIC) {
Branch: 2 branches
BranchTrueFalseTotal
if (op->has_directives && op->directives_mode_code == GQL_VM_ARGS_DYNAMIC) { 0 114 114
if (op->has_directives && op->directives_mode_code == GQL_VM_ARGS_DYNAMIC) { 0 0 0
6389 0 ▶ if (!gql_runtime_vm_evaluate_runtime_guards_native(
Branch: 1 branch
BranchTrueFalseTotal
if (!gql_runtime_vm_evaluate_runtime_guards_native( 0 0 0
6390 aTHX_
6391 0 op->directives_payload_native,
6392 variables_hv,
6393 NULL,
6394 0
6395 )) {
6396 0 keep = 0;
6397 } else {
6398 0 op->has_directives = 0;
6399 0 op->directives_mode_code = GQL_VM_ARGS_NONE;
6400 0 gql_runtime_vm_native_directives_payload_destroy(aTHX_ op->directives_payload_native);
6401 0 op->directives_payload_native = NULL;
6402 }
6403 }
6404  
6405 114 ▶ if (keep && slot && (slot->arg_def_count > 0 || op->has_args)) {
Branch: 4 branches
BranchTrueFalseTotal
if (keep && slot && (slot->arg_def_count > 0 || op->has_args)) { 114 0 114
if (keep && slot && (slot->arg_def_count > 0 || op->has_args)) { 114 0 114
if (keep && slot && (slot->arg_def_count > 0 || op->has_args)) { 108 6 114
if (keep && slot && (slot->arg_def_count > 0 || op->has_args)) { 0 108 108
6406 6 gql_runtime_vm_native_args_payload_t *specialized_payload = gql_runtime_vm_specialize_arg_payload_native(
6407 aTHX_ runtime, slot, op, variables_hv
6408 );
6409 6 gql_runtime_vm_native_args_payload_destroy(aTHX_ op->args_payload_native);
6410 6 op->args_payload_native = NULL;
6411 6 ▶ if (specialized_payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (specialized_payload) { 6 0 6
6412 6 op->args_payload_native = specialized_payload;
6413 6 op->args_mode_code = GQL_VM_ARGS_STATIC;
6414 6 op->has_args = 1;
6415 } else {
6416 0 op->args_mode_code = GQL_VM_ARGS_NONE;
6417 0 op->has_args = 0;
6418 }
6419 }
6420  
6421 114 ▶ if (!keep) {
Branch: 1 branch
BranchTrueFalseTotal
if (!keep) { 0 114 114
6422 /* Same asymmetry class as the destroy-path fix: the name strings
6423 * are owned per entry, so freeing only the array leaks them. */
6424 0 gql_runtime_vm_free_op_abstract_child_names(aTHX_ op);
6425 0 Safefree(op->abstract_child_indexes);
6426 0 gql_runtime_vm_native_args_payload_destroy(aTHX_ op->args_payload_native);
6427 0 op->args_payload_native = NULL;
6428 0 gql_runtime_vm_native_directives_payload_destroy(aTHX_ op->directives_payload_native);
6429 0 op->directives_payload_native = NULL;
6430 0 SvREFCNT_dec(op->runtime_directives_sv);
6431 0 op->runtime_directives_sv = NULL;
6432 0 Zero(op, 1, gql_runtime_vm_native_op_t);
6433 0 continue;
6434 }
6435  
6436 114 ▶ if (write_index != read_index) {
Branch: 1 branch
BranchTrueFalseTotal
if (write_index != read_index) { 0 114 114
6437 0 block->ops[write_index] = block->ops[read_index];
6438 0 Zero(&block->ops[read_index], 1, gql_runtime_vm_native_op_t);
6439 }
6440 114 write_index++;
6441 }
6442 75 block->op_count = write_index;
6443 }
6444 }
6445  
6446 #endif
« lib/GraphQL/Houtou.xs ↑ Summary src/parser_shared_ast.h »