about summary refs log tree commit diff
path: root/src/libstd/macros.rs
AgeCommit message (Collapse)AuthorLines
2014-02-20Mass rename if_ok! to try!Alex Crichton-1/+1
This "bubble up an error" macro was originally named if_ok! in order to get it landed, but after the fact it was discovered that this name is not exactly desirable. The name `if_ok!` isn't immediately clear that is has much to do with error handling, and it doesn't look fantastic in all contexts (if if_ok!(...) {}). In general, the agreed opinion about `if_ok!` is that is came in as subpar. The name `try!` is more invocative of error handling, it's shorter by 2 letters, and it looks fitting in almost all circumstances. One concern about the word `try!` is that it's too invocative of exceptions, but the belief is that this will be overcome with documentation and examples. Close #12037
2014-02-19rustdoc: Handle links to reexported itemsAlex Crichton-2/+5
When building up our path cache, we don't plaster over a path which was previously inserted if we're inserting a non-public-item thing. Closes #11678
2014-02-19rustdoc: Show macros in documentationAlex Crichton-0/+172
Any macro tagged with #[macro_export] will be showed in the documentation for that module. This also documents all the existing macros inside of std::macros. Closes #3163 cc #5605 Closes #9954
2014-02-13Lift $dst outside the closure in write!Alex Crichton-6/+8
If you were writing to something along the lines of `self.foo` then with the new closure rules it meant that you were borrowing `self` for the entirety of the closure, meaning that you couldn't format other fields of `self` at the same time as writing to a buffer contained in `self`. By lifting the borrow outside of the closure the borrow checker can better understand that you're only borrowing one of the fields at a time. This had to use type ascription as well in order to preserve trait object coercions.
2014-02-08Clean up formatting in macros moduleBrendan Zabarauskas-58/+74
2014-02-08Add unimplemented! macroBrendan Zabarauskas-0/+7
2014-02-06Remove std::conditionAlex Crichton-44/+0
This has been a long time coming. Conditions in rust were initially envisioned as being a good alternative to error code return pattern. The idea is that all errors are fatal-by-default, and you can opt-in to handling the error by registering an error handler. While sounding nice, conditions ended up having some unforseen shortcomings: * Actually handling an error has some very awkward syntax: let mut result = None; let mut answer = None; io::io_error::cond.trap(|e| { result = Some(e) }).inside(|| { answer = Some(some_io_operation()); }); match result { Some(err) => { /* hit an I/O error */ } None => { let answer = answer.unwrap(); /* deal with the result of I/O */ } } This pattern can certainly use functions like io::result, but at its core actually handling conditions is fairly difficult * The "zero value" of a function is often confusing. One of the main ideas behind using conditions was to change the signature of I/O functions. Instead of read_be_u32() returning a result, it returned a u32. Errors were notified via a condition, and if you caught the condition you understood that the "zero value" returned is actually a garbage value. These zero values are often difficult to understand, however. One case of this is the read_bytes() function. The function takes an integer length of the amount of bytes to read, and returns an array of that size. The array may actually be shorter, however, if an error occurred. Another case is fs::stat(). The theoretical "zero value" is a blank stat struct, but it's a little awkward to create and return a zero'd out stat struct on a call to stat(). In general, the return value of functions that can raise error are much more natural when using a Result as opposed to an always-usable zero-value. * Conditions impose a necessary runtime requirement on *all* I/O. In theory I/O is as simple as calling read() and write(), but using conditions imposed the restriction that a rust local task was required if you wanted to catch errors with I/O. While certainly an surmountable difficulty, this was always a bit of a thorn in the side of conditions. * Functions raising conditions are not always clear that they are raising conditions. This suffers a similar problem to exceptions where you don't actually know whether a function raises a condition or not. The documentation likely explains, but if someone retroactively adds a condition to a function there's nothing forcing upstream users to acknowledge a new point of task failure. * Libaries using I/O are not guaranteed to correctly raise on conditions when an error occurs. In developing various I/O libraries, it's much easier to just return `None` from a read rather than raising an error. The silent contract of "don't raise on EOF" was a little difficult to understand and threw a wrench into the answer of the question "when do I raise a condition?" Many of these difficulties can be overcome through documentation, examples, and general practice. In the end, all of these difficulties added together ended up being too overwhelming and improving various aspects didn't end up helping that much. A result-based I/O error handling strategy also has shortcomings, but the cognitive burden is much smaller. The tooling necessary to make this strategy as usable as conditions were is much smaller than the tooling necessary for conditions. Perhaps conditions may manifest themselves as a future entity, but for now we're going to remove them from the standard library. Closes #9795 Closes #8968
2014-02-03std: Remove io::io_errorAlex Crichton-0/+5
* All I/O now returns IoResult<T> = Result<T, IoError> * All formatting traits now return fmt::Result = IoResult<()> * The if_ok!() macro was added to libstd
2014-01-27std: add begin_unwind_fmt that reduces codesize for formatted fail!().Huon Wilson-2/+12
This ends up saving a single `call` instruction in the optimised code, but saves a few hundred lines of non-optimised IR for `fn main() { fail!("foo {}", "bar"); }` (comparing against the minimal generic baseline from the parent commit).
2014-01-24Delete ignore! macroSteven Fackler-3/+0
This was a holdover from when we didn't allow nested comment blocks (think #if 0). It isn't used anywhere.
2014-01-24Move macro_rules! macros to libstdSteven Fackler-0/+192
They all have to go into a single module at the moment unfortunately. Ideally, the logging macros would live in std::logging, condition! would live in std::condition, format! in std::fmt, etc. However, this introduces cyclic dependencies between those modules and the macros they use which the current expansion system can't deal with. We may be able to get around this by changing the expansion phase to a two-pass system but that's for a later PR. Closes #2247 cc #11763
2013-10-11De-pub some private runtime componentsAlex Crichton-44/+0
This change was waiting for privacy to get sorted out, which should be true now that #8215 has landed. Closes #4427
2013-10-10auto merge of #9749 : alexcrichton/rust/less-io, r=brsonbors-1/+1
This implements a number of the baby steps needed to start eliminating everything inside of `std::io`. It turns out that there are a *lot* of users of that module, so I'm going to try to tackle them separately instead of bringing down the whole system all at once. This pull implements a large amount of unimplemented functionality inside of `std::rt::io` including: * Native file I/O (file descriptors, *FILE) * Native stdio (through the native file descriptors) * Native processes (extracted from `std::run`) I also found that there are a number of users of `std::io` which desire to read an input line-by-line, so I added an implementation of `read_until` and `read_line` to `BufferedReader`. With all of these changes in place, I started to axe various usages of `std::io`. There's a lot of one-off uses here-and-there, but the major use-case remaining that doesn't have a fantastic solution is `extra::json`. I ran into a few compiler bugs when attempting to remove that, so I figured I'd come back to it later instead. There is one fairly major change in this pull, and it's moving from native stdio to uv stdio via `print` and `println`. Unfortunately logging still goes through native I/O (via `dumb_println`). This is going to need some thinking, because I still want the goal of logging/printing to be 0 allocations, and this is not possible if `io::stdio::stderr()` is called on each log message. Instead I think that this may need to be cached as the `logger` field inside the `Task` struct, but that will require a little more workings to get right (this is also a similar problem for print/println, do we cache `stdout()` to not have to re-create it every time?).
2013-10-10Migrate users of io::fd_t to io::native::file::fd_tAlex Crichton-1/+1
2013-10-09Don't abort if the runtime is run twice.Alex Crichton-38/+0
This changes an `assert_once_ever!` assertion to just a plain old assertion around an atomic boolean to ensure that one particular runtime doesn't attempt to exit twice. Closes #9739
2013-09-30std: Remove usage of fmt!Alex Crichton-9/+10
2013-09-20Implement a web backend for rustdoc_ngAlex Crichton-0/+1
This large commit implements and `html` output option for rustdoc_ng. The executable has been altered to be invoked as "rustdoc_ng html <crate>" and it will dump everything into the local "doc" directory. JSON can still be generated by changing 'html' to 'json'. This also fixes a number of bugs in rustdoc_ng relating to comment stripping, along with some other various issues that I found along the way. The `make doc` command has been altered to generate the new documentation into the `doc/ng/$(CRATE)` directories.
2013-08-23Define cfg(rtopt) when optimizing. Turn off runtime sanity checksBrian Anderson-2/+4
Naturally, and sadly, turning off sanity checks in the runtime is a noticable performance win. The particular test I'm running goes from ~1.5 s to ~1.3s. Sanity checks are turned *on* when not optimizing, or when cfg includes `rtdebug` or `rtassert`.
2013-08-20Add assert_once_ever macro. Close #7748. (fixme cf #8472)Ben Blum-0/+36
2013-08-09Remove rtdebug_! and make rtdebug! work properly.Corey Richardson-12/+4
It now actually does logging, and is compiled out when `--cfg rtdebug` is not given to the libstd build, which it isn't by default. This makes the rt benchmarks 18-50% faster.
2013-08-01A major refactoring that changes the way the runtime uses TLS. In thetoddaaro-2/+7
old design the TLS held the scheduler struct, and the scheduler struct held the active task. This posed all sorts of weird problems due to how we wanted to use the contents of TLS. The cleaner approach is to leave the active task in TLS and have the task hold the scheduler. To make this work out the scheduler has to run inside a regular task, and then once that is the case the context switching code is massively simplified, as instead of three possible paths there is only one. The logical flow is also easier to follow, as the scheduler struct acts somewhat like a "token" indicating what is active. These changes also necessitated changing a large number of runtime tests, and rewriting most of the runtime testing helpers. Polish level is "low", as I will very soon start on more scheduler changes that will require wiping the polish off. That being said there should be sufficient comments around anything complex to make this entirely respectable as a standalone commit.
2013-06-18std::rt: Improve the rtabort! macroBrian Anderson-11/+8
2013-06-17std: Rename `abort!` to `rtabort!` to match other macrosBrian Anderson-2/+2
2013-06-17std::rt: move abort function to util moduleBrian Anderson-9/+1
2013-06-16Merge remote-tracking branch 'brson/io'Brian Anderson-8/+11
Conflicts: src/libstd/rt/comm.rs src/libstd/rt/mod.rs src/libstd/rt/sched.rs src/libstd/rt/task.rs src/libstd/rt/test.rs src/libstd/rt/tube.rs src/libstd/rt/uv/uvio.rs src/libstd/rt/uvio.rs src/libstd/task/spawn.rs
2013-06-14redesigned the pinning to pin deal with things on dequeue, not on enqueuetoddaaro-11/+0
2013-06-10debugged a compiler ICE when merging local::borrow changes into the main io ↵toddaaro-6/+19
branch and modified the incoming new file lang.rs to be api-compatible
2013-05-22libstd: Rename libcore to libstd and libstd to libextra; update makefiles.Patrick Walton-0/+53
This only changes the directory names; it does not change the "real" metadata names.