Skip to content

Extract named constants for 0xf0 pointer shifts#481

Open
thedavidmeister wants to merge 2 commits intomainfrom
extract-pointer-shift-constant
Open

Extract named constants for 0xf0 pointer shifts#481
thedavidmeister wants to merge 2 commits intomainfrom
extract-pointer-shift-constant

Conversation

@thedavidmeister
Copy link
Copy Markdown
Contributor

@thedavidmeister thedavidmeister commented Apr 13, 2026

Summary

  • Replaces all 19 occurrences of magic number 0xf0 in shr(0xf0, ...) with named constants per use case
  • Each constant documents what the shift extracts and where it's used
  • Bytecode is unchanged — constants are inlined by the compiler

Constants introduced:

  • OPCODE_FUNCTION_POINTER_SHIFT — LibEval, BaseRainlangExtern, LibIntegrityCheck
  • SOURCE_OFFSET_SHIFT — LibEval, LibInterpreterStateDataContract
  • ACTIVE_SOURCE_POINTER_SHIFT — LibParseState
  • PAREN_POINTER_SHIFT — LibParseState, LibParse
  • COMMENT_SEQUENCE_SHIFT — LibParseInterstitial

Closes #475.

Test plan

  • Clean build, no warnings
  • Creation code tests pass (bytecode unchanged)
  • CI green

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Replaced hardcoded bit-shift literals with named constants across parsing, evaluation, integrity, and state handling code to reduce magic numbers and improve maintainability.
    • Introduced centralized shift constants and updated assembly bit-extraction sites to use them.
    • Behavior, control flow, and public APIs remain unchanged.

- OPCODE_FUNCTION_POINTER_SHIFT — function pointer table reads
- SOURCE_OFFSET_SHIFT — source offset reads from bytecode header
- ACTIVE_SOURCE_POINTER_SHIFT — parse-time source linked list
- PAREN_POINTER_SHIFT — paren tracking during operand processing
- COMMENT_SEQUENCE_SHIFT — comment delimiter sequence reads

Bytecode is unchanged since constants are inlined by the compiler.

Closes #475.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 131e7500-3075-4bd9-ac37-7eb2e9bf427e

📥 Commits

Reviewing files that changed from the base of the PR and between ec7902d and 5cc2f10.

📒 Files selected for processing (1)
  • src/lib/eval/LibEval.sol
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/eval/LibEval.sol

📝 Walkthrough

Walkthrough

Replaced hardcoded bit-shift literals (0xf0) with named constants for several assembly-extracted values (function-pointer, source-offset, paren pointer, active-source pointer, comment sequence) across eval, parse, integrity, state, and extern code paths. No control flow or semantics were altered.

Changes

Cohort / File(s) Summary
Eval constants & dispatch
src/lib/eval/LibEval.sol
Added OPCODE_FUNCTION_POINTER_SHIFT and SOURCE_OFFSET_SHIFT (both 0xf0) and replaced hardcoded shr(0xf0, ...) uses in opcode dispatch and source-pointer extraction.
Extern & integrity
src/abstract/BaseRainlangExtern.sol, src/lib/integrity/LibIntegrityCheck.sol
Replaced inline-assembly shr(0xf0, ...) with shr(OPCODE_FUNCTION_POINTER_SHIFT, ...) when extracting opcode/function pointers.
Parse constants & uses
src/lib/parse/LibParseState.sol, src/lib/parse/LibParse.sol
Added ACTIVE_SOURCE_POINTER_SHIFT and PAREN_POINTER_SHIFT (both 0xf0) and replaced shr(0xf0, ...) with these named constants for active-source head and paren-group pointer extraction.
Parse interstitial (comments)
src/lib/parse/LibParseInterstitial.sol
Added COMMENT_SEQUENCE_SHIFT (0xf0) and replaced shr(0xf0, ...) with shr(COMMENT_SEQUENCE_SHIFT, ...) in comment delimiter extraction.
Interpreter state deserialization
src/lib/state/LibInterpreterStateDataContract.sol
Imported SOURCE_OFFSET_SHIFT and replaced shr(0xf0, mload(cursor)) with shr(SOURCE_OFFSET_SHIFT, mload(cursor)) in unsafeDeserialize.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

🐰
A nibble, a nibble, the bits now named,
No more mystery where shifts once reigned.
Constants in order, hops light and spry,
I tidy the code and then munch a pie. 🍪

🚥 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 accurately describes the main change: extracting hardcoded 0xf0 values into named constants for pointer shifts across multiple files.
Linked Issues check ✅ Passed The PR fully addresses #475 by replacing ~19 occurrences of 0xf0 shift magic numbers with five named constants (OPCODE_FUNCTION_POINTER_SHIFT, SOURCE_OFFSET_SHIFT, ACTIVE_SOURCE_POINTER_SHIFT, PAREN_POINTER_SHIFT, COMMENT_SEQUENCE_SHIFT) across all required files.
Out of Scope Changes check ✅ Passed All changes are strictly scoped to extracting 0xf0 shift constants into named constants with no modifications to control flow, logic, or error handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch extract-pointer-shift-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 and usage tips.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.

Extract named constant for function pointer table shift (0xF0)

1 participant