mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
7120fdac7a
Add basic Serde serialization capabilities to Stable MIR This PR adds basic Serde serialization capabilities to Stable MIR. It is intentionally minimal (just wrapping all stable MIR types with a Serde `derive`), so that any important design decisions can be discussed before going further. A simple test is included with this PR to validate that JSON can actually be emitted. ## Notes When I wrapped the Stable MIR error types in `compiler/stable_mir/src/error.rs`, it caused test failures (though I'm not sure why) so I backed those out. ## Future Work So, this PR will support serializing basic stable MIR, but it _does not_ support serializing interned values beneath `Ty`s and `AllocId`s, etc... My current thinking about how to handle this is as follows: 1. Add new `visited_X` fields to the `Tables` struct for each interned category of interest. 2. As serialization is occuring, serialize interned values as usual _and_ also record the interned value we referenced in `visited_X`. (Possibly) In addition, if an interned value recursively references other interned values, record those interned values as well. 3. Teach the stable MIR `Context` how to access the `visited_X` values and expose them with wrappers in `stable_mir/src/lib.rs` to users (e.g. to serialize and/or further analyze them). ### Pros This approach does not commit to any specific serialization format regarding interned values or other more complex cases, which avoids us locking into any behaviors that may not be desired long-term. ### Cons The user will need to manually handle serializing interned values. ### Alternatives 1. We can directly provide access to the underlying `Tables` maps for interned values; the disadvantage of this approach is that it either requires extra processing for users to filter out to only use the values that they need _or_ users may serialize extra values that they don't need. The advantage is that the implementation is even simpler. The other pros/cons are similar to the above. 2. We can directly serialize interned values by expanding them in-place. The pro is that this may make some basic inputs easier to consume. However, the cons are that there will need to be special provisions for dealing with cyclical values on both the producer and consumer _and_ global values will possibly need to be de-duplicated on the consumer side. |
||
---|---|---|
.. | ||
auxiliary | ||
codegen-backend | ||
fluent-messages | ||
internal-lints | ||
mod_dir_simple | ||
session-diagnostic | ||
stable-mir | ||
compiler-calls.rs | ||
deriving-global.rs | ||
deriving-hygiene.rs | ||
dropck_tarena_sound_drop.rs | ||
dropck-tarena-cycle-checked.rs | ||
dropck-tarena-cycle-checked.stderr | ||
dropck-tarena-unsound-drop.rs | ||
dropck-tarena-unsound-drop.stderr | ||
empty-struct-braces-derive.rs | ||
hash-stable-is-unstable.rs | ||
hash-stable-is-unstable.stderr | ||
lint-pass-macros.rs | ||
missing-rustc-driver-error.rs | ||
missing-rustc-driver-error.stderr | ||
mod_dir_path_canonicalized.rs | ||
obtain-borrowck.rs | ||
obtain-borrowck.run.stdout | ||
pathless-extern-unstable.rs | ||
pathless-extern-unstable.stderr | ||
pprust-expr-roundtrip.rs | ||
regions-mock-tcx.rs | ||
run-compiler-twice.rs | ||
rustc_encodable_hygiene.rs |