GaloisInc / saw-script

The SAW scripting language.
BSD 3-Clause "New" or "Revised" License
438 stars 63 forks source link

Improve AST-level source position tracking #2071

Closed sauclovian-g closed 4 weeks ago

sauclovian-g commented 3 months ago

At the AST level (src/SAWScript/AST.hs) statements have source positions on each constructor, but expressions, patterns, and types are instead handled by having an extra constructor with just a position that's inserted at, in theory, strategic places to assure that position information is available. The idea is to use the next enclosing such position.

This doesn't actually work out very well. First, for type errors, one really wants the exact position of the exact expression that one's complaining about and not an approximation. Second, it's hard to use in practice (since it has to be carried around as pass state) and it's also hard to know in general what position you have and what it's actually the position of.

We decided this should be removed in favor of just storing positions in each constructor, at least for expressions and patterns. So far whether to extend this to types is TBD.

sauclovian-g commented 2 months ago

Update: we decided to extend it to types.

After that there's a third set of changes, which is that some downstream code is using a global variable in a shared monad to push positions around. This should be ripped out; it's difficult to reason about global variables and after the position tracking updates it should no longer be necessary either.

sauclovian-g commented 4 weeks ago

Further update: that global variable reaches almost everywhere and clearing out is a big deal. I'm going to open a new issue for it and close this one, as this one's done.

sauclovian-g commented 4 weeks ago

That issue is #2128.