Skip to content

[WIP] Prototype AST rewrite for parameterless witness method#23

Closed
Copilot wants to merge 7 commits into
mainfrom
copilot/prototype-compiler-ast-rewrite
Closed

[WIP] Prototype AST rewrite for parameterless witness method#23
Copilot wants to merge 7 commits into
mainfrom
copilot/prototype-compiler-ast-rewrite

Conversation

Copilot AI commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

Implementation Plan: AST Rewrite for Parameterless witness()

  • Understand the current architecture and resolve() method
  • Add javac tools dependency for AST manipulation (JCTree)
  • Create a function to translate InstantiationPlan to JCTree method calls
  • Created WitnessResolutionPlugin as compiler plugin
  • Configure Maven to enable the compiler plugin
  • Add parameterless witness() method
  • Update plugin to handle parameterless witness()
  • Simplify plugin implementation
  • Add test for parameterless witness()
  • Document the new functionality
  • Address code review feedback
  • Verify the implementation compiles and runs correctly
Original prompt

This section details on the original issue you should resolve

<issue_title>Prototype compiler AST rewrite for parameterless witness()</issue_title>
<issue_description>It should be possible to expose a parameterless T witness() static method that gets rewritten into the expected witness constructor calls after witness resolution.

We only need the new Ty<>() {} "trick" because of type erasure. And of course because we can only resolve witnesses at runtime currently.

We can modify the AST as explained here: https://www.baeldung.com/java-build-compiler-plugin

In the current checker code, we ignore the success branch from the resolve() call. It contains an InstantiationPlan which describes the tree of WitnessConstructor that should be invoked to build the witness instance.

Roughly:

  • Write a function that translates an InstantiationPlan tree into a JCTree of method call invocations. Each InstantiationPlan contains a WitnessConstructor which contains a ExecutableElement. This should be enough to build the JCTree?
  • Then update the success branch of the resolve() call in the checker to replace the current AST node with the tree build from the function above. </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 19, 2025
@codecov

codecov Bot commented Dec 19, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.11%. Comparing base (8d575fa) to head (ad166c4).

Additional details and impacted files
@@            Coverage Diff            @@
##               main      #23   +/-   ##
=========================================
  Coverage     66.11%   66.11%           
  Complexity      320      320           
=========================================
  Files            55       55           
  Lines           782      782           
  Branches         65       65           
=========================================
  Hits            517      517           
  Misses          219      219           
  Partials         46       46           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI and others added 2 commits December 19, 2025 06:52
- Created AstRewriter class to translate InstantiationPlan to JCTree expressions
- Created WitnessResolutionPlugin as a javac compiler plugin
- Plugin collects witness() calls and replaces them with direct constructor calls
- Registered plugin via META-INF/services

Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
Added compiler configuration to enable the witness resolution plugin during compilation

Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
@Garciat Garciat marked this pull request as ready for review December 19, 2025 06:53
Copilot AI and others added 4 commits December 19, 2025 06:55
- Added parameterless witness() method to TypeClasses
- Updated WitnessResolutionPlugin to handle both witness() variants
- Parameterless version uses type inference from assignment context
- Plugin rewrites both versions to direct constructor calls

Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
- Replaced two-pass approach with single TreeTranslator
- Simplified witness call detection logic
- Plugin now rewrites AST in-place during ANALYZE phase
- Added test for parameterless witness() method

Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
Added documentation for the new compile-time witness() method and compiler plugin

Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
- Improved stream to list conversion in AstRewriter
- Replaced System.err logging with javac diagnostic API
- Added compilation unit tracking for proper diagnostic reporting

Co-authored-by: Garciat <118277+Garciat@users.noreply.github.com>
@Garciat Garciat closed this Dec 19, 2025
@Garciat Garciat deleted the copilot/prototype-compiler-ast-rewrite branch December 19, 2025 07:01
Copilot AI requested a review from Garciat December 19, 2025 07:01
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.

Implement compiler AST rewrite for parameterless witness()

2 participants