1. 27 6月, 2014 1 次提交
    • A
      rustrt: Reorganize task usage · 7d756e44
      Alex Crichton 提交于
      Most of the comments are available on the Task structure itself, but this commit
      is aimed at making FFI-style usage of Rust tasks a little nicer.
      
      Primarily, this commit enables re-use of tasks across multiple invocations. The
      method `run` will no longer unconditionally destroy the task itself. Rather, the
      task will be internally re-usable if the closure specified did not fail. Once a
      task has failed once it is considered poisoned and it can never be used again.
      
      Along the way I tried to document shortcomings of the current method of tearing
      down a task, opening a few issues as well. For now none of the behavior is a
      showstopper, but it's useful to acknowledge it. Also along the way I attempted
      to remove as much `unsafe` code as possible, opting for safer abstractions.
      7d756e44
  2. 16 6月, 2014 1 次提交
  3. 15 6月, 2014 1 次提交
    • A
      rustc: Obsolete the `@` syntax entirely · ade807c6
      Alex Crichton 提交于
      This removes all remnants of `@` pointers from rustc. Additionally, this removes
      the `GC` structure from the prelude as it seems odd exporting an experimental
      type in the prelude by default.
      
      Closes #14193
      [breaking-change]
      ade807c6
  4. 10 6月, 2014 1 次提交
  5. 07 6月, 2014 2 次提交
    • A
      libs: Fix miscellaneous fallout of librustrt · 75014f7b
      Alex Crichton 提交于
      75014f7b
    • A
      std: Extract librustrt out of libstd · 5ec36c35
      Alex Crichton 提交于
      As part of the libstd facade efforts, this commit extracts the runtime interface
      out of the standard library into a standalone crate, librustrt. This crate will
      provide the following services:
      
      * Definition of the rtio interface
      * Definition of the Runtime interface
      * Implementation of the Task structure
      * Implementation of task-local-data
      * Implementation of task failure via unwinding via libunwind
      * Implementation of runtime initialization and shutdown
      * Implementation of thread-local-storage for the local rust Task
      
      Notably, this crate avoids the following services:
      
      * Thread creation and destruction. The crate does not require the knowledge of
        an OS threading system, and as a result it seemed best to leave out the
        `rt::thread` module from librustrt. The librustrt module does depend on
        mutexes, however.
      * Implementation of backtraces. There is no inherent requirement for the runtime
        to be able to generate backtraces. As will be discussed later, this
        functionality continues to live in libstd rather than librustrt.
      
      As usual, a number of architectural changes were required to make this crate
      possible. Users of "stable" functionality will not be impacted by this change,
      but users of the `std::rt` module will likely note the changes. A list of
      architectural changes made is:
      
      * The stdout/stderr handles no longer live directly inside of the `Task`
        structure. This is a consequence of librustrt not knowing about `std::io`.
        These two handles are now stored inside of task-local-data.
      
        The handles were originally stored inside of the `Task` for perf reasons, and
        TLD is not currently as fast as it could be. For comparison, 100k prints goes
        from 59ms to 68ms (a 15% slowdown). This appeared to me to be an acceptable
        perf loss for the successful extraction of a librustrt crate.
      
      * The `rtio` module was forced to duplicate more functionality of `std::io`. As
        the module no longer depends on `std::io`, `rtio` now defines structures such
        as socket addresses, addrinfo fiddly bits, etc. The primary change made was
        that `rtio` now defines its own `IoError` type. This type is distinct from
        `std::io::IoError` in that it does not have an enum for what error occurred,
        but rather a platform-specific error code.
      
        The native and green libraries will be updated in later commits for this
        change, and the bulk of this effort was put behind updating the two libraries
        for this change (with `rtio`).
      
      * Printing a message on task failure (along with the backtrace) continues to
        live in libstd, not in librustrt. This is a consequence of the above decision
        to move the stdout/stderr handles to TLD rather than inside the `Task` itself.
        The unwinding API now supports registration of global callback functions which
        will be invoked when a task fails, allowing for libstd to register a function
        to print a message and a backtrace.
      
        The API for registering a callback is experimental and unsafe, as the
        ramifications of running code on unwinding is pretty hairy.
      
      * The `std::unstable::mutex` module has moved to `std::rt::mutex`.
      
      * The `std::unstable::sync` module has been moved to `std::rt::exclusive` and
        the type has been rewritten to not internally have an Arc and to have an RAII
        guard structure when locking. Old code should stop using `Exclusive` in favor
        of the primitives in `libsync`, but if necessary, old code should port to
        `Arc<Exclusive<T>>`.
      
      * The local heap has been stripped down to have fewer debugging options. None of
        these were tested, and none of these have been used in a very long time.
      
      [breaking-change]
      5ec36c35
  6. 28 5月, 2014 1 次提交
  7. 25 5月, 2014 1 次提交
  8. 24 5月, 2014 1 次提交
  9. 23 5月, 2014 1 次提交
  10. 20 5月, 2014 1 次提交
  11. 14 5月, 2014 1 次提交
    • A
      std: Move the owned module from core to std · cbc31df4
      Alex Crichton 提交于
      The compiler was updated to recognize that implementations for ty_uniq(..) are
      allowed if the Box lang item is located in the current crate. This enforces the
      idea that libcore cannot allocated, and moves all related trait implementations
      from libcore to libstd.
      
      This is a breaking change in that the AnyOwnExt trait has moved from the any
      module to the owned module. Any previous users of std::any::AnyOwnExt should now
      use std::owned::AnyOwnExt instead. This was done because the trait is intended
      for Box traits and only Box traits.
      
      [breaking-change]
      cbc31df4
  12. 11 5月, 2014 1 次提交
    • A
      core: Remove the cast module · f94d671b
      Alex Crichton 提交于
      This commit revisits the `cast` module in libcore and libstd, and scrutinizes
      all functions inside of it. The result was to remove the `cast` module entirely,
      folding all functionality into the `mem` module. Specifically, this is the fate
      of each function in the `cast` module.
      
      * transmute - This function was moved to `mem`, but it is now marked as
                    #[unstable]. This is due to planned changes to the `transmute`
                    function and how it can be invoked (see the #[unstable] comment).
                    For more information, see RFC 5 and #12898
      
      * transmute_copy - This function was moved to `mem`, with clarification that is
                         is not an error to invoke it with T/U that are different
                         sizes, but rather that it is strongly discouraged. This
                         function is now #[stable]
      
      * forget - This function was moved to `mem` and marked #[stable]
      
      * bump_box_refcount - This function was removed due to the deprecation of
                            managed boxes as well as its questionable utility.
      
      * transmute_mut - This function was previously deprecated, and removed as part
                        of this commit.
      
      * transmute_mut_unsafe - This function doesn't serve much of a purpose when it
                               can be achieved with an `as` in safe code, so it was
                               removed.
      
      * transmute_lifetime - This function was removed because it is likely a strong
                             indication that code is incorrect in the first place.
      
      * transmute_mut_lifetime - This function was removed for the same reasons as
                                 `transmute_lifetime`
      
      * copy_lifetime - This function was moved to `mem`, but it is marked
                        `#[unstable]` now due to the likelihood of being removed in
                        the future if it is found to not be very useful.
      
      * copy_mut_lifetime - This function was also moved to `mem`, but had the same
                            treatment as `copy_lifetime`.
      
      * copy_lifetime_vec - This function was removed because it is not used today,
                            and its existence is not necessary with DST
                            (copy_lifetime will suffice).
      
      In summary, the cast module was stripped down to these functions, and then the
      functions were moved to the `mem` module.
      
          transmute - #[unstable]
          transmute_copy - #[stable]
          forget - #[stable]
          copy_lifetime - #[unstable]
          copy_mut_lifetime - #[unstable]
      
      [breaking-change]
      f94d671b
  13. 08 5月, 2014 2 次提交
    • A
      std: Modernize the local_data api · ab92ea52
      Alex Crichton 提交于
      This commit brings the local_data api up to modern rust standards with a few key
      improvements:
      
      * The `pop` and `set` methods have been combined into one method, `replace`
      
      * The `get_mut` method has been removed. All interior mutability should be done
        through `RefCell`.
      
      * All functionality is now exposed as a method on the keys themselves. Instead
        of importing std::local_data, you now use "key.replace()" and "key.get()".
      
      * All closures have been removed in favor of RAII functionality. This means that
        get() and get_mut() no long require closures, but rather return
        Option<SmartPointer> where the smart pointer takes care of relinquishing the
        borrow and also implements the necessary Deref traits
      
      * The modify() function was removed to cut the local_data interface down to its
        bare essentials (similarly to how RefCell removed set/get).
      
      [breaking-change]
      ab92ea52
    • A
      std: Add I/O timeouts to networking objects · e27f27c8
      Alex Crichton 提交于
      These timeouts all follow the same pattern as established by the timeouts on
      acceptors. There are three methods: set_timeout, set_read_timeout, and
      set_write_timeout. Each of these sets a point in the future after which
      operations will time out.
      
      Timeouts with cloned objects are a little trickier. Each object is viewed as
      having its own timeout, unaffected by other objects' timeouts. Additionally,
      timeouts do not propagate when a stream is cloned or when a cloned stream has
      its timeouts modified.
      
      This commit is just the public interface which will be exposed for timeouts, the
      implementation will come in later commits.
      e27f27c8
  14. 07 5月, 2014 2 次提交
    • A
      core: Add unwrap()/unwrap_err() methods to Result · d4b5d82a
      Alex Crichton 提交于
      These implementations must live in libstd right now because the fmt module has
      not been migrated yet. This will occur in a later PR.
      
      Just to be clear, there are new extension traits, but they are not necessary
      once the std::fmt module has migrated to libcore, which is a planned migration
      in the future.
      d4b5d82a
    • P
      librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, except · 090040bf
      Patrick Walton 提交于
      for `~str`/`~[]`.
      
      Note that `~self` still remains, since I forgot to add support for
      `Box<self>` before the snapshot.
      
      How to update your code:
      
      * Instead of `~EXPR`, you should write `box EXPR`.
      
      * Instead of `~TYPE`, you should write `Box<Type>`.
      
      * Instead of `~PATTERN`, you should write `box PATTERN`.
      
      [breaking-change]
      090040bf
  15. 03 5月, 2014 1 次提交
  16. 24 4月, 2014 1 次提交
    • A
      std: Change Finally to take `&mut self` · b4ecbe93
      Alex Crichton 提交于
      As with the previous commits, the Finally trait is primarily implemented for
      closures, so the trait was modified from `&self` to `&mut self`. This will
      require that any closure variable invoked with `finally` to be stored in a
      mutable slot.
      
      [breaking-change]
      b4ecbe93
  17. 19 4月, 2014 1 次提交
  18. 16 4月, 2014 1 次提交
  19. 11 4月, 2014 1 次提交
    • A
      std: Make std::comm return types consistent · 545d4718
      Alex Crichton 提交于
      There are currently a number of return values from the std::comm methods, not
      all of which are necessarily completely expressive:
      
        Sender::try_send(t: T) -> bool
          This method currently doesn't transmit back the data `t` if the send fails
          due to the other end having disconnected. Additionally, this shares the name
          of the synchronous try_send method, but it differs in semantics in that it
          only has one failure case, not two (the buffer can never be full).
      
        SyncSender::try_send(t: T) -> TrySendResult<T>
          This method accurately conveys all possible information, but it uses a
          custom type to the std::comm module with no convenience methods on it.
          Additionally, if you want to inspect the result you're forced to import
          something from `std::comm`.
      
        SyncSender::send_opt(t: T) -> Option<T>
          This method uses Some(T) as an "error value" and None as a "success value",
          but almost all other uses of Option<T> have Some/None the other way
      
        Receiver::try_recv(t: T) -> TryRecvResult<T>
          Similarly to the synchronous try_send, this custom return type is lacking in
          terms of usability (no convenience methods).
      
      With this number of drawbacks in mind, I believed it was time to re-work the
      return types of these methods. The new API for the comm module is:
      
        Sender::send(t: T) -> ()
        Sender::send_opt(t: T) -> Result<(), T>
        SyncSender::send(t: T) -> ()
        SyncSender::send_opt(t: T) -> Result<(), T>
        SyncSender::try_send(t: T) -> Result<(), TrySendError<T>>
        Receiver::recv() -> T
        Receiver::recv_opt() -> Result<T, ()>
        Receiver::try_recv() -> Result<T, TryRecvError>
      
      The notable changes made are:
      
      * Sender::try_send => Sender::send_opt. This renaming brings the semantics in
        line with the SyncSender::send_opt method. An asychronous send only has one
        failure case, unlike the synchronous try_send method which has two failure
        cases (full/disconnected).
      
      * Sender::send_opt returns the data back to the caller if the send is guaranteed
        to fail. This method previously returned `bool`, but then it was unable to
        retrieve the data if the data was guaranteed to fail to send. There is still a
        race such that when `Ok(())` is returned the data could still fail to be
        received, but that's inherent to an asynchronous channel.
      
      * Result is now the basis of all return values. This not only adds lots of
        convenience methods to all return values for free, but it also means that you
        can inspect the return values with no extra imports (Ok/Err are in the
        prelude). Additionally, it's now self documenting when something failed or not
        because the return value has "Err" in the name.
      
      Things I'm a little uneasy about:
      
      * The methods send_opt and recv_opt are not returning options, but rather
        results. I felt more strongly that Option was the wrong return type than the
        _opt prefix was wrong, and I coudn't think of a much better name for these
        methods. One possible way to think about them is to read the _opt suffix as
        "optionally".
      
      * Result<T, ()> is often better expressed as Option<T>. This is only applicable
        to the recv_opt() method, but I thought it would be more consistent for
        everything to return Result rather than one method returning an Option.
      
      Despite my two reasons to feel uneasy, I feel much better about the consistency
      in return values at this point, and I think the only real open question is if
      there's a better suffix for {send,recv}_opt.
      
      Closes #11527
      545d4718
  20. 08 4月, 2014 1 次提交
  21. 01 4月, 2014 3 次提交
    • H
      rand: bubble up IO messages futher. · bc7a2d72
      Huon Wilson 提交于
      The various ...Rng::new() methods can hit IO errors from the OSRng they use,
      and it seems sensible to expose them at a higher level. Unfortunately, writing
      e.g. `StdRng::new().unwrap()` gives a much poorer error message than if it
      failed internally, but this is a problem with all `IoResult`s.
      bc7a2d72
    • A
      Switch some tuple structs to pub fields · 922dcfdc
      Alex Crichton 提交于
      This commit deals with the fallout of the previous change by making tuples
      structs have public fields where necessary (now that the fields are private by
      default).
      922dcfdc
    • A
      std: Switch field privacy as necessary · 9a3d04ae
      Alex Crichton 提交于
      9a3d04ae
  22. 28 3月, 2014 1 次提交
  23. 25 3月, 2014 1 次提交
    • A
      comm: Implement synchronous channels · 56cae9b3
      Alex Crichton 提交于
      This commit contains an implementation of synchronous, bounded channels for
      Rust. This is an implementation of the proposal made last January [1]. These
      channels are built on mutexes, and currently focus on a working implementation
      rather than speed. Receivers for sync channels have select() implemented for
      them, but there is currently no implementation of select() for sync senders.
      
      Rust will continue to provide both synchronous and asynchronous channels as part
      of the standard distribution, there is no intent to remove asynchronous
      channels. This flavor of channels is meant to provide an alternative to
      asynchronous channels because like green tasks, asynchronous channels are not
      appropriate for all situations.
      
      [1] - https://mail.mozilla.org/pipermail/rust-dev/2014-January/007924.html
      56cae9b3
  24. 24 3月, 2014 1 次提交
  25. 22 3月, 2014 1 次提交
  26. 16 3月, 2014 1 次提交
    • A
      log: Introduce liblog, the old std::logging · cc6ec8df
      Alex Crichton 提交于
      This commit moves all logging out of the standard library into an external
      crate. This crate is the new crate which is responsible for all logging macros
      and logging implementation. A few reasons for this change are:
      
      * The crate map has always been a bit of a code smell among rust programs. It
        has difficulty being loaded on almost all platforms, and it's used almost
        exclusively for logging and only logging. Removing the crate map is one of the
        end goals of this movement.
      
      * The compiler has a fair bit of special support for logging. It has the
        __log_level() expression as well as generating a global word per module
        specifying the log level. This is unfairly favoring the built-in logging
        system, and is much better done purely in libraries instead of the compiler
        itself.
      
      * Initialization of logging is much easier to do if there is no reliance on a
        magical crate map being available to set module log levels.
      
      * If the logging library can be written outside of the standard library, there's
        no reason that it shouldn't be. It's likely that we're not going to build the
        highest quality logging library of all time, so third-party libraries should
        be able to provide just as high-quality logging systems as the default one
        provided in the rust distribution.
      
      With a migration such as this, the change does not come for free. There are some
      subtle changes in the behavior of liblog vs the previous logging macros:
      
      * The core change of this migration is that there is no longer a physical
        log-level per module. This concept is still emulated (it is quite useful), but
        there is now only a global log level, not a local one. This global log level
        is a reflection of the maximum of all log levels specified. The previously
        generated logging code looked like:
      
          if specified_level <= __module_log_level() {
              println!(...)
          }
      
        The newly generated code looks like:
      
          if specified_level <= ::log::LOG_LEVEL {
              if ::log::module_enabled(module_path!()) {
                  println!(...)
              }
          }
      
        Notably, the first layer of checking is still intended to be "super fast" in
        that it's just a load of a global word and a compare. The second layer of
        checking is executed to determine if the current module does indeed have
        logging turned on.
      
        This means that if any module has a debug log level turned on, all modules
        with debug log levels get a little bit slower (they all do more expensive
        dynamic checks to determine if they're turned on or not).
      
        Semantically, this migration brings no change in this respect, but
        runtime-wise, this will have a perf impact on some code.
      
      * A `RUST_LOG=::help` directive will no longer print out a list of all modules
        that can be logged. This is because the crate map will no longer specify the
        log levels of all modules, so the list of modules is not known. Additionally,
        warnings can no longer be provided if a malformed logging directive was
        supplied.
      
      The new "hello world" for logging looks like:
      
          #[phase(syntax, link)]
          extern crate log;
      
          fn main() {
              debug!("Hello, world!");
          }
      cc6ec8df
  27. 14 3月, 2014 1 次提交
    • A
      std: Rename Chan/Port types and constructor · 78580651
      Alex Crichton 提交于
      * Chan<T> => Sender<T>
      * Port<T> => Receiver<T>
      * Chan::new() => channel()
      * constructor returns (Sender, Receiver) instead of (Receiver, Sender)
      * local variables named `port` renamed to `rx`
      * local variables named `chan` renamed to `tx`
      
      Closes #11765
      78580651
  28. 18 2月, 2014 1 次提交
  29. 14 2月, 2014 1 次提交
    • A
      Don't require an allocation for on_exit messages · 21a064d5
      Alex Crichton 提交于
      Instead, use an enum to allow running both a procedure and sending the task
      result over a channel. I expect the common case to be sending on a channel (e.g.
      task::try), so don't require an extra allocation in the common case.
      
      cc #11389
      21a064d5
  30. 12 2月, 2014 1 次提交
    • A
      Rewrite channels yet again for upgradeability · 0a6b9219
      Alex Crichton 提交于
      This, the Nth rewrite of channels, is not a rewrite of the core logic behind
      channels, but rather their API usage. In the past, we had the distinction
      between oneshot, stream, and shared channels, but the most recent rewrite
      dropped oneshots in favor of streams and shared channels.
      
      This distinction of stream vs shared has shown that it's not quite what we'd
      like either, and this moves the `std::comm` module in the direction of "one
      channel to rule them all". There now remains only one Chan and one Port.
      
      This new channel is actually a hybrid oneshot/stream/shared channel under the
      hood in order to optimize for the use cases in question. Additionally, this also
      reduces the cognitive burden of having to choose between a Chan or a SharedChan
      in an API.
      
      My simple benchmarks show no reduction in efficiency over the existing channels
      today, and a 3x improvement in the oneshot case. I sadly don't have a
      pre-last-rewrite compiler to test out the old old oneshots, but I would imagine
      that the performance is comparable, but slightly slower (due to atomic reference
      counting).
      
      This commit also brings the bonus bugfix to channels that the pending queue of
      messages are all dropped when a Port disappears rather then when both the Port
      and the Chan disappear.
      0a6b9219
  31. 08 2月, 2014 1 次提交
  32. 04 2月, 2014 2 次提交
    • A
      std: Remove try_send_deferred plus all fallout · b49771e3
      Alex Crichton 提交于
      Now that extra::sync primitives are built on a proper mutex instead of a
      pthreads one, there's no longer any use for this function.
      b49771e3
    • A
      std: Remove io::io_error · ece8a8f5
      Alex Crichton 提交于
      * 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
      ece8a8f5
  33. 30 1月, 2014 2 次提交