2014-01-24 01:40:54 -06:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-04-25 02:39:58 -05:00
|
|
|
//! # The Rust Standard Library
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-04-25 02:39:58 -05:00
|
|
|
//! The Rust Standard Library provides the essential runtime
|
|
|
|
//! functionality for building portable Rust software.
|
|
|
|
//! It is linked to all Rust crates by default.
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-04-25 02:39:58 -05:00
|
|
|
//! ## Intrinsic types and operations
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-05-24 13:56:38 -05:00
|
|
|
//! The [`ptr`](ptr/index.html) and [`mem`](mem/index.html)
|
2014-05-19 23:51:21 -05:00
|
|
|
//! modules deal with unsafe pointers and memory manipulation.
|
2014-05-24 13:56:38 -05:00
|
|
|
//! [`kinds`](kinds/index.html) defines the special built-in traits,
|
|
|
|
//! and [`raw`](raw/index.html) the runtime representation of Rust types.
|
2014-05-22 11:44:54 -05:00
|
|
|
//! These are some of the lowest-level building blocks in Rust.
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-04-25 02:39:58 -05:00
|
|
|
//! ## Math on primitive types and math traits
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-04-25 02:39:58 -05:00
|
|
|
//! Although basic operations on primitive types are implemented
|
|
|
|
//! directly by the compiler, the standard library additionally
|
|
|
|
//! defines many common operations through traits defined in
|
|
|
|
//! mod [`num`](num/index.html).
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-04-25 02:39:58 -05:00
|
|
|
//! ## Pervasive types
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-05-24 13:56:38 -05:00
|
|
|
//! The [`option`](option/index.html) and [`result`](result/index.html)
|
2014-04-25 02:39:58 -05:00
|
|
|
//! modules define optional and error-handling types, `Option` and `Result`.
|
2014-05-24 13:56:38 -05:00
|
|
|
//! [`iter`](iter/index.html) defines Rust's iterator protocol
|
2014-04-25 02:39:58 -05:00
|
|
|
//! along with a wide variety of iterators.
|
2014-05-24 13:56:38 -05:00
|
|
|
//! [`Cell` and `RefCell`](cell/index.html) are for creating types that
|
2014-04-25 02:39:58 -05:00
|
|
|
//! manage their own mutability.
|
2013-10-31 17:09:24 -05:00
|
|
|
//!
|
2014-04-25 02:39:58 -05:00
|
|
|
//! ## Vectors, slices and strings
|
|
|
|
//!
|
|
|
|
//! The common container type, `Vec`, a growable vector backed by an
|
|
|
|
//! array, lives in the [`vec`](vec/index.html) module. References to
|
|
|
|
//! arrays, `&[T]`, more commonly called "slices", are built-in types
|
|
|
|
//! for which the [`slice`](slice/index.html) module defines many
|
|
|
|
//! methods.
|
|
|
|
//!
|
2014-05-19 19:23:26 -05:00
|
|
|
//! `&str`, a UTF-8 string, is a built-in type, and the standard library
|
|
|
|
//! defines methods for it on a variety of traits in the
|
|
|
|
//! [`str`](str/index.html) module. Rust strings are immutable;
|
2014-05-27 13:37:30 -05:00
|
|
|
//! use the `String` type defined in [`string`](string/index.html)
|
2014-04-25 02:39:58 -05:00
|
|
|
//! for a mutable string builder.
|
|
|
|
//!
|
|
|
|
//! For converting to strings use the [`format!`](fmt/index.html)
|
|
|
|
//! macro, and for converting from strings use the
|
|
|
|
//! [`FromStr`](from_str/index.html) trait.
|
|
|
|
//!
|
|
|
|
//! ## Platform abstractions
|
|
|
|
//!
|
|
|
|
//! Besides basic data types, the standard library is largely concerned
|
|
|
|
//! with abstracting over differences in common platforms, most notably
|
|
|
|
//! Windows and Unix derivatives. The [`os`](os/index.html) module
|
|
|
|
//! provides a number of basic functions for interacting with the
|
|
|
|
//! operating environment, including program arguments, environment
|
|
|
|
//! variables, and directory navigation. The [`path`](path/index.html)
|
|
|
|
//! module encapsulates the platform-specific rules for dealing
|
|
|
|
//! with file paths.
|
|
|
|
//!
|
|
|
|
//! `std` also includes modules for interoperating with the
|
|
|
|
//! C language: [`c_str`](c_str/index.html) and
|
|
|
|
//! [`c_vec`](c_vec/index.html).
|
|
|
|
//!
|
|
|
|
//! ## Concurrency, I/O, and the runtime
|
|
|
|
//!
|
|
|
|
//! The [`task`](task/index.html) module contains Rust's threading abstractions,
|
|
|
|
//! while [`comm`](comm/index.html) contains the channel types for message
|
|
|
|
//! passing. [`sync`](sync/index.html) contains further, primitive, shared
|
|
|
|
//! memory types, including [`atomics`](sync/atomics/index.html).
|
|
|
|
//!
|
2014-07-12 20:06:53 -05:00
|
|
|
//! Common types of I/O, including files, TCP, UDP, pipes, Unix domain sockets,
|
2014-05-07 01:29:57 -05:00
|
|
|
//! timers, and process spawning, are defined in the [`io`](io/index.html) module.
|
2014-04-25 02:39:58 -05:00
|
|
|
//!
|
|
|
|
//! Rust's I/O and concurrency depends on a small runtime interface
|
|
|
|
//! that lives, along with its support code, in mod [`rt`](rt/index.html).
|
|
|
|
//! While a notable part of the standard library's architecture, this
|
|
|
|
//! module is not intended for public use.
|
|
|
|
//!
|
|
|
|
//! ## The Rust prelude and macros
|
|
|
|
//!
|
2014-05-07 01:29:57 -05:00
|
|
|
//! Finally, the [`prelude`](prelude/index.html) defines a
|
2014-04-25 02:39:58 -05:00
|
|
|
//! common set of traits, types, and functions that are made available
|
|
|
|
//! to all code by default. [`macros`](macros/index.html) contains
|
2014-05-07 01:29:57 -05:00
|
|
|
//! all the standard macros, such as `assert!`, `fail!`, `println!`,
|
|
|
|
//! and `format!`, also available to all Rust code.
|
2012-11-30 02:47:45 -06:00
|
|
|
|
2014-07-01 09:12:04 -05:00
|
|
|
#![crate_name = "std"]
|
2014-06-30 19:22:40 -05:00
|
|
|
#![unstable]
|
2014-03-21 20:05:05 -05:00
|
|
|
#![comment = "The Rust standard library"]
|
|
|
|
#![license = "MIT/ASL2"]
|
|
|
|
#![crate_type = "rlib"]
|
|
|
|
#![crate_type = "dylib"]
|
|
|
|
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
|
|
|
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
2014-07-11 13:21:57 -05:00
|
|
|
html_root_url = "http://doc.rust-lang.org/master/",
|
2014-06-06 11:12:18 -05:00
|
|
|
html_playground_url = "http://play.rust-lang.org/")]
|
2014-06-17 18:00:04 -05:00
|
|
|
|
2014-06-20 18:39:23 -05:00
|
|
|
#![feature(macro_rules, globs, managed_boxes, linkage)]
|
|
|
|
#![feature(default_type_params, phase, lang_items, unsafe_destructor)]
|
2013-10-02 20:10:16 -05:00
|
|
|
|
2013-05-17 15:12:42 -05:00
|
|
|
// Don't link to std. We are std.
|
2014-03-21 20:05:05 -05:00
|
|
|
#![no_std]
|
2012-04-19 03:00:52 -05:00
|
|
|
|
2014-05-06 21:03:14 -05:00
|
|
|
#![allow(deprecated)]
|
2014-04-03 23:52:13 -05:00
|
|
|
#![deny(missing_doc)]
|
2012-06-04 20:34:24 -05:00
|
|
|
|
2013-10-22 17:13:18 -05:00
|
|
|
// When testing libstd, bring in libuv as the I/O backend so tests can print
|
2013-11-11 00:46:32 -06:00
|
|
|
// things and all of the std::io tests have an I/O interface to run on top
|
2013-10-22 17:13:18 -05:00
|
|
|
// of
|
2014-02-19 21:29:58 -06:00
|
|
|
#[cfg(test)] extern crate rustuv;
|
|
|
|
#[cfg(test)] extern crate native;
|
|
|
|
#[cfg(test)] extern crate green;
|
2014-05-22 13:28:01 -05:00
|
|
|
#[cfg(test)] extern crate debug;
|
2014-06-11 20:47:09 -05:00
|
|
|
#[cfg(test)] #[phase(plugin, link)] extern crate log;
|
2013-10-22 17:13:18 -05:00
|
|
|
|
2014-05-13 18:10:05 -05:00
|
|
|
extern crate alloc;
|
Add libunicode; move unicode functions from core
- created new crate, libunicode, below libstd
- split Char trait into Char (libcore) and UnicodeChar (libunicode)
- Unicode-aware functions now live in libunicode
- is_alphabetic, is_XID_start, is_XID_continue, is_lowercase,
is_uppercase, is_whitespace, is_alphanumeric, is_control,
is_digit, to_uppercase, to_lowercase
- added width method in UnicodeChar trait
- determines printed width of character in columns, or None if it is
a non-NULL control character
- takes a boolean argument indicating whether the present context is
CJK or not (characters with 'A'mbiguous widths are double-wide in
CJK contexts, single-wide otherwise)
- split StrSlice into StrSlice (libcore) and UnicodeStrSlice
(libunicode)
- functionality formerly in StrSlice that relied upon Unicode
functionality from Char is now in UnicodeStrSlice
- words, is_whitespace, is_alphanumeric, trim, trim_left, trim_right
- also moved Words type alias into libunicode because words method is
in UnicodeStrSlice
- unified Unicode tables from libcollections, libcore, and libregex into
libunicode
- updated unicode.py in src/etc to generate aforementioned tables
- generated new tables based on latest Unicode data
- added UnicodeChar and UnicodeStrSlice traits to prelude
- libunicode is now the collection point for the std::char module,
combining the libunicode functionality with the Char functionality
from libcore
- thus, moved doc comment for char from core::char to unicode::char
- libcollections remains the collection point for std::str
The Unicode-aware functions that previously lived in the Char and
StrSlice traits are no longer available to programs that only use
libcore. To regain use of these methods, include the libunicode crate
and use the UnicodeChar and/or UnicodeStrSlice traits:
extern crate unicode;
use unicode::UnicodeChar;
use unicode::UnicodeStrSlice;
use unicode::Words; // if you want to use the words() method
NOTE: this does *not* impact programs that use libstd, since UnicodeChar
and UnicodeStrSlice have been added to the prelude.
closes #15224
[breaking-change]
2014-06-30 16:04:10 -05:00
|
|
|
extern crate unicode;
|
2014-04-30 22:04:56 -05:00
|
|
|
extern crate core;
|
std: Recreate a `collections` module
As with the previous commit with `librand`, this commit shuffles around some
`collections` code. The new state of the world is similar to that of librand:
* The libcollections crate now only depends on libcore and liballoc.
* The standard library has a new module, `std::collections`. All functionality
of libcollections is reexported through this module.
I would like to stress that this change is purely cosmetic. There are very few
alterations to these primitives.
There are a number of notable points about the new organization:
* std::{str, slice, string, vec} all moved to libcollections. There is no reason
that these primitives shouldn't be necessarily usable in a freestanding
context that has allocation. These are all reexported in their usual places in
the standard library.
* The `hashmap`, and transitively the `lru_cache`, modules no longer reside in
`libcollections`, but rather in libstd. The reason for this is because the
`HashMap::new` contructor requires access to the OSRng for initially seeding
the hash map. Beyond this requirement, there is no reason that the hashmap
could not move to libcollections.
I do, however, have a plan to move the hash map to the collections module. The
`HashMap::new` function could be altered to require that the `H` hasher
parameter ascribe to the `Default` trait, allowing the entire `hashmap` module
to live in libcollections. The key idea would be that the default hasher would
be different in libstd. Something along the lines of:
// src/libstd/collections/mod.rs
pub type HashMap<K, V, H = RandomizedSipHasher> =
core_collections::HashMap<K, V, H>;
This is not possible today because you cannot invoke static methods through
type aliases. If we modified the compiler, however, to allow invocation of
static methods through type aliases, then this type definition would
essentially be switching the default hasher from `SipHasher` in libcollections
to a libstd-defined `RandomizedSipHasher` type. This type's `Default`
implementation would randomly seed the `SipHasher` instance, and otherwise
perform the same as `SipHasher`.
This future state doesn't seem incredibly far off, but until that time comes,
the hashmap module will live in libstd to not compromise on functionality.
* In preparation for the hashmap moving to libcollections, the `hash` module has
moved from libstd to libcollections. A previously snapshotted commit enables a
distinct `Writer` trait to live in the `hash` module which `Hash`
implementations are now parameterized over.
Due to using a custom trait, the `SipHasher` implementation has lost its
specialized methods for writing integers. These can be re-added
backwards-compatibly in the future via default methods if necessary, but the
FNV hashing should satisfy much of the need for speedier hashing.
A list of breaking changes:
* HashMap::{get, get_mut} no longer fails with the key formatted into the error
message with `{:?}`, instead, a generic message is printed. With backtraces,
it should still be not-too-hard to track down errors.
* The HashMap, HashSet, and LruCache types are now available through
std::collections instead of the collections crate.
* Manual implementations of hash should be parameterized over `hash::Writer`
instead of just `Writer`.
[breaking-change]
2014-05-29 20:50:12 -05:00
|
|
|
extern crate core_collections = "collections";
|
2014-06-03 22:09:39 -05:00
|
|
|
extern crate core_rand = "rand";
|
2014-06-07 13:13:26 -05:00
|
|
|
extern crate core_sync = "sync";
|
2014-06-03 22:09:39 -05:00
|
|
|
extern crate libc;
|
|
|
|
extern crate rustrt;
|
2014-02-24 12:16:03 -06:00
|
|
|
|
2013-06-17 01:21:49 -05:00
|
|
|
// Make std testable by not duplicating lang items. See #2912
|
2014-02-14 12:10:06 -06:00
|
|
|
#[cfg(test)] extern crate realstd = "std";
|
2014-05-13 18:10:05 -05:00
|
|
|
#[cfg(test)] pub use realstd::kinds;
|
|
|
|
#[cfg(test)] pub use realstd::ops;
|
|
|
|
#[cfg(test)] pub use realstd::cmp;
|
|
|
|
#[cfg(test)] pub use realstd::ty;
|
2014-07-10 16:19:17 -05:00
|
|
|
#[cfg(test)] pub use realstd::boxed;
|
2014-05-15 20:18:00 -05:00
|
|
|
#[cfg(test)] pub use realstd::gc;
|
2013-03-26 21:53:33 -05:00
|
|
|
|
2014-05-20 12:38:05 -05:00
|
|
|
|
|
|
|
// NB: These reexports are in the order they should be listed in rustdoc
|
2014-04-30 22:22:55 -05:00
|
|
|
|
2014-04-30 22:36:58 -05:00
|
|
|
pub use core::any;
|
2014-04-30 23:11:17 -05:00
|
|
|
pub use core::bool;
|
2014-05-01 13:19:56 -05:00
|
|
|
pub use core::cell;
|
2014-04-30 22:55:38 -05:00
|
|
|
pub use core::clone;
|
2014-05-20 12:38:05 -05:00
|
|
|
#[cfg(not(test))] pub use core::cmp;
|
2014-04-30 22:46:51 -05:00
|
|
|
pub use core::default;
|
2014-05-21 00:27:24 -05:00
|
|
|
pub use core::finally;
|
2014-04-30 22:04:56 -05:00
|
|
|
pub use core::intrinsics;
|
2014-04-30 23:41:03 -05:00
|
|
|
pub use core::iter;
|
2014-05-20 12:38:05 -05:00
|
|
|
#[cfg(not(test))] pub use core::kinds;
|
2014-04-30 22:13:05 -05:00
|
|
|
pub use core::mem;
|
2014-05-20 12:38:05 -05:00
|
|
|
#[cfg(not(test))] pub use core::ops;
|
2014-04-30 22:17:50 -05:00
|
|
|
pub use core::ptr;
|
2014-04-30 22:38:31 -05:00
|
|
|
pub use core::raw;
|
2014-05-20 22:24:17 -05:00
|
|
|
pub use core::simd;
|
2014-04-30 23:02:13 -05:00
|
|
|
pub use core::tuple;
|
2014-07-01 19:21:15 -05:00
|
|
|
// FIXME #15320: primitive documentation needs top-level modules, this
|
|
|
|
// should be `std::tuple::unit`.
|
|
|
|
pub use core::unit;
|
2014-05-20 12:38:05 -05:00
|
|
|
#[cfg(not(test))] pub use core::ty;
|
2014-05-10 15:46:05 -05:00
|
|
|
pub use core::result;
|
2014-06-02 17:49:42 -05:00
|
|
|
pub use core::option;
|
2014-04-30 22:04:56 -05:00
|
|
|
|
2014-07-10 16:19:17 -05:00
|
|
|
pub use alloc::boxed;
|
|
|
|
#[deprecated = "use boxed instead"]
|
|
|
|
pub use owned = boxed;
|
|
|
|
|
2014-05-13 18:10:05 -05:00
|
|
|
pub use alloc::rc;
|
|
|
|
|
std: Recreate a `collections` module
As with the previous commit with `librand`, this commit shuffles around some
`collections` code. The new state of the world is similar to that of librand:
* The libcollections crate now only depends on libcore and liballoc.
* The standard library has a new module, `std::collections`. All functionality
of libcollections is reexported through this module.
I would like to stress that this change is purely cosmetic. There are very few
alterations to these primitives.
There are a number of notable points about the new organization:
* std::{str, slice, string, vec} all moved to libcollections. There is no reason
that these primitives shouldn't be necessarily usable in a freestanding
context that has allocation. These are all reexported in their usual places in
the standard library.
* The `hashmap`, and transitively the `lru_cache`, modules no longer reside in
`libcollections`, but rather in libstd. The reason for this is because the
`HashMap::new` contructor requires access to the OSRng for initially seeding
the hash map. Beyond this requirement, there is no reason that the hashmap
could not move to libcollections.
I do, however, have a plan to move the hash map to the collections module. The
`HashMap::new` function could be altered to require that the `H` hasher
parameter ascribe to the `Default` trait, allowing the entire `hashmap` module
to live in libcollections. The key idea would be that the default hasher would
be different in libstd. Something along the lines of:
// src/libstd/collections/mod.rs
pub type HashMap<K, V, H = RandomizedSipHasher> =
core_collections::HashMap<K, V, H>;
This is not possible today because you cannot invoke static methods through
type aliases. If we modified the compiler, however, to allow invocation of
static methods through type aliases, then this type definition would
essentially be switching the default hasher from `SipHasher` in libcollections
to a libstd-defined `RandomizedSipHasher` type. This type's `Default`
implementation would randomly seed the `SipHasher` instance, and otherwise
perform the same as `SipHasher`.
This future state doesn't seem incredibly far off, but until that time comes,
the hashmap module will live in libstd to not compromise on functionality.
* In preparation for the hashmap moving to libcollections, the `hash` module has
moved from libstd to libcollections. A previously snapshotted commit enables a
distinct `Writer` trait to live in the `hash` module which `Hash`
implementations are now parameterized over.
Due to using a custom trait, the `SipHasher` implementation has lost its
specialized methods for writing integers. These can be re-added
backwards-compatibly in the future via default methods if necessary, but the
FNV hashing should satisfy much of the need for speedier hashing.
A list of breaking changes:
* HashMap::{get, get_mut} no longer fails with the key formatted into the error
message with `{:?}`, instead, a generic message is printed. With backtraces,
it should still be not-too-hard to track down errors.
* The HashMap, HashSet, and LruCache types are now available through
std::collections instead of the collections crate.
* Manual implementations of hash should be parameterized over `hash::Writer`
instead of just `Writer`.
[breaking-change]
2014-05-29 20:50:12 -05:00
|
|
|
pub use core_collections::slice;
|
|
|
|
pub use core_collections::str;
|
|
|
|
pub use core_collections::string;
|
|
|
|
pub use core_collections::vec;
|
|
|
|
|
2014-06-03 22:09:39 -05:00
|
|
|
pub use rustrt::c_str;
|
|
|
|
pub use rustrt::local_data;
|
|
|
|
|
Add libunicode; move unicode functions from core
- created new crate, libunicode, below libstd
- split Char trait into Char (libcore) and UnicodeChar (libunicode)
- Unicode-aware functions now live in libunicode
- is_alphabetic, is_XID_start, is_XID_continue, is_lowercase,
is_uppercase, is_whitespace, is_alphanumeric, is_control,
is_digit, to_uppercase, to_lowercase
- added width method in UnicodeChar trait
- determines printed width of character in columns, or None if it is
a non-NULL control character
- takes a boolean argument indicating whether the present context is
CJK or not (characters with 'A'mbiguous widths are double-wide in
CJK contexts, single-wide otherwise)
- split StrSlice into StrSlice (libcore) and UnicodeStrSlice
(libunicode)
- functionality formerly in StrSlice that relied upon Unicode
functionality from Char is now in UnicodeStrSlice
- words, is_whitespace, is_alphanumeric, trim, trim_left, trim_right
- also moved Words type alias into libunicode because words method is
in UnicodeStrSlice
- unified Unicode tables from libcollections, libcore, and libregex into
libunicode
- updated unicode.py in src/etc to generate aforementioned tables
- generated new tables based on latest Unicode data
- added UnicodeChar and UnicodeStrSlice traits to prelude
- libunicode is now the collection point for the std::char module,
combining the libunicode functionality with the Char functionality
from libcore
- thus, moved doc comment for char from core::char to unicode::char
- libcollections remains the collection point for std::str
The Unicode-aware functions that previously lived in the Char and
StrSlice traits are no longer available to programs that only use
libcore. To regain use of these methods, include the libunicode crate
and use the UnicodeChar and/or UnicodeStrSlice traits:
extern crate unicode;
use unicode::UnicodeChar;
use unicode::UnicodeStrSlice;
use unicode::Words; // if you want to use the words() method
NOTE: this does *not* impact programs that use libstd, since UnicodeChar
and UnicodeStrSlice have been added to the prelude.
closes #15224
[breaking-change]
2014-06-30 16:04:10 -05:00
|
|
|
pub use unicode::char;
|
|
|
|
|
2014-06-07 13:13:26 -05:00
|
|
|
pub use core_sync::comm;
|
|
|
|
|
2014-03-11 15:38:36 -05:00
|
|
|
// Run tests with libgreen instead of libnative.
|
|
|
|
//
|
|
|
|
// FIXME: This egregiously hacks around starting the test runner in a different
|
|
|
|
// threading mode than the default by reaching into the auto-generated
|
|
|
|
// '__test' module.
|
|
|
|
#[cfg(test)] #[start]
|
2014-06-25 14:47:34 -05:00
|
|
|
fn start(argc: int, argv: *const *const u8) -> int {
|
2014-03-24 12:40:36 -05:00
|
|
|
green::start(argc, argv, rustuv::event_loop, __test::main)
|
2014-03-11 15:38:36 -05:00
|
|
|
}
|
|
|
|
|
2014-04-29 22:05:51 -05:00
|
|
|
/* Exported macros */
|
|
|
|
|
2014-02-16 23:40:26 -06:00
|
|
|
pub mod macros;
|
2014-04-29 22:05:51 -05:00
|
|
|
pub mod bitflags;
|
2014-01-24 01:40:54 -06:00
|
|
|
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 16:03:29 -06:00
|
|
|
mod rtdeps;
|
2013-03-06 21:09:17 -06:00
|
|
|
|
2013-01-08 21:37:25 -06:00
|
|
|
/* The Prelude. */
|
|
|
|
|
|
|
|
pub mod prelude;
|
2011-12-13 18:25:51 -06:00
|
|
|
|
2013-10-31 17:09:24 -05:00
|
|
|
|
2012-11-30 02:47:45 -06:00
|
|
|
/* Primitive types */
|
2012-04-14 19:21:10 -05:00
|
|
|
|
2014-01-08 05:57:31 -06:00
|
|
|
#[path = "num/float_macros.rs"] mod float_macros;
|
2013-05-12 20:14:40 -05:00
|
|
|
#[path = "num/int_macros.rs"] mod int_macros;
|
|
|
|
#[path = "num/uint_macros.rs"] mod uint_macros;
|
|
|
|
|
|
|
|
#[path = "num/int.rs"] pub mod int;
|
|
|
|
#[path = "num/i8.rs"] pub mod i8;
|
|
|
|
#[path = "num/i16.rs"] pub mod i16;
|
|
|
|
#[path = "num/i32.rs"] pub mod i32;
|
|
|
|
#[path = "num/i64.rs"] pub mod i64;
|
|
|
|
|
|
|
|
#[path = "num/uint.rs"] pub mod uint;
|
|
|
|
#[path = "num/u8.rs"] pub mod u8;
|
|
|
|
#[path = "num/u16.rs"] pub mod u16;
|
|
|
|
#[path = "num/u32.rs"] pub mod u32;
|
|
|
|
#[path = "num/u64.rs"] pub mod u64;
|
|
|
|
|
|
|
|
#[path = "num/f32.rs"] pub mod f32;
|
|
|
|
#[path = "num/f64.rs"] pub mod f64;
|
2012-11-30 02:47:45 -06:00
|
|
|
|
std: Recreate a `rand` module
This commit shuffles around some of the `rand` code, along with some
reorganization. The new state of the world is as follows:
* The librand crate now only depends on libcore. This interface is experimental.
* The standard library has a new module, `std::rand`. This interface will
eventually become stable.
Unfortunately, this entailed more of a breaking change than just shuffling some
names around. The following breaking changes were made to the rand library:
* Rng::gen_vec() was removed. This has been replaced with Rng::gen_iter() which
will return an infinite stream of random values. Previous behavior can be
regained with `rng.gen_iter().take(n).collect()`
* Rng::gen_ascii_str() was removed. This has been replaced with
Rng::gen_ascii_chars() which will return an infinite stream of random ascii
characters. Similarly to gen_iter(), previous behavior can be emulated with
`rng.gen_ascii_chars().take(n).collect()`
* {IsaacRng, Isaac64Rng, XorShiftRng}::new() have all been removed. These all
relied on being able to use an OSRng for seeding, but this is no longer
available in librand (where these types are defined). To retain the same
functionality, these types now implement the `Rand` trait so they can be
generated with a random seed from another random number generator. This allows
the stdlib to use an OSRng to create seeded instances of these RNGs.
* Rand implementations for `Box<T>` and `@T` were removed. These seemed to be
pretty rare in the codebase, and it allows for librand to not depend on
liballoc. Additionally, other pointer types like Rc<T> and Arc<T> were not
supported. If this is undesirable, librand can depend on liballoc and regain
these implementations.
* The WeightedChoice structure is no longer built with a `Vec<Weighted<T>>`,
but rather a `&mut [Weighted<T>]`. This means that the WeightedChoice
structure now has a lifetime associated with it.
* The `sample` method on `Rng` has been moved to a top-level function in the
`rand` module due to its dependence on `Vec`.
cc #13851
[breaking-change]
2014-05-25 03:39:37 -05:00
|
|
|
pub mod rand;
|
2012-11-30 02:47:45 -06:00
|
|
|
|
2013-04-22 14:42:25 -05:00
|
|
|
pub mod ascii;
|
|
|
|
|
2014-05-15 20:18:00 -05:00
|
|
|
#[cfg(not(test))]
|
2013-11-19 22:20:06 -06:00
|
|
|
pub mod gc;
|
2011-12-13 18:25:51 -06:00
|
|
|
|
2012-11-30 02:47:45 -06:00
|
|
|
/* Common traits */
|
|
|
|
|
|
|
|
pub mod from_str;
|
2012-10-03 21:24:06 -05:00
|
|
|
pub mod num;
|
|
|
|
pub mod to_str;
|
std: Recreate a `collections` module
As with the previous commit with `librand`, this commit shuffles around some
`collections` code. The new state of the world is similar to that of librand:
* The libcollections crate now only depends on libcore and liballoc.
* The standard library has a new module, `std::collections`. All functionality
of libcollections is reexported through this module.
I would like to stress that this change is purely cosmetic. There are very few
alterations to these primitives.
There are a number of notable points about the new organization:
* std::{str, slice, string, vec} all moved to libcollections. There is no reason
that these primitives shouldn't be necessarily usable in a freestanding
context that has allocation. These are all reexported in their usual places in
the standard library.
* The `hashmap`, and transitively the `lru_cache`, modules no longer reside in
`libcollections`, but rather in libstd. The reason for this is because the
`HashMap::new` contructor requires access to the OSRng for initially seeding
the hash map. Beyond this requirement, there is no reason that the hashmap
could not move to libcollections.
I do, however, have a plan to move the hash map to the collections module. The
`HashMap::new` function could be altered to require that the `H` hasher
parameter ascribe to the `Default` trait, allowing the entire `hashmap` module
to live in libcollections. The key idea would be that the default hasher would
be different in libstd. Something along the lines of:
// src/libstd/collections/mod.rs
pub type HashMap<K, V, H = RandomizedSipHasher> =
core_collections::HashMap<K, V, H>;
This is not possible today because you cannot invoke static methods through
type aliases. If we modified the compiler, however, to allow invocation of
static methods through type aliases, then this type definition would
essentially be switching the default hasher from `SipHasher` in libcollections
to a libstd-defined `RandomizedSipHasher` type. This type's `Default`
implementation would randomly seed the `SipHasher` instance, and otherwise
perform the same as `SipHasher`.
This future state doesn't seem incredibly far off, but until that time comes,
the hashmap module will live in libstd to not compromise on functionality.
* In preparation for the hashmap moving to libcollections, the `hash` module has
moved from libstd to libcollections. A previously snapshotted commit enables a
distinct `Writer` trait to live in the `hash` module which `Hash`
implementations are now parameterized over.
Due to using a custom trait, the `SipHasher` implementation has lost its
specialized methods for writing integers. These can be re-added
backwards-compatibly in the future via default methods if necessary, but the
FNV hashing should satisfy much of the need for speedier hashing.
A list of breaking changes:
* HashMap::{get, get_mut} no longer fails with the key formatted into the error
message with `{:?}`, instead, a generic message is printed. With backtraces,
it should still be not-too-hard to track down errors.
* The HashMap, HashSet, and LruCache types are now available through
std::collections instead of the collections crate.
* Manual implementations of hash should be parameterized over `hash::Writer`
instead of just `Writer`.
[breaking-change]
2014-05-29 20:50:12 -05:00
|
|
|
|
|
|
|
/* Common data structures */
|
|
|
|
|
|
|
|
pub mod collections;
|
2014-06-23 18:15:40 -05:00
|
|
|
pub mod hash;
|
2012-08-01 18:04:43 -05:00
|
|
|
|
2012-11-30 02:47:45 -06:00
|
|
|
/* Tasks and communication */
|
|
|
|
|
2012-11-28 14:33:00 -06:00
|
|
|
pub mod task;
|
2013-12-12 19:27:37 -06:00
|
|
|
pub mod sync;
|
2012-02-22 06:06:38 -06:00
|
|
|
|
2012-11-30 02:47:45 -06:00
|
|
|
/* Runtime and platform support */
|
2011-12-13 18:25:51 -06:00
|
|
|
|
2014-03-14 13:16:10 -05:00
|
|
|
pub mod c_vec;
|
2014-06-08 22:12:10 -05:00
|
|
|
pub mod dynamic_lib;
|
2012-10-03 21:24:06 -05:00
|
|
|
pub mod os;
|
2013-11-11 00:46:32 -06:00
|
|
|
pub mod io;
|
2012-10-03 21:24:06 -05:00
|
|
|
pub mod path;
|
2013-07-29 03:12:41 -05:00
|
|
|
pub mod fmt;
|
2013-10-31 17:09:24 -05:00
|
|
|
|
2013-07-12 16:43:57 -05:00
|
|
|
// FIXME #7809: This shouldn't be pub, and it should be reexported under 'unstable'
|
2013-04-27 20:57:15 -05:00
|
|
|
// but name resolution doesn't work without it being pub.
|
2014-01-05 08:09:07 -06:00
|
|
|
#[unstable]
|
2013-04-27 20:57:15 -05:00
|
|
|
pub mod rt;
|
2014-06-03 22:09:39 -05:00
|
|
|
mod failure;
|
2012-11-30 02:47:45 -06:00
|
|
|
|
2012-11-28 14:33:00 -06:00
|
|
|
// A curious inner-module that's not exported that contains the binding
|
2013-05-17 17:28:44 -05:00
|
|
|
// 'std' so that macro-expanded references to std::error and such
|
|
|
|
// can be resolved within libstd.
|
2013-03-13 21:12:55 -05:00
|
|
|
#[doc(hidden)]
|
2013-05-20 17:20:16 -05:00
|
|
|
mod std {
|
2014-05-25 18:21:07 -05:00
|
|
|
// mods used for deriving
|
2013-05-20 17:20:16 -05:00
|
|
|
pub use clone;
|
|
|
|
pub use cmp;
|
2014-02-21 23:33:23 -06:00
|
|
|
pub use hash;
|
2014-05-04 15:20:47 -05:00
|
|
|
|
2014-05-25 18:21:07 -05:00
|
|
|
pub use comm; // used for select!()
|
|
|
|
pub use fmt; // used for any formatting strings
|
|
|
|
pub use io; // used for println!()
|
|
|
|
pub use local_data; // used for local_data_key!()
|
|
|
|
pub use option; // used for bitflags!()
|
|
|
|
pub use rt; // used for fail!()
|
|
|
|
pub use vec; // used for vec![]
|
|
|
|
|
|
|
|
// The test runner calls ::std::os::args() but really wants realstd
|
|
|
|
#[cfg(test)] pub use os = realstd::os;
|
2014-05-04 15:20:47 -05:00
|
|
|
// The test runner requires std::slice::Vector, so re-export std::slice just for it.
|
|
|
|
#[cfg(test)] pub use slice;
|
2013-05-20 17:20:16 -05:00
|
|
|
}
|