Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING: Remove support for .wasm imports #5135

Merged
merged 4 commits into from
May 7, 2020
Merged
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
2 changes: 0 additions & 2 deletions cli/compilers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ use futures::Future;
mod compiler_worker;
mod js;
mod ts;
mod wasm;

pub use js::JsCompiler;
pub use ts::runtime_compile;
pub use ts::runtime_transpile;
pub use ts::TargetLib;
pub use ts::TsCompiler;
pub use wasm::WasmCompiler;

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

Expand Down
2 changes: 0 additions & 2 deletions cli/compilers/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,6 @@ impl TsCompiler {
}
}

// TODO(bartlomieju): exactly same function is in `wasm.rs` - only difference
// it created WasmCompiler instead of TsCompiler - deduplicate
async fn execute_in_thread(
global_state: GlobalState,
req: Buf,
Expand Down
185 changes: 0 additions & 185 deletions cli/compilers/wasm.rs

This file was deleted.

20 changes: 0 additions & 20 deletions cli/compilers/wasm_wrap.js

This file was deleted.

10 changes: 1 addition & 9 deletions cli/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::compilers::CompiledModule;
use crate::compilers::JsCompiler;
use crate::compilers::TargetLib;
use crate::compilers::TsCompiler;
use crate::compilers::WasmCompiler;
use crate::deno_dir;
use crate::file_fetcher::SourceFileFetcher;
use crate::flags;
Expand Down Expand Up @@ -36,7 +35,6 @@ pub struct GlobalStateInner {
pub file_fetcher: SourceFileFetcher,
pub js_compiler: JsCompiler,
pub ts_compiler: TsCompiler,
pub wasm_compiler: WasmCompiler,
pub lockfile: Option<Mutex<Lockfile>>,
pub compiler_starts: AtomicUsize,
compile_lock: AsyncMutex<()>,
Expand Down Expand Up @@ -87,7 +85,6 @@ impl GlobalState {
file_fetcher,
ts_compiler,
js_compiler: JsCompiler {},
wasm_compiler: WasmCompiler::default(),
lockfile,
compiler_starts: AtomicUsize::new(0),
compile_lock: AsyncMutex::new(()),
Expand Down Expand Up @@ -116,12 +113,6 @@ impl GlobalState {
let compile_lock = self.compile_lock.lock().await;

let compiled_module = match out.media_type {
msg::MediaType::Json | msg::MediaType::Unknown => {
state1.js_compiler.compile(out).await
}
msg::MediaType::Wasm => {
state1.wasm_compiler.compile(state1.clone(), &out).await
}
msg::MediaType::TypeScript
| msg::MediaType::TSX
| msg::MediaType::JSX => {
Expand Down Expand Up @@ -152,6 +143,7 @@ impl GlobalState {
state1.js_compiler.compile(out).await
}
}
_ => state1.js_compiler.compile(out).await,
}?;
drop(compile_lock);

Expand Down
2 changes: 1 addition & 1 deletion cli/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn compiler_snapshot() {
deno_core::js_check(isolate.execute(
"<anon>",
r#"
if (!(bootstrap.tsCompilerRuntime && bootstrap.wasmCompilerRuntime)) {
if (!(bootstrap.tsCompilerRuntime)) {
throw Error("bad");
}
console.log(`ts version: ${ts.version}`);
Expand Down
49 changes: 2 additions & 47 deletions cli/js/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
// This module is the entry point for "compiler" isolate, ie. the one
// that is created when Deno needs to compile TS/WASM to JS.
//
// It provides a two functions that should be called by Rust:
// It provides a single functions that should be called by Rust:
// - `bootstrapTsCompilerRuntime`
// - `bootstrapWasmCompilerRuntime`
// Either of these functions must be called when creating isolate
// This functions must be called when creating isolate
// to properly setup runtime.

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

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

function base64ToUint8Array(data: string): Uint8Array {
const binString = atob(data);
const size = binString.length;
const bytes = new Uint8Array(size);
for (let i = 0; i < size; i++) {
bytes[i] = binString.charCodeAt(i);
}
return bytes;
}

let rootExports: string[] | undefined;

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

async function wasmCompilerOnMessage({
data: binary,
}: {
data: string;
}): Promise<void> {
const buffer = base64ToUint8Array(binary);
// @ts-ignore
const compiled = await WebAssembly.compile(buffer);

util.log(">>> WASM compile start");

const importList = Array.from(
// @ts-ignore
new Set(WebAssembly.Module.imports(compiled).map(({ module }) => module))
);
const exportList = Array.from(
// @ts-ignore
new Set(WebAssembly.Module.exports(compiled).map(({ name }) => name))
);

globalThis.postMessage({ importList, exportList });

util.log("<<< WASM compile end");

// Currently Rust shuts down worker after single request
}

function bootstrapTsCompilerRuntime(): void {
bootstrapWorkerRuntime("TS", false);
globalThis.onmessage = tsCompilerOnMessage;
}

function bootstrapWasmCompilerRuntime(): void {
bootstrapWorkerRuntime("WASM", false);
globalThis.onmessage = wasmCompilerOnMessage;
}

// Removes the `__proto__` for security reasons. This intentionally makes
// Deno non compliant with ECMA-262 Annex B.2.2.1
//
Expand All @@ -1632,7 +1588,6 @@ Object.defineProperties(globalThis, {
bootstrap: {
value: {
...globalThis.bootstrap,
wasmCompilerRuntime: bootstrapWasmCompilerRuntime,
tsCompilerRuntime: bootstrapTsCompilerRuntime,
},
configurable: true,
Expand Down
1 change: 0 additions & 1 deletion cli/js/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ declare global {
workerRuntime: ((name: string) => Promise<void> | void) | undefined;
// Assigned to `self` global - compiler
tsCompilerRuntime: (() => void) | undefined;
wasmCompilerRuntime: (() => void) | undefined;
};

var onerror:
Expand Down
Loading