Skip to content

Commit 2b66b8a

Browse files
authored
BREAKING: Remove support for .wasm imports (#5135)
Importing .wasm files is non-standardized therefore deciding to support current functionality past 1.0 release is risky. Besides that .wasm import posed many challenges in our codebase due to complex interactions with TS compiler which spawned thread for each encountered .wasm import. This commit removes: - cli/compilers/wasm.rs - cli/compilers/wasm_wrap.js - two integration tests related to .wasm imports
1 parent 93cf3bd commit 2b66b8a

20 files changed

+5
-388
lines changed

cli/compilers/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ use futures::Future;
66
mod compiler_worker;
77
mod js;
88
mod ts;
9-
mod wasm;
109

1110
pub use js::JsCompiler;
1211
pub use ts::runtime_compile;
1312
pub use ts::runtime_transpile;
1413
pub use ts::TargetLib;
1514
pub use ts::TsCompiler;
16-
pub use wasm::WasmCompiler;
1715

1816
pub type CompilationResultFuture = dyn Future<Output = JsonResult>;
1917

cli/compilers/ts.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,6 @@ impl TsCompiler {
691691
}
692692
}
693693

694-
// TODO(bartlomieju): exactly same function is in `wasm.rs` - only difference
695-
// it created WasmCompiler instead of TsCompiler - deduplicate
696694
async fn execute_in_thread(
697695
global_state: GlobalState,
698696
req: Buf,

cli/compilers/wasm.rs

Lines changed: 0 additions & 185 deletions
This file was deleted.

cli/compilers/wasm_wrap.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

cli/global_state.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::compilers::CompiledModule;
33
use crate::compilers::JsCompiler;
44
use crate::compilers::TargetLib;
55
use crate::compilers::TsCompiler;
6-
use crate::compilers::WasmCompiler;
76
use crate::deno_dir;
87
use crate::file_fetcher::SourceFileFetcher;
98
use crate::flags;
@@ -36,7 +35,6 @@ pub struct GlobalStateInner {
3635
pub file_fetcher: SourceFileFetcher,
3736
pub js_compiler: JsCompiler,
3837
pub ts_compiler: TsCompiler,
39-
pub wasm_compiler: WasmCompiler,
4038
pub lockfile: Option<Mutex<Lockfile>>,
4139
pub compiler_starts: AtomicUsize,
4240
compile_lock: AsyncMutex<()>,
@@ -87,7 +85,6 @@ impl GlobalState {
8785
file_fetcher,
8886
ts_compiler,
8987
js_compiler: JsCompiler {},
90-
wasm_compiler: WasmCompiler::default(),
9188
lockfile,
9289
compiler_starts: AtomicUsize::new(0),
9390
compile_lock: AsyncMutex::new(()),
@@ -116,12 +113,6 @@ impl GlobalState {
116113
let compile_lock = self.compile_lock.lock().await;
117114

118115
let compiled_module = match out.media_type {
119-
msg::MediaType::Json | msg::MediaType::Unknown => {
120-
state1.js_compiler.compile(out).await
121-
}
122-
msg::MediaType::Wasm => {
123-
state1.wasm_compiler.compile(state1.clone(), &out).await
124-
}
125116
msg::MediaType::TypeScript
126117
| msg::MediaType::TSX
127118
| msg::MediaType::JSX => {
@@ -152,6 +143,7 @@ impl GlobalState {
152143
state1.js_compiler.compile(out).await
153144
}
154145
}
146+
_ => state1.js_compiler.compile(out).await,
155147
}?;
156148
drop(compile_lock);
157149

cli/js.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn compiler_snapshot() {
5050
deno_core::js_check(isolate.execute(
5151
"<anon>",
5252
r#"
53-
if (!(bootstrap.tsCompilerRuntime && bootstrap.wasmCompilerRuntime)) {
53+
if (!(bootstrap.tsCompilerRuntime)) {
5454
throw Error("bad");
5555
}
5656
console.log(`ts version: ${ts.version}`);

cli/js/compiler.ts

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
// This module is the entry point for "compiler" isolate, ie. the one
55
// that is created when Deno needs to compile TS/WASM to JS.
66
//
7-
// It provides a two functions that should be called by Rust:
7+
// It provides a single functions that should be called by Rust:
88
// - `bootstrapTsCompilerRuntime`
9-
// - `bootstrapWasmCompilerRuntime`
10-
// Either of these functions must be called when creating isolate
9+
// This functions must be called when creating isolate
1110
// to properly setup runtime.
1211

1312
// NOTE: this import has side effects!
@@ -22,7 +21,6 @@ import { sendAsync, sendSync } from "./ops/dispatch_json.ts";
2221
import { bootstrapWorkerRuntime } from "./runtime_worker.ts";
2322
import { assert, log } from "./util.ts";
2423
import * as util from "./util.ts";
25-
import { atob } from "./web/text_encoding.ts";
2624
import { TextDecoder, TextEncoder } from "./web/text_encoding.ts";
2725
import { core } from "./core.ts";
2826

@@ -1123,16 +1121,6 @@ function commonPath(paths: string[], sep = "/"): string {
11231121
return prefix.endsWith(sep) ? prefix : `${prefix}${sep}`;
11241122
}
11251123

1126-
function base64ToUint8Array(data: string): Uint8Array {
1127-
const binString = atob(data);
1128-
const size = binString.length;
1129-
const bytes = new Uint8Array(size);
1130-
for (let i = 0; i < size; i++) {
1131-
bytes[i] = binString.charCodeAt(i);
1132-
}
1133-
return bytes;
1134-
}
1135-
11361124
let rootExports: string[] | undefined;
11371125

11381126
function normalizeUrl(rootName: string): string {
@@ -1585,43 +1573,11 @@ async function tsCompilerOnMessage({
15851573
// Currently Rust shuts down worker after single request
15861574
}
15871575

1588-
async function wasmCompilerOnMessage({
1589-
data: binary,
1590-
}: {
1591-
data: string;
1592-
}): Promise<void> {
1593-
const buffer = base64ToUint8Array(binary);
1594-
// @ts-ignore
1595-
const compiled = await WebAssembly.compile(buffer);
1596-
1597-
util.log(">>> WASM compile start");
1598-
1599-
const importList = Array.from(
1600-
// @ts-ignore
1601-
new Set(WebAssembly.Module.imports(compiled).map(({ module }) => module))
1602-
);
1603-
const exportList = Array.from(
1604-
// @ts-ignore
1605-
new Set(WebAssembly.Module.exports(compiled).map(({ name }) => name))
1606-
);
1607-
1608-
globalThis.postMessage({ importList, exportList });
1609-
1610-
util.log("<<< WASM compile end");
1611-
1612-
// Currently Rust shuts down worker after single request
1613-
}
1614-
16151576
function bootstrapTsCompilerRuntime(): void {
16161577
bootstrapWorkerRuntime("TS", false);
16171578
globalThis.onmessage = tsCompilerOnMessage;
16181579
}
16191580

1620-
function bootstrapWasmCompilerRuntime(): void {
1621-
bootstrapWorkerRuntime("WASM", false);
1622-
globalThis.onmessage = wasmCompilerOnMessage;
1623-
}
1624-
16251581
// Removes the `__proto__` for security reasons. This intentionally makes
16261582
// Deno non compliant with ECMA-262 Annex B.2.2.1
16271583
//
@@ -1632,7 +1588,6 @@ Object.defineProperties(globalThis, {
16321588
bootstrap: {
16331589
value: {
16341590
...globalThis.bootstrap,
1635-
wasmCompilerRuntime: bootstrapWasmCompilerRuntime,
16361591
tsCompilerRuntime: bootstrapTsCompilerRuntime,
16371592
},
16381593
configurable: true,

cli/js/globals.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ declare global {
147147
workerRuntime: ((name: string) => Promise<void> | void) | undefined;
148148
// Assigned to `self` global - compiler
149149
tsCompilerRuntime: (() => void) | undefined;
150-
wasmCompilerRuntime: (() => void) | undefined;
151150
};
152151

153152
var onerror:

0 commit comments

Comments
 (0)