6 releases (stable)
| new 2.1.0 | Feb 14, 2026 |
|---|---|
| 2.0.0 | Jan 8, 2026 |
| 1.0.2 | Nov 18, 2025 |
| 0.2.0 | Oct 21, 2025 |
#1872 in Programming languages
537 downloads per month
Used in 4 crates
(2 directly)
365KB
8K
SLoC
Safety property verification for transpiled Rust code.
Verifies memory safety, type safety, and other Rust safety guarantees.
Unsafe Code Auditing
This module provides comprehensive auditing of unsafe blocks in generated Rust code:
- Detection and counting of all unsafe blocks
- Confidence scoring for elimination potential
- Suggestions for safer alternatives
- Unsafe density metrics (<5 per 1000 LOC target)
Example
use decy_verify::{UnsafeAuditor, audit_rust_code};
let rust_code = r#"
fn example() {
unsafe {
let ptr = std::ptr::null_mut();
}
}
"#;
let report = audit_rust_code(rust_code).expect("Failed to audit");
println!("Unsafe blocks found: {}", report.unsafe_blocks.len());
println!("Unsafe density: {:.2}%", report.unsafe_density_percent);
What's New in 2.0
Release Date: January 2025
- 99.9% Test Pass Rate - 1,391 tests passing
- 95% Code Coverage - Comprehensive test suite
- DECY-220: Fixed malloc cast expression handling (
(int*)malloc(n)→Vec<T>) - Portable Tests: All test paths use
CARGO_MANIFEST_DIR - System Include Discovery: Automatic detection of
stdlib.h,string.h
cargo install decy
Quick Start
# Transpile a C file to Rust
decy transpile input.c -o output.rs
# Transpile an entire project
decy transpile-project src/ -o rust_output/
# Audit unsafe code
decy audit output.rs
Example:
// input.c
int add(int a, int b) {
return a + b;
}
decy transpile input.c
// Generated Rust (no unsafe!)
fn add(a: i32, b: i32) -> i32 {
a + b
}
Quality Metrics (PMAT)
| Metric | Score | Target |
|---|---|---|
| Rust Project Score | 92.9% (A+) | 90%+ |
| Repository Health | 84.5/100 (B+) | 80+ |
| Test Coverage | 95.1% | 80%+ |
| Test Pass Rate | 99.9% | 100% |
| Clippy Warnings | 0 | 0 |
Run quality analysis:
pmat rust-project-score
pmat repo-score
pmat analyze complexity
Installation
From crates.io (Recommended)
cargo install decy
From Source
git clone https://github.com/paiml/decy.git
cd decy
make install # Installs Rust + LLVM/Clang
cargo install --path crates/decy
Requirements
- Rust: 1.70+ (stable)
- LLVM/Clang: 14+ (for C parsing)
- Platform: Linux, macOS, Windows (WSL2)
Features
Core Transpilation
# Single file
decy transpile input.c -o output.rs
# Project with caching (10-20x faster on unchanged files)
decy transpile-project src/ -o rust_output/
decy cache-stats src/
Debug & Visualization
# Visualize C AST
decy debug --visualize-ast input.c
# Visualize ownership inference
decy debug --visualize-ownership input.c
# Step-through debugging
decy debug --step-through input.c
Safety Analysis
# Audit unsafe blocks
decy audit output.rs --verbose
# Generate verification book
decy verify --book-output ./book
MCP Integration
# Start MCP server for Claude Code
decy mcp-server --port 3000
Architecture
C Source → Parser → HIR → Analyzer → Ownership → Codegen → Rust
│ │ │ │ │
clang Rust-IR Types &T/&mut T Safe code
Crates
| Crate | Description |
|---|---|
decy-parser |
C AST parsing (clang-sys) |
decy-hir |
High-level IR (Rust-oriented) |
decy-analyzer |
Static analysis, type inference |
decy-ownership |
Ownership inference (pointers → references) |
decy-codegen |
Rust code generation |
decy-verify |
Safety verification |
decy-debugger |
AST/HIR visualization |
decy |
CLI binary |
Unsafe Minimization
Decy uses a 4-phase approach to minimize unsafe code:
| Phase | Reduction | Technique |
|---|---|---|
| 1. Pattern-Based | 100% → 50% | malloc/free → Box, arrays → Vec |
| 2. Ownership | 50% → 20% | Infer &T, &mut T from usage |
| 3. Lifetime | 20% → 10% | Infer <'a, 'b> annotations |
| 4. Safe Wrappers | 10% → <5% | Generate safe abstractions |
Target: <5 unsafe blocks per 1000 LOC
Development
EXTREME TDD Workflow
# RED: Write failing tests
git commit -m "[RED] DECY-XXX: Add failing tests"
# GREEN: Minimal implementation
git commit -m "[GREEN] DECY-XXX: Implement feature"
# REFACTOR: Meet quality gates
git commit -m "[REFACTOR] DECY-XXX: Clean up"
Quality Gates
make quality-gates # Run all checks
make test # Run tests
make coverage # Generate coverage report
Running Tests
cargo test --workspace # All tests
cargo test -p decy-ownership # Single crate
cargo llvm-cov --workspace # Coverage
Documentation
- Getting Started - Developer guide
- Specification - Technical spec
- Unsafe Strategy - How we reduce unsafe
- Roadmap - Development plan
License
MIT OR Apache-2.0
Acknowledgments
- C2Rust - Mozilla's C-to-Rust transpiler
- PMAT - Quality metrics toolkit
- Toyota Production System - Quality principles
Built with EXTREME quality standards
Dependencies
~10–26MB
~283K SLoC