Skip to content

Commit 09d1d97

Browse files
committed
Auto merge of #136003 - davidv1992:eliminate-field-offset, r=<try>
Removed dependency on the field-offset crate. This touches the core of the query system, should be evaluated carefully for performance.
2 parents f940188 + 4efb1b1 commit 09d1d97

File tree

7 files changed

+7
-37
lines changed

7 files changed

+7
-37
lines changed

Diff for: Cargo.lock

-21
Original file line numberDiff line numberDiff line change
@@ -1195,16 +1195,6 @@ version = "2.3.0"
11951195
source = "registry+https://github.com/rust-lang/crates.io-index"
11961196
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
11971197

1198-
[[package]]
1199-
name = "field-offset"
1200-
version = "0.3.6"
1201-
source = "registry+https://github.com/rust-lang/crates.io-index"
1202-
checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f"
1203-
dependencies = [
1204-
"memoffset",
1205-
"rustc_version",
1206-
]
1207-
12081198
[[package]]
12091199
name = "filetime"
12101200
version = "0.2.25"
@@ -2270,15 +2260,6 @@ dependencies = [
22702260
"libc",
22712261
]
22722262

2273-
[[package]]
2274-
name = "memoffset"
2275-
version = "0.9.1"
2276-
source = "registry+https://github.com/rust-lang/crates.io-index"
2277-
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
2278-
dependencies = [
2279-
"autocfg",
2280-
]
2281-
22822263
[[package]]
22832264
name = "mime"
22842265
version = "0.3.17"
@@ -4118,7 +4099,6 @@ version = "0.0.0"
41184099
dependencies = [
41194100
"bitflags",
41204101
"either",
4121-
"field-offset",
41224102
"gsgdt",
41234103
"polonius-engine",
41244104
"rustc-rayon-core",
@@ -4364,7 +4344,6 @@ dependencies = [
43644344
name = "rustc_query_impl"
43654345
version = "0.0.0"
43664346
dependencies = [
4367-
"field-offset",
43684347
"measureme",
43694348
"rustc_data_structures",
43704349
"rustc_errors",

Diff for: compiler/rustc_middle/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2021"
77
# tidy-alphabetical-start
88
bitflags = "2.4.1"
99
either = "1.5.0"
10-
field-offset = "0.3.5"
1110
gsgdt = "0.1.2"
1211
polonius-engine = "0.13.0"
1312
rustc-rayon-core = { version = "0.5.0" }

Diff for: compiler/rustc_middle/src/query/plumbing.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::ops::Deref;
22

3-
use field_offset::FieldOffset;
43
use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
54
use rustc_hir::def_id::{DefId, LocalDefId};
65
use rustc_hir::hir_id::OwnerId;
@@ -24,8 +23,8 @@ pub struct DynamicQuery<'tcx, C: QueryCache> {
2423
pub eval_always: bool,
2524
pub dep_kind: DepKind,
2625
pub handle_cycle_error: HandleCycleError,
27-
pub query_state: FieldOffset<QueryStates<'tcx>, QueryState<C::Key>>,
28-
pub query_cache: FieldOffset<QueryCaches<'tcx>, C>,
26+
pub query_state: for<'a> fn(&'a QueryStates<'tcx>) -> &'a QueryState<C::Key>,
27+
pub query_cache: for<'a> fn(&'a QueryCaches<'tcx>) -> &'a C,
2928
pub cache_on_disk: fn(tcx: TyCtxt<'tcx>, key: &C::Key) -> bool,
3029
pub execute_query: fn(tcx: TyCtxt<'tcx>, k: C::Key) -> C::Value,
3130
pub compute: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,

Diff for: compiler/rustc_query_impl/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
field-offset = "0.3.5"
98
measureme = "11"
109
rustc_data_structures = { path = "../rustc_data_structures" }
1110
rustc_errors = { path = "../rustc_errors" }

Diff for: compiler/rustc_query_impl/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#![warn(unreachable_pub)]
1212
// tidy-alphabetical-end
1313

14-
use field_offset::offset_of;
1514
use rustc_data_structures::stable_hasher::HashStable;
1615
use rustc_data_structures::sync::AtomicU64;
1716
use rustc_middle::arena::Arena;
@@ -20,8 +19,7 @@ use rustc_middle::query::erase::{Erase, erase, restore};
2019
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
2120
use rustc_middle::query::plumbing::{DynamicQuery, QuerySystem, QuerySystemFns};
2221
use rustc_middle::query::{
23-
AsLocalKey, DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
24-
queries,
22+
AsLocalKey, DynamicQueries, ExternProviders, Providers, QueryEngine, queries,
2523
};
2624
use rustc_middle::ty::TyCtxt;
2725
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
@@ -89,15 +87,15 @@ where
8987
where
9088
QueryCtxt<'tcx>: 'a,
9189
{
92-
self.dynamic.query_state.apply(&qcx.tcx.query_system.states)
90+
(self.dynamic.query_state)(&qcx.tcx.query_system.states)
9391
}
9492

9593
#[inline(always)]
9694
fn query_cache<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a Self::Cache
9795
where
9896
'tcx: 'a,
9997
{
100-
self.dynamic.query_cache.apply(&qcx.tcx.query_system.caches)
98+
(self.dynamic.query_cache)(&qcx.tcx.query_system.caches)
10199
}
102100

103101
#[inline(always)]

Diff for: compiler/rustc_query_impl/src/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ macro_rules! define_queries {
605605
eval_always: is_eval_always!([$($modifiers)*]),
606606
dep_kind: dep_graph::dep_kinds::$name,
607607
handle_cycle_error: handle_cycle_error!([$($modifiers)*]),
608-
query_state: offset_of!(QueryStates<'tcx> => $name),
609-
query_cache: offset_of!(QueryCaches<'tcx> => $name),
608+
query_state: |states| &states.$name,
609+
query_cache: |cache| &cache.$name,
610610
cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
611611
execute_query: |tcx, key| erase(tcx.$name(key)),
612612
compute: |tcx, key| {

Diff for: src/tools/tidy/src/deps.rs

-4
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
284284
"expect-test",
285285
"fallible-iterator", // dependency of `thorin`
286286
"fastrand",
287-
"field-offset",
288287
"flate2",
289288
"fluent-bundle",
290289
"fluent-langneg",
@@ -326,7 +325,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
326325
"measureme",
327326
"memchr",
328327
"memmap2",
329-
"memoffset",
330328
"miniz_oxide",
331329
"nix",
332330
"nu-ansi-term",
@@ -366,14 +364,12 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
366364
"rustc-rayon-core",
367365
"rustc-stable-hash",
368366
"rustc_apfloat",
369-
"rustc_version",
370367
"rustix",
371368
"ruzstd", // via object in thorin-dwp
372369
"ryu",
373370
"scoped-tls",
374371
"scopeguard",
375372
"self_cell",
376-
"semver",
377373
"serde",
378374
"serde_derive",
379375
"serde_json",

0 commit comments

Comments
 (0)