Skip to content

Commit a87db3e

Browse files
committed
rustc: Use the new for protocol
1 parent 5eb6d19 commit a87db3e

File tree

16 files changed

+628
-19
lines changed

16 files changed

+628
-19
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,24 @@ pub fn get_type_param_count(cstore: @mut cstore::CStore, def: ast::def_id)
4444
}
4545

4646
/// Iterates over all the language items in the given crate.
47+
#[cfg(stage0)]
4748
pub fn each_lang_item(cstore: @mut cstore::CStore,
4849
cnum: ast::crate_num,
4950
f: &fn(ast::node_id, uint) -> bool) {
5051
let crate_data = cstore::get_crate_data(cstore, cnum);
5152
decoder::each_lang_item(crate_data, f)
5253
}
54+
/// Iterates over all the language items in the given crate.
55+
#[cfg(not(stage0))]
56+
pub fn each_lang_item(cstore: @mut cstore::CStore,
57+
cnum: ast::crate_num,
58+
f: &fn(ast::node_id, uint) -> bool) -> bool {
59+
let crate_data = cstore::get_crate_data(cstore, cnum);
60+
decoder::each_lang_item(crate_data, f)
61+
}
5362

5463
/// Iterates over all the paths in the given crate.
64+
#[cfg(stage0)]
5565
pub fn each_path(cstore: @mut cstore::CStore,
5666
cnum: ast::crate_num,
5767
f: &fn(&str, decoder::def_like) -> bool) {
@@ -61,6 +71,17 @@ pub fn each_path(cstore: @mut cstore::CStore,
6171
};
6272
decoder::each_path(cstore.intr, crate_data, get_crate_data, f);
6373
}
74+
/// Iterates over all the paths in the given crate.
75+
#[cfg(not(stage0))]
76+
pub fn each_path(cstore: @mut cstore::CStore,
77+
cnum: ast::crate_num,
78+
f: &fn(&str, decoder::def_like) -> bool) -> bool {
79+
let crate_data = cstore::get_crate_data(cstore, cnum);
80+
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
81+
cstore::get_crate_data(cstore, cnum)
82+
};
83+
decoder::each_path(cstore.intr, crate_data, get_crate_data, f)
84+
}
6485

6586
pub fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
6687
let cstore = tcx.cstore;

src/librustc/metadata/decoder.rs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,23 @@ fn item_def_id(d: ebml::Doc, cdata: cmd) -> ast::def_id {
196196
|d| parse_def_id(d)));
197197
}
198198
199+
#[cfg(stage0)]
199200
fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) {
200201
for reader::tagged_docs(d, tag_items_data_item_reexport) |reexport_doc| {
201202
if !f(reexport_doc) {
202203
return;
203204
}
204205
}
205206
}
207+
#[cfg(not(stage0))]
208+
fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) -> bool {
209+
for reader::tagged_docs(d, tag_items_data_item_reexport) |reexport_doc| {
210+
if !f(reexport_doc) {
211+
return false;
212+
}
213+
}
214+
return true;
215+
}
206216
207217
fn variant_disr_val(d: ebml::Doc) -> Option<int> {
208218
do reader::maybe_get_doc(d, tag_disr_val).chain |val_doc| {
@@ -454,6 +464,7 @@ fn def_like_to_def(def_like: def_like) -> ast::def {
454464
}
455465
456466
/// Iterates over the language items in the given crate.
467+
#[cfg(stage0)]
457468
pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) {
458469
let root = reader::Doc(cdata.data);
459470
let lang_items = reader::get_doc(root, tag_lang_items);
@@ -469,11 +480,29 @@ pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) {
469480
}
470481
}
471482
}
483+
/// Iterates over the language items in the given crate.
484+
#[cfg(not(stage0))]
485+
pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) -> bool {
486+
let root = reader::Doc(cdata.data);
487+
let lang_items = reader::get_doc(root, tag_lang_items);
488+
for reader::tagged_docs(lang_items, tag_lang_items_item) |item_doc| {
489+
let id_doc = reader::get_doc(item_doc, tag_lang_items_item_id);
490+
let id = reader::doc_as_u32(id_doc) as uint;
491+
let node_id_doc = reader::get_doc(item_doc,
492+
tag_lang_items_item_node_id);
493+
let node_id = reader::doc_as_u32(node_id_doc) as ast::node_id;
494+
495+
if !f(node_id, id) {
496+
return false;
497+
}
498+
}
499+
return true;
500+
}
472501
473502
/// Iterates over all the paths in the given crate.
474-
pub fn each_path(intr: @ident_interner, cdata: cmd,
475-
get_crate_data: GetCrateDataCb,
476-
f: &fn(&str, def_like) -> bool) {
503+
pub fn _each_path(intr: @ident_interner, cdata: cmd,
504+
get_crate_data: GetCrateDataCb,
505+
f: &fn(&str, def_like) -> bool) -> bool {
477506
let root = reader::Doc(cdata.data);
478507
let items = reader::get_doc(root, tag_items);
479508
let items_data = reader::get_doc(items, tag_items_data);
@@ -555,10 +584,20 @@ pub fn each_path(intr: @ident_interner, cdata: cmd,
555584
}
556585
}
557586
558-
// If broken, stop here.
559-
if broken {
560-
return;
561-
}
587+
return broken;
588+
}
589+
590+
#[cfg(stage0)]
591+
pub fn each_path(intr: @ident_interner, cdata: cmd,
592+
get_crate_data: GetCrateDataCb,
593+
f: &fn(&str, def_like) -> bool) {
594+
_each_path(intr, cdata, get_crate_data, f);
595+
}
596+
#[cfg(not(stage0))]
597+
pub fn each_path(intr: @ident_interner, cdata: cmd,
598+
get_crate_data: GetCrateDataCb,
599+
f: &fn(&str, def_like) -> bool) -> bool {
600+
_each_path(intr, cdata, get_crate_data, f)
562601
}
563602
564603
pub fn get_item_path(intr: @ident_interner, cdata: cmd, id: ast::node_id)

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,11 +1391,10 @@ pub fn encode_metadata(parms: EncodeParams, crate: &crate) -> ~[u8] {
13911391
ecx.stats.total_bytes = *wr.pos;
13921392
13931393
if (tcx.sess.meta_stats()) {
1394-
do wr.bytes.each |e| {
1394+
for wr.bytes.each |e| {
13951395
if *e == 0 {
13961396
ecx.stats.zero_bytes += 1;
13971397
}
1398-
true
13991398
}
14001399
14011400
io::println("metadata stats:");

src/librustc/metadata/filesearch.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
2121

2222
pub trait FileSearch {
2323
fn sysroot(&self) -> @Path;
24+
#[cfg(stage0)]
2425
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool);
26+
#[cfg(not(stage0))]
27+
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) -> bool;
2528
fn get_target_lib_path(&self) -> Path;
2629
fn get_target_lib_file_path(&self, file: &Path) -> Path;
2730
}
@@ -37,6 +40,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
3740
}
3841
impl FileSearch for FileSearchImpl {
3942
fn sysroot(&self) -> @Path { self.sysroot }
43+
#[cfg(stage0)]
4044
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) {
4145
debug!("filesearch: searching additional lib search paths");
4246
// a little weird
@@ -60,6 +64,30 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
6064
result::Err(_) => true
6165
};
6266
}
67+
#[cfg(not(stage0))]
68+
fn for_each_lib_search_path(&self, f: &fn(&Path) -> bool) -> bool {
69+
debug!("filesearch: searching additional lib search paths");
70+
// a little weird
71+
self.addl_lib_search_paths.each(f);
72+
73+
debug!("filesearch: searching target lib path");
74+
if !f(&make_target_lib_path(self.sysroot,
75+
self.target_triple)) {
76+
return false;
77+
}
78+
debug!("filesearch: searching rustpkg lib path nearest");
79+
if match get_rustpkg_lib_path_nearest() {
80+
result::Ok(ref p) => f(p),
81+
result::Err(_) => true
82+
} {
83+
return true;
84+
}
85+
debug!("filesearch: searching rustpkg lib path");
86+
match get_rustpkg_lib_path() {
87+
result::Ok(ref p) => f(p),
88+
result::Err(_) => true
89+
}
90+
}
6391
fn get_target_lib_path(&self) -> Path {
6492
make_target_lib_path(self.sysroot, self.target_triple)
6593
}

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ enum MoveError {
6767
pub impl<'self> CheckLoanCtxt<'self> {
6868
fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
6969

70+
#[cfg(stage0)]
7071
fn each_issued_loan(&self,
7172
scope_id: ast::node_id,
7273
op: &fn(&Loan) -> bool)
@@ -84,7 +85,27 @@ pub impl<'self> CheckLoanCtxt<'self> {
8485
}
8586
}
8687
}
88+
#[cfg(not(stage0))]
89+
fn each_issued_loan(&self,
90+
scope_id: ast::node_id,
91+
op: &fn(&Loan) -> bool) -> bool
92+
{
93+
//! Iterates over each loan that that has been issued
94+
//! on entrance to `scope_id`, regardless of whether it is
95+
//! actually *in scope* at that point. Sometimes loans
96+
//! are issued for future scopes and thus they may have been
97+
//! *issued* but not yet be in effect.
98+
99+
for self.dfcx.each_bit_on_entry(scope_id) |loan_index| {
100+
let loan = &self.all_loans[loan_index];
101+
if !op(loan) {
102+
return false;
103+
}
104+
}
105+
return true;
106+
}
87107

