Skip to content

Commit 6d34691

Browse files
committed
---
yaml --- r: 136446 b: refs/heads/dist-snap c: ef4b921 h: refs/heads/master v: v3
1 parent b85be0e commit 6d34691

File tree

27 files changed

+188
-405
lines changed

27 files changed

+188
-405
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 189b7332968972f34cdbbbd9b62d97ababf53059
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 8875584363c1c1569dad3ac573b9a6bd775de894
9+
refs/heads/dist-snap: ef4b92159997093e1fd53a6f8dde377d78d7da4a
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/doc/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4273,7 +4273,7 @@ very common with iterators: we can ignore unnecessary bounds checks, but still
42734273
know that we're safe.
42744274

42754275
There's another detail here that's not 100% clear because of how `println!`
4276-
works. `num` is actually of type `&int`. That is, it's a reference to an `int`,
4276+
works. `num` is actually of type `&int`, that is, it's a reference to an `int`,
42774277
not an `int` itself. `println!` handles the dereferencing for us, so we don't
42784278
see it. This code works fine too:
42794279

branches/dist-snap/src/libcore/str.rs

Lines changed: 10 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -419,76 +419,8 @@ struct TwoWaySearcher {
419419
memory: uint
420420
}
421421

422-
/*
423-
This is the Two-Way search algorithm, which was introduced in the paper:
424-
Crochemore, M., Perrin, D., 1991, Two-way string-matching, Journal of the ACM 38(3):651-675.
425-
426-
Here's some background information.
427-
428-
A *word* is a string of symbols. The *length* of a word should be a familiar
429-
notion, and here we denote it for any word x by |x|.
430-
(We also allow for the possibility of the *empty word*, a word of length zero).
431-
432-
If x is any non-empty word, then an integer p with 0 < p <= |x| is said to be a
433-
*period* for x iff for all i with 0 <= i <= |x| - p - 1, we have x[i] == x[i+p].
434-
For example, both 1 and 2 are periods for the string "aa". As another example,
435-
the only period of the string "abcd" is 4.
436-
437-
We denote by period(x) the *smallest* period of x (provided that x is non-empty).
438-
This is always well-defined since every non-empty word x has at least one period,
439-
|x|. We sometimes call this *the period* of x.
440-
441-
If u, v and x are words such that x = uv, where uv is the concatenation of u and
442-
v, then we say that (u, v) is a *factorization* of x.
443-
444-
Let (u, v) be a factorization for a word x. Then if w is a non-empty word such
445-
that both of the following hold
446-
447-
- either w is a suffix of u or u is a suffix of w
448-
- either w is a prefix of v or v is a prefix of w
449-
450-
then w is said to be a *repetition* for the factorization (u, v).
451-
452-
Just to unpack this, there are four possibilities here. Let w = "abc". Then we
453-
might have:
454-
455-
- w is a suffix of u and w is a prefix of v. ex: ("lolabc", "abcde")
456-
- w is a suffix of u and v is a prefix of w. ex: ("lolabc", "ab")
457-
- u is a suffix of w and w is a prefix of v. ex: ("bc", "abchi")
458-
- u is a suffix of w and v is a prefix of w. ex: ("bc", "a")
459-
460-
Note that the word vu is a repetition for any factorization (u,v) of x = uv,
461-
so every factorization has at least one repetition.
462-
463-
If x is a string and (u, v) is a factorization for x, then a *local period* for
464-
(u, v) is an integer r such that there is some word w such that |w| = r and w is
465-
a repetition for (u, v).
466-
467-
We denote by local_period(u, v) the smallest local period of (u, v). We sometimes
468-
call this *the local period* of (u, v). Provided that x = uv is non-empty, this
469-
is well-defined (because each non-empty word has at least one factorization, as
470-
noted above).
471-
472-
It can be proven that the following is an equivalent definition of a local period
473-
for a factorization (u, v): any positive integer r such that x[i] == x[i+r] for
474-
all i such that |u| - r <= i <= |u| - 1 and such that both x[i] and x[i+r] are
475-
defined. (i.e. i > 0 and i + r < |x|).
476-
477-
Using the above reformulation, it is easy to prove that
478-
479-
1 <= local_period(u, v) <= period(uv)
480-
481-
A factorization (u, v) of x such that local_period(u,v) = period(x) is called a
482-
*critical factorization*.
483-
484-
The algorithm hinges on the following theorem, which is stated without proof:
485-
486-
**Critical Factorization Theorem** Any word x has at least one critical
487-
factorization (u, v) such that |u| < period(x).
488-
489-
The purpose of maximal_suffix is to find such a critical factorization.
490-
491-
*/
422+
// This is the Two-Way search algorithm, which was introduced in the paper:
423+
// Crochemore, M., Perrin, D., 1991, Two-way string-matching, Journal of the ACM 38(3):651-675.
492424
impl TwoWaySearcher {
493425
fn new(needle: &[u8]) -> TwoWaySearcher {
494426
let (crit_pos1, period1) = TwoWaySearcher::maximal_suffix(needle, false);
@@ -504,19 +436,15 @@ impl TwoWaySearcher {
504436
period = period2;
505437
}
506438

507-
// This isn't in the original algorithm, as far as I'm aware.
508439
let byteset = needle.iter()
509440
.fold(0, |a, &b| (1 << ((b & 0x3f) as uint)) | a);
510441

511-
// A particularly readable explanation of what's going on here can be found
512-
// in Crochemore and Rytter's book "Text Algorithms", ch 13. Specifically
513-
// see the code for "Algorithm CP" on p. 323.
442+
// The logic here (calculating crit_pos and period, the final if statement to see which
443+
// period to use for the TwoWaySearcher) is essentially an implementation of the
444+
// "small-period" function from the paper (p. 670)
514445
//
515-
// What's going on is we have some critical factorization (u, v) of the
516-
// needle, and we want to determine whether u is a suffix of
517-
// v.slice_to(period). If it is, we use "Algorithm CP1". Otherwise we use
518-
// "Algorithm CP2", which is optimized for when the period of the needle
519-
// is large.
446+
// In the paper they check whether `needle.slice_to(crit_pos)` is a suffix of
447+
// `needle.slice(crit_pos, crit_pos + period)`, which is precisely what this does
520448
if needle.slice_to(crit_pos) == needle.slice(period, period + crit_pos) {
521449
TwoWaySearcher {
522450
crit_pos: crit_pos,
@@ -538,11 +466,6 @@ impl TwoWaySearcher {
538466
}
539467
}
540468

541-
// One of the main ideas of Two-Way is that we factorize the needle into
542-
// two halves, (u, v), and begin trying to find v in the haystack by scanning
543-
// left to right. If v matches, we try to match u by scanning right to left.
544-
// How far we can jump when we encounter a mismatch is all based on the fact
545-
// that (u, v) is a critical factorization for the needle.
546469
#[inline]
547470
fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool) -> Option<(uint, uint)> {
548471
'search: loop {
@@ -556,9 +479,6 @@ impl TwoWaySearcher {
556479
((haystack[self.position + needle.len() - 1] & 0x3f)
557480
as uint)) & 1 == 0 {
558481
self.position += needle.len();
559-
if !long_period {
560-
self.memory = 0;
561-
}
562482
continue 'search;
563483
}
564484

@@ -597,9 +517,9 @@ impl TwoWaySearcher {
597517
}
598518
}
599519

600-
// Computes a critical factorization (u, v) of `arr`.
601-
// Specifically, returns (i, p), where i is the starting index of v in some
602-
// critical factorization (u, v) and p = period(v)
520+
// returns (i, p) where i is the "critical position", the starting index of
521+
// of maximal suffix, and p is the period of the suffix
522+
// see p. 668 of the paper
603523
#[inline]
604524
fn maximal_suffix(arr: &[u8], reversed: bool) -> (uint, uint) {
605525
let mut left = -1; // Corresponds to i in the paper

branches/dist-snap/src/libcoretest/str.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ fn strslice_issue_16589() {
2626
check_contains_all_substrings("012345678901234567890123456789bcdabcdabcd");
2727
}
2828

29-
#[test]
30-
fn strslice_issue_16878() {
31-
assert!(!"1234567ah012345678901ah".contains("hah"));
32-
assert!(!"00abc01234567890123456789abc".contains("bcabc"));
33-
}
34-
3529

3630
#[test]
3731
fn test_strslice_contains() {

branches/dist-snap/src/librustc/driver/driver.rs

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use back::link;
1313
use back::write;
1414
use driver::session::Session;
1515
use driver::config;
16+
use front;
1617
use lint;
1718
use llvm::{ContextRef, ModuleRef};
1819
use metadata::common::LinkMeta;
@@ -165,7 +166,7 @@ pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
165166
}
166167

167168
if sess.show_span() {
168-
syntax::show_span::run(sess.diagnostic(), &krate);
169+
front::show_span::run(sess, &krate);
169170
}
170171

171172
krate
@@ -193,29 +194,11 @@ pub fn phase_2_configure_and_expand(sess: &Session,
193194
*sess.crate_metadata.borrow_mut() =
194195
collect_crate_metadata(sess, krate.attrs.as_slice());
195196

196-
time(time_passes, "gated feature checking", (), |_| {
197-
let (features, unknown_features) =
198-
syntax::feature_gate::check_crate(&sess.parse_sess.span_diagnostic, &krate);
199-
200-
for uf in unknown_features.iter() {
201-
sess.add_lint(lint::builtin::UNKNOWN_FEATURES,
202-
ast::CRATE_NODE_ID,
203-
*uf,
204-
"unknown feature".to_string());
205-
}
206-
207-
sess.abort_if_errors();
208-
*sess.features.borrow_mut() = features;
209-
});
210-
211-
let any_exe = sess.crate_types.borrow().iter().any(|ty| {
212-
*ty == config::CrateTypeExecutable
213-
});
197+
time(time_passes, "gated feature checking", (), |_|
198+
front::feature_gate::check_crate(sess, &krate));
214199

215200
krate = time(time_passes, "crate injection", krate, |krate|
216-
syntax::std_inject::maybe_inject_crates_ref(krate,
217-
sess.opts.alt_std_name.clone(),
218-
any_exe));
201+
front::std_inject::maybe_inject_crates_ref(sess, krate));
219202

220203
// strip before expansion to allow macros to depend on
221204
// configuration variables e.g/ in
@@ -226,7 +209,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
226209
// baz! should not use this definition unless foo is enabled.
227210

228211
krate = time(time_passes, "configuration 1", krate, |krate|
229-
syntax::config::strip_unconfigured_items(krate));
212+
front::config::strip_unconfigured_items(krate));
230213

231214
let mut addl_plugins = Some(addl_plugins);
232215
let Plugins { macros, registrars }
@@ -236,7 +219,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
236219
let mut registry = Registry::new(&krate);
237220

238221
time(time_passes, "plugin registration", (), |_| {
239-
if sess.features.borrow().rustc_diagnostic_macros {
222+
if sess.features.rustc_diagnostic_macros.get() {
240223
registry.register_macro("__diagnostic_used",
241224
diagnostics::plugin::expand_diagnostic_used);
242225
registry.register_macro("__register_diagnostic",
@@ -288,7 +271,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
288271
os::setenv("PATH", os::join_paths(new_path.as_slice()).unwrap());
289272
}
290273
let cfg = syntax::ext::expand::ExpansionConfig {
291-
deriving_hash_type_parameter: sess.features.borrow().default_type_params,
274+
deriving_hash_type_parameter: sess.features.default_type_params.get(),
292275
crate_name: crate_name.to_string(),
293276
};
294277
let ret = syntax::ext::expand::expand_crate(&sess.parse_sess,
@@ -307,16 +290,13 @@ pub fn phase_2_configure_and_expand(sess: &Session,
307290

308291
// strip again, in case expansion added anything with a #[cfg].
309292
krate = time(time_passes, "configuration 2", krate, |krate|
310-
syntax::config::strip_unconfigured_items(krate));
293+
front::config::strip_unconfigured_items(krate));
311294

312295
krate = time(time_passes, "maybe building test harness", krate, |krate|
313-
syntax::test::modify_for_testing(&sess.parse_sess,
314-
&sess.opts.cfg,
315-
krate,
316-
sess.diagnostic()));
296+
front::test::modify_for_testing(sess, krate));
317297

318298
krate = time(time_passes, "prelude injection", krate, |krate|
319-
syntax::std_inject::maybe_inject_prelude(krate));
299+
front::std_inject::maybe_inject_prelude(sess, krate));
320300

321301
time(time_passes, "checking that all macro invocations are gone", &krate, |krate|
322302
syntax::ext::expand::check_for_macros(&sess.parse_sess, krate));

branches/dist-snap/src/librustc/driver/session.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use driver::config;
1313
use driver::driver;
14+
use front;
1415
use metadata::cstore::CStore;
1516
use metadata::filesearch;
1617
use lint;
@@ -20,7 +21,6 @@ use syntax::ast::NodeId;
2021
use syntax::codemap::Span;
2122
use syntax::diagnostic;
2223
use syntax::diagnostics;
23-
use syntax::feature_gate;
2424
use syntax::parse;
2525
use syntax::parse::token;
2626
use syntax::parse::ParseSess;
@@ -47,9 +47,10 @@ pub struct Session {
4747
pub working_dir: Path,
4848
pub lint_store: RefCell<lint::LintStore>,
4949
pub lints: RefCell<NodeMap<Vec<(lint::LintId, codemap::Span, String)>>>,
50+
pub node_id: Cell<ast::NodeId>,
5051
pub crate_types: RefCell<Vec<config::CrateType>>,
5152
pub crate_metadata: RefCell<Vec<String>>,
52-
pub features: RefCell<feature_gate::Features>,
53+
pub features: front::feature_gate::Features,
5354

5455
/// The maximum recursion limit for potentially infinitely recursive
5556
/// operations such as auto-dereference and monomorphization.
@@ -128,10 +129,17 @@ impl Session {
128129
lints.insert(id, vec!((lint_id, sp, msg)));
129130
}
130131
pub fn next_node_id(&self) -> ast::NodeId {
131-
self.parse_sess.next_node_id()
132+
self.reserve_node_ids(1)
132133
}
133134
pub fn reserve_node_ids(&self, count: ast::NodeId) -> ast::NodeId {
134-
self.parse_sess.reserve_node_ids(count)
135+
let v = self.node_id.get();
136+
137+
match v.checked_add(&count) {
138+
Some(next) => { self.node_id.set(next); }
139+
None => self.bug("Input too large, ran out of node ids!")
140+
}
141+
142+
v
135143
}
136144
pub fn diagnostic<'a>(&'a self) -> &'a diagnostic::SpanHandler {
137145
&self.parse_sess.span_diagnostic
@@ -243,9 +251,10 @@ pub fn build_session_(sopts: config::Options,
243251
working_dir: os::getcwd(),
244252
lint_store: RefCell::new(lint::LintStore::new()),
245253
lints: RefCell::new(NodeMap::new()),
254+
node_id: Cell::new(1),
246255
crate_types: RefCell::new(Vec::new()),
247256
crate_metadata: RefCell::new(Vec::new()),
248-
features: RefCell::new(feature_gate::Features::new()),
257+
features: front::feature_gate::Features::new(),
249258
recursion_limit: Cell::new(64),
250259
};
251260

branches/dist-snap/src/libsyntax/config.rs renamed to branches/dist-snap/src/librustc/front/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use fold::Folder;
12-
use {ast, fold, attr};
13-
use codemap::Spanned;
14-
use ptr::P;
11+
use syntax::fold::Folder;
12+
use syntax::{ast, fold, attr};
13+
use syntax::codemap::Spanned;
14+
use syntax::ptr::P;
1515

1616
/// A folder that strips out items that do not belong in the current
1717
/// configuration.

0 commit comments

Comments
 (0)