Skip to content

Commit fc67cad

Browse files
authored
Auto merge of #36948 - brson:sys, r=brson
More refactoring to obey platform abstraction lint The most interesting things here are moving `std/sys/common` to `std/sys_common`, and `std/num/{f32,f64}.rs` to `std/{f32,f64}.rs`, and adding more documentation to `std/lib.rs`. r? @alexcrichton
2 parents 35a1fef + 6135cbc commit fc67cad

33 files changed

+354
-300
lines changed
File renamed without changes.
File renamed without changes.

src/libstd/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ mod lazy;
289289
mod util;
290290
mod stdio;
291291

292-
const DEFAULT_BUF_SIZE: usize = 8 * 1024;
292+
const DEFAULT_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
293293

294294
// A few methods below (read_to_string, read_line) will append data into a
295295
// `String` buffer, but we need to be pretty careful when doing this. The

src/libstd/io/stdio.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,7 @@ pub fn stdin() -> Stdin {
214214
_ => Maybe::Fake
215215
};
216216

217-
// The default buffer capacity is 64k, but apparently windows
218-
// doesn't like 64k reads on stdin. See #13304 for details, but the
219-
// idea is that on windows we use a slightly smaller buffer that's
220-
// been seen to be acceptable.
221-
Arc::new(Mutex::new(if cfg!(windows) {
222-
BufReader::with_capacity(8 * 1024, stdin)
223-
} else {
224-
BufReader::new(stdin)
225-
}))
217+
Arc::new(Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin)))
226218
}
227219
}
228220

src/libstd/lib.rs

+70-76
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,27 @@
210210
test(no_crate_inject, attr(deny(warnings))),
211211
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
212212

213+
// Don't link to std. We are std.
214+
#![no_std]
215+
216+
#![deny(missing_docs)]
217+
218+
// Tell the compiler to link to either panic_abort or panic_unwind
213219
#![needs_panic_runtime]
214220

221+
// Always use alloc_system during stage0 since jemalloc might be unavailable or
222+
// disabled (Issue #30592)
223+
#![cfg_attr(stage0, feature(alloc_system))]
224+
225+
// Turn warnings into errors, but only after stage0, where it can be useful for
226+
// code to emit warnings during language transitions
227+
#![cfg_attr(not(stage0), deny(warnings))]
228+
229+
// std may use features in a platform-specific way
230+
#![allow(unused_features)]
231+
232+
// std is implemented with unstable features, many of which are internal
233+
// compiler details that will never be stable
215234
#![feature(alloc)]
216235
#![feature(allow_internal_unstable)]
217236
#![feature(asm)]
@@ -248,7 +267,6 @@
248267
#![feature(link_args)]
249268
#![feature(linkage)]
250269
#![feature(macro_reexport)]
251-
#![cfg_attr(test, feature(map_values_mut))]
252270
#![feature(needs_panic_runtime)]
253271
#![feature(num_bits_bytes)]
254272
#![feature(old_wrapping)]
@@ -284,21 +302,13 @@
284302
#![feature(zero_one)]
285303
#![cfg_attr(test, feature(update_panic_count))]
286304

287-
// Issue# 30592: Systematically use alloc_system during stage0 since jemalloc
288-
// might be unavailable or disabled
289-
#![cfg_attr(stage0, feature(alloc_system))]
290-
291-
// Don't link to std. We are std.
292-
#![no_std]
293-
294-
#![deny(missing_docs)]
295-
#![allow(unused_features)] // std may use features in a platform-specific way
296-
#![cfg_attr(not(stage0), deny(warnings))]
297-
305+
// Explicitly import the prelude. The compiler uses this same unstable attribute
306+
// to import the prelude implicitly when building crates that depend on std.
298307
#[prelude_import]
299308
#[allow(unused)]
300309
use prelude::v1::*;
301310

311+
// Access to Bencher, etc.
302312
#[cfg(test)] extern crate test;
303313

304314
// We want to reexport a few macros from core but libcore has already been
@@ -326,11 +336,22 @@ extern crate alloc_system;
326336
// compiler-rt intrinsics
327337
extern crate compiler_builtins;
328338

329-
// Make std testable by not duplicating lang items and other globals. See #2912
339+
// During testing, this crate is not actually the "real" std library, but rather
340+
// it links to the real std library, which was compiled from this same source
341+
// code. So any lang items std defines are conditionally excluded (or else they
342+
// wolud generate duplicate lang item errors), and any globals it defines are
343+
// _not_ the globals used by "real" std. So this import, defined only during
344+
// testing gives test-std access to real-std lang items and globals. See #2912
330345
#[cfg(test)] extern crate std as realstd;
331346

332-
// NB: These reexports are in the order they should be listed in rustdoc
347+
// The standard macros that are not built-in to the compiler.
348+
#[macro_use]
349+
mod macros;
350+
351+
// The Rust prelude
352+
pub mod prelude;
333353

