Skip to content

Latest commit

 

History

History
197 lines (121 loc) · 10.6 KB

CLAUDE.md

File metadata and controls

197 lines (121 loc) · 10.6 KB

Human documentation starts at the README and continues under docs/src.

Writing

Everything written for this repository is short and human-readable.

  • No headings, bold labels or numbered scaffolding where a paragraph is enough.
  • No lead that summarizes what follows, and no closing that repeats it.
  • No restatement of what the reader can already see.
  • No account of how the work was done, and no approval of what is already correct.
  • No hedging: a claim that is not verified is not made.
  • No sycophancy, no emoji, and no sentence that only introduces the next one.
  • No tombstones: what was removed leaves no trace.
  • No negative definitions: what a thing is not stays unwritten.

Architecture

  • solx (this repo) is the Rust workspace of the slang compiler: the CLI, the Slang frontend, the dialect binding and codegen.
  • Slang is the parser and binder, a git dependency pinned by rev in Cargo.toml.
  • solx-llvm (submodule) is a fork of LLVM with the Sol and Yul MLIR dialects and an EVM target backend.
  • solidity (submodule) is upstream solc, kept for its test/libsolidity/semanticTests, which the tester runs.
Solidity → Slang (parse, bind) → Sol-dialect MLIR → Sol→Yul→Standard passes → LLVM IR → LLVM optimizer → EVM bytecode

Workspace Crates

Crate Purpose
solx CLI entry point, the slang binary
solx-core Pipeline orchestration
solx-slang Lowers the Slang AST to Sol-dialect MLIR
solx-mlir The Sol and Yul dialect binding over melior: values, places, types, blocks
solx-codegen-evm LLVM IR to EVM bytecode: optimization and emission
solx-standard-json solc-compatible JSON I/O protocol
solx-utils Shared types: contract names, EVM versions, hashing, CBOR metadata
solx-dev Developer tool: builds LLVM, runs project tests
solx-tester Test runner over the REVM corpus
solx-compiler-downloader Downloads and verifies compiler binaries
solx-benchmark-converter Benchmark analysis and comparison

Code layout

A type has one inherent impl block, with public items before private ones.

Slang Frontend

solx-slang lowers the Slang AST to Sol-dialect MLIR through solx-mlir. The rules below are the design law of that frontend.

Ground truth

  1. Ground truth is legacy solc: solc --asm, --bin and --storage-layout define behavior. The compiler is never evidence about itself.

  2. LIT fixtures follow the compiler: one that stops matching a correct change is rewritten, and no emission code exists to keep a fixture passing. The semantic tests are followed: they come from solc, and the compiler changes to pass them.

Validation and failure

  1. Codegen does no validation. Slang owns every check on the program. The frontend lowers whatever Slang accepts and never re-implements a solc rule.

  2. Emission has no error path: no Result, no diagnostics. A construct not lowered yet is unimplemented!. Any other panic names the Slang guarantee that turned out broken. Input Slang accepts is never a panic site.

  3. Dispatch is decided up front. The handler for a construct is resolved and called. There is no try-this-then-that and no "not applicable" return value.

  4. A file-level output such as ast is built from Slang alone, before the error check and codegen, so it is present even when compilation fails.

Slang as the source of truth

  1. Slang is the single source of semantic truth. Types, selectors, signatures, layout, linearisation and name resolution come from its API and are never recomputed or approximated here, by the compiler or by the tester.

  2. Type facts come from the dialect's own predicates, never from matching printed type text.

Emission model

  1. Codegen is one traversal. A definition is materialized the first time something names it, marked before its body is emitted, and nothing walks the program ahead of emission to collect or pre-register.

  2. A segment's module defines what that segment reaches: the deploy module from the constructor, the runtime module from its externally visible functions and every function whose pointer the deploy code takes. No pass removes unused symbols.

  3. Caches are memos filled on first use, living on the object that owns the fact. A cache that must be complete before a phase is a hidden pre-pass.

  4. A fact the emitting context can derive from a relationship it already sees is derived there, never threaded down as a parameter.

Scopes and modules

  1. Lowering is methods on the scope that owns the mutable state of that level: source unit, contract, function, assembly block. The AST node is input, the scope is the receiver, and each level's derived facts are computed once when the scope opens.

  2. The lowering layer has no traits, macros, free functions or namespace types. One mechanism only.

  3. Modules mirror what a construct is, not how Slang's grammar spells it. A group of files has one obvious reason to exist.

  4. The dialect crate knows nothing about Slang, and vocabulary only the frontend uses lives in the frontend.

