Repository navigation
Credit c_local arguments from programs that files loaded at any depth define, keep them after a later tokenize, and stop input types from defining variables - #423
Merged
Conversation
… define, keep them after a later tokenize, and stop input types from defining variables - A call credits a program's positional c_local names when the resolved execution scope defines the program at the call: files run, done or included at any depth, sight: do/run/include directives, the file actually run (resolved by path, not file name), an ado named after the program, and, from a program body, a file loaded anywhere in the file. A top-level program drop, a later or nested later definition, and a same-named file in another directory no longer credit it. - A tokenize, macro shift or local 1 after `c_local `1'' ran no longer erases the credit; if/else branches start from the state before them. - input (every spelling) no longer registers storage types such as double or str10 as variables. - Rename wildcard checks visit only the name's line; the variable prefix index lives for one analysis, so a changed declared-variable map is never answered from a stale index. Co-authored-by: Claude Opus 5.5 <[email protected]>
Contributor
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 59 minutes. View limit details
|
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.
#415 merged without independent review, and a cold review then found problems in it. The biggest one: valid projects got a false
`result' is not definedwhenever the program thatc_locals an argument came from a file loaded through another file or asight:directive. Its reachability check compared file names against the caller's owndo/runlines. This PR fixes that and the other findings.Positional
c_localcredit now uses the resolved execution scope. I chose the scope-based design over the fallback. The diagnostics provider's positional fallback now reads the forward call sites the scope resolver already builds. Those sites are transitive and resolved by path, and they includesight:directive sites. It walks statements in execution order, and each per-name lookup is built once. The analyzer keeps only what one file shows on its own: same-file definitions,program drop, and an ado named after the program. Its file-name matching is removed. The workspace index now keeps<name>.adowhen several files define a program, because that is the file Stata loads.These now report 0 issues (they reported 1 on main):
nestedrun,nesteddo,nestedinclude: main loadssetup.do, which loadslibrary.dodirective20,directive21(anddirective):// sight: do|include|run library.docollideado:setter.adobesidealib.do(always 1 on main in 3 runs)collideboth,selectcollision: the file actually run winsbodylaterload: a call in a program body, with the library loaded before the program is calledadolater: an ado named after the program, with a later same-file definition (main gave 0 or 1 depending on index order)These now warn (main reported 0):
basename:run a/lib.dowith the setter only inb/lib.dodropped: call afterprogram drop setterdirectnestedif,nesteddefinition: call before a definition insideif 1 { }These are unchanged:
a3(never loaded) and a later top-level definition still warn.statementorder(run library.do; setter result;on one#delimit ;line) is still 0.capture program drop setterfollowed by a definition still credits.A reset after the
c_localno longer erases it (laterToken: 1 → 0). The check is now order-aware. Atokenize,macro shift,local 1orgettokeninto1blocks credit only for ac_localthat runs after it on the first pass. Eachif/elsebranch starts from the state before the chain.inputno longer defines its storage types as variables (inptyped,inputtype: 0 → 1 withundefinedVariable = "warning"). The full spellinginputhad the same bug back to v0.15.1, so the fix covers every spelling. A table test checks that every abbreviation ofgenerate,input,renameandconfirmgives the same result as the full word.Quadratic work removed
renamewildcard check reads only the tokens on the name's line, found by binary search: token visits for 100/200/400 renames went from 82,012/324,012/1,288,012 to 812/1,612/3,212. This covers bothrenaandrename.prefix.exprprobe's second read used to return a stale answer and now returns the right one.Trade-offs and limits
docs/configuration.mdsays this.input byte x:lab ystill dropsy. That is a parser limitation that predates this PR.c_localdoes not revalidate the caller. The resolver's interface hash keys on program names; this is also true on main.Proof: each fixture above was checked 3× before and after. Regression tests fail on main (18 in the new unit and CLI tests, 2 in the
inputtests). StataMP 18 confirmedlaterTokenand its loop variant (resultset),inp double wage str10 city(onlywageandcity), andprogram drop(rc 199, local unset).check:line-endings,typecheck,bun test ./tests(10157 pass),lintandtest:ciall pass. One earlier full run hit a random-seed parser property failure (di _ = 1). The same input fails on main, and that test file passed on 3 reruns.Created with Claude Opus 5.5 in Claude Code.