Skip to content

Commit

Permalink
Auto merge of rust-lang#136003 - davidv1992:eliminate-field-offset, r…
Browse files Browse the repository at this point in the history
…=<try>

Removed dependency on the field-offset crate.

This touches the core of the query system, should be evaluated carefully for performance.
  • Loading branch information
bors committed Jan 24, 2025
2 parents 8231e85 + 5fd7599 commit 4405608
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 33 deletions.
21 changes: 0 additions & 21 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1195,16 +1195,6 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"

[[package]]
name = "field-offset"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f"
dependencies = [
"memoffset",
"rustc_version",
]

[[package]]
name = "filetime"
version = "0.2.25"
Expand Down Expand Up @@ -2270,15 +2260,6 @@ dependencies = [
"libc",
]

[[package]]
name = "memoffset"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
dependencies = [
"autocfg",
]

[[package]]
name = "mime"
version = "0.3.17"
Expand Down Expand Up @@ -4118,7 +4099,6 @@ version = "0.0.0"
dependencies = [
"bitflags",
"either",
"field-offset",
"gsgdt",
"polonius-engine",
"rustc-rayon-core",
Expand Down Expand Up @@ -4364,7 +4344,6 @@ dependencies = [
name = "rustc_query_impl"
version = "0.0.0"
dependencies = [
"field-offset",
"measureme",
"rustc_data_structures",
"rustc_errors",
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
# tidy-alphabetical-start
bitflags = "2.4.1"
either = "1.5.0"
field-offset = "0.3.5"
gsgdt = "0.1.2"
polonius-engine = "0.13.0"
rustc-rayon-core = { version = "0.5.0" }
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::ops::Deref;

use field_offset::FieldOffset;
use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::hir_id::OwnerId;
Expand All @@ -24,8 +23,8 @@ pub struct DynamicQuery<'tcx, C: QueryCache> {
pub eval_always: bool,
pub dep_kind: DepKind,
pub handle_cycle_error: HandleCycleError,
pub query_state: FieldOffset<QueryStates<'tcx>, QueryState<C::Key>>,
pub query_cache: FieldOffset<QueryCaches<'tcx>, C>,
pub query_state: for<'a> fn(&'a QueryStates<'tcx>) -> &'a QueryState<C::Key>,
pub query_cache: for<'a> fn(&'a QueryCaches<'tcx>) -> &'a C,
pub cache_on_disk: fn(tcx: TyCtxt<'tcx>, key: &C::Key) -> bool,
pub execute_query: fn(tcx: TyCtxt<'tcx>, k: C::Key) -> C::Value,
pub compute: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
# tidy-alphabetical-start
field-offset = "0.3.5"
measureme = "11"
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![warn(unreachable_pub)]
// tidy-alphabetical-end

use field_offset::offset_of;
use rustc_data_structures::stable_hasher::HashStable;
use rustc_data_structures::sync::AtomicU64;
use rustc_middle::arena::Arena;
Expand All @@ -20,8 +19,7 @@ use rustc_middle::query::erase::{Erase, erase, restore};
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
use rustc_middle::query::plumbing::{DynamicQuery, QuerySystem, QuerySystemFns};
use rustc_middle::query::{
AsLocalKey, DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
queries,
AsLocalKey, DynamicQueries, ExternProviders, Providers, QueryEngine, queries,
};
use rustc_middle::ty::TyCtxt;
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
Expand Down Expand Up @@ -89,15 +87,15 @@ where
where
QueryCtxt<'tcx>: 'a,
{
self.dynamic.query_state.apply(&qcx.tcx.query_system.states)
(self.dynamic.query_state)(&qcx.tcx.query_system.states)
}

#[inline(always)]
fn query_cache<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a Self::Cache
where
'tcx: 'a,
{
self.dynamic.query_cache.apply(&qcx.tcx.query_system.caches)
(self.dynamic.query_cache)(&qcx.tcx.query_system.caches)
}

#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ macro_rules! define_queries {
eval_always: is_eval_always!([$($modifiers)*]),
dep_kind: dep_graph::dep_kinds::$name,
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
query_state: offset_of!(QueryStates<'tcx> => $name),
query_cache: offset_of!(QueryCaches<'tcx> => $name),
query_state: |states| &states.$name,
query_cache: |cache| &cache.$name,
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
execute_query: |tcx, key| erase(tcx.$name(key)),
compute: |tcx, key| {
Expand Down

0 comments on commit 4405608

Please sign in to comment.