-
-
Notifications
You must be signed in to change notification settings - Fork 59
[PoC] Implement eager binding for nested template arguments #204
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
Conversation
|
Hey! Wow thank you so much for that work! That has been a very long standing issue. If you haven't already, could you run your changes on the patterns in the WerWolv/ImHex-Patterns repo? The unit tests there should provide good coverage to make sure nothing else broke and will show if there's any changes that will need to be done due to the changed lexical scope now. |
I've run it past all except this one. Need to remove the parent. diff --git a/patterns/xilinx_bootgen.hexpat b/patterns/xilinx_bootgen.hexpat
index 5fb9b40..523630e 100644
--- a/patterns/xilinx_bootgen.hexpat
+++ b/patterns/xilinx_bootgen.hexpat
@@ -213,7 +213,7 @@ namespace zynqmp {
u64 destination_execution_address;
u64 destination_load_address;
- NullableWordPtr<std::Array<u8,parent.encrypted_partition_data_word_length*4>, u32> actual_partition_word_offset;
+ NullableWordPtr<std::Array<u8,encrypted_partition_data_word_length*4>, u32> actual_partition_word_offset;
PartitionAttributeBits attributes;
u32 section_count;
|
|
It seems that the CI for ImHex Patterns Tests does not pull the correct branch. |
That should be fixed now. The CI now passes along the current git hash and the git repo to the ImHex-Pattern repo unit tests CI and uses that repo instead of being hardcoded to master of this repo. |
ad3842f to
70b4881
Compare
This commit changes the evaluation of nested template arguments from lazy (pass-by-name) to eager (pass-by-value) to enforce correct lexical scoping. Motivation: Previously, in a nested template like `T<K<x>>`, the argument `x` was resolved lazily within the scope of `T` instead of the scope where it was declared. This pass-by-name behavior for nested types violated lexical scoping and caused unpredictable variable resolution. Implementation: The core of the fix was to separate a type's declaration from its application: 1. A new `ASTNodeTypeApplication` node was introduced to represent a specific instantiation of a type. It captures the fully resolved template arguments at the declaration site, effectively creating a closure over the surrounding scope. 2. The parser was updated to eagerly evaluate all arguments—including nested types—into this new `ASTNodeTypeApplication` node. 3. `ASTNodeTypeDecl` was simplified to only handle the static declaration of a type, leaving all instantiation-specific logic to `ASTNodeTypeApplication`. As a key benefit of this cleaner separation, forward-declared types can now be used in templates, enabling mutually recursive template definitions. 4. A new test suite (`test_pattern_template_parameters_scope.hpp`) was added to verify the corrected behavior with various nested and recursive template scenarios that previously failed.
Break the cycle manually when the parser and parser manager get reset.
…or template parameters.
…d a single evaluation.
|
Seems to fully pass now besides the Xilinx Bootgen Pattern you mentioned earlier. I will update that one manually once your PR is merged |
|
I have also tested out what I could and it seems to be working really well overall. The implementation of it also looks decent. If you could try to make your code style match the one of the surrounding code, that would be great (e.g spaces between |
|
I wonder what impact this change is going to have on peoples local patterns . As far as I know templates have always needed parent to access them and there is even an example in the documentation that shows how to create an array of arrays that uses the parent in the inner most template argument. I guess there is not much we can do about it other than maybe a small explanation in the error message when patterns that have always works now suddenly start to fail. |
|
Yeah you're right, this is going to break patterns but I'm more than willing to do that because having to use parent there in the first place never made sense. I'd expect not too many people to have used it before since it only worked for really basic cases. As you see from the unit tests now, there's only a single pattern in the ImHex-Patterns repo that was affected by this |
This commit changes the evaluation of nested template arguments from lazy (pass-by-name) to eager (pass-by-value) to enforce correct lexical scoping.
Motivation:
Previously, in a nested template like
T<K<x>>, the argumentxwas resolved lazily within the scope ofTinstead of the scope where it was declared. This pass-by-name behavior for nested types violated lexical scoping and caused unpredictable variable resolution.Implementation:
The core of the fix was to separate a type's declaration from its application:
A new
ASTNodeTypeApplicationnode was introduced to represent a specific instantiation of a type. It captures the fully resolved template arguments at the declaration site, effectively creating a closure over the surrounding scope.The parser was updated to eagerly evaluate all arguments—including nested types—into this new
ASTNodeTypeApplicationnode.ASTNodeTypeDeclwas simplified to only handle the static declaration of a type, leaving all instantiation-specific logic toASTNodeTypeApplication. As a key benefit of this cleaner separation, forward-declared types can now be used in templates, enabling mutually recursive template definitions.A new test suite (
test_pattern_template_parameters_scope.hpp) was added to verify the corrected behavior with various nested and recursive template scenarios that previously failed.fix #144