MIR: Provide utility functions for looking up full identifiers
RyanGlScott opened this issue · comments
Finding the names of MIR identifiers in a MIR JSON file is challenging, and doubly so when the name is autogenerated. For instance, consider this file:
pub fn f<A>(x: A) -> A {
x
}
pub fn g(x: u32) -> u32 {
f(x)
}
Let's suppose you want to look up the identifier corresponding to f
when the A
type parameter is instantiated with u32
(as is the case when g
invokes the f
function). Currently, there is no good way to do this—you'd have to dig into the MIR JSON file manually to discover that the autogenerated name is something like test::f::_instc5e93708b8ca6e2a
. Users shouldn't have to do this!
Instead, we should offer utility functions to make it possible to look up these sorts of names directly from SAW. For instance, we could imagine a command like this:
mir_instantiated_name : String -> [MIRType] -> String
Where the String
argument represents a polymorphic function being called (in this case, "test::f
) and the [MIRType]
list represents the list of types to instantiate the function with (in this case, [mir_u32]
). The String
that it returns would then be the name of the fully instantiated function identifier (in this case, test::f::_instc5e93708b8ca6e2a
). This API closely resembles that of the existing mir_find_adt
function, which already performs a similar sort of type-based name lookup.
Other useful commands worth adding would be something that granted users the ability to look up names using things that resemble fully qualified syntax (e.g., <Ty>::foo
). In order to support this, we may have to extend mir-json
to include more information linking foo
back to Ty
, especially if foo
is located in an impl Ty
block (currently, nothing in the mir-json
file makes it obvious which impl<N>
block specifically corresponds to the impl Ty
block).