Repository navigation
feat(v18): build against the upb libpg_query fork (PG 18.6 + combined patches) #198
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,6 +218,22 @@ function callWasm(fn: () => number): number { | |
| } | ||
| } | ||
|
|
||
| // libpg_query reports a failed allocation as a plain "out of memory" error and | ||
| // keeps going, but the instance's heap stays grown to the size it reached (WASM | ||
| // memory never shrinks), so load a fresh instance and let this one be freed. | ||
| function outOfMemoryError(): Error { | ||
| stale = true; | ||
| instantiate(); | ||
| return new Error('libpg_query ran out of WASM memory (heap limit is WASM_MAXIMUM_MEMORY, 1 GiB); parse large inputs in smaller pieces'); | ||
| } | ||
|
Comment on lines
+224
to
+228
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bug · medium OOM path marks instance stale without bumping The new 📋 Prompt for AI AgentsIn versions/18/src/index.ts and templates/full/index.ts, update outOfMemoryError() (versions/18/src/index.ts:224-228, templates/full/index.ts:217-221) to also count the failure, mirroring callWasm's catch: |
||
|
|
||
| function throwIfErrorString(resultStr: string): void { | ||
| if (resultStr === 'out of memory') throw outOfMemoryError(); | ||
| if (resultStr.startsWith('syntax error') || resultStr.startsWith('deparse error') || resultStr.startsWith('ERROR') || resultStr.startsWith('stack depth limit exceeded')) { | ||
| throw new Error(resultStr); | ||
| } | ||
| } | ||
|
|
||
| function ensureLoaded() { | ||
| if (!wasmModule) throw new Error("WASM module not initialized. Call `loadModule()` first."); | ||
| } | ||
|
|
@@ -328,6 +344,7 @@ export const parse = awaitInit(async (query: string): Promise<ParseResult> => { | |
| const funcname = funcnamePtr ? wasmModule.UTF8ToString(funcnamePtr) : undefined; | ||
| const filename = filenamePtr ? wasmModule.UTF8ToString(filenamePtr) : undefined; | ||
|
|
||
| if (message === 'out of memory') throw outOfMemoryError(); | ||
| throw new SqlError(message, { | ||
| message, | ||
| cursorPosition: cursorpos > 0 ? cursorpos - 1 : 0, // Convert to 0-based | ||
|
|
@@ -364,6 +381,7 @@ export const parsePlPgSQL = awaitInit(async (query: string): Promise<ParseResult | |
|
|
||
| // Success is always a JSON object; anything else is an error message | ||
| if (!resultStr.startsWith('{')) { | ||
| if (resultStr === 'out of memory') throw outOfMemoryError(); | ||
| throw new Error(resultStr); | ||
| } | ||
|
|
||
|
|
@@ -387,9 +405,7 @@ export const fingerprint = awaitInit(async (query: string): Promise<string> => { | |
| resultPtr = callWasm(() => wasmModule._wasm_fingerprint(queryPtr)); | ||
| const resultStr = ptrToString(resultPtr); | ||
|
|
||
| if (resultStr.startsWith('syntax error') || resultStr.startsWith('deparse error') || resultStr.startsWith('ERROR')) { | ||
| throw new Error(resultStr); | ||
| } | ||
| throwIfErrorString(resultStr); | ||
|
|
||
| return resultStr; | ||
| } finally { | ||
|
|
@@ -411,9 +427,7 @@ export const normalize = awaitInit(async (query: string): Promise<string> => { | |
| resultPtr = callWasm(() => wasmModule._wasm_normalize_query(queryPtr)); | ||
| const resultStr = ptrToString(resultPtr); | ||
|
|
||
| if (resultStr.startsWith('syntax error') || resultStr.startsWith('deparse error') || resultStr.startsWith('ERROR')) { | ||
| throw new Error(resultStr); | ||
| } | ||
| throwIfErrorString(resultStr); | ||
|
|
||
| return resultStr; | ||
| } finally { | ||
|
|
@@ -468,6 +482,7 @@ export function parseSync(query: string): ParseResult { | |
| const funcname = funcnamePtr ? wasmModule.UTF8ToString(funcnamePtr) : undefined; | ||
| const filename = filenamePtr ? wasmModule.UTF8ToString(filenamePtr) : undefined; | ||
|
|
||
| if (message === 'out of memory') throw outOfMemoryError(); | ||
| throw new SqlError(message, { | ||
| message, | ||
| cursorPosition: cursorpos > 0 ? cursorpos - 1 : 0, // Convert to 0-based | ||
|
|
@@ -507,6 +522,7 @@ export function parsePlPgSQLSync(query: string): ParseResult { | |
|
|
||
| // Success is always a JSON object; anything else is an error message | ||
| if (!resultStr.startsWith('{')) { | ||
| if (resultStr === 'out of memory') throw outOfMemoryError(); | ||
| throw new Error(resultStr); | ||
| } | ||
|
|
||
|
|
@@ -533,9 +549,7 @@ export function fingerprintSync(query: string): string { | |
| resultPtr = callWasm(() => wasmModule._wasm_fingerprint(queryPtr)); | ||
| const resultStr = ptrToString(resultPtr); | ||
|
|
||
| if (resultStr.startsWith('syntax error') || resultStr.startsWith('deparse error') || resultStr.startsWith('ERROR')) { | ||
| throw new Error(resultStr); | ||
| } | ||
| throwIfErrorString(resultStr); | ||
|
|
||
| return resultStr; | ||
| } finally { | ||
|
|
@@ -560,9 +574,7 @@ export function normalizeSync(query: string): string { | |
| resultPtr = callWasm(() => wasmModule._wasm_normalize_query(queryPtr)); | ||
| const resultStr = ptrToString(resultPtr); | ||
|
|
||
| if (resultStr.startsWith('syntax error') || resultStr.startsWith('deparse error') || resultStr.startsWith('ERROR')) { | ||
| throw new Error(resultStr); | ||
| } | ||
| throwIfErrorString(resultStr); | ||
|
|
||
| return resultStr; | ||
| } finally { | ||
|
|
@@ -584,9 +596,7 @@ export const scan = awaitInit(async (query: string): Promise<ScanResult> => { | |
| resultPtr = callWasm(() => wasmModule._wasm_scan(queryPtr)); | ||
| const resultStr = ptrToString(resultPtr); | ||
|
|
||
| if (resultStr.startsWith('syntax error') || resultStr.startsWith('deparse error') || resultStr.startsWith('ERROR')) { | ||
| throw new Error(resultStr); | ||
| } | ||
| throwIfErrorString(resultStr); | ||
|
|
||
| return JSON.parse(resultStr); | ||
| } finally { | ||
|
|
@@ -611,9 +621,7 @@ export function scanSync(query: string): ScanResult { | |
| resultPtr = callWasm(() => wasmModule._wasm_scan(queryPtr)); | ||
| const resultStr = ptrToString(resultPtr); | ||
|
|
||
| if (resultStr.startsWith('syntax error') || resultStr.startsWith('deparse error') || resultStr.startsWith('ERROR')) { | ||
| throw new Error(resultStr); | ||
| } | ||
| throwIfErrorString(resultStr); | ||
|
|
||
| return JSON.parse(resultStr); | ||
| } finally { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regenerate the PostgreSQL 18 types for the new pin.
The
f75f801parser emitsDefElem.arg_locationand the subscription statements'conninfo_location. The upstreampg_query.protoat that commit declares these fields. The checked-in PostgreSQL 18 types do not, so TypeScript consumers cannot read them without a cast.The pin bump does not regenerate these files.
fetch:protosruns only when invoked directly, and no build or types script calls it. Runpnpm fetch:protos, thenpnpm build:types. Commit and publish the regenerated PostgreSQL 18 types.