-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Codegen: improve implementation of generated parent/child relationship #19866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This improves the implementation of the generated parent/child relationship by adding a new `all_children` field to `ql.Class` which lists all children (both direct and inherited) of a class, carefully avoiding duplicating children in case of diamond inheritance. This: * simplifies the generated code, * avoid children ambiguities in case of diamond inheritance. This only comes with some changes in the order of children in the generated tests (we were previously sorting bases alphabetically there). For the rest this should be a non-functional change.
There was a problem hiding this comment.
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 enhances codegen for parent/child relationships by introducing an all_children
list on ql.Class
, ensuring both direct and inherited children are included without duplication. It refactors generators to a Resolver
class, updates templates to iterate over all_children
, and aligns tests with the new API.
- Add
all_children
support and replaceprev_child
logic across lib, templates, and generators - Refactor
qlgen
into a statefulResolver
with caching and diamond-safe traversal - Update tests in
test_qlgen.py
/test_ql.py
and checksums in generated file lists
Reviewed Changes
Copilot reviewed 8 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
swift/ql/.generated.list | Updated checksum for ParentChild.qll reflecting template changes |
rust/ql/.generated.list | Updated checksum for ParentChild.qll reflecting template changes |
misc/codegen/test/test_qlgen.py | Adjust tests to assert all_children and drop prev_child args |
misc/codegen/test/test_ql.py | Replace properties -based child checks with all_children usage |
misc/codegen/templates/ql_parent.mustache | Refactor getImmediateChildOf to loop over all_children |
misc/codegen/lib/ql.py | Add Child class, is_child flag, and all_children on Class |
misc/codegen/generators/rusttestgen.py | Use Resolver.should_skip_qltest instead of previous skip logic |
misc/codegen/generators/qlgen.py | Introduce Resolver class, caching, and new property/class methods |
Comments suppressed due to low confidence (4)
misc/codegen/generators/qlgen.py:254
- [nitpick] Add a docstring to
_get_all_properties
to explain its traversal order, deduplication strategy, and how it handles inherited properties.
def _get_all_properties(
misc/codegen/test/test_qlgen.py:474
- Consider adding a dedicated test case for a diamond inheritance scenario to verify that
all_children
correctly avoids duplicate entries when multiple bases introduce the same child property.
[
misc/codegen/generators/rusttestgen.py:63
- The
qlgen
module is referenced here but not imported; please addimport qlgen
at the top ofrusttestgen.py
to avoid a NameError.
resolver = qlgen.Resolver(schema.classes)
misc/codegen/templates/ql_parent.mustache:12
- [nitpick] This deeply nested logic around
getImmediateChildOf{{name}}
can be hard to follow. Consider refactoring into smaller sections or adding clarifying comments to improve readability.
{{#final}}
Hmm, I'm a bit surprised there were some changes in results highlighted by DCA on the rust experiment. @hvitved is there maybe some instability there? |
This improves the implementation of the generated parent/child relationship by adding a new
all_children
field toql.Class
which lists all children (both direct and inherited) of a class, carefully avoiding duplicating children in case of diamond inheritance. This:This only comes with some changes in the order of children in the generated tests (we were previously sorting bases alphabetically there). For the rest this is a non-functional change, particularly highlighted by the fact that no
PrintAst
tests changed their results. It also only changes a private module, so no change note is even required.While we currently have no diamond inheritance of child fields, we will have it shortly in Rust.