Repository navigation
Credit caller locals from the program definition Stata has in memory, navigate to locals a loaded program sets, and fix Find References file names, graph arguments after a quoted path, and EPIPE on early pipe close - #431
Merged
Conversation
… navigate to locals a loaded program sets, and fix file names in Find References, graph arguments after a quoted path, and EPIPE on an early pipe close - A call's c_local, local() option and c_local-of-argument writes now come from the definition the caller's resolved execution scope reaches at the call (defined earlier, by a parent, or by a file loaded before it); the ado named after the program counts only when none is, also after program drop (checked in StataMP 18). The index no longer overwrites a program with its ado; it keeps the definition whose URI sorts first and lists every definition, so results no longer depend on index order. - The analyzer credits a workspace program only when no scope can change the answer (the one definition outside the file, or, inside a program body, the file's own helper); the rest is decided by one walk that diagnostics and navigation share. - Go to Definition, hover, completion and Find References treat the argument word or option argument as the local's definition wherever the warning is suppressed, including through a loaded file. - Find References reads save/use/do/type/... as a file command only in command position: first in a statement or right after a one-line if condition, split as the parser splits it. A separate if or in ends the file names after using; if.dta does not. - sight graph --json looks for the option comma after the whole path, so do "survey, wave 1.do" 2019 passes ["2019"]. - check, parse and graph stop writing quietly when the reader closes early and keep their exit codes.
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 45 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.
A cold review of #422 and #423 found that Sight credited caller locals from the wrong definition of a program. If a do-file that had run defined
setter, asetter.adobeside it still decided which locals the call set. In Stata the reverse holds: a program already in memory is used, and the ado is loaded only when no program of that name is in memory, including afterprogram drop(checked in StataMP 18). #423 also took away navigation for a local that a loaded program sets: the warning went away, but Go to Definition, hover and completion returned nothing. The review also found three smaller bugs in Find References,sight graphand the CLI.Which definition a call uses (S5). One walk over the file, using the resolved execution scope, now decides which definition each call reaches: one defined earlier in the file, one from a parent, or one from a file loaded before the call. If none of those defines it, the ado named after the program is used. The walk then derives all three kinds of caller write from that definition: a literal
c_local, alocal()option, and ac_localof an argument. The analyzer credits a workspace program only when no scope could change the answer: the program's one definition outside the file, or, inside a program body, the file's own helper. Everything else goes to the walk. The index no longer replaces a program with its ado. It keeps the definition whose URI sorts first and lists every definition inSymbolTable.program_definitions. That field is a small addition tosrc/types/index.ts, outside the directories this PR owns.fixinverse: 1 issue → 0.optinverse: 1 → 0, and 0 in all 8 repeats.shadowado: 0 → 1, and it no longer offers a definition, hover or completion.optinversefailed 8 of 8 times on main because of the ado overwrite, so that failure was deterministic. The order dependence sits underneath it: without the overwrite, "last file indexed wins" decides. One new test indexes the same workspace in both file orders. Another covers a helper name that several ados define. Both fail on main.Navigation for locals a loaded program sets (S8). Definition, hover, completion and Find References now read the same walk as diagnostics. Wherever the warning is suppressed, the argument word (or the option argument) is the local's definition, and Find References also works from that word.
navdirect: Go to Definition goes to main.do line 2, cols 7–13, hover shows the local, and completion offers it. The cases that still warn return no definition.Find References file names (S7).
save,use,typeand the other file-name commands count only as a statement's command. That means first in the statement after any prefixes, or first after a one-lineifcondition. Workspace files are indexed without an AST, so theifsplit copies the parser's rule rather than using the AST.if _N > 0 regress type i.xfindsi.x.if save == 1 regress y L.dtafindsL.dta. Inappend using if.dta l.dta,l.dtais a file name. The cases from #413 and #422 still pass, and the token-count test still passes.sight graph --json(S10). The option comma is searched for only after the whole path.do "survey, wave 1.do" 2019→["2019"], anddo "child,part.do" x→["x"].Early pipe close (S11).
check,parseandgraphnow stop writing without printing an error when the reader closes early (| head -1). They keep their documented exit codes (0 on success, 2 when a file fails) under bothbun src/cli.tsandnode dist/sight-server.js.Not fixed
runcalls on one physical line with a call between them. This did not fall out of S5: forward call sites carry only a line number. On a line that holds several loads, the earliest load end still counts for all of them.Corpus (3,780 ados) compared with
chk-final2.json(origin/main at 9f94055): 0 new diagnostics at new positions, and the result is identical across 3 runs.undefined_macrotoout_of_scope_symbol("used before it is defined (line N)" / "defined only inside program parseit"). This is in_pss_chk_testmainopts,gsem_parse_gauss_args,gsem_parse_poisson_argsandgsem_parse_st_args. Each calls a same-file helper whose name other ados also define (parseit,CheckNumVar). On main, which definition counted depended on index order: the structurally identical_pss_chk_cimainoptswas already classified the new way. The file's own helper now always counts.CheckNumVar ldepvar \ldepvar',GetVCE, ... `options'`). The analyzer treats the call's own arguments as after the definition. That rule is unchanged and already applied to files whose helper happened to win the merge.rev2-anworkspaces from 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 give the same issue counts as before (2 runs each).Proof: the probes for
fixinverse,shadowado,optinverse,navdirect,ref_normalandgraphcommawere run before and after. 18 new tests fail on origin/main and pass here (plus the node EPIPE cases, which failed before the change).check:line-endings,typecheck,bun test ./tests(10284 pass),lintandtest:ciall pass when run separately.