aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-29 18:57:20 +0100
committerGitHub <[email protected]>2020-07-29 18:57:20 +0100
commit2e10f156c5de08431869e6c7d383888bcca4527e (patch)
tree4de0bef2ca0215da21322427062d1005cb0167e6
parent17126b9827dcec89bbe07add455a4ad893db58fa (diff)
parent63de7bbb5b4cfb4797adb303ce2a48cf8ff2cff4 (diff)
Merge #5574
5574: Replace rand with oorandom r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--Cargo.lock90
-rw-r--r--crates/ra_ide/Cargo.toml2
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs10
-rw-r--r--crates/ra_ide/test_data/rainbow_highlighting.html12
-rw-r--r--crates/rust-analyzer/Cargo.toml2
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs25
-rw-r--r--xtask/tests/tidy.rs1
7 files changed, 44 insertions, 98 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b7a9516e3..c656f846d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -401,17 +401,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
401checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" 401checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
402 402
403[[package]] 403[[package]]
404name = "getrandom"
405version = "0.1.14"
406source = "registry+https://github.com/rust-lang/crates.io-index"
407checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
408dependencies = [
409 "cfg-if",
410 "libc",
411 "wasi",
412]
413
414[[package]]
415name = "gimli" 404name = "gimli"
416version = "0.22.0" 405version = "0.22.0"
417source = "registry+https://github.com/rust-lang/crates.io-index" 406source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -811,6 +800,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
811checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" 800checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d"
812 801
813[[package]] 802[[package]]
803name = "oorandom"
804version = "11.1.2"
805source = "registry+https://github.com/rust-lang/crates.io-index"
806checksum = "a170cebd8021a008ea92e4db85a72f80b35df514ec664b296fdcbb654eac0b2c"
807
808[[package]]
814name = "parking_lot" 809name = "parking_lot"
815version = "0.11.0" 810version = "0.11.0"
816source = "registry+https://github.com/rust-lang/crates.io-index" 811source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -869,12 +864,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
869checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" 864checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
870 865
871[[package]] 866[[package]]
872name = "ppv-lite86"
873version = "0.2.8"
874source = "registry+https://github.com/rust-lang/crates.io-index"
875checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
876
877[[package]]
878name = "proc-macro2" 867name = "proc-macro2"
879version = "1.0.19" 868version = "1.0.19"
880source = "registry+https://github.com/rust-lang/crates.io-index" 869source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1046,6 +1035,7 @@ dependencies = [
1046 "indexmap", 1035 "indexmap",
1047 "itertools", 1036 "itertools",
1048 "log", 1037 "log",
1038 "oorandom",
1049 "ra_assists", 1039 "ra_assists",
1050 "ra_cfg", 1040 "ra_cfg",
1051 "ra_db", 1041 "ra_db",
@@ -1056,7 +1046,6 @@ dependencies = [
1056 "ra_ssr", 1046 "ra_ssr",
1057 "ra_syntax", 1047 "ra_syntax",
1058 "ra_text_edit", 1048 "ra_text_edit",
1059 "rand",
1060 "rustc-hash", 1049 "rustc-hash",
1061 "stdx", 1050 "stdx",
1062 "test_utils", 1051 "test_utils",
@@ -1218,57 +1207,6 @@ dependencies = [
1218] 1207]
1219 1208
1220[[package]] 1209[[package]]
1221name = "rand"
1222version = "0.7.3"
1223source = "registry+https://github.com/rust-lang/crates.io-index"
1224checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
1225dependencies = [
1226 "getrandom",
1227 "libc",
1228 "rand_chacha",
1229 "rand_core",
1230 "rand_hc",
1231 "rand_pcg",
1232]
1233
1234[[package]]
1235name = "rand_chacha"
1236version = "0.2.2"
1237source = "registry+https://github.com/rust-lang/crates.io-index"
1238checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
1239dependencies = [
1240 "ppv-lite86",
1241 "rand_core",
1242]
1243
1244[[package]]
1245name = "rand_core"
1246version = "0.5.1"
1247source = "registry+https://github.com/rust-lang/crates.io-index"
1248checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
1249dependencies = [
1250 "getrandom",
1251]
1252
1253[[package]]
1254name = "rand_hc"
1255version = "0.2.0"
1256source = "registry+https://github.com/rust-lang/crates.io-index"
1257checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
1258dependencies = [
1259 "rand_core",
1260]
1261
1262[[package]]
1263name = "rand_pcg"
1264version = "0.2.1"
1265source = "registry+https://github.com/rust-lang/crates.io-index"
1266checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
1267dependencies = [
1268 "rand_core",
1269]
1270
1271[[package]]
1272name = "rayon" 1210name = "rayon"
1273version = "1.3.1" 1211version = "1.3.1"
1274source = "registry+https://github.com/rust-lang/crates.io-index" 1212source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1354,6 +1292,7 @@ dependencies = [
1354 "lsp-server", 1292 "lsp-server",
1355 "lsp-types", 1293 "lsp-types",
1356 "mimalloc", 1294 "mimalloc",
1295 "oorandom",
1357 "parking_lot", 1296 "parking_lot",
1358 "pico-args", 1297 "pico-args",
1359 "ra_cfg", 1298 "ra_cfg",
@@ -1372,7 +1311,6 @@ dependencies = [
1372 "ra_text_edit", 1311 "ra_text_edit",
1373 "ra_toolchain", 1312 "ra_toolchain",
1374 "ra_tt", 1313 "ra_tt",
1375 "rand",
1376 "rayon", 1314 "rayon",
1377 "rustc-hash", 1315 "rustc-hash",
1378 "serde", 1316 "serde",
@@ -1414,16 +1352,16 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
1414 1352
1415[[package]] 1353[[package]]
1416name = "salsa" 1354name = "salsa"
1417version = "0.15.0" 1355version = "0.15.1"
1418source = "registry+https://github.com/rust-lang/crates.io-index" 1356source = "registry+https://github.com/rust-lang/crates.io-index"
1419checksum = "885b4b99dde959decc84e85dd943bd140b4aabd62db2f8206ef5270f77ec20b9" 1357checksum = "d4cdc109fcc9e9450c7ef47fb7474e99bffd51799da03ed0a6c7f0e2cb3848a6"
1420dependencies = [ 1358dependencies = [
1421 "crossbeam-utils", 1359 "crossbeam-utils",
1422 "indexmap", 1360 "indexmap",
1423 "lock_api", 1361 "lock_api",
1424 "log", 1362 "log",
1363 "oorandom",
1425 "parking_lot", 1364 "parking_lot",
1426 "rand",
1427 "rustc-hash", 1365 "rustc-hash",
1428 "salsa-macros", 1366 "salsa-macros",
1429 "smallvec", 1367 "smallvec",
@@ -1832,12 +1770,6 @@ dependencies = [
1832] 1770]
1833 1771
1834[[package]] 1772[[package]]
1835name = "wasi"
1836version = "0.9.0+wasi-snapshot-preview1"
1837source = "registry+https://github.com/rust-lang/crates.io-index"
1838checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1839
1840[[package]]
1841name = "winapi" 1773name = "winapi"
1842version = "0.2.8" 1774version = "0.2.8"
1843source = "registry+https://github.com/rust-lang/crates.io-index" 1775source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index 6f8107491..f4181c4eb 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -17,7 +17,7 @@ indexmap = "1.3.2"
17itertools = "0.9.0" 17itertools = "0.9.0"
18log = "0.4.8" 18log = "0.4.8"
19rustc-hash = "1.1.0" 19rustc-hash = "1.1.0"
20rand = { version = "0.7.3", features = ["small_rng"] } 20oorandom = "11.1.2"
21 21
22stdx = { path = "../stdx" } 22stdx = { path = "../stdx" }
23 23
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 0be55bca9..a5e7d2867 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -1,5 +1,6 @@
1//! Renders a bit of code as HTML. 1//! Renders a bit of code as HTML.
2 2
3use oorandom::Rand32;
3use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
4use ra_syntax::{AstNode, TextRange, TextSize}; 5use ra_syntax::{AstNode, TextRange, TextSize};
5 6
@@ -9,13 +10,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
9 let parse = db.parse(file_id); 10 let parse = db.parse(file_id);
10 11
11 fn rainbowify(seed: u64) -> String { 12 fn rainbowify(seed: u64) -> String {
12 use rand::prelude::*; 13 let mut rng = Rand32::new(seed);
13 let mut rng = SmallRng::seed_from_u64(seed);
14 format!( 14 format!(
15 "hsl({h},{s}%,{l}%)", 15 "hsl({h},{s}%,{l}%)",
16 h = rng.gen_range::<u16, _, _>(0, 361), 16 h = rng.rand_range(0..361),
17 s = rng.gen_range::<u16, _, _>(42, 99), 17 s = rng.rand_range(42..99),
18 l = rng.gen_range::<u16, _, _>(40, 91), 18 l = rng.rand_range(40..91),
19 ) 19 )
20 } 20 }
21 21
diff --git a/crates/ra_ide/test_data/rainbow_highlighting.html b/crates/ra_ide/test_data/rainbow_highlighting.html
index 08d83302c..401e87a73 100644
--- a/crates/ra_ide/test_data/rainbow_highlighting.html
+++ b/crates/ra_ide/test_data/rainbow_highlighting.html
@@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; } 36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
37</style> 37</style>
38<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> 38<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
39 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> 39 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span>
40 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 40 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(76,47%,83%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
41 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 41 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(15,86%,51%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
42 42
43 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span> 43 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span>
44 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 44 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(90,74%,79%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
45<span class="punctuation">}</span> 45<span class="punctuation">}</span>
46 46
47<span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> 47<span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
48 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> 48 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span>
49<span class="punctuation">}</span></code></pre> \ No newline at end of file 49<span class="punctuation">}</span></code></pre> \ No newline at end of file
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 3f9c820c5..931fc61ed 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -23,7 +23,7 @@ log = "0.4.8"
23lsp-types = { version = "0.78.0", features = ["proposed"] } 23lsp-types = { version = "0.78.0", features = ["proposed"] }
24parking_lot = "0.11.0" 24parking_lot = "0.11.0"
25pico-args = "0.3.1" 25pico-args = "0.3.1"
26rand = { version = "0.7.3", features = ["small_rng"] } 26oorandom = "11.1.2"
27rustc-hash = "1.1.0" 27rustc-hash = "1.1.0"
28serde = { version = "1.0.106", features = ["derive"] } 28serde = { version = "1.0.106", features = ["derive"] }
29serde_json = "1.0.48" 29serde_json = "1.0.48"
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index ccc058682..66d201ba6 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -1,7 +1,10 @@
1//! Fully type-check project and print various stats, like the number of type 1//! Fully type-check project and print various stats, like the number of type
2//! errors. 2//! errors.
3 3
4use std::{path::Path, time::Instant}; 4use std::{
5 path::Path,
6 time::{Instant, SystemTime, UNIX_EPOCH},
7};
5 8
6use hir::{ 9use hir::{
7 db::{AstDatabase, DefDatabase, HirDatabase}, 10 db::{AstDatabase, DefDatabase, HirDatabase},
@@ -10,12 +13,12 @@ use hir::{
10use hir_def::FunctionId; 13use hir_def::FunctionId;
11use hir_ty::{Ty, TypeWalk}; 14use hir_ty::{Ty, TypeWalk};
12use itertools::Itertools; 15use itertools::Itertools;
16use oorandom::Rand32;
13use ra_db::{ 17use ra_db::{
14 salsa::{self, ParallelDatabase}, 18 salsa::{self, ParallelDatabase},
15 SourceDatabaseExt, 19 SourceDatabaseExt,
16}; 20};
17use ra_syntax::AstNode; 21use ra_syntax::AstNode;
18use rand::{seq::SliceRandom, thread_rng};
19use rayon::prelude::*; 22use rayon::prelude::*;
20use rustc_hash::FxHashSet; 23use rustc_hash::FxHashSet;
21use stdx::format_to; 24use stdx::format_to;
@@ -46,6 +49,11 @@ pub fn analysis_stats(
46 load_output_dirs: bool, 49 load_output_dirs: bool,
47 with_proc_macro: bool, 50 with_proc_macro: bool,
48) -> Result<()> { 51) -> Result<()> {
52 let mut rng = {
53 let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64;
54 Rand32::new(seed)
55 };
56
49 let db_load_time = Instant::now(); 57 let db_load_time = Instant::now();
50 let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; 58 let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?;
51 let db = host.raw_database(); 59 let db = host.raw_database();
@@ -57,7 +65,7 @@ pub fn analysis_stats(
57 65
58 let mut krates = Crate::all(db); 66 let mut krates = Crate::all(db);
59 if randomize { 67 if randomize {
60 krates.shuffle(&mut thread_rng()); 68 shuffle(&mut rng, &mut krates);
61 } 69 }
62 for krate in krates { 70 for krate in krates {
63 let module = krate.root_module(db).expect("crate without root module"); 71 let module = krate.root_module(db).expect("crate without root module");
@@ -72,7 +80,7 @@ pub fn analysis_stats(
72 } 80 }
73 81
74 if randomize { 82 if randomize {
75 visit_queue.shuffle(&mut thread_rng()); 83 shuffle(&mut rng, &mut visit_queue);
76 } 84 }
77 85
78 eprintln!("Crates in this dir: {}", num_crates); 86 eprintln!("Crates in this dir: {}", num_crates);
@@ -110,7 +118,7 @@ pub fn analysis_stats(
110 ); 118 );
111 119
112 if randomize { 120 if randomize {
113 funcs.shuffle(&mut thread_rng()); 121 shuffle(&mut rng, &mut funcs);
114 } 122 }
115 123
116 let mut bar = match verbosity { 124 let mut bar = match verbosity {
@@ -306,3 +314,10 @@ pub fn analysis_stats(
306 314
307 Ok(()) 315 Ok(())
308} 316}
317
318fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
319 for i in (1..slice.len()).rev() {
320 let idx = rng.rand_range(0..i as u32) as usize;
321 slice.swap(idx, i)
322 }
323}
diff --git a/xtask/tests/tidy.rs b/xtask/tests/tidy.rs
index adadffc53..d65a2acbc 100644
--- a/xtask/tests/tidy.rs
+++ b/xtask/tests/tidy.rs
@@ -55,7 +55,6 @@ fn check_licenses() {
550BSD OR MIT OR Apache-2.0 550BSD OR MIT OR Apache-2.0
56Apache-2.0 OR BSL-1.0 56Apache-2.0 OR BSL-1.0
57Apache-2.0 OR MIT 57Apache-2.0 OR MIT
58Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT
59Apache-2.0/MIT 58Apache-2.0/MIT
60BSD-2-Clause 59BSD-2-Clause
61BSD-3-Clause 60BSD-3-Clause