Skip to content

Commit

Permalink
Auto merge of rust-lang#119030 - GuillaumeGomez:rollup-sb5e7wi, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

Rollup of 5 pull requests

Successful merges:

 - rust-lang#118828 (Remove dead codes in rustc_codegen_gcc)
 - rust-lang#118830 (Add support for `--env` on `tracked_env::var`)
 - rust-lang#119001 (rustdoc-search: remove parallel searchWords array)
 - rust-lang#119011 (coverage: Regression test for `assert!(!false)`)
 - rust-lang#119020 (remove `hex` dependency in bootstrap)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 17, 2023
2 parents 4451777 + b4d70b4 commit 1ed2eb8
Show file tree
Hide file tree
Showing 24 changed files with 219 additions and 103 deletions.
11 changes: 0 additions & 11 deletions compiler/rustc_codegen_gcc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,6 @@ pub trait TypeReflection<'gcc, 'tcx> {
fn is_i128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_u128(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;

fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;
fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool;

fn is_vector(&self) -> bool;
}

Expand Down Expand Up @@ -464,14 +461,6 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
self.unqualified() == cx.u128_type.unqualified()
}

fn is_f32(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.context.new_type::<f32>()
}

fn is_f64(&self, cx: &CodegenCx<'gcc, 'tcx>) -> bool {
self.unqualified() == cx.context.new_type::<f64>()
}

