Skip to content

Commit 86b3739

Browse files
---
yaml --- r: 188366 b: refs/heads/auto c: 2f88655 h: refs/heads/master v: v3
1 parent 74549d4 commit 86b3739

File tree

26 files changed

+741
-201
lines changed

26 files changed

+741
-201
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: bdf6e4fcf5ed8b8fe3c281040414e4f6a6afb8d6
13+
refs/heads/auto: 2f8865556bd6cae123b3db4ceaa0c7977dacea8d
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#![feature(unboxed_closures)]
7474
#![feature(unsafe_no_drop_flag)]
7575
#![feature(core)]
76+
#![feature(unique)]
7677
#![cfg_attr(test, feature(test, alloc, rustc_private))]
7778
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
7879
feature(libc))]

branches/auto/src/libcollections/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,8 +2176,8 @@ mod tests {
21762176
fn test_connect() {
21772177
let v: [Vec<i32>; 0] = [];
21782178
assert_eq!(v.connect(&0), []);
2179-
assert_eq!([vec![1], vec![2, 3]].connect(&0), [1, 0, 2, 3]);
2180-
assert_eq!([vec![1], vec![2], vec![3]].connect(&0), [1, 0, 2, 0, 3]);
2179+
assert_eq!([vec![1i], vec![2, 3]].connect(&0), [1, 0, 2, 3]);
2180+
assert_eq!([vec![1i], vec![2], vec![3]].connect(&0), [1, 0, 2, 0, 3]);
21812181

21822182
let v: [&[_]; 2] = [&[1], &[2, 3]];
21832183
assert_eq!(v.connect(&0), [1, 0, 2, 3]);

branches/auto/src/libcore/iter.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,13 +1570,24 @@ pub struct Map<I, F> {
15701570
f: F,
15711571
}
15721572

1573+
impl<I: Iterator, F, B> Map<I, F> where F: FnMut(I::Item) -> B {
1574+
#[inline]
1575+
fn do_map(&mut self, elt: Option<I::Item>) -> Option<B> {
1576+
match elt {
1577+
Some(a) => Some((self.f)(a)),
1578+
_ => None
1579+
}
1580+
}
1581+
}
1582+
15731583
#[stable(feature = "rust1", since = "1.0.0")]
15741584
impl<B, I: Iterator, F> Iterator for Map<I, F> where F: FnMut(I::Item) -> B {
15751585
type Item = B;
15761586

15771587
#[inline]
15781588
fn next(&mut self) -> Option<B> {
1579-
self.iter.next().map(|a| (self.f)(a))
1589+
let next = self.iter.next();
1590+
self.do_map(next)
15801591
}
15811592

15821593
#[inline]
@@ -1591,7 +1602,8 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for Map<I, F> where
15911602
{
15921603
#[inline]
15931604
fn next_back(&mut self) -> Option<B> {
1594-
self.iter.next_back().map(|a| (self.f)(a))
1605+
let next = self.iter.next_back();
1606+
self.do_map(next)
15951607
}
15961608
}
15971609

@@ -1606,7 +1618,8 @@ impl<B, I: RandomAccessIterator, F> RandomAccessIterator for Map<I, F> where
16061618

16071619
#[inline]
16081620
fn idx(&mut self, index: usize) -> Option<B> {
1609-
self.iter.idx(index).map(|a| (self.f)(a))
1621+
let elt = self.iter.idx(index);
1622+
self.do_map(elt)
16101623
}
16111624
}
16121625

branches/auto/src/libcoretest/hash/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct CustomHasher { output: u64 }
8686

8787
impl Hasher for CustomHasher {
8888
fn finish(&self) -> u64 { self.output }
89-
fn write(&mut self, _: &[u8]) { panic!() }
89+
fn write(&mut self, data: &[u8]) { panic!() }
9090
fn write_u64(&mut self, data: u64) { self.output = data; }
9191
}
9292

branches/auto/src/libcoretest/str.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,15 @@ fn trim_ws() {
188188

189189
mod pattern {
190190
use std::str::Pattern;
191-
use std::str::{Searcher, ReverseSearcher};
191+
use std::str::{Searcher, ReverseSearcher, DoubleEndedSearcher};
192192
use std::str::SearchStep::{self, Match, Reject, Done};
193193

194194
macro_rules! make_test {
195195
($name:ident, $p:expr, $h:expr, [$($e:expr,)*]) => {
196196
mod $name {
197-
use std::str::SearchStep::{Match, Reject};
197+
use std::str::Pattern;
198+
use std::str::{Searcher, ReverseSearcher, DoubleEndedSearcher};
199+
use std::str::SearchStep::{self, Match, Reject, Done};
198200
use super::{cmp_search_to_vec};
199201
#[test]
200202
fn fwd() {

branches/auto/src/librand/rand_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl<T:Rand> Rand for Option<T> {
214214

215215
#[cfg(test)]
216216
mod tests {
217+
use std::prelude::v1::*;
217218
use std::rand::{Rng, thread_rng, Open01, Closed01};
218219

219220
struct ConstantRng(u64);

branches/auto/src/librbml/io.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,32 +140,32 @@ mod tests {
140140
fn test_seekable_mem_writer() {
141141
let mut writer = SeekableMemWriter::new();
142142
assert_eq!(writer.tell(), Ok(0));
143-
writer.write_all(&[0]).unwrap();
143+
writer.write(&[0]).unwrap();
144144
assert_eq!(writer.tell(), Ok(1));
145-
writer.write_all(&[1, 2, 3]).unwrap();
146-
writer.write_all(&[4, 5, 6, 7]).unwrap();
145+
writer.write(&[1, 2, 3]).unwrap();
146+
writer.write(&[4, 5, 6, 7]).unwrap();
147147
assert_eq!(writer.tell(), Ok(8));
148148
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7];
149149
assert_eq!(writer.get_ref(), b);
150150

151151
writer.seek(0, old_io::SeekSet).unwrap();
152152
assert_eq!(writer.tell(), Ok(0));
153-
writer.write_all(&[3, 4]).unwrap();
153+
writer.write(&[3, 4]).unwrap();
154154
let b: &[_] = &[3, 4, 2, 3, 4, 5, 6, 7];
155155
assert_eq!(writer.get_ref(), b);
156156

157157
writer.seek(1, old_io::SeekCur).unwrap();
158-
writer.write_all(&[0, 1]).unwrap();
158+
writer.write(&[0, 1]).unwrap();
159159
let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 7];
160160
assert_eq!(writer.get_ref(), b);
161161

162162
writer.seek(-1, old_io::SeekEnd).unwrap();
163-
writer.write_all(&[1, 2]).unwrap();
163+
writer.write(&[1, 2]).unwrap();
164164
let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 1, 2];
165165
assert_eq!(writer.get_ref(), b);
166166

167167
writer.seek(1, old_io::SeekEnd).unwrap();
168-
writer.write_all(&[1]).unwrap();
168+
writer.write(&[1]).unwrap();
169169
let b: &[_] = &[3, 4, 2, 0, 1, 5, 6, 1, 2, 0, 1];
170170
assert_eq!(writer.get_ref(), b);
171171
}
@@ -174,7 +174,7 @@ mod tests {
174174
fn seek_past_end() {
175175
let mut r = SeekableMemWriter::new();
176176
r.seek(10, old_io::SeekSet).unwrap();
177-
assert!(r.write_all(&[3]).is_ok());
177+
assert!(r.write(&[3]).is_ok());
178178
}
179179

180180
#[test]
@@ -190,7 +190,7 @@ mod tests {
190190
b.iter(|| {
191191
let mut wr = SeekableMemWriter::new();
192192
for _ in 0..times {
193-
wr.write_all(&src).unwrap();
193+
wr.write(&src).unwrap();
194194
}
195195

196196
let v = wr.unwrap();

branches/auto/src/librustc/metadata/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,6 @@ pub const tag_macro_def: uint = 0x9e;
252252
pub const tag_macro_def_body: uint = 0x9f;
253253

254254
pub const tag_paren_sugar: uint = 0xa0;
255+
256+
pub const tag_codemap: uint = 0xa1;
257+
pub const tag_codemap_filemap: uint = 0xa2;

branches/auto/src/librustc/metadata/creader.rs

Lines changed: 133 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use syntax::ast;
2626
use syntax::abi;
2727
use syntax::attr;
2828
use syntax::attr::AttrMetaMethods;
29-
use syntax::codemap::{Span, mk_sp};
29+
use syntax::codemap::{self, Span, mk_sp, Pos};
3030
use syntax::parse;
3131
use syntax::parse::token::InternedString;
3232
use syntax::parse::token;
@@ -373,15 +373,17 @@ impl<'a> CrateReader<'a> {
373373
// Maintain a reference to the top most crate.
374374
let root = if root.is_some() { root } else { &crate_paths };
375375

376-
let cnum_map = self.resolve_crate_deps(root, lib.metadata.as_slice(), span);
376+
let loader::Library { dylib, rlib, metadata } = lib;
377377

378-
let loader::Library{ dylib, rlib, metadata } = lib;
378+
let cnum_map = self.resolve_crate_deps(root, metadata.as_slice(), span);
379+
let codemap_import_info = import_codemap(self.sess.codemap(), &metadata);
379380

380381
let cmeta = Rc::new( cstore::crate_metadata {
381382
name: name.to_string(),
382383
data: metadata,
383384
cnum_map: cnum_map,
384385
cnum: cnum,
386+
codemap_import_info: codemap_import_info,
385387
span: span,
386388
});
387389

@@ -586,3 +588,131 @@ impl<'a> CrateReader<'a> {
586588
}
587589
}
588590
}
591+
592+
/// Imports the codemap from an external crate into the codemap of the crate
593+
/// currently being compiled (the "local crate").
594+
///
595+
/// The import algorithm works analogous to how AST items are inlined from an
596+
/// external crate's metadata:
597+
/// For every FileMap in the external codemap an 'inline' copy is created in the
598+
/// local codemap. The correspondence relation between external and local
599+
/// FileMaps is recorded in the `ImportedFileMap` objects returned from this
600+
/// function. When an item from an external crate is later inlined into this
601+
/// crate, this correspondence information is used to translate the span
602+
/// information of the inlined item so that it refers the correct positions in
603+
/// the local codemap (see `astencode::DecodeContext::tr_span()`).
604+
///
605+
/// The import algorithm in the function below will reuse FileMaps already
606+
/// existing in the local codemap. For example, even if the FileMap of some
607+
/// source file of libstd gets imported many times, there will only ever be
608+
/// one FileMap object for the corresponding file in the local codemap.
609+
///
610+
/// Note that imported FileMaps do not actually contain the source code of the
611+
/// file they represent, just information about length, line breaks, and
612+
/// multibyte characters. This information is enough to generate valid debuginfo
613+
/// for items inlined from other crates.
614+
fn import_codemap(local_codemap: &codemap::CodeMap,
615+
metadata: &MetadataBlob)
616+
-> Vec<cstore::ImportedFileMap> {
617+
let external_codemap = decoder::get_imported_filemaps(metadata.as_slice());
618+
619+
let imported_filemaps = external_codemap.into_iter().map(|filemap_to_import| {
620+
// Try to find an existing FileMap that can be reused for the filemap to
621+
// be imported. A FileMap is reusable if it is exactly the same, just
622+
// positioned at a different offset within the codemap.
623+
let reusable_filemap = {
624+
local_codemap.files
625+
.borrow()
626+
.iter()
627+
.find(|fm| are_equal_modulo_startpos(&fm, &filemap_to_import))
628+
.map(|rc| rc.clone())
629+
};
630+
631+
match reusable_filemap {
632+
Some(fm) => {
633+
cstore::ImportedFileMap {
634+
original_start_pos: filemap_to_import.start_pos,
635+
original_end_pos: filemap_to_import.end_pos,
636+
translated_filemap: fm
637+
}
638+
}
639+
None => {
640+
// We can't reuse an existing FileMap, so allocate a new one
641+
// containing the information we need.
642+
let codemap::FileMap {
643+
name,
644+
start_pos,
645+
end_pos,
646+
lines,
647+
multibyte_chars,
648+
..
649+
} = filemap_to_import;
650+
651+
let source_length = (end_pos - start_pos).to_usize();
652+
653+
// Translate line-start positions and multibyte character
654+
// position into frame of reference local to file.
655+
// `CodeMap::new_imported_filemap()` will then translate those
656+
// coordinates to their new global frame of reference when the
657+
// offset of the FileMap is known.
658+
let lines = lines.into_inner().map_in_place(|pos| pos - start_pos);
659+
let multibyte_chars = multibyte_chars
660+
.into_inner()
661+
.map_in_place(|mbc|
662+
codemap::MultiByteChar {
663+
pos: mbc.pos + start_pos,
664+
bytes: mbc.bytes
665+
});
666+
667+
let local_version = local_codemap.new_imported_filemap(name,
668+
source_length,
669+
lines,
670+
multibyte_chars);
671+
cstore::ImportedFileMap {
672+
original_start_pos: start_pos,
673+
original_end_pos: end_pos,
674+
translated_filemap: local_version
675+
}
676+
}
677+
}
678+
}).collect();
679+
680+
return imported_filemaps;
681+
682+
fn are_equal_modulo_startpos(fm1: &codemap::FileMap,
683+
fm2: &codemap::FileMap)
684+
-> bool {
685+
if fm1.name != fm2.name {
686+
return false;
687+
}
688+
689+
let lines1 = fm1.lines.borrow();
690+
let lines2 = fm2.lines.borrow();
691+
692+
if lines1.len() != lines2.len() {
693+
return false;
694+
}
695+
696+
for (&line1, &line2) in lines1.iter().zip(lines2.iter()) {
697+
if (line1 - fm1.start_pos) != (line2 - fm2.start_pos) {
698+
return false;
699+
}
700+
}
701+
702+
let multibytes1 = fm1.multibyte_chars.borrow();
703+
let multibytes2 = fm2.multibyte_chars.borrow();
704+
705+
if multibytes1.len() != multibytes2.len() {
706+
return false;
707+
}
708+
709+
for (mb1, mb2) in multibytes1.iter().zip(multibytes2.iter()) {
710+
if (mb1.bytes != mb2.bytes) ||
711+
((mb1.pos - fm1.start_pos) != (mb2.pos - fm2.start_pos)) {
712+
return false;
713+
}
714+
}
715+
716+
true
717+
}
718+
}

branches/auto/src/librustc/metadata/cstore.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::cell::RefCell;
2727
use std::rc::Rc;
2828
use flate::Bytes;
2929
use syntax::ast;
30-
use syntax::codemap::Span;
30+
use syntax::codemap;
3131
use syntax::parse::token::IdentInterner;
3232

3333
// A map from external crate numbers (as decoded from some crate file) to
@@ -41,12 +41,24 @@ pub enum MetadataBlob {
4141
MetadataArchive(loader::ArchiveMetadata),
4242
}
4343

44+
/// Holds information about a codemap::FileMap imported from another crate.
45+
/// See creader::import_codemap() for more information.
46+
pub struct ImportedFileMap {
47+
/// This FileMap's byte-offset within the codemap of its original crate
48+
pub original_start_pos: codemap::BytePos,
49+
/// The end of this FileMap within the codemap of its original crate
50+
pub original_end_pos: codemap::BytePos,
51+
/// The imported FileMap's representation within the local codemap
52+
pub translated_filemap: Rc<codemap::FileMap>
53+
}
54+
4455
pub struct crate_metadata {
4556
pub name: String,
4657
pub data: MetadataBlob,
4758
pub cnum_map: cnum_map,
4859
pub cnum: ast::CrateNum,
49-
pub span: Span,
60+
pub codemap_import_info: Vec<ImportedFileMap>,
61+
pub span: codemap::Span,
5062
}
5163

5264
#[derive(Copy, Debug, PartialEq, Clone)]

branches/auto/src/librustc/metadata/decoder.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,11 +1561,26 @@ pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
15611561
}
15621562
}
15631563

1564-
15651564
pub fn is_default_trait<'tcx>(cdata: Cmd, id: ast::NodeId) -> bool {
15661565
let item_doc = lookup_item(id, cdata.data());
15671566
match item_family(item_doc) {
15681567
Family::DefaultImpl => true,
15691568
_ => false
15701569
}
15711570
}
1571+
1572+
pub fn get_imported_filemaps(metadata: &[u8]) -> Vec<codemap::FileMap> {
1573+
let crate_doc = rbml::Doc::new(metadata);
1574+
let cm_doc = reader::get_doc(crate_doc, tag_codemap);
1575+
1576+
let mut filemaps = vec![];
1577+
1578+
reader::tagged_docs(cm_doc, tag_codemap_filemap, |filemap_doc| {
1579+
let mut decoder = reader::Decoder::new(filemap_doc);
1580+
let filemap: codemap::FileMap = Decodable::decode(&mut decoder).unwrap();
1581+
filemaps.push(filemap);
1582+
true
1583+
});
1584+
1585+
return filemaps;
1586+
}

0 commit comments

Comments
 (0)