Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework rustc_serialize #329

Closed
3 tasks done
matthewjasper opened this issue Jul 4, 2020 · 4 comments
Closed
3 tasks done

Rework rustc_serialize #329

matthewjasper opened this issue Jul 4, 2020 · 4 comments
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team

Comments

@matthewjasper
Copy link

matthewjasper commented Jul 4, 2020

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.

@matthewjasper matthewjasper added T-compiler Add this label so rfcbot knows to poll the compiler team major-change A proposal to make a major change to rustc labels Jul 4, 2020
@rustbot
Copy link
Collaborator

rustbot commented Jul 4, 2020

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.

@rustbot rustbot added the to-announce Announce this issue on triage meeting label Jul 4, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Jul 6, 2020

@rustbot second

@rustbot rustbot added the final-comment-period The FCP has started, most (if not all) team members are in agreement label Jul 6, 2020
@spastorino spastorino removed the to-announce Announce this issue on triage meeting label Jul 8, 2020
@matthewjasper matthewjasper added finished-final-comment-period The FCP has finished, action upon the disposition label needs to be taken major-change-accepted A major change proposal that was accepted to-announce Announce this issue on triage meeting and removed final-comment-period The FCP has started, most (if not all) team members are in agreement finished-final-comment-period The FCP has finished, action upon the disposition label needs to be taken labels Jul 20, 2020
@spastorino spastorino removed the to-announce Announce this issue on triage meeting label Jul 22, 2020
@extf33
Copy link

extf33 commented Sep 5, 2023

@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);
        }
    }

@matthewjasper
Copy link
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
Labels
major-change A proposal to make a major change to rustc major-change-accepted A major change proposal that was accepted T-compiler Add this label so rfcbot knows to poll the compiler team
Projects
None yet
Development

No branches or pull requests

5 participants