Skip to content

pi constant word#535

Open
thedavidmeister wants to merge 4 commits into
mainfrom
2026-06-15-issue-225
Open

pi constant word#535
thedavidmeister wants to merge 4 commits into
mainfrom
2026-06-15-issue-225

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Adds a pi constant standard op, mirroring the existing e word (LibOpE).

Closes #225

⚠️ REQUIRES multi-network interpreter redeploy at land (per #237)

This is a deployed-interpreter-bytecode change (the same class as the e word / #237). Adding the op shifts the interpreter/parser/expression-deployer/Rainlang bytecode, so the pinned deploy addresses and codehashes change. The fork-gated LibInterpreterDeployTest / LibInterpreterDeployProdTest tests assert the live on-chain bytecode against these pins and will stay red on every network until the contracts are redeployed via the manual interpreter-redeploy workflow. Do not merge without human review + the redeploy at land.

What changed (mirrors the e PRs #246 / #375)

LibOpE mirror:

  • New src/lib/op/math/LibOpPi.solintegrity (0 in / 1 out), run (pushes the constant), referenceFn, identical in structure/gas to LibOpE.
  • pi is encoded as a Float at the same precision/convention as LibDecimalFloat.FLOAT_E: a 67-digit coefficient × 10⁻⁶⁶, packed Float.wrap(bytes32(0xffffffbe1dd4c9e873614f593bba9c6007d9a7ac8d03a4b6c700a65cb537a1b4)). (The same packing reproduces the published FLOAT_E byte-for-byte; the pi value round-trips to π accurate to 66 decimal places. rain-math-float 0.1.1 has no FLOAT_PI, so the constant is defined locally in LibOpPi, matching how the lib defines FLOAT_E.)
  • Registered pi in src/lib/op/LibAllStandardOps.sol between mul and power across all four parallel arrays (authoring meta, operand handlers, integrity pointers, opcode pointers); ALL_STANDARD_OPS_LENGTH 72 → 73.
  • Updated word-ordering assertions in test/src/lib/op/LibAllStandardOps.t.sol (pi at index 59; later indices shifted).
  • New test/src/lib/op/math/LibOpPi.t.sol mirroring LibOpE.t.sol (parse _: pi(); + eval to π, integrity, operand-disallowed, bad input/output arity).

Regenerated artifacts (staged):

  • src/generated/RainlangInterpreter.pointers.sol
  • src/generated/RainlangParser.pointers.sol
  • src/generated/RainlangExpressionDeployer.pointers.sol
  • src/generated/Rainlang.pointers.sol
  • meta/AuthoringMeta.rain.meta, meta/RainlangExpressionDeployer.rain.meta

(RainlangStore.pointers.sol unchanged — store bytecode doesn't depend on opcodes. Pointer generation was iterated to a stable fixed point; rainix-sol-artifacts produces no further diff and leaves the crate ABIs untouched.)

New pinned values after regeneration:

contract deploy address codehash
RainlangInterpreter 0x7E694007Bb400ab2147a2060D2e48703F3FA1cef 0x3069f10fd2956d0681277d4834e35e9fefaf6d3a079af0a44ccab979ffba052d
RainlangParser 0x088Bdb2B554E3CdedA4137bEeF92ffEe1e9F4DBf 0x844ca2709f34283f566cee50abb1b948bf0e46fc62e1ff46df5659570186eaea
RainlangExpressionDeployer 0xC0BFfCcb665d3ebCa5Aba3816d94F35C8467d6f7 0x65c7c20b94c1878de8d25c6c0bd22ba470a9983719e274626e87e679b8da1df7
Rainlang 0x7c08C22E0700E9bB51082907514F8F68806fEEA0 0xe6cdd994c12e5626c2c0d6e0ad7c0fdf0bd290ea4c8a474e1f32ae040b12df6f
RainlangStore (unchanged) 0x1Aa775533E28B1D843e1A589034984E3a62005DC 0xdaa0024dc105c6a9ea0838604bad0a5e662743eca97789c2cecfdf8667d0bf9b

Verification

  • forge build clean (only pre-existing boolean-cst lint warnings in unrelated files).
  • forge fmt --check clean; one-contract-per-file respected.
  • Full suite: 1497 passed. The only failures are fork tests requiring *_RPC_URL env vars (LibInterpreterDeploy*, plus fork-constructor math op tests) — environment-gated, identical on main, and exactly the codehash checks the redeploy resolves.
  • LibOpPiTest (7) + LibOpETest + LibAllStandardOpsTest + filesystem-ordering all green.
  • Mutation check: pointing LibOpPi.run at FLOAT_E instead of FLOAT_PI makes testOpPiRun fail (runreferenceFn); restored to π and re-confirmed green.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Added the mathematical constant "pi" as a new opcode available in the standard operations library.

Add a `pi` standard op mirroring the existing `e` word (LibOpE),
stacking the mathematical constant pi as a Float.

- New `LibOpPi` library with integrity/run/referenceFn, encoding pi as a
  Float at the same precision/convention as `LibDecimalFloat.FLOAT_E`
  (67-digit coefficient * 10^-66; round-trips to pi to 66 decimal places).
- Register `pi` in `LibAllStandardOps` between `mul` and `power` across
  all four parallel arrays (authoring meta, operand handlers, integrity
  pointers, opcode pointers); bump ALL_STANDARD_OPS_LENGTH 72 -> 73.
- Update the word-ordering assertions in LibAllStandardOps.t.sol.
- Add `LibOpPi.t.sol` mirroring `LibOpE.t.sol` (parse + eval to pi,
  integrity, operand-disallowed, bad input/output arity).
- Regenerate bytecode pointer artifacts: interpreter, parser, expression
  deployer, and Rainlang `.pointers.sol` (creation/runtime code, deploy
  addresses, codehashes, parse-meta, function pointer tables) plus the
  CBOR authoring meta. Converged to a stable fixed point.

This is a deployed-interpreter-bytecode change: the pinned deploy
addresses and codehashes change, so landing REQUIRES the multi-network
interpreter redeploy workflow (per #237 / the LibOpE class of change).

Closes #225

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Jun 15, 2026
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@thedavidmeister, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 12 minutes and 29 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 96d906bc-b1f1-4f9f-b4e7-55e013fc1362

📥 Commits

Reviewing files that changed from the base of the PR and between 3b532de and 776cb72.

📒 Files selected for processing (36)
  • test/src/abstract/BaseRainlangExtern.construction.t.sol
  • test/src/abstract/BaseRainlangExtern.ierc165.t.sol
  • test/src/abstract/BaseRainlangExtern.integrityOpcodeRange.t.sol
  • test/src/abstract/BaseRainlangSubParser.ierc165.t.sol
  • test/src/abstract/BaseRainlangSubParser.subParseLiteral2.t.sol
  • test/src/abstract/BaseRainlangSubParser.subParseWord2.t.sol
  • test/src/abstract/ChildRainlangExtern.sol
  • test/src/abstract/ChildRainlangSubParser.sol
  • test/src/abstract/EmptyPointersExtern.sol
  • test/src/abstract/EmptyWordParsersSubParser.sol
  • test/src/abstract/HappyPathLiteralSubParser.sol
  • test/src/abstract/MismatchedExternMoreIntegrity.sol
  • test/src/abstract/MismatchedExternMoreOpcodes.sol
  • test/src/abstract/MismatchedLiteralSubParser.sol
  • test/src/abstract/MismatchedWordSubParser.sol
  • test/src/abstract/NoMatchLiteralSubParser.sol
  • test/src/abstract/TestableExtern.sol
  • test/src/abstract/TwoOpExtern.sol
  • test/src/concrete/MockExternBadLiteralIndex.sol
  • test/src/concrete/ModifierTestParser.sol
  • test/src/concrete/RainlangInterpreter.zeroFunctionPointers.t.sol
  • test/src/concrete/RainlangParser.parseMemoryOverflow.t.sol
  • test/src/concrete/RainlangReferenceExtern.subParserIndexOutOfBounds.t.sol
  • test/src/concrete/ZeroFPRainlangInterpreter.sol
  • test/src/lib/integrity/IntegrityHighwater.sol
  • test/src/lib/integrity/IntegritySingleOp.sol
  • test/src/lib/integrity/LibIntegrityCheck.t.sol
  • test/src/lib/parse/BadLengthSubParser.sol
  • test/src/lib/parse/ConstantReturningSubParser.sol
  • test/src/lib/parse/ContextReturningSubParser.sol
  • test/src/lib/parse/LibSubParse.badSubParserResult.t.sol
  • test/src/lib/parse/LibSubParse.constantAccumulation.t.sol
  • test/src/lib/parse/LibSubParse.subParseWords.t.sol
  • test/src/lib/parse/MultiConstantSubParser.sol
  • test/src/lib/state/LibInterpreterStateDataContract.t.sol
  • test/src/lib/state/LibInterpreterStateDataContractExtern.sol
📝 Walkthrough

Walkthrough

Adds a pi opcode to the Rainlang interpreter. A new LibOpPi library defines a FLOAT_PI constant and implements integrity, run (via inline assembly), and referenceFn. LibAllStandardOps is updated to include LibOpPi in all function pointer tables and metadata. Tests and compiled bytecode artifacts are regenerated accordingly.

Changes

pi opcode implementation, wiring, and artifacts

Layer / File(s) Summary
LibOpPi library
src/lib/op/math/LibOpPi.sol
Defines FLOAT_PI constant, integrity (0 inputs → 1 output), run pushing FLOAT_PI via inline assembly, and referenceFn returning the unwrapped value for test assertions.
LibAllStandardOps wiring
src/lib/op/LibAllStandardOps.sol
Imports LibOpPi, increments ALL_STANDARD_OPS_LENGTH from 72 to 73, inserts the "pi" authoringMetaV2 entry, and appends LibOpPi entries to the operand handler, integrity, and opcode execution function pointer tables.
Tests
test/src/lib/op/math/LibOpPi.t.sol, test/src/lib/op/LibAllStandardOps.t.sol
Adds LibOpPiTest with integrity bounds, run output, pi() eval, and negative cases (extra inputs, zero/two outputs, disallowed operand). Updates testAuthoringMetaV2Content to assert "pi" at its new index and shifts subsequent word assertions.
Regenerated bytecode artifacts
crates/bindings/abi/Rainlang.json, crates/test_fixtures/abi/Rainlang.json, crates/test_fixtures/abi/RainlangExpressionDeployer.json
Replaces bytecode.object and deployedBytecode.object hex strings with new compiled outputs; ABI function entries are unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hippity hoppity, what do we see?
A new opcode constant, round as can be!
Three point one four one five nine and more,
FLOAT_PI is pushed right onto the store.
The rabbit rejoices — now Rainlang's got pi,
Baked fresh in the bytecode, reaching the sky! 🥧

🚥 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 'pi constant word' is concise, clear, and accurately describes the main change: adding a pi constant as a standard opcode/word to the Rainlang interpreter.
Linked Issues check ✅ Passed The PR fully implements the requirement from issue #225 to add a word for pi, including the library implementation, integration into standard ops, tests, and bytecode regeneration.
Out of Scope Changes check ✅ Passed All changes are directly in scope: pi opcode implementation, integration, tests, and necessary bytecode artifact updates align with the linked issue objective.
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 2026-06-15-issue-225

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.

The pi opcode changes the interpreter bytecode, which cascades through the
expression deployer, parser, and Rainlang registry. Refresh the committed
forge ABI artifacts so the copy-artifacts determinism check passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/op/math/LibOpPi.sol`:
- Around line 11-12: The NatSpec documentation block in LibOpPi.sol for the pi
constant has an explicit `@dev` tag on line 11 but line 12 (containing the
hexadecimal representation) is untagged. According to NatSpec formatting rules,
when a block uses explicit tags, all lines must be explicitly tagged. Add the
`@dev` tag to line 12 to properly tag the continuation of the pi constant
documentation.
- Line 3: The pragma declaration in LibOpPi.sol uses a caret range (^0.8.25)
which allows multiple compiler versions and violates the requirement for
deterministic builds. Change the pragma solidity statement from using the caret
operator (^) to an equals operator (=) to pin the exact version. Replace pragma
solidity ^0.8.25; with pragma solidity =0.8.25; to enforce exact version
matching as required by the coding guidelines.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 379c9863-5c0c-4155-9707-a529c59b7d1f

📥 Commits

Reviewing files that changed from the base of the PR and between 2808e73 and 3b532de.

⛔ Files ignored due to path filters (4)
  • src/generated/Rainlang.pointers.sol is excluded by !**/generated/**
  • src/generated/RainlangExpressionDeployer.pointers.sol is excluded by !**/generated/**
  • src/generated/RainlangInterpreter.pointers.sol is excluded by !**/generated/**
  • src/generated/RainlangParser.pointers.sol is excluded by !**/generated/**
📒 Files selected for processing (11)
  • crates/bindings/abi/Rainlang.json
  • crates/test_fixtures/abi/Rainlang.json
  • crates/test_fixtures/abi/RainlangExpressionDeployer.json
  • crates/test_fixtures/abi/RainlangInterpreter.json
  • crates/test_fixtures/abi/RainlangParser.json
  • meta/AuthoringMeta.rain.meta
  • meta/RainlangExpressionDeployer.rain.meta
  • src/lib/op/LibAllStandardOps.sol
  • src/lib/op/math/LibOpPi.sol
  • test/src/lib/op/LibAllStandardOps.t.sol
  • test/src/lib/op/math/LibOpPi.t.sol

@@ -0,0 +1,49 @@
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Pragma in changed Solidity file:"
rg -n '^pragma solidity' src/lib/op/math/LibOpPi.sol

echo
echo "Checking toolchain config for Cancun target (if foundry.toml exists):"
fd -H 'foundry.toml' | xargs -r rg -n '^\s*(evm_version|solc_version)\s*='

Repository: rainlanguage/rainlang

Length of output: 222


Pin pragma to exact 0.8.25.

Line 3 uses pragma solidity ^0.8.25; (caret range), but the repository requires exact version pinning to ensure deterministic builds and compiler behavior consistency.

Suggested fix
-pragma solidity ^0.8.25;
+pragma solidity =0.8.25;

Per coding guidelines: "**/*.sol: Solidity version must be exactly 0.8.25 with EVM target cancun." The EVM target is correctly configured in foundry.toml, but the pragma declaration must use = instead of ^.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/op/math/LibOpPi.sol` at line 3, The pragma declaration in LibOpPi.sol
uses a caret range (^0.8.25) which allows multiple compiler versions and
violates the requirement for deterministic builds. Change the pragma solidity
statement from using the caret operator (^) to an equals operator (=) to pin the
exact version. Replace pragma solidity ^0.8.25; with pragma solidity =0.8.25; to
enforce exact version matching as required by the coding guidelines.

Source: Coding guidelines

Comment on lines +11 to +12
/// @dev The mathematical constant pi as a `Float`.
/// 3.141592653589793238462643383279502884197169399375105820974944592308e66, -66

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix tagged NatSpec block formatting.

Line 12 is untagged inside a block that already uses an explicit tag (@dev), which violates the NatSpec tagging rule.

Suggested fix
 /// `@dev` The mathematical constant pi as a `Float`.
-/// 3.141592653589793238462643383279502884197169399375105820974944592308e66, -66
+/// `@dev` Encoded as coefficient/exponent: 3.141592653589793238462643383279502884197169399375105820974944592308e66, -66.

As per coding guidelines: "In NatSpec doc blocks containing explicit tags (e.g., @title), all entries must be explicitly tagged; untagged lines do not continue the previous tag."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/// @dev The mathematical constant pi as a `Float`.
/// 3.141592653589793238462643383279502884197169399375105820974944592308e66, -66
/// `@dev` The mathematical constant pi as a `Float`.
/// `@dev` Encoded as coefficient/exponent: 3.141592653589793238462643383279502884197169399375105820974944592308e66, -66.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/op/math/LibOpPi.sol` around lines 11 - 12, The NatSpec documentation
block in LibOpPi.sol for the pi constant has an explicit `@dev` tag on line 11 but
line 12 (containing the hexadecimal representation) is untagged. According to
NatSpec formatting rules, when a block uses explicit tags, all lines must be
explicitly tagged. Add the `@dev` tag to line 12 to properly tag the continuation
of the pi constant documentation.

Source: Coding guidelines

thedavidmeister and others added 2 commits June 16, 2026 15:17
The prior red was transient: CI staged rainix@main during the ~3.5h window
when rainix main HEAD (c54864d1) had the dangling LICENSE symlink that broke
GitHub action-staging. That is now fixed on rainix main (LICENSE -> LICENSES/
LicenseRef-DCL-1.0.txt); this retriggers CI to pick it up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

word for pi

1 participant