Skip to content

Simplify Ast::find_element Functions - #811

Open
InsertCreativityHere wants to merge 2 commits into
icerpc:mainfrom
InsertCreativityHere:separate-primitive-lookups
Open

Simplify Ast::find_element Functions#811
InsertCreativityHere wants to merge 2 commits into
icerpc:mainfrom
InsertCreativityHere:separate-primitive-lookups

Conversation

@InsertCreativityHere

Copy link
Copy Markdown
Member

Currently, we have 4 functions on Ast for looking stuff up, 2 that return raw AST-nodes, and 2 that return references to Slice elements. This PR addresses the latter 2. This is a stepping stone towards fixing #806 and #808.

These 2 functions were named find_element and find_element_with_scope; the first took a fully-scoped ID, the 2nd works could take relative IDs. I deleted find_element_with_scope, since it was only called by vscode-slice, and there, we can fix the callers to manually append the scope and use find_element instead. And for find_element, I restricted the types it could be used to lookup.

Right now, you can lookup both primitive and user-defined types. After this PR, you can only use this function to lookup user-defined types. To signal this, I changed it's name from find_element to find_symbol_by_id.

Element is the base-most thing in slicec, everything is an Element, struct, Sequence, Identifier, Primitive.
Symbol is the compiler jargon term for something a user-wrote in a Slice file, so this term does not include the primitives.

What's Changed

  • The find_element and find_element_by_id functions were simplified and merged into a single find_symbol_by_id function. This can no longer be used to lookup primitive types.

@@ -546,10 +546,14 @@ mod underlying_type {
let ast = parse_for_ast(slice);

// Assert

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple test places were reworked slightly to keep everything under 120 and easily readable.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR streamlines AST element lookup APIs by removing the scope-resolving lookup and introducing a renamed, more constrained lookup method that targets user-defined symbols only (not primitives). It updates internal call sites, tests, and documentation to reflect the new API as a stepping stone toward #806 and #808 work.

Changes:

  • Replaced Ast::find_element / Ast::find_element_with_scope usage with Ast::find_symbol_by_id across the codebase and tests.
  • Removed the scope-based element lookup API and standardized callers on fully-qualified IDs.
  • Updated public-facing documentation (README + rustdoc) to reference the new method.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
slicec/src/ast/mod.rs Removes find_element_with_scope, renames/tightens element lookup to find_symbol_by_id (NamedSymbol-only) and updates rustdoc references.
slicec/src/slice_file_converter.rs Switches symbol lookup to find_symbol_by_id for named symbol conversion path.
slicec/src/diagnostics/annotated_diagnostic.rs Uses find_symbol_by_id for resolving diagnostic scopes to entities.
slicec/README.md Updates example AST lookup call to find_symbol_by_id.
slicec/tests/typealias_tests.rs Migrates lookups to find_symbol_by_id in type-alias tests.
slicec/tests/tag_tests.rs Migrates lookups to find_symbol_by_id in tag tests.
slicec/tests/structs/tags.rs Migrates struct field lookup to find_symbol_by_id.
slicec/tests/structs/container.rs Migrates struct lookup to find_symbol_by_id for container/fields assertions.
slicec/tests/sequence_tests.rs Migrates type-alias lookup to find_symbol_by_id for sequence tests.
slicec/tests/scope_resolution_tests.rs Migrates all field lookups to find_symbol_by_id in scope resolution tests.
slicec/tests/result_tests.rs Migrates operation lookup to find_symbol_by_id in result type tests.
slicec/tests/primitives/mod.rs Migrates type-alias lookup to find_symbol_by_id while still validating primitive patching behavior.
slicec/tests/preprocessor_tests.rs Migrates interface/struct/operation lookups to find_symbol_by_id in preprocessor tests.
slicec/tests/parser_tests.rs Migrates struct/enumerator lookups to find_symbol_by_id in parser tests.
slicec/tests/optional_tests.rs Migrates all member/parameter lookups to find_symbol_by_id in optional type tests.
slicec/tests/module_tests.rs Migrates module/struct lookups to find_symbol_by_id in module tests.
slicec/tests/interfaces/operations.rs Migrates operation lookups to find_symbol_by_id across operation behavior tests.
slicec/tests/interfaces/mod.rs Migrates interface lookups to find_symbol_by_id in interface container tests.
slicec/tests/interfaces/inheritance.rs Migrates interface lookups to find_symbol_by_id in inheritance tests.
slicec/tests/identifier_tests.rs Migrates identifier-related lookups to find_symbol_by_id.
slicec/tests/enums/container.rs Migrates enum/enumerator/field lookups to find_symbol_by_id.
slicec/tests/custom_tests.rs Migrates custom type lookup to find_symbol_by_id.
slicec/tests/comment_tests.rs Migrates interface/operation/struct lookups to find_symbol_by_id in doc comment tests.
slicec/tests/attribute_tests.rs Migrates operation/module/parameter lookups to find_symbol_by_id in attribute tests.
Suppressed comments (1)

slicec/src/ast/mod.rs:158

  • Same doc issue for find_node_with_scope: the guidance to use find_symbol_by_id is only correct for user-defined symbols. Primitive lookups should continue to use find_node/find_node_with_scope and match Node::Primitive.
    /// This is a low level method used for retrieving nodes from the AST directly.
    /// Only use this if you need access to the node, or the pointer, holding a slice element.
    ///
    /// If you want a reference to the Slice construct itself, use [find_symbol_by_id](Ast::find_symbol_by_id) instead.
    ///

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread slicec/src/ast/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants