Commit Graph

26540 Commits

Author SHA1 Message Date
Huon Wilson
5d86e24ab2 std::unstable::mutex: streamline & clarify documentation. 2014-02-16 10:13:56 +11:00
Huon Wilson
0f4294b4e2 sync: Add #[must_use] to the Mutex guard.
This helps people remember to save the return value to keep the mutex
locked as appropriate.
2014-02-16 10:13:56 +11:00
Huon Wilson
0937f65999 std: add a NativeMutex type as a wrapper to destroy StaticNativeMutex.
This obsoletes LittleLock, and so it is removed.
2014-02-16 10:13:56 +11:00
Huon Wilson
b87ed605c0 std: Rename unstable::mutex::Mutex to StaticNativeMutex.
This better reflects its purpose and design.
2014-02-16 10:13:56 +11:00
Huon Wilson
75d92dbabe std: add tests for the _noguard lock/signal/wait methods on Mutex. 2014-02-16 10:13:56 +11:00
Huon Wilson
76a59fd6e2 std: add an RAII unlocker to Mutex.
This automatically unlocks its lock when it goes out of scope, and
provides a safe(ish) method to call .wait.
2014-02-16 10:13:56 +11:00
Flavio Percoco
fd57717b16 Add test and close #8893 2014-02-16 00:00:38 +01:00
Steven Fackler
23fdbcf7dd Add a method to LimitReader to return the limit
This is useful in contexts like this:

let size = rdr.read_be_i32() as uint;
let mut limit = LimitReader::new(rdr.by_ref(), size);
let thing = read_a_thing(&mut limit);
assert!(limit.limit() == 0);
2014-02-15 14:22:56 -08:00
Brian Anderson
508cb29dc4 mk: Base the windows dist target on prepare.mk 2014-02-15 14:18:00 -08:00
Brian Anderson
8f2bee2117 mk: Fix a dist bug
Fallout from moving doc/ to src/doc
2014-02-15 14:18:00 -08:00
Brian Anderson
9cd96e4f02 mk: Base the install target on prepare.mk 2014-02-15 14:18:00 -08:00
Brian Anderson
4cd8bdc969 mk: Add prepare.mk
This is a slightly more generic rewrite of install.mk. Currently
used for nothing, but we'll base all the binary distributables off it.
2014-02-15 14:17:57 -08:00
bors
6b025c803c auto merge of #12272 : alexcrichton/rust/snapshot, r=kballard
This notably contains the `extern mod` => `extern crate` change.

Closes #9880
2014-02-15 14:06:26 -08:00
bors
4af28c98fa auto merge of #12296 : dotdash/rust/byval_noalias, r=cmr
Function parameters that are to be passed by value but don't fit into a
single register are currently passed by creating a copy on the stack and
passing a pointer to that copy to the callee. Since the copy is made
just for the function call, there are no aliases.

For example, this sometimes allows LLVM to eliminate unnecessary calls
to drop glue. Given

````rust
struct Foo {
    a: int,
    b: Option<~str>,
}

extern {
    fn eat(eat: Option<~str>);
}

pub fn foo(v: Foo) {
    match v {
        Foo { a: _, b } => unsafe { eat(b) }
    }
}
````

LLVM currently can't eliminate the drop call for the string, because it
only sees a _pointer_ to Foo, for which it has to expect an alias. So we
get:

````llvm
; Function Attrs: uwtable
define void @_ZN3foo20h9f32c90ae7201edbxaa4v0.0E(%struct.Foo* nocapture) unnamed_addr #0 {
"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit":
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  %4 = load { i64, i64, [0 x i8] }** %1, align 8
  %5 = icmp eq { i64, i64, [0 x i8] }* %4, null
  br i1 %5, label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit, label %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"

"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i": ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit"
  %6 = bitcast { i64, i64, [0 x i8] }* %4 to i8*
  tail call void @free(i8* %6) #1
  br label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit

_ZN3Foo9glue_drop17hf611996539d3036fE.exit:       ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit", %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"
  ret void
}
````

But with the `noalias` attribute, it can safely optimize that to:

````llvm
define void @_ZN3foo20hd28431f929f0d6c4xaa4v0.0E(%struct.Foo* noalias nocapture) unnamed_addr #0 {
_ZN3Foo9glue_drop17he9afbc09d4e9c851E.exit:
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  ret void
}
````
2014-02-15 12:46:23 -08:00
Björn Steinbrink
500d29b589 Declare by-value on-stack parameters to be noalias
Function parameters that are to be passed by value but don't fit into a
single register are currently passed by creating a copy on the stack and
passing a pointer to that copy to the callee. Since the copy is made
just for the function call, there are no aliases.

For example, this sometimes allows LLVM to eliminate unnecessary calls
to drop glue. Given

````rust
struct Foo {
    a: int,
    b: Option<~str>,
}

extern {
    fn eat(eat: Option<~str>);
}

pub fn foo(v: Foo) {
    match v {
        Foo { a: _, b } => unsafe { eat(b) }
    }
}
````

