Rollup merge of #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 #110407 we're not blocked on fluent anymore, which means that it's now a blocking edge.  This saves a few more seconds. cc ````@Zoxc```` who added it recently
This commit is contained in:
commit
41ae7fcf9b
4 changed files with 52 additions and 10 deletions
|
@ -3181,7 +3181,6 @@ dependencies = [
|
||||||
"rustc_index",
|
"rustc_index",
|
||||||
"rustc_macros",
|
"rustc_macros",
|
||||||
"rustc_serialize",
|
"rustc_serialize",
|
||||||
"serde_json",
|
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
"stacker",
|
"stacker",
|
||||||
|
|
|
@ -21,7 +21,6 @@ rustc-hash = "1.1.0"
|
||||||
rustc_index = { path = "../rustc_index", package = "rustc_index" }
|
rustc_index = { path = "../rustc_index", package = "rustc_index" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
serde_json = "1.0.59"
|
|
||||||
smallvec = { version = "1.8.1", features = [
|
smallvec = { version = "1.8.1", features = [
|
||||||
"const_generics",
|
"const_generics",
|
||||||
"union",
|
"union",
|
||||||
|
|
|
@ -87,6 +87,7 @@ use crate::fx::FxHashMap;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::collections::hash_map::Entry;
|
use std::collections::hash_map::Entry;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::fmt::Display;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::intrinsics::unlikely;
|
use std::intrinsics::unlikely;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -97,7 +98,6 @@ use std::time::{Duration, Instant};
|
||||||
pub use measureme::EventId;
|
pub use measureme::EventId;
|
||||||
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
|
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use serde_json::json;
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
|
@ -763,6 +763,31 @@ impl Drop for VerboseTimingGuard<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct JsonTimePassesEntry<'a> {
|
||||||
|
pass: &'a str,
|
||||||
|
time: f64,
|
||||||
|
start_rss: Option<usize>,
|
||||||
|
end_rss: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for JsonTimePassesEntry<'_> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let Self { pass: what, time, start_rss, end_rss } = self;
|
||||||
|
write!(f, r#"{{"pass":"{what}","time":{time},"rss_start":"#).unwrap();
|
||||||
|
match start_rss {
|
||||||
|
Some(rss) => write!(f, "{rss}")?,
|
||||||
|
None => write!(f, "null")?,
|
||||||
|
}
|
||||||
|
write!(f, r#","rss_end":"#)?;
|
||||||
|
match end_rss {
|
||||||
|
Some(rss) => write!(f, "{rss}")?,
|
||||||
|
None => write!(f, "null")?,
|
||||||
|
}
|
||||||
|
write!(f, "}}")?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn print_time_passes_entry(
|
pub fn print_time_passes_entry(
|
||||||
what: &str,
|
what: &str,
|
||||||
dur: Duration,
|
dur: Duration,
|
||||||
|
@ -772,13 +797,10 @@ pub fn print_time_passes_entry(
|
||||||
) {
|
) {
|
||||||
match format {
|
match format {
|
||||||
TimePassesFormat::Json => {
|
TimePassesFormat::Json => {
|
||||||
let json = json!({
|
let entry =
|
||||||
"pass": what,
|
JsonTimePassesEntry { pass: what, time: dur.as_secs_f64(), start_rss, end_rss };
|
||||||
"time": dur.as_secs_f64(),
|
|
||||||
"rss_start": start_rss,
|
eprintln!(r#"time: {entry}"#);
|
||||||
"rss_end": end_rss,
|
|
||||||
});
|
|
||||||
eprintln!("time: {json}");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TimePassesFormat::Text => (),
|
TimePassesFormat::Text => (),
|
||||||
|
@ -894,3 +916,6 @@ cfg_if! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
19
compiler/rustc_data_structures/src/profiling/tests.rs
Normal file
19
compiler/rustc_data_structures/src/profiling/tests.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
use super::JsonTimePassesEntry;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn with_rss() {
|
||||||
|
let entry =
|
||||||
|
JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: Some(10), end_rss: Some(20) };
|
||||||
|
|
||||||
|
assert_eq!(entry.to_string(), r#"{"pass":"typeck","time":56.1,"rss_start":10,"rss_end":20}"#)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_rss() {
|
||||||
|
let entry = JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: None, end_rss: None };
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
entry.to_string(),
|
||||||
|
r#"{"pass":"typeck","time":56.1,"rss_start":null,"rss_end":null}"#
|
||||||
|
)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue