Skip to content

Commit

Permalink
Auto merge of rust-lang#82654 - JohnTitor:rollup-nkcdkzp, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#82309 (Propagate RUSTDOCFLAGS in the environment when documenting)
 - rust-lang#82403 (rustbuild: print out env vars on verbose rustc invocations)
 - rust-lang#82507 (Rename the `tidy` binary to `rust-tidy`)
 - rust-lang#82531 (Add GUI tests)
 - rust-lang#82532 (Add `build.print_step_rusage` to config.toml)
 - rust-lang#82543 (fix env var name in CI)
 - rust-lang#82622 (Propagate `--test-args` for `x.py test src/tools/cargo`)
 - rust-lang#82628 (Try to clarify GlobalAlloc::realloc documentation comment.)
 - rust-lang#82630 (Fix a typo in the `find_anon_type` doc)
 - rust-lang#82643 (Add more proc-macro attribute tests)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 1, 2021
2 parents 05c3001 + e2d8efb commit d2731d8
Show file tree
Hide file tree
Showing 29 changed files with 2,428 additions and 391 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -63,7 +63,7 @@ jobs:
run: "echo \"[CI_PR_NUMBER=$num]\""
env:
num: "${{ github.event.number }}"
if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'"
if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'"
- name: add extra environment variables
run: src/ci/scripts/setup-environment.sh
env:
Expand Down Expand Up @@ -425,7 +425,7 @@ jobs:
run: "echo \"[CI_PR_NUMBER=$num]\""
env:
num: "${{ github.event.number }}"
if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'"
if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'"
- name: add extra environment variables
run: src/ci/scripts/setup-environment.sh
env:
Expand Down Expand Up @@ -532,7 +532,7 @@ jobs:
run: "echo \"[CI_PR_NUMBER=$num]\""
env:
num: "${{ github.event.number }}"
if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'"
if: "success() && !env.SKIP_JOB && github.event_name == 'pull_request'"
- name: add extra environment variables
run: src/ci/scripts/setup-environment.sh
env:
Expand Down
Expand Up @@ -19,7 +19,7 @@ use rustc_middle::ty::{self, Region, TyCtxt};
/// { x.push(y); }
/// ```
/// The function returns the nested type corresponding to the anonymous region
/// for e.g., `&u8` and Vec<`&u8`.
/// for e.g., `&u8` and `Vec<&u8>`.
pub(crate) fn find_anon_type(
tcx: TyCtxt<'tcx>,
region: Region<'tcx>,
Expand Down
6 changes: 6 additions & 0 deletions config.toml.example
Expand Up @@ -290,6 +290,12 @@ changelog-seen = 2
# tracking over time)
#print-step-timings = false

# Print out resource usage data for each rustbuild step, as defined by the Unix
# struct rusage. (Note that this setting is completely unstable: the data it
# captures, what platforms it supports, the format of its associated output, and
# this setting's very existence, are all subject to change.)
#print-step-rusage = false

# =============================================================================
# General install configuration options
# =============================================================================
Expand Down
7 changes: 5 additions & 2 deletions library/core/src/alloc/global.rs
Expand Up @@ -122,7 +122,7 @@ pub unsafe trait GlobalAlloc {
/// this allocator,
///
/// * `layout` must be the same layout that was used
/// to allocate that block of memory,
/// to allocate that block of memory.
#[stable(feature = "global_alloc", since = "1.28.0")]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);

Expand Down Expand Up @@ -167,7 +167,10 @@ pub unsafe trait GlobalAlloc {
/// and should be considered unusable (unless of course it was
/// transferred back to the caller again via the return value of
/// this method). The new memory block is allocated with `layout`, but
/// with the `size` updated to `new_size`.
/// with the `size` updated to `new_size`. This new layout should be
/// used when deallocating the new memory block with `dealloc`. The range
/// `0..min(layout.size(), new_size)` of the new memory block is
/// guaranteed to have the same values as the original block.
///
/// If this method returns null, then ownership of the memory
/// block has not been transferred to this allocator, and the
Expand Down
88 changes: 85 additions & 3 deletions src/bootstrap/bin/rustc.rs
Expand Up @@ -139,6 +139,12 @@ fn main() {
}

if verbose > 1 {
let rust_env_vars =
env::vars().filter(|(k, _)| k.starts_with("RUST") || k.starts_with("CARGO"));
for (i, (k, v)) in rust_env_vars.enumerate() {
eprintln!("rustc env[{}]: {:?}={:?}", i, k, v);
}
eprintln!("rustc working directory: {}", env::current_dir().unwrap().display());
eprintln!(
"rustc command: {:?}={:?} {:?}",
bootstrap::util::dylib_path_var(),
Expand All @@ -155,16 +161,24 @@ fn main() {
cmd.status().expect(&errmsg)
};

if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() {
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some()
|| env::var_os("RUSTC_PRINT_STEP_RUSAGE").is_some()
{
if let Some(crate_name) = crate_name {
let dur = start.elapsed();
let is_test = args.iter().any(|a| a == "--test");
// If the user requested resource usage data, then
// include that in addition to the timing output.
let rusage_data =
env::var_os("RUSTC_PRINT_STEP_RUSAGE").and_then(|_| format_rusage_data());
eprintln!(
"[RUSTC-TIMING] {} test:{} {}.{:03}",
"[RUSTC-TIMING] {} test:{} {}.{:03}{}{}",
crate_name,
is_test,
dur.as_secs(),
dur.subsec_millis()
dur.subsec_millis(),
if rusage_data.is_some() { " " } else { "" },
rusage_data.unwrap_or(String::new()),
);
}
}
Expand Down Expand Up @@ -192,3 +206,71 @@ fn main() {
}
}
}

#[cfg(not(unix))]
/// getrusage is not available on non-unix platforms. So for now, we do not
/// bother trying to make a shim for it.
fn format_rusage_data() -> Option<String> {
None
}

#[cfg(unix)]
/// Tries to build a string with human readable data for several of the rusage
/// fields. Note that we are focusing mainly on data that we believe to be
/// supplied on Linux (the `rusage` struct has other fields in it but they are
/// currently unsupported by Linux).
fn format_rusage_data() -> Option<String> {
let rusage: libc::rusage = unsafe {
let mut recv = std::mem::zeroed();
// -1 is RUSAGE_CHILDREN, which means to get the rusage for all children
// (and grandchildren, etc) processes that have respectively terminated
// and been waited for.
let retval = libc::getrusage(-1, &mut recv);
if retval != 0 {
return None;
}
recv
};
// Mac OS X reports the maxrss in bytes, not kb.
let divisor = if env::consts::OS == "macos" { 1024 } else { 1 };
let maxrss = rusage.ru_maxrss + (divisor - 1) / divisor;

let mut init_str = format!(
"user: {USER_SEC}.{USER_USEC:03} \
sys: {SYS_SEC}.{SYS_USEC:03} \
max rss (kb): {MAXRSS}",
USER_SEC = rusage.ru_utime.tv_sec,
USER_USEC = rusage.ru_utime.tv_usec,
SYS_SEC = rusage.ru_stime.tv_sec,
SYS_USEC = rusage.ru_stime.tv_usec,
MAXRSS = maxrss
);

// The remaining rusage stats vary in platform support. So we treat
// uniformly zero values in each category as "not worth printing", since it
// either means no events of that type occurred, or that the platform
// does not support it.

let minflt = rusage.ru_minflt;
let majflt = rusage.ru_majflt;
if minflt != 0 || majflt != 0 {
init_str.push_str(&format!(" page reclaims: {} page faults: {}", minflt, majflt));
}

let inblock = rusage.ru_inblock;
let oublock = rusage.ru_oublock;
if inblock != 0 || oublock != 0 {
init_str.push_str(&format!(" fs block inputs: {} fs block outputs: {}", inblock, oublock));
}

let nvcsw = rusage.ru_nvcsw;
let nivcsw = rusage.ru_nivcsw;
if nvcsw != 0 || nivcsw != 0 {
init_str.push_str(&format!(
" voluntary ctxt switches: {} involuntary ctxt switches: {}",
nvcsw, nivcsw
));
}

return Some(init_str);
}
34 changes: 25 additions & 9 deletions src/bootstrap/builder.rs
Expand Up @@ -939,6 +939,12 @@ impl<'a> Builder<'a> {
// but this breaks CI. At the very least, stage0 `rustdoc` needs `--cfg bootstrap`. See
// #71458.
let mut rustdocflags = rustflags.clone();
rustdocflags.propagate_cargo_env("RUSTDOCFLAGS");
if stage == 0 {
rustdocflags.env("RUSTDOCFLAGS_BOOTSTRAP");
} else {
rustdocflags.env("RUSTDOCFLAGS_NOT_BOOTSTRAP");
}

if let Ok(s) = env::var("CARGOFLAGS") {
cargo.args(s.split_whitespace());
Expand Down Expand Up @@ -1259,6 +1265,10 @@ impl<'a> Builder<'a> {
cargo.env("RUSTC_PRINT_STEP_TIMINGS", "1");
}

if self.config.print_step_rusage {
cargo.env("RUSTC_PRINT_STEP_RUSAGE", "1");
}

if self.config.backtrace_on_ice {
cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
}
Expand Down Expand Up @@ -1544,21 +1554,27 @@ impl<'a> Builder<'a> {
mod tests;

#[derive(Debug, Clone)]
struct Rustflags(String);
struct Rustflags(String, TargetSelection);

impl Rustflags {
fn new(target: TargetSelection) -> Rustflags {
let mut ret = Rustflags(String::new());
let mut ret = Rustflags(String::new(), target);
ret.propagate_cargo_env("RUSTFLAGS");
ret
}

/// By default, cargo will pick up on various variables in the environment. However, bootstrap
/// reuses those variables to pass additional flags to rustdoc, so by default they get overriden.
/// Explicitly add back any previous value in the environment.
///
/// `prefix` is usually `RUSTFLAGS` or `RUSTDOCFLAGS`.
fn propagate_cargo_env(&mut self, prefix: &str) {
// Inherit `RUSTFLAGS` by default ...
ret.env("RUSTFLAGS");
self.env(prefix);

// ... and also handle target-specific env RUSTFLAGS if they're
// configured.
let target_specific = format!("CARGO_TARGET_{}_RUSTFLAGS", crate::envify(&target.triple));
ret.env(&target_specific);

ret
// ... and also handle target-specific env RUSTFLAGS if they're configured.
let target_specific = format!("CARGO_TARGET_{}_{}", crate::envify(&self.1.triple), prefix);
self.env(&target_specific);
}

fn env(&mut self, env: &str) {
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.rs
Expand Up @@ -161,6 +161,7 @@ pub struct Config {
pub verbose_tests: bool,
pub save_toolstates: Option<PathBuf>,
pub print_step_timings: bool,
pub print_step_rusage: bool,
pub missing_tools: bool,

// Fallback musl-root for all targets
Expand Down Expand Up @@ -380,6 +381,7 @@ struct Build {
configure_args: Option<Vec<String>>,
local_rebuild: Option<bool>,
print_step_timings: Option<bool>,
print_step_rusage: Option<bool>,
check_stage: Option<u32>,
doc_stage: Option<u32>,
build_stage: Option<u32>,
Expand Down Expand Up @@ -679,6 +681,7 @@ impl Config {
set(&mut config.configure_args, build.configure_args);
set(&mut config.local_rebuild, build.local_rebuild);
set(&mut config.print_step_timings, build.print_step_timings);
set(&mut config.print_step_rusage, build.print_step_rusage);

// See https://github.com/rust-lang/compiler-team/issues/326
config.stage = match config.cmd {
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/test.rs
Expand Up @@ -212,6 +212,7 @@ impl Step for Cargo {
if !builder.fail_fast {
cargo.arg("--no-fail-fast");
}
cargo.arg("--").args(builder.config.cmd.test_args());

// Don't run cross-compile tests, we may not have cross-compiled libstd libs
// available.
Expand Down
8 changes: 7 additions & 1 deletion src/bootstrap/tool.rs
Expand Up @@ -47,7 +47,7 @@ impl Step for ToolBuild {
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
let compiler = self.compiler;
let target = self.target;
let tool = self.tool;
let mut tool = self.tool;
let path = self.path;
let is_optional_tool = self.is_optional_tool;

Expand Down Expand Up @@ -208,6 +208,12 @@ impl Step for ToolBuild {
None
}
} else {
// HACK(#82501): on Windows, the tools directory gets added to PATH when running tests, and
// compiletest confuses HTML tidy with the in-tree tidy. Name the in-tree tidy something
// different so the problem doesn't come up.
if tool == "tidy" {
tool = "rust-tidy";
}
let cargo_out =
builder.cargo_out(compiler, self.mode, target).join(exe(tool, compiler.host));
let bin = builder.tools_dir(compiler).join(exe(tool, compiler.host));
Expand Down
2 changes: 1 addition & 1 deletion src/ci/github-actions/ci.yml
Expand Up @@ -110,7 +110,7 @@ x--expand-yaml-anchors--remove:
run: echo "[CI_PR_NUMBER=$num]"
env:
num: ${{ github.event.number }}
if: success() && !env.SKIP_JOBS && github.event_name == 'pull_request'
if: success() && !env.SKIP_JOB && github.event_name == 'pull_request'

- name: add extra environment variables
run: src/ci/scripts/setup-environment.sh
Expand Down
11 changes: 11 additions & 0 deletions src/test/rustdoc-gui/search-input-mobile.goml
@@ -0,0 +1,11 @@
// Test to ensure that you can click on the search input, whatever the width.
// The PR which fixed it is: https://github.com/rust-lang/rust/pull/81592
goto: file://|DOC_PATH|/index.html
size: (463, 700)
// We first check that the search input isn't already focused.
assert-false: ("input.search-input:focus")
click: "input.search-input"
reload:
size: (750, 700)
click: "input.search-input"
assert: ("input.search-input:focus")
26 changes: 26 additions & 0 deletions src/test/rustdoc-gui/shortcuts.goml
@@ -0,0 +1,26 @@
// Check that the various shortcuts are working.
goto: file://|DOC_PATH|/index.html
// We first check that the search input isn't already focused.
assert-false: "input.search-input:focus"
press-key: "s"
assert: "input.search-input:focus"
press-key: "Escape"
assert-false: "input.search-input:focus"
// We now check for the help popup.
press-key: "?"
assert: ("#help", {"display": "flex"})
assert-false: "#help.hidden"
press-key: "Escape"
assert: ("#help.hidden", {"display": "none"})
// Check for the themes list.
assert: ("#theme-choices", {"display": "none"})
press-key: "t"
assert: ("#theme-choices", {"display": "block"})
press-key: "t"
// We ensure that 't' hides back the menu.
assert: ("#theme-choices", {"display": "none"})
press-key: "t"
assert: ("#theme-choices", {"display": "block"})
press-key: "Escape"
// We ensure that 'Escape' hides the menu too.
assert: ("#theme-choices", {"display": "none"})
26 changes: 26 additions & 0 deletions src/test/ui/proc-macro/attr-complex-fn.rs
@@ -0,0 +1,26 @@
// check-pass
// compile-flags: -Z span-debug --error-format human
// aux-build:test-macros.rs

#![feature(stmt_expr_attributes)]
#![feature(custom_inner_attributes)]
#![feature(rustc_attrs)]

#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;

#[macro_use]
extern crate test_macros;

trait MyTrait<T> {}
struct MyStruct<const N: bool>;

#[print_attr]
fn foo<T: MyTrait<MyStruct<{ true }>>>() {}

impl<T> MyTrait<T> for MyStruct<{true}> {
#![print_attr]
#![rustc_dummy]
}

fn main() {}

0 comments on commit d2731d8

Please sign in to comment.