From 829357425e161f2960ad826a0067a2c6577d4995 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Wed, 28 Jan 2026 17:23:04 -0500 Subject: [PATCH 1/3] Make IDs 32bits --- rust/rubydex-sys/src/declaration_api.rs | 12 +++++----- rust/rubydex-sys/src/definition_api.rs | 20 ++++++++-------- rust/rubydex-sys/src/document_api.rs | 6 ++--- rust/rubydex-sys/src/graph_api.rs | 22 ++++++++--------- rust/rubydex-sys/src/reference_api.rs | 14 +++++------ rust/rubydex/Cargo.toml | 2 +- rust/rubydex/src/model/declaration.rs | 6 ++--- rust/rubydex/src/model/definitions.rs | 32 ++++++++++++------------- rust/rubydex/src/model/id.rs | 26 ++++++++------------ rust/rubydex/src/model/identity_maps.rs | 4 ++++ rust/rubydex/src/model/ids.rs | 10 ++++---- rust/rubydex/src/model/name.rs | 4 ++-- rust/rubydex/src/resolution.rs | 2 +- 13 files changed, 79 insertions(+), 81 deletions(-) diff --git a/rust/rubydex-sys/src/declaration_api.rs b/rust/rubydex-sys/src/declaration_api.rs index 9ae6cdcf3..3241a3183 100644 --- a/rust/rubydex-sys/src/declaration_api.rs +++ b/rust/rubydex-sys/src/declaration_api.rs @@ -21,7 +21,7 @@ use rubydex::model::ids::{DeclarationId, StringId}; /// /// This function will panic if the name pointer is invalid. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_declaration_name(pointer: GraphPointer, name_id: i64) -> *const c_char { +pub unsafe extern "C" fn rdx_declaration_name(pointer: GraphPointer, name_id: u32) -> *const c_char { with_graph(pointer, |graph| { let name_id = DeclarationId::new(name_id); if let Some(decl) = graph.declarations().get(&name_id) { @@ -40,9 +40,9 @@ pub unsafe extern "C" fn rdx_declaration_name(pointer: GraphPointer, name_id: i6 #[unsafe(no_mangle)] pub unsafe extern "C" fn rdx_declaration_member( pointer: GraphPointer, - name_id: i64, + name_id: u32, member: *const c_char, -) -> *const i64 { +) -> *const u32 { let Ok(member_str) = (unsafe { utils::convert_char_ptr_to_string(member) }) else { return ptr::null(); }; @@ -72,7 +72,7 @@ pub unsafe extern "C" fn rdx_declaration_member( /// /// This function will panic if the name pointer is invalid. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_declaration_unqualified_name(pointer: GraphPointer, name_id: i64) -> *const c_char { +pub unsafe extern "C" fn rdx_declaration_unqualified_name(pointer: GraphPointer, name_id: u32) -> *const c_char { with_graph(pointer, |graph| { let name_id = DeclarationId::new(name_id); if let Some(decl) = graph.declarations().get(&name_id) { @@ -96,7 +96,7 @@ pub unsafe extern "C" fn rdx_declaration_unqualified_name(pointer: GraphPointer, #[unsafe(no_mangle)] pub unsafe extern "C" fn rdx_declaration_definitions_iter_new( pointer: GraphPointer, - decl_id: i64, + decl_id: u32, ) -> *mut DefinitionsIter { // Snapshot the IDs and kinds at iterator creation to avoid borrowing across FFI calls with_graph(pointer, |graph| { @@ -104,7 +104,7 @@ pub unsafe extern "C" fn rdx_declaration_definitions_iter_new( if let Some(decl) = graph.declarations().get(&decl_id) { rdx_definitions_iter_new_from_ids(graph, decl.definitions()) } else { - DefinitionsIter::new(Vec::<(i64, DefinitionKind)>::new().into_boxed_slice()) + DefinitionsIter::new(Vec::<(u32, DefinitionKind)>::new().into_boxed_slice()) } }) } diff --git a/rust/rubydex-sys/src/definition_api.rs b/rust/rubydex-sys/src/definition_api.rs index 627167b71..a159ff29d 100644 --- a/rust/rubydex-sys/src/definition_api.rs +++ b/rust/rubydex-sys/src/definition_api.rs @@ -57,7 +57,7 @@ pub(crate) fn map_definition_to_kind(defn: &Definition) -> DefinitionKind { /// /// This function will panic if the definition cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_definition_kind(pointer: GraphPointer, definition_id: i64) -> DefinitionKind { +pub unsafe extern "C" fn rdx_definition_kind(pointer: GraphPointer, definition_id: u32) -> DefinitionKind { with_graph(pointer, |graph| { let definition_id = DefinitionId::new(definition_id); if let Some(defn) = graph.definitions().get(&definition_id) { @@ -79,7 +79,7 @@ pub unsafe extern "C" fn rdx_definition_kind(pointer: GraphPointer, definition_i /// /// This function will panic if the definition cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_definition_name(pointer: GraphPointer, definition_id: i64) -> *const c_char { +pub unsafe extern "C" fn rdx_definition_name(pointer: GraphPointer, definition_id: u32) -> *const c_char { with_graph(pointer, |graph| { let def_id = DefinitionId::new(definition_id); if let Some(defn) = graph.definitions().get(&def_id) { @@ -99,13 +99,13 @@ pub unsafe extern "C" fn rdx_definition_name(pointer: GraphPointer, definition_i /// Shared iterator over definition (id, kind) pairs #[derive(Debug)] pub struct DefinitionsIter { - pub entries: Box<[(i64, DefinitionKind)]>, + pub entries: Box<[(u32, DefinitionKind)]>, pub index: usize, } impl DefinitionsIter { #[must_use] - pub fn new(entries: Box<[(i64, DefinitionKind)]>) -> *mut DefinitionsIter { + pub fn new(entries: Box<[(u32, DefinitionKind)]>) -> *mut DefinitionsIter { Box::into_raw(Box::new(DefinitionsIter { entries, index: 0 })) } } @@ -131,7 +131,7 @@ pub unsafe extern "C" fn rdx_definitions_iter_len(iter: *const DefinitionsIter) #[unsafe(no_mangle)] pub unsafe extern "C" fn rdx_definitions_iter_next( iter: *mut DefinitionsIter, - out_id: *mut i64, + out_id: *mut u32, out_kind: *mut DefinitionKind, ) -> bool { if iter.is_null() || out_id.is_null() || out_kind.is_null() { @@ -191,7 +191,7 @@ pub struct CommentArray { /// # Panics /// This function will panic if a definition or document cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_definition_comments(pointer: GraphPointer, definition_id: i64) -> *mut CommentArray { +pub unsafe extern "C" fn rdx_definition_comments(pointer: GraphPointer, definition_id: u32) -> *mut CommentArray { with_graph(pointer, |graph| { let def_id = DefinitionId::new(definition_id); let Some(defn) = graph.definitions().get(&def_id) else { @@ -265,7 +265,7 @@ pub unsafe extern "C" fn rdx_definition_comments_free(ptr: *mut CommentArray) { /// /// This function will panic if a definition or document cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_definition_location(pointer: GraphPointer, definition_id: i64) -> *mut Location { +pub unsafe extern "C" fn rdx_definition_location(pointer: GraphPointer, definition_id: u32) -> *mut Location { with_graph(pointer, |graph| { let def_id = DefinitionId::new(definition_id); let Some(defn) = graph.definitions().get(&def_id) else { @@ -299,7 +299,7 @@ where .map_or_else(|| panic!("Definition not found: {id:?}"), map_definition_to_kind); (id, kind) }) - .collect::>() + .collect::>() .into_boxed_slice(); DefinitionsIter::new(entries) @@ -314,7 +314,7 @@ where /// # Panics /// This function will panic if a definition cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_definition_is_deprecated(pointer: GraphPointer, definition_id: i64) -> bool { +pub unsafe extern "C" fn rdx_definition_is_deprecated(pointer: GraphPointer, definition_id: u32) -> bool { with_graph(pointer, |graph| { let def_id = DefinitionId::new(definition_id); let defn = graph.definitions().get(&def_id).expect("definition not found"); @@ -335,7 +335,7 @@ pub unsafe extern "C" fn rdx_definition_is_deprecated(pointer: GraphPointer, def /// # Panics /// Panics if the definition's document does not exist in the graph. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_definition_name_location(pointer: GraphPointer, definition_id: i64) -> *mut Location { +pub unsafe extern "C" fn rdx_definition_name_location(pointer: GraphPointer, definition_id: u32) -> *mut Location { with_graph(pointer, |graph| { let def_id = DefinitionId::new(definition_id); let Some(defn) = graph.definitions().get(&def_id) else { diff --git a/rust/rubydex-sys/src/document_api.rs b/rust/rubydex-sys/src/document_api.rs index f3319c3e3..a3e827cd7 100644 --- a/rust/rubydex-sys/src/document_api.rs +++ b/rust/rubydex-sys/src/document_api.rs @@ -19,7 +19,7 @@ use rubydex::model::ids::UriId; /// /// This function will panic if the URI pointer is invalid. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_document_uri(pointer: GraphPointer, uri_id: i64) -> *const c_char { +pub unsafe extern "C" fn rdx_document_uri(pointer: GraphPointer, uri_id: u32) -> *const c_char { with_graph(pointer, |graph| { let uri_id = UriId::new(uri_id); if let Some(doc) = graph.documents().get(&uri_id) { @@ -41,14 +41,14 @@ pub unsafe extern "C" fn rdx_document_uri(pointer: GraphPointer, uri_id: i64) -> /// - `pointer` must be a valid `GraphPointer` previously returned by this crate. /// - The returned pointer must be freed with `rdx_document_definitions_iter_free`. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_document_definitions_iter_new(pointer: GraphPointer, uri_id: i64) -> *mut DefinitionsIter { +pub unsafe extern "C" fn rdx_document_definitions_iter_new(pointer: GraphPointer, uri_id: u32) -> *mut DefinitionsIter { // Snapshot the IDs and kinds at iterator creation to avoid borrowing across FFI calls with_graph(pointer, |graph| { let uri_id = UriId::new(uri_id); if let Some(doc) = graph.documents().get(&uri_id) { rdx_definitions_iter_new_from_ids(graph, doc.definitions()) } else { - DefinitionsIter::new(Vec::<(i64, DefinitionKind)>::new().into_boxed_slice()) + DefinitionsIter::new(Vec::<(u32, DefinitionKind)>::new().into_boxed_slice()) } }) } diff --git a/rust/rubydex-sys/src/graph_api.rs b/rust/rubydex-sys/src/graph_api.rs index c0d743cf7..f29a0a3a9 100644 --- a/rust/rubydex-sys/src/graph_api.rs +++ b/rust/rubydex-sys/src/graph_api.rs @@ -65,7 +65,7 @@ pub unsafe extern "C" fn rdx_graph_declarations_search( query::declaration_search(graph, &query) .into_iter() .map(|id| *id) - .collect::>() + .collect::>() .into_boxed_slice() }); @@ -85,7 +85,7 @@ pub unsafe extern "C" fn rdx_graph_resolve_constant( const_name: *const c_char, nesting: *const *const c_char, count: usize, -) -> *const i64 { +) -> *const u32 { with_mut_graph(pointer, |graph| { let nesting: Vec = unsafe { utils::convert_double_pointer_to_vec(nesting, count).unwrap() }; let const_name: String = unsafe { utils::convert_char_ptr_to_string(const_name).unwrap() }; @@ -191,7 +191,7 @@ pub unsafe extern "C" fn rdx_graph_set_encoding(pointer: GraphPointer, encoding_ #[derive(Debug)] pub struct DeclarationsIter { /// The snapshot of declaration IDs - ids: Box<[i64]>, + ids: Box<[u32]>, /// The current index of the iterator index: usize, } @@ -210,7 +210,7 @@ pub unsafe extern "C" fn rdx_graph_declarations_iter_new(pointer: GraphPointer) .declarations() .keys() .map(|name_id| **name_id) - .collect::>() + .collect::>() .into_boxed_slice() }); @@ -239,7 +239,7 @@ pub unsafe extern "C" fn rdx_graph_declarations_iter_len(iter: *const Declaratio /// - `iter` must be a valid pointer previously returned by `rdx_graph_declarations_iter_new`. /// - `out_id` must be a valid, writable pointer. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_graph_declarations_iter_next(iter: *mut DeclarationsIter, out_id: *mut i64) -> bool { +pub unsafe extern "C" fn rdx_graph_declarations_iter_next(iter: *mut DeclarationsIter, out_id: *mut u32) -> bool { if iter.is_null() || out_id.is_null() { return false; } @@ -279,7 +279,7 @@ pub unsafe extern "C" fn rdx_graph_declarations_iter_free(iter: *mut Declaration #[derive(Debug)] pub struct DocumentsIter { /// The snapshot of document (URI) IDs - ids: Box<[i64]>, + ids: Box<[u32]>, /// The current index of the iterator index: usize, } @@ -298,7 +298,7 @@ pub unsafe extern "C" fn rdx_graph_documents_iter_new(pointer: GraphPointer) -> .documents() .keys() .map(|uri_id| **uri_id) - .collect::>() + .collect::>() .into_boxed_slice() }); @@ -327,7 +327,7 @@ pub unsafe extern "C" fn rdx_graph_documents_iter_len(iter: *const DocumentsIter /// - `iter` must be a valid pointer previously returned by `rdx_graph_documents_iter_new`. /// - `out_id` must be a valid, writable pointer. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_graph_documents_iter_next(iter: *mut DocumentsIter, out_id: *mut i64) -> bool { +pub unsafe extern "C" fn rdx_graph_documents_iter_next(iter: *mut DocumentsIter, out_id: *mut u32) -> bool { if iter.is_null() || out_id.is_null() { return false; } @@ -369,7 +369,7 @@ pub unsafe extern "C" fn rdx_graph_documents_iter_free(iter: *mut DocumentsIter) /// - `name` must be a valid, null-terminated UTF-8 string /// - `out_id` must be a valid, writable pointer #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_graph_get_declaration(pointer: GraphPointer, name: *const c_char) -> *const i64 { +pub unsafe extern "C" fn rdx_graph_get_declaration(pointer: GraphPointer, name: *const c_char) -> *const u32 { let Ok(name_str) = (unsafe { utils::convert_char_ptr_to_string(name) }) else { return ptr::null(); }; @@ -392,7 +392,7 @@ pub unsafe extern "C" fn rdx_graph_get_declaration(pointer: GraphPointer, name: #[unsafe(no_mangle)] pub unsafe extern "C" fn rdx_graph_constant_references_iter_new(pointer: GraphPointer) -> *mut ReferencesIter { with_graph(pointer, |graph| { - let refs: Vec<(i64, ReferenceKind)> = graph + let refs: Vec<(u32, ReferenceKind)> = graph .constant_references() .keys() .map(|id| (**id, ReferenceKind::Constant)) @@ -409,7 +409,7 @@ pub unsafe extern "C" fn rdx_graph_constant_references_iter_new(pointer: GraphPo #[unsafe(no_mangle)] pub unsafe extern "C" fn rdx_graph_method_references_iter_new(pointer: GraphPointer) -> *mut ReferencesIter { with_graph(pointer, |graph| { - let refs: Vec<(i64, ReferenceKind)> = graph + let refs: Vec<(u32, ReferenceKind)> = graph .method_references() .keys() .map(|id| (**id, ReferenceKind::Method)) diff --git a/rust/rubydex-sys/src/reference_api.rs b/rust/rubydex-sys/src/reference_api.rs index 66762e44b..bf2ce9faa 100644 --- a/rust/rubydex-sys/src/reference_api.rs +++ b/rust/rubydex-sys/src/reference_api.rs @@ -18,13 +18,13 @@ pub enum ReferenceKind { /// Shared iterator over reference (id, kind) pairs #[derive(Debug)] pub struct ReferencesIter { - pub entries: Box<[(i64, ReferenceKind)]>, + pub entries: Box<[(u32, ReferenceKind)]>, pub index: usize, } impl ReferencesIter { #[must_use] - pub fn new(entries: Box<[(i64, ReferenceKind)]>) -> *mut ReferencesIter { + pub fn new(entries: Box<[(u32, ReferenceKind)]>) -> *mut ReferencesIter { Box::into_raw(Box::new(ReferencesIter { entries, index: 0 })) } } @@ -54,7 +54,7 @@ pub unsafe extern "C" fn rdx_references_iter_len(iter: *const ReferencesIter) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn rdx_references_iter_next( iter: *mut ReferencesIter, - out_id: *mut i64, + out_id: *mut u32, out_kind: *mut ReferenceKind, ) -> bool { if iter.is_null() || out_id.is_null() || out_kind.is_null() { @@ -101,7 +101,7 @@ pub unsafe extern "C" fn rdx_references_iter_free(iter: *mut ReferencesIter) { /// /// This function will panic if the reference cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_constant_reference_name(pointer: GraphPointer, reference_id: i64) -> *const c_char { +pub unsafe extern "C" fn rdx_constant_reference_name(pointer: GraphPointer, reference_id: u32) -> *const c_char { with_graph(pointer, |graph| { let ref_id = ReferenceId::new(reference_id); let reference = graph.constant_references().get(&ref_id).expect("Reference not found"); @@ -127,7 +127,7 @@ pub unsafe extern "C" fn rdx_constant_reference_name(pointer: GraphPointer, refe /// /// This function will panic if the reference cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_method_reference_name(pointer: GraphPointer, reference_id: i64) -> *const c_char { +pub unsafe extern "C" fn rdx_method_reference_name(pointer: GraphPointer, reference_id: u32) -> *const c_char { with_graph(pointer, |graph| { let ref_id = ReferenceId::new(reference_id); let reference = graph.method_references().get(&ref_id).expect("Reference not found"); @@ -152,7 +152,7 @@ pub unsafe extern "C" fn rdx_method_reference_name(pointer: GraphPointer, refere /// /// This function will panic if a reference or document cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_constant_reference_location(pointer: GraphPointer, reference_id: i64) -> *mut Location { +pub unsafe extern "C" fn rdx_constant_reference_location(pointer: GraphPointer, reference_id: u32) -> *mut Location { with_graph(pointer, |graph| { let ref_id = ReferenceId::new(reference_id); let reference = graph.constant_references().get(&ref_id).expect("Reference not found"); @@ -177,7 +177,7 @@ pub unsafe extern "C" fn rdx_constant_reference_location(pointer: GraphPointer, /// /// This function will panic if a reference or document cannot be found. #[unsafe(no_mangle)] -pub unsafe extern "C" fn rdx_method_reference_location(pointer: GraphPointer, reference_id: i64) -> *mut Location { +pub unsafe extern "C" fn rdx_method_reference_location(pointer: GraphPointer, reference_id: u32) -> *mut Location { with_graph(pointer, |graph| { let ref_id = ReferenceId::new(reference_id); let reference = graph.method_references().get(&ref_id).expect("Reference not found"); diff --git a/rust/rubydex/Cargo.toml b/rust/rubydex/Cargo.toml index afb4a6a23..810d7bbf3 100644 --- a/rust/rubydex/Cargo.toml +++ b/rust/rubydex/Cargo.toml @@ -18,7 +18,7 @@ test_utils = ["dep:tempfile"] [dependencies] ruby-prism = "1.8.0" url = "2.5.4" -xxhash-rust = { version = "0.8.15", features = ["xxh3"] } +xxhash-rust = { version = "0.8.15", features = ["xxh32"] } clap = { version = "4.5.16", features = ["derive"] } glob = "0.3.2" bitflags = "2.9" diff --git a/rust/rubydex/src/model/declaration.rs b/rust/rubydex/src/model/declaration.rs index ffcbaa7e8..7789e7eaf 100644 --- a/rust/rubydex/src/model/declaration.rs +++ b/rust/rubydex/src/model/declaration.rs @@ -475,11 +475,11 @@ impl Namespace { } namespace_declaration!(Class, ClassDeclaration); -assert_mem_size!(ClassDeclaration, 224); +assert_mem_size!(ClassDeclaration, 216); namespace_declaration!(Module, ModuleDeclaration); -assert_mem_size!(ModuleDeclaration, 224); +assert_mem_size!(ModuleDeclaration, 216); namespace_declaration!(SingletonClass, SingletonClassDeclaration); -assert_mem_size!(SingletonClassDeclaration, 224); +assert_mem_size!(SingletonClassDeclaration, 216); simple_declaration!(ConstantDeclaration); assert_mem_size!(ConstantDeclaration, 112); diff --git a/rust/rubydex/src/model/definitions.rs b/rust/rubydex/src/model/definitions.rs index 4fe7dd38b..1e5a8b1e4 100644 --- a/rust/rubydex/src/model/definitions.rs +++ b/rust/rubydex/src/model/definitions.rs @@ -229,7 +229,7 @@ pub struct ClassDefinition { superclass_ref: Option, mixins: Vec, } -assert_mem_size!(ClassDefinition, 144); +assert_mem_size!(ClassDefinition, 120); impl ClassDefinition { #[must_use] @@ -354,7 +354,7 @@ pub struct SingletonClassDefinition { /// Mixins declared in this singleton class mixins: Vec, } -assert_mem_size!(SingletonClassDefinition, 128); +assert_mem_size!(SingletonClassDefinition, 112); impl SingletonClassDefinition { #[must_use] @@ -458,7 +458,7 @@ pub struct ModuleDefinition { members: Vec, mixins: Vec, } -assert_mem_size!(ModuleDefinition, 128); +assert_mem_size!(ModuleDefinition, 112); impl ModuleDefinition { #[must_use] @@ -558,7 +558,7 @@ pub struct ConstantDefinition { comments: Vec, lexical_nesting_id: Option, } -assert_mem_size!(ConstantDefinition, 72); +assert_mem_size!(ConstantDefinition, 56); impl ConstantDefinition { #[must_use] @@ -628,7 +628,7 @@ pub struct ConstantAliasDefinition { alias_constant: ConstantDefinition, target_name_id: NameId, } -assert_mem_size!(ConstantAliasDefinition, 80); +assert_mem_size!(ConstantAliasDefinition, 64); impl ConstantAliasDefinition { #[must_use] @@ -705,7 +705,7 @@ pub struct MethodDefinition { visibility: Visibility, receiver: Option, } -assert_mem_size!(MethodDefinition, 112); +assert_mem_size!(MethodDefinition, 88); impl MethodDefinition { #[allow(clippy::too_many_arguments)] @@ -803,14 +803,14 @@ pub enum Parameter { Forward(ParameterStruct), Block(ParameterStruct), } -assert_mem_size!(Parameter, 24); +assert_mem_size!(Parameter, 16); #[derive(Debug, Clone)] pub struct ParameterStruct { offset: Offset, str: StringId, } -assert_mem_size!(ParameterStruct, 16); +assert_mem_size!(ParameterStruct, 12); impl ParameterStruct { #[must_use] @@ -845,7 +845,7 @@ pub struct AttrAccessorDefinition { lexical_nesting_id: Option, visibility: Visibility, } -assert_mem_size!(AttrAccessorDefinition, 72); +assert_mem_size!(AttrAccessorDefinition, 56); impl AttrAccessorDefinition { #[must_use] @@ -926,7 +926,7 @@ pub struct AttrReaderDefinition { lexical_nesting_id: Option, visibility: Visibility, } -assert_mem_size!(AttrReaderDefinition, 72); +assert_mem_size!(AttrReaderDefinition, 56); impl AttrReaderDefinition { #[must_use] @@ -1007,7 +1007,7 @@ pub struct AttrWriterDefinition { lexical_nesting_id: Option, visibility: Visibility, } -assert_mem_size!(AttrWriterDefinition, 72); +assert_mem_size!(AttrWriterDefinition, 56); impl AttrWriterDefinition { #[must_use] @@ -1087,7 +1087,7 @@ pub struct GlobalVariableDefinition { comments: Vec, lexical_nesting_id: Option, } -assert_mem_size!(GlobalVariableDefinition, 72); +assert_mem_size!(GlobalVariableDefinition, 56); impl GlobalVariableDefinition { #[must_use] @@ -1160,7 +1160,7 @@ pub struct InstanceVariableDefinition { comments: Vec, lexical_nesting_id: Option, } -assert_mem_size!(InstanceVariableDefinition, 72); +assert_mem_size!(InstanceVariableDefinition, 56); impl InstanceVariableDefinition { #[must_use] @@ -1233,7 +1233,7 @@ pub struct ClassVariableDefinition { comments: Vec, lexical_nesting_id: Option, } -assert_mem_size!(ClassVariableDefinition, 72); +assert_mem_size!(ClassVariableDefinition, 56); impl ClassVariableDefinition { #[must_use] @@ -1301,7 +1301,7 @@ pub struct MethodAliasDefinition { comments: Vec, lexical_nesting_id: Option, } -assert_mem_size!(MethodAliasDefinition, 80); +assert_mem_size!(MethodAliasDefinition, 56); impl MethodAliasDefinition { #[must_use] @@ -1382,7 +1382,7 @@ pub struct GlobalVariableAliasDefinition { comments: Vec, lexical_nesting_id: Option, } -assert_mem_size!(GlobalVariableAliasDefinition, 80); +assert_mem_size!(GlobalVariableAliasDefinition, 56); impl GlobalVariableAliasDefinition { #[must_use] diff --git a/rust/rubydex/src/model/id.rs b/rust/rubydex/src/model/id.rs index 6de084bb5..0201be37a 100644 --- a/rust/rubydex/src/model/id.rs +++ b/rust/rubydex/src/model/id.rs @@ -1,26 +1,20 @@ -//! This module contains stable ID representations that compose the `Graph` global representation - use std::{ hash::{Hash, Hasher}, marker::PhantomData, ops::Deref, }; -use xxhash_rust::xxh3::xxh3_64; +use xxhash_rust::xxh32; -/// A stable ID representation using i64. -/// -/// We use i64 instead of u64 because `SQLite` doesn't support unsigned integers. -/// IDs are generated from `xxh3_64` hashes (u64) then cast to i64, preserving all bits. -/// Negative values are expected and normal - not a sign of memory corruption. +/// A deterministic type-safe ID representation #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Id { - value: i64, + value: u32, _marker: PhantomData, } impl Id { #[must_use] - pub fn new(value: i64) -> Self { + pub fn new(value: u32) -> Self { Self { value, _marker: PhantomData, @@ -29,7 +23,7 @@ impl Id { } impl Deref for Id { - type Target = i64; + type Target = u32; fn deref(&self) -> &Self::Target { &self.value @@ -44,21 +38,21 @@ impl std::fmt::Display for Id { impl Hash for Id { fn hash(&self, state: &mut H) { - state.write_i64(self.value); + state.write_u32(self.value); } } impl From<&str> for Id { fn from(value: &str) -> Self { - let hash = xxh3_64(value.as_bytes()); - Self::new(hash.cast_signed()) + let hash = xxh32::xxh32(value.as_bytes(), 0); + Self::new(hash) } } impl From<&String> for Id { fn from(value: &String) -> Self { - let hash = xxh3_64(value.as_bytes()); - Self::new(hash.cast_signed()) + let hash = xxh32::xxh32(value.as_bytes(), 0); + Self::new(hash) } } diff --git a/rust/rubydex/src/model/identity_maps.rs b/rust/rubydex/src/model/identity_maps.rs index 414c0cdbd..a82e3f109 100644 --- a/rust/rubydex/src/model/identity_maps.rs +++ b/rust/rubydex/src/model/identity_maps.rs @@ -16,6 +16,10 @@ impl Hasher for IdentityHasher { unreachable!("IdentityHasher only supports write_u64"); } + fn write_u32(&mut self, i: u32) { + self.hash = u64::from(i); + } + fn write_u64(&mut self, i: u64) { self.hash = i; } diff --git a/rust/rubydex/src/model/ids.rs b/rust/rubydex/src/model/ids.rs index e6d89a1a6..30df3a36e 100644 --- a/rust/rubydex/src/model/ids.rs +++ b/rust/rubydex/src/model/ids.rs @@ -9,29 +9,29 @@ pub type DeclarationId = Id; pub struct DefinitionMarker; // DefinitionId represents the ID of a definition found in a specific file pub type DefinitionId = Id; -assert_mem_size!(DefinitionId, 8); +assert_mem_size!(DefinitionId, 4); #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct UriMarker; // UriId represents the ID of a URI, which is the unique identifier for a document pub type UriId = Id; -assert_mem_size!(UriId, 8); +assert_mem_size!(UriId, 4); #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct StringMarker; /// `StringId` represents an ID for an interned string value pub type StringId = Id; -assert_mem_size!(StringId, 8); +assert_mem_size!(StringId, 4); #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct ReferenceMarker; /// `ReferenceId` represents the ID of a reference occurrence in a file. /// It is built from the reference kind, `uri_id` and the reference `offset`. pub type ReferenceId = Id; -assert_mem_size!(ReferenceId, 8); +assert_mem_size!(ReferenceId, 4); #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct NameMarker; /// `NameId` represents an ID for any constant name that we find as part of a reference or definition pub type NameId = Id; -assert_mem_size!(NameId, 8); +assert_mem_size!(NameId, 4); diff --git a/rust/rubydex/src/model/name.rs b/rust/rubydex/src/model/name.rs index b017d9d5f..8f5d264bf 100644 --- a/rust/rubydex/src/model/name.rs +++ b/rust/rubydex/src/model/name.rs @@ -14,7 +14,7 @@ pub enum ParentScope { /// There's a parent scope in this reference (e.g.: `Foo::Bar`) Some(NameId), } -assert_mem_size!(ParentScope, 16); +assert_mem_size!(ParentScope, 8); impl ParentScope { pub fn map_or(&self, default: T, f: F) -> T @@ -84,7 +84,7 @@ pub struct Name { nesting: Option, ref_count: u32, } -assert_mem_size!(Name, 48); +assert_mem_size!(Name, 24); impl Name { #[must_use] diff --git a/rust/rubydex/src/resolution.rs b/rust/rubydex/src/resolution.rs index 5f4808cd0..a03452745 100644 --- a/rust/rubydex/src/resolution.rs +++ b/rust/rubydex/src/resolution.rs @@ -1800,7 +1800,7 @@ mod tests { assert_eq!( [ - "Top", "Foo", "Qux", "Bar", "AfterTop", "Baz", "Zip", "Zap", "Zop", "Boop" + "Top", "Foo", "Bar", "AfterTop", "Qux", "Baz", "Zip", "Zap", "Zop", "Boop" ], names .iter() From 24aca6a835bc45f2c8078e8a1c99c30c53090db8 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 29 Jan 2026 15:48:15 -0500 Subject: [PATCH 2/3] Allow definition and reference IDs to be tagged --- rust/rubydex/src/model/definitions.rs | 109 ++++++++++++++++++++++---- rust/rubydex/src/model/id.rs | 29 +++++++ rust/rubydex/src/model/ids.rs | 35 ++++++++- rust/rubydex/src/model/references.rs | 47 ++++++++--- 4 files changed, 190 insertions(+), 30 deletions(-) diff --git a/rust/rubydex/src/model/definitions.rs b/rust/rubydex/src/model/definitions.rs index 1e5a8b1e4..4e0cc091a 100644 --- a/rust/rubydex/src/model/definitions.rs +++ b/rust/rubydex/src/model/definitions.rs @@ -49,6 +49,53 @@ impl DefinitionFlags { } } +#[repr(u8)] +#[derive(PartialEq, Debug)] +pub enum DefinitionKind { + Class = 0, + SingletonClass = 1, + Module = 2, + Constant = 3, + ConstantAlias = 4, + Method = 5, + AttrAccessor = 6, + AttrReader = 7, + AttrWriter = 8, + GlobalVariable = 9, + InstanceVariable = 10, + ClassVariable = 11, + MethodAlias = 12, + GlobalVariableAlias = 13, +} + +impl From for DefinitionKind { + fn from(value: u8) -> Self { + match value { + 0 => DefinitionKind::Class, + 1 => DefinitionKind::SingletonClass, + 2 => DefinitionKind::Module, + 3 => DefinitionKind::Constant, + 4 => DefinitionKind::ConstantAlias, + 5 => DefinitionKind::Method, + 6 => DefinitionKind::AttrAccessor, + 7 => DefinitionKind::AttrReader, + 8 => DefinitionKind::AttrWriter, + 9 => DefinitionKind::GlobalVariable, + 10 => DefinitionKind::InstanceVariable, + 11 => DefinitionKind::ClassVariable, + 12 => DefinitionKind::MethodAlias, + 13 => DefinitionKind::GlobalVariableAlias, + _ => panic!("Invalid DefinitionKind value: {value}"), + } + } +} + +impl From for u8 { + fn from(kind: DefinitionKind) -> Self { + kind as u8 + } +} + #[derive(Debug)] pub enum Definition { Class(Box), @@ -260,7 +307,9 @@ impl ClassDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)); + id.tag_kind(DefinitionKind::Class); + id } #[must_use] @@ -382,7 +431,9 @@ impl SingletonClassDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)); + id.tag_kind(DefinitionKind::SingletonClass); + id } #[must_use] @@ -486,7 +537,9 @@ impl ModuleDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)); + id.tag_kind(DefinitionKind::Module); + id } #[must_use] @@ -582,7 +635,9 @@ impl ConstantDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.name_id)); + id.tag_kind(DefinitionKind::Constant); + id } #[must_use] @@ -641,13 +696,15 @@ impl ConstantAliasDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!( + let mut id = DefinitionId::from(&format!( "{}{}{}{}", *self.alias_constant.uri_id(), self.alias_constant.offset().start(), *self.alias_constant.name_id(), *self.target_name_id, - )) + )); + id.tag_kind(DefinitionKind::ConstantAlias); + id } #[must_use] @@ -742,7 +799,9 @@ impl MethodDefinition { formatted_id.push_str(&receiver.to_string()); } - DefinitionId::from(&formatted_id) + let mut id = DefinitionId::from(&formatted_id); + id.tag_kind(DefinitionKind::Method); + id } #[must_use] @@ -871,7 +930,9 @@ impl AttrAccessorDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)); + id.tag_kind(DefinitionKind::AttrAccessor); + id } #[must_use] @@ -952,7 +1013,9 @@ impl AttrReaderDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)); + id.tag_kind(DefinitionKind::AttrReader); + id } #[must_use] @@ -1033,7 +1096,9 @@ impl AttrWriterDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)); + id.tag_kind(DefinitionKind::AttrWriter); + id } #[must_use] @@ -1111,7 +1176,9 @@ impl GlobalVariableDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)); + id.tag_kind(DefinitionKind::GlobalVariable); + id } #[must_use] @@ -1184,7 +1251,9 @@ impl InstanceVariableDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)); + id.tag_kind(DefinitionKind::InstanceVariable); + id } #[must_use] @@ -1257,7 +1326,9 @@ impl ClassVariableDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)) + let mut id = DefinitionId::from(&format!("{}{}{}", *self.uri_id, self.offset.start(), *self.str_id)); + id.tag_kind(DefinitionKind::ClassVariable); + id } #[must_use] @@ -1327,13 +1398,15 @@ impl MethodAliasDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!( + let mut id = DefinitionId::from(&format!( "{}{}{}{}", *self.uri_id, self.offset.start(), *self.new_name_str_id, *self.old_name_str_id, - )) + )); + id.tag_kind(DefinitionKind::MethodAlias); + id } #[must_use] @@ -1408,13 +1481,15 @@ impl GlobalVariableAliasDefinition { #[must_use] pub fn id(&self) -> DefinitionId { - DefinitionId::from(&format!( + let mut id = DefinitionId::from(&format!( "{}{}{}{}", *self.uri_id, self.offset.start(), *self.new_name_str_id, *self.old_name_str_id, - )) + )); + id.tag_kind(DefinitionKind::GlobalVariableAlias); + id } #[must_use] diff --git a/rust/rubydex/src/model/id.rs b/rust/rubydex/src/model/id.rs index 0201be37a..524b07c6e 100644 --- a/rust/rubydex/src/model/id.rs +++ b/rust/rubydex/src/model/id.rs @@ -5,6 +5,24 @@ use std::{ }; use xxhash_rust::xxh32; +const TAG_BITS: u32 = 4; +const TAG_MASK: u32 = (1 << TAG_BITS) - 1; + +pub trait Taggable { + type Kind: Into + From; +} + +impl Id { + pub fn tag_kind(&mut self, kind: T::Kind) { + self.value = (self.value & !TAG_MASK) | u32::from(kind.into()); + } + + #[must_use] + pub fn kind(&self) -> T::Kind { + ((self.value & TAG_MASK) as u8).into() + } +} + /// A deterministic type-safe ID representation #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Id { @@ -62,6 +80,9 @@ mod tests { #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct Marker; + impl Taggable for Marker { + type Kind = u8; + } pub type TestId = Id; #[test] @@ -81,4 +102,12 @@ mod tests { let id = TestId::new(123); assert_eq!(*id, 123); } + + #[test] + fn tagging_preserves_higher_bits() { + let mut id = TestId::new(0x1234_1234); + id.tag_kind(0b0000_1111); + assert_eq!(*id, 0x1234_123F); + assert_eq!(id.kind(), 0b0000_1111); + } } diff --git a/rust/rubydex/src/model/ids.rs b/rust/rubydex/src/model/ids.rs index 30df3a36e..2439fe281 100644 --- a/rust/rubydex/src/model/ids.rs +++ b/rust/rubydex/src/model/ids.rs @@ -1,4 +1,11 @@ -use crate::{assert_mem_size, model::id::Id}; +use crate::{ + assert_mem_size, + model::{ + definitions::DefinitionKind, + id::{Id, Taggable}, + references::ReferenceKind, + }, +}; #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct DeclarationMarker; @@ -7,6 +14,10 @@ pub type DeclarationId = Id; #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct DefinitionMarker; +impl Taggable for DefinitionMarker { + type Kind = DefinitionKind; +} + // DefinitionId represents the ID of a definition found in a specific file pub type DefinitionId = Id; assert_mem_size!(DefinitionId, 4); @@ -25,6 +36,9 @@ assert_mem_size!(StringId, 4); #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub struct ReferenceMarker; +impl Taggable for ReferenceMarker { + type Kind = ReferenceKind; +} /// `ReferenceId` represents the ID of a reference occurrence in a file. /// It is built from the reference kind, `uri_id` and the reference `offset`. pub type ReferenceId = Id; @@ -35,3 +49,22 @@ pub struct NameMarker; /// `NameId` represents an ID for any constant name that we find as part of a reference or definition pub type NameId = Id; assert_mem_size!(NameId, 4); + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn definition_ids_can_be_tagged() { + let mut id = DefinitionId::from("some_input"); + id.tag_kind(DefinitionKind::Class); + assert_eq!(DefinitionKind::Class, id.kind()); + } + + #[test] + fn reference_ids_can_be_tagged() { + let mut id = ReferenceId::from("some_input"); + id.tag_kind(ReferenceKind::Constant); + assert_eq!(ReferenceKind::Constant, id.kind()); + } +} diff --git a/rust/rubydex/src/model/references.rs b/rust/rubydex/src/model/references.rs index ff1499121..06833f4ae 100644 --- a/rust/rubydex/src/model/references.rs +++ b/rust/rubydex/src/model/references.rs @@ -4,6 +4,29 @@ use crate::{ offset::Offset, }; +#[repr(u8)] +#[derive(PartialEq, Debug)] +pub enum ReferenceKind { + Constant = 0, + Method = 1, +} + +impl From for ReferenceKind { + fn from(value: u8) -> Self { + match value { + 0 => ReferenceKind::Constant, + 1 => ReferenceKind::Method, + _ => panic!("Invalid ReferenceKind value: {value}"), + } + } +} + +impl From for u8 { + fn from(kind: ReferenceKind) -> Self { + kind as u8 + } +} + /// A reference to a constant #[derive(Debug)] pub struct ConstantReference { @@ -14,7 +37,7 @@ pub struct ConstantReference { /// The offsets inside of the document where we found the reference offset: Offset, } -assert_mem_size!(ConstantReference, 24); +assert_mem_size!(ConstantReference, 16); impl ConstantReference { #[must_use] @@ -43,15 +66,15 @@ impl ConstantReference { #[must_use] pub fn id(&self) -> ReferenceId { - // C::- - let key = format!( - "C:{}:{}:{}-{}", + let mut id = ReferenceId::from(&format!( + "{}:{}:{}-{}", self.name_id, self.uri_id, self.offset.start(), self.offset.end() - ); - ReferenceId::from(&key) + )); + id.tag_kind(ReferenceKind::Constant); + id } } @@ -67,7 +90,7 @@ pub struct MethodRef { /// The receiver of the method call if it's a constant receiver: Option, } -assert_mem_size!(MethodRef, 40); +assert_mem_size!(MethodRef, 24); impl MethodRef { #[must_use] @@ -102,14 +125,14 @@ impl MethodRef { #[must_use] pub fn id(&self) -> ReferenceId { - // M::- - let key = format!( - "M:{}:{}:{}-{}", + let mut id = ReferenceId::from(&format!( + "{}:{}:{}-{}", self.str, self.uri_id, self.offset.start(), self.offset.end() - ); - ReferenceId::from(&key) + )); + id.tag_kind(ReferenceKind::Method); + id } } From f4869941783cb3a75c1bee6cac2d2e2b57b1975b Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 29 Jan 2026 16:01:40 -0500 Subject: [PATCH 3/3] Adjust C side for u32 IDs --- ext/rubydex/declaration.c | 12 ++++++------ ext/rubydex/document.c | 4 ++-- ext/rubydex/graph.c | 28 ++++++++++++++-------------- ext/rubydex/handle.h | 4 ++-- rust/rubydex-sys/src/utils.rs | 4 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ext/rubydex/declaration.c b/ext/rubydex/declaration.c index 97ed09901..000ef0a1b 100644 --- a/ext/rubydex/declaration.c +++ b/ext/rubydex/declaration.c @@ -52,10 +52,10 @@ static VALUE declaration_definitions_yield(VALUE args) { HandleData *data; TypedData_Get_Struct(self, HandleData, &handle_type, data); - int64_t id = 0; + uint32_t id = 0; DefinitionKind kind; while (rdx_definitions_iter_next(iter, &id, &kind)) { - VALUE argv[] = {data->graph_obj, LL2NUM(id)}; + VALUE argv[] = {data->graph_obj, UINT2NUM(id)}; VALUE defn_class = rdxi_definition_class_for_kind(kind); VALUE handle = rb_class_new_instance(2, argv, defn_class); rb_yield(handle); @@ -120,14 +120,14 @@ static VALUE rdxr_declaration_member(VALUE self, VALUE name) { rb_raise(rb_eTypeError, "expected String"); } - const int64_t *id_ptr = rdx_declaration_member(graph, data->id, StringValueCStr(name)); + const uint32_t *id_ptr = rdx_declaration_member(graph, data->id, StringValueCStr(name)); if (id_ptr == NULL) { return Qnil; } - int64_t id = *id_ptr; - free_i64(id_ptr); - VALUE argv[] = {data->graph_obj, LL2NUM(id)}; + uint32_t id = *id_ptr; + free_u32(id_ptr); + VALUE argv[] = {data->graph_obj, UINT2NUM(id)}; return rb_class_new_instance(2, argv, cDeclaration); } diff --git a/ext/rubydex/document.c b/ext/rubydex/document.c index 9f5b31d0a..bd48d3e56 100644 --- a/ext/rubydex/document.c +++ b/ext/rubydex/document.c @@ -33,10 +33,10 @@ static VALUE document_definitions_yield(VALUE args) { HandleData *data; TypedData_Get_Struct(self, HandleData, &handle_type, data); - int64_t id = 0; + uint32_t id = 0; DefinitionKind kind; while (rdx_definitions_iter_next(iter, &id, &kind)) { - VALUE argv[] = {data->graph_obj, LL2NUM(id)}; + VALUE argv[] = {data->graph_obj, UINT2NUM(id)}; VALUE defn_class = rdxi_definition_class_for_kind(kind); VALUE handle = rb_class_new_instance(2, argv, defn_class); rb_yield(handle); diff --git a/ext/rubydex/graph.c b/ext/rubydex/graph.c index c1ff639d8..2559a406b 100644 --- a/ext/rubydex/graph.c +++ b/ext/rubydex/graph.c @@ -63,9 +63,9 @@ static VALUE graph_declarations_yield(VALUE args) { VALUE self = rb_ary_entry(args, 0); void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1)); - int64_t id = 0; + uint32_t id = 0; while (rdx_graph_declarations_iter_next(iter, &id)) { - VALUE argv[] = {self, LL2NUM(id)}; + VALUE argv[] = {self, UINT2NUM(id)}; VALUE handle = rb_class_new_instance(2, argv, cDeclaration); rb_yield(handle); } @@ -141,9 +141,9 @@ static VALUE graph_documents_yield(VALUE args) { VALUE self = rb_ary_entry(args, 0); void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1)); - int64_t id = 0; + uint32_t id = 0; while (rdx_graph_documents_iter_next(iter, &id)) { - VALUE argv[] = {self, LL2NUM(id)}; + VALUE argv[] = {self, UINT2NUM(id)}; VALUE handle = rb_class_new_instance(2, argv, cDocument); rb_yield(handle); } @@ -198,14 +198,14 @@ static VALUE rdxr_graph_aref(VALUE self, VALUE key) { rb_raise(rb_eTypeError, "expected String"); } - const int64_t *id_ptr = rdx_graph_get_declaration(graph, StringValueCStr(key)); + const uint32_t *id_ptr = rdx_graph_get_declaration(graph, StringValueCStr(key)); if (id_ptr == NULL) { return Qnil; } - int64_t id = *id_ptr; - free_i64(id_ptr); - VALUE argv[] = {self, LL2NUM(id)}; + uint32_t id = *id_ptr; + free_u32(id_ptr); + VALUE argv[] = {self, UINT2NUM(id)}; return rb_class_new_instance(2, argv, cDeclaration); } @@ -215,11 +215,11 @@ static VALUE graph_references_yield(VALUE args) { VALUE self = rb_ary_entry(args, 0); void *iter = (void *)(uintptr_t)NUM2ULL(rb_ary_entry(args, 1)); - int64_t id = 0; + uint32_t id = 0; ReferenceKind kind; while (rdx_references_iter_next(iter, &id, &kind)) { VALUE ref_class = rdxi_reference_class_for_kind(kind); - VALUE argv[] = {self, LL2NUM(id)}; + VALUE argv[] = {self, UINT2NUM(id)}; VALUE obj = rb_class_new_instance(2, argv, ref_class); rb_yield(obj); } @@ -333,7 +333,7 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes void *graph; TypedData_Get_Struct(self, void *, &graph_type, graph); - const int64_t *id_ptr = + const uint32_t *id_ptr = rdx_graph_resolve_constant(graph, StringValueCStr(const_name), (const char **)converted_file_paths, length); for (size_t i = 0; i < length; i++) { @@ -345,9 +345,9 @@ static VALUE rdxr_graph_resolve_constant(VALUE self, VALUE const_name, VALUE nes return Qnil; } - int64_t id = *id_ptr; - free_i64(id_ptr); - VALUE argv[] = {self, LL2NUM(id)}; + uint32_t id = *id_ptr; + free_u32(id_ptr); + VALUE argv[] = {self, UINT2NUM(id)}; return rb_class_new_instance(2, argv, cDeclaration); } diff --git a/ext/rubydex/handle.h b/ext/rubydex/handle.h index 57caaaad3..8b0a568ba 100644 --- a/ext/rubydex/handle.h +++ b/ext/rubydex/handle.h @@ -5,7 +5,7 @@ typedef struct { VALUE graph_obj; // Ruby Graph object to keep it alive - int64_t id; // Canonical ID (i64) mapping to a DeclarationId, DefinitionId, UriId, etc. See `ids.rs`. + uint32_t id; // Canonical ID mapping to a DeclarationId, DefinitionId, UriId, etc. See `ids.rs`. } HandleData; static void handle_mark(void *ptr) { @@ -36,7 +36,7 @@ static VALUE rdxr_handle_initialize(VALUE self, VALUE graph_obj, VALUE id_val) { HandleData *data; TypedData_Get_Struct(self, HandleData, &handle_type, data); data->graph_obj = graph_obj; - data->id = NUM2LL(id_val); + data->id = NUM2UINT(id_val); return self; } diff --git a/rust/rubydex-sys/src/utils.rs b/rust/rubydex-sys/src/utils.rs index 80a192825..e5cf96ba3 100644 --- a/rust/rubydex-sys/src/utils.rs +++ b/rust/rubydex-sys/src/utils.rs @@ -41,9 +41,9 @@ pub extern "C" fn free_c_string(ptr: *const c_char) { } } -/// Frees a boxed i64 allocated on the Rust side +/// Frees a boxed u32 allocated on the Rust side #[unsafe(no_mangle)] -pub extern "C" fn free_i64(ptr: *const i64) { +pub extern "C" fn free_u32(ptr: *const u32) { unsafe { let _ = Box::from_raw(ptr.cast_mut()); }