@geastack/compiler 1.0.36 → 1.0.38

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 (544) hide show
  1. package/dist/cli-emit.js +5 -0
  2. package/dist/cli.js +10 -0
  3. package/dist/compiler.d.ts +10 -3
  4. package/dist/compiler.js +364 -224
  5. package/dist/conversion/build.d.ts +13 -1
  6. package/dist/conversion/build.js +336 -141
  7. package/dist/conversion/graph-validation.d.ts +7 -2
  8. package/dist/conversion/graph-validation.js +36 -22
  9. package/dist/conversion/native-sum.js +106 -17
  10. package/dist/diagnostics/sweep.js +1 -1
  11. package/dist/ir/callable-class-flow.d.ts +0 -11
  12. package/dist/ir/callable-class-flow.js +970 -169
  13. package/dist/ir/certificate.d.ts +1 -1
  14. package/dist/ir/certificate.js +12 -1
  15. package/dist/ir/certify/carrier-keys.d.ts +17 -1
  16. package/dist/ir/certify/carrier-keys.js +35 -2
  17. package/dist/ir/certify/function-source.js +2 -1
  18. package/dist/ir/certify/has-property-key.d.ts +6 -0
  19. package/dist/ir/certify/has-property-key.js +8 -1
  20. package/dist/ir/certify/property-access-keys.js +2 -1
  21. package/dist/ir/certify/runtime-helper.js +2 -1
  22. package/dist/ir/construction-only-fields.d.ts +35 -2
  23. package/dist/ir/construction-only-fields.js +100 -0
  24. package/dist/ir/emission-representations.d.ts +2 -2
  25. package/dist/ir/emission-representations.js +9 -3
  26. package/dist/ir/generic-call-entry.d.ts +3 -1
  27. package/dist/ir/logical-receivers.js +29 -1
  28. package/dist/ir/lower-completion.js +11 -6
  29. package/dist/ir/lower-destructuring.js +3 -2
  30. package/dist/ir/native-host-method-reads.d.ts +5 -0
  31. package/dist/ir/native-host-method-reads.js +30 -21
  32. package/dist/ir/operation-conversions.js +4 -1
  33. package/dist/ir/publish-conversion-recipes.js +12 -1
  34. package/dist/plugins/apple/jsx.js +1 -1
  35. package/dist/plugins/gea/component-classes.js +1 -1
  36. package/dist/plugins/gea/component-inline.js +1 -1
  37. package/dist/plugins/gea/contract.d.ts +1 -1
  38. package/dist/plugins/gea/contract.js +1 -1
  39. package/dist/plugins/gea/host.js +27 -1
  40. package/dist/plugins/gea/lower.js +8 -1
  41. package/dist/plugins/gea/producer.js +1 -1
  42. package/dist/plugins/gea/reactive-slots.d.ts +1 -1
  43. package/dist/plugins/gea/reactive-slots.js +1 -1
  44. package/dist/plugins/load.js +51 -22
  45. package/dist/preflight/run.d.ts +12 -1
  46. package/dist/preflight/run.js +65 -29
  47. package/dist/projection/native-callable-data.js +2 -1
  48. package/dist/representation/plan.js +102 -4
  49. package/dist/semantics/alias-this-field-declaration-transform.js +1 -1
  50. package/dist/semantics/ambient-type-realization-transform.js +1 -1
  51. package/dist/semantics/ambient.d.ts +1 -1
  52. package/dist/semantics/ambient.js +1 -1
  53. package/dist/semantics/borrowed-builtin-call-bind-source-transform.js +1 -1
  54. package/dist/semantics/borrowed-method-receiver-copy-source-transform.js +1 -1
  55. package/dist/semantics/call-invalidated-narrowing.d.ts +1 -1
  56. package/dist/semantics/call-invalidated-narrowing.js +4 -2
  57. package/dist/semantics/callable-own-data-slots.d.ts +6 -0
  58. package/dist/semantics/callable-own-data-slots.js +177 -101
  59. package/dist/semantics/class-alias.d.ts +1 -1
  60. package/dist/semantics/class-alias.js +1 -1
  61. package/dist/semantics/class-heritage.d.ts +1 -1
  62. package/dist/semantics/class-heritage.js +1 -1
  63. package/dist/semantics/commonjs-wrapper.d.ts +4 -3
  64. package/dist/semantics/commonjs-wrapper.js +50 -7
  65. package/dist/semantics/constructor-function-class-source-transform.js +1 -1
  66. package/dist/semantics/constructor-slot-subclasses.d.ts +1 -1
  67. package/dist/semantics/constructor-slot-subclasses.js +1 -1
  68. package/dist/semantics/declaration-overlay-transform.js +3 -2
  69. package/dist/semantics/declared-integers.d.ts +1 -1
  70. package/dist/semantics/declared-integers.js +1 -1
  71. package/dist/semantics/define-property-source-transform.js +1 -1
  72. package/dist/semantics/diagnostic-source-preparation.d.ts +1 -1
  73. package/dist/semantics/documentation-ranges.d.ts +1 -1
  74. package/dist/semantics/documentation-ranges.js +1 -1
  75. package/dist/semantics/dynamic-fallback.d.ts +1 -1
  76. package/dist/semantics/dynamic-fallback.js +1 -1
  77. package/dist/semantics/frontend-timing.js +19 -0
  78. package/dist/semantics/frontend.d.ts +2 -2
  79. package/dist/semantics/frontend.js +127 -54
  80. package/dist/semantics/host-declaration-provenance.d.ts +1 -1
  81. package/dist/semantics/host-methods.d.ts +1 -1
  82. package/dist/semantics/host-methods.js +1 -1
  83. package/dist/semantics/host-protocols.d.ts +1 -1
  84. package/dist/semantics/host-protocols.js +1 -1
  85. package/dist/semantics/inherited-accessor.d.ts +1 -1
  86. package/dist/semantics/inherited-accessor.js +1 -1
  87. package/dist/semantics/interface-families.d.ts +1 -1
  88. package/dist/semantics/interface-families.js +1 -1
  89. package/dist/semantics/interface-implementors.d.ts +1 -1
  90. package/dist/semantics/interface-implementors.js +1 -1
  91. package/dist/semantics/jsdoc-namepath-transform.js +1 -1
  92. package/dist/semantics/jsx-runtime-provider.d.ts +1 -1
  93. package/dist/semantics/jsx-runtime-provider.js +1 -1
  94. package/dist/semantics/known-caller-predicate-parameters.d.ts +1 -1
  95. package/dist/semantics/known-caller-predicate-parameters.js +1 -1
  96. package/dist/semantics/model/edges.d.ts +124 -0
  97. package/dist/semantics/model/edges.js +192 -0
  98. package/dist/semantics/model/graph.d.ts +26 -2
  99. package/dist/semantics/model/graph.js +54 -0
  100. package/dist/semantics/model/sealed-facts.d.ts +19 -0
  101. package/dist/semantics/model/sealed-facts.js +221 -0
  102. package/dist/semantics/model/selected-signature.d.ts +1 -1
  103. package/dist/semantics/model/selected-signature.js +1 -1
  104. package/dist/semantics/module-resolution.d.ts +1 -1
  105. package/dist/semantics/module-resolution.js +1 -1
  106. package/dist/semantics/native-function-signatures.d.ts +1 -1
  107. package/dist/semantics/native-function-signatures.js +1 -1
  108. package/dist/semantics/native-object-data-slots.js +20 -4
  109. package/dist/semantics/new-callee-class-tag-source-transform.js +1 -1
  110. package/dist/semantics/node-project.d.ts +1 -1
  111. package/dist/semantics/node-project.js +1 -1
  112. package/dist/semantics/node-source-hooks.js +1 -1
  113. package/dist/semantics/normalize/absent-globals.d.ts +1 -1
  114. package/dist/semantics/normalize/absent-globals.js +1 -1
  115. package/dist/semantics/normalize/any-cast-member-call.d.ts +1 -1
  116. package/dist/semantics/normalize/any-cast-member-call.js +1 -1
  117. package/dist/semantics/normalize/arguments-objects.d.ts +1 -1
  118. package/dist/semantics/normalize/arguments-objects.js +1 -1
  119. package/dist/semantics/normalize/asserted-argument-arms.d.ts +1 -1
  120. package/dist/semantics/normalize/asserted-argument-arms.js +1 -1
  121. package/dist/semantics/normalize/asserted-arm-absence.d.ts +1 -1
  122. package/dist/semantics/normalize/asserted-arm-absence.js +1 -1
  123. package/dist/semantics/normalize/assignment-patterns.d.ts +1 -1
  124. package/dist/semantics/normalize/assignment-patterns.js +1 -1
  125. package/dist/semantics/normalize/bag-absence.d.ts +1 -1
  126. package/dist/semantics/normalize/bag-absence.js +1 -1
  127. package/dist/semantics/normalize/binding-fixpoint.js +9 -2
  128. package/dist/semantics/normalize/bivariant-slot-parameter.d.ts +1 -1
  129. package/dist/semantics/normalize/bivariant-slot-parameter.js +1 -1
  130. package/dist/semantics/normalize/callable-data-write.d.ts +1 -1
  131. package/dist/semantics/normalize/callable-data-write.js +1 -1
  132. package/dist/semantics/normalize/callback-parameter-contracts.d.ts +1 -1
  133. package/dist/semantics/normalize/callback-parameter-contracts.js +1 -1
  134. package/dist/semantics/normalize/cells/agreement.d.ts +18 -1
  135. package/dist/semantics/normalize/cells/agreement.js +8 -0
  136. package/dist/semantics/normalize/cells/candidates.d.ts +1 -1
  137. package/dist/semantics/normalize/cells/candidates.js +1 -1
  138. package/dist/semantics/normalize/cells/facts.d.ts +1 -1
  139. package/dist/semantics/normalize/cells/facts.js +1 -1
  140. package/dist/semantics/normalize/cells/index.d.ts +2 -2
  141. package/dist/semantics/normalize/cells/index.js +1 -1
  142. package/dist/semantics/normalize/cells/model.d.ts +1 -1
  143. package/dist/semantics/normalize/cells/policies/bag.d.ts +1 -1
  144. package/dist/semantics/normalize/cells/policies/collection.d.ts +1 -1
  145. package/dist/semantics/normalize/cells/policies/collection.js +1 -1
  146. package/dist/semantics/normalize/cells/policies/field.d.ts +1 -1
  147. package/dist/semantics/normalize/cells/policies/field.js +1 -1
  148. package/dist/semantics/normalize/cells/policies/index.d.ts +1 -1
  149. package/dist/semantics/normalize/cells/policies/local.d.ts +1 -1
  150. package/dist/semantics/normalize/cells/policies/local.js +1 -1
  151. package/dist/semantics/normalize/cells/policies/parameter.d.ts +1 -1
  152. package/dist/semantics/normalize/cells/policies/parameter.js +1 -1
  153. package/dist/semantics/normalize/cells/policies/return.d.ts +1 -1
  154. package/dist/semantics/normalize/cells/policies/return.js +1 -1
  155. package/dist/semantics/normalize/cells/policies/shared.d.ts +1 -1
  156. package/dist/semantics/normalize/cells/policy.d.ts +1 -1
  157. package/dist/semantics/normalize/census.d.ts +1 -1
  158. package/dist/semantics/normalize/census.js +45 -12
  159. package/dist/semantics/normalize/class-instance-record-statement.d.ts +1 -1
  160. package/dist/semantics/normalize/class-instance-record-statement.js +1 -1
  161. package/dist/semantics/normalize/collection-bindings.d.ts +1 -1
  162. package/dist/semantics/normalize/collection-bindings.js +1 -1
  163. package/dist/semantics/normalize/commonjs-module-record.d.ts +1 -1
  164. package/dist/semantics/normalize/commonjs-module-record.js +1 -1
  165. package/dist/semantics/normalize/commonjs-require.d.ts +1 -1
  166. package/dist/semantics/normalize/commonjs-require.js +1 -1
  167. package/dist/semantics/normalize/contribution.d.ts +4 -3
  168. package/dist/semantics/normalize/contribution.js +145 -42
  169. package/dist/semantics/normalize/dead-event-emissions.d.ts +1 -1
  170. package/dist/semantics/normalize/dead-event-emissions.js +1 -1
  171. package/dist/semantics/normalize/dead-method-copies.d.ts +1 -1
  172. package/dist/semantics/normalize/dead-method-copies.js +1 -1
  173. package/dist/semantics/normalize/dead-typeof-guards.d.ts +1 -1
  174. package/dist/semantics/normalize/dead-typeof-guards.js +1 -1
  175. package/dist/semantics/normalize/deferred-intrinsic-protocols.d.ts +1 -1
  176. package/dist/semantics/normalize/deferred-intrinsic-protocols.js +1 -1
  177. package/dist/semantics/normalize/derived-expression-type.d.ts +1 -1
  178. package/dist/semantics/normalize/derived-expression-type.js +4 -4
  179. package/dist/semantics/normalize/evaluation-order.d.ts +1 -1
  180. package/dist/semantics/normalize/evaluation-order.js +1 -1
  181. package/dist/semantics/normalize/field-bindings.d.ts +1 -1
  182. package/dist/semantics/normalize/field-bindings.js +4 -3
  183. package/dist/semantics/normalize/flow/array-element-continuation.d.ts +1 -1
  184. package/dist/semantics/normalize/flow/array-element-continuation.js +3 -3
  185. package/dist/semantics/normalize/flow/callable-array-origins.d.ts +1 -1
  186. package/dist/semantics/normalize/flow/callable-array-origins.js +1 -1
  187. package/dist/semantics/normalize/flow/callable-completions.d.ts +1 -1
  188. package/dist/semantics/normalize/flow/callable-completions.js +1 -1
  189. package/dist/semantics/normalize/flow/callable-reach.d.ts +1 -1
  190. package/dist/semantics/normalize/flow/callable-reach.js +73 -52
  191. package/dist/semantics/normalize/flow/class-family-member-read.d.ts +1 -1
  192. package/dist/semantics/normalize/flow/class-family-member-read.js +3 -3
  193. package/dist/semantics/normalize/flow/collection-value-continuation.d.ts +1 -1
  194. package/dist/semantics/normalize/flow/collection-value-continuation.js +1 -1
  195. package/dist/semantics/normalize/flow/component-solver.d.ts +181 -3
  196. package/dist/semantics/normalize/flow/component-solver.js +705 -164
  197. package/dist/semantics/normalize/flow/computed-key-set.d.ts +1 -1
  198. package/dist/semantics/normalize/flow/computed-key-set.js +1 -1
  199. package/dist/semantics/normalize/flow/export-importers.d.ts +1 -1
  200. package/dist/semantics/normalize/flow/export-importers.js +13 -3
  201. package/dist/semantics/normalize/flow/host-text-sink.d.ts +1 -1
  202. package/dist/semantics/normalize/flow/host-text-sink.js +1 -1
  203. package/dist/semantics/normalize/flow/intrinsic-array-callback-frames.d.ts +1 -1
  204. package/dist/semantics/normalize/flow/intrinsic-array-callback-frames.js +1 -1
  205. package/dist/semantics/normalize/flow/intrinsic-data-definition.d.ts +1 -1
  206. package/dist/semantics/normalize/flow/intrinsic-data-definition.js +1 -1
  207. package/dist/semantics/normalize/flow/invocation-facts.d.ts +1 -1
  208. package/dist/semantics/normalize/flow/invocation-facts.js +1 -1
  209. package/dist/semantics/normalize/flow/member-call-forwarding.d.ts +1 -1
  210. package/dist/semantics/normalize/flow/member-call-forwarding.js +1 -1
  211. package/dist/semantics/normalize/flow/model.d.ts +1 -1
  212. package/dist/semantics/normalize/flow/model.js +5 -1
  213. package/dist/semantics/normalize/flow/native-collection-protocol.d.ts +1 -1
  214. package/dist/semantics/normalize/flow/native-collection-protocol.js +1 -1
  215. package/dist/semantics/normalize/flow/node-path-token.d.ts +1 -1
  216. package/dist/semantics/normalize/flow/object-binding-continuation.d.ts +1 -1
  217. package/dist/semantics/normalize/flow/object-binding-continuation.js +1 -1
  218. package/dist/semantics/normalize/flow/origin-authority.d.ts +1 -1
  219. package/dist/semantics/normalize/flow/owned-class-receivers.d.ts +1 -1
  220. package/dist/semantics/normalize/flow/owned-class-receivers.js +1 -1
  221. package/dist/semantics/normalize/flow/parameter-values.d.ts +1 -1
  222. package/dist/semantics/normalize/flow/parameter-values.js +1 -1
  223. package/dist/semantics/normalize/flow/record-alias-closure.d.ts +1 -1
  224. package/dist/semantics/normalize/flow/record-alias-closure.js +1 -1
  225. package/dist/semantics/normalize/flow/seeded-origins.d.ts +1 -1
  226. package/dist/semantics/normalize/flow/seeded-origins.js +1 -1
  227. package/dist/semantics/normalize/flow/source-accessor-descriptor.d.ts +1 -1
  228. package/dist/semantics/normalize/flow/source-accessor-descriptor.js +1 -1
  229. package/dist/semantics/normalize/flow/source-callable-own-data.d.ts +1 -1
  230. package/dist/semantics/normalize/flow/source-callable-own-data.js +1 -1
  231. package/dist/semantics/normalize/flow/source-callable-readonly-set.d.ts +1 -1
  232. package/dist/semantics/normalize/flow/source-callable-readonly-set.js +1 -1
  233. package/dist/semantics/normalize/flow/source-class-data.d.ts +1 -1
  234. package/dist/semantics/normalize/flow/source-class-data.js +1 -1
  235. package/dist/semantics/normalize/flow/source-class-instanceof.d.ts +1 -1
  236. package/dist/semantics/normalize/flow/source-class-instanceof.js +1 -1
  237. package/dist/semantics/normalize/flow/source-class-static-data.d.ts +1 -1
  238. package/dist/semantics/normalize/flow/source-class-static-data.js +1 -1
  239. package/dist/semantics/normalize/flow/source-commonjs-exports.d.ts +1 -1
  240. package/dist/semantics/normalize/flow/source-construction-frames.d.ts +1 -1
  241. package/dist/semantics/normalize/flow/source-construction-frames.js +1 -1
  242. package/dist/semantics/normalize/flow/source-descriptor-protocol.d.ts +1 -1
  243. package/dist/semantics/normalize/flow/source-descriptor-protocol.js +1 -1
  244. package/dist/semantics/normalize/flow/source-executing-parameter-values.d.ts +1 -1
  245. package/dist/semantics/normalize/flow/source-executing-parameter-values.js +1 -1
  246. package/dist/semantics/normalize/flow/source-global-binding.d.ts +1 -1
  247. package/dist/semantics/normalize/flow/source-global-binding.js +1 -1
  248. package/dist/semantics/normalize/flow/source-intrinsic-member-data.d.ts +1 -1
  249. package/dist/semantics/normalize/flow/source-intrinsic-member-data.js +1 -1
  250. package/dist/semantics/normalize/flow/source-invocation-frame-layout.d.ts +1 -1
  251. package/dist/semantics/normalize/flow/source-invocation-frame-layout.js +24 -32
  252. package/dist/semantics/normalize/flow/source-invocation-receiver.d.ts +1 -1
  253. package/dist/semantics/normalize/flow/source-invocation-receiver.js +1 -1
  254. package/dist/semantics/normalize/flow/source-native-class-alias.d.ts +1 -1
  255. package/dist/semantics/normalize/flow/source-native-class-alias.js +1 -1
  256. package/dist/semantics/normalize/flow/source-native-iterable-integrity.d.ts +1 -1
  257. package/dist/semantics/normalize/flow/source-native-iterable-integrity.js +1 -1
  258. package/dist/semantics/normalize/flow/source-native-origin.d.ts +1 -1
  259. package/dist/semantics/normalize/flow/source-native-origin.js +1 -1
  260. package/dist/semantics/normalize/flow/source-normal-predecessor.d.ts +1 -1
  261. package/dist/semantics/normalize/flow/source-normal-predecessor.js +1 -1
  262. package/dist/semantics/normalize/flow/source-property-key.d.ts +1 -1
  263. package/dist/semantics/normalize/flow/source-property-key.js +1 -1
  264. package/dist/semantics/normalize/flow/source-prototype-method-identity.d.ts +1 -1
  265. package/dist/semantics/normalize/flow/source-prototype-method-identity.js +1 -1
  266. package/dist/semantics/normalize/flow/source-proxy-operation.d.ts +1 -1
  267. package/dist/semantics/normalize/flow/source-proxy-operation.js +1 -1
  268. package/dist/semantics/normalize/flow/source-raw-constructor-entry.d.ts +1 -1
  269. package/dist/semantics/normalize/flow/source-raw-constructor-entry.js +1 -1
  270. package/dist/semantics/normalize/flow/source-read-protocol.d.ts +1 -1
  271. package/dist/semantics/normalize/flow/source-read-protocol.js +1 -1
  272. package/dist/semantics/normalize/flow/source-record-data.d.ts +1 -1
  273. package/dist/semantics/normalize/flow/source-record-data.js +1 -1
  274. package/dist/semantics/normalize/flow/source-value-session.d.ts +33 -3
  275. package/dist/semantics/normalize/flow/source-value-session.js +381 -173
  276. package/dist/semantics/normalize/flow/standard-prototype-method-source.d.ts +1 -1
  277. package/dist/semantics/normalize/flow/standard-prototype-method-source.js +1 -1
  278. package/dist/semantics/normalize/flow/targets.d.ts +1 -1
  279. package/dist/semantics/normalize/flow/targets.js +1 -1
  280. package/dist/semantics/normalize/flow/value-flow.d.ts +1 -1
  281. package/dist/semantics/normalize/flow/value-flow.js +243 -52
  282. package/dist/semantics/normalize/flow/value-provenance.d.ts +1 -1
  283. package/dist/semantics/normalize/flow/value-provenance.js +1 -1
  284. package/dist/semantics/normalize/fresh-dictionary-storage.d.ts +1 -1
  285. package/dist/semantics/normalize/fresh-dictionary-storage.js +1 -1
  286. package/dist/semantics/normalize/fresh-ordinary-object.d.ts +1 -1
  287. package/dist/semantics/normalize/fresh-ordinary-object.js +1 -1
  288. package/dist/semantics/normalize/fresh-table-last-use.d.ts +1 -1
  289. package/dist/semantics/normalize/fresh-table-last-use.js +1 -1
  290. package/dist/semantics/normalize/gating.d.ts +3 -3
  291. package/dist/semantics/normalize/gating.js +17 -20
  292. package/dist/semantics/normalize/generic-function-choice.d.ts +1 -1
  293. package/dist/semantics/normalize/generic-function-choice.js +1 -1
  294. package/dist/semantics/normalize/global-host-mutations.d.ts +1 -1
  295. package/dist/semantics/normalize/global-host-mutations.js +420 -138
  296. package/dist/semantics/normalize/host-effect-contracts.d.ts +1 -1
  297. package/dist/semantics/normalize/host-effect-contracts.js +1 -1
  298. package/dist/semantics/normalize/host-mutation-computed-keys.d.ts +1 -1
  299. package/dist/semantics/normalize/host-mutation-key-reader.d.ts +1 -1
  300. package/dist/semantics/normalize/host-mutation-key-reader.js +1 -1
  301. package/dist/semantics/normalize/identities.d.ts +41 -1
  302. package/dist/semantics/normalize/identities.js +75 -9
  303. package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +1 -1
  304. package/dist/semantics/normalize/implicit-arguments-tuple.js +1 -1
  305. package/dist/semantics/normalize/implicit-arguments.d.ts +1 -1
  306. package/dist/semantics/normalize/implicit-arguments.js +1 -1
  307. package/dist/semantics/normalize/installed-global-properties.d.ts +1 -1
  308. package/dist/semantics/normalize/installed-global-properties.js +1 -1
  309. package/dist/semantics/normalize/instantiation.d.ts +1 -1
  310. package/dist/semantics/normalize/instantiation.js +1 -1
  311. package/dist/semantics/normalize/intrinsic-accessor-getter.d.ts +1 -1
  312. package/dist/semantics/normalize/intrinsic-accessor-getter.js +1 -1
  313. package/dist/semantics/normalize/intrinsic-property-call.d.ts +1 -1
  314. package/dist/semantics/normalize/intrinsic-property-call.js +1 -1
  315. package/dist/semantics/normalize/intrinsic-prototype.d.ts +1 -1
  316. package/dist/semantics/normalize/intrinsic-prototype.js +1 -1
  317. package/dist/semantics/normalize/intrinsic-return-identity.d.ts +1 -1
  318. package/dist/semantics/normalize/intrinsic-return-identity.js +1 -1
  319. package/dist/semantics/normalize/intrinsic-static-member.d.ts +1 -1
  320. package/dist/semantics/normalize/jsdoc-type-names.d.ts +1 -1
  321. package/dist/semantics/normalize/jsdoc-type-names.js +1 -1
  322. package/dist/semantics/normalize/local-bindings.d.ts +1 -1
  323. package/dist/semantics/normalize/local-bindings.js +3 -2
  324. package/dist/semantics/normalize/logical-object-truthiness.d.ts +1 -1
  325. package/dist/semantics/normalize/logical-object-truthiness.js +1 -1
  326. package/dist/semantics/normalize/logical-result-type.d.ts +1 -1
  327. package/dist/semantics/normalize/logical-result-type.js +1 -1
  328. package/dist/semantics/normalize/merged-declaration.d.ts +1 -1
  329. package/dist/semantics/normalize/merged-declaration.js +1 -1
  330. package/dist/semantics/normalize/namespace-paths.d.ts +1 -1
  331. package/dist/semantics/normalize/namespace-paths.js +1 -1
  332. package/dist/semantics/normalize/never-override-result.d.ts +1 -1
  333. package/dist/semantics/normalize/never-override-result.js +1 -1
  334. package/dist/semantics/normalize/normalize.d.ts +23 -4
  335. package/dist/semantics/normalize/normalize.js +125 -15
  336. package/dist/semantics/normalize/null-blind-parameter.d.ts +1 -1
  337. package/dist/semantics/normalize/null-blind-parameter.js +1 -1
  338. package/dist/semantics/normalize/nullable-memo.d.ts +28 -0
  339. package/dist/semantics/normalize/nullable-memo.js +99 -0
  340. package/dist/semantics/normalize/object-bag-bindings.d.ts +1 -1
  341. package/dist/semantics/normalize/object-bag-bindings.js +15 -4
  342. package/dist/semantics/normalize/omitted-stated-parameter.d.ts +1 -1
  343. package/dist/semantics/normalize/omitted-stated-parameter.js +1 -1
  344. package/dist/semantics/normalize/open-type-form.d.ts +1 -1
  345. package/dist/semantics/normalize/open-type-form.js +1 -1
  346. package/dist/semantics/normalize/override-field-arms.d.ts +1 -1
  347. package/dist/semantics/normalize/override-field-arms.js +1 -1
  348. package/dist/semantics/normalize/parameter-bindings.d.ts +1 -52
  349. package/dist/semantics/normalize/parameter-bindings.js +105 -10
  350. package/dist/semantics/normalize/parameter-slot.d.ts +1 -1
  351. package/dist/semantics/normalize/parameter-slot.js +1 -1
  352. package/dist/semantics/normalize/physical-overload-result.d.ts +1 -1
  353. package/dist/semantics/normalize/physical-overload-result.js +1 -1
  354. package/dist/semantics/normalize/primitive-property-absence.d.ts +1 -1
  355. package/dist/semantics/normalize/producer-context.d.ts +1 -1
  356. package/dist/semantics/normalize/producers/allocations.d.ts +1 -1
  357. package/dist/semantics/normalize/producers/allocations.js +1 -1
  358. package/dist/semantics/normalize/producers/binding-kind.d.ts +1 -1
  359. package/dist/semantics/normalize/producers/binding-kind.js +1 -1
  360. package/dist/semantics/normalize/producers/bindings.d.ts +1 -1
  361. package/dist/semantics/normalize/producers/bindings.js +1 -1
  362. package/dist/semantics/normalize/producers/boundary.d.ts +1 -1
  363. package/dist/semantics/normalize/producers/boundary.js +1 -1
  364. package/dist/semantics/normalize/producers/cited-value-type.d.ts +1 -1
  365. package/dist/semantics/normalize/producers/cited-value-type.js +1 -1
  366. package/dist/semantics/normalize/producers/class-lifecycle.js +1 -1
  367. package/dist/semantics/normalize/producers/computations.js +1 -1
  368. package/dist/semantics/normalize/producers/conditional-guard.d.ts +1 -1
  369. package/dist/semantics/normalize/producers/control-loops.d.ts +1 -1
  370. package/dist/semantics/normalize/producers/control-loops.js +1 -1
  371. package/dist/semantics/normalize/producers/control.d.ts +1 -1
  372. package/dist/semantics/normalize/producers/control.js +1 -1
  373. package/dist/semantics/normalize/producers/declaration-lifecycle.js +1 -1
  374. package/dist/semantics/normalize/producers/destructuring.d.ts +1 -1
  375. package/dist/semantics/normalize/producers/destructuring.js +1 -1
  376. package/dist/semantics/normalize/producers/dynamic-language.js +1 -1
  377. package/dist/semantics/normalize/producers/enums.d.ts +1 -1
  378. package/dist/semantics/normalize/producers/enums.js +1 -1
  379. package/dist/semantics/normalize/producers/erasure.d.ts +1 -1
  380. package/dist/semantics/normalize/producers/erasure.js +1 -1
  381. package/dist/semantics/normalize/producers/exact-arms.d.ts +1 -1
  382. package/dist/semantics/normalize/producers/exact-arms.js +1 -1
  383. package/dist/semantics/normalize/producers/intrinsic-accessor-getter.d.ts +1 -1
  384. package/dist/semantics/normalize/producers/invocations.d.ts +1 -1
  385. package/dist/semantics/normalize/producers/invocations.js +1 -1
  386. package/dist/semantics/normalize/producers/iteration-yield.d.ts +1 -1
  387. package/dist/semantics/normalize/producers/iteration-yield.js +1 -1
  388. package/dist/semantics/normalize/producers/jsx.js +1 -1
  389. package/dist/semantics/normalize/producers/logical-merge-type.d.ts +1 -1
  390. package/dist/semantics/normalize/producers/logical-merge-type.js +1 -1
  391. package/dist/semantics/normalize/producers/mint.js +88 -5
  392. package/dist/semantics/normalize/producers/native-callable-readonly-set.d.ts +1 -1
  393. package/dist/semantics/normalize/producers/native-own-assignment.d.ts +1 -1
  394. package/dist/semantics/normalize/producers/native-own-assignment.js +1 -1
  395. package/dist/semantics/normalize/producers/nullish.d.ts +1 -1
  396. package/dist/semantics/normalize/producers/nullish.js +1 -1
  397. package/dist/semantics/normalize/producers/object-assignment.d.ts +1 -1
  398. package/dist/semantics/normalize/producers/object-assignment.js +1 -1
  399. package/dist/semantics/normalize/producers/object-tag.d.ts +1 -1
  400. package/dist/semantics/normalize/producers/object-tag.js +1 -1
  401. package/dist/semantics/normalize/producers/optional-chain.d.ts +1 -1
  402. package/dist/semantics/normalize/producers/optional-chain.js +1 -1
  403. package/dist/semantics/normalize/producers/properties.d.ts +1 -1
  404. package/dist/semantics/normalize/producers/properties.js +1 -1
  405. package/dist/semantics/normalize/producers/protocol.d.ts +1 -1
  406. package/dist/semantics/normalize/producers/protocol.js +1 -1
  407. package/dist/semantics/normalize/producers/references.d.ts +1 -1
  408. package/dist/semantics/normalize/producers/references.js +1 -1
  409. package/dist/semantics/normalize/producers/shared.d.ts +1 -1
  410. package/dist/semantics/normalize/producers/shared.js +1 -1
  411. package/dist/semantics/normalize/producers/spread-arguments.d.ts +1 -1
  412. package/dist/semantics/normalize/producers/spread-arguments.js +1 -1
  413. package/dist/semantics/normalize/producers/tagged-template.d.ts +1 -1
  414. package/dist/semantics/normalize/producers/tagged-template.js +1 -1
  415. package/dist/semantics/normalize/producers/tuple-spread.d.ts +1 -1
  416. package/dist/semantics/normalize/producers/tuple-spread.js +1 -1
  417. package/dist/semantics/normalize/property-key-domain.d.ts +8 -1
  418. package/dist/semantics/normalize/property-key-domain.js +74 -47
  419. package/dist/semantics/normalize/reachability.d.ts +1 -1
  420. package/dist/semantics/normalize/reachability.js +3 -2
  421. package/dist/semantics/normalize/reassigned-bindings.d.ts +1 -1
  422. package/dist/semantics/normalize/record-home-arms.d.ts +1 -1
  423. package/dist/semantics/normalize/record-home-arms.js +1 -1
  424. package/dist/semantics/normalize/record-link-families.d.ts +1 -1
  425. package/dist/semantics/normalize/record-link-families.js +1 -1
  426. package/dist/semantics/normalize/record-stand-in-arms.d.ts +1 -1
  427. package/dist/semantics/normalize/record-stand-in-arms.js +1 -1
  428. package/dist/semantics/normalize/record-storage-families.d.ts +1 -1
  429. package/dist/semantics/normalize/record-storage-families.js +1 -1
  430. package/dist/semantics/normalize/return-bindings.d.ts +1 -1
  431. package/dist/semantics/normalize/return-bindings.js +1 -1
  432. package/dist/semantics/normalize/return-paths.d.ts +1 -1
  433. package/dist/semantics/normalize/return-paths.js +1 -1
  434. package/dist/semantics/normalize/round-tables.d.ts +21 -0
  435. package/dist/semantics/normalize/round-tables.js +59 -0
  436. package/dist/semantics/normalize/script-global-redefinition.d.ts +1 -1
  437. package/dist/semantics/normalize/script-global-redefinition.js +1 -1
  438. package/dist/semantics/normalize/shared-array-storage.d.ts +1 -1
  439. package/dist/semantics/normalize/shared-array-storage.js +1 -1
  440. package/dist/semantics/normalize/sloppy-absence.d.ts +1 -1
  441. package/dist/semantics/normalize/sloppy-absence.js +1 -1
  442. package/dist/semantics/normalize/source-native-iterable.d.ts +2 -2
  443. package/dist/semantics/normalize/source-native-iterable.js +4 -2
  444. package/dist/semantics/normalize/source-object-prototype-absence.d.ts +1 -1
  445. package/dist/semantics/normalize/source-object-prototype-absence.js +1 -1
  446. package/dist/semantics/normalize/specialization.d.ts +1 -1
  447. package/dist/semantics/normalize/specialization.js +1 -1
  448. package/dist/semantics/normalize/specialized-source-frames.d.ts +1 -1
  449. package/dist/semantics/normalize/specialized-source-frames.js +12 -4
  450. package/dist/semantics/normalize/structural-any-binding-consumer.d.ts +1 -1
  451. package/dist/semantics/normalize/structural-any-binding-consumer.js +1 -1
  452. package/dist/semantics/normalize/structural-array-element.d.ts +1 -1
  453. package/dist/semantics/normalize/structural-array-element.js +1 -1
  454. package/dist/semantics/normalize/structural-array-read.d.ts +1 -1
  455. package/dist/semantics/normalize/structural-array-read.js +1 -1
  456. package/dist/semantics/normalize/structural-callable.d.ts +1 -1
  457. package/dist/semantics/normalize/structural-callable.js +1 -1
  458. package/dist/semantics/normalize/structural-creation-order.d.ts +1 -1
  459. package/dist/semantics/normalize/structural-creation-order.js +1 -1
  460. package/dist/semantics/normalize/structural-declarations.d.ts +1 -1
  461. package/dist/semantics/normalize/structural-declarations.js +1 -1
  462. package/dist/semantics/normalize/structural-declared-body.d.ts +1 -1
  463. package/dist/semantics/normalize/structural-declared-body.js +1 -1
  464. package/dist/semantics/normalize/structural-generics.d.ts +1 -1
  465. package/dist/semantics/normalize/structural-generics.js +1 -1
  466. package/dist/semantics/normalize/structural-indexed-access.d.ts +1 -1
  467. package/dist/semantics/normalize/structural-indexed-access.js +1 -1
  468. package/dist/semantics/normalize/structural-instantiated-member.d.ts +1 -1
  469. package/dist/semantics/normalize/structural-instantiated-member.js +199 -68
  470. package/dist/semantics/normalize/structural-joins.d.ts +1 -1
  471. package/dist/semantics/normalize/structural-layout-relevance.d.ts +1 -1
  472. package/dist/semantics/normalize/structural-layout-relevance.js +1 -1
  473. package/dist/semantics/normalize/structural-layout-type.d.ts +1 -1
  474. package/dist/semantics/normalize/structural-layout-type.js +14 -2
  475. package/dist/semantics/normalize/structural-leaves.d.ts +1 -1
  476. package/dist/semantics/normalize/structural-leaves.js +1 -1
  477. package/dist/semantics/normalize/structural-local-union.d.ts +1 -1
  478. package/dist/semantics/normalize/structural-local-union.js +21 -16
  479. package/dist/semantics/normalize/structural-members.d.ts +1 -1
  480. package/dist/semantics/normalize/structural-members.js +1 -1
  481. package/dist/semantics/normalize/structural-mutable-field.d.ts +1 -2
  482. package/dist/semantics/normalize/structural-mutable-field.js +17 -4
  483. package/dist/semantics/normalize/structural-mutable-method.d.ts +1 -1
  484. package/dist/semantics/normalize/structural-mutable-method.js +1 -1
  485. package/dist/semantics/normalize/structural-parts.d.ts +1 -1
  486. package/dist/semantics/normalize/structural-parts.js +1 -1
  487. package/dist/semantics/normalize/structural-receiver.d.ts +1 -1
  488. package/dist/semantics/normalize/structural-receiver.js +1 -1
  489. package/dist/semantics/normalize/structural-rules.d.ts +4 -4
  490. package/dist/semantics/normalize/structural-rules.js +30 -12
  491. package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
  492. package/dist/semantics/normalize/structural-self-reference.js +1 -1
  493. package/dist/semantics/normalize/structural.d.ts +1 -1
  494. package/dist/semantics/normalize/structural.js +2467 -2239
  495. package/dist/semantics/normalize/suppressed-write-arms.d.ts +1 -1
  496. package/dist/semantics/normalize/suppressed-write-arms.js +1 -1
  497. package/dist/semantics/normalize/symbol-keyed-this-slots.d.ts +1 -1
  498. package/dist/semantics/normalize/symbol-keyed-this-slots.js +1 -1
  499. package/dist/semantics/normalize/unreduced-type-form.d.ts +1 -1
  500. package/dist/semantics/normalize/unreduced-type-form.js +1 -1
  501. package/dist/semantics/normalize/unresolvable-names.d.ts +1 -1
  502. package/dist/semantics/normalize/unresolvable-names.js +1 -1
  503. package/dist/semantics/normalize/unshared-array-result.d.ts +1 -1
  504. package/dist/semantics/normalize/unshared-array-result.js +1 -1
  505. package/dist/semantics/package-sources.d.ts +1 -1
  506. package/dist/semantics/package-sources.js +1 -1
  507. package/dist/semantics/program.d.ts +1 -1
  508. package/dist/semantics/program.js +11 -5
  509. package/dist/semantics/prototype-install-source-transform.js +1 -1
  510. package/dist/semantics/prototype-object-class-source-transform.js +1 -1
  511. package/dist/semantics/prototype-reparenting.d.ts +1 -1
  512. package/dist/semantics/prototype-reparenting.js +1 -1
  513. package/dist/semantics/shared-declaration-files.d.ts +1 -1
  514. package/dist/semantics/source-transform-exports.js +1 -1
  515. package/dist/semantics/stable-checker.d.ts +9 -1
  516. package/dist/semantics/stable-checker.js +21 -5
  517. package/dist/semantics/subclass-member-overlay-transform.js +46 -5
  518. package/dist/semantics/symbol-keyed-expando-source-transform.js +1 -1
  519. package/dist/semantics/this-constructor-source-transform.js +1 -1
  520. package/dist/semantics/typescript.d.ts +12 -0
  521. package/dist/semantics/typescript.js +12 -0
  522. package/dist/semantics/uncached-jsdoc-tags.d.ts +16 -0
  523. package/dist/semantics/uncached-jsdoc-tags.js +23 -0
  524. package/dist/semantics/unchecked-guard-argument-copies.d.ts +1 -1
  525. package/dist/semantics/unchecked-guard-argument-copies.js +1 -1
  526. package/dist/semantics/unchecked-write-member-declarations.d.ts +1 -1
  527. package/dist/semantics/unchecked-write-member-declarations.js +1 -1
  528. package/dist/semantics/uninstantiable-classes.d.ts +1 -1
  529. package/dist/semantics/uninstantiable-classes.js +1 -1
  530. package/dist/targets/cpp/conversions.js +137 -87
  531. package/dist/targets/cpp/emit-bindings.js +13 -0
  532. package/dist/targets/cpp/emit-context.d.ts +13 -0
  533. package/dist/targets/cpp/emit-context.js +9 -0
  534. package/dist/targets/cpp/emit-in.js +2 -1
  535. package/dist/targets/cpp/emit-iterator.d.ts +6 -5
  536. package/dist/targets/cpp/emit-iterator.js +23 -13
  537. package/dist/targets/cpp/emit-narrowing.d.ts +8 -0
  538. package/dist/targets/cpp/emit-narrowing.js +11 -1
  539. package/dist/targets/cpp/emit-properties.js +9 -0
  540. package/dist/targets/cpp/emit-record-view.d.ts +9 -0
  541. package/dist/targets/cpp/emit-record-view.js +12 -1
  542. package/dist/targets/cpp/emit.js +14 -2
  543. package/package.json +7 -1
  544. package/src/targets/cpp/runtime/gea_runtime.h +10 -2
