Skip to content

Commit

Permalink
Unrolled build for rust-lang#136034
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#136034 - weihanglo:null-as-f64-nan, r=compiler-errors

fix(bootstrap): deserialize null as `f64::NAN`

When doing optimized build through opt-dist,
I've often run into errors like `invalid type: null, expected f64`.
This is likely because some f64 fields might actually bet set null.
Unfortunately, serde_json doesn't handle null <-> NaN well.

This commit addresses it by having a custom deserialize method, so null is always be deserialized to `f64:NAN`.

See:

* https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/opt-dist.3A.20.60invalid.20type.3A.20null.2C.20expect.20f64.60.20failure
* serde-rs/json#202

r? `@Kobzol`
  • Loading branch information
rust-timer authored Jan 25, 2025
2 parents 6365178 + 5f8bcec commit 5954621
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/build_helper/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct JsonInvocation {
//
// This is necessary to easily correlate this invocation with logs or other data.
pub start_time: u64,
#[serde(deserialize_with = "null_as_f64_nan")]
pub duration_including_children_sec: f64,
pub children: Vec<JsonNode>,
}
Expand All @@ -28,6 +29,7 @@ pub enum JsonNode {
type_: String,
debug_repr: String,

#[serde(deserialize_with = "null_as_f64_nan")]
duration_excluding_children_sec: f64,
system_stats: JsonStepSystemStats,

Expand Down Expand Up @@ -88,5 +90,11 @@ pub struct JsonInvocationSystemStats {
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct JsonStepSystemStats {
#[serde(deserialize_with = "null_as_f64_nan")]
pub cpu_utilization_percent: f64,
}

fn null_as_f64_nan<'de, D: serde::Deserializer<'de>>(d: D) -> Result<f64, D::Error> {
use serde::Deserialize as _;
Option::<f64>::deserialize(d).map(|f| f.unwrap_or(f64::NAN))
}

0 comments on commit 5954621

Please sign in to comment.