Skip to content

Rollup of 8 pull requests #37341

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

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
da9e9e8
Remove `CrateReader`, use `CrateLoader` instead.
jseyfried Oct 19, 2016
feefe77
Remove `{in,de}flate_bytes_zlib`.
nnethercote Oct 20, 2016
94771a1
Use fast decompression in `deflate_bytes`.
nnethercote Oct 20, 2016
b94d2fb
Rename `csearch.rs` -> `cstore_impl.rs`.
jseyfried Oct 19, 2016
63f9314
Move `Library` into `creader.rs`.
jseyfried Oct 20, 2016
80fe1d2
Rename `loader.rs` -> `locator.rs`.
jseyfried Oct 20, 2016
209fe0d
Fix line stepping in debugger.
vadimcn Oct 19, 2016
a935481
Avoid an unnecessary clone in `macro_parser::parse`.
nnethercote Oct 20, 2016
e382267
Avoid an unnecessary clone in `generic_extensions`.
nnethercote Oct 20, 2016
b817cf8
Replace the `String` in `ParseResult::Failure` with `Token`.
nnethercote Oct 21, 2016
974817d
when pop skol, also remove from proj cache
nikomatsakis Oct 19, 2016
567b11f
only remove keys that mention skolemized regions
nikomatsakis Oct 19, 2016
483bc86
add regression test for #37154
nikomatsakis Oct 19, 2016
7e603d4
Implement `From<Cow<str>> for String` and `From<Cow<[T]>> for Vec<T>`.
SimonSapin Oct 21, 2016
4a413d8
Rollup merge of #37294 - nikomatsakis:issue-37154, r=nikomatsakis
Manishearth Oct 22, 2016
7b1282c
Rollup merge of #37298 - nnethercote:faster-deflate, r=alexcrichton
Manishearth Oct 22, 2016
034ae77
Rollup merge of #37301 - jseyfried:improve_metadata_modules, r=eddyb
Manishearth Oct 22, 2016
14e7c6d
Rollup merge of #37310 - vadimcn:drop-spans, r=michaelwoerister
Manishearth Oct 22, 2016
2e4d80d
Rollup merge of #37318 - nnethercote:html5ever-more, r=nrc,eddyb
Manishearth Oct 22, 2016
e941e01
Rollup merge of #37326 - SimonSapin:from-cow, r=alexcrichton
Manishearth Oct 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,13 @@ impl<'a> From<&'a str> for String {
}
}

