Commit Graph

25692 Commits

Author SHA1 Message Date
Trent Ogren
e1e7ddc494 Fix typo in tutorial 2014-01-23 10:43:48 -06:00
bors
657e353022 auto merge of #11739 : thestinger/rust/rm-old-ext, r=alexcrichton 2014-01-23 05:56:30 -08:00
bors
7cabd40320 auto merge of #11737 : alexcrichton/rust/issue-11729, r=thestinger
Closes #11729
2014-01-23 03:51:29 -08:00
bors
aa9cf4cf8d auto merge of #11701 : FeGs/rust/stray-debug-in-metadata, r=alexcrichton
When there is `println!` macro in the code, compiling is never end.

```rust
// print.rs
fn main() {
  println!("Hello!");
}
```

```bash
$ RUST_LOG=rustc rustc print.rs
```

And this is a part of output from stderr.

```bash
# ...
Looking up syntax::ast::DefId{crate: 1u32, node: 176234u32}
looking up syntax::ast::DefId{crate: 1u32, node: 176235u32} : extra::ebml::Doc<>{data: &[168u8, 16u8, 0u8, 0u8, 16u8, 51u8, 101u8, 53u8, 97u8, 101u8, 98u8, 56u8, 51u8, 55u8, 97u8, 101u8, 49u8, 54u8, 50u8
# ...
# vector which has infinite length.
```

* note : rust 0.9, 0.10-pre
2014-01-23 01:31:39 -08:00
bors
19e0cbe420 auto merge of #11682 : thestinger/rust/vector, r=brson
This is just an initial implementation and does not yet fully replace `~[T]`. A generic initialization syntax for containers is missing, and the slice functionality needs to be reworked to make auto-slicing unnecessary.

Traits for supporting indexing properly are also required. This also needs to be fixed to make ring buffers as easy to use as vectors.

The tests and documentation for `~[T]` can be ported over to this type when it is removed. I don't really expect DST to happen for vectors as having both `~[T]` and `Vec<T>` is overcomplicated and changing the slice representation to 3 words is not at all appealing. Unlike with traits, it's possible (and easy) to implement `RcSlice<T>` and `GcSlice<T>` without compiler help.
2014-01-22 23:26:33 -08:00
bors
52ba3b6414 auto merge of #11611 : SiegeLord/rust/exp_printing, r=alexcrichton
Fixes #6593

Currently, Rust provides no way to print very large or very small floating point values which come up routinely in scientific and modeling work. The classical solution to this is to use the scientific/exponential notation, which not-coincidentally, corresponds to how floating point values are encoded in memory. Given this, there are two solutions to the problem. One is what, as far as I understand it, Python does. I.e. for floating point numbers in a certain range it does what we do today with the `'f'` formatting flag, otherwise it switches to exponential notation. The other way is to provide a set of formatting flags to explicitly choose the exponential notation, like it is done in C. I've chosen the second way as I think its important to provide that kind of control to the user.

This pull request changes the `std::num::strconv::float_to_str_common` function to optionally format floating point numbers using the exponential (scientific) notation. The base of the significant can be varied between 2 and 25, while the base of the exponent can be 2 or 10.

Additionally this adds two new formatting specifiers to `format!` and friends: `'e'` and `'E'` which switch between outputs like `1.0e5` and `1.0E5`. Mostly parroting C stdlib in this sense, although I wasn't going for an exact output match.
2014-01-22 22:01:40 -08:00
bors
7ea063ea0f auto merge of #11294 : alexcrichton/rust/native-timer, r=brson
Commit messages have the fun details

Closes #10925
2014-01-22 20:41:29 -08:00
Daniel Micay
b2ec71fc27 hashmap: port to Vec<T> 2014-01-22 23:13:57 -05:00
Daniel Micay
1798de7d08 add new vector representation as a library 2014-01-22 23:13:57 -05:00
Daniel Micay
17d23b8c17 vec: make unsafe indexing functions higher-level 2014-01-22 23:13:57 -05:00
Daniel Micay
802d41fe23 libc: switch free to the proper signature
This does not attempt to fully propagate the mutability everywhere, but
gives new code a hint to avoid the same issues.
2014-01-22 23:13:53 -05:00
Alex Crichton
b8e43838cf Implement native timers
Native timers are a much hairier thing to deal with than green timers due to the
interface that we would like to expose (both a blocking sleep() and a
channel-based interface). I ended up implementing timers in three different ways
for the various platforms that we supports.

