Skip to content

transform: add inline C expression rewrite mode for patch specifications#210

Open
kumarak wants to merge 2 commits into
mainfrom
kumarak/rewrite-mode
Open

transform: add inline C expression rewrite mode for patch specifications#210
kumarak wants to merge 2 commits into
mainfrom
kumarak/rewrite-mode

Conversation

@kumarak
Copy link
Copy Markdown
Collaborator

@kumarak kumarak commented Apr 24, 2026

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.

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>
contract: "message_nonnull_contract"
```

### Rewrite Mode
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

@kumarak kumarak force-pushed the kumarak/rewrite-mode branch 2 times, most recently from 79db3c2 to 54da073 Compare April 28, 2026 04:20
@kumarak kumarak closed this Apr 28, 2026
@kumarak kumarak force-pushed the kumarak/rewrite-mode branch from c4c90ae to 1d45d39 Compare April 28, 2026 14:22
@kumarak kumarak reopened this Apr 28, 2026
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.

1 participant