From c602fe88281be334a0db83067b90be43551e3c7f Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Tue, 27 Oct 2026 14:04:53 +0800 Subject: [PATCH] refactor(schemas): select native and GPU variants by name --- src/domain/analysisView/gpuCodeObjectsView.ts | 10 ++-- src/domain/gpu/gpuCodeObjects.ts | 52 +++++++++++-------- src/domain/native/functionInventory.ts | 9 ++-- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/domain/analysisView/gpuCodeObjectsView.ts b/src/domain/analysisView/gpuCodeObjectsView.ts index 2447d0f268..f00ed3cad1 100644 --- a/src/domain/analysisView/gpuCodeObjectsView.ts +++ b/src/domain/analysisView/gpuCodeObjectsView.ts @@ -4,7 +4,7 @@ import { z } from "zod"; import { gpuCodeObjectsSchema, gpuCodeObjectsObjectSchema, - gpuCodeObjectsSelectionSchema, + gpuCodeObjectsSelectionSchemas, gpuObjectSchema, gpuKernelSchema, gpuTargetSchema, @@ -31,16 +31,16 @@ import { AnalysisResourceConstraintError } from "../analysisErrorCore.js"; export const gpuCodeObjectsViewRequestSchema = z.discriminatedUnion( "collection", [ - gpuCodeObjectsSelectionSchema.options[0].extend({ + gpuCodeObjectsSelectionSchemas.objects.extend({ kind: z.literal("gpu-code-objects"), }), - gpuCodeObjectsSelectionSchema.options[1].extend({ + gpuCodeObjectsSelectionSchemas.kernels.extend({ kind: z.literal("gpu-code-objects"), }), - gpuCodeObjectsSelectionSchema.options[2].extend({ + gpuCodeObjectsSelectionSchemas.ptx.extend({ kind: z.literal("gpu-code-objects"), }), - gpuCodeObjectsSelectionSchema.options[3].extend({ + gpuCodeObjectsSelectionSchemas.targets.extend({ kind: z.literal("gpu-code-objects"), }), ], diff --git a/src/domain/gpu/gpuCodeObjects.ts b/src/domain/gpu/gpuCodeObjects.ts index 5f8bd69026..ae00de1ec3 100644 --- a/src/domain/gpu/gpuCodeObjects.ts +++ b/src/domain/gpu/gpuCodeObjects.ts @@ -377,32 +377,38 @@ const selection = { offset: count.default(0), limit: z.number().int().positive().default(32), }; +export const gpuCodeObjectsSelectionSchemas = { + objects: z.strictObject({ + ...selection, + collection: z.literal("objects"), + fields: z.array(gpuObjectSchema.keyof()).optional(), + }), + kernels: z.strictObject({ + ...selection, + collection: z.literal("kernels"), + object_ids: z.array(z.string()).optional(), + names: z.array(z.string()).optional(), + fields: z.array(gpuKernelSchema.keyof()).optional(), + }), + ptx: z.strictObject({ + collection: z.literal("ptx"), + object_id: z.string(), + offset: count.default(0), + limit: z.number().int().positive().default(4096), + }), + targets: z.strictObject({ + ...selection, + collection: z.literal("targets"), + fields: z.array(gpuTargetSchema.keyof()).optional(), + }), +}; export const gpuCodeObjectsSelectionSchema = z.discriminatedUnion( "collection", [ - z.strictObject({ - ...selection, - collection: z.literal("objects"), - fields: z.array(gpuObjectSchema.keyof()).optional(), - }), - z.strictObject({ - ...selection, - collection: z.literal("kernels"), - object_ids: z.array(z.string()).optional(), - names: z.array(z.string()).optional(), - fields: z.array(gpuKernelSchema.keyof()).optional(), - }), - z.strictObject({ - collection: z.literal("ptx"), - object_id: z.string(), - offset: count.default(0), - limit: z.number().int().positive().default(4096), - }), - z.strictObject({ - ...selection, - collection: z.literal("targets"), - fields: z.array(gpuTargetSchema.keyof()).optional(), - }), + gpuCodeObjectsSelectionSchemas.objects, + gpuCodeObjectsSelectionSchemas.kernels, + gpuCodeObjectsSelectionSchemas.ptx, + gpuCodeObjectsSelectionSchemas.targets, ], ); export const inspectGpuCodeObjectsInputSchema = z diff --git a/src/domain/native/functionInventory.ts b/src/domain/native/functionInventory.ts index b43e1a1179..c121e88a80 100644 --- a/src/domain/native/functionInventory.ts +++ b/src/domain/native/functionInventory.ts @@ -6,9 +6,11 @@ import { readEvidencePayload } from "../evidenceValidation.js"; import { digestCanonicalValue } from "../canonicalDigest.js"; import { functionDossierSchema } from "../native/functionDossier.js"; import { + availableFunctionBodySchema, functionBodySchema, functionBodyEntryAgrees, } from "../native/functionBody.js"; +import { unavailableNativeFactSchema } from "./nativeFactAvailability.js"; import { nativeSymbolOrigin } from "./nativeSymbol.js"; import { addressedValueSchema, @@ -26,11 +28,10 @@ import { const matchingRowsSchema = nativeInventoryRowsSchemas.names.element .extend({ address: nativeAddressInputSchema }) .array(); -const availableBodySchema = functionBodySchema.options[1]; const matchingBodySchema = z.discriminatedUnion("available", [ - functionBodySchema.options[0], - availableBodySchema.safeExtend({ - ranges: availableBodySchema.shape.ranges.element + unavailableNativeFactSchema, + availableFunctionBodySchema.safeExtend({ + ranges: availableFunctionBodySchema.shape.ranges.element .extend({ start: nativeAddressInputSchema, end: nativeAddressInputSchema,