From adf0e6cd7f5869639c0edb5c1052c47313050d82 Mon Sep 17 00:00:00 2001 From: Ralph Date: Fri, 3 Jul 2026 03:04:05 -0700 Subject: [PATCH] fix(deps): bson 3.x/mongodb feature mismatch broke default build (#5830 follow-up) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bson 3.x made serde support opt-in and mongodb's `compat-3-0-0` feature selects the crate's bson-2 internals — our direct bson dep and mongodb's internal bson type disagreed, breaking `Collection` methods under default features. Enable `serde` on the bson deps and switch mongodb's feature from `compat-3-0-0` to `bson-3` (+ required `compat-3-3-0`) so both sides resolve to the same bson major version. Co-Authored-By: Claude Sonnet 5 --- CHANGELOG.md | 4 ++++ CLAUDE.md | 2 +- Cargo.lock | 33 +++++------------------------ Cargo.toml | 2 +- crates/perry-ext-mongodb/Cargo.toml | 4 ++-- crates/perry-stdlib/Cargo.toml | 4 ++-- 6 files changed, 15 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 894c49d90e..7c23c615fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v0.5.1218 — bson 3.x/mongodb crate type mismatch broke the default build (#5830 follow-up) + +`deps(deps): bump bson from 2.15.0 to 3.1.0` (#5830) merged clean through CI but broke `cargo build`/`cargo check -p perry-stdlib` (and `perry-ext-mongodb`) under default features: two regressions stacked. (1) bson 3.x made serde support opt-in (`bson::Document` no longer implements `serde::{Serialize,Deserialize}` without the `serde` feature) — our direct `bson = "3.1"` dep in `perry-stdlib`/`perry-ext-mongodb` didn't request it, so every `serde_json::from_str::` call failed to typecheck. (2) The `mongodb` crate's `compat-3-0-0` feature (which we had carried over unchanged from the pre-bump Cargo.toml) actually selects the crate's **bson-2** internals (`mongodb::bson` re-exported bson 2.15.0), not bson 3 — so `Collection` methods (`find_one`, `update_one`, etc.) expected the *other* bson major version than the one our own code passed in, and `Cargo.lock` carried both bson 2.15.0 and 3.1.0 simultaneously. Fix: add `features = ["serde"]` to both crates' `bson` dependency, and swap the `mongodb` dependency's `compat-3-0-0` feature for `bson-3` (plus the now-required `compat-3-3-0` marker) so `mongodb`'s internal bson matches our direct dependency — collapses back to a single resolved `bson` version. Caught by `cargo check -p perry-stdlib -p perry-ext-mongodb` with default features; CI's `cargo-test` job apparently didn't exercise this combination for #5830, which is worth follow-up (tracked informally, no issue filed yet). + ## v0.5.1217 — switch inside async/generator state machines miscompiled (#5885, fixes #5868) Two state-machine defects, one shared fix. (1) A `yield`/`await` inside a switch case was silently lowered to `0`: the linearizer had no `Stmt::Switch` arm, so the switch fell to the catch-all, was emitted unsplit inside one state, and codegen's fallback lowered the residual `Expr::Yield` to `0.0` — `async f(x){ switch(x){ case 1: return await g() } }` resolved to `0` without suspending, and a generator `yield` inside a case vanished. (2) A loop-level `continue` inside a yield-free switch in a CPS'd loop survived as a raw `Stmt::Continue` the dispatch loop ignored, silently running the rest of the iteration. Both live in production paths since #5854 put async class methods through CPS; minifiers turn if-chains into switches routinely. New `desugar_switch_to_ifs` (generator/break_continue.rs): discriminant temp + match-index + guarded-`if` chain preserving JS switch semantics (single-eval discriminant, in-order first-match-wins tests, fallthrough, default-in-the-middle, `break` — incl. from nested if/try — via done-flag with remainder guarding; `continue`/`return`/`throw` pass through). Wired into a new yielding-switch `linearize_body` arm, a splice in `rewrite_break_continue_in_stmts` for continue-bearing yield-free switches (`next_local_id` threaded through), and the labeled arm (`break label` → plain break in a labeled switch). e2e: `crates/perry/tests/issue_5868_switch_state_machine.rs` (9 scenarios vs node). Note: this PR's labeled run showed parity/smokes/doc-tests failing to BUILD with the pre-existing #5466 E0308 feature-combo breakage (#5872) — zero parity tests executed; compiler-output-regression and the full cargo-test suite are green. diff --git a/CLAUDE.md b/CLAUDE.md index bbc3350085..243fdbc33f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,7 +8,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co Perry is a native TypeScript compiler written in Rust that compiles TypeScript source code directly to native executables. It uses SWC for TypeScript parsing and LLVM for code generation. -**Current Version:** 0.5.1217 +**Current Version:** 0.5.1218 ## TypeScript Parity Status diff --git a/Cargo.lock b/Cargo.lock index 08e73b8dc7..c838df639b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -817,29 +817,6 @@ dependencies = [ "alloc-stdlib", ] -[[package]] -name = "bson" -version = "2.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969a9ba84b0ff843813e7249eed1678d9b6607ce5a3b8f0a47af3fcf7978e6e" -dependencies = [ - "ahash 0.8.12", - "base64", - "bitvec", - "getrandom 0.2.17", - "getrandom 0.3.4", - "hex", - "indexmap", - "js-sys", - "once_cell", - "rand 0.9.4", - "serde", - "serde_bytes", - "serde_json", - "time", - "uuid", -] - [[package]] name = "bson" version = "3.1.0" @@ -854,6 +831,7 @@ dependencies = [ "indexmap", "js-sys", "rand 0.9.4", + "serde", "serde_bytes", "simdutf8", "thiserror 2.0.18", @@ -4603,7 +4581,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da0cd419a51a5fb44819e290fbdb0665a54f21dead8923446a799c7f4d26ad9" dependencies = [ - "bson 2.15.0", + "bson", "mongocrypt-sys", "once_cell", "serde", @@ -4623,7 +4601,7 @@ checksum = "276ba0cd571553d1f6936c6f180964776ece6ab7507dc8765f8a9c9c49d8cd00" dependencies = [ "base64", "bitflags 2.12.1", - "bson 2.15.0", + "bson", "derive-where", "derive_more", "futures-core", @@ -5797,7 +5775,7 @@ dependencies = [ name = "perry-ext-mongodb" version = "0.5.1217" dependencies = [ - "bson 3.1.0", + "bson", "futures-util", "mongodb", "perry-ffi", @@ -6028,7 +6006,7 @@ dependencies = [ "base64", "bcrypt", "brotli", - "bson 3.1.0", + "bson", "bytes", "cbc", "chacha20poly1305", @@ -7677,7 +7655,6 @@ version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ - "indexmap", "itoa", "memchr", "serde", diff --git a/Cargo.toml b/Cargo.toml index 6a364223fa..be45408952 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -301,7 +301,7 @@ strip = false codegen-units = 16 [workspace.package] -version = "0.5.1217" +version = "0.5.1218" edition = "2021" license = "MIT" repository = "https://github.com/PerryTS/perry" diff --git a/crates/perry-ext-mongodb/Cargo.toml b/crates/perry-ext-mongodb/Cargo.toml index 408618e1aa..11e454a416 100644 --- a/crates/perry-ext-mongodb/Cargo.toml +++ b/crates/perry-ext-mongodb/Cargo.toml @@ -10,8 +10,8 @@ crate-type = ["staticlib", "rlib"] [dependencies] perry-ffi.workspace = true -mongodb = { version = "3.7", default-features = false, features = ["compat-3-0-0", "rustls-tls", "dns-resolver"] } -bson = "3.1" +mongodb = { version = "3.7", default-features = false, features = ["bson-3", "compat-3-3-0", "rustls-tls", "dns-resolver"] } +bson = { version = "3.1", features = ["serde"] } tokio = { workspace = true } futures-util = "0.3" serde_json = "1" diff --git a/crates/perry-stdlib/Cargo.toml b/crates/perry-stdlib/Cargo.toml index e8e4fbcd29..8a40bfbb2c 100644 --- a/crates/perry-stdlib/Cargo.toml +++ b/crates/perry-stdlib/Cargo.toml @@ -377,8 +377,8 @@ rustls-pemfile = { version = "2", optional = true } # Database sqlx = { version = "0.9.0", default-features = false, features = ["runtime-tokio", "mysql", "postgres", "chrono"], optional = true } redis = { version = "1.2", features = ["tokio-comp", "connection-manager"], optional = true } -mongodb = { version = "3.7", default-features = false, features = ["compat-3-0-0", "rustls-tls", "dns-resolver"], optional = true } -bson = { version = "3.1", optional = true } +mongodb = { version = "3.7", default-features = false, features = ["bson-3", "compat-3-3-0", "rustls-tls", "dns-resolver"], optional = true } +bson = { version = "3.1", optional = true, features = ["serde"] } rusqlite = { version = "0.37", features = ["bundled", "column_decltype", "limits", "session"], optional = true } # Crypto