Add extended-analysis=local to bound data-flow memory on large source trees - #3519
Open
carlfriedrich wants to merge 1 commit into
Open
Add extended-analysis=local to bound data-flow memory on large source trees#3519carlfriedrich wants to merge 1 commit into
extended-analysis=local to bound data-flow memory on large source trees#3519carlfriedrich wants to merge 1 commit into
Conversation
… trees
Make `extended-analysis` a three-way scope control instead of a boolean:
true (default) - whole-program data-flow analysis; data flow is followed
into sourced files (inlined into the CFG)
local (new) - per-file data-flow analysis; sourced files are treated as
opaque boundaries and not inlined into the CFG
false - no data-flow analysis
All three still follow sources for parsing and AST-level checks; they differ
only in how far the data-flow pass reaches.
`local` bounds memory when many checked files source a shared tree of
libraries: with `true`, every includer re-inlines the entire sourced tree
into its own CFG and the context-sensitive fixpoint runs over that multiplied
graph, growing memory super-linearly (see koalaman#3177, koalaman#3442). `local` keeps
per-file data-flow checks (e.g. SC2317) while removing the cross-file
multiplication, unlike `false` which drops data-flow checks entirely.
The wire values true/false are unchanged (true=EAFull, false=EAOff); only the
internal representation changes from Bool to an ExtendedAnalysisMode enum.
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.
Summary
Adds a third value,
local, to the existingextended-analysisoption (flag,.shellcheckrc, and inline directive). It runs dataflow analysis per file, treatingsource'd files as opaque boundaries instead of inlining their bodies into the control-flow graph.extended-analysisbecomes a three-way scope control:true(default)source)local(new)falseAll three still follow sources for parsing and AST-level checks (variable resolution, SC2154, etc.), they differ only in how far the data-flow pass reaches.
true/falseare unchanged and fully backward compatible.Motivation
ShellCheck's whole-program iterative dataflow analysis can consume a great deal of memory on large graphs. The worst case is a set of scripts that each
sourcea shared tree of libraries and are all checked in one invocation: every includer re-inlines the entire sourced tree into its own control-flow graph, and the context-sensitive fixpoint (which retains per-call-path state) then runs over that multiplied graph. Memory grows super-linearly with graph size.This is the situation described in #3177 and #3442. The current escape hatch is
extended-analysis=false, which throws out all dataflow checks.localis a middle ground: it keeps per-file dataflow analysis (so intra-file checks such as SC2317 still fire) while removing the cross-file multiplication that drives the blow-up.What changes for users
--extended-analysis=local,extended-analysis=localin.shellcheckrc, and# shellcheck extended-analysis=localinline.localkeeps dataflow checks that are decidable within a single file.localgives up dataflow that crosses asourceboundary. Concretely, it won't use knowledge from a sourced file (e.g. "this sourced function always exits", "this sourced variable is always an integer") the waytruedoes. Compared totruethis can mean a few fewer/extra findings around cross-source data flow. Compared tofalseit is strictly more analysis.Evidence
A real ~200-file project (many scripts sourcing files from a shared library tree), whole-tree invocation:
truelocalfalseOn that project
localroughly halves peak memory versustrue. The 4-finding delta is cross-source dataflow thattrueresolves via inlining.Review note / open question
I chose
localas a new additional value (single lowercase word, matching existing directive-value conventions) to keep the change minimal. A fully-named triad would probably be more consistent, though (e.g.none/local/fullwithtrue/falsekept as backwards-compatible aliases). Open for discussion.