108+
#[cfg(stage0)]
88109
fn each_in_scope_loan(&self,
89110
scope_id: ast::node_id,
90111
op: &fn(&Loan) -> bool)
@@ -101,7 +122,26 @@ pub impl<'self> CheckLoanCtxt<'self> {
101122
}
102123
}
103124
}
125+
#[cfg(not(stage0))]
126+
fn each_in_scope_loan(&self,
127+
scope_id: ast::node_id,
128+
op: &fn(&Loan) -> bool) -> bool
129+
{
130+
//! Like `each_issued_loan()`, but only considers loans that are
131+
//! currently in scope.
104132
133+
let region_maps = self.tcx().region_maps;
134+
for self.each_issued_loan(scope_id) |loan| {
135+
if region_maps.is_subscope_of(scope_id, loan.kill_scope) {
136+
if !op(loan) {
137+
return false;
138+
}
139+
}
140+
}
141+
return true;
142+
}
143+
144+
#[cfg(stage0)]
105145
fn each_in_scope_restriction(&self,
106146
scope_id: ast::node_id,
107147
loan_path: @LoanPath,
@@ -120,6 +160,26 @@ pub impl<'self> CheckLoanCtxt<'self> {
120160
}
121161
}
122162
}
163+
#[cfg(not(stage0))]
164+
fn each_in_scope_restriction(&self,
165+
scope_id: ast::node_id,
166+
loan_path: @LoanPath,
167+
op: &fn(&Loan, &Restriction) -> bool) -> bool
168+
{
169+
//! Iterates through all the in-scope restrictions for the
170+
//! given `loan_path`
171+
172+
for self.each_in_scope_loan(scope_id) |loan| {
173+
for loan.restrictions.each |restr| {
174+
if restr.loan_path == loan_path {
175+
if !op(loan, restr) {
176+
return false;
177+
}
178+
}
179+
}
180+
}
181+
return true;
182+
}
123183

