Make context explicit in flow analysis API #43077
Labels
analyzer-technical-debt
area-dart-model
For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.
model-flow
Implementation of flow analysis in analyzer/cfe
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
Flow analysis currently works by maintaining a stack of contexts that parallels the set of code constructs surrounding the expression currently being analyzed; entries are pushed and popped on this stack by
FlowAnalysis
methods whose name ends inbegin
, andend
, respectively. This allows it to maintain state information that the client doesn't need to know about, but it carries a big disadvantage: if the client ever fails to match upbegin
andend
calls properly, this typically results in a hard crash, but the crash doesn't occur until some time after the mismatched begin/end pair; this makes it very hard to debug.@johnniwinther, @scheglov, and I have talked about this in the past, and the solution we've generally favored is to change the API of flow analysis so that each of the
begin
methods returns the context object, and each of theend
methods takes it as a first argument; this frees flow analysis from having to keep a stack (though it could still do so as a safety check). This means that (a) the client can't forget to callbegin
, because it won't have a context object to thread through to theend
call, and (b) if the client forgets to callend
, it will result in incorrect analysis but probably not a crash.Probably we would want to do this in stages:
I'm currently dealing with a bug related to improper nesting of
begin
andend
calls, so I might need to work on this ASAPThe text was updated successfully, but these errors were encountered: