refactor(model): share exact pickle integer projection (#16837)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 05:19:03 +08:00
1 parent 78853792fb
commit 5cd3af6237
3 files changed
+7 -8

No files matched your search

+1 -3
View File
@@ -12,6 +12,7 @@ import {
} from "./ModelFormat.js";
import {
calleeName,
exactInt,
pickleOpcodeName,
type PickleCall,
type PickleNode,
@@ -176,9 +177,6 @@ export const pickleFacts = (
};
};
const exactInt = (node: PickleNode | undefined): bigint | undefined =>
node?.kind === "int" && node.value !== null ? node.value : undefined;
const text = (node: PickleNode | undefined): string | undefined =>
node?.kind === "str" ? node.value : undefined;
+3
View File
@@ -37,6 +37,9 @@ export type PickleNode =
| { readonly kind: "persistent"; readonly pid: PickleNode }
| PickleCall;
export const exactInt = (node: PickleNode | undefined): bigint | undefined =>
node?.kind === "int" && node.value !== null ? node.value : undefined;
/** A REDUCE/NEWOBJ/OBJ/INST result; APPEND, SETITEM and BUILD record what loading would do to it. */
export interface PickleCall {
readonly kind: "call";
+3 -5
View File
@@ -49,6 +49,7 @@ import {
} from "./PickleInspection.js";
import {
PickleWalker,
exactInt,
PickleWork,
type PickleBudgets,
type PickleNode,
@@ -191,9 +192,6 @@ const hashRemainder = async (
}
};
const intValue = (node: PickleNode | undefined): bigint | undefined =>
node?.kind === "int" && node.value !== null ? node.value : undefined;
/** Storage references in first-appearance order; later conflicting declarations keep the first. */
const storageReferences = (
walker: PickleWalker,
@@ -279,7 +277,7 @@ export const readPickleFile = async (
return walker;
};
const first = await walk(0, "data");
const legacy = intValue(first.result) === LEGACY_MAGIC;
const legacy = exactInt(first.result) === LEGACY_MAGIC;
const limitations: string[] = [];
let headerEnd = first.position;
let version: number | null = null;
@@ -290,7 +288,7 @@ export const readPickleFile = async (
if (legacy) {
streams[0] = { ...streams[0]!, role: "magic" };
const protocol = await walk(headerEnd, "protocol");
const declared = intValue(protocol.result);
const declared = exactInt(protocol.result);
if (declared !== LEGACY_PROTOCOL)
throw malformedInput(
MODEL_FORMAT,