@gasm-compiler/core 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -118,6 +118,17 @@ import { compile } from "@gasm-compiler/core/browser";
118
118
  const wgslCode = compile(wasmBytes);
119
119
  ```
120
120
 
121
+ The compiler has no required browser initialization step. For applications that
122
+ want to fetch and cache the Wasm compiler ahead of time, the browser entry point
123
+ also exposes an optional async path:
124
+
125
+ ```typescript
126
+ import { compileAsync, preloadCompiler } from "@gasm-compiler/core/browser";
127
+
128
+ await preloadCompiler();
129
+ const wgslCode = await compileAsync(wasmBytes);
130
+ ```
131
+
121
132
  ### Using with WebGPU
122
133
 
123
134
  ```typescript
@@ -229,6 +240,47 @@ Compiles a WebAssembly binary to WGSL.
229
240
 
230
241
  **Throws:** `CompileError` on validation or compilation failure
231
242
 
243
+ ### `compileAsync(source, options?)`
244
+
245
+ ```typescript
246
+ function compileAsync(source: Uint8Array, options?: CompileOptions): Promise<string>
247
+ ```
248
+
249
+ Async equivalent of `compile`. In browsers this can be paired with
250
+ `preloadCompiler()` to fetch and instantiate the compiler artifact before the
251
+ first compilation.
252
+
253
+ ### `compileWithDiagnostics(source, options?)`
254
+
255
+ ```typescript
256
+ function compileWithDiagnostics(
257
+ source: Uint8Array,
258
+ options?: CompileOptions,
259
+ ): CompileWithDiagnosticsResult
260
+ ```
261
+
262
+ Compiles a WebAssembly binary and returns diagnostics instead of throwing.
263
+
264
+ ### `compileWithDiagnosticsAsync(source, options?)`
265
+
266
+ ```typescript
267
+ function compileWithDiagnosticsAsync(
268
+ source: Uint8Array,
269
+ options?: CompileOptions,
270
+ ): Promise<CompileWithDiagnosticsResult>
271
+ ```
272
+
273
+ Async equivalent of `compileWithDiagnostics`.
274
+
275
+ ### `preloadCompiler(options?)`
276
+
277
+ ```typescript
278
+ function preloadCompiler(options?: { wasmUrl?: string | URL }): Promise<void>
279
+ ```
280
+
281
+ Optional performance hook for browser applications that want to load the
282
+ compiler before the first call to `compileAsync`.
283
+
232
284
  ### `CompileOptions`
233
285
 
