Conversation
- Rename ParameterKind variants to full names (e.g. Req -> RequiredPositional) - Merge two let-else bindings into one in rdx_definition_signatures - Make collect_method_signatures private - Change Signature#initialize from keyword arguments to positional arguments Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
79877ae to
39084db
Compare
ext/rubydex/signature.c
Outdated
| } | ||
|
|
||
| VALUE rdxi_signatures_to_ruby(SignatureArray *arr, VALUE graph_obj, VALUE default_method_def) { | ||
| if (arr == NULL || arr->len == 0) { |
There was a problem hiding this comment.
How about we raise in rdxr_method_definition_signatures and rdxr_method_alias_definition_signatures if the pointer is NULL?
This should never really happen, so I'm trying to avoid having it fail silently.
There was a problem hiding this comment.
Yeah, I think the design is weird. Will take a look at this tonight.
There was a problem hiding this comment.
Fixed the implementation. rdx_method_definition_signatures and rdx_method_alias_definition_signatures always return an array. rdxi_signatures_to_ruby can safely skips checking if arr is NULL.
| let mut boxed = sig_entries.into_boxed_slice(); | ||
| let len = boxed.len(); | ||
| let items_ptr = boxed.as_mut_ptr(); | ||
| std::mem::forget(boxed); |
There was a problem hiding this comment.
Do we need to forget here if we're ultimately passing this to Box::into_raw?
There was a problem hiding this comment.
If we don't use forget, the contents of the Box will be deallocated by the destructor.
We could use Box::into_raw instead, but I don't think it's worth the rewrite since the mem::forget pattern is already used elsewhere in the codebase.
let items_ptr = Box::into_raw(boxed) as *mut SignatureEntry;
ext/rubydex/signature.c
Outdated
| ParameterEntry param_entry = sig_entry.parameters[j]; | ||
|
|
||
| VALUE param_class = parameter_class_for_kind(param_entry.kind); | ||
| VALUE name_sym = ID2SYM(rb_intern(param_entry.name)); |
There was a problem hiding this comment.
Does rb_intern make a copy of the string we pass? I'm asking because we free the signature array object further below. If Ruby interning just keeps a pointer, it could lead to a seg fault.
There was a problem hiding this comment.
I believe rb_intern copies the string, but I couldn't find any documentation that explicitly says so. Changed to rb_str_intern with rb_utf8_str_new_cstr, which creates dynamic symbols (subject to GC) from a copied C string.
| /// | ||
| /// Panics if the definition or its document does not exist. | ||
| #[must_use] | ||
| pub fn source_at(&self, definition_id: &DefinitionId) -> &str { |
There was a problem hiding this comment.
I think we can move this to Offset and pass the document as we do with https://github.com/Shopify/rubydex/blob/main/rust/rubydex/src/offset.rs#L90-L103
b33e8c6 to
e0b3e8a
Compare
| } | ||
|
|
||
| /// Returns a newly allocated array of signatures for the given method definition id. | ||
| /// Returns NULL if the definition is not a method definition. |
| end | ||
| end | ||
|
|
||
| def test_method_definition_signatures_with_various_parameter_kinds |
There was a problem hiding this comment.
Can we include test cases for singleton methods?
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
eef4e19 to
aeeebb3
Compare
Summary
MethodDefinition#signatures, returning an array ofRubydex::SignatureobjectsSignatureholds an array of typedParametersubclasses (PositionalParameter,KeywordParameter, etc.) withnameandlocationattributesParameterKind,SignatureEntry,SignatureArray) and C extension glue for conversionExtracted from #686.
Test plan
🤖 Generated with Claude Code