You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, mir-json makes use of two macros to automatically derive ToJson implementations for several types based on their variant names. Here is one place where such a macro is used:
As a result, the CastKindFloatToFloat will be rendered as the string "FloatToFloat" in JSON, PtrToPtr will be rendered as "PtrToPtr", and so on.
This approach, while terse, has the downside that if the variant names change between different versions of the rustc API, then the JSON schema used in the ToJson impls will silently change. This actually matters in practice. For instannce, the version of rustc that mir-json currently pins against (nightly-2023-01-23) has a CastKind named Pointer, but in version 1.79.0 of rustc, Pointer is now named PointerCoercion instead, which means that downstream tools (e.g., Crucible) would need to parse the corresponding JSON differently. I wouldn't have been aware of this fact unless I bothered to look it up!
To avoid the possibility of nasty surprises like this, I propose that we avoid the use of macros like basic_json_enum_impl! and instead hand-write all of the ToJson impls, using a match expression to ensure that all possible variants are covered. This is more verbose, but it does mean that if future versions of rustc change the variant names, then we will be notified immediately when upgrading rustc versions, rather than having to play detective after the fact to figure out what changed.
The text was updated successfully, but these errors were encountered:
Currently,
mir-json
makes use of two macros to automatically deriveToJson
implementations for several types based on their variant names. Here is one place where such a macro is used:mir-json/src/analyz/ty_json.rs
Line 41 in ac740ee
As a result, the
CastKind
FloatToFloat
will be rendered as the string"FloatToFloat"
in JSON,PtrToPtr
will be rendered as"PtrToPtr"
, and so on.This approach, while terse, has the downside that if the variant names change between different versions of the
rustc
API, then the JSON schema used in theToJson
impls will silently change. This actually matters in practice. For instannce, the version ofrustc
thatmir-json
currently pins against (nightly-2023-01-23
) has aCastKind
namedPointer
, but in version 1.79.0 ofrustc
,Pointer
is now namedPointerCoercion
instead, which means that downstream tools (e.g., Crucible) would need to parse the corresponding JSON differently. I wouldn't have been aware of this fact unless I bothered to look it up!To avoid the possibility of nasty surprises like this, I propose that we avoid the use of macros like
basic_json_enum_impl!
and instead hand-write all of theToJson
impls, using amatch
expression to ensure that all possible variants are covered. This is more verbose, but it does mean that if future versions ofrustc
change the variant names, then we will be notified immediately when upgradingrustc
versions, rather than having to play detective after the fact to figure out what changed.The text was updated successfully, but these errors were encountered: