Skip to content

Commit 87115fd

Browse files
committed
auto merge of #13901 : alexcrichton/rust/facade, r=brson
This is the second step in implementing #13851. This PR cannot currently land until a snapshot exists with #13892, but I imagine that this review will take longer. This PR refactors a large amount of functionality outside of the standard library into a new library, libcore. This new library has 0 dependencies (in theory). In practice, this library currently depends on these symbols being available: * `rust_begin_unwind` and `rust_fail_bounds_check` - These are the two entry points of failure in libcore. The symbols are provided by libstd currently. In the future (see the bullets on #13851) this will be officially supported with nice error mesages. Additionally, there will only be one failure entry point once `std::fmt` migrates to libcore. * `memcpy` - This is often generated by LLVM. This is also quite trivial to implement for any platform, so I'm not too worried about this. * `memcmp` - This is required for comparing strings. This function is quite common *everywhere*, so I don't feel to bad about relying on a consumer of libcore to define it. * `malloc` and `free` - This is quite unfortunate, and is a temporary stopgap until we deal with the `~` situation. More details can be found in the module `core::should_not_exist` * `fmod` and `fmodf` - These exist because the `Rem` trait is defined in libcore, so the `Rem` implementation for floats must also be defined in libcore. I imagine that any platform using floating-point modulus will have these symbols anyway, and otherwise they will be optimized out. * `fdim` and `fdimf` - Like `fmod`, these are from the `Signed` trait being defined in libcore. I don't expect this to be much of a problem These dependencies all "Just Work" for now because libcore only exists as an rlib, not as a dylib. The commits themselves are organized to show that the overall diff of this extraction is not all that large. Most modules were able to be moved with very few modifications. The primary module left out of this iteration is `std::fmt`. I plan on migrating the `fmt` module to libcore, but I chose to not do so at this time because it had implications on the `Writer` trait that I wanted to deal with in isolation. There are a few breaking changes in these commits, but they are fairly minor, and are all labeled with `[breaking-change]`. The nastiest parts of this movement come up with `~[T]` and `~str` being language-defined types today. I believe that much of this nastiness will get better over time as we migrate towards `Vec<T>` and `Str` (or whatever the types will be named). There will likely always be some extension traits, but the situation won't be as bad as it is today. Known deficiencies: * rustdoc will get worse in terms of readability. This is the next issue I will tackle as part of #13851. If others think that the rustdoc change should happen first, I can also table this to fix rustdoc first. * The compiler reveals that all these types are reexports via error messages like `core::option::Option`. This is filed as #13065, and I believe that issue would have a higher priority now. I do not currently plan on fixing that as part of #13851. If others believe that this issue should be fixed, I can also place it on the roadmap for #13851. I recommend viewing these changes on a commit-by-commit basis. The overall change is likely too overwhelming to take in.
2 parents 445988b + 07caa22 commit 87115fd

Some content is hidden

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

115 files changed

+14123
-12874
lines changed

mk/crates.mk

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@
5151

5252
TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
5353
uuid serialize sync getopts collections num test time rand \
54-
workcache url log regex graphviz
54+
workcache url log regex graphviz core
5555
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat regex_macros
5656
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5757
TOOLS := compiletest rustdoc rustc
5858

59-
DEPS_std := libc native:rustrt native:compiler-rt native:backtrace
59+
DEPS_core :=
60+
DEPS_std := core libc native:rustrt native:compiler-rt native:backtrace
6061
DEPS_green := std rand native:context_switch
6162
DEPS_rustuv := std native:uv native:uv_support
6263
DEPS_native := std
@@ -95,6 +96,8 @@ TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
9596
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
9697
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
9798

99+
ONLY_RLIB_core := 1
100+
98101
################################################################################
99102
# You should not need to edit below this line
100103
################################################################################

mk/host.mk

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# $(5) - the name of the crate being processed
1919
define CP_HOST_STAGE_N_CRATE
2020

21+
ifeq ($$(ONLY_RLIB_$(5)),)
2122
$$(HLIB$(2)_H_$(4))/stamp.$(5): \
2223
$$(TLIB$(1)_T_$(3)_H_$(4))/stamp.$(5) \
2324
$$(RUST_DEPS_$(5):%=$$(HLIB$(2)_H_$(4))/stamp.%) \
@@ -30,6 +31,10 @@ $$(HLIB$(2)_H_$(4))/stamp.$(5): \
3031
$$(HLIB$(2)_H_$(4))
3132
$$(call LIST_ALL_OLD_GLOB_MATCHES,\
3233
$$(dir $$@)$$(call CFG_LIB_GLOB_$(3),$(5)))
34+
else
35+
$$(HLIB$(2)_H_$(4))/stamp.$(5):
36+
$$(Q)touch $$@
37+
endif
3338

3439
endef
3540

@@ -54,9 +59,6 @@ endef
5459
# $(4) - the host triple (same as $(3))
5560
define CP_HOST_STAGE_N
5661

57-
$$(HBIN$(2)_H_$(4))/:
58-
@mkdir -p $$@
59-
6062
ifneq ($(CFG_LIBDIR_RELATIVE),bin)
6163
$$(HLIB$(2)_H_$(4))/:
6264
@mkdir -p $$@

src/doc/rust.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3274,7 +3274,7 @@ The machine types are the following:
32743274

32753275
* The signed two's complement word types `i8`, `i16`, `i32` and `i64`, with
32763276
values drawn from the integer intervals [-(2^(7)), 2^7 - 1],
3277-
[-(2^(15)), 2^15 - 1], $[-(2^(31)), 2^31 - 1], [-(2^(63)), 2^63 - 1]
3277+
[-(2^(15)), 2^15 - 1], [-(2^(31)), 2^31 - 1], [-(2^(63)), 2^63 - 1]
32783278
respectively.
32793279

32803280
* The IEEE 754-2008 `binary32` and `binary64` floating-point types: `f32` and

src/libstd/any.rs renamed to src/libcore/any.rs

+5-22
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
//! the extension traits (`*Ext`) for the full details.
2222
2323
use cast::{transmute, transmute_copy};
24-
use fmt;
2524
use option::{Option, Some, None};
2625
use owned::Box;
2726
use raw::TraitObject;
@@ -145,28 +144,12 @@ impl AnyOwnExt for Box<Any> {
145144
}
146145
}
147146

148-
///////////////////////////////////////////////////////////////////////////////
149-
// Trait implementations
150-
///////////////////////////////////////////////////////////////////////////////
151-
152-
impl fmt::Show for Box<Any> {
153-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154-
f.pad("Box<Any>")
155-
}
156-
}
157-
158-
impl<'a> fmt::Show for &'a Any {
159-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
160-
f.pad("&Any")
161-
}
162-
}
163-
164147
#[cfg(test)]
165148
mod tests {
166149
use prelude::*;
167150
use super::*;
168151
use owned::Box;
169-
use str::StrSlice;
152+
use realstd::str::StrAllocating;
170153

171154
#[deriving(Eq, Show)]
172155
struct Test;
@@ -291,13 +274,13 @@ mod tests {
291274

292275
#[test]
293276
fn test_show() {
294-
let a = box 8u as Box<Any>;
295-
let b = box Test as Box<Any>;
277+
let a = box 8u as Box<::realcore::any::Any>;
278+
let b = box Test as Box<::realcore::any::Any>;
296279
assert_eq!(format!("{}", a), "Box<Any>".to_owned());
297280
assert_eq!(format!("{}", b), "Box<Any>".to_owned());
298281

299-
let a = &8u as &Any;
300-
let b = &Test as &Any;
282+
let a = &8u as &::realcore::any::Any;
283+
let b = &Test as &::realcore::any::Any;
301284
assert_eq!(format!("{}", a), "&Any".to_owned());
302285
assert_eq!(format!("{}", b), "&Any".to_owned());
303286
}

src/libstd/bool.rs renamed to src/libcore/bool.rs

+5-35
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//!
1515
//! Implementations of the following traits:
1616
//!
17-
//! * `FromStr`
1817
//! * `Not`
1918
//! * `Ord`
2019
//! * `TotalOrd`
@@ -24,11 +23,9 @@
2423
//!
2524
//! A `to_bit` conversion function.
2625
27-
use from_str::FromStr;
2826
use num::{Int, one, zero};
29-
use option::{None, Option, Some};
3027

31-
#[cfg(not(test))] use cmp::{Eq, Ord, TotalOrd, Ordering};
28+
#[cfg(not(test))] use cmp::{Eq, Ord, TotalOrd, Ordering, TotalEq};
3229
#[cfg(not(test))] use ops::{Not, BitAnd, BitOr, BitXor};
3330
#[cfg(not(test))] use default::Default;
3431

@@ -55,28 +52,6 @@ pub fn to_bit<N: Int>(p: bool) -> N {
5552
// Trait impls on `bool`
5653
/////////////////////////////////////////////////////////////////////////////
5754

58-
impl FromStr for bool {
59-
/// Parse a `bool` from a string.
60-
///
61-
/// Yields an `Option<bool>`, because `s` may or may not actually be parseable.
62-
///
63-
/// # Examples
64-
///
65-
/// ```rust
66-
/// assert_eq!(from_str::<bool>("true"), Some(true));
67-
/// assert_eq!(from_str::<bool>("false"), Some(false));
68-
/// assert_eq!(from_str::<bool>("not even a boolean"), None);
69-
/// ```
70-
#[inline]
71-
fn from_str(s: &str) -> Option<bool> {
72-
match s {
73-
"true" => Some(true),
74-
"false" => Some(false),
75-
_ => None,
76-
}
77-
}
78-
}
79-
8055
#[cfg(not(test))]
8156
impl Not<bool> for bool {
8257
/// The logical complement of a boolean value.
@@ -190,16 +165,18 @@ impl Eq for bool {
190165
fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
191166
}
192167

168+
#[cfg(not(test))]
169+
impl TotalEq for bool {}
170+
193171
#[cfg(not(test))]
194172
impl Default for bool {
195173
fn default() -> bool { false }
196174
}
197175

198176
#[cfg(test)]
199177
mod tests {
200-
use prelude::*;
178+
use realstd::prelude::*;
201179
use super::to_bit;
202-
use str::StrSlice;
203180

204181
#[test]
205182
fn test_to_bit() {
@@ -260,13 +237,6 @@ mod tests {
260237
assert_eq!(!false, true);
261238
}
262239

263-
#[test]
264-
fn test_from_str() {
265-
assert_eq!(from_str::<bool>("true"), Some(true));
266-
assert_eq!(from_str::<bool>("false"), Some(false));
267-
assert_eq!(from_str::<bool>("not even a boolean"), None);
268-
}
269-
270240
#[test]
271241
fn test_to_str() {
272242
assert_eq!(false.to_str(), "false".to_owned());

src/libstd/cast.rs renamed to src/libcore/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
108108
mod tests {
109109
use cast::{bump_box_refcount, transmute};
110110
use raw;
111-
use str::StrSlice;
111+
use realstd::str::StrAllocating;
112112

113113
#[test]
114114
fn test_transmute_copy() {

src/libstd/cell.rs renamed to src/libcore/cell.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
use clone::Clone;
1414
use cmp::Eq;
15-
use fmt;
1615
use kinds::{marker, Copy};
1716
use ops::{Deref, DerefMut, Drop};
1817
use option::{None, Option, Some};
@@ -60,12 +59,6 @@ impl<T:Eq + Copy> Eq for Cell<T> {
6059
}
6160
}
6261

63-
impl<T: Copy + fmt::Show> fmt::Show for Cell<T> {
64-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
65-
write!(f.buf, r"Cell \{ value: {} \}", self.get())
66-
}
67-
}
68-
6962
/// A mutable memory location with dynamically checked borrow rules
7063
pub struct RefCell<T> {
7164
value: Unsafe<T>,
@@ -228,22 +221,22 @@ mod test {
228221
#[test]
229222
fn smoketest_cell() {
230223
let x = Cell::new(10);
231-
assert_eq!(x, Cell::new(10));
232-
assert_eq!(x.get(), 10);
224+
assert!(x == Cell::new(10));
225+
assert!(x.get() == 10);
233226
x.set(20);
234-
assert_eq!(x, Cell::new(20));
235-
assert_eq!(x.get(), 20);
227+
assert!(x == Cell::new(20));
228+
assert!(x.get() == 20);
236229

237230
let y = Cell::new((30, 40));
238-
assert_eq!(y, Cell::new((30, 40)));
239-
assert_eq!(y.get(), (30, 40));
231+
assert!(y == Cell::new((30, 40)));
232+
assert!(y.get() == (30, 40));
240233
}
241234

242235
#[test]
243236
fn cell_has_sensible_show() {
244237
use str::StrSlice;
245238

246-
let x = Cell::new("foo bar");
239+
let x = ::realcore::cell::Cell::new("foo bar");
247240
assert!(format!("{}", x).contains(x.get()));
248241

249242
x.set("baz qux");

0 commit comments

Comments
 (0)