rubydex 0.1.0.beta1-x86_64-linux → 0.1.0.beta2-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rubydex/declaration.c +146 -0
  3. data/ext/rubydex/declaration.h +10 -0
  4. data/ext/rubydex/definition.c +234 -0
  5. data/ext/rubydex/definition.h +28 -0
  6. data/ext/rubydex/diagnostic.c +6 -0
  7. data/ext/rubydex/diagnostic.h +11 -0
  8. data/ext/rubydex/document.c +98 -0
  9. data/ext/rubydex/document.h +10 -0
  10. data/ext/rubydex/extconf.rb +36 -15
  11. data/ext/rubydex/graph.c +405 -0
  12. data/ext/rubydex/graph.h +10 -0
  13. data/ext/rubydex/handle.h +44 -0
  14. data/ext/rubydex/location.c +22 -0
  15. data/ext/rubydex/location.h +15 -0
  16. data/ext/rubydex/reference.c +104 -0
  17. data/ext/rubydex/reference.h +16 -0
  18. data/ext/rubydex/rubydex.c +22 -0
  19. data/ext/rubydex/utils.c +27 -0
  20. data/ext/rubydex/utils.h +13 -0
  21. data/lib/rubydex/3.2/rubydex.so +0 -0
  22. data/lib/rubydex/3.3/rubydex.so +0 -0
  23. data/lib/rubydex/3.4/rubydex.so +0 -0
  24. data/lib/rubydex/4.0/rubydex.so +0 -0
  25. data/lib/rubydex/librubydex_sys.so +0 -0
  26. data/lib/rubydex/version.rb +1 -1
  27. data/rust/Cargo.lock +1275 -0
  28. data/rust/Cargo.toml +23 -0
  29. data/rust/about.hbs +78 -0
  30. data/rust/about.toml +9 -0
  31. data/rust/rubydex/Cargo.toml +41 -0
  32. data/rust/rubydex/src/diagnostic.rs +108 -0
  33. data/rust/rubydex/src/errors.rs +28 -0
  34. data/rust/rubydex/src/indexing/local_graph.rs +172 -0
  35. data/rust/rubydex/src/indexing/ruby_indexer.rs +5397 -0
  36. data/rust/rubydex/src/indexing.rs +128 -0
  37. data/rust/rubydex/src/job_queue.rs +186 -0
  38. data/rust/rubydex/src/lib.rs +15 -0
  39. data/rust/rubydex/src/listing.rs +249 -0
  40. data/rust/rubydex/src/main.rs +116 -0
  41. data/rust/rubydex/src/model/comment.rs +24 -0
  42. data/rust/rubydex/src/model/declaration.rs +541 -0
  43. data/rust/rubydex/src/model/definitions.rs +1475 -0
  44. data/rust/rubydex/src/model/document.rs +111 -0
  45. data/rust/rubydex/src/model/encoding.rs +22 -0
  46. data/rust/rubydex/src/model/graph.rs +1387 -0
  47. data/rust/rubydex/src/model/id.rs +90 -0
  48. data/rust/rubydex/src/model/identity_maps.rs +54 -0
  49. data/rust/rubydex/src/model/ids.rs +32 -0
  50. data/rust/rubydex/src/model/name.rs +188 -0
  51. data/rust/rubydex/src/model/references.rs +129 -0
  52. data/rust/rubydex/src/model/string_ref.rs +44 -0
  53. data/rust/rubydex/src/model/visibility.rs +41 -0
  54. data/rust/rubydex/src/model.rs +13 -0
  55. data/rust/rubydex/src/offset.rs +70 -0
  56. data/rust/rubydex/src/position.rs +6 -0
  57. data/rust/rubydex/src/query.rs +103 -0
  58. data/rust/rubydex/src/resolution.rs +4421 -0
  59. data/rust/rubydex/src/stats/memory.rs +71 -0
  60. data/rust/rubydex/src/stats/timer.rs +126 -0
  61. data/rust/rubydex/src/stats.rs +9 -0
  62. data/rust/rubydex/src/test_utils/context.rs +226 -0
  63. data/rust/rubydex/src/test_utils/graph_test.rs +229 -0
  64. data/rust/rubydex/src/test_utils/local_graph_test.rs +166 -0
  65. data/rust/rubydex/src/test_utils.rs +52 -0
  66. data/rust/rubydex/src/visualization/dot.rs +176 -0
  67. data/rust/rubydex/src/visualization.rs +6 -0
  68. data/rust/rubydex/tests/cli.rs +167 -0
  69. data/rust/rubydex-sys/Cargo.toml +20 -0
  70. data/rust/rubydex-sys/build.rs +14 -0
  71. data/rust/rubydex-sys/cbindgen.toml +12 -0
  72. data/rust/rubydex-sys/src/declaration_api.rs +114 -0
  73. data/rust/rubydex-sys/src/definition_api.rs +350 -0
  74. data/rust/rubydex-sys/src/diagnostic_api.rs +99 -0
  75. data/rust/rubydex-sys/src/document_api.rs +54 -0
  76. data/rust/rubydex-sys/src/graph_api.rs +493 -0
  77. data/rust/rubydex-sys/src/lib.rs +9 -0
  78. data/rust/rubydex-sys/src/location_api.rs +79 -0
  79. data/rust/rubydex-sys/src/name_api.rs +81 -0
  80. data/rust/rubydex-sys/src/reference_api.rs +191 -0
  81. data/rust/rubydex-sys/src/utils.rs +50 -0
  82. data/rust/rustfmt.toml +2 -0
  83. metadata +77 -2
