diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index 6db2910bca4..aaac7fb4460 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -23,6 +23,7 @@ #![feature(integer_atomics)] #![feature(test)] #![feature(associated_type_bounds)] +#![feature(thread_id_value)] #![cfg_attr(unix, feature(libc))] #![allow(rustc::default_hash_types)] diff --git a/src/librustc_data_structures/profiling.rs b/src/librustc_data_structures/profiling.rs index 44cef727f03..90f74328a1d 100644 --- a/src/librustc_data_structures/profiling.rs +++ b/src/librustc_data_structures/profiling.rs @@ -88,7 +88,6 @@ use std::fs; use std::path::Path; use std::process; use std::sync::Arc; -use std::thread::ThreadId; use std::time::{Duration, Instant}; use std::u32; @@ -129,17 +128,13 @@ bitflags::bitflags! { Self::QUERY_PROVIDERS.bits | Self::QUERY_BLOCKED.bits | Self::INCR_CACHE_LOADS.bits; - - // empty() and none() aren't const-fns unfortunately - const NONE = 0; - const ALL = !Self::NONE.bits; } } // keep this in sync with the `-Z self-profile-events` help message in librustc_session/options.rs const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[ - ("none", EventFilter::NONE), - ("all", EventFilter::ALL), + ("none", EventFilter::empty()), + ("all", EventFilter::all()), ("default", EventFilter::DEFAULT), ("generic-activity", EventFilter::GENERIC_ACTIVITIES), ("query-provider", EventFilter::QUERY_PROVIDERS), @@ -149,10 +144,6 @@ const EVENT_FILTERS_BY_NAME: &[(&str, EventFilter)] = &[ ("query-keys", EventFilter::QUERY_KEYS), ]; -fn thread_id_to_u32(tid: ThreadId) -> u32 { - unsafe { std::mem::transmute::(tid) as u32 } -} - /// Something that uniquely identifies a query invocation. pub struct QueryInvocationId(pub u32); @@ -185,7 +176,7 @@ impl SelfProfilerRef { // If there is no SelfProfiler then the filter mask is set to NONE, // ensuring that nothing ever tries to actually access it. let event_filter_mask = - profiler.as_ref().map(|p| p.event_filter_mask).unwrap_or(EventFilter::NONE); + profiler.as_ref().map(|p| p.event_filter_mask).unwrap_or(EventFilter::empty()); SelfProfilerRef { profiler, @@ -318,7 +309,7 @@ impl SelfProfilerRef { ) { drop(self.exec(event_filter, |profiler| { let event_id = StringId::new_virtual(query_invocation_id.0); - let thread_id = thread_id_to_u32(std::thread::current().id()); + let thread_id = std::thread::current().id().as_u64() as u32; profiler.profiler.record_instant_event( event_kind(profiler), @@ -477,7 +468,7 @@ impl<'a> TimingGuard<'a> { event_kind: StringId, event_id: EventId, ) -> TimingGuard<'a> { - let thread_id = thread_id_to_u32(std::thread::current().id()); + let thread_id = std::thread::current().id().as_u64() as u32; let raw_profiler = &profiler.profiler; let timing_guard = raw_profiler.start_recording_interval_event(event_kind, event_id, thread_id);