In all three of the implementations, there is a worker thread which does send()s
on channels for timers. This worker thread is initialized once and then
communicated to in a platform-specific manner, but there's always a shared
channel available for sending messages to the worker thread.

* Windows - I decided to use windows kernel timer objects via
  CreateWaitableTimer and SetWaitableTimer in order to provide sleeping
  capabilities. The worker thread blocks via WaitForMultipleObjects where one of
  the objects is an event that is used to wake up the helper thread (which then
  drains the incoming message channel for requests).

* Linux/(Android?) - These have the ideal interface for implementing timers,
  timerfd_create. Each timer corresponds to a timerfd, and the helper thread
  uses epoll to wait for all active timers and then send() for the next one that
  wakes up. The tricky part in this implementation is updating a timerfd, but
  see the implementation for the fun details

* OSX/FreeBSD - These obviously don't have the windows APIs, and sadly don't
  have the timerfd api available to them, so I have thrown together a solution
  which uses select() plus a timeout in order to ad-hoc-ly implement a timer
  solution for threads. The implementation is backed by a sorted array of timers
  which need to fire. As I said, this is an ad-hoc solution which is certainly
  not accurate timing-wise. I have done this implementation due to the lack of
  other primitives to provide an implementation, and I've done it the best that
  I could, but I'm sure that there's room for improvement.

I'm pretty happy with how these implementations turned out. In theory we could
drop the timerfd implementation and have linux use the select() + timeout
implementation, but it's so inaccurate that I would much rather continue to use
timerfd rather than my ad-hoc select() implementation.

The only change that I would make to the API in general is to have a generic
sleep() method on an IoFactory which doesn't require allocating a Timer object.
For everything but windows it's super-cheap to request a blocking sleep for a
set amount of time, and it's probably worth it to provide a sleep() which
doesn't do something like allocate a file descriptor on linux.
2014-01-22 19:31:39 -08:00
Daniel Micay
a2dab3c46e remove old rc extension from detection files 2014-01-22 20:39:32 -05:00
SiegeLord
acd718b378 Remove the initial and trailing blank doc-comment lines 2014-01-22 20:32:40 -05:00
SiegeLord
c13e0de836 Add some tests for the exponential notation 2014-01-22 20:32:40 -05:00
SiegeLord
25b107f1e3 Add LowerExp 'e' and UpperExp 'E' format traits/specifiers 2014-01-22 20:32:40 -05:00
SiegeLord
2b4bd0780b float_to_str_bytes_common can now handle exponential notation 2014-01-22 20:32:40 -05:00
Alex Crichton
8edf57ee42 Don't fatally fail in driver::early_error
Closes #11729
2014-01-22 15:48:55 -08:00
Alex Crichton
530909f2d8 Implement std::rt::at_exit
This routine is currently only used to clean up the timer helper thread in the
libnative implementation, but there are possibly other uses for this.

The documentation is clear that the procedures are *not* run with any task
context and hence have very little available to them. I also opted to disallow
at_exit inside of at_exit and just abort the process at that point.
2014-01-22 15:15:28 -08:00
Ben Striegel
fce792249e Typo in module tutorial 2014-01-22 16:03:00 -05:00
bors
aedf567a95 auto merge of #10943 : fhahn/rust/issue-7313-replace-c-types, r=alexcrichton
I've started working on a patch for #7313 . So far I tried to replace C types in `src/libstd/unstable/*` and related files.

