@shapeshift-labs/frontier-lang-compiler 0.2.19 → 0.2.20
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 +37 -1
- package/bench/smoke.mjs +25 -1
- package/dist/index.d.ts +105 -1
- package/dist/index.js +373 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,11 +93,12 @@ console.log(pythonProjection.sourceProjection.stubs.lossClass); // "nativeSource
|
|
|
93
93
|
console.log(pythonProjection.targets.find((entry) => entry.target === 'rust').lossClass); // "missingAdapter"
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
The projection target matrix separates
|
|
96
|
+
The projection target matrix separates five runtime/API classes:
|
|
97
97
|
|
|
98
98
|
- `exactSourceProjection`: exact source can be emitted when the import carries matching source text or source-preservation evidence.
|
|
99
99
|
- `nativeSourceStubs`: declaration stubs can be emitted, but bodies, resolved types, and executable semantics are review-required.
|
|
100
100
|
- `unsupportedTargetFeatures`: a target slot exists, but the source profile or import evidence declares features such as macros, preprocessors, dynamic runtime behavior, generated code, unsupported syntax, or unresolved inference that this facade cannot prove lossless.
|
|
101
|
+
- `targetAdapterProjection`: a host-owned native-to-target adapter is present and produced target output with its own evidence/readiness.
|
|
101
102
|
- `missingAdapter`: no native-to-target projection adapter is declared; preserve or stub the original source language instead, or inject host-owned parser/semantic adapter evidence.
|
|
102
103
|
|
|
103
104
|
Preserve exact native source text, token/trivia hashes, comments, whitespace, and source directives as evidence. This does not claim full semantic understanding; it keeps round-trip material available while exact parser adapters catch up:
|
|
@@ -192,6 +193,41 @@ console.log(rustCandidate.ok); // true only because emitOnBlocked requested code
|
|
|
192
193
|
|
|
193
194
|
`compileNativeSource` returns the import result, projection, target loss matrix cell, combined losses, readiness, evidence, and output hash. Admission queues should treat `ok` as "code was emitted", not as merge approval; `readiness` and `targetCoverage` carry the merge signal.
|
|
194
195
|
|
|
196
|
+
Provide a target projection adapter when the host owns real native-to-target translation semantics:
|
|
197
|
+
|
|
198
|
+
```js
|
|
199
|
+
const jsToRustAdapter = {
|
|
200
|
+
id: 'app-js-to-rust',
|
|
201
|
+
sourceLanguage: 'javascript',
|
|
202
|
+
target: 'rust',
|
|
203
|
+
coverage: {
|
|
204
|
+
readiness: 'needs-review',
|
|
205
|
+
handledLossKinds: ['dynamicRuntime']
|
|
206
|
+
},
|
|
207
|
+
project(input) {
|
|
208
|
+
return {
|
|
209
|
+
output: `// projected from ${input.sourceLanguage}\npub fn add_todo() {}\n`,
|
|
210
|
+
readiness: 'needs-review',
|
|
211
|
+
evidence: [{
|
|
212
|
+
id: 'evidence_app_js_to_rust',
|
|
213
|
+
kind: 'projection',
|
|
214
|
+
status: 'passed',
|
|
215
|
+
summary: 'Host JS-to-Rust adapter emitted declaration-compatible Rust.'
|
|
216
|
+
}]
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const rustWithAdapter = compileNativeSource(compiledJs.importResult, {
|
|
222
|
+
target: 'rust',
|
|
223
|
+
targetAdapters: [jsToRustAdapter]
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
console.log(rustWithAdapter.outputMode); // "target-adapter"
|
|
227
|
+
console.log(rustWithAdapter.targetCoverage.lossClass); // "targetAdapterProjection"
|
|
228
|
+
console.log(rustWithAdapter.targetProjection.adapter.id); // "app-js-to-rust"
|
|
229
|
+
```
|
|
230
|
+
|
|
195
231
|
Project a native import back to source. Exact source is preserved when the import carries matching source-preservation evidence or when supplied text matches the import hash; otherwise the compiler emits declaration stubs with review-required loss evidence:
|
|
196
232
|
|
|
197
233
|
```js
|
package/bench/smoke.mjs
CHANGED
|
@@ -101,6 +101,27 @@ const nativeCompiles = nativeImportResults.map((imported, index) => compileNativ
|
|
|
101
101
|
const nativeCompileDurationMs = performance.now() - nativeCompileStart;
|
|
102
102
|
const nativeCompileBytes = nativeCompiles.reduce((sum, result) => sum + result.output.length, 0);
|
|
103
103
|
const nativeCompileBlocked = nativeCompiles.filter((result) => result.readiness.readiness === 'blocked').length;
|
|
104
|
+
const nativeTargetAdapterStart = performance.now();
|
|
105
|
+
const nativeTargetAdapterCompiles = nativeImportResults.slice(0, 25).map((imported, index) => {
|
|
106
|
+
const target = index % 2 === 0 ? 'rust' : 'python';
|
|
107
|
+
return compileNativeSource(imported, {
|
|
108
|
+
target,
|
|
109
|
+
targetAdapters: [{
|
|
110
|
+
id: `bench-target-adapter-${index}`,
|
|
111
|
+
sourceLanguage: imported.language,
|
|
112
|
+
target,
|
|
113
|
+
coverage: {
|
|
114
|
+
readiness: 'needs-review',
|
|
115
|
+
handledLossKinds: ['dynamicRuntime', 'dynamicDispatch', 'typeInference', 'overloadResolution']
|
|
116
|
+
},
|
|
117
|
+
project() {
|
|
118
|
+
return { output: `// bench target adapter ${index}\n`, readiness: 'needs-review' };
|
|
119
|
+
}
|
|
120
|
+
}]
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
const nativeTargetAdapterDurationMs = performance.now() - nativeTargetAdapterStart;
|
|
124
|
+
const nativeTargetAdapterBytes = nativeTargetAdapterCompiles.reduce((sum, result) => sum + result.output.length, 0);
|
|
104
125
|
|
|
105
126
|
console.log(JSON.stringify({
|
|
106
127
|
compiles: 250,
|
|
@@ -132,5 +153,8 @@ console.log(JSON.stringify({
|
|
|
132
153
|
nativeCompiles: nativeCompiles.length,
|
|
133
154
|
nativeCompileBytes,
|
|
134
155
|
nativeCompileBlocked,
|
|
135
|
-
nativeCompileDurationMs: Number(nativeCompileDurationMs.toFixed(2))
|
|
156
|
+
nativeCompileDurationMs: Number(nativeCompileDurationMs.toFixed(2)),
|
|
157
|
+
nativeTargetAdapterCompiles: nativeTargetAdapterCompiles.length,
|
|
158
|
+
nativeTargetAdapterBytes,
|
|
159
|
+
nativeTargetAdapterDurationMs: Number(nativeTargetAdapterDurationMs.toFixed(2))
|
|
136
160
|
}));
|
package/dist/index.d.ts
CHANGED
|
@@ -271,6 +271,7 @@ export type ProjectionTargetLossClass =
|
|
|
271
271
|
| 'exactSourceProjection'
|
|
272
272
|
| 'nativeSourceStubs'
|
|
273
273
|
| 'unsupportedTargetFeatures'
|
|
274
|
+
| 'targetAdapterProjection'
|
|
274
275
|
| 'missingAdapter'
|
|
275
276
|
| string;
|
|
276
277
|
|
|
@@ -299,6 +300,9 @@ export interface ProjectionTargetCoverageEntry {
|
|
|
299
300
|
readonly categories: readonly NativeImportTaxonomyKind[];
|
|
300
301
|
readonly reason: string;
|
|
301
302
|
readonly adapter?: string;
|
|
303
|
+
readonly adapterKind?: 'importer' | 'targetProjection' | string;
|
|
304
|
+
readonly adapterVersion?: string;
|
|
305
|
+
readonly adapterCoverage?: NativeTargetProjectionAdapterCoverageInput;
|
|
302
306
|
readonly notes: readonly string[];
|
|
303
307
|
}
|
|
304
308
|
|
|
@@ -339,6 +343,7 @@ export interface ProjectionTargetLossMatrix {
|
|
|
339
343
|
readonly sourceProjectionByLossClass: Readonly<Record<ProjectionTargetLossClass, number>>;
|
|
340
344
|
readonly exactSourceProjection: number;
|
|
341
345
|
readonly nativeSourceStubs: number;
|
|
346
|
+
readonly targetAdapterProjection: number;
|
|
342
347
|
readonly unsupportedTargetFeatures: number;
|
|
343
348
|
readonly missingAdapters: number;
|
|
344
349
|
};
|
|
@@ -353,6 +358,7 @@ export interface ProjectionTargetLossMatrixOptions {
|
|
|
353
358
|
readonly languages?: readonly NativeImportLanguageProfile[];
|
|
354
359
|
readonly imports?: readonly NativeSourceImportResult[];
|
|
355
360
|
readonly adapters?: readonly NativeImporterAdapter[];
|
|
361
|
+
readonly targetAdapters?: readonly NativeTargetProjectionAdapter[];
|
|
356
362
|
readonly targets?: readonly (FrontierCompileTarget | string)[];
|
|
357
363
|
readonly generatedAt?: number;
|
|
358
364
|
}
|
|
@@ -1124,6 +1130,94 @@ export type NativeImporterAdapterImportResult = NativeSourceImportResult & {
|
|
|
1124
1130
|
readonly diagnostics: readonly NativeImporterAdapterDiagnostic[];
|
|
1125
1131
|
};
|
|
1126
1132
|
|
|
1133
|
+
export interface NativeTargetProjectionAdapterCoverageInput {
|
|
1134
|
+
readonly readiness?: SemanticMergeReadiness;
|
|
1135
|
+
readonly lossKinds?: readonly NativeImportKnownLossKind[];
|
|
1136
|
+
readonly handledLossKinds?: readonly NativeImportKnownLossKind[];
|
|
1137
|
+
readonly sourceMapPrecision?: SourceMapMappingRecord['precision'] | 'none' | string;
|
|
1138
|
+
readonly semanticCoverage?: Partial<NativeImporterAdapterSemanticCoverage>;
|
|
1139
|
+
readonly notes?: readonly string[];
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
export interface NativeTargetProjectionAdapterSummary {
|
|
1143
|
+
readonly id: string;
|
|
1144
|
+
readonly sourceLanguage: FrontierSourceLanguage | string;
|
|
1145
|
+
readonly target: FrontierCompileTarget | string;
|
|
1146
|
+
readonly version?: string;
|
|
1147
|
+
readonly capabilities: readonly string[];
|
|
1148
|
+
readonly supportedParsers: readonly string[];
|
|
1149
|
+
readonly supportedExtensions: readonly string[];
|
|
1150
|
+
readonly coverage: Required<Pick<NativeTargetProjectionAdapterCoverageInput, 'readiness' | 'lossKinds' | 'handledLossKinds' | 'notes'>> & NativeTargetProjectionAdapterCoverageInput;
|
|
1151
|
+
readonly diagnostics: readonly NativeImporterAdapterDiagnostic[];
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
export interface NativeTargetProjectionAdapterInput {
|
|
1155
|
+
readonly importResult: NativeSourceImportResult;
|
|
1156
|
+
readonly sourceProjection: NativeSourceProjectionResult;
|
|
1157
|
+
readonly sourceLanguage: FrontierSourceLanguage | string;
|
|
1158
|
+
readonly target: FrontierCompileTarget | string;
|
|
1159
|
+
readonly targetPath?: string;
|
|
1160
|
+
readonly targetCoverage?: ProjectionTargetCoverageEntry;
|
|
1161
|
+
readonly options: Record<string, unknown>;
|
|
1162
|
+
readonly metadata: Record<string, unknown>;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
export interface NativeTargetProjectionAdapterResult {
|
|
1166
|
+
readonly id?: string;
|
|
1167
|
+
readonly output?: string;
|
|
1168
|
+
readonly outputHash?: string;
|
|
1169
|
+
readonly sourceMaps?: readonly SourceMapRecord[];
|
|
1170
|
+
readonly losses?: readonly NativeAstLossRecord[];
|
|
1171
|
+
readonly evidence?: readonly EvidenceRecord[];
|
|
1172
|
+
readonly diagnostics?: readonly NativeImporterAdapterDiagnostic[];
|
|
1173
|
+
readonly readiness?: SemanticMergeReadiness;
|
|
1174
|
+
readonly metadata?: Record<string, unknown>;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
export interface NativeTargetProjectionAdapter {
|
|
1178
|
+
readonly id: string;
|
|
1179
|
+
readonly sourceLanguage?: FrontierSourceLanguage | string;
|
|
1180
|
+
readonly language?: FrontierSourceLanguage | string;
|
|
1181
|
+
readonly target: FrontierCompileTarget | string;
|
|
1182
|
+
readonly targetLanguage?: FrontierCompileTarget | string;
|
|
1183
|
+
readonly version?: string;
|
|
1184
|
+
readonly capabilities?: readonly string[];
|
|
1185
|
+
readonly supportedParsers?: readonly string[];
|
|
1186
|
+
readonly supportedExtensions?: readonly string[];
|
|
1187
|
+
readonly coverage?: NativeTargetProjectionAdapterCoverageInput;
|
|
1188
|
+
readonly diagnostics?: readonly NativeImporterAdapterDiagnostic[];
|
|
1189
|
+
readonly project: (input: NativeTargetProjectionAdapterInput) => NativeTargetProjectionAdapterResult;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
export interface NativeTargetProjectionAdapterResolverInput {
|
|
1193
|
+
readonly importResult: NativeSourceImportResult;
|
|
1194
|
+
readonly sourceProjection: NativeSourceProjectionResult;
|
|
1195
|
+
readonly sourceLanguage: FrontierSourceLanguage | string;
|
|
1196
|
+
readonly target: FrontierCompileTarget | string;
|
|
1197
|
+
readonly sourcePath?: string;
|
|
1198
|
+
readonly parser?: string;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
export interface NativeTargetProjectionResult {
|
|
1202
|
+
readonly kind: 'frontier.lang.nativeTargetProjection';
|
|
1203
|
+
readonly version: 1;
|
|
1204
|
+
readonly id: string;
|
|
1205
|
+
readonly sourceLanguage: FrontierSourceLanguage | string;
|
|
1206
|
+
readonly target: FrontierCompileTarget | string;
|
|
1207
|
+
readonly targetPath?: string;
|
|
1208
|
+
readonly adapter: NativeTargetProjectionAdapterSummary;
|
|
1209
|
+
readonly output: string;
|
|
1210
|
+
readonly outputHash: string;
|
|
1211
|
+
readonly outputMode: 'target-adapter';
|
|
1212
|
+
readonly sourceMaps: readonly SourceMapRecord[];
|
|
1213
|
+
readonly losses: readonly NativeAstLossRecord[];
|
|
1214
|
+
readonly lossSummary: NativeImportLossSummary;
|
|
1215
|
+
readonly readiness: NativeImportReadinessClassification;
|
|
1216
|
+
readonly evidence: readonly EvidenceRecord[];
|
|
1217
|
+
readonly diagnostics: readonly NativeImporterAdapterDiagnostic[];
|
|
1218
|
+
readonly metadata: Record<string, unknown>;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1127
1221
|
export interface NativeProjectSourceInput extends ImportNativeSourceOptions {
|
|
1128
1222
|
readonly adapter?: NativeImporterAdapter | string;
|
|
1129
1223
|
readonly adapterOptions?: Record<string, unknown>;
|
|
@@ -1221,11 +1315,19 @@ export interface NativeSourceProjectionResult {
|
|
|
1221
1315
|
readonly metadata: Record<string, unknown>;
|
|
1222
1316
|
}
|
|
1223
1317
|
|
|
1224
|
-
export type NativeSourceCompileOutputMode = NativeSourceProjectionMode | 'target-stubs';
|
|
1318
|
+
export type NativeSourceCompileOutputMode = NativeSourceProjectionMode | 'target-stubs' | 'target-adapter';
|
|
1225
1319
|
|
|
1226
1320
|
export interface CompileNativeSourceOptions extends ProjectNativeImportToSourceOptions {
|
|
1227
1321
|
readonly target?: FrontierCompileTarget | string;
|
|
1228
1322
|
readonly adapters?: readonly NativeImporterAdapter[];
|
|
1323
|
+
readonly targetAdapters?: readonly NativeTargetProjectionAdapter[];
|
|
1324
|
+
readonly targetAdapter?: NativeTargetProjectionAdapter | string;
|
|
1325
|
+
readonly targetAdapterResolver?: (
|
|
1326
|
+
input: NativeTargetProjectionAdapterResolverInput,
|
|
1327
|
+
adapters: readonly NativeTargetProjectionAdapter[]
|
|
1328
|
+
) => NativeTargetProjectionAdapter | undefined;
|
|
1329
|
+
readonly targetAdapterOptions?: Record<string, unknown>;
|
|
1330
|
+
readonly targetAdapterMetadata?: Record<string, unknown>;
|
|
1229
1331
|
readonly languages?: readonly NativeImportLanguageProfile[];
|
|
1230
1332
|
readonly generatedAt?: number;
|
|
1231
1333
|
readonly emitOnBlocked?: boolean;
|
|
@@ -1249,6 +1351,7 @@ export interface NativeSourceCompileResult {
|
|
|
1249
1351
|
readonly outputMode: NativeSourceCompileOutputMode;
|
|
1250
1352
|
readonly importResult: NativeSourceImportResult;
|
|
1251
1353
|
readonly projection: NativeSourceProjectionResult;
|
|
1354
|
+
readonly targetProjection?: NativeTargetProjectionResult;
|
|
1252
1355
|
readonly targetCoverage: ProjectionTargetCoverageEntry;
|
|
1253
1356
|
readonly projectionMatrix: ProjectionTargetLossMatrix;
|
|
1254
1357
|
readonly losses: readonly NativeAstLossRecord[];
|
|
@@ -1342,6 +1445,7 @@ export declare function createBabelNativeImporterAdapter(options?: JavaScriptNat
|
|
|
1342
1445
|
export declare function createTypeScriptCompilerNativeImporterAdapter(options?: TypeScriptCompilerNativeImporterAdapterOptions): NativeImporterAdapter;
|
|
1343
1446
|
export declare function createTreeSitterNativeImporterAdapter(options?: TreeSitterNativeImporterAdapterOptions): NativeImporterAdapter;
|
|
1344
1447
|
export declare function runNativeImporterAdapter(adapter: NativeImporterAdapter, input: RunNativeImporterAdapterOptions): Promise<NativeImporterAdapterImportResult>;
|
|
1448
|
+
export declare function runNativeTargetProjectionAdapter(adapter: NativeTargetProjectionAdapter, input: NativeTargetProjectionAdapterInput): NativeTargetProjectionResult;
|
|
1345
1449
|
export declare function projectNativeImportToSource(importResult: NativeSourceImportResult | NativeProjectImportResult, options?: ProjectNativeImportToSourceOptions): NativeSourceProjectionResult;
|
|
1346
1450
|
export declare function importNativeSource(input: ImportNativeSourceOptions): NativeSourceImportResult;
|
|
1347
1451
|
export declare function diffNativeSources(input: DiffNativeSourcesOptions): NativeSourceChangeSet;
|
package/dist/index.js
CHANGED
|
@@ -151,6 +151,7 @@ export const ProjectionTargetLossClasses = Object.freeze([
|
|
|
151
151
|
'exactSourceProjection',
|
|
152
152
|
'nativeSourceStubs',
|
|
153
153
|
'unsupportedTargetFeatures',
|
|
154
|
+
'targetAdapterProjection',
|
|
154
155
|
'missingAdapter'
|
|
155
156
|
]);
|
|
156
157
|
|
|
@@ -277,11 +278,38 @@ export function compileNativeSource(input, options = {}) {
|
|
|
277
278
|
const projectionMatrix = createProjectionTargetLossMatrix({
|
|
278
279
|
imports: [importResult],
|
|
279
280
|
adapters: options.adapters,
|
|
281
|
+
targetAdapters: options.targetAdapters,
|
|
280
282
|
languages: options.languages,
|
|
281
283
|
targets: [target],
|
|
282
284
|
generatedAt: options.generatedAt
|
|
283
285
|
});
|
|
284
286
|
const targetCoverage = nativeSourceCompileTargetCoverage(projectionMatrix, sourceLanguage, target);
|
|
287
|
+
const targetAdapter = resolveNativeTargetProjectionAdapter({
|
|
288
|
+
importResult,
|
|
289
|
+
sourceProjection: projection,
|
|
290
|
+
sourceLanguage,
|
|
291
|
+
target,
|
|
292
|
+
sourcePath: importResult.sourcePath ?? importResult.nativeSource?.sourcePath,
|
|
293
|
+
parser: importResult.nativeAst?.parser ?? importResult.nativeSource?.parser ?? options.parser
|
|
294
|
+
}, options);
|
|
295
|
+
const targetProjection = targetAdapter
|
|
296
|
+
? runNativeTargetProjectionAdapter(targetAdapter, {
|
|
297
|
+
importResult,
|
|
298
|
+
sourceProjection: projection,
|
|
299
|
+
sourceLanguage,
|
|
300
|
+
target,
|
|
301
|
+
targetPath: options.targetPath,
|
|
302
|
+
targetCoverage,
|
|
303
|
+
options: options.targetAdapterOptions ?? {},
|
|
304
|
+
metadata: {
|
|
305
|
+
nativeCompileResultId: id,
|
|
306
|
+
sourceLanguage,
|
|
307
|
+
target,
|
|
308
|
+
projectionId: projection.id,
|
|
309
|
+
...options.targetAdapterMetadata
|
|
310
|
+
}
|
|
311
|
+
})
|
|
312
|
+
: undefined;
|
|
285
313
|
const targetLosses = nativeSourceCompileTargetLosses({
|
|
286
314
|
importResult,
|
|
287
315
|
projection,
|
|
@@ -290,26 +318,32 @@ export function compileNativeSource(input, options = {}) {
|
|
|
290
318
|
target,
|
|
291
319
|
idPart
|
|
292
320
|
});
|
|
293
|
-
const
|
|
321
|
+
const output = targetProjection?.output ?? projection.sourceText;
|
|
322
|
+
const outputHash = targetProjection?.outputHash ?? projection.outputHash;
|
|
323
|
+
const outputMode = targetProjection ? targetProjection.outputMode : sameSourceTarget ? projection.mode : 'target-stubs';
|
|
294
324
|
const compileEvidence = nativeSourceCompileEvidence({
|
|
295
325
|
id: options.compileEvidenceId ?? `evidence_${idPart}_${idFragment(target)}_native_source_compile`,
|
|
296
326
|
importResult,
|
|
297
327
|
projection,
|
|
328
|
+
targetProjection,
|
|
298
329
|
targetCoverage,
|
|
299
330
|
targetLosses,
|
|
300
331
|
sourceLanguage,
|
|
301
332
|
target,
|
|
333
|
+
outputHash,
|
|
302
334
|
outputMode
|
|
303
335
|
});
|
|
304
336
|
const evidence = uniqueByEvidenceId([
|
|
305
337
|
...(importResult.evidence ?? []),
|
|
306
338
|
...(projection.evidence ?? []),
|
|
339
|
+
...(targetProjection?.evidence ?? []),
|
|
307
340
|
compileEvidence,
|
|
308
341
|
...(options.evidence ?? [])
|
|
309
342
|
]);
|
|
310
343
|
const losses = uniqueByLossId([
|
|
311
344
|
...(importResult.losses ?? []),
|
|
312
345
|
...(projection.losses ?? []),
|
|
346
|
+
...(targetProjection?.losses ?? []),
|
|
313
347
|
...targetLosses,
|
|
314
348
|
...(options.losses ?? [])
|
|
315
349
|
]);
|
|
@@ -333,11 +367,12 @@ export function compileNativeSource(input, options = {}) {
|
|
|
333
367
|
target,
|
|
334
368
|
language: sourceLanguage,
|
|
335
369
|
sourcePath: importResult.sourcePath ?? importResult.nativeSource?.sourcePath,
|
|
336
|
-
output
|
|
337
|
-
outputHash
|
|
370
|
+
output,
|
|
371
|
+
outputHash,
|
|
338
372
|
outputMode,
|
|
339
373
|
importResult,
|
|
340
374
|
projection,
|
|
375
|
+
targetProjection,
|
|
341
376
|
targetCoverage,
|
|
342
377
|
projectionMatrix,
|
|
343
378
|
losses,
|
|
@@ -351,6 +386,8 @@ export function compileNativeSource(input, options = {}) {
|
|
|
351
386
|
semanticIndexId: importResult.semanticIndex?.id ?? importResult.universalAst?.semanticIndex?.id,
|
|
352
387
|
universalAstId: importResult.universalAst?.id,
|
|
353
388
|
projectionId: projection.id,
|
|
389
|
+
targetProjectionId: targetProjection?.id,
|
|
390
|
+
targetProjectionAdapterId: targetProjection?.adapter?.id,
|
|
354
391
|
projectionMode: projection.mode,
|
|
355
392
|
outputMode,
|
|
356
393
|
sourceTarget,
|
|
@@ -657,11 +694,13 @@ export function createNativeImportCoverageMatrix(input = {}) {
|
|
|
657
694
|
export function createProjectionTargetLossMatrix(input = {}) {
|
|
658
695
|
const imports = input.imports ?? [];
|
|
659
696
|
const adapters = input.adapters ?? [];
|
|
660
|
-
const
|
|
697
|
+
const targetAdapters = input.targetAdapters ?? [];
|
|
698
|
+
const profiles = mergeNativeImportProfiles(input.languages ?? NativeImportLanguageProfiles, imports, adapters, targetAdapters);
|
|
661
699
|
const targets = normalizeProjectionMatrixTargets(input.targets ?? FrontierCompileTargets);
|
|
662
700
|
const languages = profiles.map((profile) => projectionTargetCoverageForProfile(profile, {
|
|
663
701
|
imports,
|
|
664
702
|
adapters,
|
|
703
|
+
targetAdapters,
|
|
665
704
|
targets
|
|
666
705
|
}));
|
|
667
706
|
const summary = projectionTargetLossMatrixSummary(languages);
|
|
@@ -674,7 +713,7 @@ export function createProjectionTargetLossMatrix(input = {}) {
|
|
|
674
713
|
metadata: {
|
|
675
714
|
compileTargets: targets,
|
|
676
715
|
lossClasses: [...ProjectionTargetLossClasses],
|
|
677
|
-
note: 'Projection target coverage separates exact source preservation, declaration stubs, known unsupported target features, and missing native-to-target adapters.'
|
|
716
|
+
note: 'Projection target coverage separates exact source preservation, declaration stubs, host-owned target adapters, known unsupported target features, and missing native-to-target adapters.'
|
|
678
717
|
}
|
|
679
718
|
};
|
|
680
719
|
}
|
|
@@ -1159,6 +1198,120 @@ export async function runNativeImporterAdapter(adapter, input = {}) {
|
|
|
1159
1198
|
};
|
|
1160
1199
|
}
|
|
1161
1200
|
|
|
1201
|
+
export function runNativeTargetProjectionAdapter(adapter, input = {}) {
|
|
1202
|
+
const summary = normalizeNativeTargetProjectionAdapter(adapter);
|
|
1203
|
+
const sourceLanguage = normalizeNativeLanguageId(input.sourceLanguage ?? summary.sourceLanguage);
|
|
1204
|
+
const target = normalizeProjectionMatrixTargets([input.target ?? summary.target])[0] ?? summary.target;
|
|
1205
|
+
const diagnosticContext = {
|
|
1206
|
+
sourcePath: input.importResult?.sourcePath ?? input.importResult?.nativeSource?.sourcePath,
|
|
1207
|
+
sourceHash: input.importResult?.sourceHash ?? input.importResult?.nativeSource?.sourceHash,
|
|
1208
|
+
language: sourceLanguage,
|
|
1209
|
+
parser: `target:${target}`,
|
|
1210
|
+
parserVersion: summary.version
|
|
1211
|
+
};
|
|
1212
|
+
const projectInput = {
|
|
1213
|
+
importResult: input.importResult,
|
|
1214
|
+
sourceProjection: input.sourceProjection,
|
|
1215
|
+
sourceLanguage,
|
|
1216
|
+
target,
|
|
1217
|
+
targetPath: input.targetPath,
|
|
1218
|
+
targetCoverage: input.targetCoverage,
|
|
1219
|
+
options: input.options ?? {},
|
|
1220
|
+
metadata: input.metadata ?? {}
|
|
1221
|
+
};
|
|
1222
|
+
let projected;
|
|
1223
|
+
let thrownDiagnostic;
|
|
1224
|
+
try {
|
|
1225
|
+
projected = adapter.project(projectInput) ?? {};
|
|
1226
|
+
} catch (error) {
|
|
1227
|
+
thrownDiagnostic = {
|
|
1228
|
+
severity: 'error',
|
|
1229
|
+
code: 'targetAdapter.project.threw',
|
|
1230
|
+
phase: 'emit',
|
|
1231
|
+
kind: 'targetProjectionLoss',
|
|
1232
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1233
|
+
metadata: {
|
|
1234
|
+
errorName: error instanceof Error ? error.name : undefined
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
projected = {};
|
|
1238
|
+
}
|
|
1239
|
+
const diagnostics = [
|
|
1240
|
+
...normalizeAdapterDiagnostics(summary.diagnostics, summary, diagnosticContext, 'target-adapter'),
|
|
1241
|
+
...(thrownDiagnostic ? normalizeAdapterDiagnostics([thrownDiagnostic], summary, diagnosticContext, 'throw') : []),
|
|
1242
|
+
...normalizeAdapterDiagnostics(projected.diagnostics, summary, diagnosticContext, 'project')
|
|
1243
|
+
];
|
|
1244
|
+
const output = typeof projected.output === 'string' ? projected.output : input.sourceProjection?.sourceText ?? '';
|
|
1245
|
+
const outputHash = projected.outputHash ?? hashSemanticValue(output);
|
|
1246
|
+
const adapterEvidence = nativeTargetProjectionAdapterEvidence(summary, diagnostics, {
|
|
1247
|
+
...diagnosticContext,
|
|
1248
|
+
sourceLanguage,
|
|
1249
|
+
target,
|
|
1250
|
+
outputHash,
|
|
1251
|
+
targetPath: input.targetPath
|
|
1252
|
+
});
|
|
1253
|
+
const evidence = uniqueByEvidenceId([
|
|
1254
|
+
...(projected.evidence ?? []),
|
|
1255
|
+
adapterEvidence
|
|
1256
|
+
]);
|
|
1257
|
+
const losses = uniqueByLossId([
|
|
1258
|
+
...(projected.losses ?? []),
|
|
1259
|
+
...diagnostics.map((diagnostic, index) => nativeTargetProjectionDiagnosticToLoss(diagnostic, index, summary, {
|
|
1260
|
+
...diagnosticContext,
|
|
1261
|
+
sourceLanguage,
|
|
1262
|
+
target
|
|
1263
|
+
}))
|
|
1264
|
+
]);
|
|
1265
|
+
const lossSummary = summarizeNativeImportLosses(losses, {
|
|
1266
|
+
evidence,
|
|
1267
|
+
parser: diagnosticContext.parser,
|
|
1268
|
+
scanKind: 'native-target-projection',
|
|
1269
|
+
semanticStatus: input.importResult?.metadata?.semanticStatus
|
|
1270
|
+
});
|
|
1271
|
+
const classifiedReadiness = classifyNativeImportReadiness(losses, {
|
|
1272
|
+
evidence,
|
|
1273
|
+
parser: diagnosticContext.parser,
|
|
1274
|
+
scanKind: 'native-target-projection',
|
|
1275
|
+
semanticStatus: input.importResult?.metadata?.semanticStatus
|
|
1276
|
+
});
|
|
1277
|
+
const declaredReadiness = normalizeSemanticMergeReadiness(projected.readiness ?? summary.coverage.readiness);
|
|
1278
|
+
const readiness = declaredReadiness
|
|
1279
|
+
? {
|
|
1280
|
+
...classifiedReadiness,
|
|
1281
|
+
readiness: maxSemanticMergeReadiness(classifiedReadiness.readiness, declaredReadiness),
|
|
1282
|
+
reasons: uniqueStrings([
|
|
1283
|
+
...classifiedReadiness.reasons,
|
|
1284
|
+
...(declaredReadiness === classifiedReadiness.readiness ? [] : [`Target adapter declared readiness ${declaredReadiness}.`])
|
|
1285
|
+
])
|
|
1286
|
+
}
|
|
1287
|
+
: classifiedReadiness;
|
|
1288
|
+
return {
|
|
1289
|
+
kind: 'frontier.lang.nativeTargetProjection',
|
|
1290
|
+
version: 1,
|
|
1291
|
+
id: projected.id ?? `native_target_projection_${idFragment(summary.id)}_${idFragment(sourceLanguage)}_${idFragment(target)}`,
|
|
1292
|
+
sourceLanguage,
|
|
1293
|
+
target,
|
|
1294
|
+
targetPath: input.targetPath,
|
|
1295
|
+
adapter: summary,
|
|
1296
|
+
output,
|
|
1297
|
+
outputHash,
|
|
1298
|
+
outputMode: 'target-adapter',
|
|
1299
|
+
sourceMaps: projected.sourceMaps ?? [],
|
|
1300
|
+
losses,
|
|
1301
|
+
lossSummary,
|
|
1302
|
+
readiness,
|
|
1303
|
+
evidence,
|
|
1304
|
+
diagnostics: diagnostics.map(serializableDiagnostic),
|
|
1305
|
+
metadata: {
|
|
1306
|
+
importId: input.importResult?.id,
|
|
1307
|
+
projectionId: input.sourceProjection?.id,
|
|
1308
|
+
targetCoverageLossClass: input.targetCoverage?.lossClass,
|
|
1309
|
+
targetCoverageReadiness: input.targetCoverage?.readiness,
|
|
1310
|
+
...projected.metadata
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1162
1315
|
export function projectNativeImportToSource(importResult, options = {}) {
|
|
1163
1316
|
if (!importResult || typeof importResult !== 'object') {
|
|
1164
1317
|
throw new Error('projectNativeImportToSource requires a native import result');
|
|
@@ -3950,6 +4103,7 @@ function projectionTargetCoverageForProfile(profile, context) {
|
|
|
3950
4103
|
const aliases = new Set([profile.language, ...(profile.aliases ?? [])].map(normalizeNativeLanguageId).filter(Boolean));
|
|
3951
4104
|
const matchingImports = (context.imports ?? []).filter((imported) => aliases.has(normalizeNativeLanguageId(imported?.language ?? imported?.nativeAst?.language)));
|
|
3952
4105
|
const matchingAdapters = (context.adapters ?? []).filter((adapter) => aliases.has(normalizeNativeLanguageId(adapter?.language)));
|
|
4106
|
+
const matchingTargetAdapters = (context.targetAdapters ?? []).filter((adapter) => aliases.has(normalizeNativeLanguageId(adapter?.sourceLanguage ?? adapter?.language)));
|
|
3953
4107
|
const importedLossKinds = uniqueStrings(matchingImports.flatMap((imported) => (imported?.losses ?? []).map((loss) => loss.kind).filter(Boolean)));
|
|
3954
4108
|
const knownLossKinds = uniqueStrings([...(profile.knownLossKinds ?? []), ...importedLossKinds]);
|
|
3955
4109
|
const parserAdapters = uniqueStrings([
|
|
@@ -3960,6 +4114,7 @@ function projectionTargetCoverageForProfile(profile, context) {
|
|
|
3960
4114
|
const targets = (context.targets ?? FrontierCompileTargets).map((target) => projectionTargetCoverageEntry(profile, target, {
|
|
3961
4115
|
matchingImports,
|
|
3962
4116
|
matchingAdapters,
|
|
4117
|
+
matchingTargetAdapters,
|
|
3963
4118
|
knownLossKinds
|
|
3964
4119
|
}));
|
|
3965
4120
|
return {
|
|
@@ -4037,8 +4192,14 @@ function projectionTargetCoverageEntry(profile, target, context) {
|
|
|
4037
4192
|
const normalizedTarget = normalizeProjectionMatrixTargets([target])[0] ?? String(target);
|
|
4038
4193
|
const declaredTargets = new Set(normalizeProjectionMatrixTargets(profile.projectionTargets ?? []));
|
|
4039
4194
|
const adapterTargets = new Set((context.matchingAdapters ?? []).flatMap(adapterProjectionTargets));
|
|
4195
|
+
const targetAdapter = matchingNativeTargetProjectionAdapter({
|
|
4196
|
+
sourceLanguage: profile.language,
|
|
4197
|
+
target: normalizedTarget,
|
|
4198
|
+
sourcePath: context.matchingImports?.[0]?.sourcePath ?? context.matchingImports?.[0]?.nativeSource?.sourcePath
|
|
4199
|
+
}, context.matchingTargetAdapters ?? []);
|
|
4200
|
+
const targetAdapterSummary = targetAdapter ? normalizeNativeTargetProjectionAdapter(targetAdapter) : undefined;
|
|
4040
4201
|
const sameSourceTarget = nativeLanguageCompileTarget(profile.language, profile.aliases) === normalizedTarget;
|
|
4041
|
-
const hasProjectionAdapter = declaredTargets.has(normalizedTarget) || adapterTargets.has(normalizedTarget);
|
|
4202
|
+
const hasProjectionAdapter = Boolean(targetAdapterSummary) || declaredTargets.has(normalizedTarget) || adapterTargets.has(normalizedTarget);
|
|
4042
4203
|
if (!hasProjectionAdapter) {
|
|
4043
4204
|
return {
|
|
4044
4205
|
target: normalizedTarget,
|
|
@@ -4054,6 +4215,48 @@ function projectionTargetCoverageEntry(profile, target, context) {
|
|
|
4054
4215
|
}
|
|
4055
4216
|
|
|
4056
4217
|
const featureLossKinds = projectionUnsupportedFeatureLossKinds(context.knownLossKinds);
|
|
4218
|
+
if (targetAdapterSummary) {
|
|
4219
|
+
const handledLossKinds = new Set(targetAdapterSummary.coverage.handledLossKinds ?? []);
|
|
4220
|
+
const unhandledFeatureLossKinds = featureLossKinds.filter((kind) => !handledLossKinds.has(kind));
|
|
4221
|
+
if (unhandledFeatureLossKinds.length) {
|
|
4222
|
+
return {
|
|
4223
|
+
target: normalizedTarget,
|
|
4224
|
+
lossClass: 'unsupportedTargetFeatures',
|
|
4225
|
+
supported: true,
|
|
4226
|
+
readiness: 'needs-review',
|
|
4227
|
+
lossKinds: unhandledFeatureLossKinds,
|
|
4228
|
+
categories: uniqueStrings(unhandledFeatureLossKinds.map(nativeImportCategoryForLossKind)),
|
|
4229
|
+
reason: `${profile.language} has target adapter ${targetAdapterSummary.id}, but source feature losses remain unhandled for ${normalizedTarget}: ${unhandledFeatureLossKinds.join(', ')}.`,
|
|
4230
|
+
adapter: targetAdapterSummary.id,
|
|
4231
|
+
adapterKind: 'targetProjection',
|
|
4232
|
+
adapterVersion: targetAdapterSummary.version,
|
|
4233
|
+
adapterCoverage: targetAdapterSummary.coverage,
|
|
4234
|
+
notes: uniqueStrings([
|
|
4235
|
+
...(targetAdapterSummary.coverage.notes ?? []),
|
|
4236
|
+
'Adapter output is available, but merge readiness still requires review for unhandled source-language feature losses.'
|
|
4237
|
+
])
|
|
4238
|
+
};
|
|
4239
|
+
}
|
|
4240
|
+
const adapterLossKinds = uniqueStrings(targetAdapterSummary.coverage.lossKinds ?? []);
|
|
4241
|
+
return {
|
|
4242
|
+
target: normalizedTarget,
|
|
4243
|
+
lossClass: 'targetAdapterProjection',
|
|
4244
|
+
supported: true,
|
|
4245
|
+
readiness: targetAdapterSummary.coverage.readiness ?? 'needs-review',
|
|
4246
|
+
lossKinds: adapterLossKinds,
|
|
4247
|
+
categories: uniqueStrings(adapterLossKinds.map(nativeImportCategoryForLossKind)),
|
|
4248
|
+
reason: `${profile.language} can project to ${normalizedTarget} through host target adapter ${targetAdapterSummary.id}.`,
|
|
4249
|
+
adapter: targetAdapterSummary.id,
|
|
4250
|
+
adapterKind: 'targetProjection',
|
|
4251
|
+
adapterVersion: targetAdapterSummary.version,
|
|
4252
|
+
adapterCoverage: targetAdapterSummary.coverage,
|
|
4253
|
+
notes: uniqueStrings([
|
|
4254
|
+
...(targetAdapterSummary.coverage.notes ?? []),
|
|
4255
|
+
'The host adapter owns native-to-target translation semantics and must provide evidence for merge admission.'
|
|
4256
|
+
])
|
|
4257
|
+
};
|
|
4258
|
+
}
|
|
4259
|
+
|
|
4057
4260
|
if (featureLossKinds.length) {
|
|
4058
4261
|
return {
|
|
4059
4262
|
target: normalizedTarget,
|
|
@@ -4115,6 +4318,7 @@ function projectionTargetLossMatrixSummary(languages) {
|
|
|
4115
4318
|
sourceProjectionByLossClass,
|
|
4116
4319
|
exactSourceProjection: (sourceProjectionByLossClass.exactSourceProjection ?? 0) + (byLossClass.exactSourceProjection ?? 0),
|
|
4117
4320
|
nativeSourceStubs: (sourceProjectionByLossClass.nativeSourceStubs ?? 0) + (byLossClass.nativeSourceStubs ?? 0),
|
|
4321
|
+
targetAdapterProjection: byLossClass.targetAdapterProjection ?? 0,
|
|
4118
4322
|
unsupportedTargetFeatures: byLossClass.unsupportedTargetFeatures ?? 0,
|
|
4119
4323
|
missingAdapters: byLossClass.missingAdapter ?? 0
|
|
4120
4324
|
};
|
|
@@ -4324,9 +4528,11 @@ function nativeSourceCompileEvidence(input) {
|
|
|
4324
4528
|
metadata: {
|
|
4325
4529
|
importId: input.importResult.id,
|
|
4326
4530
|
projectionId: input.projection.id,
|
|
4531
|
+
targetProjectionId: input.targetProjection?.id,
|
|
4532
|
+
targetProjectionAdapterId: input.targetProjection?.adapter?.id,
|
|
4327
4533
|
sourceLanguage: input.sourceLanguage,
|
|
4328
4534
|
target: input.target,
|
|
4329
|
-
outputHash: input.projection.outputHash,
|
|
4535
|
+
outputHash: input.outputHash ?? input.projection.outputHash,
|
|
4330
4536
|
outputMode: input.outputMode,
|
|
4331
4537
|
projectionMode: input.projection.mode,
|
|
4332
4538
|
targetLossClass: input.targetCoverage.lossClass,
|
|
@@ -4359,7 +4565,7 @@ function nativeImportLanguageProfile(language, input = {}) {
|
|
|
4359
4565
|
});
|
|
4360
4566
|
}
|
|
4361
4567
|
|
|
4362
|
-
function mergeNativeImportProfiles(languages, imports, adapters) {
|
|
4568
|
+
function mergeNativeImportProfiles(languages, imports, adapters, targetAdapters = []) {
|
|
4363
4569
|
const profilesByLanguage = new Map();
|
|
4364
4570
|
for (const profile of languages) {
|
|
4365
4571
|
const normalized = normalizeNativeLanguageId(profile.language ?? profile);
|
|
@@ -4385,6 +4591,16 @@ function mergeNativeImportProfiles(languages, imports, adapters) {
|
|
|
4385
4591
|
parserAdapters: uniqueStrings([...(existing.parserAdapters ?? []), adapter.parser ?? adapter.id].filter(Boolean))
|
|
4386
4592
|
});
|
|
4387
4593
|
}
|
|
4594
|
+
for (const adapter of targetAdapters) {
|
|
4595
|
+
const summary = safeNativeTargetProjectionAdapterSummary(adapter);
|
|
4596
|
+
const normalized = normalizeNativeLanguageId(summary?.sourceLanguage);
|
|
4597
|
+
if (!normalized) continue;
|
|
4598
|
+
const existing = profilesByLanguage.get(normalized) ?? nativeImportLanguageProfile(normalized, { supportsLightweightScan: false, parserAdapters: [] });
|
|
4599
|
+
profilesByLanguage.set(normalized, {
|
|
4600
|
+
...existing,
|
|
4601
|
+
projectionTargets: uniqueStrings([...(existing.projectionTargets ?? []), summary.target].filter(Boolean))
|
|
4602
|
+
});
|
|
4603
|
+
}
|
|
4388
4604
|
return [...profilesByLanguage.values()].sort((left, right) => left.language.localeCompare(right.language));
|
|
4389
4605
|
}
|
|
4390
4606
|
|
|
@@ -5217,6 +5433,11 @@ function maxSemanticMergeReadiness(left, right) {
|
|
|
5217
5433
|
return leftRank >= rightRank ? left : right;
|
|
5218
5434
|
}
|
|
5219
5435
|
|
|
5436
|
+
function normalizeSemanticMergeReadiness(value) {
|
|
5437
|
+
const readiness = String(value ?? '').toLowerCase();
|
|
5438
|
+
return Object.prototype.hasOwnProperty.call(semanticMergeReadinessRank, readiness) ? readiness : undefined;
|
|
5439
|
+
}
|
|
5440
|
+
|
|
5220
5441
|
export function createUniversalAstFromDocument(document, input = {}) {
|
|
5221
5442
|
return createUniversalAstEnvelope({
|
|
5222
5443
|
id: input.id ?? `universal_ast_${idFragment(document.id)}`,
|
|
@@ -5886,6 +6107,150 @@ function resolveNativeProjectAdapter(source, adapters, input) {
|
|
|
5886
6107
|
});
|
|
5887
6108
|
}
|
|
5888
6109
|
|
|
6110
|
+
function resolveNativeTargetProjectionAdapter(input, options = {}) {
|
|
6111
|
+
const adapters = options.targetAdapters ?? [];
|
|
6112
|
+
if (options.targetAdapter && typeof options.targetAdapter === 'object') return options.targetAdapter;
|
|
6113
|
+
if (typeof options.targetAdapter === 'string') {
|
|
6114
|
+
const explicit = adapters.find((adapter) => adapter?.id === options.targetAdapter);
|
|
6115
|
+
if (explicit) return explicit;
|
|
6116
|
+
}
|
|
6117
|
+
if (typeof options.targetAdapterResolver === 'function') {
|
|
6118
|
+
const resolved = options.targetAdapterResolver(input, adapters);
|
|
6119
|
+
if (resolved) return resolved;
|
|
6120
|
+
}
|
|
6121
|
+
return matchingNativeTargetProjectionAdapter(input, adapters);
|
|
6122
|
+
}
|
|
6123
|
+
|
|
6124
|
+
function matchingNativeTargetProjectionAdapter(input, adapters = []) {
|
|
6125
|
+
return adapters.find((adapter) => nativeTargetProjectionAdapterMatches(adapter, input));
|
|
6126
|
+
}
|
|
6127
|
+
|
|
6128
|
+
function nativeTargetProjectionAdapterMatches(adapter, input = {}) {
|
|
6129
|
+
const summary = safeNativeTargetProjectionAdapterSummary(adapter);
|
|
6130
|
+
if (!summary) return false;
|
|
6131
|
+
if (input.sourceLanguage && normalizeNativeLanguageId(input.sourceLanguage) !== summary.sourceLanguage) return false;
|
|
6132
|
+
const target = normalizeProjectionMatrixTargets([input.target])[0] ?? String(input.target ?? '').toLowerCase();
|
|
6133
|
+
if (target && target !== summary.target) return false;
|
|
6134
|
+
const parser = input.parser ? String(input.parser).toLowerCase() : undefined;
|
|
6135
|
+
if (parser && summary.supportedParsers.length && !summary.supportedParsers.map((item) => item.toLowerCase()).includes(parser)) return false;
|
|
6136
|
+
const sourcePath = String(input.sourcePath ?? '').toLowerCase();
|
|
6137
|
+
if (sourcePath && summary.supportedExtensions.length) {
|
|
6138
|
+
return summary.supportedExtensions.some((extension) => sourcePath.endsWith(extension));
|
|
6139
|
+
}
|
|
6140
|
+
return true;
|
|
6141
|
+
}
|
|
6142
|
+
|
|
6143
|
+
function safeNativeTargetProjectionAdapterSummary(adapter) {
|
|
6144
|
+
try {
|
|
6145
|
+
return normalizeNativeTargetProjectionAdapter(adapter);
|
|
6146
|
+
} catch {
|
|
6147
|
+
return undefined;
|
|
6148
|
+
}
|
|
6149
|
+
}
|
|
6150
|
+
|
|
6151
|
+
function normalizeNativeTargetProjectionAdapter(adapter) {
|
|
6152
|
+
if (!adapter || typeof adapter !== 'object') {
|
|
6153
|
+
throw new Error('Native target projection adapter must be an object');
|
|
6154
|
+
}
|
|
6155
|
+
if (!adapter.id) throw new Error('Native target projection adapter requires an id');
|
|
6156
|
+
const sourceLanguage = normalizeNativeLanguageId(adapter.sourceLanguage ?? adapter.language);
|
|
6157
|
+
if (!sourceLanguage) throw new Error(`Native target projection adapter ${adapter.id} requires a sourceLanguage`);
|
|
6158
|
+
const target = normalizeProjectionMatrixTargets([adapter.target ?? adapter.targetLanguage])[0];
|
|
6159
|
+
if (!target) throw new Error(`Native target projection adapter ${adapter.id} requires a target`);
|
|
6160
|
+
if (typeof adapter.project !== 'function') throw new Error(`Native target projection adapter ${adapter.id} requires a project function`);
|
|
6161
|
+
const capabilities = normalizeStringList(adapter.capabilities);
|
|
6162
|
+
const summaryInput = {
|
|
6163
|
+
id: String(adapter.id),
|
|
6164
|
+
sourceLanguage,
|
|
6165
|
+
language: sourceLanguage,
|
|
6166
|
+
target,
|
|
6167
|
+
parser: `target:${target}`,
|
|
6168
|
+
version: adapter.version === undefined ? undefined : String(adapter.version)
|
|
6169
|
+
};
|
|
6170
|
+
return Object.freeze({
|
|
6171
|
+
id: summaryInput.id,
|
|
6172
|
+
sourceLanguage,
|
|
6173
|
+
target,
|
|
6174
|
+
version: summaryInput.version,
|
|
6175
|
+
capabilities,
|
|
6176
|
+
supportedParsers: normalizeStringList(adapter.supportedParsers),
|
|
6177
|
+
supportedExtensions: normalizeStringList(adapter.supportedExtensions).map((extension) => extension.startsWith('.') ? extension.toLowerCase() : `.${extension.toLowerCase()}`),
|
|
6178
|
+
coverage: normalizeNativeTargetProjectionAdapterCoverage(adapter.coverage, { capabilities }),
|
|
6179
|
+
diagnostics: normalizeAdapterDiagnostics(adapter.diagnostics, summaryInput, {
|
|
6180
|
+
language: sourceLanguage,
|
|
6181
|
+
parser: summaryInput.parser,
|
|
6182
|
+
parserVersion: summaryInput.version
|
|
6183
|
+
}, 'target-adapter')
|
|
6184
|
+
});
|
|
6185
|
+
}
|
|
6186
|
+
|
|
6187
|
+
function normalizeNativeTargetProjectionAdapterCoverage(value = {}, context = {}) {
|
|
6188
|
+
const capabilities = new Set(normalizeStringList(context.capabilities).map((capability) => capability.toLowerCase()));
|
|
6189
|
+
const lossKinds = uniqueStrings(value.lossKinds ?? []);
|
|
6190
|
+
const handledLossKinds = uniqueStrings([
|
|
6191
|
+
...(value.handledLossKinds ?? []),
|
|
6192
|
+
...(capabilities.has('macros') || capabilities.has('macroexpansion') ? ['macroExpansion', 'macroHygiene'] : []),
|
|
6193
|
+
...(capabilities.has('preprocessor') ? ['preprocessor', 'conditionalCompilation'] : []),
|
|
6194
|
+
...(capabilities.has('dynamicruntime') ? ['dynamicRuntime', 'dynamicDispatch'] : []),
|
|
6195
|
+
...(capabilities.has('typeinference') ? ['typeInference', 'overloadResolution'] : [])
|
|
6196
|
+
]);
|
|
6197
|
+
return Object.freeze({
|
|
6198
|
+
readiness: normalizeSemanticMergeReadiness(value.readiness) ?? 'needs-review',
|
|
6199
|
+
lossKinds,
|
|
6200
|
+
handledLossKinds,
|
|
6201
|
+
sourceMapPrecision: value.sourceMapPrecision,
|
|
6202
|
+
semanticCoverage: value.semanticCoverage ?? {},
|
|
6203
|
+
notes: uniqueStrings(value.notes ?? ['Target projection adapter output is host-owned evidence and should be reviewed unless declared ready.'])
|
|
6204
|
+
});
|
|
6205
|
+
}
|
|
6206
|
+
|
|
6207
|
+
function nativeTargetProjectionAdapterEvidence(adapter, diagnostics, input) {
|
|
6208
|
+
const errors = diagnostics.filter((diagnostic) => diagnostic.severity === 'error').length;
|
|
6209
|
+
const warnings = diagnostics.filter((diagnostic) => diagnostic.severity === 'warning').length;
|
|
6210
|
+
return {
|
|
6211
|
+
id: `evidence_${idFragment(adapter.id)}_native_target_projection_adapter`,
|
|
6212
|
+
kind: 'projection',
|
|
6213
|
+
status: errors ? 'failed' : 'passed',
|
|
6214
|
+
path: input.sourcePath,
|
|
6215
|
+
summary: `Ran ${adapter.id} native target projection adapter from ${input.sourceLanguage} to ${input.target} with ${diagnostics.length} diagnostic(s).`,
|
|
6216
|
+
metadata: {
|
|
6217
|
+
adapterId: adapter.id,
|
|
6218
|
+
adapterVersion: adapter.version,
|
|
6219
|
+
sourceLanguage: input.sourceLanguage,
|
|
6220
|
+
target: input.target,
|
|
6221
|
+
targetPath: input.targetPath,
|
|
6222
|
+
outputHash: input.outputHash,
|
|
6223
|
+
capabilities: adapter.capabilities,
|
|
6224
|
+
coverage: adapter.coverage,
|
|
6225
|
+
diagnostics: diagnostics.map(serializableDiagnostic),
|
|
6226
|
+
errors,
|
|
6227
|
+
warnings
|
|
6228
|
+
}
|
|
6229
|
+
};
|
|
6230
|
+
}
|
|
6231
|
+
|
|
6232
|
+
function nativeTargetProjectionDiagnosticToLoss(diagnostic, index, adapter, input) {
|
|
6233
|
+
return {
|
|
6234
|
+
id: `loss_${idFragment(diagnostic.id ?? `${adapter.id}_${index}_${diagnostic.code ?? diagnostic.severity}`)}`,
|
|
6235
|
+
severity: diagnostic.severity,
|
|
6236
|
+
phase: diagnostic.phase ?? 'emit',
|
|
6237
|
+
sourceFormat: input.sourceLanguage,
|
|
6238
|
+
kind: diagnostic.kind ?? 'targetProjectionLoss',
|
|
6239
|
+
message: diagnostic.message,
|
|
6240
|
+
span: diagnostic.span,
|
|
6241
|
+
metadata: {
|
|
6242
|
+
adapterId: adapter.id,
|
|
6243
|
+
adapterVersion: adapter.version,
|
|
6244
|
+
diagnosticId: diagnostic.id,
|
|
6245
|
+
diagnosticCode: diagnostic.code,
|
|
6246
|
+
sourceLanguage: input.sourceLanguage,
|
|
6247
|
+
target: input.target,
|
|
6248
|
+
path: diagnostic.path,
|
|
6249
|
+
...diagnostic.metadata
|
|
6250
|
+
}
|
|
6251
|
+
};
|
|
6252
|
+
}
|
|
6253
|
+
|
|
5889
6254
|
function normalizeNativeImporterAdapter(adapter) {
|
|
5890
6255
|
if (!adapter || typeof adapter !== 'object') {
|
|
5891
6256
|
throw new Error('Native importer adapter must be an object');
|
package/package.json
CHANGED