transform: add inline C expression rewrite mode for patch specifications#210
Open
kumarak wants to merge 2 commits into
Open
transform: add inline C expression rewrite mode for patch specifications#210kumarak wants to merge 2 commits into
kumarak wants to merge 2 commits into
Conversation
kumarak
added a commit
that referenced
this pull request
Apr 24, 2026
Three cleanups from the PR #210 deep review: - Mark the post-dispatch BinOpKind check unreachable. Shifts, cmps, and arith/bitwise collectively exhaust BinOpKind, so the `err(...)` return was dead — now `llvm_unreachable` so the optimizer sees the invariant and assert builds fail loudly if it is ever broken. - Fold `emit() + require_value()` into an `emit_value` helper and convert all 12 operand-consumer sites. No behavior change; each site drops the intermediate assignment. - Drop the `Ident` AST variant. `parse_primary`'s ident branch now peeks for `(` and either dispatches directly to `finish_call` or rejects at parse time, moving the "bare identifier only valid as a call target" error from emit- to parse-time. `finish_call` takes the callee name + column directly, so no `std::get_if< Ident >` unwrap remains. `parse_postfix` rejects `(` after any non-ident primary with the same error it used to. UNBALANCED_ERR LIT input switched from `(uint16_t $A` to `($A` — the old input incidentally exercised the bubbling-Ident path, not the unbalanced-parens path it claims to test. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
kumarak
commented
Apr 27, 2026
| contract: "message_nonnull_contract" | ||
| ``` | ||
|
|
||
| ### Rewrite Mode |
Collaborator
Author
There was a problem hiding this comment.
@wizardengineer @akshithg, Let me know if rewrite mode with fragments will be helpful for some of the patches. I may be extending it to other modes as well.
79db3c2 to
54da073
Compare
c4c90ae to
1d45d39
Compare
This reverts commit 4213cb8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a new patch-spec mode that replaces the result of a matched operation with an inline C expression, eliminating the need for an external patch. The expression is parsed and lowered directly into CIR at the match site, with support for captures, arithmetic and logical operations, casts, pointer semantics, struct access, and function calls. It adds a full parsing and lowering pipeline under RewriteExpression/, integrates emission into the existing patch infrastructure, and includes comprehensive LIT tests covering both valid constructs and error cases.