@@ -0,0 +1,191 @@
1
+ //! C API for exposing references through ID handles (like definitions)
2
+
3
+ use std::ffi::CString;
4
+
5
+ use crate::graph_api::{GraphPointer, with_graph};
6
+ use crate::location_api::{Location, create_location_for_uri_and_offset};
7
+ use libc::c_char;
8
+ use rubydex::model::ids::ReferenceId;
9
+
10
+ /// Kind of reference for FFI dispatch
11
+ #[repr(C)]
12
+ #[derive(Copy, Clone, Debug, PartialEq, Eq)]
13
+ pub enum ReferenceKind {
14
+ Constant = 0,
15
+ Method = 1,
16
+ }
17
+
18
+ /// Shared iterator over reference (id, kind) pairs
19
+ #[derive(Debug)]
20
+ pub struct ReferencesIter {
21
+ pub entries: Box<[(i64, ReferenceKind)]>,
22
+ pub index: usize,
23
+ }
24
+
25
+ impl ReferencesIter {
26
+ #[must_use]
27
+ pub fn new(entries: Box<[(i64, ReferenceKind)]>) -> *mut ReferencesIter {
28
+ Box::into_raw(Box::new(ReferencesIter { entries, index: 0 }))
29
+ }
30
+ }
31
+
32
+ /// Returns the total number of entries in the iterator snapshot.
33
+ ///
34
+ /// # Safety
35
+ /// - `iter` must be a valid pointer previously returned by `ReferencesIter::new`.
36
+ #[unsafe(no_mangle)]
37
+ pub unsafe extern "C" fn rdx_references_iter_len(iter: *const ReferencesIter) -> usize {
38
+ if iter.is_null() {
39
+ return 0;
40
+ }
41
+ unsafe { (&*iter).entries.len() }
42
+ }
43
+
44
+ /// Advances the iterator and writes the next entry into the provided out params.
45
+ /// Returns `true` if an entry was written, or `false` if the iterator is exhausted or inputs are invalid.
46
+ ///
47
+ /// # Safety
48
+ /// - `iter` must be a valid pointer previously returned by `ReferencesIter::new`.
49
+ /// - `out_id` and `out_kind` must be valid, writable pointers.
50
+ ///
51
+ /// # Panics
52
+ /// - If the iterator is exhausted or inputs are invalid.
53
+ /// - If the name, URI, start, or end pointers are invalid.
54
+ #[unsafe(no_mangle)]
55
+ pub unsafe extern "C" fn rdx_references_iter_next(
56
+ iter: *mut ReferencesIter,
57
+ out_id: *mut i64,
58
+ out_kind: *mut ReferenceKind,
59
+ ) -> bool {
60
+ if iter.is_null() || out_id.is_null() || out_kind.is_null() {
61
+ return false;
62
+ }
63
+
64
+ let it = unsafe { &mut *iter };
65
+ if it.index >= it.entries.len() {
66
+ return false;
67
+ }
68
+
69
+ let (id, kind) = it.entries[it.index];
70
+ it.index += 1;
71
+ unsafe {
72
+ *out_id = id;
73
+ *out_kind = kind;
74
+ }
75
+ true
76
+ }
77
+
78
+ /// Frees an iterator created by `ReferencesIter::new`.
79
+ ///
80
+ /// # Safety
81
+ /// - `iter` must be a pointer previously returned by `ReferencesIter::new`.
82
+ /// - `iter` must not be used after being freed.
83
+ #[unsafe(no_mangle)]
84
+ pub unsafe extern "C" fn rdx_references_iter_free(iter: *mut ReferencesIter) {
85
+ if iter.is_null() {
86
+ return;
87
+ }
88
+ unsafe {
89
+ let _ = Box::from_raw(iter);
90
+ }
91
+ }
92
+
93
+ /// Returns the UTF-8 name string for a constant reference id.
94
+ /// Caller must free with `free_c_string`.
95
+ ///
96
+ /// # Safety
97
+ ///
98
+ /// Assumes pointer is valid.
99
+ ///
100
+ /// # Panics
101
+ ///
102
+ /// This function will panic if the reference cannot be found.
103
+ #[unsafe(no_mangle)]
104
+ pub unsafe extern "C" fn rdx_constant_reference_name(pointer: GraphPointer, reference_id: i64) -> *const c_char {
105
+ with_graph(pointer, |graph| {
106
+ let ref_id = ReferenceId::new(reference_id);
107
+ let reference = graph.constant_references().get(&ref_id).expect("Reference not found");
108
+ let name = graph.names().get(reference.name_id()).expect("Name ID should exist");
109
+
110
+ let name_string = graph
111
+ .strings()
112
+ .get(name.str())
113
+ .expect("String ID should exist")
114
+ .to_string();
115
+ CString::new(name_string).unwrap().into_raw().cast_const()
116
+ })
117
+ }
118
+
119
+ /// Returns the UTF-8 name string for a method reference id.
120
+ /// Caller must free with `free_c_string`.
121
+ ///
122
+ /// # Safety
123
+ ///
124
+ /// Assumes pointer is valid.
125
+ ///
126
+ /// # Panics
127
+ ///
128
+ /// This function will panic if the reference cannot be found.
129
+ #[unsafe(no_mangle)]
130
+ pub unsafe extern "C" fn rdx_method_reference_name(pointer: GraphPointer, reference_id: i64) -> *const c_char {
131
+ with_graph(pointer, |graph| {
132
+ let ref_id = ReferenceId::new(reference_id);
133
+ let reference = graph.method_references().get(&ref_id).expect("Reference not found");
134
+ let name = graph
135
+ .strings()
136
+ .get(reference.str())
137
+ .expect("Name ID should exist")
138
+ .to_string();
139
+ CString::new(name).unwrap().into_raw().cast_const()
140
+ })
141
+ }
142
+
143
+ /// Returns a newly allocated `Location` for the given constant reference id.
144
+ /// Caller must free the returned pointer with `rdx_location_free`.
145
+ ///
146
+ /// # Safety
147
+ ///
148
+ /// - `pointer` must be a valid pointer previously returned by `rdx_graph_new`.
149
+ /// - `reference_id` must be a valid reference id.
150
+ ///
151
+ /// # Panics
152
+ ///
153
+ /// This function will panic if a reference or document cannot be found.
154
+ #[unsafe(no_mangle)]
155
+ pub unsafe extern "C" fn rdx_constant_reference_location(pointer: GraphPointer, reference_id: i64) -> *mut Location {
156
+ with_graph(pointer, |graph| {
157
+ let ref_id = ReferenceId::new(reference_id);
158
+ let reference = graph.constant_references().get(&ref_id).expect("Reference not found");
159
+ let document = graph
160
+ .documents()
161
+ .get(&reference.uri_id())
162
+ .expect("Document should exist");
163
+
164
+ create_location_for_uri_and_offset(graph, document, reference.offset())
165
+ })
166
+ }
167
+
168
+ /// Returns a newly allocated `Location` for the given method reference id.
169
+ /// Caller must free the returned pointer with `rdx_location_free`.
170
+ ///
171
+ /// # Safety
172
+ ///
173
+ /// - `pointer` must be a valid pointer previously returned by `rdx_graph_new`.
174
+ /// - `reference_id` must be a valid reference id.
175
+ ///
176
+ /// # Panics
177
+ ///
178
+ /// This function will panic if a reference or document cannot be found.
179
+ #[unsafe(no_mangle)]
180
+ pub unsafe extern "C" fn rdx_method_reference_location(pointer: GraphPointer, reference_id: i64) -> *mut Location {
181
+ with_graph(pointer, |graph| {
182
+ let ref_id = ReferenceId::new(reference_id);
183
+ let reference = graph.method_references().get(&ref_id).expect("Reference not found");
184
+ let document = graph
185
+ .documents()
186
+ .get(&reference.uri_id())
187
+ .expect("Document should exist");
188
+
189
+ create_location_for_uri_and_offset(graph, document, reference.offset())
190
+ })
191
+ }
@@ -0,0 +1,50 @@
1
+ use libc::{c_char, size_t};
2
+ use std::ffi::{CStr, CString};
3
+ use std::slice;
4
+ use std::str::Utf8Error;
5
+
6
+ /// Converts a C array of strings into a Vec<String>
7
+ ///
8
+ /// # Safety
9
+ ///
10
+ /// This function is unsafe because it attempts to instantiate a Vec<String> from a raw char** pointer
11
+ ///
12
+ /// # Errors
13
+ ///
14
+ /// This function errors if any of the strings inside the array contain invalid UTF-8 data
15
+ pub unsafe fn convert_double_pointer_to_vec(data: *const *const c_char, len: size_t) -> Result<Vec<String>, Utf8Error> {
16
+ unsafe {
17
+ slice::from_raw_parts(data, len)
18
+ .iter()
19
+ .map(|arg| CStr::from_ptr(*arg).to_str().map(ToString::to_string))
20
+ .collect()
21
+ }
22
+ }
23
+
24
+ /// # Safety
25
+ ///
26
+ /// This function is unsafe because it dereferences the char pointer, which needs to be valid for the duration of the
27
+ /// function
28
+ ///
29
+ /// # Errors
30
+ ///
31
+ /// This function errors if any of the strings inside the array contain invalid UTF-8 data
32
+ pub unsafe fn convert_char_ptr_to_string(data: *const c_char) -> Result<String, Utf8Error> {
33
+ unsafe { CStr::from_ptr(data).to_str().map(ToString::to_string) }
34
+ }
35
+
36
+ /// Frees a `CString` allocated on the Rust side
37
+ #[unsafe(no_mangle)]
38
+ pub extern "C" fn free_c_string(ptr: *const c_char) {
39
+ unsafe {
40
+ let _ = CString::from_raw(ptr.cast_mut());
41
+ }
42
+ }
43
+
44
+ /// Frees a boxed i64 allocated on the Rust side
45
+ #[unsafe(no_mangle)]
46
+ pub extern "C" fn free_i64(ptr: *const i64) {
47
+ unsafe {
48
+ let _ = Box::from_raw(ptr.cast_mut());
49
+ }
50
+ }
data/rust/rustfmt.toml ADDED
@@ -0,0 +1,2 @@
1
+ max_width = 120
2
+ edition = "2024"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta1
4
+ version: 0.1.0.beta2
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-01-21 00:00:00.000000000 Z
11
+ date: 2026-01-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A high performance static analysis suite for Ruby, built in Rust with
14
14
  Ruby APIs