Ops and dialects

  1. Every dialect op has exactly one home: the entity whose operation it is. Values cast and compare, places load and store, blocks branch. Nothing builds an op outside its home.

  2. Solidity emits Sol ops, inline assembly emits Yul ops. A Sol value enters Yul only through the bridge ops, and emitting one dialect's operation with the other's op is wrong even when the result is equivalent.

  3. Conversion has three separate layers: raw op emitters that do one thing, value-level policy that decides which to call, and expression-level helpers that lower an expression to a target type. Every site that needs a typed expression goes through the helpers.

Domains

  1. A domain lands complete over the types that exist when it lands. Later domains extend the earlier mechanisms for the types they introduce, so every mechanism is designed once as an extension point.

Debug locations

  1. An op carries the first byte of the innermost node it is lowered from. A lowering that emits a node's own ops runs inside at_node(node, …), and a Solidity body's implicit return inside at_node_end. A construct that emits no op of its own, such as a block or an expression statement, takes no at_node, so no position is resolved that no op carries.

  2. A construct that emits ops lands with its locations pinned in a debug_location*.sol fixture.

Fixtures

  1. A LIT fixture pins op shape. A tester case under tests/solidity/ pins behavior.

  2. A fixture has one RUN line, slang --emit-mlir=sol %s | FileCheck %s, and no prose. The CHECKs are the whole statement. A debug-location fixture runs slang --emit-mlir=sol --debug-info --debug-info-runtime %s | FileCheck %s --implicit-check-not='loc(unknown)'.

  3. One fixture per construct. A new case joins the fixture that owns its construct.

  4. Every CHECK must fail when the input line it matches is deleted.

  5. Every fixture source line is observed by some CHECK.

  6. A base the fixture does not observe is abstract.

  7. A file that only a fixture imports lives in Inputs/, which lit skips, and joins the RUN line after %s as %S/Inputs/<file>.

CLI tests

  1. A test input selects only the outputs the test asserts on.

  2. An expected-output JSON fixture is compared as JSON, never after deserializing into the type it pins.

  3. A test that can only fail together with another one is deleted.

Naming and docs

  1. One concept has one name across the frontend.

  2. A lowering method is named after the node it lowers. The receiver already says which dialect.

  3. An imported type that clashes with a local one takes the prefix of the crate it came from.

  4. No contractions in Rust names: identifier, not id; message, not msg; context, not ctx. Initialisms read as words stay short, such as abi, mlir, ods, url, api, and unit symbols such as ms. FileCheck captures stay short, such as ADDR and PTR.

  5. A doc says why the item exists or what is non-obvious, never its name again.

  6. A // comment carries only a constraint the code cannot express.

Build Commands

Build solx-dev, then LLVM with MLIR, then the compiler:

cargo build --release --bin solx-dev
./target/release/solx-dev llvm build --enable-utils --build-type RelWithDebInfo   # target-llvm/target-final/
cargo build              # target/debug/slang
cargo build --release    # target/release/slang

Testing

cargo test                                        # unit and CLI tests
cargo clippy --all-targets
cargo build --release && cargo run-tester         # the REVM corpus at -O M3B3 against target/release/slang
cargo run-tester --path tests/solidity/simple/default.sol   # one test

LIT runs the fixtures under solx-mlir/tests/lit/ against target/debug/slang:

export PATH="$PWD/target-llvm/target-final/bin:$PWD/target/debug:$PATH"
PYTHONPATH=solx-llvm/llvm/utils/lit python3 target-llvm/target-final/bin/llvm-lit solx-mlir/tests/lit/

Pull requests

A PR body is one or two sentences saying what the PR delivers, with short bullets or a numbered list where they help.

It is forbidden to post low-level code changes, the process of how the work was done, or anything derivable from the PR diff.

The integration tests run on every PR. These labels switch on optional CI:

  • ci:sanitizer for the address sanitizer tests
  • ci:integration-benchmark-full to compare every compiler in the Foundry and Hardhat benchmarks, from the next push or re-run
  • ci:release for a dry run of the release pipeline
  • ci:sourcify-sweep for the Sourcify sweep

A change to renovate.json is validated before pushing, with the checks CI repeats in its renovate-config-check job, at the Renovate version that job pins:

export RENOVATE_VERSION=$(sed -n 's/.*RENOVATE_VERSION: "\(.*\)"/\1/p' .github/workflows/test.yaml)
npx --yes --package "renovate@$RENOVATE_VERSION" -- renovate-config-validator renovate.json
LOG_LEVEL=debug npx --yes "renovate@$RENOVATE_VERSION" --platform=local --dry-run=full

The dry run is what catches matchPackageNames silently missing a git-source cargo dependency, whose packageName is the git URL rather than the Cargo.toml key. Those are matched by matchDepNames, as the pinned-fork rule does for inkwell, melior, slang_solidity and web3.