Add semantic contexts for Swift, Kotlin, PHP, Rust, and Go - #1015
Conversation
safishamsi
left a comment
There was a problem hiding this comment.
Thanks for the PR — the design is solid and the test coverage is strong across all five languages. One issue before merge: there's a latent crash in the Go method_declaration block where emit_go_method_refs(...) appears to be outside the if name_node: guard. If name_node is None, method_nid will be undefined and you'll get an UnboundLocalError. Tests pass currently only because fixtures always have a name node. Could you fix the indentation and open a fresh PR against v8?
|
Thanks for the PR — the design is solid and the test coverage is strong across all five languages. One issue before merge: there's a latent crash in the Go |
|
@safishamsi I redid the test and indent looked right. Re-pushed the changes with a proof. I think it's getting really unwieldy with the current line-count for both manual and AI-driven reviews. Can I do some refactoring of the methods so they are more sustainable in this? I was hesitant of doing this in the middle of adding the functionality to unblock some of the stuff I needed from |
|
Fetched the branch and checked line 4719 directly: ``` The bug is still there. The structural test missed it because it inspects the AST of the source file but the reference to The fix is a single 4-space indent on line 4719: ```python On the refactoring question — once this is fixed and merged, a follow-up PR for internal refactoring of the Go extractor methods is welcome, just keep it separate from the new functionality. |
|
When I changed the indent like you mentioned I saw the errors like so: So it's definitely wasn't a fix here. |
Summary
Second wave of the cross-language semantic extractor (after #996). Brings the same vocabulary to Swift,
Kotlin, PHP, Rust, and Go: normalized type-relationship edges and
referencesedges withparameter_type/return_type/generic_arg/field/attributecontexts.Storage is unchanged —
graph.jsonsimply carries more source-backed edges.What changed
protocol_declarationvs class/struct/enum/actor declarations to classify eachinheritance_specifierasinherits(class supertype) orimplements(protocol / extensionconformance).
protocol P: Qemitsinherits. Methodparameterandreturn_type, plusproperty_declarationannotations, emitreferenceswith the standard contexts.delegation_specifierintoinherits(constructor_invocation) vsimplements(plain
user_type). Functionfunction_value_parametersand post-colon return types emitreferences;property_declarationtypes emitfield.base_clause→inherits,class_interface_clause→implements,use Trait→mixes_in. Typed properties, simple parameters, and post-)return types emitreferences. Also fixesthe event-listener
property_declarationhandler to only short-circuit when it actually matched a$listen/$subscribeproperty — non-listener typed properties were previously dropped.impl Trait for TemitsT implements Trait. Supertraits ontrait_itemviatrait_boundsemitinherits. Structfield_declarationtypes emitreferences field;function_itemparameters and return types emitparameter_type/return_type, with genericarguments emitted as
generic_arg.field_declarationwithout afield_identifier(the Go embedded-field syntax) emitsembeds; named fields emitreferences field. Interfacetype_elementries emitembeds(interfaceembedding).
method_declaration/function_declarationparameters andresult(handling bothsingle-type and
parameter_listforms) emitparameter_type/return_type.Fixture changes
tests/fixtures/sample.swift: addsBaseProcessorclass,Result<T>, acurrent: Result<DataProcessor>property, and arun(input: DataProcessor) -> Result<DataProcessor>method.tests/fixtures/sample.kt: addsLoggableinterface,BaseProcessoropen class,Result<T>, aDataProcessor : BaseProcessor(), Loggablethat overrideslog(), acurrent: Result<DataProcessor>property, and a
runmethod.tests/fixtures/sample.php: addsLoggableinterface,HasNametrait,BaseProcessor,Result,and a
DataProcessor extends BaseProcessor implements Loggablewithuse HasName;, aprivate Result $current;field, and arun(DataProcessor $input): Resultmethod.tests/fixtures/sample.rs: addsProcessor/Logger: Processortraits,Result<T>, aDataProcessorstruct with aResult<DataProcessor>field, animpl Processor for DataProcessor, anda
build(input: DataProcessor) -> Result<DataProcessor>method.tests/fixtures/sample.go: addsLogger/Readerinterfaces, aReaderLoggerthat embeds both,BaseProcessor,Result, and aDataProcessorthat embedsBaseProcessorwith a*Resultfield plusa
Build(input *DataProcessor) (*Result, error)method.These fixture additions keep all pre-existing per-language assertions intact. The Swift
test_swift_conformance_edge/test_swift_extension_conformance_edgetests are renamed totest_swift_protocol_conformance_emits_implements/test_swift_extension_conformance_emits_implementsand now assert
implementsto match the new split.Tests
Full pytest suite: 1294 passed, 11 skipped.
New tests:
test_swift_protocol_conformance_emits_implementstest_swift_extension_conformance_emits_implementstest_swift_splits_inherits_and_implementstest_swift_parameter_return_generic_and_field_contextstest_kotlin_splits_inherits_and_implementstest_kotlin_parameter_return_generic_and_field_contextstest_php_splits_inherits_implements_mixes_intest_php_property_parameter_and_return_contextstest_rust_trait_impl_emits_implementstest_rust_supertrait_emits_inheritstest_rust_struct_field_emits_field_contexttest_rust_method_parameter_return_and_generic_contextstest_go_embeds_struct_fieldtest_go_interface_embedding_emits_embedstest_go_struct_named_field_emits_field_contexttest_go_method_parameter_return_contextsCompatibility note
Swift
inheritsedges for protocol conformance are nowimplements. This matches the Java migrationapplied in #996 and the C# split that also landed in PR 1 — protocols / interfaces / traits are
uniformly modeled as
implements, class supertyping asinherits. Existing call/contains/method/importedges and node IDs are unchanged.
Non-goals