Skip to content

Commit 687e099

Browse files
incr.comp.: Make a bunch of query results encodable.
1 parent 8fbc91c commit 687e099

File tree

6 files changed

+61
-11
lines changed

6 files changed

+61
-11
lines changed

src/librustc/middle/borrowck.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use util::nodemap::FxHashSet;
1515
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
1616
StableHasherResult};
1717

18+
#[derive(Debug, RustcEncodable, RustcDecodable)]
1819
pub struct BorrowCheckResult {
1920
pub used_mut_nodes: FxHashSet<HirId>,
2021
}

src/librustc/mir/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use std::ops::{Index, IndexMut};
3636
use std::rc::Rc;
3737
use std::vec::IntoIter;
3838
use syntax::ast::{self, Name};
39+
use syntax::symbol::InternedString;
3940
use syntax_pos::Span;
4041

4142
mod cache;
@@ -1724,21 +1725,21 @@ impl Location {
17241725
}
17251726
}
17261727

1727-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
1728+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
17281729
pub enum UnsafetyViolationKind {
17291730
General,
17301731
ExternStatic(ast::NodeId),
17311732
BorrowPacked(ast::NodeId),
17321733
}
17331734

1734-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
1735+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
17351736
pub struct UnsafetyViolation {
17361737
pub source_info: SourceInfo,
1737-
pub description: &'static str,
1738+
pub description: InternedString,
17381739
pub kind: UnsafetyViolationKind,
17391740
}
17401741

1741-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1742+
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
17421743
pub struct UnsafetyCheckResult {
17431744
/// Violations that are propagated *upwards* from this function
17441745
pub violations: Rc<[UnsafetyViolation]>,

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ impl<'tcx> DtorckConstraint<'tcx> {
27022702
}
27032703
}
27042704

2705-
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
2705+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable)]
27062706
pub struct SymbolName {
27072707
// FIXME: we don't rely on interning or equality here - better have
27082708
// this be a `&'tcx str`.

src/librustc_data_structures/indexed_set.rs

+21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::slice;
1717
use bitslice::{BitSlice, Word};
1818
use bitslice::{bitwise, Union, Subtract, Intersect};
1919
use indexed_vec::Idx;
20+
use rustc_serialize;
2021

2122
/// Represents a set (or packed family of sets), of some element type
2223
/// E, where each E is identified by some unique index type `T`.
@@ -35,6 +36,26 @@ impl<T: Idx> Clone for IdxSetBuf<T> {
3536
}
3637
}
3738

39+
impl<T: Idx> rustc_serialize::Encodable for IdxSetBuf<T> {
40+
fn encode<E: rustc_serialize::Encoder>(&self,
41+
encoder: &mut E)
42+
-> Result<(), E::Error> {
43+
self.bits.encode(encoder)
44+
}
45+
}
46+
47+
impl<T: Idx> rustc_serialize::Decodable for IdxSetBuf<T> {
48+
fn decode<D: rustc_serialize::Decoder>(d: &mut D) -> Result<IdxSetBuf<T>, D::Error> {
49+
let words: Vec<Word> = rustc_serialize::Decodable::decode(d)?;
50+
51+
Ok(IdxSetBuf {
52+
_pd: PhantomData,
53+
bits: words,
54+
})
55+
}
56+
}
57+
58+
3859
// pnkfelix wants to have this be `IdxSet<T>([Word]) and then pass
3960
// around `&mut IdxSet<T>` or `&IdxSet<T>`.
4061
//

src/librustc_mir/transform/check_unsafety.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::mir::*;
2020
use rustc::mir::visit::{LvalueContext, Visitor};
2121

2222
use syntax::ast;
23+
use syntax::symbol::Symbol;
2324

2425
use std::rc::Rc;
2526
use util;
@@ -145,7 +146,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
145146
self.visibility_scope_info[source_info.scope].lint_root;
146147
self.register_violations(&[UnsafetyViolation {
147148
source_info,
148-
description: "borrow of packed field",
149+
description: Symbol::intern("borrow of packed field").as_str(),
149150
kind: UnsafetyViolationKind::BorrowPacked(lint_root)
150151
}], &[]);
151152
}
@@ -209,7 +210,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
209210
self.visibility_scope_info[source_info.scope].lint_root;
210211
self.register_violations(&[UnsafetyViolation {
211212
source_info,
212-
description: "use of extern static",
213+
description: Symbol::intern("use of extern static").as_str(),
213214
kind: UnsafetyViolationKind::ExternStatic(lint_root)
214215
}], &[]);
215216
}
@@ -225,7 +226,9 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
225226
{
226227
let source_info = self.source_info;
227228
self.register_violations(&[UnsafetyViolation {
228-
source_info, description, kind: UnsafetyViolationKind::General
229+
source_info,
230+
description: Symbol::intern(description).as_str(),
231+
kind: UnsafetyViolationKind::General,
229232
}], &[]);
230233
}
231234

@@ -433,15 +436,15 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
433436
struct_span_err!(
434437
tcx.sess, source_info.span, E0133,
435438
"{} requires unsafe function or block", description)
436-
.span_label(source_info.span, description)
439+
.span_label(source_info.span, &description[..])
437440
.emit();
438441
}
439442
UnsafetyViolationKind::ExternStatic(lint_node_id) => {
440443
tcx.lint_node(SAFE_EXTERN_STATICS,
441444
lint_node_id,
442445
source_info.span,
443446
&format!("{} requires unsafe function or \
444-
block (error E0133)", description));
447+
block (error E0133)", &description[..]));
445448
}
446449
UnsafetyViolationKind::BorrowPacked(lint_node_id) => {
447450
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
@@ -451,7 +454,7 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
451454
lint_node_id,
452455
source_info.span,
453456
&format!("{} requires unsafe function or \
454-
block (error E0133)", description));
457+
block (error E0133)", &description[..]));
455458
}
456459
}
457460
}

src/libserialize/collection_impls.rs

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::hash::{Hash, BuildHasher};
1414

1515
use {Decodable, Encodable, Decoder, Encoder};
1616
use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSet};
17+
use std::rc::Rc;
1718

1819
impl<
1920
T: Encodable
@@ -194,3 +195,26 @@ impl<T, S> Decodable for HashSet<T, S>
194195
})
195196
}
196197
}
198+
199+
impl<T: Encodable> Encodable for Rc<[T]> {
200+
fn encode<E: Encoder>(&self, s: &mut E) -> Result<(), E::Error> {
201+
s.emit_seq(self.len(), |s| {
202+
for (index, e) in self.iter().enumerate() {
203+
s.emit_seq_elt(index, |s| e.encode(s))?;
204+
}
205+
Ok(())
206+
})
207+
}
208+
}
209+
210+
impl<T: Decodable> Decodable for Rc<[T]> {
211+
fn decode<D: Decoder>(d: &mut D) -> Result<Rc<[T]>, D::Error> {
212+
d.read_seq(|d, len| {
213+
let mut vec = Vec::with_capacity(len);
214+
for index in 0..len {
215+
vec.push(d.read_seq_elt(index, |d| Decodable::decode(d))?);
216+
}
217+
Ok(vec.into())
218+
})
219+
}
220+
}

0 commit comments

Comments
 (0)