@@ -1,3 +1,13 @@
1
+ const NO_GROUNDING_KEYS = [];
2
+ const groundingKeysOf = (node) => {
3
+ const keys = node.groundingKeys;
4
+ if (keys === undefined)
5
+ return NO_GROUNDING_KEYS;
6
+ // Fail closed: keys with no domain to carry are a malformed node, not an empty one.
7
+ if (node.groundingDomain === undefined)
8
+ throw new Error('grounding keys need a grounding domain');
9
+ return Array.isArray(keys) ? keys : [keys];
10
+ };
1
11
  /**
2
12
  * Solve a lazily discovered dependency graph. `all-dependencies` admits a
3
13
  * recursive component when every member has complete local facts and every
@@ -6,31 +16,68 @@
6
16
  * a cycle and propagates witnesses over explicitly labelled dependency edges.
7
17
  * An acyclic unseeded node remains a complete, vacuous answer.
8
18
  */
9
- export const dependencyComponentSolver = (expand, mode) => invalidatableComponentSolver(expand, mode).solve;
19
+ export const dependencyComponentSolver = (expand, mode) => {
20
+ const expanded = new Map();
21
+ return componentEngine({
22
+ slotOf: (key) => {
23
+ let slot = expanded.get(key);
24
+ if (slot === undefined)
25
+ expanded.set(key, (slot = {
26
+ node: expand(key),
27
+ componentRead: false,
28
+ componentAnswer: null,
29
+ groundedInNoDomain: false,
30
+ groundedInFirstDomain: UNSETTLED
31
+ }));
32
+ return slot;
33
+ },
34
+ existingSlotOf: (key) => expanded.get(key),
35
+ localOf: (slot) => slot.node,
36
+ dependenciesOf: (slot) => slot.node.dependencies
37
+ }, mode).solve;
38
+ };
39
+ const componentAnswers = {
40
+ completeGrounded: Object.freeze({ status: 'complete', grounded: true }),
41
+ complete: Object.freeze({ status: 'complete', grounded: false }),
42
+ refusedGrounded: Object.freeze({ status: 'refused', grounded: true }),
43
+ refused: Object.freeze({ status: 'refused', grounded: false })
44
+ };
45
+ const componentAnswer = (complete, grounded) => complete
46
+ ? grounded
47
+ ? componentAnswers.completeGrounded
48
+ : componentAnswers.complete
49
+ : grounded
50
+ ? componentAnswers.refusedGrounded
51
+ : componentAnswers.refused;
52
+ const UNSETTLED = 0;
53
+ const GROUNDED = 1;
54
+ const UNGROUNDED = 2;
10
55
  /**
11
56
  * The same solver, plus eviction for a graph that keeps growing underneath it.
12
57
  * `invalidate` forgets every cached answer that could have read a changed
13
58
  * node: the changed nodes themselves and everything that reaches them over
14
- * required edges. A node nothing cached ever expanded cannot have contributed
59
+ * required edges. A node nothing cached ever read cannot have contributed
15
60
  * to a cached answer, so the walk stops there. Every other answer is a pure
16
61
  * function of nodes that did not change, and stays.
17
62
  */
