Skip to content

Commit 41ae7fc

Browse files
authored
Rollup merge of rust-lang#110409 - Nilstrieb:some-manual-javascript-object-notationing, r=fee1-dead
Don't use `serde_json` to serialize a simple JSON object This avoids `rustc_data_structures` depending on `serde_json` which allows it to be compiled much earlier, unlocking most of rustc. This used to not matter, but after rust-lang#110407 we're not blocked on fluent anymore, which means that it's now a blocking edge. ![image](https://user-images.githubusercontent.com/48135649/232313178-e0150420-3020-4eb6-98d3-fe5294a8f947.png) This saves a few more seconds. cc ````@Zoxc```` who added it recently
2 parents afea84f + 7859a8e commit 41ae7fc

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

Diff for: Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,6 @@ dependencies = [
31813181
"rustc_index",
31823182
"rustc_macros",
31833183
"rustc_serialize",
3184-
"serde_json",
31853184
"smallvec",
31863185
"stable_deref_trait",
31873186
"stacker",

Diff for: compiler/rustc_data_structures/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ rustc-hash = "1.1.0"
2121
rustc_index = { path = "../rustc_index", package = "rustc_index" }
2222
rustc_macros = { path = "../rustc_macros" }
2323
rustc_serialize = { path = "../rustc_serialize" }
24-
serde_json = "1.0.59"
2524
smallvec = { version = "1.8.1", features = [
2625
"const_generics",
2726
"union",

Diff for: compiler/rustc_data_structures/src/profiling.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ use crate::fx::FxHashMap;
8787
use std::borrow::Borrow;
8888
use std::collections::hash_map::Entry;
8989
use std::error::Error;
90+
use std::fmt::Display;
9091
use std::fs;
9192
use std::intrinsics::unlikely;
9293
use std::path::Path;
@@ -97,7 +98,6 @@ use std::time::{Duration, Instant};
9798
pub use measureme::EventId;
9899
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
99100
use parking_lot::RwLock;
100-
use serde_json::json;
101101
use smallvec::SmallVec;
102102

103103
bitflags::bitflags! {
@@ -763,6 +763,31 @@ impl Drop for VerboseTimingGuard<'_> {
763763
}
764764
}
765765

766+
struct JsonTimePassesEntry<'a> {
767+
pass: &'a str,
768+
time: f64,
769+
start_rss: Option<usize>,
770+
end_rss: Option<usize>,
771+
}
772+
773+
impl Display for JsonTimePassesEntry<'_> {
774+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
775+
let Self { pass: what, time, start_rss, end_rss } = self;
776+
write!(f, r#"{{"pass":"{what}","time":{time},"rss_start":"#).unwrap();
777+
match start_rss {
778+
Some(rss) => write!(f, "{rss}")?,
779+
None => write!(f, "null")?,
780+
}
781+
write!(f, r#","rss_end":"#)?;
782+
match end_rss {
783+
Some(rss) => write!(f, "{rss}")?,
784+
None => write!(f, "null")?,
785+
}
786+
write!(f, "}}")?;
787+
Ok(())
788+
}
789+
}
790+
766791
pub fn print_time_passes_entry(
767792
what: &str,
768793
dur: Duration,
@@ -772,13 +797,10 @@ pub fn print_time_passes_entry(
772797
) {
773798
match format {
774799
TimePassesFormat::Json => {
775-
let json = json!({
776-
"pass": what,
777-
"time": dur.as_secs_f64(),
778-
"rss_start": start_rss,
779-
"rss_end": end_rss,
780-
});
781-
eprintln!("time: {json}");
800+
let entry =
801+
JsonTimePassesEntry { pass: what, time: dur.as_secs_f64(), start_rss, end_rss };
802+
803+
eprintln!(r#"time: {entry}"#);
782804
return;
783805
}
784806
TimePassesFormat::Text => (),
@@ -894,3 +916,6 @@ cfg_if! {
894916
}
895917
}
896918
}
919+
920+
#[cfg(test)]
921+
mod tests;
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use super::JsonTimePassesEntry;
2+
3+
#[test]
4+
fn with_rss() {
5+
let entry =
6+
JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: Some(10), end_rss: Some(20) };
7+
8+
assert_eq!(entry.to_string(), r#"{"pass":"typeck","time":56.1,"rss_start":10,"rss_end":20}"#)
9+
}
10+
11+
#[test]
12+
fn no_rss() {
13+
let entry = JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: None, end_rss: None };
14+
15+
assert_eq!(
16+
entry.to_string(),
17+
r#"{"pass":"typeck","time":56.1,"rss_start":null,"rss_end":null}"#
18+
)
19+
}

0 commit comments

Comments
 (0)