bonsai-js 1.0.0 → 1.2.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +24 -4
  3. package/dist/artifact.d.mts +47 -0
  4. package/dist/artifact.mjs +139 -0
  5. package/dist/artifact.mjs.map +1 -0
  6. package/dist/builtins/index.d.mts +91 -0
  7. package/dist/builtins/index.mjs +93 -0
  8. package/dist/builtins/index.mjs.map +1 -0
  9. package/dist/check/bind.mjs +117 -0
  10. package/dist/check/bind.mjs.map +1 -0
  11. package/dist/check/checker.mjs +34 -120
  12. package/dist/check/checker.mjs.map +1 -1
  13. package/dist/compile/compiler.mjs +2 -3
  14. package/dist/compile/compiler.mjs.map +1 -1
  15. package/dist/declared.mjs +8 -1
  16. package/dist/declared.mjs.map +1 -1
  17. package/dist/digest.mjs +109 -0
  18. package/dist/digest.mjs.map +1 -0
  19. package/dist/environment.d.mts +14 -1
  20. package/dist/environment.mjs +65 -315
  21. package/dist/environment.mjs.map +1 -1
  22. package/dist/errors.d.mts +21 -2
  23. package/dist/errors.mjs +17 -1
  24. package/dist/errors.mjs.map +1 -1
  25. package/dist/features.mjs +3 -3
  26. package/dist/features.mjs.map +1 -1
  27. package/dist/functions/builtins.mjs +551 -474
  28. package/dist/functions/builtins.mjs.map +1 -1
  29. package/dist/functions/define.mjs +53 -11
  30. package/dist/functions/define.mjs.map +1 -1
  31. package/dist/functions/descriptions.mjs +110 -0
  32. package/dist/functions/descriptions.mjs.map +1 -0
  33. package/dist/index.d.mts +4 -3
  34. package/dist/index.mjs +3 -2
  35. package/dist/lite/index.d.mts +4 -3
  36. package/dist/lite/index.mjs +3 -2
  37. package/dist/lite/index.mjs.map +1 -1
  38. package/dist/load.mjs +307 -0
  39. package/dist/load.mjs.map +1 -0
  40. package/dist/program.mjs +321 -0
  41. package/dist/program.mjs.map +1 -0
  42. package/dist/query/index.mjs +1 -1
  43. package/dist/runtime/core.d.mts +18 -0
  44. package/dist/runtime/core.mjs +31 -0
  45. package/dist/runtime/core.mjs.map +1 -0
  46. package/dist/runtime/create.d.mts +61 -0
  47. package/dist/runtime/create.mjs +76 -0
  48. package/dist/runtime/create.mjs.map +1 -0
  49. package/dist/runtime/index.d.mts +24 -0
  50. package/dist/runtime/index.mjs +34 -0
  51. package/dist/runtime/index.mjs.map +1 -0
  52. package/dist/service/index.mjs +12 -8
  53. package/dist/service/index.mjs.map +1 -1
  54. package/dist/syntax/parser.mjs +1 -1
  55. package/dist/syntax/printer.mjs +1 -1
  56. package/dist/types.mjs +103 -23
  57. package/dist/types.mjs.map +1 -1
  58. package/dist/version.mjs +7 -0
  59. package/dist/version.mjs.map +1 -0
  60. package/package.json +26 -2