@@ -23,7 +23,25 @@ files:
23
23
  - README.md
24
24
  - THIRD_PARTY_LICENSES.html
25
25
  - exe/rdx
26
+ - ext/rubydex/declaration.c
27
+ - ext/rubydex/declaration.h
28
+ - ext/rubydex/definition.c
29
+ - ext/rubydex/definition.h
30
+ - ext/rubydex/diagnostic.c
31
+ - ext/rubydex/diagnostic.h
32
+ - ext/rubydex/document.c
33
+ - ext/rubydex/document.h
26
34
  - ext/rubydex/extconf.rb
35
+ - ext/rubydex/graph.c
36
+ - ext/rubydex/graph.h
37
+ - ext/rubydex/handle.h
38
+ - ext/rubydex/location.c
39
+ - ext/rubydex/location.h
40
+ - ext/rubydex/reference.c
41
+ - ext/rubydex/reference.h
42
+ - ext/rubydex/rubydex.c
43
+ - ext/rubydex/utils.c
44
+ - ext/rubydex/utils.h
27
45
  - lib/rubydex.rb
28
46
  - lib/rubydex/3.2/rubydex.so
29
47
  - lib/rubydex/3.3/rubydex.so
@@ -32,8 +50,65 @@ files:
32
50
  - lib/rubydex/comment.rb