#[stable(feature = "string_from_cow_str", since = "1.14.0")]
impl<'a> From<Cow<'a, str>> for String {
fn from(s: Cow<'a, str>) -> String {
s.into_owned()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<&'a str> for Cow<'a, str> {
#[inline]
Expand Down
7 changes: 7 additions & 0 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,13 @@ impl<'a, T: Clone> From<&'a [T]> for Vec<T> {
}
}

#[stable(feature = "vec_from_cow_slice", since = "1.14.0")]
impl<'a, T> From<Cow<'a, [T]>> for Vec<T> where [T]: ToOwned<Owned=Vec<T>> {
fn from(s: Cow<'a, [T]>) -> Vec<T> {
s.into_owned()
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<&'a str> for Vec<u8> {
fn from(s: &'a str) -> Vec<u8> {
Expand Down
6 changes: 6 additions & 0 deletions src/libcollectionstest/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ fn test_from_str() {
assert_eq!(owned.as_ref().map(|s| &**s), Some("string"));
}

#[test]
fn test_from_cow_str() {
assert_eq!(String::from(Cow::Borrowed("string")), "string");
assert_eq!(String::from(Cow::Owned(String::from("string"))), "string");
}

#[test]
fn test_unsized_to_string() {
let s: &str = "abc";
Expand Down
8 changes: 8 additions & 0 deletions src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ fn test_cow_from() {
}
}

#[test]
fn test_from_cow() {
let borrowed: &[_] = &["borrowed", "(slice)"];
let owned = vec!["owned", "(vec)"];
assert_eq!(Vec::from(Cow::Borrowed(borrowed)), vec!["borrowed", "(slice)"]);
assert_eq!(Vec::from(Cow::Owned(owned)), vec!["owned", "(vec)"]);
}

#[allow(dead_code)]
fn assert_covariance() {
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> { d }
Expand Down
35 changes: 10 additions & 25 deletions src/libflate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ extern "C" {
-> *mut c_void;
}

const LZ_NORM: c_int = 0x80; // LZ with 128 probes, "normal"
const TINFL_FLAG_PARSE_ZLIB_HEADER: c_int = 0x1; // parse zlib header and adler32 checksum
const TDEFL_WRITE_ZLIB_HEADER: c_int = 0x01000; // write zlib header and adler32 checksum
const LZ_FAST: c_int = 0x01; // LZ with 1 probe, "fast"
const TDEFL_GREEDY_PARSING_FLAG: c_int = 0x04000; // fast greedy parsing instead of lazy parsing

fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Bytes {
/// Compress a buffer without writing any sort of header on the output. Fast
/// compression is used because it is almost twice as fast as default
/// compression and the compression ratio is only marginally worse.
pub fn deflate_bytes(bytes: &[u8]) -> Bytes {
let flags = LZ_FAST | TDEFL_GREEDY_PARSING_FLAG;
unsafe {
let mut outsz: size_t = 0;
let res = tdefl_compress_mem_to_heap(bytes.as_ptr() as *const _,
Expand All @@ -113,17 +116,9 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Bytes {
}
}

/// Compress a buffer, without writing any sort of header on the output.
pub fn deflate_bytes(bytes: &[u8]) -> Bytes {
deflate_bytes_internal(bytes, LZ_NORM)
}

/// Compress a buffer, using a header that zlib can understand.
pub fn deflate_bytes_zlib(bytes: &[u8]) -> Bytes {
deflate_bytes_internal(bytes, LZ_NORM | TDEFL_WRITE_ZLIB_HEADER)
}

fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Result<Bytes, Error> {
/// Decompress a buffer without parsing any sort of header on the input.
pub fn inflate_bytes(bytes: &[u8]) -> Result<Bytes, Error> {
let flags = 0;
unsafe {
let mut outsz: size_t = 0;
let res = tinfl_decompress_mem_to_heap(bytes.as_ptr() as *const _,
Expand All @@ -141,16 +136,6 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Result<Bytes, Error> {
}
}

/// Decompress a buffer, without parsing any sort of header on the input.
pub fn inflate_bytes(bytes: &[u8]) -> Result<Bytes, Error> {
inflate_bytes_internal(bytes, 0)
}

/// Decompress a buffer that starts with a zlib header.
pub fn inflate_bytes_zlib(bytes: &[u8]) -> Result<Bytes, Error> {
inflate_bytes_internal(bytes, TINFL_FLAG_PARSE_ZLIB_HEADER)
}

#[cfg(test)]
mod tests {
#![allow(deprecated)]
Expand Down
4 changes: 4 additions & 0 deletions src/librustc/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,5 +839,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
debug!("pop_skolemized({:?})", skol_map);
let skol_regions: FnvHashSet<_> = skol_map.values().cloned().collect();
self.region_vars.pop_skolemized(&skol_regions, &snapshot.region_vars_snapshot);
if !skol_map.is_empty() {
self.projection_cache.borrow_mut().rollback_skolemized(
&snapshot.projection_cache_snapshot);
}
}
}
10 changes: 8 additions & 2 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
infcx.skolemize_late_bound_regions(&obligation.predicate, snapshot);

let skol_obligation = obligation.with(skol_predicate);
match project_and_unify_type(selcx, &skol_obligation) {
let r = match project_and_unify_type(selcx, &skol_obligation) {
Ok(result) => {
let span = obligation.cause.span;
match infcx.leak_check(false, span, &skol_map, snapshot) {
Expand All @@ -178,7 +178,9 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
Err(e) => {
Err(e)
}
}
};

r
})
}

Expand Down Expand Up @@ -1396,6 +1398,10 @@ impl<'tcx> ProjectionCache<'tcx> {
self.map.rollback_to(snapshot.snapshot);
}

pub fn rollback_skolemized(&mut self, snapshot: &ProjectionCacheSnapshot) {
self.map.partial_rollback(&snapshot.snapshot, &|k| k.has_re_skol());
}

pub fn commit(&mut self, snapshot: ProjectionCacheSnapshot) {
self.map.commit(snapshot.snapshot);
}
Expand Down
22 changes: 4 additions & 18 deletions src/librustc/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use ty::subst::Substs;
use ty::{self, Ty, TypeFlags, TypeFoldable};

#[derive(Debug)]
pub struct FlagComputation {
pub flags: TypeFlags,

Expand Down Expand Up @@ -182,24 +183,9 @@ impl FlagComputation {
}

fn add_region(&mut self, r: &ty::Region) {
match *r {
ty::ReVar(..) => {
self.add_flags(TypeFlags::HAS_RE_INFER);
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX);
}
ty::ReSkolemized(..) => {
self.add_flags(TypeFlags::HAS_RE_INFER);
self.add_flags(TypeFlags::HAS_RE_SKOL);
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX);
}
ty::ReLateBound(debruijn, _) => { self.add_depth(debruijn.depth); }
ty::ReEarlyBound(..) => { self.add_flags(TypeFlags::HAS_RE_EARLY_BOUND); }
ty::ReStatic | ty::ReErased => {}
_ => { self.add_flags(TypeFlags::HAS_FREE_REGIONS); }
}

if !r.is_global() {
self.add_flags(TypeFlags::HAS_LOCAL_NAMES);
self.add_flags(r.type_flags());
if let ty::ReLateBound(debruijn, _) = *r {
self.add_depth(debruijn.depth);
}
}

Expand Down
26 changes: 9 additions & 17 deletions src/librustc/ty/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
fn needs_subst(&self) -> bool {
self.has_type_flags(TypeFlags::NEEDS_SUBST)
}
fn has_re_skol(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_RE_SKOL)
}
fn has_closure_types(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_CLOSURE)
}
Expand Down Expand Up @@ -632,26 +635,15 @@ struct HasTypeFlagsVisitor {

impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
fn visit_ty(&mut self, t: Ty) -> bool {
t.flags.get().intersects(self.flags)
let flags = t.flags.get();
debug!("HasTypeFlagsVisitor: t={:?} t.flags={:?} self.flags={:?}", t, flags, self.flags);
flags.intersects(self.flags)
}

fn visit_region(&mut self, r: &'tcx ty::Region) -> bool {
if self.flags.intersects(ty::TypeFlags::HAS_LOCAL_NAMES) {
// does this represent a region that cannot be named
// in a global way? used in fulfillment caching.
match *r {
ty::ReStatic | ty::ReEmpty | ty::ReErased => {}
_ => return true,
}
}
if self.flags.intersects(ty::TypeFlags::HAS_RE_INFER |
ty::TypeFlags::KEEP_IN_LOCAL_TCX) {
match *r {
ty::ReVar(_) | ty::ReSkolemized(..) => { return true }
_ => {}
}
}
false
let flags = r.type_flags();
debug!("HasTypeFlagsVisitor: r={:?} r.flags={:?} self.flags={:?}", r, flags, self.flags);
flags.intersects(self.flags)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ bitflags! {
TypeFlags::HAS_SELF.bits |
TypeFlags::HAS_TY_INFER.bits |
TypeFlags::HAS_RE_INFER.bits |
TypeFlags::HAS_RE_SKOL.bits |
TypeFlags::HAS_RE_EARLY_BOUND.bits |
TypeFlags::HAS_FREE_REGIONS.bits |
TypeFlags::HAS_TY_ERR.bits |
Expand Down
31 changes: 30 additions & 1 deletion src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl<T> Binder<T> {

impl fmt::Debug for TypeFlags {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.bits)
write!(f, "{:x}", self.bits)
}
}

Expand Down Expand Up @@ -866,6 +866,35 @@ impl Region {
r => r
}
}

pub fn type_flags(&self) -> TypeFlags {
let mut flags = TypeFlags::empty();

match *self {
ty::ReVar(..) => {
flags = flags | TypeFlags::HAS_RE_INFER;
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
}
ty::ReSkolemized(..) => {
flags = flags | TypeFlags::HAS_RE_INFER;
flags = flags | TypeFlags::HAS_RE_SKOL;
flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
}
ty::ReLateBound(..) => { }
ty::ReEarlyBound(..) => { flags = flags | TypeFlags::HAS_RE_EARLY_BOUND; }
ty::ReStatic | ty::ReErased => { }
_ => { flags = flags | TypeFlags::HAS_FREE_REGIONS; }
}

match *self {
ty::ReStatic | ty::ReEmpty | ty::ReErased => (),
_ => flags = flags | TypeFlags::HAS_LOCAL_NAMES,
}

debug!("type_flags({:?}) = {:?}", self, flags);

flags
}
}

// Type utilities
Expand Down
61 changes: 46 additions & 15 deletions src/librustc_data_structures/snapshot_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use fnv::FnvHashMap;
use std::hash::Hash;
use std::ops;
use std::mem;

#[cfg(test)]
mod test;
Expand All @@ -31,6 +32,7 @@ enum UndoLog<K, V> {
CommittedSnapshot,
Inserted(K),
Overwrite(K, V),
Noop,
}

impl<K, V> SnapshotMap<K, V>
Expand Down Expand Up @@ -100,24 +102,33 @@ impl<K, V> SnapshotMap<K, V>
}
}

pub fn partial_rollback<F>(&mut self,
snapshot: &Snapshot,
should_revert_key: &F)
where F: Fn(&K) -> bool
{
self.assert_open_snapshot(snapshot);
for i in (snapshot.len + 1..self.undo_log.len()).rev() {
let reverse = match self.undo_log[i] {
UndoLog::OpenSnapshot => false,
UndoLog::CommittedSnapshot => false,
UndoLog::Noop => false,
UndoLog::Inserted(ref k) => should_revert_key(k),
UndoLog::Overwrite(ref k, _) => should_revert_key(k),
};

if reverse {
let entry = mem::replace(&mut self.undo_log[i], UndoLog::Noop);
self.reverse(entry);
}
}
}

pub fn rollback_to(&mut self, snapshot: Snapshot) {
self.assert_open_snapshot(&snapshot);
while self.undo_log.len() > snapshot.len + 1 {
match self.undo_log.pop().unwrap() {
UndoLog::OpenSnapshot => {
panic!("cannot rollback an uncommitted snapshot");
}

UndoLog::CommittedSnapshot => {}

UndoLog::Inserted(key) => {
self.map.remove(&key);
}

UndoLog::Overwrite(key, old_value) => {
self.map.insert(key, old_value);
}
}
let entry = self.undo_log.pop().unwrap();
self.reverse(entry);
}

let v = self.undo_log.pop().unwrap();
Expand All @@ -127,6 +138,26 @@ impl<K, V> SnapshotMap<K, V>
});
assert!(self.undo_log.len() == snapshot.len);
}

fn reverse(&mut self, entry: UndoLog<K, V>) {
match entry {
UndoLog::OpenSnapshot => {
panic!("cannot rollback an uncommitted snapshot");
}

UndoLog::CommittedSnapshot => {}

UndoLog::Inserted(key) => {
self.map.remove(&key);
}

UndoLog::Overwrite(key, old_value) => {
self.map.insert(key, old_value);
}

UndoLog::Noop => {}
}
}
}

impl<'k, K, V> ops::Index<&'k K> for SnapshotMap<K, V>
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ pub fn phase_2_configure_and_expand<'a, F>(sess: &Session,
// its contents but the results of name resolution on those contents. Hopefully we'll push
// this back at some point.
let _ignore = sess.dep_graph.in_ignore();
let mut crate_loader = CrateLoader::new(sess, &cstore, &krate, crate_name);
let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name, krate.config.clone());
crate_loader.preprocess(&krate);
let resolver_arenas = Resolver::arenas();
let mut resolver =
Resolver::new(sess, &krate, make_glob_map, &mut crate_loader, &resolver_arenas);
Expand Down
Loading