crucible-mir
: Improve pretty-printing of ZST constants
#1312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ConstZST
(i.e., constant values with zero-sized types) do not include any information about what the zero-sized type is. In particular, function constants are represented asConstZST
s, and the only way to determine what function theConstZST
corresponds to is to look at its type (FnDef
), which stores theDefId
of the function name itself.Previously, the
crucible-mir
pretty-printer was printingConstZST
s as<ZST>
because it did not have access to any type information when pretty-printingConstVal
s. This results in very suboptimal pretty-printed output (see the example below). This is also true for other forms ofConstZST
s, although currentlymir-json
only turns function constants intoConstZST
s. (In the future, this could conceivably change.)To fix this issue, we add special cases in the
Pretty Constant
instance (which does have access to type information forConstVal
s) such thatConstZST
s are printed using their type information. In particular, if theConstZST
has typeTyFnDef
, then the functionDefId
stored in theTyFnDef
is printed. All other forms ofConstZST
s are printed like<ZST: [ty]>
, where[ty]
is the pretty-printed type.As an example of the improvements in this patch, consider this program:
Before the changes in this patch, the MIR for
bar()
would be pretty-printed as:(Note the call to
<ZST>()
, which gives no indication whatsoever about what function was called.)After the changes in this patch, it is pretty-printed as:
Fixes GaloisInc/mir-json#79.