rust/src
Mazdak Farrokhzad 4dcb7af0e7
Rollup merge of #58454 - pitdicker:windows_stdio, r=alexcrichton
Refactor Windows stdio and remove stdin double buffering

I was looking for something nice and small to work on, tried to tackle a few FIXME's in Windows stdio, and things grew from there.

This part of the standard library contains some tricky code, and has changed over the years to handle more corner cases. It could use some refactoring and extra comments.

Changes/fixes:
- Made `StderrRaw` `pub(crate)`, to remove the `Write` implementations on `sys::Stderr` (used unsynchronised for panic output).
- Remove the unused `Read` implementation on `sys::windows::stdin`
- The `windows::stdio::Output` enum made sense when we cached the handles, but we can use simple functions like `is_console` now that we get the handle on every read/write
- `write` can now calculate the number of written bytes as UTF-8 when we can't write all `u16`s.
- If `write` could only write one half of a surrogate pair, attempt another write for the other because user code can't reslice in any way that would allow us to write it otherwise.
- Removed the double buffering on stdin. Documentation on the unexposed `StdinRaw` says: 'This handle is not synchronized or buffered in any fashion'; which is now true.
- `sys::windows::Stdin` now always only partially fills its buffer, so we can guarantee any arbitrary UTF-16 can be re-encoded without losing any data.
- `sys::windows::STDIN_BUF_SIZE` is slightly larger to compensate. There should be no real change in the number of syscalls the buffered `Stdin` does. This buffer is a little larger, while the extra buffer on Stdin is gone.
- `sys::windows::Stdin` now attempts to handle unpaired surrogates at its buffer boundary.
- `sys::windows::Stdin` no langer allocates for its buffer, but the UTF-16 decoding still does.

