Skip to content
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/miri.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:
pull_request:
paths:
# The FFI-free crate set covered by MIRI_CRATES in scripts/rust-miri.ts
# The crate set covered by MIRI_CRATES in scripts/rust-miri.ts
- "src/ast/**"
- "src/base64/**"
- "src/clap/**"
Expand All @@ -22,6 +22,7 @@ on:
- "src/ptr/**"
- "src/resolve_builtins/**"
- "src/shell_parser/**"
- "src/threading/**"
- "src/wyhash/**"
- "scripts/rust-miri.ts"
- "Cargo.toml"
Expand Down
16 changes: 10 additions & 6 deletions scripts/rust-miri.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bun
/**
* `cargo miri test` for the FFI-free crate set.
* `cargo miri test` for the crates Miri can interpret end to end.
*
* Miri interprets MIR and catches UB (use-after-free, out-of-bounds,
* uninit reads, data races, aliasing violations) at runtime. It cannot call
* foreign functions, so this only covers the pure-Rust corner of the
* workspace — which is also where `unsafe` density is highest.
* foreign functions beyond the libc subset it ships shims for, so this only
* covers the (nearly) pure-Rust corner of the workspace — which is also where
* `unsafe` density is highest.
*
* Aliasing model: `-Zmiri-tree-borrows`, not the default Stacked Borrows.
* Stacked Borrows invalidates every raw pointer derived from `&mut self` the
Expand All @@ -27,9 +28,11 @@ import { resolve } from "node:path";
const repo = resolve(import.meta.dirname, "..");

// Crates that pass `cargo miri test` under Tree Borrows. To add one it must
// (a) have at least one `#[test]`, (b) compile under `--cfg test`, (c) not
// call into `extern "C"` at test runtime — Miri reports
// `unsupported operation: can't call foreign function` if it does.
// (a) have at least one `#[test]`, (b) compile under `--cfg test`, (c) only
// call `extern "C"` functions Miri ships shims for at test runtime (libc's
// futex syscall and thread APIs, as bun_threading does, are fine; anything
// vendored is not) — Miri reports
// `unsupported operation: can't call foreign function` otherwise.
const MIRI_CRATES = [
"bun_ast",
"bun_base64",
Expand All @@ -44,6 +47,7 @@ const MIRI_CRATES = [
"bun_ptr",
"bun_resolve_builtins",
"bun_shell_parser",
"bun_threading",
"bun_wyhash",
];

Expand Down
20 changes: 16 additions & 4 deletions src/bundler/LinkerContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,9 +1366,17 @@ impl SourceMapDataTask {
// pointee outlives every task (joined via `line_offset_wait_group`).
let ctx = task.ctx.expect("SourceMapDataTask.ctx");
scopeguard::defer! {
// Both `&self` methods (atomic ops) — safe via `ParentRef::Deref`.
ctx.mark_pending_task_done();
ctx.source_maps.line_offset_wait_group.finish();
// SAFETY: the linker is blocked in `line_offset_wait_group.wait()`
// (or will be) until this finish, so the group is live; it frees the
// tasks as soon as `wait()` returns (`generate_chunks_in_parallel`),
// which is why this goes through `finish_raw` and is the last
// statement to touch `ctx`.
unsafe {
WaitGroup::finish_raw(
&raw const (*ctx.as_const_ptr()).source_maps.line_offset_wait_group,
)
};
}

// SAFETY: ctx is BundleV2.linker; container_of recovers the parent. We
Expand Down Expand Up @@ -1403,9 +1411,13 @@ impl SourceMapDataTask {
// pointee outlives every task (joined via `quoted_contents_wait_group`).
let ctx = task.ctx.expect("SourceMapDataTask.ctx");
scopeguard::defer! {
// Both `&self` methods (atomic ops) — safe via `ParentRef::Deref`.
ctx.mark_pending_task_done();
ctx.source_maps.quoted_contents_wait_group.finish();
// SAFETY: as in `run_line_offset`, for `quoted_contents_wait_group`.
unsafe {
WaitGroup::finish_raw(
&raw const (*ctx.as_const_ptr()).source_maps.quoted_contents_wait_group,
)
};
}

// SAFETY: see `run_line_offset` — raw-ptr container_of, no `&mut`
Expand Down
Loading