LLVM currently can't eliminate the drop call for the string, because it
only sees a _pointer_ to Foo, for which it has to expect an alias. So we
get:

````llvm
; Function Attrs: uwtable
define void @_ZN3foo20h9f32c90ae7201edbxaa4v0.0E(%struct.Foo* nocapture) unnamed_addr #0 {
"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit":
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  %4 = load { i64, i64, [0 x i8] }** %1, align 8
  %5 = icmp eq { i64, i64, [0 x i8] }* %4, null
  br i1 %5, label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit, label %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"

"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i": ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit"
  %6 = bitcast { i64, i64, [0 x i8] }* %4 to i8*
  tail call void @free(i8* %6) #1
  br label %_ZN3Foo9glue_drop17hf611996539d3036fE.exit

_ZN3Foo9glue_drop17hf611996539d3036fE.exit:       ; preds = %"_ZN34std..option..Option$LT$$UP$str$GT$9glue_drop17hc39b3015f3b9c69dE.exit", %"_ZN8_$UP$str9glue_drop17h15dbdbe2b8897a98E.exit.i.i"
  ret void
}
````

But with the `noalias` attribute, it can safely optimize that to:

````llvm
define void @_ZN3foo20hd28431f929f0d6c4xaa4v0.0E(%struct.Foo* noalias nocapture) unnamed_addr #0 {
_ZN3Foo9glue_drop17he9afbc09d4e9c851E.exit:
  %1 = getelementptr inbounds %struct.Foo* %0, i64 0, i32 1, i32 0
  %2 = load { i64, i64, [0 x i8] }** %1, align 8
  store { i64, i64, [0 x i8] }* null, { i64, i64, [0 x i8] }** %1, align 8
  %3 = ptrtoint { i64, i64, [0 x i8] }* %2 to i64
  %.fca.0.insert = insertvalue { i64 } undef, i64 %3, 0
  tail call void @eat({ i64 } %.fca.0.insert)
  ret void
}
````
2014-02-15 21:34:11 +01:00
bors
adea48abb7 auto merge of #12270 : bstrie/rust/pnoise, r=huonw
Mostly just style fixes, but also remove a heap allocation and switch to using a buffered writer rather than doing 60,000 `println!`s.
2014-02-15 10:51:26 -08:00
Ben Striegel
bfa3e6062f Clean up the Perlin noise benchmark 2014-02-15 13:12:32 -05:00
bors
7762baa89b auto merge of #12282 : cmr/rust/cleanup-ptr, r=huonw 2014-02-15 09:36:26 -08:00
Corey Richardson
254c155fca impl fmt::Pointer for &T and &mut T 2014-02-15 12:11:50 -05:00
Corey Richardson
49e11630fa std: clean up ptr a bit 2014-02-15 12:11:41 -05:00
bors
a7aa4c477e auto merge of #12286 : sfackler/rust/no-conditions, r=alexcrichton 2014-02-15 03:56:27 -08:00
Brian Anderson
5d88a4a76c mk: Clean up conditions for including dist.mk 2014-02-15 03:00:00 -08:00
bors
fba32ea79f auto merge of #12283 : kballard/rust/env-args-bytes, r=erickt
Change `os::args()` and `os::env()` to use `str::from_utf8_lossy()`.
Add new functions `os::args_as_bytes()` and `os::env_as_bytes()` to retrieve the args/env as byte vectors instead.

The existing methods were left returning strings because I expect that the common use-case is to want string handling.

Fixes #7188.
2014-02-15 02:36:27 -08:00
Alex Crichton
e72ddbdc25 Fix all code examples 2014-02-14 23:49:22 -08:00
bors
c9f13b47fe auto merge of #12230 : DaGenix/rust/io-decorator-changes, r=sfackler
I created RefReader and RefWriter structs that wrap a mutable reference to a Reader or Writer value. This works exactly like the ByRef struct in the iter module and allows passing a reference to a Reader or Writer to function expecting a Reader or Writer by value with the caller retaining ownership to the original value.

I also modified LimitReader to take the wrapped Reader by value instead of by reference.

@sfackler
2014-02-14 23:46:29 -08:00
Steven Fackler
e7147ce84f Remove broken link to old conditions tutorial 2014-02-14 23:45:57 -08:00
Alex Crichton
6667f90292 Update rustdoc testing to test all code blocks
It's too easy to forget the `rust` tag to have a code example tested, and it's
far more common to have testable code than untestable code.

This alters rustdoc to have only two directives, `ignore` and `should_fail`. The
`ignore` directive ignores the code block entirely, and the `should_fail`
directive has been fixed to only fail the test if the code execution fails, not
also compilation.
2014-02-14 23:30:10 -08:00
Alex Crichton
a41b0c2529 extern mod => extern crate
This was previously implemented, and it just needed a snapshot to go through
2014-02-14 22:55:21 -08:00
Alex Crichton
359ac360a4 Register new snapshots
This enables the parser error for `extern mod` => `extern crate` transitions.
2014-02-14 22:55:20 -08:00
Palmer Cox
4c233d1c73 Update LimitReader to take the Reader to wrap by value 2014-02-15 00:58:44 -05:00
Palmer Cox
d4dd4c68f8 Create RefReader and RefWriter adaptor structs
RefReader and RefWriter allow a caller to pass a Reader or Writer
instance by reference to generic functions that are expecting arguments
by value.
2014-02-15 00:58:43 -05:00
Kevin Ballard
d22b1646aa Use str::from_utf8_lossy() for os::env() and friends
Parse the environment by default with from_utf8_lossy. Also provide
byte-vector equivalents (e.g. os::env_as_bytes()).

Unfortunately, setenv() can't have a byte-vector equivalent because of
Windows support, unless we want to define a setenv_bytes() that fails
under Windows for non-UTF8 (or non-UTF16).
2014-02-14 21:23:37 -08:00
Kevin Ballard
c73d5ce8ab Use str::from_utf8_lossy() in os::args(), add os::args_as_bytes()
os::args() was using str::raw::from_c_str(), which would assert if the
C-string wasn't valid UTF-8. Switch to using from_utf8_lossy() instead,
and add a separate function os::args_as_bytes() that returns the ~[u8]
byte-vectors instead.
2014-02-14 21:23:37 -08:00
Kevin Ballard
8cc8eb7b8e Add c_str::CString.as_bytes_no_nul() 2014-02-14 21:23:37 -08:00
bors
3496e93d13 auto merge of #12274 : brson/rust/mkfiles, r=alexcrichton
I've been working on binary installers and ended up taking this detour, which does a few things:

* It expands the documentation on the build system with new comments in Makefile.in
* It displays some of that documentation via `make help`
* Removes some unused and broken snapshot code
* Adds `NO_MKFILE_DEPS` to convenience makefile hacking
* Moves almost all of Makefile.in to files in `mk/`

The documentation provided by `make help` and its implementation are somewhat quirky.
2014-02-14 20:51:26 -08:00
bors
f0bad904a1 auto merge of #12276 : alexcrichton/rust/issue-8449, r=kballard
This was just waiting for compiler-rt support, which was added in #12027

Closes #8449
2014-02-14 19:31:28 -08:00
Alex Crichton
90311fc68f Enable 64-bit checked multiplication on 32-bit
This was just waiting for compiler-rt support, which was added in #12027

Closes #8449
2014-02-14 19:26:41 -08:00
Brian Anderson
8d4b675ced mk: Address review feedback 2014-02-14 19:17:50 -08:00
bors
9b173edf86 auto merge of #12277 : alexcrichton/rust/fix-rustdoc-render, r=huonw
The std macros used to be injected with a filename of "<std-macros>", but macros
are now injected with a filename of "<{} macros>" where `{}` is filled in with
the crate name. This updates rustdoc to understand this new system so it'll
render source more frequently.
2014-02-14 17:51:29 -08:00
Brian Anderson
24915c84e0 mk: Move version info to top of main.mk
Just so it's easier to find.
2014-02-14 17:45:54 -08:00
Brian Anderson
334af011f0 mk: Improve build system help commands 2014-02-14 17:45:54 -08:00
Brian Anderson
ab17f445fe mk: Add NO_MKFILE_DEPS for turning off rebuild from makefile changes 2014-02-14 17:45:54 -08:00
Brian Anderson
2852fea61e mk: Move most of Makefile.in to .mk files
Because the build system treats Makefile.in and the .mk files slightly
differently (.in is copied, .mk are included), this makes the system
more uniform. Fewer build system changes will require a complete
reconfigure.
2014-02-14 17:45:54 -08:00
Brian Anderson
94d2c8a21f mk: Remove the concept of 'snapshot transitions'
This way of doing snapshots hasn't been used since 2011.
2014-02-14 17:45:53 -08:00
Brian Anderson
b11e73d0be mk: Add some serious documentation and 'make help'
'make help' is implemented in a fairly ridiculous way, using awk
to parse comments out of Makefile.in and displaying them.
2014-02-14 17:45:53 -08:00
bors
d365c3a6e6 auto merge of #12271 : kballard/rust/vim-extern-crate, r=huonw 2014-02-14 15:51:29 -08:00
Kevin Ballard
33b2b8a16f Add crate keyword to gedit language spec 2014-02-14 15:37:22 -08:00
Kevin Ballard
fff12220af Add crate to emacs and kate modefiles 2014-02-14 14:37:07 -08:00
bors
718c13fe3d auto merge of #12195 : kballard/rust/rustdoc-strip-impls-of-stripped, r=cmr
Strip trait impls for types that are stripped either due to the strip-hidden or strip-private passes.

This fixes the search index including trait methods on stripped structs (which breaks searching), and it also removes private types from the implementors list of a trait.

Fixes #9981 and #11439.
2014-02-14 13:36:35 -08:00
Alex Crichton
1bf1eeac6e Update restrictions on rustdoc source rendering
The std macros used to be injected with a filename of "<std-macros>", but macros
are now injected with a filename of "<{} macros>" where `{}` is filled in with
the crate name. This updates rustdoc to understand this new system so it'll
render source more frequently.
2014-02-14 13:11:36 -08:00