### Testing
I did some manual testing of reading and writing to console. The console does support UTF-16 in some sense, but doesn't supporting displaying characters outside the BMP.
- compile stage 1 stdlib with a tiny value for `MAX_BUFFER_SIZE` to make it easier to catch corner cases
- run a simple test program that reads on stdin, and echo's to stdout
- write some lines with plenty of ASCII and emoji in a text editor
- copy and paste in console to stdin
- return with `\r\n\` or CTRL-Z
- copy and paste in text editor
- check it round-trips

-----

Fixes https://github.com/rust-lang/rust/issues/23344. All but one of the suggestions in that issue are now implemented. the missing one is:

> * When reading data, we require the entire set of input to be valid UTF-16. We should instead attempt to read as much of the input as possible as valid UTF-16, only returning an error for the actual invalid elements. For example if we read 10 elements, 5 of which are valid UTF-16, the 6th is bad, and then the remaining are all valid UTF-16, we should probably return the first 5 on a call to `read`, then return an error, then return the remaining on the next call to `read`.

Stdin in Console mode is dealing with text directly input by a user. In my opinion getting an unpaired surrogate is quite unlikely in that case, and a valid reason to error on the entire line of input (which is probably short). Dealing with it is incompatible with an unbuffered stdin, which seems the more interesting guarantee to me.
2019-02-24 05:56:00 +01:00
..
bootstrap Rollup merge of #57929 - GuillaumeGomez:rustodc-remove-old-style-files, r=ollie27 2019-02-17 14:52:21 +08:00
build_helper rustc: doc comments 2019-02-10 23:42:32 +00:00
ci Added a connection timeout and speed threshold when downloading the Docker cache 2019-02-23 03:25:14 +08:00
doc fix typo 2019-02-20 17:59:17 +01:00
etc Rollup merge of #58489 - xfix:fix-keyword-tests-runtime-error, r=alexcrichton 2019-02-17 14:52:20 +08:00
grammar Remove licenses 2018-12-25 21:08:33 -07:00
liballoc Rollup merge of #58183 - jethrogb:jb/alloc-box-guarantees, r=SimonSapin 2019-02-24 05:55:57 +01:00
libarena libarena => 2018 2019-02-11 23:49:48 +01:00
libcore Rollup merge of #58595 - stjepang:make-duration-consts-associated, r=oli-obk 2019-02-23 09:25:29 +01:00
libfmt_macros Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
libgraphviz Auto merge of #58051 - SimonSapin:str_escape, r=alexcrichton 2019-02-12 23:30:16 +00:00
libpanic_abort SGX target: fix panic = abort 2019-02-14 12:39:54 +05:30
libpanic_unwind libpanic_unwind => 2018: remove unused extern crate. 2019-02-13 18:09:09 +01:00
libproc_macro Rollup merge of #57856 - lzutao:fix-old-first-edition, r=steveklabnik 2019-02-14 02:41:16 +01:00
libprofiler_builtins Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
librustc Auto merge of #58232 - ljedrz:HirIdification_continued, r=Zoxc 2019-02-24 00:24:16 +00:00
librustc_allocator Auto merge of #58098 - oli-obk:maybe_allow_internal_unstable, r=petrochenkov 2019-02-12 12:10:10 +00:00
librustc_apfloat Auto merge of #58341 - alexreg:cosmetic-2-doc-comments, r=steveklabnik 2019-02-12 19:09:24 +00:00
librustc_asan Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
librustc_borrowck HirIdification: change some NodeId to HirId calls 2019-02-20 11:00:43 +01:00
librustc_codegen_llvm codegen and write_metadata can mutate ModuleLLvm. 2019-02-21 13:38:44 +00:00
librustc_codegen_ssa Allow Self::Module to be mutated. 2019-02-20 21:35:34 +00:00
librustc_codegen_utils Rollup merge of #58259 - taiki-e:librustc_codegen_utils-2018, r=Centril 2019-02-09 00:15:59 +01:00
librustc_cratesio_shim librustc_cratesio_shim => 2018 2019-02-08 20:55:12 +09:00
librustc_data_structures Update parking_lot to 0.7 2019-02-22 13:49:19 +01:00
librustc_driver Fix a transposition in driver.rs. 2019-02-18 17:33:52 -08:00
librustc_errors Rollup merge of #58296 - estebank:hidden-suggestion, r=oli-obk 2019-02-14 02:41:21 +01:00
librustc_fs_util rustc: doc comments 2019-02-10 23:42:32 +00:00
librustc_incremental rustc: doc comments 2019-02-10 23:42:32 +00:00
librustc_lint hir: HirId-ify intravisit 2019-02-20 11:00:43 +01:00
librustc_llvm Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
librustc_lsan Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
librustc_metadata hir: HirId-ify intravisit 2019-02-20 11:00:43 +01:00
librustc_mir Auto merge of #58232 - ljedrz:HirIdification_continued, r=Zoxc 2019-02-24 00:24:16 +00:00
librustc_msan Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
librustc_passes hir: HirId-ify intravisit 2019-02-20 11:00:43 +01:00
librustc_plugin Auto merge of #58341 - alexreg:cosmetic-2-doc-comments, r=steveklabnik 2019-02-12 19:09:24 +00:00
librustc_privacy HirIdification: change some NodeId to HirId calls 2019-02-20 11:00:43 +01:00
librustc_resolve Rollup merge of #58476 - nnethercote:rm-LazyTokenStream, r=petrochenkov 2019-02-23 09:25:26 +01:00
librustc_save_analysis Reduce the size of hir::Expr. 2019-02-14 11:52:03 +11:00
librustc_target Search for target_triple.json only if builtin target not found 2019-02-20 19:37:54 +01:00
librustc_traits HirId-ify hir::BodyId 2019-02-13 09:54:58 +01:00
librustc_tsan Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
librustc_typeck Auto merge of #58232 - ljedrz:HirIdification_continued, r=Zoxc 2019-02-24 00:24:16 +00:00
librustdoc Auto merge of #58232 - ljedrz:HirIdification_continued, r=Zoxc 2019-02-24 00:24:16 +00:00
libserialize Auto merge of #58341 - alexreg:cosmetic-2-doc-comments, r=steveklabnik 2019-02-12 19:09:24 +00:00
libstd Rollup merge of #58454 - pitdicker:windows_stdio, r=alexcrichton 2019-02-24 05:56:00 +01:00
libsyntax Rollup merge of #57364 - hdhoang:33418_negative_bounds, r=estebank 2019-02-24 05:55:55 +01:00
libsyntax_ext Make interpolated_to_tokenstream a method on Nonterminal. 2019-02-18 10:06:26 +11:00
libsyntax_pos Auto merge of #58341 - alexreg:cosmetic-2-doc-comments, r=steveklabnik 2019-02-12 19:09:24 +00:00
libterm Auto merge of #58341 - alexreg:cosmetic-2-doc-comments, r=steveklabnik 2019-02-12 19:09:24 +00:00
libtest Rollup merge of #57856 - lzutao:fix-old-first-edition, r=steveklabnik 2019-02-14 02:41:16 +01:00
libunwind Revert removed #![feature(nll)] 2019-02-10 16:13:30 +09:00
llvm-emscripten@7f23313edf Pull in fix for dist-i686-linux build 2018-11-09 16:59:45 +01:00
llvm-project@73a75d35b9 Update LLVM: apply patches for RISC-V 64-bit support 2019-02-12 18:58:06 +03:00
rtstartup Remove licenses 2018-12-25 21:08:33 -07:00
rustc rustc: Fix regression where jemalloc isn't used 2019-01-03 13:52:36 -08:00
rustllvm rustc: Implement incremental "fat" LTO 2019-02-12 04:58:31 -08:00
stdsimd@9a60697044 update stdsimd 2019-02-17 11:22:04 +01:00
test Rollup merge of #57364 - hdhoang:33418_negative_bounds, r=estebank 2019-02-24 05:55:55 +01:00
tools Auto merge of #58232 - ljedrz:HirIdification_continued, r=Zoxc 2019-02-24 00:24:16 +00:00
.gitignore
README.md remove link to removed readme 2019-01-15 19:48:37 -06:00
stage0.txt Bump the bootstrap compiler 2019-02-17 18:14:32 +01:00

This directory contains the source code of the rust project, including:

  • rustc and its tests
  • libstd
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc guide.

There is also useful content in the following READMEs, which are gradually being moved over to the guide: