Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
transpiler:
name: transpiler (ruff, mypy, unit tests)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
- run: uv sync --locked
- run: uv run ruff check .
- run: uv run mypy ferrite/
- run: uv run pytest tests/unit

runtime:
name: pyrt (build, test, clippy)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build -p pyrt
- run: cargo test -p pyrt
- run: cargo clippy -p pyrt -- -D warnings

# Gates NOT yet enabled — each is added by the card that makes it pass, because
# CI must be green on every commit and its directory does not exist yet
# (TRD §11). Do not assume these were forgotten.
#
# 5 uv run pytest tests/harness T-004 (tests OF the harness)
# 6 uv run pytest tests/golden T-017 (codegen determinism)
# 7 uv run pytest tests/conformance T-019 (behavioural equivalence)
# 8 uv run pytest tests/property T-054 (differential fuzzing)
# 9 bench/report.py --check-regressions T-055 (S1-S4 must not drop)
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# --- Python -----------------------------------------------------------------
__pycache__/
*.py[cod]
.venv/
*.egg-info/
.pytest_cache/
.mypy_cache/
.ruff_cache/
.hypothesis/

# --- Rust -------------------------------------------------------------------
target/

# --- Ferrite build products (TRD §9) ----------------------------------------
# `ferrite build` writes a crate per module here; `ferrite verify` writes the
# report and the per-test capture.
ferrite_out/
*.so
ferrite_report.json
ferrite_results.json
repair.log
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Rust workspace root (TRD §9, ADR-0009).
#
# Every Rust command in AGENTS.md, TRD §11 and PLAN.md is workspace-scoped
# (`cargo build -p pyrt`, `cargo test -p pyrt`, `cargo clippy -p pyrt`), which
# needs a workspace root to exist.

[workspace]
resolver = "2"
members = ["pyrt"]

# Load-bearing, not cosmetic. `ferrite build` writes a standalone crate per
# module into ferrite_out/, and tests/harness/fixtures/fib/fib_rs/ is a
# hand-written standalone crate. Without these exclusions the workspace adopts
# them and `cargo build -p pyrt` starts building them too.
exclude = ["ferrite_out", "tests"]

[workspace.package]
version = "0.1.0"
edition = "2021"
rust-version = "1.75"

[workspace.dependencies]
# TRD §2 — the only crates generated output may use. Adding a crate here is a
# TRD edit first. `pyrt` must NOT enable pyo3/extension-module (ADR-0009);
# generated crates do, because maturin builds them.
pyo3 = { version = "0.22" }
indexmap = "2"
15 changes: 15 additions & 0 deletions bench/corpus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# bench/corpus/

The frozen benchmark corpus for S1–S6 (PRD §5). 50 modules: 20 Advent-of-Code
solutions (2019–2023), 20 numeric/data-processing kernels, 10 extracted from real
OSS hot paths.

Each module is a directory: `mod.py`, `test_mod.py` (at least 5 tests including an
error case), and `bench.py` defining a representative workload.

**Freezing rule (TESTING.md §6.1):** once M3 starts, adding or removing a corpus
module requires a note in `docs/DECISIONS.md`. Otherwise S1 drifts upward for
reasons that have nothing to do with the transpiler getting better.

Empty until T-055. The measurement rules that make these numbers defensible are
in TESTING.md §6.
9 changes: 9 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# examples/

Quickstart scripts referenced by `README.md` and `AGENTS.md`.

`collatz.py` and `test_collatz.py` land with the M1 exit gate (PLAN.md), which
requires `ferrite build` + `ferrite verify` to succeed on an iterative
`collatz_length`, a recursive `fibonacci`, and a `newton_sqrt`.

This directory is empty until then. Nothing here is a stub.
7 changes: 7 additions & 0 deletions ferrite/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Ferrite — a Python-to-Rust transpiler with a correctness guarantee.

