Skip to content

Rework rustc_serialize #329

Closed
Closed

Description

@matthewjasper

Proposal

rust-lang/rust#73851 reworks specialization in the following noticeable ways:

  • The type parameter in the Encodable and Decodable traits is moved from the method to the trait.
  • These traits are now derived using macros in rustc_macros rather than the built-in RustcEncodable and RustcDecodable derives.
  • Specialized implementations of Encodable and Decodable now directly use specialization.
  • A lot of transmutes are removed

Further documentation of serialization in rustc after the PR has landed can be found at rust-lang/rustc-dev-guide#785.

Mentors or Reviewers

PR has already been reviewed by @oli-obk

Process

The main points of the Major Change Process is as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

Activity

  1. added
    T-compilerAdd this label so rfcbot knows to poll the compiler team
    major-changeA proposal to make a major change to rustc
    on Jul 4, 2020
  2. rustbot commented on Jul 4, 2020

    @rustbot
    Collaborator

    This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.

  3. oli-obk commented on Jul 6, 2020

    @oli-obk
    Contributor

    @rustbot second

  4. added
    final-comment-periodThe FCP has started, most (if not all) team members are in agreement
    on Jul 6, 2020
  5. added
    finished-final-comment-periodThe FCP has finished, action upon the disposition label needs to be taken
    to-announceAnnounce this issue on triage meeting
    and removed
    final-comment-periodThe FCP has started, most (if not all) team members are in agreement
    finished-final-comment-periodThe FCP has finished, action upon the disposition label needs to be taken
    on Jul 20, 2020
  6. extf33 commented on Sep 5, 2023

    @extf33

    @matthewjasper

    Hello, I came across this issue while looking for a way to serialize/deserialize the MIR Body.
    I have two questions.

    1. Where in the rustc code is the decode() method, which is associated with the MIR Body (as mentioned below), used?

    2. Is it possible to serialize the MIR Body to a file (during a MIR pass) and then load it back by deserializing it?
      If so, how should the code be written?
      I thought of a logic like the one below.

      use crate::MirPass;
      use rustc_middle::mir::*;
      use rustc_middle::ty::TyCtxt;
      use rustc_serialize::opaque::{FileEncoder, MemDecoder};
      use rustc_serialize::{Decodable, Encodable};
      use std::fs;
      
      pub struct MirSerDe;
      
      impl<'tcx> MirPass<'tcx> for MirSerDe {
          fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
              let tmpfile = tempfile::NamedTempFile::new().unwrap();
              let tmpfile = tmpfile.path();
      
              // Serialize
              let mut encoder = FileEncoder::new(&tmpfile).unwrap();
              Encodable::encode(body, &mut encoder);
              encoder.finish().unwrap();
      
              // Deserialize
              let data = fs::read(&tmpfile).unwrap();
              let mut decoder = MemDecoder::new(&data[..], 0);
              let decoded = Decodable::decode(&mut decoder);
      
              assert_eq!(body, decoded);
          }
      }
  7. matthewjasper commented on Sep 5, 2023

    @matthewjasper
    Author

    Zulip (or a new issue if you have a suitable repository for it) might be a better place to discuss this than this Github issue, but to answer your questions:

    1. There is one decode call here:
      https://github.com/rust-lang/rust/blob/af488be5f82b5e1010f7b52bc4fcda697793950d/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs#L88
      and another here:
      https://github.com/rust-lang/rust/blob/b402182d4e0b00254c1afd0620547e2ee42ae336/compiler/rustc_middle/src/query/on_disk_cache.rs#L532
    2. I don't think we have support for this. You'll need a decoder that implements TyDecoder and encoder that implements TyEncoder and neither of the current types used for this would be suitable. You could try implementing your own. What do you actually want to do here? Why can't you keep the MIR in memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustcmajor-change-acceptedA major change proposal that was accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions