Skip to content

codegen: use LibCodeGen.addressConstantString instead of a local copy - #11

Merged
thedavidmeister merged 1 commit into
mainfrom
codegen-dedupe-address-constant
Aug 18, 2026
Merged

codegen: use LibCodeGen.addressConstantString instead of a local copy#11
thedavidmeister merged 1 commit into
mainfrom
codegen-dedupe-address-constant

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Closes #10

Motivation

script/BuildPointers.sol defined its own addressConstantString for
address constant DEPLOYED_ADDRESS = address(...) while, in the same file,
calling LibCodeGen.bytesConstantString from rain-sol-codegen for the other
generated constants. LibCodeGen already publishes the address emitter, and its
version is strictly more general — parameterised on the comment text and the
constant name instead of hardcoding both.

Changes

  • script/BuildPointers.sol: local addressConstantString deleted; the call
    site now uses LibCodeGen.addressConstantString(vm, <the same NatSpec>, "DEPLOYED_ADDRESS", deployed).
  • rain-sol-codegen 0.1.0 -> 0.1.3 (foundry.toml, soldeer.lock, the two
    versioned import prefixes). Required: the pinned 0.1.0 predates
    addressConstantString, which first shipped in published 0.1.2.

Why 0.1.3 and not latest

0.1.0 -> 0.1.3 is purely additive in src/lib — it adds
addressConstantString, bytes32ConstantString and LibSnapshot.sol and
changes nothing this repo already calls, so generated output cannot move.

0.1.4 is not a candidate here. It changes LibFs.pathForContract from
src/generated/<name>.pointers.sol to src/generated/<name>.sol and rewrites
the THIS FILE IS AUTOGENERATED BY ./script/BuildPointers.sol header emitted
into every generated file. Taking it would rename and rewrite the committed
per-tag snapshots — including frozen ones — which is a separate migration, not a
side effect of deduplicating one function.

Drift check: byte-identical, nothing regenerated

The issue asks whether this repo's private copy had drifted from the shared one.
It had not. Both emit

\n<comment>\naddress constant DEPLOYED_ADDRESS = address(0x…);\n

and the shared function's only extra behaviour is a line-wrap branch that fires
above 120 columns. This line is 88 columns
(17 + 16 ("DEPLOYED_ADDRESS") + 3 (" = ") + 8 ("address(") + 42 + 2 (");")), so
the single-space branch is taken and the bytes match exactly.

Confirmed empirically, not just by reading: forge script ./script/BuildPointers.sol && forge fmt on this branch leaves src/generated/ completely clean. No
generated file moves, so no frozen src/generated/<tag>/ snapshot is rewritten
0_1_3/, 0_1_4/ and 0_1_5/ are all untouched, and CI's
frozen-snapshots-append-only check independently enforces that.

