Skip to content

Commit 5c872dd

Browse files
cleanup: inline slotmap_key_ffi helper for clarity
Remove the `slotmap_key_ffi` helper and inline `key.data().as_ffi()` at each call site. This makes the symmetry with the generated `KeyData::from_ffi(ffi).into()` more visible. Co-authored-by: Infinity 🤖 <infinity@hydro.run> PR: #2810
1 parent aa12c7d commit 5c872dd

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

dfir_lang/src/graph/meta_graph.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -851,12 +851,6 @@ impl DfirGraph {
851851
prefix: TokenStream,
852852
diagnostics: &mut Diagnostics,
853853
) -> Result<TokenStream, Diagnostics> {
854-
// Convert a slotmap key to its FFI representation for use in generated code.
855-
// The FFI value can reconstruct the key at runtime via `KeyData::from_ffi`.
856-
fn slotmap_key_ffi(key: impl Key) -> u64 {
857-
key.data().as_ffi()
858-
}
859-
860854
let df = Ident::new(GRAPH, Span::call_site());
861855
let context = Ident::new(CONTEXT, Span::call_site());
862856

@@ -998,7 +992,7 @@ impl DfirGraph {
998992
let mut subgraph_blocks = Vec::new();
999993
{
1000994
for &(subgraph_id, subgraph_nodes) in all_subgraphs.iter() {
1001-
let sg_metrics_ffi = slotmap_key_ffi(subgraph_id);
995+
let sg_metrics_ffi = subgraph_id.data().as_ffi();
1002996
let (recv_hoffs, send_hoffs) = &subgraph_handoffs[subgraph_id];
1003997

1004998
// Generate buffer ident helpers for this subgraph's handoffs.
@@ -1029,7 +1023,7 @@ impl DfirGraph {
10291023
.zip(recv_buf_idents.iter())
10301024
.zip(recv_hoffs.iter())
10311025
.map(|((port_ident, buf_ident), &hoff_id)| {
1032-
let hoff_ffi = slotmap_key_ffi(hoff_id);
1026+
let hoff_ffi = hoff_id.data().as_ffi();
10331027
// Use call_site span for internal identifiers to avoid
10341028
// hygiene issues when invoked through declarative macros
10351029
// (e.g. dfir_expect_warnings!). TODO(#2781): define these once.
@@ -1455,7 +1449,7 @@ impl DfirGraph {
14551449
.iter()
14561450
.zip(send_buf_idents.iter())
14571451
.map(|(&hoff_id, buf_ident)| {
1458-
let hoff_ffi = slotmap_key_ffi(hoff_id);
1452+
let hoff_ffi = hoff_id.data().as_ffi();
14591453
quote! {
14601454
__dfir_metrics.handoffs[
14611455
#root::slotmap::KeyData::from_ffi(#hoff_ffi).into()
@@ -1513,7 +1507,7 @@ impl DfirGraph {
15131507
// Generate metrics initialization: one entry per handoff and per subgraph.
15141508
let metrics_init_code = {
15151509
let handoff_inits = handoff_nodes.iter().map(|&(node_id, _)| {
1516-
let ffi = slotmap_key_ffi(node_id);
1510+
let ffi = node_id.data().as_ffi();
15171511
quote! {
15181512
dfir_metrics.handoffs.insert(
15191513
#root::slotmap::KeyData::from_ffi(#ffi).into(),
@@ -1522,7 +1516,7 @@ impl DfirGraph {
15221516
}
15231517
});
15241518
let subgraph_inits = all_subgraphs.iter().map(|&(sg_id, _)| {
1525-
let ffi = slotmap_key_ffi(sg_id);
1519+
let ffi = sg_id.data().as_ffi();
15261520
quote! {
15271521
dfir_metrics.subgraphs.insert(
15281522
#root::slotmap::KeyData::from_ffi(#ffi).into(),

0 commit comments

Comments
 (0)