[Issue 20674] [DIP1000] inference of `scope` is easily confused

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 10 13:55:13 UTC 2021


--- Comment #4 from Paul Backus <snarwin+bugzilla at gmail.com> ---
(In reply to Dennis from comment #3)
> (In reply to Walter Bright from comment #1)
> > To do what this example asks for, data flow analysis would be required. This
> > can be done, but is a large increase in implementation complexity and time
> > to compile.
> This puzzles me. The examples don't contain a single branch or loop. Surely
> you can infer scope here without creating a control-flow graph, right?

Currently, in order to infer scope for `p`, you only need to check each usage
of `p` for compliance with scope.

To make the example (and others like it) work, you would need to recursively
check each usage of any variable that `p` might be assigned to (like `p2`), and
each usage of any variable that any of *those* variables might be assigned to,
and so on, until you cannot find any new variables to check.

What I've just described is a graph search problem. Whether the compiler
actually builds an explicit control-flow graph or not, it amounts to the same


More information about the Digitalmars-d-bugs mailing list