@pulse-compute/wasm-compiler 0.0.0 → 1.0.0-beta.1
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 +52 -1
- package/bin/provider-proof-composition.js +34 -0
- package/bin/pulsewasm-extract.js +20 -0
- package/package.json +60 -5
- package/src/artifacts-dir.js +13 -0
- package/src/ast-json.js +52 -0
- package/src/build-manifest.js +354 -0
- package/src/canonical-api-compiler.js +245 -0
- package/src/canonical-native-compiler.js +411 -0
- package/src/canonical-native-plan.js +1477 -0
- package/src/canonical-project-compiler.js +1218 -0
- package/src/canonical-router-compiler.js +25 -0
- package/src/cli-intents.js +1235 -0
- package/src/cli.js +1927 -0
- package/src/codegen/assemblyscript-compile.js +3 -0
- package/src/codegen/assemblyscript-core.js +3 -0
- package/src/codegen/assemblyscript-shape.js +3 -0
- package/src/codegen/assemblyscript-wasm-smoke.js +3 -0
- package/src/codegen/backend-capabilities.js +3 -0
- package/src/codegen/channel-broadcaster.js +3 -0
- package/src/codegen/compiled-handlers.js +3 -0
- package/src/codegen/compiled-wasm-runtime.js +3 -0
- package/src/codegen/config-references.js +248 -0
- package/src/codegen/dispatch-ts.js +145 -0
- package/src/codegen/effect-composition.js +331 -0
- package/src/codegen/effect-runtime.js +418 -0
- package/src/codegen/execution-harness-ts.js +467 -0
- package/src/codegen/handler-bindings-ts.js +298 -0
- package/src/codegen/handler-library-contracts.js +3 -0
- package/src/codegen/host-capabilities.js +3 -0
- package/src/codegen/host-runtime-kernel.js +3 -0
- package/src/codegen/integrated-compiled-app.js +3 -0
- package/src/codegen/json-body.js +3 -0
- package/src/codegen/library-sidecars.js +3 -0
- package/src/codegen/local-harness-ts.js +453 -0
- package/src/codegen/pulse-wrapper.js +217 -0
- package/src/codegen/request-result-headers.js +3 -0
- package/src/codegen/schema-json-compile.js +3 -0
- package/src/codegen/schema-json-sidecar-v2.js +3 -0
- package/src/codegen/schema-json-sidecar.js +3 -0
- package/src/codegen/streaming-passthrough.js +3 -0
- package/src/codegen/wasm-host-abi.js +3 -0
- package/src/codegen/wasm-host-bridge.js +3 -0
- package/src/compiled-wasm-host-runtime-kv.js +3 -0
- package/src/config-resolver.js +813 -0
- package/src/crypto-requirement-planner.js +89 -0
- package/src/definitions/config-schema.js +14 -0
- package/src/definitions/handler-roles.js +14 -0
- package/src/definitions/path-grammar.js +14 -0
- package/src/definitions/router-api.js +14 -0
- package/src/diagnostics/codes.js +14 -0
- package/src/diagnostics/reporter.js +14 -0
- package/src/diagnostics.js +14 -0
- package/src/dispatch-table.js +400 -0
- package/src/events/event-emit.js +265 -0
- package/src/events/event-topology.js +127 -0
- package/src/execution-plan.js +463 -0
- package/src/extractor.js +2816 -0
- package/src/handler-eval.js +1154 -0
- package/src/handler-table.js +326 -0
- package/src/index.js +19 -0
- package/src/javascript-application-plan.js +181 -0
- package/src/kv-provider.js +3 -0
- package/src/path-table.js +60 -0
- package/src/path.js +14 -0
- package/src/patterns/config-define.js +30 -0
- package/src/patterns/dependency-call.js +18 -0
- package/src/patterns/env-lookup.js +13 -0
- package/src/patterns/handler-reference.js +29 -0
- package/src/patterns/path-literal.js +35 -0
- package/src/patterns/result.js +15 -0
- package/src/patterns/router-chain-call.js +50 -0
- package/src/patterns/router-construction.js +19 -0
- package/src/project/package-reachability.js +782 -0
- package/src/project/reachable-graph-builder.js +992 -0
- package/src/project/reachable-graph-contract.js +54 -0
- package/src/project/reachable-graph-implementation.js +36 -0
- package/src/project/router-module-linker.js +710 -0
- package/src/project-config-compiler.js +222 -0
- package/src/project-target-support.js +500 -0
- package/src/provider-toolchain.js +299 -0
- package/src/spine/async-surface-normalizer.js +312 -0
- package/src/spine/canonical-handler-ir.js +335 -0
- package/src/spine/canonical-native-module.js +87 -0
- package/src/spine/canonical-native-plan.js +89 -0
- package/src/spine/canonical-project.js +76 -0
- package/src/spine/canonical-router.js +155 -0
- package/src/spine/canonical-source.js +165 -0
- package/src/spine/diagnostic-authority.js +290 -0
- package/src/spine/equivalence.js +262 -0
- package/src/spine/guest-unit-stage.js +87 -0
- package/src/spine/handler-ir-emitter.js +454 -0
- package/src/spine/handler-ir-managed.js +1597 -0
- package/src/spine/handler-ir.js +797 -0
- package/src/spine/handler-surface-authority.js +585 -0
- package/src/spine/package-operation-seam.js +1015 -0
- package/src/spine/pipeline.js +202 -0
- package/src/spine/plain-handler-frontend.js +537 -0
- package/src/spine/provider-requirement-authority.js +208 -0
- package/src/spine/router-control-contract.js +17 -0
- package/src/spine/router-handler-frontend.js +513 -0
- package/src/spine/router-handler-ir.js +372 -0
- package/src/spine/router-topology-frontend.js +635 -0
- package/src/stable-id.js +14 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const crypto = require('node:crypto');
|
|
4
|
+
const { HANDLER_IR_VERSION } = require('./handler-ir.js');
|
|
5
|
+
|
|
6
|
+
const CANONICAL_HANDLER_IR_VERSION = HANDLER_IR_VERSION;
|
|
7
|
+
const CANONICAL_HANDLER_IR_CONTRACT_ID = 'pulse.canonical-handler-ir';
|
|
8
|
+
const payloads = new WeakMap();
|
|
9
|
+
|
|
10
|
+
class CanonicalHandlerIrError extends Error {
|
|
11
|
+
constructor(code, message, detail = {}) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = 'CanonicalHandlerIrError';
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.detail = Object.freeze({ ...detail });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function stableHash(value) {
|
|
20
|
+
return crypto.createHash('sha256').update(String(value)).digest('hex');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function requireString(value, field) {
|
|
24
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
25
|
+
throw new CanonicalHandlerIrError('PULSE_CANONICAL_HANDLER_IR_INVALID', `${field} must be a non-empty string.`, { field, value });
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function annotateSites(effectSites, continuationSites, routerMetadata) {
|
|
31
|
+
const routeRanges = routerMetadata && Array.isArray(routerMetadata.routes) ? routerMetadata.routes : [];
|
|
32
|
+
const entryRanges = routerMetadata && Array.isArray(routerMetadata.entries) ? routerMetadata.entries : [];
|
|
33
|
+
|
|
34
|
+
function ownerForPosition(position) {
|
|
35
|
+
const offset = position && Number(position.offset);
|
|
36
|
+
if (!Number.isSafeInteger(offset)) return undefined;
|
|
37
|
+
return entryRanges.find((entry) => entry && entry.generatedRange && offset >= entry.generatedRange.start && offset < entry.generatedRange.end)
|
|
38
|
+
|| routeRanges.find((route) => route && route.generatedRange && offset >= route.generatedRange.start && offset < route.generatedRange.end);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function annotate(site) {
|
|
42
|
+
const owner = ownerForPosition(site && site.position);
|
|
43
|
+
if (!owner) return site;
|
|
44
|
+
const ownerKind = owner.kind || 'route';
|
|
45
|
+
const plane = owner.plane || (ownerKind === 'event' ? 'event' : 'http');
|
|
46
|
+
const annotated = {
|
|
47
|
+
...site,
|
|
48
|
+
applicationEntryStableId: owner.stableId,
|
|
49
|
+
applicationEntryKind: ownerKind,
|
|
50
|
+
applicationEntryPlane: plane,
|
|
51
|
+
applicationEntryIndex: Number.isInteger(owner.index) ? owner.index : undefined
|
|
52
|
+
};
|
|
53
|
+
if (plane === 'http') {
|
|
54
|
+
annotated.routerEntryStableId = owner.stableId;
|
|
55
|
+
annotated.routerEntryKind = ownerKind;
|
|
56
|
+
annotated.routerEntryIndex = Number.isInteger(owner.index) ? owner.index : undefined;
|
|
57
|
+
annotated.routerEntryPath = owner.path || undefined;
|
|
58
|
+
}
|
|
59
|
+
if (ownerKind === 'route') {
|
|
60
|
+
annotated.routeStableId = owner.routeStableId || owner.stableId;
|
|
61
|
+
annotated.routeRuntimeId = Number.isInteger(owner.routeRuntimeId) ? owner.routeRuntimeId : owner.runtimeId;
|
|
62
|
+
annotated.routeMethod = owner.method;
|
|
63
|
+
annotated.routePath = owner.path;
|
|
64
|
+
}
|
|
65
|
+
if (ownerKind === 'event') {
|
|
66
|
+
annotated.eventStableId = owner.eventStableId || owner.stableId;
|
|
67
|
+
annotated.eventRuntimeId = owner.eventRuntimeId;
|
|
68
|
+
annotated.eventType = owner.eventType;
|
|
69
|
+
annotated.eventSchemaId = owner.eventSchemaId;
|
|
70
|
+
}
|
|
71
|
+
return Object.freeze(annotated);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
effectSites: Object.freeze(effectSites.map(annotate)),
|
|
76
|
+
continuationSites: Object.freeze(continuationSites.map(annotate))
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function providerOperationsForSites(effectSites, continuationSites) {
|
|
81
|
+
return Object.freeze(effectSites.map((site) => Object.freeze({
|
|
82
|
+
id: site.id,
|
|
83
|
+
kind: site.providerKind || (site.kind === 'fetch' ? 'fetch' : String(site.kind).split('.')[0]),
|
|
84
|
+
operation: site.operation || (site.kind === 'fetch' ? 'dispatch' : undefined),
|
|
85
|
+
capability: site.capability,
|
|
86
|
+
opaqueReturn: (site.kind === 'fetch' && continuationSites.some((continuation) => continuation.kind === 'opaque-fetch-return' && continuation.effectIds.includes(site.id))) || site.result === 'opaque-response',
|
|
87
|
+
resource: site.resource,
|
|
88
|
+
package: site.package,
|
|
89
|
+
contractId: site.contractId,
|
|
90
|
+
payload: site.payload,
|
|
91
|
+
result: site.result,
|
|
92
|
+
position: site.position,
|
|
93
|
+
routeStableId: site.routeStableId,
|
|
94
|
+
routeRuntimeId: site.routeRuntimeId,
|
|
95
|
+
routeMethod: site.routeMethod,
|
|
96
|
+
routePath: site.routePath,
|
|
97
|
+
routerEntryStableId: site.routerEntryStableId,
|
|
98
|
+
routerEntryKind: site.routerEntryKind,
|
|
99
|
+
routerEntryIndex: site.routerEntryIndex,
|
|
100
|
+
routerEntryPath: site.routerEntryPath,
|
|
101
|
+
applicationEntryStableId: site.applicationEntryStableId,
|
|
102
|
+
applicationEntryKind: site.applicationEntryKind,
|
|
103
|
+
applicationEntryPlane: site.applicationEntryPlane,
|
|
104
|
+
applicationEntryIndex: site.applicationEntryIndex,
|
|
105
|
+
eventStableId: site.eventStableId,
|
|
106
|
+
eventRuntimeId: site.eventRuntimeId,
|
|
107
|
+
eventType: site.eventType,
|
|
108
|
+
eventSchemaId: site.eventSchemaId
|
|
109
|
+
})));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function packageEffectSummary(packageEffects) {
|
|
113
|
+
return Object.freeze(packageEffects.map((effect) => Object.freeze({
|
|
114
|
+
contractId: effect.contractId,
|
|
115
|
+
package: effect.package,
|
|
116
|
+
import: effect.import,
|
|
117
|
+
kind: effect.kind,
|
|
118
|
+
operation: effect.operation,
|
|
119
|
+
capability: effect.capability,
|
|
120
|
+
result: effect.result,
|
|
121
|
+
placement: effect.placement,
|
|
122
|
+
range: effect.range
|
|
123
|
+
})));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function createCanonicalHandlerIr(input) {
|
|
127
|
+
if (!input || typeof input !== 'object') {
|
|
128
|
+
throw new CanonicalHandlerIrError('PULSE_CANONICAL_HANDLER_IR_INVALID', 'Canonical Handler IR input must be an object.');
|
|
129
|
+
}
|
|
130
|
+
const frontend = input.frontend;
|
|
131
|
+
const operationIr = input.operationIr;
|
|
132
|
+
if (!frontend || !['canonical-source', 'canonical-router-handler'].includes(frontend.frontend)) {
|
|
133
|
+
throw new CanonicalHandlerIrError('PULSE_CANONICAL_HANDLER_IR_FRONTEND_UNSUPPORTED', 'Canonical Handler IR requires a supported internal handler frontend.', {
|
|
134
|
+
frontend: frontend && frontend.frontend
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (!operationIr || operationIr.version !== HANDLER_IR_VERSION) {
|
|
138
|
+
throw new CanonicalHandlerIrError('PULSE_CANONICAL_HANDLER_IR_INVALID', `Canonical Handler IR requires ${HANDLER_IR_VERSION}.`, { version: operationIr && operationIr.version });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const compilerVersion = requireString(input.compilerVersion, 'compilerVersion');
|
|
142
|
+
const programVersion = requireString(input.programVersion, 'programVersion');
|
|
143
|
+
const runtimeProtocolVersion = requireString(input.runtimeProtocolVersion, 'runtimeProtocolVersion');
|
|
144
|
+
const options = input.options || {};
|
|
145
|
+
const sourceText = frontend.sourceText;
|
|
146
|
+
const authoringSourceText = options.authoringSourceText === undefined ? sourceText : String(options.authoringSourceText);
|
|
147
|
+
const loweredSourceText = options.loweredSourceText === undefined ? sourceText : String(options.loweredSourceText);
|
|
148
|
+
const schemaBundle = frontend.schemaBundle || Object.freeze({
|
|
149
|
+
registry: Object.freeze([]),
|
|
150
|
+
schemaIds: Object.freeze([]),
|
|
151
|
+
sourceHash: stableHash(`empty-schema:${frontend.fileName || ''}`)
|
|
152
|
+
});
|
|
153
|
+
const packageEffectsInput = Object.freeze([...(options.packageEffects || [])]);
|
|
154
|
+
const packageEffects = packageEffectSummary(packageEffectsInput);
|
|
155
|
+
const packageIntrinsicsInput = Object.freeze([...(options.packageIntrinsics || [])]);
|
|
156
|
+
const metadataExtensions = options.metadataExtensions && typeof options.metadataExtensions === 'object' ? options.metadataExtensions : {};
|
|
157
|
+
const compilerOwnedIntrinsics = Object.freeze([...(options.compilerOwnedIntrinsics || packageIntrinsicsInput)].map((entry) => Object.freeze({
|
|
158
|
+
compilerName: String(entry.compilerName),
|
|
159
|
+
intrinsic: String(entry.intrinsic),
|
|
160
|
+
valueKind: String(entry.valueKind || 'unknown')
|
|
161
|
+
})));
|
|
162
|
+
const compilerOwnedCalls = Object.freeze([...new Set([
|
|
163
|
+
...(options.compilerOwnedCalls || []).map(String),
|
|
164
|
+
...compilerOwnedIntrinsics.map((entry) => entry.compilerName)
|
|
165
|
+
])]);
|
|
166
|
+
const compilerPrelude = options.compilerPrelude || '';
|
|
167
|
+
const routerMetadata = options.routerMetadata || metadataExtensions.router;
|
|
168
|
+
const applicationEntries = metadataExtensions.applicationEntries
|
|
169
|
+
|| routerMetadata && routerMetadata.applicationEntries;
|
|
170
|
+
const events = metadataExtensions.events || routerMetadata && routerMetadata.events;
|
|
171
|
+
const annotated = annotateSites(operationIr.effectSites, operationIr.continuationSites, metadataExtensions.router);
|
|
172
|
+
const capabilities = Object.freeze([...new Set([
|
|
173
|
+
...operationIr.analysis.capabilities,
|
|
174
|
+
...annotated.effectSites.map((site) => site.capability)
|
|
175
|
+
])].sort());
|
|
176
|
+
const providerOperations = providerOperationsForSites(annotated.effectSites, annotated.continuationSites);
|
|
177
|
+
const warnings = Object.freeze([...(frontend.warnings || []), ...(metadataExtensions.warnings || [])]);
|
|
178
|
+
const genericRequestCount = Number(operationIr.analysis.genericJsonCount || 0);
|
|
179
|
+
const schemaBoundRequestCount = Number(operationIr.analysis.schemaBoundJsonCount || 0);
|
|
180
|
+
const jsonPolicy = options.emitJsonPolicy === true || genericRequestCount > 0 || schemaBoundRequestCount > 0 || metadataExtensions.json
|
|
181
|
+
? Object.freeze({
|
|
182
|
+
strict: options.strict !== false,
|
|
183
|
+
schemaBoundRequestCount,
|
|
184
|
+
genericRequestCount,
|
|
185
|
+
genericParserRequired: genericRequestCount > 0,
|
|
186
|
+
maxBytes: Number(schemaBundle.registry && schemaBundle.registry.maxBytes || 65536),
|
|
187
|
+
...(metadataExtensions.json || {})
|
|
188
|
+
})
|
|
189
|
+
: undefined;
|
|
190
|
+
const userAuthoredAsync = Boolean(
|
|
191
|
+
(frontend.normalization && frontend.normalization.userAuthoredAsync)
|
|
192
|
+
|| metadataExtensions.userAuthoredAsync
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
const ir = Object.freeze({
|
|
196
|
+
version: CANONICAL_HANDLER_IR_VERSION,
|
|
197
|
+
contractId: CANONICAL_HANDLER_IR_CONTRACT_ID,
|
|
198
|
+
kind: operationIr.kind || 'plain-handler',
|
|
199
|
+
frontend: frontend.frontend,
|
|
200
|
+
compilerVersion,
|
|
201
|
+
programVersion,
|
|
202
|
+
runtimeProtocolVersion,
|
|
203
|
+
file: frontend.fileName,
|
|
204
|
+
sourceHash: stableHash(authoringSourceText),
|
|
205
|
+
loweredSourceHash: stableHash(loweredSourceText),
|
|
206
|
+
projectSourceHash: stableHash(`${authoringSourceText}\n${loweredSourceText}\n${schemaBundle.sourceHash}\n${JSON.stringify(packageEffectsInput)}\n${JSON.stringify(packageIntrinsicsInput)}`),
|
|
207
|
+
handler: Object.freeze({ ...(options.handlerMetadata || { id: 'default', ctxParameter: operationIr.ctxName }) }),
|
|
208
|
+
capabilities,
|
|
209
|
+
providerOperations,
|
|
210
|
+
effectSites: annotated.effectSites,
|
|
211
|
+
continuationSites: annotated.continuationSites,
|
|
212
|
+
schema: Object.freeze({
|
|
213
|
+
registry: schemaBundle.registry,
|
|
214
|
+
ids: schemaBundle.schemaIds,
|
|
215
|
+
declaredIds: schemaBundle.declaredSchemaIds || schemaBundle.schemaIds,
|
|
216
|
+
deferredIds: schemaBundle.deferredSchemaIds || Object.freeze([]),
|
|
217
|
+
registryIrVersion: schemaBundle.registryIrVersion,
|
|
218
|
+
registryHash: schemaBundle.registryHash,
|
|
219
|
+
codecTableHash: schemaBundle.codecTableHash,
|
|
220
|
+
responseCaseIds: schemaBundle.responseCaseIds || Object.freeze([]),
|
|
221
|
+
fullCodecRealization: schemaBundle.fullCodecRealization !== false,
|
|
222
|
+
sourceHash: schemaBundle.sourceHash
|
|
223
|
+
}),
|
|
224
|
+
schemaReferences: operationIr.analysis.schemaReferences,
|
|
225
|
+
...(jsonPolicy ? { json: jsonPolicy } : {}),
|
|
226
|
+
packageEffects,
|
|
227
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
228
|
+
authoring: metadataExtensions.authoring,
|
|
229
|
+
...(metadataExtensions.application ? { application: metadataExtensions.application } : {}),
|
|
230
|
+
...(applicationEntries ? { applicationEntries } : {}),
|
|
231
|
+
...(events ? { events } : {}),
|
|
232
|
+
router: routerMetadata,
|
|
233
|
+
compilerOwnedCalls,
|
|
234
|
+
compilerOwnedIntrinsics,
|
|
235
|
+
compilerPreludeHash: options.compilerPrelude ? stableHash(options.compilerPrelude) : undefined,
|
|
236
|
+
invariants: Object.freeze({
|
|
237
|
+
userAuthoredAsync,
|
|
238
|
+
promiseSemantics: false,
|
|
239
|
+
asyncify: false
|
|
240
|
+
}),
|
|
241
|
+
operationSummary: operationIr.summary,
|
|
242
|
+
surfaceSummary: Object.freeze({
|
|
243
|
+
recognition: input.surfaceFacts && input.surfaceFacts.recognition && input.surfaceFacts.recognition.summary,
|
|
244
|
+
classification: input.surfaceFacts && input.surfaceFacts.classification && input.surfaceFacts.classification.summary,
|
|
245
|
+
normalization: input.surfaceFacts && input.surfaceFacts.normalization,
|
|
246
|
+
validation: input.surfaceFacts && input.surfaceFacts.validation
|
|
247
|
+
})
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
payloads.set(ir, Object.freeze({
|
|
251
|
+
sourceFile: frontend.sourceFile,
|
|
252
|
+
sourceText,
|
|
253
|
+
loweredSourceText,
|
|
254
|
+
authoringSourceText,
|
|
255
|
+
schemaBundle,
|
|
256
|
+
compilerPrelude,
|
|
257
|
+
operationIr,
|
|
258
|
+
packageEffectsInput,
|
|
259
|
+
packageIntrinsicsInput,
|
|
260
|
+
surfaceFacts: input.surfaceFacts
|
|
261
|
+
}));
|
|
262
|
+
return ir;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function assertCanonicalHandlerIr(value) {
|
|
266
|
+
if (!value || value.version !== CANONICAL_HANDLER_IR_VERSION || value.contractId !== CANONICAL_HANDLER_IR_CONTRACT_ID || !payloads.has(value)) {
|
|
267
|
+
throw new CanonicalHandlerIrError('PULSE_CANONICAL_HANDLER_IR_INVALID', 'Expected an internally created canonical Handler IR value.', {
|
|
268
|
+
version: value && value.version,
|
|
269
|
+
contractId: value && value.contractId
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
return value;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function payloadForCanonicalHandlerIr(value) {
|
|
276
|
+
const ir = assertCanonicalHandlerIr(value);
|
|
277
|
+
return payloads.get(ir);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
function definedSnapshot(value) {
|
|
282
|
+
if (Array.isArray(value)) return Object.freeze(value.map(definedSnapshot));
|
|
283
|
+
if (!value || typeof value !== 'object') return value;
|
|
284
|
+
const out = {};
|
|
285
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
286
|
+
if (entry !== undefined) out[key] = definedSnapshot(entry);
|
|
287
|
+
}
|
|
288
|
+
return Object.freeze(out);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function canonicalHandlerIrSnapshot(value) {
|
|
292
|
+
const ir = assertCanonicalHandlerIr(value);
|
|
293
|
+
return definedSnapshot({
|
|
294
|
+
version: ir.version,
|
|
295
|
+
contractId: ir.contractId,
|
|
296
|
+
kind: ir.kind,
|
|
297
|
+
frontend: ir.frontend,
|
|
298
|
+
compilerVersion: ir.compilerVersion,
|
|
299
|
+
programVersion: ir.programVersion,
|
|
300
|
+
runtimeProtocolVersion: ir.runtimeProtocolVersion,
|
|
301
|
+
file: ir.file,
|
|
302
|
+
sourceHash: ir.sourceHash,
|
|
303
|
+
loweredSourceHash: ir.loweredSourceHash,
|
|
304
|
+
projectSourceHash: ir.projectSourceHash,
|
|
305
|
+
handler: ir.handler,
|
|
306
|
+
capabilities: ir.capabilities,
|
|
307
|
+
providerOperations: ir.providerOperations,
|
|
308
|
+
effectSites: ir.effectSites,
|
|
309
|
+
continuationSites: ir.continuationSites,
|
|
310
|
+
schema: ir.schema,
|
|
311
|
+
schemaReferences: ir.schemaReferences,
|
|
312
|
+
json: ir.json,
|
|
313
|
+
packageEffects: ir.packageEffects,
|
|
314
|
+
warnings: ir.warnings,
|
|
315
|
+
authoring: ir.authoring,
|
|
316
|
+
application: ir.application,
|
|
317
|
+
router: ir.router,
|
|
318
|
+
compilerOwnedCalls: ir.compilerOwnedCalls,
|
|
319
|
+
compilerOwnedIntrinsics: ir.compilerOwnedIntrinsics,
|
|
320
|
+
compilerPreludeHash: ir.compilerPreludeHash,
|
|
321
|
+
invariants: ir.invariants,
|
|
322
|
+
operationSummary: ir.operationSummary,
|
|
323
|
+
surfaceSummary: ir.surfaceSummary
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
module.exports = Object.freeze({
|
|
328
|
+
CANONICAL_HANDLER_IR_VERSION,
|
|
329
|
+
CANONICAL_HANDLER_IR_CONTRACT_ID,
|
|
330
|
+
CanonicalHandlerIrError,
|
|
331
|
+
createCanonicalHandlerIr,
|
|
332
|
+
assertCanonicalHandlerIr,
|
|
333
|
+
payloadForCanonicalHandlerIr,
|
|
334
|
+
canonicalHandlerIrSnapshot
|
|
335
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { defineCompilerSpineSegment, definePhaseAdapter } = require('./pipeline.js');
|
|
4
|
+
|
|
5
|
+
const traces = new WeakMap();
|
|
6
|
+
const facts = new WeakMap();
|
|
7
|
+
|
|
8
|
+
const CANONICAL_NATIVE_MODULE_SPINE = defineCompilerSpineSegment({
|
|
9
|
+
id: 'pulse.compiler.canonical-native-module.v1',
|
|
10
|
+
phases: ['native-realization', 'guest-realization', 'artifact-verification'],
|
|
11
|
+
adapters: [
|
|
12
|
+
definePhaseAdapter({
|
|
13
|
+
id: 'pulse.canonical-native-module.native-realization',
|
|
14
|
+
phase: 'native-realization',
|
|
15
|
+
mode: 'provider-neutral-primary-assemblyscript-compilation',
|
|
16
|
+
inputKind: 'provider-neutral-native-plan',
|
|
17
|
+
outputKind: 'primary-native-realization-envelope',
|
|
18
|
+
run({ value, context }) {
|
|
19
|
+
const providerRequirements = context.resolveProviderRequirements(value.plan);
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
plan: value.plan,
|
|
22
|
+
options: value.options,
|
|
23
|
+
providerRequirements,
|
|
24
|
+
realization: context.realize(value.plan, value.options, providerRequirements)
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}),
|
|
28
|
+
definePhaseAdapter({
|
|
29
|
+
id: 'pulse.canonical-native-module.guest-realization',
|
|
30
|
+
phase: 'guest-realization',
|
|
31
|
+
mode: 'selected-first-party-core-wasm-composition',
|
|
32
|
+
inputKind: 'primary-native-realization-envelope',
|
|
33
|
+
outputKind: 'portable-native-realization-envelope',
|
|
34
|
+
run({ value, context }) {
|
|
35
|
+
return Object.freeze({
|
|
36
|
+
...value,
|
|
37
|
+
realization: context.realizeGuests(value.realization, value.plan, value.options)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
definePhaseAdapter({
|
|
42
|
+
id: 'pulse.canonical-native-module.artifact-verification',
|
|
43
|
+
phase: 'artifact-verification',
|
|
44
|
+
mode: 'canonical-native-wasm-verification',
|
|
45
|
+
inputKind: 'portable-native-realization-envelope',
|
|
46
|
+
outputKind: 'verified-portable-native-wasm-artifact',
|
|
47
|
+
run({ value, context }) {
|
|
48
|
+
const compiled = context.verify(value.realization, value.plan, value.options, value.providerRequirements);
|
|
49
|
+
return Object.freeze({ ...value, compiled });
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function executeCanonicalNativeModuleSpine(plan, options, realization) {
|
|
56
|
+
if (!realization || typeof realization !== 'object') {
|
|
57
|
+
throw new TypeError('executeCanonicalNativeModuleSpine requires realization functions.');
|
|
58
|
+
}
|
|
59
|
+
for (const key of ['resolveProviderRequirements', 'realize', 'realizeGuests', 'verify']) {
|
|
60
|
+
if (typeof realization[key] !== 'function') throw new TypeError(`executeCanonicalNativeModuleSpine requires ${key}.`);
|
|
61
|
+
}
|
|
62
|
+
const result = CANONICAL_NATIVE_MODULE_SPINE.run(Object.freeze({ plan, options }), realization);
|
|
63
|
+
const envelope = result.output;
|
|
64
|
+
if (envelope && envelope.compiled && typeof envelope.compiled === 'object') {
|
|
65
|
+
traces.set(envelope.compiled, result.trace);
|
|
66
|
+
facts.set(envelope.compiled, Object.freeze({
|
|
67
|
+
providerRequirements: envelope.providerRequirements,
|
|
68
|
+
realization: envelope.realization
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
return envelope.compiled;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function traceForCanonicalNativeModule(compiled) {
|
|
75
|
+
return compiled && typeof compiled === 'object' ? traces.get(compiled) : undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function realizationFactsForCanonicalNativeModule(compiled) {
|
|
79
|
+
return compiled && typeof compiled === 'object' ? facts.get(compiled) : undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = Object.freeze({
|
|
83
|
+
CANONICAL_NATIVE_MODULE_SPINE,
|
|
84
|
+
executeCanonicalNativeModuleSpine,
|
|
85
|
+
traceForCanonicalNativeModule,
|
|
86
|
+
realizationFactsForCanonicalNativeModule
|
|
87
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { defineCompilerSpineSegment, definePhaseAdapter } = require('./pipeline.js');
|
|
4
|
+
const {
|
|
5
|
+
packageOperationRecognitionForCompiled,
|
|
6
|
+
packageOperationRecognitionFromEffects,
|
|
7
|
+
lowerCanonicalPackageOperations
|
|
8
|
+
} = require('./package-operation-seam.js');
|
|
9
|
+
const { collectProviderRequirements } = require('./provider-requirement-authority.js');
|
|
10
|
+
|
|
11
|
+
const traces = new WeakMap();
|
|
12
|
+
const facts = new WeakMap();
|
|
13
|
+
|
|
14
|
+
const CANONICAL_NATIVE_PLAN_SPINE = defineCompilerSpineSegment({
|
|
15
|
+
id: 'pulse.compiler.canonical-native-plan.v1',
|
|
16
|
+
phases: ['native-lowering', 'package-lowering'],
|
|
17
|
+
adapters: [
|
|
18
|
+
definePhaseAdapter({
|
|
19
|
+
id: 'pulse.canonical-native-plan.native-lowering',
|
|
20
|
+
phase: 'native-lowering',
|
|
21
|
+
mode: 'canonical-native-plan-builder',
|
|
22
|
+
inputKind: 'canonical-program',
|
|
23
|
+
outputKind: 'canonical-native-plan-envelope',
|
|
24
|
+
run({ value, context }) {
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
compiled: value.compiled,
|
|
27
|
+
options: value.options,
|
|
28
|
+
plan: context.buildNativePlan(value.compiled, value.options)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
definePhaseAdapter({
|
|
33
|
+
id: 'pulse.canonical-native-plan.package-lowering',
|
|
34
|
+
phase: 'package-lowering',
|
|
35
|
+
mode: 'canonical-package-operations-only',
|
|
36
|
+
inputKind: 'canonical-native-plan-envelope',
|
|
37
|
+
outputKind: 'provider-neutral-native-plan-envelope',
|
|
38
|
+
run({ value }) {
|
|
39
|
+
const recognition = packageOperationRecognitionForCompiled(value.compiled)
|
|
40
|
+
|| packageOperationRecognitionFromEffects((value.compiled.metadata && value.compiled.metadata.packageEffects) || []);
|
|
41
|
+
const packageLowering = lowerCanonicalPackageOperations(recognition);
|
|
42
|
+
const providerRequirements = collectProviderRequirements(value.plan, packageLowering);
|
|
43
|
+
return Object.freeze({ ...value, recognition, packageLowering, providerRequirements });
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function executeCanonicalNativePlanSpine(compiled, options, buildNativePlan) {
|
|
50
|
+
if (typeof buildNativePlan !== 'function') throw new TypeError('executeCanonicalNativePlanSpine requires a native-plan builder.');
|
|
51
|
+
const result = CANONICAL_NATIVE_PLAN_SPINE.run(Object.freeze({ compiled, options }), { buildNativePlan });
|
|
52
|
+
const envelope = result.output;
|
|
53
|
+
if (envelope && envelope.plan && typeof envelope.plan === 'object') {
|
|
54
|
+
traces.set(envelope.plan, result.trace);
|
|
55
|
+
facts.set(envelope.plan, Object.freeze({
|
|
56
|
+
packageRecognition: envelope.recognition,
|
|
57
|
+
packageLowering: envelope.packageLowering,
|
|
58
|
+
providerRequirements: envelope.providerRequirements
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
return envelope.plan;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function traceForCanonicalNativePlan(plan) {
|
|
65
|
+
return plan && typeof plan === 'object' ? traces.get(plan) : undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function loweringFactsForCanonicalNativePlan(plan) {
|
|
69
|
+
return plan && typeof plan === 'object' ? facts.get(plan) : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function packageLoweringForCanonicalNativePlan(plan) {
|
|
73
|
+
const record = loweringFactsForCanonicalNativePlan(plan);
|
|
74
|
+
return record && record.packageLowering;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function providerRequirementsForCanonicalNativePlan(plan) {
|
|
78
|
+
const record = loweringFactsForCanonicalNativePlan(plan);
|
|
79
|
+
return record && record.providerRequirements;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = Object.freeze({
|
|
83
|
+
CANONICAL_NATIVE_PLAN_SPINE,
|
|
84
|
+
executeCanonicalNativePlanSpine,
|
|
85
|
+
traceForCanonicalNativePlan,
|
|
86
|
+
loweringFactsForCanonicalNativePlan,
|
|
87
|
+
packageLoweringForCanonicalNativePlan,
|
|
88
|
+
providerRequirementsForCanonicalNativePlan
|
|
89
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { defineCompilerSpineSegment, definePassThroughAdapter, definePhaseAdapter } = require('./pipeline.js');
|
|
4
|
+
|
|
5
|
+
const traces = new WeakMap();
|
|
6
|
+
|
|
7
|
+
const CANONICAL_PROJECT_SPINE = defineCompilerSpineSegment({
|
|
8
|
+
id: 'pulse.compiler.canonical-project.v1',
|
|
9
|
+
phases: [
|
|
10
|
+
'root-extraction',
|
|
11
|
+
'surface-recognition',
|
|
12
|
+
'surface-normalization',
|
|
13
|
+
'semantic-classification',
|
|
14
|
+
'contract-validation',
|
|
15
|
+
'canonical-ir'
|
|
16
|
+
],
|
|
17
|
+
adapters: [
|
|
18
|
+
definePassThroughAdapter({
|
|
19
|
+
id: 'pulse.legacy.canonical-project.root-extraction',
|
|
20
|
+
phase: 'root-extraction',
|
|
21
|
+
inputKind: 'canonical-project-request',
|
|
22
|
+
outputKind: 'legacy-project-request'
|
|
23
|
+
}),
|
|
24
|
+
definePassThroughAdapter({
|
|
25
|
+
id: 'pulse.legacy.canonical-project.surface-recognition',
|
|
26
|
+
phase: 'surface-recognition',
|
|
27
|
+
inputKind: 'legacy-project-request',
|
|
28
|
+
outputKind: 'legacy-project-request'
|
|
29
|
+
}),
|
|
30
|
+
definePassThroughAdapter({
|
|
31
|
+
id: 'pulse.legacy.canonical-project.surface-normalization',
|
|
32
|
+
phase: 'surface-normalization',
|
|
33
|
+
inputKind: 'legacy-project-request',
|
|
34
|
+
outputKind: 'legacy-project-request'
|
|
35
|
+
}),
|
|
36
|
+
definePassThroughAdapter({
|
|
37
|
+
id: 'pulse.legacy.canonical-project.semantic-classification',
|
|
38
|
+
phase: 'semantic-classification',
|
|
39
|
+
inputKind: 'legacy-project-request',
|
|
40
|
+
outputKind: 'legacy-project-request'
|
|
41
|
+
}),
|
|
42
|
+
definePassThroughAdapter({
|
|
43
|
+
id: 'pulse.legacy.canonical-project.contract-validation',
|
|
44
|
+
phase: 'contract-validation',
|
|
45
|
+
inputKind: 'legacy-project-request',
|
|
46
|
+
outputKind: 'legacy-project-request'
|
|
47
|
+
}),
|
|
48
|
+
definePhaseAdapter({
|
|
49
|
+
id: 'pulse.legacy.canonical-project.canonical-ir',
|
|
50
|
+
phase: 'canonical-ir',
|
|
51
|
+
mode: 'legacy-envelope',
|
|
52
|
+
inputKind: 'legacy-project-request',
|
|
53
|
+
outputKind: 'canonical-project-program',
|
|
54
|
+
run({ value, context }) {
|
|
55
|
+
return context.compileLegacy(value.entryFile, value.options);
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
function executeCanonicalProjectSpine(entryFile, options, compileLegacy) {
|
|
62
|
+
if (typeof compileLegacy !== 'function') throw new TypeError('executeCanonicalProjectSpine requires a legacy compiler function.');
|
|
63
|
+
const result = CANONICAL_PROJECT_SPINE.run(Object.freeze({ entryFile, options }), { compileLegacy });
|
|
64
|
+
if (result.output && typeof result.output === 'object') traces.set(result.output, result.trace);
|
|
65
|
+
return result.output;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function traceForCanonicalProjectOutput(output) {
|
|
69
|
+
return output && typeof output === 'object' ? traces.get(output) : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = Object.freeze({
|
|
73
|
+
CANONICAL_PROJECT_SPINE,
|
|
74
|
+
executeCanonicalProjectSpine,
|
|
75
|
+
traceForCanonicalProjectOutput
|
|
76
|
+
});
|