Skip to content

Commit 99d1384

Browse files
author
Dave Huseby
committed
---
yaml --- r: 226935 b: refs/heads/master c: fe5336b h: refs/heads/master i: 226933: 3a35d32 226931: 0674c47 226927: e5141a3 v: v3
1 parent 7ea3a8a commit 99d1384

File tree

132 files changed

+15542
-1755
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+15542
-1755
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 741a19f8efcb060febfaf29bee13860a55ba8bf2
2+
refs/heads/master: fe5336b04d134559d910ce8f27e6deb3ca997119
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
44
refs/heads/try: b53c0f93eedcdedd4fd89bccc5a3a09d1c5cd23e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/doc/trpl/the-stack-and-the-heap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ reuse.
549549
If you’d like to dive into this topic in greater detail, [this paper][wilson]
550550
is a great introduction.
551551

552-
[wilson]: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.143.4688
552+
[wilson]: http://www.cs.northwestern.edu/~pdinda/icsclass/doc/dsa.pdf
553553

554554
## Semantic impact
555555

trunk/src/etc/unicode.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,46 @@ def emit_conversions_module(f, to_upper, to_lower, to_title):
395395
is_pub=False, t_type = t_type, pfun=pfun)
396396
f.write("}\n\n")
397397

398+
def emit_grapheme_module(f, grapheme_table, grapheme_cats):
399+
f.write("""pub mod grapheme {
400+
use core::slice::SliceExt;
401+
pub use self::GraphemeCat::*;
402+
use core::result::Result::{Ok, Err};
403+
404+
#[allow(non_camel_case_types)]
405+
#[derive(Clone, Copy)]
406+
pub enum GraphemeCat {
407+
""")
408+
for cat in grapheme_cats + ["Any"]:
409+
f.write(" GC_" + cat + ",\n")
410+
f.write(""" }
411+
412+
fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat {
413+
use core::cmp::Ordering::{Equal, Less, Greater};
414+
match r.binary_search_by(|&(lo, hi, _)| {
415+
if lo <= c && c <= hi { Equal }
416+
else if hi < c { Less }
417+
else { Greater }
418+
}) {
419+
Ok(idx) => {
420+
let (_, _, cat) = r[idx];
421+
cat
422+
}
423+
Err(_) => GC_Any
424+
}
425+
}
426+
427+
pub fn grapheme_category(c: char) -> GraphemeCat {
428+
bsearch_range_value_table(c, grapheme_cat_table)
429+
}
430+
431+
""")
432+
433+
emit_table(f, "grapheme_cat_table", grapheme_table, "&'static [(char, char, GraphemeCat)]",
434+
pfun=lambda x: "(%s,%s,GC_%s)" % (escape_char(x[0]), escape_char(x[1]), x[2]),
435+
is_pub=False)
436+
f.write("}\n")
437+
398438
def emit_charwidth_module(f, width_table):
399439
f.write("pub mod charwidth {\n")
400440
f.write(" use core::option::Option;\n")
@@ -457,6 +497,79 @@ def emit_norm_module(f, canon, compat, combine, norm_props):
457497
canon_comp_keys = canon_comp.keys()
458498
canon_comp_keys.sort()
459499

500+
f.write("pub mod normalization {\n")
501+
502+
def mkdata_fun(table):
503+
def f(char):
504+
data = "(%s,&[" % escape_char(char)
505+
first = True
506+
for d in table[char]:
507+
if not first:
508+
data += ","
509+
first = False
510+
data += escape_char(d)
511+
data += "])"
512+
return data
513+
return f
514+
515+
f.write(" // Canonical decompositions\n")
516+
emit_table(f, "canonical_table", canon_keys, "&'static [(char, &'static [char])]",
517+
pfun=mkdata_fun(canon))
518+
519+
f.write(" // Compatibility decompositions\n")
520+
emit_table(f, "compatibility_table", compat_keys, "&'static [(char, &'static [char])]",
521+
pfun=mkdata_fun(compat))
522+
523+
def comp_pfun(char):
524+
data = "(%s,&[" % escape_char(char)
525+
canon_comp[char].sort(lambda x, y: x[0] - y[0])
526+
first = True
527+
for pair in canon_comp[char]:
528+
if not first:
529+
data += ","
530+
first = False
531+
data += "(%s,%s)" % (escape_char(pair[0]), escape_char(pair[1]))
532+
data += "])"
533+
return data
534+
535+
f.write(" // Canonical compositions\n")
536+
emit_table(f, "composition_table", canon_comp_keys,
537+
"&'static [(char, &'static [(char, char)])]", pfun=comp_pfun)
538+
539+
f.write("""
540+
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
541+
use core::cmp::Ordering::{Equal, Less, Greater};
542+
use core::slice::SliceExt;
543+
use core::result::Result::{Ok, Err};
544+
match r.binary_search_by(|&(lo, hi, _)| {
545+
if lo <= c && c <= hi { Equal }
546+
else if hi < c { Less }
547+
else { Greater }
548+
}) {
549+
Ok(idx) => {
550+
let (_, _, result) = r[idx];
551+
result
552+
}
553+
Err(_) => 0
554+
}
555+
}\n
556+
""")
557+
558+
emit_table(f, "combining_class_table", combine, "&'static [(char, char, u8)]", is_pub=False,
559+
pfun=lambda x: "(%s,%s,%s)" % (escape_char(x[0]), escape_char(x[1]), x[2]))
560+
561+
f.write(""" #[deprecated(reason = "use the crates.io `unicode-normalization` lib instead",
562+
since = "1.0.0")]
563+
#[unstable(feature = "unicode",
564+
reason = "this functionality will be moved to crates.io")]
565+
pub fn canonical_combining_class(c: char) -> u8 {
566+
bsearch_range_value_table(c, combining_class_table)
567+
}
568+
569+
}
570+
571+
""")
572+
460573
def remove_from_wtable(wtable, val):
461574
wtable_out = []
462575
while wtable:
@@ -536,3 +649,53 @@ def optimize_width_table(wtable):
536649
# normalizations and conversions module
537650
emit_norm_module(rf, canon_decomp, compat_decomp, combines, norm_props)
538651
emit_conversions_module(rf, to_upper, to_lower, to_title)
652+
653+
### character width module
654+
width_table = []
655+
for zwcat in ["Me", "Mn", "Cf"]:
656+
width_table.extend(map(lambda (lo, hi): (lo, hi, 0, 0), gencats[zwcat]))
657+
width_table.append((4448, 4607, 0, 0))
658+
659+
# get widths, except those that are explicitly marked zero-width above
660+
ea_widths = load_east_asian_width(["W", "F", "A"], ["Me", "Mn", "Cf"])
661+
# these are doublewidth
662+
for dwcat in ["W", "F"]:
663+
width_table.extend(map(lambda (lo, hi): (lo, hi, 2, 2), ea_widths[dwcat]))
664+
width_table.extend(map(lambda (lo, hi): (lo, hi, 1, 2), ea_widths["A"]))
665+
666+
width_table.sort(key=lambda w: w[0])
667+
668+
# soft hyphen is not zero width in preformatted text; it's used to indicate
669+
# a hyphen inserted to facilitate a linebreak.
670+
width_table = remove_from_wtable(width_table, 173)
671+
672+
# optimize the width table by collapsing adjacent entities when possible
673+
width_table = optimize_width_table(width_table)
674+
emit_charwidth_module(rf, width_table)
675+
676+
### grapheme cluster module
677+
# from http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Break_Property_Values
678+
grapheme_cats = load_properties("auxiliary/GraphemeBreakProperty.txt", [])
679+
680+
# Control
681+
# Note 1:
682+
# This category also includes Cs (surrogate codepoints), but Rust's `char`s are
683+
# Unicode Scalar Values only, and surrogates are thus invalid `char`s.
684+
# Thus, we have to remove Cs from the Control category
685+
# Note 2:
686+
# 0x0a and 0x0d (CR and LF) are not in the Control category for Graphemes.
687+
# However, the Graphemes iterator treats these as a special case, so they
688+
# should be included in grapheme_cats["Control"] for our implementation.
689+
grapheme_cats["Control"] = group_cat(list(
690+
(set(ungroup_cat(grapheme_cats["Control"]))
691+
| set(ungroup_cat(grapheme_cats["CR"]))
692+
| set(ungroup_cat(grapheme_cats["LF"])))
693+
- set(ungroup_cat([surrogate_codepoints]))))
694+
del(grapheme_cats["CR"])
695+
del(grapheme_cats["LF"])
696+
697+
grapheme_table = []
698+
for cat in grapheme_cats:
699+
grapheme_table.extend([(x, y, cat) for (x, y) in grapheme_cats[cat]])
700+
grapheme_table.sort(key=lambda w: w[0])
701+
emit_grapheme_module(rf, grapheme_table, grapheme_cats.keys())

trunk/src/liballoc/arc.rs

Lines changed: 77 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ impl<T: ?Sized> Arc<T> {
272272
}
273273
}
274274

275+
/// Get the number of weak references to this value.
276+
#[inline]
277+
#[unstable(feature = "arc_counts")]
278+
#[deprecated(since = "1.2.0", reason = "renamed to Arc::weak_count")]
279+
pub fn weak_count<T: ?Sized>(this: &Arc<T>) -> usize { Arc::weak_count(this) }
280+
281+
/// Get the number of strong references to this value.
282+
#[inline]
283+
#[unstable(feature = "arc_counts")]
284+
#[deprecated(since = "1.2.0", reason = "renamed to Arc::strong_count")]
285+
pub fn strong_count<T: ?Sized>(this: &Arc<T>) -> usize { Arc::strong_count(this) }
286+
275287
#[stable(feature = "rust1", since = "1.0.0")]
276288
impl<T: ?Sized> Clone for Arc<T> {
277289
/// Makes a clone of the `Arc<T>`.
@@ -472,6 +484,13 @@ impl<T: ?Sized> Arc<T> {
472484
}
473485
}
474486

487+
#[inline]
488+
#[unstable(feature = "arc_unique")]
489+
#[deprecated(since = "1.2", reason = "use Arc::get_mut instead")]
490+
pub fn get_mut<T: ?Sized>(this: &mut Arc<T>) -> Option<&mut T> {
491+
Arc::get_mut(this)
492+
}
493+
475494
#[stable(feature = "rust1", since = "1.0.0")]
476495
impl<T: ?Sized> Drop for Arc<T> {
477496
/// Drops the `Arc<T>`.
@@ -841,7 +860,7 @@ mod tests {
841860
use std::sync::atomic::Ordering::{Acquire, SeqCst};
842861
use std::thread;
843862
use std::vec::Vec;
844-
use super::{Arc, Weak};
863+
use super::{Arc, Weak, get_mut, weak_count, strong_count};
845864
use std::sync::Mutex;
846865

847866
struct Canary(*mut atomic::AtomicUsize);
@@ -879,39 +898,43 @@ mod tests {
879898

880899
#[test]
881900
fn test_arc_get_mut() {
882-
let mut x = Arc::new(3);
883-
*Arc::get_mut(&mut x).unwrap() = 4;
884-
assert_eq!(*x, 4);
885-
let y = x.clone();
886-
assert!(Arc::get_mut(&mut x).is_none());
887-
drop(y);
888-
assert!(Arc::get_mut(&mut x).is_some());
889-
let _w = x.downgrade();
890-
assert!(Arc::get_mut(&mut x).is_none());
901+
unsafe {
902+
let mut x = Arc::new(3);
903+
*get_mut(&mut x).unwrap() = 4;
904+
assert_eq!(*x, 4);
905+
let y = x.clone();
906+
assert!(get_mut(&mut x).is_none());
907+
drop(y);
908+
assert!(get_mut(&mut x).is_some());
909+
let _w = x.downgrade();
910+
assert!(get_mut(&mut x).is_none());
911+
}
891912
}
892913

893914
#[test]
894915
fn test_cowarc_clone_make_unique() {
895-
let mut cow0 = Arc::new(75);
896-
let mut cow1 = cow0.clone();
897-
let mut cow2 = cow1.clone();
898-
899-
assert!(75 == *Arc::make_unique(&mut cow0));
900-
assert!(75 == *Arc::make_unique(&mut cow1));
901-
assert!(75 == *Arc::make_unique(&mut cow2));
902-
903-
*Arc::make_unique(&mut cow0) += 1;
904-
*Arc::make_unique(&mut cow1) += 2;
905-
*Arc::make_unique(&mut cow2) += 3;
906-
907-
assert!(76 == *cow0);
908-
assert!(77 == *cow1);
909-
assert!(78 == *cow2);
910-
911-
// none should point to the same backing memory
912-
assert!(*cow0 != *cow1);
913-
assert!(*cow0 != *cow2);
914-
assert!(*cow1 != *cow2);
916+
unsafe {
917+
let mut cow0 = Arc::new(75);
918+
let mut cow1 = cow0.clone();
919+
let mut cow2 = cow1.clone();
920+
921+
assert!(75 == *Arc::make_unique(&mut cow0));
922+
assert!(75 == *Arc::make_unique(&mut cow1));
923+
assert!(75 == *Arc::make_unique(&mut cow2));
924+
925+
*Arc::make_unique(&mut cow0) += 1;
926+
*Arc::make_unique(&mut cow1) += 2;
927+
*Arc::make_unique(&mut cow2) += 3;
928+
929+
assert!(76 == *cow0);
930+
assert!(77 == *cow1);
931+
assert!(78 == *cow2);
932+
933+
// none should point to the same backing memory
934+
assert!(*cow0 != *cow1);
935+
assert!(*cow0 != *cow2);
936+
assert!(*cow1 != *cow2);
937+
}
915938
}
916939

917940
#[test]
@@ -924,7 +947,9 @@ mod tests {
924947
assert!(75 == *cow1);
925948
assert!(75 == *cow2);
926949

927-
*Arc::make_unique(&mut cow0) += 1;
950+
unsafe {
951+
*Arc::make_unique(&mut cow0) += 1;
952+
}
928953

929954
assert!(76 == *cow0);
930955
assert!(75 == *cow1);
@@ -945,7 +970,9 @@ mod tests {
945970
assert!(75 == *cow0);
946971
assert!(75 == *cow1_weak.upgrade().unwrap());
947972

948-
*Arc::make_unique(&mut cow0) += 1;
973+
unsafe {
974+
*Arc::make_unique(&mut cow0) += 1;
975+
}
949976

950977
assert!(76 == *cow0);
951978
assert!(cow1_weak.upgrade().is_none());
@@ -1001,40 +1028,40 @@ mod tests {
10011028
#[test]
10021029
fn test_strong_count() {
10031030
let a = Arc::new(0u32);
1004-
assert!(Arc::strong_count(&a) == 1);
1031+
assert!(strong_count(&a) == 1);
10051032
let w = a.downgrade();
1006-
assert!(Arc::strong_count(&a) == 1);
1033+
assert!(strong_count(&a) == 1);
10071034
let b = w.upgrade().expect("");
1008-
assert!(Arc::strong_count(&b) == 2);
1009-
assert!(Arc::strong_count(&a) == 2);
1035+
assert!(strong_count(&b) == 2);
1036+
assert!(strong_count(&a) == 2);
10101037
drop(w);
10111038
drop(a);
1012-
assert!(Arc::strong_count(&b) == 1);
1039+
assert!(strong_count(&b) == 1);
10131040
let c = b.clone();
1014-
assert!(Arc::strong_count(&b) == 2);
1015-
assert!(Arc::strong_count(&c) == 2);
1041+
assert!(strong_count(&b) == 2);
1042+
assert!(strong_count(&c) == 2);
10161043
}
10171044

10181045
#[test]
10191046
fn test_weak_count() {
10201047
let a = Arc::new(0u32);
1021-
assert!(Arc::strong_count(&a) == 1);
1022-
assert!(Arc::weak_count(&a) == 0);
1048+
assert!(strong_count(&a) == 1);
1049+
assert!(weak_count(&a) == 0);
10231050
let w = a.downgrade();
1024-
assert!(Arc::strong_count(&a) == 1);
1025-
assert!(Arc::weak_count(&a) == 1);
1051+
assert!(strong_count(&a) == 1);
1052+
assert!(weak_count(&a) == 1);
10261053
let x = w.clone();
1027-
assert!(Arc::weak_count(&a) == 2);
1054+
assert!(weak_count(&a) == 2);
10281055
drop(w);
10291056
drop(x);
1030-
assert!(Arc::strong_count(&a) == 1);
1031-
assert!(Arc::weak_count(&a) == 0);
1057+
assert!(strong_count(&a) == 1);
1058+
assert!(weak_count(&a) == 0);
10321059
let c = a.clone();
1033-
assert!(Arc::strong_count(&a) == 2);
1034-
assert!(Arc::weak_count(&a) == 0);
1060+
assert!(strong_count(&a) == 2);
1061+
assert!(weak_count(&a) == 0);
10351062
let d = c.downgrade();
1036-
assert!(Arc::weak_count(&c) == 1);
1037-
assert!(Arc::strong_count(&c) == 2);
1063+
assert!(weak_count(&c) == 1);
1064+
assert!(strong_count(&c) == 2);
10381065

10391066
drop(a);
10401067
drop(c);

0 commit comments

Comments
 (0)