circle-ir 4.18.1 → 4.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/dist/analysis/advisories.d.ts +21 -3
  2. package/dist/analysis/advisories.d.ts.map +1 -1
  3. package/dist/analysis/advisories.js +26 -8
  4. package/dist/analysis/advisories.js.map +1 -1
  5. package/dist/analysis/arg-executing-programs.d.ts +16 -0
  6. package/dist/analysis/arg-executing-programs.d.ts.map +1 -0
  7. package/dist/analysis/arg-executing-programs.js +24 -0
  8. package/dist/analysis/arg-executing-programs.js.map +1 -0
  9. package/dist/analysis/config-loader.d.ts.map +1 -1
  10. package/dist/analysis/config-loader.js +32 -23
  11. package/dist/analysis/config-loader.js.map +1 -1
  12. package/dist/analysis/constant-caller-gate.d.ts +3 -1
  13. package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
  14. package/dist/analysis/constant-caller-gate.js +108 -1
  15. package/dist/analysis/constant-caller-gate.js.map +1 -1
  16. package/dist/analysis/constant-propagation/index.d.ts.map +1 -1
  17. package/dist/analysis/constant-propagation/index.js +1 -1
  18. package/dist/analysis/constant-propagation/index.js.map +1 -1
  19. package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
  20. package/dist/analysis/constant-propagation/patterns.js +5 -0
  21. package/dist/analysis/constant-propagation/patterns.js.map +1 -1
  22. package/dist/analysis/constant-propagation/propagator.d.ts +1 -1
  23. package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
  24. package/dist/analysis/constant-propagation/propagator.js +15 -1
  25. package/dist/analysis/constant-propagation/propagator.js.map +1 -1
  26. package/dist/analysis/constant-propagation/types.d.ts +2 -0
  27. package/dist/analysis/constant-propagation/types.d.ts.map +1 -1
  28. package/dist/analysis/dependency-versions.d.ts +33 -0
  29. package/dist/analysis/dependency-versions.d.ts.map +1 -1
  30. package/dist/analysis/dependency-versions.js +70 -0
  31. package/dist/analysis/dependency-versions.js.map +1 -1
  32. package/dist/analysis/interprocedural.d.ts +6 -0
  33. package/dist/analysis/interprocedural.d.ts.map +1 -1
  34. package/dist/analysis/interprocedural.js +53 -6
  35. package/dist/analysis/interprocedural.js.map +1 -1
  36. package/dist/analysis/js-helper-return.d.ts +12 -0
  37. package/dist/analysis/js-helper-return.d.ts.map +1 -0
  38. package/dist/analysis/js-helper-return.js +64 -0
  39. package/dist/analysis/js-helper-return.js.map +1 -0
  40. package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
  41. package/dist/analysis/passes/constant-propagation-pass.js +1 -0
  42. package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
  43. package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
  44. package/dist/analysis/passes/cross-file-pass.js +61 -0
  45. package/dist/analysis/passes/cross-file-pass.js.map +1 -1
  46. package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
  47. package/dist/analysis/passes/csharp-sanitizer-credit.js +60 -3
  48. package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
  49. package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts +15 -0
  50. package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts.map +1 -1
  51. package/dist/analysis/passes/deserialization-safety-gate-pass.js +60 -1
  52. package/dist/analysis/passes/deserialization-safety-gate-pass.js.map +1 -1
  53. package/dist/analysis/passes/interprocedural-pass.d.ts +23 -1
  54. package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
  55. package/dist/analysis/passes/interprocedural-pass.js +148 -6
  56. package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
  57. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  58. package/dist/analysis/passes/language-sources-pass.js +150 -7
  59. package/dist/analysis/passes/language-sources-pass.js.map +1 -1
  60. package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
  61. package/dist/analysis/passes/resource-leak-pass.js +20 -4
  62. package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
  63. package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
  64. package/dist/analysis/passes/sink-filter-pass.js +229 -8
  65. package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
  66. package/dist/analysis/passes/taint-propagation-pass.d.ts +7 -3
  67. package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
  68. package/dist/analysis/passes/taint-propagation-pass.js +176 -15
  69. package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
  70. package/dist/analysis/passes/xml-entity-expansion-pass.d.ts.map +1 -1
  71. package/dist/analysis/passes/xml-entity-expansion-pass.js +50 -6
  72. package/dist/analysis/passes/xml-entity-expansion-pass.js.map +1 -1
  73. package/dist/analysis/pep440-version.d.ts +40 -0
  74. package/dist/analysis/pep440-version.d.ts.map +1 -0
  75. package/dist/analysis/pep440-version.js +149 -0
  76. package/dist/analysis/pep440-version.js.map +1 -0
  77. package/dist/analysis/rules.d.ts.map +1 -1
  78. package/dist/analysis/rules.js +6 -0
  79. package/dist/analysis/rules.js.map +1 -1
  80. package/dist/analysis/sbom.d.ts +43 -4
  81. package/dist/analysis/sbom.d.ts.map +1 -1
  82. package/dist/analysis/sbom.js +265 -33
  83. package/dist/analysis/sbom.js.map +1 -1
  84. package/dist/analysis/taint-matcher.d.ts.map +1 -1
  85. package/dist/analysis/taint-matcher.js +107 -5
  86. package/dist/analysis/taint-matcher.js.map +1 -1
  87. package/dist/analyzer.d.ts +6 -0
  88. package/dist/analyzer.d.ts.map +1 -1
  89. package/dist/analyzer.js +27 -1
  90. package/dist/analyzer.js.map +1 -1
  91. package/dist/browser/circle-ir.js +3379 -101
  92. package/dist/core/circle-ir-core.cjs +218 -35
  93. package/dist/core/circle-ir-core.js +218 -35
  94. package/dist/core/extractors/dfg.js +46 -7
  95. package/dist/core/extractors/dfg.js.map +1 -1
  96. package/dist/core/extractors/ts-declaration-detail.d.ts +8 -0
  97. package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -1
  98. package/dist/core/extractors/ts-declaration-detail.js +22 -0
  99. package/dist/core/extractors/ts-declaration-detail.js.map +1 -1
  100. package/dist/facts/arrow.d.ts +106 -0
  101. package/dist/facts/arrow.d.ts.map +1 -0
  102. package/dist/facts/arrow.js +196 -0
  103. package/dist/facts/arrow.js.map +1 -0
  104. package/dist/facts/facts2.d.ts +59 -0
  105. package/dist/facts/facts2.d.ts.map +1 -0
  106. package/dist/facts/facts2.js +362 -0
  107. package/dist/facts/facts2.js.map +1 -0
  108. package/dist/facts/index.d.ts +20 -0
  109. package/dist/facts/index.d.ts.map +1 -0
  110. package/dist/facts/index.js +14 -0
  111. package/dist/facts/index.js.map +1 -0
  112. package/dist/facts/java-facts.d.ts +56 -0
  113. package/dist/facts/java-facts.d.ts.map +1 -0
  114. package/dist/facts/java-facts.js +250 -0
  115. package/dist/facts/java-facts.js.map +1 -0
  116. package/dist/facts/order.d.ts +39 -0
  117. package/dist/facts/order.d.ts.map +1 -0
  118. package/dist/facts/order.js +120 -0
  119. package/dist/facts/order.js.map +1 -0
  120. package/dist/facts/schema.d.ts +60 -0
  121. package/dist/facts/schema.d.ts.map +1 -0
  122. package/dist/facts/schema.js +126 -0
  123. package/dist/facts/schema.js.map +1 -0
  124. package/dist/facts/schema2.d.ts +47 -0
  125. package/dist/facts/schema2.d.ts.map +1 -0
  126. package/dist/facts/schema2.js +194 -0
  127. package/dist/facts/schema2.js.map +1 -0
  128. package/dist/facts/table.d.ts +80 -0
  129. package/dist/facts/table.d.ts.map +1 -0
  130. package/dist/facts/table.js +548 -0
  131. package/dist/facts/table.js.map +1 -0
  132. package/dist/graph-facts/dead-code.d.ts +2 -0
  133. package/dist/graph-facts/dead-code.d.ts.map +1 -1
  134. package/dist/graph-facts/dead-code.js +1 -1
  135. package/dist/graph-facts/dead-code.js.map +1 -1
  136. package/dist/graph-facts/reach.d.ts +24 -6
  137. package/dist/graph-facts/reach.d.ts.map +1 -1
  138. package/dist/graph-facts/reach.js +52 -12
  139. package/dist/graph-facts/reach.js.map +1 -1
  140. package/dist/graph-facts/removal-reach.d.ts +2 -0
  141. package/dist/graph-facts/removal-reach.d.ts.map +1 -1
  142. package/dist/graph-facts/removal-reach.js +1 -1
  143. package/dist/graph-facts/removal-reach.js.map +1 -1
  144. package/dist/index.d.ts +10 -4
  145. package/dist/index.d.ts.map +1 -1
  146. package/dist/index.js +13 -2
  147. package/dist/index.js.map +1 -1
  148. package/dist/navigation/java-graph.d.ts +23 -0
  149. package/dist/navigation/java-graph.d.ts.map +1 -1
  150. package/dist/navigation/java-graph.js +222 -8
  151. package/dist/navigation/java-graph.js.map +1 -1
  152. package/dist/navigation/navigation-index.d.ts +9 -0
  153. package/dist/navigation/navigation-index.d.ts.map +1 -1
  154. package/dist/navigation/navigation-index.js +25 -0
  155. package/dist/navigation/navigation-index.js.map +1 -1
  156. package/dist/navigation/ts-call-edges.d.ts +9 -0
  157. package/dist/navigation/ts-call-edges.d.ts.map +1 -1
  158. package/dist/navigation/ts-call-edges.js.map +1 -1
  159. package/dist/resolution/cross-file.d.ts +46 -0
  160. package/dist/resolution/cross-file.d.ts.map +1 -1
  161. package/dist/resolution/cross-file.js +281 -13
  162. package/dist/resolution/cross-file.js.map +1 -1
  163. package/dist/stable-ids/files.d.ts +22 -0
  164. package/dist/stable-ids/files.d.ts.map +1 -0
  165. package/dist/stable-ids/files.js +28 -0
  166. package/dist/stable-ids/files.js.map +1 -0
  167. package/dist/stable-ids/hash.d.ts +16 -4
  168. package/dist/stable-ids/hash.d.ts.map +1 -1
  169. package/dist/stable-ids/hash.js +266 -80
  170. package/dist/stable-ids/hash.js.map +1 -1
  171. package/dist/stable-ids/index.d.ts +3 -2
  172. package/dist/stable-ids/index.d.ts.map +1 -1
  173. package/dist/stable-ids/index.js +3 -2
  174. package/dist/stable-ids/index.js.map +1 -1
  175. package/dist/stable-ids/nodes.d.ts +45 -1
  176. package/dist/stable-ids/nodes.d.ts.map +1 -1
  177. package/dist/stable-ids/nodes.js +118 -15
  178. package/dist/stable-ids/nodes.js.map +1 -1
  179. package/dist/stable-ids/ts-parse-errors.d.ts +5 -1
  180. package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
  181. package/dist/stable-ids/ts-parse-errors.js +35 -2
  182. package/dist/stable-ids/ts-parse-errors.js.map +1 -1
  183. package/package.json +8 -4
  184. package/schemas/facts@1.json +134 -0
  185. package/schemas/facts@2.json +216 -0
@@ -0,0 +1,196 @@
1
+ /**
2
+ * `facts@1` and `facts@2` tables → Arrow IPC file bytes, one file per
3
+ * relation, plus the manifest. The wire form the graph store reads
4
+ * (graph-store design §3). The two schemes share the writer; only the
5
+ * relation table and the `facts` metadata value differ.
6
+ *
7
+ * `apache-arrow` is an optional dependency loaded on first use, so the library
8
+ * keeps running where it is not installed (browser bundles leave it external)
9
+ * and nothing is paid until a caller asks for facts. Determinism: Arrow JS
10
+ * writes no timestamps or random ids, dictionary ids are assigned here by
11
+ * column position (never by the library's global counter), the full
12
+ * vocabulary is written as every dictionary, and batches are cut at
13
+ * `FACTS_CHUNK_ROWS` after the canonical sort — two runs over the same facts
14
+ * give identical bytes (locked by `tests/facts/arrow.test.ts`). Columns arrive
15
+ * as typed arrays (`FactTable`), so a batch is buffer slices, not cells.
16
+ */
17
+ import { blake3 } from '../stable-ids/hash.js';
18
+ import { FACTS_CHUNK_ROWS, FACTS_ID_WIDTH, FACTS_RELATION_NAMES, FACTS_RELATIONS, FACTS_SCHEME, } from './schema.js';
19
+ import { FACTS2_RELATION_NAMES, FACTS2_RELATIONS, FACTS2_SCHEME } from './schema2.js';
20
+ import { canonicalTable, tableFromRows } from './table.js';
21
+ const FACTS1_SPEC = { scheme: FACTS_SCHEME, names: FACTS_RELATION_NAMES, relations: FACTS_RELATIONS };
22
+ const FACTS2_SPEC = { scheme: FACTS2_SCHEME, names: FACTS2_RELATION_NAMES, relations: FACTS2_RELATIONS };
23
+ let arrowModule;
24
+ /** The `apache-arrow` module, loaded once; a clear error when it is not installed. */
25
+ export async function loadArrow() {
26
+ arrowModule ??= import('apache-arrow').catch((e) => {
27
+ arrowModule = undefined;
28
+ throw new Error(`facts@1: emitting Arrow needs the optional dependency apache-arrow (npm install apache-arrow): ${e instanceof Error ? e.message : String(e)}`);
29
+ });
30
+ return arrowModule;
31
+ }
32
+ const encoder = new TextEncoder();
33
+ const HEX = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
34
+ /** Lowercase hex of the bytes. */
35
+ export function hex(bytes) {
36
+ let s = '';
37
+ for (let i = 0; i < bytes.length; i++)
38
+ s += HEX[bytes[i]];
39
+ return s;
40
+ }
41
+ function arrowType(arrow, c, dictionaryId) {
42
+ switch (c.type) {
43
+ case 'fixed16': return new arrow.FixedSizeBinary(FACTS_ID_WIDTH);
44
+ case 'u32': return new arrow.Uint32();
45
+ case 'utf8': return new arrow.Utf8();
46
+ case 'bool': return new arrow.Bool();
47
+ case 'dict': return new arrow.Dictionary(new arrow.Utf8(), new arrow.Int8(), dictionaryId, false);
48
+ }
49
+ }
50
+ /** Arrow Utf8 buffers for `strings[start, end)`: offsets and the UTF-8 bytes, encoded in place into one buffer. */
51
+ function utf8Data(strings, start, end) {
52
+ const n = end - start;
53
+ const offsets = new Int32Array(n + 1);
54
+ let bound = 0;
55
+ for (let i = start; i < end; i++)
56
+ bound += strings[i].length * 3;
57
+ const buffer = new Uint8Array(bound);
58
+ let total = 0;
59
+ for (let i = 0; i < n; i++) {
60
+ const s = strings[start + i];
61
+ if (s.length > 0)
62
+ total += encoder.encodeInto(s, buffer.subarray(total)).written;
63
+ offsets[i + 1] = total;
64
+ }
65
+ return { offsets, bytes: buffer.subarray(0, total) };
66
+ }
67
+ function bitmap(flags, start, end) {
68
+ const n = end - start;
69
+ const out = new Uint8Array(Math.ceil(n / 8) || 1);
70
+ for (let i = 0; i < n; i++)
71
+ if (flags[start + i] !== 0)
72
+ out[i >> 3] |= 1 << (i & 7);
73
+ return out;
74
+ }
75
+ function columnData(arrow, c, type, data, start, end, dictionary) {
76
+ const n = end - start;
77
+ switch (c.type) {
78
+ case 'fixed16':
79
+ return arrow.makeData({ type: type, length: n, nullCount: 0, data: data.subarray(start * FACTS_ID_WIDTH, end * FACTS_ID_WIDTH) });
80
+ case 'u32':
81
+ return arrow.makeData({ type: type, length: n, nullCount: 0, data: data.subarray(start, end) });
82
+ case 'bool':
83
+ return arrow.makeData({ type: type, length: n, nullCount: 0, data: bitmap(data, start, end) });
84
+ case 'utf8': {
85
+ const u = utf8Data(data, start, end);
86
+ return arrow.makeData({ type: type, length: n, nullCount: 0, valueOffsets: u.offsets, data: u.bytes });
87
+ }
88
+ case 'dict':
89
+ return arrow.makeData({ type: type, length: n, nullCount: 0, data: data.subarray(start, end), dictionary });
90
+ }
91
+ }
92
+ function isTable(x) {
93
+ return !Array.isArray(x);
94
+ }
95
+ /**
96
+ * Arrow IPC file bytes for one relation. A `FactTable` is written as given
97
+ * (it must already be canonical: sorted, no duplicates); rows in the row form
98
+ * are put in canonical form first (sorted and deduplicated).
99
+ */
100
+ export async function relationToArrowIpc(name, input, options = {}) {
101
+ return writeRelation(FACTS1_SPEC, name, input, options);
102
+ }
103
+ /** `relationToArrowIpc` for a `facts@2` relation: the `facts@2` columns and `facts` metadata value. */
104
+ export async function relation2ToArrowIpc(name, input, options = {}) {
105
+ return writeRelation(FACTS2_SPEC, name, input, options);
106
+ }
107
+ async function writeRelation(spec, name, input, options) {
108
+ const arrow = await loadArrow();
109
+ const relation = spec.relations[name];
110
+ if (!relation)
111
+ throw new Error(`${spec.scheme}: no relation ${String(name)}`);
112
+ let table;
113
+ let duplicatesDropped = 0;
114
+ if (isTable(input)) {
115
+ if (input.columns.length !== relation.columns.length)
116
+ throw new Error(`${spec.scheme}: a ${name} table has ${input.columns.length} columns, the relation ${relation.columns.length}`);
117
+ table = input;
118
+ }
119
+ else {
120
+ const c = canonicalTable(relation, tableFromRows(relation, input).columns, input.length);
121
+ table = c.table;
122
+ duplicatesDropped = c.duplicatesDropped;
123
+ }
124
+ const types = relation.columns.map((c, i) => arrowType(arrow, c, i));
125
+ const dictionaries = relation.columns.map(c => {
126
+ if (c.type !== 'dict')
127
+ return undefined;
128
+ const vocab = c.values;
129
+ const u = utf8Data(vocab, 0, vocab.length);
130
+ return arrow.makeVector(arrow.makeData({ type: new arrow.Utf8(), length: vocab.length, nullCount: 0, valueOffsets: u.offsets, data: u.bytes }));
131
+ });
132
+ const fields = relation.columns.map((c, i) => new arrow.Field(c.name, types[i], c.nullable));
133
+ const metadata = new Map([['facts', spec.scheme], ['ids', 'ids@0.1']]);
134
+ if (options.engine)
135
+ metadata.set('engine', options.engine);
136
+ if (options.parser)
137
+ metadata.set('parser', options.parser);
138
+ const schema = new arrow.Schema(fields, metadata);
139
+ const batches = [];
140
+ for (let start = 0; start < table.length; start += FACTS_CHUNK_ROWS) {
141
+ const end = Math.min(start + FACTS_CHUNK_ROWS, table.length);
142
+ const children = relation.columns.map((c, i) => columnData(arrow, c, types[i], table.columns[i], start, end, dictionaries[i]));
143
+ const struct = arrow.makeData({ type: new arrow.Struct(fields), length: end - start, nullCount: 0, children });
144
+ batches.push(new arrow.RecordBatch(schema, struct));
145
+ }
146
+ const bytes = arrow.RecordBatchFileWriter.writeAll(new arrow.Table(schema, batches)).toUint8Array(true);
147
+ return { bytes, batches: batches.length, rows: table.length, duplicatesDropped };
148
+ }
149
+ /**
150
+ * Every relation as IPC file bytes plus the manifest. Takes the emitter's
151
+ * `FactSet` (canonical tables with their dedupe counts) or a record of
152
+ * relations in either form.
153
+ */
154
+ export async function factsToArrow(input, options = {}) {
155
+ const { relations, manifest } = await writeAll(FACTS1_SPEC, input, options);
156
+ return { scheme: FACTS_SCHEME, relations, manifest: { facts: FACTS_SCHEME, ...manifest } };
157
+ }
158
+ /**
159
+ * Every `facts@2` relation as IPC file bytes plus the manifest. Takes the
160
+ * `facts@2` emitter's `Fact2Set` or a record of the twelve relations in
161
+ * either form.
162
+ */
163
+ export async function facts2ToArrow(input, options = {}) {
164
+ const { relations, manifest } = await writeAll(FACTS2_SPEC, input, options);
165
+ return { scheme: FACTS2_SCHEME, relations, manifest: { facts: FACTS2_SCHEME, ...manifest } };
166
+ }
167
+ async function writeAll(spec, input, options) {
168
+ const set = 'relations' in input && 'duplicatesDropped' in input ? input : undefined;
169
+ const relations = {};
170
+ const manifestRelations = {};
171
+ for (const name of spec.names) {
172
+ const data = set ? set.relations[name] : input[name];
173
+ if (data === undefined)
174
+ throw new Error(`${spec.scheme}: relation ${name} is missing`);
175
+ const { bytes, batches, rows, duplicatesDropped } = await writeRelation(spec, name, data, options);
176
+ relations[name] = bytes;
177
+ manifestRelations[name] = {
178
+ file: `${name}.arrow`,
179
+ rows,
180
+ batches,
181
+ bytes: bytes.length,
182
+ blake3: hex(blake3(bytes)),
183
+ duplicates_dropped: set ? set.duplicatesDropped[name] : duplicatesDropped,
184
+ };
185
+ }
186
+ const manifest = {
187
+ ids: 'ids@0.1',
188
+ ...(options.source ? { source: options.source } : {}),
189
+ ...(options.engine ? { engine: options.engine } : {}),
190
+ ...(options.parser ? { parser: options.parser } : {}),
191
+ chunk_rows: FACTS_CHUNK_ROWS,
192
+ relations: manifestRelations,
193
+ };
194
+ return { relations, manifest };
195
+ }
196
+ //# sourceMappingURL=arrow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrow.js","sourceRoot":"","sources":["../../src/facts/arrow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,YAAY,GAKb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAA8C,MAAM,cAAc,CAAC;AAClI,OAAO,EAAE,cAAc,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAC;AAoEhG,MAAM,WAAW,GAAuD,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,oBAAoB,EAA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EAAE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACnG,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QACxB,iBAAiB,CAAC,IAAI,CAAC,GAAG;YACxB,IAAI,EAAE,GAAG,IAAI,QAAQ;YACrB,IAAI;YACJ,OAAO;YACP,KAAK,EAAE,KAAK,CAAC,MAAM;YACnB,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1B,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,iBAAiB;SAC1E,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG;QACf,GAAG,EAAE,SAAkB;QACvB,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,UAAU,EAAE,gBAAgB;QAC5B,SAAS,EAAE,iBAAiB;KAC7B,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * `facts@2` rows from a call graph: a post-pass over the graph the engine
3
+ * already builds (`java-graph@0.1`), the counterpart of `javaGraphFactSet` for the `facts@2`
4
+ * schema. Opt-in: `facts@1` stays the default (`JavaGraphOptions.factsScheme`).
5
+ *
6
+ * Against the `facts@1` post-pass:
7
+ * - every relation that names a file carries the stable file key
8
+ * (`fileKey(path)`), never a dense index;
9
+ * - a site (`call`, `unresolved`, `ref`, `registration`) carries `rel_line` =
10
+ * its line minus the start line of the declaration whose body holds it, and
11
+ * its column, and no file (the file is that declaration's file);
12
+ * - `decl` has no position (`decl_pos` holds it) and gains `name`,
13
+ * `parent_id`, `type_only`, the two `ids@0.1` flags, `contained` (the
14
+ * reach walk's `contains` rule, `containedIn`) and `loads_parent` (the
15
+ * graph's member-initializes-its-class `loads`);
16
+ * - `call.declaring` marks the polymorphic row whose callee is the member the
17
+ * receiver's static type declares;
18
+ * - `ref` (references), `registration` (unresolved registrations),
19
+ * `files.partial` and `parse_error` (the first blocking parse error, its
20
+ * column 0-based) are new.
21
+ *
22
+ * The `#n` re-key of a declaration id two files derive is the `facts@1` one,
23
+ * and it rewrites `parent_id` and every site's declaration as it rewrites
24
+ * `caller_id`. Built as columns, then each relation goes through
25
+ * `canonicalTable` (sorted, duplicates dropped and counted).
26
+ */
27
+ import type { JavaGraph } from '../navigation/java-graph.js';
28
+ import type { CallEdge, ReferenceEdge, TsEntry, UnresolvedCall, UnresolvedRegistration } from '../navigation/ts-call-edges.js';
29
+ import { type StableIdFile } from '../stable-ids/types.js';
30
+ import { type Facts2RelationName } from './schema2.js';
31
+ import { type FactTable } from './table.js';
32
+ import { type JavaFactsInput } from './java-facts.js';
33
+ /** One file's source as the post-pass reads it: path, code (for `content_hash`), its imports and, optionally, its DFG (for `flow`). */
34
+ export type Facts2Input = JavaFactsInput;
35
+ /** The twelve relations in canonical form (sorted sets) with what the dedupe dropped from each. */
36
+ export interface Fact2Set {
37
+ relations: Readonly<Record<Facts2RelationName, FactTable>>;
38
+ duplicatesDropped: Readonly<Record<Facts2RelationName, number>>;
39
+ }
40
+ /** What the post-pass reads from a graph (`JavaGraph` has it). */
41
+ export interface Facts2Graph {
42
+ ids: 'ids@0.1';
43
+ files: readonly StableIdFile[];
44
+ edges: readonly CallEdge[];
45
+ unresolved: readonly UnresolvedCall[];
46
+ references: readonly ReferenceEdge[];
47
+ entries: readonly Pick<TsEntry, 'id' | 'kind' | 'certainty' | 'evidence'>[];
48
+ unresolvedRegistrations: readonly UnresolvedRegistration[];
49
+ typeOnly: readonly string[];
50
+ }
51
+ /** Mark `edge` as the declaring row of its polymorphic site (for `call.declaring`). */
52
+ export declare function markDeclaringEdge(edge: CallEdge): void;
53
+ /**
54
+ * The `facts@2` relations of a `java-graph@0.1` graph. Every file the graph
55
+ * holds must be in `inputs`; an input the graph does not hold is written as a
56
+ * Java file with no declarations.
57
+ */
58
+ export declare function javaGraphFact2Set(graph: JavaGraph, inputs: readonly Facts2Input[]): Fact2Set;
59
+ //# sourceMappingURL=facts2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts2.d.ts","sourceRoot":"","sources":["../../src/facts/facts2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAgB,aAAa,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAG7I,OAAO,EAAqC,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG9F,OAAO,EAAmE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACxH,OAAO,EAAwF,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAClI,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEnF,uIAAuI;AACvI,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC;AAEzC,mGAAmG;AACnG,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC,CAAC;IAC3D,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAC;CACjE;AAED,kEAAkE;AAClE,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IAC/B,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC3B,UAAU,EAAE,SAAS,cAAc,EAAE,CAAC;IACtC,UAAU,EAAE,SAAS,aAAa,EAAE,CAAC;IACrC,OAAO,EAAE,SAAS,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,EAAE,CAAC;IAC5E,uBAAuB,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC3D,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAgBD,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,CAEtD;AAuTD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,QAAQ,CAE5F"}
@@ -0,0 +1,362 @@
1
+ /**
2
+ * `facts@2` rows from a call graph: a post-pass over the graph the engine
3
+ * already builds (`java-graph@0.1`), the counterpart of `javaGraphFactSet` for the `facts@2`
4
+ * schema. Opt-in: `facts@1` stays the default (`JavaGraphOptions.factsScheme`).
5
+ *
6
+ * Against the `facts@1` post-pass:
7
+ * - every relation that names a file carries the stable file key
8
+ * (`fileKey(path)`), never a dense index;
9
+ * - a site (`call`, `unresolved`, `ref`, `registration`) carries `rel_line` =
10
+ * its line minus the start line of the declaration whose body holds it, and
11
+ * its column, and no file (the file is that declaration's file);
12
+ * - `decl` has no position (`decl_pos` holds it) and gains `name`,
13
+ * `parent_id`, `type_only`, the two `ids@0.1` flags, `contained` (the
14
+ * reach walk's `contains` rule, `containedIn`) and `loads_parent` (the
15
+ * graph's member-initializes-its-class `loads`);
16
+ * - `call.declaring` marks the polymorphic row whose callee is the member the
17
+ * receiver's static type declares;
18
+ * - `ref` (references), `registration` (unresolved registrations),
19
+ * `files.partial` and `parse_error` (the first blocking parse error, its
20
+ * column 0-based) are new.
21
+ *
22
+ * The `#n` re-key of a declaration id two files derive is the `facts@1` one,
23
+ * and it rewrites `parent_id` and every site's declaration as it rewrites
24
+ * `caller_id`. Built as columns, then each relation goes through
25
+ * `canonicalTable` (sorted, duplicates dropped and counted).
26
+ */
27
+ import { containedIn } from '../graph-facts/reach.js';
28
+ import { digest128 } from '../stable-ids/hash.js';
29
+ import { NodeIdWriter, declLocator, locateNodes } from '../stable-ids/nodes.js';
30
+ import { STABLE_ID_SCHEME } from '../stable-ids/types.js';
31
+ import { compareCodePoints } from './order.js';
32
+ import { FACTS_ID_WIDTH } from './schema.js';
33
+ import { FACTS2_RELATION_NAMES, FACTS2_RELATIONS, FACTS2_SCHEME, fileKey } from './schema2.js';
34
+ import { IdDecoder, allocTable, canonicalTable, dictIndex, keyCollisions } from './table.js';
35
+ import { contentHash, factsEntryKind } from './java-facts.js';
36
+ /**
37
+ * Polymorphic call edges that are the declaring row of their site. The Java
38
+ * graph sets `via` on the other rows only, so `buildJavaGraph` marks the
39
+ * declaring one here. A mark, not a field, so the graph's JSON is unchanged.
40
+ */
41
+ const declaringEdges = new WeakSet();
42
+ /** Mark `edge` as the declaring row of its polymorphic site (for `call.declaring`). */
43
+ export function markDeclaringEdge(edge) {
44
+ declaringEdges.add(edge);
45
+ }
46
+ function isDeclaring(e) {
47
+ return e.tier === 'polymorphic' && declaringEdges.has(e);
48
+ }
49
+ function dict(relation, column) {
50
+ return dictIndex(relation.columns.find(c => c.name === column));
51
+ }
52
+ function code(d, value, column) {
53
+ const k = d.get(value);
54
+ if (k === undefined)
55
+ throw new Error(`${FACTS2_SCHEME}: ${JSON.stringify(value)} is not in the ${column} vocabulary`);
56
+ return k;
57
+ }
58
+ /**
59
+ * The twelve `facts@2` relations of a graph, each a canonical set, with the
60
+ * dedupe counts. `inputs` must cover every file of the graph (a file the
61
+ * graph names but the inputs do not is an error, never a silent gap).
62
+ */
63
+ function graphFact2Set(graph, inputs, extras) {
64
+ if (graph.ids !== STABLE_ID_SCHEME)
65
+ throw new Error(`${FACTS2_SCHEME}: graph ids are ${String(graph.ids)}, not ${STABLE_ID_SCHEME}`);
66
+ const R = FACTS2_RELATIONS;
67
+ const ids = new IdDecoder();
68
+ const paths = [...new Set(inputs.map(i => i.path))].sort(compareCodePoints);
69
+ const byPath = new Map(inputs.map(i => [i.path, i]));
70
+ const graphFiles = new Map(graph.files.map(f => [f.file, f]));
71
+ for (const f of graph.files)
72
+ if (!byPath.has(f.file))
73
+ throw new Error(`${FACTS2_SCHEME}: ${f.file} is in the graph but not in the inputs`);
74
+ const keys = new Map(paths.map(p => [p, fileKey(p)]));
75
+ const orderedFiles = paths.map(p => graphFiles.get(p)).filter((f) => f !== undefined);
76
+ // Each file's declarations by their engine id, for parents, start lines and site owners.
77
+ const declsOf = new Map(orderedFiles.map(f => [f.file, new Map(f.decls.map(d => [d.id, d]))]));
78
+ const declIn = (file, id) => {
79
+ const d = declsOf.get(file)?.get(id);
80
+ if (!d)
81
+ throw new Error(`${FACTS2_SCHEME}: declaration ${id} is not in ${file}`);
82
+ return d;
83
+ };
84
+ // files
85
+ const files = allocTable(R.files, paths.length);
86
+ let partialCount = 0;
87
+ {
88
+ const languages = dict(R.files, 'language');
89
+ for (let i = 0; i < paths.length; i++) {
90
+ const p = paths[i];
91
+ const g = graphFiles.get(p);
92
+ const language = g?.language ?? extras.language;
93
+ if (language === undefined)
94
+ throw new Error(`${FACTS2_SCHEME}: ${p} is in the inputs but not in the graph`);
95
+ files[0].set(keys.get(p), i * FACTS_ID_WIDTH);
96
+ files[1][i] = p;
97
+ files[2].set(contentHash(byPath.get(p).code), i * FACTS_ID_WIDTH);
98
+ files[3][i] = code(languages, language, 'language');
99
+ if (g?.partial) {
100
+ files[4][i] = 1;
101
+ partialCount++;
102
+ }
103
+ }
104
+ }
105
+ // parse_error — one row per partial file.
106
+ const parseError = allocTable(R.parse_error, partialCount);
107
+ {
108
+ let i = 0;
109
+ for (const f of orderedFiles) {
110
+ if (!f.partial)
111
+ continue;
112
+ const e = f.parseError;
113
+ if (!e)
114
+ throw new Error(`${FACTS2_SCHEME}: ${f.file} is partial but has no parse error`);
115
+ parseError[0].set(keys.get(f.file), i * FACTS_ID_WIDTH);
116
+ parseError[1][i] = e.line;
117
+ // The engine's parse-error column is 1-based; every column in facts@2 is 0-based.
118
+ parseError[2][i] = Math.max(0, e.column - 1);
119
+ parseError[3][i] = e.nodeKind;
120
+ parseError[4][i] = e.parent;
121
+ i++;
122
+ }
123
+ }
124
+ // decl and decl_pos — in file order (code point), the order the duplicate rule counts in.
125
+ const declCount = orderedFiles.reduce((n, f) => n + f.decls.length, 0);
126
+ const decl = allocTable(R.decl, declCount);
127
+ const declPos = allocTable(R.decl_pos, declCount);
128
+ const rekey = new Map();
129
+ const rekeyed = (file, id) => (rekey.size > 0 ? rekey.get(file)?.get(id)?.id ?? id : id);
130
+ {
131
+ const kinds = dict(R.decl, 'kind');
132
+ const typeOnly = new Set(graph.typeOnly);
133
+ const loads = new Set((extras.loads ?? []).map(l => `${l.from}\n${l.to}`));
134
+ const seen = new Map();
135
+ let i = 0;
136
+ for (const f of orderedFiles) {
137
+ const file = keys.get(f.file);
138
+ const byId = declsOf.get(f.file);
139
+ const module = f.decls[0];
140
+ for (const d of f.decls) {
141
+ let id = d.id;
142
+ let qualifiedName = d.qualified_name;
143
+ const n = (seen.get(d.id) ?? 0) + 1;
144
+ seen.set(d.id, n);
145
+ if (n > 1) {
146
+ qualifiedName = `${d.qualified_name}#${n}`;
147
+ id = digest128([STABLE_ID_SCHEME, f.language, d.kind, qualifiedName, d.signature]);
148
+ let m = rekey.get(f.file);
149
+ if (!m)
150
+ rekey.set(f.file, (m = new Map()));
151
+ m.set(d.id, { id, qualifiedName });
152
+ }
153
+ const o = i * FACTS_ID_WIDTH;
154
+ const parent = d.parent === null ? undefined : byId.get(d.parent);
155
+ ids.put(id, decl[0], o);
156
+ decl[1][i] = code(kinds, d.kind, 'kind');
157
+ decl[2][i] = d.name;
158
+ decl[3][i] = qualifiedName;
159
+ decl[4][i] = d.signature;
160
+ decl[5].set(file, o);
161
+ // No nulls in facts@2: all-zero bytes for a module's parent and for a missing body hash (the arrays start zeroed).
162
+ if (d.parent !== null)
163
+ ids.put(rekeyed(f.file, d.parent), decl[6], o);
164
+ if (d.body_hash)
165
+ ids.put(d.body_hash, decl[7], o);
166
+ decl[8][i] = typeOnly.has(d.id) ? 1 : 0;
167
+ decl[9][i] = d.flags.includes('unstable:anonymous') ? 1 : 0;
168
+ decl[10][i] = d.flags.includes('unstable:duplicate') || n > 1 ? 1 : 0;
169
+ decl[11][i] = d !== module && parent !== undefined && containedIn(d, parent, module, f.language) ? 1 : 0;
170
+ decl[12][i] = d.parent !== null && loads.has(`${d.id}\n${d.parent}`) ? 1 : 0;
171
+ ids.put(id, declPos[0], o);
172
+ declPos[1][i] = d.start_line;
173
+ declPos[2][i] = d.end_line;
174
+ declPos[3][i] = d.start_column;
175
+ declPos[4][i] = d.end_column;
176
+ i++;
177
+ }
178
+ }
179
+ }
180
+ /** The site's line relative to the start line of `owner`, the declaration (in the site's file) whose body holds it. */
181
+ const relLine = (site, owner) => {
182
+ const start = declIn(site.file, owner).start_line;
183
+ const rel = site.line - start;
184
+ if (rel < 0)
185
+ throw new Error(`${FACTS2_SCHEME}: a site at ${site.file}:${site.line} lies above its declaration's start line ${start}`);
186
+ return rel;
187
+ };
188
+ // call
189
+ const call = allocTable(R.call, graph.edges.length);
190
+ {
191
+ const tiers = dict(R.call, 'tier');
192
+ for (let i = 0; i < graph.edges.length; i++) {
193
+ const e = graph.edges[i];
194
+ ids.put(rekeyed(e.site.file, e.from), call[0], i * FACTS_ID_WIDTH);
195
+ ids.put(e.to, call[1], i * FACTS_ID_WIDTH);
196
+ call[2][i] = code(tiers, e.tier, 'tier');
197
+ call[3][i] = e.methodName;
198
+ call[4][i] = relLine(e.site, e.from);
199
+ call[5][i] = e.site.col;
200
+ call[6][i] = isDeclaring(e) ? 1 : 0;
201
+ }
202
+ }
203
+ // unresolved
204
+ const unresolved = allocTable(R.unresolved, graph.unresolved.length);
205
+ {
206
+ const reasons = dict(R.unresolved, 'reason');
207
+ for (let i = 0; i < graph.unresolved.length; i++) {
208
+ const u = graph.unresolved[i];
209
+ ids.put(rekeyed(u.site.file, u.from), unresolved[0], i * FACTS_ID_WIDTH);
210
+ unresolved[1][i] = code(reasons, u.reason, 'reason');
211
+ // No nulls in facts@2: the empty string when the receiver is unknown.
212
+ unresolved[2][i] = u.receiver ?? '';
213
+ unresolved[3][i] = u.methodName;
214
+ unresolved[4][i] = relLine(u.site, u.from);
215
+ unresolved[5][i] = u.site.col;
216
+ }
217
+ }
218
+ // ref
219
+ const ref = allocTable(R.ref, graph.references.length);
220
+ for (let i = 0; i < graph.references.length; i++) {
221
+ const r = graph.references[i];
222
+ ids.put(rekeyed(r.site.file, r.from), ref[0], i * FACTS_ID_WIDTH);
223
+ ids.put(r.to, ref[1], i * FACTS_ID_WIDTH);
224
+ ref[2][i] = relLine(r.site, r.from);
225
+ ref[3][i] = r.site.col;
226
+ }
227
+ // registration — `from` as the engine gives it (Java), else the innermost declaration enclosing the site.
228
+ const registration = allocTable(R.registration, graph.unresolvedRegistrations.length);
229
+ {
230
+ const reasons = dict(R.registration, 'reason');
231
+ const locators = new Map();
232
+ const owner = (site) => {
233
+ const f = graphFiles.get(site.file);
234
+ if (!f)
235
+ throw new Error(`${FACTS2_SCHEME}: a registration in ${site.file}, which is not in the graph`);
236
+ let at = locators.get(site.file);
237
+ if (!at)
238
+ locators.set(site.file, (at = declLocator(f)));
239
+ return (at(site.line, site.col) ?? f.decls[0]).id;
240
+ };
241
+ for (let i = 0; i < graph.unresolvedRegistrations.length; i++) {
242
+ const reg = graph.unresolvedRegistrations[i];
243
+ const from = reg.from ?? owner(reg.site);
244
+ ids.put(rekeyed(reg.site.file, from), registration[0], i * FACTS_ID_WIDTH);
245
+ registration[1][i] = code(reasons, reg.reason, 'reason');
246
+ registration[2][i] = reg.evidence;
247
+ registration[3][i] = relLine(reg.site, from);
248
+ registration[4][i] = reg.site.col;
249
+ }
250
+ }
251
+ // flow — def-use edges on fixed-width node ids, as in facts@1.
252
+ const flowCapacity = orderedFiles.reduce((n, f) => n + (byPath.get(f.file).dfg?.uses.length ?? 0), 0);
253
+ const flow = allocTable(R.flow, flowCapacity);
254
+ let flowCount = 0;
255
+ if (flowCapacity > 0) {
256
+ const defUse = code(dict(R.flow, 'kind'), 'def-use', 'kind');
257
+ const writer = new NodeIdWriter();
258
+ const from = flow[0];
259
+ const to = flow[1];
260
+ const kinds = flow[2];
261
+ for (const f of orderedFiles) {
262
+ const dfg = byPath.get(f.file).dfg;
263
+ if (!dfg || dfg.uses.length === 0)
264
+ continue;
265
+ const fileRekey = rekey.get(f.file);
266
+ const bodyId = (d) => {
267
+ const r = fileRekey?.get(d.id);
268
+ return r ? `${r.id}.${d.body_hash}` : d.body_id;
269
+ };
270
+ const defs = locateNodes(f, dfg.defs, (d, at) => at(d.line, d.column));
271
+ const defIds = new Uint8Array(defs.length * FACTS_ID_WIDTH);
272
+ const defAt = new Map();
273
+ for (let i = 0; i < defs.length; i++) {
274
+ const n = defs[i];
275
+ if (n === null)
276
+ continue;
277
+ writer.forBody(bodyId(n.decl), 'def');
278
+ writer.write(n.ordinal, defIds, i * FACTS_ID_WIDTH);
279
+ defAt.set(dfg.defs[i].id, i * FACTS_ID_WIDTH);
280
+ }
281
+ const uses = locateNodes(f, dfg.uses, (u, at) => at(u.line, u.column));
282
+ for (let i = 0; i < uses.length; i++) {
283
+ const n = uses[i];
284
+ const u = dfg.uses[i];
285
+ if (n === null || u.def_id === null)
286
+ continue;
287
+ const d = defAt.get(u.def_id);
288
+ if (d === undefined)
289
+ continue;
290
+ const o = flowCount * FACTS_ID_WIDTH;
291
+ for (let k = 0; k < FACTS_ID_WIDTH; k++)
292
+ from[o + k] = defIds[d + k];
293
+ writer.forBody(bodyId(n.decl), 'use');
294
+ writer.write(n.ordinal, to, o);
295
+ kinds[flowCount] = defUse;
296
+ flowCount++;
297
+ }
298
+ }
299
+ }
300
+ // imports
301
+ const importCount = paths.reduce((n, p) => n + byPath.get(p).imports.length, 0);
302
+ const imports = allocTable(R.imports, importCount);
303
+ {
304
+ let i = 0;
305
+ for (const p of paths) {
306
+ const file = keys.get(p);
307
+ for (const imp of byPath.get(p).imports) {
308
+ imports[0].set(file, i * FACTS_ID_WIDTH);
309
+ imports[1][i] = imp.target;
310
+ imports[2][i] = imp.wildcard ? 1 : 0;
311
+ i++;
312
+ }
313
+ }
314
+ }
315
+ // entries
316
+ const entries = allocTable(R.entries, graph.entries.length);
317
+ {
318
+ const kinds = dict(R.entries, 'kind');
319
+ const certainties = dict(R.entries, 'certainty');
320
+ for (let i = 0; i < graph.entries.length; i++) {
321
+ const e = graph.entries[i];
322
+ ids.put(e.id, entries[0], i * FACTS_ID_WIDTH);
323
+ entries[1][i] = code(kinds, factsEntryKind(e.kind), 'kind');
324
+ entries[2][i] = e.evidence;
325
+ entries[3][i] = code(certainties, e.certainty, 'certainty');
326
+ }
327
+ }
328
+ const raw = {
329
+ files: { columns: files, length: paths.length },
330
+ decl: { columns: decl, length: declCount },
331
+ decl_pos: { columns: declPos, length: declCount },
332
+ call: { columns: call, length: graph.edges.length },
333
+ unresolved: { columns: unresolved, length: graph.unresolved.length },
334
+ ref: { columns: ref, length: graph.references.length },
335
+ registration: { columns: registration, length: graph.unresolvedRegistrations.length },
336
+ parse_error: { columns: parseError, length: partialCount },
337
+ flow: { columns: flow, length: flowCount },
338
+ imports: { columns: imports, length: importCount },
339
+ entries: { columns: entries, length: graph.entries.length },
340
+ moved: { columns: allocTable(R.moved, 0), length: 0 },
341
+ };
342
+ const relations = {};
343
+ const duplicatesDropped = {};
344
+ for (const name of FACTS2_RELATION_NAMES) {
345
+ const { table, duplicatesDropped: dropped } = canonicalTable(R[name], raw[name].columns, raw[name].length);
346
+ relations[name] = table;
347
+ duplicatesDropped[name] = dropped;
348
+ }
349
+ // Two paths with one key (a 128-bit collision) must fail, never merge.
350
+ if (keyCollisions(R.files, relations.files) > 0)
351
+ throw new Error(`${FACTS2_SCHEME}: two paths share a file key`);
352
+ return { relations, duplicatesDropped };
353
+ }
354
+ /**
355
+ * The `facts@2` relations of a `java-graph@0.1` graph. Every file the graph
356
+ * holds must be in `inputs`; an input the graph does not hold is written as a
357
+ * Java file with no declarations.
358
+ */
359
+ export function javaGraphFact2Set(graph, inputs) {
360
+ return graphFact2Set(graph, inputs, { loads: graph.loads, language: 'java' });
361
+ }
362
+ //# sourceMappingURL=facts2.js.map