33
51
  - lib/rubydex/diagnostic.rb
34
52
  - lib/rubydex/graph.rb
53
+ - lib/rubydex/librubydex_sys.so
35
54
  - lib/rubydex/location.rb
36
55
  - lib/rubydex/version.rb
56
+ - rust/Cargo.lock
57
+ - rust/Cargo.toml
58
+ - rust/about.hbs
59
+ - rust/about.toml
60
+ - rust/rubydex-sys/Cargo.toml
61
+ - rust/rubydex-sys/build.rs
62
+ - rust/rubydex-sys/cbindgen.toml
63
+ - rust/rubydex-sys/src/declaration_api.rs
64
+ - rust/rubydex-sys/src/definition_api.rs
65
+ - rust/rubydex-sys/src/diagnostic_api.rs
66
+ - rust/rubydex-sys/src/document_api.rs
67
+ - rust/rubydex-sys/src/graph_api.rs
68
+ - rust/rubydex-sys/src/lib.rs
69
+ - rust/rubydex-sys/src/location_api.rs
70
+ - rust/rubydex-sys/src/name_api.rs
71
+ - rust/rubydex-sys/src/reference_api.rs
72
+ - rust/rubydex-sys/src/utils.rs
73
+ - rust/rubydex/Cargo.toml
74
+ - rust/rubydex/src/diagnostic.rs
75
+ - rust/rubydex/src/errors.rs
76
+ - rust/rubydex/src/indexing.rs
77
+ - rust/rubydex/src/indexing/local_graph.rs
78
+ - rust/rubydex/src/indexing/ruby_indexer.rs
79
+ - rust/rubydex/src/job_queue.rs
80
+ - rust/rubydex/src/lib.rs
81
+ - rust/rubydex/src/listing.rs
82
+ - rust/rubydex/src/main.rs
83
+ - rust/rubydex/src/model.rs
84
+ - rust/rubydex/src/model/comment.rs
85
+ - rust/rubydex/src/model/declaration.rs
86
+ - rust/rubydex/src/model/definitions.rs
87
+ - rust/rubydex/src/model/document.rs
88
+ - rust/rubydex/src/model/encoding.rs
89
+ - rust/rubydex/src/model/graph.rs
90
+ - rust/rubydex/src/model/id.rs
91
+ - rust/rubydex/src/model/identity_maps.rs
92
+ - rust/rubydex/src/model/ids.rs
93
+ - rust/rubydex/src/model/name.rs
94
+ - rust/rubydex/src/model/references.rs
95
+ - rust/rubydex/src/model/string_ref.rs
96
+ - rust/rubydex/src/model/visibility.rs
97
+ - rust/rubydex/src/offset.rs
98
+ - rust/rubydex/src/position.rs
99
+ - rust/rubydex/src/query.rs
100
+ - rust/rubydex/src/resolution.rs
101
+ - rust/rubydex/src/stats.rs
102
+ - rust/rubydex/src/stats/memory.rs
103
+ - rust/rubydex/src/stats/timer.rs
104
+ - rust/rubydex/src/test_utils.rs
105
+ - rust/rubydex/src/test_utils/context.rs
106
+ - rust/rubydex/src/test_utils/graph_test.rs
107
+ - rust/rubydex/src/test_utils/local_graph_test.rs
108
+ - rust/rubydex/src/visualization.rs
109
+ - rust/rubydex/src/visualization/dot.rs
110
+ - rust/rubydex/tests/cli.rs
111
+ - rust/rustfmt.toml
37
112
  homepage: https://github.com/Shopify/rubydex
38
113
  licenses:
39
114
  - MIT