18
- const invalidatableComponentSolver = (expand, mode) => {
19
- const nodes = new Map();
20
- // No `groundedDomains` here. It is a pure function of the expanded graph
21
- // (`groundingDomainsFrom`, memoized by key), never of how components closed,
22
- // so storing it per node only meant computing it for every node of every
23
- // component -- the whole value-origin subgraph walked ~115,000 times on
24
- // a large program -- when the only places it can change an answer are a cyclic
25
- // component's requirement check and the published result of a node someone
26
- // actually asks about.
27
- const results = new Map();
28
- const componentOf = new Map();
63
+ const componentEngine = (graph, mode) => {
64
+ // No `groundedDomains` in an answer. It is a pure function of the graph
65
+ // (`groundingDomainsFrom`, memoized per node), never of how components
66
+ // closed, so storing it per node only meant computing it for every node of
67
+ // every component -- the whole value-origin subgraph walked ~115,000 times
68
+ // on a large program -- when the only places it can change an answer are a
69
+ // cyclic component's requirement check and the published result of a node
70
+ // someone actually asks about.
71
+ const { existingSlotOf, localOf, dependenciesOf } = graph;
72
+ // `groundingDomainsFrom`'s memo: a bit of the node for the empty answer and
73
+ // this table for any other. A field per node holding the set was ~1.8 MB on
74
+ // a 48K-line app's source-value solve (~224K nodes), and a table holding
75
+ // every answer was as large again, since ~45K of them are the empty one.
76
+ const domainsByRoot = new Map();
29
77
  const nodeOf = (key) => {
30
- let node = nodes.get(key);
31
- if (node === undefined) {
32
- node = expand(key);
33
- nodes.set(key, node);
78
+ const slot = graph.slotOf(key);
79
+ if (!slot.componentRead) {
80
+ slot.componentRead = true;
34
81
  // Checked here, once per node, rather than inside the grounding walk.
35
82
  // There it was `dependencies.includes(...)` per grounding edge, so a node
36
83
  // carrying g grounding edges over d required ones paid g*d comparisons --
@@ -38,15 +85,20 @@ const invalidatableComponentSolver = (expand, mode) => {
38
85
  // the node's own dependencies answers all g in O(d + g), and moving the
39
86
  // check to expansion makes it cover EVERY node the solver sees instead of
40
87
  // only the ones some grounding walk happened to reach.
41
- const grounding = node.groundingDependencies;
42
- if (grounding !== undefined && grounding.length > 0) {
43
- const declared = new Set(node.dependencies);
44
- for (const edge of grounding)
88
+ const local = localOf(slot);
89
+ const grounding = local.groundingDependencies;
90
+ const keyed = groundingKeysOf(local);
91
+ if ((grounding !== undefined && grounding.length > 0) || keyed.length > 0) {
92
+ const declared = new Set(dependenciesOf(slot));
93
+ for (const edge of grounding ?? [])
45
94
  if (!declared.has(edge.dependency))
46
95
  throw new Error('grounding dependency must also be a closure dependency');
96
+ for (const dependency of keyed)
97
+ if (!declared.has(dependency))
98
+ throw new Error('grounding dependency must also be a closure dependency');
47
99
  }
48
100
  }
49
- return node;
101
+ return slot;
50
102
  };
51
103
  /**
52
104
  * Grounding walks only the domain-labelled subgraph, never all closure edges.
@@ -70,8 +122,24 @@ const invalidatableComponentSolver = (expand, mode) => {
70
122
  * admitted here unconditionally, before any edge is walked.
71
123
  */
72
124
  const NO_DOMAINS = new Set();
125
+ // A node's published grounding is kept for the life of its answer and is
126
+ // nearly always one domain (this compiler has one): one shared set per
127
+ // domain, not one per grounded node.
128
+ const singleDomains = new Map();
129
+ const onlyDomain = (domain) => {
130
+ let set = singleDomains.get(domain);
131
+ if (set === undefined)
132
+ singleDomains.set(domain, (set = new Set([domain])));
133
+ return set;
134
+ };
73
135
  const NO_MEMBERS = [];
74
- const groundingCache = new Map();
136
+ /**
137
+ * Only the components `explain` has something to say about -- an unseeded
138
+ * cycle or an unmet grounding domain -- which is nearly none of them:
139
+ * `explain` reads a component for those two facts alone, so a members list
140
+ * kept for every component was ~190K arrays for nothing.
141
+ */
142
+ const explained = new Map();
75
143
  /**
76
144
  * Whether a node reaches a witness of `domain` over edges labelled with
77
145
  * `domain`, for every node any walk has settled. A node's own seed counts.
@@ -92,11 +160,29 @@ const invalidatableComponentSolver = (expand, mode) => {
92
160
  * (checked in `nodeOf`), so a node whose answer could have read a changed
93
161
  * node is one of the required dependents `invalidate` already evicts.
94
162
  */
163
+ let firstDomain;
95
164
  const groundedIn = new Map();
165
+ // A settled node is one a walk visited, so it has a slot (`nodeOf`).
166
+ const settledIn = (domain) => {
167
+ firstDomain ??= domain;
168
+ if (domain === firstDomain)
169
+ return {
170
+ get: (key) => {
171
+ const code = existingSlotOf(key)?.groundedInFirstDomain ?? UNSETTLED;
172
+ return code === UNSETTLED ? undefined : code === GROUNDED;
173
+ },
174
+ set: (key, grounded) => {
175
+ existingSlotOf(key).groundedInFirstDomain = grounded ? GROUNDED : UNGROUNDED;
176
+ }
177
+ };
178
+ let table = groundedIn.get(domain);
179
+ if (table === undefined)
180
+ groundedIn.set(domain, (table = new Map()));
181
+ const settled = table;
182
+ return { get: (key) => settled.get(key), set: (key, grounded) => void settled.set(key, grounded) };
183
+ };
96
184
  const groundedFor = (domain, start) => {
97
- let settled = groundedIn.get(domain);
98
- if (settled === undefined)
99
- groundedIn.set(domain, (settled = new Map()));
185
+ const settled = settledIn(domain);
100
186
  const known = settled.get(start);
101
187
  if (known !== undefined)
102
188
  return known;
@@ -105,33 +191,40 @@ const invalidatableComponentSolver = (expand, mode) => {
105
191
  const inRegion = new Set(region);
106
192
  const predecessors = new Map();
107
193
  const witnesses = [];
194
+ // One grounding edge of `key` in this domain: true when it reaches a settled witness, which ends `key`'s edges.
195
+ const follow = (key, dependency) => {
196
+ const answer = settled.get(dependency);
197
+ if (answer === true) {
198
+ witnesses.push(key);
199
+ return true;
200
+ }
201
+ if (answer === false)
202
+ return false;
203
+ let incoming = predecessors.get(dependency);
204
+ if (incoming === undefined)
205
+ predecessors.set(dependency, (incoming = []));
206
+ incoming.push(key);
207
+ if (!inRegion.has(dependency)) {
208
+ inRegion.add(dependency);
209
+ region.push(dependency);
210
+ }
211
+ return false;
212
+ };
108
213
  for (let cursor = 0; cursor < region.length; cursor++) {
109
214
  const key = region[cursor];
110
- const node = nodeOf(key);
111
- if (node.groundingSeeds?.includes(domain)) {
215
+ const local = localOf(nodeOf(key));
216
+ if (local.groundingSeeds?.includes(domain)) {
112
217
  witnesses.push(key);
113
218
  continue;
114
219
  }
115
- for (const edge of node.groundingDependencies ?? []) {
116
- if (edge.domain !== domain)
117
- continue;
118
- const dependency = edge.dependency;
119
- const answer = settled.get(dependency);
120
- if (answer === true) {
121
- witnesses.push(key);
220
+ let witnessed = false;
221
+ for (const edge of local.groundingDependencies ?? [])
222
+ if (edge.domain === domain && (witnessed = follow(key, edge.dependency)))
122
223
  break;
123
- }
124
- if (answer === false)
125
- continue;
126
- let incoming = predecessors.get(dependency);
127
- if (incoming === undefined)
128
- predecessors.set(dependency, (incoming = []));
129
- incoming.push(key);
130
- if (!inRegion.has(dependency)) {
131
- inRegion.add(dependency);
132
- region.push(dependency);
133
- }
134
- }
224
+ if (!witnessed && local.groundingDomain === domain)
225
+ for (const dependency of groundingKeysOf(local))
226
+ if (follow(key, dependency))
227
+ break;
135
228
  }
136
229
  // Backward from the witnesses: everything that reaches one is grounded.
137
230
  const grounded = new Set(witnesses);
@@ -146,17 +239,20 @@ const invalidatableComponentSolver = (expand, mode) => {
146
239
  return grounded.has(start);
147
240
  };
148
241
  const groundingDomainsFrom = (root) => {
149
- const known = groundingCache.get(root);
242
+ const rootSlot = nodeOf(root);
243
+ if (rootSlot.groundedInNoDomain)
244
+ return NO_DOMAINS;
245
+ const known = domainsByRoot.get(root);
150
246
  if (known !== undefined)
151
247
  return known;
152
- const rootNode = nodeOf(root);
248
+ const rootNode = localOf(rootSlot);
153
249
  // A node that neither witnesses a domain nor labels an edge with one can
154
250
  // only ever answer the empty set, and that is most of them: `seeded-origin`
155
251
  // clients (`seeded-origins.ts`) never set a grounding field at all, and a
156
252
  // solver is built per query there. Answering without allocating a walk is
157
253
  // what keeps this off that path entirely.
158
- if (!rootNode.groundingSeeds?.length && !rootNode.groundingDependencies?.length) {
159
- groundingCache.set(root, NO_DOMAINS);
254
+ if (!rootNode.groundingSeeds?.length && !rootNode.groundingDependencies?.length && groundingKeysOf(rootNode).length === 0) {
255
+ rootSlot.groundedInNoDomain = true;
160
256
  return NO_DOMAINS;
161
257
  }
162
258
  // The root's own seeds, whatever their domain, and each domain one of its
@@ -165,8 +261,16 @@ const invalidatableComponentSolver = (expand, mode) => {
165
261
  for (const edge of rootNode.groundingDependencies ?? [])
166
262
  if (!found.has(edge.domain) && groundedFor(edge.domain, edge.dependency))
167
263
  found.add(edge.domain);
168
- groundingCache.set(root, found);
169
- return found;
264
+ const keyedDomain = rootNode.groundingDomain;
265
+ for (const dependency of groundingKeysOf(rootNode))
266
+ if (!found.has(keyedDomain) && groundedFor(keyedDomain, dependency))
267
+ found.add(keyedDomain);
268
+ const answer = found.size === 0 ? NO_DOMAINS : found.size === 1 ? onlyDomain(found.values().next().value) : found;
269
+ if (answer === NO_DOMAINS)
270
+ rootSlot.groundedInNoDomain = true;
271
+ else
272
+ domainsByRoot.set(root, answer);
273
+ return answer;
170
274
  };
171
275
  const explainFrom = (root) => {
172
276
  const paths = new Map([[root, [root]]]);
@@ -178,7 +282,8 @@ const invalidatableComponentSolver = (expand, mode) => {
178
282
  const causes = [];
179
283
  for (let cursor = 0; cursor < queue.length; cursor++) {
180
284
  const key = queue[cursor];
181
- const node = nodeOf(key);
285
+ const slot = nodeOf(key);
286
+ const node = localOf(slot);
182
287
  const path = paths.get(key);
183
288
  const reasons = node.causes ?? [];
184
289
  if (!node.locallyComplete && reasons.length === 0 && !emittedIncomplete.has(key)) {
@@ -196,7 +301,7 @@ const invalidatableComponentSolver = (expand, mode) => {
196
301
  causes.push({ kind: 'opaque', root: key, cause, path });
197
302
  }
198
303
  }
199
- const component = componentOf.get(key);
304
+ const component = explained.get(key);
200
305
  if (component?.unseededCycle && !emittedCycles.has(component)) {
201
306
  emittedCycles.add(component);
202
307
  causes.push({ kind: 'unseeded-cycle', members: component.members, path });
@@ -212,7 +317,7 @@ const invalidatableComponentSolver = (expand, mode) => {
212
317
  causes.push({ kind: 'unseeded-cycle', domain, members: component.members, unmet: component.unmet, path });
213
318
  }
214
319
  }
215
- for (const dependency of node.dependencies) {
320
+ for (const dependency of dependenciesOf(slot)) {
216
321
  if (paths.has(dependency))
217
322
  continue;
218
323
  paths.set(dependency, [...path, dependency]);
@@ -224,10 +329,11 @@ const invalidatableComponentSolver = (expand, mode) => {
224
329
  /**
225
330
  * A node's published grounding, computed when someone asks for it rather than
226
331
  * when its component closed. Same function, same memo, same answer: the walk
227
- * reads only `expand`ed nodes, which never change, so when it runs cannot
228
- * change what it returns. In `grounding-domains` mode the legacy aggregate
229
- * flag is the domain set's emptiness, exactly as the component loop used to
230
- * record it; in the other modes it stays the seed witness that loop computes.
332
+ * reads only nodes whose facts cannot change while the memo stands, so when
333
+ * it runs cannot change what it returns. In `grounding-domains` mode the
334
+ * legacy aggregate flag is the domain set's emptiness, exactly as the
335
+ * component loop used to record it; in the other modes it stays the seed
336
+ * witness that loop computes.
231
337
  *
232
338
  * A plain object, not one with accessors. Deferring these two fields behind
233
339
  * getters was tried and cost 4.7% of a whole compile in this one function:
@@ -245,9 +351,10 @@ const invalidatableComponentSolver = (expand, mode) => {
245
351
  explain: () => explainFrom(root)
246
352
  };
247
353
  };
354
+ const answerOf = (key) => existingSlotOf(key)?.componentAnswer ?? null;
248
355
  const solve = (root) => {
249
- const known = results.get(root);
250
- if (known !== undefined)
356
+ const known = answerOf(root);
357
+ if (known !== null)
251
358
  return publish(root, known);
252
359
  const indices = new Map();
253
360
  const low = new Map();
@@ -266,8 +373,8 @@ const invalidatableComponentSolver = (expand, mode) => {
266
373
  let lowest = index;
267
374
  stack.push(key);
268
375
  active.add(key);
269
- for (const dependency of nodeOf(key).dependencies) {
270
- if (results.has(dependency))
376
+ for (const dependency of dependenciesOf(nodeOf(key))) {
377
+ if (answerOf(dependency) !== null)
271
378
  continue;
272
379
  const seen = indices.get(dependency);
273
380
  if (seen === undefined) {
@@ -299,15 +406,16 @@ const invalidatableComponentSolver = (expand, mode) => {
299
406
  const unseededDomains = new Set();
300
407
  const unmet = [];
301
408
  for (const current of members) {
302
- const node = nodeOf(current);
409
+ const slot = nodeOf(current);
410
+ const node = localOf(slot);
303
411
  complete &&= node.locallyComplete;
304
412
  grounded ||= node.seed === true;
305
- for (const dependency of node.dependencies) {
413
+ for (const dependency of dependenciesOf(slot)) {
306
414
  if (memberSet === null ? dependency === key : memberSet.has(dependency)) {
307
415
  cyclic = true;
308
416
  continue;
309
417
  }
310
- const dependencyResult = results.get(dependency);
418
+ const dependencyResult = answerOf(dependency);
311
419
  complete &&= dependencyResult?.status === 'complete';
312
420
  grounded ||= dependencyResult?.grounded === true;
313
421
  }
@@ -322,7 +430,7 @@ const invalidatableComponentSolver = (expand, mode) => {
322
430
  if (mode === 'grounding-domains' && complete && cyclic) {
323
431
  for (const current of members) {
324
432
  const groundedForNode = groundingDomainsFrom(current);
325
- for (const domain of nodeOf(current).groundingRequirements ?? []) {
433
+ for (const domain of localOf(nodeOf(current)).groundingRequirements ?? []) {
326
434
  if (groundedForNode.has(domain))
327
435
  continue;
328
436
  unseededDomains.add(domain);
@@ -332,18 +440,20 @@ const invalidatableComponentSolver = (expand, mode) => {
332
440
  if (unseededDomains.size > 0)
333
441
  complete = false;
334
442
  }
335
- // Kept for `explain`, and empty for nearly every component: the shared
336
- // empties keep a Set and an array per node of a large graph off the heap.
337
- const component = unseededDomains.size === 0
338
- ? { members, unseededCycle, unseededDomains: NO_DOMAINS, unmet: NO_MEMBERS }
339
- : { members, unseededCycle, unseededDomains, unmet };
443
+ const component = unseededDomains.size > 0
444
+ ? { members, unseededCycle, unseededDomains, unmet }
445
+ : unseededCycle
446
+ ? { members, unseededCycle, unseededDomains: NO_DOMAINS, unmet: NO_MEMBERS }
447
+ : null;
448
+ const answer = componentAnswer(complete, grounded);
340
449
  for (const current of members) {
341
- componentOf.set(current, component);
342
- results.set(current, { status: complete ? 'complete' : 'refused', grounded });
450
+ nodeOf(current).componentAnswer = answer;
451
+ if (component !== null)
452
+ explained.set(current, component);
343
453
  }
344
454
  };
345
455
  visit(root);
346
- return publish(root, results.get(root));
456
+ return publish(root, answerOf(root));
347
457
  };
348
458
  const invalidate = (changed, requiredDependentsOf) => {
349
459
  const queue = [...changed];
@@ -353,11 +463,15 @@ const invalidatableComponentSolver = (expand, mode) => {
353
463
  if (seen.has(key))
354
464
  continue;
355
465
  seen.add(key);
356
- if (!nodes.delete(key))
466
+ const slot = existingSlotOf(key);
467
+ if (slot === undefined || !slot.componentRead)
357
468
  continue;
358
- results.delete(key);
359
- componentOf.delete(key);
360
- groundingCache.delete(key);
469
+ slot.componentRead = false;
470
+ slot.componentAnswer = null;
471
+ slot.groundedInNoDomain = false;
472
+ domainsByRoot.delete(key);
473
+ slot.groundedInFirstDomain = UNSETTLED;
474
+ explained.delete(key);
361
475
  for (const settled of groundedIn.values())
362
476
  settled.delete(key);
363
477
  for (const dependent of requiredDependentsOf(key))
@@ -366,6 +480,294 @@ const invalidatableComponentSolver = (expand, mode) => {
366
480
  };
367
481
  return { solve, invalidate };
368
482
  };
483
+ /** Past this many entries an edge collection becomes a hash table: a lookup is a linear scan below it. */
484
+ const SMALL_EDGES = 8;
485
+ const edgeCount = (edges) => edges === null ? 0 : edges instanceof Map || edges instanceof Set ? edges.size : Array.isArray(edges) ? edges.length : 1;
486
+ const NO_EDGE_STATES = [];
487
+ const edgeStates = (edges) => edges === null ? NO_EDGE_STATES : edges instanceof Set || Array.isArray(edges) ? edges : [edges];
488
+ const withDependent = (edges, state) => {
489
+ if (edges === null)
490
+ return state;
491
+ if (edges instanceof Set)
492
+ return edges.add(state);
493
+ const small = Array.isArray(edges) ? edges : [edges];
494
+ return small.length < SMALL_EDGES ? small.concat([state]) : new Set(small).add(state);
495
+ };
496
+ const edgeHas = (edges, state) => edges === null
497
+ ? false
498
+ : edges instanceof Set
499
+ ? edges.has(state)
500
+ : Array.isArray(edges)
501
+ ? edges.includes(state)
502
+ : edges === state;
503
+ /** `withDependent` for a collection that may already hold `state`. */
504
+ const withMember = (edges, state) => edgeHas(edges, state) ? edges : withDependent(edges, state);
505
+ const NO_FACT = Symbol('no fact');
506
+ const NO_FACTS = new Set();
507
+ const INDEXED = 1;
508
+ const COMPONENT_READ = 2;
509
+ /**
510
+ * Every observed edge is required, in the order observed. ~151K of a
511
+ * 48K-line app's ~155K states that require anything require exactly what
512
+ * they observe: a second copy of the edge list, as keys, for each of them.
513
+ */
514
+ const REQUIRES_OBSERVED = 4;
515
+ /**
516
+ * A state's component answer is one of the four shared `componentAnswers` or
517
+ * none, so it is three bits of `flags` rather than a field: a field is 8 bytes
518
+ * on each of a 48K-line app's ~224K states.
519
+ */
520
+ const ANSWER_SHIFT = 3;
521
+ const ANSWER_MASK = 7 << ANSWER_SHIFT;
522
+ const answerCodes = [
523
+ null,
524
+ componentAnswers.completeGrounded,
525
+ componentAnswers.complete,
526
+ componentAnswers.refusedGrounded,
527
+ componentAnswers.refused
528
+ ];
529
+ /**
530
+ * This state's fact collection may also be another state's, so it is copied
531
+ * before it is written. ~23K of a 48K-line app's ~28K multi-fact states hold
532
+ * the same facts, in the same order, as some other state -- 300K of 335K
533
+ * entries -- mostly because a node forwards what it reads.
534
+ */
535
+ const SHARED_FACTS = 64;
536
+ /**
537
+ * The required edges are some other list, kept by the solver beside its
538
+ * states (`explicitRequired`) rather than in a field every state pays for:
539
+ * ~4K states of ~224K.
540
+ */
541
+ const EXPLICIT_REQUIRED = 128;
542
+ /** `groundedInFirstDomain`, two bits of `flags`. */
543
+ const GROUNDED_SHIFT = 8;
544
+ const GROUNDED_MASK = 3 << GROUNDED_SHIFT;
545
+ /** `groundedInNoDomain`. */
546
+ const NO_GROUNDING_DOMAIN = 1 << 10;
547
+ /** A key that is its own state (`keysAreStates`) has been made a node of the solver: `stateOf` has run for it. */
548
+ const MINTED = 1 << 11;
549
+ /** One of the facts a state holds when it holds exactly one, told apart from the collection forms (see `FactState.facts`). */
550
+ const isLoneFact = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) && !(value instanceof Set);
551
+ /**
552
+ * One node of a `dependencyFactSolver`, which is also its own fact set:
553
+ * `read`/`observe` hand the state itself out as the node's live
554
+ * `ReadonlySet`. A consumer may keep that set to compare its size later (the
555
+ * own-key stamps in `source-value-session.ts`), so it has to be one object for
556
+ * the node's life -- and the state already is.
557
+ *
558
+ * The facts are held inline while there is at most one, in a `Set` only from
559
+ * the second. Half the nodes of a 48K-line app's solve hold no fact and a
560
+ * third hold exactly one, and the smallest `Set` is a 152-byte hash table:
561
+ * ~30 MB of tables for ~200K sets of at most one element. Iteration is in
562
+ * insertion order and `has` is SameValueZero, as for a `Set`.
563
+ *
564
+ * A class, so ~224K instances share one shape and one copy of the methods,
565
+ * and so its two booleans can share one field. Abstract over where the key
566
+ * lives: a caller that interns one record per key can make that record the
567
+ * state itself (`keysAreStates`), and a key record and a state per node were
568
+ * two headers and a pointer each way -- ~9 MB on a 48K-line app.
569
+ */
570
+ export class FactState {
571
+ /**
572
+ * Every scheduled edge, holding the dependency's STATE and not just its
573
+ * key. A transfer re-reads the same edges on every re-evaluation, so
574
+ * resolving the key through the global state map each time was a lookup
575
+ * per edge read across the whole solve -- the single largest self-time
576
+ * entry in a large program's profile. The owner already has to touch this
577
+ * collection to know the edge exists; carrying the state in it makes the
578
+ * repeat read free.
579
+ *
580
+ * This and the two edge collections below are null until the first edge
581
+ * that would go in them, a lone state or an exactly sized array while they
582
+ * are small, and a hash table only past `SMALL_EDGES`. A 48K-line app's
583
+ * solve holds ~224K states; three quarters of them have at most one edge
584
+ * of each kind, and a one-entry Map or Set is ~180 bytes of hash table:
585
+ * ~90 MB of tables for edges a field holds in 8. Insertion order, which
586
+ * `propagate`'s wake-ups and `explain`'s paths follow, is the same in
587
+ * every form.
588
+ *
589
+ * Observed edges never become a table: past `SMALL_EDGES` they are an
590
+ * array of this state's own, grown by `push`, and whether an edge exists is
591
+ * asked of the dependency's `dependents` instead (`observedState`). A
592
+ * key-to-state Map was ~1.3 KB a state for the ~4K states that observe
593
+ * more than eight.
594
+ */
595
+ observedDependencies = null;
596
+ /**
597
+ * Dependents, held as states for the same reason `key` is: `propagate`
598
+ * fires an edge by re-enqueuing its owner, and it already holds that
599
+ * owner's state from the moment the edge was recorded.
600
+ */
601
+ dependents = null;
602
+ /** The last seal, which the component solve reads as this node's local facts. */
603
+ sealed = undefined;
604
+ flags = 0;
605
+ /**
606
+ * No fact, one fact held as itself, two to `SMALL_EDGES` facts in an
607
+ * exactly sized array, more in a `Set`: ~22K of a 48K-line app's ~28K
608
+ * multi-fact states hold at most eight, and the smallest `Set` holding two
609
+ * is ~180 bytes of hash table. One field for all four forms rather than one
610
+ * for the lone fact and one for the collection: a lone fact that could be
611
+ * mistaken for a collection (`isLoneFact`) is held as a one-element array.
612
+ */
613
+ facts = NO_FACT;
614
+ /** Seeded: this state's facts are visible to `holdersOf`. */
615
+ get indexed() {
616
+ return (this.flags & INDEXED) !== 0;
617
+ }
618
+ set indexed(value) {
619
+ this.flags = value ? this.flags | INDEXED : this.flags & ~INDEXED;
620
+ }
621
+ get requiresObserved() {
622
+ return (this.flags & REQUIRES_OBSERVED) !== 0;
623
+ }
624
+ set requiresObserved(value) {
625
+ this.flags = value ? this.flags | REQUIRES_OBSERVED : this.flags & ~REQUIRES_OBSERVED;
626
+ }
627
+ get groundedInFirstDomain() {
628
+ return ((this.flags & GROUNDED_MASK) >> GROUNDED_SHIFT);
629
+ }
630
+ set groundedInFirstDomain(value) {
631
+ this.flags = (this.flags & ~GROUNDED_MASK) | (value << GROUNDED_SHIFT);
632
+ }
633
+ get groundedInNoDomain() {
634
+ return (this.flags & NO_GROUNDING_DOMAIN) !== 0;
635
+ }
636
+ set groundedInNoDomain(value) {
637
+ this.flags = value ? this.flags | NO_GROUNDING_DOMAIN : this.flags & ~NO_GROUNDING_DOMAIN;
638
+ }
639
+ get minted() {
640
+ return (this.flags & MINTED) !== 0;
641
+ }
642
+ set minted(value) {
643
+ this.flags = value ? this.flags | MINTED : this.flags & ~MINTED;
644
+ }
645
+ get explicitRequired() {
646
+ return (this.flags & EXPLICIT_REQUIRED) !== 0;
647
+ }
648
+ set explicitRequired(value) {
649
+ this.flags = value ? this.flags | EXPLICIT_REQUIRED : this.flags & ~EXPLICIT_REQUIRED;
650
+ }
651
+ get componentAnswer() {
652
+ return answerCodes[(this.flags & ANSWER_MASK) >> ANSWER_SHIFT];
653
+ }
654
+ set componentAnswer(answer) {
655
+ const code = answerCodes.indexOf(answer);
656
+ // Fail closed: only the shared answers have a code.
657
+ if (code < 0)
658
+ throw new Error('component answer is not one of the shared answers');
659
+ this.flags = (this.flags & ~ANSWER_MASK) | (code << ANSWER_SHIFT);
660
+ }
661
+ get componentRead() {
662
+ return (this.flags & COMPONENT_READ) !== 0;
663
+ }
664
+ set componentRead(value) {
665
+ this.flags = value ? this.flags | COMPONENT_READ : this.flags & ~COMPONENT_READ;
666
+ }
667
+ get size() {
668
+ const facts = this.facts;
669
+ if (facts === NO_FACT)
670
+ return 0;
671
+ if (Array.isArray(facts))
672
+ return facts.length;
673
+ return facts instanceof Set ? facts.size : 1;
674
+ }
675
+ has(value) {
676
+ const facts = this.facts;
677
+ if (facts === NO_FACT)
678
+ return false;
679
+ // `includes` is SameValueZero, as `Set.prototype.has` is.
680
+ if (Array.isArray(facts))
681
+ return facts.includes(value);
682
+ if (facts instanceof Set)
683
+ return facts.has(value);
684
+ // A lone fact is an object (`isLoneFact`), so identity is SameValueZero here.
685
+ return facts === value;
686
+ }
687
+ add(value) {
688
+ const facts = this.facts;
689
+ if (facts === NO_FACT) {
690
+ this.facts = isLoneFact(value) ? value : [value];
691
+ return;
692
+ }
693
+ if (facts instanceof Set) {
694
+ if ((this.flags & SHARED_FACTS) === 0) {
695
+ facts.add(value);
696
+ return;
697
+ }
698
+ if (facts.has(value))
699
+ return;
700
+ this.facts = new Set(facts).add(value);
701
+ this.flags &= ~SHARED_FACTS;
702
+ return;
703
+ }
704
+ if (this.has(value))
705
+ return;
706
+ // A new array rather than a push: a pushed array keeps growth slack,
707
+ // and no reader iterates a state's facts while they are added
708
+ // (`factsFrom`), so a replaced array is never mid-iteration.
709
+ const small = Array.isArray(facts) ? facts : [facts];
710
+ this.facts = small.length < SMALL_EDGES ? small.concat([value]) : new Set(small).add(value);
711
+ this.flags &= ~SHARED_FACTS;
712
+ }
713
+ /**
714
+ * Holds `other`'s fact collection when it is the same facts in the same
715
+ * order, so iteration is unchanged; both are marked shared, and `add`
716
+ * copies a shared `Set` before writing it (an array is never written: it is
717
+ * replaced). Only collections are shared: none or a lone fact costs nothing.
718
+ */
719
+ shareFactsOf(other) {
720
+ const mine = this.facts;
721
+ const theirs = other.facts;
722
+ if (mine === theirs)
723
+ return true;
724
+ if (!(mine instanceof Set || Array.isArray(mine)) || !(theirs instanceof Set || Array.isArray(theirs)))
725
+ return false;
726
+ if (this.size !== other.size)
727
+ return false;
728
+ const left = mine.values();
729
+ const right = theirs.values();
730
+ for (let a = left.next(), b = right.next(); !a.done; a = left.next(), b = right.next())
731
+ if (a.value !== b.value)
732
+ return false;
733
+ this.facts = theirs;
734
+ this.flags |= SHARED_FACTS;
735
+ other.flags |= SHARED_FACTS;
736
+ return true;
737
+ }
738
+ values() {
739
+ const facts = this.facts;
740
+ if (facts === NO_FACT)
741
+ return NO_FACTS.values();
742
+ if (Array.isArray(facts) || facts instanceof Set)
743
+ return facts.values();
744
+ return [facts].values();
745
+ }
746
+ keys() {
747
+ return this.values();
748
+ }
749
+ [Symbol.iterator]() {
750
+ return this.values();
751
+ }
752
+ entries() {
753
+ const facts = this.facts;
754
+ if (facts instanceof Set)
755
+ return facts.entries();
756
+ return [...this.values()].map((value) => [value, value]).values();
757
+ }
758
+ forEach(callback, thisArg) {
759
+ for (const value of this)
760
+ callback.call(thisArg, value, value, this);
761
+ }
762
+ }
763
+ /** A state for a key that cannot hold one, kept in the solver's own table. */
764
+ class KeyedFactState extends FactState {
765
+ solverKey;
766
+ constructor(solverKey) {
767
+ super();
768
+ this.solverKey = solverKey;
769
+ }
770
+ }
369
771
  /** `GEA_SOLVER_COUNTS` exit reports of the solvers still alive at exit. */
370
772
  const exitReports = new Set();
371
773
  if (process.env['GEA_SOLVER_COUNTS'] !== undefined)
@@ -373,8 +775,114 @@ if (process.env['GEA_SOLVER_COUNTS'] !== undefined)
373
775
  for (const report of exitReports)
374
776
  report.deref()?.();
375
777
  });
376
- export const dependencyFactSolver = (expand, mode) => {
377
- const states = new Map();
778
+ /**
779
+ * `expand` is either one definition for every node (its callbacks are handed
780
+ * the node's key) or a function minting one per node, called once as the node
781
+ * is created.
782
+ *
783
+ * With `keysAreStates`, every key is a `FactState` subclass instance the
784
+ * caller interned once per question, and the key is the node's state: a table
785
+ * keyed by key costs a hash entry per node -- ~7 MB of table for a 48K-line
786
+ * app's ~224K nodes -- and a separate state per key a header and two pointers.
787
+ * Such keys must be private to one solver. Otherwise states are kept in a
788
+ * table keyed by key.
789
+ */
790
+ export const dependencyFactSolver = (expand, mode, keysAreStates = false) => {
791
+ const table = keysAreStates ? null : new Map();
792
+ const existingStateOf = (key) => {
793
+ if (table !== null)
794
+ return table.get(key);
795
+ const state = key;
796
+ return state.minted ? state : undefined;
797
+ };
798
+ let stateCount = 0;
799
+ // Every state, for the `GEA_SOLVER_SIZES` report alone: keys that are states have no iteration.
800
+ const everyState = process.env['GEA_SOLVER_SIZES'] === undefined ? null : [];
801
+ // A definition per key is kept beside the states only for a caller that
802
+ // supplies one; a shared definition is not stored per state at all.
803
+ const definitions = typeof expand === 'function' ? new Map() : null;
804
+ const definitionOf = (state) => definitions === null ? expand : definitions.get(state.solverKey);
805
+ const observedState = (owner, dependency) => {
806
+ const observed = owner.observedDependencies;
807
+ if (observed === null)
808
+ return undefined;
809
+ if (!Array.isArray(observed))
810
+ return observed.solverKey === dependency ? observed : undefined;
811
+ if (observed.length <= SMALL_EDGES) {
812
+ for (const candidate of observed)
813
+ if (candidate.solverKey === dependency)
814
+ return candidate;
815
+ return undefined;
816
+ }
817
+ // An owner is among a dependency's dependents exactly when it observes
818
+ // it: the two edges are only ever added together (`factsFrom`).
819
+ const state = existingStateOf(dependency);
820
+ return state !== undefined && edgeHas(state.dependents, owner) ? state : undefined;
821
+ };
822
+ const withObserved = (observed, dependencyState) => {
823
+ if (observed === null)
824
+ return dependencyState;
825
+ if (!Array.isArray(observed))
826
+ return [observed, dependencyState];
827
+ if (observed.length < SMALL_EDGES)
828
+ return observed.concat([dependencyState]);
829
+ // Past `SMALL_EDGES` the array is this state's own (copied once, here) and grows in place.
830
+ if (observed.length === SMALL_EDGES)
831
+ return [...observed, dependencyState];
832
+ observed.push(dependencyState);
833
+ return observed;
834
+ };
835
+ // A key is held alone only when it cannot be mistaken for a collection of
836
+ // keys: an object that is neither an array nor a `Set`. Any other key (none
837
+ // in this solver's one caller) takes the one-element array it always had.
838
+ const loneRequired = (dependency) => typeof dependency === 'object' && dependency !== null && !Array.isArray(dependency) && !(dependency instanceof Set);
839
+ const explicitRequired = new Map();
840
+ const explicitRequiredOf = (state) => (state.explicitRequired ? explicitRequired.get(state) : null);
841
+ const setExplicitRequired = (state, required) => {
842
+ if (required === null)
843
+ return;
844
+ explicitRequired.set(state, required);
845
+ state.explicitRequired = true;
846
+ };
847
+ // A dependent of `dependency` observes it, so under `requiresObserved` it also requires it.
848
+ const isRequired = (state, dependency) => {
849
+ if (state.requiresObserved)
850
+ return observedState(state, dependency) !== undefined;
851
+ const required = explicitRequiredOf(state);
852
+ if (required === null)
853
+ return false;
854
+ if (required instanceof Set)
855
+ return required.has(dependency);
856
+ if (Array.isArray(required))
857
+ return required.includes(dependency);
858
+ return required === dependency;
859
+ };
860
+ const withRequired = (required, dependency) => {
861
+ if (required === null)
862
+ return loneRequired(dependency) ? dependency : [dependency];
863
+ if (required instanceof Set)
864
+ return required.add(dependency);
865
+ const small = Array.isArray(required) ? required : [required];
866
+ return small.length < SMALL_EDGES ? small.concat([dependency]) : new Set(small).add(dependency);
867
+ };
868
+ // A copy for an array: a long one grows in place while its owner runs.
869
+ const observedKeys = (observed) => observed === null
870
+ ? NO_DEPENDENCIES
871
+ : Array.isArray(observed)
872
+ ? observed.map((state) => state.solverKey)
873
+ : [observed.solverKey];
874
+ const requiredOf = (state) => {
875
+ if (state === undefined)
876
+ return NO_DEPENDENCIES;
877
+ if (state.requiresObserved)
878
+ return observedKeys(state.observedDependencies);
879
+ const required = explicitRequiredOf(state);
880
+ return required === null
881
+ ? NO_DEPENDENCIES
882
+ : required instanceof Set || Array.isArray(required)
883
+ ? required
884
+ : [required];
885
+ };
378
886
  // States, not keys: `propagate` used to hold keys and call `stateOf(key)`
379
887
  // on every drain, a Map lookup per edge fire across a large program's millions
380
888
  // of observe edges. The State is already in hand wherever an edge fires or is
@@ -391,29 +899,28 @@ export const dependencyFactSolver = (expand, mode) => {
391
899
  // after the drain and needs to know what the drain touched.
392
900
  const sealDirty = new Set();
393
901
  const enqueue = (state) => {
394
- sealDirty.add(state.key);
902
+ sealDirty.add(state.solverKey);
395
903
  if (queued.has(state))
396
904
  return;
397
905
  queued.add(state);
398
906
  queue.push(state);
399
907
  };
400
908
  const stateOf = (key) => {
401
- let state = states.get(key);
909
+ let state = existingStateOf(key);
402
910
  if (state === undefined) {
403
911
  // No edge readers kept on the state: three closures and their context
404
912
  // for the life of every state, when only a running transfer or seal ever
405
913
  // calls them. `transferOf`/`sealOf` mint them for that call.
406
- const built = {
407
- key,
408
- definition: expand(key),
409
- observedDependencies: null,
410
- requiredDependencies: null,
411
- facts: new Set(),
412
- dependents: null,
413
- indexed: false
414
- };
914
+ const built = table !== null ? new KeyedFactState(key) : key;
915
+ if (definitions !== null)
916
+ definitions.set(key, expand(key));
415
917
  state = built;
416
- states.set(key, state);
918
+ if (table !== null)
919
+ table.set(key, built);
920
+ else
921
+ built.minted = true;
922
+ stateCount++;
923
+ everyState?.push(built);
417
924
  enqueue(built);
418
925
  }
419
926
  return state;
@@ -431,7 +938,7 @@ export const dependencyFactSolver = (expand, mode) => {
431
938
  return;
432
939
  state.indexed = true;
433
940
  // Facts it published before it was seeded never reached the index.
434
- for (const fact of state.facts)
941
+ for (const fact of state)
435
942
  index(state, fact);
436
943
  };
437
944
  // The reverse of `observedDependencies`/`dependents`: every state that has
@@ -439,6 +946,8 @@ export const dependencyFactSolver = (expand, mode) => {
439
946
  // `holdersOf` about it. Only seeded states publish here (see
440
947
  // `DependencyFactHoldersOf`), so its size is bounded by the candidates'
441
948
  // facts, not by every (state, fact) pair in the program.
949
+ // Each in the small edge forms (`EdgeStates`): ~12K of these sets on a
950
+ // 48K-line app, most holding a few states, at ~200 bytes of table apiece.
442
951
  const holders = new Map();
443
952
  const valueSubscribers = new Map();
444
953
  // A node that asked `holdersOf(fact)` before this state held it named no
@@ -448,33 +957,33 @@ export const dependencyFactSolver = (expand, mode) => {
448
957
  // answer forever and never be asked again, which is the silently-wrong
449
958
  // result SEMANTIC-AUTHORITY ranks below a slow one.
450
959
  const index = (state, fact) => {
451
- let holding = holders.get(fact);
452
- if (holding === undefined)
453
- holders.set(fact, (holding = new Set()));
454
- holding.add(state);
960
+ const holding = holders.get(fact) ?? null;
961
+ const held = withMember(holding, state);
962
+ if (held !== holding)
963
+ holders.set(fact, held);
455
964
  const subscribers = valueSubscribers.get(fact);
456
965
  if (subscribers !== undefined)
457
- for (const subscriber of subscribers)
966
+ for (const subscriber of edgeStates(subscribers))
458
967
  enqueue(subscriber);
459
968
  };
460
969
  const NO_HOLDERS = [];
461
970
  const holdersOfFrom = (ownerState, fact) => {
462
- let subscribers = valueSubscribers.get(fact);
463
- if (subscribers === undefined)
464
- valueSubscribers.set(fact, (subscribers = new Set()));
465
- // Idempotent by construction (a Set), so re-asking on every re-evaluation
971
+ const subscribers = valueSubscribers.get(fact) ?? null;
972
+ const subscribed = withMember(subscribers, ownerState);
973
+ if (subscribed !== subscribers)
974
+ valueSubscribers.set(fact, subscribed);
975
+ // Idempotent by construction (a membership test), so re-asking on every re-evaluation
466
976
  // of the same node costs a lookup and nothing else -- no revision to bump,
467
977
  // no queue entry to make, because registering the subscription changes
468
978
  // nothing about what THIS transfer already computed with the holders it
469
979
  // just read below. It only matters for facts published AFTER this call,
470
980
  // which `propagate` below wakes through this same set.
471
- subscribers.add(ownerState);
472
981
  const holding = holders.get(fact);
473
982
  if (holding === undefined)
474
983
  return NO_HOLDERS;
475
984
  const found = [];
476
- for (const holder of holding)
477
- found.push(holder.key);
985
+ for (const holder of edgeStates(holding))
986
+ found.push(holder.solverKey);
478
987
  return found;
479
988
  };
480
989
  // The owner's state is handed in rather than looked up: every transfer and
@@ -482,31 +991,43 @@ export const dependencyFactSolver = (expand, mode) => {
482
991
  // for a state the caller is already holding was, on a large program, a quarter
483
992
  // of the whole compile.
484
993
  const factsFrom = (ownerState, dependency, required) => {
485
- let observed = ownerState.observedDependencies;
486
- let dependencyState = observed === null ? undefined : observed.get(dependency);
994
+ let dependencyState = observedState(ownerState, dependency);
487
995
  let changed = false;
996
+ // While every edge so far was required (a first edge that is required
997
+ // starts it), a required new edge keeps `requiresObserved`. The first new
998
+ // edge that is only observed ends it: the required edges are then exactly
999
+ // the ones observed so far, in that order, and from here on are kept in
1000
+ // `explicitRequired`.
1001
+ let joinsObserved = false;
488
1002
  if (dependencyState === undefined) {
1003
+ if (required)
1004
+ joinsObserved = ownerState.requiresObserved || ownerState.observedDependencies === null;
1005
+ else if (ownerState.requiresObserved) {
1006
+ let materialized = null;
1007
+ for (const key of observedKeys(ownerState.observedDependencies))
1008
+ materialized = withRequired(materialized, key);
1009
+ setExplicitRequired(ownerState, materialized);
1010
+ ownerState.requiresObserved = false;
1011
+ }
489
1012
  dependencyState = stateOf(dependency);
490
- if (observed === null)
491
- ownerState.observedDependencies = observed = new Map();
492
- observed.set(dependency, dependencyState);
493
- let dependents = dependencyState.dependents;
494
- if (dependents === null)
495
- dependencyState.dependents = dependents = new Set();
496
- dependents.add(ownerState);
1013
+ ownerState.observedDependencies = withObserved(ownerState.observedDependencies, dependencyState);
1014
+ // Appended without a membership test: an owner joins a dependency's
1015
+ // dependents exactly when its observed edge to it is new, and observed
1016
+ // edges are never removed, so it cannot already be there.
1017
+ dependencyState.dependents = withDependent(dependencyState.dependents, ownerState);
497
1018
  dependencyRevision++;
498
1019
  changed = true;
499
1020
  }
500
- if (required) {
501
- let requiredDependencies = ownerState.requiredDependencies;
502
- if (requiredDependencies === null)
503
- ownerState.requiredDependencies = requiredDependencies = new Set();
504
- if (!requiredDependencies.has(dependency)) {
505
- requiredDependencies.add(dependency);
506
- componentDirty.add(ownerState.key);
507
- dependencyRevision++;
508
- changed = true;
509
- }
1021
+ if (joinsObserved) {
1022
+ ownerState.requiresObserved = true;
1023
+ componentDirty.add(ownerState.solverKey);
1024
+ dependencyRevision++;
1025
+ }
1026
+ else if (required && !ownerState.requiresObserved && !isRequired(ownerState, dependency)) {
1027
+ setExplicitRequired(ownerState, withRequired(explicitRequiredOf(ownerState), dependency));
1028
+ componentDirty.add(ownerState.solverKey);
1029
+ dependencyRevision++;
1030
+ changed = true;
510
1031
  }
511
1032
  // A new observation may expose facts on the next pass. An upgrade also
512
1033
  // invalidates the current seal even though the fact edge already existed.
@@ -519,14 +1040,14 @@ export const dependencyFactSolver = (expand, mode) => {
519
1040
  // `propagate` adds a node's facts only AFTER its transfer has returned --
520
1041
  // `evaluate` builds its result eagerly and hands back a set of its own --
521
1042
  // so no reader is ever iterating a set that is being written.
522
- return dependencyState.facts;
1043
+ return dependencyState;
523
1044
  };
524
1045
  const readFrom = (ownerState, dependency) => factsFrom(ownerState, dependency, true);
525
1046
  const observeFrom = (ownerState, dependency) => factsFrom(ownerState, dependency, false);
526
1047
  // A state's edge readers, minted per transfer or seal call rather than kept
527
1048
  // on every state (see `stateOf`).
528
- const transferOf = (state) => state.definition.transfer((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact));
529
- const sealOf = (state) => state.definition.seal((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact));
1049
+ const transferOf = (state) => definitionOf(state).transfer((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
1050
+ const sealOf = (state) => definitionOf(state).seal((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
530
1051
  const propagate = () => {
531
1052
  for (let cursor = 0; cursor < queue.length; cursor++) {
532
1053
  const state = queue[cursor];
@@ -539,23 +1060,35 @@ export const dependencyFactSolver = (expand, mode) => {
539
1060
  // dependent already queued. The set can still grow mid-transfer (a state
540
1061
  // that reads itself), and then the newcomer must be woken too.
541
1062
  let wokenSize = -1;
1063
+ let added = false;
542
1064
  for (const fact of transferOf(state)) {
543
- if (state.facts.has(fact))
1065
+ if (state.has(fact))
544
1066
  continue;
545
- state.facts.add(fact);
1067
+ added = true;
1068
+ state.add(fact);
546
1069
  const dependents = state.dependents;
547
- const size = dependents === null ? 0 : dependents.size;
1070
+ const size = edgeCount(dependents);
548
1071
  if (wokenSize !== size) {
549
1072
  wokenSize = size;
550
- if (dependents !== null)
1073
+ if (dependents instanceof Set || Array.isArray(dependents))
551
1074
  for (const dependent of dependents)
552
1075
  enqueue(dependent);
1076
+ else if (dependents !== null)
1077
+ enqueue(dependents);
553
1078
  }
554
1079
  // Recorded at the exact point a fact is genuinely NEW, so `holders`
555
1080
  // never grows for a re-observed fact.
556
1081
  if (state.indexed)
557
1082
  index(state, fact);
558
1083
  }
1084
+ // A node forwarding what it reads ends up with the same facts as that
1085
+ // dependency: share its collection (`shareFactsOf`). Only a short edge
1086
+ // list is searched, and only a dependency of the same size compared.
1087
+ const observed = state.observedDependencies;
1088
+ if (added && state.size > 1 && observed !== null && (!Array.isArray(observed) || observed.length <= SMALL_EDGES))
1089
+ for (const dependency of edgeStates(observed))
1090
+ if (dependency.size === state.size && state.shareFactsOf(dependency))
1091
+ break;
559
1092
  }
560
1093
  queue.length = 0;
561
1094
  };
@@ -565,17 +1098,16 @@ export const dependencyFactSolver = (expand, mode) => {
565
1098
  // every query re-sealed the whole graph it had explored so far, so the last
566
1099
  // query of a large program paid for all of it. Only what `enqueue` marked is
567
1100
  // re-sealed, which is exactly what could have changed.
568
- const sealed = new Map();
569
1101
  // Nodes whose seal or required-edge set moved since the component solve last
570
1102
  // ran: the only facts a component answer reads.
571
1103
  const componentDirty = new Set();
572
1104
  const requiredDependentsOf = function* (key) {
573
- const state = states.get(key);
574
- if (state === undefined || state.dependents === null)
1105
+ const state = existingStateOf(key);
1106
+ if (state === undefined)
575
1107
  return;
576
- for (const dependent of state.dependents)
577
- if (dependent.requiredDependencies?.has(key) === true)
578
- yield dependent.key;
1108
+ for (const dependent of edgeStates(state.dependents))
1109
+ if (dependent.requiresObserved || isRequired(dependent, key))
1110
+ yield dependent.solverKey;
579
1111
  };
580
1112
  // A changed seal evicts every cached component answer that reaches it, so
581
1113
  // reporting a change for a re-seal that reproduces the same answer evicts
@@ -591,6 +1123,7 @@ export const dependencyFactSolver = (expand, mode) => {
591
1123
  // `Cause` per (node, reason) for exactly that reason.
592
1124
  const domainsEqual = (a, b) => a.length === b.length && a.every((domain, index) => domain === b[index]);
593
1125
  const groundingEdgesEqual = (a, b) => a.length === b.length && a.every((edge, index) => edge.domain === b[index].domain && edge.dependency === b[index].dependency);
1126
+ const keysEqual = (a, b) => a.length === b.length && a.every((key, index) => key === b[index]);
594
1127
  const causesEqual = (a, b) => a.length === b.length && a.every((cause, index) => cause === b[index]);
595
1128
  const sealChanged = (previous, next) => previous === undefined ||
596
1129
  previous.locallyComplete !== next.locallyComplete ||
@@ -598,7 +1131,9 @@ export const dependencyFactSolver = (expand, mode) => {
598
1131
  !causesEqual(previous.causes ?? [], next.causes ?? []) ||
599
1132
  !domainsEqual(previous.groundingRequirements ?? [], next.groundingRequirements ?? []) ||
600
1133
  !domainsEqual(previous.groundingSeeds ?? [], next.groundingSeeds ?? []) ||
601
- !groundingEdgesEqual(previous.groundingDependencies ?? [], next.groundingDependencies ?? []);
1134
+ !groundingEdgesEqual(previous.groundingDependencies ?? [], next.groundingDependencies ?? []) ||
1135
+ previous.groundingDomain !== next.groundingDomain ||
1136
+ !keysEqual(groundingKeysOf(previous), groundingKeysOf(next));
602
1137
  const counts = { roots: 0, transfers: 0, seals: 0, componentNodes: 0 };
603
1138
  // What the heap is actually holding, for the runs where memory is the wall
604
1139
  // rather than time. Counted only when asked for: it walks every state.
@@ -619,20 +1154,20 @@ export const dependencyFactSolver = (expand, mode) => {
619
1154
  // GEA_SOLVER_SIZES-gated path that prints nothing in production, and
620
1155
  // falls back to a single 'unknown' bucket for any key not shaped this way.
621
1156
  const perKind = new Map();
622
- for (const state of states.values()) {
623
- observed += state.observedDependencies?.size ?? 0;
624
- required += state.requiredDependencies?.size ?? 0;
625
- dependents += state.dependents?.size ?? 0;
626
- facts += state.facts.size;
627
- const kind = state.key.kind;
1157
+ for (const state of everyState ?? []) {
1158
+ observed += edgeCount(state.observedDependencies);
1159
+ required += [...requiredOf(state)].length;
1160
+ dependents += edgeCount(state.dependents);
1161
+ facts += state.size;
1162
+ const kind = state.solverKey.kind;
628
1163
  const bucketKey = typeof kind === 'string' ? kind : 'unknown';
629
1164
  let bucket = perKind.get(bucketKey);
630
1165
  if (bucket === undefined)
631
1166
  perKind.set(bucketKey, (bucket = { states: 0, observed: 0, required: 0, facts: 0 }));
632
1167
  bucket.states++;
633
- bucket.observed += state.observedDependencies?.size ?? 0;
634
- bucket.required += state.requiredDependencies?.size ?? 0;
635
- bucket.facts += state.facts.size;
1168
+ bucket.observed += edgeCount(state.observedDependencies);
1169
+ bucket.required += [...requiredOf(state)].length;
1170
+ bucket.facts += state.size;
636
1171
  }
637
1172
  const byKind = [...perKind]
638
1173
  .sort(([, a], [, b]) => b.observed - a.observed)
@@ -663,7 +1198,7 @@ export const dependencyFactSolver = (expand, mode) => {
663
1198
  const report = () => {
664
1199
  if (!countsEnabled)
665
1200
  return;
666
- console.error(`[SOLVER] roots=${counts.roots} states=${states.size} transfers=${counts.transfers} seals=${counts.seals} component-expansions=${counts.componentNodes}${sizes()}${describeRoot()}`);
1201
+ console.error(`[SOLVER] roots=${counts.roots} states=${stateCount} transfers=${counts.transfers} seals=${counts.seals} component-expansions=${counts.componentNodes}${sizes()}${describeRoot()}`);
667
1202
  };
668
1203
  // Weakly: an exit listener closing over `report` kept every solver's whole
669
1204
  // graph alive for the rest of the process, so a run measured with counts on
@@ -688,16 +1223,16 @@ export const dependencyFactSolver = (expand, mode) => {
688
1223
  const dirty = [...sealDirty];
689
1224
  sealDirty.clear();
690
1225
  for (const key of dirty) {
691
- const state = states.get(key);
1226
+ const state = existingStateOf(key);
692
1227
  if (state === undefined)
693
1228
  continue;
694
1229
  counts.seals++;
695
1230
  if (countsEnabled && counts.seals % 200000 === 0)
696
1231
  report();
697
1232
  const next = sealOf(state);
698
- if (sealChanged(sealed.get(key), next))
1233
+ if (sealChanged(state.sealed, next))
699
1234
  componentDirty.add(key);
700
- sealed.set(key, next);
1235
+ state.sealed = next;
701
1236
  }
702
1237
  if (queue.length === 0 && sealDirty.size === 0 && dependencyRevision === revisionBeforeSeal)
703
1238
  break;
@@ -712,15 +1247,21 @@ export const dependencyFactSolver = (expand, mode) => {
712
1247
  // observe edge -- neither of which any component answer reads. Only the
713
1248
  // answers that could have read a changed node are evicted.
714
1249
  if (componentSolver === null)
715
- componentSolver = invalidatableComponentSolver((key) => {
716
- counts.componentNodes++;
717
- if (countsEnabled && counts.componentNodes % 200000 === 0)
718
- report();
719
- const state = states.get(key);
720
- const local = sealed.get(key);
721
- if (state === undefined || local === undefined)
722
- throw new Error('unsealed dependency fact node');
723
- return { ...local, dependencies: state.requiredDependencies === null ? NO_DEPENDENCIES : [...state.requiredDependencies] };
1250
+ componentSolver = componentEngine({
1251
+ slotOf: (key) => {
1252
+ const state = existingStateOf(key);
1253
+ if (state === undefined || state.sealed === undefined)
1254
+ throw new Error('unsealed dependency fact node');
1255
+ if (!state.componentRead) {
1256
+ counts.componentNodes++;
1257
+ if (countsEnabled && counts.componentNodes % 200000 === 0)
1258
+ report();
1259
+ }
1260
+ return state;
1261
+ },
1262
+ existingSlotOf: existingStateOf,
1263
+ localOf: (state) => state.sealed,
1264
+ dependenciesOf: (state) => requiredOf(state)
724
1265
  }, mode);
725
1266
  else if (componentDirty.size > 0)
726
1267
  componentSolver.invalidate(componentDirty, requiredDependentsOf);
@@ -731,7 +1272,7 @@ export const dependencyFactSolver = (expand, mode) => {
731
1272
  status: 'complete',
732
1273
  grounded: result.grounded,
733
1274
  groundedDomains: result.groundedDomains,
734
- facts: new Set(stateOf(root).facts),
1275
+ facts: new Set(stateOf(root)),
735
1276
  explain: result.explain
736
1277
  };
737
1278
  return {
@@ -741,5 +1282,5 @@ export const dependencyFactSolver = (expand, mode) => {
741
1282
  explain: result.explain
742
1283
  };
743
1284
  };
744
- return { solve, requiredDependenciesOf: (key) => states.get(key)?.requiredDependencies ?? NO_DEPENDENCIES, seed };
1285
+ return { solve, requiredDependenciesOf: (key) => requiredOf(existingStateOf(key)), seed };
745
1286
  };