GaloisInc / saw-script

The SAW scripting language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MIR: Suggest alternate name identifiers when lookup fails

RyanGlScott opened this issue · comments

One tricky aspect of using the SAW MIR backend is figuring out what things are named in the compiled MIR JSON file, and it's quite easy to mess it up. Here is an example of some code which exhibits this trickiness:

impl A {
    fn f() {}
}

impl B {
    fn f() {}
}

There are two functions named f in this file, but when the file is compiled with mir-json, it will result in two distinct identifiers. They will likely look something like:

test::{impl#1}::f // For A::f
test::{impl#2}::f // For B::F

Of course, it's unlikely that a user will guess these identifiers on the first try. A more likely scenario is that a user will try this first:

mir_verify m "test::f" ...

There is no identifier named test::f, so naturally this will fail. On the other hand, test::f is close to the two {impl}'d identifiers above, so it would be extremely helpful if SAW could suggest these in the error message. Something like this, perhaps:

Could not find an identifier named `test::f`.
Perhaps you meant one of these identifiers?

* test::{impl#1}::f (defined at test.rs:2)
* test::{impl#2}::f (defined at test.rs:6)

This immediately provides a hint that the user is close, and it gives context for where the user should look to figure out where the actual identifier that they want lives. (I'm not sure if the accompanying line number information is easy to look up in mir-json as it currently exists, but if not, we should tweak mir-json to make this possible.)

We could imagine giving suggestions in the following circumstances:

  1. The identifier's function name is contained in the MIR JSON file, but under a different path.
  2. The user wrote {impl}, but it's ambiguous which {impl} they meant. (Imagine writing test::{impl}::f in the example above, which wouldn't be enough to determine which f you meant.)