SlimePython PoC 0–11 — Hybrid Bit-Exact Isolate, measured
Real source, conversion code, measurements and reproduction steps for PoC 0–11, run on real hardware (WSL2 / CPython 3.12.3 / RustPython 0.5.0 / wasmtime 40 / x86_64). All figures are measured on a single machine with a pinned CPython. Per the AI-Trap-17 (fabricating empirical claims) policy, we do not claim 100% over the untested space.
A tool that converts the Python you wrote into Rust that produces exactly the same results. It proves 1-bit-identical output via SHA-256. No need to rewrite cleanly; dynamic parts run as-is in a safe Python sandbox.
Hand-porting Python to Rust drifts, but this generates Rust whose output is SHA-256 1-bit-identical. Dynamic parts are delegated to a CPython Isolate (95-99% under a pinned runtime); true nondeterminism is explicitly rejected. PoC 40/40 bit-exact, proven.
Not all-Python-to-Rust but static core→pure Rust (100% bit-exact) / dynamic→deterministic CPython Isolate / nondeterminism→reject (Hybrid Bit-Exact Isolate). Extends "don't understand the meaning, transcribe the structure" to the dynamic region — letting CPython itself generate the meaning.
Source projected as structure onto Slot IR. The dynamic region is delegated to a pinned CPython (PYTHONHASHSEED=0, fixed seed/clock, pinned libm) deterministic Isolate, joined at the boundary by canonical encoding. Under the AI-Trap-17 (fabricated empirical claims) avoidance policy, 100% is promised only for the static region.
📋 "Ask your AI at this level" copies this page's explanation with an instruction matched to the level you picked. Paste it into your own AI (Claude · GPT · Gemini · Grok) to dig deeper at that resolution.
0. Model (2 regions + 2 tiers)
| Region | Target | Guarantee |
|---|---|---|
| Static | Slot IR → pure Rust | structurally bit-exact |
| Dynamic | kept as Python, delegated to a deterministic CPython Isolate | bit-exact in the same environment (contradictions preserved; only non-determinism rejected) |
| tier | impl | fidelity | speed | portability |
|---|---|---|---|---|
| Full | static-CPython Isolate | 40/40 bit-exact | at/above python3 | x86_64/glibc |
| Light | RustPython → WASM | 19/20 (only abc message wording) | ~3–6× | portable to WASM/aarch64 |
0.5 §13 static lift — conditional acceptance of dynamic syntax
Ahead of delegating to the §14 Isolate, §13 Phase 1 lowers four HIGH dynamic categories to a static-equivalent form while preserving bit-exactness (a new Step 1.5). Accepted constructs are verified twice (Python original ≡ Python lowered, then Python ≡ native Rust ≡ WASI Rust) before rejoining the normal pipeline. 50/50 lift + 25/25 reject = 75/75 PASS (three-way WASI match). The MT19937 and SHA-256 runtimes are pure-Rust, with zero external crate dependency.
| Lift category | Condition (precheck) | Lowering / Rust output |
|---|---|---|
getattr(o,"x") / setattr / hasattr | 2nd arg is a string literal (variable / f-string / runtime concat → REJECT) | Expanded to direct attribute access; hasattr/default-getattr fields become Option<T> |
threading.Lock / Thread sequential | with lock: no-op, or strict triple t = Thread(target=fn, args=tup); t.start(); t.join() (Condition/Event/Barrier/Queue/daemon/two starts before a join → REJECT) | Lock dropped; Thread triple replaced with fn(*tup) |
random.seed(N) + random.randint | seed is a compile-time integer literal (time/variable seed/sample/gauss → REJECT) | CPython-bit-exact MT19937 + getrandbits + _randbelow embedded as a _pyrandom module (zero external crate) |
type("Name", (Base,), {...}) one-shot | Module-top-level with all three args compile-time constant (variable name/dynamic bases/non-literal dict key/function-local/user metaclass → REJECT) | Expanded to class Name(Base): ...; parent methods copied into each derived Rust struct |
Out of scope (REJECT): eval/exec, dynamic metaclass with runtime args, arbitrary *args/**kwargs, globals()/locals(), C extensions, unseeded random. Phase 2 candidates: __getattr__/__setattr__ override with enumerable dispatch, module-load monkey patching.
1. Isolate runner (shared by all PoCs, ~20 lines)
The dynamic Python fragment is handed as-is to an embedded CPython under deterministic constraints; stdout is compared to python3 by SHA-256.
// PoC 2/3 Isolate runner — PYTHONHASHSEED=0, run the .py in embedded CPython
use pyo3::prelude::*;
fn main() {
std::env::set_var("PYTHONHASHSEED", "0");
std::env::set_var("PYTHONUNBUFFERED", "1");
let path = std::env::args().nth(1).unwrap();
let code = std::fs::read_to_string(&path).unwrap();
Python::with_gil(|py| {
if let Err(e) = py.run_bound(&code, None, None) { e.print(py); std::process::exit(1); }
let _ = py.run_bound("import sys\nsys.stdout.flush()", None, None);
});
}
Dynamic sample (constructs §13 rejected — still bit-exact)
# monkey patch + decorator + kwargs forwarding (PoC 2 #15) def add_log(fn): def wrapped(*args, **kwargs): return f"LOG:{fn(*args, **kwargs)}" return wrapped class Service: def compute(self, x): return x * 100 Service.compute = add_log(Service.compute) # runtime class rewrite print(Service().compute(7)) # LOG:700 — Python==Isolate, SHA-256 match
2. Correctness — 40/40 bit-exact cumulative
| PoC | Scope | Result |
|---|---|---|
| 1 | Any ×5 | 5/5 |
| 2 | *args/**kwargs + dynamic getattr/setattr + monkey ×15 | 15/15 |
| 3 | 20 real-world dynamic (metaclass / descriptors / dataclass / generators / eval-exec …) | 20/20 |
3. Full tier speed — “slow” was a build choice (PoC 4→6)
The embedding first looked ~18–38% slower than python3 on hot loops (the PoC 4 crossover). Root cause: the PIC in the shared libpython.so (GOT/PLT indirection). /usr/bin/python3 statically embeds libpython (non-PIC) (no libpython line in ldd).
# PoC 6: static build from source = production recipe (no stubs, PIE/ASLR kept) ./configure --prefix=<pfx> --disable-shared --enable-optimizations --with-lto make -j$(nproc) && make altinstall # link the Isolate against the static libpython (PyO3 shared=false / prepare_freethreaded_python) PYO3_CONFIG_FILE=pyo3-source.cfg LIBPY_KIND=source cargo build --release
| M (work/launch) | iso_source / python3 |
|---|---|
| 1 (short-lived) | 0.60× (faster) |
| 1,000,000 (hot) | 0.99× (at parity) |
Only the shared .so is slow (1.19–1.34×) — isolated with a Py_BytesMain runner (identical CLI path) + distro's non-PIC / PIC / .so 3 variants (PoC 4.5/5).
4. Light tier — RustPython → WASM (PoC 7/8)
19/20 bit-exact on the same samples (only difference: the abc exception message wording; semantics match). Cross-compiled to wasm32-wasip1 and run under wasmtime — wasm = native RustPython 20/20. The Light tier runs on WASI, where embedding CPython cannot be built.
5. Auto-routing + runtime profile (PoC 9/10)
# PoC 9 router (static): reject = non-determinism only. 0 mis-routes / 20
if target in ("wasm","aarch64"): return Decision("light", "Full unavailable")
if sig.unsupported: return Decision("full", "unsupported")
if sig.exc_text_dep and exact_exceptions: return Decision("full", "exact exception text")
if sig.hot_loop and perf == "fast": return Decision("full", "avoid hot-loop slowdown")
return Decision("light", "Light is sufficient")
PoC 10: compute-heavy code invisible to static analysis (range(var), recursion) is caught by a runtime profile → routed to Full next time. hot_varrange Light 633ms→Full 212ms (3×), hot_fib 1260ms→135ms (9×).
6. What we reject = non-determinism only (PoC 11, 4 measured classes)
| Class | Examples | Handling |
|---|---|---|
| A. preserved by default | hash/set order (seed0), dict, float math, GIL threading | bit-exact as-is |
| B. preserved via Isolate injection | unseeded random, time | deterministic via fixed seed/clock (value canonicalized) |
| C. preserved in same env only | os.environ, file I/O, subprocess | same env matches; cross-env is the CI envelope |
| D. truly non-deterministic | id(), default repr (address), getpid, uuid4 | outside the guarantee (= Python's nature) |
“Contradictions preserved, only non-determinism rejected.” The irreducible core is just memory addresses, process ID, OS entropy.
7. Download (full reproduction)
Reproduction needs CPython 3.12 / Rust 1.93 / PyO3 0.22 / RustPython 0.5 / wasmtime. See run_*.sh in each PoC directory. Questions: contact us.
