From 64e08e6b82711b24517b97de0364511d06d1e27f Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Mon, 30 Nov 2020 19:41:57 +0000 Subject: Add BPF target This change adds the bpfel-unknown-none and bpfeb-unknown-none targets which can be used to generate little endian and big endian BPF --- src/toolchain.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/toolchain.rs b/src/toolchain.rs index 484a9b699a0..49475fe2469 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -67,6 +67,7 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { LinkerFlavor::Msvc => "link.exe", LinkerFlavor::Lld(_) => "lld", LinkerFlavor::PtxLinker => "rust-ptx-linker", + LinkerFlavor::BpfLinker => "bpf-linker", }), flavor, )), -- cgit 1.4.1-3-g733a5 From 8b08cbd92fc8eb2ad3fe0f644b30731fb2374210 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 24 May 2021 18:55:30 +0200 Subject: Change the ice hook for cg_clif to refer to cg_clif's issue tracker --- src/bin/cg_clif.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs index 983839d48d2..2643fae0a81 100644 --- a/src/bin/cg_clif.rs +++ b/src/bin/cg_clif.rs @@ -1,4 +1,4 @@ -#![feature(rustc_private)] +#![feature(rustc_private, once_cell)] extern crate rustc_data_structures; extern crate rustc_driver; @@ -6,12 +6,33 @@ extern crate rustc_interface; extern crate rustc_session; extern crate rustc_target; +use std::panic; +use std::lazy::SyncLazy; + use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_interface::interface; use rustc_session::config::ErrorOutputType; use rustc_session::early_error; use rustc_target::spec::PanicStrategy; +const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new"; + +static DEFAULT_HOOK: SyncLazy) + Sync + Send + 'static>> = + SyncLazy::new(|| { + let hook = panic::take_hook(); + panic::set_hook(Box::new(|info| { + // Invoke the default handler, which prints the actual panic message and optionally a backtrace + (*DEFAULT_HOOK)(info); + + // Separate the output with an empty line + eprintln!(); + + // Print the ICE message + rustc_driver::report_ice(info, BUG_REPORT_URL); + })); + hook + }); + #[derive(Default)] pub struct CraneliftPassesCallbacks { time_passes: bool, @@ -37,7 +58,7 @@ fn main() { let start_rss = get_resident_set_size(); rustc_driver::init_rustc_env_logger(); let mut callbacks = CraneliftPassesCallbacks::default(); - rustc_driver::install_ice_hook(); + SyncLazy::force(&DEFAULT_HOOK); // Install ice hook let exit_code = rustc_driver::catch_with_exit_code(|| { let args = std::env::args_os() .enumerate() -- cgit 1.4.1-3-g733a5 From d6b03451e6d1203f9e4fc1f4c2c609cb4d045dc8 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 27 May 2021 13:08:14 +0200 Subject: Merge commit '40dd3e2b7089b5e96714e064b731f6dbf17c61a9' into sync_cg_clif-2021-05-27 --- Cargo.lock | 140 ++++----------------- Cargo.toml | 28 ++--- build_sysroot/Cargo.lock | 14 +-- build_sysroot/prepare_sysroot_src.sh | 2 +- ...builtins-Disable-128bit-atomic-operations.patch | 48 +++++++ ...iler-builtins-Remove-rotate_left-from-Int.patch | 35 ------ ...builtins-Disable-128bit-atomic-operations.patch | 48 ------- example/std_example.rs | 16 +-- .../0022-core-Disable-not-compiling-tests.patch | 40 ------ rust-toolchain | 2 +- scripts/setup_rust_fork.sh | 17 +-- scripts/tests.sh | 1 + src/archive.rs | 2 +- src/base.rs | 13 +- src/common.rs | 13 +- src/config.rs | 9 ++ src/constant.rs | 97 +++++++++++++- src/driver/aot.rs | 21 ++-- src/driver/jit.rs | 3 +- src/inline_asm.rs | 30 +++-- src/intrinsics/cpuid.rs | 7 ++ src/intrinsics/mod.rs | 2 +- src/lib.rs | 10 +- src/main_shim.rs | 9 +- src/trap.rs | 2 +- src/value_and_place.rs | 1 + 26 files changed, 266 insertions(+), 344 deletions(-) create mode 100644 crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch delete mode 100644 crate_patches/0001-compiler-builtins-Remove-rotate_left-from-Int.patch delete mode 100644 crate_patches/0002-compiler-builtins-Disable-128bit-atomic-operations.patch diff --git a/Cargo.lock b/Cargo.lock index e6792def567..a6f5925149b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,12 +25,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "byteorder" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" - [[package]] name = "cfg-if" version = "1.0.0" @@ -39,18 +33,17 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ - "byteorder", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", @@ -60,13 +53,12 @@ dependencies = [ "regalloc", "smallvec", "target-lexicon", - "thiserror", ] [[package]] name = "cranelift-codegen-meta" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -74,18 +66,18 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" [[package]] name = "cranelift-entity" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" [[package]] name = "cranelift-frontend" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ "cranelift-codegen", "log", @@ -95,15 +87,14 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ "anyhow", "cranelift-codegen", "cranelift-entity", "cranelift-module", "cranelift-native", - "errno", "libc", "log", "region", @@ -113,20 +104,19 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ "anyhow", "cranelift-codegen", "cranelift-entity", "log", - "thiserror", ] [[package]] name = "cranelift-native" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ "cranelift-codegen", "target-lexicon", @@ -134,8 +124,8 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.73.0" -source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#45bee40f338c631bff4a799288101ba328c7ad36" +version = "0.74.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" dependencies = [ "anyhow", "cranelift-codegen", @@ -154,38 +144,11 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "errno" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa68f2fb9cae9d37c9b2b3584aba698a2e97f72d7aef7b9f7aa71d8b54ce46fe" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" -dependencies = [ - "gcc", - "libc", -] - -[[package]] -name = "gcc" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" - [[package]] name = "gimli" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" +checksum = "0e4075386626662786ddb0ec9081e7c7eeb1ba31951f447ca780ef9f5d568189" dependencies = [ "indexmap", ] @@ -242,32 +205,14 @@ dependencies = [ [[package]] name = "object" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" +checksum = "1a5b3dd1c072ee7963717671d1ca129f1048fda25edea6b752bfc71ac8854170" dependencies = [ "crc32fast", "indexmap", ] -[[package]] -name = "proc-macro2" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" -dependencies = [ - "proc-macro2", -] - [[package]] name = "regalloc" version = "0.0.31" @@ -322,49 +267,12 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" -[[package]] -name = "syn" -version = "1.0.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - [[package]] name = "target-lexicon" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ae3b39281e4b14b8123bdbaddd472b7dfe215e444181f2f9d2443c2444f834" -[[package]] -name = "thiserror" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "unicode-xid" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 2789207c655..fd149af4547 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,15 +9,15 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", features = ["unwind"] } -cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } -cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } -cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } -cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", optional = true } -cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } +cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main", features = ["unwind"] } +cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } +cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } +cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } +cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main", optional = true } +cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } target-lexicon = "0.12.0" -gimli = { version = "0.23.0", default-features = false, features = ["write"]} -object = { version = "0.23.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } +gimli = { version = "0.24.0", default-features = false, features = ["write"]} +object = { version = "0.24.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.0.2" @@ -25,11 +25,11 @@ libloading = { version = "0.6.0", optional = true } smallvec = "1.6.1" # Uncomment to use local checkout of cranelift -#[patch."https://github.com/bytecodealliance/wasmtime/"] +#[patch."https://github.com/bytecodealliance/wasmtime.git"] #cranelift-codegen = { path = "../wasmtime/cranelift/codegen" } #cranelift-frontend = { path = "../wasmtime/cranelift/frontend" } #cranelift-module = { path = "../wasmtime/cranelift/module" } -#cranelift-native = { path = ../wasmtime/cranelift/native" } +#cranelift-native = { path = "../wasmtime/cranelift/native" } #cranelift-jit = { path = "../wasmtime/cranelift/jit" } #cranelift-object = { path = "../wasmtime/cranelift/object" } @@ -70,13 +70,5 @@ debug = false opt-level = 0 debug = false -[profile.dev.package.syn] -opt-level = 0 -debug = false - -[profile.release.package.syn] -opt-level = 0 -debug = false - [package.metadata.rust-analyzer] rustc_private = true diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index e058a972ead..923deb9aec4 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -40,9 +40,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" [[package]] name = "cfg-if" @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.40" +version = "0.1.43" dependencies = [ "rustc-std-workspace-core", ] @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.94" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" +checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" dependencies = [ "rustc-std-workspace-core", ] @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" +checksum = "410f7acf3cb3a44527c5d9546bad4bf4e6c460915d5f9f2fc524498bfe8f70ce" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/build_sysroot/prepare_sysroot_src.sh b/build_sysroot/prepare_sysroot_src.sh index f7fcef10774..54b7a94750c 100755 --- a/build_sysroot/prepare_sysroot_src.sh +++ b/build_sysroot/prepare_sysroot_src.sh @@ -32,7 +32,7 @@ popd git clone https://github.com/rust-lang/compiler-builtins.git || echo "rust-lang/compiler-builtins has already been cloned" pushd compiler-builtins git checkout -- . -git checkout 0.1.40 +git checkout 0.1.43 git apply ../../crate_patches/000*-compiler-builtins-*.patch popd diff --git a/crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch b/crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch new file mode 100644 index 00000000000..7daea99f579 --- /dev/null +++ b/crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch @@ -0,0 +1,48 @@ +From 1d574bf5e32d51641dcacaf8ef777e95b44f6f2a Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Thu, 18 Feb 2021 18:30:55 +0100 +Subject: [PATCH] Disable 128bit atomic operations + +Cranelift doesn't support them yet +--- + src/mem/mod.rs | 12 ------------ + 1 file changed, 12 deletions(-) + +diff --git a/src/mem/mod.rs b/src/mem/mod.rs +index 107762c..2d1ae10 100644 +--- a/src/mem/mod.rs ++++ b/src/mem/mod.rs +@@ -137,10 +137,6 @@ intrinsics! { + pub extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { + memcpy_element_unordered_atomic(dest, src, bytes); + } +- #[cfg(target_has_atomic_load_store = "128")] +- pub extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { +- memcpy_element_unordered_atomic(dest, src, bytes); +- } + + #[cfg(target_has_atomic_load_store = "8")] + pub extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { +@@ -158,10 +154,6 @@ intrinsics! { + pub extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { + memmove_element_unordered_atomic(dest, src, bytes); + } +- #[cfg(target_has_atomic_load_store = "128")] +- pub extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { +- memmove_element_unordered_atomic(dest, src, bytes); +- } + + #[cfg(target_has_atomic_load_store = "8")] + pub extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { +@@ -179,8 +171,4 @@ intrinsics! { + pub extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { + memset_element_unordered_atomic(s, c, bytes); + } +- #[cfg(target_has_atomic_load_store = "128")] +- pub extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { +- memset_element_unordered_atomic(s, c, bytes); +- } + } +-- +2.26.2.7.g19db9cfb68 + diff --git a/crate_patches/0001-compiler-builtins-Remove-rotate_left-from-Int.patch b/crate_patches/0001-compiler-builtins-Remove-rotate_left-from-Int.patch deleted file mode 100644 index b4acc4f5b73..00000000000 --- a/crate_patches/0001-compiler-builtins-Remove-rotate_left-from-Int.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 7078cca3cb614e1e82da428380b4e16fc3afef46 Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 21 Jan 2021 14:46:36 +0100 -Subject: [PATCH] Remove rotate_left from Int - ---- - src/int/mod.rs | 5 ----- - 1 file changed, 5 deletions(-) - -diff --git a/src/int/mod.rs b/src/int/mod.rs -index 06054c8..3bea17b 100644 ---- a/src/int/mod.rs -+++ b/src/int/mod.rs -@@ -85,7 +85,6 @@ pub trait Int: - fn wrapping_sub(self, other: Self) -> Self; - fn wrapping_shl(self, other: u32) -> Self; - fn wrapping_shr(self, other: u32) -> Self; -- fn rotate_left(self, other: u32) -> Self; - fn overflowing_add(self, other: Self) -> (Self, bool); - fn leading_zeros(self) -> u32; - } -@@ -209,10 +208,6 @@ macro_rules! int_impl_common { - ::wrapping_shr(self, other) - } - -- fn rotate_left(self, other: u32) -> Self { -- ::rotate_left(self, other) -- } -- - fn overflowing_add(self, other: Self) -> (Self, bool) { - ::overflowing_add(self, other) - } --- -2.26.2.7.g19db9cfb68 - diff --git a/crate_patches/0002-compiler-builtins-Disable-128bit-atomic-operations.patch b/crate_patches/0002-compiler-builtins-Disable-128bit-atomic-operations.patch deleted file mode 100644 index 7daea99f579..00000000000 --- a/crate_patches/0002-compiler-builtins-Disable-128bit-atomic-operations.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 1d574bf5e32d51641dcacaf8ef777e95b44f6f2a Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 18 Feb 2021 18:30:55 +0100 -Subject: [PATCH] Disable 128bit atomic operations - -Cranelift doesn't support them yet ---- - src/mem/mod.rs | 12 ------------ - 1 file changed, 12 deletions(-) - -diff --git a/src/mem/mod.rs b/src/mem/mod.rs -index 107762c..2d1ae10 100644 ---- a/src/mem/mod.rs -+++ b/src/mem/mod.rs -@@ -137,10 +137,6 @@ intrinsics! { - pub extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memcpy_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memcpy_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { -@@ -158,10 +154,6 @@ intrinsics! { - pub extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memmove_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memmove_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { -@@ -179,8 +171,4 @@ intrinsics! { - pub extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { - memset_element_unordered_atomic(s, c, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { -- memset_element_unordered_atomic(s, c, bytes); -- } - } --- -2.26.2.7.g19db9cfb68 - diff --git a/example/std_example.rs b/example/std_example.rs index 77ba72df8ef..7d608df9253 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -187,20 +187,6 @@ unsafe fn test_mm_slli_si128() { ); let r = _mm_slli_si128(a, 16); assert_eq_m128i(r, _mm_set1_epi8(0)); - - #[rustfmt::skip] - let a = _mm_setr_epi8( - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - ); - let r = _mm_slli_si128(a, -1); - assert_eq_m128i(_mm_set1_epi8(0), r); - - #[rustfmt::skip] - let a = _mm_setr_epi8( - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - ); - let r = _mm_slli_si128(a, -0x80000000); - assert_eq_m128i(r, _mm_set1_epi8(0)); } #[cfg(target_arch = "x86_64")] @@ -295,7 +281,7 @@ unsafe fn test_mm_extract_epi8() { 8, 9, 10, 11, 12, 13, 14, 15 ); let r1 = _mm_extract_epi8(a, 0); - let r2 = _mm_extract_epi8(a, 19); + let r2 = _mm_extract_epi8(a, 3); assert_eq!(r1, 0xFF); assert_eq!(r2, 3); } diff --git a/patches/0022-core-Disable-not-compiling-tests.patch b/patches/0022-core-Disable-not-compiling-tests.patch index 8cfffe580a1..ba0eaacd828 100644 --- a/patches/0022-core-Disable-not-compiling-tests.patch +++ b/patches/0022-core-Disable-not-compiling-tests.patch @@ -39,46 +39,6 @@ index a35897e..f0bf645 100644 pub fn decode_finite(v: T) -> Decoded { match decode(v).1 { -diff --git a/library/core/tests/num/int_macros.rs b/library/core/tests/num/int_macros.rs -index 0475aeb..9558198 100644 ---- a/library/core/tests/num/int_macros.rs -+++ b/library/core/tests/num/int_macros.rs -@@ -88,6 +88,7 @@ mod tests { - assert_eq!(x.trailing_ones(), 0); - } - -+ /* - #[test] - fn test_rotate() { - assert_eq!(A.rotate_left(6).rotate_right(2).rotate_right(4), A); -@@ -112,6 +113,7 @@ mod tests { - assert_eq!(B.rotate_left(128), B); - assert_eq!(C.rotate_left(128), C); - } -+ */ - - #[test] - fn test_swap_bytes() { -diff --git a/library/core/tests/num/uint_macros.rs b/library/core/tests/num/uint_macros.rs -index 04ed14f..a6e372e 100644 ---- a/library/core/tests/num/uint_macros.rs -+++ b/library/core/tests/num/uint_macros.rs -@@ -52,6 +52,7 @@ mod tests { - assert_eq!(x.trailing_ones(), 0); - } - -+ /* - #[test] - fn test_rotate() { - assert_eq!(A.rotate_left(6).rotate_right(2).rotate_right(4), A); -@@ -76,6 +77,7 @@ mod tests { - assert_eq!(B.rotate_left(128), B); - assert_eq!(C.rotate_left(128), C); - } -+ */ - - #[test] - fn test_swap_bytes() { diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 1a6be3a..42dbd59 100644 --- a/library/core/tests/ptr.rs diff --git a/rust-toolchain b/rust-toolchain index 5442e3345aa..9fe6e093a7b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-04-28" +channel = "nightly-2021-05-26" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 4821a07ac5d..43c4887669c 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -24,18 +24,6 @@ index 5bd1147cad5..10d68a2ff14 100644 + [patch."https://github.com/rust-lang/rust-clippy"] clippy_lints = { path = "src/tools/clippy/clippy_lints" } -diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml -index 23e689fcae7..5f077b765b6 100644 ---- a/compiler/rustc_data_structures/Cargo.toml -+++ b/compiler/rustc_data_structures/Cargo.toml -@@ -32,7 +32,6 @@ tempfile = "3.0.5" - - [dependencies.parking_lot] - version = "0.11" --features = ["nightly"] - - [target.'cfg(windows)'.dependencies] - winapi = { version = "0.3", features = ["fileapi", "psapi"] } diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml index d95b5b7f17f..00b6f0e3635 100644 --- a/library/alloc/Cargo.toml @@ -44,11 +32,12 @@ index d95b5b7f17f..00b6f0e3635 100644 [dependencies] core = { path = "../core" } --compiler_builtins = { version = "0.1.39", features = ['rustc-dep-of-std'] } -+compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std', 'no-asm'] } +-compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] } ++compiler_builtins = { version = "0.1.43", features = ['rustc-dep-of-std', 'no-asm'] } [dev-dependencies] rand = "0.7" + rand_xorshift = "0.2" EOF cat > config.toml < ArchiveBuilder<'a> for ArArchiveBuilder<'a> { }; if !self.no_builtin_ranlib { - match object::File::parse(&data) { + match object::File::parse(&*data) { Ok(object) => { symbol_table.insert( entry_name.as_bytes().to_vec(), diff --git a/src/base.rs b/src/base.rs index 3ec5c14ff17..ec3e17e5b75 100644 --- a/src/base.rs +++ b/src/base.rs @@ -110,11 +110,6 @@ pub(crate) fn codegen_fn<'tcx>( // Verify function verify_func(tcx, &clif_comments, &context.func); - // Perform rust specific optimizations - tcx.sess.time("optimize clif ir", || { - crate::optimize::optimize_function(tcx, instance, context, &mut clif_comments); - }); - // If the return block is not reachable, then the SSA builder may have inserted an `iconst.i128` // instruction, which doesn't have an encoding. context.compute_cfg(); @@ -125,10 +120,14 @@ pub(crate) fn codegen_fn<'tcx>( // invalidate it when it would change. context.domtree.clear(); - context.want_disasm = crate::pretty_clif::should_write_ir(tcx); + // Perform rust specific optimizations + tcx.sess.time("optimize clif ir", || { + crate::optimize::optimize_function(tcx, instance, context, &mut clif_comments); + }); // Define function tcx.sess.time("define function", || { + context.want_disasm = crate::pretty_clif::should_write_ir(tcx); module .define_function(func_id, context, &mut NullTrapSink {}, &mut NullStackMapSink {}) .unwrap() @@ -870,7 +869,7 @@ pub(crate) fn codegen_operand<'tcx>( pub(crate) fn codegen_panic<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, msg_str: &str, span: Span) { let location = fx.get_caller_location(span).load_scalar(fx); - let msg_ptr = fx.anonymous_str("assert", msg_str); + let msg_ptr = fx.anonymous_str(msg_str); let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap()); let args = [msg_ptr, msg_len, location]; diff --git a/src/common.rs b/src/common.rs index c12d6d0f141..488ff6e1349 100644 --- a/src/common.rs +++ b/src/common.rs @@ -347,19 +347,10 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { self.module.isa().triple() } - pub(crate) fn anonymous_str(&mut self, prefix: &str, msg: &str) -> Value { - use std::collections::hash_map::DefaultHasher; - use std::hash::{Hash, Hasher}; - - let mut hasher = DefaultHasher::new(); - msg.hash(&mut hasher); - let msg_hash = hasher.finish(); + pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value { let mut data_ctx = DataContext::new(); data_ctx.define(msg.as_bytes().to_vec().into_boxed_slice()); - let msg_id = self - .module - .declare_data(&format!("__{}_{:08x}", prefix, msg_hash), Linkage::Local, false, false) - .unwrap(); + let msg_id = self.module.declare_anonymous_data(false, false).unwrap(); // Ignore DuplicateDefinition error, as the data will be the same let _ = self.module.define_data(msg_id, &data_ctx); diff --git a/src/config.rs b/src/config.rs index e59a0cb0a23..eef3c8c8d6e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -48,6 +48,12 @@ pub struct BackendConfig { /// Can be set using `-Cllvm-args=display_cg_time=...`. pub display_cg_time: bool, + /// The register allocator to use. + /// + /// Defaults to the value of `CG_CLIF_REGALLOC` or `backtracking` otherwise. Can be set using + /// `-Cllvm-args=regalloc=...`. + pub regalloc: String, + /// Enable the Cranelift ir verifier for all compilation passes. If not set it will only run /// once before passing the clif ir to Cranelift for compilation. /// @@ -74,6 +80,8 @@ impl Default for BackendConfig { args.split(' ').map(|arg| arg.to_string()).collect() }, display_cg_time: bool_env_var("CG_CLIF_DISPLAY_CG_TIME"), + regalloc: std::env::var("CG_CLIF_REGALLOC") + .unwrap_or_else(|_| "backtracking".to_string()), enable_verifier: cfg!(debug_assertions) || bool_env_var("CG_CLIF_ENABLE_VERIFIER"), disable_incr_cache: bool_env_var("CG_CLIF_DISABLE_INCR_CACHE"), } @@ -93,6 +101,7 @@ impl BackendConfig { match name { "mode" => config.codegen_mode = value.parse()?, "display_cg_time" => config.display_cg_time = parse_bool(name, value)?, + "regalloc" => config.regalloc = value.to_string(), "enable_verifier" => config.enable_verifier = parse_bool(name, value)?, "disable_incr_cache" => config.disable_incr_cache = parse_bool(name, value)?, _ => return Err(format!("Unknown option `{}`", name)), diff --git a/src/constant.rs b/src/constant.rs index 6b132e4ff0f..3ba12c4e96d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -7,7 +7,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::ErrorReported; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{ - alloc_range, read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar, + alloc_range, read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, + Scalar, }; use rustc_middle::ty::ConstKind; @@ -375,8 +376,19 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant data_ctx.set_align(alloc.align.bytes()); if let Some(section_name) = section_name { - // FIXME set correct segment for Mach-O files - data_ctx.set_segment_section("", &*section_name); + let (segment_name, section_name) = if tcx.sess.target.is_like_osx { + if let Some(names) = section_name.split_once(',') { + names + } else { + tcx.sess.fatal(&format!( + "#[link_section = \"{}\"] is not valid for macos target: must be segment and section separated by comma", + section_name + )); + } + } else { + ("", &*section_name) + }; + data_ctx.set_segment_section(segment_name, section_name); } let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len()).to_vec(); @@ -438,12 +450,89 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( operand: &Operand<'tcx>, ) -> Option> { match operand { - Operand::Copy(_) | Operand::Move(_) => None, Operand::Constant(const_) => match const_.literal { ConstantKind::Ty(const_) => { fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val.try_to_value() } ConstantKind::Val(val, _) => Some(val), }, + // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored + // inside a temporary before being passed to the intrinsic requiring the const argument. + // This code tries to find a single constant defining definition of the referenced local. + Operand::Copy(place) | Operand::Move(place) => { + if !place.projection.is_empty() { + return None; + } + let mut computed_const_val = None; + for bb_data in fx.mir.basic_blocks() { + for stmt in &bb_data.statements { + match &stmt.kind { + StatementKind::Assign(local_and_rvalue) if &local_and_rvalue.0 == place => { + match &local_and_rvalue.1 { + Rvalue::Cast(CastKind::Misc, operand, ty) => { + if computed_const_val.is_some() { + return None; // local assigned twice + } + if !matches!(ty.kind(), ty::Uint(_) | ty::Int(_)) { + return None; + } + let const_val = mir_operand_get_const_val(fx, operand)?; + if fx.layout_of(ty).size + != const_val.try_to_scalar_int()?.size() + { + return None; + } + computed_const_val = Some(const_val); + } + Rvalue::Use(operand) => { + computed_const_val = mir_operand_get_const_val(fx, operand) + } + _ => return None, + } + } + StatementKind::SetDiscriminant { place: stmt_place, variant_index: _ } + if &**stmt_place == place => + { + return None; + } + StatementKind::LlvmInlineAsm(_) | StatementKind::CopyNonOverlapping(_) => { + return None; + } // conservative handling + StatementKind::Assign(_) + | StatementKind::FakeRead(_) + | StatementKind::SetDiscriminant { .. } + | StatementKind::StorageLive(_) + | StatementKind::StorageDead(_) + | StatementKind::Retag(_, _) + | StatementKind::AscribeUserType(_, _) + | StatementKind::Coverage(_) + | StatementKind::Nop => {} + } + } + match &bb_data.terminator().kind { + TerminatorKind::Goto { .. } + | TerminatorKind::SwitchInt { .. } + | TerminatorKind::Resume + | TerminatorKind::Abort + | TerminatorKind::Return + | TerminatorKind::Unreachable + | TerminatorKind::Drop { .. } + | TerminatorKind::Assert { .. } => {} + TerminatorKind::DropAndReplace { .. } + | TerminatorKind::Yield { .. } + | TerminatorKind::GeneratorDrop + | TerminatorKind::FalseEdge { .. } + | TerminatorKind::FalseUnwind { .. } => unreachable!(), + TerminatorKind::InlineAsm { .. } => return None, + TerminatorKind::Call { destination: Some((call_place, _)), .. } + if call_place == place => + { + return None; + } + TerminatorKind::Call { .. } => {} + } + } + computed_const_val + } } } diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 24d933728db..9cf51d15c8c 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -73,9 +73,8 @@ fn reuse_workproduct_for_cgu( let mut object = None; let work_product = cgu.work_product(tcx); if let Some(saved_file) = &work_product.saved_file { - let obj_out = tcx - .output_filenames(()) - .temp_path(OutputType::Object, Some(&cgu.name().as_str())); + let obj_out = + tcx.output_filenames(()).temp_path(OutputType::Object, Some(&cgu.name().as_str())); object = Some(obj_out.clone()); let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file); if let Err(err) = rustc_fs_util::link_or_copy(&source_file, &obj_out) { @@ -145,7 +144,13 @@ fn module_codegen( } } } - crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, &mut cx.unwind_context, false); + crate::main_shim::maybe_create_entry_wrapper( + tcx, + &mut module, + &mut cx.unwind_context, + false, + cgu.is_primary(), + ); let debug_context = cx.debug_context; let unwind_context = cx.unwind_context; @@ -275,9 +280,8 @@ pub(crate) fn run_aot( .as_str() .to_string(); - let tmp_file = tcx - .output_filenames(()) - .temp_path(OutputType::Metadata, Some(&metadata_cgu_name)); + let tmp_file = + tcx.output_filenames(()).temp_path(OutputType::Metadata, Some(&metadata_cgu_name)); let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| { crate::metadata::write_metadata(tcx, object); @@ -352,8 +356,7 @@ fn codegen_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &str) { .collect::>() .join("\n"); - let output_object_file = - tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name)); + let output_object_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name)); // Assemble `global_asm` let global_asm_object_file = add_file_stem_postfix(output_object_file.clone(), ".asm"); diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 632e86da736..4a99cb727c8 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -45,6 +45,7 @@ fn create_jit_module<'tcx>( &mut jit_module, &mut cx.unwind_context, true, + true, ); (jit_module, cx) @@ -206,7 +207,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { use object::{Object, ObjectSymbol}; let lib = libloading::Library::new(&path).unwrap(); let obj = std::fs::read(path).unwrap(); - let obj = object::File::parse(&obj).unwrap(); + let obj = object::File::parse(&*obj).unwrap(); imported_symbols.extend(obj.dynamic_symbols().filter_map(|symbol| { let name = symbol.name().unwrap().to_string(); if name.is_empty() || !symbol.is_global() || symbol.is_undefined() { diff --git a/src/inline_asm.rs b/src/inline_asm.rs index 4ab4c2957ca..09c5e6031c7 100644 --- a/src/inline_asm.rs +++ b/src/inline_asm.rs @@ -24,14 +24,22 @@ pub(crate) fn codegen_inline_asm<'tcx>( let true_ = fx.bcx.ins().iconst(types::I32, 1); fx.bcx.ins().trapnz(true_, TrapCode::User(1)); return; - } else if template[0] == InlineAsmTemplatePiece::String("mov rsi, rbx".to_string()) - && template[1] == InlineAsmTemplatePiece::String("\n".to_string()) - && template[2] == InlineAsmTemplatePiece::String("cpuid".to_string()) - && template[3] == InlineAsmTemplatePiece::String("\n".to_string()) - && template[4] == InlineAsmTemplatePiece::String("xchg rsi, rbx".to_string()) + } else if template[0] == InlineAsmTemplatePiece::String("movq %rbx, ".to_string()) + && matches!( + template[1], + InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: Some('r'), span: _ } + ) + && template[2] == InlineAsmTemplatePiece::String("\n".to_string()) + && template[3] == InlineAsmTemplatePiece::String("cpuid".to_string()) + && template[4] == InlineAsmTemplatePiece::String("\n".to_string()) + && template[5] == InlineAsmTemplatePiece::String("xchgq %rbx, ".to_string()) + && matches!( + template[6], + InlineAsmTemplatePiece::Placeholder { operand_idx: 0, modifier: Some('r'), span: _ } + ) { assert_eq!(operands.len(), 4); - let (leaf, eax_place) = match operands[0] { + let (leaf, eax_place) = match operands[1] { InlineAsmOperand::InOut { reg, late: true, ref in_value, out_place } => { let reg = expect_reg(reg); assert_eq!(reg, InlineAsmReg::X86(X86InlineAsmReg::ax)); @@ -42,10 +50,14 @@ pub(crate) fn codegen_inline_asm<'tcx>( } _ => unreachable!(), }; - let ebx_place = match operands[1] { + let ebx_place = match operands[0] { InlineAsmOperand::Out { reg, late: true, place } => { - let reg = expect_reg(reg); - assert_eq!(reg, InlineAsmReg::X86(X86InlineAsmReg::si)); + assert_eq!( + reg, + InlineAsmRegOrRegClass::RegClass(InlineAsmRegClass::X86( + X86InlineAsmRegClass::reg + )) + ); crate::base::codegen_place(fx, place.unwrap()) } _ => unreachable!(), diff --git a/src/intrinsics/cpuid.rs b/src/intrinsics/cpuid.rs index 9de12e759bc..d02dfd93c3e 100644 --- a/src/intrinsics/cpuid.rs +++ b/src/intrinsics/cpuid.rs @@ -12,6 +12,7 @@ pub(crate) fn codegen_cpuid_call<'tcx>( ) -> (Value, Value, Value, Value) { let leaf_0 = fx.bcx.create_block(); let leaf_1 = fx.bcx.create_block(); + let leaf_7 = fx.bcx.create_block(); let leaf_8000_0000 = fx.bcx.create_block(); let leaf_8000_0001 = fx.bcx.create_block(); let unsupported_leaf = fx.bcx.create_block(); @@ -25,6 +26,7 @@ pub(crate) fn codegen_cpuid_call<'tcx>( let mut switch = cranelift_frontend::Switch::new(); switch.set_entry(0, leaf_0); switch.set_entry(1, leaf_1); + switch.set_entry(7, leaf_7); switch.set_entry(0x8000_0000, leaf_8000_0000); switch.set_entry(0x8000_0001, leaf_8000_0001); switch.emit(&mut fx.bcx, leaf, unsupported_leaf); @@ -43,6 +45,11 @@ pub(crate) fn codegen_cpuid_call<'tcx>( let edx_features = fx.bcx.ins().iconst(types::I32, 1 << 25 /* sse */ | 1 << 26 /* sse2 */); fx.bcx.ins().jump(dest, &[cpu_signature, additional_information, ecx_features, edx_features]); + fx.bcx.switch_to_block(leaf_7); + // This leaf technically has subleaves, but we just return zero for all subleaves. + let zero = fx.bcx.ins().iconst(types::I32, 0); + fx.bcx.ins().jump(dest, &[zero, zero, zero, zero]); + fx.bcx.switch_to_block(leaf_8000_0000); let extended_max_basic_leaf = fx.bcx.ins().iconst(types::I32, 0); let zero = fx.bcx.ins().iconst(types::I32, 0); diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 435737f3a51..52896fc7127 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -8,8 +8,8 @@ mod simd; pub(crate) use cpuid::codegen_cpuid_call; pub(crate) use llvm::codegen_llvm_intrinsic_call; -use rustc_span::symbol::{sym, kw}; use rustc_middle::ty::print::with_no_trimmed_paths; +use rustc_span::symbol::{kw, sym}; use crate::prelude::*; use cranelift_codegen::ir::AtomicRmwOp; diff --git a/src/lib.rs b/src/lib.rs index ff6e1856059..4ee887cd5af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -256,6 +256,8 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { @@ -277,21 +279,23 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { - let mut builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); + let mut builder = + cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); if let Err(_) = builder.enable(value) { sess.fatal("The specified target cpu isn't currently supported by Cranelift."); } builder } None => { - let mut builder = cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); + let mut builder = + cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); // Don't use "haswell" as the default, as it implies `has_lzcnt`. // macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`. builder.enable("nehalem").unwrap(); builder } }; - + isa_builder.finish(flags) } diff --git a/src/main_shim.rs b/src/main_shim.rs index d1958c5f96b..8fd1e4f5811 100644 --- a/src/main_shim.rs +++ b/src/main_shim.rs @@ -14,6 +14,7 @@ pub(crate) fn maybe_create_entry_wrapper( module: &mut impl Module, unwind_context: &mut UnwindContext, is_jit: bool, + is_primary_cgu: bool, ) { let (main_def_id, is_main_fn) = match tcx.entry_fn(()) { Some((def_id, entry_ty)) => ( @@ -26,8 +27,12 @@ pub(crate) fn maybe_create_entry_wrapper( None => return, }; - let instance = Instance::mono(tcx, main_def_id).polymorphize(tcx); - if !is_jit && module.get_name(&*tcx.symbol_name(instance).name).is_none() { + if main_def_id.is_local() { + let instance = Instance::mono(tcx, main_def_id).polymorphize(tcx); + if !is_jit && module.get_name(&*tcx.symbol_name(instance).name).is_none() { + return; + } + } else if !is_primary_cgu { return; } diff --git a/src/trap.rs b/src/trap.rs index 819c8b51558..21d3e68dbc7 100644 --- a/src/trap.rs +++ b/src/trap.rs @@ -21,7 +21,7 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) { } let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, fx.symbol_name, msg); - let msg_ptr = fx.anonymous_str("trap", &real_msg); + let msg_ptr = fx.anonymous_str(&real_msg); fx.bcx.ins().call(puts, &[msg_ptr]); } diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 9a572c3501f..171f39805f8 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -561,6 +561,7 @@ impl<'tcx> CPlace<'tcx> { dst_align, src_align, true, + MemFlags::trusted(), ); } CValueInner::ByRef(_, Some(_)) => todo!(), -- cgit 1.4.1-3-g733a5 From 4e62376059c0b2421bf5eb1fdeb31cc2768727f1 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 22:05:54 +0200 Subject: Make allocator_kind a query. --- src/allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index 357a9f2daf7..d39486c2f10 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -19,7 +19,7 @@ pub(crate) fn codegen( }); if any_dynamic_crate { false - } else if let Some(kind) = tcx.allocator_kind() { + } else if let Some(kind) = tcx.allocator_kind(()) { codegen_inner(module, unwind_context, kind); true } else { -- cgit 1.4.1-3-g733a5 From 228f1c549da28dd9e740cf8099a23212dab551de Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 29 May 2021 22:49:59 +0200 Subject: Drop metadata_encoding_version. --- src/lib.rs | 1 + src/metadata.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4ee887cd5af..637e91f5117 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ extern crate rustc_fs_util; extern crate rustc_hir; extern crate rustc_incremental; extern crate rustc_index; +extern crate rustc_metadata; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; diff --git a/src/metadata.rs b/src/metadata.rs index ab238244d68..db24bf65eb5 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -10,7 +10,7 @@ pub(crate) fn write_metadata(tcx: TyCtxt<'_>, object: &mut O) use std::io::Write; let metadata = tcx.encode_metadata(); - let mut compressed = tcx.metadata_encoding_version(); + let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap(); object.add_rustc_section( -- cgit 1.4.1-3-g733a5 From d8d6a5aee0b258d5727d647d3943a75e66924932 Mon Sep 17 00:00:00 2001 From: Camille Gillot Date: Tue, 1 Jun 2021 09:05:22 +0200 Subject: Revert "Reduce the amount of untracked state in TyCtxt" --- src/allocator.rs | 2 +- src/lib.rs | 1 - src/metadata.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index d39486c2f10..357a9f2daf7 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -19,7 +19,7 @@ pub(crate) fn codegen( }); if any_dynamic_crate { false - } else if let Some(kind) = tcx.allocator_kind(()) { + } else if let Some(kind) = tcx.allocator_kind() { codegen_inner(module, unwind_context, kind); true } else { diff --git a/src/lib.rs b/src/lib.rs index 637e91f5117..4ee887cd5af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,6 @@ extern crate rustc_fs_util; extern crate rustc_hir; extern crate rustc_incremental; extern crate rustc_index; -extern crate rustc_metadata; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; diff --git a/src/metadata.rs b/src/metadata.rs index db24bf65eb5..ab238244d68 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -10,7 +10,7 @@ pub(crate) fn write_metadata(tcx: TyCtxt<'_>, object: &mut O) use std::io::Write; let metadata = tcx.encode_metadata(); - let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); + let mut compressed = tcx.metadata_encoding_version(); FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap(); object.add_rustc_section( -- cgit 1.4.1-3-g733a5 From f4eb0170aa7d9879f5d96b82d0ca2eb46b622907 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 29 May 2021 22:49:59 +0200 Subject: Drop metadata_encoding_version. --- src/lib.rs | 1 + src/metadata.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4ee887cd5af..637e91f5117 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ extern crate rustc_fs_util; extern crate rustc_hir; extern crate rustc_incremental; extern crate rustc_index; +extern crate rustc_metadata; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; diff --git a/src/metadata.rs b/src/metadata.rs index ab238244d68..db24bf65eb5 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -10,7 +10,7 @@ pub(crate) fn write_metadata(tcx: TyCtxt<'_>, object: &mut O) use std::io::Write; let metadata = tcx.encode_metadata(); - let mut compressed = tcx.metadata_encoding_version(); + let mut compressed = rustc_metadata::METADATA_HEADER.to_vec(); FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap(); object.add_rustc_section( -- cgit 1.4.1-3-g733a5 From b10a4424051dc5017e2c10055c732658be143e7f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 29 May 2021 14:51:27 +0200 Subject: Provide a default provide* implementation for CodegenBackend Both cg_llvm and cg_clif don't override it. cg_spirv does override it, so it needs to be preserved. --- src/lib.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4ee887cd5af..fbef575ba88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,6 @@ use rustc_codegen_ssa::CodegenResults; use rustc_errors::ErrorReported; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader}; -use rustc_middle::ty::query::Providers; use rustc_session::config::OutputFilenames; use rustc_session::Session; @@ -168,9 +167,6 @@ impl CodegenBackend for CraneliftCodegenBackend { Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader) } - fn provide(&self, _providers: &mut Providers) {} - fn provide_extern(&self, _providers: &mut Providers) {} - fn target_features(&self, _sess: &Session) -> Vec { vec![] } -- cgit 1.4.1-3-g733a5 From 20e9a1372b136a1d62d6fb8f5c351260f388eb58 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 29 May 2021 15:00:18 +0200 Subject: Provide default MetadataLoader --- src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fbef575ba88..de2afc49384 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::CodegenResults; use rustc_errors::ErrorReported; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; -use rustc_middle::middle::cstore::{EncodedMetadata, MetadataLoader}; +use rustc_middle::middle::cstore::EncodedMetadata; use rustc_session::config::OutputFilenames; use rustc_session::Session; @@ -163,10 +163,6 @@ impl CodegenBackend for CraneliftCodegenBackend { } } - fn metadata_loader(&self) -> Box { - Box::new(rustc_codegen_ssa::back::metadata::DefaultMetadataLoader) - } - fn target_features(&self, _sess: &Session) -> Vec { vec![] } -- cgit 1.4.1-3-g733a5 From b6f0b46e2004d7a40f2deae0caa5dc22e53e42b7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 29 May 2021 15:14:05 +0200 Subject: Allow printing the version of the default codegen backend if it isn't llvm --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index de2afc49384..fa776bf9921 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,6 +167,10 @@ impl CodegenBackend for CraneliftCodegenBackend { vec![] } + fn print_version(&self) { + println!("Cranelift version: {}", cranelift_codegen::VERSION); + } + fn codegen_crate( &self, tcx: TyCtxt<'_>, -- cgit 1.4.1-3-g733a5 From 646c6043a712c661e6774d3128eab2c1be517ee3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 29 May 2021 17:08:46 +0200 Subject: Move windows_subsystem field from CodegenResults to CrateInfo --- src/driver/aot.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 9cf51d15c8c..2270b18163b 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -177,21 +177,6 @@ pub(crate) fn run_aot( metadata: EncodedMetadata, need_metadata_module: bool, ) -> Box<(CodegenResults, FxHashMap)> { - use rustc_span::symbol::sym; - - let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID); - let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem); - let windows_subsystem = subsystem.map(|subsystem| { - if subsystem != sym::windows && subsystem != sym::console { - tcx.sess.fatal(&format!( - "invalid windows subsystem `{}`, only \ - `windows` and `console` are allowed", - subsystem - )); - } - subsystem.to_string() - }); - let mut work_products = FxHashMap::default(); let cgus = if tcx.sess.opts.output_types.should_codegen() { @@ -312,7 +297,6 @@ pub(crate) fn run_aot( allocator_module, metadata_module, metadata, - windows_subsystem, linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()), crate_info: CrateInfo::new(tcx), }, -- cgit 1.4.1-3-g733a5 From dbdeafbc2688c52e056befee035829d0e30ee924 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 29 May 2021 17:37:38 +0200 Subject: Move crate_name field from OngoingCodegen to CrateInfo --- src/driver/aot.rs | 1 - src/lib.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 2270b18163b..6676d88602c 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -292,7 +292,6 @@ pub(crate) fn run_aot( Box::new(( CodegenResults { - crate_name: tcx.crate_name(LOCAL_CRATE), modules, allocator_module, metadata_module, diff --git a/src/lib.rs b/src/lib.rs index fa776bf9921..904efed5bd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,7 +218,7 @@ impl CodegenBackend for CraneliftCodegenBackend { sess, &codegen_results, outputs, - &codegen_results.crate_name.as_str(), + &codegen_results.crate_info.local_crate_name.as_str(), ); Ok(()) -- cgit 1.4.1-3-g733a5 From 1248ff139d85c0f9f9aec0684d991e62013541b7 Mon Sep 17 00:00:00 2001 From: Richard Cobbe Date: Mon, 8 Mar 2021 12:42:54 -0800 Subject: Add first cut of functionality for #58713: support for #[link(kind = "raw-dylib")]. This does not yet support #[link_name] attributes on functions, the #[link_ordinal] attribute, #[link(kind = "raw-dylib")] on extern blocks in bin crates, or stdcall functions on 32-bit x86. --- src/archive.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/archive.rs b/src/archive.rs index bd54adc53ee..22897c43e7e 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -254,6 +254,15 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { } } } + + fn inject_dll_import_lib( + &mut self, + _lib_name: &str, + _dll_imports: &[rustc_middle::middle::cstore::DllImport], + _tmpdir: &rustc_data_structures::temp_dir::MaybeTempDir, + ) { + bug!("injecting dll imports is not supported"); + } } impl<'a> ArArchiveBuilder<'a> { -- cgit 1.4.1-3-g733a5 From bc9926a29bb9b4f3e5f8e9f20d881f45ebba81cc Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 5 Jun 2021 18:29:28 +0200 Subject: Remove unused dylib_ext variable from build.sh --- build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sh b/build.sh index 76bc1884334..086b9617fdf 100755 --- a/build.sh +++ b/build.sh @@ -34,7 +34,6 @@ if [[ "$unamestr" == 'Linux' || "$unamestr" == "FreeBSD" ]]; then export RUSTFLAGS='-Clink-arg=-Wl,-rpath=$ORIGIN/../lib '$RUSTFLAGS elif [[ "$unamestr" == 'Darwin' ]]; then export RUSTFLAGS='-Csplit-debuginfo=unpacked -Clink-arg=-Wl,-rpath,@loader_path/../lib -Zosx-rpath-install-name '$RUSTFLAGS - dylib_ext='dylib' else echo "Unsupported os $unamestr" exit 1 -- cgit 1.4.1-3-g733a5 From 20beb555655802dc84ba48185b43b61e22d808ad Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Fri, 4 Jun 2021 19:47:28 -0700 Subject: Unify duplicate linker_and_flavor methods in rustc_codegen_{cranelift,ssa}. --- src/toolchain.rs | 90 +------------------------------------------------------- 1 file changed, 1 insertion(+), 89 deletions(-) diff --git a/src/toolchain.rs b/src/toolchain.rs index 49475fe2469..f86236ef3ea 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -2,9 +2,8 @@ use std::path::PathBuf; -use rustc_middle::bug; +use rustc_codegen_ssa::back::link::linker_and_flavor; use rustc_session::Session; -use rustc_target::spec::LinkerFlavor; /// Tries to infer the path of a binary for the target toolchain from the linker name. pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf { @@ -30,90 +29,3 @@ pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf { linker } - -// Adapted from https://github.com/rust-lang/rust/blob/5db778affee7c6600c8e7a177c48282dab3f6292/src/librustc_codegen_ssa/back/link.rs#L848-L931 -fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { - fn infer_from( - sess: &Session, - linker: Option, - flavor: Option, - ) -> Option<(PathBuf, LinkerFlavor)> { - match (linker, flavor) { - (Some(linker), Some(flavor)) => Some((linker, flavor)), - // only the linker flavor is known; use the default linker for the selected flavor - (None, Some(flavor)) => Some(( - PathBuf::from(match flavor { - LinkerFlavor::Em => { - if cfg!(windows) { - "emcc.bat" - } else { - "emcc" - } - } - LinkerFlavor::Gcc => { - if cfg!(any(target_os = "solaris", target_os = "illumos")) { - // On historical Solaris systems, "cc" may have - // been Sun Studio, which is not flag-compatible - // with "gcc". This history casts a long shadow, - // and many modern illumos distributions today - // ship GCC as "gcc" without also making it - // available as "cc". - "gcc" - } else { - "cc" - } - } - LinkerFlavor::Ld => "ld", - LinkerFlavor::Msvc => "link.exe", - LinkerFlavor::Lld(_) => "lld", - LinkerFlavor::PtxLinker => "rust-ptx-linker", - LinkerFlavor::BpfLinker => "bpf-linker", - }), - flavor, - )), - (Some(linker), None) => { - let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| { - sess.fatal("couldn't extract file stem from specified linker") - }); - - let flavor = if stem == "emcc" { - LinkerFlavor::Em - } else if stem == "gcc" - || stem.ends_with("-gcc") - || stem == "clang" - || stem.ends_with("-clang") - { - LinkerFlavor::Gcc - } else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") { - LinkerFlavor::Ld - } else if stem == "link" || stem == "lld-link" { - LinkerFlavor::Msvc - } else if stem == "lld" || stem == "rust-lld" { - LinkerFlavor::Lld(sess.target.lld_flavor) - } else { - // fall back to the value in the target spec - sess.target.linker_flavor - }; - - Some((linker, flavor)) - } - (None, None) => None, - } - } - - // linker and linker flavor specified via command line have precedence over what the target - // specification specifies - if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), sess.opts.cg.linker_flavor) { - return ret; - } - - if let Some(ret) = infer_from( - sess, - sess.target.linker.clone().map(PathBuf::from), - Some(sess.target.linker_flavor), - ) { - return ret; - } - - bug!("Not enough information provided to determine how to invoke the linker"); -} -- cgit 1.4.1-3-g733a5 From a6cce1965934d7344dd77dff53dc74f3a5662d9e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Jun 2021 19:36:12 +0200 Subject: Rustup to rustc 1.54.0-nightly (e4a603270 2021-06-07) --- build_sysroot/Cargo.lock | 2 +- build_sysroot/prepare_sysroot_src.sh | 2 +- rust-toolchain | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 923deb9aec4..518c6ff3b3b 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.43" +version = "0.1.45" dependencies = [ "rustc-std-workspace-core", ] diff --git a/build_sysroot/prepare_sysroot_src.sh b/build_sysroot/prepare_sysroot_src.sh index 54b7a94750c..7032a52a3d3 100755 --- a/build_sysroot/prepare_sysroot_src.sh +++ b/build_sysroot/prepare_sysroot_src.sh @@ -32,7 +32,7 @@ popd git clone https://github.com/rust-lang/compiler-builtins.git || echo "rust-lang/compiler-builtins has already been cloned" pushd compiler-builtins git checkout -- . -git checkout 0.1.43 +git checkout 0.1.45 git apply ../../crate_patches/000*-compiler-builtins-*.patch popd diff --git a/rust-toolchain b/rust-toolchain index 9fe6e093a7b..92de398cc8b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-05-26" +channel = "nightly-2021-06-08" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -- cgit 1.4.1-3-g733a5 From 0d68742d37318a7eae1372a3c0ee3452d2d35bba Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Jun 2021 20:12:29 +0200 Subject: Ignore unsupported test --- scripts/test_rustc_tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 347fb40e6f9..428c2480684 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -64,6 +64,7 @@ rm src/test/incremental/lto.rs # requires lto rm -r src/test/run-make/emit-shared-files # requires the rustdoc executable in build/bin/ rm -r src/test/run-make/unstable-flag-required # same +rm -r src/test/run-make/emit-named-files # requires full --emit support rm src/test/pretty/asm.rs # inline asm rm src/test/pretty/raw-str-nonexpr.rs # same -- cgit 1.4.1-3-g733a5 From b7180ae39a5be0884c7be8afa61290cc1cf7451a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 10 Jun 2021 10:16:49 +0200 Subject: Add missing cargo clean when cross-compiling --- scripts/tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tests.sh b/scripts/tests.sh index 0d99d2c507c..243a0ef2851 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -96,6 +96,7 @@ function extended_sysroot_tests() { cp ./target/debug/main ./raytracer_cg_clif hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif else + cargo clean echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)" echo "[COMPILE] ebobby/simple-raytracer" ../build/cargo.sh build --target $TARGET_TRIPLE -- cgit 1.4.1-3-g733a5 From 84dd22969f79da4a417b4c424a7095522d4b83c5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 10 Jun 2021 10:19:58 +0200 Subject: Include rustc and cranelift version in debuginfo --- src/debuginfo/mod.rs | 8 +++++--- src/lib.rs | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 61e54a76f29..c67336eb3f2 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -61,9 +61,11 @@ impl<'tcx> DebugContext<'tcx> { let mut dwarf = DwarfUnit::new(encoding); - // FIXME: how to get version when building out of tree? - // Normally this would use option_env!("CFG_VERSION"). - let producer = format!("cg_clif (rustc {})", "unknown version"); + let producer = format!( + "cg_clif (rustc {}, cranelift {})", + rustc_interface::util::version_str().unwrap_or("unknown version"), + cranelift_codegen::VERSION, + ); let comp_dir = tcx.sess.working_dir.to_string_lossy(false).into_owned(); let (name, file_info) = match tcx.sess.local_crate_source_file.clone() { Some(path) => { diff --git a/src/lib.rs b/src/lib.rs index 904efed5bd9..cfc5902cbe3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ extern crate rustc_fs_util; extern crate rustc_hir; extern crate rustc_incremental; extern crate rustc_index; +extern crate rustc_interface; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; -- cgit 1.4.1-3-g733a5 From ae1bcb209a010a23858ca37117a2d57464034aba Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 10 Jun 2021 10:46:00 +0200 Subject: Use -Cprefer-dynamic for all crates in jit mode --- scripts/cargo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cargo.sh b/scripts/cargo.sh index 1daa5a78f7b..267b5d99a08 100755 --- a/scripts/cargo.sh +++ b/scripts/cargo.sh @@ -10,9 +10,9 @@ cmd=$1 shift || true if [[ "$cmd" = "jit" ]]; then -cargo "+${TOOLCHAIN}" rustc "$@" -- -Cllvm-args=mode=jit -Cprefer-dynamic +RUSTFLAGS="-Cprefer-dynamic" cargo "+${TOOLCHAIN}" rustc "$@" -- -Cllvm-args=mode=jit elif [[ "$cmd" = "lazy-jit" ]]; then -cargo "+${TOOLCHAIN}" rustc "$@" -- -Cllvm-args=mode=jit-lazy -Cprefer-dynamic +RUSTFLAGS="-Cprefer-dynamic" cargo "+${TOOLCHAIN}" rustc "$@" -- -Cllvm-args=mode=jit-lazy else cargo "+${TOOLCHAIN}" "$cmd" "$@" fi -- cgit 1.4.1-3-g733a5 From 4492f32d155dcee58f9550387c38231e10570878 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 10 Jun 2021 12:17:42 +0200 Subject: Update Cranelift and object --- Cargo.lock | 51 +++++++++++++++++++++++++++++---------------------- Cargo.toml | 2 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a6f5925149b..964a002d92e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,16 +33,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -57,8 +57,8 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -66,18 +66,18 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" [[package]] name = "cranelift-entity" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" [[package]] name = "cranelift-frontend" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "cranelift-codegen", "log", @@ -87,8 +87,8 @@ dependencies = [ [[package]] name = "cranelift-jit" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "anyhow", "cranelift-codegen", @@ -104,8 +104,8 @@ dependencies = [ [[package]] name = "cranelift-module" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "anyhow", "cranelift-codegen", @@ -115,8 +115,8 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "cranelift-codegen", "target-lexicon", @@ -124,8 +124,8 @@ dependencies = [ [[package]] name = "cranelift-object" -version = "0.74.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600" +version = "0.75.0" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" dependencies = [ "anyhow", "cranelift-codegen", @@ -203,14 +203,21 @@ dependencies = [ "libc", ] +[[package]] +name = "memchr" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" + [[package]] name = "object" -version = "0.24.0" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a5b3dd1c072ee7963717671d1ca129f1048fda25edea6b752bfc71ac8854170" +checksum = "f8bc1d42047cf336f0f939c99e97183cf31551bf0f2865a2ec9c8d91fd4ffb5e" dependencies = [ "crc32fast", "indexmap", + "memchr", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index fd149af4547..1bd7b89ac0a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", bran cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } target-lexicon = "0.12.0" gimli = { version = "0.24.0", default-features = false, features = ["write"]} -object = { version = "0.24.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } +object = { version = "0.25.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] } ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" } indexmap = "1.0.2" -- cgit 1.4.1-3-g733a5 From 75eff64977ff149ead73bc0077bac5872d599aa2 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 10 Jun 2021 12:18:10 +0200 Subject: Enable cross-compilation support in Cranelift --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1bd7b89ac0a..ef68d7ee532 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["dylib"] [dependencies] # These have to be in sync with each other -cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main", features = ["unwind"] } +cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main", features = ["unwind", "all-arch"] } cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" } -- cgit 1.4.1-3-g733a5 From d3e123fc4f8c2907db8a88e851ecb5149fa7670f Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Mon, 14 Jun 2021 18:02:53 +0800 Subject: Refactor to make interpreter and codegen backend neutral to vtable internal representation. --- src/vtable.rs | 72 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/src/vtable.rs b/src/vtable.rs index bbf07ffc85d..4d1ee47b41e 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -4,10 +4,7 @@ // FIXME dedup this logic between miri, cg_llvm and cg_clif use crate::prelude::*; - -const DROP_FN_INDEX: usize = 0; -const SIZE_INDEX: usize = 1; -const ALIGN_INDEX: usize = 2; +use ty::VtblEntry; fn vtable_memflags() -> MemFlags { let mut flags = MemFlags::trusted(); // A vtable access is always aligned and will never trap. @@ -21,7 +18,7 @@ pub(crate) fn drop_fn_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> pointer_ty(fx.tcx), vtable_memflags(), vtable, - (DROP_FN_INDEX * usize_size) as i32, + (ty::COMMON_VTABLE_ENTRIES_DROPINPLACE * usize_size) as i32, ) } @@ -31,7 +28,7 @@ pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> Val pointer_ty(fx.tcx), vtable_memflags(), vtable, - (SIZE_INDEX * usize_size) as i32, + (ty::COMMON_VTABLE_ENTRIES_SIZE * usize_size) as i32, ) } @@ -41,7 +38,7 @@ pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) - pointer_ty(fx.tcx), vtable_memflags(), vtable, - (ALIGN_INDEX * usize_size) as i32, + (ty::COMMON_VTABLE_ENTRIES_SIZE * usize_size) as i32, ) } @@ -62,7 +59,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( pointer_ty(fx.tcx), vtable_memflags(), vtable, - ((idx + 3) * usize_size as usize) as i32, + (idx * usize_size as usize) as i32, ); (ptr, func_ref) } @@ -98,42 +95,49 @@ fn build_vtable<'tcx>( Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fx.tcx), ); - let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None]; - - let methods_root; - let methods = if let Some(trait_ref) = trait_ref { - methods_root = tcx.vtable_methods(trait_ref.with_self_ty(tcx, layout.ty)); - methods_root.iter() + let vtable_entries = if let Some(trait_ref) = trait_ref { + tcx.vtable_entries(trait_ref.with_self_ty(tcx, layout.ty)) } else { - (&[]).iter() + ty::COMMON_VTABLE_ENTRIES }; - let methods = methods.cloned().map(|opt_mth| { - opt_mth.map(|(def_id, substs)| { - import_function( - tcx, - fx.module, - Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), def_id, substs) - .unwrap() - .polymorphize(fx.tcx), - ) - }) - }); - components.extend(methods); let mut data_ctx = DataContext::new(); let mut data = ::std::iter::repeat(0u8) - .take(components.len() * usize_size) + .take(vtable_entries.len() * usize_size) .collect::>() .into_boxed_slice(); - write_usize(fx.tcx, &mut data, SIZE_INDEX, layout.size.bytes()); - write_usize(fx.tcx, &mut data, ALIGN_INDEX, layout.align.abi.bytes()); + for (idx, entry) in vtable_entries.iter().enumerate() { + match entry { + VtblEntry::MetadataSize => { + write_usize(fx.tcx, &mut data, idx, layout.size.bytes()); + } + VtblEntry::MetadataAlign => { + write_usize(fx.tcx, &mut data, idx, layout.align.abi.bytes()); + } + VtblEntry::MetadataDropInPlace | VtblEntry::Vacant | VtblEntry::Method(_, _) => {} + } + } data_ctx.define(data); - for (i, component) in components.into_iter().enumerate() { - if let Some(func_id) = component { - let func_ref = fx.module.declare_func_in_data(func_id, &mut data_ctx); - data_ctx.write_function_addr((i * usize_size) as u32, func_ref); + for (idx, entry) in vtable_entries.iter().enumerate() { + match entry { + VtblEntry::MetadataDropInPlace => { + let func_ref = fx.module.declare_func_in_data(drop_in_place_fn, &mut data_ctx); + data_ctx.write_function_addr((idx * usize_size) as u32, func_ref); + } + VtblEntry::Method(def_id, substs) => { + let func_id = import_function( + tcx, + fx.module, + Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), *def_id, substs) + .unwrap() + .polymorphize(fx.tcx), + ); + let func_ref = fx.module.declare_func_in_data(func_id, &mut data_ctx); + data_ctx.write_function_addr((idx * usize_size) as u32, func_ref); + } + VtblEntry::MetadataSize | VtblEntry::MetadataAlign | VtblEntry::Vacant => {} } } -- cgit 1.4.1-3-g733a5 From 8923e42a05b59022ffcc163d9e9b13c9de1189c9 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Mon, 14 Jun 2021 23:40:09 +0200 Subject: Use the now available implementation of `IntoIterator` for arrays --- src/compiler_builtins.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler_builtins.rs b/src/compiler_builtins.rs index 177f850afb3..100c3b43160 100644 --- a/src/compiler_builtins.rs +++ b/src/compiler_builtins.rs @@ -7,7 +7,7 @@ macro builtin_functions($register:ident; $(fn $name:ident($($arg_name:ident: $ar #[cfg(feature = "jit")] pub(crate) fn $register(builder: &mut cranelift_jit::JITBuilder) { - for &(name, val) in &[$((stringify!($name), $name as *const u8)),*] { + for (name, val) in [$((stringify!($name), $name as *const u8)),*] { builder.symbol(name, val); } } -- cgit 1.4.1-3-g733a5 From 432285fbc69ab0396f8226beb9fe2ef1496f73da Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 15 Jun 2021 13:41:46 +0200 Subject: Implement llvm.x86.addcarry.64 and llvm.x86.subborrow.64 (#1178) --- src/intrinsics/llvm.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index ba4ed2162cd..0b5435285b4 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -106,6 +106,26 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( let dest = CPlace::for_ptr(Pointer::new(mem_addr), a.layout()); dest.write_cvalue(fx, a); }; + "llvm.x86.addcarry.64", (v c_in, c a, c b) { + llvm_add_sub( + fx, + BinOp::Add, + ret, + c_in, + a, + b + ); + }; + "llvm.x86.subborrow.64", (v b_in, c a, c b) { + llvm_add_sub( + fx, + BinOp::Sub, + ret, + b_in, + a, + b + ); + }; } if let Some((_, dest)) = destination { @@ -121,3 +141,43 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>( // llvm.x86.avx2.pshuf.b // llvm.x86.avx2.psrli.w // llvm.x86.sse2.psrli.w + +fn llvm_add_sub<'tcx>( + fx: &mut FunctionCx<'_, '_, 'tcx>, + bin_op: BinOp, + ret: CPlace<'tcx>, + cb_in: Value, + a: CValue<'tcx>, + b: CValue<'tcx> +) { + assert_eq!(a.layout().ty, fx.tcx.types.u64, "llvm.x86.addcarry.64/llvm.x86.subborrow.64 second operand must be u64"); + assert_eq!(b.layout().ty, fx.tcx.types.u64, "llvm.x86.addcarry.64/llvm.x86.subborrow.64 third operand must be u64"); + + // c + carry -> c + first intermediate carry or borrow respectively + let int0 = crate::num::codegen_checked_int_binop( + fx, + bin_op, + a, + b, + ); + let c = int0.value_field(fx, mir::Field::new(0)); + let cb0 = int0.value_field(fx, mir::Field::new(1)).load_scalar(fx); + + // c + carry -> c + second intermediate carry or borrow respectively + let cb_in_as_u64 = fx.bcx.ins().uextend(types::I64, cb_in); + let cb_in_as_u64 = CValue::by_val(cb_in_as_u64, fx.layout_of(fx.tcx.types.u64)); + let int1 = crate::num::codegen_checked_int_binop( + fx, + bin_op, + c, + cb_in_as_u64, + ); + let (c, cb1) = int1.load_scalar_pair(fx); + + // carry0 | carry1 -> carry or borrow respectively + let cb_out = fx.bcx.ins().bor(cb0, cb1); + + let layout = fx.layout_of(fx.tcx.mk_tup([fx.tcx.types.u8, fx.tcx.types.u64].iter())); + let val = CValue::by_val_pair(cb_out, c, layout); + ret.write_cvalue(fx, val); +} -- cgit 1.4.1-3-g733a5 From 2945b96e587e162a52c66dfaa95aec8944b11797 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Wed, 28 Apr 2021 14:44:18 +0100 Subject: Multithreading support for lazy-jit --- src/driver/jit.rs | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++----- src/lib.rs | 9 ++++++- 2 files changed, 82 insertions(+), 8 deletions(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 4a99cb727c8..3d8f837a66c 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -3,7 +3,9 @@ use std::cell::RefCell; use std::ffi::CString; +use std::lazy::{Lazy, SyncOnceCell}; use std::os::raw::{c_char, c_int}; +use std::sync::{mpsc, Mutex}; use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_codegen_ssa::CrateInfo; @@ -23,6 +25,39 @@ thread_local! { static LAZY_JIT_STATE: RefCell> = RefCell::new(None); } +/// The Sender owned by the rustc thread +static GLOBAL_MESSAGE_SENDER: SyncOnceCell>> = SyncOnceCell::new(); + +/// A message that is sent from the jitted runtime to the rustc thread. +/// Senders are responsible for upholding `Send` semantics. +enum UnsafeMessage { + /// Request that the specified `Instance` be lazily jitted. + /// + /// Nothing accessible through `instance_ptr` may be moved or mutated by the sender after + /// this message is sent. + JitFn { + instance_ptr: *const Instance<'static>, + tx: mpsc::Sender<*const u8>, + }, +} +unsafe impl Send for UnsafeMessage {} + +impl UnsafeMessage { + /// Send the message. + fn send(self) -> Result<(), mpsc::SendError> { + thread_local! { + /// The Sender owned by the local thread + static LOCAL_MESSAGE_SENDER: Lazy> = Lazy::new(|| + GLOBAL_MESSAGE_SENDER + .get().unwrap() + .lock().unwrap() + .clone() + ); + } + LOCAL_MESSAGE_SENDER.with(|sender| sender.send(self)) + } +} + fn create_jit_module<'tcx>( tcx: TyCtxt<'tcx>, backend_config: &BackendConfig, @@ -116,11 +151,6 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { .chain(backend_config.jit_args.iter().map(|arg| &**arg)) .map(|arg| CString::new(arg).unwrap()) .collect::>(); - let mut argv = args.iter().map(|arg| arg.as_ptr()).collect::>(); - - // Push a null pointer as a terminating argument. This is required by POSIX and - // useful as some dynamic linkers use it as a marker to jump over. - argv.push(std::ptr::null()); let start_sig = Signature { params: vec![ @@ -141,12 +171,49 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { let f: extern "C" fn(c_int, *const *const c_char) -> c_int = unsafe { ::std::mem::transmute(finalized_start) }; - let ret = f(args.len() as c_int, argv.as_ptr()); - std::process::exit(ret); + + let (tx, rx) = mpsc::channel(); + GLOBAL_MESSAGE_SENDER.set(Mutex::new(tx)).unwrap(); + + // Spawn the jitted runtime in a new thread so that this rustc thread can handle messages + // (eg to lazily JIT further functions as required) + std::thread::spawn(move || { + let mut argv = args.iter().map(|arg| arg.as_ptr()).collect::>(); + + // Push a null pointer as a terminating argument. This is required by POSIX and + // useful as some dynamic linkers use it as a marker to jump over. + argv.push(std::ptr::null()); + + let ret = f(args.len() as c_int, argv.as_ptr()); + std::process::exit(ret); + }); + + // Handle messages + loop { + match rx.recv().unwrap() { + // lazy JIT compilation request - compile requested instance and return pointer to result + UnsafeMessage::JitFn { instance_ptr, tx } => { + tx.send(jit_fn(instance_ptr)) + .expect("jitted runtime hung up before response to lazy JIT request was sent"); + } + } + } } #[no_mangle] extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8 { + // send the JIT request to the rustc thread, with a channel for the response + let (tx, rx) = mpsc::channel(); + UnsafeMessage::JitFn { instance_ptr, tx } + .send() + .expect("rustc thread hung up before lazy JIT request was sent"); + + // block on JIT compilation result + rx.recv() + .expect("rustc thread hung up before responding to sent lazy JIT request") +} + +fn jit_fn(instance_ptr: *const Instance<'static>) -> *const u8 { rustc_middle::ty::tls::with(|tcx| { // lift is used to ensure the correct lifetime for instance. let instance = tcx.lift(unsafe { *instance_ptr }).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index cfc5902cbe3..91ef6265938 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,11 @@ -#![feature(rustc_private, decl_macro, never_type, hash_drain_filter, vec_into_raw_parts)] +#![feature( + rustc_private, + decl_macro, + never_type, + hash_drain_filter, + vec_into_raw_parts, + once_cell, +)] #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] -- cgit 1.4.1-3-g733a5 From 4a7068dbfc87ab3af3fc8a1e5ca9a346c8787fcb Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Thu, 29 Apr 2021 00:01:59 +0100 Subject: Ensure Instances are only jitted once --- src/driver/jit.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 3d8f837a66c..39a39e764cb 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -37,6 +37,7 @@ enum UnsafeMessage { /// this message is sent. JitFn { instance_ptr: *const Instance<'static>, + trampoline_ptr: *const u8, tx: mpsc::Sender<*const u8>, }, } @@ -192,8 +193,8 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { loop { match rx.recv().unwrap() { // lazy JIT compilation request - compile requested instance and return pointer to result - UnsafeMessage::JitFn { instance_ptr, tx } => { - tx.send(jit_fn(instance_ptr)) + UnsafeMessage::JitFn { instance_ptr, trampoline_ptr, tx } => { + tx.send(jit_fn(instance_ptr, trampoline_ptr)) .expect("jitted runtime hung up before response to lazy JIT request was sent"); } } @@ -201,10 +202,10 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { } #[no_mangle] -extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8 { +extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> *const u8 { // send the JIT request to the rustc thread, with a channel for the response let (tx, rx) = mpsc::channel(); - UnsafeMessage::JitFn { instance_ptr, tx } + UnsafeMessage::JitFn { instance_ptr, trampoline_ptr, tx } .send() .expect("rustc thread hung up before lazy JIT request was sent"); @@ -213,7 +214,7 @@ extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>) -> *const u8 .expect("rustc thread hung up before responding to sent lazy JIT request") } -fn jit_fn(instance_ptr: *const Instance<'static>) -> *const u8 { +fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> *const u8 { rustc_middle::ty::tls::with(|tcx| { // lift is used to ensure the correct lifetime for instance. let instance = tcx.lift(unsafe { *instance_ptr }).unwrap(); @@ -227,6 +228,17 @@ fn jit_fn(instance_ptr: *const Instance<'static>) -> *const u8 { let name = tcx.symbol_name(instance).name; let sig = crate::abi::get_function_sig(tcx, jit_module.isa().triple(), instance); let func_id = jit_module.declare_function(name, Linkage::Export, &sig).unwrap(); + + let current_ptr = jit_module.read_got_entry(func_id); + + // If the function's GOT entry has already been updated to point at something other + // than the shim trampoline, don't re-jit but just return the new pointer instead. + // This does not need synchronization as this code is executed only by a sole rustc + // thread. + if current_ptr != trampoline_ptr { + return current_ptr; + } + jit_module.prepare_for_function_redefine(func_id).unwrap(); let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module.isa(), false); @@ -321,7 +333,7 @@ fn codegen_shim<'tcx>(cx: &mut CodegenCx<'tcx>, module: &mut JITModule, inst: In Linkage::Import, &Signature { call_conv: module.target_config().default_call_conv, - params: vec![AbiParam::new(pointer_type)], + params: vec![AbiParam::new(pointer_type), AbiParam::new(pointer_type)], returns: vec![AbiParam::new(pointer_type)], }, ) @@ -334,6 +346,7 @@ fn codegen_shim<'tcx>(cx: &mut CodegenCx<'tcx>, module: &mut JITModule, inst: In let mut builder_ctx = FunctionBuilderContext::new(); let mut trampoline_builder = FunctionBuilder::new(trampoline, &mut builder_ctx); + let trampoline_fn = module.declare_func_in_func(func_id, trampoline_builder.func); let jit_fn = module.declare_func_in_func(jit_fn, trampoline_builder.func); let sig_ref = trampoline_builder.func.import_signature(sig); @@ -343,7 +356,8 @@ fn codegen_shim<'tcx>(cx: &mut CodegenCx<'tcx>, module: &mut JITModule, inst: In trampoline_builder.switch_to_block(entry_block); let instance_ptr = trampoline_builder.ins().iconst(pointer_type, instance_ptr as u64 as i64); - let jitted_fn = trampoline_builder.ins().call(jit_fn, &[instance_ptr]); + let trampoline_ptr = trampoline_builder.ins().func_addr(pointer_type, trampoline_fn); + let jitted_fn = trampoline_builder.ins().call(jit_fn, &[instance_ptr, trampoline_ptr]); let jitted_fn = trampoline_builder.func.dfg.inst_results(jitted_fn)[0]; let call_inst = trampoline_builder.ins().call_indirect(sig_ref, jitted_fn, &fn_args); let ret_vals = trampoline_builder.func.dfg.inst_results(call_inst).to_vec(); -- cgit 1.4.1-3-g733a5 From 5c783242150f491757231e1fff1830bf1bd6a435 Mon Sep 17 00:00:00 2001 From: Alan Egerton Date: Thu, 17 Jun 2021 09:51:04 +0100 Subject: Remove lack of mulithreading support from usage.md --- docs/usage.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 3eee3b554e3..68e62da9ac3 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -40,8 +40,7 @@ $ $cg_clif_dir/build/bin/cg_clif -Cllvm-args=mode=jit -Cprefer-dynamic my_crate. ``` There is also an experimental lazy jit mode. In this mode functions are only compiled once they are -first called. It currently does not work with multi-threaded programs. When a not yet compiled -function is called from another thread than the main thread, you will get an ICE. +first called. ```bash $ $cg_clif_dir/build/cargo.sh lazy-jit -- cgit 1.4.1-3-g733a5 From a12e23bc7eaf491912e4f9887db984fe25636e1e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 17 Jun 2021 15:36:32 +0200 Subject: Rustup to rustc 1.55.0-nightly (a85f584ae 2021-06-16) --- build_sysroot/Cargo.lock | 4 ++-- rust-toolchain | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index 518c6ff3b3b..bcf692f1dc6 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" dependencies = [ "rustc-std-workspace-core", ] diff --git a/rust-toolchain b/rust-toolchain index 92de398cc8b..6cb05bef6d3 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-06-08" +channel = "nightly-2021-06-17" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -- cgit 1.4.1-3-g733a5 From ab7f1c8a0ebc39ec0a07b806980aca38413f9e90 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 17 Jun 2021 18:41:43 +0200 Subject: Fix miscompilation in vtable access Fixes #1179 --- src/vtable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vtable.rs b/src/vtable.rs index 4d1ee47b41e..3f78501bcb0 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -38,7 +38,7 @@ pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) - pointer_ty(fx.tcx), vtable_memflags(), vtable, - (ty::COMMON_VTABLE_ENTRIES_SIZE * usize_size) as i32, + (ty::COMMON_VTABLE_ENTRIES_ALIGN * usize_size) as i32, ) } -- cgit 1.4.1-3-g733a5 From 0ddb937624265f167f66b034422252d00801cd29 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 17 Jun 2021 18:42:09 +0200 Subject: Update rust patch for compiler_builtins update --- scripts/setup_rust_fork.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index 43c4887669c..b52ca6ea2ad 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -33,7 +33,7 @@ index d95b5b7f17f..00b6f0e3635 100644 [dependencies] core = { path = "../core" } -compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] } -+compiler_builtins = { version = "0.1.43", features = ['rustc-dep-of-std', 'no-asm'] } ++compiler_builtins = { version = "0.1.45", features = ['rustc-dep-of-std', 'no-asm'] } [dev-dependencies] rand = "0.7" -- cgit 1.4.1-3-g733a5 From 2db4e50618faf277aa6e7b0b45b6fc1aa5389653 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 8 Jun 2021 14:33:25 +0200 Subject: Rewrite build.sh in rust This makes it easier to compile cg_clif on systems that don't support bash shell scripts like Windows --- .gitignore | 1 + .vscode/settings.json | 17 +++++ build.sh | 88 -------------------------- build_system/build_backend.rs | 41 ++++++++++++ build_system/build_sysroot.rs | 128 ++++++++++++++++++++++++++++++++++++++ build_system/rustc_info.rs | 41 ++++++++++++ scripts/setup_rust_fork.sh | 2 +- test.sh | 4 +- y.rs | 141 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 372 insertions(+), 91 deletions(-) delete mode 100755 build.sh create mode 100644 build_system/build_backend.rs create mode 100644 build_system/build_sysroot.rs create mode 100644 build_system/rustc_info.rs create mode 100755 y.rs diff --git a/.gitignore b/.gitignore index b241bef9d1e..3e010204655 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ perf.data perf.data.old *.events *.string* +/y.bin /build /build_sysroot/sysroot_src /build_sysroot/compiler-builtins diff --git a/.vscode/settings.json b/.vscode/settings.json index 9009a532c54..cec110792ce 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -49,6 +49,23 @@ "cfg": [], }, ] + }, + { + "roots": ["./y.rs"], + "crates": [ + { + "root_module": "./y.rs", + "edition": "2018", + "deps": [{ "crate": 1, "name": "std" }], + "cfg": [], + }, + { + "root_module": "./build_sysroot/sysroot_src/library/std/src/lib.rs", + "edition": "2018", + "deps": [], + "cfg": [], + }, + ] } ] } diff --git a/build.sh b/build.sh deleted file mode 100755 index 086b9617fdf..00000000000 --- a/build.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash -set -e - -# Settings -export CHANNEL="release" -build_sysroot="clif" -target_dir='build' -while [[ $# != 0 ]]; do - case $1 in - "--debug") - export CHANNEL="debug" - ;; - "--sysroot") - build_sysroot=$2 - shift - ;; - "--target-dir") - target_dir=$2 - shift - ;; - *) - echo "Unknown flag '$1'" - echo "Usage: ./build.sh [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]" - exit 1 - ;; - esac - shift -done - -# Build cg_clif -unset CARGO_TARGET_DIR -unamestr=$(uname) -if [[ "$unamestr" == 'Linux' || "$unamestr" == "FreeBSD" ]]; then - export RUSTFLAGS='-Clink-arg=-Wl,-rpath=$ORIGIN/../lib '$RUSTFLAGS -elif [[ "$unamestr" == 'Darwin' ]]; then - export RUSTFLAGS='-Csplit-debuginfo=unpacked -Clink-arg=-Wl,-rpath,@loader_path/../lib -Zosx-rpath-install-name '$RUSTFLAGS -else - echo "Unsupported os $unamestr" - exit 1 -fi -if [[ "$CHANNEL" == "release" ]]; then - cargo build --release -else - cargo build -fi - -source scripts/ext_config.sh - -rm -rf "$target_dir" -mkdir "$target_dir" -mkdir "$target_dir"/bin "$target_dir"/lib -ln target/$CHANNEL/cg_clif{,_build_sysroot} "$target_dir"/bin -ln target/$CHANNEL/*rustc_codegen_cranelift* "$target_dir"/lib -ln rust-toolchain scripts/config.sh scripts/cargo.sh "$target_dir" - -mkdir -p "$target_dir/lib/rustlib/$TARGET_TRIPLE/lib/" -mkdir -p "$target_dir/lib/rustlib/$HOST_TRIPLE/lib/" -if [[ "$TARGET_TRIPLE" == "x86_64-pc-windows-gnu" ]]; then - cp $(rustc --print sysroot)/lib/rustlib/$TARGET_TRIPLE/lib/*.o "$target_dir/lib/rustlib/$TARGET_TRIPLE/lib/" -fi - -case "$build_sysroot" in - "none") - ;; - "llvm") - cp -r $(rustc --print sysroot)/lib/rustlib/$TARGET_TRIPLE/lib "$target_dir/lib/rustlib/$TARGET_TRIPLE/" - if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then - cp -r $(rustc --print sysroot)/lib/rustlib/$HOST_TRIPLE/lib "$target_dir/lib/rustlib/$HOST_TRIPLE/" - fi - ;; - "clif") - echo "[BUILD] sysroot" - dir=$(pwd) - cd "$target_dir" - time "$dir/build_sysroot/build_sysroot.sh" - if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then - time TARGET_TRIPLE="$HOST_TRIPLE" "$dir/build_sysroot/build_sysroot.sh" - fi - cp lib/rustlib/*/lib/libstd-* lib/ - ;; - *) - echo "Unknown sysroot kind \`$build_sysroot\`." - echo "The allowed values are:" - echo " none A sysroot that doesn't contain the standard library" - echo " llvm Copy the sysroot from rustc compiled by cg_llvm" - echo " clif Build a new sysroot using cg_clif" - exit 1 -esac diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs new file mode 100644 index 00000000000..cdddeae2a33 --- /dev/null +++ b/build_system/build_backend.rs @@ -0,0 +1,41 @@ +use std::env; +use std::process::{self, Command}; + +pub(crate) fn build_backend(channel: &str) -> String { + let mut cmd = Command::new("cargo"); + cmd.arg("build"); + + match channel { + "debug" => {} + "release" => { + cmd.arg("--release"); + } + _ => unreachable!(), + } + + if cfg!(unix) { + if cfg!(target_os = "macos") { + cmd.env( + "RUSTFLAGS", + "-Csplit-debuginfo=unpacked \ + -Clink-arg=-Wl,-rpath,@loader_path/../lib \ + -Zosx-rpath-install-name" + .to_string() + + env::var("RUSTFLAGS").as_deref().unwrap_or(""), + ); + } else { + cmd.env( + "RUSTFLAGS", + "-Clink-arg=-Wl,-rpath=$ORIGIN/../lib ".to_string() + + env::var("RUSTFLAGS").as_deref().unwrap_or(""), + ); + } + } + + eprintln!("[BUILD] rustc_codegen_cranelift"); + if !cmd.spawn().unwrap().wait().unwrap().success() { + process::exit(1); + } + + crate::rustc_info::get_dylib_name("rustc_codegen_cranelift") +} diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs new file mode 100644 index 00000000000..d6ac19dd1cc --- /dev/null +++ b/build_system/build_sysroot.rs @@ -0,0 +1,128 @@ +use crate::{try_hard_link, SysrootKind}; +use std::env; +use std::fs; +use std::path::Path; +use std::process::{self, Command}; + +pub(crate) fn build_sysroot( + channel: &str, + sysroot_kind: SysrootKind, + target_dir: &Path, + cg_clif_dylib: String, + host_triple: &str, + target_triple: &str, +) { + if target_dir.exists() { + fs::remove_dir_all(target_dir).unwrap(); + } + fs::create_dir_all(target_dir.join("bin")).unwrap(); + fs::create_dir_all(target_dir.join("lib")).unwrap(); + + // Copy the backend + for file in ["cg_clif", "cg_clif_build_sysroot"] { + try_hard_link( + Path::new("target").join(channel).join(file), + target_dir.join("bin").join(file), + ); + } + + try_hard_link( + Path::new("target").join(channel).join(&cg_clif_dylib), + target_dir.join("lib").join(cg_clif_dylib), + ); + + // Copy supporting files + try_hard_link("rust-toolchain", target_dir.join("rust-toolchain")); + try_hard_link("scripts/config.sh", target_dir.join("config.sh")); + try_hard_link("scripts/cargo.sh", target_dir.join("cargo.sh")); + + let default_sysroot = crate::rustc_info::get_default_sysroot(); + + let rustlib = target_dir.join("lib").join("rustlib"); + let host_rustlib_lib = rustlib.join(host_triple).join("lib"); + let target_rustlib_lib = rustlib.join(target_triple).join("lib"); + fs::create_dir_all(&host_rustlib_lib).unwrap(); + fs::create_dir_all(&target_rustlib_lib).unwrap(); + + if target_triple == "x86_64-pc-windows-gnu" { + if !default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib").exists() { + eprintln!( + "The x86_64-pc-windows-gnu target needs to be installed first before it is possible \ + to compile a sysroot for it.", + ); + process::exit(1); + } + for file in fs::read_dir( + default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"), + ) + .unwrap() + { + let file = file.unwrap().path(); + if file.extension().map_or(true, |ext| ext.to_str().unwrap() != "o") { + continue; // only copy object files + } + try_hard_link(&file, target_rustlib_lib.join(file.file_name().unwrap())); + } + } + + match sysroot_kind { + SysrootKind::None => {} // Nothing to do + SysrootKind::Llvm => { + for file in fs::read_dir( + default_sysroot.join("lib").join("rustlib").join(host_triple).join("lib"), + ) + .unwrap() + { + let file = file.unwrap().path(); + let file_name_str = file.file_name().unwrap().to_str().unwrap(); + if file_name_str.contains("rustc_") + || file_name_str.contains("chalk") + || file_name_str.contains("tracing") + || file_name_str.contains("regex") + { + // These are large crates that are part of the rustc-dev component and are not + // necessary to run regular programs. + continue; + } + try_hard_link(&file, host_rustlib_lib.join(file.file_name().unwrap())); + } + + if target_triple != host_triple { + for file in fs::read_dir( + default_sysroot.join("lib").join("rustlib").join(target_triple).join("lib"), + ) + .unwrap() + { + let file = file.unwrap().path(); + try_hard_link(&file, target_rustlib_lib.join(file.file_name().unwrap())); + } + } + } + SysrootKind::Clif => { + let cwd = env::current_dir().unwrap(); + + let mut cmd = Command::new(cwd.join("build_sysroot").join("build_sysroot.sh")); + cmd.current_dir(target_dir).env("TARGET_TRIPLE", target_triple); + eprintln!("[BUILD] sysroot"); + if !cmd.spawn().unwrap().wait().unwrap().success() { + process::exit(1); + } + + if host_triple != target_triple { + let mut cmd = Command::new(cwd.join("build_sysroot").join("build_sysroot.sh")); + cmd.current_dir(target_dir).env("TARGET_TRIPLE", host_triple); + eprintln!("[BUILD] sysroot"); + if !cmd.spawn().unwrap().wait().unwrap().success() { + process::exit(1); + } + } + + for file in fs::read_dir(host_rustlib_lib).unwrap() { + let file = file.unwrap().path(); + if file.file_name().unwrap().to_str().unwrap().contains("std-") { + try_hard_link(&file, target_dir.join("lib").join(file.file_name().unwrap())); + } + } + } + } +} diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs new file mode 100644 index 00000000000..28222743022 --- /dev/null +++ b/build_system/rustc_info.rs @@ -0,0 +1,41 @@ +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; + +pub(crate) fn get_host_triple() -> String { + let version_info = + Command::new("rustc").stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; + String::from_utf8(version_info) + .unwrap() + .lines() + .to_owned() + .find(|line| line.starts_with("host")) + .unwrap() + .split(":") + .nth(1) + .unwrap() + .trim() + .to_owned() +} + +pub(crate) fn get_default_sysroot() -> PathBuf { + let default_sysroot = Command::new("rustc") + .stderr(Stdio::inherit()) + .args(&["--print", "sysroot"]) + .output() + .unwrap() + .stdout; + Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() +} + +pub(crate) fn get_dylib_name(crate_name: &str) -> String { + let dylib_name = Command::new("rustc") + .stderr(Stdio::inherit()) + .args(&["--crate-name", crate_name, "--crate-type", "dylib", "--print", "file-names", "-"]) + .output() + .unwrap() + .stdout; + let dylib_name = String::from_utf8(dylib_name).unwrap().trim().to_owned(); + assert!(!dylib_name.contains('\n')); + assert!(dylib_name.contains(crate_name)); + dylib_name +} diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index b52ca6ea2ad..c494e78050a 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e -./build.sh +./y.rs build source build/config.sh echo "[SETUP] Rust fork" diff --git a/test.sh b/test.sh index e222adc7b80..a10924628bb 100755 --- a/test.sh +++ b/test.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash set -e -./build.sh --sysroot none "$@" +./y.rs build --sysroot none "$@" rm -r target/out || true scripts/tests.sh no_sysroot -./build.sh "$@" +./y.rs build "$@" scripts/tests.sh base_sysroot scripts/tests.sh extended_sysroot diff --git a/y.rs b/y.rs new file mode 100755 index 00000000000..7971e713082 --- /dev/null +++ b/y.rs @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +#![allow()] /*This line is ignored by bash +# This block is ignored by rustc +set -e +echo "[BUILD] y.rs" 1>&2 +rustc $0 -o ${0/.rs/.bin} -g +exec ${0/.rs/.bin} $@ +*/ + +//! The build system for cg_clif +//! +//! # Manual compilation +//! +//! If your system doesn't support shell scripts you can manually compile and run this file using +//! for example: +//! +//! ```shell +//! $ rustc y.rs -o build/y.bin +//! $ build/y.bin +//! ``` +//! +//! # Naming +//! +//! The name `y.rs` was chosen to not conflict with rustc's `x.py`. + +use std::env; +use std::fs; +use std::path::{Path, PathBuf}; +use std::process; + +#[path = "build_system/build_backend.rs"] +mod build_backend; +#[path = "build_system/build_sysroot.rs"] +mod build_sysroot; +#[path = "build_system/rustc_info.rs"] +mod rustc_info; + +fn usage() { + eprintln!("Usage:"); + eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]"); +} + +macro_rules! arg_error { + ($($err:tt)*) => {{ + eprintln!($($err)*); + usage(); + std::process::exit(1); + }}; +} + +enum Command { + Build, +} + +#[derive(Copy, Clone)] +enum SysrootKind { + None, + Clif, + Llvm, +} + +fn main() { + env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); + env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); + + let mut args = env::args().skip(1); + let command = match args.next().as_deref() { + Some("prepare") => { + if args.next().is_some() { + arg_error!("./x.rs prepare doesn't expect arguments"); + } + todo!(); + } + Some("build") => Command::Build, + Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), + Some(command) => arg_error!("Unknown command {}", command), + None => { + usage(); + process::exit(0); + } + }; + + let mut target_dir = PathBuf::from("build"); + let mut channel = "release"; + let mut sysroot_kind = SysrootKind::Clif; + while let Some(arg) = args.next().as_deref() { + match arg { + "--target-dir" => { + target_dir = PathBuf::from(args.next().unwrap_or_else(|| { + arg_error!("--target-dir requires argument"); + })) + } + "--debug" => channel = "debug", + "--sysroot" => { + sysroot_kind = match args.next().as_deref() { + Some("none") => SysrootKind::None, + Some("clif") => SysrootKind::Clif, + Some("llvm") => SysrootKind::Llvm, + Some(arg) => arg_error!("Unknown sysroot kind {}", arg), + None => arg_error!("--sysroot requires argument"), + } + } + flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag), + arg => arg_error!("Unexpected argument {}", arg), + } + } + + let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { + host_triple + } else { + rustc_info::get_host_triple() + }; + let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") { + if target_triple != "" { + target_triple + } else { + host_triple.clone() // Empty target triple can happen on GHA + } + } else { + host_triple.clone() + }; + + let cg_clif_dylib = build_backend::build_backend(channel); + build_sysroot::build_sysroot( + channel, + sysroot_kind, + &target_dir, + cg_clif_dylib, + &host_triple, + &target_triple, + ); +} + +#[track_caller] +fn try_hard_link(src: impl AsRef, dst: impl AsRef) { + let src = src.as_ref(); + let dst = dst.as_ref(); + if let Err(_) = fs::hard_link(src, dst) { + fs::copy(src, dst).unwrap(); // Fallback to copying if hardlinking failed + } +} -- cgit 1.4.1-3-g733a5 From fe6a2892a6dd285774c3b1c84a2de45209454ce6 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 11 Jun 2021 18:50:01 +0200 Subject: Rewrite prepare.sh in rust --- .cirrus.yml | 2 +- .github/workflows/main.yml | 2 +- .github/workflows/rustc.yml | 4 +-- Readme.md | 8 ++--- build_system/build_backend.rs | 6 ++-- build_system/build_sysroot.rs | 3 +- build_system/prepare.rs | 74 +++++++++++++++++++++++++++++++++++++++++++ build_system/utils.rs | 18 +++++++++++ docs/usage.md | 2 +- prepare.sh | 29 ----------------- scripts/rustup.sh | 2 +- y.rs | 20 +++++------- 12 files changed, 114 insertions(+), 56 deletions(-) create mode 100644 build_system/prepare.rs create mode 100644 build_system/utils.rs delete mode 100755 prepare.sh diff --git a/.cirrus.yml b/.cirrus.yml index e173df423a7..61da6a2491c 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -14,7 +14,7 @@ task: - . $HOME/.cargo/env - git config --global user.email "user@example.com" - git config --global user.name "User" - - ./prepare.sh + - ./y.rs prepare test_script: - . $HOME/.cargo/env - # Enable backtraces for easier debugging diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d45e36c956..6734920bdd6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,7 @@ jobs: run: | git config --global user.email "user@example.com" git config --global user.name "User" - ./prepare.sh + ./y.rs prepare - name: Test env: diff --git a/.github/workflows/rustc.yml b/.github/workflows/rustc.yml index e01a92598ba..1c08e5ece33 100644 --- a/.github/workflows/rustc.yml +++ b/.github/workflows/rustc.yml @@ -34,7 +34,7 @@ jobs: run: | git config --global user.email "user@example.com" git config --global user.name "User" - ./prepare.sh + ./y.rs prepare - name: Test run: | @@ -72,7 +72,7 @@ jobs: run: | git config --global user.email "user@example.com" git config --global user.name "User" - ./prepare.sh + ./y.rs prepare - name: Test run: | diff --git a/Readme.md b/Readme.md index 08f9373be62..37644b6382c 100644 --- a/Readme.md +++ b/Readme.md @@ -10,8 +10,8 @@ If not please open an issue. ```bash $ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git $ cd rustc_codegen_cranelift -$ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking -$ ./build.sh +$ ./y.rs prepare # download and patch sysroot src and install hyperfine for benchmarking +$ ./y.rs build ``` To run the test suite replace the last command with: @@ -20,7 +20,7 @@ To run the test suite replace the last command with: $ ./test.sh ``` -This will implicitly build cg_clif too. Both `build.sh` and `test.sh` accept a `--debug` argument to +This will implicitly build cg_clif too. Both `y.rs build` and `test.sh` accept a `--debug` argument to build in debug mode. Alternatively you can download a pre built version from [GHA]. It is listed in the artifacts section @@ -32,7 +32,7 @@ of workflow runs. Unfortunately due to GHA restrictions you need to be logged in rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects. -Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `build.sh` or `test.sh`). +Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`). In the directory with your project (where you can do the usual `cargo build`), run: diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index cdddeae2a33..81c47fa8358 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,5 +1,5 @@ use std::env; -use std::process::{self, Command}; +use std::process::Command; pub(crate) fn build_backend(channel: &str) -> String { let mut cmd = Command::new("cargo"); @@ -33,9 +33,7 @@ pub(crate) fn build_backend(channel: &str) -> String { } eprintln!("[BUILD] rustc_codegen_cranelift"); - if !cmd.spawn().unwrap().wait().unwrap().success() { - process::exit(1); - } + crate::utils::spawn_and_wait(cmd); crate::rustc_info::get_dylib_name("rustc_codegen_cranelift") } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index d6ac19dd1cc..60906a8f19a 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -1,4 +1,5 @@ -use crate::{try_hard_link, SysrootKind}; +use crate::utils::try_hard_link; +use crate::SysrootKind; use std::env; use std::fs; use std::path::Path; diff --git a/build_system/prepare.rs b/build_system/prepare.rs new file mode 100644 index 00000000000..4aef9162594 --- /dev/null +++ b/build_system/prepare.rs @@ -0,0 +1,74 @@ +use std::ffi::OsStr; +use std::ffi::OsString; +use std::fs; +use std::process::Command; + +use crate::utils::spawn_and_wait; + +pub(crate) fn prepare() { + // FIXME implement in rust + let prepare_sysroot_cmd = Command::new("./build_sysroot/prepare_sysroot_src.sh"); + spawn_and_wait(prepare_sysroot_cmd); + + eprintln!("[INSTALL] hyperfine"); + Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); + + clone_repo( + "rand", + "https://github.com/rust-random/rand.git", + "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", + ); + + eprintln!("[PATCH] rand"); + for patch in get_patches("crate_patches", "rand") { + let mut patch_arg = OsString::from("../crate_patches/"); + patch_arg.push(patch); + let mut apply_patch_cmd = Command::new("git"); + apply_patch_cmd.arg("am").arg(patch_arg).current_dir("rand"); + spawn_and_wait(apply_patch_cmd); + } + + clone_repo( + "regex", + "https://github.com/rust-lang/regex.git", + "341f207c1071f7290e3f228c710817c280c8dca1", + ); + + clone_repo( + "simple-raytracer", + "https://github.com/ebobby/simple-raytracer", + "804a7a21b9e673a482797aa289a18ed480e4d813", + ); + + eprintln!("[LLVM BUILD] simple-raytracer"); + let mut build_cmd = Command::new("cargo"); + build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); + spawn_and_wait(build_cmd); + fs::copy("simple-raytracer/target/debug/main", "simple-raytracer/raytracer_cg_llvm").unwrap(); +} + +fn clone_repo(name: &str, repo: &str, commit: &str) { + eprintln!("[CLONE] {}", repo); + // Ignore exit code as the repo may already have been checked out + Command::new("git").arg("clone").arg(repo).spawn().unwrap().wait().unwrap(); + + let mut clean_cmd = Command::new("git"); + clean_cmd.arg("checkout").arg("--").arg(".").current_dir(name); + spawn_and_wait(clean_cmd); + + let mut checkout_cmd = Command::new("git"); + checkout_cmd.arg("checkout").arg(commit).current_dir(name); + spawn_and_wait(checkout_cmd); +} + +fn get_patches(patch_dir: &str, crate_name: &str) -> Vec { + let mut patches: Vec<_> = fs::read_dir(patch_dir) + .unwrap() + .map(|entry| entry.unwrap().path()) + .filter(|path| path.extension() == Some(OsStr::new("patch"))) + .map(|path| path.file_name().unwrap().to_owned()) + .filter(|file_name| file_name.to_str().unwrap().split("-").nth(1).unwrap() == crate_name) + .collect(); + patches.sort(); + patches +} diff --git a/build_system/utils.rs b/build_system/utils.rs new file mode 100644 index 00000000000..3eba87ee8a4 --- /dev/null +++ b/build_system/utils.rs @@ -0,0 +1,18 @@ +use std::fs; +use std::path::Path; +use std::process::{self, Command}; + +#[track_caller] +pub(crate) fn try_hard_link(src: impl AsRef, dst: impl AsRef) { + let src = src.as_ref(); + let dst = dst.as_ref(); + if let Err(_) = fs::hard_link(src, dst) { + fs::copy(src, dst).unwrap(); // Fallback to copying if hardlinking failed + } +} + +pub(crate) fn spawn_and_wait(mut cmd: Command) { + if !cmd.spawn().unwrap().wait().unwrap().success() { + process::exit(1); + } +} diff --git a/docs/usage.md b/docs/usage.md index 3eee3b554e3..7e1e0a9bc9d 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -2,7 +2,7 @@ rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects. -Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `build.sh` or `test.sh`). +Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`). ## Cargo diff --git a/prepare.sh b/prepare.sh deleted file mode 100755 index 64c097261c9..00000000000 --- a/prepare.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash -set -e - -./build_sysroot/prepare_sysroot_src.sh -cargo install hyperfine || echo "Skipping hyperfine install" - -git clone https://github.com/rust-random/rand.git || echo "rust-random/rand has already been cloned" -pushd rand -git checkout -- . -git checkout 0f933f9c7176e53b2a3c7952ded484e1783f0bf1 -git am ../crate_patches/*-rand-*.patch -popd - -git clone https://github.com/rust-lang/regex.git || echo "rust-lang/regex has already been cloned" -pushd regex -git checkout -- . -git checkout 341f207c1071f7290e3f228c710817c280c8dca1 -popd - -git clone https://github.com/ebobby/simple-raytracer || echo "ebobby/simple-raytracer has already been cloned" -pushd simple-raytracer -git checkout -- . -git checkout 804a7a21b9e673a482797aa289a18ed480e4d813 - -# build with cg_llvm for perf comparison -unset CARGO_TARGET_DIR -cargo build -mv target/debug/main raytracer_cg_llvm -popd diff --git a/scripts/rustup.sh b/scripts/rustup.sh index fa7557653d8..cc34c080886 100755 --- a/scripts/rustup.sh +++ b/scripts/rustup.sh @@ -17,7 +17,7 @@ case $1 in done ./clean_all.sh - ./prepare.sh + ./y.rs prepare (cd build_sysroot && cargo update) diff --git a/y.rs b/y.rs index 7971e713082..62debc117c3 100755 --- a/y.rs +++ b/y.rs @@ -24,19 +24,23 @@ exec ${0/.rs/.bin} $@ //! The name `y.rs` was chosen to not conflict with rustc's `x.py`. use std::env; -use std::fs; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process; #[path = "build_system/build_backend.rs"] mod build_backend; #[path = "build_system/build_sysroot.rs"] mod build_sysroot; +#[path = "build_system/prepare.rs"] +mod prepare; #[path = "build_system/rustc_info.rs"] mod rustc_info; +#[path = "build_system/utils.rs"] +mod utils; fn usage() { eprintln!("Usage:"); + eprintln!(" ./y.rs prepare"); eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]"); } @@ -69,7 +73,8 @@ fn main() { if args.next().is_some() { arg_error!("./x.rs prepare doesn't expect arguments"); } - todo!(); + prepare::prepare(); + process::exit(0); } Some("build") => Command::Build, Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag), @@ -130,12 +135,3 @@ fn main() { &target_triple, ); } - -#[track_caller] -fn try_hard_link(src: impl AsRef, dst: impl AsRef) { - let src = src.as_ref(); - let dst = dst.as_ref(); - if let Err(_) = fs::hard_link(src, dst) { - fs::copy(src, dst).unwrap(); // Fallback to copying if hardlinking failed - } -} -- cgit 1.4.1-3-g733a5 From 066d5f952cfb0c5d22d4ee31d6ac716b2d16668d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 16 Jun 2021 18:01:19 +0200 Subject: Rewrite prepare_sysroot_src.sh in rust --- build_sysroot/prepare_sysroot_src.sh | 39 -------- build_system/prepare.rs | 87 +++++++++++++---- build_system/rustc_info.rs | 10 ++ build_system/utils.rs | 17 ++++ .../0022-core-Disable-not-compiling-tests.patch | 83 ----------------- .../0022-sysroot-Disable-not-compiling-tests.patch | 83 +++++++++++++++++ patches/0023-core-Ignore-failing-tests.patch | 90 ------------------ patches/0023-sysroot-Ignore-failing-tests.patch | 90 ++++++++++++++++++ .../0027-Disable-128bit-atomic-operations.patch | 103 --------------------- .../0027-sysroot-128bit-atomic-operations.patch | 103 +++++++++++++++++++++ 10 files changed, 373 insertions(+), 332 deletions(-) delete mode 100755 build_sysroot/prepare_sysroot_src.sh delete mode 100644 patches/0022-core-Disable-not-compiling-tests.patch create mode 100644 patches/0022-sysroot-Disable-not-compiling-tests.patch delete mode 100644 patches/0023-core-Ignore-failing-tests.patch create mode 100644 patches/0023-sysroot-Ignore-failing-tests.patch delete mode 100644 patches/0027-Disable-128bit-atomic-operations.patch create mode 100644 patches/0027-sysroot-128bit-atomic-operations.patch diff --git a/build_sysroot/prepare_sysroot_src.sh b/build_sysroot/prepare_sysroot_src.sh deleted file mode 100755 index 7032a52a3d3..00000000000 --- a/build_sysroot/prepare_sysroot_src.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash -set -e -cd "$(dirname "$0")" - -SRC_DIR="$(dirname "$(rustup which rustc)")/../lib/rustlib/src/rust/" -DST_DIR="sysroot_src" - -if [ ! -e "$SRC_DIR" ]; then - echo "Please install rust-src component" - exit 1 -fi - -rm -rf $DST_DIR -mkdir -p $DST_DIR/library -cp -a "$SRC_DIR/library" $DST_DIR/ - -pushd $DST_DIR -echo "[GIT] init" -git init -echo "[GIT] add" -git add . -echo "[GIT] commit" -git commit -m "Initial commit" -q -for file in $(ls ../../patches/ | grep -v patcha); do -echo "[GIT] apply" "$file" -git apply ../../patches/"$file" -git add -A -git commit --no-gpg-sign -m "Patch $file" -done -popd - -git clone https://github.com/rust-lang/compiler-builtins.git || echo "rust-lang/compiler-builtins has already been cloned" -pushd compiler-builtins -git checkout -- . -git checkout 0.1.45 -git apply ../../crate_patches/000*-compiler-builtins-*.patch -popd - -echo "Successfully prepared sysroot source for building" diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 4aef9162594..b6d6457163d 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -1,14 +1,16 @@ use std::ffi::OsStr; use std::ffi::OsString; use std::fs; +use std::path::Path; +use std::path::PathBuf; use std::process::Command; +use crate::rustc_info::get_rustc_path; +use crate::utils::copy_dir_recursively; use crate::utils::spawn_and_wait; pub(crate) fn prepare() { - // FIXME implement in rust - let prepare_sysroot_cmd = Command::new("./build_sysroot/prepare_sysroot_src.sh"); - spawn_and_wait(prepare_sysroot_cmd); + prepare_sysroot(); eprintln!("[INSTALL] hyperfine"); Command::new("cargo").arg("install").arg("hyperfine").spawn().unwrap().wait().unwrap(); @@ -18,15 +20,7 @@ pub(crate) fn prepare() { "https://github.com/rust-random/rand.git", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", ); - - eprintln!("[PATCH] rand"); - for patch in get_patches("crate_patches", "rand") { - let mut patch_arg = OsString::from("../crate_patches/"); - patch_arg.push(patch); - let mut apply_patch_cmd = Command::new("git"); - apply_patch_cmd.arg("am").arg(patch_arg).current_dir("rand"); - spawn_and_wait(apply_patch_cmd); - } + apply_patches("crate_patches", "rand", Path::new("rand")); clone_repo( "regex", @@ -47,17 +41,64 @@ pub(crate) fn prepare() { fs::copy("simple-raytracer/target/debug/main", "simple-raytracer/raytracer_cg_llvm").unwrap(); } -fn clone_repo(name: &str, repo: &str, commit: &str) { +fn prepare_sysroot() { + let rustc_path = get_rustc_path(); + let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust"); + let sysroot_src = PathBuf::from("build_sysroot").canonicalize().unwrap().join("sysroot_src"); + + assert!(sysroot_src_orig.exists()); + + if sysroot_src.exists() { + fs::remove_dir_all(&sysroot_src).unwrap(); + } + fs::create_dir_all(sysroot_src.join("library")).unwrap(); + eprintln!("[COPY] sysroot src"); + copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.join("library")); + + eprintln!("[GIT] init"); + let mut git_init_cmd = Command::new("git"); + git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src); + spawn_and_wait(git_init_cmd); + + let mut git_add_cmd = Command::new("git"); + git_add_cmd.arg("add").arg(".").current_dir(&sysroot_src); + spawn_and_wait(git_add_cmd); + + let mut git_commit_cmd = Command::new("git"); + git_commit_cmd + .arg("commit") + .arg("-m") + .arg("Initial commit") + .arg("-q") + .current_dir(&sysroot_src); + spawn_and_wait(git_commit_cmd); + + apply_patches("patches", "sysroot", &sysroot_src); + + clone_repo( + "build_sysroot/compiler-builtins", + "https://github.com/rust-lang/compiler-builtins.git", + "0.1.45", + ); + + apply_patches( + "crate_patches", + "compiler-builtins", + Path::new("build_sysroot/compiler-builtins"), + ); +} + +fn clone_repo(target_dir: &str, repo: &str, rev: &str) { eprintln!("[CLONE] {}", repo); // Ignore exit code as the repo may already have been checked out - Command::new("git").arg("clone").arg(repo).spawn().unwrap().wait().unwrap(); + Command::new("git").arg("clone").arg(repo).arg(target_dir).spawn().unwrap().wait().unwrap(); let mut clean_cmd = Command::new("git"); - clean_cmd.arg("checkout").arg("--").arg(".").current_dir(name); + clean_cmd.arg("checkout").arg("--").arg(".").current_dir(target_dir); spawn_and_wait(clean_cmd); let mut checkout_cmd = Command::new("git"); - checkout_cmd.arg("checkout").arg(commit).current_dir(name); + checkout_cmd.arg("checkout").arg("-q").arg(rev).current_dir(target_dir); spawn_and_wait(checkout_cmd); } @@ -67,8 +108,20 @@ fn get_patches(patch_dir: &str, crate_name: &str) -> Vec { .map(|entry| entry.unwrap().path()) .filter(|path| path.extension() == Some(OsStr::new("patch"))) .map(|path| path.file_name().unwrap().to_owned()) - .filter(|file_name| file_name.to_str().unwrap().split("-").nth(1).unwrap() == crate_name) + .filter(|file_name| { + file_name.to_str().unwrap().split_once("-").unwrap().1.starts_with(crate_name) + }) .collect(); patches.sort(); patches } + +fn apply_patches(patch_dir: &str, crate_name: &str, target_dir: &Path) { + for patch in get_patches(patch_dir, crate_name) { + eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch); + let patch_arg = Path::new(patch_dir).join(patch).canonicalize().unwrap(); + let mut apply_patch_cmd = Command::new("git"); + apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir); + spawn_and_wait(apply_patch_cmd); + } +} diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 28222743022..f7f5d42fe09 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -17,6 +17,16 @@ pub(crate) fn get_host_triple() -> String { .to_owned() } +pub(crate) fn get_rustc_path() -> PathBuf { + let rustc_path = Command::new("rustup") + .stderr(Stdio::inherit()) + .args(&["which", "rustc"]) + .output() + .unwrap() + .stdout; + Path::new(String::from_utf8(rustc_path).unwrap().trim()).to_owned() +} + pub(crate) fn get_default_sysroot() -> PathBuf { let default_sysroot = Command::new("rustc") .stderr(Stdio::inherit()) diff --git a/build_system/utils.rs b/build_system/utils.rs index 3eba87ee8a4..12b5d70fad8 100644 --- a/build_system/utils.rs +++ b/build_system/utils.rs @@ -11,8 +11,25 @@ pub(crate) fn try_hard_link(src: impl AsRef, dst: impl AsRef) { } } +#[track_caller] pub(crate) fn spawn_and_wait(mut cmd: Command) { if !cmd.spawn().unwrap().wait().unwrap().success() { process::exit(1); } } + +pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) { + for entry in fs::read_dir(from).unwrap() { + let entry = entry.unwrap(); + let filename = entry.file_name(); + if filename == "." || filename == ".." { + continue; + } + if entry.metadata().unwrap().is_dir() { + fs::create_dir(to.join(&filename)).unwrap(); + copy_dir_recursively(&from.join(&filename), &to.join(&filename)); + } else { + fs::copy(from.join(&filename), to.join(&filename)).unwrap(); + } + } +} diff --git a/patches/0022-core-Disable-not-compiling-tests.patch b/patches/0022-core-Disable-not-compiling-tests.patch deleted file mode 100644 index ba0eaacd828..00000000000 --- a/patches/0022-core-Disable-not-compiling-tests.patch +++ /dev/null @@ -1,83 +0,0 @@ -From f6befc4bb51d84f5f1cf35938a168c953d421350 Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Sun, 24 Nov 2019 15:10:23 +0100 -Subject: [PATCH] [core] Disable not compiling tests - ---- - library/core/tests/Cargo.toml | 8 ++++++++ - library/core/tests/num/flt2dec/mod.rs | 1 - - library/core/tests/num/int_macros.rs | 2 ++ - library/core/tests/num/uint_macros.rs | 2 ++ - library/core/tests/ptr.rs | 2 ++ - library/core/tests/slice.rs | 2 ++ - 6 files changed, 16 insertions(+), 1 deletion(-) - create mode 100644 library/core/tests/Cargo.toml - -diff --git a/library/core/tests/Cargo.toml b/library/core/tests/Cargo.toml -new file mode 100644 -index 0000000..46fd999 ---- /dev/null -+++ b/library/core/tests/Cargo.toml -@@ -0,0 +1,8 @@ -+[package] -+name = "core" -+version = "0.0.0" -+edition = "2018" -+ -+[lib] -+name = "coretests" -+path = "lib.rs" -diff --git a/library/core/tests/num/flt2dec/mod.rs b/library/core/tests/num/flt2dec/mod.rs -index a35897e..f0bf645 100644 ---- a/library/core/tests/num/flt2dec/mod.rs -+++ b/library/core/tests/num/flt2dec/mod.rs -@@ -13,7 +13,6 @@ mod strategy { - mod dragon; - mod grisu; - } --mod random; - - pub fn decode_finite(v: T) -> Decoded { - match decode(v).1 { -diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs -index 1a6be3a..42dbd59 100644 ---- a/library/core/tests/ptr.rs -+++ b/library/core/tests/ptr.rs -@@ -250,6 +250,7 @@ fn test_unsized_nonnull() { - assert!(ys == zs); - } - -+/* - #[test] - #[allow(warnings)] - // Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the -@@ -289,6 +290,7 @@ fn write_unaligned_drop() { - } - DROPS.with(|d| assert_eq!(*d.borrow(), [0])); - } -+*/ - - #[test] - fn align_offset_zst() { -diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs -index 6609bc3..241b497 100644 ---- a/library/core/tests/slice.rs -+++ b/library/core/tests/slice.rs -@@ -1209,6 +1209,7 @@ fn brute_force_rotate_test_1() { - } - } - -+/* - #[test] - #[cfg(not(target_arch = "wasm32"))] - fn sort_unstable() { -@@ -1394,6 +1395,7 @@ fn partition_at_index() { - v.select_nth_unstable(0); - assert!(v == [0xDEADBEEF]); - } -+*/ - - #[test] - #[should_panic(expected = "index 0 greater than length of slice")] --- -2.21.0 (Apple Git-122) diff --git a/patches/0022-sysroot-Disable-not-compiling-tests.patch b/patches/0022-sysroot-Disable-not-compiling-tests.patch new file mode 100644 index 00000000000..ba0eaacd828 --- /dev/null +++ b/patches/0022-sysroot-Disable-not-compiling-tests.patch @@ -0,0 +1,83 @@ +From f6befc4bb51d84f5f1cf35938a168c953d421350 Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Sun, 24 Nov 2019 15:10:23 +0100 +Subject: [PATCH] [core] Disable not compiling tests + +--- + library/core/tests/Cargo.toml | 8 ++++++++ + library/core/tests/num/flt2dec/mod.rs | 1 - + library/core/tests/num/int_macros.rs | 2 ++ + library/core/tests/num/uint_macros.rs | 2 ++ + library/core/tests/ptr.rs | 2 ++ + library/core/tests/slice.rs | 2 ++ + 6 files changed, 16 insertions(+), 1 deletion(-) + create mode 100644 library/core/tests/Cargo.toml + +diff --git a/library/core/tests/Cargo.toml b/library/core/tests/Cargo.toml +new file mode 100644 +index 0000000..46fd999 +--- /dev/null ++++ b/library/core/tests/Cargo.toml +@@ -0,0 +1,8 @@ ++[package] ++name = "core" ++version = "0.0.0" ++edition = "2018" ++ ++[lib] ++name = "coretests" ++path = "lib.rs" +diff --git a/library/core/tests/num/flt2dec/mod.rs b/library/core/tests/num/flt2dec/mod.rs +index a35897e..f0bf645 100644 +--- a/library/core/tests/num/flt2dec/mod.rs ++++ b/library/core/tests/num/flt2dec/mod.rs +@@ -13,7 +13,6 @@ mod strategy { + mod dragon; + mod grisu; + } +-mod random; + + pub fn decode_finite(v: T) -> Decoded { + match decode(v).1 { +diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs +index 1a6be3a..42dbd59 100644 +--- a/library/core/tests/ptr.rs ++++ b/library/core/tests/ptr.rs +@@ -250,6 +250,7 @@ fn test_unsized_nonnull() { + assert!(ys == zs); + } + ++/* + #[test] + #[allow(warnings)] + // Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the +@@ -289,6 +290,7 @@ fn write_unaligned_drop() { + } + DROPS.with(|d| assert_eq!(*d.borrow(), [0])); + } ++*/ + + #[test] + fn align_offset_zst() { +diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs +index 6609bc3..241b497 100644 +--- a/library/core/tests/slice.rs ++++ b/library/core/tests/slice.rs +@@ -1209,6 +1209,7 @@ fn brute_force_rotate_test_1() { + } + } + ++/* + #[test] + #[cfg(not(target_arch = "wasm32"))] + fn sort_unstable() { +@@ -1394,6 +1395,7 @@ fn partition_at_index() { + v.select_nth_unstable(0); + assert!(v == [0xDEADBEEF]); + } ++*/ + + #[test] + #[should_panic(expected = "index 0 greater than length of slice")] +-- +2.21.0 (Apple Git-122) diff --git a/patches/0023-core-Ignore-failing-tests.patch b/patches/0023-core-Ignore-failing-tests.patch deleted file mode 100644 index 5d2c3049f60..00000000000 --- a/patches/0023-core-Ignore-failing-tests.patch +++ /dev/null @@ -1,90 +0,0 @@ -From dd82e95c9de212524e14fc60155de1ae40156dfc Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Sun, 24 Nov 2019 15:34:06 +0100 -Subject: [PATCH] [core] Ignore failing tests - ---- - library/core/tests/iter.rs | 4 ++++ - library/core/tests/num/bignum.rs | 10 ++++++++++ - library/core/tests/num/mod.rs | 5 +++-- - library/core/tests/time.rs | 1 + - 4 files changed, 18 insertions(+), 2 deletions(-) - -diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs -index 4bc44e9..8e3c7a4 100644 ---- a/library/core/tests/array.rs -+++ b/library/core/tests/array.rs -@@ -242,6 +242,7 @@ fn iterator_drops() { - assert_eq!(i.get(), 5); - } - -+/* - // This test does not work on targets without panic=unwind support. - // To work around this problem, test is marked is should_panic, so it will - // be automagically skipped on unsuitable targets, such as -@@ -283,6 +284,7 @@ fn array_default_impl_avoids_leaks_on_panic() { - assert_eq!(COUNTER.load(Relaxed), 0); - panic!("test succeeded") - } -+*/ - - #[test] - fn empty_array_is_always_default() { -@@ -304,6 +304,7 @@ fn array_map() { - assert_eq!(b, [1, 2, 3]); - } - -+/* - // See note on above test for why `should_panic` is used. - #[test] - #[should_panic(expected = "test succeeded")] -@@ -332,6 +333,7 @@ fn array_map_drop_safety() { - assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create); - panic!("test succeeded") - } -+*/ - - #[test] - fn cell_allows_array_cycle() { -diff --git a/library/core/tests/num/mod.rs b/library/core/tests/num/mod.rs -index a17c094..5bb11d2 100644 ---- a/library/core/tests/num/mod.rs -+++ b/library/core/tests/num/mod.rs -@@ -651,11 +651,12 @@ macro_rules! test_float { - assert_eq!((9.0 as $fty).min($neginf), $neginf); - assert_eq!(($neginf as $fty).min(-9.0), $neginf); - assert_eq!((-9.0 as $fty).min($neginf), $neginf); -- assert_eq!(($nan as $fty).min(9.0), 9.0); -- assert_eq!(($nan as $fty).min(-9.0), -9.0); -- assert_eq!((9.0 as $fty).min($nan), 9.0); -- assert_eq!((-9.0 as $fty).min($nan), -9.0); -- assert!(($nan as $fty).min($nan).is_nan()); -+ // Cranelift fmin has NaN propagation -+ //assert_eq!(($nan as $fty).min(9.0), 9.0); -+ //assert_eq!(($nan as $fty).min(-9.0), -9.0); -+ //assert_eq!((9.0 as $fty).min($nan), 9.0); -+ //assert_eq!((-9.0 as $fty).min($nan), -9.0); -+ //assert!(($nan as $fty).min($nan).is_nan()); - } - #[test] - fn max() { -@@ -673,11 +674,12 @@ macro_rules! test_float { - assert_eq!((9.0 as $fty).max($neginf), 9.0); - assert_eq!(($neginf as $fty).max(-9.0), -9.0); - assert_eq!((-9.0 as $fty).max($neginf), -9.0); -- assert_eq!(($nan as $fty).max(9.0), 9.0); -- assert_eq!(($nan as $fty).max(-9.0), -9.0); -- assert_eq!((9.0 as $fty).max($nan), 9.0); -- assert_eq!((-9.0 as $fty).max($nan), -9.0); -- assert!(($nan as $fty).max($nan).is_nan()); -+ // Cranelift fmax has NaN propagation -+ //assert_eq!(($nan as $fty).max(9.0), 9.0); -+ //assert_eq!(($nan as $fty).max(-9.0), -9.0); -+ //assert_eq!((9.0 as $fty).max($nan), 9.0); -+ //assert_eq!((-9.0 as $fty).max($nan), -9.0); -+ //assert!(($nan as $fty).max($nan).is_nan()); - } - #[test] - fn rem_euclid() { --- -2.21.0 (Apple Git-122) diff --git a/patches/0023-sysroot-Ignore-failing-tests.patch b/patches/0023-sysroot-Ignore-failing-tests.patch new file mode 100644 index 00000000000..5d2c3049f60 --- /dev/null +++ b/patches/0023-sysroot-Ignore-failing-tests.patch @@ -0,0 +1,90 @@ +From dd82e95c9de212524e14fc60155de1ae40156dfc Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Sun, 24 Nov 2019 15:34:06 +0100 +Subject: [PATCH] [core] Ignore failing tests + +--- + library/core/tests/iter.rs | 4 ++++ + library/core/tests/num/bignum.rs | 10 ++++++++++ + library/core/tests/num/mod.rs | 5 +++-- + library/core/tests/time.rs | 1 + + 4 files changed, 18 insertions(+), 2 deletions(-) + +diff --git a/library/core/tests/array.rs b/library/core/tests/array.rs +index 4bc44e9..8e3c7a4 100644 +--- a/library/core/tests/array.rs ++++ b/library/core/tests/array.rs +@@ -242,6 +242,7 @@ fn iterator_drops() { + assert_eq!(i.get(), 5); + } + ++/* + // This test does not work on targets without panic=unwind support. + // To work around this problem, test is marked is should_panic, so it will + // be automagically skipped on unsuitable targets, such as +@@ -283,6 +284,7 @@ fn array_default_impl_avoids_leaks_on_panic() { + assert_eq!(COUNTER.load(Relaxed), 0); + panic!("test succeeded") + } ++*/ + + #[test] + fn empty_array_is_always_default() { +@@ -304,6 +304,7 @@ fn array_map() { + assert_eq!(b, [1, 2, 3]); + } + ++/* + // See note on above test for why `should_panic` is used. + #[test] + #[should_panic(expected = "test succeeded")] +@@ -332,6 +333,7 @@ fn array_map_drop_safety() { + assert_eq!(DROPPED.load(Ordering::SeqCst), num_to_create); + panic!("test succeeded") + } ++*/ + + #[test] + fn cell_allows_array_cycle() { +diff --git a/library/core/tests/num/mod.rs b/library/core/tests/num/mod.rs +index a17c094..5bb11d2 100644 +--- a/library/core/tests/num/mod.rs ++++ b/library/core/tests/num/mod.rs +@@ -651,11 +651,12 @@ macro_rules! test_float { + assert_eq!((9.0 as $fty).min($neginf), $neginf); + assert_eq!(($neginf as $fty).min(-9.0), $neginf); + assert_eq!((-9.0 as $fty).min($neginf), $neginf); +- assert_eq!(($nan as $fty).min(9.0), 9.0); +- assert_eq!(($nan as $fty).min(-9.0), -9.0); +- assert_eq!((9.0 as $fty).min($nan), 9.0); +- assert_eq!((-9.0 as $fty).min($nan), -9.0); +- assert!(($nan as $fty).min($nan).is_nan()); ++ // Cranelift fmin has NaN propagation ++ //assert_eq!(($nan as $fty).min(9.0), 9.0); ++ //assert_eq!(($nan as $fty).min(-9.0), -9.0); ++ //assert_eq!((9.0 as $fty).min($nan), 9.0); ++ //assert_eq!((-9.0 as $fty).min($nan), -9.0); ++ //assert!(($nan as $fty).min($nan).is_nan()); + } + #[test] + fn max() { +@@ -673,11 +674,12 @@ macro_rules! test_float { + assert_eq!((9.0 as $fty).max($neginf), 9.0); + assert_eq!(($neginf as $fty).max(-9.0), -9.0); + assert_eq!((-9.0 as $fty).max($neginf), -9.0); +- assert_eq!(($nan as $fty).max(9.0), 9.0); +- assert_eq!(($nan as $fty).max(-9.0), -9.0); +- assert_eq!((9.0 as $fty).max($nan), 9.0); +- assert_eq!((-9.0 as $fty).max($nan), -9.0); +- assert!(($nan as $fty).max($nan).is_nan()); ++ // Cranelift fmax has NaN propagation ++ //assert_eq!(($nan as $fty).max(9.0), 9.0); ++ //assert_eq!(($nan as $fty).max(-9.0), -9.0); ++ //assert_eq!((9.0 as $fty).max($nan), 9.0); ++ //assert_eq!((-9.0 as $fty).max($nan), -9.0); ++ //assert!(($nan as $fty).max($nan).is_nan()); + } + #[test] + fn rem_euclid() { +-- +2.21.0 (Apple Git-122) diff --git a/patches/0027-Disable-128bit-atomic-operations.patch b/patches/0027-Disable-128bit-atomic-operations.patch deleted file mode 100644 index 32e59309690..00000000000 --- a/patches/0027-Disable-128bit-atomic-operations.patch +++ /dev/null @@ -1,103 +0,0 @@ -From 894e07dfec2624ba539129b1c1d63e1d7d812bda Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 18 Feb 2021 18:45:28 +0100 -Subject: [PATCH] Disable 128bit atomic operations - -Cranelift doesn't support them yet ---- - library/core/src/sync/atomic.rs | 38 --------------------------------- - library/core/tests/atomic.rs | 4 ---- - library/std/src/panic.rs | 6 ------ - 3 files changed, 48 deletions(-) - -diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs -index 81c9e1d..65c9503 100644 ---- a/library/core/src/sync/atomic.rs -+++ b/library/core/src/sync/atomic.rs -@@ -2228,44 +2228,6 @@ atomic_int! { - "AtomicU64::new(0)", - u64 AtomicU64 ATOMIC_U64_INIT - } --#[cfg(target_has_atomic_load_store = "128")] --atomic_int! { -- cfg(target_has_atomic = "128"), -- cfg(target_has_atomic_equal_alignment = "128"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), -- unstable(feature = "integer_atomics", issue = "32976"), -- "i128", -- "#![feature(integer_atomics)]\n\n", -- atomic_min, atomic_max, -- 16, -- "AtomicI128::new(0)", -- i128 AtomicI128 ATOMIC_I128_INIT --} --#[cfg(target_has_atomic_load_store = "128")] --atomic_int! { -- cfg(target_has_atomic = "128"), -- cfg(target_has_atomic_equal_alignment = "128"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- unstable(feature = "integer_atomics", issue = "32976"), -- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), -- unstable(feature = "integer_atomics", issue = "32976"), -- "u128", -- "#![feature(integer_atomics)]\n\n", -- atomic_umin, atomic_umax, -- 16, -- "AtomicU128::new(0)", -- u128 AtomicU128 ATOMIC_U128_INIT --} - - macro_rules! atomic_int_ptr_sized { - ( $($target_pointer_width:literal $align:literal)* ) => { $( -diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs -index 2d1e449..cb6da5d 100644 ---- a/library/core/tests/atomic.rs -+++ b/library/core/tests/atomic.rs -@@ -145,10 +145,6 @@ fn atomic_alignment() { - assert_eq!(align_of::(), size_of::()); - #[cfg(target_has_atomic = "64")] - assert_eq!(align_of::(), size_of::()); -- #[cfg(target_has_atomic = "128")] -- assert_eq!(align_of::(), size_of::()); -- #[cfg(target_has_atomic = "128")] -- assert_eq!(align_of::(), size_of::()); - #[cfg(target_has_atomic = "ptr")] - assert_eq!(align_of::(), size_of::()); - #[cfg(target_has_atomic = "ptr")] -diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs -index 89a822a..779fd88 100644 ---- a/library/std/src/panic.rs -+++ b/library/std/src/panic.rs -@@ -279,9 +279,6 @@ impl RefUnwindSafe for atomic::AtomicI32 {} - #[cfg(target_has_atomic_load_store = "64")] - #[stable(feature = "integer_atomics_stable", since = "1.34.0")] - impl RefUnwindSafe for atomic::AtomicI64 {} --#[cfg(target_has_atomic_load_store = "128")] --#[unstable(feature = "integer_atomics", issue = "32976")] --impl RefUnwindSafe for atomic::AtomicI128 {} - - #[cfg(target_has_atomic_load_store = "ptr")] - #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] -@@ -298,9 +295,6 @@ impl RefUnwindSafe for atomic::AtomicU32 {} - #[cfg(target_has_atomic_load_store = "64")] - #[stable(feature = "integer_atomics_stable", since = "1.34.0")] - impl RefUnwindSafe for atomic::AtomicU64 {} --#[cfg(target_has_atomic_load_store = "128")] --#[unstable(feature = "integer_atomics", issue = "32976")] --impl RefUnwindSafe for atomic::AtomicU128 {} - - #[cfg(target_has_atomic_load_store = "8")] - #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] --- -2.26.2.7.g19db9cfb68 - diff --git a/patches/0027-sysroot-128bit-atomic-operations.patch b/patches/0027-sysroot-128bit-atomic-operations.patch new file mode 100644 index 00000000000..32e59309690 --- /dev/null +++ b/patches/0027-sysroot-128bit-atomic-operations.patch @@ -0,0 +1,103 @@ +From 894e07dfec2624ba539129b1c1d63e1d7d812bda Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Thu, 18 Feb 2021 18:45:28 +0100 +Subject: [PATCH] Disable 128bit atomic operations + +Cranelift doesn't support them yet +--- + library/core/src/sync/atomic.rs | 38 --------------------------------- + library/core/tests/atomic.rs | 4 ---- + library/std/src/panic.rs | 6 ------ + 3 files changed, 48 deletions(-) + +diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs +index 81c9e1d..65c9503 100644 +--- a/library/core/src/sync/atomic.rs ++++ b/library/core/src/sync/atomic.rs +@@ -2228,44 +2228,6 @@ atomic_int! { + "AtomicU64::new(0)", + u64 AtomicU64 ATOMIC_U64_INIT + } +-#[cfg(target_has_atomic_load_store = "128")] +-atomic_int! { +- cfg(target_has_atomic = "128"), +- cfg(target_has_atomic_equal_alignment = "128"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), +- unstable(feature = "integer_atomics", issue = "32976"), +- "i128", +- "#![feature(integer_atomics)]\n\n", +- atomic_min, atomic_max, +- 16, +- "AtomicI128::new(0)", +- i128 AtomicI128 ATOMIC_I128_INIT +-} +-#[cfg(target_has_atomic_load_store = "128")] +-atomic_int! { +- cfg(target_has_atomic = "128"), +- cfg(target_has_atomic_equal_alignment = "128"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- unstable(feature = "integer_atomics", issue = "32976"), +- rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"), +- unstable(feature = "integer_atomics", issue = "32976"), +- "u128", +- "#![feature(integer_atomics)]\n\n", +- atomic_umin, atomic_umax, +- 16, +- "AtomicU128::new(0)", +- u128 AtomicU128 ATOMIC_U128_INIT +-} + + macro_rules! atomic_int_ptr_sized { + ( $($target_pointer_width:literal $align:literal)* ) => { $( +diff --git a/library/core/tests/atomic.rs b/library/core/tests/atomic.rs +index 2d1e449..cb6da5d 100644 +--- a/library/core/tests/atomic.rs ++++ b/library/core/tests/atomic.rs +@@ -145,10 +145,6 @@ fn atomic_alignment() { + assert_eq!(align_of::(), size_of::()); + #[cfg(target_has_atomic = "64")] + assert_eq!(align_of::(), size_of::()); +- #[cfg(target_has_atomic = "128")] +- assert_eq!(align_of::(), size_of::()); +- #[cfg(target_has_atomic = "128")] +- assert_eq!(align_of::(), size_of::()); + #[cfg(target_has_atomic = "ptr")] + assert_eq!(align_of::(), size_of::()); + #[cfg(target_has_atomic = "ptr")] +diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs +index 89a822a..779fd88 100644 +--- a/library/std/src/panic.rs ++++ b/library/std/src/panic.rs +@@ -279,9 +279,6 @@ impl RefUnwindSafe for atomic::AtomicI32 {} + #[cfg(target_has_atomic_load_store = "64")] + #[stable(feature = "integer_atomics_stable", since = "1.34.0")] + impl RefUnwindSafe for atomic::AtomicI64 {} +-#[cfg(target_has_atomic_load_store = "128")] +-#[unstable(feature = "integer_atomics", issue = "32976")] +-impl RefUnwindSafe for atomic::AtomicI128 {} + + #[cfg(target_has_atomic_load_store = "ptr")] + #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] +@@ -298,9 +295,6 @@ impl RefUnwindSafe for atomic::AtomicU32 {} + #[cfg(target_has_atomic_load_store = "64")] + #[stable(feature = "integer_atomics_stable", since = "1.34.0")] + impl RefUnwindSafe for atomic::AtomicU64 {} +-#[cfg(target_has_atomic_load_store = "128")] +-#[unstable(feature = "integer_atomics", issue = "32976")] +-impl RefUnwindSafe for atomic::AtomicU128 {} + + #[cfg(target_has_atomic_load_store = "8")] + #[stable(feature = "unwind_safe_atomic_refs", since = "1.14.0")] +-- +2.26.2.7.g19db9cfb68 + -- cgit 1.4.1-3-g733a5 From d71b12535e84a7c242cf217af49a0366b06c8691 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 16 Jun 2021 18:28:34 +0200 Subject: Merge the crate_patches dir into the patches dir --- build_system/prepare.rs | 21 ++++------ ...builtins-Disable-128bit-atomic-operations.patch | 48 ---------------------- .../0001-rand-Enable-c2-chacha-simd-feature.patch | 23 ----------- crate_patches/0002-rand-Disable-failing-test.patch | 33 --------------- ...builtins-Disable-128bit-atomic-operations.patch | 48 ++++++++++++++++++++++ .../0001-rand-Enable-c2-chacha-simd-feature.patch | 23 +++++++++++ patches/0002-rand-Disable-failing-test.patch | 33 +++++++++++++++ 7 files changed, 112 insertions(+), 117 deletions(-) delete mode 100644 crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch delete mode 100644 crate_patches/0001-rand-Enable-c2-chacha-simd-feature.patch delete mode 100644 crate_patches/0002-rand-Disable-failing-test.patch create mode 100644 patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch create mode 100644 patches/0001-rand-Enable-c2-chacha-simd-feature.patch create mode 100644 patches/0002-rand-Disable-failing-test.patch diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b6d6457163d..b5011ceb159 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -20,7 +20,7 @@ pub(crate) fn prepare() { "https://github.com/rust-random/rand.git", "0f933f9c7176e53b2a3c7952ded484e1783f0bf1", ); - apply_patches("crate_patches", "rand", Path::new("rand")); + apply_patches("rand", Path::new("rand")); clone_repo( "regex", @@ -73,19 +73,14 @@ fn prepare_sysroot() { .current_dir(&sysroot_src); spawn_and_wait(git_commit_cmd); - apply_patches("patches", "sysroot", &sysroot_src); + apply_patches("sysroot", &sysroot_src); clone_repo( "build_sysroot/compiler-builtins", "https://github.com/rust-lang/compiler-builtins.git", "0.1.45", ); - - apply_patches( - "crate_patches", - "compiler-builtins", - Path::new("build_sysroot/compiler-builtins"), - ); + apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } fn clone_repo(target_dir: &str, repo: &str, rev: &str) { @@ -102,8 +97,8 @@ fn clone_repo(target_dir: &str, repo: &str, rev: &str) { spawn_and_wait(checkout_cmd); } -fn get_patches(patch_dir: &str, crate_name: &str) -> Vec { - let mut patches: Vec<_> = fs::read_dir(patch_dir) +fn get_patches(crate_name: &str) -> Vec { + let mut patches: Vec<_> = fs::read_dir("patches") .unwrap() .map(|entry| entry.unwrap().path()) .filter(|path| path.extension() == Some(OsStr::new("patch"))) @@ -116,10 +111,10 @@ fn get_patches(patch_dir: &str, crate_name: &str) -> Vec { patches } -fn apply_patches(patch_dir: &str, crate_name: &str, target_dir: &Path) { - for patch in get_patches(patch_dir, crate_name) { +fn apply_patches(crate_name: &str, target_dir: &Path) { + for patch in get_patches(crate_name) { eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch); - let patch_arg = Path::new(patch_dir).join(patch).canonicalize().unwrap(); + let patch_arg = Path::new("patches").join(patch).canonicalize().unwrap(); let mut apply_patch_cmd = Command::new("git"); apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir); spawn_and_wait(apply_patch_cmd); diff --git a/crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch b/crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch deleted file mode 100644 index 7daea99f579..00000000000 --- a/crate_patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch +++ /dev/null @@ -1,48 +0,0 @@ -From 1d574bf5e32d51641dcacaf8ef777e95b44f6f2a Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Thu, 18 Feb 2021 18:30:55 +0100 -Subject: [PATCH] Disable 128bit atomic operations - -Cranelift doesn't support them yet ---- - src/mem/mod.rs | 12 ------------ - 1 file changed, 12 deletions(-) - -diff --git a/src/mem/mod.rs b/src/mem/mod.rs -index 107762c..2d1ae10 100644 ---- a/src/mem/mod.rs -+++ b/src/mem/mod.rs -@@ -137,10 +137,6 @@ intrinsics! { - pub extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memcpy_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memcpy_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { -@@ -158,10 +154,6 @@ intrinsics! { - pub extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { - memmove_element_unordered_atomic(dest, src, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { -- memmove_element_unordered_atomic(dest, src, bytes); -- } - - #[cfg(target_has_atomic_load_store = "8")] - pub extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { -@@ -179,8 +171,4 @@ intrinsics! { - pub extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { - memset_element_unordered_atomic(s, c, bytes); - } -- #[cfg(target_has_atomic_load_store = "128")] -- pub extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { -- memset_element_unordered_atomic(s, c, bytes); -- } - } --- -2.26.2.7.g19db9cfb68 - diff --git a/crate_patches/0001-rand-Enable-c2-chacha-simd-feature.patch b/crate_patches/0001-rand-Enable-c2-chacha-simd-feature.patch deleted file mode 100644 index 01dc0fcc537..00000000000 --- a/crate_patches/0001-rand-Enable-c2-chacha-simd-feature.patch +++ /dev/null @@ -1,23 +0,0 @@ -From 9c5663e36391fa20becf84f3af2e82afa5bb720b Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Sat, 15 Aug 2020 19:56:03 +0200 -Subject: [PATCH] [rand] Enable c2-chacha simd feature - ---- - rand_chacha/Cargo.toml | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml -index 9190b7f..872cca2 100644 ---- a/rand_chacha/Cargo.toml -+++ b/rand_chacha/Cargo.toml -@@ -24,5 +24,5 @@ ppv-lite86 = { version = "0.2.8", default-features = false } - - [features] - default = ["std"] --std = ["ppv-lite86/std"] -+std = ["ppv-lite86/std", "ppv-lite86/simd"] - simd = [] # deprecated --- -2.20.1 - diff --git a/crate_patches/0002-rand-Disable-failing-test.patch b/crate_patches/0002-rand-Disable-failing-test.patch deleted file mode 100644 index 19fd20d7269..00000000000 --- a/crate_patches/0002-rand-Disable-failing-test.patch +++ /dev/null @@ -1,33 +0,0 @@ -From a8fb97120d71252538b6b026695df40d02696bdb Mon Sep 17 00:00:00 2001 -From: bjorn3 -Date: Sat, 15 Aug 2020 20:04:38 +0200 -Subject: [PATCH] [rand] Disable failing test - ---- - src/distributions/uniform.rs | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs -index 480b859..c80bb6f 100644 ---- a/src/distributions/uniform.rs -+++ b/src/distributions/uniform.rs -@@ -1085,7 +1085,7 @@ mod tests { - _ => panic!("`UniformDurationMode` was not serialized/deserialized correctly") - } - } -- -+ - #[test] - #[cfg(feature = "serde1")] - fn test_uniform_serialization() { -@@ -1314,6 +1314,7 @@ mod tests { - not(target_arch = "wasm32"), - not(target_arch = "asmjs") - ))] -+ #[ignore] // FIXME - fn test_float_assertions() { - use super::SampleUniform; - use std::panic::catch_unwind; --- -2.20.1 - diff --git a/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch b/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch new file mode 100644 index 00000000000..7daea99f579 --- /dev/null +++ b/patches/0001-compiler-builtins-Disable-128bit-atomic-operations.patch @@ -0,0 +1,48 @@ +From 1d574bf5e32d51641dcacaf8ef777e95b44f6f2a Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Thu, 18 Feb 2021 18:30:55 +0100 +Subject: [PATCH] Disable 128bit atomic operations + +Cranelift doesn't support them yet +--- + src/mem/mod.rs | 12 ------------ + 1 file changed, 12 deletions(-) + +diff --git a/src/mem/mod.rs b/src/mem/mod.rs +index 107762c..2d1ae10 100644 +--- a/src/mem/mod.rs ++++ b/src/mem/mod.rs +@@ -137,10 +137,6 @@ intrinsics! { + pub extern "C" fn __llvm_memcpy_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { + memcpy_element_unordered_atomic(dest, src, bytes); + } +- #[cfg(target_has_atomic_load_store = "128")] +- pub extern "C" fn __llvm_memcpy_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { +- memcpy_element_unordered_atomic(dest, src, bytes); +- } + + #[cfg(target_has_atomic_load_store = "8")] + pub extern "C" fn __llvm_memmove_element_unordered_atomic_1(dest: *mut u8, src: *const u8, bytes: usize) -> () { +@@ -158,10 +154,6 @@ intrinsics! { + pub extern "C" fn __llvm_memmove_element_unordered_atomic_8(dest: *mut u64, src: *const u64, bytes: usize) -> () { + memmove_element_unordered_atomic(dest, src, bytes); + } +- #[cfg(target_has_atomic_load_store = "128")] +- pub extern "C" fn __llvm_memmove_element_unordered_atomic_16(dest: *mut u128, src: *const u128, bytes: usize) -> () { +- memmove_element_unordered_atomic(dest, src, bytes); +- } + + #[cfg(target_has_atomic_load_store = "8")] + pub extern "C" fn __llvm_memset_element_unordered_atomic_1(s: *mut u8, c: u8, bytes: usize) -> () { +@@ -179,8 +171,4 @@ intrinsics! { + pub extern "C" fn __llvm_memset_element_unordered_atomic_8(s: *mut u64, c: u8, bytes: usize) -> () { + memset_element_unordered_atomic(s, c, bytes); + } +- #[cfg(target_has_atomic_load_store = "128")] +- pub extern "C" fn __llvm_memset_element_unordered_atomic_16(s: *mut u128, c: u8, bytes: usize) -> () { +- memset_element_unordered_atomic(s, c, bytes); +- } + } +-- +2.26.2.7.g19db9cfb68 + diff --git a/patches/0001-rand-Enable-c2-chacha-simd-feature.patch b/patches/0001-rand-Enable-c2-chacha-simd-feature.patch new file mode 100644 index 00000000000..01dc0fcc537 --- /dev/null +++ b/patches/0001-rand-Enable-c2-chacha-simd-feature.patch @@ -0,0 +1,23 @@ +From 9c5663e36391fa20becf84f3af2e82afa5bb720b Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Sat, 15 Aug 2020 19:56:03 +0200 +Subject: [PATCH] [rand] Enable c2-chacha simd feature + +--- + rand_chacha/Cargo.toml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/rand_chacha/Cargo.toml b/rand_chacha/Cargo.toml +index 9190b7f..872cca2 100644 +--- a/rand_chacha/Cargo.toml ++++ b/rand_chacha/Cargo.toml +@@ -24,5 +24,5 @@ ppv-lite86 = { version = "0.2.8", default-features = false } + + [features] + default = ["std"] +-std = ["ppv-lite86/std"] ++std = ["ppv-lite86/std", "ppv-lite86/simd"] + simd = [] # deprecated +-- +2.20.1 + diff --git a/patches/0002-rand-Disable-failing-test.patch b/patches/0002-rand-Disable-failing-test.patch new file mode 100644 index 00000000000..19fd20d7269 --- /dev/null +++ b/patches/0002-rand-Disable-failing-test.patch @@ -0,0 +1,33 @@ +From a8fb97120d71252538b6b026695df40d02696bdb Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Sat, 15 Aug 2020 20:04:38 +0200 +Subject: [PATCH] [rand] Disable failing test + +--- + src/distributions/uniform.rs | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs +index 480b859..c80bb6f 100644 +--- a/src/distributions/uniform.rs ++++ b/src/distributions/uniform.rs +@@ -1085,7 +1085,7 @@ mod tests { + _ => panic!("`UniformDurationMode` was not serialized/deserialized correctly") + } + } +- ++ + #[test] + #[cfg(feature = "serde1")] + fn test_uniform_serialization() { +@@ -1314,6 +1314,7 @@ mod tests { + not(target_arch = "wasm32"), + not(target_arch = "asmjs") + ))] ++ #[ignore] // FIXME + fn test_float_assertions() { + use super::SampleUniform; + use std::panic::catch_unwind; +-- +2.20.1 + -- cgit 1.4.1-3-g733a5 From ad971bbed773cad7cb446b49b07c64504e9a79fb Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Jun 2021 13:27:56 +0200 Subject: Rewrite build_sysroot.sh in rust --- build_sysroot/build_sysroot.sh | 39 ------------------------- build_system/build_sysroot.rs | 66 ++++++++++++++++++++++++++++++++---------- y.rs | 2 ++ 3 files changed, 53 insertions(+), 54 deletions(-) delete mode 100755 build_sysroot/build_sysroot.sh diff --git a/build_sysroot/build_sysroot.sh b/build_sysroot/build_sysroot.sh deleted file mode 100755 index 0354304e55b..00000000000 --- a/build_sysroot/build_sysroot.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -# Requires the CHANNEL env var to be set to `debug` or `release.` - -set -e - -source ./config.sh - -dir=$(pwd) - -# Use rustc with cg_clif as hotpluggable backend instead of the custom cg_clif driver so that -# build scripts are still compiled using cg_llvm. -export RUSTC=$dir"/bin/cg_clif_build_sysroot" -export RUSTFLAGS=$RUSTFLAGS" --clif" - -cd "$(dirname "$0")" - -# Cleanup for previous run -# v Clean target dir except for build scripts and incremental cache -rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true - -# We expect the target dir in the default location. Guard against the user changing it. -export CARGO_TARGET_DIR=target - -# Build libs -export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked -Cpanic=abort" -export __CARGO_DEFAULT_LIB_METADATA="cg_clif" -if [[ "$1" != "--debug" ]]; then - sysroot_channel='release' - # FIXME Enable incremental again once rust-lang/rust#74946 is fixed - CARGO_INCREMENTAL=0 RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target "$TARGET_TRIPLE" --release -else - sysroot_channel='debug' - cargo build --target "$TARGET_TRIPLE" -fi - -# Copy files to sysroot -ln "target/$TARGET_TRIPLE/$sysroot_channel/deps/"* "$dir/lib/rustlib/$TARGET_TRIPLE/lib/" -rm "$dir/lib/rustlib/$TARGET_TRIPLE/lib/"*.{rmeta,d} diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 60906a8f19a..9988b35b363 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -1,6 +1,6 @@ +use crate::utils::spawn_and_wait; use crate::utils::try_hard_link; use crate::SysrootKind; -use std::env; use std::fs; use std::path::Path; use std::process::{self, Command}; @@ -100,24 +100,14 @@ pub(crate) fn build_sysroot( } } SysrootKind::Clif => { - let cwd = env::current_dir().unwrap(); - - let mut cmd = Command::new(cwd.join("build_sysroot").join("build_sysroot.sh")); - cmd.current_dir(target_dir).env("TARGET_TRIPLE", target_triple); - eprintln!("[BUILD] sysroot"); - if !cmd.spawn().unwrap().wait().unwrap().success() { - process::exit(1); - } + build_clif_sysroot_for_triple(channel, target_dir, target_triple); if host_triple != target_triple { - let mut cmd = Command::new(cwd.join("build_sysroot").join("build_sysroot.sh")); - cmd.current_dir(target_dir).env("TARGET_TRIPLE", host_triple); - eprintln!("[BUILD] sysroot"); - if !cmd.spawn().unwrap().wait().unwrap().success() { - process::exit(1); - } + build_clif_sysroot_for_triple(channel, target_dir, host_triple); } + // Copy std for the host to the lib dir. This is necessary for the jit mode to find + // libstd. for file in fs::read_dir(host_rustlib_lib).unwrap() { let file = file.unwrap().path(); if file.file_name().unwrap().to_str().unwrap().contains("std-") { @@ -127,3 +117,49 @@ pub(crate) fn build_sysroot( } } } + +fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str) { + let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); + + // FIXME add option to skip this + // Cleanup the target dir with the exception of build scripts and the incremental cache + for dir in ["build", "deps", "examples", "native"] { + if build_dir.join(dir).exists() { + fs::remove_dir_all(build_dir.join(dir)).unwrap(); + } + } + + // Build sysroot + let mut build_cmd = Command::new("cargo"); + build_cmd.arg("build").arg("--target").arg(triple).current_dir("build_sysroot"); + let mut rustflags = "--clif -Zforce-unstable-if-unmarked".to_string(); + if channel == "release" { + build_cmd.arg("--release"); + rustflags.push_str(" -Zmir-opt-level=3"); + } + build_cmd.env("RUSTFLAGS", rustflags); + build_cmd + .env("RUSTC", target_dir.join("bin").join("cg_clif_build_sysroot").canonicalize().unwrap()); + // FIXME Enable incremental again once rust-lang/rust#74946 is fixed + build_cmd.env("CARGO_INCREMENTAL", "0").env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); + spawn_and_wait(build_cmd); + + // Copy all relevant files to the sysroot + for entry in + fs::read_dir(Path::new("build_sysroot/target").join(triple).join(channel).join("deps")) + .unwrap() + { + let entry = entry.unwrap(); + if let Some(ext) = entry.path().extension() { + if ext == "rmeta" || ext == "d" || ext == "dSYM" { + continue; + } + } else { + continue; + }; + try_hard_link( + entry.path(), + target_dir.join("lib").join("rustlib").join(triple).join("lib").join(entry.file_name()), + ); + } +} diff --git a/y.rs b/y.rs index 62debc117c3..27ab44f5870 100755 --- a/y.rs +++ b/y.rs @@ -66,6 +66,8 @@ enum SysrootKind { fn main() { env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1"); env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1"); + // The target dir is expected in the default location. Guard against the user changing it. + env::set_var("CARGO_TARGET_DIR", "target"); let mut args = env::args().skip(1); let command = match args.next().as_deref() { -- cgit 1.4.1-3-g733a5 From 0d6b3dab658d76078741cc78b0bda1682b43a7ec Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Jun 2021 13:35:58 +0200 Subject: Allow preserving the old sysroot --- build_system/build_sysroot.rs | 13 ++++++++----- config.txt | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 config.txt diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 9988b35b363..fb34875f50f 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -121,11 +121,14 @@ pub(crate) fn build_sysroot( fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str) { let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); - // FIXME add option to skip this - // Cleanup the target dir with the exception of build scripts and the incremental cache - for dir in ["build", "deps", "examples", "native"] { - if build_dir.join(dir).exists() { - fs::remove_dir_all(build_dir.join(dir)).unwrap(); + let keep_sysroot = + fs::read_to_string("config.txt").unwrap().lines().any(|line| line.trim() == "keep_sysroot"); + if !keep_sysroot { + // Cleanup the target dir with the exception of build scripts and the incremental cache + for dir in ["build", "deps", "examples", "native"] { + if build_dir.join(dir).exists() { + fs::remove_dir_all(build_dir.join(dir)).unwrap(); + } } } diff --git a/config.txt b/config.txt new file mode 100644 index 00000000000..f707b9322af --- /dev/null +++ b/config.txt @@ -0,0 +1,7 @@ +# This file allows configuring the build system. + +# Disables cleaning of the sysroot dir. This will cause old compiled artifacts to be re-used when +# the sysroot source hasn't changed. This is useful when the codegen backend hasn't been modified. +# This option can be changed while the build system is already running for as long as sysroot +# building hasn't started yet. +#keep_sysroot -- cgit 1.4.1-3-g733a5 From e5563b50772e45dc2ad9111769f48d216570af71 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Jun 2021 13:38:50 +0200 Subject: Improve windows support --- build_system/build_backend.rs | 2 +- build_system/build_sysroot.rs | 35 ++++++++++++++++++++++++----------- build_system/prepare.rs | 18 +++++++++++------- build_system/rustc_info.rs | 22 +++++++++++++++------- 4 files changed, 51 insertions(+), 26 deletions(-) diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 81c47fa8358..db046be1866 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -35,5 +35,5 @@ pub(crate) fn build_backend(channel: &str) -> String { eprintln!("[BUILD] rustc_codegen_cranelift"); crate::utils::spawn_and_wait(cmd); - crate::rustc_info::get_dylib_name("rustc_codegen_cranelift") + crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib") } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index fb34875f50f..547159438e9 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -1,10 +1,12 @@ -use crate::utils::spawn_and_wait; -use crate::utils::try_hard_link; -use crate::SysrootKind; +use std::env; use std::fs; use std::path::Path; use std::process::{self, Command}; +use crate::rustc_info::get_file_name; +use crate::utils::{spawn_and_wait, try_hard_link}; +use crate::SysrootKind; + pub(crate) fn build_sysroot( channel: &str, sysroot_kind: SysrootKind, @@ -22,15 +24,24 @@ pub(crate) fn build_sysroot( // Copy the backend for file in ["cg_clif", "cg_clif_build_sysroot"] { try_hard_link( - Path::new("target").join(channel).join(file), - target_dir.join("bin").join(file), + Path::new("target").join(channel).join(get_file_name(file, "bin")), + target_dir.join("bin").join(get_file_name(file, "bin")), ); } - try_hard_link( - Path::new("target").join(channel).join(&cg_clif_dylib), - target_dir.join("lib").join(cg_clif_dylib), - ); + if cfg!(windows) { + // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the + // binaries. + try_hard_link( + Path::new("target").join(channel).join(&cg_clif_dylib), + target_dir.join("bin").join(cg_clif_dylib), + ); + } else { + try_hard_link( + Path::new("target").join(channel).join(&cg_clif_dylib), + target_dir.join("lib").join(cg_clif_dylib), + ); + } // Copy supporting files try_hard_link("rust-toolchain", target_dir.join("rust-toolchain")); @@ -141,8 +152,10 @@ fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str) rustflags.push_str(" -Zmir-opt-level=3"); } build_cmd.env("RUSTFLAGS", rustflags); - build_cmd - .env("RUSTC", target_dir.join("bin").join("cg_clif_build_sysroot").canonicalize().unwrap()); + build_cmd.env( + "RUSTC", + env::current_dir().unwrap().join(target_dir).join("bin").join("cg_clif_build_sysroot"), + ); // FIXME Enable incremental again once rust-lang/rust#74946 is fixed build_cmd.env("CARGO_INCREMENTAL", "0").env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif"); spawn_and_wait(build_cmd); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index b5011ceb159..d26f24f8856 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -1,13 +1,12 @@ +use std::env; use std::ffi::OsStr; use std::ffi::OsString; use std::fs; use std::path::Path; -use std::path::PathBuf; use std::process::Command; -use crate::rustc_info::get_rustc_path; -use crate::utils::copy_dir_recursively; -use crate::utils::spawn_and_wait; +use crate::rustc_info::{get_file_name, get_rustc_path}; +use crate::utils::{copy_dir_recursively, spawn_and_wait}; pub(crate) fn prepare() { prepare_sysroot(); @@ -38,13 +37,18 @@ pub(crate) fn prepare() { let mut build_cmd = Command::new("cargo"); build_cmd.arg("build").env_remove("CARGO_TARGET_DIR").current_dir("simple-raytracer"); spawn_and_wait(build_cmd); - fs::copy("simple-raytracer/target/debug/main", "simple-raytracer/raytracer_cg_llvm").unwrap(); + fs::copy( + Path::new("simple-raytracer/target/debug").join(get_file_name("main", "bin")), + // FIXME use get_file_name here too once testing is migrated to rust + "simple-raytracer/raytracer_cg_llvm", + ) + .unwrap(); } fn prepare_sysroot() { let rustc_path = get_rustc_path(); let sysroot_src_orig = rustc_path.parent().unwrap().join("../lib/rustlib/src/rust"); - let sysroot_src = PathBuf::from("build_sysroot").canonicalize().unwrap().join("sysroot_src"); + let sysroot_src = env::current_dir().unwrap().join("build_sysroot").join("sysroot_src"); assert!(sysroot_src_orig.exists()); @@ -114,7 +118,7 @@ fn get_patches(crate_name: &str) -> Vec { fn apply_patches(crate_name: &str, target_dir: &Path) { for patch in get_patches(crate_name) { eprintln!("[PATCH] {:?} <- {:?}", target_dir.file_name().unwrap(), patch); - let patch_arg = Path::new("patches").join(patch).canonicalize().unwrap(); + let patch_arg = env::current_dir().unwrap().join("patches").join(patch); let mut apply_patch_cmd = Command::new("git"); apply_patch_cmd.arg("am").arg(patch_arg).arg("-q").current_dir(target_dir); spawn_and_wait(apply_patch_cmd); diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index f7f5d42fe09..3bf86d9a114 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -37,15 +37,23 @@ pub(crate) fn get_default_sysroot() -> PathBuf { Path::new(String::from_utf8(default_sysroot).unwrap().trim()).to_owned() } -pub(crate) fn get_dylib_name(crate_name: &str) -> String { - let dylib_name = Command::new("rustc") +pub(crate) fn get_file_name(crate_name: &str, crate_type: &str) -> String { + let file_name = Command::new("rustc") .stderr(Stdio::inherit()) - .args(&["--crate-name", crate_name, "--crate-type", "dylib", "--print", "file-names", "-"]) + .args(&[ + "--crate-name", + crate_name, + "--crate-type", + crate_type, + "--print", + "file-names", + "-", + ]) .output() .unwrap() .stdout; - let dylib_name = String::from_utf8(dylib_name).unwrap().trim().to_owned(); - assert!(!dylib_name.contains('\n')); - assert!(dylib_name.contains(crate_name)); - dylib_name + let file_name = String::from_utf8(file_name).unwrap().trim().to_owned(); + assert!(!file_name.contains('\n')); + assert!(file_name.contains(crate_name)); + file_name } -- cgit 1.4.1-3-g733a5 From b0d7b526d96fc428123444d8852e6ab5674f809e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Jun 2021 13:41:20 +0200 Subject: [CI] Test compilation on Windows --- .github/workflows/main.yml | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6734920bdd6..4442cbe5f94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -87,3 +87,63 @@ jobs: with: name: cg_clif-${{ runner.os }}-cross-x86_64-mingw path: cg_clif.tar.xz + + build_windows: + runs-on: windows-latest + timeout-minutes: 60 + + steps: + - uses: actions/checkout@v2 + + #- name: Cache cargo installed crates + # uses: actions/cache@v2 + # with: + # path: ~/.cargo/bin + # key: ${{ runner.os }}-cargo-installed-crates + + #- name: Cache cargo registry and index + # uses: actions/cache@v2 + # with: + # path: | + # ~/.cargo/registry + # ~/.cargo/git + # key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }} + + #- name: Cache cargo target dir + # uses: actions/cache@v2 + # with: + # path: target + # key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} + + - name: Prepare dependencies + run: | + git config --global user.email "user@example.com" + git config --global user.name "User" + git config --global core.autocrlf false + rustup set default-host x86_64-pc-windows-gnu + rustc y.rs -o y.exe -g + ./y.exe prepare + + - name: Build + #name: Test + run: | + # Enable backtraces for easier debugging + #export RUST_BACKTRACE=1 + + # Reduce amount of benchmark runs as they are slow + #export COMPILE_RUNS=2 + #export RUN_RUNS=2 + + # Enable extra checks + #export CG_CLIF_ENABLE_VERIFIER=1 + + ./y.exe build + + #- name: Package prebuilt cg_clif + # run: tar cvfJ cg_clif.tar.xz build + + #- name: Upload prebuilt cg_clif + # uses: actions/upload-artifact@v2 + # with: + # name: cg_clif-${{ runner.os }} + # path: cg_clif.tar.xz -- cgit 1.4.1-3-g733a5 From bc67726882cc368e6aa382ea97c616d666d9b11d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 18 Jun 2021 16:18:44 +0200 Subject: Update rust-analyzer import assist config --- .vscode/settings.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cec110792ce..38ffef5ac99 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,9 @@ { // source for rustc_* is not included in the rust-src component; disable the errors about this "rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"], - "rust-analyzer.assist.importMergeBehavior": "last", + "rust-analyzer.assist.importGranularity": "module", + "rust-analyzer.assist.importEnforceGranularity": true, + "rust-analyzer.assist.importPrefix": "by_crate", "rust-analyzer.cargo.runBuildScripts": true, "rust-analyzer.linkedProjects": [ "./Cargo.toml", -- cgit 1.4.1-3-g733a5 From d571910f4dd057d26c7c2f483a4b3a813e292d00 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Jun 2021 14:07:56 +0200 Subject: Give an error when attempting to build for MSVC --- y.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/y.rs b/y.rs index 27ab44f5870..55457745d25 100755 --- a/y.rs +++ b/y.rs @@ -127,6 +127,14 @@ fn main() { host_triple.clone() }; + if target_triple.ends_with("-msvc") { + eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift."); + eprintln!("Switch to the MinGW toolchain for Windows support."); + eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to"); + eprintln!("set the global default target to MinGW"); + process::exit(1); + } + let cg_clif_dylib = build_backend::build_backend(channel); build_sysroot::build_sysroot( channel, -- cgit 1.4.1-3-g733a5 From 9fd8fa21231e488c3f784e811b9f7c7548561594 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 19 Jun 2021 14:51:48 +0200 Subject: Move some things from config.sh to ext_config.sh --- scripts/config.sh | 5 ----- scripts/ext_config.sh | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/config.sh b/scripts/config.sh index 99b302ee1d9..1aeed266d9a 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -18,10 +18,5 @@ export RUSTC=$dir"/bin/cg_clif" export RUSTDOCFLAGS=$linker' -Cpanic=abort -Zpanic-abort-tests '\ '-Zcodegen-backend='$dir'/lib/'$dylib' --sysroot '$dir -# FIXME fix `#[linkage = "extern_weak"]` without this -if [[ "$(uname)" == 'Darwin' ]]; then - export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup" -fi - export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib:"$dir"/lib" export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH diff --git a/scripts/ext_config.sh b/scripts/ext_config.sh index 3f98d77d76c..9f8331865ce 100644 --- a/scripts/ext_config.sh +++ b/scripts/ext_config.sh @@ -25,3 +25,8 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then echo "Unknown non-native platform" fi fi + +# FIXME fix `#[linkage = "extern_weak"]` without this +if [[ "$(uname)" == 'Darwin' ]]; then + export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup" +fi -- cgit 1.4.1-3-g733a5 From b497c7d9549ebb576d0212d53088ab9d48aa9cef Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 11 May 2021 22:05:54 +0200 Subject: Make allocator_kind a query. --- src/allocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index 357a9f2daf7..d39486c2f10 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -19,7 +19,7 @@ pub(crate) fn codegen( }); if any_dynamic_crate { false - } else if let Some(kind) = tcx.allocator_kind() { + } else if let Some(kind) = tcx.allocator_kind(()) { codegen_inner(module, unwind_context, kind); true } else { -- cgit 1.4.1-3-g733a5 From 80e9188fb1a404427513e080b8a27ac262769614 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 20 Jun 2021 12:41:40 +0200 Subject: Rewrite cargo.sh in rust --- Readme.md | 2 +- build_system/build_sysroot.rs | 12 ++++-- docs/usage.md | 6 +-- scripts/cargo.rs | 85 +++++++++++++++++++++++++++++++++++++++++++ scripts/cargo.sh | 18 --------- scripts/config.sh | 17 +-------- scripts/ext_config.sh | 2 +- scripts/filter_profile.rs | 5 ++- scripts/setup_rust_fork.sh | 2 +- scripts/tests.sh | 35 +++++++++--------- 10 files changed, 121 insertions(+), 63 deletions(-) create mode 100644 scripts/cargo.rs delete mode 100755 scripts/cargo.sh diff --git a/Readme.md b/Readme.md index 37644b6382c..dad8ed90b53 100644 --- a/Readme.md +++ b/Readme.md @@ -37,7 +37,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo In the directory with your project (where you can do the usual `cargo build`), run: ```bash -$ $cg_clif_dir/build/cargo.sh build +$ $cg_clif_dir/build/cargo build ``` This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend. diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 547159438e9..507af3f9aa7 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -43,10 +43,14 @@ pub(crate) fn build_sysroot( ); } - // Copy supporting files - try_hard_link("rust-toolchain", target_dir.join("rust-toolchain")); - try_hard_link("scripts/config.sh", target_dir.join("config.sh")); - try_hard_link("scripts/cargo.sh", target_dir.join("cargo.sh")); + // Build and copy cargo wrapper + let mut build_cargo_wrapper_cmd = Command::new("rustc"); + build_cargo_wrapper_cmd + .arg("scripts/cargo.rs") + .arg("-o") + .arg(target_dir.join("cargo")) + .arg("-g"); + spawn_and_wait(build_cargo_wrapper_cmd); let default_sysroot = crate::rustc_info::get_default_sysroot(); diff --git a/docs/usage.md b/docs/usage.md index 7e1e0a9bc9d..aac44b62d01 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -9,7 +9,7 @@ Assuming `$cg_clif_dir` is the directory you cloned this repo into and you follo In the directory with your project (where you can do the usual `cargo build`), run: ```bash -$ $cg_clif_dir/build/cargo.sh build +$ $cg_clif_dir/build/cargo build ``` This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend. @@ -30,7 +30,7 @@ In jit mode cg_clif will immediately execute your code without creating an execu > The jit mode will probably need cargo integration to make this possible. ```bash -$ $cg_clif_dir/build/cargo.sh jit +$ $cg_clif_dir/build/cargo jit ``` or @@ -44,7 +44,7 @@ first called. It currently does not work with multi-threaded programs. When a no function is called from another thread than the main thread, you will get an ICE. ```bash -$ $cg_clif_dir/build/cargo.sh lazy-jit +$ $cg_clif_dir/build/cargo lazy-jit ``` ## Shell diff --git a/scripts/cargo.rs b/scripts/cargo.rs new file mode 100644 index 00000000000..543e7c19276 --- /dev/null +++ b/scripts/cargo.rs @@ -0,0 +1,85 @@ +use std::env; +use std::os::unix::process::CommandExt; +use std::path::PathBuf; +use std::process::{Command, Stdio}; + +fn main() { + if env::var("RUSTC_WRAPPER").map_or(false, |wrapper| wrapper.contains("sccache")) { + eprintln!( + "\x1b[1;93m=== Warning: Unsetting RUSTC_WRAPPER to prevent interference with sccache ===\x1b[0m" + ); + env::remove_var("RUSTC_WRAPPER"); + } + + let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap()); + + env::set_var("RUSTC", sysroot.join("bin/cg_clif".to_string() + env::consts::EXE_SUFFIX)); + + let mut rustdoc_flags = env::var("RUSTDOCFLAGS").unwrap_or(String::new()); + rustdoc_flags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend="); + rustdoc_flags.push_str( + sysroot + .join(if cfg!(windows) { "bin" } else { "lib" }) + .join( + env::consts::DLL_PREFIX.to_string() + + "rustc_codegen_cranelift" + + env::consts::DLL_SUFFIX, + ) + .to_str() + .unwrap(), + ); + rustdoc_flags.push_str(" --sysroot "); + rustdoc_flags.push_str(sysroot.to_str().unwrap()); + env::set_var("RUSTDOCFLAGS", rustdoc_flags); + + let default_sysroot = Command::new("rustc") + .stderr(Stdio::inherit()) + .args(&["--print", "sysroot"]) + .output() + .unwrap() + .stdout; + let default_sysroot = std::str::from_utf8(&default_sysroot).unwrap().trim(); + + let extra_ld_lib_path = + default_sysroot.to_string() + ":" + sysroot.join("lib").to_str().unwrap(); + if cfg!(target_os = "macos") { + env::set_var( + "DYLD_LIBRARY_PATH", + env::var("DYLD_LIBRARY_PATH").unwrap_or(String::new()) + ":" + &extra_ld_lib_path, + ); + } else if cfg!(unix) { + env::set_var( + "LD_LIBRARY_PATH", + env::var("LD_LIBRARY_PATH").unwrap_or(String::new()) + ":" + &extra_ld_lib_path, + ); + } + + // Ensure that the right toolchain is used + env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); + + let args: Vec<_> = match env::args().nth(1).as_deref() { + Some("jit") => { + env::set_var( + "RUSTFLAGS", + env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", + ); + std::array::IntoIter::new(["rustc".to_string()]) + .chain(env::args().skip(2)) + .chain(["--".to_string(), "-Cllvm-args=mode=jit".to_string()]) + .collect() + } + Some("lazy-jit") => { + env::set_var( + "RUSTFLAGS", + env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic", + ); + std::array::IntoIter::new(["rustc".to_string()]) + .chain(env::args().skip(2)) + .chain(["--".to_string(), "-Cllvm-args=mode=jit-lazy".to_string()]) + .collect() + } + _ => env::args().skip(1).collect(), + }; + + Command::new("cargo").args(args).exec(); +} diff --git a/scripts/cargo.sh b/scripts/cargo.sh deleted file mode 100755 index 267b5d99a08..00000000000 --- a/scripts/cargo.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -dir=$(dirname "$0") -source "$dir/config.sh" - -# read nightly compiler from rust-toolchain file -TOOLCHAIN=$(cat "$dir/rust-toolchain" | grep channel | sed "s/channel = \"\(.*\)\"/\1/") - -cmd=$1 -shift || true - -if [[ "$cmd" = "jit" ]]; then -RUSTFLAGS="-Cprefer-dynamic" cargo "+${TOOLCHAIN}" rustc "$@" -- -Cllvm-args=mode=jit -elif [[ "$cmd" = "lazy-jit" ]]; then -RUSTFLAGS="-Cprefer-dynamic" cargo "+${TOOLCHAIN}" rustc "$@" -- -Cllvm-args=mode=jit-lazy -else -cargo "+${TOOLCHAIN}" "$cmd" "$@" -fi diff --git a/scripts/config.sh b/scripts/config.sh index 1aeed266d9a..cf325ab574e 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -2,21 +2,6 @@ set -e -dylib=$(echo "" | rustc --print file-names --crate-type dylib --crate-name rustc_codegen_cranelift -) - -if echo "$RUSTC_WRAPPER" | grep sccache; then -echo -echo -e "\x1b[1;93m=== Warning: Unset RUSTC_WRAPPER to prevent interference with sccache ===\x1b[0m" -echo -export RUSTC_WRAPPER= -fi - -dir=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd) - -export RUSTC=$dir"/bin/cg_clif" - -export RUSTDOCFLAGS=$linker' -Cpanic=abort -Zpanic-abort-tests '\ -'-Zcodegen-backend='$dir'/lib/'$dylib' --sysroot '$dir - +dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../build"; pwd) export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib:"$dir"/lib" export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH diff --git a/scripts/ext_config.sh b/scripts/ext_config.sh index 9f8331865ce..11d6c4c8318 100644 --- a/scripts/ext_config.sh +++ b/scripts/ext_config.sh @@ -1,6 +1,6 @@ # Note to people running shellcheck: this file should only be sourced, not executed directly. -# Various env vars that should only be set for the build system but not for cargo.sh +# Various env vars that should only be set for the build system set -e diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index 15388926ec9..9e196afbe4f 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -2,9 +2,10 @@ #![forbid(unsafe_code)]/* This line is ignored by bash # This block is ignored by rustc pushd $(dirname "$0")/../ -source build/config.sh +source scripts/config.sh +RUSTC="$(pwd)/build/bin/cg_clif" popd -PROFILE=$1 OUTPUT=$2 exec $RUSTC $RUSTFLAGS -Cllvm-args=mode=jit -Cprefer-dynamic $0 +PROFILE=$1 OUTPUT=$2 exec $RUSTC -Cllvm-args=mode=jit -Cprefer-dynamic $0 #*/ //! This program filters away uninteresting samples and trims uninteresting frames for stackcollapse diff --git a/scripts/setup_rust_fork.sh b/scripts/setup_rust_fork.sh index c494e78050a..52adaaa8de6 100644 --- a/scripts/setup_rust_fork.sh +++ b/scripts/setup_rust_fork.sh @@ -2,7 +2,7 @@ set -e ./y.rs build -source build/config.sh +source scripts/config.sh echo "[SETUP] Rust fork" git clone https://github.com/rust-lang/rust.git || true diff --git a/scripts/tests.sh b/scripts/tests.sh index 243a0ef2851..c875aad2849 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -2,9 +2,10 @@ set -e -source build/config.sh +source scripts/config.sh source scripts/ext_config.sh -MY_RUSTC="$RUSTC $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2" +export RUSTC=false # ensure that cg_llvm isn't accidentally used +MY_RUSTC="$(pwd)/build/bin/cg_clif $RUSTFLAGS -L crate=target/out --out-dir target/out -Cdebuginfo=2" function no_sysroot_tests() { echo "[BUILD] mini_core" @@ -75,64 +76,64 @@ function base_sysroot_tests() { function extended_sysroot_tests() { pushd rand - cargo clean + ../build/cargo clean if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then echo "[TEST] rust-random/rand" - ../build/cargo.sh test --workspace + ../build/cargo test --workspace else echo "[AOT] rust-random/rand" - ../build/cargo.sh build --workspace --target $TARGET_TRIPLE --tests + ../build/cargo build --workspace --target $TARGET_TRIPLE --tests fi popd pushd simple-raytracer if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then echo "[BENCH COMPILE] ebobby/simple-raytracer" - hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "cargo clean" \ + hyperfine --runs "${RUN_RUNS:-10}" --warmup 1 --prepare "../build/cargo clean" \ "RUSTC=rustc RUSTFLAGS='' cargo build" \ - "../build/cargo.sh build" + "../build/cargo build" echo "[BENCH RUN] ebobby/simple-raytracer" cp ./target/debug/main ./raytracer_cg_clif hyperfine --runs "${RUN_RUNS:-10}" ./raytracer_cg_llvm ./raytracer_cg_clif else - cargo clean + ../build/cargo clean echo "[BENCH COMPILE] ebobby/simple-raytracer (skipped)" echo "[COMPILE] ebobby/simple-raytracer" - ../build/cargo.sh build --target $TARGET_TRIPLE + ../build/cargo build --target $TARGET_TRIPLE echo "[BENCH RUN] ebobby/simple-raytracer (skipped)" fi popd pushd build_sysroot/sysroot_src/library/core/tests echo "[TEST] libcore" - cargo clean + ../../../../../build/cargo clean if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then - ../../../../../build/cargo.sh test + ../../../../../build/cargo test else - ../../../../../build/cargo.sh build --target $TARGET_TRIPLE --tests + ../../../../../build/cargo build --target $TARGET_TRIPLE --tests fi popd pushd regex echo "[TEST] rust-lang/regex example shootout-regex-dna" - cargo clean + ../build/cargo clean export RUSTFLAGS="$RUSTFLAGS --cap-lints warn" # newer aho_corasick versions throw a deprecation warning # Make sure `[codegen mono items] start` doesn't poison the diff - ../build/cargo.sh build --example shootout-regex-dna --target $TARGET_TRIPLE + ../build/cargo build --example shootout-regex-dna --target $TARGET_TRIPLE if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then cat examples/regexdna-input.txt \ - | ../build/cargo.sh run --example shootout-regex-dna --target $TARGET_TRIPLE \ + | ../build/cargo run --example shootout-regex-dna --target $TARGET_TRIPLE \ | grep -v "Spawned thread" > res.txt diff -u res.txt examples/regexdna-output.txt fi if [[ "$HOST_TRIPLE" = "$TARGET_TRIPLE" ]]; then echo "[TEST] rust-lang/regex tests" - ../build/cargo.sh test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q + ../build/cargo test --tests -- --exclude-should-panic --test-threads 1 -Zunstable-options -q else echo "[AOT] rust-lang/regex tests" - ../build/cargo.sh build --tests --target $TARGET_TRIPLE + ../build/cargo build --tests --target $TARGET_TRIPLE fi popd } -- cgit 1.4.1-3-g733a5 From 62e49c5b61c196c942e644c0b81b0f4b232bd461 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 20 Jun 2021 13:20:51 +0200 Subject: Fix compiling cargo.rs on windows --- scripts/cargo.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/cargo.rs b/scripts/cargo.rs index 543e7c19276..fdb9bcf6dbc 100644 --- a/scripts/cargo.rs +++ b/scripts/cargo.rs @@ -1,4 +1,5 @@ use std::env; +#[cfg(unix)] use std::os::unix::process::CommandExt; use std::path::PathBuf; use std::process::{Command, Stdio}; @@ -81,5 +82,11 @@ fn main() { _ => env::args().skip(1).collect(), }; + #[cfg(unix)] Command::new("cargo").args(args).exec(); + + #[cfg(not(unix))] + std::process::exit( + Command::new("cargo").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), + ); } -- cgit 1.4.1-3-g733a5 From 03c9ecfb306f00fa39595c63d062f7ab98d6f19f Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 20 Jun 2021 14:40:49 +0200 Subject: Remove unnecessary LD_LIBRARY_PATH parts --- scripts/cargo.rs | 14 -------------- scripts/config.sh | 3 +-- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/scripts/cargo.rs b/scripts/cargo.rs index fdb9bcf6dbc..5cb352a1aff 100644 --- a/scripts/cargo.rs +++ b/scripts/cargo.rs @@ -41,20 +41,6 @@ fn main() { .stdout; let default_sysroot = std::str::from_utf8(&default_sysroot).unwrap().trim(); - let extra_ld_lib_path = - default_sysroot.to_string() + ":" + sysroot.join("lib").to_str().unwrap(); - if cfg!(target_os = "macos") { - env::set_var( - "DYLD_LIBRARY_PATH", - env::var("DYLD_LIBRARY_PATH").unwrap_or(String::new()) + ":" + &extra_ld_lib_path, - ); - } else if cfg!(unix) { - env::set_var( - "LD_LIBRARY_PATH", - env::var("LD_LIBRARY_PATH").unwrap_or(String::new()) + ":" + &extra_ld_lib_path, - ); - } - // Ensure that the right toolchain is used env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); diff --git a/scripts/config.sh b/scripts/config.sh index cf325ab574e..d316a7c6981 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -2,6 +2,5 @@ set -e -dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../build"; pwd) -export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib:"$dir"/lib" +export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib" export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH -- cgit 1.4.1-3-g733a5 From 089d986c5c9ce6237013a4842f3093e721d4f589 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 20 Jun 2021 18:26:17 +0200 Subject: Remove unused variable --- scripts/cargo.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/scripts/cargo.rs b/scripts/cargo.rs index 5cb352a1aff..b7e8dd44974 100644 --- a/scripts/cargo.rs +++ b/scripts/cargo.rs @@ -2,7 +2,7 @@ use std::env; #[cfg(unix)] use std::os::unix::process::CommandExt; use std::path::PathBuf; -use std::process::{Command, Stdio}; +use std::process::Command; fn main() { if env::var("RUSTC_WRAPPER").map_or(false, |wrapper| wrapper.contains("sccache")) { @@ -33,14 +33,6 @@ fn main() { rustdoc_flags.push_str(sysroot.to_str().unwrap()); env::set_var("RUSTDOCFLAGS", rustdoc_flags); - let default_sysroot = Command::new("rustc") - .stderr(Stdio::inherit()) - .args(&["--print", "sysroot"]) - .output() - .unwrap() - .stdout; - let default_sysroot = std::str::from_utf8(&default_sysroot).unwrap().trim(); - // Ensure that the right toolchain is used env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); -- cgit 1.4.1-3-g733a5 From 57c6eb7b2ba4375039d289e84e51e9e784b08f31 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Jun 2021 17:49:43 +0200 Subject: Test multithreading support in lazy-jit --- example/std_example.rs | 2 -- scripts/tests.sh | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/example/std_example.rs b/example/std_example.rs index 7d608df9253..5bc51a541b5 100644 --- a/example/std_example.rs +++ b/example/std_example.rs @@ -15,8 +15,6 @@ fn main() { let stderr = ::std::io::stderr(); let mut stderr = stderr.lock(); - // FIXME support lazy jit when multi threading - #[cfg(not(lazy_jit))] std::thread::spawn(move || { println!("Hello from another thread!"); }); diff --git a/scripts/tests.sh b/scripts/tests.sh index 243a0ef2851..9bbda6b8059 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -46,7 +46,7 @@ function base_sysroot_tests() { $MY_RUSTC -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" echo "[JIT-lazy] std_example" - $MY_RUSTC -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --cfg lazy_jit --target "$HOST_TRIPLE" + $MY_RUSTC -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" else echo "[JIT] std_example (skipped)" fi -- cgit 1.4.1-3-g733a5 From 4d289dba2ea409672600c571004fee64ec931a10 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Sun, 20 Jun 2021 17:43:25 +0800 Subject: Update other codegens to use tcx managed vtable allocations. --- src/common.rs | 2 +- src/constant.rs | 2 +- src/lib.rs | 2 +- src/unsize.rs | 4 +-- src/vtable.rs | 106 ++++++-------------------------------------------------- 5 files changed, 14 insertions(+), 102 deletions(-) diff --git a/src/common.rs b/src/common.rs index 488ff6e1349..a8a0bb52a24 100644 --- a/src/common.rs +++ b/src/common.rs @@ -233,7 +233,7 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) module: &'m mut dyn Module, pub(crate) tcx: TyCtxt<'tcx>, pub(crate) pointer_type: Type, // Cached from module - pub(crate) vtables: FxHashMap<(Ty<'tcx>, Option>), DataId>, + pub(crate) vtables: FxHashMap<(Ty<'tcx>, Option>), Pointer>, pub(crate) constants_cx: ConstantCx, pub(crate) instance: Instance<'tcx>, diff --git a/src/constant.rs b/src/constant.rs index 3ba12c4e96d..a87b3703949 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -249,7 +249,7 @@ pub(crate) fn codegen_const_value<'tcx>( } } -fn pointer_for_allocation<'tcx>( +pub(crate) fn pointer_for_allocation<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, alloc: &'tcx Allocation, ) -> crate::pointer::Pointer { diff --git a/src/lib.rs b/src/lib.rs index 6aadaf8a7ca..b817bf4aff7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,7 @@ mod prelude { pub(crate) use cranelift_codegen::isa::{self, CallConv}; pub(crate) use cranelift_codegen::Context; pub(crate) use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable}; - pub(crate) use cranelift_module::{self, DataContext, DataId, FuncId, Linkage, Module}; + pub(crate) use cranelift_module::{self, DataContext, FuncId, Linkage, Module}; pub(crate) use crate::abi::*; pub(crate) use crate::base::{codegen_operand, codegen_place}; diff --git a/src/unsize.rs b/src/unsize.rs index 042583cd572..b9d379c6117 100644 --- a/src/unsize.rs +++ b/src/unsize.rs @@ -31,9 +31,7 @@ pub(crate) fn unsized_info<'tcx>( // change to the vtable. old_info.expect("unsized_info: missing old info for trait upcast") } - (_, &ty::Dynamic(ref data, ..)) => { - crate::vtable::get_vtable(fx, fx.layout_of(source), data.principal()) - } + (_, &ty::Dynamic(ref data, ..)) => crate::vtable::get_vtable(fx, source, data.principal()), _ => bug!("unsized_info: invalid unsizing {:?} -> {:?}", source, target), } } diff --git a/src/vtable.rs b/src/vtable.rs index 4d1ee47b41e..12f7092d935 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -4,7 +4,7 @@ // FIXME dedup this logic between miri, cg_llvm and cg_clif use crate::prelude::*; -use ty::VtblEntry; +use super::constant::pointer_for_allocation; fn vtable_memflags() -> MemFlags { let mut flags = MemFlags::trusted(); // A vtable access is always aligned and will never trap. @@ -66,105 +66,19 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( pub(crate) fn get_vtable<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, - layout: TyAndLayout<'tcx>, + ty: Ty<'tcx>, trait_ref: Option>, ) -> Value { - let data_id = if let Some(data_id) = fx.vtables.get(&(layout.ty, trait_ref)) { - *data_id + let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) { + *vtable_ptr } else { - let data_id = build_vtable(fx, layout, trait_ref); - fx.vtables.insert((layout.ty, trait_ref), data_id); - data_id - }; - - let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) -} - -fn build_vtable<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - layout: TyAndLayout<'tcx>, - trait_ref: Option>, -) -> DataId { - let tcx = fx.tcx; - let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize; + let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); + let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); + let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); - let drop_in_place_fn = import_function( - tcx, - fx.module, - Instance::resolve_drop_in_place(tcx, layout.ty).polymorphize(fx.tcx), - ); - - let vtable_entries = if let Some(trait_ref) = trait_ref { - tcx.vtable_entries(trait_ref.with_self_ty(tcx, layout.ty)) - } else { - ty::COMMON_VTABLE_ENTRIES + fx.vtables.insert((ty, trait_ref), vtable_ptr); + vtable_ptr }; - let mut data_ctx = DataContext::new(); - let mut data = ::std::iter::repeat(0u8) - .take(vtable_entries.len() * usize_size) - .collect::>() - .into_boxed_slice(); - - for (idx, entry) in vtable_entries.iter().enumerate() { - match entry { - VtblEntry::MetadataSize => { - write_usize(fx.tcx, &mut data, idx, layout.size.bytes()); - } - VtblEntry::MetadataAlign => { - write_usize(fx.tcx, &mut data, idx, layout.align.abi.bytes()); - } - VtblEntry::MetadataDropInPlace | VtblEntry::Vacant | VtblEntry::Method(_, _) => {} - } - } - data_ctx.define(data); - - for (idx, entry) in vtable_entries.iter().enumerate() { - match entry { - VtblEntry::MetadataDropInPlace => { - let func_ref = fx.module.declare_func_in_data(drop_in_place_fn, &mut data_ctx); - data_ctx.write_function_addr((idx * usize_size) as u32, func_ref); - } - VtblEntry::Method(def_id, substs) => { - let func_id = import_function( - tcx, - fx.module, - Instance::resolve_for_vtable(tcx, ParamEnv::reveal_all(), *def_id, substs) - .unwrap() - .polymorphize(fx.tcx), - ); - let func_ref = fx.module.declare_func_in_data(func_id, &mut data_ctx); - data_ctx.write_function_addr((idx * usize_size) as u32, func_ref); - } - VtblEntry::MetadataSize | VtblEntry::MetadataAlign | VtblEntry::Vacant => {} - } - } - - data_ctx.set_align(fx.tcx.data_layout.pointer_align.pref.bytes()); - - let data_id = fx.module.declare_anonymous_data(false, false).unwrap(); - - fx.module.define_data(data_id, &data_ctx).unwrap(); - - data_id -} - -fn write_usize(tcx: TyCtxt<'_>, buf: &mut [u8], idx: usize, num: u64) { - let pointer_size = - tcx.layout_of(ParamEnv::reveal_all().and(tcx.types.usize)).unwrap().size.bytes() as usize; - let target = &mut buf[idx * pointer_size..(idx + 1) * pointer_size]; - - match tcx.data_layout.endian { - rustc_target::abi::Endian::Little => match pointer_size { - 4 => target.copy_from_slice(&(num as u32).to_le_bytes()), - 8 => target.copy_from_slice(&(num as u64).to_le_bytes()), - _ => todo!("pointer size {} is not yet supported", pointer_size), - }, - rustc_target::abi::Endian::Big => match pointer_size { - 4 => target.copy_from_slice(&(num as u32).to_be_bytes()), - 8 => target.copy_from_slice(&(num as u64).to_be_bytes()), - _ => todo!("pointer size {} is not yet supported", pointer_size), - }, - } + vtable_ptr.get_addr(fx) } -- cgit 1.4.1-3-g733a5 From 6048adc8b1cc5db39af736cf4531c46059b6966d Mon Sep 17 00:00:00 2001 From: Smitty Date: Sat, 12 Jun 2021 19:49:48 -0400 Subject: Support allocation failures when interperting MIR Note that this breaks Miri. Closes #79601 --- src/vtable.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vtable.rs b/src/vtable.rs index 12f7092d935..5788aabaadc 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -72,7 +72,10 @@ pub(crate) fn get_vtable<'tcx>( let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) { *vtable_ptr } else { - let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); + let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) { + Ok(alloc) => alloc, + Err(_) => fx.tcx.sess().fatal("allocation of constant vtable failed"), + }; let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); -- cgit 1.4.1-3-g733a5 From 17373a94018ee37365cc1c1c48e88372bb7c4283 Mon Sep 17 00:00:00 2001 From: Smitty Date: Tue, 29 Jun 2021 19:17:14 -0400 Subject: fix sess error This passed x.py check locally, not sure why it wasn't rebased right... --- src/vtable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vtable.rs b/src/vtable.rs index 5788aabaadc..7ee34b23e46 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -74,7 +74,7 @@ pub(crate) fn get_vtable<'tcx>( } else { let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) { Ok(alloc) => alloc, - Err(_) => fx.tcx.sess().fatal("allocation of constant vtable failed"), + Err(_) => fx.tcx.sess.fatal("allocation of constant vtable failed"), }; let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); -- cgit 1.4.1-3-g733a5 From 4cbba98420b27af2c56df1878ff1992c7993a7bc Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 30 Jun 2021 21:21:06 +0200 Subject: Rustup to rustc 1.55.0-nightly (6d820866a 2021-06-29) --- build_sysroot/Cargo.lock | 10 +++++----- build_system/prepare.rs | 2 +- rust-toolchain | 2 +- src/base.rs | 6 +++++- src/common.rs | 1 - src/lib.rs | 10 ++-------- src/vtable.rs | 16 ++++------------ 7 files changed, 18 insertions(+), 29 deletions(-) diff --git a/build_sysroot/Cargo.lock b/build_sysroot/Cargo.lock index bcf692f1dc6..46f661107e7 100644 --- a/build_sysroot/Cargo.lock +++ b/build_sysroot/Cargo.lock @@ -56,7 +56,7 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.45" +version = "0.1.46" dependencies = [ "rustc-std-workspace-core", ] @@ -121,9 +121,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "compiler_builtins", "libc", @@ -195,9 +195,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410f7acf3cb3a44527c5d9546bad4bf4e6c460915d5f9f2fc524498bfe8f70ce" +checksum = "dead70b0b5e03e9c814bcb6b01e03e68f7c57a80aa48c72ec92152ab3e818d49" dependencies = [ "compiler_builtins", "rustc-std-workspace-core", diff --git a/build_system/prepare.rs b/build_system/prepare.rs index d26f24f8856..1f4ec825e1e 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -82,7 +82,7 @@ fn prepare_sysroot() { clone_repo( "build_sysroot/compiler-builtins", "https://github.com/rust-lang/compiler-builtins.git", - "0.1.45", + "0.1.46", ); apply_patches("compiler-builtins", Path::new("build_sysroot/compiler-builtins")); } diff --git a/rust-toolchain b/rust-toolchain index 6cb05bef6d3..c1b2d71ebc7 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-06-17" +channel = "nightly-2021-06-30" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/src/base.rs b/src/base.rs index ec3e17e5b75..f44ab276590 100644 --- a/src/base.rs +++ b/src/base.rs @@ -21,6 +21,11 @@ pub(crate) fn codegen_fn<'tcx>( debug_assert!(!instance.substs.needs_infer()); let mir = tcx.instance_mir(instance.def); + let _mir_guard = crate::PrintOnPanic(|| { + let mut buf = Vec::new(); + rustc_mir::util::write_mir_pretty(tcx, Some(instance.def_id()), &mut buf).unwrap(); + String::from_utf8_lossy(&buf).into_owned() + }); // Declare function let symbol_name = tcx.symbol_name(instance); @@ -52,7 +57,6 @@ pub(crate) fn codegen_fn<'tcx>( module, tcx, pointer_type, - vtables: FxHashMap::default(), constants_cx: ConstantCx::new(), instance, diff --git a/src/common.rs b/src/common.rs index a8a0bb52a24..892ccf27f6d 100644 --- a/src/common.rs +++ b/src/common.rs @@ -233,7 +233,6 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> { pub(crate) module: &'m mut dyn Module, pub(crate) tcx: TyCtxt<'tcx>, pub(crate) pointer_type: Type, // Cached from module - pub(crate) vtables: FxHashMap<(Ty<'tcx>, Option>), Pointer>, pub(crate) constants_cx: ConstantCx, pub(crate) instance: Instance<'tcx>, diff --git a/src/lib.rs b/src/lib.rs index 49d9dd2bb5e..6e127ce23dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,4 @@ -#![feature( - rustc_private, - decl_macro, - never_type, - hash_drain_filter, - vec_into_raw_parts, - once_cell, -)] +#![feature(rustc_private, decl_macro, never_type, hash_drain_filter, vec_into_raw_parts, once_cell)] #![warn(rust_2018_idioms)] #![warn(unused_lifetimes)] #![warn(unreachable_pub)] @@ -23,6 +16,7 @@ extern crate rustc_incremental; extern crate rustc_index; extern crate rustc_interface; extern crate rustc_metadata; +extern crate rustc_mir; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; diff --git a/src/vtable.rs b/src/vtable.rs index 1c3cd431fb4..1e1e3683877 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -1,10 +1,9 @@ //! Codegen vtables and vtable accesses. //! //! See `rustc_codegen_ssa/src/meth.rs` for reference. -// FIXME dedup this logic between miri, cg_llvm and cg_clif -use crate::prelude::*; use super::constant::pointer_for_allocation; +use crate::prelude::*; fn vtable_memflags() -> MemFlags { let mut flags = MemFlags::trusted(); // A vtable access is always aligned and will never trap. @@ -69,16 +68,9 @@ pub(crate) fn get_vtable<'tcx>( ty: Ty<'tcx>, trait_ref: Option>, ) -> Value { - let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) { - *vtable_ptr - } else { - let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); - let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); - let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); - - fx.vtables.insert((ty, trait_ref), vtable_ptr); - vtable_ptr - }; + let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); + let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); + let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); vtable_ptr.get_addr(fx) } -- cgit 1.4.1-3-g733a5 From f5a16339562a2e6f597fc94e82ec8f7d67902e2e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 1 Jul 2021 12:05:10 +0200 Subject: Reduce duplication of vtables --- src/constant.rs | 17 +++++++++++------ src/vtable.rs | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index a87b3703949..d22ebd5e2ff 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -190,7 +190,6 @@ pub(crate) fn codegen_const_value<'tcx>( let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id); let base_addr = match alloc_kind { Some(GlobalAlloc::Memory(alloc)) => { - fx.constants_cx.todo.push(TodoItem::Alloc(ptr.alloc_id)); let data_id = data_id_for_alloc_id( &mut fx.constants_cx, fx.module, @@ -249,12 +248,11 @@ pub(crate) fn codegen_const_value<'tcx>( } } -pub(crate) fn pointer_for_allocation<'tcx>( +fn pointer_for_allocation<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, alloc: &'tcx Allocation, ) -> crate::pointer::Pointer { let alloc_id = fx.tcx.create_memory_alloc(alloc); - fx.constants_cx.todo.push(TodoItem::Alloc(alloc_id)); let data_id = data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, alloc.mutability); @@ -266,12 +264,13 @@ pub(crate) fn pointer_for_allocation<'tcx>( crate::pointer::Pointer::new(global_ptr) } -fn data_id_for_alloc_id( +pub(crate) fn data_id_for_alloc_id( cx: &mut ConstantCx, module: &mut dyn Module, alloc_id: AllocId, mutability: rustc_hir::Mutability, ) -> DataId { + cx.todo.push(TodoItem::Alloc(alloc_id)); *cx.anon_allocs.entry(alloc_id).or_insert_with(|| { module.declare_anonymous_data(mutability == rustc_hir::Mutability::Mut, false).unwrap() }) @@ -352,7 +351,14 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant GlobalAlloc::Memory(alloc) => alloc, GlobalAlloc::Function(_) | GlobalAlloc::Static(_) => unreachable!(), }; - let data_id = data_id_for_alloc_id(cx, module, alloc_id, alloc.mutability); + let data_id = *cx.anon_allocs.entry(alloc_id).or_insert_with(|| { + module + .declare_anonymous_data( + alloc.mutability == rustc_hir::Mutability::Mut, + false, + ) + .unwrap() + }); (data_id, alloc, None) } TodoItem::Static(def_id) => { @@ -415,7 +421,6 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant continue; } GlobalAlloc::Memory(target_alloc) => { - cx.todo.push(TodoItem::Alloc(reloc)); data_id_for_alloc_id(cx, module, reloc, target_alloc.mutability) } GlobalAlloc::Static(def_id) => { diff --git a/src/vtable.rs b/src/vtable.rs index 1e1e3683877..021686544eb 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -2,7 +2,7 @@ //! //! See `rustc_codegen_ssa/src/meth.rs` for reference. -use super::constant::pointer_for_allocation; +use crate::constant::data_id_for_alloc_id; use crate::prelude::*; fn vtable_memflags() -> MemFlags { @@ -68,9 +68,16 @@ pub(crate) fn get_vtable<'tcx>( ty: Ty<'tcx>, trait_ref: Option>, ) -> Value { - let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); - let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); - let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); - - vtable_ptr.get_addr(fx) + let alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); + let data_id = data_id_for_alloc_id( + &mut fx.constants_cx, + &mut *fx.module, + alloc_id, + Mutability::Not, + ); + let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + if fx.clif_comments.enabled() { + fx.add_comment(local_data_id, format!("vtable: {:?}", alloc_id)); + } + fx.bcx.ins().global_value(fx.pointer_type, local_data_id) } -- cgit 1.4.1-3-g733a5 From e0f3ad21188f82f98de1cbaf679828dafa66b7a4 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 2 Jul 2021 11:32:27 +0200 Subject: Disable new rustc test requiring unwinding support --- scripts/test_rustc_tests.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/test_rustc_tests.sh b/scripts/test_rustc_tests.sh index 428c2480684..2f5c2cf737b 100755 --- a/scripts/test_rustc_tests.sh +++ b/scripts/test_rustc_tests.sh @@ -38,7 +38,8 @@ rm src/test/ui/threads-sendsync/task-stderr.rs rm src/test/ui/numbers-arithmetic/int-abs-overflow.rs rm src/test/ui/drop/drop-trait-enum.rs rm src/test/ui/numbers-arithmetic/issue-8460.rs -rm src/test/incremental/change_crate_dep_kind.rs # requires -Cpanic=unwind +rm src/test/ui/rt-explody-panic-payloads.rs +rm src/test/incremental/change_crate_dep_kind.rs rm src/test/ui/issues/issue-28950.rs # depends on stack size optimizations rm src/test/ui/init-large-type.rs # same -- cgit 1.4.1-3-g733a5 From ae98d5a78dfe5f9d45d69d49f4f0776bdf8afab5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 2 Jul 2021 12:07:08 +0200 Subject: Don't use data object for non-primitive scalars Fixes #1041 --- src/constant.rs | 126 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 66 insertions(+), 60 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index d22ebd5e2ff..481ba38f74d 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -1,16 +1,13 @@ //! Handling of `static`s, `const`s and promoted allocations -use rustc_span::DUMMY_SP; - -use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::ErrorReported; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::mir::interpret::{ - alloc_range, read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, - Scalar, + read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar, }; use rustc_middle::ty::ConstKind; +use rustc_span::DUMMY_SP; use cranelift_codegen::ir::GlobalValueData; use cranelift_module::*; @@ -171,65 +168,74 @@ pub(crate) fn codegen_const_value<'tcx>( } match const_val { - ConstValue::Scalar(x) => { - if fx.clif_type(layout.ty).is_none() { - let (size, align) = (layout.size, layout.align.pref); - let mut alloc = Allocation::from_bytes( - std::iter::repeat(0).take(size.bytes_usize()).collect::>(), - align, - Mutability::Not, - ); - alloc.write_scalar(fx, alloc_range(Size::ZERO, size), x.into()).unwrap(); - let alloc = fx.tcx.intern_const_alloc(alloc); - return CValue::by_ref(pointer_for_allocation(fx, alloc), layout); - } - - match x { - Scalar::Int(int) => CValue::const_val(fx, layout, int), - Scalar::Ptr(ptr) => { - let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id); - let base_addr = match alloc_kind { - Some(GlobalAlloc::Memory(alloc)) => { - let data_id = data_id_for_alloc_id( - &mut fx.constants_cx, - fx.module, - ptr.alloc_id, - alloc.mutability, - ); - let local_data_id = - fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); - if fx.clif_comments.enabled() { - fx.add_comment(local_data_id, format!("{:?}", ptr.alloc_id)); - } - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) - } - Some(GlobalAlloc::Function(instance)) => { - let func_id = crate::abi::import_function(fx.tcx, fx.module, instance); - let local_func_id = - fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); - fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) - } - Some(GlobalAlloc::Static(def_id)) => { - assert!(fx.tcx.is_static(def_id)); - let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); - let local_data_id = - fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); - if fx.clif_comments.enabled() { - fx.add_comment(local_data_id, format!("{:?}", def_id)); - } - fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + ConstValue::Scalar(x) => match x { + Scalar::Int(int) => { + if fx.clif_type(layout.ty).is_some() { + return CValue::const_val(fx, layout, int); + } else { + let raw_val = int.to_bits(int.size()).unwrap(); + let val = match int.size().bytes() { + 1 => fx.bcx.ins().iconst(types::I8, raw_val as i64), + 2 => fx.bcx.ins().iconst(types::I16, raw_val as i64), + 4 => fx.bcx.ins().iconst(types::I32, raw_val as i64), + 8 => fx.bcx.ins().iconst(types::I64, raw_val as i64), + 16 => { + let lsb = fx.bcx.ins().iconst(types::I64, raw_val as u64 as i64); + let msb = + fx.bcx.ins().iconst(types::I64, (raw_val >> 64) as u64 as i64); + fx.bcx.ins().iconcat(lsb, msb) } - None => bug!("missing allocation {:?}", ptr.alloc_id), - }; - let val = if ptr.offset.bytes() != 0 { - fx.bcx.ins().iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap()) - } else { - base_addr + _ => unreachable!(), }; - CValue::by_val(val, layout) + + let place = CPlace::new_stack_slot(fx, layout); + place.to_ptr().store(fx, val, MemFlags::trusted()); + place.to_cvalue(fx) } } - } + Scalar::Ptr(ptr) => { + let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id); + let base_addr = match alloc_kind { + Some(GlobalAlloc::Memory(alloc)) => { + let data_id = data_id_for_alloc_id( + &mut fx.constants_cx, + fx.module, + ptr.alloc_id, + alloc.mutability, + ); + let local_data_id = + fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + if fx.clif_comments.enabled() { + fx.add_comment(local_data_id, format!("{:?}", ptr.alloc_id)); + } + fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + } + Some(GlobalAlloc::Function(instance)) => { + let func_id = crate::abi::import_function(fx.tcx, fx.module, instance); + let local_func_id = + fx.module.declare_func_in_func(func_id, &mut fx.bcx.func); + fx.bcx.ins().func_addr(fx.pointer_type, local_func_id) + } + Some(GlobalAlloc::Static(def_id)) => { + assert!(fx.tcx.is_static(def_id)); + let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false); + let local_data_id = + fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); + if fx.clif_comments.enabled() { + fx.add_comment(local_data_id, format!("{:?}", def_id)); + } + fx.bcx.ins().global_value(fx.pointer_type, local_data_id) + } + None => bug!("missing allocation {:?}", ptr.alloc_id), + }; + let val = if ptr.offset.bytes() != 0 { + fx.bcx.ins().iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap()) + } else { + base_addr + }; + CValue::by_val(val, layout) + } + }, ConstValue::ByRef { alloc, offset } => CValue::by_ref( pointer_for_allocation(fx, alloc) .offset_i64(fx, i64::try_from(offset.bytes()).unwrap()), -- cgit 1.4.1-3-g733a5 From dd1419a1c4843ef306f7c5955b93f601d8da2341 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Jun 2021 19:18:17 +0200 Subject: Update Cranelift and object This adds AArch64 support for unixes using ELF object files like Linux --- Cargo.lock | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 964a002d92e..748faeaffbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "cranelift-entity", ] @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -67,17 +67,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" [[package]] name = "cranelift-entity" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" [[package]] name = "cranelift-frontend" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "cranelift-codegen", "log", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "anyhow", "cranelift-codegen", @@ -105,7 +105,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "anyhow", "cranelift-codegen", @@ -116,16 +116,17 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "cranelift-codegen", + "libc", "target-lexicon", ] [[package]] name = "cranelift-object" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#3d56728b8698d538a00d9f1c295149bbf5e8b78b" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" dependencies = [ "anyhow", "cranelift-codegen", @@ -171,9 +172,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.86" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libloading" @@ -211,9 +212,9 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "object" -version = "0.25.2" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8bc1d42047cf336f0f939c99e97183cf31551bf0f2865a2ec9c8d91fd4ffb5e" +checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7" dependencies = [ "crc32fast", "indexmap", -- cgit 1.4.1-3-g733a5 From 1bd9a132f6111b77348b8014b849b056a4f6759a Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 25 Jun 2021 19:18:53 +0200 Subject: Only test global_asm on x86_64 --- example/mini_core_hello_world.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 6570f2bf9f2..d997ce6d1b3 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -292,7 +292,7 @@ fn main() { #[cfg(not(any(jit, windows)))] test_tls(); - #[cfg(all(not(jit), target_os = "linux"))] + #[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))] unsafe { global_asm_test(); } @@ -303,12 +303,12 @@ fn main() { assert_eq!(*REF1, *REF2); } -#[cfg(all(not(jit), target_os = "linux"))] +#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))] extern "C" { fn global_asm_test(); } -#[cfg(all(not(jit), target_os = "linux"))] +#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))] global_asm! { " .global global_asm_test -- cgit 1.4.1-3-g733a5 From cda811173e5862ecf75a19df5e8c69fd5d8a4ead Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 29 Jun 2021 20:37:06 +0200 Subject: Fix compilation for AArch64 --- build_system/build_sysroot.rs | 21 ++++++++++++++++++--- src/lib.rs | 10 ++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 507af3f9aa7..72d6a0265ef 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -115,10 +115,16 @@ pub(crate) fn build_sysroot( } } SysrootKind::Clif => { - build_clif_sysroot_for_triple(channel, target_dir, target_triple); + build_clif_sysroot_for_triple(channel, target_dir, host_triple, None); if host_triple != target_triple { - build_clif_sysroot_for_triple(channel, target_dir, host_triple); + // When cross-compiling it is often necessary to manually pick the right linker + let linker = if target_triple == "aarch64-unknown-linux-gnu" { + Some("aarch64-linux-gnu-gcc") + } else { + None + }; + build_clif_sysroot_for_triple(channel, target_dir, target_triple, linker); } // Copy std for the host to the lib dir. This is necessary for the jit mode to find @@ -133,7 +139,12 @@ pub(crate) fn build_sysroot( } } -fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str) { +fn build_clif_sysroot_for_triple( + channel: &str, + target_dir: &Path, + triple: &str, + linker: Option<&str>, +) { let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); let keep_sysroot = @@ -155,6 +166,10 @@ fn build_clif_sysroot_for_triple(channel: &str, target_dir: &Path, triple: &str) build_cmd.arg("--release"); rustflags.push_str(" -Zmir-opt-level=3"); } + if let Some(linker) = linker { + use std::fmt::Write; + write!(rustflags, " -Clinker={}", linker).unwrap(); + } build_cmd.env("RUSTFLAGS", rustflags); build_cmd.env( "RUSTC", diff --git a/src/lib.rs b/src/lib.rs index 6e127ce23dc..50317b192ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -287,10 +287,12 @@ fn build_isa(sess: &Session, backend_config: &BackendConfig) -> Box { let mut builder = - cranelift_codegen::isa::lookup_variant(target_triple, variant).unwrap(); - // Don't use "haswell" as the default, as it implies `has_lzcnt`. - // macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`. - builder.enable("nehalem").unwrap(); + cranelift_codegen::isa::lookup_variant(target_triple.clone(), variant).unwrap(); + if target_triple.architecture == target_lexicon::Architecture::X86_64 { + // Don't use "haswell" as the default, as it implies `has_lzcnt`. + // macOS CI is still at Ivy Bridge EP, so `lzcnt` is interpreted as `bsr`. + builder.enable("nehalem").unwrap(); + } builder } }; -- cgit 1.4.1-3-g733a5 From e8ff364493e6be9bee1e065221fcd88da319647e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 2 Jul 2021 12:39:34 +0200 Subject: Fix rust-analyzer setting --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 38ffef5ac99..f62e59cefc2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,7 +3,7 @@ "rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"], "rust-analyzer.assist.importGranularity": "module", "rust-analyzer.assist.importEnforceGranularity": true, - "rust-analyzer.assist.importPrefix": "by_crate", + "rust-analyzer.assist.importPrefix": "crate", "rust-analyzer.cargo.runBuildScripts": true, "rust-analyzer.linkedProjects": [ "./Cargo.toml", -- cgit 1.4.1-3-g733a5 From 42f9ad56e9ebc92725fec0b704184e1c09059133 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 2 Jul 2021 12:54:09 +0200 Subject: [CI] Split build and test steps --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4442cbe5f94..c8593498057 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -55,6 +55,9 @@ jobs: git config --global user.name "User" ./y.rs prepare + - name: Build + run: ./y.rs build --sysroot none + - name: Test env: TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} -- cgit 1.4.1-3-g733a5 From 3dc9ec246c4eabd9907636ccd1bca85b3df56d53 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 2 Jul 2021 14:43:01 +0200 Subject: [CI] Cross compile to aarch64-unknown-linux-gnu --- .github/workflows/main.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c8593498057..f81ac877260 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,6 +19,9 @@ jobs: - os: ubuntu-latest env: TARGET_TRIPLE: x86_64-pc-windows-gnu + - os: ubuntu-latest + env: + TARGET_TRIPLE: aarch64-unknown-linux-gnu steps: - uses: actions/checkout@v2 @@ -49,6 +52,11 @@ jobs: sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable rustup target add x86_64-pc-windows-gnu + - name: Install AArch64 toolchain and qemu + if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu' + run: | + sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user + - name: Prepare dependencies run: | git config --global user.email "user@example.com" -- cgit 1.4.1-3-g733a5 From c692896ba27adc1c14941593349c76bd27e189f5 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Fri, 2 Jul 2021 17:07:32 +0200 Subject: Recover from `&dyn mut ...` parse errors --- compiler/rustc_parse/src/parser/ty.rs | 22 +++++++++++++++++++++- src/test/ui/parser/recover-ref-dyn-mut.rs | 9 +++++++++ src/test/ui/parser/recover-ref-dyn-mut.stderr | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/parser/recover-ref-dyn-mut.rs create mode 100644 src/test/ui/parser/recover-ref-dyn-mut.stderr diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index de5a5632600..1fbf01b1b97 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -393,7 +393,7 @@ impl<'a> Parser<'a> { let and_span = self.prev_token.span; let mut opt_lifetime = if self.check_lifetime() { Some(self.expect_lifetime()) } else { None }; - let mutbl = self.parse_mutability(); + let mut mutbl = self.parse_mutability(); if self.token.is_lifetime() && mutbl == Mutability::Mut && opt_lifetime.is_none() { // A lifetime is invalid here: it would be part of a bare trait bound, which requires // it to be followed by a plus, but we disallow plus in the pointee type. @@ -417,6 +417,26 @@ impl<'a> Parser<'a> { opt_lifetime = Some(self.expect_lifetime()); } + } else if self.token.is_keyword(kw::Dyn) + && mutbl == Mutability::Not + && self.look_ahead(1, |t| t.is_keyword(kw::Mut)) + { + // We have `&dyn mut ...`, which is invalid and should be `&mut dyn ...`. + let span = and_span.to(self.look_ahead(1, |t| t.span)); + let mut err = self.struct_span_err(span, "`mut` must precede `dyn`"); + err.span_suggestion( + span, + "place `mut` before `dyn`", + "&mut dyn".to_string(), + Applicability::MachineApplicable, + ); + err.emit(); + + // Recovery + mutbl = Mutability::Mut; + let (dyn_tok, dyn_tok_sp) = (self.token.clone(), self.token_spacing); + self.bump(); + self.bump_with((dyn_tok, dyn_tok_sp)); } let ty = self.parse_ty_no_plus()?; Ok(TyKind::Rptr(opt_lifetime, MutTy { ty, mutbl })) diff --git a/src/test/ui/parser/recover-ref-dyn-mut.rs b/src/test/ui/parser/recover-ref-dyn-mut.rs new file mode 100644 index 00000000000..3016275cc0f --- /dev/null +++ b/src/test/ui/parser/recover-ref-dyn-mut.rs @@ -0,0 +1,9 @@ +// Test that the parser detects `&dyn mut`, offers a help message, and +// recovers. + +fn main() { + let r: &dyn mut Trait; + //~^ ERROR: `mut` must precede `dyn` + //~| HELP: place `mut` before `dyn` + //~| ERROR: cannot find trait `Trait` in this scope [E0405] +} diff --git a/src/test/ui/parser/recover-ref-dyn-mut.stderr b/src/test/ui/parser/recover-ref-dyn-mut.stderr new file mode 100644 index 00000000000..c048c8ea1b0 --- /dev/null +++ b/src/test/ui/parser/recover-ref-dyn-mut.stderr @@ -0,0 +1,15 @@ +error: `mut` must precede `dyn` + --> $DIR/recover-ref-dyn-mut.rs:5:12 + | +LL | let r: &dyn mut Trait; + | ^^^^^^^^ help: place `mut` before `dyn`: `&mut dyn` + +error[E0405]: cannot find trait `Trait` in this scope + --> $DIR/recover-ref-dyn-mut.rs:5:21 + | +LL | let r: &dyn mut Trait; + | ^^^^^ not found in this scope + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0405`. -- cgit 1.4.1-3-g733a5 From 55e077970891c33122ed34f7f8a061709ba01dc3 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Fri, 2 Jul 2021 19:14:02 +0200 Subject: Check if the patched sysroot source is up to date before using it Fixes #1181 --- .gitignore | 1 + build_system/build_sysroot.rs | 20 +++++++++++++++++++- build_system/prepare.rs | 9 ++++++++- build_system/rustc_info.rs | 6 ++++++ clean_all.sh | 3 ++- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 3e010204655..12e779fe7c7 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ perf.data.old /build /build_sysroot/sysroot_src /build_sysroot/compiler-builtins +/build_sysroot/rustc_version /rust /rand /regex diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 72d6a0265ef..e7946aa36ad 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,7 +3,7 @@ use std::fs; use std::path::Path; use std::process::{self, Command}; -use crate::rustc_info::get_file_name; +use crate::rustc_info::{get_file_name, get_rustc_version}; use crate::utils::{spawn_and_wait, try_hard_link}; use crate::SysrootKind; @@ -145,6 +145,24 @@ fn build_clif_sysroot_for_triple( triple: &str, linker: Option<&str>, ) { + match fs::read_to_string(Path::new("build_sysroot").join("rustc_version")) { + Err(e) => { + eprintln!("Failed to get rustc version for patched sysroot source: {}", e); + eprintln!("Hint: Try `./y.rs prepare` to patch the sysroot source"); + process::exit(1); + } + Ok(source_version) => { + let rustc_version = get_rustc_version(); + if source_version != rustc_version { + eprintln!("The patched sysroot source is outdated"); + eprintln!("Source version: {}", source_version.trim()); + eprintln!("Rustc version: {}", rustc_version.trim()); + eprintln!("Hint: Try `./y.rs prepare` to update the patched sysroot source"); + process::exit(1); + } + } + } + let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); let keep_sysroot = diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 1f4ec825e1e..401b8271abc 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -5,7 +5,7 @@ use std::fs; use std::path::Path; use std::process::Command; -use crate::rustc_info::{get_file_name, get_rustc_path}; +use crate::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; use crate::utils::{copy_dir_recursively, spawn_and_wait}; pub(crate) fn prepare() { @@ -59,6 +59,13 @@ fn prepare_sysroot() { eprintln!("[COPY] sysroot src"); copy_dir_recursively(&sysroot_src_orig.join("library"), &sysroot_src.join("library")); + let rustc_version = get_rustc_version(); + fs::write( + Path::new("build_sysroot").join("rustc_version"), + &rustc_version, + ) + .unwrap(); + eprintln!("[GIT] init"); let mut git_init_cmd = Command::new("git"); git_init_cmd.arg("init").arg("-q").current_dir(&sysroot_src); diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 3bf86d9a114..9206bb02bd3 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -1,6 +1,12 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; +pub(crate) fn get_rustc_version() -> String { + let version_info = + Command::new("rustc").stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout; + String::from_utf8(version_info).unwrap() +} + pub(crate) fn get_host_triple() -> String { let version_info = Command::new("rustc").stderr(Stdio::inherit()).args(&["-vV"]).output().unwrap().stdout; diff --git a/clean_all.sh b/clean_all.sh index a7bbeb05cac..f4f8c82d69f 100755 --- a/clean_all.sh +++ b/clean_all.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e -rm -rf target/ build/ build_sysroot/{sysroot_src/,target/,compiler-builtins/} perf.data{,.old} +rm -rf build_sysroot/{sysroot_src/,target/,compiler-builtins/,rustc_version} +rm -rf target/ build/ perf.data{,.old} rm -rf rand/ regex/ simple-raytracer/ -- cgit 1.4.1-3-g733a5 From 6a31385363f26f5324b2e125a96541efec88f60c Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 3 Jul 2021 14:28:53 +0200 Subject: Misc target related improvements --- src/base.rs | 19 ++++++++++++++++--- src/driver/aot.rs | 4 +++- src/driver/jit.rs | 2 +- src/optimize/mod.rs | 5 ++++- src/pretty_clif.rs | 9 +++------ 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/base.rs b/src/base.rs index f44ab276590..3d78eed77b9 100644 --- a/src/base.rs +++ b/src/base.rs @@ -109,7 +109,14 @@ pub(crate) fn codegen_fn<'tcx>( let context = &mut cx.cached_context; context.func = func; - crate::pretty_clif::write_clif_file(tcx, "unopt", None, instance, &context, &clif_comments); + crate::pretty_clif::write_clif_file( + tcx, + "unopt", + module.isa(), + instance, + &context, + &clif_comments, + ); // Verify function verify_func(tcx, &clif_comments, &context.func); @@ -126,7 +133,13 @@ pub(crate) fn codegen_fn<'tcx>( // Perform rust specific optimizations tcx.sess.time("optimize clif ir", || { - crate::optimize::optimize_function(tcx, instance, context, &mut clif_comments); + crate::optimize::optimize_function( + tcx, + module.isa(), + instance, + context, + &mut clif_comments, + ); }); // Define function @@ -141,7 +154,7 @@ pub(crate) fn codegen_fn<'tcx>( crate::pretty_clif::write_clif_file( tcx, "opt", - Some(module.isa()), + module.isa(), instance, &context, &clif_comments, diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 6676d88602c..5d2c79e3e87 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -290,13 +290,15 @@ pub(crate) fn run_aot( None }; + // FIXME handle `-Ctarget-cpu=native` + let target_cpu = tcx.sess.opts.cg.target_cpu.as_ref().unwrap_or(&tcx.sess.target.cpu).to_owned(); Box::new(( CodegenResults { modules, allocator_module, metadata_module, metadata, - linker_info: LinkerInfo::new(tcx, crate::target_triple(tcx.sess).to_string()), + linker_info: LinkerInfo::new(tcx, target_cpu), crate_info: CrateInfo::new(tcx), }, work_products, diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 39a39e764cb..f454d0efab8 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -159,7 +159,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { AbiParam::new(jit_module.target_config().pointer_type()), ], returns: vec![AbiParam::new(jit_module.target_config().pointer_type() /*isize*/)], - call_conv: CallConv::triple_default(&crate::target_triple(tcx.sess)), + call_conv: jit_module.target_config().default_call_conv, }; let start_func_id = jit_module.declare_function("main", Linkage::Import, &start_sig).unwrap(); let finalized_start: *const u8 = jit_module.get_finalized_function(start_func_id); diff --git a/src/optimize/mod.rs b/src/optimize/mod.rs index 137fb5f7731..61033d85a12 100644 --- a/src/optimize/mod.rs +++ b/src/optimize/mod.rs @@ -1,17 +1,20 @@ //! Various optimizations specific to cg_clif +use cranelift_codegen::isa::TargetIsa; + use crate::prelude::*; pub(crate) mod peephole; pub(crate) fn optimize_function<'tcx>( tcx: TyCtxt<'tcx>, + isa: &dyn TargetIsa, instance: Instance<'tcx>, ctx: &mut Context, clif_comments: &mut crate::pretty_clif::CommentWriter, ) { // FIXME classify optimizations over opt levels once we have more - crate::pretty_clif::write_clif_file(tcx, "preopt", None, instance, &ctx, &*clif_comments); + crate::pretty_clif::write_clif_file(tcx, "preopt", isa, instance, &ctx, &*clif_comments); crate::base::verify_func(tcx, &*clif_comments, &ctx.func); } diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index cd8c5b51608..2f278134d5b 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -233,7 +233,7 @@ pub(crate) fn write_ir_file( pub(crate) fn write_clif_file<'tcx>( tcx: TyCtxt<'tcx>, postfix: &str, - isa: Option<&dyn cranelift_codegen::isa::TargetIsa>, + isa: &dyn cranelift_codegen::isa::TargetIsa, instance: Instance<'tcx>, context: &cranelift_codegen::Context, mut clif_comments: &CommentWriter, @@ -242,22 +242,19 @@ pub(crate) fn write_clif_file<'tcx>( tcx, || format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix), |file| { - let value_ranges = isa - .map(|isa| context.build_value_labels_ranges(isa).expect("value location ranges")); - let mut clif = String::new(); cranelift_codegen::write::decorate_function( &mut clif_comments, &mut clif, &context.func, - &DisplayFunctionAnnotations { isa, value_ranges: value_ranges.as_ref() }, + &DisplayFunctionAnnotations { isa: Some(isa), value_ranges: None }, ) .unwrap(); writeln!(file, "test compile")?; writeln!(file, "set is_pic")?; writeln!(file, "set enable_simd")?; - writeln!(file, "target {} haswell", crate::target_triple(tcx.sess))?; + writeln!(file, "target {} nehalem", crate::target_triple(tcx.sess))?; writeln!(file)?; file.write_all(clif.as_bytes())?; Ok(()) -- cgit 1.4.1-3-g733a5 From 751ae51044510f7f047a2cbd278eb42a380ff886 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 3 Jul 2021 14:41:33 +0200 Subject: Update Cranelift --- Cargo.lock | 20 ++++++++++---------- src/debuginfo/line_info.rs | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 748faeaffbf..a406dbee8bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "cranelift-entity", ] @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -67,17 +67,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" [[package]] name = "cranelift-entity" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" [[package]] name = "cranelift-frontend" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "cranelift-codegen", "log", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "anyhow", "cranelift-codegen", @@ -105,7 +105,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "anyhow", "cranelift-codegen", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "cranelift-codegen", "libc", @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#f2d2f3a841f4da8188df0a5f1033b5bdeaf02bcd" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" dependencies = [ "anyhow", "cranelift-codegen", diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index 9eb06770630..c7e15f81e03 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -10,7 +10,7 @@ use rustc_span::{ }; use cranelift_codegen::binemit::CodeOffset; -use cranelift_codegen::machinst::MachSrcLoc; +use cranelift_codegen::MachSrcLoc; use gimli::write::{ Address, AttributeValue, FileId, FileInfo, LineProgram, LineString, LineStringTable, -- cgit 1.4.1-3-g733a5 From 913c0bc01dbab632d1512f703c026aac7acfa197 Mon Sep 17 00:00:00 2001 From: Smitty Date: Sat, 3 Jul 2021 11:14:19 -0400 Subject: Make vtable_allocation always succeed --- src/vtable.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/vtable.rs b/src/vtable.rs index 7ee34b23e46..12f7092d935 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -72,10 +72,7 @@ pub(crate) fn get_vtable<'tcx>( let vtable_ptr = if let Some(vtable_ptr) = fx.vtables.get(&(ty, trait_ref)) { *vtable_ptr } else { - let vtable_alloc_id = match fx.tcx.vtable_allocation(ty, trait_ref) { - Ok(alloc) => alloc, - Err(_) => fx.tcx.sess.fatal("allocation of constant vtable failed"), - }; + let vtable_alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); let vtable_allocation = fx.tcx.global_alloc(vtable_alloc_id).unwrap_memory(); let vtable_ptr = pointer_for_allocation(fx, vtable_allocation); -- cgit 1.4.1-3-g733a5 From ac730b4464ae1a9b6c4a8a2da1f260e72e3c2603 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 4 Jul 2021 12:37:00 +0200 Subject: Update Cranelift This has a fix for a miscompilation on AArch64 cc #1184 --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a406dbee8bd..56d0974b253 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cranelift-bforest" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "cranelift-entity", ] @@ -42,7 +42,7 @@ dependencies = [ [[package]] name = "cranelift-codegen" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "cranelift-bforest", "cranelift-codegen-meta", @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "cranelift-codegen-shared", "cranelift-entity", @@ -67,17 +67,17 @@ dependencies = [ [[package]] name = "cranelift-codegen-shared" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" [[package]] name = "cranelift-entity" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" [[package]] name = "cranelift-frontend" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "cranelift-codegen", "log", @@ -88,7 +88,7 @@ dependencies = [ [[package]] name = "cranelift-jit" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "anyhow", "cranelift-codegen", @@ -105,7 +105,7 @@ dependencies = [ [[package]] name = "cranelift-module" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "anyhow", "cranelift-codegen", @@ -116,7 +116,7 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "cranelift-codegen", "libc", @@ -126,7 +126,7 @@ dependencies = [ [[package]] name = "cranelift-object" version = "0.75.0" -source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#93b7cdd6a267ab445864ad8e5bc8b384b0e676ca" +source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8" dependencies = [ "anyhow", "cranelift-codegen", -- cgit 1.4.1-3-g733a5 From 83cca1b03c808998032295ab845589d4a4316908 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 4 Jul 2021 12:39:22 +0200 Subject: Write better clif ir header --- src/pretty_clif.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs index 2f278134d5b..05db74745a1 100644 --- a/src/pretty_clif.rs +++ b/src/pretty_clif.rs @@ -251,10 +251,14 @@ pub(crate) fn write_clif_file<'tcx>( ) .unwrap(); - writeln!(file, "test compile")?; - writeln!(file, "set is_pic")?; - writeln!(file, "set enable_simd")?; - writeln!(file, "target {} nehalem", crate::target_triple(tcx.sess))?; + for flag in isa.flags().iter() { + writeln!(file, "set {}", flag)?; + } + write!(file, "target {}", isa.triple().architecture.to_string())?; + for isa_flag in isa.isa_flags().iter() { + write!(file, " {}", isa_flag)?; + } + writeln!(file, "\n")?; writeln!(file)?; file.write_all(clif.as_bytes())?; Ok(()) -- cgit 1.4.1-3-g733a5 From 0d531c37375006917a151ed3932fb09d3e6a431d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 4 Jul 2021 15:10:06 +0200 Subject: Better config parsing and allow specifying host and target triple in config --- build_system/build_sysroot.rs | 4 +--- build_system/config.rs | 55 +++++++++++++++++++++++++++++++++++++++++++ config.txt | 6 +++++ y.rs | 6 +++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 build_system/config.rs diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index e7946aa36ad..00735ac1493 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -165,9 +165,7 @@ fn build_clif_sysroot_for_triple( let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); - let keep_sysroot = - fs::read_to_string("config.txt").unwrap().lines().any(|line| line.trim() == "keep_sysroot"); - if !keep_sysroot { + if !crate::config::get_bool("keep_sysroot") { // Cleanup the target dir with the exception of build scripts and the incremental cache for dir in ["build", "deps", "examples", "native"] { if build_dir.join(dir).exists() { diff --git a/build_system/config.rs b/build_system/config.rs new file mode 100644 index 00000000000..ef540cf1f82 --- /dev/null +++ b/build_system/config.rs @@ -0,0 +1,55 @@ +use std::{fs, process}; + +fn load_config_file() -> Vec<(String, Option)> { + fs::read_to_string("config.txt") + .unwrap() + .lines() + .map(|line| if let Some((line, _comment)) = line.split_once('#') { line } else { line }) + .map(|line| line.trim()) + .filter(|line| !line.is_empty()) + .map(|line| { + if let Some((key, val)) = line.split_once('=') { + (key.trim().to_owned(), Some(val.trim().to_owned())) + } else { + (line.to_owned(), None) + } + }) + .collect() +} + +pub(crate) fn get_bool(name: &str) -> bool { + let values = load_config_file() + .into_iter() + .filter(|(key, _)| key == name) + .map(|(_, val)| val) + .collect::>(); + if values.is_empty() { + false + } else { + if values.iter().any(|val| val.is_some()) { + eprintln!("Boolean config `{}` has a value", name); + process::exit(1); + } + true + } +} + +pub(crate) fn get_value(name: &str) -> Option { + let values = load_config_file() + .into_iter() + .filter(|(key, _)| key == name) + .map(|(_, val)| val) + .collect::>(); + if values.is_empty() { + None + } else if values.len() == 1 { + if values[0].is_none() { + eprintln!("Config `{}` missing value", name); + process::exit(1); + } + values.into_iter().next().unwrap() + } else { + eprintln!("Config `{}` given multiple values: {:?}", name, values); + process::exit(1); + } +} diff --git a/config.txt b/config.txt index f707b9322af..c5fd7beb747 100644 --- a/config.txt +++ b/config.txt @@ -1,5 +1,11 @@ # This file allows configuring the build system. +# The host triple +#host = x86_64-unknown-linux-gnu + +# The target triple +#target = x86_64-unknown-linux-gnu + # Disables cleaning of the sysroot dir. This will cause old compiled artifacts to be re-used when # the sysroot source hasn't changed. This is useful when the codegen backend hasn't been modified. # This option can be changed while the build system is already running for as long as sysroot diff --git a/y.rs b/y.rs index 55457745d25..aeaac59fff0 100755 --- a/y.rs +++ b/y.rs @@ -31,6 +31,8 @@ use std::process; mod build_backend; #[path = "build_system/build_sysroot.rs"] mod build_sysroot; +#[path = "build_system/config.rs"] +mod config; #[path = "build_system/prepare.rs"] mod prepare; #[path = "build_system/rustc_info.rs"] @@ -114,6 +116,8 @@ fn main() { let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { host_triple + } else if let Some(host_triple) = crate::config::get_value("host") { + host_triple } else { rustc_info::get_host_triple() }; @@ -123,6 +127,8 @@ fn main() { } else { host_triple.clone() // Empty target triple can happen on GHA } + } else if let Some(target_triple) = crate::config::get_value("target") { + target_triple } else { host_triple.clone() }; -- cgit 1.4.1-3-g733a5 From 53478823e42d4172cec837d6bbedf1d090402a64 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 4 Jul 2021 18:15:13 +0200 Subject: Refactor cg_clif building --- build_system/build_backend.rs | 7 ++++--- build_system/build_sysroot.rs | 32 ++++++++++++++++---------------- config.txt | 8 ++++++-- y.rs | 4 ++-- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index db046be1866..1df2bcc4541 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -1,9 +1,10 @@ use std::env; +use std::path::{Path, PathBuf}; use std::process::Command; -pub(crate) fn build_backend(channel: &str) -> String { +pub(crate) fn build_backend(channel: &str, host_triple: &str) -> PathBuf { let mut cmd = Command::new("cargo"); - cmd.arg("build"); + cmd.arg("build").arg("--target").arg(host_triple); match channel { "debug" => {} @@ -35,5 +36,5 @@ pub(crate) fn build_backend(channel: &str) -> String { eprintln!("[BUILD] rustc_codegen_cranelift"); crate::utils::spawn_and_wait(cmd); - crate::rustc_info::get_file_name("rustc_codegen_cranelift", "dylib") + Path::new("target").join(host_triple).join(channel) } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 00735ac1493..9fb88c27961 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -1,6 +1,6 @@ use std::env; use std::fs; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::process::{self, Command}; use crate::rustc_info::{get_file_name, get_rustc_version}; @@ -11,7 +11,7 @@ pub(crate) fn build_sysroot( channel: &str, sysroot_kind: SysrootKind, target_dir: &Path, - cg_clif_dylib: String, + cg_clif_build_dir: PathBuf, host_triple: &str, target_triple: &str, ) { @@ -24,24 +24,24 @@ pub(crate) fn build_sysroot( // Copy the backend for file in ["cg_clif", "cg_clif_build_sysroot"] { try_hard_link( - Path::new("target").join(channel).join(get_file_name(file, "bin")), + cg_clif_build_dir.join(get_file_name(file, "bin")), target_dir.join("bin").join(get_file_name(file, "bin")), ); } - if cfg!(windows) { - // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the - // binaries. - try_hard_link( - Path::new("target").join(channel).join(&cg_clif_dylib), - target_dir.join("bin").join(cg_clif_dylib), - ); - } else { - try_hard_link( - Path::new("target").join(channel).join(&cg_clif_dylib), - target_dir.join("lib").join(cg_clif_dylib), - ); - } + let cg_clif_dylib = get_file_name("rustc_codegen_cranelift", "dylib"); + try_hard_link( + cg_clif_build_dir.join(&cg_clif_dylib), + target_dir + .join(if cfg!(windows) { + // Windows doesn't have rpath support, so the cg_clif dylib needs to be next to the + // binaries. + "bin" + } else { + "lib" + }) + .join(cg_clif_dylib), + ); // Build and copy cargo wrapper let mut build_cargo_wrapper_cmd = Command::new("rustc"); diff --git a/config.txt b/config.txt index c5fd7beb747..b14db27d620 100644 --- a/config.txt +++ b/config.txt @@ -1,9 +1,13 @@ # This file allows configuring the build system. -# The host triple +# Which triple to produce a compiler toolchain for. +# +# Defaults to the default triple of rustc on the host system. #host = x86_64-unknown-linux-gnu -# The target triple +# Which triple to build libraries (core/alloc/std/test/proc_macro) for. +# +# Defaults to `host`. #target = x86_64-unknown-linux-gnu # Disables cleaning of the sysroot dir. This will cause old compiled artifacts to be re-used when diff --git a/y.rs b/y.rs index aeaac59fff0..43937588b48 100755 --- a/y.rs +++ b/y.rs @@ -141,12 +141,12 @@ fn main() { process::exit(1); } - let cg_clif_dylib = build_backend::build_backend(channel); + let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple); build_sysroot::build_sysroot( channel, sysroot_kind, &target_dir, - cg_clif_dylib, + cg_clif_build_dir, &host_triple, &target_triple, ); -- cgit 1.4.1-3-g733a5 From 38585b3f01a3e11d47bb61d83d915c0c6f302ded Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 4 Jul 2021 18:17:26 +0200 Subject: Don't overwrite LD_LIBRARY_PATH in config.sh --- scripts/config.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/config.sh b/scripts/config.sh index d316a7c6981..53ada369b08 100644 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -2,5 +2,5 @@ set -e -export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib" -export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH +export LD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$LD_LIBRARY_PATH" +export DYLD_LIBRARY_PATH="$(rustc --print sysroot)/lib:$DYLD_LIBRARY_PATH" -- cgit 1.4.1-3-g733a5 From 6b3a061e947fcb928b94cd5a7db3bdfd225f87b4 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 7 Jun 2021 12:18:28 +0200 Subject: Remove LibSource The information is stored in used_crate_source too anyway --- src/driver/jit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 4a99cb727c8..3f96e741d35 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -185,7 +185,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { .find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable) .unwrap() .1; - for &(cnum, _) in &crate_info.used_crates_dynamic { + for &cnum in &crate_info.used_crates { let src = &crate_info.used_crate_source[&cnum]; match data[cnum.as_usize() - 1] { Linkage::NotLinked | Linkage::IncludedFromDylib => {} -- cgit 1.4.1-3-g733a5 From a0cdbd1aa61e47fed13e84cbbda9460ea88b7100 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 5 Jul 2021 18:44:37 +0200 Subject: Rustfmt --- src/bin/cg_clif.rs | 2 +- src/driver/aot.rs | 3 ++- src/driver/jit.rs | 13 ++++++++----- src/intrinsics/llvm.rs | 28 +++++++++++++--------------- src/vtable.rs | 8 ++------ 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/bin/cg_clif.rs b/src/bin/cg_clif.rs index 2643fae0a81..a044b43b864 100644 --- a/src/bin/cg_clif.rs +++ b/src/bin/cg_clif.rs @@ -6,8 +6,8 @@ extern crate rustc_interface; extern crate rustc_session; extern crate rustc_target; -use std::panic; use std::lazy::SyncLazy; +use std::panic; use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry}; use rustc_interface::interface; diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 5d2c79e3e87..74cb665d061 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -291,7 +291,8 @@ pub(crate) fn run_aot( }; // FIXME handle `-Ctarget-cpu=native` - let target_cpu = tcx.sess.opts.cg.target_cpu.as_ref().unwrap_or(&tcx.sess.target.cpu).to_owned(); + let target_cpu = + tcx.sess.opts.cg.target_cpu.as_ref().unwrap_or(&tcx.sess.target.cpu).to_owned(); Box::new(( CodegenResults { modules, diff --git a/src/driver/jit.rs b/src/driver/jit.rs index f454d0efab8..8ab94336432 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -26,7 +26,8 @@ thread_local! { } /// The Sender owned by the rustc thread -static GLOBAL_MESSAGE_SENDER: SyncOnceCell>> = SyncOnceCell::new(); +static GLOBAL_MESSAGE_SENDER: SyncOnceCell>> = + SyncOnceCell::new(); /// A message that is sent from the jitted runtime to the rustc thread. /// Senders are responsible for upholding `Send` semantics. @@ -195,14 +196,17 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! { // lazy JIT compilation request - compile requested instance and return pointer to result UnsafeMessage::JitFn { instance_ptr, trampoline_ptr, tx } => { tx.send(jit_fn(instance_ptr, trampoline_ptr)) - .expect("jitted runtime hung up before response to lazy JIT request was sent"); + .expect("jitted runtime hung up before response to lazy JIT request was sent"); } } } } #[no_mangle] -extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> *const u8 { +extern "C" fn __clif_jit_fn( + instance_ptr: *const Instance<'static>, + trampoline_ptr: *const u8, +) -> *const u8 { // send the JIT request to the rustc thread, with a channel for the response let (tx, rx) = mpsc::channel(); UnsafeMessage::JitFn { instance_ptr, trampoline_ptr, tx } @@ -210,8 +214,7 @@ extern "C" fn __clif_jit_fn(instance_ptr: *const Instance<'static>, trampoline_p .expect("rustc thread hung up before lazy JIT request was sent"); // block on JIT compilation result - rx.recv() - .expect("rustc thread hung up before responding to sent lazy JIT request") + rx.recv().expect("rustc thread hung up before responding to sent lazy JIT request") } fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> *const u8 { diff --git a/src/intrinsics/llvm.rs b/src/intrinsics/llvm.rs index 0b5435285b4..be3704ca276 100644 --- a/src/intrinsics/llvm.rs +++ b/src/intrinsics/llvm.rs @@ -148,30 +148,28 @@ fn llvm_add_sub<'tcx>( ret: CPlace<'tcx>, cb_in: Value, a: CValue<'tcx>, - b: CValue<'tcx> + b: CValue<'tcx>, ) { - assert_eq!(a.layout().ty, fx.tcx.types.u64, "llvm.x86.addcarry.64/llvm.x86.subborrow.64 second operand must be u64"); - assert_eq!(b.layout().ty, fx.tcx.types.u64, "llvm.x86.addcarry.64/llvm.x86.subborrow.64 third operand must be u64"); + assert_eq!( + a.layout().ty, + fx.tcx.types.u64, + "llvm.x86.addcarry.64/llvm.x86.subborrow.64 second operand must be u64" + ); + assert_eq!( + b.layout().ty, + fx.tcx.types.u64, + "llvm.x86.addcarry.64/llvm.x86.subborrow.64 third operand must be u64" + ); // c + carry -> c + first intermediate carry or borrow respectively - let int0 = crate::num::codegen_checked_int_binop( - fx, - bin_op, - a, - b, - ); + let int0 = crate::num::codegen_checked_int_binop(fx, bin_op, a, b); let c = int0.value_field(fx, mir::Field::new(0)); let cb0 = int0.value_field(fx, mir::Field::new(1)).load_scalar(fx); // c + carry -> c + second intermediate carry or borrow respectively let cb_in_as_u64 = fx.bcx.ins().uextend(types::I64, cb_in); let cb_in_as_u64 = CValue::by_val(cb_in_as_u64, fx.layout_of(fx.tcx.types.u64)); - let int1 = crate::num::codegen_checked_int_binop( - fx, - bin_op, - c, - cb_in_as_u64, - ); + let int1 = crate::num::codegen_checked_int_binop(fx, bin_op, c, cb_in_as_u64); let (c, cb1) = int1.load_scalar_pair(fx); // carry0 | carry1 -> carry or borrow respectively diff --git a/src/vtable.rs b/src/vtable.rs index 021686544eb..4a5f9f133a2 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -69,12 +69,8 @@ pub(crate) fn get_vtable<'tcx>( trait_ref: Option>, ) -> Value { let alloc_id = fx.tcx.vtable_allocation(ty, trait_ref); - let data_id = data_id_for_alloc_id( - &mut fx.constants_cx, - &mut *fx.module, - alloc_id, - Mutability::Not, - ); + let data_id = + data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, Mutability::Not); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); if fx.clif_comments.enabled() { fx.add_comment(local_data_id, format!("vtable: {:?}", alloc_id)); -- cgit 1.4.1-3-g733a5 From fed71e344818dd2b1f2e48005b6d3da21cda30f5 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Mon, 5 Jul 2021 18:46:13 +0200 Subject: Pass CrateInfo instead of TyCtxt to load_imported_symbols_for_jit --- src/driver/jit.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 8ab94336432..a53d281303f 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -10,6 +10,7 @@ use std::sync::{mpsc, Mutex}; use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink}; use rustc_codegen_ssa::CrateInfo; use rustc_middle::mir::mono::MonoItem; +use rustc_session::Session; use cranelift_jit::{JITBuilder, JITModule}; @@ -65,7 +66,8 @@ fn create_jit_module<'tcx>( backend_config: &BackendConfig, hotswap: bool, ) -> (JITModule, CodegenCx<'tcx>) { - let imported_symbols = load_imported_symbols_for_jit(tcx); + let crate_info = CrateInfo::new(tcx); + let imported_symbols = load_imported_symbols_for_jit(tcx.sess, crate_info); let isa = crate::build_isa(tcx.sess, backend_config); let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names()); @@ -255,14 +257,16 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) -> }) } -fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { +fn load_imported_symbols_for_jit( + sess: &Session, + crate_info: CrateInfo, +) -> Vec<(String, *const u8)> { use rustc_middle::middle::dependency_format::Linkage; let mut dylib_paths = Vec::new(); - let crate_info = CrateInfo::new(tcx); - let formats = tcx.dependency_formats(()); - let data = &formats + let data = &crate_info + .dependency_formats .iter() .find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable) .unwrap() @@ -272,9 +276,8 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { match data[cnum.as_usize() - 1] { Linkage::NotLinked | Linkage::IncludedFromDylib => {} Linkage::Static => { - let name = tcx.crate_name(cnum); - let mut err = - tcx.sess.struct_err(&format!("Can't load static lib {}", name.as_str())); + let name = &crate_info.crate_name[&cnum]; + let mut err = sess.struct_err(&format!("Can't load static lib {}", name.as_str())); err.note("rustc_codegen_cranelift can only load dylibs in JIT mode."); err.emit(); } @@ -314,7 +317,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> { std::mem::forget(lib) } - tcx.sess.abort_if_errors(); + sess.abort_if_errors(); imported_symbols } -- cgit 1.4.1-3-g733a5 From a151982af34047bcac2ec8e35b147c95a40706ae Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 6 Jul 2021 14:44:18 -0700 Subject: Add doc comment for `impl From for TryReserveError` --- library/alloc/src/collections/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/alloc/src/collections/mod.rs b/library/alloc/src/collections/mod.rs index b9b3d650ea2..97bfe2f3984 100644 --- a/library/alloc/src/collections/mod.rs +++ b/library/alloc/src/collections/mod.rs @@ -83,6 +83,7 @@ pub enum TryReserveError { #[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] impl From for TryReserveError { + /// Always evaluates to [`TryReserveError::CapacityOverflow`]. #[inline] fn from(_: LayoutError) -> Self { TryReserveError::CapacityOverflow -- cgit 1.4.1-3-g733a5 From 65b28a987bfce11c37634fff2be129ffc16096d5 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Fri, 25 Jun 2021 14:28:03 -0700 Subject: Add ui test for command line lints with tool names This adds a ui test to make sure rustc accepts lint arguments such as `-A clippy::foo` when clippy is disabled. --- src/test/ui/lint/command-line-register-lint-tool.rs | 7 +++++++ src/test/ui/lint/command-line-register-unknown-lint-tool.rs | 4 ++++ .../ui/lint/command-line-register-unknown-lint-tool.stderr | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/test/ui/lint/command-line-register-lint-tool.rs create mode 100644 src/test/ui/lint/command-line-register-unknown-lint-tool.rs create mode 100644 src/test/ui/lint/command-line-register-unknown-lint-tool.stderr diff --git a/src/test/ui/lint/command-line-register-lint-tool.rs b/src/test/ui/lint/command-line-register-lint-tool.rs new file mode 100644 index 00000000000..d6e95fd3ec4 --- /dev/null +++ b/src/test/ui/lint/command-line-register-lint-tool.rs @@ -0,0 +1,7 @@ +// compile-flags: -A known_tool::foo +// check-pass + +#![feature(register_tool)] +#![register_tool(known_tool)] + +fn main() {} diff --git a/src/test/ui/lint/command-line-register-unknown-lint-tool.rs b/src/test/ui/lint/command-line-register-unknown-lint-tool.rs new file mode 100644 index 00000000000..435e951c809 --- /dev/null +++ b/src/test/ui/lint/command-line-register-unknown-lint-tool.rs @@ -0,0 +1,4 @@ +// compile-flags: -A unknown_tool::foo +// check-fail + +fn main() {} diff --git a/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr new file mode 100644 index 00000000000..9e0177c47da --- /dev/null +++ b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr @@ -0,0 +1,11 @@ +error[E0602]: unknown lint: `unknown_tool::foo` + | + = note: requested on the command line with `-A unknown_tool::foo` + +error[E0602]: unknown lint: `unknown_tool::foo` + | + = note: requested on the command line with `-A unknown_tool::foo` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0602`. -- cgit 1.4.1-3-g733a5 From 1e0db4cfedcb9ecdc8df62aac22bec00a5c3c1b5 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 24 Jun 2021 16:38:32 -0700 Subject: Parse tool name for command line lint options --- compiler/rustc_lint/src/context.rs | 20 +++++++++++++++++--- compiler/rustc_lint/src/lib.rs | 3 +++ compiler/rustc_lint/src/tests.rs | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 compiler/rustc_lint/src/tests.rs diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 00869ac3c9a..76ac4cfdf84 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -334,9 +334,16 @@ impl LintStore { } } - /// Checks the validity of lint names derived from the command line - pub fn check_lint_name_cmdline(&self, sess: &Session, lint_name: &str, level: Level) { - let db = match self.check_lint_name(lint_name, None) { + /// Checks the validity of lint names derived from the command line. Returns + /// true if the lint is valid, false otherwise. + pub fn check_lint_name_cmdline( + &self, + sess: &Session, + lint_name: &str, + level: Option, + ) -> bool { + let (tool_name, lint_name) = parse_lint_and_tool_name(lint_name); + let db = match self.check_lint_name(lint_name, tool_name) { CheckLintNameResult::Ok(_) => None, CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)), CheckLintNameResult::NoLint(suggestion) => { @@ -1018,3 +1025,10 @@ impl<'tcx> LayoutOf for LateContext<'tcx> { self.tcx.layout_of(self.param_env.and(ty)) } } + +pub fn parse_lint_and_tool_name(lint_name: &str) -> (Option, &str) { + match lint_name.split_once("::") { + Some((tool_name, lint_name)) => (Some(Symbol::intern(tool_name)), lint_name), + None => (None, lint_name), + } +} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 89f9809d643..6f0cedca90c 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -494,3 +494,6 @@ fn register_internals(store: &mut LintStore) { ], ); } + +#[cfg(test)] +mod tests; diff --git a/compiler/rustc_lint/src/tests.rs b/compiler/rustc_lint/src/tests.rs new file mode 100644 index 00000000000..a50c88aa0f7 --- /dev/null +++ b/compiler/rustc_lint/src/tests.rs @@ -0,0 +1,24 @@ +use crate::context::parse_lint_and_tool_name; +use rustc_span::{with_default_session_globals, Symbol}; + +#[test] +fn parse_lint_no_tool() { + with_default_session_globals(|| assert_eq!(parse_lint_and_tool_name("foo"), (None, "foo"))); +} + +#[test] +fn parse_lint_with_tool() { + with_default_session_globals(|| { + assert_eq!(parse_lint_and_tool_name("clippy::foo"), (Some(Symbol::intern("clippy")), "foo")) + }); +} + +#[test] +fn parse_lint_multiple_path() { + with_default_session_globals(|| { + assert_eq!( + parse_lint_and_tool_name("clippy::foo::bar"), + (Some(Symbol::intern("clippy")), "foo::bar") + ) + }); +} -- cgit 1.4.1-3-g733a5 From 8b4f538320cbb40643bfb94f28313d4137126b01 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Tue, 6 Jul 2021 17:19:20 -0700 Subject: Unify lint tool and lint name checking This shares a little more code between checking command line and attribute lint specifications. --- compiler/rustc_lint/src/context.rs | 44 +++++++++++++--- compiler/rustc_lint/src/levels.rs | 61 ++++++++++++---------- .../command-line-register-unknown-lint-tool.stderr | 8 +-- 3 files changed, 73 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 76ac4cfdf84..263ed83ed5a 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -16,7 +16,7 @@ use self::TargetLint::*; -use crate::levels::LintLevelsBuilder; +use crate::levels::{is_known_lint_tool, LintLevelsBuilder}; use crate::passes::{EarlyLintPassObject, LateLintPassObject}; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; @@ -129,6 +129,8 @@ pub enum CheckLintNameResult<'a> { Ok(&'a [LintId]), /// Lint doesn't exist. Potentially contains a suggestion for a correct lint name. NoLint(Option), + /// The lint refers to a tool that has not been registered. + NoTool, /// The lint is either renamed or removed. This is the warning /// message, and an optional new name (`None` if removed). Warning(String, Option), @@ -334,16 +336,17 @@ impl LintStore { } } - /// Checks the validity of lint names derived from the command line. Returns - /// true if the lint is valid, false otherwise. + /// Checks the validity of lint names derived from the command line. pub fn check_lint_name_cmdline( &self, sess: &Session, lint_name: &str, - level: Option, - ) -> bool { + level: Level, + crate_attrs: &[ast::Attribute], + ) { let (tool_name, lint_name) = parse_lint_and_tool_name(lint_name); - let db = match self.check_lint_name(lint_name, tool_name) { + + let db = match self.check_lint_and_tool_name(sess, tool_name, lint_name, crate_attrs) { CheckLintNameResult::Ok(_) => None, CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)), CheckLintNameResult::NoLint(suggestion) => { @@ -365,6 +368,13 @@ impl LintStore { ))), _ => None, }, + CheckLintNameResult::NoTool => Some(struct_span_err!( + sess, + DUMMY_SP, + E0602, + "unknown lint tool: `{}`", + tool_name.unwrap() + )), }; if let Some(mut db) = db { @@ -398,6 +408,22 @@ impl LintStore { } } + pub fn check_lint_and_tool_name( + &self, + sess: &Session, + tool_name: Option, + lint_name: &str, + crate_attrs: &[ast::Attribute], + ) -> CheckLintNameResult<'_> { + if let Some(tool_name) = tool_name { + if !is_known_lint_tool(tool_name, sess, crate_attrs) { + return CheckLintNameResult::NoTool; + } + } + + self.check_lint_name(lint_name, tool_name) + } + /// Checks the name of a lint for its existence, and whether it was /// renamed or removed. Generates a DiagnosticBuilder containing a /// warning for renamed and removed lints. This is over both lint @@ -1028,7 +1054,11 @@ impl<'tcx> LayoutOf for LateContext<'tcx> { pub fn parse_lint_and_tool_name(lint_name: &str) -> (Option, &str) { match lint_name.split_once("::") { - Some((tool_name, lint_name)) => (Some(Symbol::intern(tool_name)), lint_name), + Some((tool_name, lint_name)) => { + let tool_name = Symbol::intern(tool_name); + + (Some(tool_name), lint_name) + } None => (None, lint_name), } } diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index c0a059b92aa..30ee8c9b6ae 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -88,7 +88,7 @@ impl<'s> LintLevelsBuilder<'s> { self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid); for &(ref lint_name, level) in &sess.opts.lint_opts { - store.check_lint_name_cmdline(sess, &lint_name, level); + store.check_lint_name_cmdline(sess, &lint_name, level, self.crate_attrs); let orig_level = level; // If the cap is less than this specified level, e.g., if we've got @@ -110,7 +110,7 @@ impl<'s> LintLevelsBuilder<'s> { } for lint_name in &sess.opts.force_warns { - store.check_lint_name_cmdline(sess, lint_name, Level::ForceWarn); + store.check_lint_name_cmdline(sess, lint_name, Level::ForceWarn, self.crate_attrs); let lints = store .find_lints(lint_name) .unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids")); @@ -321,33 +321,15 @@ impl<'s> LintLevelsBuilder<'s> { continue; } }; - let tool_name = if meta_item.path.segments.len() > 1 { - let tool_ident = meta_item.path.segments[0].ident; - if !is_known_lint_tool(tool_ident.name, sess, &self.crate_attrs) { - let mut err = struct_span_err!( - sess, - tool_ident.span, - E0710, - "unknown tool name `{}` found in scoped lint: `{}`", - tool_ident.name, - pprust::path_to_string(&meta_item.path), - ); - if sess.is_nightly_build() { - err.help(&format!( - "add `#![register_tool({})]` to the crate root", - tool_ident.name - )); - } - err.emit(); - continue; - } - - Some(meta_item.path.segments.remove(0).ident.name) + let tool_ident = if meta_item.path.segments.len() > 1 { + Some(meta_item.path.segments.remove(0).ident) } else { None }; + let tool_name = tool_ident.map(|ident| ident.name); let name = pprust::path_to_string(&meta_item.path); - let lint_result = store.check_lint_name(&name, tool_name); + let lint_result = + store.check_lint_and_tool_name(sess, tool_name, &name, self.crate_attrs); match &lint_result { CheckLintNameResult::Ok(ids) => { let src = LintLevelSource::Node( @@ -364,7 +346,8 @@ impl<'s> LintLevelsBuilder<'s> { CheckLintNameResult::Tool(result) => { match *result { Ok(ids) => { - let complete_name = &format!("{}::{}", tool_name.unwrap(), name); + let complete_name = + &format!("{}::{}", tool_ident.unwrap().name, name); let src = LintLevelSource::Node( Symbol::intern(complete_name), sp, @@ -419,6 +402,26 @@ impl<'s> LintLevelsBuilder<'s> { } } + &CheckLintNameResult::NoTool => { + let mut err = struct_span_err!( + sess, + tool_ident.map_or(DUMMY_SP, |ident| ident.span), + E0710, + "unknown tool name `{}` found in scoped lint: `{}::{}`", + tool_name.unwrap(), + tool_name.unwrap(), + pprust::path_to_string(&meta_item.path), + ); + if sess.is_nightly_build() { + err.help(&format!( + "add `#![register_tool({})]` to the crate root", + tool_name.unwrap() + )); + } + err.emit(); + continue; + } + _ if !self.warn_about_weird_lints => {} CheckLintNameResult::Warning(msg, renamed) => { @@ -450,8 +453,8 @@ impl<'s> LintLevelsBuilder<'s> { let (level, src) = self.sets.get_lint_level(lint, self.cur, Some(&specs), self.sess); struct_lint_level(self.sess, lint, level, src, Some(sp.into()), |lint| { - let name = if let Some(tool_name) = tool_name { - format!("{}::{}", tool_name, name) + let name = if let Some(tool_ident) = tool_ident { + format!("{}::{}", tool_ident.name, name) } else { name.to_string() }; @@ -578,7 +581,7 @@ impl<'s> LintLevelsBuilder<'s> { } } -fn is_known_lint_tool(m_item: Symbol, sess: &Session, attrs: &[ast::Attribute]) -> bool { +pub fn is_known_lint_tool(m_item: Symbol, sess: &Session, attrs: &[ast::Attribute]) -> bool { if [sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item) { return true; } diff --git a/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr index 9e0177c47da..b7c5893a0ea 100644 --- a/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr +++ b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr @@ -1,10 +1,10 @@ -error[E0602]: unknown lint: `unknown_tool::foo` +error[E0602]: unknown lint tool: `unknown_tool` | - = note: requested on the command line with `-A unknown_tool::foo` + = note: requested on the command line with `-A foo` -error[E0602]: unknown lint: `unknown_tool::foo` +error[E0602]: unknown lint tool: `unknown_tool` | - = note: requested on the command line with `-A unknown_tool::foo` + = note: requested on the command line with `-A foo` error: aborting due to 2 previous errors -- cgit 1.4.1-3-g733a5 From 0db66e568c4f01527832a85fc2a89f4ea7b13c8e Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Wed, 7 Jul 2021 01:33:25 -0700 Subject: Add self to mailmap --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index 5d9bc173364..8b504084266 100644 --- a/.mailmap +++ b/.mailmap @@ -114,6 +114,7 @@ Heather Heather Herman J. Radtke III Herman J. Radtke III Ilyong Cho +inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Ivan Ivaschenko J. J. Weber Jakub Adam Wieczorek -- cgit 1.4.1-3-g733a5 From 3a31c6d8272c14388a34622193baf553636fe470 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 7 Jul 2021 11:08:52 +0200 Subject: Rustup to rustc 1.55.0-nightly (885399992 2021-07-06) --- rust-toolchain | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain b/rust-toolchain index c1b2d71ebc7..f806f7bdcd9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2021-06-30" +channel = "nightly-2021-07-07" components = ["rust-src", "rustc-dev", "llvm-tools-preview"] -- cgit 1.4.1-3-g733a5 From 00b2f56bc6f9add36b8616f369e2d169261eaeab Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Wed, 7 Jul 2021 11:39:29 +0200 Subject: Add memchr to list of permitted cg_clif deps Object started depending on it --- src/tools/tidy/src/deps.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index ea587210b4f..799d685ce5c 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -254,6 +254,7 @@ const PERMITTED_CRANELIFT_DEPENDENCIES: &[&str] = &[ "libloading", "log", "mach", + "memchr", "object", "regalloc", "region", -- cgit 1.4.1-3-g733a5 From 04a9c10fc27fcf7c4a4415401c7653a361177631 Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Wed, 7 Jul 2021 14:25:40 +0200 Subject: Fix ICE when misplaced visibility cannot be properly parsed --- compiler/rustc_parse/src/parser/item.rs | 8 +++++++- src/test/ui/parser/issue-86895.rs | 3 +++ src/test/ui/parser/issue-86895.stderr | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/parser/issue-86895.rs create mode 100644 src/test/ui/parser/issue-86895.stderr diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 2daa9e2485b..2ce63d011f4 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1791,7 +1791,13 @@ impl<'a> Parser<'a> { if self.check_keyword(kw::Pub) { let sp = sp_start.to(self.prev_token.span); if let Ok(snippet) = self.span_to_snippet(sp) { - let vis = self.parse_visibility(FollowedByType::No)?; + let vis = match self.parse_visibility(FollowedByType::No) { + Ok(v) => v, + Err(mut d) => { + d.cancel(); + return Err(err); + } + }; let vs = pprust::vis_to_string(&vis); let vs = vs.trim_end(); err.span_suggestion( diff --git a/src/test/ui/parser/issue-86895.rs b/src/test/ui/parser/issue-86895.rs new file mode 100644 index 00000000000..4cd09843107 --- /dev/null +++ b/src/test/ui/parser/issue-86895.rs @@ -0,0 +1,3 @@ +const pub () {} +//~^ ERROR expected one of `async`, `extern`, `fn`, or `unsafe` +pub fn main() {} diff --git a/src/test/ui/parser/issue-86895.stderr b/src/test/ui/parser/issue-86895.stderr new file mode 100644 index 00000000000..575d857c0ed --- /dev/null +++ b/src/test/ui/parser/issue-86895.stderr @@ -0,0 +1,8 @@ +error: expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub` + --> $DIR/issue-86895.rs:1:7 + | +LL | const pub () {} + | ^^^ expected one of `async`, `extern`, `fn`, or `unsafe` + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From e5c24ba400b2744455868c2ac4292d8ee3b1b0be Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 7 Jul 2021 14:27:54 +0200 Subject: Clean up rustdoc static files --- src/bootstrap/test.rs | 2 +- src/ci/docker/host-x86_64/mingw-check/Dockerfile | 4 +- src/librustdoc/config.rs | 2 +- src/librustdoc/html/static/FiraSans-LICENSE.txt | 94 - src/librustdoc/html/static/FiraSans-Medium.woff | Bin 186824 -> 0 bytes src/librustdoc/html/static/FiraSans-Medium.woff2 | Bin 132780 -> 0 bytes src/librustdoc/html/static/FiraSans-Regular.woff | Bin 183268 -> 0 bytes src/librustdoc/html/static/FiraSans-Regular.woff2 | Bin 129188 -> 0 bytes .../html/static/SourceCodePro-It.ttf.woff | Bin 58444 -> 0 bytes .../html/static/SourceCodePro-It.ttf.woff2 | Bin 44896 -> 0 bytes .../html/static/SourceCodePro-LICENSE.txt | 93 - .../html/static/SourceCodePro-Regular.ttf.woff | Bin 68152 -> 0 bytes .../html/static/SourceCodePro-Regular.ttf.woff2 | Bin 52228 -> 0 bytes .../html/static/SourceCodePro-Semibold.ttf.woff | Bin 68080 -> 0 bytes .../html/static/SourceCodePro-Semibold.ttf.woff2 | Bin 52348 -> 0 bytes .../html/static/SourceSerif4-Bold.ttf.woff | Bin 110552 -> 0 bytes .../html/static/SourceSerif4-Bold.ttf.woff2 | Bin 81320 -> 0 bytes .../html/static/SourceSerif4-It.ttf.woff | Bin 78108 -> 0 bytes .../html/static/SourceSerif4-It.ttf.woff2 | Bin 59860 -> 0 bytes src/librustdoc/html/static/SourceSerif4-LICENSE.md | 93 - .../html/static/SourceSerif4-Regular.ttf.woff | Bin 103604 -> 0 bytes .../html/static/SourceSerif4-Regular.ttf.woff2 | Bin 76180 -> 0 bytes src/librustdoc/html/static/brush.svg | 1 - src/librustdoc/html/static/clipboard.svg | 1 - src/librustdoc/html/static/css/normalize.css | 2 + src/librustdoc/html/static/css/noscript.css | 15 + src/librustdoc/html/static/css/rustdoc.css | 1888 ++++++++++++++++++++ src/librustdoc/html/static/css/settings.css | 107 ++ src/librustdoc/html/static/css/themes/ayu.css | 607 +++++++ src/librustdoc/html/static/css/themes/dark.css | 479 +++++ src/librustdoc/html/static/css/themes/light.css | 469 +++++ src/librustdoc/html/static/down-arrow.svg | 1 - src/librustdoc/html/static/favicon-16x16.png | Bin 2214 -> 0 bytes src/librustdoc/html/static/favicon-32x32.png | Bin 2919 -> 0 bytes src/librustdoc/html/static/favicon.svg | 24 - .../html/static/fonts/FiraSans-LICENSE.txt | 94 + .../html/static/fonts/FiraSans-Medium.woff | Bin 0 -> 186824 bytes .../html/static/fonts/FiraSans-Medium.woff2 | Bin 0 -> 132780 bytes .../html/static/fonts/FiraSans-Regular.woff | Bin 0 -> 183268 bytes .../html/static/fonts/FiraSans-Regular.woff2 | Bin 0 -> 129188 bytes .../html/static/fonts/SourceCodePro-It.ttf.woff | Bin 0 -> 58444 bytes .../html/static/fonts/SourceCodePro-It.ttf.woff2 | Bin 0 -> 44896 bytes .../html/static/fonts/SourceCodePro-LICENSE.txt | 93 + .../static/fonts/SourceCodePro-Regular.ttf.woff | Bin 0 -> 68152 bytes .../static/fonts/SourceCodePro-Regular.ttf.woff2 | Bin 0 -> 52228 bytes .../static/fonts/SourceCodePro-Semibold.ttf.woff | Bin 0 -> 68080 bytes .../static/fonts/SourceCodePro-Semibold.ttf.woff2 | Bin 0 -> 52348 bytes .../html/static/fonts/SourceSerif4-Bold.ttf.woff | Bin 0 -> 110552 bytes .../html/static/fonts/SourceSerif4-Bold.ttf.woff2 | Bin 0 -> 81320 bytes .../html/static/fonts/SourceSerif4-It.ttf.woff | Bin 0 -> 78108 bytes .../html/static/fonts/SourceSerif4-It.ttf.woff2 | Bin 0 -> 59860 bytes .../html/static/fonts/SourceSerif4-LICENSE.md | 93 + .../static/fonts/SourceSerif4-Regular.ttf.woff | Bin 0 -> 103604 bytes .../static/fonts/SourceSerif4-Regular.ttf.woff2 | Bin 0 -> 76180 bytes .../noto-sans-kr-v13-korean-regular-LICENSE.txt | 93 + .../fonts/noto-sans-kr-v13-korean-regular.woff | Bin 0 -> 287068 bytes src/librustdoc/html/static/images/brush.svg | 1 + src/librustdoc/html/static/images/clipboard.svg | 1 + src/librustdoc/html/static/images/down-arrow.svg | 1 + .../html/static/images/favicon-16x16.png | Bin 0 -> 2214 bytes .../html/static/images/favicon-32x32.png | Bin 0 -> 2919 bytes src/librustdoc/html/static/images/favicon.svg | 24 + src/librustdoc/html/static/images/rust-logo.png | Bin 0 -> 5758 bytes src/librustdoc/html/static/images/wheel.svg | 1 + src/librustdoc/html/static/js/main.js | 1018 +++++++++++ src/librustdoc/html/static/js/search.js | 1561 ++++++++++++++++ src/librustdoc/html/static/js/settings.js | 60 + src/librustdoc/html/static/js/source-script.js | 249 +++ src/librustdoc/html/static/js/storage.js | 219 +++ src/librustdoc/html/static/main.js | 1018 ----------- src/librustdoc/html/static/normalize.css | 2 - src/librustdoc/html/static/noscript.css | 15 - .../noto-sans-kr-v13-korean-regular-LICENSE.txt | 93 - .../static/noto-sans-kr-v13-korean-regular.woff | Bin 287068 -> 0 bytes src/librustdoc/html/static/rust-logo.png | Bin 5758 -> 0 bytes src/librustdoc/html/static/rustdoc.css | 1888 -------------------- src/librustdoc/html/static/search.js | 1561 ---------------- src/librustdoc/html/static/settings.css | 107 -- src/librustdoc/html/static/settings.js | 60 - src/librustdoc/html/static/source-script.js | 249 --- src/librustdoc/html/static/storage.js | 219 --- src/librustdoc/html/static/themes/ayu.css | 607 ------- src/librustdoc/html/static/themes/dark.css | 479 ----- src/librustdoc/html/static/themes/light.css | 469 ----- src/librustdoc/html/static/wheel.svg | 1 - src/librustdoc/html/static_files.rs | 83 +- src/librustdoc/theme/tests.rs | 2 +- src/test/run-make-fulldeps/rustdoc-themes/Makefile | 2 +- 88 files changed, 7123 insertions(+), 7122 deletions(-) delete mode 100644 src/librustdoc/html/static/FiraSans-LICENSE.txt delete mode 100644 src/librustdoc/html/static/FiraSans-Medium.woff delete mode 100644 src/librustdoc/html/static/FiraSans-Medium.woff2 delete mode 100644 src/librustdoc/html/static/FiraSans-Regular.woff delete mode 100644 src/librustdoc/html/static/FiraSans-Regular.woff2 delete mode 100644 src/librustdoc/html/static/SourceCodePro-It.ttf.woff delete mode 100644 src/librustdoc/html/static/SourceCodePro-It.ttf.woff2 delete mode 100644 src/librustdoc/html/static/SourceCodePro-LICENSE.txt delete mode 100644 src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff delete mode 100644 src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff2 delete mode 100644 src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff delete mode 100644 src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff2 delete mode 100644 src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff delete mode 100644 src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff2 delete mode 100644 src/librustdoc/html/static/SourceSerif4-It.ttf.woff delete mode 100644 src/librustdoc/html/static/SourceSerif4-It.ttf.woff2 delete mode 100644 src/librustdoc/html/static/SourceSerif4-LICENSE.md delete mode 100644 src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff delete mode 100644 src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff2 delete mode 100644 src/librustdoc/html/static/brush.svg delete mode 100644 src/librustdoc/html/static/clipboard.svg create mode 100644 src/librustdoc/html/static/css/normalize.css create mode 100644 src/librustdoc/html/static/css/noscript.css create mode 100644 src/librustdoc/html/static/css/rustdoc.css create mode 100644 src/librustdoc/html/static/css/settings.css create mode 100644 src/librustdoc/html/static/css/themes/ayu.css create mode 100644 src/librustdoc/html/static/css/themes/dark.css create mode 100644 src/librustdoc/html/static/css/themes/light.css delete mode 100644 src/librustdoc/html/static/down-arrow.svg delete mode 100644 src/librustdoc/html/static/favicon-16x16.png delete mode 100644 src/librustdoc/html/static/favicon-32x32.png delete mode 100644 src/librustdoc/html/static/favicon.svg create mode 100644 src/librustdoc/html/static/fonts/FiraSans-LICENSE.txt create mode 100644 src/librustdoc/html/static/fonts/FiraSans-Medium.woff create mode 100644 src/librustdoc/html/static/fonts/FiraSans-Medium.woff2 create mode 100644 src/librustdoc/html/static/fonts/FiraSans-Regular.woff create mode 100644 src/librustdoc/html/static/fonts/FiraSans-Regular.woff2 create mode 100644 src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff create mode 100644 src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff2 create mode 100644 src/librustdoc/html/static/fonts/SourceCodePro-LICENSE.txt create mode 100644 src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff create mode 100644 src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff2 create mode 100644 src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff create mode 100644 src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff2 create mode 100644 src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff create mode 100644 src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff2 create mode 100644 src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff create mode 100644 src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff2 create mode 100644 src/librustdoc/html/static/fonts/SourceSerif4-LICENSE.md create mode 100644 src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff create mode 100644 src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff2 create mode 100644 src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular-LICENSE.txt create mode 100644 src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular.woff create mode 100644 src/librustdoc/html/static/images/brush.svg create mode 100644 src/librustdoc/html/static/images/clipboard.svg create mode 100644 src/librustdoc/html/static/images/down-arrow.svg create mode 100644 src/librustdoc/html/static/images/favicon-16x16.png create mode 100644 src/librustdoc/html/static/images/favicon-32x32.png create mode 100644 src/librustdoc/html/static/images/favicon.svg create mode 100644 src/librustdoc/html/static/images/rust-logo.png create mode 100644 src/librustdoc/html/static/images/wheel.svg create mode 100644 src/librustdoc/html/static/js/main.js create mode 100644 src/librustdoc/html/static/js/search.js create mode 100644 src/librustdoc/html/static/js/settings.js create mode 100644 src/librustdoc/html/static/js/source-script.js create mode 100644 src/librustdoc/html/static/js/storage.js delete mode 100644 src/librustdoc/html/static/main.js delete mode 100644 src/librustdoc/html/static/normalize.css delete mode 100644 src/librustdoc/html/static/noscript.css delete mode 100644 src/librustdoc/html/static/noto-sans-kr-v13-korean-regular-LICENSE.txt delete mode 100644 src/librustdoc/html/static/noto-sans-kr-v13-korean-regular.woff delete mode 100644 src/librustdoc/html/static/rust-logo.png delete mode 100644 src/librustdoc/html/static/rustdoc.css delete mode 100644 src/librustdoc/html/static/search.js delete mode 100644 src/librustdoc/html/static/settings.css delete mode 100644 src/librustdoc/html/static/settings.js delete mode 100644 src/librustdoc/html/static/source-script.js delete mode 100644 src/librustdoc/html/static/storage.js delete mode 100644 src/librustdoc/html/static/themes/ayu.css delete mode 100644 src/librustdoc/html/static/themes/dark.css delete mode 100644 src/librustdoc/html/static/themes/light.css delete mode 100644 src/librustdoc/html/static/wheel.svg diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 64b3ee7c359..e4d6a3f587b 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -742,7 +742,7 @@ impl Step for RustdocTheme { let rustdoc = builder.out.join("bootstrap/debug/rustdoc"); let mut cmd = builder.tool_cmd(Tool::RustdocTheme); cmd.arg(rustdoc.to_str().unwrap()) - .arg(builder.src.join("src/librustdoc/html/static/themes").to_str().unwrap()) + .arg(builder.src.join("src/librustdoc/html/static/css/themes").to_str().unwrap()) .env("RUSTC_STAGE", self.compiler.stage.to_string()) .env("RUSTC_SYSROOT", builder.sysroot(self.compiler)) .env("RUSTDOC_LIBDIR", builder.sysroot_libdir(self.compiler, self.compiler.host)) diff --git a/src/ci/docker/host-x86_64/mingw-check/Dockerfile b/src/ci/docker/host-x86_64/mingw-check/Dockerfile index 8066ea3a944..c27e42a2662 100644 --- a/src/ci/docker/host-x86_64/mingw-check/Dockerfile +++ b/src/ci/docker/host-x86_64/mingw-check/Dockerfile @@ -40,5 +40,5 @@ ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \ /scripts/validate-toolstate.sh && \ /scripts/validate-error-codes.sh && \ # Runs checks to ensure that there are no ES5 issues in our JS code. - es-check es5 ../src/librustdoc/html/static/*.js && \ - eslint ../src/librustdoc/html/static/*.js + es-check es5 ../src/librustdoc/html/static/js/*.js && \ + eslint ../src/librustdoc/html/static/js/*.js diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 1b5a00dde59..4cf647a81ae 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -513,7 +513,7 @@ impl Options { )) .warn("the theme may appear incorrect when loaded") .help(&format!( - "to see what rules are missing, call `rustdoc --check-theme \"{}\"`", + "to see what rules are missing, call `rustdoc --check-theme \"{}\"`", theme_s )) .emit(); diff --git a/src/librustdoc/html/static/FiraSans-LICENSE.txt b/src/librustdoc/html/static/FiraSans-LICENSE.txt deleted file mode 100644 index ff9afab064a..00000000000 --- a/src/librustdoc/html/static/FiraSans-LICENSE.txt +++ /dev/null @@ -1,94 +0,0 @@ -Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A. -with Reserved Font Name < Fira >, - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/FiraSans-Medium.woff b/src/librustdoc/html/static/FiraSans-Medium.woff deleted file mode 100644 index 7d742c5fb7d..00000000000 Binary files a/src/librustdoc/html/static/FiraSans-Medium.woff and /dev/null differ diff --git a/src/librustdoc/html/static/FiraSans-Medium.woff2 b/src/librustdoc/html/static/FiraSans-Medium.woff2 deleted file mode 100644 index 7a1e5fc548e..00000000000 Binary files a/src/librustdoc/html/static/FiraSans-Medium.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/FiraSans-Regular.woff b/src/librustdoc/html/static/FiraSans-Regular.woff deleted file mode 100644 index d8e0363f4e1..00000000000 Binary files a/src/librustdoc/html/static/FiraSans-Regular.woff and /dev/null differ diff --git a/src/librustdoc/html/static/FiraSans-Regular.woff2 b/src/librustdoc/html/static/FiraSans-Regular.woff2 deleted file mode 100644 index e766e06ccb0..00000000000 Binary files a/src/librustdoc/html/static/FiraSans-Regular.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-It.ttf.woff b/src/librustdoc/html/static/SourceCodePro-It.ttf.woff deleted file mode 100644 index 8d68f2febdd..00000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-It.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-It.ttf.woff2 b/src/librustdoc/html/static/SourceCodePro-It.ttf.woff2 deleted file mode 100644 index 462c34efcd9..00000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-It.ttf.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-LICENSE.txt b/src/librustdoc/html/static/SourceCodePro-LICENSE.txt deleted file mode 100644 index 07542572e33..00000000000 --- a/src/librustdoc/html/static/SourceCodePro-LICENSE.txt +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. - -This Font Software is licensed under the SIL Open Font License, Version 1.1. - -This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff b/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff deleted file mode 100644 index 7be076e1fca..00000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff2 b/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff2 deleted file mode 100644 index 10b558e0b69..00000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-Regular.ttf.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff b/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff deleted file mode 100644 index 61bc67b8025..00000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff2 b/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff2 deleted file mode 100644 index 5ec64eef0ec..00000000000 Binary files a/src/librustdoc/html/static/SourceCodePro-Semibold.ttf.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff b/src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff deleted file mode 100644 index 8ad41888e6e..00000000000 Binary files a/src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff2 b/src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff2 deleted file mode 100644 index db57d21455c..00000000000 Binary files a/src/librustdoc/html/static/SourceSerif4-Bold.ttf.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/SourceSerif4-It.ttf.woff b/src/librustdoc/html/static/SourceSerif4-It.ttf.woff deleted file mode 100644 index 2a34b5c42a8..00000000000 Binary files a/src/librustdoc/html/static/SourceSerif4-It.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceSerif4-It.ttf.woff2 b/src/librustdoc/html/static/SourceSerif4-It.ttf.woff2 deleted file mode 100644 index 1cbc021a3aa..00000000000 Binary files a/src/librustdoc/html/static/SourceSerif4-It.ttf.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/SourceSerif4-LICENSE.md b/src/librustdoc/html/static/SourceSerif4-LICENSE.md deleted file mode 100644 index 68ea1892406..00000000000 --- a/src/librustdoc/html/static/SourceSerif4-LICENSE.md +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. - -This Font Software is licensed under the SIL Open Font License, Version 1.1. - -This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff b/src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff deleted file mode 100644 index 45a5521ab0c..00000000000 Binary files a/src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff and /dev/null differ diff --git a/src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff2 b/src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff2 deleted file mode 100644 index 2db73fe2b49..00000000000 Binary files a/src/librustdoc/html/static/SourceSerif4-Regular.ttf.woff2 and /dev/null differ diff --git a/src/librustdoc/html/static/brush.svg b/src/librustdoc/html/static/brush.svg deleted file mode 100644 index ea266e856a9..00000000000 --- a/src/librustdoc/html/static/brush.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/librustdoc/html/static/clipboard.svg b/src/librustdoc/html/static/clipboard.svg deleted file mode 100644 index 8adbd996304..00000000000 --- a/src/librustdoc/html/static/clipboard.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/librustdoc/html/static/css/normalize.css b/src/librustdoc/html/static/css/normalize.css new file mode 100644 index 00000000000..fdb8a8c652e --- /dev/null +++ b/src/librustdoc/html/static/css/normalize.css @@ -0,0 +1,2 @@ +/* ignore-tidy-linelength */ +/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:0.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace, monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type="button"],[type="reset"],[type="submit"],button{-webkit-appearance:button}[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none} diff --git a/src/librustdoc/html/static/css/noscript.css b/src/librustdoc/html/static/css/noscript.css new file mode 100644 index 00000000000..0a196edd53b --- /dev/null +++ b/src/librustdoc/html/static/css/noscript.css @@ -0,0 +1,15 @@ +/* +This whole CSS file is used only in case rustdoc is rendered with javascript disabled. Since a lot +of content is hidden by default (depending on the settings too), we have to overwrite some of the +rules. +*/ + +#main .attributes { + /* Since there is no toggle (the "[-]") when JS is disabled, no need for this margin either. */ + margin-left: 0 !important; +} + +#copy-path { + /* It requires JS to work so no need to display it in this case. */ + display: none; +} diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css new file mode 100644 index 00000000000..71123aa9a0e --- /dev/null +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -0,0 +1,1888 @@ +/* See FiraSans-LICENSE.txt for the Fira Sans license. */ +@font-face { + font-family: 'Fira Sans'; + font-style: normal; + font-weight: 400; + src: local('Fira Sans'), + url("FiraSans-Regular.woff2") format("woff2"), + url("FiraSans-Regular.woff") format('woff'); + font-display: swap; +} +@font-face { + font-family: 'Fira Sans'; + font-style: normal; + font-weight: 500; + src: local('Fira Sans Medium'), + url("FiraSans-Medium.woff2") format("woff2"), + url("FiraSans-Medium.woff") format('woff'); + font-display: swap; +} + +/* See SourceSerif4-LICENSE.md for the Source Serif 4 license. */ +@font-face { + font-family: 'Source Serif 4'; + font-style: normal; + font-weight: 400; + src: local('Source Serif 4'), + url("SourceSerif4-Regular.ttf.woff2") format("woff2"), + url("SourceSerif4-Regular.ttf.woff") format("woff"); + font-display: swap; +} +@font-face { + font-family: 'Source Serif 4'; + font-style: italic; + font-weight: 400; + src: local('Source Serif 4 Italic'), + url("SourceSerif4-It.ttf.woff2") format("woff2"), + url("SourceSerif4-It.ttf.woff") format("woff"); + font-display: swap; +} +@font-face { + font-family: 'Source Serif 4'; + font-style: normal; + font-weight: 700; + src: local('Source Serif 4 Bold'), + url("SourceSerif4-Bold.ttf.woff2") format("woff2"), + url("SourceSerif4-Bold.ttf.woff") format("woff"); + font-display: swap; +} + +/* See SourceCodePro-LICENSE.txt for the Source Code Pro license. */ +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 400; + /* Avoid using locally installed font because bad versions are in circulation: + * see https://github.com/rust-lang/rust/issues/24355 */ + src: url("SourceCodePro-Regular.ttf.woff2") format("woff2"), + url("SourceCodePro-Regular.ttf.woff") format("woff"); + font-display: swap; +} +@font-face { + font-family: 'Source Code Pro'; + font-style: italic; + font-weight: 400; + src: url("SourceCodePro-It.ttf.woff2") format("woff2"), + url("SourceCodePro-It.ttf.woff") format("woff"); + font-display: swap; +} +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 600; + src: url("SourceCodePro-Semibold.ttf.woff2") format("woff2"), + url("SourceCodePro-Semibold.ttf.woff") format("woff"); + font-display: swap; +} + +/* Avoid using legacy CJK serif fonts in Windows like Batang */ +@font-face { + font-family: 'Noto Sans KR'; + src: url("noto-sans-kr-v13-korean-regular.woff") format("woff"); + font-display: swap; + unicode-range: U+A960-A97F, U+AC00-D7AF, U+D7B0-D7FF; +} + +* { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} + +/* This part handles the "default" theme being used depending on the system one. */ +html { + content: ""; +} +@media (prefers-color-scheme: light) { + html { + content: "light"; + } +} +@media (prefers-color-scheme: dark) { + html { + content: "dark"; + } +} + +/* General structure and fonts */ + +body { + font: 16px/1.4 "Source Serif 4", "Noto Sans KR", serif; + margin: 0; + position: relative; + padding: 10px 15px 20px 15px; + + -webkit-font-feature-settings: "kern", "liga"; + -moz-font-feature-settings: "kern", "liga"; + font-feature-settings: "kern", "liga"; +} + +h1 { + font-size: 1.5em; +} +h2 { + font-size: 1.4em; +} +h3 { + font-size: 1.3em; +} +h1, h2, h3, h4 { + font-weight: 500; + margin: 20px 0 15px 0; + padding-bottom: 6px; +} +h1.fqn { + display: flex; + border-bottom: 1px dashed; + margin-top: 0; + + /* workaround to keep flex from breaking below 700 px width due to the float: right on the nav + above the h1 */ + padding-left: 1px; +} +h1.fqn > .in-band > a:hover { + text-decoration: underline; +} +h2, h3, h4 { + border-bottom: 1px solid; +} +.impl, +.impl-items .method, +.methods .method, +.impl-items .type, +.methods .type, +.impl-items .associatedconstant, +.methods .associatedconstant, +.impl-items .associatedtype, +.methods .associatedtype { + flex-basis: 100%; + font-weight: 600; + margin-top: 16px; + margin-bottom: 10px; + position: relative; +} +.impl, .method.trait-impl, +.type.trait-impl, +.associatedconstant.trait-impl, +.associatedtype.trait-impl { + padding-left: 15px; +} + +div.impl-items > div { + padding-left: 0; +} + +h1, h2, h3, h4, +.sidebar, a.source, .search-input, .search-results .result-name, +.content table td:first-child > a, +.item-left > a, +div.item-list .out-of-band, span.since, +#source-sidebar, #sidebar-toggle, +details.rustdoc-toggle > summary::before, +details.undocumented > summary::before, +div.impl-items > div:not(.docblock):not(.item-info), +.content ul.crate a.crate, a.srclink, +/* This selector is for the items listed in the "all items" page. */ +#main > ul.docblock > li > a { + font-family: "Fira Sans", Arial, sans-serif; +} + +.content ul.crate a.crate { + font-size: 16px/1.6; +} + +ol, ul { + padding-left: 25px; +} +ul ul, ol ul, ul ol, ol ol { + margin-bottom: .6em; +} + +p { + margin: 0 0 .6em 0; +} + +summary { + outline: none; +} + +/* Fix some style changes due to normalize.css 8 */ + +td, +th { + padding: 0; +} + +table { + border-collapse: collapse; +} + +button, +input, +optgroup, +select, +textarea { + color: inherit; + font: inherit; + margin: 0; +} + +/* end tweaks for normalize.css 8 */ + +details:not(.rustdoc-toggle) summary { + margin-bottom: .6em; +} + +code, pre, a.test-arrow { + font-family: "Source Code Pro", monospace; +} +.docblock code, .docblock-short code { + border-radius: 3px; + padding: 0 0.1em; +} +.docblock pre code, .docblock-short pre code { + padding: 0; + padding-right: 1ex; +} +pre { + padding: 14px; +} + +.source .content pre { + padding: 20px; +} + +img { + max-width: 100%; +} + +li { + position: relative; +} + +.source .content { + margin-top: 50px; + max-width: none; + overflow: visible; + margin-left: 0px; +} + +nav.sub { + font-size: 16px; + text-transform: uppercase; +} + +.sidebar { + width: 200px; + position: fixed; + left: 0; + top: 0; + bottom: 0; + overflow: auto; +} + +/* Improve the scrollbar display on firefox */ +* { + scrollbar-width: initial; +} +.sidebar { + scrollbar-width: thin; +} + +/* Improve the scrollbar display on webkit-based browsers */ +::-webkit-scrollbar { + width: 12px; +} +.sidebar::-webkit-scrollbar { + width: 8px; +} +::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0; +} + +.sidebar .block > ul > li { + margin-right: -10px; +} + +.content, nav { + max-width: 960px; +} + +/* Everything else */ + +.hidden { + display: none !important; +} + +.logo-container { + height: 100px; + width: 100px; + position: relative; + margin: 20px auto; + display: block; + margin-top: 10px; +} + +.logo-container > img { + max-width: 100px; + max-height: 100px; + position: absolute; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); + display: block; +} + +.sidebar .location { + border: 1px solid; + font-size: 17px; + margin: 30px 10px 20px 10px; + text-align: center; + word-wrap: break-word; +} + +.sidebar .version { + font-size: 15px; + text-align: center; + border-bottom: 1px solid; + overflow-wrap: break-word; + word-wrap: break-word; /* deprecated */ + word-break: break-word; /* Chrome, non-standard */ +} + +.location:empty { + border: none; +} + +.location a:first-of-type { + font-weight: 500; +} +.location a:hover { + text-decoration: underline; +} + +.block { + padding: 0; + margin-bottom: 14px; +} +.block h2, .block h3 { + text-align: center; +} +.block ul, .block li { + margin: 0 10px; + padding: 0; + list-style: none; +} + +.block a { + display: block; + text-overflow: ellipsis; + overflow: hidden; + line-height: 15px; + padding: 7px 5px; + font-size: 14px; + font-weight: 300; + transition: border 500ms ease-out; +} + +.sidebar-title { + border-top: 1px solid; + border-bottom: 1px solid; + text-align: center; + font-size: 17px; + margin-bottom: 5px; +} + +.sidebar-links { + margin-bottom: 15px; +} + +.sidebar-links > a { + padding-left: 10px; + width: 100%; +} + +.sidebar-menu { + display: none; +} + +.content { + padding: 15px 0; +} + +.source .content pre.rust { + white-space: pre; + overflow: auto; + padding-left: 0; +} + +.rustdoc .example-wrap { + display: inline-flex; + margin-bottom: 10px; +} + +.example-wrap { + position: relative; + width: 100%; +} + +.example-wrap > pre.line-number { + overflow: initial; + border: 1px solid; + padding: 13px 8px; + text-align: right; + border-top-left-radius: 5px; + border-bottom-left-radius: 5px; +} + +.rustdoc:not(.source) .example-wrap > pre.rust { + width: 100%; + overflow-x: auto; +} + +.rustdoc .example-wrap > pre { + margin: 0; +} + +#search { + margin-left: 230px; + position: relative; +} + +#results > table { + width: 100%; + table-layout: fixed; +} + +.content > .example-wrap pre.line-numbers { + position: relative; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} +.line-numbers span { + cursor: pointer; +} + +.docblock-short { + overflow-wrap: anywhere; +} +.docblock-short p { + display: inline; +} + +.docblock-short p { + overflow: hidden; + text-overflow: ellipsis; + margin: 0; +} +/* Wrap non-pre code blocks (`text`) but not (```text```). */ +.docblock > :not(pre) > code, +.docblock-short > :not(pre) > code { + white-space: pre-wrap; +} + +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { + border-bottom: 1px solid; +} + +.top-doc .docblock h1 { font-size: 1.3em; } +.top-doc .docblock h2 { font-size: 1.15em; } +.top-doc .docblock h3, +.top-doc .docblock h4, +.top-doc .docblock h5 { + font-size: 1em; +} + +.docblock h1 { font-size: 1em; } +.docblock h2 { font-size: 0.95em; } +.docblock h3, .docblock h4, .docblock h5 { font-size: 0.9em; } + +.docblock { + margin-left: 24px; + position: relative; +} + +.content .out-of-band { + flex-grow: 0; + text-align: right; + font-size: 23px; + margin: 0px; + padding: 0 0 0 12px; + font-weight: normal; +} + +.method > code, .trait-impl > code, .invisible > code { + max-width: calc(100% - 41px); + display: block; +} + +.invisible { + width: 100%; + display: inline-block; +} + +.content .in-band { + flex-grow: 1; + margin: 0px; + padding: 0px; +} + +.in-band > code { + display: inline-block; +} + +#main { + position: relative; +} +#main > .since { + top: inherit; + font-family: "Fira Sans", Arial, sans-serif; +} + +.content table:not(.table-display) { + border-spacing: 0 5px; +} +.content td { vertical-align: top; } +.content td:first-child { padding-right: 20px; } +.content td p:first-child { margin-top: 0; } +.content td h1, .content td h2 { margin-left: 0; font-size: 1.1em; } +.content tr:first-child td { border-top: 0; } + +.docblock table { + margin: .5em 0; + width: calc(100% - 2px); + border: 1px dashed; +} + +.docblock table td { + padding: .5em; + border: 1px dashed; +} + +.docblock table th { + padding: .5em; + text-align: left; + border: 1px solid; +} + +.fields + table { + margin-bottom: 1em; +} + +.content .item-list { + list-style-type: none; + padding: 0; +} + +.content .multi-column { + -moz-column-count: 5; + -moz-column-gap: 2.5em; + -webkit-column-count: 5; + -webkit-column-gap: 2.5em; + column-count: 5; + column-gap: 2.5em; +} +.content .multi-column li { width: 100%; display: inline-block; } + +.content > .methods > .method { + font-size: 1em; + position: relative; +} +/* Shift "where ..." part of method or fn definition down a line */ +.content .method .where, +.content .fn .where, +.content .where.fmt-newline { + display: block; + font-size: 0.8em; +} + +.content .methods > div:not(.notable-traits):not(.method) { + margin-left: 40px; + margin-bottom: 15px; +} + +.content .docblock > .impl-items { + margin-left: 20px; + margin-top: -34px; +} +.content .docblock >.impl-items .table-display { + margin: 0; +} +.content .docblock >.impl-items table td { + padding: 0; +} +.content .docblock > .impl-items .table-display, .impl-items table td { + border: none; +} + +.content .item-info code { + font-size: 90%; +} + +.content .item-info { + position: relative; + margin-left: 33px; +} + +.sub-variant > div > .item-info { + margin-top: initial; +} + +.content .item-info::before { + content: '⬑'; + font-size: 25px; + position: absolute; + top: -6px; + left: -19px; +} + +.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant, +.impl-items > .associatedtype, .content .impl-items details > summary > .type, +.impl-items details > summary > .associatedconstant, +.impl-items details > summary > .associatedtype { + margin-left: 20px; +} + +.content .impl-items .docblock, .content .impl-items .item-info { + margin-bottom: .6em; +} + +.content .impl-items > .item-info { + margin-left: 40px; +} + +.methods > .item-info, .content .impl-items > .item-info { + margin-top: -8px; +} + +.impl-items { + flex-basis: 100%; +} + +#main > .item-info { + margin-top: 0; +} + +nav:not(.sidebar) { + border-bottom: 1px solid; + padding-bottom: 10px; + margin-bottom: 10px; +} +nav.main { + padding: 20px 0; + text-align: center; +} +nav.main .current { + border-top: 1px solid; + border-bottom: 1px solid; +} +nav.main .separator { + border: 1px solid; + display: inline-block; + height: 23px; + margin: 0 20px; +} +nav.sum { text-align: right; } +nav.sub form { display: inline; } + +nav.sub, .content { + margin-left: 230px; +} + +a { + text-decoration: none; + background: transparent; +} + +.small-section-header { + display: flex; + justify-content: space-between; + position: relative; +} + +.small-section-header:hover > .anchor { + display: initial; +} + +.in-band:hover > .anchor, .impl:hover > .anchor, .method.trait-impl:hover > .anchor, +.type.trait-impl:hover > .anchor, .associatedconstant.trait-impl:hover > .anchor, +.associatedtype.trait-impl:hover > .anchor { + display: inline-block; + position: absolute; +} +.anchor { + display: none; + position: absolute; + left: -7px; +} +.anchor.field { + left: -5px; +} +.small-section-header > .anchor { + left: -28px; + padding-right: 10px; /* avoid gap that causes hover to disappear */ +} +.anchor:before { + content: '\2002\00a7\2002'; +} + +.docblock a:not(.srclink):not(.test-arrow):hover, +.docblock-short a:not(.srclink):not(.test-arrow):hover, .item-info a { + text-decoration: underline; +} + +.invisible > .srclink, +.method > code + .srclink { + position: absolute; + top: 0; + right: 0; + font-size: 17px; + font-weight: normal; +} + +.block a.current.crate { font-weight: 500; } + +.item-table { + display: grid; + column-gap: 1.2rem; + row-gap: 0.0rem; + grid-template-columns: auto 1fr; + /* align content left */ + justify-items: start; +} + +.item-left, .item-right { + display: block; +} +.item-left { + grid-column: 1; +} +.item-right { + grid-column: 2; +} + +.search-container { + position: relative; +} +.search-container > div { + display: inline-flex; + width: calc(100% - 63px); +} +#crate-search { + min-width: 115px; + margin-top: 5px; + padding: 6px; + padding-right: 19px; + flex: none; + border: 0; + border-right: 0; + border-radius: 4px 0 0 4px; + outline: none; + cursor: pointer; + border-right: 1px solid; + -moz-appearance: none; + -webkit-appearance: none; + /* Removes default arrow from firefox */ + text-indent: 0.01px; + text-overflow: ""; + background-repeat: no-repeat; + background-color: transparent; + background-size: 20px; + background-position: calc(100% - 1px) 56%; +} +.search-container > .top-button { + position: absolute; + right: 0; + top: 10px; +} +.search-input { + /* Override Normalize.css: we have margins and do + not want to overflow - the `moz` attribute is necessary + until Firefox 29, too early to drop at this point */ + -moz-box-sizing: border-box !important; + box-sizing: border-box !important; + outline: none; + border: none; + border-radius: 1px; + margin-top: 5px; + padding: 10px 16px; + font-size: 17px; + transition: border-color 300ms ease; + transition: border-radius 300ms ease-in-out; + transition: box-shadow 300ms ease-in-out; + width: 100%; +} + +#crate-search + .search-input { + border-radius: 0 1px 1px 0; + width: calc(100% - 32px); +} + +.search-input:focus { + border-radius: 2px; + border: 0; + outline: 0; +} + +.search-results { + display: none; + padding-bottom: 2em; +} + +.search-results.active { + display: block; + /* prevent overhanging tabs from moving the first result */ + clear: both; +} + +.search-results .desc > span { + white-space: nowrap; + text-overflow: ellipsis; + overflow: hidden; + display: block; +} + +.search-results > a { + display: block; + width: 100%; + /* A little margin ensures the browser's outlining of focused links has room to display. */ + margin-left: 2px; + margin-right: 2px; + border-bottom: 1px solid #aaa3; +} + +.search-results > a > div { + display: flex; + flex-flow: row wrap; +} + +.search-results .result-name, .search-results div.desc, .search-results .result-description { + width: 50%; +} +.search-results .result-name { + padding-right: 1em; +} + +.search-results .result-name > span { + display: inline-block; + margin: 0; + font-weight: normal; +} + +body.blur > :not(#help) { + filter: blur(8px); + -webkit-filter: blur(8px); + opacity: .7; +} + +#help { + width: 100%; + height: 100vh; + position: fixed; + top: 0; + left: 0; + display: flex; + justify-content: center; + align-items: center; +} +#help > div { + flex: 0 0 auto; + box-shadow: 0 0 6px rgba(0,0,0,.2); + width: 550px; + height: auto; + border: 1px solid; +} +#help dt { + float: left; + clear: left; + display: block; + margin-right: 0.5rem; +} +#help > div > span { + text-align: center; + display: block; + margin: 10px 0; + font-size: 18px; + border-bottom: 1px solid #ccc; + padding-bottom: 4px; + margin-bottom: 6px; +} +#help dd { margin: 5px 35px; } +#help .infos { padding-left: 0; } +#help h1, #help h2 { margin-top: 0; } +#help > div div { + width: 50%; + float: left; + padding: 0 20px 20px 17px;; +} + +.stab { + border-width: 1px; + border-style: solid; + padding: 3px; + margin-bottom: 5px; + font-size: 90%; + font-weight: normal; +} +.stab p { + display: inline; +} + +.stab .emoji { + font-size: 1.5em; +} + +/* Black one-pixel outline around emoji shapes */ +.emoji { + text-shadow: + 1px 0 0 black, + -1px 0 0 black, + 0 1px 0 black, + 0 -1px 0 black; +} + +.module-item .stab, +.import-item .stab { + border-radius: 3px; + display: inline-block; + font-size: 80%; + line-height: 1.2; + margin-bottom: 0; + margin-left: .3em; + padding: 2px; + vertical-align: text-bottom; +} + +.module-item.unstable, +.import-item.unstable { + opacity: 0.65; +} + +.since { + font-weight: normal; + font-size: initial; +} + +.impl-items .since, .impl .since, .methods .since { + padding-left: 12px; + padding-right: 2px; + position: initial; +} + +.impl-items .srclink, .impl .srclink, .methods .srclink { + /* Override header settings otherwise it's too bold */ + font-size: 17px; + font-weight: normal; +} + +.rightside { + float: right; +} + +.has-srclink { + font-size: 16px; + margin-bottom: 12px; + /* Push the src link out to the right edge consistently */ + justify-content: space-between; +} + +.variants_table { + width: 100%; +} + +.variants_table tbody tr td:first-child { + width: 1%; /* make the variant name as small as possible */ +} + +td.summary-column { + width: 100%; +} + +.summary { + padding-right: 0px; +} + +pre.rust .question-mark { + font-weight: bold; +} + +a.test-arrow { + display: inline-block; + position: absolute; + padding: 5px 10px 5px 10px; + border-radius: 5px; + font-size: 130%; + top: 5px; + right: 5px; + z-index: 1; +} +a.test-arrow:hover{ + text-decoration: none; +} + +.section-header:hover a:before { + position: absolute; + left: -25px; + padding-right: 10px; /* avoid gap that causes hover to disappear */ + content: '\2002\00a7\2002'; +} + +.section-header:hover a { + text-decoration: none; +} + +.section-header a { + color: inherit; +} + +.code-attribute { + font-weight: 300; +} + +.since + .srclink { + padding-left: 10px; +} + +.item-spacer { + width: 100%; + height: 12px; +} + +.out-of-band > span.since { + position: initial; + font-size: 20px; + margin-right: 5px; +} + +.sub-variant, .sub-variant > h3 { + margin-top: 0px !important; + padding-top: 1px; +} + +#main > details > .sub-variant > h3 { + font-size: 15px; + margin-left: 25px; + margin-bottom: 5px; +} + +.sub-variant > div { + margin-left: 20px; + margin-bottom: 10px; +} + +.sub-variant > div > span { + display: block; + position: relative; +} + +.toggle-label { + display: inline-block; + margin-left: 4px; + margin-top: 3px; +} + +.docblock > .section-header:first-child { + margin-left: 15px; + margin-top: 0; +} + +.docblock > .section-header:first-child:hover > a:before { + left: -10px; +} + +#main > .variant, #main > .structfield { + display: block; +} + + +:target > code { + opacity: 1; +} + +:target { + padding-right: 3px; +} + +.information { + position: absolute; + left: -25px; + margin-top: 7px; + z-index: 1; +} + +.tooltip { + position: relative; + display: inline-block; + cursor: pointer; +} + +.tooltip::after { + display: none; + text-align: center; + padding: 5px 3px 3px 3px; + border-radius: 6px; + margin-left: 5px; + font-size: 16px; +} + +.tooltip.ignore::after { + content: "This example is not tested"; +} +.tooltip.compile_fail::after { + content: "This example deliberately fails to compile"; +} +.tooltip.should_panic::after { + content: "This example panics"; +} +.tooltip.edition::after { + content: "This code runs with edition " attr(data-edition); +} + +.tooltip::before { + content: " "; + position: absolute; + top: 50%; + left: 16px; + margin-top: -5px; + border-width: 5px; + border-style: solid; + display: none; +} + +.tooltip:hover::before, .tooltip:hover::after { + display: inline; +} + +.tooltip.compile_fail, .tooltip.should_panic, .tooltip.ignore { + font-weight: bold; + font-size: 20px; +} + +.notable-traits-tooltip { + display: inline-block; + cursor: pointer; +} + +.notable-traits:hover .notable-traits-tooltiptext, +.notable-traits .notable-traits-tooltiptext.force-tooltip { + display: inline-block; +} + +.notable-traits .notable-traits-tooltiptext { + display: none; + padding: 5px 3px 3px 3px; + border-radius: 6px; + margin-left: 5px; + z-index: 10; + font-size: 16px; + cursor: default; + position: absolute; + border: 1px solid; +} + +.notable-traits-tooltip::after { + /* The margin on the tooltip does not capture hover events, + this extends the area of hover enough so that mouse hover is not + lost when moving the mouse to the tooltip */ + content: "\00a0\00a0\00a0"; +} + +.notable-traits .notable, .notable-traits .docblock { + margin: 0; +} + +.notable-traits .notable { + margin: 0; + margin-bottom: 13px; + font-size: 19px; + font-weight: 600; +} + +.notable-traits .docblock code.content{ + margin: 0; + padding: 0; + font-size: 20px; +} + +/* Example code has the "Run" button that needs to be positioned relative to the pre */ +pre.rust.rust-example-rendered { + position: relative; +} + +pre.rust { + tab-size: 4; + -moz-tab-size: 4; +} + +.search-failed { + text-align: center; + margin-top: 20px; + display: none; +} + +.search-failed.active { + display: block; +} + +.search-failed > ul { + text-align: left; + max-width: 570px; + margin-left: auto; + margin-right: auto; +} + +#titles { + height: 35px; +} + +#titles > button { + float: left; + width: 33.3%; + text-align: center; + font-size: 18px; + cursor: pointer; + border: 0; + border-top: 2px solid; +} + +#titles > button:not(:last-child) { + margin-right: 1px; + width: calc(33.3% - 1px); +} + +#titles > button > div.count { + display: inline-block; + font-size: 16px; +} + +.notable-traits { + cursor: pointer; + z-index: 2; + margin-left: 5px; +} + +#all-types { + text-align: center; + border: 1px solid; + margin: 0 10px; + margin-bottom: 10px; + display: block; + border-radius: 7px; +} +#all-types > p { + margin: 5px 0; +} + +#sidebar-toggle { + position: fixed; + top: 30px; + left: 300px; + z-index: 10; + padding: 3px; + border-top-right-radius: 3px; + border-bottom-right-radius: 3px; + cursor: pointer; + font-weight: bold; + transition: left .5s; + font-size: 1.2em; + border: 1px solid; + border-left: 0; +} +#source-sidebar { + position: fixed; + top: 0; + bottom: 0; + left: 0; + width: 300px; + z-index: 1; + overflow: auto; + transition: left .5s; + border-right: 1px solid; +} +#source-sidebar > .title { + font-size: 1.5em; + text-align: center; + border-bottom: 1px solid; + margin-bottom: 6px; +} + +.theme-picker { + position: absolute; + left: 211px; + top: 19px; +} + +.theme-picker button { + outline: none; +} + +#settings-menu, #help-button { + position: absolute; + top: 10px; +} + +#settings-menu { + right: 0; + outline: none; +} + +#theme-picker, #settings-menu, #help-button, #copy-path { + padding: 4px; + width: 27px; + height: 29px; + border: 1px solid; + border-radius: 3px; + cursor: pointer; +} + +#help-button { + right: 30px; + font-family: "Fira Sans", Arial, sans-serif; + text-align: center; + font-size: 17px; + padding-top: 2px; +} + +#copy-path { + background: initial; + margin-left: 10px; + padding: 0; + padding-left: 2px; + border: 0; +} + +#theme-choices { + display: none; + position: absolute; + left: 0; + top: 28px; + border: 1px solid; + border-radius: 3px; + z-index: 1; + cursor: pointer; +} + +#theme-choices > button { + border: none; + width: 100%; + padding: 4px 8px; + text-align: center; + background: rgba(0,0,0,0); +} + +#theme-choices > button:not(:first-child) { + border-top: 1px solid; +} + +kbd { + display: inline-block; + padding: 3px 5px; + font: 15px monospace; + line-height: 10px; + vertical-align: middle; + border: solid 1px; + border-radius: 3px; + box-shadow: inset 0 -1px 0; + cursor: default; +} + +.hidden-by-impl-hider, +.hidden-by-usual-hider { + /* important because of conflicting rule for small screens */ + display: none !important; +} + +#implementations-list > h3 > span.in-band { + width: 100%; +} + +.table-display { + width: 100%; + border: 0; + border-collapse: collapse; + border-spacing: 0; + font-size: 16px; +} + +.table-display tr td:first-child { + padding-right: 0; +} + +.table-display tr td:last-child { + float: right; +} +.table-display .out-of-band { + position: relative; + font-size: 19px; + display: block; +} +#implementors-list > .impl-items .table-display .out-of-band { + font-size: 17px; +} + +.table-display td:hover .anchor { + display: block; + top: 2px; + left: -5px; +} + +#main > ul { + padding-left: 10px; +} +#main > ul > li { + list-style: none; +} + +.non-exhaustive { + margin-bottom: 1em; +} + +div.children { + padding-left: 27px; + display: none; +} +div.name { + cursor: pointer; + position: relative; + margin-left: 16px; +} +div.files > a { + display: block; + padding: 0 3px; +} +div.files > a:hover, div.name:hover { + background-color: #a14b4b; +} +div.name.expand + .children { + display: block; +} +div.name::before { + content: "\25B6"; + padding-left: 4px; + font-size: 0.7em; + position: absolute; + left: -16px; + top: 4px; +} +div.name.expand::before { + transform: rotate(90deg); + left: -15px; + top: 2px; +} + +/* The hideme class is used on summary tags that contain a span with + placeholder text shown only when the toggle is closed. For instance, + "Expand description" or "Show methods". */ +details.rustdoc-toggle > summary.hideme { + cursor: pointer; +} + +details.rustdoc-toggle > summary, details.undocumented > summary { + list-style: none; +} +details.rustdoc-toggle > summary::-webkit-details-marker, +details.rustdoc-toggle > summary::marker, +details.undocumented > summary::-webkit-details-marker, +details.undocumented > summary::marker { + display: none; +} + +details.rustdoc-toggle > summary.hideme > span { + margin-left: 9px; +} + +details.rustdoc-toggle > summary::before { + content: "[+]"; + font-weight: 300; + font-size: 0.8em; + letter-spacing: 1px; + cursor: pointer; +} + +details.rustdoc-toggle.top-doc > summary, +details.rustdoc-toggle.top-doc > summary::before, +details.rustdoc-toggle.non-exhaustive > summary, +details.rustdoc-toggle.non-exhaustive > summary::before { + font-family: 'Fira Sans'; + font-size: 16px; +} + +details.non-exhaustive { + margin-bottom: 8px; +} + +details.rustdoc-toggle > summary.hideme::before { + position: relative; +} + +details.rustdoc-toggle > summary:not(.hideme)::before { + position: absolute; + left: -23px; + top: 3px; +} + +.impl-items > details.rustdoc-toggle > summary:not(.hideme)::before, +.undocumented > details.rustdoc-toggle > summary:not(.hideme)::before { + position: absolute; + left: -2px; +} + +/* When a "hideme" summary is open and the "Expand description" or "Show + methods" text is hidden, we want the [-] toggle that remains to not + affect the layout of the items to its right. To do that, we use + absolute positioning. Note that we also set position: relative + on the parent
to make this work properly. */ +details.rustdoc-toggle[open] > summary.hideme { + position: absolute; +} + +details.rustdoc-toggle, details.undocumented { + position: relative; +} + +details.rustdoc-toggle[open] > summary.hideme > span { + display: none; +} + +details.rustdoc-toggle[open] > summary::before { + content: "[−]"; + display: inline; +} + +details.undocumented > summary::before { + content: "[+] Show hidden undocumented items"; + cursor: pointer; + font-size: 16px; + font-weight: 300; +} + +details.undocumented[open] > summary::before { + content: "[−] Hide undocumented items"; +} + +/* Media Queries */ + +@media (min-width: 701px) { + /* In case there is no documentation before a code block, we need to add some margin at the top + to prevent an overlay between the "collapse toggle" and the information tooltip. + However, it's not needed with smaller screen width because the doc/code block is always put + "one line" below. */ + .docblock > .information:first-child > .tooltip { + margin-top: 16px; + } +} + +@media (max-width: 700px) { + body { + padding-top: 0px; + } + + .rustdoc > .sidebar { + height: 45px; + min-height: 40px; + margin: 0; + margin-left: -15px; + padding: 0 15px; + position: static; + z-index: 11; + } + + .sidebar > .location { + float: right; + margin: 0px; + margin-top: 2px; + padding: 3px 10px 1px 10px; + min-height: 39px; + background: inherit; + text-align: left; + font-size: 24px; + } + + .sidebar .location:empty { + padding: 0; + } + + .sidebar .logo-container { + width: 35px; + height: 35px; + margin-top: 5px; + margin-bottom: 5px; + float: left; + margin-left: 50px; + } + + .sidebar .logo-container > img { + max-width: 35px; + max-height: 35px; + } + + .sidebar-menu { + position: fixed; + z-index: 10; + font-size: 2rem; + cursor: pointer; + width: 45px; + left: 0; + text-align: center; + display: block; + border-bottom: 1px solid; + border-right: 1px solid; + height: 45px; + } + + .rustdoc.source > .sidebar > .sidebar-menu { + display: none; + } + + .sidebar-elems { + position: fixed; + z-index: 1; + left: 0; + top: 45px; + bottom: 0; + overflow-y: auto; + border-right: 1px solid; + display: none; + } + + .sidebar > .block.version { + overflow: hidden; + border-bottom: none; + margin-bottom: 0; + height: 100%; + padding-left: 12px; + } + .sidebar > .block.version > div.narrow-helper { + float: left; + width: 1px; + height: 100%; + } + .sidebar > .block.version > p { + /* hide Version text if too narrow */ + margin: 0; + min-width: 55px; + /* vertically center */ + display: flex; + align-items: center; + height: 100%; + } + + nav.sub { + width: calc(100% - 32px); + float: right; + } + + .content { + margin-left: 0px; + } + + #main, #search { + margin-top: 45px; + padding: 0; + } + + #search { + margin-left: 0; + } + + .anchor { + display: none !important; + } + + .theme-picker { + left: 10px; + top: 54px; + z-index: 1; + } + + .notable-traits { + position: absolute; + left: -22px; + top: 24px; + } + + #titles > button > div.count { + float: left; + width: 100%; + } + + #titles { + height: 50px; + } + + .sidebar.mobile { + position: fixed; + width: 100%; + margin-left: 0; + background-color: rgba(0,0,0,0); + height: 100%; + } + /* + This allows to prevent the version text to overflow the sidebar title on mobile mode when the + sidebar is displayed (after clicking on the "hamburger" button). + */ + .sidebar.mobile > div.version { + overflow: hidden; + max-height: 33px; + } + .sidebar { + width: calc(100% + 30px); + } + + .show-it { + display: block; + width: 246px; + } + + .show-it > .block.items { + margin: 8px 0; + } + + .show-it > .block.items > ul { + margin: 0; + } + + .show-it > .block.items > ul > li { + text-align: center; + margin: 2px 0; + } + + .show-it > .block.items > ul > li > a { + font-size: 21px; + } + + /* Because of ios, we need to actually have a full height sidebar title so the + * actual sidebar can show up. But then we need to make it transparent so we don't + * hide content. The filler just allows to create the background for the sidebar + * title. But because of the absolute position, I had to lower the z-index. + */ + #sidebar-filler { + position: fixed; + left: 45px; + width: calc(100% - 45px); + top: 0; + height: 45px; + z-index: -1; + border-bottom: 1px solid; + } + + #main > details.rustdoc-toggle > summary::before, + #main > div > details.rustdoc-toggle > summary::before { + left: -11px; + } + + #all-types { + margin: 10px; + } + + #sidebar-toggle { + top: 100px; + width: 30px; + font-size: 1.5rem; + text-align: center; + padding: 0; + } + + #source-sidebar { + z-index: 11; + } + + #main > .line-numbers { + margin-top: 0; + } + + .notable-traits .notable-traits-tooltiptext { + left: 0; + top: 100%; + } + + /* We don't display the help button on mobile devices. */ + #help-button { + display: none; + } + + /* Display an alternating layout on tablets and phones */ + .item-table { + display: flex; + flex-flow: column wrap; + } + .item-left, .item-right { + width: 100%; + } + + .search-container > div { + width: calc(100% - 32px); + } + + /* Display an alternating layout on tablets and phones */ + .search-results > a { + border-bottom: 1px solid #aaa9; + padding: 5px 0px; + } + .search-results .result-name, .search-results div.desc, .search-results .result-description { + width: 100%; + } + .search-results div.desc, .search-results .result-description, .item-right { + padding-left: 2em; + } +} + +@media print { + nav.sub, .content .out-of-band { + display: none; + } +} + +@media (max-width: 464px) { + #titles, #titles > button { + height: 73px; + } + + /* This is to prevent the search bar from being underneath the
+ * element following it. + */ + #main, #search { + margin-top: 100px; + } + + #main > table:not(.table-display) td { + word-break: break-word; + width: 50%; + } + + .search-container > div { + display: block; + width: calc(100% - 37px); + } + + #crate-search { + width: 100%; + border-radius: 4px; + border: 0; + } + + #crate-search + .search-input { + width: calc(100% + 71px); + margin-left: -36px; + } + + #theme-picker, #settings-menu { + padding: 5px; + width: 31px; + height: 31px; + } + + #theme-picker { + margin-top: -2px; + } + + #settings-menu { + top: 7px; + } + + .docblock { + margin-left: 12px; + } +} diff --git a/src/librustdoc/html/static/css/settings.css b/src/librustdoc/html/static/css/settings.css new file mode 100644 index 00000000000..fb8990b30e2 --- /dev/null +++ b/src/librustdoc/html/static/css/settings.css @@ -0,0 +1,107 @@ +.setting-line { + padding: 5px; + position: relative; +} + +.setting-line > div { + display: inline-block; + vertical-align: top; + font-size: 17px; + padding-top: 2px; +} + +.setting-line > .title { + font-size: 19px; + width: 100%; + max-width: none; + border-bottom: 1px solid; +} + +.toggle { + position: relative; + display: inline-block; + width: 45px; + height: 27px; + margin-right: 20px; +} + +.toggle input { + opacity: 0; + position: absolute; +} + +.select-wrapper { + float: right; + position: relative; + height: 27px; + min-width: 25%; +} + +.select-wrapper select { + appearance: none; + -moz-appearance: none; + -webkit-appearance: none; + background: none; + border: 2px solid #ccc; + padding-right: 28px; + width: 100%; +} + +.select-wrapper img { + pointer-events: none; + position: absolute; + right: 0; + bottom: 0; + background: #ccc; + height: 100%; + width: 28px; + padding: 0px 4px; +} + +.select-wrapper select option { + color: initial; +} + +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .3s; + transition: .3s; +} + +.slider:before { + position: absolute; + content: ""; + height: 19px; + width: 19px; + left: 4px; + bottom: 4px; + background-color: white; + -webkit-transition: .3s; + transition: .3s; +} + +input:checked + .slider { + background-color: #2196F3; +} + +input:focus + .slider { + box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3); +} + +input:checked + .slider:before { + -webkit-transform: translateX(19px); + -ms-transform: translateX(19px); + transform: translateX(19px); +} + +.setting-line > .sub-settings { + padding-left: 42px; + width: 100%; + display: block; +} diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css new file mode 100644 index 00000000000..171d06c0a36 --- /dev/null +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -0,0 +1,607 @@ +/* +Based off of the Ayu theme +Original by Dempfi (https://github.com/dempfi/ayu) +*/ + +/* General structure and fonts */ + +body { + background-color: #0f1419; + color: #c5c5c5; +} + +h1, h2, h3, h4 { + color: white; +} +h1.fqn { + border-bottom-color: #5c6773; +} +h1.fqn a { + color: #fff; +} +h2, h3, h4 { + border-bottom-color: #5c6773; +} +h4 { + border: none; +} + +.in-band { + background-color: #0f1419; +} + +.invisible { + background: rgba(0, 0, 0, 0); +} + +code { + color: #ffb454; +} +h3 > code, h4 > code, h5 > code { + color: #e6e1cf; +} +pre > code { + color: #e6e1cf; +} +span code { + color: #e6e1cf; +} +.docblock a > code { + color: #39AFD7 !important; +} +.docblock code, .docblock-short code { + background-color: #191f26; +} +pre, .rustdoc.source .example-wrap { + color: #e6e1cf; + background-color: #191f26; +} + +.sidebar { + background-color: #14191f; +} + +.logo-container.rust-logo > img { + filter: drop-shadow(1px 0 0px #fff) + drop-shadow(0 1px 0 #fff) + drop-shadow(-1px 0 0 #fff) + drop-shadow(0 -1px 0 #fff); +} + +/* Improve the scrollbar display on firefox */ +* { + scrollbar-color: #5c6773 transparent; +} + +.sidebar { + scrollbar-color: #5c6773 transparent; +} + +/* Improve the scrollbar display on webkit-based browsers */ +::-webkit-scrollbar-track { + background-color: transparent; +} +::-webkit-scrollbar-thumb { + background-color: #5c6773; +} +.sidebar::-webkit-scrollbar-track { + background-color: transparent; +} +.sidebar::-webkit-scrollbar-thumb { + background-color: #5c6773; +} + +.sidebar .current { + background-color: transparent; + color: #ffb44c; +} + +.source .sidebar { + background-color: #0f1419; +} + +.sidebar .location { + border-color: #000; + background-color: #0f1419; + color: #fff; +} + +.sidebar-elems .location { + color: #ff7733; +} + +.sidebar-elems .location a { + color: #fff; +} + +.sidebar .version { + border-bottom-color: #424c57; +} + +.sidebar-title { + border-top-color: #5c6773; + border-bottom-color: #5c6773; +} + +.block a:hover { + background: transparent; + color: #ffb44c; +} + +.line-numbers span { color: #5c6773; } +.line-numbers .line-highlighted { + color: #708090; + background-color: rgba(255, 236, 164, 0.06); + padding-right: 4px; + border-right: 1px solid #ffb44c; +} + +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { + border-bottom-color: #5c6773; +} + +.docblock table, .docblock table td, .docblock table th { + border-color: #5c6773; +} + +.content .method .where, +.content .fn .where, +.content .where.fmt-newline { + color: #c5c5c5; +} + +.search-results a:hover { + background-color: #777; +} + +.search-results a:focus { + color: #000 !important; + background-color: #c6afb3; +} +.search-results a { + color: #0096cf; +} +.search-results a span.desc { + color: #c5c5c5; +} + +.content .item-info::before { color: #ccc; } + +.content span.foreigntype, .content a.foreigntype { color: #ef57ff; } +.content span.union, .content a.union { color: #98a01c; } +.content span.constant, .content a.constant, +.content span.static, .content a.static { color: #6380a0; } +.content span.primitive, .content a.primitive { color: #32889b; } +.content span.traitalias, .content a.traitalias { color: #57d399; } +.content span.keyword, .content a.keyword { color: #de5249; } + +.content span.externcrate, .content span.mod, .content a.mod { + color: #acccf9; +} +.content span.struct, .content a.struct { + color: #ffa0a5; +} +.content span.enum, .content a.enum { + color: #99e0c9; +} +.content span.trait, .content a.trait { + color: #39AFD7; +} +.content span.type, .content a.type { + color: #cfbcf5; +} +.content span.fn, .content a.fn, .content span.method, +.content a.method, .content span.tymethod, +.content a.tymethod, .content .fnname { + color: #fdd687; +} +.content span.attr, .content a.attr, .content span.derive, +.content a.derive, .content span.macro, .content a.macro { + color: #a37acc; +} + +pre.rust .comment { color: #788797; } +pre.rust .doccomment { color: #a1ac88; } + +nav:not(.sidebar) { + border-bottom-color: #424c57; +} +nav.main .current { + border-top-color: #5c6773; + border-bottom-color: #5c6773; +} +nav.main .separator { + border: 1px solid #5c6773; +} +a { + color: #c5c5c5; +} + +.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), +.docblock-short a:not(.srclink):not(.test-arrow), .item-info a, +#help a { + color: #39AFD7; +} + +details.rustdoc-toggle > summary.hideme > span, +details.rustdoc-toggle > summary::before, +details.undocumented > summary::before { + color: #999; +} + +#crate-search { + color: #c5c5c5; + background-color: #141920; + box-shadow: 0 0 0 1px #424c57,0 0 0 2px transparent; + border-color: #424c57; +} + +.search-input { + color: #ffffff; + background-color: #141920; + box-shadow: 0 0 0 1px #424c57,0 0 0 2px transparent; + transition: box-shadow 150ms ease-in-out; +} + +#crate-search+.search-input:focus { + box-shadow: 0 0 0 1px #148099,0 0 0 2px transparent; +} + +.search-input:disabled { + background-color: #3e3e3e; +} + +.module-item .stab, +.import-item .stab { + color: #000; +} + +.stab.unstable, +.stab.deprecated, +.stab.portability { + color: #c5c5c5; + background: #314559 !important; + border-style: none !important; + border-radius: 4px; + padding: 3px 6px 3px 6px; +} + +.stab.portability > code { + color: #e6e1cf; + background: none; +} + +#help > div { + background: #14191f; + box-shadow: 0px 6px 20px 0px black; + border: none; + border-radius: 4px; +} + +#help > div > span { + border-bottom-color: #5c6773; +} + +.since { + color: grey; +} + +tr.result span.primitive::after, tr.result span.keyword::after { + color: #788797; +} + +.line-numbers :target { background-color: transparent; } + +/* Code highlighting */ +pre.rust .number, pre.rust .string { color: #b8cc52; } +pre.rust .kw, pre.rust .kw-2, pre.rust .prelude-ty, +pre.rust .bool-val, pre.rust .prelude-val, +pre.rust .op, pre.rust .lifetime { color: #ff7733; } +pre.rust .macro, pre.rust .macro-nonterminal { color: #a37acc; } +pre.rust .question-mark { + color: #ff9011; +} +pre.rust .self { + color: #36a3d9; + font-style: italic; +} +pre.rust .attribute { + color: #e6e1cf; +} +pre.rust .attribute .ident, pre.rust .attribute .op { + color: #e6e1cf; +} + +.example-wrap > pre.line-number { + color: #5c67736e; + border: none; +} + +a.test-arrow { + font-size: 100%; + color: #788797; + border-radius: 4px; + background-color: rgba(57, 175, 215, 0.09); +} + +a.test-arrow:hover { + background-color: rgba(57, 175, 215, 0.368); + color: #c5c5c5; +} + +.toggle-label, +.code-attribute { + color: #999; +} + +:target, :target * { + background: rgba(255, 236, 164, 0.06); +} + +:target { + border-right: 3px solid rgba(255, 180, 76, 0.85); +} + +pre.compile_fail { + border-left: 2px solid rgba(255,0,0,.4); +} + +pre.compile_fail:hover, .information:hover + pre.compile_fail { + border-left: 2px solid #f00; +} + +pre.should_panic { + border-left: 2px solid rgba(255,0,0,.4); +} + +pre.should_panic:hover, .information:hover + pre.should_panic { + border-left: 2px solid #f00; +} + +pre.ignore { + border-left: 2px solid rgba(255,142,0,.6); +} + +pre.ignore:hover, .information:hover + pre.ignore { + border-left: 2px solid #ff9200; +} + +.tooltip.compile_fail { + color: rgba(255,0,0,.5); +} + +.information > .compile_fail:hover { + color: #f00; +} + +.tooltip.should_panic { + color: rgba(255,0,0,.5); +} + +.information > .should_panic:hover { + color: #f00; +} + +.tooltip.ignore { + color: rgba(255,142,0,.6); +} + +.information > .ignore:hover { + color: #ff9200; +} + +.search-failed a { + color: #39AFD7; +} + +.tooltip::after { + background-color: #314559; + color: #c5c5c5; + border: 1px solid #5c6773; +} + +.tooltip::before { + border-color: transparent #314559 transparent transparent; +} + +.notable-traits-tooltiptext { + background-color: #314559; + border-color: #5c6773; +} + +.notable-traits-tooltiptext .notable { + border-bottom-color: #5c6773; +} + +#titles > button.selected { + background-color: #141920 !important; + border-bottom: 1px solid #ffb44c !important; + border-top: none; +} + +#titles > button:not(.selected) { + background-color: transparent !important; + border: none; +} + +#titles > button:hover { + border-bottom: 1px solid rgba(242, 151, 24, 0.3); +} + +#titles > button > div.count { + color: #888; +} + +/* rules that this theme does not need to set, here to satisfy the rule checker */ +/* note that a lot of these are partially set in some way (meaning they are set +individually rather than as a group) */ +/* FIXME: these rules should be at the bottom of the file but currently must be +above the `@media (max-width: 700px)` rules due to a bug in the css checker */ +/* see https://github.com/rust-lang/rust/pull/71237#issuecomment-618170143 */ +.search-input:focus {} +.content span.attr,.content a.attr,.block a.current.attr,.content span.derive,.content a.derive, +.block a.current.derive,.content span.macro,.content a.macro,.block a.current.macro {} +.content span.struct,.content a.struct,.block a.current.struct {} +#titles>button:hover,#titles>button.selected {} +.content span.type,.content a.type,.block a.current.type {} +.content span.union,.content a.union,.block a.current.union {} +pre.rust .lifetime {} +.stab.unstable {} +h2,h3:not(.impl):not(.method):not(.type):not(.tymethod),h4:not(.method):not(.type):not(.tymethod) {} +.content span.enum,.content a.enum,.block a.current.enum {} +.content span.constant,.content a.constant,.block a.current.constant,.content span.static, +.content a.static, .block a.current.static {} +.content span.keyword,.content a.keyword,.block a.current.keyword {} +pre.rust .comment {} +.content span.traitalias,.content a.traitalias,.block a.current.traitalias {} +.content span.fn,.content a.fn,.block a.current.fn,.content span.method,.content a.method, +.block a.current.method,.content span.tymethod,.content a.tymethod,.block a.current.tymethod, +.content .fnname {} +pre.rust .kw {} +pre.rust .self,pre.rust .bool-val,pre.rust .prelude-val,pre.rust .attribute, +pre.rust .attribute .ident {} +.content span.foreigntype,.content a.foreigntype,.block a.current.foreigntype {} +pre.rust .doccomment {} +.stab.deprecated {} +.content a.attr,.content a.derive,.content a.macro {} +.stab.portability {} +.content span.primitive,.content a.primitive,.block a.current.primitive {} +.content span.externcrate,.content span.mod,.content a.mod,.block a.current.mod {} +pre.rust .kw-2,pre.rust .prelude-ty {} +.content span.trait,.content a.trait,.block a.current.trait {} + +.search-results a:focus span {} +a.result-trait:focus {} +a.result-traitalias:focus {} +a.result-mod:focus, +a.result-externcrate:focus {} +a.result-mod:focus {} +a.result-externcrate:focus {} +a.result-enum:focus {} +a.result-struct:focus {} +a.result-union:focus {} +a.result-fn:focus, +a.result-method:focus, +a.result-tymethod:focus {} +a.result-type:focus {} +a.result-foreigntype:focus {} +a.result-attr:focus, +a.result-derive:focus, +a.result-macro:focus {} +a.result-constant:focus, +a.result-static:focus {} +a.result-primitive:focus {} +a.result-keyword:focus {} + +@media (max-width: 700px) { + .sidebar-menu { + background-color: #14191f; + border-bottom-color: #5c6773; + border-right-color: #5c6773; + } + + .sidebar-elems { + background-color: #14191f; + border-right-color: #5c6773; + } + + #sidebar-filler { + background-color: #14191f; + border-bottom-color: #5c6773; + } +} + +kbd { + color: #c5c5c5; + background-color: #314559; + border-color: #5c6773; + border-bottom-color: #5c6773; + box-shadow-color: #c6cbd1; +} + +#theme-picker, #settings-menu, #help-button { + border-color: #5c6773; + background-color: #0f1419; + color: #fff; +} + +#theme-picker > img, #settings-menu > img { + filter: invert(100); +} + +#copy-path { + color: #fff; +} +#copy-path > img { + filter: invert(70%); +} +#copy-path:hover > img { + filter: invert(100%); +} + +#theme-picker:hover, #theme-picker:focus, +#settings-menu:hover, #settings-menu:focus, +#help-button:hover, #help-button:focus { + border-color: #e0e0e0; +} + +#theme-choices { + border-color: #5c6773; + background-color: #0f1419; +} + +#theme-choices > button:not(:first-child) { + border-top-color: #5c6773; +} + +#theme-choices > button:hover, #theme-choices > button:focus { + background-color: rgba(110, 110, 110, 0.33); +} + +@media (max-width: 700px) { + #theme-picker { + background: #0f1419; + } +} + +#all-types { + background-color: #14191f; +} +#all-types:hover { + background-color: rgba(70, 70, 70, 0.33); +} + +.search-results .result-name span.alias { + color: #c5c5c5; +} +.search-results .result-name span.grey { + color: #999; +} + +#sidebar-toggle { + background-color: #14191f; +} +#sidebar-toggle:hover { + background-color: rgba(70, 70, 70, 0.33); +} +#source-sidebar { + background-color: #14191f; +} +#source-sidebar > .title { + color: #fff; + border-bottom-color: #5c6773; +} +div.files > a:hover, div.name:hover { + background-color: #14191f; + color: #ffb44c; +} +div.files > .selected { + background-color: #14191f; + color: #ffb44c; +} +.setting-line > .title { + border-bottom-color: #5c6773; +} +input:checked + .slider { + background-color: #ffb454 !important; +} diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css new file mode 100644 index 00000000000..d9ea28058ad --- /dev/null +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -0,0 +1,479 @@ +body { + background-color: #353535; + color: #ddd; +} + +h1, h2, h3, h4 { + color: #ddd; +} +h1.fqn { + border-bottom-color: #d2d2d2; +} +h2, h3, h4 { + border-bottom-color: #d2d2d2; +} + +.in-band { + background-color: #353535; +} + +.invisible { + background: rgba(0, 0, 0, 0); +} + +.docblock code, .docblock-short code { + background-color: #2A2A2A; +} +pre, .rustdoc.source .example-wrap { + background-color: #2A2A2A; +} + +.sidebar { + background-color: #505050; +} + +.logo-container.rust-logo > img { + filter: drop-shadow(1px 0 0px #fff) + drop-shadow(0 1px 0 #fff) + drop-shadow(-1px 0 0 #fff) + drop-shadow(0 -1px 0 #fff) +} + +/* Improve the scrollbar display on firefox */ +* { + scrollbar-color: rgb(64, 65, 67) #717171; +} +.sidebar { + scrollbar-color: rgba(32,34,37,.6) transparent; +} + +/* Improve the scrollbar display on webkit-based browsers */ +::-webkit-scrollbar-track { + background-color: #717171; +} +::-webkit-scrollbar-thumb { + background-color: rgba(32, 34, 37, .6); +} +.sidebar::-webkit-scrollbar-track { + background-color: #717171; +} +.sidebar::-webkit-scrollbar-thumb { + background-color: rgba(32, 34, 37, .6); +} + +.sidebar .current { + background-color: #333; +} + +.source .sidebar { + background-color: #353535; +} + +.sidebar .location { + border-color: #fff; + background: #575757; + color: #DDD; +} + +.sidebar .version { + border-bottom-color: #DDD; +} + +.sidebar-title { + border-top-color: #777; + border-bottom-color: #777; +} + +.block a:hover { + background: #444; +} + +.line-numbers span { color: #3B91E2; } +.line-numbers .line-highlighted { + background-color: #0a042f !important; +} + +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { + border-bottom-color: #DDD; +} + +.docblock table, .docblock table td, .docblock table th { + border-color: #ddd; +} + +.content .method .where, +.content .fn .where, +.content .where.fmt-newline { + color: #ddd; +} + +.search-results a:hover { + background-color: #777; +} + +.search-results a:focus { + color: #eee !important; + background-color: #616161; +} +.search-results a:focus span { color: #eee !important; } +a.result-trait:focus { background-color: #013191; } +a.result-traitalias:focus { background-color: #013191; } +a.result-mod:focus, +a.result-externcrate:focus { background-color: #afc6e4; } +a.result-mod:focus { background-color: #803a1b; } +a.result-externcrate:focus { background-color: #396bac; } +a.result-enum:focus { background-color: #5b4e68; } +a.result-struct:focus { background-color: #194e9f; } +a.result-union:focus { background-color: #b7bd49; } +a.result-fn:focus, +a.result-method:focus, +a.result-tymethod:focus { background-color: #4950ed; } +a.result-type:focus { background-color: #38902c; } +a.result-foreigntype:focus { background-color: #b200d6; } +a.result-attr:focus, +a.result-derive:focus, +a.result-macro:focus { background-color: #217d1c; } +a.result-constant:focus, +a.result-static:focus { background-color: #0063cc; } +a.result-primitive:focus { background-color: #00708a; } +a.result-keyword:focus { background-color: #884719; } + +.content .item-info::before { color: #ccc; } + +.content span.enum, .content a.enum, .block a.current.enum { color: #82b089; } +.content span.struct, .content a.struct, .block a.current.struct { color: #2dbfb8; } +.content span.type, .content a.type, .block a.current.type { color: #ff7f00; } +.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #dd7de8; } +.content span.attr, .content a.attr, .block a.current.attr, +.content span.derive, .content a.derive, .block a.current.derive, +.content span.macro, .content a.macro, .block a.current.macro { color: #09bd00; } +.content span.union, .content a.union, .block a.current.union { color: #a6ae37; } +.content span.constant, .content a.constant, .block a.current.constant, +.content span.static, .content a.static, .block a.current.static { color: #82a5c9; } +.content span.primitive, .content a.primitive, .block a.current.primitive { color: #43aec7; } +.content span.externcrate, +.content span.mod, .content a.mod, .block a.current.mod { color: #bda000; } +.content span.trait, .content a.trait, .block a.current.trait { color: #b78cf2; } +.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #b397da; } +.content span.fn, .content a.fn, .block a.current.fn, +.content span.method, .content a.method, .block a.current.method, +.content span.tymethod, .content a.tymethod, .block a.current.tymethod, +.content .fnname{ color: #2BAB63; } +.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; } + +pre.rust .comment { color: #8d8d8b; } +pre.rust .doccomment { color: #8ca375; } + +nav:not(.sidebar) { + border-bottom-color: #4e4e4e; +} +nav.main .current { + border-top-color: #eee; + border-bottom-color: #eee; +} +nav.main .separator { + border-color: #eee; +} +a { + color: #ddd; +} + +.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), +.docblock-short a:not(.srclink):not(.test-arrow), .item-info a, +#help a { + color: #D2991D; +} + +a.test-arrow { + color: #dedede; +} + +details.rustdoc-toggle > summary.hideme > span, +details.rustdoc-toggle > summary::before, +details.undocumented > summary::before { + color: #999; +} + +#crate-search { + color: #111; + background-color: #f0f0f0; + border-color: #000; + box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; +} + +.search-input { + color: #111; + background-color: #f0f0f0; + box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; +} + +.search-input:focus { + border-color: #008dfd; +} + +.search-input:disabled { + background-color: #c5c4c4; +} + +#crate-search + .search-input:focus { + box-shadow: 0 0 8px 4px #078dd8; +} + +.module-item .stab, +.import-item .stab { + color: #ddd; +} + +.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; } +.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; } +.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; } +.stab.portability > code { background: none; } + +#help > div { + background: #4d4d4d; + border-color: #bfbfbf; +} + +#help > div > span { + border-bottom-color: #bfbfbf; +} + +#help dt { + border-color: #bfbfbf; + background: rgba(0,0,0,0); +} + +.since { + color: grey; +} + +tr.result span.primitive::after, tr.result span.keyword::after { + color: #ddd; +} + +.line-numbers :target { background-color: transparent; } + +/* Code highlighting */ +pre.rust .kw { color: #ab8ac1; } +pre.rust .kw-2, pre.rust .prelude-ty { color: #769acb; } +pre.rust .number, pre.rust .string { color: #83a300; } +pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val, +pre.rust .attribute, pre.rust .attribute .ident { color: #ee6868; } +pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; } +pre.rust .lifetime { color: #d97f26; } +pre.rust .question-mark { + color: #ff9011; +} + +.example-wrap > pre.line-number { + border-color: #4a4949; +} + +a.test-arrow { + background-color: rgba(78, 139, 202, 0.2); +} + +a.test-arrow:hover{ + background-color: #4e8bca; +} + +.toggle-label, +.code-attribute { + color: #999; +} + +:target, :target * { + background-color: #494a3d; +} + +:target { + border-right: 3px solid #bb7410; +} + +pre.compile_fail { + border-left: 2px solid rgba(255,0,0,.8); +} + +pre.compile_fail:hover, .information:hover + pre.compile_fail { + border-left: 2px solid #f00; +} + +pre.should_panic { + border-left: 2px solid rgba(255,0,0,.8); +} + +pre.should_panic:hover, .information:hover + pre.should_panic { + border-left: 2px solid #f00; +} + +pre.ignore { + border-left: 2px solid rgba(255,142,0,.6); +} + +pre.ignore:hover, .information:hover + pre.ignore { + border-left: 2px solid #ff9200; +} + +.tooltip.compile_fail { + color: rgba(255,0,0,.8); +} + +.information > .compile_fail:hover { + color: #f00; +} + +.tooltip.should_panic { + color: rgba(255,0,0,.8); +} + +.information > .should_panic:hover { + color: #f00; +} + +.tooltip.ignore { + color: rgba(255,142,0,.6); +} + +.information > .ignore:hover { + color: #ff9200; +} + +.search-failed a { + color: #0089ff; +} + +.tooltip::after { + background-color: #000; + color: #fff; + border-color: #000; +} + +.tooltip::before { + border-color: transparent black transparent transparent; +} + +.notable-traits-tooltiptext { + background-color: #111; + border-color: #777; +} + +.notable-traits-tooltiptext .notable { + border-bottom-color: #d2d2d2; +} + +#titles > button:not(.selected) { + background-color: #252525; + border-top-color: #252525; +} + +#titles > button:hover, #titles > button.selected { + border-top-color: #0089ff; + background-color: #353535; +} + +#titles > button > div.count { + color: #888; +} + +@media (max-width: 700px) { + .sidebar-menu { + background-color: #505050; + border-bottom-color: #e0e0e0; + border-right-color: #e0e0e0; + } + + .sidebar-elems { + background-color: #505050; + border-right-color: #000; + } + + #sidebar-filler { + background-color: #505050; + border-bottom-color: #e0e0e0; + } +} + +kbd { + color: #000; + background-color: #fafbfc; + border-color: #d1d5da; + border-bottom-color: #c6cbd1; + box-shadow-color: #c6cbd1; +} + +#theme-picker, #settings-menu, #help-button { + border-color: #e0e0e0; + background: #f0f0f0; + color: #000; +} + +#theme-picker:hover, #theme-picker:focus, +#settings-menu:hover, #settings-menu:focus, +#help-button:hover, #help-button:focus { + border-color: #ffb900; +} + +#copy-path { + color: #999; +} +#copy-path > img { + filter: invert(50%); +} +#copy-path:hover > img { + filter: invert(65%); +} + +#theme-choices { + border-color: #e0e0e0; + background-color: #353535; +} + +#theme-choices > button:not(:first-child) { + border-top-color: #e0e0e0; +} + +#theme-choices > button:hover, #theme-choices > button:focus { + background-color: #4e4e4e; +} + +@media (max-width: 700px) { + #theme-picker { + background: #f0f0f0; + } +} + +#all-types { + background-color: #505050; +} +#all-types:hover { + background-color: #606060; +} + +.search-results .result-name span.alias { + color: #fff; +} +.search-results .result-name span.grey { + color: #ccc; +} + +#sidebar-toggle { + background-color: #565656; +} +#sidebar-toggle:hover { + background-color: #676767; +} +#source-sidebar { + background-color: #565656; +} +#source-sidebar > .title { + border-bottom-color: #ccc; +} +div.files > a:hover, div.name:hover { + background-color: #444; +} +div.files > .selected { + background-color: #333; +} +.setting-line > .title { + border-bottom-color: #ddd; +} diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css new file mode 100644 index 00000000000..6785b79ffda --- /dev/null +++ b/src/librustdoc/html/static/css/themes/light.css @@ -0,0 +1,469 @@ +/* General structure and fonts */ + +body { + background-color: white; + color: black; +} + +h1, h2, h3, h4 { + color: black; +} +h1.fqn { + border-bottom-color: #D5D5D5; +} +h2, h3, h4 { + border-bottom-color: #DDDDDD; +} + +.in-band { + background-color: white; +} + +.invisible { + background: rgba(0, 0, 0, 0); +} + +.docblock code, .docblock-short code { + background-color: #F5F5F5; +} +pre, .rustdoc.source .example-wrap { + background-color: #F5F5F5; +} + +.sidebar { + background-color: #F1F1F1; +} + +/* Improve the scrollbar display on firefox */ +* { + scrollbar-color: rgba(36, 37, 39, 0.6) #e6e6e6; +} + +.sidebar { + scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9; +} + +.logo-container.rust-logo > img { + /* No need for a border in here! */ +} + +/* Improve the scrollbar display on webkit-based browsers */ +::-webkit-scrollbar-track { + background-color: #ecebeb; +} +::-webkit-scrollbar-thumb { + background-color: rgba(36, 37, 39, 0.6); +} +.sidebar::-webkit-scrollbar-track { + background-color: #dcdcdc; +} +.sidebar::-webkit-scrollbar-thumb { + background-color: rgba(36, 37, 39, 0.6); +} + +.sidebar .current { + background-color: #fff; +} + +.source .sidebar { + background-color: #fff; +} + +.sidebar .location { + border-color: #000; + background-color: #fff; + color: #333; +} + +.sidebar .version { + border-bottom-color: #DDD; +} + +.sidebar-title { + border-top-color: #777; + border-bottom-color: #777; +} + +.block a:hover { + background: #F5F5F5; +} + +.line-numbers span { color: #c67e2d; } +.line-numbers .line-highlighted { + background-color: #f6fdb0 !important; +} + +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { + border-bottom-color: #ddd; +} + +.docblock table, .docblock table td, .docblock table th { + border-color: #ddd; +} + +.content .method .where, +.content .fn .where, +.content .where.fmt-newline { + color: #4E4C4C; +} + +.search-results a:hover { + background-color: #ddd; +} + +.search-results a:focus { + color: #000 !important; + background-color: #ccc; +} +.search-results a:focus span { color: #000 !important; } +a.result-trait:focus { background-color: #c7b6ff; } +a.result-traitalias:focus { background-color: #c7b6ff; } +a.result-mod:focus, +a.result-externcrate:focus { background-color: #afc6e4; } +a.result-enum:focus { background-color: #b4d1b9; } +a.result-struct:focus { background-color: #e7b1a0; } +a.result-union:focus { background-color: #b7bd49; } +a.result-fn:focus, +a.result-method:focus, +a.result-tymethod:focus { background-color: #c6afb3; } +a.result-type:focus { background-color: #ffc891; } +a.result-foreigntype:focus { background-color: #f5c4ff; } +a.result-attr:focus, +a.result-derive:focus, +a.result-macro:focus { background-color: #8ce488; } +a.result-constant:focus, +a.result-static:focus { background-color: #c3e0ff; } +a.result-primitive:focus { background-color: #9aecff; } +a.result-keyword:focus { background-color: #f99650; } + +.content .item-info::before { color: #ccc; } + +.content span.enum, .content a.enum, .block a.current.enum { color: #508157; } +.content span.struct, .content a.struct, .block a.current.struct { color: #ad448e; } +.content span.type, .content a.type, .block a.current.type { color: #ba5d00; } +.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #cd00e2; } +.content span.attr, .content a.attr, .block a.current.attr, +.content span.derive, .content a.derive, .block a.current.derive, +.content span.macro, .content a.macro, .block a.current.macro { color: #068000; } +.content span.union, .content a.union, .block a.current.union { color: #767b27; } +.content span.constant, .content a.constant, .block a.current.constant, +.content span.static, .content a.static, .block a.current.static { color: #546e8a; } +.content span.primitive, .content a.primitive, .block a.current.primitive { color: #2c8093; } +.content span.externcrate, +.content span.mod, .content a.mod, .block a.current.mod { color: #4d76ae; } +.content span.trait, .content a.trait, .block a.current.trait { color: #7c5af3; } +.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #6841f1; } +.content span.fn, .content a.fn, .block a.current.fn, +.content span.method, .content a.method, .block a.current.method, +.content span.tymethod, .content a.tymethod, .block a.current.tymethod, +.content .fnname { color: #9a6e31; } +.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; } + +nav:not(.sidebar) { + border-bottom-color: #e0e0e0; +} +nav.main .current { + border-top-color: #000; + border-bottom-color: #000; +} +nav.main .separator { + border: 1px solid #000; +} +a { + color: #000; +} + +.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), +.docblock-short a:not(.srclink):not(.test-arrow), .item-info a, +#help a { + color: #3873AD; +} + +a.test-arrow { + color: #f5f5f5; +} + +details.rustdoc-toggle > summary.hideme > span, +details.rustdoc-toggle > summary::before, +details.undocumented > summary::before { + color: #999; +} + +#crate-search { + color: #555; + background-color: white; + border-color: #e0e0e0; + box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; +} + +.search-input { + color: #555; + background-color: white; + box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; +} + +.search-input:focus { + border-color: #66afe9; +} + +.search-input:disabled { + background-color: #e6e6e6; +} + +#crate-search + .search-input:focus { + box-shadow: 0 0 8px #078dd8; +} + +.module-item .stab, +.import-item .stab { + color: #000; +} + +.stab.unstable { background: #FFF5D6; border-color: #FFC600; } +.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; } +.stab.portability { background: #F3DFFF; border-color: #b07bdb; } +.stab.portability > code { background: none; } + +#help > div { + background: #e9e9e9; + border-color: #bfbfbf; +} + +#help > div > span { + border-bottom-color: #bfbfbf; +} + +.since { + color: grey; +} + +tr.result span.primitive::after, tr.result span.keyword::after { + color: black; +} + +.line-numbers :target { background-color: transparent; } + +/* Code highlighting */ +pre.rust .kw { color: #8959A8; } +pre.rust .kw-2, pre.rust .prelude-ty { color: #4271AE; } +pre.rust .number, pre.rust .string { color: #718C00; } +pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val, +pre.rust .attribute, pre.rust .attribute .ident { color: #C82829; } +pre.rust .comment { color: #8E908C; } +pre.rust .doccomment { color: #4D4D4C; } +pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; } +pre.rust .lifetime { color: #B76514; } +pre.rust .question-mark { + color: #ff9011; +} + +.example-wrap > pre.line-number { + border-color: #c7c7c7; +} + +a.test-arrow { + background-color: rgba(78, 139, 202, 0.2); +} + +a.test-arrow:hover{ + background-color: #4e8bca; +} + +.toggle-label, +.code-attribute { + color: #999; +} + +:target, :target * { + background: #FDFFD3; +} + +:target { + border-right: 3px solid #ffb44c; +} + +pre.compile_fail { + border-left: 2px solid rgba(255,0,0,.5); +} + +pre.compile_fail:hover, .information:hover + pre.compile_fail { + border-left: 2px solid #f00; +} + +pre.should_panic { + border-left: 2px solid rgba(255,0,0,.5); +} + +pre.should_panic:hover, .information:hover + pre.should_panic { + border-left: 2px solid #f00; +} + +pre.ignore { + border-left: 2px solid rgba(255,142,0,.6); +} + +pre.ignore:hover, .information:hover + pre.ignore { + border-left: 2px solid #ff9200; +} + +.tooltip.compile_fail { + color: rgba(255,0,0,.5); +} + +.information > .compile_fail:hover { + color: #f00; +} + +.tooltip.should_panic { + color: rgba(255,0,0,.5); +} + +.information > .should_panic:hover { + color: #f00; +} + +.tooltip.ignore { + color: rgba(255,142,0,.6); +} + +.information > .ignore:hover { + color: #ff9200; +} + +.search-failed a { + color: #0089ff; +} + +.tooltip::after { + background-color: #000; + color: #fff; +} + +.tooltip::before { + border-color: transparent black transparent transparent; +} + +.notable-traits-tooltiptext { + background-color: #eee; + border-color: #999; +} + +.notable-traits-tooltiptext .notable { + border-bottom-color: #DDDDDD; +} + +#titles > button:not(.selected) { + background-color: #e6e6e6; + border-top-color: #e6e6e6; +} + +#titles > button:hover, #titles > button.selected { + background-color: #ffffff; + border-top-color: #0089ff; +} + +#titles > button > div.count { + color: #888; +} + +@media (max-width: 700px) { + .sidebar-menu { + background-color: #F1F1F1; + border-bottom-color: #e0e0e0; + border-right-color: #e0e0e0; + } + + .sidebar-elems { + background-color: #F1F1F1; + border-right-color: #000; + } + + #sidebar-filler { + background-color: #F1F1F1; + border-bottom-color: #e0e0e0; + } +} + +kbd { + color: #000; + background-color: #fafbfc; + border-color: #d1d5da; + border-bottom-color: #c6cbd1; + box-shadow-color: #c6cbd1; +} + +#theme-picker, #settings-menu, #help-button { + border-color: #e0e0e0; + background-color: #fff; +} + +#theme-picker:hover, #theme-picker:focus, +#settings-menu:hover, #settings-menu:focus, +#help-button:hover, #help-button:focus { + border-color: #717171; +} + +#copy-path { + color: #999; +} +#copy-path > img { + filter: invert(50%); +} +#copy-path:hover > img { + filter: invert(35%); +} + +#theme-choices { + border-color: #ccc; + background-color: #fff; +} + +#theme-choices > button:not(:first-child) { + border-top-color: #e0e0e0; +} + +#theme-choices > button:hover, #theme-choices > button:focus { + background-color: #eee; +} + +@media (max-width: 700px) { + #theme-picker { + background: #fff; + } +} + +#all-types { + background-color: #fff; +} +#all-types:hover { + background-color: #f9f9f9; +} + +.search-results .result-name span.alias { + color: #000; +} +.search-results .result-name span.grey { + color: #999; +} + +#sidebar-toggle { + background-color: #F1F1F1; +} +#sidebar-toggle:hover { + background-color: #E0E0E0; +} +#source-sidebar { + background-color: #F1F1F1; +} +#source-sidebar > .title { + border-bottom-color: #ccc; +} +div.files > a:hover, div.name:hover { + background-color: #E0E0E0; +} +div.files > .selected { + background-color: #fff; +} +.setting-line > .title { + border-bottom-color: #D5D5D5; +} diff --git a/src/librustdoc/html/static/down-arrow.svg b/src/librustdoc/html/static/down-arrow.svg deleted file mode 100644 index 35437e77a71..00000000000 --- a/src/librustdoc/html/static/down-arrow.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/librustdoc/html/static/favicon-16x16.png b/src/librustdoc/html/static/favicon-16x16.png deleted file mode 100644 index 7cfe6c13550..00000000000 Binary files a/src/librustdoc/html/static/favicon-16x16.png and /dev/null differ diff --git a/src/librustdoc/html/static/favicon-32x32.png b/src/librustdoc/html/static/favicon-32x32.png deleted file mode 100644 index 5109c1de8be..00000000000 Binary files a/src/librustdoc/html/static/favicon-32x32.png and /dev/null differ diff --git a/src/librustdoc/html/static/favicon.svg b/src/librustdoc/html/static/favicon.svg deleted file mode 100644 index 8b34b511989..00000000000 --- a/src/librustdoc/html/static/favicon.svg +++ /dev/null @@ -1,24 +0,0 @@ - - - - - diff --git a/src/librustdoc/html/static/fonts/FiraSans-LICENSE.txt b/src/librustdoc/html/static/fonts/FiraSans-LICENSE.txt new file mode 100644 index 00000000000..ff9afab064a --- /dev/null +++ b/src/librustdoc/html/static/fonts/FiraSans-LICENSE.txt @@ -0,0 +1,94 @@ +Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A. +with Reserved Font Name < Fira >, + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/fonts/FiraSans-Medium.woff b/src/librustdoc/html/static/fonts/FiraSans-Medium.woff new file mode 100644 index 00000000000..7d742c5fb7d Binary files /dev/null and b/src/librustdoc/html/static/fonts/FiraSans-Medium.woff differ diff --git a/src/librustdoc/html/static/fonts/FiraSans-Medium.woff2 b/src/librustdoc/html/static/fonts/FiraSans-Medium.woff2 new file mode 100644 index 00000000000..7a1e5fc548e Binary files /dev/null and b/src/librustdoc/html/static/fonts/FiraSans-Medium.woff2 differ diff --git a/src/librustdoc/html/static/fonts/FiraSans-Regular.woff b/src/librustdoc/html/static/fonts/FiraSans-Regular.woff new file mode 100644 index 00000000000..d8e0363f4e1 Binary files /dev/null and b/src/librustdoc/html/static/fonts/FiraSans-Regular.woff differ diff --git a/src/librustdoc/html/static/fonts/FiraSans-Regular.woff2 b/src/librustdoc/html/static/fonts/FiraSans-Regular.woff2 new file mode 100644 index 00000000000..e766e06ccb0 Binary files /dev/null and b/src/librustdoc/html/static/fonts/FiraSans-Regular.woff2 differ diff --git a/src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff b/src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff new file mode 100644 index 00000000000..8d68f2febdd Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff differ diff --git a/src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff2 b/src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff2 new file mode 100644 index 00000000000..462c34efcd9 Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceCodePro-It.ttf.woff2 differ diff --git a/src/librustdoc/html/static/fonts/SourceCodePro-LICENSE.txt b/src/librustdoc/html/static/fonts/SourceCodePro-LICENSE.txt new file mode 100644 index 00000000000..07542572e33 --- /dev/null +++ b/src/librustdoc/html/static/fonts/SourceCodePro-LICENSE.txt @@ -0,0 +1,93 @@ +Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff b/src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff new file mode 100644 index 00000000000..7be076e1fca Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff differ diff --git a/src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff2 b/src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff2 new file mode 100644 index 00000000000..10b558e0b69 Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceCodePro-Regular.ttf.woff2 differ diff --git a/src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff b/src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff new file mode 100644 index 00000000000..61bc67b8025 Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff differ diff --git a/src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff2 b/src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff2 new file mode 100644 index 00000000000..5ec64eef0ec Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceCodePro-Semibold.ttf.woff2 differ diff --git a/src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff b/src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff new file mode 100644 index 00000000000..8ad41888e6e Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff differ diff --git a/src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff2 b/src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff2 new file mode 100644 index 00000000000..db57d21455c Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceSerif4-Bold.ttf.woff2 differ diff --git a/src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff b/src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff new file mode 100644 index 00000000000..2a34b5c42a8 Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff differ diff --git a/src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff2 b/src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff2 new file mode 100644 index 00000000000..1cbc021a3aa Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceSerif4-It.ttf.woff2 differ diff --git a/src/librustdoc/html/static/fonts/SourceSerif4-LICENSE.md b/src/librustdoc/html/static/fonts/SourceSerif4-LICENSE.md new file mode 100644 index 00000000000..68ea1892406 --- /dev/null +++ b/src/librustdoc/html/static/fonts/SourceSerif4-LICENSE.md @@ -0,0 +1,93 @@ +Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff b/src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff new file mode 100644 index 00000000000..45a5521ab0c Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff differ diff --git a/src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff2 b/src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff2 new file mode 100644 index 00000000000..2db73fe2b49 Binary files /dev/null and b/src/librustdoc/html/static/fonts/SourceSerif4-Regular.ttf.woff2 differ diff --git a/src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular-LICENSE.txt b/src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular-LICENSE.txt new file mode 100644 index 00000000000..922d5fdc18d --- /dev/null +++ b/src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular-LICENSE.txt @@ -0,0 +1,93 @@ +Copyright 2014, 2015 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular.woff b/src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular.woff new file mode 100644 index 00000000000..01d6b6b5466 Binary files /dev/null and b/src/librustdoc/html/static/fonts/noto-sans-kr-v13-korean-regular.woff differ diff --git a/src/librustdoc/html/static/images/brush.svg b/src/librustdoc/html/static/images/brush.svg new file mode 100644 index 00000000000..ea266e856a9 --- /dev/null +++ b/src/librustdoc/html/static/images/brush.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/librustdoc/html/static/images/clipboard.svg b/src/librustdoc/html/static/images/clipboard.svg new file mode 100644 index 00000000000..8adbd996304 --- /dev/null +++ b/src/librustdoc/html/static/images/clipboard.svg @@ -0,0 +1 @@ + diff --git a/src/librustdoc/html/static/images/down-arrow.svg b/src/librustdoc/html/static/images/down-arrow.svg new file mode 100644 index 00000000000..35437e77a71 --- /dev/null +++ b/src/librustdoc/html/static/images/down-arrow.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/librustdoc/html/static/images/favicon-16x16.png b/src/librustdoc/html/static/images/favicon-16x16.png new file mode 100644 index 00000000000..7cfe6c13550 Binary files /dev/null and b/src/librustdoc/html/static/images/favicon-16x16.png differ diff --git a/src/librustdoc/html/static/images/favicon-32x32.png b/src/librustdoc/html/static/images/favicon-32x32.png new file mode 100644 index 00000000000..5109c1de8be Binary files /dev/null and b/src/librustdoc/html/static/images/favicon-32x32.png differ diff --git a/src/librustdoc/html/static/images/favicon.svg b/src/librustdoc/html/static/images/favicon.svg new file mode 100644 index 00000000000..8b34b511989 --- /dev/null +++ b/src/librustdoc/html/static/images/favicon.svg @@ -0,0 +1,24 @@ + + + + + diff --git a/src/librustdoc/html/static/images/rust-logo.png b/src/librustdoc/html/static/images/rust-logo.png new file mode 100644 index 00000000000..74b4bd69504 Binary files /dev/null and b/src/librustdoc/html/static/images/rust-logo.png differ diff --git a/src/librustdoc/html/static/images/wheel.svg b/src/librustdoc/html/static/images/wheel.svg new file mode 100644 index 00000000000..01da3b24c7c --- /dev/null +++ b/src/librustdoc/html/static/images/wheel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js new file mode 100644 index 00000000000..98128878999 --- /dev/null +++ b/src/librustdoc/html/static/js/main.js @@ -0,0 +1,1018 @@ +// Local js definitions: +/* global addClass, getSettingValue, hasClass, searchState */ +/* global onEach, onEachLazy, removeClass */ +/* global switchTheme, useSystemTheme */ + +if (!String.prototype.startsWith) { + String.prototype.startsWith = function(searchString, position) { + position = position || 0; + return this.indexOf(searchString, position) === position; + }; +} +if (!String.prototype.endsWith) { + String.prototype.endsWith = function(suffix, length) { + var l = length || this.length; + return this.indexOf(suffix, l - suffix.length) !== -1; + }; +} + +if (!DOMTokenList.prototype.add) { + DOMTokenList.prototype.add = function(className) { + if (className && !hasClass(this, className)) { + if (this.className && this.className.length > 0) { + this.className += " " + className; + } else { + this.className = className; + } + } + }; +} + +if (!DOMTokenList.prototype.remove) { + DOMTokenList.prototype.remove = function(className) { + if (className && this.className) { + this.className = (" " + this.className + " ").replace(" " + className + " ", " ") + .trim(); + } + }; +} + +(function () { + var rustdocVars = document.getElementById("rustdoc-vars"); + if (rustdocVars) { + window.rootPath = rustdocVars.attributes["data-root-path"].value; + window.currentCrate = rustdocVars.attributes["data-current-crate"].value; + window.searchJS = rustdocVars.attributes["data-search-js"].value; + window.searchIndexJS = rustdocVars.attributes["data-search-index-js"].value; + } + var sidebarVars = document.getElementById("sidebar-vars"); + if (sidebarVars) { + window.sidebarCurrent = { + name: sidebarVars.attributes["data-name"].value, + ty: sidebarVars.attributes["data-ty"].value, + relpath: sidebarVars.attributes["data-relpath"].value, + }; + } +}()); + +// Gets the human-readable string for the virtual-key code of the +// given KeyboardEvent, ev. +// +// This function is meant as a polyfill for KeyboardEvent#key, +// since it is not supported in IE 11 or Chrome for Android. We also test for +// KeyboardEvent#keyCode because the handleShortcut handler is +// also registered for the keydown event, because Blink doesn't fire +// keypress on hitting the Escape key. +// +// So I guess you could say things are getting pretty interoperable. +function getVirtualKey(ev) { + if ("key" in ev && typeof ev.key != "undefined") { + return ev.key; + } + + var c = ev.charCode || ev.keyCode; + if (c == 27) { + return "Escape"; + } + return String.fromCharCode(c); +} + +var THEME_PICKER_ELEMENT_ID = "theme-picker"; +var THEMES_ELEMENT_ID = "theme-choices"; + +function getThemesElement() { + return document.getElementById(THEMES_ELEMENT_ID); +} + +function getThemePickerElement() { + return document.getElementById(THEME_PICKER_ELEMENT_ID); +} + +// Returns the current URL without any query parameter or hash. +function getNakedUrl() { + return window.location.href.split("?")[0].split("#")[0]; +} + +function showThemeButtonState() { + var themePicker = getThemePickerElement(); + var themeChoices = getThemesElement(); + + themeChoices.style.display = "block"; + themePicker.style.borderBottomRightRadius = "0"; + themePicker.style.borderBottomLeftRadius = "0"; +} + +function hideThemeButtonState() { + var themePicker = getThemePickerElement(); + var themeChoices = getThemesElement(); + + themeChoices.style.display = "none"; + themePicker.style.borderBottomRightRadius = "3px"; + themePicker.style.borderBottomLeftRadius = "3px"; +} + +// Set up the theme picker list. +(function () { + var themeChoices = getThemesElement(); + var themePicker = getThemePickerElement(); + var availableThemes/* INSERT THEMES HERE */; + + function switchThemeButtonState() { + if (themeChoices.style.display === "block") { + hideThemeButtonState(); + } else { + showThemeButtonState(); + } + } + + function handleThemeButtonsBlur(e) { + var active = document.activeElement; + var related = e.relatedTarget; + + if (active.id !== THEME_PICKER_ELEMENT_ID && + (!active.parentNode || active.parentNode.id !== THEMES_ELEMENT_ID) && + (!related || + (related.id !== THEME_PICKER_ELEMENT_ID && + (!related.parentNode || related.parentNode.id !== THEMES_ELEMENT_ID)))) { + hideThemeButtonState(); + } + } + + themePicker.onclick = switchThemeButtonState; + themePicker.onblur = handleThemeButtonsBlur; + availableThemes.forEach(function(item) { + var but = document.createElement("button"); + but.textContent = item; + but.onclick = function() { + switchTheme(window.currentTheme, window.mainTheme, item, true); + useSystemTheme(false); + }; + but.onblur = handleThemeButtonsBlur; + themeChoices.appendChild(but); + }); +}()); + +(function() { + "use strict"; + + window.searchState = { + loadingText: "Loading search results...", + input: document.getElementsByClassName("search-input")[0], + outputElement: function() { + return document.getElementById("search"); + }, + title: document.title, + titleBeforeSearch: document.title, + timeout: null, + // On the search screen, so you remain on the last tab you opened. + // + // 0 for "In Names" + // 1 for "In Parameters" + // 2 for "In Return Types" + currentTab: 0, + // tab and back preserves the element that was focused. + focusedByTab: [null, null, null], + clearInputTimeout: function() { + if (searchState.timeout !== null) { + clearTimeout(searchState.timeout); + searchState.timeout = null; + } + }, + // Sets the focus on the search bar at the top of the page + focus: function() { + searchState.input.focus(); + }, + // Removes the focus from the search bar. + defocus: function() { + searchState.input.blur(); + }, + showResults: function(search) { + if (search === null || typeof search === 'undefined') { + search = searchState.outputElement(); + } + addClass(main, "hidden"); + removeClass(search, "hidden"); + searchState.mouseMovedAfterSearch = false; + document.title = searchState.title; + }, + hideResults: function(search) { + if (search === null || typeof search === 'undefined') { + search = searchState.outputElement(); + } + addClass(search, "hidden"); + removeClass(main, "hidden"); + document.title = searchState.titleBeforeSearch; + // We also remove the query parameter from the URL. + if (searchState.browserSupportsHistoryApi()) { + history.replaceState("", window.currentCrate + " - Rust", + getNakedUrl() + window.location.hash); + } + }, + getQueryStringParams: function() { + var params = {}; + window.location.search.substring(1).split("&"). + map(function(s) { + var pair = s.split("="); + params[decodeURIComponent(pair[0])] = + typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]); + }); + return params; + }, + putBackSearch: function(search_input) { + var search = searchState.outputElement(); + if (search_input.value !== "" && hasClass(search, "hidden")) { + searchState.showResults(search); + if (searchState.browserSupportsHistoryApi()) { + var extra = "?search=" + encodeURIComponent(search_input.value); + history.replaceState(search_input.value, "", + getNakedUrl() + extra + window.location.hash); + } + document.title = searchState.title; + } + }, + browserSupportsHistoryApi: function() { + return window.history && typeof window.history.pushState === "function"; + }, + setup: function() { + var search_input = searchState.input; + if (!searchState.input) { + return; + } + function loadScript(url) { + var script = document.createElement('script'); + script.src = url; + document.head.append(script); + } + + var searchLoaded = false; + function loadSearch() { + if (!searchLoaded) { + searchLoaded = true; + loadScript(window.searchJS); + loadScript(window.searchIndexJS); + } + } + + search_input.addEventListener("focus", function() { + searchState.putBackSearch(this); + search_input.origPlaceholder = searchState.input.placeholder; + search_input.placeholder = "Type your search here."; + loadSearch(); + }); + search_input.addEventListener("blur", function() { + search_input.placeholder = searchState.input.origPlaceholder; + }); + + search_input.removeAttribute('disabled'); + + // `crates{version}.js` should always be loaded before this script, so we can use it + // safely. + searchState.addCrateDropdown(window.ALL_CRATES); + var params = searchState.getQueryStringParams(); + if (params.search !== undefined) { + var search = searchState.outputElement(); + search.innerHTML = "

" + + searchState.loadingText + "

"; + searchState.showResults(search); + loadSearch(); + } + }, + addCrateDropdown: function(crates) { + var elem = document.getElementById("crate-search"); + + if (!elem) { + return; + } + var savedCrate = getSettingValue("saved-filter-crate"); + for (var i = 0, len = crates.length; i < len; ++i) { + var option = document.createElement("option"); + option.value = crates[i]; + option.innerText = crates[i]; + elem.appendChild(option); + // Set the crate filter from saved storage, if the current page has the saved crate + // filter. + // + // If not, ignore the crate filter -- we want to support filtering for crates on + // sites like doc.rust-lang.org where the crates may differ from page to page while + // on the + // same domain. + if (crates[i] === savedCrate) { + elem.value = savedCrate; + } + } + }, + }; + + function getPageId() { + if (window.location.hash) { + var tmp = window.location.hash.replace(/^#/, ""); + if (tmp.length > 0) { + return tmp; + } + } + return null; + } + + function showSidebar() { + var elems = document.getElementsByClassName("sidebar-elems")[0]; + if (elems) { + addClass(elems, "show-it"); + } + var sidebar = document.getElementsByClassName("sidebar")[0]; + if (sidebar) { + addClass(sidebar, "mobile"); + var filler = document.getElementById("sidebar-filler"); + if (!filler) { + var div = document.createElement("div"); + div.id = "sidebar-filler"; + sidebar.appendChild(div); + } + } + } + + function hideSidebar() { + var elems = document.getElementsByClassName("sidebar-elems")[0]; + if (elems) { + removeClass(elems, "show-it"); + } + var sidebar = document.getElementsByClassName("sidebar")[0]; + removeClass(sidebar, "mobile"); + var filler = document.getElementById("sidebar-filler"); + if (filler) { + filler.remove(); + } + document.getElementsByTagName("body")[0].style.marginTop = ""; + } + + var toggleAllDocsId = "toggle-all-docs"; + var main = document.getElementById("main"); + var savedHash = ""; + + function handleHashes(ev) { + var elem; + var search = searchState.outputElement(); + if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) { + // This block occurs when clicking on an element in the navbar while + // in a search. + searchState.hideResults(search); + var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1); + if (searchState.browserSupportsHistoryApi()) { + // `window.location.search`` contains all the query parameters, not just `search`. + history.replaceState(hash, "", + getNakedUrl() + window.location.search + "#" + hash); + } + elem = document.getElementById(hash); + if (elem) { + elem.scrollIntoView(); + } + } + // This part is used in case an element is not visible. + if (savedHash !== window.location.hash) { + savedHash = window.location.hash; + if (savedHash.length === 0) { + return; + } + expandSection(savedHash.slice(1)); // we remove the '#' + } + } + + function onHashChange(ev) { + // If we're in mobile mode, we should hide the sidebar in any case. + hideSidebar(); + handleHashes(ev); + } + + function openParentDetails(elem) { + while (elem) { + if (elem.tagName === "DETAILS") { + elem.open = true; + } + elem = elem.parentNode; + } + } + + function expandSection(id) { + openParentDetails(document.getElementById(id)); + } + + function getHelpElement(build) { + if (build) { + buildHelperPopup(); + } + return document.getElementById("help"); + } + + function displayHelp(display, ev, help) { + if (display) { + help = help ? help : getHelpElement(true); + if (hasClass(help, "hidden")) { + ev.preventDefault(); + removeClass(help, "hidden"); + addClass(document.body, "blur"); + } + } else { + // No need to build the help popup if we want to hide it in case it hasn't been + // built yet... + help = help ? help : getHelpElement(false); + if (help && !hasClass(help, "hidden")) { + ev.preventDefault(); + addClass(help, "hidden"); + removeClass(document.body, "blur"); + } + } + } + + function handleEscape(ev) { + var help = getHelpElement(false); + var search = searchState.outputElement(); + if (help && !hasClass(help, "hidden")) { + displayHelp(false, ev, help); + } else if (search && !hasClass(search, "hidden")) { + searchState.clearInputTimeout(); + ev.preventDefault(); + searchState.hideResults(search); + } + searchState.defocus(); + hideThemeButtonState(); + } + + var disableShortcuts = getSettingValue("disable-shortcuts") === "true"; + function handleShortcut(ev) { + // Don't interfere with browser shortcuts + if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) { + return; + } + + if (document.activeElement.tagName === "INPUT") { + switch (getVirtualKey(ev)) { + case "Escape": + handleEscape(ev); + break; + } + } else { + switch (getVirtualKey(ev)) { + case "Escape": + handleEscape(ev); + break; + + case "s": + case "S": + displayHelp(false, ev); + ev.preventDefault(); + searchState.focus(); + break; + + case "+": + case "-": + ev.preventDefault(); + toggleAllDocs(); + break; + + case "?": + displayHelp(true, ev); + break; + + case "t": + case "T": + displayHelp(false, ev); + ev.preventDefault(); + var themePicker = getThemePickerElement(); + themePicker.click(); + themePicker.focus(); + break; + + default: + if (getThemePickerElement().parentNode.contains(ev.target)) { + handleThemeKeyDown(ev); + } + } + } + } + + function handleThemeKeyDown(ev) { + var active = document.activeElement; + var themes = getThemesElement(); + switch (getVirtualKey(ev)) { + case "ArrowUp": + ev.preventDefault(); + if (active.previousElementSibling && ev.target.id !== THEME_PICKER_ELEMENT_ID) { + active.previousElementSibling.focus(); + } else { + showThemeButtonState(); + themes.lastElementChild.focus(); + } + break; + case "ArrowDown": + ev.preventDefault(); + if (active.nextElementSibling && ev.target.id !== THEME_PICKER_ELEMENT_ID) { + active.nextElementSibling.focus(); + } else { + showThemeButtonState(); + themes.firstElementChild.focus(); + } + break; + case "Enter": + case "Return": + case "Space": + if (ev.target.id === THEME_PICKER_ELEMENT_ID && themes.style.display === "none") { + ev.preventDefault(); + showThemeButtonState(); + themes.firstElementChild.focus(); + } + break; + case "Home": + ev.preventDefault(); + themes.firstElementChild.focus(); + break; + case "End": + ev.preventDefault(); + themes.lastElementChild.focus(); + break; + // The escape key is handled in handleEscape, not here, + // so that pressing escape will close the menu even if it isn't focused + } + } + + document.addEventListener("keypress", handleShortcut); + document.addEventListener("keydown", handleShortcut); + + (function() { + var x = document.getElementsByClassName("version-selector"); + if (x.length > 0) { + x[0].onchange = function() { + var i, match, + url = document.location.href, + stripped = "", + len = window.rootPath.match(/\.\.\//g).length + 1; + + for (i = 0; i < len; ++i) { + match = url.match(/\/[^/]*$/); + if (i < len - 1) { + stripped = match[0] + stripped; + } + url = url.substring(0, url.length - match[0].length); + } + + var selectedVersion = document.getElementsByClassName("version-selector")[0].value; + url += "/" + selectedVersion + stripped; + + document.location.href = url; + }; + } + }()); + + // delayed sidebar rendering. + window.initSidebarItems = function(items) { + var sidebar = document.getElementsByClassName("sidebar-elems")[0]; + var current = window.sidebarCurrent; + + function addSidebarCrates(crates) { + if (!hasClass(document.body, "crate")) { + // We only want to list crates on the crate page. + return; + } + // Draw a convenient sidebar of known crates if we have a listing + var div = document.createElement("div"); + div.className = "block crate"; + div.innerHTML = "

Crates

"; + var ul = document.createElement("ul"); + div.appendChild(ul); + + for (var i = 0; i < crates.length; ++i) { + var klass = "crate"; + if (window.rootPath !== "./" && crates[i] === window.currentCrate) { + klass += " current"; + } + var link = document.createElement("a"); + link.href = window.rootPath + crates[i] + "/index.html"; + link.className = klass; + link.textContent = crates[i]; + + var li = document.createElement("li"); + li.appendChild(link); + ul.appendChild(li); + } + sidebar.appendChild(div); + } + + function block(shortty, longty) { + var filtered = items[shortty]; + if (!filtered) { + return; + } + + var div = document.createElement("div"); + div.className = "block " + shortty; + var h3 = document.createElement("h3"); + h3.textContent = longty; + div.appendChild(h3); + var ul = document.createElement("ul"); + + for (var i = 0, len = filtered.length; i < len; ++i) { + var item = filtered[i]; + var name = item[0]; + var desc = item[1]; // can be null + + var klass = shortty; + if (name === current.name && shortty === current.ty) { + klass += " current"; + } + var path; + if (shortty === "mod") { + path = name + "/index.html"; + } else { + path = shortty + "." + name + ".html"; + } + var link = document.createElement("a"); + link.href = current.relpath + path; + link.title = desc; + link.className = klass; + link.textContent = name; + var li = document.createElement("li"); + li.appendChild(link); + ul.appendChild(li); + } + div.appendChild(ul); + sidebar.appendChild(div); + } + + if (sidebar) { + var isModule = hasClass(document.body, "mod"); + if (!isModule) { + block("primitive", "Primitive Types"); + block("mod", "Modules"); + block("macro", "Macros"); + block("struct", "Structs"); + block("enum", "Enums"); + block("union", "Unions"); + block("constant", "Constants"); + block("static", "Statics"); + block("trait", "Traits"); + block("fn", "Functions"); + block("type", "Type Definitions"); + block("foreigntype", "Foreign Types"); + block("keyword", "Keywords"); + block("traitalias", "Trait Aliases"); + } + + // `crates{version}.js` should always be loaded before this script, so we can use + // it safely. + addSidebarCrates(window.ALL_CRATES); + } + }; + + window.register_implementors = function(imp) { + var implementors = document.getElementById("implementors-list"); + var synthetic_implementors = document.getElementById("synthetic-implementors-list"); + + if (synthetic_implementors) { + // This `inlined_types` variable is used to avoid having the same implementation + // showing up twice. For example "String" in the "Sync" doc page. + // + // By the way, this is only used by and useful for traits implemented automatically + // (like "Send" and "Sync"). + var inlined_types = new Set(); + onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) { + var aliases = el.getAttribute("data-aliases"); + if (!aliases) { + return; + } + aliases.split(",").forEach(function(alias) { + inlined_types.add(alias); + }); + }); + } + + var libs = Object.getOwnPropertyNames(imp); + for (var i = 0, llength = libs.length; i < llength; ++i) { + if (libs[i] === window.currentCrate) { continue; } + var structs = imp[libs[i]]; + + struct_loop: + for (var j = 0, slength = structs.length; j < slength; ++j) { + var struct = structs[j]; + + var list = struct.synthetic ? synthetic_implementors : implementors; + + if (struct.synthetic) { + for (var k = 0, stlength = struct.types.length; k < stlength; k++) { + if (inlined_types.has(struct.types[k])) { + continue struct_loop; + } + inlined_types.add(struct.types[k]); + } + } + + var code = document.createElement("code"); + code.innerHTML = struct.text; + + onEachLazy(code.getElementsByTagName("a"), function(elem) { + var href = elem.getAttribute("href"); + + if (href && href.indexOf("http") !== 0) { + elem.setAttribute("href", window.rootPath + href); + } + }); + + var display = document.createElement("h3"); + addClass(display, "impl"); + display.innerHTML = "" + + "" + + "
" + code.outerHTML + "
"; + list.appendChild(display); + } + } + }; + if (window.pending_implementors) { + window.register_implementors(window.pending_implementors); + } + + function labelForToggleButton(sectionIsCollapsed) { + if (sectionIsCollapsed) { + // button will expand the section + return "+"; + } + // button will collapse the section + // note that this text is also set in the HTML template in ../render/mod.rs + return "\u2212"; // "\u2212" is "−" minus sign + } + + function toggleAllDocs() { + var innerToggle = document.getElementById(toggleAllDocsId); + if (!innerToggle) { + return; + } + var sectionIsCollapsed = false; + if (hasClass(innerToggle, "will-expand")) { + removeClass(innerToggle, "will-expand"); + onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) { + if (!hasClass(e, "type-contents-toggle")) { + e.open = true; + } + }); + innerToggle.title = "collapse all docs"; + } else { + addClass(innerToggle, "will-expand"); + onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) { + if (e.parentNode.id !== "main" || + (!hasClass(e, "implementors-toggle") && + !hasClass(e, "type-contents-toggle"))) + { + e.open = false; + } + }); + sectionIsCollapsed = true; + innerToggle.title = "expand all docs"; + } + innerToggle.children[0].innerText = labelForToggleButton(sectionIsCollapsed); + } + + function insertAfter(newNode, referenceNode) { + referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); + } + + (function() { + var toggles = document.getElementById(toggleAllDocsId); + if (toggles) { + toggles.onclick = toggleAllDocs; + } + + var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true"; + var hideImplementations = getSettingValue("auto-hide-trait-implementations") === "true"; + var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false"; + + function setImplementorsTogglesOpen(id, open) { + var list = document.getElementById(id); + if (list !== null) { + onEachLazy(list.getElementsByClassName("implementors-toggle"), function(e) { + e.open = open; + }); + } + } + + if (hideImplementations) { + setImplementorsTogglesOpen("trait-implementations-list", false); + setImplementorsTogglesOpen("blanket-implementations-list", false); + } + + onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) { + if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) { + e.open = true; + } + if (hideMethodDocs && hasClass(e, "method-toggle")) { + e.open = false; + } + + }); + + var pageId = getPageId(); + if (pageId !== null) { + expandSection(pageId); + } + }()); + + (function() { + // To avoid checking on "rustdoc-line-numbers" value on every loop... + var lineNumbersFunc = function() {}; + if (getSettingValue("line-numbers") === "true") { + lineNumbersFunc = function(x) { + var count = x.textContent.split("\n").length; + var elems = []; + for (var i = 0; i < count; ++i) { + elems.push(i + 1); + } + var node = document.createElement("pre"); + addClass(node, "line-number"); + node.innerHTML = elems.join("\n"); + x.parentNode.insertBefore(node, x); + }; + } + onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) { + if (hasClass(e, "compile_fail")) { + e.addEventListener("mouseover", function() { + this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00"; + }); + e.addEventListener("mouseout", function() { + this.parentElement.previousElementSibling.childNodes[0].style.color = ""; + }); + } else if (hasClass(e, "ignore")) { + e.addEventListener("mouseover", function() { + this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200"; + }); + e.addEventListener("mouseout", function() { + this.parentElement.previousElementSibling.childNodes[0].style.color = ""; + }); + } + lineNumbersFunc(e); + }); + }()); + + function handleClick(id, f) { + var elem = document.getElementById(id); + if (elem) { + elem.addEventListener("click", f); + } + } + handleClick("help-button", function(ev) { + displayHelp(true, ev); + }); + + onEachLazy(document.getElementsByTagName("a"), function(el) { + // For clicks on internal links ( tags with a hash property), we expand the section we're + // jumping to *before* jumping there. We can't do this in onHashChange, because it changes + // the height of the document so we wind up scrolled to the wrong place. + if (el.hash) { + el.addEventListener("click", function() { + expandSection(el.hash.slice(1)); + }); + } + }); + + onEachLazy(document.getElementsByClassName("notable-traits"), function(e) { + e.onclick = function() { + this.getElementsByClassName('notable-traits-tooltiptext')[0] + .classList.toggle("force-tooltip"); + }; + }); + + var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0]; + if (sidebar_menu) { + sidebar_menu.onclick = function() { + var sidebar = document.getElementsByClassName("sidebar")[0]; + if (hasClass(sidebar, "mobile")) { + hideSidebar(); + } else { + showSidebar(); + } + }; + } + + var buildHelperPopup = function() { + var popup = document.createElement("aside"); + addClass(popup, "hidden"); + popup.id = "help"; + + popup.addEventListener("click", function(ev) { + if (ev.target === popup) { + // Clicked the blurred zone outside the help popup; dismiss help. + displayHelp(false, ev); + } + }); + + var book_info = document.createElement("span"); + book_info.innerHTML = "You can find more information in \ + the rustdoc book."; + + var container = document.createElement("div"); + var shortcuts = [ + ["?", "Show this help dialog"], + ["S", "Focus the search field"], + ["T", "Focus the theme picker menu"], + ["↑", "Move up in search results"], + ["↓", "Move down in search results"], + ["← / →", "Switch result tab (when results focused)"], + ["⏎", "Go to active search result"], + ["+", "Expand all sections"], + ["-", "Collapse all sections"], + ].map(function(x) { + return "
" + + x[0].split(" ") + .map(function(y, index) { + return (index & 1) === 0 ? "" + y + "" : " " + y + " "; + }) + .join("") + "
" + x[1] + "
"; + }).join(""); + var div_shortcuts = document.createElement("div"); + addClass(div_shortcuts, "shortcuts"); + div_shortcuts.innerHTML = "

Keyboard Shortcuts

" + shortcuts + "
"; + + var infos = [ + "Prefix searches with a type followed by a colon (e.g., fn:) to \ + restrict the search to a given item kind.", + "Accepted kinds are: fn, mod, struct, \ + enum, trait, type, macro, \ + and const.", + "Search functions by type signature (e.g., vec -> usize or \ + * -> vec)", + "Search multiple things at once by splitting your query with comma (e.g., \ + str,u8 or String,struct:Vec,test)", + "You can look for items with an exact name by putting double quotes around \ + your request: \"string\"", + "Look for items inside another one by searching for a path: vec::Vec", + ].map(function(x) { + return "

" + x + "

"; + }).join(""); + var div_infos = document.createElement("div"); + addClass(div_infos, "infos"); + div_infos.innerHTML = "

Search Tricks

" + infos; + + container.appendChild(book_info); + container.appendChild(div_shortcuts); + container.appendChild(div_infos); + + popup.appendChild(container); + insertAfter(popup, searchState.outputElement()); + // So that it's only built once and then it'll do nothing when called! + buildHelperPopup = function() {}; + }; + + onHashChange(null); + window.addEventListener("hashchange", onHashChange); + searchState.setup(); +}()); + +(function () { + var reset_button_timeout = null; + + window.copy_path = function(but) { + var parent = but.parentElement; + var path = []; + + onEach(parent.childNodes, function(child) { + if (child.tagName === 'A') { + path.push(child.textContent); + } + }); + + var el = document.createElement('textarea'); + el.value = 'use ' + path.join('::') + ';'; + el.setAttribute('readonly', ''); + // To not make it appear on the screen. + el.style.position = 'absolute'; + el.style.left = '-9999px'; + + document.body.appendChild(el); + el.select(); + document.execCommand('copy'); + document.body.removeChild(el); + + // There is always one children, but multiple childNodes. + but.children[0].style.display = 'none'; + + var tmp; + if (but.childNodes.length < 2) { + tmp = document.createTextNode('✓'); + but.appendChild(tmp); + } else { + onEachLazy(but.childNodes, function(e) { + if (e.nodeType === Node.TEXT_NODE) { + tmp = e; + return true; + } + }); + tmp.textContent = '✓'; + } + + if (reset_button_timeout !== null) { + window.clearTimeout(reset_button_timeout); + } + + function reset_button() { + tmp.textContent = ''; + reset_button_timeout = null; + but.children[0].style.display = ""; + } + + reset_button_timeout = window.setTimeout(reset_button, 1000); + }; +}()); diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js new file mode 100644 index 00000000000..a7fc0b831f4 --- /dev/null +++ b/src/librustdoc/html/static/js/search.js @@ -0,0 +1,1561 @@ +/* global addClass, getNakedUrl, getSettingValue, hasOwnPropertyRustdoc, initSearch, onEach */ +/* global onEachLazy, removeClass, searchState, updateLocalStorage */ + +(function() { +// This mapping table should match the discriminants of +// `rustdoc::html::item_type::ItemType` type in Rust. +var itemTypes = ["mod", + "externcrate", + "import", + "struct", + "enum", + "fn", + "type", + "static", + "trait", + "impl", + "tymethod", + "method", + "structfield", + "variant", + "macro", + "primitive", + "associatedtype", + "constant", + "associatedconstant", + "union", + "foreigntype", + "keyword", + "existential", + "attr", + "derive", + "traitalias"]; + +// used for special search precedence +var TY_PRIMITIVE = itemTypes.indexOf("primitive"); +var TY_KEYWORD = itemTypes.indexOf("keyword"); + +// In the search display, allows to switch between tabs. +function printTab(nb) { + if (nb === 0 || nb === 1 || nb === 2) { + searchState.currentTab = nb; + } + var nb_copy = nb; + onEachLazy(document.getElementById("titles").childNodes, function(elem) { + if (nb_copy === 0) { + addClass(elem, "selected"); + } else { + removeClass(elem, "selected"); + } + nb_copy -= 1; + }); + onEachLazy(document.getElementById("results").childNodes, function(elem) { + if (nb === 0) { + addClass(elem, "active"); + } else { + removeClass(elem, "active"); + } + nb -= 1; + }); +} + +function removeEmptyStringsFromArray(x) { + for (var i = 0, len = x.length; i < len; ++i) { + if (x[i] === "") { + x.splice(i, 1); + i -= 1; + } + } +} + +/** + * A function to compute the Levenshtein distance between two strings + * Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported + * Full License can be found at http://creativecommons.org/licenses/by-sa/3.0/legalcode + * This code is an unmodified version of the code written by Marco de Wit + * and was found at https://stackoverflow.com/a/18514751/745719 + */ +var levenshtein_row2 = []; +function levenshtein(s1, s2) { + if (s1 === s2) { + return 0; + } + var s1_len = s1.length, s2_len = s2.length; + if (s1_len && s2_len) { + var i1 = 0, i2 = 0, a, b, c, c2, row = levenshtein_row2; + while (i1 < s1_len) { + row[i1] = ++i1; + } + while (i2 < s2_len) { + c2 = s2.charCodeAt(i2); + a = i2; + ++i2; + b = i2; + for (i1 = 0; i1 < s1_len; ++i1) { + c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0); + a = row[i1]; + b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c); + row[i1] = b; + } + } + return b; + } + return s1_len + s2_len; +} + +window.initSearch = function(rawSearchIndex) { + var MAX_LEV_DISTANCE = 3; + var MAX_RESULTS = 200; + var GENERICS_DATA = 2; + var NAME = 0; + var INPUTS_DATA = 0; + var OUTPUT_DATA = 1; + var NO_TYPE_FILTER = -1; + var currentResults, index, searchIndex; + var ALIASES = {}; + var params = searchState.getQueryStringParams(); + + // Populate search bar with query string search term when provided, + // but only if the input bar is empty. This avoid the obnoxious issue + // where you start trying to do a search, and the index loads, and + // suddenly your search is gone! + if (searchState.input.value === "") { + searchState.input.value = params.search || ""; + } + + /** + * Executes the query and builds an index of results + * @param {[Object]} query [The user query] + * @param {[type]} searchWords [The list of search words to query + * against] + * @param {[type]} filterCrates [Crate to search in if defined] + * @return {[type]} [A search index of results] + */ + function execQuery(query, searchWords, filterCrates) { + function itemTypeFromName(typename) { + for (var i = 0, len = itemTypes.length; i < len; ++i) { + if (itemTypes[i] === typename) { + return i; + } + } + return NO_TYPE_FILTER; + } + + var valLower = query.query.toLowerCase(), + val = valLower, + typeFilter = itemTypeFromName(query.type), + results = {}, results_in_args = {}, results_returned = {}, + split = valLower.split("::"); + + removeEmptyStringsFromArray(split); + + function transformResults(results) { + var out = []; + for (var i = 0, len = results.length; i < len; ++i) { + if (results[i].id > -1) { + var obj = searchIndex[results[i].id]; + obj.lev = results[i].lev; + var res = buildHrefAndPath(obj); + obj.displayPath = pathSplitter(res[0]); + obj.fullPath = obj.displayPath + obj.name; + // To be sure than it some items aren't considered as duplicate. + obj.fullPath += "|" + obj.ty; + obj.href = res[1]; + out.push(obj); + if (out.length >= MAX_RESULTS) { + break; + } + } + } + return out; + } + + function sortResults(results, isType) { + var ar = []; + for (var entry in results) { + if (hasOwnPropertyRustdoc(results, entry)) { + ar.push(results[entry]); + } + } + results = ar; + var i, len, result; + for (i = 0, len = results.length; i < len; ++i) { + result = results[i]; + result.word = searchWords[result.id]; + result.item = searchIndex[result.id] || {}; + } + // if there are no results then return to default and fail + if (results.length === 0) { + return []; + } + + results.sort(function(aaa, bbb) { + var a, b; + + // sort by exact match with regard to the last word (mismatch goes later) + a = (aaa.word !== val); + b = (bbb.word !== val); + if (a !== b) { return a - b; } + + // Sort by non levenshtein results and then levenshtein results by the distance + // (less changes required to match means higher rankings) + a = (aaa.lev); + b = (bbb.lev); + if (a !== b) { return a - b; } + + // sort by crate (non-current crate goes later) + a = (aaa.item.crate !== window.currentCrate); + b = (bbb.item.crate !== window.currentCrate); + if (a !== b) { return a - b; } + + // sort by item name length (longer goes later) + a = aaa.word.length; + b = bbb.word.length; + if (a !== b) { return a - b; } + + // sort by item name (lexicographically larger goes later) + a = aaa.word; + b = bbb.word; + if (a !== b) { return (a > b ? +1 : -1); } + + // sort by index of keyword in item name (no literal occurrence goes later) + a = (aaa.index < 0); + b = (bbb.index < 0); + if (a !== b) { return a - b; } + // (later literal occurrence, if any, goes later) + a = aaa.index; + b = bbb.index; + if (a !== b) { return a - b; } + + // special precedence for primitive and keyword pages + if ((aaa.item.ty === TY_PRIMITIVE && bbb.item.ty !== TY_KEYWORD) || + (aaa.item.ty === TY_KEYWORD && bbb.item.ty !== TY_PRIMITIVE)) { + return -1; + } + if ((bbb.item.ty === TY_PRIMITIVE && aaa.item.ty !== TY_PRIMITIVE) || + (bbb.item.ty === TY_KEYWORD && aaa.item.ty !== TY_KEYWORD)) { + return 1; + } + + // sort by description (no description goes later) + a = (aaa.item.desc === ""); + b = (bbb.item.desc === ""); + if (a !== b) { return a - b; } + + // sort by type (later occurrence in `itemTypes` goes later) + a = aaa.item.ty; + b = bbb.item.ty; + if (a !== b) { return a - b; } + + // sort by path (lexicographically larger goes later) + a = aaa.item.path; + b = bbb.item.path; + if (a !== b) { return (a > b ? +1 : -1); } + + // que sera, sera + return 0; + }); + + for (i = 0, len = results.length; i < len; ++i) { + result = results[i]; + + // this validation does not make sense when searching by types + if (result.dontValidate) { + continue; + } + var name = result.item.name.toLowerCase(), + path = result.item.path.toLowerCase(), + parent = result.item.parent; + + if (!isType && !validateResult(name, path, split, parent)) { + result.id = -1; + } + } + return transformResults(results); + } + + function extractGenerics(val) { + val = val.toLowerCase(); + if (val.indexOf("<") !== -1) { + var values = val.substring(val.indexOf("<") + 1, val.lastIndexOf(">")); + return { + name: val.substring(0, val.indexOf("<")), + generics: values.split(/\s*,\s*/), + }; + } + return { + name: val, + generics: [], + }; + } + + function getObjectNameFromId(id) { + if (typeof id === "number") { + return searchIndex[id].name; + } + return id; + } + + function checkGenerics(obj, val) { + // The names match, but we need to be sure that all generics kinda + // match as well. + var tmp_lev, elem_name; + if (val.generics.length > 0) { + if (obj.length > GENERICS_DATA && + obj[GENERICS_DATA].length >= val.generics.length) { + var elems = Object.create(null); + var elength = obj[GENERICS_DATA].length; + for (var x = 0; x < elength; ++x) { + if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) { + elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0; + } + elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; + } + var total = 0; + var done = 0; + // We need to find the type that matches the most to remove it in order + // to move forward. + var vlength = val.generics.length; + for (x = 0; x < vlength; ++x) { + var lev = MAX_LEV_DISTANCE + 1; + var firstGeneric = getObjectNameFromId(val.generics[x]); + var match = null; + if (elems[firstGeneric]) { + match = firstGeneric; + lev = 0; + } else { + for (elem_name in elems) { + tmp_lev = levenshtein(elem_name, firstGeneric); + if (tmp_lev < lev) { + lev = tmp_lev; + match = elem_name; + } + } + } + if (match !== null) { + elems[match] -= 1; + if (elems[match] == 0) { + delete elems[match]; + } + total += lev; + done += 1; + } else { + return MAX_LEV_DISTANCE + 1; + } + } + return Math.ceil(total / done); + } + } + return MAX_LEV_DISTANCE + 1; + } + + // Check for type name and type generics (if any). + function checkType(obj, val, literalSearch) { + var lev_distance = MAX_LEV_DISTANCE + 1; + var len, x, firstGeneric; + if (obj[NAME] === val.name) { + if (literalSearch) { + if (val.generics && val.generics.length !== 0) { + if (obj.length > GENERICS_DATA && + obj[GENERICS_DATA].length > 0) { + var elems = Object.create(null); + len = obj[GENERICS_DATA].length; + for (x = 0; x < len; ++x) { + if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) { + elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0; + } + elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; + } + + var allFound = true; + len = val.generics.length; + for (x = 0; x < len; ++x) { + firstGeneric = getObjectNameFromId(val.generics[x]); + if (elems[firstGeneric]) { + elems[firstGeneric] -= 1; + } else { + allFound = false; + break; + } + } + if (allFound) { + return true; + } + } + return false; + } + return true; + } else { + // If the type has generics but don't match, then it won't return at this point. + // Otherwise, `checkGenerics` will return 0 and it'll return. + if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length !== 0) { + var tmp_lev = checkGenerics(obj, val); + if (tmp_lev <= MAX_LEV_DISTANCE) { + return tmp_lev; + } + } + } + } else if (literalSearch) { + if ((!val.generics || val.generics.length === 0) && + obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) { + return obj[GENERICS_DATA].some( + function(name) { + return name === val.name; + }); + } + return false; + } + lev_distance = Math.min(levenshtein(obj[NAME], val.name), lev_distance); + if (lev_distance <= MAX_LEV_DISTANCE) { + // The generics didn't match but the name kinda did so we give it + // a levenshtein distance value that isn't *this* good so it goes + // into the search results but not too high. + lev_distance = Math.ceil((checkGenerics(obj, val) + lev_distance) / 2); + } else if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) { + // We can check if the type we're looking for is inside the generics! + var olength = obj[GENERICS_DATA].length; + for (x = 0; x < olength; ++x) { + lev_distance = Math.min(levenshtein(obj[GENERICS_DATA][x], val.name), + lev_distance); + } + } + // Now whatever happens, the returned distance is "less good" so we should mark it + // as such, and so we add 1 to the distance to make it "less good". + return lev_distance + 1; + } + + function findArg(obj, val, literalSearch, typeFilter) { + var lev_distance = MAX_LEV_DISTANCE + 1; + + if (obj && obj.type && obj.type[INPUTS_DATA] && obj.type[INPUTS_DATA].length > 0) { + var length = obj.type[INPUTS_DATA].length; + for (var i = 0; i < length; i++) { + var tmp = obj.type[INPUTS_DATA][i]; + if (!typePassesFilter(typeFilter, tmp[1])) { + continue; + } + tmp = checkType(tmp, val, literalSearch); + if (literalSearch) { + if (tmp) { + return true; + } + continue; + } + lev_distance = Math.min(tmp, lev_distance); + if (lev_distance === 0) { + return 0; + } + } + } + return literalSearch ? false : lev_distance; + } + + function checkReturned(obj, val, literalSearch, typeFilter) { + var lev_distance = MAX_LEV_DISTANCE + 1; + + if (obj && obj.type && obj.type.length > OUTPUT_DATA) { + var ret = obj.type[OUTPUT_DATA]; + if (typeof ret[0] === "string") { + ret = [ret]; + } + for (var x = 0, len = ret.length; x < len; ++x) { + var tmp = ret[x]; + if (!typePassesFilter(typeFilter, tmp[1])) { + continue; + } + tmp = checkType(tmp, val, literalSearch); + if (literalSearch) { + if (tmp) { + return true; + } + continue; + } + lev_distance = Math.min(tmp, lev_distance); + if (lev_distance === 0) { + return 0; + } + } + } + return literalSearch ? false : lev_distance; + } + + function checkPath(contains, lastElem, ty) { + if (contains.length === 0) { + return 0; + } + var ret_lev = MAX_LEV_DISTANCE + 1; + var path = ty.path.split("::"); + + if (ty.parent && ty.parent.name) { + path.push(ty.parent.name.toLowerCase()); + } + + var length = path.length; + var clength = contains.length; + if (clength > length) { + return MAX_LEV_DISTANCE + 1; + } + for (var i = 0; i < length; ++i) { + if (i + clength > length) { + break; + } + var lev_total = 0; + var aborted = false; + for (var x = 0; x < clength; ++x) { + var lev = levenshtein(path[i + x], contains[x]); + if (lev > MAX_LEV_DISTANCE) { + aborted = true; + break; + } + lev_total += lev; + } + if (!aborted) { + ret_lev = Math.min(ret_lev, Math.round(lev_total / clength)); + } + } + return ret_lev; + } + + function typePassesFilter(filter, type) { + // No filter + if (filter <= NO_TYPE_FILTER) return true; + + // Exact match + if (filter === type) return true; + + // Match related items + var name = itemTypes[type]; + switch (itemTypes[filter]) { + case "constant": + return name === "associatedconstant"; + case "fn": + return name === "method" || name === "tymethod"; + case "type": + return name === "primitive" || name === "associatedtype"; + case "trait": + return name === "traitalias"; + } + + // No match + return false; + } + + function createAliasFromItem(item) { + return { + crate: item.crate, + name: item.name, + path: item.path, + desc: item.desc, + ty: item.ty, + parent: item.parent, + type: item.type, + is_alias: true, + }; + } + + function handleAliases(ret, query, filterCrates) { + // We separate aliases and crate aliases because we want to have current crate + // aliases to be before the others in the displayed results. + var aliases = []; + var crateAliases = []; + if (filterCrates !== undefined) { + if (ALIASES[filterCrates] && ALIASES[filterCrates][query.search]) { + var query_aliases = ALIASES[filterCrates][query.search]; + var len = query_aliases.length; + for (var i = 0; i < len; ++i) { + aliases.push(createAliasFromItem(searchIndex[query_aliases[i]])); + } + } + } else { + Object.keys(ALIASES).forEach(function(crate) { + if (ALIASES[crate][query.search]) { + var pushTo = crate === window.currentCrate ? crateAliases : aliases; + var query_aliases = ALIASES[crate][query.search]; + var len = query_aliases.length; + for (var i = 0; i < len; ++i) { + pushTo.push(createAliasFromItem(searchIndex[query_aliases[i]])); + } + } + }); + } + + var sortFunc = function(aaa, bbb) { + if (aaa.path < bbb.path) { + return 1; + } else if (aaa.path === bbb.path) { + return 0; + } + return -1; + }; + crateAliases.sort(sortFunc); + aliases.sort(sortFunc); + + var pushFunc = function(alias) { + alias.alias = query.raw; + var res = buildHrefAndPath(alias); + alias.displayPath = pathSplitter(res[0]); + alias.fullPath = alias.displayPath + alias.name; + alias.href = res[1]; + + ret.others.unshift(alias); + if (ret.others.length > MAX_RESULTS) { + ret.others.pop(); + } + }; + onEach(aliases, pushFunc); + onEach(crateAliases, pushFunc); + } + + // quoted values mean literal search + var nSearchWords = searchWords.length; + var i, it; + var ty; + var fullId; + var returned; + var in_args; + var len; + if ((val.charAt(0) === "\"" || val.charAt(0) === "'") && + val.charAt(val.length - 1) === val.charAt(0)) + { + val = extractGenerics(val.substr(1, val.length - 2)); + for (i = 0; i < nSearchWords; ++i) { + if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { + continue; + } + in_args = findArg(searchIndex[i], val, true, typeFilter); + returned = checkReturned(searchIndex[i], val, true, typeFilter); + ty = searchIndex[i]; + fullId = ty.id; + + if (searchWords[i] === val.name + && typePassesFilter(typeFilter, searchIndex[i].ty) + && results[fullId] === undefined) { + results[fullId] = { + id: i, + index: -1, + dontValidate: true, + }; + } + if (in_args && results_in_args[fullId] === undefined) { + results_in_args[fullId] = { + id: i, + index: -1, + dontValidate: true, + }; + } + if (returned && results_returned[fullId] === undefined) { + results_returned[fullId] = { + id: i, + index: -1, + dontValidate: true, + }; + } + } + query.inputs = [val]; + query.output = val; + query.search = val; + // searching by type + } else if (val.search("->") > -1) { + var trimmer = function(s) { return s.trim(); }; + var parts = val.split("->").map(trimmer); + var input = parts[0]; + // sort inputs so that order does not matter + var inputs = input.split(",").map(trimmer).sort(); + for (i = 0, len = inputs.length; i < len; ++i) { + inputs[i] = extractGenerics(inputs[i]); + } + var output = extractGenerics(parts[1]); + + for (i = 0; i < nSearchWords; ++i) { + if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { + continue; + } + var type = searchIndex[i].type; + ty = searchIndex[i]; + if (!type) { + continue; + } + fullId = ty.id; + + returned = checkReturned(ty, output, true, NO_TYPE_FILTER); + if (output.name === "*" || returned) { + in_args = false; + var is_module = false; + + if (input === "*") { + is_module = true; + } else { + var allFound = true; + for (it = 0, len = inputs.length; allFound && it < len; it++) { + allFound = checkType(type, inputs[it], true); + } + in_args = allFound; + } + if (in_args) { + results_in_args[fullId] = { + id: i, + index: -1, + dontValidate: true, + }; + } + if (returned) { + results_returned[fullId] = { + id: i, + index: -1, + dontValidate: true, + }; + } + if (is_module) { + results[fullId] = { + id: i, + index: -1, + dontValidate: true, + }; + } + } + } + query.inputs = inputs.map(function(input) { + return input.name; + }); + query.output = output.name; + } else { + query.inputs = [val]; + query.output = val; + query.search = val; + // gather matching search results up to a certain maximum + val = val.replace(/_/g, ""); + + var valGenerics = extractGenerics(val); + + var paths = valLower.split("::"); + removeEmptyStringsFromArray(paths); + val = paths[paths.length - 1]; + var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1); + + var lev, j; + for (j = 0; j < nSearchWords; ++j) { + ty = searchIndex[j]; + if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) { + continue; + } + var lev_add = 0; + if (paths.length > 1) { + lev = checkPath(contains, paths[paths.length - 1], ty); + if (lev > MAX_LEV_DISTANCE) { + continue; + } else if (lev > 0) { + lev_add = lev / 10; + } + } + + returned = MAX_LEV_DISTANCE + 1; + in_args = MAX_LEV_DISTANCE + 1; + var index = -1; + // we want lev results to go lower than others + lev = MAX_LEV_DISTANCE + 1; + fullId = ty.id; + + if (searchWords[j].indexOf(split[i]) > -1 || + searchWords[j].indexOf(val) > -1 || + ty.normalizedName.indexOf(val) > -1) + { + // filter type: ... queries + if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) { + index = ty.normalizedName.indexOf(val); + } + } + if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) { + if (typePassesFilter(typeFilter, ty.ty)) { + lev += 1; + } else { + lev = MAX_LEV_DISTANCE + 1; + } + } + in_args = findArg(ty, valGenerics, false, typeFilter); + returned = checkReturned(ty, valGenerics, false, typeFilter); + + lev += lev_add; + if (lev > 0 && val.length > 3 && searchWords[j].indexOf(val) > -1) { + if (val.length < 6) { + lev -= 1; + } else { + lev = 0; + } + } + if (in_args <= MAX_LEV_DISTANCE) { + if (results_in_args[fullId] === undefined) { + results_in_args[fullId] = { + id: j, + index: index, + lev: in_args, + }; + } + results_in_args[fullId].lev = + Math.min(results_in_args[fullId].lev, in_args); + } + if (returned <= MAX_LEV_DISTANCE) { + if (results_returned[fullId] === undefined) { + results_returned[fullId] = { + id: j, + index: index, + lev: returned, + }; + } + results_returned[fullId].lev = + Math.min(results_returned[fullId].lev, returned); + } + if (typePassesFilter(typeFilter, ty.ty) && + (index !== -1 || lev <= MAX_LEV_DISTANCE)) { + if (index !== -1 && paths.length < 2) { + lev = 0; + } + if (results[fullId] === undefined) { + results[fullId] = { + id: j, + index: index, + lev: lev, + }; + } + results[fullId].lev = Math.min(results[fullId].lev, lev); + } + } + } + + var ret = { + "in_args": sortResults(results_in_args, true), + "returned": sortResults(results_returned, true), + "others": sortResults(results, false), + }; + handleAliases(ret, query, filterCrates); + return ret; + } + + /** + * Validate performs the following boolean logic. For example: + * "File::open" will give IF A PARENT EXISTS => ("file" && "open") + * exists in (name || path || parent) OR => ("file" && "open") exists in + * (name || path ) + * + * This could be written functionally, but I wanted to minimise + * functions on stack. + * + * @param {[string]} name [The name of the result] + * @param {[string]} path [The path of the result] + * @param {[string]} keys [The keys to be used (["file", "open"])] + * @param {[object]} parent [The parent of the result] + * @return {boolean} [Whether the result is valid or not] + */ + function validateResult(name, path, keys, parent) { + for (var i = 0, len = keys.length; i < len; ++i) { + // each check is for validation so we negate the conditions and invalidate + if (!( + // check for an exact name match + name.indexOf(keys[i]) > -1 || + // then an exact path match + path.indexOf(keys[i]) > -1 || + // next if there is a parent, check for exact parent match + (parent !== undefined && parent.name !== undefined && + parent.name.toLowerCase().indexOf(keys[i]) > -1) || + // lastly check to see if the name was a levenshtein match + levenshtein(name, keys[i]) <= MAX_LEV_DISTANCE)) { + return false; + } + } + return true; + } + + function getQuery(raw) { + var matches, type, query; + query = raw; + + matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i); + if (matches) { + type = matches[1].replace(/^const$/, "constant"); + query = query.substring(matches[0].length); + } + + return { + raw: raw, + query: query, + type: type, + id: query + type + }; + } + + function nextTab(direction) { + var next = (searchState.currentTab + direction + 3) % searchState.focusedByTab.length; + searchState.focusedByTab[searchState.currentTab] = document.activeElement; + printTab(next); + focusSearchResult(); + } + + // Focus the first search result on the active tab, or the result that + // was focused last time this tab was active. + function focusSearchResult() { + var target = searchState.focusedByTab[searchState.currentTab] || + document.querySelectorAll(".search-results.active a").item(0) || + document.querySelectorAll("#titles > button").item(searchState.currentTab); + if (target) { + target.focus(); + } + } + + function buildHrefAndPath(item) { + var displayPath; + var href; + var type = itemTypes[item.ty]; + var name = item.name; + var path = item.path; + + if (type === "mod") { + displayPath = path + "::"; + href = window.rootPath + path.replace(/::/g, "/") + "/" + + name + "/index.html"; + } else if (type === "primitive" || type === "keyword") { + displayPath = ""; + href = window.rootPath + path.replace(/::/g, "/") + + "/" + type + "." + name + ".html"; + } else if (type === "externcrate") { + displayPath = ""; + href = window.rootPath + name + "/index.html"; + } else if (item.parent !== undefined) { + var myparent = item.parent; + var anchor = "#" + type + "." + name; + var parentType = itemTypes[myparent.ty]; + var pageType = parentType; + var pageName = myparent.name; + + if (parentType === "primitive") { + displayPath = myparent.name + "::"; + } else if (type === "structfield" && parentType === "variant") { + // Structfields belonging to variants are special: the + // final path element is the enum name. + var enumNameIdx = item.path.lastIndexOf("::"); + var enumName = item.path.substr(enumNameIdx + 2); + path = item.path.substr(0, enumNameIdx); + displayPath = path + "::" + enumName + "::" + myparent.name + "::"; + anchor = "#variant." + myparent.name + ".field." + name; + pageType = "enum"; + pageName = enumName; + } else { + displayPath = path + "::" + myparent.name + "::"; + } + href = window.rootPath + path.replace(/::/g, "/") + + "/" + pageType + + "." + pageName + + ".html" + anchor; + } else { + displayPath = item.path + "::"; + href = window.rootPath + item.path.replace(/::/g, "/") + + "/" + type + "." + name + ".html"; + } + return [displayPath, href]; + } + + function escape(content) { + var h1 = document.createElement("h1"); + h1.textContent = content; + return h1.innerHTML; + } + + function pathSplitter(path) { + var tmp = "" + path.replace(/::/g, "::"); + if (tmp.endsWith("")) { + return tmp.slice(0, tmp.length - 6); + } + return tmp; + } + + function addTab(array, query, display) { + var extraClass = ""; + if (display === true) { + extraClass = " active"; + } + + var output = document.createElement("div"); + var duplicates = {}; + var length = 0; + if (array.length > 0) { + output.className = "search-results " + extraClass; + + array.forEach(function(item) { + if (item.is_alias !== true) { + if (duplicates[item.fullPath]) { + return; + } + duplicates[item.fullPath] = true; + } + + var name = item.name; + var type = itemTypes[item.ty]; + + length += 1; + + var extra = ""; + if (type === "primitive") { + extra = " (primitive type)"; + } else if (type === "keyword") { + extra = " (keyword)"; + } + + var link = document.createElement("a"); + link.className = "result-" + type; + link.href = item.href; + + var wrapper = document.createElement("div"); + var resultName = document.createElement("div"); + resultName.className = "result-name"; + + if (item.is_alias) { + var alias = document.createElement("span"); + alias.className = "alias"; + + var bold = document.createElement("b"); + bold.innerText = item.alias; + alias.appendChild(bold); + + alias.insertAdjacentHTML( + "beforeend", + " - see "); + + resultName.appendChild(alias); + } + resultName.insertAdjacentHTML( + "beforeend", + item.displayPath + "" + name + extra + ""); + wrapper.appendChild(resultName); + + var description = document.createElement("div"); + description.className = "desc"; + var spanDesc = document.createElement("span"); + spanDesc.insertAdjacentHTML("beforeend", item.desc); + + description.appendChild(spanDesc); + wrapper.appendChild(description); + link.appendChild(wrapper); + output.appendChild(link); + }); + } else { + output.className = "search-failed" + extraClass; + output.innerHTML = "No results :(
" + + "Try on DuckDuckGo?

" + + "Or try looking in one of these:"; + } + return [output, length]; + } + + function makeTabHeader(tabNb, text, nbElems) { + if (searchState.currentTab === tabNb) { + return ""; + } + return ""; + } + + function showResults(results, go_to_first) { + var search = searchState.outputElement(); + if (go_to_first || (results.others.length === 1 + && getSettingValue("go-to-only-result") === "true" + // By default, the search DOM element is "empty" (meaning it has no children not + // text content). Once a search has been run, it won't be empty, even if you press + // ESC or empty the search input (which also "cancels" the search). + && (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))) + { + var elem = document.createElement("a"); + elem.href = results.others[0].href; + removeClass(elem, "active"); + // For firefox, we need the element to be in the DOM so it can be clicked. + document.body.appendChild(elem); + elem.click(); + return; + } + var query = getQuery(searchState.input.value); + + currentResults = query.id; + + var ret_others = addTab(results.others, query); + var ret_in_args = addTab(results.in_args, query, false); + var ret_returned = addTab(results.returned, query, false); + + // Navigate to the relevant tab if the current tab is empty, like in case users search + // for "-> String". If they had selected another tab previously, they have to click on + // it again. + var currentTab = searchState.currentTab; + if ((currentTab === 0 && ret_others[1] === 0) || + (currentTab === 1 && ret_in_args[1] === 0) || + (currentTab === 2 && ret_returned[1] === 0)) { + if (ret_others[1] !== 0) { + currentTab = 0; + } else if (ret_in_args[1] !== 0) { + currentTab = 1; + } else if (ret_returned[1] !== 0) { + currentTab = 2; + } + } + + var output = "

Results for " + escape(query.query) + + (query.type ? " (type: " + escape(query.type) + ")" : "") + "

" + + "
" + + makeTabHeader(0, "In Names", ret_others[1]) + + makeTabHeader(1, "In Parameters", ret_in_args[1]) + + makeTabHeader(2, "In Return Types", ret_returned[1]) + + "
"; + + var resultsElem = document.createElement("div"); + resultsElem.id = "results"; + resultsElem.appendChild(ret_others[0]); + resultsElem.appendChild(ret_in_args[0]); + resultsElem.appendChild(ret_returned[0]); + + search.innerHTML = output; + search.appendChild(resultsElem); + // Reset focused elements. + searchState.focusedByTab = [null, null, null]; + searchState.showResults(search); + var elems = document.getElementById("titles").childNodes; + elems[0].onclick = function() { printTab(0); }; + elems[1].onclick = function() { printTab(1); }; + elems[2].onclick = function() { printTab(2); }; + printTab(currentTab); + } + + function execSearch(query, searchWords, filterCrates) { + function getSmallest(arrays, positions, notDuplicates) { + var start = null; + + for (var it = 0, len = positions.length; it < len; ++it) { + if (arrays[it].length > positions[it] && + (start === null || start > arrays[it][positions[it]].lev) && + !notDuplicates[arrays[it][positions[it]].fullPath]) { + start = arrays[it][positions[it]].lev; + } + } + return start; + } + + function mergeArrays(arrays) { + var ret = []; + var positions = []; + var notDuplicates = {}; + + for (var x = 0, arrays_len = arrays.length; x < arrays_len; ++x) { + positions.push(0); + } + while (ret.length < MAX_RESULTS) { + var smallest = getSmallest(arrays, positions, notDuplicates); + + if (smallest === null) { + break; + } + for (x = 0; x < arrays_len && ret.length < MAX_RESULTS; ++x) { + if (arrays[x].length > positions[x] && + arrays[x][positions[x]].lev === smallest && + !notDuplicates[arrays[x][positions[x]].fullPath]) { + ret.push(arrays[x][positions[x]]); + notDuplicates[arrays[x][positions[x]].fullPath] = true; + positions[x] += 1; + } + } + } + return ret; + } + + // Split search query by ",", while respecting angle bracket nesting. + // Since "<" is an alias for the Ord family of traits, it also uses + // lookahead to distinguish "<"-as-less-than from "<"-as-angle-bracket. + // + // tokenizeQuery("A, D") == ["A", "D"] + // tokenizeQuery("A)/g; + var ret = []; + var start = 0; + for (i = 0; i < l; ++i) { + switch (raw[i]) { + case "<": + nextAngle.lastIndex = i + 1; + matched = nextAngle.exec(raw); + if (matched && matched[1] === '>') { + depth += 1; + } + break; + case ">": + if (depth > 0) { + depth -= 1; + } + break; + case ",": + if (depth === 0) { + ret.push(raw.substring(start, i)); + start = i + 1; + } + break; + } + } + if (start !== i) { + ret.push(raw.substring(start, i)); + } + return ret; + } + + var queries = tokenizeQuery(query.raw); + var results = { + "in_args": [], + "returned": [], + "others": [], + }; + + for (var i = 0, len = queries.length; i < len; ++i) { + query = queries[i].trim(); + if (query.length !== 0) { + var tmp = execQuery(getQuery(query), searchWords, filterCrates); + + results.in_args.push(tmp.in_args); + results.returned.push(tmp.returned); + results.others.push(tmp.others); + } + } + if (queries.length > 1) { + return { + "in_args": mergeArrays(results.in_args), + "returned": mergeArrays(results.returned), + "others": mergeArrays(results.others), + }; + } + return { + "in_args": results.in_args[0], + "returned": results.returned[0], + "others": results.others[0], + }; + } + + function getFilterCrates() { + var elem = document.getElementById("crate-search"); + + if (elem && elem.value !== "All crates" && + hasOwnPropertyRustdoc(rawSearchIndex, elem.value)) + { + return elem.value; + } + return undefined; + } + + function search(e, forced) { + var params = searchState.getQueryStringParams(); + var query = getQuery(searchState.input.value.trim()); + + if (e) { + e.preventDefault(); + } + + if (query.query.length === 0) { + return; + } + if (!forced && query.id === currentResults) { + if (query.query.length > 0) { + searchState.putBackSearch(searchState.input); + } + return; + } + + // Update document title to maintain a meaningful browser history + searchState.title = "Results for " + query.query + " - Rust"; + + // Because searching is incremental by character, only the most + // recent search query is added to the browser history. + if (searchState.browserSupportsHistoryApi()) { + var newURL = getNakedUrl() + "?search=" + encodeURIComponent(query.raw) + + window.location.hash; + if (!history.state && !params.search) { + history.pushState(query, "", newURL); + } else { + history.replaceState(query, "", newURL); + } + } + + var filterCrates = getFilterCrates(); + showResults(execSearch(query, index, filterCrates), params.go_to_first); + } + + function buildIndex(rawSearchIndex) { + searchIndex = []; + var searchWords = []; + var i, word; + var currentIndex = 0; + var id = 0; + + for (var crate in rawSearchIndex) { + if (!hasOwnPropertyRustdoc(rawSearchIndex, crate)) { + continue; + } + + var crateSize = 0; + + searchWords.push(crate); + // This object should have exactly the same set of fields as the "row" + // object defined below. Your JavaScript runtime will thank you. + // https://mathiasbynens.be/notes/shapes-ics + var crateRow = { + crate: crate, + ty: 1, // == ExternCrate + name: crate, + path: "", + desc: rawSearchIndex[crate].doc, + parent: undefined, + type: null, + id: id, + normalizedName: crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""), + }; + id += 1; + searchIndex.push(crateRow); + currentIndex += 1; + + // an array of (Number) item types + var itemTypes = rawSearchIndex[crate].t; + // an array of (String) item names + var itemNames = rawSearchIndex[crate].n; + // an array of (String) full paths (or empty string for previous path) + var itemPaths = rawSearchIndex[crate].q; + // an array of (String) descriptions + var itemDescs = rawSearchIndex[crate].d; + // an array of (Number) the parent path index + 1 to `paths`, or 0 if none + var itemParentIdxs = rawSearchIndex[crate].i; + // an array of (Object | null) the type of the function, if any + var itemFunctionSearchTypes = rawSearchIndex[crate].f; + // an array of [(Number) item type, + // (String) name] + var paths = rawSearchIndex[crate].p; + // a array of [(String) alias name + // [Number] index to items] + var aliases = rawSearchIndex[crate].a; + + // convert `rawPaths` entries into object form + var len = paths.length; + for (i = 0; i < len; ++i) { + paths[i] = {ty: paths[i][0], name: paths[i][1]}; + } + + // convert `item*` into an object form, and construct word indices. + // + // before any analysis is performed lets gather the search terms to + // search against apart from the rest of the data. This is a quick + // operation that is cached for the life of the page state so that + // all other search operations have access to this cached data for + // faster analysis operations + len = itemTypes.length; + var lastPath = ""; + for (i = 0; i < len; ++i) { + // This object should have exactly the same set of fields as the "crateRow" + // object defined above. + if (typeof itemNames[i] === "string") { + word = itemNames[i].toLowerCase(); + searchWords.push(word); + } else { + word = ""; + searchWords.push(""); + } + var row = { + crate: crate, + ty: itemTypes[i], + name: itemNames[i], + path: itemPaths[i] ? itemPaths[i] : lastPath, + desc: itemDescs[i], + parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, + type: itemFunctionSearchTypes[i], + id: id, + normalizedName: word.indexOf("_") === -1 ? word : word.replace(/_/g, ""), + }; + id += 1; + searchIndex.push(row); + lastPath = row.path; + crateSize += 1; + } + + if (aliases) { + ALIASES[crate] = {}; + var j, local_aliases; + for (var alias_name in aliases) { + if (!hasOwnPropertyRustdoc(aliases, alias_name)) { + continue; + } + + if (!hasOwnPropertyRustdoc(ALIASES[crate], alias_name)) { + ALIASES[crate][alias_name] = []; + } + local_aliases = aliases[alias_name]; + for (j = 0, len = local_aliases.length; j < len; ++j) { + ALIASES[crate][alias_name].push(local_aliases[j] + currentIndex); + } + } + } + currentIndex += crateSize; + } + return searchWords; + } + + function registerSearchEvents() { + var searchAfter500ms = function() { + searchState.clearInputTimeout(); + if (searchState.input.value.length === 0) { + if (searchState.browserSupportsHistoryApi()) { + history.replaceState("", window.currentCrate + " - Rust", + getNakedUrl() + window.location.hash); + } + searchState.hideResults(); + } else { + searchState.timeout = setTimeout(search, 500); + } + }; + searchState.input.onkeyup = searchAfter500ms; + searchState.input.oninput = searchAfter500ms; + document.getElementsByClassName("search-form")[0].onsubmit = function(e) { + e.preventDefault(); + searchState.clearInputTimeout(); + search(); + }; + searchState.input.onchange = function(e) { + if (e.target !== document.activeElement) { + // To prevent doing anything when it's from a blur event. + return; + } + // Do NOT e.preventDefault() here. It will prevent pasting. + searchState.clearInputTimeout(); + // zero-timeout necessary here because at the time of event handler execution the + // pasted content is not in the input field yet. Shouldn’t make any difference for + // change, though. + setTimeout(search, 0); + }; + searchState.input.onpaste = searchState.input.onchange; + + searchState.outputElement().addEventListener("keydown", function(e) { + // We only handle unmodified keystrokes here. We don't want to interfere with, + // for instance, alt-left and alt-right for history navigation. + if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) { + return; + } + // up and down arrow select next/previous search result, or the + // search box if we're already at the top. + if (e.which === 38) { // up + var previous = document.activeElement.previousElementSibling; + if (previous) { + previous.focus(); + } else { + searchState.focus(); + } + e.preventDefault(); + } else if (e.which === 40) { // down + var next = document.activeElement.nextElementSibling; + if (next) { + next.focus(); + } + var rect = document.activeElement.getBoundingClientRect(); + if (window.innerHeight - rect.bottom < rect.height) { + window.scrollBy(0, rect.height); + } + e.preventDefault(); + } else if (e.which === 37) { // left + nextTab(-1); + e.preventDefault(); + } else if (e.which === 39) { // right + nextTab(1); + e.preventDefault(); + } + }); + + searchState.input.addEventListener("keydown", function(e) { + if (e.which === 40) { // down + focusSearchResult(); + e.preventDefault(); + } + }); + + + var selectCrate = document.getElementById("crate-search"); + if (selectCrate) { + selectCrate.onchange = function() { + updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value); + // In case you "cut" the entry from the search input, then change the crate filter + // before paste back the previous search, you get the old search results without + // the filter. To prevent this, we need to remove the previous results. + currentResults = null; + search(undefined, true); + }; + } + + // Push and pop states are used to add search results to the browser + // history. + if (searchState.browserSupportsHistoryApi()) { + // Store the previous so we can revert back to it later. + var previousTitle = document.title; + + window.addEventListener("popstate", function(e) { + var params = searchState.getQueryStringParams(); + // Revert to the previous title manually since the History + // API ignores the title parameter. + document.title = previousTitle; + // When browsing forward to search results the previous + // search will be repeated, so the currentResults are + // cleared to ensure the search is successful. + currentResults = null; + // Synchronize search bar with query string state and + // perform the search. This will empty the bar if there's + // nothing there, which lets you really go back to a + // previous state with nothing in the bar. + if (params.search && params.search.length > 0) { + searchState.input.value = params.search; + // Some browsers fire "onpopstate" for every page load + // (Chrome), while others fire the event only when actually + // popping a state (Firefox), which is why search() is + // called both here and at the end of the startSearch() + // function. + search(e); + } else { + searchState.input.value = ""; + // When browsing back from search results the main page + // visibility must be reset. + searchState.hideResults(); + } + }); + } + + // This is required in firefox to avoid this problem: Navigating to a search result + // with the keyboard, hitting enter, and then hitting back would take you back to + // the doc page, rather than the search that should overlay it. + // This was an interaction between the back-forward cache and our handlers + // that try to sync state between the URL and the search input. To work around it, + // do a small amount of re-init on page show. + window.onpageshow = function(){ + var qSearch = searchState.getQueryStringParams().search; + if (searchState.input.value === "" && qSearch) { + searchState.input.value = qSearch; + } + search(); + }; + } + + index = buildIndex(rawSearchIndex); + registerSearchEvents(); + // If there's a search term in the URL, execute the search now. + if (searchState.getQueryStringParams().search) { + search(); + } +}; + +if (window.searchIndex !== undefined) { + initSearch(window.searchIndex); +} + +})(); diff --git a/src/librustdoc/html/static/js/settings.js b/src/librustdoc/html/static/js/settings.js new file mode 100644 index 00000000000..4f10e14e855 --- /dev/null +++ b/src/librustdoc/html/static/js/settings.js @@ -0,0 +1,60 @@ +// Local js definitions: +/* global getSettingValue, getVirtualKey, onEachLazy, updateLocalStorage, updateSystemTheme */ + +(function () { + function changeSetting(settingName, value) { + updateLocalStorage("rustdoc-" + settingName, value); + + switch (settingName) { + case "preferred-dark-theme": + case "preferred-light-theme": + case "use-system-theme": + updateSystemTheme(); + break; + } + } + + function handleKey(ev) { + // Don't interfere with browser shortcuts + if (ev.ctrlKey || ev.altKey || ev.metaKey) { + return; + } + switch (getVirtualKey(ev)) { + case "Enter": + case "Return": + case "Space": + ev.target.checked = !ev.target.checked; + ev.preventDefault(); + break; + } + } + + function setEvents() { + onEachLazy(document.getElementsByClassName("slider"), function(elem) { + var toggle = elem.previousElementSibling; + var settingId = toggle.id; + var settingValue = getSettingValue(settingId); + if (settingValue !== null) { + toggle.checked = settingValue === "true"; + } + toggle.onchange = function() { + changeSetting(this.id, this.checked); + }; + toggle.onkeyup = handleKey; + toggle.onkeyrelease = handleKey; + }); + onEachLazy(document.getElementsByClassName("select-wrapper"), function(elem) { + var select = elem.getElementsByTagName("select")[0]; + var settingId = select.id; + var settingValue = getSettingValue(settingId); + if (settingValue !== null) { + select.value = settingValue; + } + select.onchange = function() { + changeSetting(this.id, this.value); + }; + }); + } + + window.addEventListener("DOMContentLoaded", setEvents); +})(); diff --git a/src/librustdoc/html/static/js/source-script.js b/src/librustdoc/html/static/js/source-script.js new file mode 100644 index 00000000000..4d9a59f836b --- /dev/null +++ b/src/librustdoc/html/static/js/source-script.js @@ -0,0 +1,249 @@ +// From rust: +/* global search, sourcesIndex */ + +// Local js definitions: +/* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, searchState */ +/* global updateLocalStorage */ +(function() { + +function getCurrentFilePath() { + var parts = window.location.pathname.split("/"); + var rootPathParts = window.rootPath.split("/"); + + for (var i = 0, len = rootPathParts.length; i < len; ++i) { + if (rootPathParts[i] === "..") { + parts.pop(); + } + } + var file = window.location.pathname.substring(parts.join("/").length); + if (file.startsWith("/")) { + file = file.substring(1); + } + return file.substring(0, file.length - 5); +} + +function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { + var name = document.createElement("div"); + name.className = "name"; + + fullPath += elem["name"] + "/"; + + name.onclick = function() { + if (hasClass(this, "expand")) { + removeClass(this, "expand"); + } else { + addClass(this, "expand"); + } + }; + name.innerText = elem["name"]; + + var i, len; + + var children = document.createElement("div"); + children.className = "children"; + var folders = document.createElement("div"); + folders.className = "folders"; + if (elem.dirs) { + for (i = 0, len = elem.dirs.length; i < len; ++i) { + if (createDirEntry(elem.dirs[i], folders, fullPath, currentFile, + hasFoundFile)) { + addClass(name, "expand"); + hasFoundFile = true; + } + } + } + children.appendChild(folders); + + var files = document.createElement("div"); + files.className = "files"; + if (elem.files) { + for (i = 0, len = elem.files.length; i < len; ++i) { + var file = document.createElement("a"); + file.innerText = elem.files[i]; + file.href = window.rootPath + "src/" + fullPath + elem.files[i] + ".html"; + if (!hasFoundFile && currentFile === fullPath + elem.files[i]) { + file.className = "selected"; + addClass(name, "expand"); + hasFoundFile = true; + } + files.appendChild(file); + } + } + search.fullPath = fullPath; + children.appendChild(files); + parent.appendChild(name); + parent.appendChild(children); + return hasFoundFile && currentFile.startsWith(fullPath); +} + +function toggleSidebar() { + var sidebar = document.getElementById("source-sidebar"); + var child = this.children[0].children[0]; + if (child.innerText === ">") { + sidebar.style.left = ""; + this.style.left = ""; + child.innerText = "<"; + updateLocalStorage("rustdoc-source-sidebar-show", "true"); + } else { + sidebar.style.left = "-300px"; + this.style.left = "0"; + child.innerText = ">"; + updateLocalStorage("rustdoc-source-sidebar-show", "false"); + } +} + +function createSidebarToggle() { + var sidebarToggle = document.createElement("div"); + sidebarToggle.id = "sidebar-toggle"; + sidebarToggle.onclick = toggleSidebar; + + var inner1 = document.createElement("div"); + inner1.style.position = "relative"; + + var inner2 = document.createElement("div"); + inner2.style.paddingTop = "3px"; + if (getCurrentValue("rustdoc-source-sidebar-show") === "true") { + inner2.innerText = "<"; + } else { + inner2.innerText = ">"; + sidebarToggle.style.left = "0"; + } + + inner1.appendChild(inner2); + sidebarToggle.appendChild(inner1); + return sidebarToggle; +} + +// This function is called from "source-files.js", generated in `html/render/mod.rs`. +// eslint-disable-next-line no-unused-vars +function createSourceSidebar() { + if (!window.rootPath.endsWith("/")) { + window.rootPath += "/"; + } + var main = document.getElementById("main"); + + var sidebarToggle = createSidebarToggle(); + main.insertBefore(sidebarToggle, main.firstChild); + + var sidebar = document.createElement("div"); + sidebar.id = "source-sidebar"; + if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") { + sidebar.style.left = "-300px"; + } + + var currentFile = getCurrentFilePath(); + var hasFoundFile = false; + + var title = document.createElement("div"); + title.className = "title"; + title.innerText = "Files"; + sidebar.appendChild(title); + Object.keys(sourcesIndex).forEach(function(key) { + sourcesIndex[key].name = key; + hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", + currentFile, hasFoundFile); + }); + + main.insertBefore(sidebar, main.firstChild); + // Focus on the current file in the source files sidebar. + var selected_elem = sidebar.getElementsByClassName("selected")[0]; + if (typeof selected_elem !== "undefined") { + selected_elem.focus(); + } +} + +var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/; + +function highlightSourceLines(scrollTo, match) { + if (typeof match === "undefined") { + match = window.location.hash.match(lineNumbersRegex); + } + if (!match) { + return; + } + var from = parseInt(match[1], 10); + var to = from; + if (typeof match[2] !== "undefined") { + to = parseInt(match[2], 10); + } + if (to < from) { + var tmp = to; + to = from; + from = tmp; + } + var elem = document.getElementById(from); + if (!elem) { + return; + } + if (scrollTo) { + var x = document.getElementById(from); + if (x) { + x.scrollIntoView(); + } + } + onEachLazy(document.getElementsByClassName("line-numbers"), function(e) { + onEachLazy(e.getElementsByTagName("span"), function(i_e) { + removeClass(i_e, "line-highlighted"); + }); + }); + for (var i = from; i <= to; ++i) { + elem = document.getElementById(i); + if (!elem) { + break; + } + addClass(elem, "line-highlighted"); + } +} + +var handleSourceHighlight = (function() { + var prev_line_id = 0; + + var set_fragment = function(name) { + var x = window.scrollX, + y = window.scrollY; + if (searchState.browserSupportsHistoryApi()) { + history.replaceState(null, null, "#" + name); + highlightSourceLines(true); + } else { + location.replace("#" + name); + } + // Prevent jumps when selecting one or many lines + window.scrollTo(x, y); + }; + + return function(ev) { + var cur_line_id = parseInt(ev.target.id, 10); + ev.preventDefault(); + + if (ev.shiftKey && prev_line_id) { + // Swap selection if needed + if (prev_line_id > cur_line_id) { + var tmp = prev_line_id; + prev_line_id = cur_line_id; + cur_line_id = tmp; + } + + set_fragment(prev_line_id + "-" + cur_line_id); + } else { + prev_line_id = cur_line_id; + + set_fragment(cur_line_id); + } + }; +}()); + +window.addEventListener("hashchange", function() { + var match = window.location.hash.match(lineNumbersRegex); + if (match) { + return highlightSourceLines(false, match); + } +}); + +onEachLazy(document.getElementsByClassName("line-numbers"), function(el) { + el.addEventListener("click", handleSourceHighlight); +}); + +highlightSourceLines(true); + +window.createSourceSidebar = createSourceSidebar; +})(); diff --git a/src/librustdoc/html/static/js/storage.js b/src/librustdoc/html/static/js/storage.js new file mode 100644 index 00000000000..2eaa81a97d8 --- /dev/null +++ b/src/librustdoc/html/static/js/storage.js @@ -0,0 +1,219 @@ +// From rust: +/* global resourcesSuffix */ +var darkThemes = ["dark", "ayu"]; +window.currentTheme = document.getElementById("themeStyle"); +window.mainTheme = document.getElementById("mainThemeStyle"); + +var settingsDataset = (function () { + var settingsElement = document.getElementById("default-settings"); + if (settingsElement === null) { + return null; + } + var dataset = settingsElement.dataset; + if (dataset === undefined) { + return null; + } + return dataset; +})(); + +function getSettingValue(settingName) { + var current = getCurrentValue('rustdoc-' + settingName); + if (current !== null) { + return current; + } + if (settingsDataset !== null) { + var def = settingsDataset[settingName.replace(/-/g,'_')]; + if (def !== undefined) { + return def; + } + } + return null; +} + +var localStoredTheme = getSettingValue("theme"); + +var savedHref = []; + +// eslint-disable-next-line no-unused-vars +function hasClass(elem, className) { + return elem && elem.classList && elem.classList.contains(className); +} + +// eslint-disable-next-line no-unused-vars +function addClass(elem, className) { + if (!elem || !elem.classList) { + return; + } + elem.classList.add(className); +} + +// eslint-disable-next-line no-unused-vars +function removeClass(elem, className) { + if (!elem || !elem.classList) { + return; + } + elem.classList.remove(className); +} + +function onEach(arr, func, reversed) { + if (arr && arr.length > 0 && func) { + var length = arr.length; + var i; + if (reversed) { + for (i = length - 1; i >= 0; --i) { + if (func(arr[i])) { + return true; + } + } + } else { + for (i = 0; i < length; ++i) { + if (func(arr[i])) { + return true; + } + } + } + } + return false; +} + +function onEachLazy(lazyArray, func, reversed) { + return onEach( + Array.prototype.slice.call(lazyArray), + func, + reversed); +} + +// eslint-disable-next-line no-unused-vars +function hasOwnPropertyRustdoc(obj, property) { + return Object.prototype.hasOwnProperty.call(obj, property); +} + +function updateLocalStorage(name, value) { + try { + window.localStorage.setItem(name, value); + } catch(e) { + // localStorage is not accessible, do nothing + } +} + +function getCurrentValue(name) { + try { + return window.localStorage.getItem(name); + } catch(e) { + return null; + } +} + +function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) { + var fullBasicCss = "rustdoc" + resourcesSuffix + ".css"; + var fullNewTheme = newTheme + resourcesSuffix + ".css"; + var newHref = mainStyleElem.href.replace(fullBasicCss, fullNewTheme); + + // If this new value comes from a system setting or from the previously + // saved theme, no need to save it. + if (saveTheme) { + updateLocalStorage("rustdoc-theme", newTheme); + } + + if (styleElem.href === newHref) { + return; + } + + var found = false; + if (savedHref.length === 0) { + onEachLazy(document.getElementsByTagName("link"), function(el) { + savedHref.push(el.href); + }); + } + onEach(savedHref, function(el) { + if (el === newHref) { + found = true; + return true; + } + }); + if (found) { + styleElem.href = newHref; + } +} + +// This function is called from "main.js". +// eslint-disable-next-line no-unused-vars +function useSystemTheme(value) { + if (value === undefined) { + value = true; + } + + updateLocalStorage("rustdoc-use-system-theme", value); + + // update the toggle if we're on the settings page + var toggle = document.getElementById("use-system-theme"); + if (toggle && toggle instanceof HTMLInputElement) { + toggle.checked = value; + } +} + +var updateSystemTheme = (function() { + if (!window.matchMedia) { + // fallback to the CSS computed value + return function() { + var cssTheme = getComputedStyle(document.documentElement) + .getPropertyValue('content'); + + switchTheme( + window.currentTheme, + window.mainTheme, + JSON.parse(cssTheme) || "light", + true + ); + }; + } + + // only listen to (prefers-color-scheme: dark) because light is the default + var mql = window.matchMedia("(prefers-color-scheme: dark)"); + + function handlePreferenceChange(mql) { + // maybe the user has disabled the setting in the meantime! + if (getSettingValue("use-system-theme") !== "false") { + var lightTheme = getSettingValue("preferred-light-theme") || "light"; + var darkTheme = getSettingValue("preferred-dark-theme") || "dark"; + + if (mql.matches) { + // prefers a dark theme + switchTheme(window.currentTheme, window.mainTheme, darkTheme, true); + } else { + // prefers a light theme, or has no preference + switchTheme(window.currentTheme, window.mainTheme, lightTheme, true); + } + + // note: we save the theme so that it doesn't suddenly change when + // the user disables "use-system-theme" and reloads the page or + // navigates to another page + } + } + + mql.addListener(handlePreferenceChange); + + return function() { + handlePreferenceChange(mql); + }; +})(); + +if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) { + // update the preferred dark theme if the user is already using a dark theme + // See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732 + if (getSettingValue("use-system-theme") === null + && getSettingValue("preferred-dark-theme") === null + && darkThemes.indexOf(localStoredTheme) >= 0) { + updateLocalStorage("rustdoc-preferred-dark-theme", localStoredTheme); + } + + // call the function to initialize the theme at least once! + updateSystemTheme(); +} else { + switchTheme( + window.currentTheme, + window.mainTheme, + getSettingValue("theme") || "light", + false + ); +} diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js deleted file mode 100644 index 98128878999..00000000000 --- a/src/librustdoc/html/static/main.js +++ /dev/null @@ -1,1018 +0,0 @@ -// Local js definitions: -/* global addClass, getSettingValue, hasClass, searchState */ -/* global onEach, onEachLazy, removeClass */ -/* global switchTheme, useSystemTheme */ - -if (!String.prototype.startsWith) { - String.prototype.startsWith = function(searchString, position) { - position = position || 0; - return this.indexOf(searchString, position) === position; - }; -} -if (!String.prototype.endsWith) { - String.prototype.endsWith = function(suffix, length) { - var l = length || this.length; - return this.indexOf(suffix, l - suffix.length) !== -1; - }; -} - -if (!DOMTokenList.prototype.add) { - DOMTokenList.prototype.add = function(className) { - if (className && !hasClass(this, className)) { - if (this.className && this.className.length > 0) { - this.className += " " + className; - } else { - this.className = className; - } - } - }; -} - -if (!DOMTokenList.prototype.remove) { - DOMTokenList.prototype.remove = function(className) { - if (className && this.className) { - this.className = (" " + this.className + " ").replace(" " + className + " ", " ") - .trim(); - } - }; -} - -(function () { - var rustdocVars = document.getElementById("rustdoc-vars"); - if (rustdocVars) { - window.rootPath = rustdocVars.attributes["data-root-path"].value; - window.currentCrate = rustdocVars.attributes["data-current-crate"].value; - window.searchJS = rustdocVars.attributes["data-search-js"].value; - window.searchIndexJS = rustdocVars.attributes["data-search-index-js"].value; - } - var sidebarVars = document.getElementById("sidebar-vars"); - if (sidebarVars) { - window.sidebarCurrent = { - name: sidebarVars.attributes["data-name"].value, - ty: sidebarVars.attributes["data-ty"].value, - relpath: sidebarVars.attributes["data-relpath"].value, - }; - } -}()); - -// Gets the human-readable string for the virtual-key code of the -// given KeyboardEvent, ev. -// -// This function is meant as a polyfill for KeyboardEvent#key, -// since it is not supported in IE 11 or Chrome for Android. We also test for -// KeyboardEvent#keyCode because the handleShortcut handler is -// also registered for the keydown event, because Blink doesn't fire -// keypress on hitting the Escape key. -// -// So I guess you could say things are getting pretty interoperable. -function getVirtualKey(ev) { - if ("key" in ev && typeof ev.key != "undefined") { - return ev.key; - } - - var c = ev.charCode || ev.keyCode; - if (c == 27) { - return "Escape"; - } - return String.fromCharCode(c); -} - -var THEME_PICKER_ELEMENT_ID = "theme-picker"; -var THEMES_ELEMENT_ID = "theme-choices"; - -function getThemesElement() { - return document.getElementById(THEMES_ELEMENT_ID); -} - -function getThemePickerElement() { - return document.getElementById(THEME_PICKER_ELEMENT_ID); -} - -// Returns the current URL without any query parameter or hash. -function getNakedUrl() { - return window.location.href.split("?")[0].split("#")[0]; -} - -function showThemeButtonState() { - var themePicker = getThemePickerElement(); - var themeChoices = getThemesElement(); - - themeChoices.style.display = "block"; - themePicker.style.borderBottomRightRadius = "0"; - themePicker.style.borderBottomLeftRadius = "0"; -} - -function hideThemeButtonState() { - var themePicker = getThemePickerElement(); - var themeChoices = getThemesElement(); - - themeChoices.style.display = "none"; - themePicker.style.borderBottomRightRadius = "3px"; - themePicker.style.borderBottomLeftRadius = "3px"; -} - -// Set up the theme picker list. -(function () { - var themeChoices = getThemesElement(); - var themePicker = getThemePickerElement(); - var availableThemes/* INSERT THEMES HERE */; - - function switchThemeButtonState() { - if (themeChoices.style.display === "block") { - hideThemeButtonState(); - } else { - showThemeButtonState(); - } - } - - function handleThemeButtonsBlur(e) { - var active = document.activeElement; - var related = e.relatedTarget; - - if (active.id !== THEME_PICKER_ELEMENT_ID && - (!active.parentNode || active.parentNode.id !== THEMES_ELEMENT_ID) && - (!related || - (related.id !== THEME_PICKER_ELEMENT_ID && - (!related.parentNode || related.parentNode.id !== THEMES_ELEMENT_ID)))) { - hideThemeButtonState(); - } - } - - themePicker.onclick = switchThemeButtonState; - themePicker.onblur = handleThemeButtonsBlur; - availableThemes.forEach(function(item) { - var but = document.createElement("button"); - but.textContent = item; - but.onclick = function() { - switchTheme(window.currentTheme, window.mainTheme, item, true); - useSystemTheme(false); - }; - but.onblur = handleThemeButtonsBlur; - themeChoices.appendChild(but); - }); -}()); - -(function() { - "use strict"; - - window.searchState = { - loadingText: "Loading search results...", - input: document.getElementsByClassName("search-input")[0], - outputElement: function() { - return document.getElementById("search"); - }, - title: document.title, - titleBeforeSearch: document.title, - timeout: null, - // On the search screen, so you remain on the last tab you opened. - // - // 0 for "In Names" - // 1 for "In Parameters" - // 2 for "In Return Types" - currentTab: 0, - // tab and back preserves the element that was focused. - focusedByTab: [null, null, null], - clearInputTimeout: function() { - if (searchState.timeout !== null) { - clearTimeout(searchState.timeout); - searchState.timeout = null; - } - }, - // Sets the focus on the search bar at the top of the page - focus: function() { - searchState.input.focus(); - }, - // Removes the focus from the search bar. - defocus: function() { - searchState.input.blur(); - }, - showResults: function(search) { - if (search === null || typeof search === 'undefined') { - search = searchState.outputElement(); - } - addClass(main, "hidden"); - removeClass(search, "hidden"); - searchState.mouseMovedAfterSearch = false; - document.title = searchState.title; - }, - hideResults: function(search) { - if (search === null || typeof search === 'undefined') { - search = searchState.outputElement(); - } - addClass(search, "hidden"); - removeClass(main, "hidden"); - document.title = searchState.titleBeforeSearch; - // We also remove the query parameter from the URL. - if (searchState.browserSupportsHistoryApi()) { - history.replaceState("", window.currentCrate + " - Rust", - getNakedUrl() + window.location.hash); - } - }, - getQueryStringParams: function() { - var params = {}; - window.location.search.substring(1).split("&"). - map(function(s) { - var pair = s.split("="); - params[decodeURIComponent(pair[0])] = - typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]); - }); - return params; - }, - putBackSearch: function(search_input) { - var search = searchState.outputElement(); - if (search_input.value !== "" && hasClass(search, "hidden")) { - searchState.showResults(search); - if (searchState.browserSupportsHistoryApi()) { - var extra = "?search=" + encodeURIComponent(search_input.value); - history.replaceState(search_input.value, "", - getNakedUrl() + extra + window.location.hash); - } - document.title = searchState.title; - } - }, - browserSupportsHistoryApi: function() { - return window.history && typeof window.history.pushState === "function"; - }, - setup: function() { - var search_input = searchState.input; - if (!searchState.input) { - return; - } - function loadScript(url) { - var script = document.createElement('script'); - script.src = url; - document.head.append(script); - } - - var searchLoaded = false; - function loadSearch() { - if (!searchLoaded) { - searchLoaded = true; - loadScript(window.searchJS); - loadScript(window.searchIndexJS); - } - } - - search_input.addEventListener("focus", function() { - searchState.putBackSearch(this); - search_input.origPlaceholder = searchState.input.placeholder; - search_input.placeholder = "Type your search here."; - loadSearch(); - }); - search_input.addEventListener("blur", function() { - search_input.placeholder = searchState.input.origPlaceholder; - }); - - search_input.removeAttribute('disabled'); - - // `crates{version}.js` should always be loaded before this script, so we can use it - // safely. - searchState.addCrateDropdown(window.ALL_CRATES); - var params = searchState.getQueryStringParams(); - if (params.search !== undefined) { - var search = searchState.outputElement(); - search.innerHTML = "<h3 style=\"text-align: center;\">" + - searchState.loadingText + "</h3>"; - searchState.showResults(search); - loadSearch(); - } - }, - addCrateDropdown: function(crates) { - var elem = document.getElementById("crate-search"); - - if (!elem) { - return; - } - var savedCrate = getSettingValue("saved-filter-crate"); - for (var i = 0, len = crates.length; i < len; ++i) { - var option = document.createElement("option"); - option.value = crates[i]; - option.innerText = crates[i]; - elem.appendChild(option); - // Set the crate filter from saved storage, if the current page has the saved crate - // filter. - // - // If not, ignore the crate filter -- we want to support filtering for crates on - // sites like doc.rust-lang.org where the crates may differ from page to page while - // on the - // same domain. - if (crates[i] === savedCrate) { - elem.value = savedCrate; - } - } - }, - }; - - function getPageId() { - if (window.location.hash) { - var tmp = window.location.hash.replace(/^#/, ""); - if (tmp.length > 0) { - return tmp; - } - } - return null; - } - - function showSidebar() { - var elems = document.getElementsByClassName("sidebar-elems")[0]; - if (elems) { - addClass(elems, "show-it"); - } - var sidebar = document.getElementsByClassName("sidebar")[0]; - if (sidebar) { - addClass(sidebar, "mobile"); - var filler = document.getElementById("sidebar-filler"); - if (!filler) { - var div = document.createElement("div"); - div.id = "sidebar-filler"; - sidebar.appendChild(div); - } - } - } - - function hideSidebar() { - var elems = document.getElementsByClassName("sidebar-elems")[0]; - if (elems) { - removeClass(elems, "show-it"); - } - var sidebar = document.getElementsByClassName("sidebar")[0]; - removeClass(sidebar, "mobile"); - var filler = document.getElementById("sidebar-filler"); - if (filler) { - filler.remove(); - } - document.getElementsByTagName("body")[0].style.marginTop = ""; - } - - var toggleAllDocsId = "toggle-all-docs"; - var main = document.getElementById("main"); - var savedHash = ""; - - function handleHashes(ev) { - var elem; - var search = searchState.outputElement(); - if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) { - // This block occurs when clicking on an element in the navbar while - // in a search. - searchState.hideResults(search); - var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1); - if (searchState.browserSupportsHistoryApi()) { - // `window.location.search`` contains all the query parameters, not just `search`. - history.replaceState(hash, "", - getNakedUrl() + window.location.search + "#" + hash); - } - elem = document.getElementById(hash); - if (elem) { - elem.scrollIntoView(); - } - } - // This part is used in case an element is not visible. - if (savedHash !== window.location.hash) { - savedHash = window.location.hash; - if (savedHash.length === 0) { - return; - } - expandSection(savedHash.slice(1)); // we remove the '#' - } - } - - function onHashChange(ev) { - // If we're in mobile mode, we should hide the sidebar in any case. - hideSidebar(); - handleHashes(ev); - } - - function openParentDetails(elem) { - while (elem) { - if (elem.tagName === "DETAILS") { - elem.open = true; - } - elem = elem.parentNode; - } - } - - function expandSection(id) { - openParentDetails(document.getElementById(id)); - } - - function getHelpElement(build) { - if (build) { - buildHelperPopup(); - } - return document.getElementById("help"); - } - - function displayHelp(display, ev, help) { - if (display) { - help = help ? help : getHelpElement(true); - if (hasClass(help, "hidden")) { - ev.preventDefault(); - removeClass(help, "hidden"); - addClass(document.body, "blur"); - } - } else { - // No need to build the help popup if we want to hide it in case it hasn't been - // built yet... - help = help ? help : getHelpElement(false); - if (help && !hasClass(help, "hidden")) { - ev.preventDefault(); - addClass(help, "hidden"); - removeClass(document.body, "blur"); - } - } - } - - function handleEscape(ev) { - var help = getHelpElement(false); - var search = searchState.outputElement(); - if (help && !hasClass(help, "hidden")) { - displayHelp(false, ev, help); - } else if (search && !hasClass(search, "hidden")) { - searchState.clearInputTimeout(); - ev.preventDefault(); - searchState.hideResults(search); - } - searchState.defocus(); - hideThemeButtonState(); - } - - var disableShortcuts = getSettingValue("disable-shortcuts") === "true"; - function handleShortcut(ev) { - // Don't interfere with browser shortcuts - if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts) { - return; - } - - if (document.activeElement.tagName === "INPUT") { - switch (getVirtualKey(ev)) { - case "Escape": - handleEscape(ev); - break; - } - } else { - switch (getVirtualKey(ev)) { - case "Escape": - handleEscape(ev); - break; - - case "s": - case "S": - displayHelp(false, ev); - ev.preventDefault(); - searchState.focus(); - break; - - case "+": - case "-": - ev.preventDefault(); - toggleAllDocs(); - break; - - case "?": - displayHelp(true, ev); - break; - - case "t": - case "T": - displayHelp(false, ev); - ev.preventDefault(); - var themePicker = getThemePickerElement(); - themePicker.click(); - themePicker.focus(); - break; - - default: - if (getThemePickerElement().parentNode.contains(ev.target)) { - handleThemeKeyDown(ev); - } - } - } - } - - function handleThemeKeyDown(ev) { - var active = document.activeElement; - var themes = getThemesElement(); - switch (getVirtualKey(ev)) { - case "ArrowUp": - ev.preventDefault(); - if (active.previousElementSibling && ev.target.id !== THEME_PICKER_ELEMENT_ID) { - active.previousElementSibling.focus(); - } else { - showThemeButtonState(); - themes.lastElementChild.focus(); - } - break; - case "ArrowDown": - ev.preventDefault(); - if (active.nextElementSibling && ev.target.id !== THEME_PICKER_ELEMENT_ID) { - active.nextElementSibling.focus(); - } else { - showThemeButtonState(); - themes.firstElementChild.focus(); - } - break; - case "Enter": - case "Return": - case "Space": - if (ev.target.id === THEME_PICKER_ELEMENT_ID && themes.style.display === "none") { - ev.preventDefault(); - showThemeButtonState(); - themes.firstElementChild.focus(); - } - break; - case "Home": - ev.preventDefault(); - themes.firstElementChild.focus(); - break; - case "End": - ev.preventDefault(); - themes.lastElementChild.focus(); - break; - // The escape key is handled in handleEscape, not here, - // so that pressing escape will close the menu even if it isn't focused - } - } - - document.addEventListener("keypress", handleShortcut); - document.addEventListener("keydown", handleShortcut); - - (function() { - var x = document.getElementsByClassName("version-selector"); - if (x.length > 0) { - x[0].onchange = function() { - var i, match, - url = document.location.href, - stripped = "", - len = window.rootPath.match(/\.\.\//g).length + 1; - - for (i = 0; i < len; ++i) { - match = url.match(/\/[^/]*$/); - if (i < len - 1) { - stripped = match[0] + stripped; - } - url = url.substring(0, url.length - match[0].length); - } - - var selectedVersion = document.getElementsByClassName("version-selector")[0].value; - url += "/" + selectedVersion + stripped; - - document.location.href = url; - }; - } - }()); - - // delayed sidebar rendering. - window.initSidebarItems = function(items) { - var sidebar = document.getElementsByClassName("sidebar-elems")[0]; - var current = window.sidebarCurrent; - - function addSidebarCrates(crates) { - if (!hasClass(document.body, "crate")) { - // We only want to list crates on the crate page. - return; - } - // Draw a convenient sidebar of known crates if we have a listing - var div = document.createElement("div"); - div.className = "block crate"; - div.innerHTML = "<h3>Crates</h3>"; - var ul = document.createElement("ul"); - div.appendChild(ul); - - for (var i = 0; i < crates.length; ++i) { - var klass = "crate"; - if (window.rootPath !== "./" && crates[i] === window.currentCrate) { - klass += " current"; - } - var link = document.createElement("a"); - link.href = window.rootPath + crates[i] + "/index.html"; - link.className = klass; - link.textContent = crates[i]; - - var li = document.createElement("li"); - li.appendChild(link); - ul.appendChild(li); - } - sidebar.appendChild(div); - } - - function block(shortty, longty) { - var filtered = items[shortty]; - if (!filtered) { - return; - } - - var div = document.createElement("div"); - div.className = "block " + shortty; - var h3 = document.createElement("h3"); - h3.textContent = longty; - div.appendChild(h3); - var ul = document.createElement("ul"); - - for (var i = 0, len = filtered.length; i < len; ++i) { - var item = filtered[i]; - var name = item[0]; - var desc = item[1]; // can be null - - var klass = shortty; - if (name === current.name && shortty === current.ty) { - klass += " current"; - } - var path; - if (shortty === "mod") { - path = name + "/index.html"; - } else { - path = shortty + "." + name + ".html"; - } - var link = document.createElement("a"); - link.href = current.relpath + path; - link.title = desc; - link.className = klass; - link.textContent = name; - var li = document.createElement("li"); - li.appendChild(link); - ul.appendChild(li); - } - div.appendChild(ul); - sidebar.appendChild(div); - } - - if (sidebar) { - var isModule = hasClass(document.body, "mod"); - if (!isModule) { - block("primitive", "Primitive Types"); - block("mod", "Modules"); - block("macro", "Macros"); - block("struct", "Structs"); - block("enum", "Enums"); - block("union", "Unions"); - block("constant", "Constants"); - block("static", "Statics"); - block("trait", "Traits"); - block("fn", "Functions"); - block("type", "Type Definitions"); - block("foreigntype", "Foreign Types"); - block("keyword", "Keywords"); - block("traitalias", "Trait Aliases"); - } - - // `crates{version}.js` should always be loaded before this script, so we can use - // it safely. - addSidebarCrates(window.ALL_CRATES); - } - }; - - window.register_implementors = function(imp) { - var implementors = document.getElementById("implementors-list"); - var synthetic_implementors = document.getElementById("synthetic-implementors-list"); - - if (synthetic_implementors) { - // This `inlined_types` variable is used to avoid having the same implementation - // showing up twice. For example "String" in the "Sync" doc page. - // - // By the way, this is only used by and useful for traits implemented automatically - // (like "Send" and "Sync"). - var inlined_types = new Set(); - onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) { - var aliases = el.getAttribute("data-aliases"); - if (!aliases) { - return; - } - aliases.split(",").forEach(function(alias) { - inlined_types.add(alias); - }); - }); - } - - var libs = Object.getOwnPropertyNames(imp); - for (var i = 0, llength = libs.length; i < llength; ++i) { - if (libs[i] === window.currentCrate) { continue; } - var structs = imp[libs[i]]; - - struct_loop: - for (var j = 0, slength = structs.length; j < slength; ++j) { - var struct = structs[j]; - - var list = struct.synthetic ? synthetic_implementors : implementors; - - if (struct.synthetic) { - for (var k = 0, stlength = struct.types.length; k < stlength; k++) { - if (inlined_types.has(struct.types[k])) { - continue struct_loop; - } - inlined_types.add(struct.types[k]); - } - } - - var code = document.createElement("code"); - code.innerHTML = struct.text; - - onEachLazy(code.getElementsByTagName("a"), function(elem) { - var href = elem.getAttribute("href"); - - if (href && href.indexOf("http") !== 0) { - elem.setAttribute("href", window.rootPath + href); - } - }); - - var display = document.createElement("h3"); - addClass(display, "impl"); - display.innerHTML = "<span class=\"in-band\"><table class=\"table-display\">" + - "<tbody><tr><td><code>" + code.outerHTML + "</code></td><td></td></tr>" + - "</tbody></table></span>"; - list.appendChild(display); - } - } - }; - if (window.pending_implementors) { - window.register_implementors(window.pending_implementors); - } - - function labelForToggleButton(sectionIsCollapsed) { - if (sectionIsCollapsed) { - // button will expand the section - return "+"; - } - // button will collapse the section - // note that this text is also set in the HTML template in ../render/mod.rs - return "\u2212"; // "\u2212" is "−" minus sign - } - - function toggleAllDocs() { - var innerToggle = document.getElementById(toggleAllDocsId); - if (!innerToggle) { - return; - } - var sectionIsCollapsed = false; - if (hasClass(innerToggle, "will-expand")) { - removeClass(innerToggle, "will-expand"); - onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) { - if (!hasClass(e, "type-contents-toggle")) { - e.open = true; - } - }); - innerToggle.title = "collapse all docs"; - } else { - addClass(innerToggle, "will-expand"); - onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function(e) { - if (e.parentNode.id !== "main" || - (!hasClass(e, "implementors-toggle") && - !hasClass(e, "type-contents-toggle"))) - { - e.open = false; - } - }); - sectionIsCollapsed = true; - innerToggle.title = "expand all docs"; - } - innerToggle.children[0].innerText = labelForToggleButton(sectionIsCollapsed); - } - - function insertAfter(newNode, referenceNode) { - referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); - } - - (function() { - var toggles = document.getElementById(toggleAllDocsId); - if (toggles) { - toggles.onclick = toggleAllDocs; - } - - var hideMethodDocs = getSettingValue("auto-hide-method-docs") === "true"; - var hideImplementations = getSettingValue("auto-hide-trait-implementations") === "true"; - var hideLargeItemContents = getSettingValue("auto-hide-large-items") !== "false"; - - function setImplementorsTogglesOpen(id, open) { - var list = document.getElementById(id); - if (list !== null) { - onEachLazy(list.getElementsByClassName("implementors-toggle"), function(e) { - e.open = open; - }); - } - } - - if (hideImplementations) { - setImplementorsTogglesOpen("trait-implementations-list", false); - setImplementorsTogglesOpen("blanket-implementations-list", false); - } - - onEachLazy(document.getElementsByClassName("rustdoc-toggle"), function (e) { - if (!hideLargeItemContents && hasClass(e, "type-contents-toggle")) { - e.open = true; - } - if (hideMethodDocs && hasClass(e, "method-toggle")) { - e.open = false; - } - - }); - - var pageId = getPageId(); - if (pageId !== null) { - expandSection(pageId); - } - }()); - - (function() { - // To avoid checking on "rustdoc-line-numbers" value on every loop... - var lineNumbersFunc = function() {}; - if (getSettingValue("line-numbers") === "true") { - lineNumbersFunc = function(x) { - var count = x.textContent.split("\n").length; - var elems = []; - for (var i = 0; i < count; ++i) { - elems.push(i + 1); - } - var node = document.createElement("pre"); - addClass(node, "line-number"); - node.innerHTML = elems.join("\n"); - x.parentNode.insertBefore(node, x); - }; - } - onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) { - if (hasClass(e, "compile_fail")) { - e.addEventListener("mouseover", function() { - this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00"; - }); - e.addEventListener("mouseout", function() { - this.parentElement.previousElementSibling.childNodes[0].style.color = ""; - }); - } else if (hasClass(e, "ignore")) { - e.addEventListener("mouseover", function() { - this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200"; - }); - e.addEventListener("mouseout", function() { - this.parentElement.previousElementSibling.childNodes[0].style.color = ""; - }); - } - lineNumbersFunc(e); - }); - }()); - - function handleClick(id, f) { - var elem = document.getElementById(id); - if (elem) { - elem.addEventListener("click", f); - } - } - handleClick("help-button", function(ev) { - displayHelp(true, ev); - }); - - onEachLazy(document.getElementsByTagName("a"), function(el) { - // For clicks on internal links (<A> tags with a hash property), we expand the section we're - // jumping to *before* jumping there. We can't do this in onHashChange, because it changes - // the height of the document so we wind up scrolled to the wrong place. - if (el.hash) { - el.addEventListener("click", function() { - expandSection(el.hash.slice(1)); - }); - } - }); - - onEachLazy(document.getElementsByClassName("notable-traits"), function(e) { - e.onclick = function() { - this.getElementsByClassName('notable-traits-tooltiptext')[0] - .classList.toggle("force-tooltip"); - }; - }); - - var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0]; - if (sidebar_menu) { - sidebar_menu.onclick = function() { - var sidebar = document.getElementsByClassName("sidebar")[0]; - if (hasClass(sidebar, "mobile")) { - hideSidebar(); - } else { - showSidebar(); - } - }; - } - - var buildHelperPopup = function() { - var popup = document.createElement("aside"); - addClass(popup, "hidden"); - popup.id = "help"; - - popup.addEventListener("click", function(ev) { - if (ev.target === popup) { - // Clicked the blurred zone outside the help popup; dismiss help. - displayHelp(false, ev); - } - }); - - var book_info = document.createElement("span"); - book_info.innerHTML = "You can find more information in \ - <a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>."; - - var container = document.createElement("div"); - var shortcuts = [ - ["?", "Show this help dialog"], - ["S", "Focus the search field"], - ["T", "Focus the theme picker menu"], - ["↑", "Move up in search results"], - ["↓", "Move down in search results"], - ["← / →", "Switch result tab (when results focused)"], - ["⏎", "Go to active search result"], - ["+", "Expand all sections"], - ["-", "Collapse all sections"], - ].map(function(x) { - return "<dt>" + - x[0].split(" ") - .map(function(y, index) { - return (index & 1) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " "; - }) - .join("") + "</dt><dd>" + x[1] + "</dd>"; - }).join(""); - var div_shortcuts = document.createElement("div"); - addClass(div_shortcuts, "shortcuts"); - div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>"; - - var infos = [ - "Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \ - restrict the search to a given item kind.", - "Accepted kinds are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \ - <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \ - and <code>const</code>.", - "Search functions by type signature (e.g., <code>vec -> usize</code> or \ - <code>* -> vec</code>)", - "Search multiple things at once by splitting your query with comma (e.g., \ - <code>str,u8</code> or <code>String,struct:Vec,test</code>)", - "You can look for items with an exact name by putting double quotes around \ - your request: <code>\"string\"</code>", - "Look for items inside another one by searching for a path: <code>vec::Vec</code>", - ].map(function(x) { - return "<p>" + x + "</p>"; - }).join(""); - var div_infos = document.createElement("div"); - addClass(div_infos, "infos"); - div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos; - - container.appendChild(book_info); - container.appendChild(div_shortcuts); - container.appendChild(div_infos); - - popup.appendChild(container); - insertAfter(popup, searchState.outputElement()); - // So that it's only built once and then it'll do nothing when called! - buildHelperPopup = function() {}; - }; - - onHashChange(null); - window.addEventListener("hashchange", onHashChange); - searchState.setup(); -}()); - -(function () { - var reset_button_timeout = null; - - window.copy_path = function(but) { - var parent = but.parentElement; - var path = []; - - onEach(parent.childNodes, function(child) { - if (child.tagName === 'A') { - path.push(child.textContent); - } - }); - - var el = document.createElement('textarea'); - el.value = 'use ' + path.join('::') + ';'; - el.setAttribute('readonly', ''); - // To not make it appear on the screen. - el.style.position = 'absolute'; - el.style.left = '-9999px'; - - document.body.appendChild(el); - el.select(); - document.execCommand('copy'); - document.body.removeChild(el); - - // There is always one children, but multiple childNodes. - but.children[0].style.display = 'none'; - - var tmp; - if (but.childNodes.length < 2) { - tmp = document.createTextNode('✓'); - but.appendChild(tmp); - } else { - onEachLazy(but.childNodes, function(e) { - if (e.nodeType === Node.TEXT_NODE) { - tmp = e; - return true; - } - }); - tmp.textContent = '✓'; - } - - if (reset_button_timeout !== null) { - window.clearTimeout(reset_button_timeout); - } - - function reset_button() { - tmp.textContent = ''; - reset_button_timeout = null; - but.children[0].style.display = ""; - } - - reset_button_timeout = window.setTimeout(reset_button, 1000); - }; -}()); diff --git a/src/librustdoc/html/static/normalize.css b/src/librustdoc/html/static/normalize.css deleted file mode 100644 index fdb8a8c652e..00000000000 --- a/src/librustdoc/html/static/normalize.css +++ /dev/null @@ -1,2 +0,0 @@ -/* ignore-tidy-linelength */ -/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */ html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:0.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace, monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type="button"],[type="reset"],[type="submit"],button{-webkit-appearance:button}[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none} diff --git a/src/librustdoc/html/static/noscript.css b/src/librustdoc/html/static/noscript.css deleted file mode 100644 index 0a196edd53b..00000000000 --- a/src/librustdoc/html/static/noscript.css +++ /dev/null @@ -1,15 +0,0 @@ -/* -This whole CSS file is used only in case rustdoc is rendered with javascript disabled. Since a lot -of content is hidden by default (depending on the settings too), we have to overwrite some of the -rules. -*/ - -#main .attributes { - /* Since there is no toggle (the "[-]") when JS is disabled, no need for this margin either. */ - margin-left: 0 !important; -} - -#copy-path { - /* It requires JS to work so no need to display it in this case. */ - display: none; -} diff --git a/src/librustdoc/html/static/noto-sans-kr-v13-korean-regular-LICENSE.txt b/src/librustdoc/html/static/noto-sans-kr-v13-korean-regular-LICENSE.txt deleted file mode 100644 index 922d5fdc18d..00000000000 --- a/src/librustdoc/html/static/noto-sans-kr-v13-korean-regular-LICENSE.txt +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2014, 2015 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. - -This Font Software is licensed under the SIL Open Font License, Version 1.1. - -This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/src/librustdoc/html/static/noto-sans-kr-v13-korean-regular.woff b/src/librustdoc/html/static/noto-sans-kr-v13-korean-regular.woff deleted file mode 100644 index 01d6b6b5466..00000000000 Binary files a/src/librustdoc/html/static/noto-sans-kr-v13-korean-regular.woff and /dev/null differ diff --git a/src/librustdoc/html/static/rust-logo.png b/src/librustdoc/html/static/rust-logo.png deleted file mode 100644 index 74b4bd69504..00000000000 Binary files a/src/librustdoc/html/static/rust-logo.png and /dev/null differ diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css deleted file mode 100644 index 71123aa9a0e..00000000000 --- a/src/librustdoc/html/static/rustdoc.css +++ /dev/null @@ -1,1888 +0,0 @@ -/* See FiraSans-LICENSE.txt for the Fira Sans license. */ -@font-face { - font-family: 'Fira Sans'; - font-style: normal; - font-weight: 400; - src: local('Fira Sans'), - url("FiraSans-Regular.woff2") format("woff2"), - url("FiraSans-Regular.woff") format('woff'); - font-display: swap; -} -@font-face { - font-family: 'Fira Sans'; - font-style: normal; - font-weight: 500; - src: local('Fira Sans Medium'), - url("FiraSans-Medium.woff2") format("woff2"), - url("FiraSans-Medium.woff") format('woff'); - font-display: swap; -} - -/* See SourceSerif4-LICENSE.md for the Source Serif 4 license. */ -@font-face { - font-family: 'Source Serif 4'; - font-style: normal; - font-weight: 400; - src: local('Source Serif 4'), - url("SourceSerif4-Regular.ttf.woff2") format("woff2"), - url("SourceSerif4-Regular.ttf.woff") format("woff"); - font-display: swap; -} -@font-face { - font-family: 'Source Serif 4'; - font-style: italic; - font-weight: 400; - src: local('Source Serif 4 Italic'), - url("SourceSerif4-It.ttf.woff2") format("woff2"), - url("SourceSerif4-It.ttf.woff") format("woff"); - font-display: swap; -} -@font-face { - font-family: 'Source Serif 4'; - font-style: normal; - font-weight: 700; - src: local('Source Serif 4 Bold'), - url("SourceSerif4-Bold.ttf.woff2") format("woff2"), - url("SourceSerif4-Bold.ttf.woff") format("woff"); - font-display: swap; -} - -/* See SourceCodePro-LICENSE.txt for the Source Code Pro license. */ -@font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 400; - /* Avoid using locally installed font because bad versions are in circulation: - * see https://github.com/rust-lang/rust/issues/24355 */ - src: url("SourceCodePro-Regular.ttf.woff2") format("woff2"), - url("SourceCodePro-Regular.ttf.woff") format("woff"); - font-display: swap; -} -@font-face { - font-family: 'Source Code Pro'; - font-style: italic; - font-weight: 400; - src: url("SourceCodePro-It.ttf.woff2") format("woff2"), - url("SourceCodePro-It.ttf.woff") format("woff"); - font-display: swap; -} -@font-face { - font-family: 'Source Code Pro'; - font-style: normal; - font-weight: 600; - src: url("SourceCodePro-Semibold.ttf.woff2") format("woff2"), - url("SourceCodePro-Semibold.ttf.woff") format("woff"); - font-display: swap; -} - -/* Avoid using legacy CJK serif fonts in Windows like Batang */ -@font-face { - font-family: 'Noto Sans KR'; - src: url("noto-sans-kr-v13-korean-regular.woff") format("woff"); - font-display: swap; - unicode-range: U+A960-A97F, U+AC00-D7AF, U+D7B0-D7FF; -} - -* { - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box; -} - -/* This part handles the "default" theme being used depending on the system one. */ -html { - content: ""; -} -@media (prefers-color-scheme: light) { - html { - content: "light"; - } -} -@media (prefers-color-scheme: dark) { - html { - content: "dark"; - } -} - -/* General structure and fonts */ - -body { - font: 16px/1.4 "Source Serif 4", "Noto Sans KR", serif; - margin: 0; - position: relative; - padding: 10px 15px 20px 15px; - - -webkit-font-feature-settings: "kern", "liga"; - -moz-font-feature-settings: "kern", "liga"; - font-feature-settings: "kern", "liga"; -} - -h1 { - font-size: 1.5em; -} -h2 { - font-size: 1.4em; -} -h3 { - font-size: 1.3em; -} -h1, h2, h3, h4 { - font-weight: 500; - margin: 20px 0 15px 0; - padding-bottom: 6px; -} -h1.fqn { - display: flex; - border-bottom: 1px dashed; - margin-top: 0; - - /* workaround to keep flex from breaking below 700 px width due to the float: right on the nav - above the h1 */ - padding-left: 1px; -} -h1.fqn > .in-band > a:hover { - text-decoration: underline; -} -h2, h3, h4 { - border-bottom: 1px solid; -} -.impl, -.impl-items .method, -.methods .method, -.impl-items .type, -.methods .type, -.impl-items .associatedconstant, -.methods .associatedconstant, -.impl-items .associatedtype, -.methods .associatedtype { - flex-basis: 100%; - font-weight: 600; - margin-top: 16px; - margin-bottom: 10px; - position: relative; -} -.impl, .method.trait-impl, -.type.trait-impl, -.associatedconstant.trait-impl, -.associatedtype.trait-impl { - padding-left: 15px; -} - -div.impl-items > div { - padding-left: 0; -} - -h1, h2, h3, h4, -.sidebar, a.source, .search-input, .search-results .result-name, -.content table td:first-child > a, -.item-left > a, -div.item-list .out-of-band, span.since, -#source-sidebar, #sidebar-toggle, -details.rustdoc-toggle > summary::before, -details.undocumented > summary::before, -div.impl-items > div:not(.docblock):not(.item-info), -.content ul.crate a.crate, a.srclink, -/* This selector is for the items listed in the "all items" page. */ -#main > ul.docblock > li > a { - font-family: "Fira Sans", Arial, sans-serif; -} - -.content ul.crate a.crate { - font-size: 16px/1.6; -} - -ol, ul { - padding-left: 25px; -} -ul ul, ol ul, ul ol, ol ol { - margin-bottom: .6em; -} - -p { - margin: 0 0 .6em 0; -} - -summary { - outline: none; -} - -/* Fix some style changes due to normalize.css 8 */ - -td, -th { - padding: 0; -} - -table { - border-collapse: collapse; -} - -button, -input, -optgroup, -select, -textarea { - color: inherit; - font: inherit; - margin: 0; -} - -/* end tweaks for normalize.css 8 */ - -details:not(.rustdoc-toggle) summary { - margin-bottom: .6em; -} - -code, pre, a.test-arrow { - font-family: "Source Code Pro", monospace; -} -.docblock code, .docblock-short code { - border-radius: 3px; - padding: 0 0.1em; -} -.docblock pre code, .docblock-short pre code { - padding: 0; - padding-right: 1ex; -} -pre { - padding: 14px; -} - -.source .content pre { - padding: 20px; -} - -img { - max-width: 100%; -} - -li { - position: relative; -} - -.source .content { - margin-top: 50px; - max-width: none; - overflow: visible; - margin-left: 0px; -} - -nav.sub { - font-size: 16px; - text-transform: uppercase; -} - -.sidebar { - width: 200px; - position: fixed; - left: 0; - top: 0; - bottom: 0; - overflow: auto; -} - -/* Improve the scrollbar display on firefox */ -* { - scrollbar-width: initial; -} -.sidebar { - scrollbar-width: thin; -} - -/* Improve the scrollbar display on webkit-based browsers */ -::-webkit-scrollbar { - width: 12px; -} -.sidebar::-webkit-scrollbar { - width: 8px; -} -::-webkit-scrollbar-track { - -webkit-box-shadow: inset 0; -} - -.sidebar .block > ul > li { - margin-right: -10px; -} - -.content, nav { - max-width: 960px; -} - -/* Everything else */ - -.hidden { - display: none !important; -} - -.logo-container { - height: 100px; - width: 100px; - position: relative; - margin: 20px auto; - display: block; - margin-top: 10px; -} - -.logo-container > img { - max-width: 100px; - max-height: 100px; - position: absolute; - left: 50%; - top: 50%; - transform: translate(-50%, -50%); - display: block; -} - -.sidebar .location { - border: 1px solid; - font-size: 17px; - margin: 30px 10px 20px 10px; - text-align: center; - word-wrap: break-word; -} - -.sidebar .version { - font-size: 15px; - text-align: center; - border-bottom: 1px solid; - overflow-wrap: break-word; - word-wrap: break-word; /* deprecated */ - word-break: break-word; /* Chrome, non-standard */ -} - -.location:empty { - border: none; -} - -.location a:first-of-type { - font-weight: 500; -} -.location a:hover { - text-decoration: underline; -} - -.block { - padding: 0; - margin-bottom: 14px; -} -.block h2, .block h3 { - text-align: center; -} -.block ul, .block li { - margin: 0 10px; - padding: 0; - list-style: none; -} - -.block a { - display: block; - text-overflow: ellipsis; - overflow: hidden; - line-height: 15px; - padding: 7px 5px; - font-size: 14px; - font-weight: 300; - transition: border 500ms ease-out; -} - -.sidebar-title { - border-top: 1px solid; - border-bottom: 1px solid; - text-align: center; - font-size: 17px; - margin-bottom: 5px; -} - -.sidebar-links { - margin-bottom: 15px; -} - -.sidebar-links > a { - padding-left: 10px; - width: 100%; -} - -.sidebar-menu { - display: none; -} - -.content { - padding: 15px 0; -} - -.source .content pre.rust { - white-space: pre; - overflow: auto; - padding-left: 0; -} - -.rustdoc .example-wrap { - display: inline-flex; - margin-bottom: 10px; -} - -.example-wrap { - position: relative; - width: 100%; -} - -.example-wrap > pre.line-number { - overflow: initial; - border: 1px solid; - padding: 13px 8px; - text-align: right; - border-top-left-radius: 5px; - border-bottom-left-radius: 5px; -} - -.rustdoc:not(.source) .example-wrap > pre.rust { - width: 100%; - overflow-x: auto; -} - -.rustdoc .example-wrap > pre { - margin: 0; -} - -#search { - margin-left: 230px; - position: relative; -} - -#results > table { - width: 100%; - table-layout: fixed; -} - -.content > .example-wrap pre.line-numbers { - position: relative; - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} -.line-numbers span { - cursor: pointer; -} - -.docblock-short { - overflow-wrap: anywhere; -} -.docblock-short p { - display: inline; -} - -.docblock-short p { - overflow: hidden; - text-overflow: ellipsis; - margin: 0; -} -/* Wrap non-pre code blocks (`text`) but not (```text```). */ -.docblock > :not(pre) > code, -.docblock-short > :not(pre) > code { - white-space: pre-wrap; -} - -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { - border-bottom: 1px solid; -} - -.top-doc .docblock h1 { font-size: 1.3em; } -.top-doc .docblock h2 { font-size: 1.15em; } -.top-doc .docblock h3, -.top-doc .docblock h4, -.top-doc .docblock h5 { - font-size: 1em; -} - -.docblock h1 { font-size: 1em; } -.docblock h2 { font-size: 0.95em; } -.docblock h3, .docblock h4, .docblock h5 { font-size: 0.9em; } - -.docblock { - margin-left: 24px; - position: relative; -} - -.content .out-of-band { - flex-grow: 0; - text-align: right; - font-size: 23px; - margin: 0px; - padding: 0 0 0 12px; - font-weight: normal; -} - -.method > code, .trait-impl > code, .invisible > code { - max-width: calc(100% - 41px); - display: block; -} - -.invisible { - width: 100%; - display: inline-block; -} - -.content .in-band { - flex-grow: 1; - margin: 0px; - padding: 0px; -} - -.in-band > code { - display: inline-block; -} - -#main { - position: relative; -} -#main > .since { - top: inherit; - font-family: "Fira Sans", Arial, sans-serif; -} - -.content table:not(.table-display) { - border-spacing: 0 5px; -} -.content td { vertical-align: top; } -.content td:first-child { padding-right: 20px; } -.content td p:first-child { margin-top: 0; } -.content td h1, .content td h2 { margin-left: 0; font-size: 1.1em; } -.content tr:first-child td { border-top: 0; } - -.docblock table { - margin: .5em 0; - width: calc(100% - 2px); - border: 1px dashed; -} - -.docblock table td { - padding: .5em; - border: 1px dashed; -} - -.docblock table th { - padding: .5em; - text-align: left; - border: 1px solid; -} - -.fields + table { - margin-bottom: 1em; -} - -.content .item-list { - list-style-type: none; - padding: 0; -} - -.content .multi-column { - -moz-column-count: 5; - -moz-column-gap: 2.5em; - -webkit-column-count: 5; - -webkit-column-gap: 2.5em; - column-count: 5; - column-gap: 2.5em; -} -.content .multi-column li { width: 100%; display: inline-block; } - -.content > .methods > .method { - font-size: 1em; - position: relative; -} -/* Shift "where ..." part of method or fn definition down a line */ -.content .method .where, -.content .fn .where, -.content .where.fmt-newline { - display: block; - font-size: 0.8em; -} - -.content .methods > div:not(.notable-traits):not(.method) { - margin-left: 40px; - margin-bottom: 15px; -} - -.content .docblock > .impl-items { - margin-left: 20px; - margin-top: -34px; -} -.content .docblock >.impl-items .table-display { - margin: 0; -} -.content .docblock >.impl-items table td { - padding: 0; -} -.content .docblock > .impl-items .table-display, .impl-items table td { - border: none; -} - -.content .item-info code { - font-size: 90%; -} - -.content .item-info { - position: relative; - margin-left: 33px; -} - -.sub-variant > div > .item-info { - margin-top: initial; -} - -.content .item-info::before { - content: '⬑'; - font-size: 25px; - position: absolute; - top: -6px; - left: -19px; -} - -.content .impl-items .method, .content .impl-items > .type, .impl-items > .associatedconstant, -.impl-items > .associatedtype, .content .impl-items details > summary > .type, -.impl-items details > summary > .associatedconstant, -.impl-items details > summary > .associatedtype { - margin-left: 20px; -} - -.content .impl-items .docblock, .content .impl-items .item-info { - margin-bottom: .6em; -} - -.content .impl-items > .item-info { - margin-left: 40px; -} - -.methods > .item-info, .content .impl-items > .item-info { - margin-top: -8px; -} - -.impl-items { - flex-basis: 100%; -} - -#main > .item-info { - margin-top: 0; -} - -nav:not(.sidebar) { - border-bottom: 1px solid; - padding-bottom: 10px; - margin-bottom: 10px; -} -nav.main { - padding: 20px 0; - text-align: center; -} -nav.main .current { - border-top: 1px solid; - border-bottom: 1px solid; -} -nav.main .separator { - border: 1px solid; - display: inline-block; - height: 23px; - margin: 0 20px; -} -nav.sum { text-align: right; } -nav.sub form { display: inline; } - -nav.sub, .content { - margin-left: 230px; -} - -a { - text-decoration: none; - background: transparent; -} - -.small-section-header { - display: flex; - justify-content: space-between; - position: relative; -} - -.small-section-header:hover > .anchor { - display: initial; -} - -.in-band:hover > .anchor, .impl:hover > .anchor, .method.trait-impl:hover > .anchor, -.type.trait-impl:hover > .anchor, .associatedconstant.trait-impl:hover > .anchor, -.associatedtype.trait-impl:hover > .anchor { - display: inline-block; - position: absolute; -} -.anchor { - display: none; - position: absolute; - left: -7px; -} -.anchor.field { - left: -5px; -} -.small-section-header > .anchor { - left: -28px; - padding-right: 10px; /* avoid gap that causes hover to disappear */ -} -.anchor:before { - content: '\2002\00a7\2002'; -} - -.docblock a:not(.srclink):not(.test-arrow):hover, -.docblock-short a:not(.srclink):not(.test-arrow):hover, .item-info a { - text-decoration: underline; -} - -.invisible > .srclink, -.method > code + .srclink { - position: absolute; - top: 0; - right: 0; - font-size: 17px; - font-weight: normal; -} - -.block a.current.crate { font-weight: 500; } - -.item-table { - display: grid; - column-gap: 1.2rem; - row-gap: 0.0rem; - grid-template-columns: auto 1fr; - /* align content left */ - justify-items: start; -} - -.item-left, .item-right { - display: block; -} -.item-left { - grid-column: 1; -} -.item-right { - grid-column: 2; -} - -.search-container { - position: relative; -} -.search-container > div { - display: inline-flex; - width: calc(100% - 63px); -} -#crate-search { - min-width: 115px; - margin-top: 5px; - padding: 6px; - padding-right: 19px; - flex: none; - border: 0; - border-right: 0; - border-radius: 4px 0 0 4px; - outline: none; - cursor: pointer; - border-right: 1px solid; - -moz-appearance: none; - -webkit-appearance: none; - /* Removes default arrow from firefox */ - text-indent: 0.01px; - text-overflow: ""; - background-repeat: no-repeat; - background-color: transparent; - background-size: 20px; - background-position: calc(100% - 1px) 56%; -} -.search-container > .top-button { - position: absolute; - right: 0; - top: 10px; -} -.search-input { - /* Override Normalize.css: we have margins and do - not want to overflow - the `moz` attribute is necessary - until Firefox 29, too early to drop at this point */ - -moz-box-sizing: border-box !important; - box-sizing: border-box !important; - outline: none; - border: none; - border-radius: 1px; - margin-top: 5px; - padding: 10px 16px; - font-size: 17px; - transition: border-color 300ms ease; - transition: border-radius 300ms ease-in-out; - transition: box-shadow 300ms ease-in-out; - width: 100%; -} - -#crate-search + .search-input { - border-radius: 0 1px 1px 0; - width: calc(100% - 32px); -} - -.search-input:focus { - border-radius: 2px; - border: 0; - outline: 0; -} - -.search-results { - display: none; - padding-bottom: 2em; -} - -.search-results.active { - display: block; - /* prevent overhanging tabs from moving the first result */ - clear: both; -} - -.search-results .desc > span { - white-space: nowrap; - text-overflow: ellipsis; - overflow: hidden; - display: block; -} - -.search-results > a { - display: block; - width: 100%; - /* A little margin ensures the browser's outlining of focused links has room to display. */ - margin-left: 2px; - margin-right: 2px; - border-bottom: 1px solid #aaa3; -} - -.search-results > a > div { - display: flex; - flex-flow: row wrap; -} - -.search-results .result-name, .search-results div.desc, .search-results .result-description { - width: 50%; -} -.search-results .result-name { - padding-right: 1em; -} - -.search-results .result-name > span { - display: inline-block; - margin: 0; - font-weight: normal; -} - -body.blur > :not(#help) { - filter: blur(8px); - -webkit-filter: blur(8px); - opacity: .7; -} - -#help { - width: 100%; - height: 100vh; - position: fixed; - top: 0; - left: 0; - display: flex; - justify-content: center; - align-items: center; -} -#help > div { - flex: 0 0 auto; - box-shadow: 0 0 6px rgba(0,0,0,.2); - width: 550px; - height: auto; - border: 1px solid; -} -#help dt { - float: left; - clear: left; - display: block; - margin-right: 0.5rem; -} -#help > div > span { - text-align: center; - display: block; - margin: 10px 0; - font-size: 18px; - border-bottom: 1px solid #ccc; - padding-bottom: 4px; - margin-bottom: 6px; -} -#help dd { margin: 5px 35px; } -#help .infos { padding-left: 0; } -#help h1, #help h2 { margin-top: 0; } -#help > div div { - width: 50%; - float: left; - padding: 0 20px 20px 17px;; -} - -.stab { - border-width: 1px; - border-style: solid; - padding: 3px; - margin-bottom: 5px; - font-size: 90%; - font-weight: normal; -} -.stab p { - display: inline; -} - -.stab .emoji { - font-size: 1.5em; -} - -/* Black one-pixel outline around emoji shapes */ -.emoji { - text-shadow: - 1px 0 0 black, - -1px 0 0 black, - 0 1px 0 black, - 0 -1px 0 black; -} - -.module-item .stab, -.import-item .stab { - border-radius: 3px; - display: inline-block; - font-size: 80%; - line-height: 1.2; - margin-bottom: 0; - margin-left: .3em; - padding: 2px; - vertical-align: text-bottom; -} - -.module-item.unstable, -.import-item.unstable { - opacity: 0.65; -} - -.since { - font-weight: normal; - font-size: initial; -} - -.impl-items .since, .impl .since, .methods .since { - padding-left: 12px; - padding-right: 2px; - position: initial; -} - -.impl-items .srclink, .impl .srclink, .methods .srclink { - /* Override header settings otherwise it's too bold */ - font-size: 17px; - font-weight: normal; -} - -.rightside { - float: right; -} - -.has-srclink { - font-size: 16px; - margin-bottom: 12px; - /* Push the src link out to the right edge consistently */ - justify-content: space-between; -} - -.variants_table { - width: 100%; -} - -.variants_table tbody tr td:first-child { - width: 1%; /* make the variant name as small as possible */ -} - -td.summary-column { - width: 100%; -} - -.summary { - padding-right: 0px; -} - -pre.rust .question-mark { - font-weight: bold; -} - -a.test-arrow { - display: inline-block; - position: absolute; - padding: 5px 10px 5px 10px; - border-radius: 5px; - font-size: 130%; - top: 5px; - right: 5px; - z-index: 1; -} -a.test-arrow:hover{ - text-decoration: none; -} - -.section-header:hover a:before { - position: absolute; - left: -25px; - padding-right: 10px; /* avoid gap that causes hover to disappear */ - content: '\2002\00a7\2002'; -} - -.section-header:hover a { - text-decoration: none; -} - -.section-header a { - color: inherit; -} - -.code-attribute { - font-weight: 300; -} - -.since + .srclink { - padding-left: 10px; -} - -.item-spacer { - width: 100%; - height: 12px; -} - -.out-of-band > span.since { - position: initial; - font-size: 20px; - margin-right: 5px; -} - -.sub-variant, .sub-variant > h3 { - margin-top: 0px !important; - padding-top: 1px; -} - -#main > details > .sub-variant > h3 { - font-size: 15px; - margin-left: 25px; - margin-bottom: 5px; -} - -.sub-variant > div { - margin-left: 20px; - margin-bottom: 10px; -} - -.sub-variant > div > span { - display: block; - position: relative; -} - -.toggle-label { - display: inline-block; - margin-left: 4px; - margin-top: 3px; -} - -.docblock > .section-header:first-child { - margin-left: 15px; - margin-top: 0; -} - -.docblock > .section-header:first-child:hover > a:before { - left: -10px; -} - -#main > .variant, #main > .structfield { - display: block; -} - - -:target > code { - opacity: 1; -} - -:target { - padding-right: 3px; -} - -.information { - position: absolute; - left: -25px; - margin-top: 7px; - z-index: 1; -} - -.tooltip { - position: relative; - display: inline-block; - cursor: pointer; -} - -.tooltip::after { - display: none; - text-align: center; - padding: 5px 3px 3px 3px; - border-radius: 6px; - margin-left: 5px; - font-size: 16px; -} - -.tooltip.ignore::after { - content: "This example is not tested"; -} -.tooltip.compile_fail::after { - content: "This example deliberately fails to compile"; -} -.tooltip.should_panic::after { - content: "This example panics"; -} -.tooltip.edition::after { - content: "This code runs with edition " attr(data-edition); -} - -.tooltip::before { - content: " "; - position: absolute; - top: 50%; - left: 16px; - margin-top: -5px; - border-width: 5px; - border-style: solid; - display: none; -} - -.tooltip:hover::before, .tooltip:hover::after { - display: inline; -} - -.tooltip.compile_fail, .tooltip.should_panic, .tooltip.ignore { - font-weight: bold; - font-size: 20px; -} - -.notable-traits-tooltip { - display: inline-block; - cursor: pointer; -} - -.notable-traits:hover .notable-traits-tooltiptext, -.notable-traits .notable-traits-tooltiptext.force-tooltip { - display: inline-block; -} - -.notable-traits .notable-traits-tooltiptext { - display: none; - padding: 5px 3px 3px 3px; - border-radius: 6px; - margin-left: 5px; - z-index: 10; - font-size: 16px; - cursor: default; - position: absolute; - border: 1px solid; -} - -.notable-traits-tooltip::after { - /* The margin on the tooltip does not capture hover events, - this extends the area of hover enough so that mouse hover is not - lost when moving the mouse to the tooltip */ - content: "\00a0\00a0\00a0"; -} - -.notable-traits .notable, .notable-traits .docblock { - margin: 0; -} - -.notable-traits .notable { - margin: 0; - margin-bottom: 13px; - font-size: 19px; - font-weight: 600; -} - -.notable-traits .docblock code.content{ - margin: 0; - padding: 0; - font-size: 20px; -} - -/* Example code has the "Run" button that needs to be positioned relative to the pre */ -pre.rust.rust-example-rendered { - position: relative; -} - -pre.rust { - tab-size: 4; - -moz-tab-size: 4; -} - -.search-failed { - text-align: center; - margin-top: 20px; - display: none; -} - -.search-failed.active { - display: block; -} - -.search-failed > ul { - text-align: left; - max-width: 570px; - margin-left: auto; - margin-right: auto; -} - -#titles { - height: 35px; -} - -#titles > button { - float: left; - width: 33.3%; - text-align: center; - font-size: 18px; - cursor: pointer; - border: 0; - border-top: 2px solid; -} - -#titles > button:not(:last-child) { - margin-right: 1px; - width: calc(33.3% - 1px); -} - -#titles > button > div.count { - display: inline-block; - font-size: 16px; -} - -.notable-traits { - cursor: pointer; - z-index: 2; - margin-left: 5px; -} - -#all-types { - text-align: center; - border: 1px solid; - margin: 0 10px; - margin-bottom: 10px; - display: block; - border-radius: 7px; -} -#all-types > p { - margin: 5px 0; -} - -#sidebar-toggle { - position: fixed; - top: 30px; - left: 300px; - z-index: 10; - padding: 3px; - border-top-right-radius: 3px; - border-bottom-right-radius: 3px; - cursor: pointer; - font-weight: bold; - transition: left .5s; - font-size: 1.2em; - border: 1px solid; - border-left: 0; -} -#source-sidebar { - position: fixed; - top: 0; - bottom: 0; - left: 0; - width: 300px; - z-index: 1; - overflow: auto; - transition: left .5s; - border-right: 1px solid; -} -#source-sidebar > .title { - font-size: 1.5em; - text-align: center; - border-bottom: 1px solid; - margin-bottom: 6px; -} - -.theme-picker { - position: absolute; - left: 211px; - top: 19px; -} - -.theme-picker button { - outline: none; -} - -#settings-menu, #help-button { - position: absolute; - top: 10px; -} - -#settings-menu { - right: 0; - outline: none; -} - -#theme-picker, #settings-menu, #help-button, #copy-path { - padding: 4px; - width: 27px; - height: 29px; - border: 1px solid; - border-radius: 3px; - cursor: pointer; -} - -#help-button { - right: 30px; - font-family: "Fira Sans", Arial, sans-serif; - text-align: center; - font-size: 17px; - padding-top: 2px; -} - -#copy-path { - background: initial; - margin-left: 10px; - padding: 0; - padding-left: 2px; - border: 0; -} - -#theme-choices { - display: none; - position: absolute; - left: 0; - top: 28px; - border: 1px solid; - border-radius: 3px; - z-index: 1; - cursor: pointer; -} - -#theme-choices > button { - border: none; - width: 100%; - padding: 4px 8px; - text-align: center; - background: rgba(0,0,0,0); -} - -#theme-choices > button:not(:first-child) { - border-top: 1px solid; -} - -kbd { - display: inline-block; - padding: 3px 5px; - font: 15px monospace; - line-height: 10px; - vertical-align: middle; - border: solid 1px; - border-radius: 3px; - box-shadow: inset 0 -1px 0; - cursor: default; -} - -.hidden-by-impl-hider, -.hidden-by-usual-hider { - /* important because of conflicting rule for small screens */ - display: none !important; -} - -#implementations-list > h3 > span.in-band { - width: 100%; -} - -.table-display { - width: 100%; - border: 0; - border-collapse: collapse; - border-spacing: 0; - font-size: 16px; -} - -.table-display tr td:first-child { - padding-right: 0; -} - -.table-display tr td:last-child { - float: right; -} -.table-display .out-of-band { - position: relative; - font-size: 19px; - display: block; -} -#implementors-list > .impl-items .table-display .out-of-band { - font-size: 17px; -} - -.table-display td:hover .anchor { - display: block; - top: 2px; - left: -5px; -} - -#main > ul { - padding-left: 10px; -} -#main > ul > li { - list-style: none; -} - -.non-exhaustive { - margin-bottom: 1em; -} - -div.children { - padding-left: 27px; - display: none; -} -div.name { - cursor: pointer; - position: relative; - margin-left: 16px; -} -div.files > a { - display: block; - padding: 0 3px; -} -div.files > a:hover, div.name:hover { - background-color: #a14b4b; -} -div.name.expand + .children { - display: block; -} -div.name::before { - content: "\25B6"; - padding-left: 4px; - font-size: 0.7em; - position: absolute; - left: -16px; - top: 4px; -} -div.name.expand::before { - transform: rotate(90deg); - left: -15px; - top: 2px; -} - -/* The hideme class is used on summary tags that contain a span with - placeholder text shown only when the toggle is closed. For instance, - "Expand description" or "Show methods". */ -details.rustdoc-toggle > summary.hideme { - cursor: pointer; -} - -details.rustdoc-toggle > summary, details.undocumented > summary { - list-style: none; -} -details.rustdoc-toggle > summary::-webkit-details-marker, -details.rustdoc-toggle > summary::marker, -details.undocumented > summary::-webkit-details-marker, -details.undocumented > summary::marker { - display: none; -} - -details.rustdoc-toggle > summary.hideme > span { - margin-left: 9px; -} - -details.rustdoc-toggle > summary::before { - content: "[+]"; - font-weight: 300; - font-size: 0.8em; - letter-spacing: 1px; - cursor: pointer; -} - -details.rustdoc-toggle.top-doc > summary, -details.rustdoc-toggle.top-doc > summary::before, -details.rustdoc-toggle.non-exhaustive > summary, -details.rustdoc-toggle.non-exhaustive > summary::before { - font-family: 'Fira Sans'; - font-size: 16px; -} - -details.non-exhaustive { - margin-bottom: 8px; -} - -details.rustdoc-toggle > summary.hideme::before { - position: relative; -} - -details.rustdoc-toggle > summary:not(.hideme)::before { - position: absolute; - left: -23px; - top: 3px; -} - -.impl-items > details.rustdoc-toggle > summary:not(.hideme)::before, -.undocumented > details.rustdoc-toggle > summary:not(.hideme)::before { - position: absolute; - left: -2px; -} - -/* When a "hideme" summary is open and the "Expand description" or "Show - methods" text is hidden, we want the [-] toggle that remains to not - affect the layout of the items to its right. To do that, we use - absolute positioning. Note that we also set position: relative - on the parent <details> to make this work properly. */ -details.rustdoc-toggle[open] > summary.hideme { - position: absolute; -} - -details.rustdoc-toggle, details.undocumented { - position: relative; -} - -details.rustdoc-toggle[open] > summary.hideme > span { - display: none; -} - -details.rustdoc-toggle[open] > summary::before { - content: "[−]"; - display: inline; -} - -details.undocumented > summary::before { - content: "[+] Show hidden undocumented items"; - cursor: pointer; - font-size: 16px; - font-weight: 300; -} - -details.undocumented[open] > summary::before { - content: "[−] Hide undocumented items"; -} - -/* Media Queries */ - -@media (min-width: 701px) { - /* In case there is no documentation before a code block, we need to add some margin at the top - to prevent an overlay between the "collapse toggle" and the information tooltip. - However, it's not needed with smaller screen width because the doc/code block is always put - "one line" below. */ - .docblock > .information:first-child > .tooltip { - margin-top: 16px; - } -} - -@media (max-width: 700px) { - body { - padding-top: 0px; - } - - .rustdoc > .sidebar { - height: 45px; - min-height: 40px; - margin: 0; - margin-left: -15px; - padding: 0 15px; - position: static; - z-index: 11; - } - - .sidebar > .location { - float: right; - margin: 0px; - margin-top: 2px; - padding: 3px 10px 1px 10px; - min-height: 39px; - background: inherit; - text-align: left; - font-size: 24px; - } - - .sidebar .location:empty { - padding: 0; - } - - .sidebar .logo-container { - width: 35px; - height: 35px; - margin-top: 5px; - margin-bottom: 5px; - float: left; - margin-left: 50px; - } - - .sidebar .logo-container > img { - max-width: 35px; - max-height: 35px; - } - - .sidebar-menu { - position: fixed; - z-index: 10; - font-size: 2rem; - cursor: pointer; - width: 45px; - left: 0; - text-align: center; - display: block; - border-bottom: 1px solid; - border-right: 1px solid; - height: 45px; - } - - .rustdoc.source > .sidebar > .sidebar-menu { - display: none; - } - - .sidebar-elems { - position: fixed; - z-index: 1; - left: 0; - top: 45px; - bottom: 0; - overflow-y: auto; - border-right: 1px solid; - display: none; - } - - .sidebar > .block.version { - overflow: hidden; - border-bottom: none; - margin-bottom: 0; - height: 100%; - padding-left: 12px; - } - .sidebar > .block.version > div.narrow-helper { - float: left; - width: 1px; - height: 100%; - } - .sidebar > .block.version > p { - /* hide Version text if too narrow */ - margin: 0; - min-width: 55px; - /* vertically center */ - display: flex; - align-items: center; - height: 100%; - } - - nav.sub { - width: calc(100% - 32px); - float: right; - } - - .content { - margin-left: 0px; - } - - #main, #search { - margin-top: 45px; - padding: 0; - } - - #search { - margin-left: 0; - } - - .anchor { - display: none !important; - } - - .theme-picker { - left: 10px; - top: 54px; - z-index: 1; - } - - .notable-traits { - position: absolute; - left: -22px; - top: 24px; - } - - #titles > button > div.count { - float: left; - width: 100%; - } - - #titles { - height: 50px; - } - - .sidebar.mobile { - position: fixed; - width: 100%; - margin-left: 0; - background-color: rgba(0,0,0,0); - height: 100%; - } - /* - This allows to prevent the version text to overflow the sidebar title on mobile mode when the - sidebar is displayed (after clicking on the "hamburger" button). - */ - .sidebar.mobile > div.version { - overflow: hidden; - max-height: 33px; - } - .sidebar { - width: calc(100% + 30px); - } - - .show-it { - display: block; - width: 246px; - } - - .show-it > .block.items { - margin: 8px 0; - } - - .show-it > .block.items > ul { - margin: 0; - } - - .show-it > .block.items > ul > li { - text-align: center; - margin: 2px 0; - } - - .show-it > .block.items > ul > li > a { - font-size: 21px; - } - - /* Because of ios, we need to actually have a full height sidebar title so the - * actual sidebar can show up. But then we need to make it transparent so we don't - * hide content. The filler just allows to create the background for the sidebar - * title. But because of the absolute position, I had to lower the z-index. - */ - #sidebar-filler { - position: fixed; - left: 45px; - width: calc(100% - 45px); - top: 0; - height: 45px; - z-index: -1; - border-bottom: 1px solid; - } - - #main > details.rustdoc-toggle > summary::before, - #main > div > details.rustdoc-toggle > summary::before { - left: -11px; - } - - #all-types { - margin: 10px; - } - - #sidebar-toggle { - top: 100px; - width: 30px; - font-size: 1.5rem; - text-align: center; - padding: 0; - } - - #source-sidebar { - z-index: 11; - } - - #main > .line-numbers { - margin-top: 0; - } - - .notable-traits .notable-traits-tooltiptext { - left: 0; - top: 100%; - } - - /* We don't display the help button on mobile devices. */ - #help-button { - display: none; - } - - /* Display an alternating layout on tablets and phones */ - .item-table { - display: flex; - flex-flow: column wrap; - } - .item-left, .item-right { - width: 100%; - } - - .search-container > div { - width: calc(100% - 32px); - } - - /* Display an alternating layout on tablets and phones */ - .search-results > a { - border-bottom: 1px solid #aaa9; - padding: 5px 0px; - } - .search-results .result-name, .search-results div.desc, .search-results .result-description { - width: 100%; - } - .search-results div.desc, .search-results .result-description, .item-right { - padding-left: 2em; - } -} - -@media print { - nav.sub, .content .out-of-band { - display: none; - } -} - -@media (max-width: 464px) { - #titles, #titles > button { - height: 73px; - } - - /* This is to prevent the search bar from being underneath the <section> - * element following it. - */ - #main, #search { - margin-top: 100px; - } - - #main > table:not(.table-display) td { - word-break: break-word; - width: 50%; - } - - .search-container > div { - display: block; - width: calc(100% - 37px); - } - - #crate-search { - width: 100%; - border-radius: 4px; - border: 0; - } - - #crate-search + .search-input { - width: calc(100% + 71px); - margin-left: -36px; - } - - #theme-picker, #settings-menu { - padding: 5px; - width: 31px; - height: 31px; - } - - #theme-picker { - margin-top: -2px; - } - - #settings-menu { - top: 7px; - } - - .docblock { - margin-left: 12px; - } -} diff --git a/src/librustdoc/html/static/search.js b/src/librustdoc/html/static/search.js deleted file mode 100644 index a7fc0b831f4..00000000000 --- a/src/librustdoc/html/static/search.js +++ /dev/null @@ -1,1561 +0,0 @@ -/* global addClass, getNakedUrl, getSettingValue, hasOwnPropertyRustdoc, initSearch, onEach */ -/* global onEachLazy, removeClass, searchState, updateLocalStorage */ - -(function() { -// This mapping table should match the discriminants of -// `rustdoc::html::item_type::ItemType` type in Rust. -var itemTypes = ["mod", - "externcrate", - "import", - "struct", - "enum", - "fn", - "type", - "static", - "trait", - "impl", - "tymethod", - "method", - "structfield", - "variant", - "macro", - "primitive", - "associatedtype", - "constant", - "associatedconstant", - "union", - "foreigntype", - "keyword", - "existential", - "attr", - "derive", - "traitalias"]; - -// used for special search precedence -var TY_PRIMITIVE = itemTypes.indexOf("primitive"); -var TY_KEYWORD = itemTypes.indexOf("keyword"); - -// In the search display, allows to switch between tabs. -function printTab(nb) { - if (nb === 0 || nb === 1 || nb === 2) { - searchState.currentTab = nb; - } - var nb_copy = nb; - onEachLazy(document.getElementById("titles").childNodes, function(elem) { - if (nb_copy === 0) { - addClass(elem, "selected"); - } else { - removeClass(elem, "selected"); - } - nb_copy -= 1; - }); - onEachLazy(document.getElementById("results").childNodes, function(elem) { - if (nb === 0) { - addClass(elem, "active"); - } else { - removeClass(elem, "active"); - } - nb -= 1; - }); -} - -function removeEmptyStringsFromArray(x) { - for (var i = 0, len = x.length; i < len; ++i) { - if (x[i] === "") { - x.splice(i, 1); - i -= 1; - } - } -} - -/** - * A function to compute the Levenshtein distance between two strings - * Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported - * Full License can be found at http://creativecommons.org/licenses/by-sa/3.0/legalcode - * This code is an unmodified version of the code written by Marco de Wit - * and was found at https://stackoverflow.com/a/18514751/745719 - */ -var levenshtein_row2 = []; -function levenshtein(s1, s2) { - if (s1 === s2) { - return 0; - } - var s1_len = s1.length, s2_len = s2.length; - if (s1_len && s2_len) { - var i1 = 0, i2 = 0, a, b, c, c2, row = levenshtein_row2; - while (i1 < s1_len) { - row[i1] = ++i1; - } - while (i2 < s2_len) { - c2 = s2.charCodeAt(i2); - a = i2; - ++i2; - b = i2; - for (i1 = 0; i1 < s1_len; ++i1) { - c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0); - a = row[i1]; - b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c); - row[i1] = b; - } - } - return b; - } - return s1_len + s2_len; -} - -window.initSearch = function(rawSearchIndex) { - var MAX_LEV_DISTANCE = 3; - var MAX_RESULTS = 200; - var GENERICS_DATA = 2; - var NAME = 0; - var INPUTS_DATA = 0; - var OUTPUT_DATA = 1; - var NO_TYPE_FILTER = -1; - var currentResults, index, searchIndex; - var ALIASES = {}; - var params = searchState.getQueryStringParams(); - - // Populate search bar with query string search term when provided, - // but only if the input bar is empty. This avoid the obnoxious issue - // where you start trying to do a search, and the index loads, and - // suddenly your search is gone! - if (searchState.input.value === "") { - searchState.input.value = params.search || ""; - } - - /** - * Executes the query and builds an index of results - * @param {[Object]} query [The user query] - * @param {[type]} searchWords [The list of search words to query - * against] - * @param {[type]} filterCrates [Crate to search in if defined] - * @return {[type]} [A search index of results] - */ - function execQuery(query, searchWords, filterCrates) { - function itemTypeFromName(typename) { - for (var i = 0, len = itemTypes.length; i < len; ++i) { - if (itemTypes[i] === typename) { - return i; - } - } - return NO_TYPE_FILTER; - } - - var valLower = query.query.toLowerCase(), - val = valLower, - typeFilter = itemTypeFromName(query.type), - results = {}, results_in_args = {}, results_returned = {}, - split = valLower.split("::"); - - removeEmptyStringsFromArray(split); - - function transformResults(results) { - var out = []; - for (var i = 0, len = results.length; i < len; ++i) { - if (results[i].id > -1) { - var obj = searchIndex[results[i].id]; - obj.lev = results[i].lev; - var res = buildHrefAndPath(obj); - obj.displayPath = pathSplitter(res[0]); - obj.fullPath = obj.displayPath + obj.name; - // To be sure than it some items aren't considered as duplicate. - obj.fullPath += "|" + obj.ty; - obj.href = res[1]; - out.push(obj); - if (out.length >= MAX_RESULTS) { - break; - } - } - } - return out; - } - - function sortResults(results, isType) { - var ar = []; - for (var entry in results) { - if (hasOwnPropertyRustdoc(results, entry)) { - ar.push(results[entry]); - } - } - results = ar; - var i, len, result; - for (i = 0, len = results.length; i < len; ++i) { - result = results[i]; - result.word = searchWords[result.id]; - result.item = searchIndex[result.id] || {}; - } - // if there are no results then return to default and fail - if (results.length === 0) { - return []; - } - - results.sort(function(aaa, bbb) { - var a, b; - - // sort by exact match with regard to the last word (mismatch goes later) - a = (aaa.word !== val); - b = (bbb.word !== val); - if (a !== b) { return a - b; } - - // Sort by non levenshtein results and then levenshtein results by the distance - // (less changes required to match means higher rankings) - a = (aaa.lev); - b = (bbb.lev); - if (a !== b) { return a - b; } - - // sort by crate (non-current crate goes later) - a = (aaa.item.crate !== window.currentCrate); - b = (bbb.item.crate !== window.currentCrate); - if (a !== b) { return a - b; } - - // sort by item name length (longer goes later) - a = aaa.word.length; - b = bbb.word.length; - if (a !== b) { return a - b; } - - // sort by item name (lexicographically larger goes later) - a = aaa.word; - b = bbb.word; - if (a !== b) { return (a > b ? +1 : -1); } - - // sort by index of keyword in item name (no literal occurrence goes later) - a = (aaa.index < 0); - b = (bbb.index < 0); - if (a !== b) { return a - b; } - // (later literal occurrence, if any, goes later) - a = aaa.index; - b = bbb.index; - if (a !== b) { return a - b; } - - // special precedence for primitive and keyword pages - if ((aaa.item.ty === TY_PRIMITIVE && bbb.item.ty !== TY_KEYWORD) || - (aaa.item.ty === TY_KEYWORD && bbb.item.ty !== TY_PRIMITIVE)) { - return -1; - } - if ((bbb.item.ty === TY_PRIMITIVE && aaa.item.ty !== TY_PRIMITIVE) || - (bbb.item.ty === TY_KEYWORD && aaa.item.ty !== TY_KEYWORD)) { - return 1; - } - - // sort by description (no description goes later) - a = (aaa.item.desc === ""); - b = (bbb.item.desc === ""); - if (a !== b) { return a - b; } - - // sort by type (later occurrence in `itemTypes` goes later) - a = aaa.item.ty; - b = bbb.item.ty; - if (a !== b) { return a - b; } - - // sort by path (lexicographically larger goes later) - a = aaa.item.path; - b = bbb.item.path; - if (a !== b) { return (a > b ? +1 : -1); } - - // que sera, sera - return 0; - }); - - for (i = 0, len = results.length; i < len; ++i) { - result = results[i]; - - // this validation does not make sense when searching by types - if (result.dontValidate) { - continue; - } - var name = result.item.name.toLowerCase(), - path = result.item.path.toLowerCase(), - parent = result.item.parent; - - if (!isType && !validateResult(name, path, split, parent)) { - result.id = -1; - } - } - return transformResults(results); - } - - function extractGenerics(val) { - val = val.toLowerCase(); - if (val.indexOf("<") !== -1) { - var values = val.substring(val.indexOf("<") + 1, val.lastIndexOf(">")); - return { - name: val.substring(0, val.indexOf("<")), - generics: values.split(/\s*,\s*/), - }; - } - return { - name: val, - generics: [], - }; - } - - function getObjectNameFromId(id) { - if (typeof id === "number") { - return searchIndex[id].name; - } - return id; - } - - function checkGenerics(obj, val) { - // The names match, but we need to be sure that all generics kinda - // match as well. - var tmp_lev, elem_name; - if (val.generics.length > 0) { - if (obj.length > GENERICS_DATA && - obj[GENERICS_DATA].length >= val.generics.length) { - var elems = Object.create(null); - var elength = obj[GENERICS_DATA].length; - for (var x = 0; x < elength; ++x) { - if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) { - elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0; - } - elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; - } - var total = 0; - var done = 0; - // We need to find the type that matches the most to remove it in order - // to move forward. - var vlength = val.generics.length; - for (x = 0; x < vlength; ++x) { - var lev = MAX_LEV_DISTANCE + 1; - var firstGeneric = getObjectNameFromId(val.generics[x]); - var match = null; - if (elems[firstGeneric]) { - match = firstGeneric; - lev = 0; - } else { - for (elem_name in elems) { - tmp_lev = levenshtein(elem_name, firstGeneric); - if (tmp_lev < lev) { - lev = tmp_lev; - match = elem_name; - } - } - } - if (match !== null) { - elems[match] -= 1; - if (elems[match] == 0) { - delete elems[match]; - } - total += lev; - done += 1; - } else { - return MAX_LEV_DISTANCE + 1; - } - } - return Math.ceil(total / done); - } - } - return MAX_LEV_DISTANCE + 1; - } - - // Check for type name and type generics (if any). - function checkType(obj, val, literalSearch) { - var lev_distance = MAX_LEV_DISTANCE + 1; - var len, x, firstGeneric; - if (obj[NAME] === val.name) { - if (literalSearch) { - if (val.generics && val.generics.length !== 0) { - if (obj.length > GENERICS_DATA && - obj[GENERICS_DATA].length > 0) { - var elems = Object.create(null); - len = obj[GENERICS_DATA].length; - for (x = 0; x < len; ++x) { - if (!elems[getObjectNameFromId(obj[GENERICS_DATA][x])]) { - elems[getObjectNameFromId(obj[GENERICS_DATA][x])] = 0; - } - elems[getObjectNameFromId(obj[GENERICS_DATA][x])] += 1; - } - - var allFound = true; - len = val.generics.length; - for (x = 0; x < len; ++x) { - firstGeneric = getObjectNameFromId(val.generics[x]); - if (elems[firstGeneric]) { - elems[firstGeneric] -= 1; - } else { - allFound = false; - break; - } - } - if (allFound) { - return true; - } - } - return false; - } - return true; - } else { - // If the type has generics but don't match, then it won't return at this point. - // Otherwise, `checkGenerics` will return 0 and it'll return. - if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length !== 0) { - var tmp_lev = checkGenerics(obj, val); - if (tmp_lev <= MAX_LEV_DISTANCE) { - return tmp_lev; - } - } - } - } else if (literalSearch) { - if ((!val.generics || val.generics.length === 0) && - obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) { - return obj[GENERICS_DATA].some( - function(name) { - return name === val.name; - }); - } - return false; - } - lev_distance = Math.min(levenshtein(obj[NAME], val.name), lev_distance); - if (lev_distance <= MAX_LEV_DISTANCE) { - // The generics didn't match but the name kinda did so we give it - // a levenshtein distance value that isn't *this* good so it goes - // into the search results but not too high. - lev_distance = Math.ceil((checkGenerics(obj, val) + lev_distance) / 2); - } else if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) { - // We can check if the type we're looking for is inside the generics! - var olength = obj[GENERICS_DATA].length; - for (x = 0; x < olength; ++x) { - lev_distance = Math.min(levenshtein(obj[GENERICS_DATA][x], val.name), - lev_distance); - } - } - // Now whatever happens, the returned distance is "less good" so we should mark it - // as such, and so we add 1 to the distance to make it "less good". - return lev_distance + 1; - } - - function findArg(obj, val, literalSearch, typeFilter) { - var lev_distance = MAX_LEV_DISTANCE + 1; - - if (obj && obj.type && obj.type[INPUTS_DATA] && obj.type[INPUTS_DATA].length > 0) { - var length = obj.type[INPUTS_DATA].length; - for (var i = 0; i < length; i++) { - var tmp = obj.type[INPUTS_DATA][i]; - if (!typePassesFilter(typeFilter, tmp[1])) { - continue; - } - tmp = checkType(tmp, val, literalSearch); - if (literalSearch) { - if (tmp) { - return true; - } - continue; - } - lev_distance = Math.min(tmp, lev_distance); - if (lev_distance === 0) { - return 0; - } - } - } - return literalSearch ? false : lev_distance; - } - - function checkReturned(obj, val, literalSearch, typeFilter) { - var lev_distance = MAX_LEV_DISTANCE + 1; - - if (obj && obj.type && obj.type.length > OUTPUT_DATA) { - var ret = obj.type[OUTPUT_DATA]; - if (typeof ret[0] === "string") { - ret = [ret]; - } - for (var x = 0, len = ret.length; x < len; ++x) { - var tmp = ret[x]; - if (!typePassesFilter(typeFilter, tmp[1])) { - continue; - } - tmp = checkType(tmp, val, literalSearch); - if (literalSearch) { - if (tmp) { - return true; - } - continue; - } - lev_distance = Math.min(tmp, lev_distance); - if (lev_distance === 0) { - return 0; - } - } - } - return literalSearch ? false : lev_distance; - } - - function checkPath(contains, lastElem, ty) { - if (contains.length === 0) { - return 0; - } - var ret_lev = MAX_LEV_DISTANCE + 1; - var path = ty.path.split("::"); - - if (ty.parent && ty.parent.name) { - path.push(ty.parent.name.toLowerCase()); - } - - var length = path.length; - var clength = contains.length; - if (clength > length) { - return MAX_LEV_DISTANCE + 1; - } - for (var i = 0; i < length; ++i) { - if (i + clength > length) { - break; - } - var lev_total = 0; - var aborted = false; - for (var x = 0; x < clength; ++x) { - var lev = levenshtein(path[i + x], contains[x]); - if (lev > MAX_LEV_DISTANCE) { - aborted = true; - break; - } - lev_total += lev; - } - if (!aborted) { - ret_lev = Math.min(ret_lev, Math.round(lev_total / clength)); - } - } - return ret_lev; - } - - function typePassesFilter(filter, type) { - // No filter - if (filter <= NO_TYPE_FILTER) return true; - - // Exact match - if (filter === type) return true; - - // Match related items - var name = itemTypes[type]; - switch (itemTypes[filter]) { - case "constant": - return name === "associatedconstant"; - case "fn": - return name === "method" || name === "tymethod"; - case "type": - return name === "primitive" || name === "associatedtype"; - case "trait": - return name === "traitalias"; - } - - // No match - return false; - } - - function createAliasFromItem(item) { - return { - crate: item.crate, - name: item.name, - path: item.path, - desc: item.desc, - ty: item.ty, - parent: item.parent, - type: item.type, - is_alias: true, - }; - } - - function handleAliases(ret, query, filterCrates) { - // We separate aliases and crate aliases because we want to have current crate - // aliases to be before the others in the displayed results. - var aliases = []; - var crateAliases = []; - if (filterCrates !== undefined) { - if (ALIASES[filterCrates] && ALIASES[filterCrates][query.search]) { - var query_aliases = ALIASES[filterCrates][query.search]; - var len = query_aliases.length; - for (var i = 0; i < len; ++i) { - aliases.push(createAliasFromItem(searchIndex[query_aliases[i]])); - } - } - } else { - Object.keys(ALIASES).forEach(function(crate) { - if (ALIASES[crate][query.search]) { - var pushTo = crate === window.currentCrate ? crateAliases : aliases; - var query_aliases = ALIASES[crate][query.search]; - var len = query_aliases.length; - for (var i = 0; i < len; ++i) { - pushTo.push(createAliasFromItem(searchIndex[query_aliases[i]])); - } - } - }); - } - - var sortFunc = function(aaa, bbb) { - if (aaa.path < bbb.path) { - return 1; - } else if (aaa.path === bbb.path) { - return 0; - } - return -1; - }; - crateAliases.sort(sortFunc); - aliases.sort(sortFunc); - - var pushFunc = function(alias) { - alias.alias = query.raw; - var res = buildHrefAndPath(alias); - alias.displayPath = pathSplitter(res[0]); - alias.fullPath = alias.displayPath + alias.name; - alias.href = res[1]; - - ret.others.unshift(alias); - if (ret.others.length > MAX_RESULTS) { - ret.others.pop(); - } - }; - onEach(aliases, pushFunc); - onEach(crateAliases, pushFunc); - } - - // quoted values mean literal search - var nSearchWords = searchWords.length; - var i, it; - var ty; - var fullId; - var returned; - var in_args; - var len; - if ((val.charAt(0) === "\"" || val.charAt(0) === "'") && - val.charAt(val.length - 1) === val.charAt(0)) - { - val = extractGenerics(val.substr(1, val.length - 2)); - for (i = 0; i < nSearchWords; ++i) { - if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { - continue; - } - in_args = findArg(searchIndex[i], val, true, typeFilter); - returned = checkReturned(searchIndex[i], val, true, typeFilter); - ty = searchIndex[i]; - fullId = ty.id; - - if (searchWords[i] === val.name - && typePassesFilter(typeFilter, searchIndex[i].ty) - && results[fullId] === undefined) { - results[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - if (in_args && results_in_args[fullId] === undefined) { - results_in_args[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - if (returned && results_returned[fullId] === undefined) { - results_returned[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - } - query.inputs = [val]; - query.output = val; - query.search = val; - // searching by type - } else if (val.search("->") > -1) { - var trimmer = function(s) { return s.trim(); }; - var parts = val.split("->").map(trimmer); - var input = parts[0]; - // sort inputs so that order does not matter - var inputs = input.split(",").map(trimmer).sort(); - for (i = 0, len = inputs.length; i < len; ++i) { - inputs[i] = extractGenerics(inputs[i]); - } - var output = extractGenerics(parts[1]); - - for (i = 0; i < nSearchWords; ++i) { - if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) { - continue; - } - var type = searchIndex[i].type; - ty = searchIndex[i]; - if (!type) { - continue; - } - fullId = ty.id; - - returned = checkReturned(ty, output, true, NO_TYPE_FILTER); - if (output.name === "*" || returned) { - in_args = false; - var is_module = false; - - if (input === "*") { - is_module = true; - } else { - var allFound = true; - for (it = 0, len = inputs.length; allFound && it < len; it++) { - allFound = checkType(type, inputs[it], true); - } - in_args = allFound; - } - if (in_args) { - results_in_args[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - if (returned) { - results_returned[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - if (is_module) { - results[fullId] = { - id: i, - index: -1, - dontValidate: true, - }; - } - } - } - query.inputs = inputs.map(function(input) { - return input.name; - }); - query.output = output.name; - } else { - query.inputs = [val]; - query.output = val; - query.search = val; - // gather matching search results up to a certain maximum - val = val.replace(/_/g, ""); - - var valGenerics = extractGenerics(val); - - var paths = valLower.split("::"); - removeEmptyStringsFromArray(paths); - val = paths[paths.length - 1]; - var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1); - - var lev, j; - for (j = 0; j < nSearchWords; ++j) { - ty = searchIndex[j]; - if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) { - continue; - } - var lev_add = 0; - if (paths.length > 1) { - lev = checkPath(contains, paths[paths.length - 1], ty); - if (lev > MAX_LEV_DISTANCE) { - continue; - } else if (lev > 0) { - lev_add = lev / 10; - } - } - - returned = MAX_LEV_DISTANCE + 1; - in_args = MAX_LEV_DISTANCE + 1; - var index = -1; - // we want lev results to go lower than others - lev = MAX_LEV_DISTANCE + 1; - fullId = ty.id; - - if (searchWords[j].indexOf(split[i]) > -1 || - searchWords[j].indexOf(val) > -1 || - ty.normalizedName.indexOf(val) > -1) - { - // filter type: ... queries - if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) { - index = ty.normalizedName.indexOf(val); - } - } - if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) { - if (typePassesFilter(typeFilter, ty.ty)) { - lev += 1; - } else { - lev = MAX_LEV_DISTANCE + 1; - } - } - in_args = findArg(ty, valGenerics, false, typeFilter); - returned = checkReturned(ty, valGenerics, false, typeFilter); - - lev += lev_add; - if (lev > 0 && val.length > 3 && searchWords[j].indexOf(val) > -1) { - if (val.length < 6) { - lev -= 1; - } else { - lev = 0; - } - } - if (in_args <= MAX_LEV_DISTANCE) { - if (results_in_args[fullId] === undefined) { - results_in_args[fullId] = { - id: j, - index: index, - lev: in_args, - }; - } - results_in_args[fullId].lev = - Math.min(results_in_args[fullId].lev, in_args); - } - if (returned <= MAX_LEV_DISTANCE) { - if (results_returned[fullId] === undefined) { - results_returned[fullId] = { - id: j, - index: index, - lev: returned, - }; - } - results_returned[fullId].lev = - Math.min(results_returned[fullId].lev, returned); - } - if (typePassesFilter(typeFilter, ty.ty) && - (index !== -1 || lev <= MAX_LEV_DISTANCE)) { - if (index !== -1 && paths.length < 2) { - lev = 0; - } - if (results[fullId] === undefined) { - results[fullId] = { - id: j, - index: index, - lev: lev, - }; - } - results[fullId].lev = Math.min(results[fullId].lev, lev); - } - } - } - - var ret = { - "in_args": sortResults(results_in_args, true), - "returned": sortResults(results_returned, true), - "others": sortResults(results, false), - }; - handleAliases(ret, query, filterCrates); - return ret; - } - - /** - * Validate performs the following boolean logic. For example: - * "File::open" will give IF A PARENT EXISTS => ("file" && "open") - * exists in (name || path || parent) OR => ("file" && "open") exists in - * (name || path ) - * - * This could be written functionally, but I wanted to minimise - * functions on stack. - * - * @param {[string]} name [The name of the result] - * @param {[string]} path [The path of the result] - * @param {[string]} keys [The keys to be used (["file", "open"])] - * @param {[object]} parent [The parent of the result] - * @return {boolean} [Whether the result is valid or not] - */ - function validateResult(name, path, keys, parent) { - for (var i = 0, len = keys.length; i < len; ++i) { - // each check is for validation so we negate the conditions and invalidate - if (!( - // check for an exact name match - name.indexOf(keys[i]) > -1 || - // then an exact path match - path.indexOf(keys[i]) > -1 || - // next if there is a parent, check for exact parent match - (parent !== undefined && parent.name !== undefined && - parent.name.toLowerCase().indexOf(keys[i]) > -1) || - // lastly check to see if the name was a levenshtein match - levenshtein(name, keys[i]) <= MAX_LEV_DISTANCE)) { - return false; - } - } - return true; - } - - function getQuery(raw) { - var matches, type, query; - query = raw; - - matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i); - if (matches) { - type = matches[1].replace(/^const$/, "constant"); - query = query.substring(matches[0].length); - } - - return { - raw: raw, - query: query, - type: type, - id: query + type - }; - } - - function nextTab(direction) { - var next = (searchState.currentTab + direction + 3) % searchState.focusedByTab.length; - searchState.focusedByTab[searchState.currentTab] = document.activeElement; - printTab(next); - focusSearchResult(); - } - - // Focus the first search result on the active tab, or the result that - // was focused last time this tab was active. - function focusSearchResult() { - var target = searchState.focusedByTab[searchState.currentTab] || - document.querySelectorAll(".search-results.active a").item(0) || - document.querySelectorAll("#titles > button").item(searchState.currentTab); - if (target) { - target.focus(); - } - } - - function buildHrefAndPath(item) { - var displayPath; - var href; - var type = itemTypes[item.ty]; - var name = item.name; - var path = item.path; - - if (type === "mod") { - displayPath = path + "::"; - href = window.rootPath + path.replace(/::/g, "/") + "/" + - name + "/index.html"; - } else if (type === "primitive" || type === "keyword") { - displayPath = ""; - href = window.rootPath + path.replace(/::/g, "/") + - "/" + type + "." + name + ".html"; - } else if (type === "externcrate") { - displayPath = ""; - href = window.rootPath + name + "/index.html"; - } else if (item.parent !== undefined) { - var myparent = item.parent; - var anchor = "#" + type + "." + name; - var parentType = itemTypes[myparent.ty]; - var pageType = parentType; - var pageName = myparent.name; - - if (parentType === "primitive") { - displayPath = myparent.name + "::"; - } else if (type === "structfield" && parentType === "variant") { - // Structfields belonging to variants are special: the - // final path element is the enum name. - var enumNameIdx = item.path.lastIndexOf("::"); - var enumName = item.path.substr(enumNameIdx + 2); - path = item.path.substr(0, enumNameIdx); - displayPath = path + "::" + enumName + "::" + myparent.name + "::"; - anchor = "#variant." + myparent.name + ".field." + name; - pageType = "enum"; - pageName = enumName; - } else { - displayPath = path + "::" + myparent.name + "::"; - } - href = window.rootPath + path.replace(/::/g, "/") + - "/" + pageType + - "." + pageName + - ".html" + anchor; - } else { - displayPath = item.path + "::"; - href = window.rootPath + item.path.replace(/::/g, "/") + - "/" + type + "." + name + ".html"; - } - return [displayPath, href]; - } - - function escape(content) { - var h1 = document.createElement("h1"); - h1.textContent = content; - return h1.innerHTML; - } - - function pathSplitter(path) { - var tmp = "<span>" + path.replace(/::/g, "::</span><span>"); - if (tmp.endsWith("<span>")) { - return tmp.slice(0, tmp.length - 6); - } - return tmp; - } - - function addTab(array, query, display) { - var extraClass = ""; - if (display === true) { - extraClass = " active"; - } - - var output = document.createElement("div"); - var duplicates = {}; - var length = 0; - if (array.length > 0) { - output.className = "search-results " + extraClass; - - array.forEach(function(item) { - if (item.is_alias !== true) { - if (duplicates[item.fullPath]) { - return; - } - duplicates[item.fullPath] = true; - } - - var name = item.name; - var type = itemTypes[item.ty]; - - length += 1; - - var extra = ""; - if (type === "primitive") { - extra = " <i>(primitive type)</i>"; - } else if (type === "keyword") { - extra = " <i>(keyword)</i>"; - } - - var link = document.createElement("a"); - link.className = "result-" + type; - link.href = item.href; - - var wrapper = document.createElement("div"); - var resultName = document.createElement("div"); - resultName.className = "result-name"; - - if (item.is_alias) { - var alias = document.createElement("span"); - alias.className = "alias"; - - var bold = document.createElement("b"); - bold.innerText = item.alias; - alias.appendChild(bold); - - alias.insertAdjacentHTML( - "beforeend", - "<span class=\"grey\"><i> - see </i></span>"); - - resultName.appendChild(alias); - } - resultName.insertAdjacentHTML( - "beforeend", - item.displayPath + "<span class=\"" + type + "\">" + name + extra + "</span>"); - wrapper.appendChild(resultName); - - var description = document.createElement("div"); - description.className = "desc"; - var spanDesc = document.createElement("span"); - spanDesc.insertAdjacentHTML("beforeend", item.desc); - - description.appendChild(spanDesc); - wrapper.appendChild(description); - link.appendChild(wrapper); - output.appendChild(link); - }); - } else { - output.className = "search-failed" + extraClass; - output.innerHTML = "No results :(<br/>" + - "Try on <a href=\"https://duckduckgo.com/?q=" + - encodeURIComponent("rust " + query.query) + - "\">DuckDuckGo</a>?<br/><br/>" + - "Or try looking in one of these:<ul><li>The <a " + - "href=\"https://doc.rust-lang.org/reference/index.html\">Rust Reference</a> " + - " for technical details about the language.</li><li><a " + - "href=\"https://doc.rust-lang.org/rust-by-example/index.html\">Rust By " + - "Example</a> for expository code examples.</a></li><li>The <a " + - "href=\"https://doc.rust-lang.org/book/index.html\">Rust Book</a> for " + - "introductions to language features and the language itself.</li><li><a " + - "href=\"https://docs.rs\">Docs.rs</a> for documentation of crates released on" + - " <a href=\"https://crates.io/\">crates.io</a>.</li></ul>"; - } - return [output, length]; - } - - function makeTabHeader(tabNb, text, nbElems) { - if (searchState.currentTab === tabNb) { - return "<button class=\"selected\">" + text + - " <div class=\"count\">(" + nbElems + ")</div></button>"; - } - return "<button>" + text + " <div class=\"count\">(" + nbElems + ")</div></button>"; - } - - function showResults(results, go_to_first) { - var search = searchState.outputElement(); - if (go_to_first || (results.others.length === 1 - && getSettingValue("go-to-only-result") === "true" - // By default, the search DOM element is "empty" (meaning it has no children not - // text content). Once a search has been run, it won't be empty, even if you press - // ESC or empty the search input (which also "cancels" the search). - && (!search.firstChild || search.firstChild.innerText !== searchState.loadingText))) - { - var elem = document.createElement("a"); - elem.href = results.others[0].href; - removeClass(elem, "active"); - // For firefox, we need the element to be in the DOM so it can be clicked. - document.body.appendChild(elem); - elem.click(); - return; - } - var query = getQuery(searchState.input.value); - - currentResults = query.id; - - var ret_others = addTab(results.others, query); - var ret_in_args = addTab(results.in_args, query, false); - var ret_returned = addTab(results.returned, query, false); - - // Navigate to the relevant tab if the current tab is empty, like in case users search - // for "-> String". If they had selected another tab previously, they have to click on - // it again. - var currentTab = searchState.currentTab; - if ((currentTab === 0 && ret_others[1] === 0) || - (currentTab === 1 && ret_in_args[1] === 0) || - (currentTab === 2 && ret_returned[1] === 0)) { - if (ret_others[1] !== 0) { - currentTab = 0; - } else if (ret_in_args[1] !== 0) { - currentTab = 1; - } else if (ret_returned[1] !== 0) { - currentTab = 2; - } - } - - var output = "<h1>Results for " + escape(query.query) + - (query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" + - "<div id=\"titles\">" + - makeTabHeader(0, "In Names", ret_others[1]) + - makeTabHeader(1, "In Parameters", ret_in_args[1]) + - makeTabHeader(2, "In Return Types", ret_returned[1]) + - "</div>"; - - var resultsElem = document.createElement("div"); - resultsElem.id = "results"; - resultsElem.appendChild(ret_others[0]); - resultsElem.appendChild(ret_in_args[0]); - resultsElem.appendChild(ret_returned[0]); - - search.innerHTML = output; - search.appendChild(resultsElem); - // Reset focused elements. - searchState.focusedByTab = [null, null, null]; - searchState.showResults(search); - var elems = document.getElementById("titles").childNodes; - elems[0].onclick = function() { printTab(0); }; - elems[1].onclick = function() { printTab(1); }; - elems[2].onclick = function() { printTab(2); }; - printTab(currentTab); - } - - function execSearch(query, searchWords, filterCrates) { - function getSmallest(arrays, positions, notDuplicates) { - var start = null; - - for (var it = 0, len = positions.length; it < len; ++it) { - if (arrays[it].length > positions[it] && - (start === null || start > arrays[it][positions[it]].lev) && - !notDuplicates[arrays[it][positions[it]].fullPath]) { - start = arrays[it][positions[it]].lev; - } - } - return start; - } - - function mergeArrays(arrays) { - var ret = []; - var positions = []; - var notDuplicates = {}; - - for (var x = 0, arrays_len = arrays.length; x < arrays_len; ++x) { - positions.push(0); - } - while (ret.length < MAX_RESULTS) { - var smallest = getSmallest(arrays, positions, notDuplicates); - - if (smallest === null) { - break; - } - for (x = 0; x < arrays_len && ret.length < MAX_RESULTS; ++x) { - if (arrays[x].length > positions[x] && - arrays[x][positions[x]].lev === smallest && - !notDuplicates[arrays[x][positions[x]].fullPath]) { - ret.push(arrays[x][positions[x]]); - notDuplicates[arrays[x][positions[x]].fullPath] = true; - positions[x] += 1; - } - } - } - return ret; - } - - // Split search query by ",", while respecting angle bracket nesting. - // Since "<" is an alias for the Ord family of traits, it also uses - // lookahead to distinguish "<"-as-less-than from "<"-as-angle-bracket. - // - // tokenizeQuery("A<B, C>, D") == ["A<B, C>", "D"] - // tokenizeQuery("A<B, C, D") == ["A<B", "C", "D"] - function tokenizeQuery(raw) { - var i, matched; - var l = raw.length; - var depth = 0; - var nextAngle = /(<|>)/g; - var ret = []; - var start = 0; - for (i = 0; i < l; ++i) { - switch (raw[i]) { - case "<": - nextAngle.lastIndex = i + 1; - matched = nextAngle.exec(raw); - if (matched && matched[1] === '>') { - depth += 1; - } - break; - case ">": - if (depth > 0) { - depth -= 1; - } - break; - case ",": - if (depth === 0) { - ret.push(raw.substring(start, i)); - start = i + 1; - } - break; - } - } - if (start !== i) { - ret.push(raw.substring(start, i)); - } - return ret; - } - - var queries = tokenizeQuery(query.raw); - var results = { - "in_args": [], - "returned": [], - "others": [], - }; - - for (var i = 0, len = queries.length; i < len; ++i) { - query = queries[i].trim(); - if (query.length !== 0) { - var tmp = execQuery(getQuery(query), searchWords, filterCrates); - - results.in_args.push(tmp.in_args); - results.returned.push(tmp.returned); - results.others.push(tmp.others); - } - } - if (queries.length > 1) { - return { - "in_args": mergeArrays(results.in_args), - "returned": mergeArrays(results.returned), - "others": mergeArrays(results.others), - }; - } - return { - "in_args": results.in_args[0], - "returned": results.returned[0], - "others": results.others[0], - }; - } - - function getFilterCrates() { - var elem = document.getElementById("crate-search"); - - if (elem && elem.value !== "All crates" && - hasOwnPropertyRustdoc(rawSearchIndex, elem.value)) - { - return elem.value; - } - return undefined; - } - - function search(e, forced) { - var params = searchState.getQueryStringParams(); - var query = getQuery(searchState.input.value.trim()); - - if (e) { - e.preventDefault(); - } - - if (query.query.length === 0) { - return; - } - if (!forced && query.id === currentResults) { - if (query.query.length > 0) { - searchState.putBackSearch(searchState.input); - } - return; - } - - // Update document title to maintain a meaningful browser history - searchState.title = "Results for " + query.query + " - Rust"; - - // Because searching is incremental by character, only the most - // recent search query is added to the browser history. - if (searchState.browserSupportsHistoryApi()) { - var newURL = getNakedUrl() + "?search=" + encodeURIComponent(query.raw) + - window.location.hash; - if (!history.state && !params.search) { - history.pushState(query, "", newURL); - } else { - history.replaceState(query, "", newURL); - } - } - - var filterCrates = getFilterCrates(); - showResults(execSearch(query, index, filterCrates), params.go_to_first); - } - - function buildIndex(rawSearchIndex) { - searchIndex = []; - var searchWords = []; - var i, word; - var currentIndex = 0; - var id = 0; - - for (var crate in rawSearchIndex) { - if (!hasOwnPropertyRustdoc(rawSearchIndex, crate)) { - continue; - } - - var crateSize = 0; - - searchWords.push(crate); - // This object should have exactly the same set of fields as the "row" - // object defined below. Your JavaScript runtime will thank you. - // https://mathiasbynens.be/notes/shapes-ics - var crateRow = { - crate: crate, - ty: 1, // == ExternCrate - name: crate, - path: "", - desc: rawSearchIndex[crate].doc, - parent: undefined, - type: null, - id: id, - normalizedName: crate.indexOf("_") === -1 ? crate : crate.replace(/_/g, ""), - }; - id += 1; - searchIndex.push(crateRow); - currentIndex += 1; - - // an array of (Number) item types - var itemTypes = rawSearchIndex[crate].t; - // an array of (String) item names - var itemNames = rawSearchIndex[crate].n; - // an array of (String) full paths (or empty string for previous path) - var itemPaths = rawSearchIndex[crate].q; - // an array of (String) descriptions - var itemDescs = rawSearchIndex[crate].d; - // an array of (Number) the parent path index + 1 to `paths`, or 0 if none - var itemParentIdxs = rawSearchIndex[crate].i; - // an array of (Object | null) the type of the function, if any - var itemFunctionSearchTypes = rawSearchIndex[crate].f; - // an array of [(Number) item type, - // (String) name] - var paths = rawSearchIndex[crate].p; - // a array of [(String) alias name - // [Number] index to items] - var aliases = rawSearchIndex[crate].a; - - // convert `rawPaths` entries into object form - var len = paths.length; - for (i = 0; i < len; ++i) { - paths[i] = {ty: paths[i][0], name: paths[i][1]}; - } - - // convert `item*` into an object form, and construct word indices. - // - // before any analysis is performed lets gather the search terms to - // search against apart from the rest of the data. This is a quick - // operation that is cached for the life of the page state so that - // all other search operations have access to this cached data for - // faster analysis operations - len = itemTypes.length; - var lastPath = ""; - for (i = 0; i < len; ++i) { - // This object should have exactly the same set of fields as the "crateRow" - // object defined above. - if (typeof itemNames[i] === "string") { - word = itemNames[i].toLowerCase(); - searchWords.push(word); - } else { - word = ""; - searchWords.push(""); - } - var row = { - crate: crate, - ty: itemTypes[i], - name: itemNames[i], - path: itemPaths[i] ? itemPaths[i] : lastPath, - desc: itemDescs[i], - parent: itemParentIdxs[i] > 0 ? paths[itemParentIdxs[i] - 1] : undefined, - type: itemFunctionSearchTypes[i], - id: id, - normalizedName: word.indexOf("_") === -1 ? word : word.replace(/_/g, ""), - }; - id += 1; - searchIndex.push(row); - lastPath = row.path; - crateSize += 1; - } - - if (aliases) { - ALIASES[crate] = {}; - var j, local_aliases; - for (var alias_name in aliases) { - if (!hasOwnPropertyRustdoc(aliases, alias_name)) { - continue; - } - - if (!hasOwnPropertyRustdoc(ALIASES[crate], alias_name)) { - ALIASES[crate][alias_name] = []; - } - local_aliases = aliases[alias_name]; - for (j = 0, len = local_aliases.length; j < len; ++j) { - ALIASES[crate][alias_name].push(local_aliases[j] + currentIndex); - } - } - } - currentIndex += crateSize; - } - return searchWords; - } - - function registerSearchEvents() { - var searchAfter500ms = function() { - searchState.clearInputTimeout(); - if (searchState.input.value.length === 0) { - if (searchState.browserSupportsHistoryApi()) { - history.replaceState("", window.currentCrate + " - Rust", - getNakedUrl() + window.location.hash); - } - searchState.hideResults(); - } else { - searchState.timeout = setTimeout(search, 500); - } - }; - searchState.input.onkeyup = searchAfter500ms; - searchState.input.oninput = searchAfter500ms; - document.getElementsByClassName("search-form")[0].onsubmit = function(e) { - e.preventDefault(); - searchState.clearInputTimeout(); - search(); - }; - searchState.input.onchange = function(e) { - if (e.target !== document.activeElement) { - // To prevent doing anything when it's from a blur event. - return; - } - // Do NOT e.preventDefault() here. It will prevent pasting. - searchState.clearInputTimeout(); - // zero-timeout necessary here because at the time of event handler execution the - // pasted content is not in the input field yet. Shouldn’t make any difference for - // change, though. - setTimeout(search, 0); - }; - searchState.input.onpaste = searchState.input.onchange; - - searchState.outputElement().addEventListener("keydown", function(e) { - // We only handle unmodified keystrokes here. We don't want to interfere with, - // for instance, alt-left and alt-right for history navigation. - if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) { - return; - } - // up and down arrow select next/previous search result, or the - // search box if we're already at the top. - if (e.which === 38) { // up - var previous = document.activeElement.previousElementSibling; - if (previous) { - previous.focus(); - } else { - searchState.focus(); - } - e.preventDefault(); - } else if (e.which === 40) { // down - var next = document.activeElement.nextElementSibling; - if (next) { - next.focus(); - } - var rect = document.activeElement.getBoundingClientRect(); - if (window.innerHeight - rect.bottom < rect.height) { - window.scrollBy(0, rect.height); - } - e.preventDefault(); - } else if (e.which === 37) { // left - nextTab(-1); - e.preventDefault(); - } else if (e.which === 39) { // right - nextTab(1); - e.preventDefault(); - } - }); - - searchState.input.addEventListener("keydown", function(e) { - if (e.which === 40) { // down - focusSearchResult(); - e.preventDefault(); - } - }); - - - var selectCrate = document.getElementById("crate-search"); - if (selectCrate) { - selectCrate.onchange = function() { - updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value); - // In case you "cut" the entry from the search input, then change the crate filter - // before paste back the previous search, you get the old search results without - // the filter. To prevent this, we need to remove the previous results. - currentResults = null; - search(undefined, true); - }; - } - - // Push and pop states are used to add search results to the browser - // history. - if (searchState.browserSupportsHistoryApi()) { - // Store the previous <title> so we can revert back to it later. - var previousTitle = document.title; - - window.addEventListener("popstate", function(e) { - var params = searchState.getQueryStringParams(); - // Revert to the previous title manually since the History - // API ignores the title parameter. - document.title = previousTitle; - // When browsing forward to search results the previous - // search will be repeated, so the currentResults are - // cleared to ensure the search is successful. - currentResults = null; - // Synchronize search bar with query string state and - // perform the search. This will empty the bar if there's - // nothing there, which lets you really go back to a - // previous state with nothing in the bar. - if (params.search && params.search.length > 0) { - searchState.input.value = params.search; - // Some browsers fire "onpopstate" for every page load - // (Chrome), while others fire the event only when actually - // popping a state (Firefox), which is why search() is - // called both here and at the end of the startSearch() - // function. - search(e); - } else { - searchState.input.value = ""; - // When browsing back from search results the main page - // visibility must be reset. - searchState.hideResults(); - } - }); - } - - // This is required in firefox to avoid this problem: Navigating to a search result - // with the keyboard, hitting enter, and then hitting back would take you back to - // the doc page, rather than the search that should overlay it. - // This was an interaction between the back-forward cache and our handlers - // that try to sync state between the URL and the search input. To work around it, - // do a small amount of re-init on page show. - window.onpageshow = function(){ - var qSearch = searchState.getQueryStringParams().search; - if (searchState.input.value === "" && qSearch) { - searchState.input.value = qSearch; - } - search(); - }; - } - - index = buildIndex(rawSearchIndex); - registerSearchEvents(); - // If there's a search term in the URL, execute the search now. - if (searchState.getQueryStringParams().search) { - search(); - } -}; - -if (window.searchIndex !== undefined) { - initSearch(window.searchIndex); -} - -})(); diff --git a/src/librustdoc/html/static/settings.css b/src/librustdoc/html/static/settings.css deleted file mode 100644 index fb8990b30e2..00000000000 --- a/src/librustdoc/html/static/settings.css +++ /dev/null @@ -1,107 +0,0 @@ -.setting-line { - padding: 5px; - position: relative; -} - -.setting-line > div { - display: inline-block; - vertical-align: top; - font-size: 17px; - padding-top: 2px; -} - -.setting-line > .title { - font-size: 19px; - width: 100%; - max-width: none; - border-bottom: 1px solid; -} - -.toggle { - position: relative; - display: inline-block; - width: 45px; - height: 27px; - margin-right: 20px; -} - -.toggle input { - opacity: 0; - position: absolute; -} - -.select-wrapper { - float: right; - position: relative; - height: 27px; - min-width: 25%; -} - -.select-wrapper select { - appearance: none; - -moz-appearance: none; - -webkit-appearance: none; - background: none; - border: 2px solid #ccc; - padding-right: 28px; - width: 100%; -} - -.select-wrapper img { - pointer-events: none; - position: absolute; - right: 0; - bottom: 0; - background: #ccc; - height: 100%; - width: 28px; - padding: 0px 4px; -} - -.select-wrapper select option { - color: initial; -} - -.slider { - position: absolute; - cursor: pointer; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: #ccc; - -webkit-transition: .3s; - transition: .3s; -} - -.slider:before { - position: absolute; - content: ""; - height: 19px; - width: 19px; - left: 4px; - bottom: 4px; - background-color: white; - -webkit-transition: .3s; - transition: .3s; -} - -input:checked + .slider { - background-color: #2196F3; -} - -input:focus + .slider { - box-shadow: 0 0 0 2px #0a84ff, 0 0 0 6px rgba(10, 132, 255, 0.3); -} - -input:checked + .slider:before { - -webkit-transform: translateX(19px); - -ms-transform: translateX(19px); - transform: translateX(19px); -} - -.setting-line > .sub-settings { - padding-left: 42px; - width: 100%; - display: block; -} diff --git a/src/librustdoc/html/static/settings.js b/src/librustdoc/html/static/settings.js deleted file mode 100644 index 4f10e14e855..00000000000 --- a/src/librustdoc/html/static/settings.js +++ /dev/null @@ -1,60 +0,0 @@ -// Local js definitions: -/* global getSettingValue, getVirtualKey, onEachLazy, updateLocalStorage, updateSystemTheme */ - -(function () { - function changeSetting(settingName, value) { - updateLocalStorage("rustdoc-" + settingName, value); - - switch (settingName) { - case "preferred-dark-theme": - case "preferred-light-theme": - case "use-system-theme": - updateSystemTheme(); - break; - } - } - - function handleKey(ev) { - // Don't interfere with browser shortcuts - if (ev.ctrlKey || ev.altKey || ev.metaKey) { - return; - } - switch (getVirtualKey(ev)) { - case "Enter": - case "Return": - case "Space": - ev.target.checked = !ev.target.checked; - ev.preventDefault(); - break; - } - } - - function setEvents() { - onEachLazy(document.getElementsByClassName("slider"), function(elem) { - var toggle = elem.previousElementSibling; - var settingId = toggle.id; - var settingValue = getSettingValue(settingId); - if (settingValue !== null) { - toggle.checked = settingValue === "true"; - } - toggle.onchange = function() { - changeSetting(this.id, this.checked); - }; - toggle.onkeyup = handleKey; - toggle.onkeyrelease = handleKey; - }); - onEachLazy(document.getElementsByClassName("select-wrapper"), function(elem) { - var select = elem.getElementsByTagName("select")[0]; - var settingId = select.id; - var settingValue = getSettingValue(settingId); - if (settingValue !== null) { - select.value = settingValue; - } - select.onchange = function() { - changeSetting(this.id, this.value); - }; - }); - } - - window.addEventListener("DOMContentLoaded", setEvents); -})(); diff --git a/src/librustdoc/html/static/source-script.js b/src/librustdoc/html/static/source-script.js deleted file mode 100644 index 4d9a59f836b..00000000000 --- a/src/librustdoc/html/static/source-script.js +++ /dev/null @@ -1,249 +0,0 @@ -// From rust: -/* global search, sourcesIndex */ - -// Local js definitions: -/* global addClass, getCurrentValue, hasClass, onEachLazy, removeClass, searchState */ -/* global updateLocalStorage */ -(function() { - -function getCurrentFilePath() { - var parts = window.location.pathname.split("/"); - var rootPathParts = window.rootPath.split("/"); - - for (var i = 0, len = rootPathParts.length; i < len; ++i) { - if (rootPathParts[i] === "..") { - parts.pop(); - } - } - var file = window.location.pathname.substring(parts.join("/").length); - if (file.startsWith("/")) { - file = file.substring(1); - } - return file.substring(0, file.length - 5); -} - -function createDirEntry(elem, parent, fullPath, currentFile, hasFoundFile) { - var name = document.createElement("div"); - name.className = "name"; - - fullPath += elem["name"] + "/"; - - name.onclick = function() { - if (hasClass(this, "expand")) { - removeClass(this, "expand"); - } else { - addClass(this, "expand"); - } - }; - name.innerText = elem["name"]; - - var i, len; - - var children = document.createElement("div"); - children.className = "children"; - var folders = document.createElement("div"); - folders.className = "folders"; - if (elem.dirs) { - for (i = 0, len = elem.dirs.length; i < len; ++i) { - if (createDirEntry(elem.dirs[i], folders, fullPath, currentFile, - hasFoundFile)) { - addClass(name, "expand"); - hasFoundFile = true; - } - } - } - children.appendChild(folders); - - var files = document.createElement("div"); - files.className = "files"; - if (elem.files) { - for (i = 0, len = elem.files.length; i < len; ++i) { - var file = document.createElement("a"); - file.innerText = elem.files[i]; - file.href = window.rootPath + "src/" + fullPath + elem.files[i] + ".html"; - if (!hasFoundFile && currentFile === fullPath + elem.files[i]) { - file.className = "selected"; - addClass(name, "expand"); - hasFoundFile = true; - } - files.appendChild(file); - } - } - search.fullPath = fullPath; - children.appendChild(files); - parent.appendChild(name); - parent.appendChild(children); - return hasFoundFile && currentFile.startsWith(fullPath); -} - -function toggleSidebar() { - var sidebar = document.getElementById("source-sidebar"); - var child = this.children[0].children[0]; - if (child.innerText === ">") { - sidebar.style.left = ""; - this.style.left = ""; - child.innerText = "<"; - updateLocalStorage("rustdoc-source-sidebar-show", "true"); - } else { - sidebar.style.left = "-300px"; - this.style.left = "0"; - child.innerText = ">"; - updateLocalStorage("rustdoc-source-sidebar-show", "false"); - } -} - -function createSidebarToggle() { - var sidebarToggle = document.createElement("div"); - sidebarToggle.id = "sidebar-toggle"; - sidebarToggle.onclick = toggleSidebar; - - var inner1 = document.createElement("div"); - inner1.style.position = "relative"; - - var inner2 = document.createElement("div"); - inner2.style.paddingTop = "3px"; - if (getCurrentValue("rustdoc-source-sidebar-show") === "true") { - inner2.innerText = "<"; - } else { - inner2.innerText = ">"; - sidebarToggle.style.left = "0"; - } - - inner1.appendChild(inner2); - sidebarToggle.appendChild(inner1); - return sidebarToggle; -} - -// This function is called from "source-files.js", generated in `html/render/mod.rs`. -// eslint-disable-next-line no-unused-vars -function createSourceSidebar() { - if (!window.rootPath.endsWith("/")) { - window.rootPath += "/"; - } - var main = document.getElementById("main"); - - var sidebarToggle = createSidebarToggle(); - main.insertBefore(sidebarToggle, main.firstChild); - - var sidebar = document.createElement("div"); - sidebar.id = "source-sidebar"; - if (getCurrentValue("rustdoc-source-sidebar-show") !== "true") { - sidebar.style.left = "-300px"; - } - - var currentFile = getCurrentFilePath(); - var hasFoundFile = false; - - var title = document.createElement("div"); - title.className = "title"; - title.innerText = "Files"; - sidebar.appendChild(title); - Object.keys(sourcesIndex).forEach(function(key) { - sourcesIndex[key].name = key; - hasFoundFile = createDirEntry(sourcesIndex[key], sidebar, "", - currentFile, hasFoundFile); - }); - - main.insertBefore(sidebar, main.firstChild); - // Focus on the current file in the source files sidebar. - var selected_elem = sidebar.getElementsByClassName("selected")[0]; - if (typeof selected_elem !== "undefined") { - selected_elem.focus(); - } -} - -var lineNumbersRegex = /^#?(\d+)(?:-(\d+))?$/; - -function highlightSourceLines(scrollTo, match) { - if (typeof match === "undefined") { - match = window.location.hash.match(lineNumbersRegex); - } - if (!match) { - return; - } - var from = parseInt(match[1], 10); - var to = from; - if (typeof match[2] !== "undefined") { - to = parseInt(match[2], 10); - } - if (to < from) { - var tmp = to; - to = from; - from = tmp; - } - var elem = document.getElementById(from); - if (!elem) { - return; - } - if (scrollTo) { - var x = document.getElementById(from); - if (x) { - x.scrollIntoView(); - } - } - onEachLazy(document.getElementsByClassName("line-numbers"), function(e) { - onEachLazy(e.getElementsByTagName("span"), function(i_e) { - removeClass(i_e, "line-highlighted"); - }); - }); - for (var i = from; i <= to; ++i) { - elem = document.getElementById(i); - if (!elem) { - break; - } - addClass(elem, "line-highlighted"); - } -} - -var handleSourceHighlight = (function() { - var prev_line_id = 0; - - var set_fragment = function(name) { - var x = window.scrollX, - y = window.scrollY; - if (searchState.browserSupportsHistoryApi()) { - history.replaceState(null, null, "#" + name); - highlightSourceLines(true); - } else { - location.replace("#" + name); - } - // Prevent jumps when selecting one or many lines - window.scrollTo(x, y); - }; - - return function(ev) { - var cur_line_id = parseInt(ev.target.id, 10); - ev.preventDefault(); - - if (ev.shiftKey && prev_line_id) { - // Swap selection if needed - if (prev_line_id > cur_line_id) { - var tmp = prev_line_id; - prev_line_id = cur_line_id; - cur_line_id = tmp; - } - - set_fragment(prev_line_id + "-" + cur_line_id); - } else { - prev_line_id = cur_line_id; - - set_fragment(cur_line_id); - } - }; -}()); - -window.addEventListener("hashchange", function() { - var match = window.location.hash.match(lineNumbersRegex); - if (match) { - return highlightSourceLines(false, match); - } -}); - -onEachLazy(document.getElementsByClassName("line-numbers"), function(el) { - el.addEventListener("click", handleSourceHighlight); -}); - -highlightSourceLines(true); - -window.createSourceSidebar = createSourceSidebar; -})(); diff --git a/src/librustdoc/html/static/storage.js b/src/librustdoc/html/static/storage.js deleted file mode 100644 index 2eaa81a97d8..00000000000 --- a/src/librustdoc/html/static/storage.js +++ /dev/null @@ -1,219 +0,0 @@ -// From rust: -/* global resourcesSuffix */ -var darkThemes = ["dark", "ayu"]; -window.currentTheme = document.getElementById("themeStyle"); -window.mainTheme = document.getElementById("mainThemeStyle"); - -var settingsDataset = (function () { - var settingsElement = document.getElementById("default-settings"); - if (settingsElement === null) { - return null; - } - var dataset = settingsElement.dataset; - if (dataset === undefined) { - return null; - } - return dataset; -})(); - -function getSettingValue(settingName) { - var current = getCurrentValue('rustdoc-' + settingName); - if (current !== null) { - return current; - } - if (settingsDataset !== null) { - var def = settingsDataset[settingName.replace(/-/g,'_')]; - if (def !== undefined) { - return def; - } - } - return null; -} - -var localStoredTheme = getSettingValue("theme"); - -var savedHref = []; - -// eslint-disable-next-line no-unused-vars -function hasClass(elem, className) { - return elem && elem.classList && elem.classList.contains(className); -} - -// eslint-disable-next-line no-unused-vars -function addClass(elem, className) { - if (!elem || !elem.classList) { - return; - } - elem.classList.add(className); -} - -// eslint-disable-next-line no-unused-vars -function removeClass(elem, className) { - if (!elem || !elem.classList) { - return; - } - elem.classList.remove(className); -} - -function onEach(arr, func, reversed) { - if (arr && arr.length > 0 && func) { - var length = arr.length; - var i; - if (reversed) { - for (i = length - 1; i >= 0; --i) { - if (func(arr[i])) { - return true; - } - } - } else { - for (i = 0; i < length; ++i) { - if (func(arr[i])) { - return true; - } - } - } - } - return false; -} - -function onEachLazy(lazyArray, func, reversed) { - return onEach( - Array.prototype.slice.call(lazyArray), - func, - reversed); -} - -// eslint-disable-next-line no-unused-vars -function hasOwnPropertyRustdoc(obj, property) { - return Object.prototype.hasOwnProperty.call(obj, property); -} - -function updateLocalStorage(name, value) { - try { - window.localStorage.setItem(name, value); - } catch(e) { - // localStorage is not accessible, do nothing - } -} - -function getCurrentValue(name) { - try { - return window.localStorage.getItem(name); - } catch(e) { - return null; - } -} - -function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) { - var fullBasicCss = "rustdoc" + resourcesSuffix + ".css"; - var fullNewTheme = newTheme + resourcesSuffix + ".css"; - var newHref = mainStyleElem.href.replace(fullBasicCss, fullNewTheme); - - // If this new value comes from a system setting or from the previously - // saved theme, no need to save it. - if (saveTheme) { - updateLocalStorage("rustdoc-theme", newTheme); - } - - if (styleElem.href === newHref) { - return; - } - - var found = false; - if (savedHref.length === 0) { - onEachLazy(document.getElementsByTagName("link"), function(el) { - savedHref.push(el.href); - }); - } - onEach(savedHref, function(el) { - if (el === newHref) { - found = true; - return true; - } - }); - if (found) { - styleElem.href = newHref; - } -} - -// This function is called from "main.js". -// eslint-disable-next-line no-unused-vars -function useSystemTheme(value) { - if (value === undefined) { - value = true; - } - - updateLocalStorage("rustdoc-use-system-theme", value); - - // update the toggle if we're on the settings page - var toggle = document.getElementById("use-system-theme"); - if (toggle && toggle instanceof HTMLInputElement) { - toggle.checked = value; - } -} - -var updateSystemTheme = (function() { - if (!window.matchMedia) { - // fallback to the CSS computed value - return function() { - var cssTheme = getComputedStyle(document.documentElement) - .getPropertyValue('content'); - - switchTheme( - window.currentTheme, - window.mainTheme, - JSON.parse(cssTheme) || "light", - true - ); - }; - } - - // only listen to (prefers-color-scheme: dark) because light is the default - var mql = window.matchMedia("(prefers-color-scheme: dark)"); - - function handlePreferenceChange(mql) { - // maybe the user has disabled the setting in the meantime! - if (getSettingValue("use-system-theme") !== "false") { - var lightTheme = getSettingValue("preferred-light-theme") || "light"; - var darkTheme = getSettingValue("preferred-dark-theme") || "dark"; - - if (mql.matches) { - // prefers a dark theme - switchTheme(window.currentTheme, window.mainTheme, darkTheme, true); - } else { - // prefers a light theme, or has no preference - switchTheme(window.currentTheme, window.mainTheme, lightTheme, true); - } - - // note: we save the theme so that it doesn't suddenly change when - // the user disables "use-system-theme" and reloads the page or - // navigates to another page - } - } - - mql.addListener(handlePreferenceChange); - - return function() { - handlePreferenceChange(mql); - }; -})(); - -if (getSettingValue("use-system-theme") !== "false" && window.matchMedia) { - // update the preferred dark theme if the user is already using a dark theme - // See https://github.com/rust-lang/rust/pull/77809#issuecomment-707875732 - if (getSettingValue("use-system-theme") === null - && getSettingValue("preferred-dark-theme") === null - && darkThemes.indexOf(localStoredTheme) >= 0) { - updateLocalStorage("rustdoc-preferred-dark-theme", localStoredTheme); - } - - // call the function to initialize the theme at least once! - updateSystemTheme(); -} else { - switchTheme( - window.currentTheme, - window.mainTheme, - getSettingValue("theme") || "light", - false - ); -} diff --git a/src/librustdoc/html/static/themes/ayu.css b/src/librustdoc/html/static/themes/ayu.css deleted file mode 100644 index 171d06c0a36..00000000000 --- a/src/librustdoc/html/static/themes/ayu.css +++ /dev/null @@ -1,607 +0,0 @@ -/* -Based off of the Ayu theme -Original by Dempfi (https://github.com/dempfi/ayu) -*/ - -/* General structure and fonts */ - -body { - background-color: #0f1419; - color: #c5c5c5; -} - -h1, h2, h3, h4 { - color: white; -} -h1.fqn { - border-bottom-color: #5c6773; -} -h1.fqn a { - color: #fff; -} -h2, h3, h4 { - border-bottom-color: #5c6773; -} -h4 { - border: none; -} - -.in-band { - background-color: #0f1419; -} - -.invisible { - background: rgba(0, 0, 0, 0); -} - -code { - color: #ffb454; -} -h3 > code, h4 > code, h5 > code { - color: #e6e1cf; -} -pre > code { - color: #e6e1cf; -} -span code { - color: #e6e1cf; -} -.docblock a > code { - color: #39AFD7 !important; -} -.docblock code, .docblock-short code { - background-color: #191f26; -} -pre, .rustdoc.source .example-wrap { - color: #e6e1cf; - background-color: #191f26; -} - -.sidebar { - background-color: #14191f; -} - -.logo-container.rust-logo > img { - filter: drop-shadow(1px 0 0px #fff) - drop-shadow(0 1px 0 #fff) - drop-shadow(-1px 0 0 #fff) - drop-shadow(0 -1px 0 #fff); -} - -/* Improve the scrollbar display on firefox */ -* { - scrollbar-color: #5c6773 transparent; -} - -.sidebar { - scrollbar-color: #5c6773 transparent; -} - -/* Improve the scrollbar display on webkit-based browsers */ -::-webkit-scrollbar-track { - background-color: transparent; -} -::-webkit-scrollbar-thumb { - background-color: #5c6773; -} -.sidebar::-webkit-scrollbar-track { - background-color: transparent; -} -.sidebar::-webkit-scrollbar-thumb { - background-color: #5c6773; -} - -.sidebar .current { - background-color: transparent; - color: #ffb44c; -} - -.source .sidebar { - background-color: #0f1419; -} - -.sidebar .location { - border-color: #000; - background-color: #0f1419; - color: #fff; -} - -.sidebar-elems .location { - color: #ff7733; -} - -.sidebar-elems .location a { - color: #fff; -} - -.sidebar .version { - border-bottom-color: #424c57; -} - -.sidebar-title { - border-top-color: #5c6773; - border-bottom-color: #5c6773; -} - -.block a:hover { - background: transparent; - color: #ffb44c; -} - -.line-numbers span { color: #5c6773; } -.line-numbers .line-highlighted { - color: #708090; - background-color: rgba(255, 236, 164, 0.06); - padding-right: 4px; - border-right: 1px solid #ffb44c; -} - -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { - border-bottom-color: #5c6773; -} - -.docblock table, .docblock table td, .docblock table th { - border-color: #5c6773; -} - -.content .method .where, -.content .fn .where, -.content .where.fmt-newline { - color: #c5c5c5; -} - -.search-results a:hover { - background-color: #777; -} - -.search-results a:focus { - color: #000 !important; - background-color: #c6afb3; -} -.search-results a { - color: #0096cf; -} -.search-results a span.desc { - color: #c5c5c5; -} - -.content .item-info::before { color: #ccc; } - -.content span.foreigntype, .content a.foreigntype { color: #ef57ff; } -.content span.union, .content a.union { color: #98a01c; } -.content span.constant, .content a.constant, -.content span.static, .content a.static { color: #6380a0; } -.content span.primitive, .content a.primitive { color: #32889b; } -.content span.traitalias, .content a.traitalias { color: #57d399; } -.content span.keyword, .content a.keyword { color: #de5249; } - -.content span.externcrate, .content span.mod, .content a.mod { - color: #acccf9; -} -.content span.struct, .content a.struct { - color: #ffa0a5; -} -.content span.enum, .content a.enum { - color: #99e0c9; -} -.content span.trait, .content a.trait { - color: #39AFD7; -} -.content span.type, .content a.type { - color: #cfbcf5; -} -.content span.fn, .content a.fn, .content span.method, -.content a.method, .content span.tymethod, -.content a.tymethod, .content .fnname { - color: #fdd687; -} -.content span.attr, .content a.attr, .content span.derive, -.content a.derive, .content span.macro, .content a.macro { - color: #a37acc; -} - -pre.rust .comment { color: #788797; } -pre.rust .doccomment { color: #a1ac88; } - -nav:not(.sidebar) { - border-bottom-color: #424c57; -} -nav.main .current { - border-top-color: #5c6773; - border-bottom-color: #5c6773; -} -nav.main .separator { - border: 1px solid #5c6773; -} -a { - color: #c5c5c5; -} - -.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), -.docblock-short a:not(.srclink):not(.test-arrow), .item-info a, -#help a { - color: #39AFD7; -} - -details.rustdoc-toggle > summary.hideme > span, -details.rustdoc-toggle > summary::before, -details.undocumented > summary::before { - color: #999; -} - -#crate-search { - color: #c5c5c5; - background-color: #141920; - box-shadow: 0 0 0 1px #424c57,0 0 0 2px transparent; - border-color: #424c57; -} - -.search-input { - color: #ffffff; - background-color: #141920; - box-shadow: 0 0 0 1px #424c57,0 0 0 2px transparent; - transition: box-shadow 150ms ease-in-out; -} - -#crate-search+.search-input:focus { - box-shadow: 0 0 0 1px #148099,0 0 0 2px transparent; -} - -.search-input:disabled { - background-color: #3e3e3e; -} - -.module-item .stab, -.import-item .stab { - color: #000; -} - -.stab.unstable, -.stab.deprecated, -.stab.portability { - color: #c5c5c5; - background: #314559 !important; - border-style: none !important; - border-radius: 4px; - padding: 3px 6px 3px 6px; -} - -.stab.portability > code { - color: #e6e1cf; - background: none; -} - -#help > div { - background: #14191f; - box-shadow: 0px 6px 20px 0px black; - border: none; - border-radius: 4px; -} - -#help > div > span { - border-bottom-color: #5c6773; -} - -.since { - color: grey; -} - -tr.result span.primitive::after, tr.result span.keyword::after { - color: #788797; -} - -.line-numbers :target { background-color: transparent; } - -/* Code highlighting */ -pre.rust .number, pre.rust .string { color: #b8cc52; } -pre.rust .kw, pre.rust .kw-2, pre.rust .prelude-ty, -pre.rust .bool-val, pre.rust .prelude-val, -pre.rust .op, pre.rust .lifetime { color: #ff7733; } -pre.rust .macro, pre.rust .macro-nonterminal { color: #a37acc; } -pre.rust .question-mark { - color: #ff9011; -} -pre.rust .self { - color: #36a3d9; - font-style: italic; -} -pre.rust .attribute { - color: #e6e1cf; -} -pre.rust .attribute .ident, pre.rust .attribute .op { - color: #e6e1cf; -} - -.example-wrap > pre.line-number { - color: #5c67736e; - border: none; -} - -a.test-arrow { - font-size: 100%; - color: #788797; - border-radius: 4px; - background-color: rgba(57, 175, 215, 0.09); -} - -a.test-arrow:hover { - background-color: rgba(57, 175, 215, 0.368); - color: #c5c5c5; -} - -.toggle-label, -.code-attribute { - color: #999; -} - -:target, :target * { - background: rgba(255, 236, 164, 0.06); -} - -:target { - border-right: 3px solid rgba(255, 180, 76, 0.85); -} - -pre.compile_fail { - border-left: 2px solid rgba(255,0,0,.4); -} - -pre.compile_fail:hover, .information:hover + pre.compile_fail { - border-left: 2px solid #f00; -} - -pre.should_panic { - border-left: 2px solid rgba(255,0,0,.4); -} - -pre.should_panic:hover, .information:hover + pre.should_panic { - border-left: 2px solid #f00; -} - -pre.ignore { - border-left: 2px solid rgba(255,142,0,.6); -} - -pre.ignore:hover, .information:hover + pre.ignore { - border-left: 2px solid #ff9200; -} - -.tooltip.compile_fail { - color: rgba(255,0,0,.5); -} - -.information > .compile_fail:hover { - color: #f00; -} - -.tooltip.should_panic { - color: rgba(255,0,0,.5); -} - -.information > .should_panic:hover { - color: #f00; -} - -.tooltip.ignore { - color: rgba(255,142,0,.6); -} - -.information > .ignore:hover { - color: #ff9200; -} - -.search-failed a { - color: #39AFD7; -} - -.tooltip::after { - background-color: #314559; - color: #c5c5c5; - border: 1px solid #5c6773; -} - -.tooltip::before { - border-color: transparent #314559 transparent transparent; -} - -.notable-traits-tooltiptext { - background-color: #314559; - border-color: #5c6773; -} - -.notable-traits-tooltiptext .notable { - border-bottom-color: #5c6773; -} - -#titles > button.selected { - background-color: #141920 !important; - border-bottom: 1px solid #ffb44c !important; - border-top: none; -} - -#titles > button:not(.selected) { - background-color: transparent !important; - border: none; -} - -#titles > button:hover { - border-bottom: 1px solid rgba(242, 151, 24, 0.3); -} - -#titles > button > div.count { - color: #888; -} - -/* rules that this theme does not need to set, here to satisfy the rule checker */ -/* note that a lot of these are partially set in some way (meaning they are set -individually rather than as a group) */ -/* FIXME: these rules should be at the bottom of the file but currently must be -above the `@media (max-width: 700px)` rules due to a bug in the css checker */ -/* see https://github.com/rust-lang/rust/pull/71237#issuecomment-618170143 */ -.search-input:focus {} -.content span.attr,.content a.attr,.block a.current.attr,.content span.derive,.content a.derive, -.block a.current.derive,.content span.macro,.content a.macro,.block a.current.macro {} -.content span.struct,.content a.struct,.block a.current.struct {} -#titles>button:hover,#titles>button.selected {} -.content span.type,.content a.type,.block a.current.type {} -.content span.union,.content a.union,.block a.current.union {} -pre.rust .lifetime {} -.stab.unstable {} -h2,h3:not(.impl):not(.method):not(.type):not(.tymethod),h4:not(.method):not(.type):not(.tymethod) {} -.content span.enum,.content a.enum,.block a.current.enum {} -.content span.constant,.content a.constant,.block a.current.constant,.content span.static, -.content a.static, .block a.current.static {} -.content span.keyword,.content a.keyword,.block a.current.keyword {} -pre.rust .comment {} -.content span.traitalias,.content a.traitalias,.block a.current.traitalias {} -.content span.fn,.content a.fn,.block a.current.fn,.content span.method,.content a.method, -.block a.current.method,.content span.tymethod,.content a.tymethod,.block a.current.tymethod, -.content .fnname {} -pre.rust .kw {} -pre.rust .self,pre.rust .bool-val,pre.rust .prelude-val,pre.rust .attribute, -pre.rust .attribute .ident {} -.content span.foreigntype,.content a.foreigntype,.block a.current.foreigntype {} -pre.rust .doccomment {} -.stab.deprecated {} -.content a.attr,.content a.derive,.content a.macro {} -.stab.portability {} -.content span.primitive,.content a.primitive,.block a.current.primitive {} -.content span.externcrate,.content span.mod,.content a.mod,.block a.current.mod {} -pre.rust .kw-2,pre.rust .prelude-ty {} -.content span.trait,.content a.trait,.block a.current.trait {} - -.search-results a:focus span {} -a.result-trait:focus {} -a.result-traitalias:focus {} -a.result-mod:focus, -a.result-externcrate:focus {} -a.result-mod:focus {} -a.result-externcrate:focus {} -a.result-enum:focus {} -a.result-struct:focus {} -a.result-union:focus {} -a.result-fn:focus, -a.result-method:focus, -a.result-tymethod:focus {} -a.result-type:focus {} -a.result-foreigntype:focus {} -a.result-attr:focus, -a.result-derive:focus, -a.result-macro:focus {} -a.result-constant:focus, -a.result-static:focus {} -a.result-primitive:focus {} -a.result-keyword:focus {} - -@media (max-width: 700px) { - .sidebar-menu { - background-color: #14191f; - border-bottom-color: #5c6773; - border-right-color: #5c6773; - } - - .sidebar-elems { - background-color: #14191f; - border-right-color: #5c6773; - } - - #sidebar-filler { - background-color: #14191f; - border-bottom-color: #5c6773; - } -} - -kbd { - color: #c5c5c5; - background-color: #314559; - border-color: #5c6773; - border-bottom-color: #5c6773; - box-shadow-color: #c6cbd1; -} - -#theme-picker, #settings-menu, #help-button { - border-color: #5c6773; - background-color: #0f1419; - color: #fff; -} - -#theme-picker > img, #settings-menu > img { - filter: invert(100); -} - -#copy-path { - color: #fff; -} -#copy-path > img { - filter: invert(70%); -} -#copy-path:hover > img { - filter: invert(100%); -} - -#theme-picker:hover, #theme-picker:focus, -#settings-menu:hover, #settings-menu:focus, -#help-button:hover, #help-button:focus { - border-color: #e0e0e0; -} - -#theme-choices { - border-color: #5c6773; - background-color: #0f1419; -} - -#theme-choices > button:not(:first-child) { - border-top-color: #5c6773; -} - -#theme-choices > button:hover, #theme-choices > button:focus { - background-color: rgba(110, 110, 110, 0.33); -} - -@media (max-width: 700px) { - #theme-picker { - background: #0f1419; - } -} - -#all-types { - background-color: #14191f; -} -#all-types:hover { - background-color: rgba(70, 70, 70, 0.33); -} - -.search-results .result-name span.alias { - color: #c5c5c5; -} -.search-results .result-name span.grey { - color: #999; -} - -#sidebar-toggle { - background-color: #14191f; -} -#sidebar-toggle:hover { - background-color: rgba(70, 70, 70, 0.33); -} -#source-sidebar { - background-color: #14191f; -} -#source-sidebar > .title { - color: #fff; - border-bottom-color: #5c6773; -} -div.files > a:hover, div.name:hover { - background-color: #14191f; - color: #ffb44c; -} -div.files > .selected { - background-color: #14191f; - color: #ffb44c; -} -.setting-line > .title { - border-bottom-color: #5c6773; -} -input:checked + .slider { - background-color: #ffb454 !important; -} diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css deleted file mode 100644 index d9ea28058ad..00000000000 --- a/src/librustdoc/html/static/themes/dark.css +++ /dev/null @@ -1,479 +0,0 @@ -body { - background-color: #353535; - color: #ddd; -} - -h1, h2, h3, h4 { - color: #ddd; -} -h1.fqn { - border-bottom-color: #d2d2d2; -} -h2, h3, h4 { - border-bottom-color: #d2d2d2; -} - -.in-band { - background-color: #353535; -} - -.invisible { - background: rgba(0, 0, 0, 0); -} - -.docblock code, .docblock-short code { - background-color: #2A2A2A; -} -pre, .rustdoc.source .example-wrap { - background-color: #2A2A2A; -} - -.sidebar { - background-color: #505050; -} - -.logo-container.rust-logo > img { - filter: drop-shadow(1px 0 0px #fff) - drop-shadow(0 1px 0 #fff) - drop-shadow(-1px 0 0 #fff) - drop-shadow(0 -1px 0 #fff) -} - -/* Improve the scrollbar display on firefox */ -* { - scrollbar-color: rgb(64, 65, 67) #717171; -} -.sidebar { - scrollbar-color: rgba(32,34,37,.6) transparent; -} - -/* Improve the scrollbar display on webkit-based browsers */ -::-webkit-scrollbar-track { - background-color: #717171; -} -::-webkit-scrollbar-thumb { - background-color: rgba(32, 34, 37, .6); -} -.sidebar::-webkit-scrollbar-track { - background-color: #717171; -} -.sidebar::-webkit-scrollbar-thumb { - background-color: rgba(32, 34, 37, .6); -} - -.sidebar .current { - background-color: #333; -} - -.source .sidebar { - background-color: #353535; -} - -.sidebar .location { - border-color: #fff; - background: #575757; - color: #DDD; -} - -.sidebar .version { - border-bottom-color: #DDD; -} - -.sidebar-title { - border-top-color: #777; - border-bottom-color: #777; -} - -.block a:hover { - background: #444; -} - -.line-numbers span { color: #3B91E2; } -.line-numbers .line-highlighted { - background-color: #0a042f !important; -} - -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { - border-bottom-color: #DDD; -} - -.docblock table, .docblock table td, .docblock table th { - border-color: #ddd; -} - -.content .method .where, -.content .fn .where, -.content .where.fmt-newline { - color: #ddd; -} - -.search-results a:hover { - background-color: #777; -} - -.search-results a:focus { - color: #eee !important; - background-color: #616161; -} -.search-results a:focus span { color: #eee !important; } -a.result-trait:focus { background-color: #013191; } -a.result-traitalias:focus { background-color: #013191; } -a.result-mod:focus, -a.result-externcrate:focus { background-color: #afc6e4; } -a.result-mod:focus { background-color: #803a1b; } -a.result-externcrate:focus { background-color: #396bac; } -a.result-enum:focus { background-color: #5b4e68; } -a.result-struct:focus { background-color: #194e9f; } -a.result-union:focus { background-color: #b7bd49; } -a.result-fn:focus, -a.result-method:focus, -a.result-tymethod:focus { background-color: #4950ed; } -a.result-type:focus { background-color: #38902c; } -a.result-foreigntype:focus { background-color: #b200d6; } -a.result-attr:focus, -a.result-derive:focus, -a.result-macro:focus { background-color: #217d1c; } -a.result-constant:focus, -a.result-static:focus { background-color: #0063cc; } -a.result-primitive:focus { background-color: #00708a; } -a.result-keyword:focus { background-color: #884719; } - -.content .item-info::before { color: #ccc; } - -.content span.enum, .content a.enum, .block a.current.enum { color: #82b089; } -.content span.struct, .content a.struct, .block a.current.struct { color: #2dbfb8; } -.content span.type, .content a.type, .block a.current.type { color: #ff7f00; } -.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #dd7de8; } -.content span.attr, .content a.attr, .block a.current.attr, -.content span.derive, .content a.derive, .block a.current.derive, -.content span.macro, .content a.macro, .block a.current.macro { color: #09bd00; } -.content span.union, .content a.union, .block a.current.union { color: #a6ae37; } -.content span.constant, .content a.constant, .block a.current.constant, -.content span.static, .content a.static, .block a.current.static { color: #82a5c9; } -.content span.primitive, .content a.primitive, .block a.current.primitive { color: #43aec7; } -.content span.externcrate, -.content span.mod, .content a.mod, .block a.current.mod { color: #bda000; } -.content span.trait, .content a.trait, .block a.current.trait { color: #b78cf2; } -.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #b397da; } -.content span.fn, .content a.fn, .block a.current.fn, -.content span.method, .content a.method, .block a.current.method, -.content span.tymethod, .content a.tymethod, .block a.current.tymethod, -.content .fnname{ color: #2BAB63; } -.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; } - -pre.rust .comment { color: #8d8d8b; } -pre.rust .doccomment { color: #8ca375; } - -nav:not(.sidebar) { - border-bottom-color: #4e4e4e; -} -nav.main .current { - border-top-color: #eee; - border-bottom-color: #eee; -} -nav.main .separator { - border-color: #eee; -} -a { - color: #ddd; -} - -.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), -.docblock-short a:not(.srclink):not(.test-arrow), .item-info a, -#help a { - color: #D2991D; -} - -a.test-arrow { - color: #dedede; -} - -details.rustdoc-toggle > summary.hideme > span, -details.rustdoc-toggle > summary::before, -details.undocumented > summary::before { - color: #999; -} - -#crate-search { - color: #111; - background-color: #f0f0f0; - border-color: #000; - box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; -} - -.search-input { - color: #111; - background-color: #f0f0f0; - box-shadow: 0 0 0 1px #000, 0 0 0 2px transparent; -} - -.search-input:focus { - border-color: #008dfd; -} - -.search-input:disabled { - background-color: #c5c4c4; -} - -#crate-search + .search-input:focus { - box-shadow: 0 0 8px 4px #078dd8; -} - -.module-item .stab, -.import-item .stab { - color: #ddd; -} - -.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #2f2f2f; } -.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; color: #2f2f2f; } -.stab.portability { background: #F3DFFF; border-color: #b07bdb; color: #2f2f2f; } -.stab.portability > code { background: none; } - -#help > div { - background: #4d4d4d; - border-color: #bfbfbf; -} - -#help > div > span { - border-bottom-color: #bfbfbf; -} - -#help dt { - border-color: #bfbfbf; - background: rgba(0,0,0,0); -} - -.since { - color: grey; -} - -tr.result span.primitive::after, tr.result span.keyword::after { - color: #ddd; -} - -.line-numbers :target { background-color: transparent; } - -/* Code highlighting */ -pre.rust .kw { color: #ab8ac1; } -pre.rust .kw-2, pre.rust .prelude-ty { color: #769acb; } -pre.rust .number, pre.rust .string { color: #83a300; } -pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val, -pre.rust .attribute, pre.rust .attribute .ident { color: #ee6868; } -pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; } -pre.rust .lifetime { color: #d97f26; } -pre.rust .question-mark { - color: #ff9011; -} - -.example-wrap > pre.line-number { - border-color: #4a4949; -} - -a.test-arrow { - background-color: rgba(78, 139, 202, 0.2); -} - -a.test-arrow:hover{ - background-color: #4e8bca; -} - -.toggle-label, -.code-attribute { - color: #999; -} - -:target, :target * { - background-color: #494a3d; -} - -:target { - border-right: 3px solid #bb7410; -} - -pre.compile_fail { - border-left: 2px solid rgba(255,0,0,.8); -} - -pre.compile_fail:hover, .information:hover + pre.compile_fail { - border-left: 2px solid #f00; -} - -pre.should_panic { - border-left: 2px solid rgba(255,0,0,.8); -} - -pre.should_panic:hover, .information:hover + pre.should_panic { - border-left: 2px solid #f00; -} - -pre.ignore { - border-left: 2px solid rgba(255,142,0,.6); -} - -pre.ignore:hover, .information:hover + pre.ignore { - border-left: 2px solid #ff9200; -} - -.tooltip.compile_fail { - color: rgba(255,0,0,.8); -} - -.information > .compile_fail:hover { - color: #f00; -} - -.tooltip.should_panic { - color: rgba(255,0,0,.8); -} - -.information > .should_panic:hover { - color: #f00; -} - -.tooltip.ignore { - color: rgba(255,142,0,.6); -} - -.information > .ignore:hover { - color: #ff9200; -} - -.search-failed a { - color: #0089ff; -} - -.tooltip::after { - background-color: #000; - color: #fff; - border-color: #000; -} - -.tooltip::before { - border-color: transparent black transparent transparent; -} - -.notable-traits-tooltiptext { - background-color: #111; - border-color: #777; -} - -.notable-traits-tooltiptext .notable { - border-bottom-color: #d2d2d2; -} - -#titles > button:not(.selected) { - background-color: #252525; - border-top-color: #252525; -} - -#titles > button:hover, #titles > button.selected { - border-top-color: #0089ff; - background-color: #353535; -} - -#titles > button > div.count { - color: #888; -} - -@media (max-width: 700px) { - .sidebar-menu { - background-color: #505050; - border-bottom-color: #e0e0e0; - border-right-color: #e0e0e0; - } - - .sidebar-elems { - background-color: #505050; - border-right-color: #000; - } - - #sidebar-filler { - background-color: #505050; - border-bottom-color: #e0e0e0; - } -} - -kbd { - color: #000; - background-color: #fafbfc; - border-color: #d1d5da; - border-bottom-color: #c6cbd1; - box-shadow-color: #c6cbd1; -} - -#theme-picker, #settings-menu, #help-button { - border-color: #e0e0e0; - background: #f0f0f0; - color: #000; -} - -#theme-picker:hover, #theme-picker:focus, -#settings-menu:hover, #settings-menu:focus, -#help-button:hover, #help-button:focus { - border-color: #ffb900; -} - -#copy-path { - color: #999; -} -#copy-path > img { - filter: invert(50%); -} -#copy-path:hover > img { - filter: invert(65%); -} - -#theme-choices { - border-color: #e0e0e0; - background-color: #353535; -} - -#theme-choices > button:not(:first-child) { - border-top-color: #e0e0e0; -} - -#theme-choices > button:hover, #theme-choices > button:focus { - background-color: #4e4e4e; -} - -@media (max-width: 700px) { - #theme-picker { - background: #f0f0f0; - } -} - -#all-types { - background-color: #505050; -} -#all-types:hover { - background-color: #606060; -} - -.search-results .result-name span.alias { - color: #fff; -} -.search-results .result-name span.grey { - color: #ccc; -} - -#sidebar-toggle { - background-color: #565656; -} -#sidebar-toggle:hover { - background-color: #676767; -} -#source-sidebar { - background-color: #565656; -} -#source-sidebar > .title { - border-bottom-color: #ccc; -} -div.files > a:hover, div.name:hover { - background-color: #444; -} -div.files > .selected { - background-color: #333; -} -.setting-line > .title { - border-bottom-color: #ddd; -} diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css deleted file mode 100644 index 6785b79ffda..00000000000 --- a/src/librustdoc/html/static/themes/light.css +++ /dev/null @@ -1,469 +0,0 @@ -/* General structure and fonts */ - -body { - background-color: white; - color: black; -} - -h1, h2, h3, h4 { - color: black; -} -h1.fqn { - border-bottom-color: #D5D5D5; -} -h2, h3, h4 { - border-bottom-color: #DDDDDD; -} - -.in-band { - background-color: white; -} - -.invisible { - background: rgba(0, 0, 0, 0); -} - -.docblock code, .docblock-short code { - background-color: #F5F5F5; -} -pre, .rustdoc.source .example-wrap { - background-color: #F5F5F5; -} - -.sidebar { - background-color: #F1F1F1; -} - -/* Improve the scrollbar display on firefox */ -* { - scrollbar-color: rgba(36, 37, 39, 0.6) #e6e6e6; -} - -.sidebar { - scrollbar-color: rgba(36, 37, 39, 0.6) #d9d9d9; -} - -.logo-container.rust-logo > img { - /* No need for a border in here! */ -} - -/* Improve the scrollbar display on webkit-based browsers */ -::-webkit-scrollbar-track { - background-color: #ecebeb; -} -::-webkit-scrollbar-thumb { - background-color: rgba(36, 37, 39, 0.6); -} -.sidebar::-webkit-scrollbar-track { - background-color: #dcdcdc; -} -.sidebar::-webkit-scrollbar-thumb { - background-color: rgba(36, 37, 39, 0.6); -} - -.sidebar .current { - background-color: #fff; -} - -.source .sidebar { - background-color: #fff; -} - -.sidebar .location { - border-color: #000; - background-color: #fff; - color: #333; -} - -.sidebar .version { - border-bottom-color: #DDD; -} - -.sidebar-title { - border-top-color: #777; - border-bottom-color: #777; -} - -.block a:hover { - background: #F5F5F5; -} - -.line-numbers span { color: #c67e2d; } -.line-numbers .line-highlighted { - background-color: #f6fdb0 !important; -} - -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { - border-bottom-color: #ddd; -} - -.docblock table, .docblock table td, .docblock table th { - border-color: #ddd; -} - -.content .method .where, -.content .fn .where, -.content .where.fmt-newline { - color: #4E4C4C; -} - -.search-results a:hover { - background-color: #ddd; -} - -.search-results a:focus { - color: #000 !important; - background-color: #ccc; -} -.search-results a:focus span { color: #000 !important; } -a.result-trait:focus { background-color: #c7b6ff; } -a.result-traitalias:focus { background-color: #c7b6ff; } -a.result-mod:focus, -a.result-externcrate:focus { background-color: #afc6e4; } -a.result-enum:focus { background-color: #b4d1b9; } -a.result-struct:focus { background-color: #e7b1a0; } -a.result-union:focus { background-color: #b7bd49; } -a.result-fn:focus, -a.result-method:focus, -a.result-tymethod:focus { background-color: #c6afb3; } -a.result-type:focus { background-color: #ffc891; } -a.result-foreigntype:focus { background-color: #f5c4ff; } -a.result-attr:focus, -a.result-derive:focus, -a.result-macro:focus { background-color: #8ce488; } -a.result-constant:focus, -a.result-static:focus { background-color: #c3e0ff; } -a.result-primitive:focus { background-color: #9aecff; } -a.result-keyword:focus { background-color: #f99650; } - -.content .item-info::before { color: #ccc; } - -.content span.enum, .content a.enum, .block a.current.enum { color: #508157; } -.content span.struct, .content a.struct, .block a.current.struct { color: #ad448e; } -.content span.type, .content a.type, .block a.current.type { color: #ba5d00; } -.content span.foreigntype, .content a.foreigntype, .block a.current.foreigntype { color: #cd00e2; } -.content span.attr, .content a.attr, .block a.current.attr, -.content span.derive, .content a.derive, .block a.current.derive, -.content span.macro, .content a.macro, .block a.current.macro { color: #068000; } -.content span.union, .content a.union, .block a.current.union { color: #767b27; } -.content span.constant, .content a.constant, .block a.current.constant, -.content span.static, .content a.static, .block a.current.static { color: #546e8a; } -.content span.primitive, .content a.primitive, .block a.current.primitive { color: #2c8093; } -.content span.externcrate, -.content span.mod, .content a.mod, .block a.current.mod { color: #4d76ae; } -.content span.trait, .content a.trait, .block a.current.trait { color: #7c5af3; } -.content span.traitalias, .content a.traitalias, .block a.current.traitalias { color: #6841f1; } -.content span.fn, .content a.fn, .block a.current.fn, -.content span.method, .content a.method, .block a.current.method, -.content span.tymethod, .content a.tymethod, .block a.current.tymethod, -.content .fnname { color: #9a6e31; } -.content span.keyword, .content a.keyword, .block a.current.keyword { color: #de5249; } - -nav:not(.sidebar) { - border-bottom-color: #e0e0e0; -} -nav.main .current { - border-top-color: #000; - border-bottom-color: #000; -} -nav.main .separator { - border: 1px solid #000; -} -a { - color: #000; -} - -.docblock:not(.type-decl) a:not(.srclink):not(.test-arrow), -.docblock-short a:not(.srclink):not(.test-arrow), .item-info a, -#help a { - color: #3873AD; -} - -a.test-arrow { - color: #f5f5f5; -} - -details.rustdoc-toggle > summary.hideme > span, -details.rustdoc-toggle > summary::before, -details.undocumented > summary::before { - color: #999; -} - -#crate-search { - color: #555; - background-color: white; - border-color: #e0e0e0; - box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; -} - -.search-input { - color: #555; - background-color: white; - box-shadow: 0 0 0 1px #e0e0e0, 0 0 0 2px transparent; -} - -.search-input:focus { - border-color: #66afe9; -} - -.search-input:disabled { - background-color: #e6e6e6; -} - -#crate-search + .search-input:focus { - box-shadow: 0 0 8px #078dd8; -} - -.module-item .stab, -.import-item .stab { - color: #000; -} - -.stab.unstable { background: #FFF5D6; border-color: #FFC600; } -.stab.deprecated { background: #ffc4c4; border-color: #db7b7b; } -.stab.portability { background: #F3DFFF; border-color: #b07bdb; } -.stab.portability > code { background: none; } - -#help > div { - background: #e9e9e9; - border-color: #bfbfbf; -} - -#help > div > span { - border-bottom-color: #bfbfbf; -} - -.since { - color: grey; -} - -tr.result span.primitive::after, tr.result span.keyword::after { - color: black; -} - -.line-numbers :target { background-color: transparent; } - -/* Code highlighting */ -pre.rust .kw { color: #8959A8; } -pre.rust .kw-2, pre.rust .prelude-ty { color: #4271AE; } -pre.rust .number, pre.rust .string { color: #718C00; } -pre.rust .self, pre.rust .bool-val, pre.rust .prelude-val, -pre.rust .attribute, pre.rust .attribute .ident { color: #C82829; } -pre.rust .comment { color: #8E908C; } -pre.rust .doccomment { color: #4D4D4C; } -pre.rust .macro, pre.rust .macro-nonterminal { color: #3E999F; } -pre.rust .lifetime { color: #B76514; } -pre.rust .question-mark { - color: #ff9011; -} - -.example-wrap > pre.line-number { - border-color: #c7c7c7; -} - -a.test-arrow { - background-color: rgba(78, 139, 202, 0.2); -} - -a.test-arrow:hover{ - background-color: #4e8bca; -} - -.toggle-label, -.code-attribute { - color: #999; -} - -:target, :target * { - background: #FDFFD3; -} - -:target { - border-right: 3px solid #ffb44c; -} - -pre.compile_fail { - border-left: 2px solid rgba(255,0,0,.5); -} - -pre.compile_fail:hover, .information:hover + pre.compile_fail { - border-left: 2px solid #f00; -} - -pre.should_panic { - border-left: 2px solid rgba(255,0,0,.5); -} - -pre.should_panic:hover, .information:hover + pre.should_panic { - border-left: 2px solid #f00; -} - -pre.ignore { - border-left: 2px solid rgba(255,142,0,.6); -} - -pre.ignore:hover, .information:hover + pre.ignore { - border-left: 2px solid #ff9200; -} - -.tooltip.compile_fail { - color: rgba(255,0,0,.5); -} - -.information > .compile_fail:hover { - color: #f00; -} - -.tooltip.should_panic { - color: rgba(255,0,0,.5); -} - -.information > .should_panic:hover { - color: #f00; -} - -.tooltip.ignore { - color: rgba(255,142,0,.6); -} - -.information > .ignore:hover { - color: #ff9200; -} - -.search-failed a { - color: #0089ff; -} - -.tooltip::after { - background-color: #000; - color: #fff; -} - -.tooltip::before { - border-color: transparent black transparent transparent; -} - -.notable-traits-tooltiptext { - background-color: #eee; - border-color: #999; -} - -.notable-traits-tooltiptext .notable { - border-bottom-color: #DDDDDD; -} - -#titles > button:not(.selected) { - background-color: #e6e6e6; - border-top-color: #e6e6e6; -} - -#titles > button:hover, #titles > button.selected { - background-color: #ffffff; - border-top-color: #0089ff; -} - -#titles > button > div.count { - color: #888; -} - -@media (max-width: 700px) { - .sidebar-menu { - background-color: #F1F1F1; - border-bottom-color: #e0e0e0; - border-right-color: #e0e0e0; - } - - .sidebar-elems { - background-color: #F1F1F1; - border-right-color: #000; - } - - #sidebar-filler { - background-color: #F1F1F1; - border-bottom-color: #e0e0e0; - } -} - -kbd { - color: #000; - background-color: #fafbfc; - border-color: #d1d5da; - border-bottom-color: #c6cbd1; - box-shadow-color: #c6cbd1; -} - -#theme-picker, #settings-menu, #help-button { - border-color: #e0e0e0; - background-color: #fff; -} - -#theme-picker:hover, #theme-picker:focus, -#settings-menu:hover, #settings-menu:focus, -#help-button:hover, #help-button:focus { - border-color: #717171; -} - -#copy-path { - color: #999; -} -#copy-path > img { - filter: invert(50%); -} -#copy-path:hover > img { - filter: invert(35%); -} - -#theme-choices { - border-color: #ccc; - background-color: #fff; -} - -#theme-choices > button:not(:first-child) { - border-top-color: #e0e0e0; -} - -#theme-choices > button:hover, #theme-choices > button:focus { - background-color: #eee; -} - -@media (max-width: 700px) { - #theme-picker { - background: #fff; - } -} - -#all-types { - background-color: #fff; -} -#all-types:hover { - background-color: #f9f9f9; -} - -.search-results .result-name span.alias { - color: #000; -} -.search-results .result-name span.grey { - color: #999; -} - -#sidebar-toggle { - background-color: #F1F1F1; -} -#sidebar-toggle:hover { - background-color: #E0E0E0; -} -#source-sidebar { - background-color: #F1F1F1; -} -#source-sidebar > .title { - border-bottom-color: #ccc; -} -div.files > a:hover, div.name:hover { - background-color: #E0E0E0; -} -div.files > .selected { - background-color: #fff; -} -.setting-line > .title { - border-bottom-color: #D5D5D5; -} diff --git a/src/librustdoc/html/static/wheel.svg b/src/librustdoc/html/static/wheel.svg deleted file mode 100644 index 01da3b24c7c..00000000000 --- a/src/librustdoc/html/static/wheel.svg +++ /dev/null @@ -1 +0,0 @@ -<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="Capa_1" width="27.434" height="29.5" enable-background="new 0 0 27.434 29.5" version="1.1" viewBox="0 0 27.434 29.5" xml:space="preserve"><g><path d="M27.315,18.389c-0.165-0.604-0.509-1.113-0.981-1.459c-0.042-0.144-0.083-0.429-0.015-0.761l0.037-0.177v-0.182V14.8 c0-1.247-0.006-1.277-0.048-1.472c-0.076-0.354-0.035-0.653,0.007-0.803c0.477-0.346,0.828-0.861,0.996-1.476 c0.261-0.956,0.076-2.091-0.508-3.114l-0.591-1.032c-0.746-1.307-1.965-2.119-3.182-2.119c-0.378,0-0.75,0.081-1.085,0.235 c-0.198-0.025-0.554-0.15-0.855-0.389l-0.103-0.082l-0.114-0.065l-1.857-1.067L18.92,3.36l-0.105-0.044 c-0.376-0.154-0.658-0.41-0.768-0.556C17.918,1.172,16.349,0,14.296,0H13.14c-2.043,0-3.608,1.154-3.749,2.721 C9.277,2.862,8.999,3.104,8.633,3.25l-0.1,0.039L8.439,3.341L6.495,4.406L6.363,4.479L6.245,4.573 C5.936,4.82,5.596,4.944,5.416,4.977c-0.314-0.139-0.66-0.21-1.011-0.21c-1.198,0-2.411,0.819-3.165,2.139L0.65,7.938 c-0.412,0.72-0.642,1.521-0.644,2.258c-0.003,0.952,0.362,1.756,1.013,2.256c0.034,0.155,0.061,0.448-0.016,0.786 c-0.038,0.168-0.062,0.28-0.062,1.563c0,1.148,0,1.148,0.015,1.262l0.009,0.073l0.017,0.073c0.073,0.346,0.045,0.643,0.011,0.802 C0.348,17.512-0.01,18.314,0,19.268c0.008,0.729,0.238,1.523,0.648,2.242l0.589,1.031c0.761,1.331,1.967,2.159,3.15,2.159 c0.324,0,0.645-0.064,0.938-0.187c0.167,0.038,0.492,0.156,0.813,0.416l0.11,0.088l0.124,0.07l2.045,1.156l0.102,0.057l0.107,0.043 c0.364,0.147,0.646,0.381,0.766,0.521c0.164,1.52,1.719,2.634,3.745,2.634h1.155c2.037,0,3.598-1.134,3.747-2.675 c0.117-0.145,0.401-0.393,0.774-0.549l0.111-0.047l0.105-0.062l1.96-1.159l0.105-0.062l0.097-0.075 c0.309-0.246,0.651-0.371,0.832-0.402c0.313,0.138,0.662,0.212,1.016,0.212c1.199,0,2.412-0.82,3.166-2.139l0.59-1.032 C27.387,20.48,27.575,19.342,27.315,18.389z M25.274,20.635l-0.59,1.032c-0.438,0.765-1.104,1.251-1.639,1.251 c-0.133,0-0.258-0.029-0.369-0.094c-0.15-0.086-0.346-0.127-0.566-0.127c-0.596,0-1.383,0.295-2.01,0.796l-1.96,1.157 c-1.016,0.425-1.846,1.291-1.846,1.929s-0.898,1.159-1.998,1.159H13.14c-1.1,0-1.998-0.514-1.998-1.141s-0.834-1.477-1.854-1.888 l-2.046-1.157c-0.636-0.511-1.425-0.814-2.006-0.814c-0.202,0-0.379,0.037-0.516,0.115c-0.101,0.057-0.214,0.084-0.333,0.084 c-0.518,0-1.179-0.498-1.62-1.271l-0.591-1.032c-0.545-0.954-0.556-1.983-0.024-2.286c0.532-0.305,0.78-1.432,0.551-2.506 c0,0,0-0.003,0-1.042c0-1.088,0.021-1.18,0.021-1.18c0.238-1.072-0.01-2.203-0.552-2.513C1.631,10.8,1.634,9.765,2.18,8.812 L2.769,7.78c0.438-0.766,1.103-1.251,1.636-1.251c0.131,0,0.255,0.029,0.365,0.092C4.92,6.707,5.114,6.747,5.334,6.747 c0.596,0,1.38-0.296,2.007-0.795l1.944-1.065c1.021-0.407,1.856-1.277,1.856-1.933c0-0.656,0.898-1.192,1.998-1.192h1.156V1.761 c1.1,0,1.998,0.545,1.998,1.211c0,0.667,0.832,1.554,1.849,1.973L20,6.013c0.618,0.489,1.401,0.775,2.012,0.775 c0.24,0,0.454-0.045,0.62-0.139c0.122-0.069,0.259-0.102,0.403-0.102c0.551,0,1.221,0.476,1.653,1.231l0.59,1.032 c0.544,0.953,0.518,2.004-0.062,2.334c-0.577,0.331-0.859,1.48-0.627,2.554c0,0,0.01,0.042,0.01,1.103c0,1.012,0,1.012,0,1.012 c-0.218,1.049,0.068,2.174,0.636,2.498C25.802,18.635,25.819,19.68,25.274,20.635z"/><path d="M13.61,7.611c-3.913,0-7.084,3.173-7.084,7.085c0,3.914,3.171,7.085,7.084,7.085s7.085-3.172,7.085-7.085 C20.695,10.784,17.523,7.611,13.61,7.611z M13.61,20.02c-2.936,0-5.323-2.388-5.323-5.323c0-2.935,2.388-5.323,5.323-5.323 s5.324,2.388,5.324,5.323C18.934,17.632,16.546,20.02,13.61,20.02z"/><path d="M13.682,9.908c-2.602,0-4.718,2.116-4.718,4.718c0,2.601,2.116,4.716,4.718,4.716c2.601,0,4.717-2.115,4.717-4.716 C18.399,12.024,16.283,9.908,13.682,9.908z M13.682,17.581c-1.633,0-2.956-1.323-2.956-2.955s1.323-2.956,2.956-2.956 c1.632,0,2.956,1.324,2.956,2.956S15.314,17.581,13.682,17.581z"/></g></svg> \ No newline at end of file diff --git a/src/librustdoc/html/static_files.rs b/src/librustdoc/html/static_files.rs index 4443c74834d..2ec7e66234d 100644 --- a/src/librustdoc/html/static_files.rs +++ b/src/librustdoc/html/static_files.rs @@ -8,44 +8,44 @@ //! directly written to a `Write` handle. /// The file contents of the main `rustdoc.css` file, responsible for the core layout of the page. -crate static RUSTDOC_CSS: &str = include_str!("static/rustdoc.css"); +crate static RUSTDOC_CSS: &str = include_str!("static/css/rustdoc.css"); /// The file contents of `settings.css`, responsible for the items on the settings page. -crate static SETTINGS_CSS: &str = include_str!("static/settings.css"); +crate static SETTINGS_CSS: &str = include_str!("static/css/settings.css"); /// The file contents of the `noscript.css` file, used in case JS isn't supported or is disabled. -crate static NOSCRIPT_CSS: &str = include_str!("static/noscript.css"); +crate static NOSCRIPT_CSS: &str = include_str!("static/css/noscript.css"); /// The file contents of `normalize.css`, included to even out standard elements between browser /// implementations. -crate static NORMALIZE_CSS: &str = include_str!("static/normalize.css"); +crate static NORMALIZE_CSS: &str = include_str!("static/css/normalize.css"); /// The file contents of `main.js`, which contains the core JavaScript used on documentation pages, /// including search behavior and docblock folding, among others. -crate static MAIN_JS: &str = include_str!("static/main.js"); +crate static MAIN_JS: &str = include_str!("static/js/main.js"); /// The file contents of `search.js`, which contains the search behavior. -crate static SEARCH_JS: &str = include_str!("static/search.js"); +crate static SEARCH_JS: &str = include_str!("static/js/search.js"); /// The file contents of `settings.js`, which contains the JavaScript used to handle the settings /// page. -crate static SETTINGS_JS: &str = include_str!("static/settings.js"); +crate static SETTINGS_JS: &str = include_str!("static/js/settings.js"); /// The file contents of `storage.js`, which contains functionality related to browser Local /// Storage, used to store documentation settings. -crate static STORAGE_JS: &str = include_str!("static/storage.js"); +crate static STORAGE_JS: &str = include_str!("static/js/storage.js"); /// The file contents of `brush.svg`, the icon used for the theme-switch button. -crate static BRUSH_SVG: &[u8] = include_bytes!("static/brush.svg"); +crate static BRUSH_SVG: &[u8] = include_bytes!("static/images/brush.svg"); /// The file contents of `wheel.svg`, the icon used for the settings button. -crate static WHEEL_SVG: &[u8] = include_bytes!("static/wheel.svg"); +crate static WHEEL_SVG: &[u8] = include_bytes!("static/images/wheel.svg"); /// The file contents of `clipboard.svg`, the icon used for the "copy path" button. -crate static CLIPBOARD_SVG: &[u8] = include_bytes!("static/clipboard.svg"); +crate static CLIPBOARD_SVG: &[u8] = include_bytes!("static/images/clipboard.svg"); /// The file contents of `down-arrow.svg`, the icon used for the crate choice combobox. -crate static DOWN_ARROW_SVG: &[u8] = include_bytes!("static/down-arrow.svg"); +crate static DOWN_ARROW_SVG: &[u8] = include_bytes!("static/images/down-arrow.svg"); /// The contents of `COPYRIGHT.txt`, the license listing for files distributed with documentation /// output. @@ -58,11 +58,11 @@ crate static LICENSE_APACHE: &[u8] = include_bytes!("static/LICENSE-APACHE.txt") crate static LICENSE_MIT: &[u8] = include_bytes!("static/LICENSE-MIT.txt"); /// The contents of `rust-logo.png`, the default icon of the documentation. -crate static RUST_LOGO: &[u8] = include_bytes!("static/rust-logo.png"); +crate static RUST_LOGO: &[u8] = include_bytes!("static/images/rust-logo.png"); /// The default documentation favicons (SVG and PNG fallbacks) -crate static RUST_FAVICON_SVG: &[u8] = include_bytes!("static/favicon.svg"); -crate static RUST_FAVICON_PNG_16: &[u8] = include_bytes!("static/favicon-16x16.png"); -crate static RUST_FAVICON_PNG_32: &[u8] = include_bytes!("static/favicon-32x32.png"); +crate static RUST_FAVICON_SVG: &[u8] = include_bytes!("static/images/favicon.svg"); +crate static RUST_FAVICON_PNG_16: &[u8] = include_bytes!("static/images/favicon-16x16.png"); +crate static RUST_FAVICON_PNG_32: &[u8] = include_bytes!("static/images/favicon-32x32.png"); crate static PAGE: &str = include_str!("templates/page.html"); @@ -70,101 +70,102 @@ crate static PAGE: &str = include_str!("templates/page.html"); crate mod themes { /// The "light" theme, selected by default when no setting is available. Used as the basis for /// the `--check-theme` functionality. - crate static LIGHT: &str = include_str!("static/themes/light.css"); + crate static LIGHT: &str = include_str!("static/css/themes/light.css"); /// The "dark" theme. - crate static DARK: &str = include_str!("static/themes/dark.css"); + crate static DARK: &str = include_str!("static/css/themes/dark.css"); /// The "ayu" theme. - crate static AYU: &str = include_str!("static/themes/ayu.css"); + crate static AYU: &str = include_str!("static/css/themes/ayu.css"); } /// Files related to the Fira Sans font. crate mod fira_sans { /// The file `FiraSans-Regular.woff`, the Regular variant of the Fira Sans font. - crate static REGULAR: &[u8] = include_bytes!("static/FiraSans-Regular.woff"); + crate static REGULAR: &[u8] = include_bytes!("static/fonts/FiraSans-Regular.woff"); /// The file `FiraSans-Regular.woff2`, the Regular variant of the Fira Sans font in woff2. - crate static REGULAR2: &[u8] = include_bytes!("static/FiraSans-Regular.woff2"); + crate static REGULAR2: &[u8] = include_bytes!("static/fonts/FiraSans-Regular.woff2"); /// The file `FiraSans-Medium.woff`, the Medium variant of the Fira Sans font. - crate static MEDIUM: &[u8] = include_bytes!("static/FiraSans-Medium.woff"); + crate static MEDIUM: &[u8] = include_bytes!("static/fonts/FiraSans-Medium.woff"); /// The file `FiraSans-Medium.woff2`, the Medium variant of the Fira Sans font in woff2. - crate static MEDIUM2: &[u8] = include_bytes!("static/FiraSans-Medium.woff2"); + crate static MEDIUM2: &[u8] = include_bytes!("static/fonts/FiraSans-Medium.woff2"); /// The file `FiraSans-LICENSE.txt`, the license text for the Fira Sans font. - crate static LICENSE: &[u8] = include_bytes!("static/FiraSans-LICENSE.txt"); + crate static LICENSE: &[u8] = include_bytes!("static/fonts/FiraSans-LICENSE.txt"); } /// Files related to the Source Serif 4 font. crate mod source_serif_4 { /// The file `SourceSerif4-Regular.ttf.woff`, the Regular variant of the Source Serif 4 font. - crate static REGULAR: &[u8] = include_bytes!("static/SourceSerif4-Regular.ttf.woff"); + crate static REGULAR: &[u8] = include_bytes!("static/fonts/SourceSerif4-Regular.ttf.woff"); /// The file `SourceSerif4-Regular.ttf.woff2`, the Regular variant of the Source Serif 4 font in /// woff2. - crate static REGULAR2: &[u8] = include_bytes!("static/SourceSerif4-Regular.ttf.woff2"); + crate static REGULAR2: &[u8] = include_bytes!("static/fonts/SourceSerif4-Regular.ttf.woff2"); /// The file `SourceSerif4-Bold.ttf.woff`, the Bold variant of the Source Serif 4 font. - crate static BOLD: &[u8] = include_bytes!("static/SourceSerif4-Bold.ttf.woff"); + crate static BOLD: &[u8] = include_bytes!("static/fonts/SourceSerif4-Bold.ttf.woff"); /// The file `SourceSerif4-Bold.ttf.woff2`, the Bold variant of the Source Serif 4 font in /// woff2. - crate static BOLD2: &[u8] = include_bytes!("static/SourceSerif4-Bold.ttf.woff2"); + crate static BOLD2: &[u8] = include_bytes!("static/fonts/SourceSerif4-Bold.ttf.woff2"); /// The file `SourceSerif4-It.ttf.woff`, the Italic variant of the Source Serif 4 font. - crate static ITALIC: &[u8] = include_bytes!("static/SourceSerif4-It.ttf.woff"); + crate static ITALIC: &[u8] = include_bytes!("static/fonts/SourceSerif4-It.ttf.woff"); /// The file `SourceSerif4-It.ttf.woff2`, the Italic variant of the Source Serif 4 font in /// woff2. - crate static ITALIC2: &[u8] = include_bytes!("static/SourceSerif4-It.ttf.woff2"); + crate static ITALIC2: &[u8] = include_bytes!("static/fonts/SourceSerif4-It.ttf.woff2"); /// The file `SourceSerif4-LICENSE.txt`, the license text for the Source Serif 4 font. - crate static LICENSE: &[u8] = include_bytes!("static/SourceSerif4-LICENSE.md"); + crate static LICENSE: &[u8] = include_bytes!("static/fonts/SourceSerif4-LICENSE.md"); } /// Files related to the Source Code Pro font. crate mod source_code_pro { /// The file `SourceCodePro-Regular.ttf.woff`, the Regular variant of the Source Code Pro font. - crate static REGULAR: &[u8] = include_bytes!("static/SourceCodePro-Regular.ttf.woff"); + crate static REGULAR: &[u8] = include_bytes!("static/fonts/SourceCodePro-Regular.ttf.woff"); /// The file `SourceCodePro-Regular.ttf.woff2`, the Regular variant of the Source Code Pro font /// in woff2. - crate static REGULAR2: &[u8] = include_bytes!("static/SourceCodePro-Regular.ttf.woff2"); + crate static REGULAR2: &[u8] = include_bytes!("static/fonts/SourceCodePro-Regular.ttf.woff2"); /// The file `SourceCodePro-Semibold.ttf.woff`, the Semibold variant of the Source Code Pro /// font. - crate static SEMIBOLD: &[u8] = include_bytes!("static/SourceCodePro-Semibold.ttf.woff"); + crate static SEMIBOLD: &[u8] = include_bytes!("static/fonts/SourceCodePro-Semibold.ttf.woff"); /// The file `SourceCodePro-Semibold.ttf.woff2`, the Semibold variant of the Source Code Pro /// font in woff2. - crate static SEMIBOLD2: &[u8] = include_bytes!("static/SourceCodePro-Semibold.ttf.woff2"); + crate static SEMIBOLD2: &[u8] = include_bytes!("static/fonts/SourceCodePro-Semibold.ttf.woff2"); /// The file `SourceCodePro-It.ttf.woff`, the Italic variant of the Source Code Pro font. - crate static ITALIC: &[u8] = include_bytes!("static/SourceCodePro-It.ttf.woff"); + crate static ITALIC: &[u8] = include_bytes!("static/fonts/SourceCodePro-It.ttf.woff"); /// The file `SourceCodePro-It.ttf.woff2`, the Italic variant of the Source Code Pro font in /// woff2. - crate static ITALIC2: &[u8] = include_bytes!("static/SourceCodePro-It.ttf.woff2"); + crate static ITALIC2: &[u8] = include_bytes!("static/fonts/SourceCodePro-It.ttf.woff2"); /// The file `SourceCodePro-LICENSE.txt`, the license text of the Source Code Pro font. - crate static LICENSE: &[u8] = include_bytes!("static/SourceCodePro-LICENSE.txt"); + crate static LICENSE: &[u8] = include_bytes!("static/fonts/SourceCodePro-LICENSE.txt"); } crate mod noto_sans_kr { /// The file `noto-sans-kr-v13-korean-regular.woff`, the Regular variant of the Noto Sans KR /// font. - crate static REGULAR: &[u8] = include_bytes!("static/noto-sans-kr-v13-korean-regular.woff"); + crate static REGULAR: &[u8] = + include_bytes!("static/fonts/noto-sans-kr-v13-korean-regular.woff"); /// The file `noto-sans-kr-v13-korean-regular-LICENSE.txt`, the license text of the Noto Sans KR /// font. crate static LICENSE: &[u8] = - include_bytes!("static/noto-sans-kr-v13-korean-regular-LICENSE.txt"); + include_bytes!("static/fonts/noto-sans-kr-v13-korean-regular-LICENSE.txt"); } /// Files related to the sidebar in rustdoc sources. crate mod sidebar { /// File script to handle sidebar. - crate static SOURCE_SCRIPT: &str = include_str!("static/source-script.js"); + crate static SOURCE_SCRIPT: &str = include_str!("static/js/source-script.js"); } diff --git a/src/librustdoc/theme/tests.rs b/src/librustdoc/theme/tests.rs index b924215733d..4968ffd5a27 100644 --- a/src/librustdoc/theme/tests.rs +++ b/src/librustdoc/theme/tests.rs @@ -105,7 +105,7 @@ fn check_invalid_css() { #[test] fn test_with_minification() { - let text = include_str!("../html/static/themes/dark.css"); + let text = include_str!("../html/static/css/themes/dark.css"); let minified = minifier::css::minify(&text).expect("CSS minification failed"); let against = load_css_paths(text.as_bytes()); diff --git a/src/test/run-make-fulldeps/rustdoc-themes/Makefile b/src/test/run-make-fulldeps/rustdoc-themes/Makefile index f5a471e66e5..f3d07b25c47 100644 --- a/src/test/run-make-fulldeps/rustdoc-themes/Makefile +++ b/src/test/run-make-fulldeps/rustdoc-themes/Makefile @@ -5,6 +5,6 @@ OUTPUT_DIR := "$(TMPDIR)/rustdoc-themes" all: - cp $(S)/src/librustdoc/html/static/themes/light.css $(TMPDIR)/test.css + cp $(S)/src/librustdoc/html/static/css/themes/light.css $(TMPDIR)/test.css $(RUSTDOC) -o $(OUTPUT_DIR) foo.rs --theme $(TMPDIR)/test.css $(HTMLDOCCK) $(OUTPUT_DIR) foo.rs -- cgit 1.4.1-3-g733a5 From 5413d2e52981924bd42a5497ea4a0bf76f2a572f Mon Sep 17 00:00:00 2001 From: Eric Holk <ericholk@microsoft.com> Date: Wed, 7 Jul 2021 10:28:35 -0700 Subject: Fix test case Previously this was using a `.stderr` file, but that does not seem to work for all cases. This change uses `// error-pattern:` instead. --- src/test/ui/lint/command-line-register-unknown-lint-tool.rs | 2 +- .../ui/lint/command-line-register-unknown-lint-tool.stderr | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 src/test/ui/lint/command-line-register-unknown-lint-tool.stderr diff --git a/src/test/ui/lint/command-line-register-unknown-lint-tool.rs b/src/test/ui/lint/command-line-register-unknown-lint-tool.rs index 435e951c809..59fc0200095 100644 --- a/src/test/ui/lint/command-line-register-unknown-lint-tool.rs +++ b/src/test/ui/lint/command-line-register-unknown-lint-tool.rs @@ -1,4 +1,4 @@ // compile-flags: -A unknown_tool::foo -// check-fail +// error-pattern: unknown lint tool: `unknown_tool` fn main() {} diff --git a/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr deleted file mode 100644 index b7c5893a0ea..00000000000 --- a/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0602]: unknown lint tool: `unknown_tool` - | - = note: requested on the command line with `-A foo` - -error[E0602]: unknown lint tool: `unknown_tool` - | - = note: requested on the command line with `-A foo` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0602`. -- cgit 1.4.1-3-g733a5 From 4a83a93e9afd29e7494af3cc2a33c44ec32b0303 Mon Sep 17 00:00:00 2001 From: Eric Holk <ericholk@microsoft.com> Date: Wed, 7 Jul 2021 10:50:50 -0700 Subject: Cleanup: unify lint name checking This change merges `check_lint_and_tool_name` into `check_lint_name` in order to avoid having two very similar functions. Also adds the `.stderr` file back for the test case, since apparently it is still needed. --- compiler/rustc_lint/src/context.rs | 28 ++++++++-------------- compiler/rustc_lint/src/levels.rs | 7 +++--- .../command-line-register-unknown-lint-tool.stderr | 11 +++++++++ 3 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 src/test/ui/lint/command-line-register-unknown-lint-tool.stderr diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 263ed83ed5a..b6ea89b5074 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -344,9 +344,9 @@ impl LintStore { level: Level, crate_attrs: &[ast::Attribute], ) { - let (tool_name, lint_name) = parse_lint_and_tool_name(lint_name); + let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name); - let db = match self.check_lint_and_tool_name(sess, tool_name, lint_name, crate_attrs) { + let db = match self.check_lint_name(sess, lint_name_only, tool_name, crate_attrs) { CheckLintNameResult::Ok(_) => None, CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)), CheckLintNameResult::NoLint(suggestion) => { @@ -408,22 +408,6 @@ impl LintStore { } } - pub fn check_lint_and_tool_name( - &self, - sess: &Session, - tool_name: Option<Symbol>, - lint_name: &str, - crate_attrs: &[ast::Attribute], - ) -> CheckLintNameResult<'_> { - if let Some(tool_name) = tool_name { - if !is_known_lint_tool(tool_name, sess, crate_attrs) { - return CheckLintNameResult::NoTool; - } - } - - self.check_lint_name(lint_name, tool_name) - } - /// Checks the name of a lint for its existence, and whether it was /// renamed or removed. Generates a DiagnosticBuilder containing a /// warning for renamed and removed lints. This is over both lint @@ -433,9 +417,17 @@ impl LintStore { /// printing duplicate warnings. pub fn check_lint_name( &self, + sess: &Session, lint_name: &str, tool_name: Option<Symbol>, + crate_attrs: &[ast::Attribute], ) -> CheckLintNameResult<'_> { + if let Some(tool_name) = tool_name { + if !is_known_lint_tool(tool_name, sess, crate_attrs) { + return CheckLintNameResult::NoTool; + } + } + let complete_name = if let Some(tool_name) = tool_name { format!("{}::{}", tool_name, lint_name) } else { diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 30ee8c9b6ae..b603483414f 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -328,8 +328,7 @@ impl<'s> LintLevelsBuilder<'s> { }; let tool_name = tool_ident.map(|ident| ident.name); let name = pprust::path_to_string(&meta_item.path); - let lint_result = - store.check_lint_and_tool_name(sess, tool_name, &name, self.crate_attrs); + let lint_result = store.check_lint_name(sess, &name, tool_name, self.crate_attrs); match &lint_result { CheckLintNameResult::Ok(ids) => { let src = LintLevelSource::Node( @@ -477,7 +476,9 @@ impl<'s> LintLevelsBuilder<'s> { if let CheckLintNameResult::Warning(_, Some(new_name)) = lint_result { // Ignore any errors or warnings that happen because the new name is inaccurate // NOTE: `new_name` already includes the tool name, so we don't have to add it again. - if let CheckLintNameResult::Ok(ids) = store.check_lint_name(&new_name, None) { + if let CheckLintNameResult::Ok(ids) = + store.check_lint_name(sess, &new_name, None, self.crate_attrs) + { let src = LintLevelSource::Node(Symbol::intern(&new_name), sp, reason); for &id in ids { self.check_gated_lint(id, attr.span); diff --git a/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr new file mode 100644 index 00000000000..c9a2aff2137 --- /dev/null +++ b/src/test/ui/lint/command-line-register-unknown-lint-tool.stderr @@ -0,0 +1,11 @@ +error[E0602]: unknown lint tool: `unknown_tool` + | + = note: requested on the command line with `-A unknown_tool::foo` + +error[E0602]: unknown lint tool: `unknown_tool` + | + = note: requested on the command line with `-A unknown_tool::foo` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0602`. -- cgit 1.4.1-3-g733a5 From 7677f5fe31fc3c701096c8071f458480951a9a5c Mon Sep 17 00:00:00 2001 From: Swordelf2 <Swordelf@mail.ru> Date: Wed, 7 Jul 2021 22:26:32 +0300 Subject: Fix typo in `ops::Drop` docs --- library/core/src/ops/drop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/ops/drop.rs b/library/core/src/ops/drop.rs index f4b1ec377d4..aa654aa5570 100644 --- a/library/core/src/ops/drop.rs +++ b/library/core/src/ops/drop.rs @@ -11,7 +11,7 @@ /// This destructor consists of two components: /// - A call to `Drop::drop` for that value, if this special `Drop` trait is implemented for its type. /// - The automatically generated "drop glue" which recursively calls the destructors -/// of the all fields of this value. +/// of all the fields of this value. /// /// As Rust automatically calls the destructors of all contained fields, /// you don't have to implement `Drop` in most cases. But there are some cases where -- cgit 1.4.1-3-g733a5 From ace3989d55f540ec692ef662b9c1329a058ded3c Mon Sep 17 00:00:00 2001 From: Josh Stone <jistone@redhat.com> Date: Wed, 7 Jul 2021 13:13:26 -0700 Subject: Revert "Add "every" as a doc alias for "all"." This reverts commit 35450365ac2fda8b948fe6fd1a1123837a9554b0. --- library/core/src/iter/traits/iterator.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 0032e8c3e47..8cb7aad28aa 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -2254,7 +2254,6 @@ pub trait Iterator { /// // we can still use `iter`, as there are more elements. /// assert_eq!(iter.next(), Some(&3)); /// ``` - #[doc(alias = "every")] #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn all<F>(&mut self, f: F) -> bool -- cgit 1.4.1-3-g733a5