234
286
  ```typescript
@@ -1 +1 @@
1
- import{a}from"./chunk-G6YRZSKB.js";import"./chunk-STDXBN5E.js";export{a as BrowserGPUExecutor};
1
+ import{a}from"./chunk-IZGS3OS2.js";import"./chunk-STDXBN5E.js";export{a as BrowserGPUExecutor};
package/dist/browser.d.ts CHANGED
@@ -1,10 +1,63 @@
1
- import { C as CompileDiagnostics, D as DispatchInfo, a as CompileOptions } from './parser-C7xAx4nx.js';
2
- export { b as CompileError, m as isCompileError, o as isParseError, r as parseWasmModule } from './parser-C7xAx4nx.js';
1
+ import { C as CompileDiagnostics, D as DispatchInfo$1, a as CompileOptions } from './error_codes-D6RsiZ33.js';
2
+ export { b as CompileError, h as ErrorCode, E as ErrorCodes, c as SPEC_VERSION_V01, d as SPEC_VERSION_V02, S as SpecVersion, e as isCompileError, g as isParseError, i as isV02Mode, f as parseWasmModule, r as resolveSpecVersion } from './error_codes-D6RsiZ33.js';
3
3
  export { BrowserGPUExecutor } from './browser-executor.js';
4
4
  export { BufferData, ExecuteOptions, ExecutionError, ExecutorConfig, IGPUExecutor, OutputBufferSpec, isExecutionError } from './executor.js';
5
5
 
6
+ type BrowserTsCompileWithDiagnosticsResult = {
7
+ ok: true;
8
+ wgsl: string;
9
+ diagnostics: CompileDiagnostics;
10
+ dispatchInfo: DispatchInfo$1;
11
+ } | {
12
+ ok: false;
13
+ diagnostics: CompileDiagnostics;
14
+ };
15
+
16
+ interface InitRustCompilerOptions {
17
+ wasmUrl?: string | URL;
18
+ }
19
+ declare function preloadCompiler(options?: InitRustCompilerOptions): Promise<void>;
20
+ declare const initRustCompiler: typeof preloadCompiler;
21
+ declare function isRustCompilerInitialized(): boolean;
22
+ declare function waitForRustCompilerInit(): Promise<void>;
23
+
24
+ /**
25
+ * Shared helpers for comparing TypeScript and Rust/Wasm WGSL output.
26
+ */
27
+ interface WgslDiffOptions {
28
+ /** Maximum diff hunk lines to include in formatted output. */
29
+ maxLines?: number;
30
+ /** Lines of context around each change hunk. */
31
+ context?: number;
32
+ }
33
+ interface WgslComparisonSummary {
34
+ equivalent: boolean;
35
+ moduleEquivalent: boolean;
36
+ functionEquivalent?: boolean;
37
+ moduleDiff?: string;
38
+ functionDiff?: string;
39
+ typescriptSnippet?: string;
40
+ rustSnippet?: string;
41
+ }
42
+ declare function normalizeWgslForComparison(wgsl: string): string;
43
+ declare function exportWgslFunctionSnippet(wgsl: string, funcName: string): string | null;
44
+ declare function summarizeWgslComparison(typescriptWgsl: string, rustWgsl: string, funcName?: string, options?: WgslDiffOptions): WgslComparisonSummary;
45
+ declare function formatUnifiedDiff(leftLabel: string, rightLabel: string, left: string, right: string, options?: WgslDiffOptions): string;
46
+
47
+ type BrowserCompilerBackend = "typescript" | "rust" | "compare";
48
+ declare function setBrowserCompilerBackend(backend: BrowserCompilerBackend): void;
49
+ declare function getBrowserCompilerBackend(): BrowserCompilerBackend;
6
50
  declare function disassembleToWAT(wasmBytes: Uint8Array): Promise<string>;
7
51
 
52
+ interface DispatchInfo {
53
+ workItemsX: number;
54
+ workItemsY: number;
55
+ workItemsZ: number;
56
+ workgroupSizeX: number;
57
+ workgroupSizeY: number;
58
+ workgroupSizeZ: number;
59
+ isParallelized: boolean;
60
+ }
8
61
  type CompileWithDiagnosticsResult = {
9
62
  ok: true;
10
63
  wgsl: string;
@@ -14,7 +67,35 @@ type CompileWithDiagnosticsResult = {
14
67
  ok: false;
15
68
  diagnostics: CompileDiagnostics;
16
69
  };
70
+ interface BackendMismatchDetails {
71
+ kind: "wgsl" | "ok_mismatch" | "rust_error" | "diagnostics";
72
+ message: string;
73
+ moduleDiff?: string;
74
+ functionDiff?: string;
75
+ typescriptWgsl?: string;
76
+ rustWgsl?: string;
77
+ }
78
+ interface BackendComparisonResult {
79
+ selectedBackend: "typescript";
80
+ returned: CompileWithDiagnosticsResult;
81
+ typescript: BrowserTsCompileWithDiagnosticsResult;
82
+ rust: CompileWithDiagnosticsResult | {
83
+ ok: false;
84
+ error: string;
85
+ };
86
+ equivalent: boolean;
87
+ mismatch?: BackendMismatchDetails;
88
+ }
89
+
17
90
  declare function compileWithDiagnostics(wasmBytes: Uint8Array, options?: CompileOptions): CompileWithDiagnosticsResult;
91
+ declare function compileWithDiagnosticsAsync(wasmBytes: Uint8Array, options?: CompileOptions, initOptions?: InitRustCompilerOptions): Promise<CompileWithDiagnosticsResult>;
92
+ declare function compileWithBackendComparison(wasmBytes: Uint8Array, options?: CompileOptions, compareOptions?: {
93
+ funcName?: string;
94
+ }): BackendComparisonResult;
95
+ declare function compileWithBackendComparisonAsync(wasmBytes: Uint8Array, options?: CompileOptions, compareOptions?: {
96
+ funcName?: string;
97
+ }, initOptions?: InitRustCompilerOptions): Promise<BackendComparisonResult>;
18
98
  declare function compile(wasmBytes: Uint8Array, options?: CompileOptions): string;
99
+ declare function compileAsync(wasmBytes: Uint8Array, options?: CompileOptions, initOptions?: InitRustCompilerOptions): Promise<string>;
19
100
 
20
- export { CompileDiagnostics, CompileOptions, type CompileWithDiagnosticsResult, DispatchInfo, compile, compileWithDiagnostics, disassembleToWAT };
101
+ export { type BackendComparisonResult, type BackendMismatchDetails, type BrowserCompilerBackend, CompileDiagnostics, CompileOptions, type CompileWithDiagnosticsResult, type DispatchInfo, type InitRustCompilerOptions, type WgslComparisonSummary, type WgslDiffOptions, compile, compileAsync, compileWithBackendComparison, compileWithBackendComparisonAsync, compileWithDiagnostics, compileWithDiagnosticsAsync, disassembleToWAT, exportWgslFunctionSnippet, formatUnifiedDiff, getBrowserCompilerBackend, initRustCompiler, isRustCompilerInitialized, normalizeWgslForComparison, preloadCompiler, setBrowserCompilerBackend, summarizeWgslComparison, waitForRustCompilerInit };