fn is_vector(&self) -> bool {
let mut typ = self.clone();
loop {
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_codegen_gcc/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
use crate::callee::get_fn;
use crate::common::SignType;

#[derive(Clone)]
pub struct FuncSig<'gcc> {
pub params: Vec<Type<'gcc>>,
pub return_type: Type<'gcc>,
}

pub struct CodegenCx<'gcc, 'tcx> {
pub check_overflow: bool,
pub codegen_unit: &'tcx CodegenUnit<'tcx>,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ impl server::Types for Rustc<'_, '_> {
}

impl server::FreeFunctions for Rustc<'_, '_> {
fn injected_env_var(&mut self, var: &str) -> Option<String> {
self.ecx.sess.opts.logical_env.get(var).cloned()
}

fn track_env_var(&mut self, var: &str, value: Option<&str>) {
self.sess()
.env_depinfo
Expand Down
1 change: 1 addition & 0 deletions library/proc_macro/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ macro_rules! with_api {
$m! {
FreeFunctions {
fn drop($self: $S::FreeFunctions);
fn injected_env_var(var: &str) -> Option<String>;
fn track_env_var(var: &str, value: Option<&str>);
fn track_path(path: &str);
fn literal_from_str(s: &str) -> Result<Literal<$S::Span, $S::Symbol>, ()>;
Expand Down
3 changes: 2 additions & 1 deletion library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,8 @@ pub mod tracked_env {
#[unstable(feature = "proc_macro_tracked_env", issue = "99515")]
pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
let key: &str = key.as_ref();
let value = env::var(key);
let value = crate::bridge::client::FreeFunctions::injected_env_var(key)
.map_or_else(|| env::var(key), Ok);
crate::bridge::client::FreeFunctions::track_env_var(key, value.as_deref().ok());
value
}
Expand Down
7 changes: 0 additions & 7 deletions src/bootstrap/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ dependencies = [
"cmake",
"fd-lock",
"filetime",
"hex",
"home",
"ignore",
"junction",
Expand Down Expand Up @@ -313,12 +312,6 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"

[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"

[[package]]
name = "home"
version = "0.5.4"
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ clap = { version = "4.4.7", default-features = false, features = ["std", "usage"
clap_complete = "4.4.3"
cmake = "0.1.38"
filetime = "0.2"
hex = "0.4"
home = "0.5.4"
ignore = "0.4.10"
libc = "0.2.150"
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/setup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::t;
use crate::utils::change_tracker::CONFIG_CHANGE_HISTORY;
use crate::utils::helpers::hex_encode;
use crate::Config;
use sha2::Digest;
use std::env::consts::EXE_SUFFIX;
Expand Down Expand Up @@ -566,7 +567,7 @@ fn create_vscode_settings_maybe(config: &Config) -> io::Result<bool> {
if let Ok(current) = fs::read_to_string(&vscode_settings) {
let mut hasher = sha2::Sha256::new();
hasher.update(&current);
let hash = hex::encode(hasher.finalize().as_slice());
let hash = hex_encode(hasher.finalize().as_slice());
if hash == *current_hash {
return Ok(true);
} else if historical_hashes.contains(&hash.as_str()) {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::{
use build_helper::ci::CiEnv;
use xz2::bufread::XzDecoder;

use crate::core::build_steps::llvm::detect_llvm_sha;
use crate::core::config::RustfmtMetadata;
use crate::utils::helpers::{check_run, exe, program_out_of_date};
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
use crate::{t, Config};

static SHOULD_FIX_BINS_AND_DYLIBS: OnceLock<bool> = OnceLock::new();
Expand Down Expand Up @@ -345,7 +345,7 @@ impl Config {
reader.consume(l);
}

let checksum = hex::encode(hasher.finalize().as_slice());
let checksum = hex_encode(hasher.finalize().as_slice());
let verified = checksum == expected;

if !verified {
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use filetime::FileTime;
use sha2::digest::Digest;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use utils::channel::GitInfo;
use utils::helpers::hex_encode;

use crate::core::builder;
use crate::core::builder::Kind;
Expand Down Expand Up @@ -1871,7 +1872,7 @@ pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
hasher.update(status);
hasher.update(additional_input);

hex::encode(hasher.finalize().as_slice())
hex_encode(hasher.finalize().as_slice())
}

/// Ensures that the behavior dump directory is properly initialized.
Expand Down
16 changes: 0 additions & 16 deletions src/bootstrap/src/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,6 @@ fn alias_and_path_for_library() {
assert_eq!(first(cache.all::<doc::Std>()), &[doc_std!(A => A, stage = 0)]);
}

#[test]
fn test_beta_rev_parsing() {
use crate::utils::helpers::extract_beta_rev;

// single digit revision
assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string()));
// multiple digits
assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string()));
// nightly channel (no beta revision)
assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None);
// stable channel (no beta revision)
assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None);
// invalid string
assert_eq!(extract_beta_rev("invalid"), None);
}

mod defaults {
use super::{configure, first, run_build};
use crate::core::builder::*;
Expand Down
56 changes: 56 additions & 0 deletions src/bootstrap/src/tests/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::utils::helpers::{extract_beta_rev, hex_encode, make};
use std::{env, path::PathBuf};

#[test]
fn test_make() {
for (host, make_path) in vec![
("dragonfly", PathBuf::from("gmake")),
("netbsd", PathBuf::from("gmake")),
("freebsd", PathBuf::from("gmake")),
("openbsd", PathBuf::from("gmake")),
("linux", PathBuf::from("make")),
// for checking the default
("_", PathBuf::from("make")),
] {
assert_eq!(make(host), make_path);
}
}

#[cfg(unix)]
#[test]
fn test_absolute_unix() {
use crate::utils::helpers::absolute_unix;

// Test an absolute path
let path = PathBuf::from("/home/user/file.txt");
assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("/home/user/file.txt"));

// Test an absolute path with double leading slashes
let path = PathBuf::from("//root//file.txt");
assert_eq!(absolute_unix(&path).unwrap(), PathBuf::from("//root/file.txt"));

// Test a relative path
let path = PathBuf::from("relative/path");
assert_eq!(absolute_unix(&path).unwrap(), env::current_dir().unwrap().join("relative/path"));
}

#[test]
fn test_beta_rev_parsing() {
// single digit revision
assert_eq!(extract_beta_rev("1.99.9-beta.7 (xxxxxx)"), Some("7".to_string()));
// multiple digits
assert_eq!(extract_beta_rev("1.99.9-beta.777 (xxxxxx)"), Some("777".to_string()));
// nightly channel (no beta revision)
assert_eq!(extract_beta_rev("1.99.9-nightly (xxxxxx)"), None);
// stable channel (no beta revision)
assert_eq!(extract_beta_rev("1.99.9 (xxxxxxx)"), None);
// invalid string
assert_eq!(extract_beta_rev("invalid"), None);
}

#[test]
fn test_string_to_hex_encode() {
let input_string = "Hello, World!";
let hex_string = hex_encode(input_string);
assert_eq!(hex_string, "48656c6c6f2c20576f726c6421");
}
3 changes: 2 additions & 1 deletion src/bootstrap/src/tests/setup.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::{RUST_ANALYZER_SETTINGS, SETTINGS_HASHES};
use crate::utils::helpers::hex_encode;
use sha2::Digest;

#[test]
fn check_matching_settings_hash() {
let mut hasher = sha2::Sha256::new();
hasher.update(&RUST_ANALYZER_SETTINGS);
let hash = hex::encode(hasher.finalize().as_slice());
let hash = hex_encode(hasher.finalize().as_slice());
assert_eq!(
&hash,
SETTINGS_HASHES.last().unwrap(),
Expand Down
12 changes: 12 additions & 0 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use crate::LldMode;

pub use crate::utils::dylib::{dylib_path, dylib_path_var};

#[cfg(test)]
#[path = "../tests/helpers.rs"]
mod tests;

/// A helper macro to `unwrap` a result except also print out details like:
///
/// * The file/line of the panic
Expand Down Expand Up @@ -540,3 +544,11 @@ pub fn add_rustdoc_cargo_linker_args(
cmd.env("RUSTDOCFLAGS", flags);
}
}

/// Converts `T` into a hexadecimal `String`.
pub fn hex_encode<T>(input: T) -> String
where
T: AsRef<[u8]>,
{
input.as_ref().iter().map(|x| format!("{:02x}", x)).collect()
}
Loading

0 comments on commit 1ed2eb8

Please sign in to comment.