QA

  • Discriminating tests:
    • The repo's own regeneration gate, which CI runs: forge script ./script/BuildPointers.sol && forge fmt && git diff --exit-code. It is
      discriminating for exactly this change because the committed
      src/generated/0_1_5/CloneFactory.pointers.sol was produced by the OLD
      hand-rolled emitter, so any byte the new one emits differently shows up as a
      diff.
    • Baseline run recorded script_rc=0 generated_files_dirty=0 — proof the gate
      actually executed and was green, not merely assumed.
  • Mutations applied:
    • Three mutants on the new call site, one per drift axis the issue names, each
      regenerated and re-checked against the committed artifacts:
    • M1 comment text (deploy address -> deployed address): KILLED,
      generated_files_dirty=1.
    • M2 constant name (DEPLOYED_ADDRESS -> DEPLOYED_ADDR): KILLED,
      generated_files_dirty=1.
    • M3 line wrapping (the comment's internal \n collapsed to a space): KILLED,
      generated_files_dirty=1.
    • 3/3 killed, 0 survived. The harness aborts if the unmutated baseline does not
      come back clean, so a silently-not-running gate cannot report kills.
  • Oracle:
    • The committed generated artifacts themselves, which are the pre-change
      output of the emitter being replaced. Byte-equality against them is the
      whole correctness claim; it is checked, not reasoned about.
  • Category check:
    • The drift axes are covered as a category, not as three examples: comment
      text, constant name and line wrapping are the complete set of inputs the
      shared function's output depends on, since it is pure over
      (comment, name, address) with one length-derived branch. The address
      itself is covered by the unchanged BYTECODE_HASH/CREATION_CODE/
      RUNTIME_CODE constants generated beside it. No production Solidity changes
      in this PR: the only non-script edits are the dependency pin and its lock.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated the code generation tooling to version 0.1.3.
    • Improved build-time handling of generated address constants.

script/BuildPointers.sol hand-rolled an address-constant emitter that
rain-sol-codegen already publishes as LibCodeGen.addressConstantString,
in the same file that already calls LibCodeGen.bytesConstantString. The
private copy hardcodes the comment text and the DEPLOYED_ADDRESS name;
the shared one is parameterised on both.

The pinned rain-sol-codegen 0.1.0 predates addressConstantString (it
first shipped in 0.1.2), so the dependency moves to 0.1.3 — the newest
version that leaves generated output byte-identical. 0.1.0 -> 0.1.3 is
purely additive in src/lib (addressConstantString, bytes32ConstantString,
LibSnapshot); 0.1.4 is not, because it renames LibFs.pathForContract's
output from <name>.pointers.sol to <name>.sol and rewrites the generated
header comment, which is a separate migration.

Generated output is unchanged: the local emitter and the shared one
produce the same bytes for this input, so no generated file moves and no
frozen per-tag snapshot is rewritten.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Aug 13, 2026
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d4192626-b878-4a44-b885-57c5b411847e

📥 Commits

Reviewing files that changed from the base of the PR and between 6173d3e and 59157c1.

⛔ Files ignored due to path filters (1)
  • soldeer.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • foundry.toml
  • script/BuildPointers.sol

Walkthrough

The PR updates rain-sol-codegen from 0.1.0 to 0.1.3 and replaces the local address constant emitter in BuildPointers.sol with LibCodeGen.addressConstantString.

Changes

Code generation integration

Layer / File(s) Summary
Update dependency and address emitter
foundry.toml, script/BuildPointers.sol
The project and script imports use rain-sol-codegen 0.1.3. BuildPointers.sol uses LibCodeGen.addressConstantString with the VM, documentation, constant name, and deployed address.

Estimated code review effort: 2 (Simple) | ~10 minutes

Mergeability Score: ⚪ Minimal · up to 59157

This change reuses the shared address-constant generator without changing generated output or production Solidity behavior; no actionable merge-blocking risk remains beyond normal checks and review.

Possibly related issues

  • rainlanguage/rain.verify#28 — Replaces a local BuildPointers.sol address-constant emitter with LibCodeGen.addressConstantString, matching this PR’s change.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: replacing the local emitter with LibCodeGen.addressConstantString.
Linked Issues check ✅ Passed The PR replaces the local emitter, passes the required comment and name, upgrades the dependency, and verifies unchanged generated output.
Out of Scope Changes check ✅ Passed The dependency update directly supports the required shared emitter change, and no unrelated code changes are reported.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codegen-dedupe-address-constant

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thedavidmeister thedavidmeister added the ai:ready AI vetter: passes review, ready for human decision label Aug 18, 2026
@thedavidmeister

Copy link
Copy Markdown
Contributor Author

🤖 ai:vetter
vet-protocol 4
lens source@59157c19faa38c4043d3f323368d684f0714d8c3 + audit skill invoked at pr:11
Reviewed 59157c1: ready — Closes #10: local addressConstantString replaced by LibCodeGen.addressConstantString with args byte-matching the frozen 0_1_5 artifact (comment/name identical, 88-col constant line under the 120-col wrap branch); rain-sol-codegen 0.1.0→0.1.3 consistent across foundry.toml, soldeer.lock and both import prefixes; src/generated untouched, no drift. Pre-existing stale NatSpec at BuildPointers.sol:22-23 (names autopublish soldeer-generate-cmd) is outside this diff.
cost 218 — emitter swap pinned by committed artifacts

@thedavidmeister
thedavidmeister merged commit ef71b90 into main Aug 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ready AI vetter: passes review, ready for human decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BuildPointers hand-rolls an address-constant emitter LibCodeGen already provides

1 participant