fix(codegen): resolve request.security TA index+length per call site (helper inlining)#47
Merged
luisleo526 merged 1 commit intoJul 7, 2026
Conversation
…(helper inlining) Two coupled fixes let a request.security nested in a multi-call helper transpile + compute correctly. Both are additive with a byte-identical fallback, so every already-transpiling strategy is unchanged (corpus 265/265 byte-identical). 1. History index (security.py). `f_secure_ema(tf, length, idxHigher, idxCurrent) => request.security(sym, tf, ta.ema(close, length)[idxHigher])[idxCurrent]` rejected because the TA history index `[idxHigher]` is a helper param, not a NumberLiteral. Add _resolve_security_index_literal: try the existing literal check first (short-circuit → identical), else resolve the index through the helper binding stack / global_expr_map and constant-fold batch-constant barstate flags (_fold_security_const_bool: isrealtime/islast→false, ishistory→true) — matching the flag folding codegen already does elsewhere. 2. Constructor length (base.py). A request.security in a helper called N times is cloned per call site (distinct sec_id + callsite_idx), but the shared TA site's ctor_args were resolved ONCE against call site 0 — so four security EMAs all sized from crossFastLen (21) instead of the per-site [21,55,21,55]. Route each sec's ctor-arg resolution through the existing per-call-site function-clone TA remap (_func_cs_ta_remap); identity for cs0/non-clones. Recovers officialjackofalltrades-concordance-execution-mandate-joat from transpile-error → STRONG (was: could not transpile). Entry/exit price p90 both 0.0000% exact, countAbsDelta 2 (residual is strategy-logic trade-count precision, not codegen — excellent needs exact count parity). pytest 1446 passed; clang exit 0. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two coupled, additive fixes let a
request.securitynested in a multi-call helper transpile and compute correctly. Both have a byte-identical fallback → every already-transpiling strategy is unchanged.Fixes
request.security(sym, tf, ta.ema(close, length)[idxHigher])inside a helper rejected[idxHigher](a helper param, not a NumberLiteral). Added_resolve_security_index_literal— tries the existing literal check first (short-circuit → identical), else resolves the index through the helper binding stack /global_expr_mapand constant-folds batch-constant barstate flags (matching the folding codegen already does elsewhere).crossFastLen(21) instead of per-site[21,55,21,55]. Route each sec's ctor-arg resolution through the existing per-call-site function-clone TA remap (_func_cs_ta_remap); identity for cs0/non-clones.Result
Recovers
officialjackofalltrades-concordance-execution-mandate-joatfrom transpile-error → strong (matchPct 99.1%, entry/exit price p90 both 0.0000% exact; residual countAbsDelta 2–3 is strategy-logic trade-count precision, not codegen — excellent needs exact count parity).Verification (fresh-context R7 = GO)
clang++exit 0.🤖 Generated with Claude Code