AST rewriting for witness() with type attribution implementation#21
AST rewriting for witness() with type attribution implementation#21Copilot wants to merge 8 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21 +/- ##
=========================================
Coverage 65.78% 65.78%
Complexity 289 289
=========================================
Files 54 54
Lines 792 792
Branches 70 70
=========================================
Hits 521 521
Misses 224 224
Partials 47 47 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add JCTree imports and TreeMaker/Names for AST manipulation - Implement WitnessCallRewriter using TreeTranslator pattern - Build method invocation trees from InstantiationPlan - Replace witness() calls with direct constructor invocations - Update pom.xml to export internal compiler packages at compile-time and test-time - Change from maven.compiler.release to source/target to allow --add-exports Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
- Add comprehensive AST_REWRITING.md documentation - Add JavaDoc for translate() method - Keep AST rewriting disabled for stability - Document how to enable transformation in production - All tests passing (36/36) - No security vulnerabilities found Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
|
@copilot You can drop the documentation. Also forget about prototyping. Try to write a full, correct implementation. Also, the build is failing. |
- Remove AST_REWRITING.md documentation file as requested - Enable AST transformation in WitnessResolutionChecker - Uncomment buildInstantiationTree usage to replace witness() calls - Update logic to only call super when transformation doesn't occur Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
Documentation removed and AST rewriting enabled in commit 5e611b3. The transformation now replaces Note: WitnessResolutionProcessorTest currently fails because transforming the AST during the ANALYZE phase creates untyped nodes. A full solution would require either:
The infrastructure is complete - |
The transformation causes NullPointerException in javac because generated nodes lack type attribution. The infrastructure is complete but transformation needs proper type attribution using javac's Attr class to work correctly. Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
|
@copilot feel free to move this to the right compiler phase. Just make it work. |
Run fmt-maven-plugin to format code according to project standards. Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
- Remove two-phase transformation approach that was causing issues - Keep witness validation during ANALYZE phase when type info is available - Transformation disabled - requires proper type attribution to work - All tests passing (36/36), build passing Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
The fundamental issue is that we need type information (available after ANALYZE phase) to perform witness resolution, but transforming the AST after ANALYZE breaks javac because the generated JCTree nodes lack proper type attribution. This creates a chicken-and-egg problem. Attempted solutions:
The working solution requires using javac's Current state (commit 85085b0): Witness validation working, all tests passing, build passing. Transformation disabled pending proper type attribution implementation. |
|
@copilot The challenges make sense. Can you find any resources that have tackled this in the past? Is it even possible? If so, can you keep trying? |
- Add imports for javac's Attr, Resolve, Types, Symtab - Add Symbol and Type information to generated JCTree nodes - Update buildMethodReference to set proper symbols on FieldAccess - Update buildQualifiedName to navigate symbol hierarchy - Update buildInstantiationTree to set return types on method invocations - Add --add-exports for javac.comp package - Attempt proper type attribution following Lombok's approach Still has issues - transformation causes test failures due to incomplete attribution Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
Yes, it's possible - projects like Lombok successfully transform ASTs. Research shows the key is proper type attribution. Implemented approach (commit 4bb32a6):
The transformation is now enabled and attempts attribution, but still fails because:
Lombok works because it operates during annotation processing with full access to the type environment. A complete solution requires either:
Continuing investigation... |
|
@copilot I implemented the checker as an annotation processor. Rebase and start over. |
Reset to main branch with annotation processor implementation. Now implementing AST transformation for witness() calls using the annotation processor's Trees API and javac internals. |
AST Transformation in Annotation Processor (WIP)
Rebased onto new main branch with annotation processor implementation and added AST transformation infrastructure.
Changes:
Current Issue:
Annotation processors run in a separate classloader context and cannot extend javac internal classes like TreeTranslator, even with --add-exports. Error: "superclass access check failed: class WitnessCallTransformer cannot access class TreeTranslator because module jdk.compiler does not export com.sun.tools.javac.tree"
Options:
Build fails at testCompile phase due to annotation processor module access.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.