This is an automated email from the git hooks/post-receive script.
pierov pushed a commit to branch geckoview-99.0.1-11.0-1 in repository tor-browser.
commit eb6ed9616cc0423c2f35aa2ff47068c2cc5c1a13 Author: Alexandre Lissy lissyx+mozillians@lissyx.dyndns.org AuthorDate: Mon Jan 31 20:46:48 2022 +0000
Bug 1751177 - Revert glean workaround for HashMap. r=janerik, a=RyanVM --- toolkit/components/glean/api/src/ipc.rs | 30 +++----- toolkit/components/glean/api/src/lib.rs | 19 ----- .../glean_parser_ext/templates/rust.jinja2 | 13 ++-- .../glean/tests/pytest/metrics_test_output | 85 +++++++++++----------- 4 files changed, 58 insertions(+), 89 deletions(-)
diff --git a/toolkit/components/glean/api/src/ipc.rs b/toolkit/components/glean/api/src/ipc.rs index bb1eded2e7ecb..77aed56146e14 100644 --- a/toolkit/components/glean/api/src/ipc.rs +++ b/toolkit/components/glean/api/src/ipc.rs @@ -3,15 +3,6 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! IPC Implementation, Rust part -//! -//! ## Implementation note -//! -//! We can't rely on a system-provided random number generator here, -//! as the sandbox a child process runs in might be severely restricted -//! (see [bug 1746254] for details). -//! That means avoiding the default `RandomState` on hash maps and use `HashState` instead. -//! -//! [bug 1746254]: https://bugzilla.mozilla.org/show_bug.cgi?id=1746254
use crate::private::MetricId; use once_cell::sync::Lazy; @@ -24,7 +15,6 @@ use std::sync::Mutex; #[cfg(feature = "with_gecko")] use {std::convert::TryInto, std::sync::atomic::AtomicU32, xpcom::interfaces::nsIXULRuntime};
-use super::HashState; use super::metrics::__glean_metric_maps;
type EventRecord = (u64, HashMap<i32, String>); @@ -33,16 +23,16 @@ type EventRecord = (u64, HashMap<i32, String>); /// process. #[derive(Debug, Default, Deserialize, Serialize)] pub struct IPCPayload { - pub counters: HashMap<MetricId, i32, HashState>, - pub custom_samples: HashMap<MetricId, Vec<i64>, HashState>, - pub denominators: HashMap<MetricId, i32, HashState>, - pub events: HashMap<MetricId, Vec<EventRecord>, HashState>, - pub labeled_counters: HashMap<MetricId, HashMap<String, i32>, HashState>, - pub memory_samples: HashMap<MetricId, Vec<u64>, HashState>, - pub numerators: HashMap<MetricId, i32, HashState>, - pub rates: HashMap<MetricId, (i32, i32), HashState>, - pub string_lists: HashMap<MetricId, Vec<String>, HashState>, - pub timing_samples: HashMap<MetricId, Vec<u64>, HashState>, + pub counters: HashMap<MetricId, i32>, + pub custom_samples: HashMap<MetricId, Vec<i64>>, + pub denominators: HashMap<MetricId, i32>, + pub events: HashMap<MetricId, Vec<EventRecord>>, + pub labeled_counters: HashMap<MetricId, HashMap<String, i32>>, + pub memory_samples: HashMap<MetricId, Vec<u64>>, + pub numerators: HashMap<MetricId, i32>, + pub rates: HashMap<MetricId, (i32, i32)>, + pub string_lists: HashMap<MetricId, Vec<String>>, + pub timing_samples: HashMap<MetricId, Vec<u64>>, }
/// Global singleton: pending IPC payload. diff --git a/toolkit/components/glean/api/src/lib.rs b/toolkit/components/glean/api/src/lib.rs index e5223417a6062..8442ae3eceb9a 100644 --- a/toolkit/components/glean/api/src/lib.rs +++ b/toolkit/components/glean/api/src/lib.rs @@ -12,9 +12,6 @@ pub extern crate uuid; // Re-exporting for use in user tests. pub use private::{DistributionData, ErrorType, RecordedEvent};
-use std::collections::hash_map::DefaultHasher; -use std::hash::BuildHasher; - // Must appear before `metrics` or its use of `ffi`'s macros will fail. #[macro_use] mod ffi; @@ -27,19 +24,3 @@ pub mod ipc;
#[cfg(test)] mod common_test; - -/// A simple hash state, which wraps `DefaultHasher` with default keys. -/// -/// This will result in the same hashes for the same values but different hashmaps. -/// Use it only when you can't rely on the random seed working, -/// e.g. in a sandboxed Windows environment. -#[derive(Debug, Default)] -pub struct HashState; - -impl BuildHasher for HashState { - type Hasher = DefaultHasher; - #[inline] - fn build_hasher(&self) -> DefaultHasher { - DefaultHasher::new() - } -} diff --git a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 index 0861da8964b19..ebaa034d522d0 100644 --- a/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 +++ b/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust.jinja2 @@ -89,13 +89,12 @@ pub(crate) mod __glean_metric_maps { use std::collections::HashMap;
use super::{id_for_extra_key, extra_keys_len}; - use crate::HashState; use crate::private::*; use once_cell::sync::Lazy;
{% for typ, metrics in metric_by_type.items() %} - pub static {{typ.0}}: Lazy<HashMap<MetricId, &Lazy<{{typ.1}}>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher({{metrics|length}}, HashState); + pub static {{typ.0}}: Lazy<HashMap<MetricId, &Lazy<{{typ.1}}>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity({{metrics|length}}); {% for metric in metrics %} map.insert({{metric.0}}.into(), &super::{{metric.1}}); {% endfor %} @@ -260,14 +259,14 @@ pub(crate) mod __glean_metric_maps {
pub(crate) const MIN_LABELED_SUBMETRIC_ID: u32 = {{min_submetric_id}}; pub(crate) static NEXT_LABELED_SUBMETRIC_ID: AtomicU32 = AtomicU32::new(MIN_LABELED_SUBMETRIC_ID); - pub(crate) static LABELED_METRICS_TO_IDS: Lazy<RwLock<HashMap<(u32, String), u32, HashState>>> = Lazy::new(|| - RwLock::new(HashMap::with_hasher(HashState)) + pub(crate) static LABELED_METRICS_TO_IDS: Lazy<RwLock<HashMap<(u32, String), u32>>> = Lazy::new(|| + RwLock::new(HashMap::new()) );
{% for typ, metrics in metric_by_type.items() %} {% if typ.0 in ('BOOLEAN_MAP', 'COUNTER_MAP', 'STRING_MAP') %} - pub static {{typ.0}}: Lazy<RwLock<HashMap<MetricId, Labeled{{typ.1}}, HashState>>> = Lazy::new(|| - RwLock::new(HashMap::with_hasher(HashState)) + pub static {{typ.0}}: Lazy<RwLock<HashMap<MetricId, Labeled{{typ.1}}>>> = Lazy::new(|| + RwLock::new(HashMap::new()) ); {% endif %} {% endfor%} diff --git a/toolkit/components/glean/tests/pytest/metrics_test_output b/toolkit/components/glean/tests/pytest/metrics_test_output index f46245360914e..e33e299cfc2b6 100644 --- a/toolkit/components/glean/tests/pytest/metrics_test_output +++ b/toolkit/components/glean/tests/pytest/metrics_test_output @@ -396,111 +396,110 @@ pub(crate) mod __glean_metric_maps { use std::collections::HashMap;
use super::{id_for_extra_key, extra_keys_len}; - use crate::HashState; use crate::private::*; use once_cell::sync::Lazy;
- pub static BOOLEAN_MAP: Lazy<HashMap<MetricId, &Lazy<BooleanMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static BOOLEAN_MAP: Lazy<HashMap<MetricId, &Lazy<BooleanMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(1.into(), &super::test::boolean_metric); map });
- pub static LABELED_BOOLEAN_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<LabeledBooleanMetric>>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(2, HashState); + pub static LABELED_BOOLEAN_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<LabeledBooleanMetric>>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(2); map.insert(2.into(), &super::test::labeled_boolean_metric); map.insert(3.into(), &super::test::labeled_boolean_metric_labels); map });
- pub static COUNTER_MAP: Lazy<HashMap<MetricId, &Lazy<CounterMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static COUNTER_MAP: Lazy<HashMap<MetricId, &Lazy<CounterMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(4.into(), &super::test::counter_metric); map });
- pub static LABELED_COUNTER_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<LabeledCounterMetric>>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(2, HashState); + pub static LABELED_COUNTER_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<LabeledCounterMetric>>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(2); map.insert(5.into(), &super::test::labeled_counter_metric); map.insert(6.into(), &super::test::labeled_counter_metric_labels); map });
- pub static STRING_MAP: Lazy<HashMap<MetricId, &Lazy<StringMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static STRING_MAP: Lazy<HashMap<MetricId, &Lazy<StringMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(7.into(), &super::test::string_metric); map });
- pub static LABELED_STRING_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<LabeledStringMetric>>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(2, HashState); + pub static LABELED_STRING_MAP: Lazy<HashMap<MetricId, &Lazy<LabeledMetric<LabeledStringMetric>>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(2); map.insert(8.into(), &super::test::labeled_string_metric); map.insert(9.into(), &super::test::labeled_string_metric_labels); map });
- pub static STRING_LIST_MAP: Lazy<HashMap<MetricId, &Lazy<StringListMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static STRING_LIST_MAP: Lazy<HashMap<MetricId, &Lazy<StringListMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(10.into(), &super::test::string_list_metric); map });
- pub static TIMESPAN_MAP: Lazy<HashMap<MetricId, &Lazy<TimespanMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static TIMESPAN_MAP: Lazy<HashMap<MetricId, &Lazy<TimespanMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(11.into(), &super::test::timespan_metric); map });
- pub static TIMING_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<TimingDistributionMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static TIMING_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<TimingDistributionMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(12.into(), &super::test::timing_distribution_metric); map });
- pub static MEMORY_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<MemoryDistributionMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static MEMORY_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<MemoryDistributionMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(13.into(), &super::test::memory_distribution_metric); map });
- pub static CUSTOM_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<CustomDistributionMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static CUSTOM_DISTRIBUTION_MAP: Lazy<HashMap<MetricId, &Lazy<CustomDistributionMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(14.into(), &super::test::custom_distribution_metric); map });
- pub static UUID_MAP: Lazy<HashMap<MetricId, &Lazy<UuidMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static UUID_MAP: Lazy<HashMap<MetricId, &Lazy<UuidMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(15.into(), &super::test_nested::uuid_metric); map });
- pub static DATETIME_MAP: Lazy<HashMap<MetricId, &Lazy<DatetimeMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static DATETIME_MAP: Lazy<HashMap<MetricId, &Lazy<DatetimeMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(16.into(), &super::test_nested::datetime_metric); map });
- pub static QUANTITY_MAP: Lazy<HashMap<MetricId, &Lazy<QuantityMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static QUANTITY_MAP: Lazy<HashMap<MetricId, &Lazy<QuantityMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(19.into(), &super::test_nested::quantity_metric); map });
- pub static RATE_MAP: Lazy<HashMap<MetricId, &Lazy<RateMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static RATE_MAP: Lazy<HashMap<MetricId, &Lazy<RateMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(20.into(), &super::test_nested::rate_metric); map });
- pub static NUMERATOR_MAP: Lazy<HashMap<MetricId, &Lazy<NumeratorMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static NUMERATOR_MAP: Lazy<HashMap<MetricId, &Lazy<NumeratorMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(21.into(), &super::test_nested::rate_with_external_denominator); map });
- pub static DENOMINATOR_MAP: Lazy<HashMap<MetricId, &Lazy<DenominatorMetric>, HashState>> = Lazy::new(|| { - let mut map = HashMap::with_capacity_and_hasher(1, HashState); + pub static DENOMINATOR_MAP: Lazy<HashMap<MetricId, &Lazy<DenominatorMetric>>> = Lazy::new(|| { + let mut map = HashMap::with_capacity(1); map.insert(22.into(), &super::test_nested::external_denominator); map }); @@ -684,18 +683,18 @@ pub(crate) mod __glean_metric_maps {
pub(crate) const MIN_LABELED_SUBMETRIC_ID: u32 = 134217729; pub(crate) static NEXT_LABELED_SUBMETRIC_ID: AtomicU32 = AtomicU32::new(MIN_LABELED_SUBMETRIC_ID); - pub(crate) static LABELED_METRICS_TO_IDS: Lazy<RwLock<HashMap<(u32, String), u32, HashState>>> = Lazy::new(|| - RwLock::new(HashMap::with_hasher(HashState)) + pub(crate) static LABELED_METRICS_TO_IDS: Lazy<RwLock<HashMap<(u32, String), u32>>> = Lazy::new(|| + RwLock::new(HashMap::new()) );
- pub static BOOLEAN_MAP: Lazy<RwLock<HashMap<MetricId, LabeledBooleanMetric, HashState>>> = Lazy::new(|| - RwLock::new(HashMap::with_hasher(HashState)) + pub static BOOLEAN_MAP: Lazy<RwLock<HashMap<MetricId, LabeledBooleanMetric>>> = Lazy::new(|| + RwLock::new(HashMap::new()) ); - pub static COUNTER_MAP: Lazy<RwLock<HashMap<MetricId, LabeledCounterMetric, HashState>>> = Lazy::new(|| - RwLock::new(HashMap::with_hasher(HashState)) + pub static COUNTER_MAP: Lazy<RwLock<HashMap<MetricId, LabeledCounterMetric>>> = Lazy::new(|| + RwLock::new(HashMap::new()) ); - pub static STRING_MAP: Lazy<RwLock<HashMap<MetricId, LabeledStringMetric, HashState>>> = Lazy::new(|| - RwLock::new(HashMap::with_hasher(HashState)) + pub static STRING_MAP: Lazy<RwLock<HashMap<MetricId, LabeledStringMetric>>> = Lazy::new(|| + RwLock::new(HashMap::new()) ); } }