So far, I have two questions. Is there a convention for passing pointers around in `std` as Rust types? Sometimes pointers are passed around as `*c_char` (which seems to be an `*i8`), `*c_void` or `*u8`, which leads to a lot of casts. E.g: [`exchange_malloc`](https://github.com/fhahn/rust/compare/issue-7313-replace-c-types?expand=1#diff-39f44b8c3f4496abab854b3425ac1617R60) used to return a `*c_char` but the function in turn only calls `malloc_raw` which returns a `*c_void`.
Is there a specific reason for this?

The second question is about `CString` and related functions like `with_c_str`. At the moment these functions use `*c_char*`. Should I replace it with `*u8` or keep it, because it's an wrapper around classical C strings?
2014-01-22 11:06:24 -08:00
Florian Hahn
2eb4f05850 Replace C types with Rust types in libstd, closes #7313 2014-01-22 19:20:47 +01:00
bors
de50c56a5c auto merge of #11727 : sanxiyn/rust/trailing-comma, r=alexcrichton
Fix #6506.
Fix #7358.
2014-01-22 09:21:25 -08:00
Seo Sanghyeon
7689353918 Allow trailing commas in argument lists and tuple patterns 2014-01-23 01:55:53 +09:00
Hong Chulju
86b0564f73 rustc/metadata: Removed stray debug statements 2014-01-22 19:38:20 +09:00
bors
750d48b0ad auto merge of #11711 : alexcrichton/rust/issue-11683, r=brson
There's lots of fun rationale in the comments of the diff.

Closes #11683
2014-01-22 00:51:20 -08:00
bors
47660f74fc auto merge of #11719 : brson/rust/bleh, r=alexcrichton 2014-01-21 22:06:20 -08:00
Brian Anderson
045716a6e9 xfail another external macro test on android 2014-01-21 21:52:35 -08:00
bors
f8477c9da5 auto merge of #11500 : jhasse/rust/patch-rlib, r=alexcrichton
Currently `rustpkg` only looks for shared libraries. After this patch it also looks for `*.rlib` files.
2014-01-21 17:26:14 -08:00
bors
918a7314a8 auto merge of #11129 : SimonSapin/rust/foo-vs-foo_opt, r=alexcrichton
[On 2013-12-06, I wrote to the rust-dev mailing list](https://mail.mozilla.org/pipermail/rust-dev/2013-December/007263.html):

> Subject: Let’s avoid having both foo() and foo_opt()
>
> We have some functions and methods such as [std::str::from_utf8](http://static.rust-lang.org/doc/master/std/str/fn.from_utf8.html) that may succeed and give a result, or fail when the input is invalid.
>
> 1. Sometimes we assume the input is valid and don’t want to deal with the error case. Task failure works nicely.
>
> 2. Sometimes we do want to do something different on invalid input, so returning an `Option<T>` works best.
>
> And so we end up with both `from_utf8` and `from_utf8`. This particular case is worse because we also have `from_utf8_owned` and `from_utf8_owned_opt`, to cover everything.
>
> Multiplying names like this is just not good design. I’d like to reduce this pattern.
>
> Getting behavior 1. when you have 2. is easy: just call `.unwrap()` on the Option. I think we should rename every `foo_opt()` function or method to just `foo`, remove the old `foo()` behavior, and tell people (through documentation) to use `foo().unwrap()` if they want it back?
>
> The downsides are that unwrap is more verbose and gives less helpful error messages on task failure. But I think it’s worth it.


The email discussion has gone around long enough. Let’s discuss a concrete proposal. For the following functions or methods, I removed `foo` (that caused task failure) and renamed `foo_opt` (that returns `Option`) to just `foo`.

Vector methods:

* `get_opt` (rename only, `get` did not exist as it would have been just `[]`)
* `head_opt`
* `last_opt`
* `pop_opt`
* `shift_opt`
* `remove_opt`

`std::path::BytesContainer` method:

* `container_as_str_opt`

`std::str` functions:

* `from_utf8_opt`
* `from_utf8_owned_opt` (also remove the now unused `not_utf8` condition)

Is there something else that should recieve the same treatement?

I did not rename `recv_opt` on channels based on @brson’s [feedback](https://mail.mozilla.org/pipermail/rust-dev/2013-December/007270.html).

Feel free to pick only some of these commits.
2014-01-21 15:56:16 -08:00
Simon Sapin
ec422d70c3 [std::str] Remove the now unused not_utf8 condition. 2014-01-21 15:48:48 -08:00
Simon Sapin
05ae134ace [std::str] Rename from_utf8_owned_opt() to from_utf8_owned(), drop the old from_utf8_owned() behavior 2014-01-21 15:48:48 -08:00
Simon Sapin
b8c4149293 [std::str] Rename from_utf8_opt() to from_utf8(), drop the old from_utf8() behavior 2014-01-21 15:48:48 -08:00
Simon Sapin
46b01647ba [std::path] Rename .container_as_str_opt() to .container_as_str(), drop the old .container_as_str() behavior 2014-01-21 15:48:47 -08:00
Simon Sapin
e75d0a9b7e [std::vec] Rename .remove_opt() to .remove(), drop the old .remove() behavior 2014-01-21 15:48:47 -08:00
Simon Sapin
b5e65731c0 [std::vec] Rename .shift_opt() to .shift(), drop the old .shift() behavior 2014-01-21 15:48:47 -08:00
Simon Sapin
bada25e425 [std::vec] Rename .pop_opt() to .pop(), drop the old .pop() behavior 2014-01-21 15:48:47 -08:00
Simon Sapin
aa66b91767 [std::vec] Rename .last_opt() to .last(), drop the old .last() behavior 2014-01-21 15:48:46 -08:00
Simon Sapin
add8f9680e [std::vec] Rename .head_opt() to .head(), drop the old .head() behavior 2014-01-21 11:45:08 -08:00
Simon Sapin
d25334d63a [std::vec] Rename .get_opt() to .get() 2014-01-21 11:44:13 -08:00
bors
505572b3f8 auto merge of #11700 : bharrisau/rust/thumb, r=alexcrichton
To build for the cortex-M series ARM processors LLC needs to be told to build for the thumb instruction set. There are two ways to do this, either with the triple "thumb\*-\*-\*" or with -march=thumb (which just overrides the triple anyway). I chose the first way.

The following will fail because the local cc doesn't know what to do with -mthumb.
````
rustc test.rs --lib --target thumb-linux-eab
error: linking with `cc` failed: exit code: 1
note: cc: error: unrecognized command line option ‘-mthumb’
````

Changing the linker works as expected.
````
rustc test.rs --lib --target thumb-linux-eabi --linker arm-none-eabi-gcc
````

Ideally I'd have the triple thumb-none-eabi, but adding a new OS looks like much more work (and I'm not familiar enough with what it does to know if it is needed).
2014-01-21 11:26:13 -08:00
bors
232d8e5605 auto merge of #11665 : alexcrichton/rust/zed-cleanup, r=brson
* Stop using hardcoded numbers that have to all get updated when something changes (inevitable errors and rebase conflicts) as well as removes some unneeded -Z options (obsoleted over time).
* Remove `std::rt::borrowck`
2014-01-21 10:06:18 -08:00
Alex Crichton
d84c3369f7 Remove no-debug-borrows from the makefiles 2014-01-21 10:02:48 -08:00
Alex Crichton
254e35c268 Capitalize debugging opts and make them u64 2014-01-21 09:23:56 -08:00
Alex Crichton
a8807771b2 Purge borrowck from libstd
This hasn't been in use since `@mut` was removed
2014-01-21 09:23:56 -08:00
Alex Crichton
57f8073b5e Remove obsoleted -Z options
* borrowck_note_pure - unused
* borrowck_note_loan - unused
* no_debug_borrows - unused
* lint_llvm - equivalent to -Z no-prepopulate-passes + --llvm-passes lint
2014-01-21 09:23:56 -08:00
Alex Crichton
eca980be57 Stop using hardcoded numbers for -Z options
Instead use a macro and generate them!
2014-01-21 09:23:54 -08:00
Alex Crichton
12c5fc5877 Flag all TLS functions as inline(never)
There's lots of fun rationale in the comments of the diff.

Closes #11683
2014-01-21 08:19:35 -08:00
bors
43cffe9d71 auto merge of #11663 : huonw/rust/paren-lint, r=cmr
The parens in `if (true) {}` are not necessary, so we'll warn about them.

cc #3070 and #11432
2014-01-21 04:26:15 -08:00
Huon Wilson
39713b8295 Remove unnecessary parentheses. 2014-01-21 22:00:18 +11:00