354+
// Public module declarations and reexports
334355
#[stable(feature = "rust1", since = "1.0.0")]
335356
pub use core::any;
336357
#[stable(feature = "rust1", since = "1.0.0")]
@@ -363,48 +384,6 @@ pub use core::raw;
363384
pub use core::result;
364385
#[stable(feature = "rust1", since = "1.0.0")]
365386
pub use core::option;
366-
367-
pub mod error;
368-
369-
#[stable(feature = "rust1", since = "1.0.0")]
370-
pub use alloc::boxed;
371-
#[stable(feature = "rust1", since = "1.0.0")]
372-
pub use alloc::rc;
373-
374-
#[stable(feature = "rust1", since = "1.0.0")]
375-
pub use core_collections::borrow;
376-
#[stable(feature = "rust1", since = "1.0.0")]
377-
pub use core_collections::fmt;
378-
#[stable(feature = "rust1", since = "1.0.0")]
379-
pub use core_collections::slice;
380-
#[stable(feature = "rust1", since = "1.0.0")]
381-
pub use core_collections::str;
382-
#[stable(feature = "rust1", since = "1.0.0")]
383-
pub use core_collections::string;
384-
#[stable(feature = "rust1", since = "1.0.0")]
385-
pub use core_collections::vec;
386-
387-
#[stable(feature = "rust1", since = "1.0.0")]
388-
pub use rustc_unicode::char;
389-
390-
/* Exported macros */
391-
392-
#[macro_use]
393-
mod macros;
394-
395-
mod rtdeps;
396-
397-
/* The Prelude. */
398-
399-
pub mod prelude;
400-
401-
402-
/* Primitive types */
403-
404-
// NB: slice and str are primitive types too, but their module docs + primitive
405-
// doc pages are inlined from the public re-exports of core_collections::{slice,
406-
// str} above.
407-
408387
#[stable(feature = "rust1", since = "1.0.0")]
409388
pub use core::isize;
410389
#[stable(feature = "rust1", since = "1.0.0")]
@@ -415,7 +394,6 @@ pub use core::i16;
415394
pub use core::i32;
416395
#[stable(feature = "rust1", since = "1.0.0")]
417396
pub use core::i64;
418-
419397
#[stable(feature = "rust1", since = "1.0.0")]
420398
pub use core::usize;
421399
#[stable(feature = "rust1", since = "1.0.0")]
@@ -426,46 +404,62 @@ pub use core::u16;
426404
pub use core::u32;
427405
#[stable(feature = "rust1", since = "1.0.0")]
428406
pub use core::u64;
407+
#[stable(feature = "rust1", since = "1.0.0")]
408+
pub use alloc::boxed;
409+
#[stable(feature = "rust1", since = "1.0.0")]
410+
pub use alloc::rc;
411+
#[stable(feature = "rust1", since = "1.0.0")]
412+
pub use core_collections::borrow;
413+
#[stable(feature = "rust1", since = "1.0.0")]
414+
pub use core_collections::fmt;
415+
#[stable(feature = "rust1", since = "1.0.0")]
416+
pub use core_collections::slice;
417+
#[stable(feature = "rust1", since = "1.0.0")]
418+
pub use core_collections::str;
419+
#[stable(feature = "rust1", since = "1.0.0")]
420+
pub use core_collections::string;
421+
#[stable(feature = "rust1", since = "1.0.0")]
422+
pub use core_collections::vec;
423+
#[stable(feature = "rust1", since = "1.0.0")]
424+
pub use rustc_unicode::char;
429425

430-
#[path = "num/f32.rs"] pub mod f32;
431-
#[path = "num/f64.rs"] pub mod f64;
432-
433-
pub mod ascii;
434-
435-
/* Common traits */
436-
437-
pub mod num;
438-
439-
/* Runtime and platform support */
426+
pub mod f32;
427+
pub mod f64;
440428

441429
#[macro_use]
442430
pub mod thread;
443-
431+
pub mod ascii;
444432
pub mod collections;
445433
pub mod env;
434+
pub mod error;
446435
pub mod ffi;
447436
pub mod fs;
448437
pub mod io;
449438
pub mod net;
439+
pub mod num;
450440
pub mod os;
451441
pub mod panic;
452442
pub mod path;
453443
pub mod process;
454444
pub mod sync;
455445
pub mod time;
456-
mod memchr;
457446

447+
// Platform-abstraction modules
458448
#[macro_use]
459-
#[path = "sys/common/mod.rs"] mod sys_common;
460-
461-
#[cfg(unix)]
462-
#[path = "sys/unix/mod.rs"] mod sys;
463-
#[cfg(windows)]
464-
#[path = "sys/windows/mod.rs"] mod sys;
449+
mod sys_common;
450+
mod sys;
465451

466-
pub mod rt;
452+
// Private support modules
467453
mod panicking;
468454
mod rand;
455+
mod memchr;
456+
457+
// This module just defines per-platform native library dependencies
458+
mod rtdeps;
459+
460+
// The runtime entry point and a few unstable public functions used by the
461+
// compiler
462+
pub mod rt;
469463

470464
// Some external utilities of the standard library rely on randomness (aka
471465
// rustc_back::TempDir and tests) and need a way to get at the OS rng we've got
File renamed without changes.

src/libstd/sys/mod.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Platform-dependent platform abstraction
12+
//!
13+
//! The `std::sys` module is the abstracted interface through which
14+
//! `std` talks to the underlying operating system. It has different
15+
//! implementations for different operating system families, today
16+
//! just Unix and Windows.
17+
//!
18+
//! The centralization of platform-specific code in this module is
19+
//! enforced by the "platform abstraction layer" tidy script in
20+
//! `tools/tidy/pal.rs`.
21+
//!
22+
//! This module is closely related to the platform-independent system
23+
//! integration code in `std::sys_common`. See that module's
24+
//! documentation for details.
25+
//!
26+
//! In the future it would be desirable for the indepedent
27+
//! implementations of this module to be extracted to their own crates
28+
//! that `std` can link to, thus enabling their implementation
29+
//! out-of-tree via crate replacement. Though due to the complex
30+
//! inter-dependencies within `std` that will be a challenging goal to
31+
//! achieve.
32+
33+
pub use self::imp::*;
34+
35+
#[cfg(unix)]
36+
#[path = "unix/mod.rs"]
37+
mod imp;
38+
39+
#[cfg(windows)]
40+
#[path = "windows/mod.rs"]
41+
mod imp;

0 commit comments

Comments
 (0)