@shapeshift-labs/frontier-lang-compiler 0.2.101 → 0.2.102
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/dist/declarations/import-adapter-core.d.ts +6 -0
- package/dist/internal/index-impl/createLightweightNativeImport.js +9 -1
- package/dist/internal/index-impl/importNativeSource.js +14 -14
- package/dist/internal/index-impl/nativeImportSemanticIndex.js +33 -0
- package/dist/semantic-import-regions.js +12 -1
- package/package.json +1 -1
|
@@ -98,6 +98,10 @@ export interface ImportNativeSourceOptions {
|
|
|
98
98
|
readonly targetPath?: string;
|
|
99
99
|
readonly targetHash?: string;
|
|
100
100
|
readonly semanticIndex?: SemanticIndexRecord;
|
|
101
|
+
readonly ownershipRegions?: readonly SemanticImportOwnershipRegion[];
|
|
102
|
+
readonly semanticOwnershipRegions?: readonly SemanticImportOwnershipRegion[];
|
|
103
|
+
readonly patchHints?: readonly SemanticImportPatchHint[];
|
|
104
|
+
readonly semanticPatchHints?: readonly SemanticImportPatchHint[];
|
|
101
105
|
readonly sourceMapId?: string;
|
|
102
106
|
readonly sourceMaps?: readonly SourceMapRecord[];
|
|
103
107
|
readonly universalAstId?: string;
|
|
@@ -112,6 +116,8 @@ export interface ImportNativeSourceOptions {
|
|
|
112
116
|
export type NativeSourceImportResult = Omit<LanguageImportResult, 'metadata'> & {
|
|
113
117
|
readonly nativeSource: NativeSourceNode;
|
|
114
118
|
readonly semanticIndex?: SemanticIndexRecord;
|
|
119
|
+
readonly ownershipRegions: readonly SemanticImportOwnershipRegion[];
|
|
120
|
+
readonly patchHints: readonly SemanticImportPatchHint[];
|
|
115
121
|
readonly universalAst: FrontierUniversalAstEnvelope;
|
|
116
122
|
readonly metadata?: Record<string, unknown> & {
|
|
117
123
|
readonly sourcePreservationRecords?: readonly SourcePreservationRecord[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{idFragment}from'../../native-import-utils.js';import{lightweightDependencyRelations}from'../../lightweight-dependency-relations.js';import{lightweightCoverageLosses,scanNativeDeclarations}from'../../native-region-scanner.js';import{semanticOwnershipRegionForDeclaration}from'../../semantic-import-regions.js';import{createSemanticIndexRecord,hashSemanticValue}from'@shapeshift-labs/frontier-lang-kernel';
|
|
1
|
+
import{idFragment,uniqueRecordsById}from'../../native-import-utils.js';import{lightweightDependencyRelations}from'../../lightweight-dependency-relations.js';import{lightweightCoverageLosses,scanNativeDeclarations}from'../../native-region-scanner.js';import{semanticOwnershipRegionForDeclaration,semanticPatchHintForRegion}from'../../semantic-import-regions.js';import{createSemanticIndexRecord,hashSemanticValue}from'@shapeshift-labs/frontier-lang-kernel';
|
|
2
2
|
export function createLightweightNativeImport(input) {
|
|
3
3
|
const parser = input.parser ?? `${input.language}.lightweight-declaration-scan`;
|
|
4
4
|
const rootId = 'native_root';
|
|
@@ -19,11 +19,13 @@ export function createLightweightNativeImport(input) {
|
|
|
19
19
|
const relations = [];
|
|
20
20
|
const facts = [];
|
|
21
21
|
const mappings = [];
|
|
22
|
+
const ownershipRegions = [];
|
|
22
23
|
const evidenceId = `evidence_${idFragment(input.sourcePath ?? input.language)}_lightweight_scan`;
|
|
23
24
|
const dependencies = lightweightDependencyRelations(input, declarations, documentId);
|
|
24
25
|
|
|
25
26
|
for (const declaration of declarations) {
|
|
26
27
|
const ownershipRegion = semanticOwnershipRegionForDeclaration(input, declaration, documentId);
|
|
28
|
+
ownershipRegions.push(ownershipRegion);
|
|
27
29
|
nodes[rootId].children.push(declaration.nodeId);
|
|
28
30
|
nodes[declaration.nodeId] = {
|
|
29
31
|
id: declaration.nodeId,
|
|
@@ -122,6 +124,8 @@ export function createLightweightNativeImport(input) {
|
|
|
122
124
|
});
|
|
123
125
|
}
|
|
124
126
|
losses.push(...lightweightCoverageLosses(input, declarations, input.sourcePreservation));
|
|
127
|
+
const semanticOwnershipRegions = uniqueRecordsById(ownershipRegions);
|
|
128
|
+
const semanticPatchHints = semanticOwnershipRegions.map((region) => semanticPatchHintForRegion(region, 'needs-review'));
|
|
125
129
|
|
|
126
130
|
const semanticIndex = createSemanticIndexRecord({
|
|
127
131
|
id: `index_${idFragment(input.sourcePath ?? input.language)}`,
|
|
@@ -135,6 +139,8 @@ export function createLightweightNativeImport(input) {
|
|
|
135
139
|
occurrences,
|
|
136
140
|
relations,
|
|
137
141
|
facts,
|
|
142
|
+
ownershipRegions: semanticOwnershipRegions,
|
|
143
|
+
patchHints: semanticPatchHints,
|
|
138
144
|
evidence: [{
|
|
139
145
|
id: evidenceId,
|
|
140
146
|
kind: 'import',
|
|
@@ -162,6 +168,8 @@ export function createLightweightNativeImport(input) {
|
|
|
162
168
|
losses,
|
|
163
169
|
semanticIndex,
|
|
164
170
|
mappings,
|
|
171
|
+
ownershipRegions: semanticOwnershipRegions,
|
|
172
|
+
patchHints: semanticPatchHints,
|
|
165
173
|
metadata: {
|
|
166
174
|
parser,
|
|
167
175
|
scanKind: 'lightweight-declaration-scan',
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import{commonGeneratedTargetPath,idFragment}from'../../native-import-utils.js';import{inferSourceMapMappings,normalizeSourceMapMappings,normalizeSourceMaps}from'../../native-source-maps.js';import{createKernelSourcePreservationRecords,summarizeKernelSourcePreservationRecords}from'../../semantic-import-source-preservation.js';import{createDocument,createImportResult,createNativeAstRecord,createPatch,createSourceMapRecord,createUniversalAstEnvelope,hashSemanticValue,nativeSourceNode}from'@shapeshift-labs/frontier-lang-kernel';
|
|
2
2
|
import{attachInputUniversalDialectRegistry}from'../../universal-dialect-registry.js';
|
|
3
3
|
import{createLightweightSemanticLayers}from'./createLightweightSemanticLayers.js';
|
|
4
|
-
import{attachNativeImportLossSummary}from'./attachNativeImportLossSummary.js';import{createLightweightNativeImport}from'./createLightweightNativeImport.js';import{createNativeSourcePreservation}from'./createNativeSourcePreservation.js';import{hasNativeExactAstEvidence}from'./hasNativeExactAstEvidence.js';import{normalizeNativeLossRecords}from'./normalizeNativeLossRecords.js';import{summarizeNativeImportLosses}from'./summarizeNativeImportLosses.js';import{unverifiedNativeAstLosses}from'./unverifiedNativeAstLosses.js';import{withNativeImportReadiness}from'./withNativeImportReadiness.js';
|
|
4
|
+
import{attachNativeImportLossSummary}from'./attachNativeImportLossSummary.js';import{createLightweightNativeImport}from'./createLightweightNativeImport.js';import{createNativeSourcePreservation}from'./createNativeSourcePreservation.js';import{hasNativeExactAstEvidence}from'./hasNativeExactAstEvidence.js';import{createNativeImportSemanticIndex}from'./nativeImportSemanticIndex.js';import{normalizeNativeLossRecords}from'./normalizeNativeLossRecords.js';import{summarizeNativeImportLosses}from'./summarizeNativeImportLosses.js';import{unverifiedNativeAstLosses}from'./unverifiedNativeAstLosses.js';import{withNativeImportReadiness}from'./withNativeImportReadiness.js';
|
|
5
5
|
export function importNativeSource(input) {
|
|
6
6
|
const language = input.language ?? input.nativeAst?.language;
|
|
7
7
|
if (!language) throw new Error('importNativeSource requires a language or nativeAst.language');
|
|
8
8
|
const sourcePath = input.sourcePath ?? input.nativeAst?.sourcePath;
|
|
9
9
|
const declaredSourceHash = input.sourceHash ?? input.nativeAst?.sourceHash;
|
|
10
|
-
const sourceHash = typeof input.sourceText === 'string'
|
|
11
|
-
|
|
12
|
-
: declaredSourceHash ?? hashSemanticValue(input.nativeAst?.nodes ?? input.nativeAst ?? {});
|
|
13
|
-
const targetPath = input.targetPath ?? input.target?.emitPath;
|
|
14
|
-
const targetHash = input.targetHash;
|
|
10
|
+
const sourceHash = typeof input.sourceText === 'string' ? hashSemanticValue(input.sourceText) : declaredSourceHash ?? hashSemanticValue(input.nativeAst?.nodes ?? input.nativeAst ?? {});
|
|
11
|
+
const targetPath = input.targetPath ?? input.target?.emitPath; const targetHash = input.targetHash;
|
|
15
12
|
const importIdPart = idFragment(input.id ?? input.nativeSourceId ?? sourcePath ?? language);
|
|
16
13
|
const sourcePreservation = input.sourcePreservation ?? (typeof input.sourceText === 'string'
|
|
17
14
|
? createNativeSourcePreservation({
|
|
@@ -146,6 +143,7 @@ export function importNativeSource(input) {
|
|
|
146
143
|
});
|
|
147
144
|
const evidence = attachNativeImportLossSummary(baseEvidence, lossSummary);
|
|
148
145
|
const semanticIndex = input.semanticIndex ?? lightweight?.semanticIndex;
|
|
146
|
+
const { ownershipRegions, patchHints, semanticIndexForResult } = createNativeImportSemanticIndex(input, lightweight, semanticIndex);
|
|
149
147
|
const sourceMapMappings = normalizeSourceMapMappings(
|
|
150
148
|
input.mappings ?? lightweight?.mappings ?? inferSourceMapMappings({
|
|
151
149
|
semanticIndex,
|
|
@@ -174,7 +172,7 @@ export function importNativeSource(input) {
|
|
|
174
172
|
target: input.target,
|
|
175
173
|
targetPath: inferredTargetPath,
|
|
176
174
|
targetHash,
|
|
177
|
-
semanticIndexId:
|
|
175
|
+
semanticIndexId: semanticIndexForResult?.id,
|
|
178
176
|
nativeAstId: nativeAst.id,
|
|
179
177
|
nativeSourceId: nativeSource.id,
|
|
180
178
|
mappings: sourceMapMappings,
|
|
@@ -191,7 +189,7 @@ export function importNativeSource(input) {
|
|
|
191
189
|
nativeSources: [nativeSource],
|
|
192
190
|
nativeAst,
|
|
193
191
|
nativeSource,
|
|
194
|
-
semanticIndex,
|
|
192
|
+
semanticIndex: semanticIndexForResult,
|
|
195
193
|
evidence,
|
|
196
194
|
losses,
|
|
197
195
|
sourcePreservation,
|
|
@@ -213,16 +211,16 @@ export function importNativeSource(input) {
|
|
|
213
211
|
evidence,
|
|
214
212
|
nativeSource,
|
|
215
213
|
nativeAst,
|
|
216
|
-
semanticIndex
|
|
214
|
+
semanticIndex: semanticIndexForResult
|
|
217
215
|
});
|
|
218
216
|
const kernelSourcePreservationSummary = summarizeKernelSourcePreservationRecords(sourcePreservationRecords);
|
|
219
217
|
const resultSourceMapMappings = sourceMaps.flatMap((sourceMap) => sourceMap.mappings ?? []);
|
|
220
|
-
const semanticLayers=input.semanticLayers??createLightweightSemanticLayers({importIdPart,language,sourcePath,sourceHash,nativeSource,nativeAst,semanticIndex,sourceMaps,losses,evidence,sourcePreservationRecords});
|
|
218
|
+
const semanticLayers=input.semanticLayers??createLightweightSemanticLayers({importIdPart,language,sourcePath,sourceHash,nativeSource,nativeAst,semanticIndex:semanticIndexForResult,sourceMaps,losses,evidence,sourcePreservationRecords});
|
|
221
219
|
let universalAst = createUniversalAstEnvelope({
|
|
222
220
|
id: input.universalAstId ?? `universal_ast_${importIdPart}`,
|
|
223
221
|
document,
|
|
224
222
|
nativeSources: [nativeSource],
|
|
225
|
-
semanticIndex,
|
|
223
|
+
semanticIndex: semanticIndexForResult,
|
|
226
224
|
sourceMaps,
|
|
227
225
|
losses,
|
|
228
226
|
evidence,
|
|
@@ -262,7 +260,7 @@ export function importNativeSource(input) {
|
|
|
262
260
|
metadata: {
|
|
263
261
|
sourceLanguage: language,
|
|
264
262
|
sourcePath,
|
|
265
|
-
semanticIndexId:
|
|
263
|
+
semanticIndexId: semanticIndexForResult?.id,
|
|
266
264
|
universalAstId: universalAst.id,
|
|
267
265
|
sourceMapIds: sourceMaps.map((sourceMap) => sourceMap.id),
|
|
268
266
|
...(sourcePreservation ? {
|
|
@@ -287,14 +285,16 @@ export function importNativeSource(input) {
|
|
|
287
285
|
document,
|
|
288
286
|
patch,
|
|
289
287
|
nativeAst,
|
|
290
|
-
semanticIndex,
|
|
288
|
+
semanticIndex: semanticIndexForResult,
|
|
291
289
|
universalAst,
|
|
292
290
|
sourceMaps,
|
|
291
|
+
ownershipRegions,
|
|
292
|
+
patchHints: semanticIndexForResult?.patchHints ?? patchHints,
|
|
293
293
|
losses,
|
|
294
294
|
evidence,
|
|
295
295
|
metadata: {
|
|
296
296
|
nativeSourceId: nativeSource.id,
|
|
297
|
-
semanticIndexId:
|
|
297
|
+
semanticIndexId: semanticIndexForResult?.id,
|
|
298
298
|
universalAstId: universalAst.id,
|
|
299
299
|
sourceMapIds: sourceMaps.map((sourceMap) => sourceMap.id),
|
|
300
300
|
semanticStatus,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import{uniqueRecordsById}from'../../native-import-utils.js';
|
|
2
|
+
import{semanticOwnershipRegionsFromSemanticIndex,semanticPatchHintForRegion}from'../../semantic-import-regions.js';
|
|
3
|
+
|
|
4
|
+
export function createNativeImportSemanticIndex(input, lightweight, semanticIndex) {
|
|
5
|
+
const ownershipRegions = uniqueRecordsById([
|
|
6
|
+
...(Array.isArray(input.ownershipRegions) ? input.ownershipRegions : []),
|
|
7
|
+
...(Array.isArray(input.semanticOwnershipRegions) ? input.semanticOwnershipRegions : []),
|
|
8
|
+
...(lightweight?.ownershipRegions ?? []),
|
|
9
|
+
...semanticOwnershipRegionsFromSemanticIndex(semanticIndex),
|
|
10
|
+
...(Array.isArray(input.universalAst?.ownershipRegions) ? input.universalAst.ownershipRegions : []),
|
|
11
|
+
...(Array.isArray(input.metadata?.ownershipRegions) ? input.metadata.ownershipRegions : [])
|
|
12
|
+
]);
|
|
13
|
+
const patchHints = uniqueRecordsById([
|
|
14
|
+
...(Array.isArray(input.patchHints) ? input.patchHints : []),
|
|
15
|
+
...(Array.isArray(input.semanticPatchHints) ? input.semanticPatchHints : []),
|
|
16
|
+
...(lightweight?.patchHints ?? []),
|
|
17
|
+
...(Array.isArray(semanticIndex?.patchHints) ? semanticIndex.patchHints : []),
|
|
18
|
+
...(Array.isArray(input.universalAst?.patchHints) ? input.universalAst.patchHints : []),
|
|
19
|
+
...(Array.isArray(input.metadata?.patchHints) ? input.metadata.patchHints : [])
|
|
20
|
+
]);
|
|
21
|
+
const resultPatchHints = patchHints.length
|
|
22
|
+
? patchHints
|
|
23
|
+
: ownershipRegions.map((region) => semanticPatchHintForRegion(region, 'needs-review'));
|
|
24
|
+
return {
|
|
25
|
+
ownershipRegions,
|
|
26
|
+
patchHints: resultPatchHints,
|
|
27
|
+
semanticIndexForResult: semanticIndex ? {
|
|
28
|
+
...semanticIndex,
|
|
29
|
+
ownershipRegions,
|
|
30
|
+
patchHints: resultPatchHints
|
|
31
|
+
} : semanticIndex
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { caseSensitiveIdFragment, idFragment, uniqueStrings } from './native-import-utils.js';
|
|
1
|
+
import { caseSensitiveIdFragment, idFragment, uniqueRecordsById, uniqueStrings } from './native-import-utils.js';
|
|
2
2
|
|
|
3
3
|
const NativeImportRegionTaxonomyKinds = Object.freeze([
|
|
4
4
|
'symbol',
|
|
@@ -172,9 +172,20 @@ function summarizeSemanticImportRegionTaxonomy(regions) {
|
|
|
172
172
|
};
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
function semanticOwnershipRegionsFromSemanticIndex(semanticIndex) {
|
|
176
|
+
const factRegions = (semanticIndex?.facts ?? [])
|
|
177
|
+
.filter((fact) => fact?.predicate === 'semanticOwnershipRegion' && fact.value && typeof fact.value === 'object')
|
|
178
|
+
.map((fact) => fact.value);
|
|
179
|
+
return uniqueRecordsById([
|
|
180
|
+
...(Array.isArray(semanticIndex?.ownershipRegions) ? semanticIndex.ownershipRegions : []),
|
|
181
|
+
...factRegions
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
|
|
175
185
|
export {
|
|
176
186
|
NativeImportRegionTaxonomyKinds,
|
|
177
187
|
semanticOwnershipRegionForDeclaration,
|
|
188
|
+
semanticOwnershipRegionsFromSemanticIndex,
|
|
178
189
|
semanticOwnershipRegionForSymbol,
|
|
179
190
|
semanticPatchHintForRegion,
|
|
180
191
|
semanticRegionKindForSymbol,
|
package/package.json
CHANGED