124184
fn loans_generated_by(&self, scope_id: ast::node_id) -> ~[uint] {
125185
//! Returns a vector of the loans that are generated as

src/librustc/middle/dataflow.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ impl<O:DataFlowOperator> DataFlowContext<O> {
182182
}
183183

184184

185+
#[cfg(stage0)]
185186
pub fn each_bit_on_entry(&self,
186187
id: ast::node_id,
187188
f: &fn(uint) -> bool) {
@@ -194,7 +195,21 @@ impl<O:DataFlowOperator> DataFlowContext<O> {
194195
id, bits_to_str(on_entry));
195196
self.each_bit(on_entry, f);
196197
}
198+
#[cfg(not(stage0))]
199+
pub fn each_bit_on_entry(&self,
200+
id: ast::node_id,
201+
f: &fn(uint) -> bool) -> bool {
202+
//! Iterates through each bit that is set on entry to `id`.
203+
//! Only useful after `propagate()` has been called.
204+
205+
let (start, end) = self.compute_id_range(id);
206+
let on_entry = vec::slice(self.on_entry, start, end);
207+
debug!("each_bit_on_entry(id=%?, on_entry=%s)",
208+
id, bits_to_str(on_entry));
209+
self.each_bit(on_entry, f)
210+
}
197211

212+
#[cfg(stage0)]
198213
pub fn each_gen_bit(&self,
199214
id: ast::node_id,
200215
f: &fn(uint) -> bool) {
@@ -206,7 +221,20 @@ impl<O:DataFlowOperator> DataFlowContext<O> {
206221
id, bits_to_str(gens));
207222
self.each_bit(gens, f)
208223
}
224+
#[cfg(not(stage0))]
225+
pub fn each_gen_bit(&self,
226+
id: ast::node_id,
227+
f: &fn(uint) -> bool) -> bool {
228+
//! Iterates through each bit in the gen set for `id`.
209229
230+
let (start, end) = self.compute_id_range(id);
231+
let gens = vec::slice(self.gens, start, end);
232+
debug!("each_gen_bit(id=%?, gens=%s)",
233+
id, bits_to_str(gens));
234+
self.each_bit(gens, f)
235+
}
236+
237+
#[cfg(stage0)]
210238
fn each_bit(&self,
211239
words: &[uint],
212240
f: &fn(uint) -> bool) {
@@ -236,6 +264,39 @@ impl<O:DataFlowOperator> DataFlowContext<O> {
236264
}
237265
}
238266
}
267+
#[cfg(not(stage0))]
268+
fn each_bit(&self,
269+
words: &[uint],
270+
f: &fn(uint) -> bool) -> bool {
271+
//! Helper for iterating over the bits in a bit set.
272+
273+
for words.eachi |word_index, &word| {
274+
if word != 0 {
275+
let base_index = word_index * uint::bits;
276+
for uint::range(0, uint::bits) |offset| {
277+
let bit = 1 << offset;
278+
if (word & bit) != 0 {
279+
// NB: we round up the total number of bits
280+
// that we store in any given bit set so that
281+
// it is an even multiple of uint::bits. This
282+
// means that there may be some stray bits at
283+
// the end that do not correspond to any
284+
// actual value. So before we callback, check
285+
// whether the bit_index is greater than the
286+
// actual value the user specified and stop
287+
// iterating if so.
288+
let bit_index = base_index + offset;
289+
if bit_index >= self.bits_per_id {
290+
return true;
291+
} else if !f(bit_index) {
292+
return false;
293+
}
294+
}
295+
}
296+
}
297+
}
298+
return true;
299+
}
239300
}
240301

241302
impl<O:DataFlowOperator+Copy+'static> DataFlowContext<O> {

src/librustc/middle/lang_items.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,18 @@ pub impl LanguageItems {
8686
}
8787
}
8888

89+
#[cfg(stage0)]
8990
fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) {
9091
for self.items.eachi |i, &item| {
9192
if !f(item.get(), i) {
9293
break;
9394
}
9495
}
9596
}
97+
#[cfg(not(stage0))]
98+
fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) -> bool {
99+
self.items.eachi(|i, &item| f(item.get(), i))
100+
}
96101

97102
pub fn item_name(index: uint) -> &'static str {
98103
match index {

0 commit comments

Comments
 (0)