Commit 69aff436

69aff436d390Merged

Sam Ruby <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

review: dedup kwarg loops; clarify unexpected-node skip rationale

Address two review comments on this PR:

  1. The required-keywords and optional-keywords iteration was byte-identical. Replace the two loops with a single loop over a 2-element array of const rbs_hash_t * (required then optional) — same source-order traversal, half the code.

  2. Add a per-line comment on the unexpected-node-type early-return explaining why the policy is "skip the whole signature": apply_rbs_ seeds overwrites @cls_meth_ptypes wholesale, so a partial seed would be worse than no seed. Matches the existing policy for the positional loop and the out-of-subset early-return above.

Behavior unchanged. 538/538 spinel tests still pass; extractor output on the four-method probe (mixed positional + required-kw + optional- kw + rest-args) is byte-identical to the prior commit.

Details

Commit
69aff436d390
Parent
ec1622a9f193

spinel_rbs_extract.cmodifiedView file

@@ -435,35 +435,28 @@
435435 }
436436 }
437437
438- /* Required keywords, then optional keywords. Both are stored as
439- * rbs_hash mapping name-Symbol → function_param. The hash is
440- * insertion-ordered (head/tail linked list); RBS's parser inserts
441- * kwargs in source order. We walk in that order, mapping each
438+ /* Required + optional keywords. Both are stored as rbs_hash
439+ * mapping name-Symbol → function_param. The hash is insertion-
440+ * ordered (head/tail linked list); RBS's parser inserts kwargs in
441+ * source order. We walk required then optional, mapping each
442442 * param's value type. The arity adds up to (positionals +
443443 * required_kwargs + optional_kwargs), matching Ruby's def in
444- * source-order — same shape collect_all sees. Optionality is
445- * an arity-affecting source property and doesn't change the
446- * type slot the seed targets. */
447- if (fn->required_keywords != NULL) {
448- rbs_hash_node_t *cur = fn->required_keywords->head;
449- while (cur != NULL) {
450- if (cur->value == NULL || cur->value->type != RBS_TYPES_FUNCTION_PARAM) {
451- sbuf_free(&ptypes); return;
452- }
453- rbs_types_function_param_t *pp = (rbs_types_function_param_t *) cur->value;
454- sbuf_t t;
455- sbuf_init(&t);
456- if (!map_type(p, pp->type, enclosing_scope, &t)) { sbuf_free(&t); sbuf_free(&ptypes); return; }
457- if (!first_p) sbuf_append_cstr(&ptypes, ",");
458- sbuf_append(&ptypes, t.buf, t.len);
459- first_p = false;
460- sbuf_free(&t);
461- cur = cur->next;
462- }
463- }
464- if (fn->optional_keywords != NULL) {
465- rbs_hash_node_t *cur = fn->optional_keywords->head;
444+ * source-order — same shape collect_all sees. Optionality is an
445+ * arity-affecting source property and doesn't change the type
446+ * slot the seed targets. */
447+ const rbs_hash_t *kw_hashes[] = { fn->required_keywords, fn->optional_keywords };
448+ for (size_t ki = 0; ki < sizeof(kw_hashes)/sizeof(kw_hashes[0]); ki++) {
449+ const rbs_hash_t *hash = kw_hashes[ki];
450+ if (hash == NULL) continue;
451+ rbs_hash_node_t *cur = hash->head;
466452 while (cur != NULL) {
453+ /* Defensive: an upstream rbs change adding a different
454+ * value-node type would land here. Skipping the whole
455+ * signature (rather than producing a partial seed) keeps
456+ * the analyzer consistent — apply_rbs_seeds overwrites a
457+ * method's ptype list wholesale, so a half-populated entry
458+ * is worse than no entry. Same policy as the positional
459+ * loop above and the existing out-of-subset early-return. */
467460 if (cur->value == NULL || cur->value->type != RBS_TYPES_FUNCTION_PARAM) {
468461 sbuf_free(&ptypes); return;
469462 }