What we are building and what "done" means: ``docs/PRD.md``.
Architecture and locked decisions: ``docs/TRD.md``.
"""

__version__ = "0.1.0.dev0"
1 change: 1 addition & 0 deletions ferrite/codegen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Rust AST, pretty printer, name mangling, crate scaffolding (TRD §1, SEMANTICS)."""
1 change: 1 addition & 0 deletions ferrite/frontend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Frontend: parse, PSS-0 subset gate, annotation validation (TRD §1)."""
1 change: 1 addition & 0 deletions ferrite/ir/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""FIR — the Ferrite IR. Frozen dataclasses, one per node (TRD §5)."""
1 change: 1 addition & 0 deletions ferrite/ir/passes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Mandatory post-lowering FIR passes, in order (TRD §5): clone insertion, then escape analysis."""
1 change: 1 addition & 0 deletions ferrite/types/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Type model and forward dataflow propagation (TRD §6)."""
1 change: 1 addition & 0 deletions ferrite/verify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Verification harness: cargo, import swap, result capture, diff (TRD §7)."""
53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[project]
name = "ferrite"
version = "0.1.0.dev0"
description = "A Python-to-Rust transpiler with a correctness guarantee."
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"typer>=0.12",
]

[project.optional-dependencies]
# F6 — the LLM repair loop. Off by default; see ADR-0007.
repair = ["anthropic>=0.34"]

[dependency-groups]
dev = [
"pytest>=8",
"hypothesis>=6",
"pyright>=1.1",
"maturin>=1.5",
"ruff>=0.6",
"mypy>=1.11",
]

# T-006 adds the console script, when ferrite/cli.py exists:
# [project.scripts]
# ferrite = "ferrite.cli:app"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
# Flat layout, not uv's default src/ layout (TRD §9).
packages = ["ferrite"]

[tool.pytest.ini_options]
testpaths = ["tests"]
markers = [
"milestone: exclude a fixture until its milestone begins (TESTING.md §2)",
]

[tool.ruff]
line-length = 100
target-version = "py312"

[tool.ruff.lint]
select = ["E", "F", "W", "I", "UP", "B", "SIM"]

[tool.mypy]
python_version = "3.12"
strict = true
files = ["ferrite"]
17 changes: 17 additions & 0 deletions pyrt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "pyrt"
description = "The Ferrite runtime: Python semantics for transpiled Rust."
version.workspace = true
edition.workspace = true
rust-version.workspace = true
publish = false

# pyrt deliberately does NOT enable pyo3/extension-module: that feature
# suppresses linking libpython, which would break `cargo test -p pyrt`. Only
# generated crates enable it (ADR-0009, TRD §2).
#
# Dependencies are added by the cards that need them (T-010 onward) using
# `.workspace = true`, so the pinned versions stay in one place (TRD §2).

[lints.rust]
unsafe_code = "forbid"
21 changes: 21 additions & 0 deletions pyrt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! `pyrt` — the Ferrite runtime.
//!
//! This crate is the contract that every emission rule is written against, which
//! is why it is built before the codegen that targets it (TRD §4). Its public
//! surface is enumerated in `docs/TRD.md` §4 and consumed by `docs/SEMANTICS.md`.
//!
//! The governing model: Python's mutable containers are reference types and
//! Rust's are value types, so every mutable container maps to an `Rc<RefCell<..>>`
//! newtype here. Cloning one produces an alias, which is exactly what Python
//! assignment does (ADR-0002).
//!
//! # Invariants
//!
//! This crate contains **zero** `unwrap()`, zero `expect()`, and zero panics. A
//! panic crossing the PyO3 boundary aborts the host Python interpreter, so the
//! lints below are load-bearing safety rather than style. Every fallible
//! operation returns a `PyResult`, and indexing raises `IndexError` instead of
//! panicking (TRD §4).

#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
#![forbid(unsafe_code)]
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Ferrite's test suite.

A real package, not a namespace directory: ``tests/property/`` does
``from tests.property.strategies import strategy_for`` (TESTING.md §1).
"""
1 change: 1 addition & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Fast unit tests: no subprocess, no cargo (TESTING.md §1)."""
7 changes: 7 additions & 0 deletions tests/unit/test_smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""T-001 — smoke test: the package imports and reports its development version."""

import ferrite


def test_imports() -> None:
assert ferrite.__version__ == "0.1.0.dev0"
8 changes: 8 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# tools/

Repository tooling. Deliberately not part of the `ferrite` package — nothing here
ships.

- `gen_semantics.py` (T-081) — regenerates the `python`/`rust` example pairs in
`docs/SEMANTICS.md` §3–§12 from `tests/golden/`. The golden fixture is the
source of truth; a doc example that does not match a golden is a bug in the doc.
Loading
Loading