I was trying to write a test that would traverse the body of every function in a crate, but I couldn't do that by only using StableMIR APIs.
Not every CrateItem is a function, and there is no method to retrieve information about the type of CrateItem, so users can't tell whether it's valid to retrieve the item body. If a user tries to get the body of a non-function, StableMIR crashes. Note that just knowing that an item is a function will likely not be enough, since there are cases where the function body might not be available.
Besides providing more information about a CrateItem, we could also change the body of CrateItem::body to return Result<> instead.
I was trying to write a test that would traverse the body of every function in a crate, but I couldn't do that by only using StableMIR APIs.
Not every
CrateItemis a function, and there is no method to retrieve information about the type ofCrateItem, so users can't tell whether it's valid to retrieve the item body. If a user tries to get the body of a non-function, StableMIR crashes. Note that just knowing that an item is a function will likely not be enough, since there are cases where the function body might not be available.Besides providing more information about a
CrateItem, we could also change the body ofCrateItem::bodyto returnResult<>instead.