Skip to content
Closed
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
30 changes: 16 additions & 14 deletions Cargo.lock

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

25 changes: 11 additions & 14 deletions src/rust/proof_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ mod chapel_ffi {
let start = start.clone();
std::thread::spawn(move || {
start.wait();
let strategy = ChapelParallelSearch::new().expect("real Chapel runtime");
let strategy =
ChapelParallelSearch::new().expect("real Chapel runtime");
assert_eq!(ChapelParallelSearch::available_prover_count(), 0);
for _ in 0..2 {
assert!(strategy.available());
Expand Down Expand Up @@ -414,10 +415,8 @@ mod chapel_ffi {
// No global environment mutation races with other Rust tests, and
// no external prover can be dispatched by this allocation/free probe.
let empty_path = tempfile::tempdir().expect("empty prover search directory");
let mut command = real_probe_command(
"real_search_without_provers_fails_and_frees_result",
CHILD,
);
let mut command =
real_probe_command("real_search_without_provers_fails_and_frees_result", CHILD);
command.env("PATH", empty_path.path());
run_real_probe(
&mut command,
Expand Down Expand Up @@ -478,7 +477,10 @@ mod chapel_ffi {
matches!(stopped_before_cleanup, Ok(true)),
"deadline returned with a live or unobservable prover: {stopped_before_cleanup:?}"
);
assert!(elapsed < Duration::from_secs(3), "deadline took {elapsed:?}");
assert!(
elapsed < Duration::from_secs(3),
"deadline took {elapsed:?}"
);
let result = result.expect("native timeout returns a failed search result");
assert!(!result.success);
assert_eq!(
Expand All @@ -500,17 +502,12 @@ mod chapel_ffi {
.expect("write finite prover");
std::fs::set_permissions(&prover, std::fs::Permissions::from_mode(0o700))
.expect("make finite prover executable");
let mut command = real_probe_command(
"real_search_deadline_stops_the_owned_prover",
CHILD,
);
let mut command =
real_probe_command("real_search_deadline_stops_the_owned_prover", CHILD);
command
.env("PATH", fixture.path())
.env(PID_FILE, fixture.path().join("prover.pid"));
run_real_probe(
&mut command,
"ECHIDNA_REAL_CHAPEL_DEADLINE_PROBE_COMPLETED",
);
run_real_probe(&mut command, "ECHIDNA_REAL_CHAPEL_DEADLINE_PROBE_COMPLETED");
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/zig_ffi/chapel_bridge.zig
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fn callOnOwner(owner: anytype, comptime function: anytype, args: anytype, result
result: @TypeOf(result),

fn run(raw: *anyopaque) void {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
self.result.* = @call(.auto, function, self.arguments);
}
};
Expand Down Expand Up @@ -650,7 +651,8 @@ const CallerAllocator = struct {
}

fn alloc(raw: *anyopaque, len: usize, alignment: std.mem.Alignment, ret_addr: usize) ?[*]u8 {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
if (!self.record() or self.allocations >= self.fail_after) return null;
const pointer = std.heap.c_allocator.rawAlloc(len, alignment, ret_addr) orelse return null;
self.allocations += 1;
Expand All @@ -659,7 +661,8 @@ const CallerAllocator = struct {
}

fn resize(raw: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) bool {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
_ = self.record();
_ = memory;
_ = alignment;
Expand All @@ -669,7 +672,8 @@ const CallerAllocator = struct {
}

fn remap(raw: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
_ = self.record();
_ = memory;
_ = alignment;
Expand All @@ -679,7 +683,8 @@ const CallerAllocator = struct {
}

fn free(raw: *anyopaque, memory: []u8, alignment: std.mem.Alignment, ret_addr: usize) void {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
_ = self.record();
// The backing allocator is cross-thread safe so a failed assertion
// never requires corrupting memory or leaking the test allocation.
Expand Down
12 changes: 8 additions & 4 deletions src/zig_ffi/runtime_owner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ const Probe = struct {
}

fn work(raw: *anyopaque) void {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
self.wrong_thread = self.wrong_thread or self.init_id != std.Thread.getCurrentId();
self.calls += 1;
}
Expand Down Expand Up @@ -239,7 +240,8 @@ test "shutdown drains accepted work and refuses new work before joining" {
shutdown_failed: bool = false,

fn work(raw: *anyopaque) void {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
self.mutex.lock();
self.entered = true;
self.changed.broadcast();
Expand Down Expand Up @@ -311,7 +313,8 @@ test "owner callbacks cannot re-enter or finalize themselves" {
stop_refused: bool = false,

fn work(raw: *anyopaque) void {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
var nested = Work{ .context = self.probe, .run = Probe.work };
self.call_refused = if (self.owner.call(&nested)) |_| false else |err| err == error.ReentrantCall;
self.stop_refused = if (self.owner.shutdown()) |_| false else |err| err == error.ReentrantCall;
Expand Down Expand Up @@ -358,7 +361,8 @@ test "a nonowner process-exit request refuses active work without a join cycle"
exit_refused: bool = false,

fn work(raw: *anyopaque) void {
const self: *@This() = @ptrCast(@alignCast(raw));
// hypatia: allow code_safety/zig_ptr_cast -- raw is the type-erased *@This() this callback was registered with
const self: *@This() = @ptrCast(@alignCast(raw)); // hypatia: allow code_safety/zig_align_cast -- same pointer, so @This() alignment holds
self.mutex.lock();
self.entered = true;
self.changed.broadcast();
Expand Down
Loading