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:
-
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. -
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
} } /* Required keywords, then optional keywords. Both are stored as * rbs_hash mapping name-Symbol → function_param. The hash is * insertion-ordered (head/tail linked list); RBS's parser inserts * kwargs in source order. We walk in that order, mapping each /* Required + optional keywords. Both are stored as rbs_hash * mapping name-Symbol → function_param. The hash is insertion- * ordered (head/tail linked list); RBS's parser inserts kwargs in * source order. We walk required then optional, mapping each * param's value type. The arity adds up to (positionals + * required_kwargs + optional_kwargs), matching Ruby's def in * source-order — same shape collect_all sees. Optionality is * an arity-affecting source property and doesn't change the * type slot the seed targets. */ if (fn->required_keywords != NULL) { rbs_hash_node_t *cur = fn->required_keywords->head; while (cur != NULL) { if (cur->value == NULL || cur->value->type != RBS_TYPES_FUNCTION_PARAM) { sbuf_free(&ptypes); return; } rbs_types_function_param_t *pp = (rbs_types_function_param_t *) cur->value; sbuf_t t; sbuf_init(&t); if (!map_type(p, pp->type, enclosing_scope, &t)) { sbuf_free(&t); sbuf_free(&ptypes); return; } if (!first_p) sbuf_append_cstr(&ptypes, ","); sbuf_append(&ptypes, t.buf, t.len); first_p = false; sbuf_free(&t); cur = cur->next; } } if (fn->optional_keywords != NULL) { rbs_hash_node_t *cur = fn->optional_keywords->head; * source-order — same shape collect_all sees. Optionality is an * arity-affecting source property and doesn't change the type * slot the seed targets. */ const rbs_hash_t *kw_hashes[] = { fn->required_keywords, fn->optional_keywords }; for (size_t ki = 0; ki < sizeof(kw_hashes)/sizeof(kw_hashes[0]); ki++) { const rbs_hash_t *hash = kw_hashes[ki]; if (hash == NULL) continue; rbs_hash_node_t *cur = hash->head; while (cur != NULL) { /* Defensive: an upstream rbs change adding a different * value-node type would land here. Skipping the whole * signature (rather than producing a partial seed) keeps * the analyzer consistent — apply_rbs_seeds overwrites a * method's ptype list wholesale, so a half-populated entry * is worse than no entry. Same policy as the positional * loop above and the existing out-of-subset early-return. */ if (cur->value == NULL || cur->value->type != RBS_TYPES_FUNCTION_PARAM) { sbuf_free(&ptypes); return; }