@@ -1 +1 @@
1
- {"version":3,"file":"features.mjs","names":[],"sources":["../src/features.ts"],"sourcesContent":["/**\n * Explaining and partial evaluation: the program features the main entry\n * point adds to every environment. `bonsai-js/lite` leaves them out, so a\n * bundle that only checks and evaluates does not carry them.\n */\nimport { analyze, type Analysis, type CallPlan } from './check/checker.js'\nimport { compileProgram, type CompiledProgram } from './compile/compiler.js'\nimport { escaping, isOwn, raised } from './runtime/attribution.js'\nimport { BonsaiRuntimeError, type BonsaiError } from './errors.js'\nimport { describeMismatch, type Out, type ValidationBudget } from './functions/define.js'\nimport {\n EVALUATE_OPTION_KEYS,\n contextOf,\n evaluationLimits,\n hostDataFailure,\n invalidContext,\n isValidDate,\n validationBudget,\n type EvaluateOptions,\n type ExplainOptions,\n type Explanation,\n type Features,\n type ProgramCore,\n type ProgramFeatures,\n} from './environment.js'\nimport {\n forTranslation,\n partiallyEvaluate,\n residualTexts,\n type PartialOptions,\n type PartialResult,\n} from './partial.js'\nimport { isStackOverflow, tooDeep } from './runtime/overflow.js'\nimport { State } from './runtime/state.js'\nimport {\n DEFAULT_MAX_ITERATIONS,\n DEFAULT_MAX_TRACE_NODES,\n SNAPSHOT_ENTRIES,\n Tracer,\n freezeAll,\n reasonsOf,\n renderTrace,\n snapshot,\n snapshotTrace,\n type ExplanationJSON,\n type Parts,\n} from './runtime/trace.js'\nimport { isMap, keyListCost } from './runtime/values.js'\nimport { forEachChild, type CallNode, type Node } from './syntax/ast.js'\nimport { BLOCKED_NAMES, isName } from './syntax/lexer.js'\nimport type { Type } from './types.js'\n\n/** Subtrees compiled for partial evaluation, in nodes, kept per program: this times its own. */\nconst SUBTREE_CACHE_FACTOR = 2\n\nconst EXPLAIN_OPTION_KEYS: ReadonlySet<string> = new Set([\n ...EVALUATE_OPTION_KEYS,\n 'maxIterations',\n 'maxTraceNodes',\n 'exhaustive',\n])\n\ninterface ExplainSettings {\n readonly maxIterations: number\n readonly maxNodes: number\n readonly exhaustive: boolean\n /** The evaluation options among them, validated by evaluationLimits. */\n readonly evaluate: EvaluateOptions | undefined\n}\n\n/** Reads explain options once, with the same TypeError/RangeError rules as evaluate's. */\nfunction explainSettings(options: unknown): ExplainSettings {\n if (options === undefined) {\n return {\n maxIterations: DEFAULT_MAX_ITERATIONS,\n maxNodes: DEFAULT_MAX_TRACE_NODES,\n exhaustive: false,\n evaluate: undefined,\n }\n }\n if (typeof options !== 'object' || options === null || Array.isArray(options))\n throw new TypeError('Explain options must be an object')\n let copy: Record<string, unknown>\n try {\n copy = { ...(options as Record<string, unknown>) }\n } catch {\n throw new TypeError('Explain options could not be read')\n }\n for (const key of Object.keys(copy)) {\n if (!EXPLAIN_OPTION_KEYS.has(key)) {\n throw new TypeError(\n `Unknown explain option key \"${key}\" (expected one of: ${[...EXPLAIN_OPTION_KEYS].join(', ')})`,\n )\n }\n }\n const count = (name: string, fallback: number): number => {\n const value = copy[name]\n if (value === undefined) return fallback\n if (typeof value !== 'number') throw new TypeError(`Explain option \"${name}\" must be a number`)\n if (!Number.isSafeInteger(value) || value < 0)\n throw new RangeError(`Explain option \"${name}\" must be a non-negative integer`)\n return value\n }\n if (copy.exhaustive !== undefined && typeof copy.exhaustive !== 'boolean')\n throw new TypeError('Explain option \"exhaustive\" must be a boolean')\n const {\n maxIterations: _iterations,\n maxTraceNodes: _nodes,\n exhaustive: _exhaustive,\n ...evaluate\n } = copy\n return {\n maxIterations: count('maxIterations', DEFAULT_MAX_ITERATIONS),\n maxNodes: count('maxTraceNodes', DEFAULT_MAX_TRACE_NODES),\n exhaustive: copy.exhaustive === true,\n evaluate,\n }\n}\n\nconst PARTIAL_OPTION_KEYS: ReadonlySet<string> = new Set([\n 'unknown',\n 'callHostFunctions',\n 'now',\n 'maxSteps',\n 'timeout',\n 'signal',\n])\n/** A variable name, then field names as reads spell them: none empty or blocked. */\nconst isPath = (path: unknown): boolean => {\n if (typeof path !== 'string') return false\n const [name, ...fields] = path.split('.')\n return isName(name) && fields.every((field) => field !== '' && !BLOCKED_NAMES.has(field))\n}\n\n/** Reads partial() options once, with the same TypeError rules as the other options. */\nfunction partialOptions(options: unknown): PartialOptions {\n if (options === undefined) return {}\n if (typeof options !== 'object' || options === null || Array.isArray(options))\n throw new TypeError('Partial options must be an object')\n let copy: Record<string, unknown>\n try {\n copy = { ...(options as Record<string, unknown>) }\n if (Array.isArray(copy.unknown)) copy.unknown = [...(copy.unknown as unknown[])]\n } catch {\n throw new TypeError('Partial options could not be read')\n }\n for (const key of Object.keys(copy)) {\n if (!PARTIAL_OPTION_KEYS.has(key)) {\n throw new TypeError(\n `Unknown partial option key \"${key}\" (expected one of: ${[...PARTIAL_OPTION_KEYS].join(', ')})`,\n )\n }\n }\n const unknown = copy.unknown\n if (unknown !== undefined && (!Array.isArray(unknown) || !unknown.every(isPath)))\n throw new TypeError('Partial option \"unknown\" must be a list of variable names or dotted paths')\n if (copy.callHostFunctions !== undefined && typeof copy.callHostFunctions !== 'boolean')\n throw new TypeError('Partial option \"callHostFunctions\" must be a boolean')\n if (copy.now !== undefined && !isValidDate(copy.now))\n throw new TypeError('Partial option \"now\" must be a valid Date')\n return copy\n}\n\n/** Paths listed as unknown, as a tree of segments: `whole` marks a listed path. */\ninterface UnknownTree {\n whole: boolean\n readonly next: Map<string, UnknownTree>\n}\n\nfunction unknownTree(paths: readonly string[]): UnknownTree {\n const root: UnknownTree = { whole: false, next: new Map() }\n for (const path of paths) {\n let node = root\n for (const segment of path.split('.')) {\n let child = node.next.get(segment)\n if (child === undefined) node.next.set(segment, (child = { whole: false, next: new Map() }))\n node = child\n }\n node.whole = true\n }\n return root\n}\n\n/**\n * Why `value` does not conform to `type`, leaving out the parts of it under\n * listed unknown paths (`skip`): those are incomplete by design. Everything\n * else is checked as evaluation checks a context.\n */\nfunction describeKnown(\n value: unknown,\n type: Type,\n path: string,\n skip: UnknownTree | undefined,\n budget: ValidationBudget,\n): string | undefined {\n if (skip === undefined) return describeMismatch(value, type, path, budget)\n if (skip.whole) return undefined\n if (type.kind === 'union') {\n let first: string | undefined\n for (const member of type.types) {\n const problem = describeKnown(value, member, path, skip, budget)\n if (problem === undefined) return undefined\n first ??= problem\n }\n return first\n }\n const actual = value === undefined ? null : value\n if (type.kind !== 'map' || !isMap(actual)) return describeMismatch(value, type, path, budget)\n if (--budget.remaining < 0) budget.onExhausted('steps')\n for (const [key, fieldType] of Object.entries(type.fields)) {\n const field = Object.hasOwn(actual, key) ? actual[key] : null\n const problem = describeKnown(field, fieldType, `${path}.${key}`, skip.next.get(key), budget)\n if (problem !== undefined) return problem\n }\n if (type.rest === undefined) return undefined\n const keys = Object.keys(actual)\n budget.remaining -= keyListCost(keys.length)\n if (budget.remaining < 0) budget.onExhausted('steps')\n for (const key of keys) {\n // As evaluation's validation: keys the language never reads, or that hold undefined, are not data.\n if (Object.hasOwn(type.fields, key) || BLOCKED_NAMES.has(key) || actual[key] === undefined)\n continue\n const problem = describeKnown(\n actual[key],\n type.rest,\n `${path}.${key}`,\n skip.next.get(key),\n budget,\n )\n if (problem !== undefined) return problem\n }\n return undefined\n}\n\nfunction programFeatures<Ctx, R>(core: ProgramCore<R>): ProgramFeatures<Ctx, R> {\n const {\n source,\n analysis,\n expect,\n settings,\n checkEnv,\n compileOptions,\n residualOf,\n prepare,\n checked,\n settle,\n } = core\n\n let traceSync: CompiledProgram | undefined\n let traceAsync: CompiledProgram | undefined\n\n function explanation(\n tracer: Tracer,\n outcome: { ok: true; value: R } | { ok: false; error: BonsaiError },\n ): Explanation<R> {\n const trace = tracer.finish()\n // A result refused after the run (a promise-like value, a failed `expect`\n // check) is the whole expression's failure: marked on the root.\n if (!outcome.ok && trace.evaluated && trace.error === undefined) {\n trace.error = { code: outcome.error.code, message: outcome.error.message }\n delete trace.value\n }\n const truncated = tracer.truncated\n // Every rendering of this explanation lists a map's keys once, however it is sliced.\n const { listings } = tracer\n // Taken once, the first time any part is serialized: one budget for the\n // whole snapshot, however often a value recurs or the traces are sliced.\n let json: ExplanationJSON | undefined\n const parts: Parts = new WeakMap()\n const toJSON = (): ExplanationJSON => {\n if (json !== undefined) return json\n const budget = { left: SNAPSHOT_ENTRIES, keys: listings }\n const result = outcome.ok\n ? { ok: true as const, value: snapshot(outcome.value, budget) }\n : { ok: false as const, error: outcome.error.toJSON() }\n // Frozen: every serialization (and every part of it) is this same snapshot.\n return (json = freezeAll({\n ...result,\n truncated,\n trace: snapshotTrace(trace, budget, parts),\n }))\n }\n tracer.parts = () => (toJSON(), parts)\n return Object.freeze({\n ...outcome,\n trace,\n truncated,\n reasons: () => reasonsOf(trace, listings),\n toString: () => renderTrace(trace, truncated, listings),\n toJSON,\n })\n }\n\n function failure(error: unknown): { ok: false; error: BonsaiError } {\n return { ok: false, error: escaping(hostDataFailure(error, source)) }\n }\n\n // A residual's nodes keep the original's offsets (or none, for known\n // values), so their text comes from the printed residual instead: mapped\n // once, the first time the residual is explained.\n let residualText: ReadonlyMap<Node, string> | undefined\n const residualTextMap = (printed: string): ReadonlyMap<Node, string> =>\n (residualText ??= residualTexts(analysis.root, printed, {\n maxSourceLength: Math.max(settings.parseLimits.maxSourceLength, printed.length),\n // Printing adds parentheses (and unary minus for negative literals).\n maxDepth: settings.parseLimits.maxDepth * 4,\n maxNodes: settings.parseLimits.maxNodes * 4,\n }))\n const textOfResidual =\n residualOf === undefined\n ? undefined\n : (node: Node): string => residualTextMap(residualOf.source).get(node) ?? ''\n\n function tracerFor(explain: ExplainSettings): Tracer {\n return new Tracer(\n source,\n analysis.root,\n explain.maxIterations,\n explain.maxNodes,\n explain.exhaustive,\n textOfResidual,\n )\n }\n\n /** With `promised`, a thenable result fails as evaluate() fails it (see settle). */\n function explainSync(\n context: unknown,\n options: ExplainOptions | undefined,\n promised = false,\n ): Explanation<R> {\n const explain = explainSettings(options)\n if (analysis.async) {\n return explanation(\n tracerFor(explain),\n failure(\n raised(\n new BonsaiRuntimeError(\n 'ASYNC_IN_SYNC',\n 'This expression calls an async function; use explain() instead of explainSync()',\n { source },\n ),\n ),\n ),\n )\n }\n const code = (traceSync ??= compileProgram(analysis, 'sync', {\n ...compileOptions,\n trace: true,\n }))\n const limits = evaluationLimits(explain.evaluate, settings)\n const ctx = contextOf(context)\n const state = new State(settings.runtimeLimits, settings.clock)\n // A residual's text is mapped once per residual, work its partial()\n // already charged, so explaining costs the steps evaluating does.\n let tracer: Tracer | undefined\n try {\n prepare(state, ctx, limits, code.localCount)\n tracer = tracerFor(explain)\n state.tracer = tracer\n const value = code.run(state) as R\n checked(value, state)\n state.checkTime()\n if (promised) settle(value)\n return explanation(tracer, { ok: true, value })\n } catch (error) {\n return explanation(tracer ?? tracerFor(explain), failure(error))\n } finally {\n state.release()\n }\n }\n\n async function explainAsync(\n context: unknown,\n options: ExplainOptions | undefined,\n ): Promise<Explanation<R>> {\n if (!analysis.async) return explainSync(context, options, true)\n const explain = explainSettings(options)\n const code = (traceAsync ??= compileProgram(analysis, 'async', {\n ...compileOptions,\n trace: true,\n }))\n const limits = evaluationLimits(explain.evaluate, settings)\n const ctx = contextOf(context)\n const state = new State(settings.runtimeLimits, settings.clock)\n let tracer: Tracer | undefined\n try {\n prepare(state, ctx, limits, code.localCount)\n tracer = tracerFor(explain)\n state.tracer = tracer\n const value = ((await code.run(state)) as Out).v as R\n // In evaluate()'s order: the expected type, the deadline, then a promise-like value.\n checked(value, state)\n state.checkTime()\n settle(value)\n return explanation(tracer, { ok: true, value })\n } catch (error) {\n return explanation(tracer ?? tracerFor(explain), failure(error))\n } finally {\n state.release()\n }\n }\n\n // Each call the original program checked, by its source span and name. A\n // residual keeps the spans of the calls it copies, so it can run each one\n // with the overloads the original chose from the declared types: checking\n // the residual again would see other types (a known branch removed, an\n // open environment) and could pick another overload.\n let callsBySpan: Map<string, CallPlan | null> | undefined\n const callKey = (call: CallNode): string => `${call.start}:${call.end}:${call.name}`\n\n function originalPlans(\n compiled: Node,\n checkedCalls: ReadonlyMap<CallNode, CallPlan>,\n ): ReadonlyMap<CallNode, CallPlan> {\n if (callsBySpan === undefined) {\n callsBySpan = new Map()\n for (const [call, plan] of analysis.calls) {\n const key = callKey(call)\n // Two calls with one span cannot be told apart; neither is reused.\n callsBySpan.set(key, callsBySpan.has(key) ? null : plan)\n }\n }\n const bySpan = callsBySpan\n const plans = new Map(checkedCalls)\n const visit = (node: Node): void => {\n if (node.type === 'Call') {\n const plan = bySpan.get(callKey(node))\n if (plan !== undefined && plan !== null) plans.set(node, plan)\n }\n forEachChild(node, visit)\n }\n visit(compiled)\n return plans\n }\n\n // Sub-trees compiled on their own for partial evaluation, by free locals.\n // Which subtrees are closed depends on the data, so the cache holds at most\n // a few times the program's own nodes, and starts over when full.\n let subtrees = new Map<Node, Map<string, CompiledProgram>>()\n let subtreeNodes = 0\n\n function partial(\n known: Record<string, unknown>,\n rawOptions: unknown,\n translation = false,\n ): PartialResult<Ctx, R> {\n const options = partialOptions(rawOptions)\n // One budget for the whole partial evaluation, validated as evaluation's is.\n const limits = evaluationLimits(\n { maxSteps: options.maxSteps, timeout: options.timeout, signal: options.signal },\n settings,\n )\n const context = contextOf(known)\n const now = options.now\n const state = new State(settings.runtimeLimits, now === undefined ? settings.clock : () => now)\n state.reset(context, source, 0, limits.maxSteps, limits.timeout, limits.signal)\n try {\n // Known variables are validated as evaluation validates them, all but\n // the parts under listed unknown paths (incomplete by design): all the\n // data a residual has folded in is checked here, once.\n if (settings.validateContext && settings.variables !== undefined) {\n const variables = settings.variables\n const skip = unknownTree(options.unknown ?? [])\n try {\n const budget = validationBudget(source, {\n maxDepth: settings.runtimeLimits.maxValueDepth,\n maxSteps: limits.maxSteps,\n timeout: limits.timeout,\n })\n for (const [name, type] of Object.entries(variables)) {\n if (!Object.hasOwn(context, name)) continue\n const problem = describeKnown(context[name], type, name, skip.next.get(name), budget)\n invalidContext(problem, source)\n }\n } catch (error) {\n // Validation only reads the known data, so any other failure is the host's.\n if (!isOwn(error)) throw hostDataFailure(error, source)\n if (error instanceof BonsaiRuntimeError) return { status: 'error', error }\n throw error\n }\n }\n const result = partiallyEvaluate<R>(\n {\n analysis,\n hostKind: (name) => {\n const def = settings.host.get(name)\n return def === undefined\n ? undefined\n : { async: def.async === true, call: def.call === true }\n },\n charge: (steps = 1) => {\n state.charge(steps)\n },\n checkTime: () => {\n state.checkTime()\n },\n listLimit: (length, at) => {\n state.listLimit(length, at)\n },\n // Translation reads the residual tree, never its printed source.\n maxSourceLength: translation ? Infinity : settings.parseLimits.maxSourceLength,\n readKnown: (read) => {\n try {\n return read()\n } catch (error) {\n throw hostDataFailure(error, source)\n }\n },\n evaluate: (node, locals, size, total) => {\n const key = locals.map(([name]) => name).join('\\u0000')\n let code = subtrees.get(node)?.get(key)\n if (code === undefined) {\n if (subtreeNodes + size > SUBTREE_CACHE_FACTOR * total) {\n subtrees = new Map()\n subtreeNodes = 0\n }\n code = compileProgram({ ...analysis, root: node }, 'sync', {\n locals: locals.map(([name]) => name),\n })\n let byLocals = subtrees.get(node)\n if (byLocals === undefined) subtrees.set(node, (byLocals = new Map()))\n byLocals.set(key, code)\n subtreeNodes += size\n }\n state.ensureLocals(code.localCount)\n locals.forEach(([, value], slot) => {\n state.locals[slot] = value\n })\n try {\n return code.run(state)\n } catch (error) {\n throw hostDataFailure(error, source)\n }\n },\n evaluateFolded: (node, origin, locals) => {\n const plan = origin.type === 'Call' ? analysis.calls.get(origin) : undefined\n const code = compileProgram(\n {\n ...analysis,\n root: node,\n calls: plan === undefined ? new Map() : new Map([[node as CallNode, plan]]),\n },\n 'sync',\n { locals: locals.map(([name]) => name) },\n )\n state.ensureLocals(code.localCount)\n locals.forEach(([, value], slot) => {\n state.locals[slot] = value\n })\n try {\n return code.run(state)\n } catch (error) {\n throw hostDataFailure(error, source)\n }\n },\n compileResidual: (\n residual,\n bindings,\n residualSource,\n readsContext,\n knownRoots,\n dependsOn,\n ) => {\n // The original expression passed the checker; inlining known\n // values can make a failing branch statically visible, and that\n // failure must happen at run time, as it would have, so findings\n // here do not stop compilation. Analyzed as a tree (not\n // re-parsed), so the printer's parentheses cannot push it past\n // the parse depth limit.\n const reanalyzed: Analysis = analyze(\n residual,\n { ...checkEnv, variables: undefined, strict: false },\n { expected: expect },\n )\n return core.residual(\n // The plans go on the calls of the tree that is compiled: the\n // analysis root, where implicit lambdas are explicit nodes.\n { ...reanalyzed, calls: originalPlans(reanalyzed.root, reanalyzed.calls) },\n new Map(Object.entries(bindings)),\n {\n source: residualSource,\n readsContext,\n knownRoots,\n dependsOn,\n shapes: state.shapes,\n },\n )\n },\n },\n context,\n options,\n )\n // A decided result still has to match `expect`, as evaluation would check it.\n if (result.status === 'value') {\n try {\n checked(result.value, state)\n } catch (error) {\n // Checking reads the value, which can be host data.\n if (!isOwn(error)) throw hostDataFailure(error, source)\n if (error instanceof BonsaiRuntimeError) return { status: 'error', error }\n throw error\n }\n }\n // The residual accepts any object at run time; its parameter is typed by this program's context.\n return result as PartialResult<Ctx, R>\n } catch (error) {\n // Host data is read through readKnown, evaluate, and the checks above,\n // which report its failures as HOST_ERROR; anything else is a failure\n // of the engine itself, not of the caller's data, so it is not relabeled.\n if (isStackOverflow(error)) throw tooDeep(source, error)\n throw error\n } finally {\n state.release()\n }\n }\n\n return {\n explainSync,\n explainAsync,\n partial(program, known, options) {\n const translation = forTranslation(program)\n let result: PartialResult<Ctx, R>\n try {\n result = partial(known as Record<string, unknown>, options, translation)\n } catch (error) {\n throw escaping(error)\n }\n if (result.status === 'error') escaping(result.error)\n return Object.freeze(result)\n },\n }\n}\n\n/** Explaining and partial evaluation, for the main entry point's environments. */\nexport const explainAndPartial: Features = { program: programFeatures }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqDA,MAAM,uBAAuB;AAE7B,MAAM,sCAA2C,IAAI,IAAI;CACvD,GAAG;CACH;CACA;CACA;AACF,CAAC;;AAWD,SAAS,gBAAgB,SAAmC;CAC1D,IAAI,YAAY,KAAA,GACd,OAAO;EACL,eAAA;EACA,UAAU;EACV,YAAY;EACZ,UAAU,KAAA;CACZ;CAEF,IAAI,OAAO,YAAY,YAAY,YAAY,QAAQ,MAAM,QAAQ,OAAO,GAC1E,MAAM,IAAI,UAAU,mCAAmC;CACzD,IAAI;CACJ,IAAI;EACF,OAAO,EAAE,GAAI,QAAoC;CACnD,QAAQ;EACN,MAAM,IAAI,UAAU,mCAAmC;CACzD;CACA,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAChC,IAAI,CAAC,oBAAoB,IAAI,GAAG,GAC9B,MAAM,IAAI,UACR,+BAA+B,IAAI,sBAAsB,CAAC,GAAG,mBAAmB,CAAC,CAAC,KAAK,IAAI,EAAE,EAC/F;CAGJ,MAAM,SAAS,MAAc,aAA6B;EACxD,MAAM,QAAQ,KAAK;EACnB,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,IAAI,OAAO,UAAU,UAAU,MAAM,IAAI,UAAU,mBAAmB,KAAK,mBAAmB;EAC9F,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAC1C,MAAM,IAAI,WAAW,mBAAmB,KAAK,iCAAiC;EAChF,OAAO;CACT;CACA,IAAI,KAAK,eAAe,KAAA,KAAa,OAAO,KAAK,eAAe,WAC9D,MAAM,IAAI,UAAU,iDAA+C;CACrE,MAAM,EACJ,eAAe,aACf,eAAe,QACf,YAAY,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AAO,OAAO,KAAK;GAC7B,SAAS,OAAO;IAEd,IAAI,CAAC,MAAM,KAAK,GAAG,MAAM,gBAAgB,OAAO,MAAM;IACtD,IAAI,iBAAiB,oBAAoB,OAAO;KAAE,QAAQ;KAAS;IAAM;IACzE,MAAM;GACR;GAGF,OAAO;EACT,SAAS,OAAO;GAId,IAAI,gBAAgB,KAAK,GAAG,MAAM,QAAQ,QAAQ,KAAK;GACvD,MAAM;EACR,UAAU;GACR,MAAM,QAAQ;EAChB;CACF;CAEA,OAAO;EACL;EACA;EACA,QAAQ,SAAS,OAAO,SAAS;GAC/B,MAAM,cAAc,eAAe,OAAO;GAC1C,IAAI;GACJ,IAAI;IACF,SAAS,QAAQ,OAAkC,SAAS,WAAW;GACzE,SAAS,OAAO;IACd,MAAM,SAAS,KAAK;GACtB;GACA,IAAI,OAAO,WAAW,SAAS,SAAS,OAAO,KAAK;GACpD,OAAO,OAAO,OAAO,MAAM;EAC7B;CACF;AACF;;AAGA,MAAa,oBAA8B,EAAE,SAAS,gBAAgB"}
1
+ {"version":3,"file":"features.mjs","names":[],"sources":["../src/features.ts"],"sourcesContent":["/**\n * Explaining and partial evaluation: the program features the main entry\n * point adds to every environment. `bonsai-js/lite` leaves them out, so a\n * bundle that only checks and evaluates does not carry them.\n */\nimport { analyze, type Analysis, type CallPlan } from './check/checker.js'\nimport { compileProgram, type CompiledProgram } from './compile/compiler.js'\nimport { escaping, isOwn, raised } from './runtime/attribution.js'\nimport { BonsaiRuntimeError, type BonsaiError } from './errors.js'\nimport { describeMismatch, type Out, type ValidationBudget } from './functions/define.js'\nimport {\n EVALUATE_OPTION_KEYS,\n contextOf,\n evaluationLimits,\n hostDataFailure,\n invalidContext,\n isValidDate,\n validationBudget,\n} from './program.js'\nimport {\n type EvaluateOptions,\n type ExplainOptions,\n type Explanation,\n type Features,\n type ProgramCore,\n type ProgramFeatures,\n} from './environment.js'\nimport {\n forTranslation,\n partiallyEvaluate,\n residualTexts,\n type PartialOptions,\n type PartialResult,\n} from './partial.js'\nimport { isStackOverflow, tooDeep } from './runtime/overflow.js'\nimport { State } from './runtime/state.js'\nimport {\n DEFAULT_MAX_ITERATIONS,\n DEFAULT_MAX_TRACE_NODES,\n SNAPSHOT_ENTRIES,\n Tracer,\n freezeAll,\n reasonsOf,\n renderTrace,\n snapshot,\n snapshotTrace,\n type ExplanationJSON,\n type Parts,\n} from './runtime/trace.js'\nimport { isMap, keyListCost } from './runtime/values.js'\nimport { forEachChild, type CallNode, type Node } from './syntax/ast.js'\nimport { BLOCKED_NAMES, isName } from './syntax/lexer.js'\nimport type { Type } from './types.js'\n\n/** Subtrees compiled for partial evaluation, in nodes, kept per program: this times its own. */\nconst SUBTREE_CACHE_FACTOR = 2\n\nconst EXPLAIN_OPTION_KEYS: ReadonlySet<string> = new Set([\n ...EVALUATE_OPTION_KEYS,\n 'maxIterations',\n 'maxTraceNodes',\n 'exhaustive',\n])\n\ninterface ExplainSettings {\n readonly maxIterations: number\n readonly maxNodes: number\n readonly exhaustive: boolean\n /** The evaluation options among them, validated by evaluationLimits. */\n readonly evaluate: EvaluateOptions | undefined\n}\n\n/** Reads explain options once, with the same TypeError/RangeError rules as evaluate's. */\nfunction explainSettings(options: unknown): ExplainSettings {\n if (options === undefined) {\n return {\n maxIterations: DEFAULT_MAX_ITERATIONS,\n maxNodes: DEFAULT_MAX_TRACE_NODES,\n exhaustive: false,\n evaluate: undefined,\n }\n }\n if (typeof options !== 'object' || options === null || Array.isArray(options))\n throw new TypeError('Explain options must be an object')\n let copy: Record<string, unknown>\n try {\n copy = { ...(options as Record<string, unknown>) }\n } catch {\n throw new TypeError('Explain options could not be read')\n }\n for (const key of Object.keys(copy)) {\n if (!EXPLAIN_OPTION_KEYS.has(key)) {\n throw new TypeError(\n `Unknown explain option key \"${key}\" (expected one of: ${[...EXPLAIN_OPTION_KEYS].join(', ')})`,\n )\n }\n }\n const count = (name: string, fallback: number): number => {\n const value = copy[name]\n if (value === undefined) return fallback\n if (typeof value !== 'number') throw new TypeError(`Explain option \"${name}\" must be a number`)\n if (!Number.isSafeInteger(value) || value < 0)\n throw new RangeError(`Explain option \"${name}\" must be a non-negative integer`)\n return value\n }\n if (copy.exhaustive !== undefined && typeof copy.exhaustive !== 'boolean')\n throw new TypeError('Explain option \"exhaustive\" must be a boolean')\n const {\n maxIterations: _iterations,\n maxTraceNodes: _nodes,\n exhaustive: _exhaustive,\n ...evaluate\n } = copy\n return {\n maxIterations: count('maxIterations', DEFAULT_MAX_ITERATIONS),\n maxNodes: count('maxTraceNodes', DEFAULT_MAX_TRACE_NODES),\n exhaustive: copy.exhaustive === true,\n evaluate,\n }\n}\n\nconst PARTIAL_OPTION_KEYS: ReadonlySet<string> = new Set([\n 'unknown',\n 'callHostFunctions',\n 'now',\n 'maxSteps',\n 'timeout',\n 'signal',\n])\n/** A variable name, then field names as reads spell them: none empty or blocked. */\nconst isPath = (path: unknown): boolean => {\n if (typeof path !== 'string') return false\n const [name, ...fields] = path.split('.')\n return isName(name) && fields.every((field) => field !== '' && !BLOCKED_NAMES.has(field))\n}\n\n/** Reads partial() options once, with the same TypeError rules as the other options. */\nfunction partialOptions(options: unknown): PartialOptions {\n if (options === undefined) return {}\n if (typeof options !== 'object' || options === null || Array.isArray(options))\n throw new TypeError('Partial options must be an object')\n let copy: Record<string, unknown>\n try {\n copy = { ...(options as Record<string, unknown>) }\n if (Array.isArray(copy.unknown)) copy.unknown = [...(copy.unknown as unknown[])]\n } catch {\n throw new TypeError('Partial options could not be read')\n }\n for (const key of Object.keys(copy)) {\n if (!PARTIAL_OPTION_KEYS.has(key)) {\n throw new TypeError(\n `Unknown partial option key \"${key}\" (expected one of: ${[...PARTIAL_OPTION_KEYS].join(', ')})`,\n )\n }\n }\n const unknown = copy.unknown\n if (unknown !== undefined && (!Array.isArray(unknown) || !unknown.every(isPath)))\n throw new TypeError('Partial option \"unknown\" must be a list of variable names or dotted paths')\n if (copy.callHostFunctions !== undefined && typeof copy.callHostFunctions !== 'boolean')\n throw new TypeError('Partial option \"callHostFunctions\" must be a boolean')\n if (copy.now !== undefined && !isValidDate(copy.now))\n throw new TypeError('Partial option \"now\" must be a valid Date')\n return copy\n}\n\n/** Paths listed as unknown, as a tree of segments: `whole` marks a listed path. */\ninterface UnknownTree {\n whole: boolean\n readonly next: Map<string, UnknownTree>\n}\n\nfunction unknownTree(paths: readonly string[]): UnknownTree {\n const root: UnknownTree = { whole: false, next: new Map() }\n for (const path of paths) {\n let node = root\n for (const segment of path.split('.')) {\n let child = node.next.get(segment)\n if (child === undefined) node.next.set(segment, (child = { whole: false, next: new Map() }))\n node = child\n }\n node.whole = true\n }\n return root\n}\n\n/**\n * Why `value` does not conform to `type`, leaving out the parts of it under\n * listed unknown paths (`skip`): those are incomplete by design. Everything\n * else is checked as evaluation checks a context.\n */\nfunction describeKnown(\n value: unknown,\n type: Type,\n path: string,\n skip: UnknownTree | undefined,\n budget: ValidationBudget,\n): string | undefined {\n if (skip === undefined) return describeMismatch(value, type, path, budget)\n if (skip.whole) return undefined\n if (type.kind === 'union') {\n let first: string | undefined\n for (const member of type.types) {\n const problem = describeKnown(value, member, path, skip, budget)\n if (problem === undefined) return undefined\n first ??= problem\n }\n return first\n }\n const actual = value === undefined ? null : value\n if (type.kind !== 'map' || !isMap(actual)) return describeMismatch(value, type, path, budget)\n if (--budget.remaining < 0) budget.onExhausted('steps')\n for (const [key, fieldType] of Object.entries(type.fields)) {\n const field = Object.hasOwn(actual, key) ? actual[key] : null\n const problem = describeKnown(field, fieldType, `${path}.${key}`, skip.next.get(key), budget)\n if (problem !== undefined) return problem\n }\n if (type.rest === undefined) return undefined\n const keys = Object.keys(actual)\n budget.remaining -= keyListCost(keys.length)\n if (budget.remaining < 0) budget.onExhausted('steps')\n for (const key of keys) {\n // As evaluation's validation: keys the language never reads, or that hold undefined, are not data.\n if (Object.hasOwn(type.fields, key) || BLOCKED_NAMES.has(key) || actual[key] === undefined)\n continue\n const problem = describeKnown(\n actual[key],\n type.rest,\n `${path}.${key}`,\n skip.next.get(key),\n budget,\n )\n if (problem !== undefined) return problem\n }\n return undefined\n}\n\nfunction programFeatures<Ctx, R>(core: ProgramCore<R>): ProgramFeatures<Ctx, R> {\n const {\n source,\n analysis,\n expect,\n settings,\n checkEnv,\n compileOptions,\n residualOf,\n prepare,\n checked,\n settle,\n } = core\n\n let traceSync: CompiledProgram | undefined\n let traceAsync: CompiledProgram | undefined\n\n function explanation(\n tracer: Tracer,\n outcome: { ok: true; value: R } | { ok: false; error: BonsaiError },\n ): Explanation<R> {\n const trace = tracer.finish()\n // A result refused after the run (a promise-like value, a failed `expect`\n // check) is the whole expression's failure: marked on the root.\n if (!outcome.ok && trace.evaluated && trace.error === undefined) {\n trace.error = { code: outcome.error.code, message: outcome.error.message }\n delete trace.value\n }\n const truncated = tracer.truncated\n // Every rendering of this explanation lists a map's keys once, however it is sliced.\n const { listings } = tracer\n // Taken once, the first time any part is serialized: one budget for the\n // whole snapshot, however often a value recurs or the traces are sliced.\n let json: ExplanationJSON | undefined\n const parts: Parts = new WeakMap()\n const toJSON = (): ExplanationJSON => {\n if (json !== undefined) return json\n const budget = { left: SNAPSHOT_ENTRIES, keys: listings }\n const result = outcome.ok\n ? { ok: true as const, value: snapshot(outcome.value, budget) }\n : { ok: false as const, error: outcome.error.toJSON() }\n // Frozen: every serialization (and every part of it) is this same snapshot.\n return (json = freezeAll({\n ...result,\n truncated,\n trace: snapshotTrace(trace, budget, parts),\n }))\n }\n tracer.parts = () => (toJSON(), parts)\n return Object.freeze({\n ...outcome,\n trace,\n truncated,\n reasons: () => reasonsOf(trace, listings),\n toString: () => renderTrace(trace, truncated, listings),\n toJSON,\n })\n }\n\n function failure(error: unknown): { ok: false; error: BonsaiError } {\n return { ok: false, error: escaping(hostDataFailure(error, source)) }\n }\n\n // A residual's nodes keep the original's offsets (or none, for known\n // values), so their text comes from the printed residual instead: mapped\n // once, the first time the residual is explained.\n let residualText: ReadonlyMap<Node, string> | undefined\n const residualTextMap = (printed: string): ReadonlyMap<Node, string> =>\n (residualText ??= residualTexts(analysis.root, printed, {\n maxSourceLength: Math.max(settings.parseLimits.maxSourceLength, printed.length),\n // Printing adds parentheses (and unary minus for negative literals).\n maxDepth: settings.parseLimits.maxDepth * 4,\n maxNodes: settings.parseLimits.maxNodes * 4,\n }))\n const textOfResidual =\n residualOf === undefined\n ? undefined\n : (node: Node): string => residualTextMap(residualOf.source).get(node) ?? ''\n\n function tracerFor(explain: ExplainSettings): Tracer {\n return new Tracer(\n source,\n analysis.root,\n explain.maxIterations,\n explain.maxNodes,\n explain.exhaustive,\n textOfResidual,\n )\n }\n\n /** With `promised`, a thenable result fails as evaluate() fails it (see settle). */\n function explainSync(\n context: unknown,\n options: ExplainOptions | undefined,\n promised = false,\n ): Explanation<R> {\n const explain = explainSettings(options)\n if (analysis.async) {\n return explanation(\n tracerFor(explain),\n failure(\n raised(\n new BonsaiRuntimeError(\n 'ASYNC_IN_SYNC',\n 'This expression calls an async function; use explain() instead of explainSync()',\n { source },\n ),\n ),\n ),\n )\n }\n const code = (traceSync ??= compileProgram(analysis, 'sync', {\n ...compileOptions,\n trace: true,\n }))\n const limits = evaluationLimits(explain.evaluate, settings)\n const ctx = contextOf(context)\n const state = new State(settings.runtimeLimits, settings.clock)\n // A residual's text is mapped once per residual, work its partial()\n // already charged, so explaining costs the steps evaluating does.\n let tracer: Tracer | undefined\n try {\n prepare(state, ctx, limits, code.localCount)\n tracer = tracerFor(explain)\n state.tracer = tracer\n const value = code.run(state) as R\n checked(value, state)\n state.checkTime()\n if (promised) settle(value)\n return explanation(tracer, { ok: true, value })\n } catch (error) {\n return explanation(tracer ?? tracerFor(explain), failure(error))\n } finally {\n state.release()\n }\n }\n\n async function explainAsync(\n context: unknown,\n options: ExplainOptions | undefined,\n ): Promise<Explanation<R>> {\n if (!analysis.async) return explainSync(context, options, true)\n const explain = explainSettings(options)\n const code = (traceAsync ??= compileProgram(analysis, 'async', {\n ...compileOptions,\n trace: true,\n }))\n const limits = evaluationLimits(explain.evaluate, settings)\n const ctx = contextOf(context)\n const state = new State(settings.runtimeLimits, settings.clock)\n let tracer: Tracer | undefined\n try {\n prepare(state, ctx, limits, code.localCount)\n tracer = tracerFor(explain)\n state.tracer = tracer\n const value = ((await code.run(state)) as Out).v as R\n // In evaluate()'s order: the expected type, the deadline, then a promise-like value.\n checked(value, state)\n state.checkTime()\n settle(value)\n return explanation(tracer, { ok: true, value })\n } catch (error) {\n return explanation(tracer ?? tracerFor(explain), failure(error))\n } finally {\n state.release()\n }\n }\n\n // Each call the original program checked, by its source span and name. A\n // residual keeps the spans of the calls it copies, so it can run each one\n // with the overloads the original chose from the declared types: checking\n // the residual again would see other types (a known branch removed, an\n // open environment) and could pick another overload.\n let callsBySpan: Map<string, CallPlan | null> | undefined\n const callKey = (call: CallNode): string => `${call.start}:${call.end}:${call.name}`\n\n function originalPlans(\n compiled: Node,\n checkedCalls: ReadonlyMap<CallNode, CallPlan>,\n ): ReadonlyMap<CallNode, CallPlan> {\n if (callsBySpan === undefined) {\n callsBySpan = new Map()\n for (const [call, plan] of analysis.calls) {\n const key = callKey(call)\n // Two calls with one span cannot be told apart; neither is reused.\n callsBySpan.set(key, callsBySpan.has(key) ? null : plan)\n }\n }\n const bySpan = callsBySpan\n const plans = new Map(checkedCalls)\n const visit = (node: Node): void => {\n if (node.type === 'Call') {\n const plan = bySpan.get(callKey(node))\n if (plan !== undefined && plan !== null) plans.set(node, plan)\n }\n forEachChild(node, visit)\n }\n visit(compiled)\n return plans\n }\n\n // Sub-trees compiled on their own for partial evaluation, by free locals.\n // Which subtrees are closed depends on the data, so the cache holds at most\n // a few times the program's own nodes, and starts over when full.\n let subtrees = new Map<Node, Map<string, CompiledProgram>>()\n let subtreeNodes = 0\n\n function partial(\n known: Record<string, unknown>,\n rawOptions: unknown,\n translation = false,\n ): PartialResult<Ctx, R> {\n const options = partialOptions(rawOptions)\n // One budget for the whole partial evaluation, validated as evaluation's is.\n const limits = evaluationLimits(\n { maxSteps: options.maxSteps, timeout: options.timeout, signal: options.signal },\n settings,\n )\n const context = contextOf(known)\n const now = options.now\n const state = new State(settings.runtimeLimits, now === undefined ? settings.clock : () => now)\n state.reset(context, source, 0, limits.maxSteps, limits.timeout, limits.signal)\n try {\n // Known variables are validated as evaluation validates them, all but\n // the parts under listed unknown paths (incomplete by design): all the\n // data a residual has folded in is checked here, once.\n if (settings.validateContext && settings.variables !== undefined) {\n const variables = settings.variables\n const skip = unknownTree(options.unknown ?? [])\n try {\n const budget = validationBudget(source, {\n maxDepth: settings.runtimeLimits.maxValueDepth,\n maxSteps: limits.maxSteps,\n timeout: limits.timeout,\n })\n for (const [name, type] of Object.entries(variables)) {\n if (!Object.hasOwn(context, name)) continue\n const problem = describeKnown(context[name], type, name, skip.next.get(name), budget)\n invalidContext(problem, source)\n }\n } catch (error) {\n // Validation only reads the known data, so any other failure is the host's.\n if (!isOwn(error)) throw hostDataFailure(error, source)\n if (error instanceof BonsaiRuntimeError) return { status: 'error', error }\n throw error\n }\n }\n const result = partiallyEvaluate<R>(\n {\n analysis,\n hostKind: (name) => {\n const def = settings.host.get(name)\n return def === undefined\n ? undefined\n : { async: def.async === true, call: def.call === true }\n },\n charge: (steps = 1) => {\n state.charge(steps)\n },\n checkTime: () => {\n state.checkTime()\n },\n listLimit: (length, at) => {\n state.listLimit(length, at)\n },\n // Translation reads the residual tree, never its printed source.\n maxSourceLength: translation ? Infinity : settings.parseLimits.maxSourceLength,\n readKnown: (read) => {\n try {\n return read()\n } catch (error) {\n throw hostDataFailure(error, source)\n }\n },\n evaluate: (node, locals, size, total) => {\n const key = locals.map(([name]) => name).join('\\u0000')\n let code = subtrees.get(node)?.get(key)\n if (code === undefined) {\n if (subtreeNodes + size > SUBTREE_CACHE_FACTOR * total) {\n subtrees = new Map()\n subtreeNodes = 0\n }\n code = compileProgram({ ...analysis, root: node }, 'sync', {\n locals: locals.map(([name]) => name),\n })\n let byLocals = subtrees.get(node)\n if (byLocals === undefined) subtrees.set(node, (byLocals = new Map()))\n byLocals.set(key, code)\n subtreeNodes += size\n }\n state.ensureLocals(code.localCount)\n locals.forEach(([, value], slot) => {\n state.locals[slot] = value\n })\n try {\n return code.run(state)\n } catch (error) {\n throw hostDataFailure(error, source)\n }\n },\n evaluateFolded: (node, origin, locals) => {\n const plan = origin.type === 'Call' ? analysis.calls.get(origin) : undefined\n const code = compileProgram(\n {\n ...analysis,\n root: node,\n calls: plan === undefined ? new Map() : new Map([[node as CallNode, plan]]),\n },\n 'sync',\n { locals: locals.map(([name]) => name) },\n )\n state.ensureLocals(code.localCount)\n locals.forEach(([, value], slot) => {\n state.locals[slot] = value\n })\n try {\n return code.run(state)\n } catch (error) {\n throw hostDataFailure(error, source)\n }\n },\n compileResidual: (\n residual,\n bindings,\n residualSource,\n readsContext,\n knownRoots,\n dependsOn,\n ) => {\n // The original expression passed the checker; inlining known\n // values can make a failing branch statically visible, and that\n // failure must happen at run time, as it would have, so findings\n // here do not stop compilation. Analyzed as a tree (not\n // re-parsed), so the printer's parentheses cannot push it past\n // the parse depth limit.\n const reanalyzed: Analysis = analyze(\n residual,\n { ...checkEnv, variables: undefined, strict: false },\n { expected: expect },\n )\n return core.residual(\n // The plans go on the calls of the tree that is compiled: the\n // analysis root, where implicit lambdas are explicit nodes.\n { ...reanalyzed, calls: originalPlans(reanalyzed.root, reanalyzed.calls) },\n new Map(Object.entries(bindings)),\n {\n source: residualSource,\n readsContext,\n knownRoots,\n dependsOn,\n shapes: state.shapes,\n },\n )\n },\n },\n context,\n options,\n )\n // A decided result still has to match `expect`, as evaluation would check it.\n if (result.status === 'value') {\n try {\n checked(result.value, state)\n } catch (error) {\n // Checking reads the value, which can be host data.\n if (!isOwn(error)) throw hostDataFailure(error, source)\n if (error instanceof BonsaiRuntimeError) return { status: 'error', error }\n throw error\n }\n }\n // The residual accepts any object at run time; its parameter is typed by this program's context.\n return result as PartialResult<Ctx, R>\n } catch (error) {\n // Host data is read through readKnown, evaluate, and the checks above,\n // which report its failures as HOST_ERROR; anything else is a failure\n // of the engine itself, not of the caller's data, so it is not relabeled.\n if (isStackOverflow(error)) throw tooDeep(source, error)\n throw error\n } finally {\n state.release()\n }\n }\n\n return {\n explainSync,\n explainAsync,\n partial(program, known, options) {\n const translation = forTranslation(program)\n let result: PartialResult<Ctx, R>\n try {\n result = partial(known as Record<string, unknown>, options, translation)\n } catch (error) {\n throw escaping(error)\n }\n if (result.status === 'error') escaping(result.error)\n return Object.freeze(result)\n },\n }\n}\n\n/** Explaining and partial evaluation, for the main entry point's environments. */\nexport const explainAndPartial: Features = { program: programFeatures }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuDA,MAAM,uBAAuB;AAE7B,MAAM,sCAA2C,IAAI,IAAI;CACvD,GAAG;CACH;CACA;CACA;AACF,CAAC;;AAWD,SAAS,gBAAgB,SAAmC;CAC1D,IAAI,YAAY,KAAA,GACd,OAAO;EACL,eAAA;EACA,UAAU;EACV,YAAY;EACZ,UAAU,KAAA;CACZ;CAEF,IAAI,OAAO,YAAY,YAAY,YAAY,QAAQ,MAAM,QAAQ,OAAO,GAC1E,MAAM,IAAI,UAAU,mCAAmC;CACzD,IAAI;CACJ,IAAI;EACF,OAAO,EAAE,GAAI,QAAoC;CACnD,QAAQ;EACN,MAAM,IAAI,UAAU,mCAAmC;CACzD;CACA,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAChC,IAAI,CAAC,oBAAoB,IAAI,GAAG,GAC9B,MAAM,IAAI,UACR,+BAA+B,IAAI,sBAAsB,CAAC,GAAG,mBAAmB,CAAC,CAAC,KAAK,IAAI,EAAE,EAC/F;CAGJ,MAAM,SAAS,MAAc,aAA6B;EACxD,MAAM,QAAQ,KAAK;EACnB,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,IAAI,OAAO,UAAU,UAAU,MAAM,IAAI,UAAU,mBAAmB,KAAK,mBAAmB;EAC9F,IAAI,CAAC,OAAO,cAAc,KAAK,KAAK,QAAQ,GAC1C,MAAM,IAAI,WAAW,mBAA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