Skip to content

Commit 6232e0f

Browse files
hyperpolymathclaude
andcommitted
feat: implement Phase 1 — linear resource analysis, violation detection, and wrapper generation
Rewrites the generic iseriser scaffold into a working ephapaxiser tool that: - Parses source files to find resource allocation/deallocation call sites (parser.rs) - Tracks ownership state and detects leaks, double-frees, use-after-free (analyzer.rs) - Generates Ephapax linear type wrapper structs enforcing exactly-once usage (wrapper_gen.rs) - Provides a domain-specific manifest format (ephapaxiser.toml) with resource definitions - Defines core ABI types: ResourceKind, LinearResource, OwnershipState, Violation, AnalysisResult All 45 tests pass (17 lib unit + 17 bin unit + 11 integration). Includes examples/safe-files/ with intentional bugs for demonstration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 349c619 commit 6232e0f

13 files changed

Lines changed: 2800 additions & 52 deletions

File tree

Cargo.lock

Lines changed: 677 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = ["Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>"]
77
description = "Enforce single-use linear type semantics on resources in existing code via Ephapax"
88
license = "PMPL-1.0-or-later"
99
repository = "https://github.com/hyperpolymath/ephapaxiser"
10-
keywords = ["ephapax", "acceleration", "code-generation"]
10+
keywords = ["ephapax", "linear-types", "resource-safety", "code-generation"]
1111
categories = ["command-line-utilities", "development-tools"]
1212

1313
[dependencies]
@@ -16,7 +16,7 @@ serde = { version = "1", features = ["derive"] }
1616
toml = "0.8"
1717
anyhow = "1"
1818
thiserror = "2"
19-
handlebars = "6"
19+
serde_json = "1"
2020
walkdir = "2"
2121

2222
[dev-dependencies]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-License-Identifier: PMPL-1.0-or-later
2+
# Example ephapaxiser manifest — demonstrates resource tracking for file operations.
3+
#
4+
# This manifest configures ephapaxiser to analyse file_ops.rs for proper
5+
# file descriptor handling (open/close pairs).
6+
7+
[project]
8+
name = "safe-files-example"
9+
10+
# Source files to analyse.
11+
[[sources]]
12+
name = "file-handler"
13+
path = "src/file_ops.rs"
14+
language = "rust"
15+
16+
# Resource definitions — file descriptors with open/close pair.
17+
[[resources]]
18+
name = "FileHandle"
19+
allocator = "open"
20+
deallocator = "close"
21+
kind = "file-descriptor"
22+
23+
# Also track database connections in this example.
24+
[[resources]]
25+
name = "DbConnection"
26+
allocator = "connect"
27+
deallocator = "disconnect"
28+
kind = "db-connection"
29+
30+
# Analysis configuration.
31+
[analysis]
32+
detect-leaks = true
33+
detect-double-free = true
34+
detect-use-after-free = true
35+
report-format = "text"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: PMPL-1.0-or-later
2+
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3+
//
4+
// Example source file for ephapaxiser analysis.
5+
//
6+
// This file demonstrates various resource usage patterns — some correct, some
7+
// intentionally buggy — so that ephapaxiser can detect violations.
8+
9+
/// Correct usage: file is opened and properly closed.
10+
fn correct_file_usage() {
11+
let fd = open("data.txt");
12+
// ... use the file ...
13+
close(fd);
14+
}
15+
16+
/// BUG: Resource leak — file is opened but never closed.
17+
fn leaky_file_usage() {
18+
let fd = open("leaked.txt");
19+
// ... forgot to close ...
20+
}
21+
22+
/// BUG: Double-free — file is closed twice.
23+
fn double_close() {
24+
let fd = open("double.txt");
25+
close(fd);
26+
close(fd);
27+
}
28+
29+
/// Correct database usage: connection is opened and properly disconnected.
30+
fn correct_db_usage() {
31+
let conn = connect("postgres://localhost/mydb");
32+
// ... query the database ...
33+
disconnect(conn);
34+
}
35+
36+
/// BUG: Database connection leak.
37+
fn leaky_db_usage() {
38+
let conn = connect("postgres://localhost/mydb");
39+
// ... forgot to disconnect ...
40+
}

0 commit comments

Comments
 (0)