Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

treesitter: Worker-pinned treesitter parsing (#62784)

Cameron Mcloughlin2040e0de59db
diff --git a/Cargo.lock b/Cargo.lock
index 2dd98c0350f..edf1fd20a9f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -539,7 +539,7 @@ dependencies = [
"serde_json",
"serde_json_lenient",
"settings",
- "shlex",
+ "shlex 1.3.0",
"streaming_diff",
"task",
"telemetry",
@@ -2216,7 +2216,7 @@ dependencies = [
"quote",
"regex",
"rustc-hash 2.1.1",
- "shlex",
+ "shlex 1.3.0",
"syn 2.0.117",
]
@@ -2234,7 +2234,7 @@ dependencies = [
"quote",
"regex",
"rustc-hash 2.1.1",
- "shlex",
+ "shlex 1.3.0",
"syn 2.0.117",
]
@@ -2909,14 +2909,14 @@ dependencies = [
[[package]]
name = "cc"
-version = "1.2.49"
+version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215"
+checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d"
dependencies = [
"find-msvc-tools",
"jobserver",
"libc",
- "shlex",
+ "shlex 2.0.1",
]
[[package]]
@@ -4180,36 +4180,36 @@ dependencies = [
[[package]]
name = "cranelift-assembler-x64"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3cd990d8a6304475bbad64534a0d418f5572f44d5f011437e6b9f1ee7d5c2570"
+checksum = "5f8e1303ae2128891cb59691a74de4547dd208bc8511a2f287cca2b93bb3c728"
dependencies = [
"cranelift-assembler-x64-meta",
]
[[package]]
name = "cranelift-assembler-x64-meta"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ccabe4636007296721080e02d7dab46d4319638ec4e3f6f7402fcb46dc5122c6"
+checksum = "58b2740a5936332028d9a1e8f29a199de2fd386e426d44da5fea70cf8e3f8e75"
dependencies = [
"cranelift-srcgen",
]
[[package]]
name = "cranelift-bforest"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "da7ed173c870c0aea202a9830880156905a028a88df076e35ce383a8acbf90a7"
+checksum = "37fd128d3629fb105e433bda09744c5a2959cd1da04617a455c4cc17dff1ebef"
dependencies = [
"cranelift-entity",
]
[[package]]
name = "cranelift-bitset"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "800cc586df98b12c502e76707c96565e40629a5322eaa15aaa34ba05f5721e31"
+checksum = "24a88f6d5a6cf6fcbc6386415d48948094721dfa4585d6615938b11ca938f20a"
dependencies = [
"serde",
"serde_derive",
@@ -4217,9 +4217,9 @@ dependencies = [
[[package]]
name = "cranelift-codegen"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ae93f863f9094ae34d2567f9edb0ae2c41d35228b286598354dd78b198868ebd"
+checksum = "daa4a357d030bdd586d8fe3da56b394f7f6b6ded506e59f945e7b32b1e126b71"
dependencies = [
"bumpalo",
"cranelift-assembler-x64",
@@ -4247,9 +4247,9 @@ dependencies = [
[[package]]
name = "cranelift-codegen-meta"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "38c505162bcf77dcb859905b3eac56a1917fc3cf326424fb06e7732031e3a8ae"
+checksum = "4121e36a8757dea6fb237435ee5095eba25bc13ecc2eaee57eb9bffd4b27784f"
dependencies = [
"cranelift-assembler-x64-meta",
"cranelift-codegen-shared",
@@ -4260,24 +4260,24 @@ dependencies = [
[[package]]
name = "cranelift-codegen-shared"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e3b786958bcb79bdb5fbae095af58f0c2da7d7895c475c991f6a6bb5a9c7e6d9"
+checksum = "5173265fc30b9e42205cf06dfca9a272ee949667ce4115d975ed2c08d466e2f8"
[[package]]
name = "cranelift-control"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2faf9a5009bce7f725ce2af7a08c4883ebac6af933e7e0aa7d84f976f4e6deb5"
+checksum = "9b6ca8a393e66dc13f915c6f456bdcf496d78fac4995792f7022b7806352d7a4"
dependencies = [
"arbitrary",
]
[[package]]
name = "cranelift-entity"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "017271194ba5e101d626560d0d6767efd341468d1ba0f4d015f19fe64020b65b"
+checksum = "e609d9ba416bc26d774f343295a1d411515248a6a6d83d5f7492a0dd919569fa"
dependencies = [
"cranelift-bitset",
"serde",
@@ -4286,9 +4286,9 @@ dependencies = [
[[package]]
name = "cranelift-frontend"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f80847f0929967f0cec82f9e0543b3901e0f0063690405891f22107b5a130fd8"
+checksum = "90a3a277b1a0aff1123f6bae61c080a4bcb6df964829ed427f98e18dff14257f"
dependencies = [
"cranelift-codegen",
"log",
@@ -4298,15 +4298,15 @@ dependencies = [
[[package]]
name = "cranelift-isle"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "75904abbc0e7b46d20f7a49c8042c8a4481c0db4253b99889c723c566295d506"
+checksum = "be53dd9b3a4cbeb9ced45c4a543ea8417ccfb334c3ba1cbb2233f4b25fb2531f"
[[package]]
name = "cranelift-native"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6e0135923540574362e16f01bf40000664263840991039ff3041ba717de6cf3a"
+checksum = "ca62ab1d9f48cad97da5843b913ccf96c3dfde935af5d750cb5a6d367ccfb262"
dependencies = [
"cranelift-codegen",
"libc",
@@ -4315,9 +4315,9 @@ dependencies = [
[[package]]
name = "cranelift-srcgen"
-version = "0.123.12"
+version = "0.123.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93fb12f76c482e034f6ebefa843c914e74112f088215d8d36d33a649f9fab99b"
+checksum = "a13b72860f54a2a19d3756bd47575fd8bddeafd6e5bbbf16372cdfebc482628a"
[[package]]
name = "crash-context"
@@ -5179,7 +5179,7 @@ dependencies = [
"serde_json_lenient",
"serde_yaml",
"settings",
- "shlex",
+ "shlex 1.3.0",
"ui",
"util",
"walkdir",
@@ -5288,7 +5288,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users 0.5.2",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -6100,7 +6100,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -6659,9 +6659,9 @@ dependencies = [
[[package]]
name = "find-msvc-tools"
-version = "0.1.5"
+version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
+checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890"
[[package]]
name = "fixedbitset"
@@ -7321,7 +7321,7 @@ dependencies = [
"gobject-sys",
"libc",
"system-deps",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -8082,6 +8082,7 @@ dependencies = [
"log",
"parking_lot",
"raw-window-handle",
+ "scheduler",
"uuid",
"wasm-bindgen",
"wasm-bindgen-futures",
@@ -10979,7 +10980,7 @@ dependencies = [
"regex",
"serde",
"serde_json",
- "shlex",
+ "shlex 1.3.0",
"tempfile",
"tokio",
"toml 0.5.11",
@@ -11760,7 +11761,7 @@ version = "0.50.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -14670,9 +14671,9 @@ checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae"
[[package]]
name = "pulley-interpreter"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "558181096e0df4984f45cfc3a7087052df4a61c36089b135a08ceca9cbd352fb"
+checksum = "2662666315cb90dfb4d99a652ee053d4d8598f71c474209e84da031ca56ae5a4"
dependencies = [
"cranelift-bitset",
"log",
@@ -14682,9 +14683,9 @@ dependencies = [
[[package]]
name = "pulley-macros"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5d52e2f14e168d75cdabe9bd5fb1ff18a1b119dc6699684aee895dbc3524da9"
+checksum = "bb9a7d9ed2618f94b6d054aba3eb2768c9b489fe16b4ef8847fbc6ed41b707bb"
dependencies = [
"proc-macro2",
"quote",
@@ -14810,7 +14811,7 @@ dependencies = [
"once_cell",
"socket2 0.6.3",
"tracing",
- "windows-sys 0.60.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -15486,7 +15487,7 @@ dependencies = [
"serde",
"serde_json",
"settings",
- "shlex",
+ "shlex 1.3.0",
"smol",
"task",
"telemetry",
@@ -15966,7 +15967,7 @@ dependencies = [
"errno 0.3.14",
"libc",
"linux-raw-sys 0.11.0",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -16240,6 +16241,7 @@ dependencies = [
"futures 0.3.32",
"parking_lot",
"rand 0.9.4",
+ "wasm_thread",
"web-time",
]
@@ -16672,16 +16674,16 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.145"
+version = "1.0.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
+checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"
dependencies = [
"indexmap 2.14.0",
"itoa",
"memchr",
- "ryu",
"serde",
"serde_core",
+ "zmij",
]
[[package]]
@@ -17090,6 +17092,12 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+[[package]]
+name = "shlex"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
+
[[package]]
name = "sidebar"
version = "0.1.0"
@@ -18591,7 +18599,7 @@ dependencies = [
"getrandom 0.3.4",
"once_cell",
"rustix 1.1.2",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -18699,7 +18707,7 @@ dependencies = [
"serde_json",
"settings",
"shellexpand",
- "shlex",
+ "shlex 1.3.0",
"task",
"terminal",
"theme",
@@ -19541,13 +19549,11 @@ dependencies = [
[[package]]
name = "tree-sitter"
-version = "0.26.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4dab76d0b724ba557954125188cf0633a1ca43199ced82d95c7b9c32cc3de1f3"
+version = "0.27.0"
+source = "git+https://github.com/tree-sitter/tree-sitter?rev=dff1fd868c750dbbae179fcd5c43ce987e4e0528#dff1fd868c750dbbae179fcd5c43ce987e4e0528"
dependencies = [
"cc",
"regex",
- "regex-syntax",
"serde_json",
"streaming-iterator",
"tree-sitter-language",
@@ -19701,9 +19707,8 @@ dependencies = [
[[package]]
name = "tree-sitter-language"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c4013970217383f67b18aef68f6fb2e8d409bc5755227092d32efb0422ba24b8"
+version = "0.1.8"
+source = "git+https://github.com/tree-sitter/tree-sitter?rev=dff1fd868c750dbbae179fcd5c43ce987e4e0528#dff1fd868c750dbbae179fcd5c43ce987e4e0528"
[[package]]
name = "tree-sitter-md"
@@ -20196,7 +20201,7 @@ dependencies = [
"serde",
"serde_json",
"serde_json_lenient",
- "shlex",
+ "shlex 1.3.0",
"smol",
"take-until",
"tempfile",
@@ -20764,9 +20769,9 @@ dependencies = [
[[package]]
name = "wasmtime"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4b4442dc12aa2473def8334f0e0f2b489be52c52507c938bbdc8be69ded4ded6"
+checksum = "93d881c5dcff5f230368d84fcf110ca25fe47badc694e7d559c3891492159916"
dependencies = [
"addr2line",
"anyhow",
@@ -20812,9 +20817,9 @@ dependencies = [
[[package]]
name = "wasmtime-c-api-impl"
-version = "36.0.9"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e5e71e971a27df819171b79597c0f1826fc7cf2c168111c64dbc5505a1ffbda7"
+checksum = "ae273769c129ee7ca247c3d849dfdda9957fece8c93307a4ef727ca0e35d62c3"
dependencies = [
"anyhow",
"log",
@@ -20825,9 +20830,9 @@ dependencies = [
[[package]]
name = "wasmtime-environ"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5d881c3d6205898a226cc487b117f23b9ed1c7da39952d65bd5eeb6745b3789c"
+checksum = "a4b25534a3ff9dd844701c2bc997f76cb1f97bf2af0546a7066ae96f49c2e068"
dependencies = [
"anyhow",
"cpp_demangle",
@@ -20852,18 +20857,18 @@ dependencies = [
[[package]]
name = "wasmtime-internal-asm-macros"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5ab1876bcfa51d6a05dea1c13933f53cbc1e316c783fddebc859f56a736eae07"
+checksum = "1d02832d760351fb3a1aa99eb8f7b95596c0f4e4e52df1547fcdb295ea5c780c"
dependencies = [
"cfg-if",
]
[[package]]
name = "wasmtime-internal-c-api-macros"
-version = "36.0.9"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "20b9553165039d365931a998d9b60278cc968ba9d81531cecde8ffc3effa1fe3"
+checksum = "8fcd4661fe1146d284b5b82d26d12c4b8056b1f0aa8a3a8f6d33e9597abf147f"
dependencies = [
"proc-macro2",
"quote",
@@ -20871,9 +20876,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-component-macro"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ae1407944a0b13a8a77930b5b951aa7134beccecad7efac1ef9f03adb7d1a0f"
+checksum = "ba2ed6dbe24607573f7bcc59222f3bc2e7f7d31609466055c67b9484045a374a"
dependencies = [
"anyhow",
"proc-macro2",
@@ -20886,15 +20891,15 @@ dependencies = [
[[package]]
name = "wasmtime-internal-component-util"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "646a53678ce6aaf6f097e18ca51f650f2841aea6d2bcd7b61931397b8b8f30db"
+checksum = "e21aadbf677ee3503ef2580ce3c6955508e90a2810e961739b30f79585af254c"
[[package]]
name = "wasmtime-internal-cranelift"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ab3495aa8300e4ca6b53f81a53ce5eff6621fd5ff8378ef9ae552d1479d57371"
+checksum = "65821bab751956cddfc6ee957beb13a0e2a6cf682050d75dfb7a0228db2ed499"
dependencies = [
"anyhow",
"cfg-if",
@@ -20919,9 +20924,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-fiber"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "29b5e4023a6b167da157338f5f0f505945eb45e78f1cac2d4dcce0922457d7d4"
+checksum = "18cf73e5e8d28a2b30d86454430c7dea3b593598dcbbc0ebb927ca2716222d41"
dependencies = [
"anyhow",
"cc",
@@ -20935,9 +20940,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-jit-debug"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9da71e2d573e3cc6f753a3b7bff98f425ca060c0e8071cc55c3d867a9edf3ecc"
+checksum = "4279dc3147ddaa21e5b3d2c0eaff117881c4f937747bdd2379eb361665843bd3"
dependencies = [
"cc",
"wasmtime-internal-versioned-export-macros",
@@ -20945,9 +20950,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-jit-icache-coherence"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "627d8f57909a4f9bb1dbe57a96229a54b89d5995353d0b321f3cb9a1a118977a"
+checksum = "a8eb677944201839c0be19b39b0f19dcd663efbcbc05a09c73f26fec7bdf0331"
dependencies = [
"anyhow",
"cfg-if",
@@ -20957,24 +20962,24 @@ dependencies = [
[[package]]
name = "wasmtime-internal-math"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "45b99315585a8a27125dd9b0150edb115d6f6ff0baae453c21d30822aab77f00"
+checksum = "db9a153e184878df396a11f8912444531c2e4d0c7a1d9e9a52b30d9853d89cb9"
dependencies = [
"libm",
]
[[package]]
name = "wasmtime-internal-slab"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8eaee97281dd3fe47ec3d46c16fb9fe2dd32f37d0523c2d5c484f11b348734e4"
+checksum = "b771494bead25e1f0c4c89a9476dd0b65eacca314ed82125f1e197fbc3f0396b"
[[package]]
name = "wasmtime-internal-unwinder"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d0c005f82c48492b6b44fa19ee5205bd933c4f8baca41e314eca8331dd3c4fd9"
+checksum = "90199caed6925420434a923861d8ad813689ca8533d2c679f805d12e35b40a4b"
dependencies = [
"anyhow",
"cfg-if",
@@ -20985,9 +20990,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-versioned-export-macros"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b73639a9c0c0e33a2ef942ca99b6772b48393be92bebbd0767c607e5b0a68e0"
+checksum = "ae71687aa834f9cc9eb5b0f97c85184d7dc70b84d32fd8927af0887998a1ba35"
dependencies = [
"proc-macro2",
"quote",
@@ -20996,9 +21001,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-winch"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "392ca021d084c7426616ef77e1284315555f11bcbb34f416d74b0732db622811"
+checksum = "5d0ba45c0d766dd56257d97702d3284b6f69efdd4c53ca981a0754cc0a139df0"
dependencies = [
"anyhow",
"cranelift-codegen",
@@ -21013,9 +21018,9 @@ dependencies = [
[[package]]
name = "wasmtime-internal-wit-bindgen"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7fd4703351476262d715b72431e80d10289908e3494050071d6521267f522d97"
+checksum = "41a64d5112c06f9d54b41e61f0b757d3a5a52361bf359f01131cc7cb8551ac73"
dependencies = [
"anyhow",
"bitflags 2.13.1",
@@ -21623,7 +21628,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.48.0",
]
[[package]]
@@ -21634,9 +21639,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "winch-codegen"
-version = "36.0.12"
+version = "36.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61ec880b20caaa72245944b54cfb22aca111f8c805e12a7542b40d66921e5323"
+checksum = "82ea9625459ce35d6a4188cf0f07c9095cbb0e5afd86f711d63955bfc4216e64"
dependencies = [
"anyhow",
"cranelift-assembler-x64",
@@ -23834,6 +23839,12 @@ dependencies = [
"zlog",
]
+[[package]]
+name = "zmij"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+
[[package]]
name = "zstd"
version = "0.11.2+zstd.1.5.2"
diff --git a/Cargo.toml b/Cargo.toml
index 94926af4e88..fe7a53e8bb0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -840,8 +840,8 @@ toml_edit = { version = "0.22", default-features = false, features = [
"serde",
] }
tower-http = "0.4.4"
+tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "dff1fd868c750dbbae179fcd5c43ce987e4e0528" }
tracing = "0.1.40"
-tree-sitter = "0.26.9"
tree-sitter-bash = "0.25.1"
tree-sitter-c = "0.24.1"
tree-sitter-cpp = { git = "https://github.com/tree-sitter/tree-sitter-cpp", rev = "5cb9b693cfd7bfacab1d9ff4acac1a4150700609" }
@@ -967,6 +967,10 @@ features = [
]
[patch.crates-io]
+# Unify `tree_sitter_language::LanguageFn` between crates.io grammar crates and
+# the git tree-sitter above; two instances of the crate would make grammar
+# constants type-incompatible with `tree_sitter::Language`.
+tree-sitter-language = { git = "https://github.com/tree-sitter/tree-sitter", rev = "dff1fd868c750dbbae179fcd5c43ce987e4e0528" }
async-process = { git = "https://github.com/zed-industries/async-process.git", rev = "0b6d6713570af61806e1e5cb40e0f757cb93fd9d" }
async-task = { git = "https://github.com/smol-rs/async-task.git", rev = "b4486cd71e4e94fbda54ce6302444de14f4d190e" }
windows-capture = { git = "https://github.com/zed-industries/windows-capture.git", rev = "f0d6c1b6691db75461b732f6d5ff56eed002eeb9" }
diff --git a/crates/gpui/src/executor.rs b/crates/gpui/src/executor.rs
index 785a58e95d8..b5c1737aa19 100644
--- a/crates/gpui/src/executor.rs
+++ b/crates/gpui/src/executor.rs
@@ -6,7 +6,9 @@ use scheduler::Instant;
use scheduler::Scheduler;
use std::{future::Future, marker::PhantomData, mem, pin::Pin, rc::Rc, sync::Arc, time::Duration};
-pub use scheduler::{FallibleTask, LocalExecutor as SchedulerLocalExecutor, Priority, Task};
+pub use scheduler::{
+ DedicatedExecutor, FallibleTask, LocalExecutor as SchedulerLocalExecutor, Priority, Task,
+};
/// A pointer to the executor that is currently running,
/// for spawning background tasks.
diff --git a/crates/gpui/src/platform_scheduler.rs b/crates/gpui/src/platform_scheduler.rs
index b7426ba466f..a50b3920a72 100644
--- a/crates/gpui/src/platform_scheduler.rs
+++ b/crates/gpui/src/platform_scheduler.rs
@@ -214,6 +214,26 @@ mod tests {
}
}
+ #[test]
+ fn dedicated_executor_tasks_share_one_thread() {
+ let background =
+ BackgroundExecutor::new(Arc::new(PlatformScheduler::new(Arc::new(SmokeDispatcher))));
+ let dedicated = scheduler::DedicatedExecutor::new(&background);
+
+ let first = dedicated.spawn(async { std::thread::current().id() });
+ let second = dedicated.spawn(async { std::thread::current().id() });
+
+ let first = futures::executor::block_on(first);
+ let second = futures::executor::block_on(second);
+
+ assert_eq!(first, second, "tasks must share the dedicated thread");
+ assert_ne!(
+ first,
+ std::thread::current().id(),
+ "dedicated tasks must not run on the spawning thread"
+ );
+ }
+
#[test]
fn spawn_dedicated_runs_on_a_real_separate_thread() {
let background =
diff --git a/crates/gpui_web/Cargo.toml b/crates/gpui_web/Cargo.toml
index 917bc14267d..a9082437967 100644
--- a/crates/gpui_web/Cargo.toml
+++ b/crates/gpui_web/Cargo.toml
@@ -11,13 +11,14 @@ workspace = true
[features]
default = ["multithreaded"]
-multithreaded = ["dep:wasm_thread"]
+multithreaded = ["dep:wasm_thread", "scheduler/wasm-threads"]
[lib]
path = "src/gpui_web.rs"
[target.'cfg(target_family = "wasm")'.dependencies]
gpui.workspace = true
+scheduler.workspace = true
parking_lot = { workspace = true, features = ["nightly"] }
gpui_wgpu.workspace = true
http_client.workspace = true
diff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rs
index d22a12879e1..7f9d377e6d0 100644
--- a/crates/language/src/syntax_map.rs
+++ b/crates/language/src/syntax_map.rs
@@ -101,7 +101,7 @@ pub struct SyntaxMapMatch<'a> {
struct SyntaxMapCapturesLayer<'a> {
depth: usize,
- captures: QueryCaptures<'a, 'a, TextProvider<'a>, &'a [u8]>,
+ captures: QueryCaptures<'a, 'a, 'static, TextProvider<'a>, &'a [u8]>,
next_capture: Option<QueryCapture<'a>>,
grammar_index: usize,
_query_cursor: QueryCursorHandle,
@@ -113,7 +113,7 @@ struct SyntaxMapMatchesLayer<'a> {
next_pattern_index: usize,
next_captures: Vec<QueryCapture<'a>>,
has_next: bool,
- matches: QueryMatches<'a, 'a, TextProvider<'a>, &'a [u8]>,
+ matches: QueryMatches<'a, 'a, 'static, TextProvider<'a>, &'a [u8]>,
query: &'a Query,
grammar_index: usize,
_query_cursor: QueryCursorHandle,
diff --git a/crates/language/src/syntax_map/syntax_map_tests.rs b/crates/language/src/syntax_map/syntax_map_tests.rs
index f54182902e4..442e6890fe7 100644
--- a/crates/language/src/syntax_map/syntax_map_tests.rs
+++ b/crates/language/src/syntax_map/syntax_map_tests.rs
@@ -1386,8 +1386,8 @@ fn check_interpolation(
check_node_edits(
depth,
range,
- old_node.child(i as u32).unwrap(),
- new_node.child(i as u32).unwrap(),
+ old_node.child(i).unwrap(),
+ new_node.child(i).unwrap(),
old_buffer,
new_buffer,
edits,
diff --git a/crates/language_core/src/grammar.rs b/crates/language_core/src/grammar.rs
index 7ab210b56cd..42c398d3cd0 100644
--- a/crates/language_core/src/grammar.rs
+++ b/crates/language_core/src/grammar.rs
@@ -26,9 +26,66 @@ impl Default for GrammarId {
}
}
+/// A handle that can produce a parseable [`tree_sitter::Language`] on the
+/// current thread.
+///
+/// On native targets a language is process-global, so the handle simply
+/// stores it. On WebAssembly, a dynamically linked grammar's functions live
+/// in the function table of the wasm instance that linked it, and every
+/// thread is a separate instance — so a parseable language is only valid on
+/// the thread that produced it, and [`tree_sitter::Language`] is `!Send`
+/// there. The handle instead stores a thread-safe resolver that links or
+/// looks up a copy of the grammar for whichever thread asks.
+#[derive(Clone)]
+pub struct ParseableLanguage {
+ #[cfg(not(target_family = "wasm"))]
+ language: tree_sitter::Language,
+ #[cfg(target_family = "wasm")]
+ resolve: std::sync::Arc<dyn Fn() -> Result<tree_sitter::Language> + Send + Sync>,
+}
+
+impl ParseableLanguage {
+ /// A parseable language valid on the calling thread.
+ pub fn resolve(&self) -> Result<tree_sitter::Language> {
+ #[cfg(not(target_family = "wasm"))]
+ {
+ Ok(self.language.clone())
+ }
+ #[cfg(target_family = "wasm")]
+ {
+ (self.resolve)()
+ }
+ }
+}
+
+#[cfg(not(target_family = "wasm"))]
+impl From<tree_sitter::Language> for ParseableLanguage {
+ fn from(language: tree_sitter::Language) -> Self {
+ Self { language }
+ }
+}
+
+#[cfg(target_family = "wasm")]
+impl ParseableLanguage {
+ pub fn from_resolver(
+ resolve: std::sync::Arc<dyn Fn() -> Result<tree_sitter::Language> + Send + Sync>,
+ ) -> Self {
+ Self { resolve }
+ }
+}
+
+impl std::fmt::Debug for ParseableLanguage {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("ParseableLanguage").finish_non_exhaustive()
+ }
+}
+
pub struct Grammar {
id: GrammarId,
+ #[cfg(not(target_family = "wasm"))]
pub ts_language: tree_sitter::Language,
+ #[cfg(target_family = "wasm")]
+ parseable_language: ParseableLanguage,
pub error_query: Option<Query>,
pub highlights_config: Option<HighlightsConfig>,
pub brackets_config: Option<BracketsConfig>,
@@ -257,7 +314,12 @@ fn populate_capture_indices(
}
impl Grammar {
- pub fn new(ts_language: tree_sitter::Language) -> Self {
+ pub fn new(language: impl Into<ParseableLanguage>) -> Self {
+ let parseable_language = language.into();
+ let error_query = parseable_language
+ .resolve()
+ .ok()
+ .and_then(|ts_language| Query::new(&ts_language, "(ERROR) @error").ok());
Self {
id: GrammarId::new(),
highlights_config: None,
@@ -269,13 +331,33 @@ impl Grammar {
override_config: None,
redactions_config: None,
runnable_config: None,
- error_query: Query::new(&ts_language, "(ERROR) @error").ok(),
+ error_query,
debug_variables_config: None,
- ts_language,
+ #[cfg(not(target_family = "wasm"))]
+ ts_language: parseable_language
+ .resolve()
+ .expect("resolving a native parseable language cannot fail"),
+ #[cfg(target_family = "wasm")]
+ parseable_language,
highlight_map: Default::default(),
}
}
+ /// A parseable [`tree_sitter::Language`] valid on the calling thread.
+ ///
+ /// See [`ParseableLanguage`] for why this is a resolution rather than a
+ /// field access on WebAssembly.
+ pub fn parseable_language(&self) -> Result<tree_sitter::Language> {
+ #[cfg(not(target_family = "wasm"))]
+ {
+ Ok(self.ts_language.clone())
+ }
+ #[cfg(target_family = "wasm")]
+ {
+ self.parseable_language.resolve()
+ }
+ }
+
pub fn id(&self) -> GrammarId {
self.id
}
@@ -365,7 +447,7 @@ impl Grammar {
}
pub fn with_highlights_query(mut self, source: &str) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut identifier_capture_indices = Vec::new();
for name in [
@@ -392,7 +474,7 @@ impl Grammar {
}
pub fn with_runnable_query(mut self, source: &str) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let extra_captures: Vec<_> = query
.capture_names()
.iter()
@@ -420,7 +502,7 @@ impl Grammar {
source: &str,
language_name: &LanguageName,
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut item_capture_ix = 0;
let mut name_capture_ix = 0;
let mut context_capture_ix = None;
@@ -462,7 +544,7 @@ impl Grammar {
source: &str,
language_name: &LanguageName,
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut text_objects_by_capture_ix = Vec::new();
for (ix, name) in query.capture_names().iter().enumerate() {
@@ -489,7 +571,7 @@ impl Grammar {
source: &str,
language_name: &LanguageName,
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut objects_by_capture_ix = Vec::new();
for (ix, name) in query.capture_names().iter().enumerate() {
@@ -516,7 +598,7 @@ impl Grammar {
source: &str,
language_name: &LanguageName,
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut open_capture_ix = 0;
let mut close_capture_ix = 0;
if populate_capture_indices(
@@ -559,7 +641,7 @@ impl Grammar {
source: &str,
language_name: &LanguageName,
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut indent_capture_ix = 0;
let mut start_capture_ix = None;
let mut end_capture_ix = None;
@@ -600,7 +682,7 @@ impl Grammar {
source: &str,
language_name: &LanguageName,
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut language_capture_ix = None;
let mut injection_language_capture_ix = None;
let mut content_capture_ix = None;
@@ -674,7 +756,7 @@ impl Grammar {
brackets: &mut BracketPairConfig,
scope_opt_in_language_servers: &[SharedString],
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut override_configs_by_id = HashMap::default();
for (ix, mut name) in query.capture_names().iter().copied().enumerate() {
@@ -751,7 +833,7 @@ impl Grammar {
source: &str,
language_name: &LanguageName,
) -> Result<Self> {
- let query = Query::new(&self.ts_language, source)?;
+ let query = Query::new(&self.parseable_language()?, source)?;
let mut redaction_capture_ix = 0;
if populate_capture_indices(
&query,
diff --git a/crates/language_core/src/language_core.rs b/crates/language_core/src/language_core.rs
index 2edbcbea9d2..88d24867c9c 100644
--- a/crates/language_core/src/language_core.rs
+++ b/crates/language_core/src/language_core.rs
@@ -8,8 +8,8 @@ pub mod language_config;
pub use grammar::{
BracketsConfig, BracketsPatternConfig, DebugVariablesConfig, DebuggerTextObject, Grammar,
GrammarId, HighlightsConfig, IndentConfig, InjectionConfig, InjectionPatternConfig,
- NEXT_GRAMMAR_ID, OutlineConfig, OverrideConfig, OverrideEntry, RedactionConfig,
- RunnableCapture, RunnableConfig, TextObject, TextObjectConfig,
+ NEXT_GRAMMAR_ID, OutlineConfig, OverrideConfig, OverrideEntry, ParseableLanguage,
+ RedactionConfig, RunnableCapture, RunnableConfig, TextObject, TextObjectConfig,
};
pub use highlight_map::{HighlightId, HighlightMap};
pub use language_config::{
diff --git a/crates/scheduler/Cargo.toml b/crates/scheduler/Cargo.toml
index 98fe3b0197c..bec534c98cf 100644
--- a/crates/scheduler/Cargo.toml
+++ b/crates/scheduler/Cargo.toml
@@ -14,6 +14,16 @@ doctest = false
[features]
test-support = []
+# Allows `spawn_dedicated` to create real threads on wasm targets by spawning
+# web workers. Off by default because it requires shared-memory threading
+# (atomics + bulk-memory); wasm consumers without those build flags keep
+# compiling, and `spawn_dedicated` panics at runtime instead.
+#
+# `flume/spin` replaces flume's internal `std::sync::Mutex` with a spinlock:
+# a contended `std` lock parks with `Atomics.wait`, which the browser forbids
+# on the main thread, and the main thread sends on flume channels every time
+# it schedules work onto a dedicated thread.
+wasm-threads = ["dep:wasm_thread", "flume/spin"]
[dependencies]
async-task.workspace = true
@@ -24,3 +34,10 @@ futures.workspace = true
parking_lot.workspace = true
rand.workspace = true
web-time.workspace = true
+
+[target.'cfg(target_family = "wasm")'.dependencies]
+# Forked because upstream is unmaintained and its worker bootstrap still calls
+# the wasm-bindgen init function with the positional arguments deprecated in 0.2.93.
+wasm_thread = { git = "https://github.com/zed-industries/wasm_thread", rev = "0cf96c7708dfb97ccf3da50347e25edcf75d6937", version = "0.3", features = [
+ "es_modules",
+], optional = true }
diff --git a/crates/scheduler/src/executor.rs b/crates/scheduler/src/executor.rs
index 7791abfc178..53f3ba52135 100644
--- a/crates/scheduler/src/executor.rs
+++ b/crates/scheduler/src/executor.rs
@@ -9,7 +9,7 @@ use std::{
pin::Pin,
rc::Rc,
sync::Arc,
- task::{Context, Poll},
+ task::{Context, Poll, Waker},
thread::{self, ThreadId},
time::Duration,
};
@@ -312,6 +312,64 @@ impl BackgroundExecutor {
}
}
+/// A long-lived handle to one dedicated session: every future spawned on it
+/// runs on that session's single thread, never on the background pool.
+///
+/// Use this when tasks rely on thread-local state being coherent across
+/// spawns, or when the per-thread setup cost of the work is high enough that
+/// it should be paid once. Creating the session costs a thread (on the web, a
+/// worker — expensive); each spawn afterwards is just a channel send.
+///
+/// Dropping the handle cancels the session: queued and future spawns resolve
+/// to cancelled tasks.
+pub struct DedicatedExecutor {
+ sender: flume::Sender<Runnable<RunnableMeta>>,
+ _session: Task<()>,
+}
+
+impl DedicatedExecutor {
+ /// Starts a dedicated session on `executor` and returns a handle that
+ /// spawns futures onto it. Under `TestScheduler` the session runs on the
+ /// deterministic test loop; no real thread is created.
+ #[track_caller]
+ pub fn new(executor: &BackgroundExecutor) -> Self {
+ let (sender, receiver) = flume::unbounded::<Runnable<RunnableMeta>>();
+ let session = executor.spawn_dedicated(move |_executor| async move {
+ while let Ok(runnable) = receiver.recv_async().await {
+ runnable.run();
+ }
+ });
+ Self {
+ sender,
+ _session: session,
+ }
+ }
+
+ /// Spawns a future onto the dedicated session's thread.
+ ///
+ /// The returned task has the usual semantics: dropping it cancels the
+ /// future, `.await`ing it yields the output, `.detach()`ing it lets it
+ /// run to completion on its own.
+ #[track_caller]
+ pub fn spawn<F>(&self, future: F) -> Task<F::Output>
+ where
+ F: Future + Send + 'static,
+ F::Output: Send + 'static,
+ {
+ let sender = self.sender.clone();
+ let (runnable, task) = async_task::Builder::new()
+ .metadata(RunnableMeta::new_with_callers_location())
+ .spawn(
+ move |_| future,
+ move |runnable| {
+ let _ = sender.send(runnable);
+ },
+ );
+ runnable.schedule();
+ Task(TaskState::Spawned(task))
+ }
+}
+
/// Task is a primitive that allows work to happen in the background.
///
/// It implements [`Future`] so you can `.await` on it.
@@ -335,6 +393,123 @@ enum TaskState<T> {
inner: Box<Task<Box<dyn Any + Send + Sync>>>,
marker: PhantomData<fn() -> T>,
},
+
+ /// A task whose real handle is delivered later by another thread (see
+ /// [`Task::rendezvous`]). Once delivered, polling replaces this state
+ /// with the delivered task's state.
+ Rendezvous(RendezvousReceiver<T>),
+}
+
+/// State shared between the two halves of a [`Task::rendezvous`] pair.
+enum RendezvousState<T> {
+ /// No task delivered yet; holds the consumer's waker if it polled.
+ Pending(Option<Waker>),
+ /// The producer delivered before the consumer consumed the task.
+ Delivered(Task<T>),
+ /// The consumer was dropped before delivery; delivery cancels the task.
+ Cancelled,
+ /// The consumer was detached before delivery; delivery detaches the task.
+ Detached,
+ /// The consumer took the delivered task.
+ Taken,
+}
+
+pub(crate) struct RendezvousReceiver<T> {
+ shared: Arc<parking_lot::Mutex<RendezvousState<T>>>,
+}
+
+impl<T> RendezvousReceiver<T> {
+ fn poll_take(&self, cx: &mut Context) -> Poll<Task<T>> {
+ let mut state = self.shared.lock();
+ match std::mem::replace(&mut *state, RendezvousState::Taken) {
+ RendezvousState::Delivered(task) => Poll::Ready(task),
+ RendezvousState::Pending(_) => {
+ *state = RendezvousState::Pending(Some(cx.waker().clone()));
+ Poll::Pending
+ }
+ RendezvousState::Cancelled | RendezvousState::Detached | RendezvousState::Taken => {
+ unreachable!("a rendezvous task was polled after its receiver was consumed")
+ }
+ }
+ }
+
+ fn is_ready(&self) -> bool {
+ match &*self.shared.lock() {
+ RendezvousState::Delivered(task) => task.is_ready(),
+ _ => false,
+ }
+ }
+
+ fn detach(self) {
+ let mut state = self.shared.lock();
+ match std::mem::replace(&mut *state, RendezvousState::Detached) {
+ RendezvousState::Delivered(task) => {
+ *state = RendezvousState::Taken;
+ drop(state);
+ task.detach();
+ }
+ // The producer applies the detached disposition on delivery.
+ RendezvousState::Pending(_) => {}
+ RendezvousState::Cancelled | RendezvousState::Detached | RendezvousState::Taken => {
+ unreachable!("a rendezvous task was detached after its receiver was consumed")
+ }
+ }
+ }
+}
+
+impl<T> Drop for RendezvousReceiver<T> {
+ fn drop(&mut self) {
+ let mut state = self.shared.lock();
+ match &*state {
+ RendezvousState::Pending(_) => *state = RendezvousState::Cancelled,
+ RendezvousState::Delivered(_) => {
+ let delivered = std::mem::replace(&mut *state, RendezvousState::Cancelled);
+ drop(state);
+ drop(delivered);
+ }
+ // `Taken`, `Detached`, and `Cancelled` record dispositions that
+ // this drop must not overwrite: the receiver is also dropped as a
+ // normal side effect of taking or detaching.
+ _ => {}
+ }
+ }
+}
+
+pub(crate) struct RendezvousSender<T> {
+ shared: Arc<parking_lot::Mutex<RendezvousState<T>>>,
+}
+
+impl<T> RendezvousSender<T> {
+ /// Hands the real task to the rendezvous, applying the consumer's
+ /// disposition if it was dropped or detached before delivery.
+ pub(crate) fn deliver(self, task: Task<T>) {
+ let mut state = self.shared.lock();
+ match std::mem::replace(&mut *state, RendezvousState::Delivered(task)) {
+ RendezvousState::Pending(waker) => {
+ drop(state);
+ if let Some(waker) = waker {
+ waker.wake();
+ }
+ }
+ RendezvousState::Cancelled => {
+ let delivered = std::mem::replace(&mut *state, RendezvousState::Cancelled);
+ drop(state);
+ drop(delivered);
+ }
+ RendezvousState::Detached => {
+ let RendezvousState::Delivered(task) =
+ std::mem::replace(&mut *state, RendezvousState::Detached)
+ else {
+ unreachable!("the delivered task was just stored");
+ };
+ drop(state);
+ task.detach();
+ }
+ RendezvousState::Delivered(_) | RendezvousState::Taken => {
+ unreachable!("a rendezvous task was delivered twice")
+ }
+ }
+ }
}
impl<T> Task<T> {
@@ -343,6 +518,20 @@ impl<T> Task<T> {
Task(TaskState::Ready(Some(val)))
}
+ /// Creates a task whose real handle arrives later through the returned
+ /// sender, typically from another thread. Until delivery the task is
+ /// pending; afterwards it behaves exactly like the delivered task.
+ /// Dropping or detaching the task before delivery is honored on delivery.
+ pub(crate) fn rendezvous() -> (Self, RendezvousSender<T>) {
+ let shared = Arc::new(parking_lot::Mutex::new(RendezvousState::Pending(None)));
+ (
+ Task(TaskState::Rendezvous(RendezvousReceiver {
+ shared: shared.clone(),
+ })),
+ RendezvousSender { shared },
+ )
+ }
+
/// Creates a Task from an async_task::Task
pub fn from_async_task(task: async_task::Task<T, RunnableMeta>) -> Self {
Task(TaskState::Spawned(task))
@@ -353,6 +542,7 @@ impl<T> Task<T> {
TaskState::Ready(_) => true,
TaskState::Spawned(task) => task.is_finished(),
TaskState::Downcast { inner, .. } => inner.is_ready(),
+ TaskState::Rendezvous(receiver) => receiver.is_ready(),
}
}
@@ -362,6 +552,7 @@ impl<T> Task<T> {
Task(TaskState::Ready(_)) => {}
Task(TaskState::Spawned(task)) => task.detach(),
Task(TaskState::Downcast { inner, .. }) => inner.detach(),
+ Task(TaskState::Rendezvous(receiver)) => receiver.detach(),
}
}
@@ -374,6 +565,7 @@ impl<T> Task<T> {
inner: Box::new(inner.fallible()),
marker: PhantomData,
},
+ TaskState::Rendezvous(receiver) => FallibleTaskState::Rendezvous(receiver),
})
}
}
@@ -403,6 +595,7 @@ impl<T> std::fmt::Debug for Task<T> {
TaskState::Downcast { inner, .. } => {
f.debug_tuple("Task::Downcast").field(inner).finish()
}
+ TaskState::Rendezvous(_) => f.debug_tuple("Task::Rendezvous").finish(),
}
}
}
@@ -423,6 +616,9 @@ enum FallibleTaskState<T> {
inner: Box<FallibleTask<Box<dyn Any + Send + Sync>>>,
marker: PhantomData<fn() -> T>,
},
+
+ /// Mirror of [`TaskState::Rendezvous`] for fallible tasks.
+ Rendezvous(RendezvousReceiver<T>),
}
impl<T> FallibleTask<T> {
@@ -437,6 +633,7 @@ impl<T> FallibleTask<T> {
FallibleTaskState::Ready(_) => {}
FallibleTaskState::Spawned(task) => task.detach(),
FallibleTaskState::Downcast { inner, .. } => inner.detach(),
+ FallibleTaskState::Rendezvous(receiver) => receiver.detach(),
}
}
}
@@ -445,19 +642,29 @@ impl<T: 'static> Future for FallibleTask<T> {
type Output = Option<T>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
- match unsafe { self.get_unchecked_mut() } {
- FallibleTask(FallibleTaskState::Ready(val)) => Poll::Ready(val.take()),
- FallibleTask(FallibleTaskState::Spawned(task)) => Pin::new(task).poll(cx),
- FallibleTask(FallibleTaskState::Downcast { inner, .. }) => {
- match Pin::new(inner.as_mut()).poll(cx) {
- Poll::Ready(Some(boxed_any)) => Poll::Ready(Some(
- *boxed_any
- .downcast::<T>()
- .expect("FallibleTask::poll: downcast type mismatch"),
- )),
- Poll::Ready(None) => Poll::Ready(None),
- Poll::Pending => Poll::Pending,
+ let this = unsafe { self.get_unchecked_mut() };
+ loop {
+ match &mut this.0 {
+ FallibleTaskState::Ready(val) => return Poll::Ready(val.take()),
+ FallibleTaskState::Spawned(task) => return Pin::new(task).poll(cx),
+ FallibleTaskState::Downcast { inner, .. } => {
+ return match Pin::new(inner.as_mut()).poll(cx) {
+ Poll::Ready(Some(boxed_any)) => Poll::Ready(Some(
+ *boxed_any
+ .downcast::<T>()
+ .expect("FallibleTask::poll: downcast type mismatch"),
+ )),
+ Poll::Ready(None) => Poll::Ready(None),
+ Poll::Pending => Poll::Pending,
+ };
}
+ FallibleTaskState::Rendezvous(receiver) => match receiver.poll_take(cx) {
+ Poll::Ready(task) => {
+ this.0 = task.fallible().0;
+ continue;
+ }
+ Poll::Pending => return Poll::Pending,
+ },
}
}
}
@@ -474,6 +681,7 @@ impl<T> std::fmt::Debug for FallibleTask<T> {
.debug_tuple("FallibleTask::Downcast")
.field(inner)
.finish(),
+ FallibleTaskState::Rendezvous(_) => f.debug_tuple("FallibleTask::Rendezvous").finish(),
}
}
}
@@ -482,17 +690,29 @@ impl<T: 'static> Future for Task<T> {
type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
- match unsafe { self.get_unchecked_mut() } {
- Task(TaskState::Ready(val)) => Poll::Ready(val.take().unwrap()),
- Task(TaskState::Spawned(task)) => Pin::new(task).poll(cx),
- Task(TaskState::Downcast { inner, .. }) => match Pin::new(inner.as_mut()).poll(cx) {
- Poll::Ready(boxed_any) => Poll::Ready(
- *boxed_any
- .downcast::<T>()
- .expect("Task::poll: downcast type mismatch"),
- ),
- Poll::Pending => Poll::Pending,
- },
+ let this = unsafe { self.get_unchecked_mut() };
+ loop {
+ match &mut this.0 {
+ TaskState::Ready(val) => return Poll::Ready(val.take().unwrap()),
+ TaskState::Spawned(task) => return Pin::new(task).poll(cx),
+ TaskState::Downcast { inner, .. } => {
+ return match Pin::new(inner.as_mut()).poll(cx) {
+ Poll::Ready(boxed_any) => Poll::Ready(
+ *boxed_any
+ .downcast::<T>()
+ .expect("Task::poll: downcast type mismatch"),
+ ),
+ Poll::Pending => Poll::Pending,
+ };
+ }
+ TaskState::Rendezvous(receiver) => match receiver.poll_take(cx) {
+ Poll::Ready(task) => {
+ this.0 = task.0;
+ continue;
+ }
+ Poll::Pending => return Poll::Pending,
+ },
+ }
}
}
}
diff --git a/crates/scheduler/src/scheduler.rs b/crates/scheduler/src/scheduler.rs
index 957af02b88f..98c561357a9 100644
--- a/crates/scheduler/src/scheduler.rs
+++ b/crates/scheduler/src/scheduler.rs
@@ -17,7 +17,6 @@ use std::{
pin::Pin,
sync::Arc,
task::{Context, Poll},
- thread,
time::Duration,
};
@@ -151,10 +150,21 @@ pub trait Scheduler: Send + Sync {
/// work don't disturb any other executor in the process.
///
/// `f` is called on the dedicated thread with a [`LocalExecutor`] pinned
-/// to it. The future `f` returns may freely be `!Send`. The returned `Task` is
-/// that future's task: dropping it cancels the root, but detached children
-/// keep running until they finish. The thread shuts down once the executor and
-/// every task on it are gone.
+/// to it. The future `f` returns may freely be `!Send`. The returned `Task`
+/// resolves to that future's output: dropping it cancels the root, but
+/// detached children keep running until they finish. The thread shuts down
+/// once the executor and every task on it are gone.
+///
+/// This function never blocks: the returned task starts as an asynchronous
+/// rendezvous that resolves to the root task's handle once the dedicated
+/// thread has spawned it, and behaves like that handle from then on. That
+/// makes it safe to call from threads that must not block, such as the web
+/// main thread. On wasm targets the thread is a web worker and requires the
+/// `wasm-threads` cargo feature (and a shared-memory build); without it this
+/// panics. Spawning a worker is far more expensive than an OS thread —
+/// module instantiation plus a fresh function table — so on the web treat a
+/// dedicated session as a long-lived place to send work, not a per-job
+/// convenience.
///
/// The caller is responsible for supplying a `session_id` that's distinct from
/// every other live session on `scheduler`. Concrete schedulers typically wrap
@@ -169,32 +179,47 @@ where
Fut: Future + 'static,
Fut::Output: Send + 'static,
{
- let (runnable_sender, runnable_receiver) = flume::unbounded::<Runnable<RunnableMeta>>();
- let (task_sender, task_receiver) = flume::bounded::<Task<Fut::Output>>(1);
-
- thread::Builder::new()
- .name(format!("spawn_dedicated session {:?}", session_id))
- .spawn(move || {
- let dispatch = move |runnable: Runnable<RunnableMeta>| {
- let _ = runnable_sender.send(runnable);
- };
- let executor = LocalExecutor::new(session_id, scheduler, dispatch);
- let root_task = executor.spawn(f(executor.clone()));
- let _ = task_sender.send(root_task);
- // After this drop, every strong reference to the runnable sender
- // lives inside a spawned task or a user-held executor clone. The
- // recv loop exits once all of those are gone.
- drop(executor);
-
- while let Ok(runnable) = runnable_receiver.recv() {
- runnable.run();
- }
- })
- .expect("failed to spawn dedicated thread");
+ let (task, delivery) = Task::rendezvous();
+ let thread_body = move || {
+ let (runnable_sender, runnable_receiver) = flume::unbounded::<Runnable<RunnableMeta>>();
+ let dispatch = move |runnable: Runnable<RunnableMeta>| {
+ let _ = runnable_sender.send(runnable);
+ };
+ let executor = LocalExecutor::new(session_id, scheduler, dispatch);
+ let root_task = executor.spawn(f(executor.clone()));
+ // If the caller already dropped or detached the rendezvous task,
+ // delivery applies that disposition to the root task here.
+ delivery.deliver(root_task);
+ // After this drop, every strong reference to the runnable sender
+ // lives inside a spawned task or a user-held executor clone. The
+ // recv loop exits once all of those are gone.
+ drop(executor);
+
+ while let Ok(runnable) = runnable_receiver.recv() {
+ runnable.run();
+ }
+ };
+ spawn_dedicated_os_thread(session_id, thread_body);
+ task
+}
- task_receiver
- .recv()
- .expect("dedicated thread failed to produce root task")
+fn spawn_dedicated_os_thread(session_id: SessionId, thread_body: impl FnOnce() + Send + 'static) {
+ let thread_name = format!("spawn_dedicated session {:?}", session_id);
+ #[cfg(not(target_family = "wasm"))]
+ std::thread::Builder::new()
+ .name(thread_name)
+ .spawn(thread_body)
+ .expect("failed to spawn dedicated thread");
+ #[cfg(all(target_family = "wasm", feature = "wasm-threads"))]
+ wasm_thread::Builder::new()
+ .name(thread_name)
+ .spawn(thread_body)
+ .expect("failed to spawn dedicated thread");
+ #[cfg(all(target_family = "wasm", not(feature = "wasm-threads")))]
+ {
+ let _ = (thread_name, thread_body);
+ panic!("spawn_dedicated on wasm requires the scheduler crate's `wasm-threads` feature");
+ }
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
diff --git a/crates/scheduler/src/tests.rs b/crates/scheduler/src/tests.rs
index 1daea8cf965..c834707ce99 100644
--- a/crates/scheduler/src/tests.rs
+++ b/crates/scheduler/src/tests.rs
@@ -34,6 +34,15 @@ fn test_background_executor_spawn() {
});
}
+#[test]
+fn test_dedicated_executor_spawn() {
+ TestScheduler::once(async |scheduler| {
+ let dedicated = DedicatedExecutor::new(&scheduler.background());
+ let task = dedicated.spawn(async move { 42 });
+ assert_eq!(task.await, 42);
+ });
+}
+
#[test]
fn test_scheduler_drops_with_stalled_detached_foreground_task() {
let scheduler = Arc::new(TestScheduler::new(TestSchedulerConfig::default()));
diff --git a/crates/vim/src/object.rs b/crates/vim/src/object.rs
index e00393ddebb..acdf64ecfd3 100644
--- a/crates/vim/src/object.rs
+++ b/crates/vim/src/object.rs
@@ -965,7 +965,7 @@ pub fn surrounding_html_tag(
while let Some(cur_node) = last_child_node {
if cur_node.child_count() >= 2 {
let first_child = cur_node.child(0);
- let last_child = cur_node.child(cur_node.child_count() as u32 - 1);
+ let last_child = cur_node.child(cur_node.child_count() - 1);
if let (Some(first_child), Some(last_child)) = (first_child, last_child) {
let open_tag = open_tag(buffer.chars_for_range(first_child.byte_range()));
let close_tag = close_tag(buffer.chars_for_range(last_child.byte_range()));