Skip to content

Commit 0154c7b

Browse files
committed
---
yaml --- r: 80563 b: refs/heads/master c: 3b07f1e h: refs/heads/master i: 80561: 0d76a47 80559: 215770d v: v3
1 parent e1544c0 commit 0154c7b

File tree

23 files changed

+1556
-329
lines changed

23 files changed

+1556
-329
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: e12c3bfbf999bb565b45b58ae9475d60c9e63ceb
2+
refs/heads/master: 3b07f1efe55d6cf59a40a5ec12d840deea5a3a6e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cbd1eefbd350797b783df119fed7956d7e1c74ad
55
refs/heads/try: 71bebebc37fbb229877da88dde13c2f35913bd77

trunk/doc/rust.md

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -962,76 +962,24 @@ parameters to allow methods with that trait to be called on values
962962
of that type.
963963

964964

965-
#### Unsafety
965+
#### Unsafe functions
966966

967-
Unsafe operations are those that potentially violate the memory-safety guarantees of Rust's static semantics.
967+
Unsafe functions are those containing unsafe operations that are not contained in an [`unsafe` block](#unsafe-blocks).
968+
Such a function must be prefixed with the keyword `unsafe`.
968969

969-
The following language level features cannot be used in the safe subset of Rust:
970+
Unsafe operations are those that potentially violate the memory-safety guarantees of Rust's static semantics.
971+
Specifically, the following operations are considered unsafe:
970972

971973
- Dereferencing a [raw pointer](#pointer-types).
972-
- Calling an unsafe function (including an intrinsic or foreign function).
973-
974-
##### Unsafe functions
975-
976-
Unsafe functions are functions that are not safe in all contexts and/or for all possible inputs.
977-
Such a function must be prefixed with the keyword `unsafe`.
974+
- Casting a [raw pointer](#pointer-types) to a safe pointer type.
975+
- Calling an unsafe function.
978976

979977
##### Unsafe blocks
980978

981-
A block of code can also be prefixed with the `unsafe` keyword, to permit calling `unsafe` functions
982-
or dereferencing raw pointers within a safe function.
983-
984-
When a programmer has sufficient conviction that a sequence of potentially unsafe operations is
985-
actually safe, they can encapsulate that sequence (taken as a whole) within an `unsafe` block. The
986-
compiler will consider uses of such code safe, in the surrounding context.
987-
988-
Unsafe blocks are used to wrap foreign libraries, make direct use of hardware or implement features
989-
not directly present in the language. For example, Rust provides the language features necessary to
990-
implement memory-safe concurrency in the language but the implementation of tasks and message
991-
passing is in the standard library.
992-
993-
Rust's type system is a conservative approximation of the dynamic safety requirements, so in some
994-
cases there is a performance cost to using safe code. For example, a doubly-linked list is not a
995-
tree structure and can only be represented with managed or reference-counted pointers in safe code.
996-
By using `unsafe` blocks to represent the reverse links as raw pointers, it can be implemented with
997-
only owned pointers.
998-
999-
##### Behavior considered unsafe
1000-
1001-
This is a list of behavior which is forbidden in all Rust code. Type checking provides the guarantee
1002-
that these issues are never caused by safe code. An `unsafe` block or function is responsible for
1003-
never invoking this behaviour or exposing an API making it possible for it to occur in safe code.
1004-
1005-
* Data races
1006-
* Dereferencing a null/dangling raw pointer
1007-
* Mutating an immutable value/reference, if it is not marked as non-`Freeze`
1008-
* Reads of [undef](http://llvm.org/docs/LangRef.html#undefined-values) (uninitialized) memory
1009-
* Breaking the [pointer aliasing rules](http://llvm.org/docs/LangRef.html#pointer-aliasing-rules)
1010-
with raw pointers (a subset of the rules used by C)
1011-
* Invoking undefined behavior via compiler intrinsics:
1012-
* Indexing outside of the bounds of an object with `std::ptr::offset` (`offset` intrinsic), with
1013-
the exception of one byte past the end which is permitted.
1014-
* Using `std::ptr::copy_nonoverlapping_memory` (`memcpy32`/`memcpy64` instrinsics) on
1015-
overlapping buffers
1016-
* Invalid values in primitive types, even in private fields/locals:
1017-
* Dangling/null pointers in non-raw pointers, or slices
1018-
* A value other than `false` (0) or `true` (1) in a `bool`
1019-
* A discriminant in an `enum` not included in the type definition
1020-
* A value in a `char` which is a surrogate or above `char::MAX`
1021-
* non-UTF-8 byte sequences in a `str`
1022-
1023-
##### Behaviour not considered unsafe
1024-
1025-
This is a list of behaviour not considered *unsafe* in Rust terms, but that may be undesired.
1026-
1027-
* Deadlocks
1028-
* Reading data from private fields (`std::repr`, `format!("{:?}", x)`)
1029-
* Leaks due to reference count cycles, even in the global heap
1030-
* Exiting without calling destructors
1031-
* Sending signals
1032-
* Accessing/modifying the file system
1033-
* Unsigned integer overflow (well-defined as wrapping)
1034-
* Signed integer overflow (well-defined as two's complement representation wrapping)
979+
A block of code can also be prefixed with the `unsafe` keyword, to permit a sequence of unsafe operations in an otherwise-safe function.
980+
This facility exists because the static semantics of Rust are a necessary approximation of the dynamic semantics.
981+
When a programmer has sufficient conviction that a sequence of unsafe operations is actually safe, they can encapsulate that sequence (taken as a whole) within an `unsafe` block. The compiler will consider uses of such code "safe", to the surrounding context.
982+
1035983

1036984
#### Diverging functions
1037985

trunk/src/libextra/workcache.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ impl Database {
198198
}
199199
}
200200

201-
// FIXME #4330: use &mut self here
202201
#[unsafe_destructor]
203202
impl Drop for Database {
204203
fn drop(&mut self) {

trunk/src/librustc/middle/trans/base.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,10 +2559,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
25592559
// LLVM type is not fully determined by the Rust type.
25602560
let (v, inlineable) = consts::const_expr(ccx, expr);
25612561
ccx.const_values.insert(id, v);
2562-
if !inlineable {
2563-
debug!("%s not inlined", sym);
2564-
ccx.non_inlineable_statics.insert(id);
2565-
}
2562+
let mut inlineable = inlineable;
25662563
exprt = true;
25672564

25682565
unsafe {
@@ -2578,8 +2575,30 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
25782575
lib::llvm::SetUnnamedAddr(g, true);
25792576
lib::llvm::SetLinkage(g,
25802577
lib::llvm::InternalLinkage);
2578+
2579+
// This is a curious case where we must make
2580+
// all of these statics inlineable. If a
2581+
// global is tagged as
2582+
// address_insignificant, then LLVM won't
2583+
// coalesce globals unless they have an
2584+
// internal linkage type. This means that
2585+
// external crates cannot use this global.
2586+
// This is a problem for things like inner
2587+
// statics in generic functions, because the
2588+
// function will be inlined into another
2589+
// crate and then attempt to link to the
2590+
// static in the original crate, only to
2591+
// find that it's not there. On the other
2592+
// side of inlininig, the crates knows to
2593+
// not declare this static as
2594+
// available_externally (because it isn't)
2595+
inlineable = true;
25812596
}
25822597

2598+
if !inlineable {
2599+
debug!("%s not inlined", sym);
2600+
ccx.non_inlineable_statics.insert(id);
2601+
}
25832602
ccx.item_symbols.insert(i.id, sym);
25842603
g
25852604
}

trunk/src/librustc/middle/trans/inline.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::vec;
2121
use syntax::ast;
2222
use syntax::ast_map::path_name;
2323
use syntax::ast_util::local_def;
24+
use syntax::attr;
2425

2526
pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
2627
-> ast::DefId {
@@ -68,7 +69,12 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
6869
match item.node {
6970
ast::item_static(*) => {
7071
let g = get_item_val(ccx, item.id);
71-
SetLinkage(g, AvailableExternallyLinkage);
72+
// see the comment in get_item_val() as to why this check is
73+
// performed here.
74+
if !attr::contains_name(item.attrs,
75+
"address_insignificant") {
76+
SetLinkage(g, AvailableExternallyLinkage);
77+
}
7278
}
7379
_ => {}
7480
}

trunk/src/librustpkg/rustpkg.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pub trait CtxMethods {
189189
fn test(&self);
190190
fn uninstall(&self, _id: &str, _vers: Option<~str>);
191191
fn unprefer(&self, _id: &str, _vers: Option<~str>);
192+
fn init(&self);
192193
}
193194

194195
impl CtxMethods for BuildContext {
@@ -319,6 +320,13 @@ impl CtxMethods for BuildContext {
319320
"test" => {
320321
self.test();
321322
}
323+
"init" => {
324+
if args.len() != 0 {
325+
return usage::init();
326+
} else {
327+
self.init();
328+
}
329+
}
322330
"uninstall" => {
323331
if args.len() < 1 {
324332
return usage::uninstall();
@@ -540,6 +548,13 @@ impl CtxMethods for BuildContext {
540548
fail!("test not yet implemented");
541549
}
542550

551+
fn init(&self) {
552+
os::mkdir_recursive(&Path("src"), U_RWX);
553+
os::mkdir_recursive(&Path("lib"), U_RWX);
554+
os::mkdir_recursive(&Path("bin"), U_RWX);
555+
os::mkdir_recursive(&Path("build"), U_RWX);
556+
}
557+
543558
fn uninstall(&self, _id: &str, _vers: Option<~str>) {
544559
fail!("uninstall not yet implemented");
545560
}
@@ -688,6 +703,7 @@ pub fn main_args(args: &[~str]) {
688703
~"list" => usage::list(),
689704
~"prefer" => usage::prefer(),
690705
~"test" => usage::test(),
706+
~"init" => usage::init(),
691707
~"uninstall" => usage::uninstall(),
692708
~"unprefer" => usage::unprefer(),
693709
_ => usage::general()

trunk/src/librustpkg/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ fn no_rebuilding() {
939939
}
940940
941941
#[test]
942+
#[ignore]
942943
fn no_rebuilding_dep() {
943944
let p_id = PkgId::new("foo");
944945
let dep_id = PkgId::new("bar");

trunk/src/librustpkg/usage.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,10 @@ and exit code will be redirected.
148148
Options:
149149
-c, --cfg Pass a cfg flag to the package script");
150150
}
151+
152+
pub fn init() {
153+
io::println("rustpkg init name
154+
155+
This makes a new workspace for working on a project named name.
156+
");
157+
}

trunk/src/librustpkg/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use workcache_support::{digest_file_with_date, digest_only_date};
3333
// you could update the match in rustpkg.rc but forget to update this list. I think
3434
// that should be fixed.
3535
static COMMANDS: &'static [&'static str] =
36-
&["build", "clean", "do", "info", "install", "list", "prefer", "test", "uninstall",
36+
&["build", "clean", "do", "info", "init", "install", "list", "prefer", "test", "uninstall",
3737
"unprefer"];
3838

3939

trunk/src/libstd/os.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,7 @@ pub fn env() -> ~[(~str,~str)] {
196196
if (ch as uint == 0) {
197197
fail!("os::env() failure getting env string from OS: %s", os::last_os_error());
198198
}
199-
let mut curr_ptr: uint = ch as uint;
200-
let mut result = ~[];
201-
while(*(curr_ptr as *libc::c_char) != 0 as libc::c_char) {
202-
let env_pair = str::raw::from_c_str(
203-
curr_ptr as *libc::c_char);
204-
result.push(env_pair);
205-
curr_ptr +=
206-
libc::strlen(curr_ptr as *libc::c_char) as uint
207-
+ 1;
208-
}
199+
let result = str::raw::from_c_multistring(ch as *libc::c_char, None);
209200
FreeEnvironmentStringsA(ch);
210201
result
211202
}

0 commit comments

Comments
 (0)