tsc-ts 0.0.10 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/README.md +1 -1
  2. package/bin/tsc-ts.js +70 -1
  3. package/dist/api/compiler/ast-utilities.d.ts +19 -1
  4. package/dist/api/compiler/ast-utilities.js +180 -95
  5. package/dist/api/compiler/ast.d.ts +20 -15
  6. package/dist/api/compiler/ast.js +1023 -995
  7. package/dist/api/compiler/astnav.js +15 -15
  8. package/dist/api/compiler/binder-utilities.js +186 -186
  9. package/dist/api/compiler/binder.js +290 -263
  10. package/dist/api/compiler/character-codes.js +2 -2
  11. package/dist/api/compiler/checker-calls.js +173 -123
  12. package/dist/api/compiler/checker-classes.d.ts +14 -3
  13. package/dist/api/compiler/checker-classes.js +134 -90
  14. package/dist/api/compiler/checker-contextual.js +64 -61
  15. package/dist/api/compiler/checker-declaration-order.js +79 -79
  16. package/dist/api/compiler/checker-declarations.d.ts +1 -0
  17. package/dist/api/compiler/checker-declarations.js +160 -136
  18. package/dist/api/compiler/checker-declared-types.js +67 -65
  19. package/dist/api/compiler/checker-decorators.js +77 -77
  20. package/dist/api/compiler/checker-deprecation.d.ts +8 -3
  21. package/dist/api/compiler/checker-deprecation.js +76 -55
  22. package/dist/api/compiler/checker-destructuring.js +47 -45
  23. package/dist/api/compiler/checker-elaboration.js +24 -24
  24. package/dist/api/compiler/checker-emit-helpers.js +4 -4
  25. package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
  26. package/dist/api/compiler/checker-emit-resolver.js +25 -13
  27. package/dist/api/compiler/checker-evaluator.js +9 -9
  28. package/dist/api/compiler/checker-expressions.js +244 -211
  29. package/dist/api/compiler/checker-functions.js +113 -107
  30. package/dist/api/compiler/checker-generated-code.d.ts +0 -11
  31. package/dist/api/compiler/checker-generated-code.js +28 -52
  32. package/dist/api/compiler/checker-grammar.d.ts +1 -0
  33. package/dist/api/compiler/checker-grammar.js +469 -438
  34. package/dist/api/compiler/checker-heritage.js +91 -93
  35. package/dist/api/compiler/checker-inference.d.ts +77 -5
  36. package/dist/api/compiler/checker-inference.js +487 -113
  37. package/dist/api/compiler/checker-iteration.d.ts +0 -10
  38. package/dist/api/compiler/checker-iteration.js +35 -52
  39. package/dist/api/compiler/checker-javascript.js +14 -14
  40. package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
  41. package/dist/api/compiler/checker-jsdoc.js +67 -58
  42. package/dist/api/compiler/checker-jsx.js +105 -88
  43. package/dist/api/compiler/checker-members.d.ts +9 -2
  44. package/dist/api/compiler/checker-members.js +210 -74
  45. package/dist/api/compiler/checker-modules.d.ts +15 -6
  46. package/dist/api/compiler/checker-modules.js +469 -309
  47. package/dist/api/compiler/checker-narrowing.js +273 -189
  48. package/dist/api/compiler/checker-object-literals.js +25 -22
  49. package/dist/api/compiler/checker-operators.js +126 -118
  50. package/dist/api/compiler/checker-overloads.js +27 -27
  51. package/dist/api/compiler/checker-property-access.js +59 -55
  52. package/dist/api/compiler/checker-services.d.ts +1 -0
  53. package/dist/api/compiler/checker-services.js +222 -210
  54. package/dist/api/compiler/checker-signatures.js +65 -49
  55. package/dist/api/compiler/checker-source-file.d.ts +5 -0
  56. package/dist/api/compiler/checker-source-file.js +154 -130
  57. package/dist/api/compiler/checker-statements.js +33 -32
  58. package/dist/api/compiler/checker-super.js +50 -50
  59. package/dist/api/compiler/checker-symbol-types.js +109 -93
  60. package/dist/api/compiler/checker-symbols.d.ts +13 -1
  61. package/dist/api/compiler/checker-symbols.js +264 -149
  62. package/dist/api/compiler/checker-type-factory.d.ts +5 -0
  63. package/dist/api/compiler/checker-type-factory.js +137 -34
  64. package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
  65. package/dist/api/compiler/checker-type-nodes.js +179 -141
  66. package/dist/api/compiler/checker-type-operators.d.ts +2 -0
  67. package/dist/api/compiler/checker-type-operators.js +110 -63
  68. package/dist/api/compiler/checker-types.d.ts +80 -3
  69. package/dist/api/compiler/checker-types.js +121 -2
  70. package/dist/api/compiler/checker-unused.js +114 -118
  71. package/dist/api/compiler/checker-utilities.js +11 -11
  72. package/dist/api/compiler/checker.d.ts +93 -31
  73. package/dist/api/compiler/checker.js +143 -35
  74. package/dist/api/compiler/command-line.d.ts +1 -3
  75. package/dist/api/compiler/command-line.js +47 -44
  76. package/dist/api/compiler/compile-program.d.ts +19 -4
  77. package/dist/api/compiler/compile-program.js +45 -26
  78. package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
  79. package/dist/api/compiler/diagnostic-messages.js +128 -122
  80. package/dist/api/compiler/diagnostics.js +7 -7
  81. package/dist/api/compiler/emitter.d.ts +7 -1
  82. package/dist/api/compiler/emitter.js +53 -11
  83. package/dist/api/compiler/file-include.d.ts +2 -1
  84. package/dist/api/compiler/file-include.js +11 -7
  85. package/dist/api/compiler/file-loader.d.ts +10 -0
  86. package/dist/api/compiler/file-loader.js +138 -41
  87. package/dist/api/compiler/instantiation.d.ts +7 -0
  88. package/dist/api/compiler/instantiation.js +101 -49
  89. package/dist/api/compiler/jsdoc.js +23 -23
  90. package/dist/api/compiler/link-tables.d.ts +48 -18
  91. package/dist/api/compiler/link-tables.js +80 -37
  92. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  93. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  94. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  95. package/dist/api/compiler/locales/de-DE.js +1 -1
  96. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  97. package/dist/api/compiler/locales/es-ES.js +1 -1
  98. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  99. package/dist/api/compiler/locales/fr-FR.js +1 -1
  100. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  101. package/dist/api/compiler/locales/it-IT.js +1 -1
  102. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  103. package/dist/api/compiler/locales/ja-JP.js +1 -1
  104. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  105. package/dist/api/compiler/locales/ko-KR.js +1 -1
  106. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  107. package/dist/api/compiler/locales/pl-PL.js +1 -1
  108. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  109. package/dist/api/compiler/locales/pt-BR.js +1 -1
  110. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  111. package/dist/api/compiler/locales/ru-RU.js +1 -1
  112. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  113. package/dist/api/compiler/locales/tr-TR.js +1 -1
  114. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  115. package/dist/api/compiler/locales/zh-CN.js +1 -1
  116. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  117. package/dist/api/compiler/locales/zh-TW.js +1 -1
  118. package/dist/api/compiler/module-resolution-types.js +6 -6
  119. package/dist/api/compiler/module-resolution.d.ts +10 -1
  120. package/dist/api/compiler/module-resolution.js +115 -84
  121. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  122. package/dist/api/compiler/module-specifiers.js +24 -18
  123. package/dist/api/compiler/name-resolver.js +74 -65
  124. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  125. package/dist/api/compiler/node-builder-names.js +210 -90
  126. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  127. package/dist/api/compiler/node-builder-reuse.js +23 -22
  128. package/dist/api/compiler/node-builder.d.ts +18 -1
  129. package/dist/api/compiler/node-builder.js +191 -102
  130. package/dist/api/compiler/option-declarations.d.ts +2 -6
  131. package/dist/api/compiler/option-declarations.js +315 -375
  132. package/dist/api/compiler/options.d.ts +15 -33
  133. package/dist/api/compiler/options.js +21 -54
  134. package/dist/api/compiler/output-paths.d.ts +4 -1
  135. package/dist/api/compiler/output-paths.js +6 -11
  136. package/dist/api/compiler/package-json.d.ts +3 -3
  137. package/dist/api/compiler/package-json.js +11 -10
  138. package/dist/api/compiler/parser.d.ts +40 -19
  139. package/dist/api/compiler/parser.js +308 -216
  140. package/dist/api/compiler/path.d.ts +9 -0
  141. package/dist/api/compiler/path.js +20 -3
  142. package/dist/api/compiler/printer/emit-context.d.ts +3 -1
  143. package/dist/api/compiler/printer/emit-context.js +16 -1
  144. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  145. package/dist/api/compiler/printer/factory-base.js +7 -3
  146. package/dist/api/compiler/printer/factory.js +3 -1
  147. package/dist/api/compiler/printer/helpers.js +10 -1
  148. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  149. package/dist/api/compiler/printer/name-generator.js +35 -16
  150. package/dist/api/compiler/printer/printer.d.ts +1 -0
  151. package/dist/api/compiler/printer/printer.js +303 -281
  152. package/dist/api/compiler/printer/utilities.js +149 -147
  153. package/dist/api/compiler/program-checker.d.ts +8 -2
  154. package/dist/api/compiler/program-checker.js +84 -34
  155. package/dist/api/compiler/program-utilities.d.ts +3 -1
  156. package/dist/api/compiler/program-utilities.js +28 -15
  157. package/dist/api/compiler/program.d.ts +2 -0
  158. package/dist/api/compiler/program.js +69 -57
  159. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  160. package/dist/api/compiler/pseudo-bigint.js +18 -0
  161. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  162. package/dist/api/compiler/regexp-checker.js +93 -76
  163. package/dist/api/compiler/relations.d.ts +27 -4
  164. package/dist/api/compiler/relations.js +337 -180
  165. package/dist/api/compiler/reparser.js +60 -56
  166. package/dist/api/compiler/scanner.d.ts +19 -2
  167. package/dist/api/compiler/scanner.js +123 -108
  168. package/dist/api/compiler/shared-results.d.ts +463 -0
  169. package/dist/api/compiler/shared-results.js +2128 -0
  170. package/dist/api/compiler/sourcemap.js +2 -2
  171. package/dist/api/compiler/symbol-accessibility.js +87 -74
  172. package/dist/api/compiler/symbol.d.ts +22 -13
  173. package/dist/api/compiler/symbol.js +15 -1
  174. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  175. package/dist/api/compiler/transformers/alias-references.js +247 -139
  176. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  177. package/dist/api/compiler/transformers/async.d.ts +0 -1
  178. package/dist/api/compiler/transformers/async.js +64 -77
  179. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  180. package/dist/api/compiler/transformers/class-fields.js +81 -78
  181. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  182. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  183. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  184. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  185. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  186. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  187. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  188. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  189. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  190. package/dist/api/compiler/transformers/declarations.js +305 -238
  191. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  192. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  193. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  194. package/dist/api/compiler/transformers/destructuring.js +19 -18
  195. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  196. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  197. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  198. package/dist/api/compiler/transformers/for-await.js +25 -25
  199. package/dist/api/compiler/transformers/import-elision.js +14 -14
  200. package/dist/api/compiler/transformers/jsx.js +12 -12
  201. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  202. package/dist/api/compiler/transformers/module.js +8 -8
  203. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  204. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  205. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  206. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  207. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  208. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  209. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  210. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  211. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  212. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  213. package/dist/api/compiler/transformers/using.js +12 -12
  214. package/dist/api/compiler/transformers/utilities.js +77 -77
  215. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  216. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  217. package/dist/api/compiler/tsconfig.d.ts +10 -2
  218. package/dist/api/compiler/tsconfig.js +136 -48
  219. package/dist/api/compiler/type-printer.js +40 -3
  220. package/dist/api/compiler/types.d.ts +2 -1
  221. package/dist/api/library/ast.generated.d.ts +42 -39
  222. package/dist/api/library/ast.generated.js +1 -1
  223. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  224. package/dist/api/library/compiler-options.generated.js +1 -1
  225. package/dist/api/library/disk.js +12 -1
  226. package/dist/api/library/enums.generated.d.ts +206 -206
  227. package/dist/api/library/enums.generated.js +206 -206
  228. package/dist/api/library/nodes.js +26 -26
  229. package/package.json +9 -9
  230. package/src/compiler/ast-utilities.ts +99 -7
  231. package/src/compiler/ast.ts +55 -26
  232. package/src/compiler/binder.ts +39 -4
  233. package/src/compiler/character-codes.ts +2 -2
  234. package/src/compiler/checker-calls.ts +76 -8
  235. package/src/compiler/checker-classes.ts +78 -24
  236. package/src/compiler/checker-contextual.ts +6 -1
  237. package/src/compiler/checker-declarations.ts +31 -4
  238. package/src/compiler/checker-declared-types.ts +8 -5
  239. package/src/compiler/checker-decorators.ts +1 -1
  240. package/src/compiler/checker-deprecation.ts +29 -8
  241. package/src/compiler/checker-destructuring.ts +10 -3
  242. package/src/compiler/checker-emit-helpers.ts +1 -0
  243. package/src/compiler/checker-emit-resolver.ts +16 -6
  244. package/src/compiler/checker-expressions.ts +79 -46
  245. package/src/compiler/checker-functions.ts +21 -6
  246. package/src/compiler/checker-generated-code.ts +2 -22
  247. package/src/compiler/checker-grammar.ts +133 -60
  248. package/src/compiler/checker-heritage.ts +22 -21
  249. package/src/compiler/checker-inference.ts +514 -87
  250. package/src/compiler/checker-iteration.ts +18 -31
  251. package/src/compiler/checker-javascript.ts +1 -1
  252. package/src/compiler/checker-jsdoc.ts +50 -27
  253. package/src/compiler/checker-jsx.ts +26 -4
  254. package/src/compiler/checker-members.ts +197 -55
  255. package/src/compiler/checker-modules.ts +332 -65
  256. package/src/compiler/checker-narrowing.ts +98 -19
  257. package/src/compiler/checker-object-literals.ts +3 -0
  258. package/src/compiler/checker-operators.ts +11 -4
  259. package/src/compiler/checker-property-access.ts +7 -2
  260. package/src/compiler/checker-services.ts +39 -12
  261. package/src/compiler/checker-signatures.ts +15 -1
  262. package/src/compiler/checker-source-file.ts +39 -13
  263. package/src/compiler/checker-statements.ts +3 -2
  264. package/src/compiler/checker-symbol-types.ts +29 -6
  265. package/src/compiler/checker-symbols.ts +158 -15
  266. package/src/compiler/checker-type-factory.ts +120 -21
  267. package/src/compiler/checker-type-nodes.ts +46 -3
  268. package/src/compiler/checker-type-operators.ts +83 -26
  269. package/src/compiler/checker-types.ts +147 -4
  270. package/src/compiler/checker-unused.ts +9 -14
  271. package/src/compiler/checker.ts +168 -41
  272. package/src/compiler/command-line.ts +28 -28
  273. package/src/compiler/compile-program.ts +51 -25
  274. package/src/compiler/decoder.ts +13 -4
  275. package/src/compiler/diagnostic-messages.ts +1973 -1892
  276. package/src/compiler/emitter.ts +57 -8
  277. package/src/compiler/encoder.ts +23 -8
  278. package/src/compiler/file-include.ts +9 -3
  279. package/src/compiler/file-loader.ts +139 -32
  280. package/src/compiler/help.ts +10 -14
  281. package/src/compiler/incremental.ts +86 -18
  282. package/src/compiler/init.ts +2 -7
  283. package/src/compiler/instantiation.ts +77 -22
  284. package/src/compiler/jsdoc.ts +3 -1
  285. package/src/compiler/link-tables.ts +82 -37
  286. package/src/compiler/locales/cs-CZ.ts +1 -1
  287. package/src/compiler/locales/de-DE.ts +1 -1
  288. package/src/compiler/locales/es-ES.ts +1 -1
  289. package/src/compiler/locales/fr-FR.ts +1 -1
  290. package/src/compiler/locales/it-IT.ts +1 -1
  291. package/src/compiler/locales/ja-JP.ts +1 -1
  292. package/src/compiler/locales/ko-KR.ts +1 -1
  293. package/src/compiler/locales/pl-PL.ts +1 -1
  294. package/src/compiler/locales/pt-BR.ts +1 -1
  295. package/src/compiler/locales/ru-RU.ts +1 -1
  296. package/src/compiler/locales/tr-TR.ts +1 -1
  297. package/src/compiler/locales/zh-CN.ts +1 -1
  298. package/src/compiler/locales/zh-TW.ts +1 -1
  299. package/src/compiler/module-resolution.ts +44 -8
  300. package/src/compiler/module-specifiers.ts +62 -20
  301. package/src/compiler/name-resolver.ts +9 -1
  302. package/src/compiler/node-builder-names.ts +236 -54
  303. package/src/compiler/node-builder-pseudo.ts +4 -7
  304. package/src/compiler/node-builder-reuse.ts +5 -4
  305. package/src/compiler/node-builder.ts +130 -31
  306. package/src/compiler/option-declarations.ts +33 -103
  307. package/src/compiler/options.ts +23 -62
  308. package/src/compiler/output-paths.ts +5 -18
  309. package/src/compiler/package-entrypoints.ts +345 -0
  310. package/src/compiler/package-json.ts +4 -4
  311. package/src/compiler/parallel-check.ts +197 -8
  312. package/src/compiler/parallel-emit.ts +1 -1
  313. package/src/compiler/parser.ts +156 -39
  314. package/src/compiler/path.ts +22 -2
  315. package/src/compiler/printer/emit-context.ts +16 -0
  316. package/src/compiler/printer/factory-base.ts +10 -3
  317. package/src/compiler/printer/factory.ts +4 -1
  318. package/src/compiler/printer/helpers.ts +10 -1
  319. package/src/compiler/printer/name-generator.ts +24 -2
  320. package/src/compiler/printer/printer.ts +35 -14
  321. package/src/compiler/printer/utilities.ts +8 -2
  322. package/src/compiler/program-checker.ts +53 -5
  323. package/src/compiler/program-utilities.ts +23 -10
  324. package/src/compiler/program.ts +13 -1
  325. package/src/compiler/pseudo-bigint.ts +17 -0
  326. package/src/compiler/regexp-checker.ts +63 -30
  327. package/src/compiler/relations.ts +233 -77
  328. package/src/compiler/reparser.ts +7 -2
  329. package/src/compiler/scanner.ts +109 -79
  330. package/src/compiler/shared-results.ts +2414 -0
  331. package/src/compiler/show-config.ts +18 -1
  332. package/src/compiler/sourcemap.ts +2 -2
  333. package/src/compiler/symbol-accessibility.ts +26 -3
  334. package/src/compiler/symbol.ts +31 -14
  335. package/src/compiler/syntax-kind.ts +188 -187
  336. package/src/compiler/thread-entry.ts +19 -2
  337. package/src/compiler/transformers/alias-references.ts +123 -4
  338. package/src/compiler/transformers/async.ts +2 -17
  339. package/src/compiler/transformers/class-fields.ts +13 -12
  340. package/src/compiler/transformers/commonjs-module.ts +11 -7
  341. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  342. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  343. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  344. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  345. package/src/compiler/transformers/declarations.ts +134 -48
  346. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  347. package/src/compiler/transformers/destructuring.ts +4 -3
  348. package/src/compiler/transformers/external-module-info.ts +1 -1
  349. package/src/compiler/transformers/jsx.ts +2 -1
  350. package/src/compiler/transformers/reference-resolver.ts +83 -19
  351. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  352. package/src/compiler/transformers/syntax-facts.ts +2 -7
  353. package/src/compiler/transformers/type-eraser.ts +10 -1
  354. package/src/compiler/transformers/type-serialization.ts +3 -2
  355. package/src/compiler/transformers/visitor-base.ts +2 -1
  356. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  357. package/src/compiler/tsc-build.ts +3 -0
  358. package/src/compiler/tsc-cli.ts +2 -0
  359. package/src/compiler/tsc-compile.ts +7 -2
  360. package/src/compiler/tsc-watch.ts +74 -45
  361. package/src/compiler/tsconfig.ts +176 -19
  362. package/src/compiler/type-printer.ts +36 -2
  363. package/src/compiler/types.ts +2 -1
  364. package/src/library/ast.generated.ts +57 -41
  365. package/src/library/compiler-options.generated.ts +117 -103
  366. package/src/library/disk.ts +10 -1
  367. package/src/library/enums.generated.ts +196 -196
@@ -0,0 +1,2128 @@
1
+ // Results one checker thread computed, as portable records other checker threads translate into their own types
2
+ // (TSC_TS_SHARE=1).
3
+ //
4
+ // A checker exports the result of a declaration-level computation (the value type of a variable or property, or the
5
+ // return type of a declared signature) as records: each type the result reaches through its identity (constituents,
6
+ // type arguments, alias arguments, instantiation arguments, and the parts of index, indexed access, conditional,
7
+ // template, string mapping and substitution types), down to types every checker can get by itself (intrinsic types,
8
+ // declared types of symbols, types of declarations and type nodes). Another checker translates the records through
9
+ // its own interning caches, so each type still has one object in it.
10
+ import { getSymbol, NodeVisitor } from './ast.js';
11
+ import { getSourceFileOfNode } from './binder-utilities.js';
12
+ import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
13
+ import { TupleElementInfo, TypeAlias, getMappedType, IndexInfo, newTypeMapper, } from './checker-types.js';
14
+ import { createTypeReference, getBigIntLiteralType, getFreshTypeOfLiteralType, getNumberLiteralType, getStringLiteralType, getTemplateLiteralType, getTupleTargetType, getUnionTypeFromSortedList, newIntersectionType, newObjectType, newUnionType, setStructuredTypeMembers, getPropagatingFlagsOfTypes, typeListHash, } from './checker-type-factory.js';
15
+ import { distributedKey, getConditionalTypeInstantiation, getIndexTypeEx, getIndexedAccessTypeEx, getNoInferType, getStringMappingType, getSubstitutionType, isNoInferType, } from './checker-type-operators.js';
16
+ import { getESSymbolLikeTypeForNode, getTypeFromTypeNode } from './checker-type-nodes.js';
17
+ import { instantiateTypeWithAlias } from './instantiation.js';
18
+ import { resolvedReturnTypeOf, sideOf } from './side-state.js';
19
+ import { getDeclarations, getSymbolId, setDeclarations } from './symbol.js';
20
+ import { keepPropertiesOnly, scannedLiteralPropertiesLimit } from './checker-members.js';
21
+ import { findResolutionCycleStartIndex } from './checker-symbols.js';
22
+ import { typeToString } from './type-printer.js';
23
+ import { getTypeOfSymbol } from './checker-symbol-types.js';
24
+ import { getReturnTypeOfSignature } from './checker-signatures.js';
25
+ // Functions, classes, enums and modules have anonymous types that are cheap to create; their members are not. (A
26
+ // function: a top-level constant computed from an enum member of a module in an import cycle doesn't compile natively.)
27
+ function sharedValueFlags() {
28
+ return 3 /* SymbolFlags.Variable */ | 4 /* SymbolFlags.Property */;
29
+ }
30
+ /** An index signature of an `AnonymousObject` record. */
31
+ export class PortableIndexInfo {
32
+ keyType;
33
+ valueType;
34
+ isReadonly;
35
+ declaration;
36
+ components;
37
+ constructor(keyType, valueType, isReadonly, declaration, components) {
38
+ this.keyType = keyType;
39
+ this.valueType = valueType;
40
+ this.isReadonly = isReadonly;
41
+ this.declaration = declaration;
42
+ this.components = components;
43
+ }
44
+ }
45
+ export class PortableRecord {
46
+ kind;
47
+ flags;
48
+ num;
49
+ text;
50
+ symbol;
51
+ node;
52
+ refs;
53
+ nums;
54
+ nodes;
55
+ texts;
56
+ /** For a symbol a checker merged: the id of a symbol it merged, which keys every checker's merged symbol. */
57
+ mergedId;
58
+ /** The alias: its symbol and the records of its type arguments. */
59
+ aliasSymbol;
60
+ aliasMergedId;
61
+ aliasRefs;
62
+ indexInfos;
63
+ /** The producer's type id, which keys the consumer's translations of the producer's types. */
64
+ id;
65
+ constructor(kind, id, flags, num, text, symbol, node, refs) {
66
+ this.kind = kind;
67
+ this.id = id;
68
+ this.flags = flags;
69
+ this.num = num;
70
+ this.text = text;
71
+ this.symbol = symbol;
72
+ this.node = node;
73
+ this.refs = refs;
74
+ this.nums = noNumbers;
75
+ this.nodes = noNodes;
76
+ this.texts = noTexts;
77
+ this.mergedId = -1;
78
+ this.aliasSymbol = undefined;
79
+ this.aliasMergedId = -1;
80
+ this.aliasRefs = noNumbers;
81
+ this.indexInfos = noIndexInfos;
82
+ }
83
+ }
84
+ const noNumbers = [];
85
+ const noNodes = [];
86
+ const noTexts = [];
87
+ const noIndexInfos = [];
88
+ /** The types every checker creates when it starts, in the same order; marker types are left out. */
89
+ export function initialTypes(c) {
90
+ return [
91
+ c.anyType,
92
+ c.autoType,
93
+ c.wildcardType,
94
+ c.blockedStringType,
95
+ c.errorType,
96
+ c.unresolvedType,
97
+ c.nonInferrableAnyType,
98
+ c.intrinsicMarkerType,
99
+ c.unknownType,
100
+ c.undefinedType,
101
+ c.undefinedWideningType,
102
+ c.missingType,
103
+ c.undefinedOrMissingType,
104
+ c.optionalType,
105
+ c.nullType,
106
+ c.nullWideningType,
107
+ c.stringType,
108
+ c.numberType,
109
+ c.bigintType,
110
+ c.regularFalseType,
111
+ c.falseType,
112
+ c.regularTrueType,
113
+ c.trueType,
114
+ c.booleanType,
115
+ c.esSymbolType,
116
+ c.voidType,
117
+ c.neverType,
118
+ c.silentNeverType,
119
+ c.implicitNeverType,
120
+ c.unreachableNeverType,
121
+ c.nonPrimitiveType,
122
+ c.stringOrNumberType,
123
+ c.stringNumberSymbolType,
124
+ c.numberOrBigIntType,
125
+ c.numericStringType,
126
+ c.templateConstraintType,
127
+ c.uniqueLiteralType,
128
+ c.emptyObjectType,
129
+ c.emptyJsxObjectType,
130
+ c.emptyFreshJsxObjectType,
131
+ c.emptyTypeLiteralType,
132
+ c.unknownEmptyObjectType,
133
+ c.unknownUnionType,
134
+ c.emptyGenericType,
135
+ c.anyFunctionType,
136
+ c.noConstraintType,
137
+ c.circularConstraintType,
138
+ c.resolvingDefaultType,
139
+ c.emptyStringType,
140
+ c.zeroType,
141
+ c.zeroBigIntType,
142
+ c.typeofType,
143
+ ];
144
+ }
145
+ /** A checker's `Exporter.mergedOrigins`, kept while its merged symbols stay the same. */
146
+ export class MergedOrigins {
147
+ origins = new Map();
148
+ size = -1;
149
+ }
150
+ /** Writes a result as records; `failure` names the first part that has no record kind. */
151
+ export class Exporter {
152
+ c;
153
+ records = [];
154
+ indexes = new Map();
155
+ /**
156
+ * The index of `records[0]`. A checker's exporter keeps the indexes of the types it exported before
157
+ * (`ThreadSharing.post`): their records are in its store already, and a result's records are only the new ones.
158
+ */
159
+ base = 0;
160
+ /** The types and properties the export in progress gave indexes, which a failed export forgets again. */
161
+ addedTypes = [];
162
+ addedProperties = [];
163
+ /** Appends `record`; its index. */
164
+ push(record) {
165
+ const index = this.base + this.records.length;
166
+ this.records.push(record);
167
+ return index;
168
+ }
169
+ initial;
170
+ failure = undefined;
171
+ /** The ids above which nodes and symbols are the checker thread's own (lazily parsed JSDoc), or Infinity. */
172
+ nodeLimit = Infinity;
173
+ symbolLimit = Infinity;
174
+ constructor(c, initial) {
175
+ this.c = c;
176
+ this.initial = initial;
177
+ }
178
+ /** Whether `node` is one every checker shares; fails if not. */
179
+ sharedNode(node) {
180
+ if (node === undefined || node.id <= this.nodeLimit)
181
+ return true;
182
+ this.fail('node of the thread');
183
+ return false;
184
+ }
185
+ /** The ids of the symbols each merged symbol merged (`getMergedSymbol`), built on first use. */
186
+ mergedOrigins = undefined;
187
+ /** Where the checker keeps `mergedOrigins` between exports. */
188
+ originsCache = undefined;
189
+ /**
190
+ * Sets the symbol of `record`: a symbol of the program, which every checker shares, or a symbol the checker merged,
191
+ * by the id of a symbol it merged. Other symbols are the checker's own.
192
+ */
193
+ symbolOf(record, symbol, alias) {
194
+ let mergedId = -1;
195
+ let shared = symbol;
196
+ if ((symbol.flags & 33554432 /* SymbolFlags.Transient */) === 0 && getSymbolId(symbol) > this.symbolLimit) {
197
+ this.fail('symbol of the thread');
198
+ return false;
199
+ }
200
+ if ((symbol.flags & 33554432 /* SymbolFlags.Transient */) !== 0) {
201
+ let origins = this.mergedOrigins;
202
+ if (origins === undefined) {
203
+ const cache = this.originsCache;
204
+ if (cache !== undefined && cache.size === this.c.mergedSymbols.size)
205
+ origins = cache.origins;
206
+ else {
207
+ origins = new Map();
208
+ for (const [id, target] of this.c.mergedSymbols)
209
+ if (!origins.has(target))
210
+ origins.set(target, id);
211
+ if (cache !== undefined) {
212
+ cache.origins = origins;
213
+ cache.size = this.c.mergedSymbols.size;
214
+ }
215
+ }
216
+ this.mergedOrigins = origins;
217
+ }
218
+ const origin = origins.get(symbol);
219
+ if (origin === undefined) {
220
+ this.fail('checker symbol ' + symbol.name);
221
+ return false;
222
+ }
223
+ mergedId = origin;
224
+ shared = undefined;
225
+ }
226
+ if (alias) {
227
+ record.aliasSymbol = shared;
228
+ record.aliasMergedId = mergedId;
229
+ }
230
+ else {
231
+ record.symbol = shared;
232
+ record.mergedId = mergedId;
233
+ }
234
+ return true;
235
+ }
236
+ /** `new PortableRecord` with the symbol `symbol` (see `symbolOf`); undefined if it is the checker's own. */
237
+ withSymbol(kind, t, symbol, num, refs) {
238
+ const record = new PortableRecord(kind, t.id, 0, num, '', undefined, undefined, refs);
239
+ return this.symbolOf(record, symbol, false) ? record : undefined;
240
+ }
241
+ addWithSymbol(kind, t, symbol, num, refs) {
242
+ const record = this.withSymbol(kind, t, symbol, num, refs);
243
+ return record === undefined ? -1 : this.add(t, record);
244
+ }
245
+ fail(reason) {
246
+ if (this.failure === undefined)
247
+ this.failure = reason;
248
+ return -1;
249
+ }
250
+ add(t, record) {
251
+ if (!this.sharedNode(record.node))
252
+ return -1;
253
+ for (const node of record.nodes)
254
+ if (!this.sharedNode(node))
255
+ return -1;
256
+ for (const info of record.indexInfos) {
257
+ if (!this.sharedNode(info.declaration))
258
+ return -1;
259
+ for (const node of info.components)
260
+ if (!this.sharedNode(node))
261
+ return -1;
262
+ }
263
+ const index = this.push(record);
264
+ this.indexes.set(t, index);
265
+ this.addedTypes.push(t);
266
+ return index;
267
+ }
268
+ types(list) {
269
+ const refs = [];
270
+ for (const t of list) {
271
+ refs.push(this.type(t));
272
+ if (this.failure !== undefined)
273
+ break;
274
+ }
275
+ return refs;
276
+ }
277
+ aliasOf(record, alias) {
278
+ if (alias === undefined)
279
+ return record;
280
+ const refs = this.types(alias.typeArguments);
281
+ this.symbolOf(record, alias.symbol, true);
282
+ record.aliasRefs = refs;
283
+ return record;
284
+ }
285
+ type(t) {
286
+ if (this.failure !== undefined)
287
+ return -1;
288
+ const known = this.indexes.get(t);
289
+ if (known !== undefined)
290
+ return known;
291
+ const initial = this.initial.get(t);
292
+ if (initial !== undefined)
293
+ return this.add(t, new PortableRecord(0 /* RecordKind.Initial */, t.id, 0, initial, '', undefined, undefined, noNumbers));
294
+ const c = this.c;
295
+ const flags = t.flags;
296
+ if ((flags & 15360 /* TypeFlags.Literal */) !== 0 && (flags & 256 /* TypeFlags.Boolean */) === 0)
297
+ return this.literal(t);
298
+ if ((flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0) {
299
+ if (c.uniqueESSymbolTypes.get(t.symbol) !== t)
300
+ return this.fail('unique symbol');
301
+ return this.addWithSymbol(4 /* RecordKind.UniqueSymbol */, t, t.symbol, 0, noNumbers);
302
+ }
303
+ if ((flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
304
+ const symbol = t.symbol;
305
+ if (symbol === undefined)
306
+ return this.fail('type parameter without a symbol');
307
+ const declared = getDeclaredTypeOfSymbol(c, symbol);
308
+ if (declared === t)
309
+ return this.addWithSymbol(5 /* RecordKind.Declared */, t, symbol, 0, noNumbers);
310
+ if ((declared.objectFlags & 3 /* ObjectFlags.ClassOrInterface */) !== 0 && declared.thisType === t)
311
+ return this.addWithSymbol(6 /* RecordKind.ThisType */, t, symbol, 0, noNumbers);
312
+ return this.fail('fresh type parameter');
313
+ }
314
+ if (t.symbol !== undefined && (flags & (134217728 /* TypeFlags.Union */ | 65536 /* TypeFlags.Enum */)) !== 0) {
315
+ // An enum type: the declared type of its symbol.
316
+ if (getDeclaredTypeOfSymbol(c, t.symbol) !== t)
317
+ return this.fail('enum type');
318
+ return this.addWithSymbol(5 /* RecordKind.Declared */, t, t.symbol, 0, noNumbers);
319
+ }
320
+ if ((flags & 134217728 /* TypeFlags.Union */) !== 0)
321
+ return this.union(t);
322
+ if ((flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
323
+ const refs = this.types(t.types);
324
+ if (this.failure !== undefined)
325
+ return -1;
326
+ const record = new PortableRecord(13 /* RecordKind.Intersection */, t.id, t.objectFlags, 0, '', undefined, undefined, refs);
327
+ return this.add(t, this.aliasOf(record, t.alias));
328
+ }
329
+ if ((flags & 1048576 /* TypeFlags.Object */) !== 0)
330
+ return this.object(t);
331
+ if ((flags & 2097152 /* TypeFlags.Index */) !== 0) {
332
+ const target = this.type(t.target);
333
+ if (this.failure !== undefined)
334
+ return -1;
335
+ return this.add(t, new PortableRecord(14 /* RecordKind.Index */, t.id, 0, t.indexFlags, '', undefined, undefined, [target]));
336
+ }
337
+ if ((flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
338
+ const access = t;
339
+ const refs = this.types([access.objectType, access.indexType]);
340
+ if (this.failure !== undefined)
341
+ return -1;
342
+ const record = new PortableRecord(15 /* RecordKind.IndexedAccess */, t.id, 0, this.c.indexedAccessKeyFlags.get(t) ?? access.accessFlags, '', undefined, undefined, refs);
343
+ return this.add(t, this.aliasOf(record, t.alias));
344
+ }
345
+ if ((flags & 67108864 /* TypeFlags.Conditional */) !== 0)
346
+ return this.conditional(t);
347
+ if ((flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0) {
348
+ const template = t;
349
+ const refs = this.types(template.types);
350
+ if (this.failure !== undefined)
351
+ return -1;
352
+ const record = new PortableRecord(17 /* RecordKind.Template */, t.id, 0, 0, '', undefined, undefined, refs);
353
+ record.texts = template.texts.slice();
354
+ return this.add(t, record);
355
+ }
356
+ if ((flags & 8388608 /* TypeFlags.StringMapping */) !== 0) {
357
+ const target = this.type(t.target);
358
+ if (this.failure !== undefined)
359
+ return -1;
360
+ return this.addWithSymbol(18 /* RecordKind.StringMapping */, t, t.symbol, 0, [target]);
361
+ }
362
+ if ((flags & 16777216 /* TypeFlags.Substitution */) !== 0) {
363
+ const substitution = t;
364
+ if (isNoInferType(c, t)) {
365
+ const base = this.type(substitution.baseType);
366
+ if (this.failure !== undefined)
367
+ return -1;
368
+ return this.add(t, new PortableRecord(20 /* RecordKind.NoInfer */, t.id, 0, 0, '', undefined, undefined, [base]));
369
+ }
370
+ const refs = this.types([substitution.baseType, substitution.constraint]);
371
+ if (this.failure !== undefined)
372
+ return -1;
373
+ return this.add(t, new PortableRecord(19 /* RecordKind.Substitution */, t.id, 0, 0, '', undefined, undefined, refs));
374
+ }
375
+ return this.fail('type flags ' + flags);
376
+ }
377
+ literal(t) {
378
+ const regular = t.regularType;
379
+ if (regular !== t) {
380
+ if (regular.freshType !== t)
381
+ return this.fail('literal');
382
+ const index = this.type(regular);
383
+ if (this.failure !== undefined)
384
+ return -1;
385
+ return this.add(t, new PortableRecord(2 /* RecordKind.FreshLiteral */, t.id, 0, 0, '', undefined, undefined, [index]));
386
+ }
387
+ if (t.symbol !== undefined) {
388
+ if (getDeclaredTypeOfSymbol(this.c, t.symbol) !== t)
389
+ return this.fail('enum literal');
390
+ return this.addWithSymbol(3 /* RecordKind.EnumLiteral */, t, t.symbol, 0, noNumbers);
391
+ }
392
+ return this.add(t, new PortableRecord(1 /* RecordKind.Literal */, t.id, t.flags, t.numberValue, t.stringValue, undefined, undefined, noNumbers));
393
+ }
394
+ union(t) {
395
+ const refs = this.types(t.types);
396
+ let origin = -1;
397
+ if (t.origin !== undefined) {
398
+ const o = t.origin;
399
+ if ((o.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
400
+ // Origins are not interned: a union key spells their constituents.
401
+ const parts = this.types(o.types);
402
+ if (this.failure !== undefined)
403
+ return -1;
404
+ const kind = (o.flags & 134217728 /* TypeFlags.Union */) !== 0 ? 12 /* RecordKind.Union */ : 13 /* RecordKind.Intersection */;
405
+ origin = this.push(new PortableRecord(kind, -1, o.objectFlags, -2, '', undefined, undefined, parts));
406
+ }
407
+ else
408
+ origin = this.type(o);
409
+ }
410
+ if (this.failure !== undefined)
411
+ return -1;
412
+ const record = new PortableRecord(12 /* RecordKind.Union */, t.id, t.objectFlags, origin, '', undefined, undefined, refs);
413
+ return this.add(t, this.aliasOf(record, t.alias));
414
+ }
415
+ object(t) {
416
+ const c = this.c;
417
+ const objectFlags = t.objectFlags;
418
+ const symbol = t.symbol;
419
+ if ((objectFlags & 4 /* ObjectFlags.Reference */) !== 0) {
420
+ const reference = t;
421
+ if (reference.node !== undefined)
422
+ return this.instantiation(t);
423
+ const target = reference.target;
424
+ if (target === t) {
425
+ if ((objectFlags & 8 /* ObjectFlags.Tuple */) !== 0)
426
+ return this.tupleTarget(t);
427
+ if (symbol === undefined || getDeclaredTypeOfSymbol(c, symbol) !== t)
428
+ return this.fail('generic target');
429
+ return this.addWithSymbol(5 /* RecordKind.Declared */, t, symbol, 0, noNumbers);
430
+ }
431
+ const refs = [this.type(target), ...this.types(reference.resolvedTypeArguments ?? [])];
432
+ if (this.failure !== undefined)
433
+ return -1;
434
+ return this.add(t, new PortableRecord(9 /* RecordKind.Reference */, t.id, 0, 0, '', undefined, undefined, refs));
435
+ }
436
+ if ((objectFlags & 3 /* ObjectFlags.ClassOrInterface */) !== 0) {
437
+ if (symbol === undefined || getDeclaredTypeOfSymbol(c, symbol) !== t)
438
+ return this.fail('declared type');
439
+ return this.addWithSymbol(5 /* RecordKind.Declared */, t, symbol, 0, noNumbers);
440
+ }
441
+ if ((objectFlags & (1024 /* ObjectFlags.ReverseMapped */ | 256 /* ObjectFlags.EvolvingArray */)) !== 0)
442
+ return this.fail('object kind');
443
+ if ((objectFlags & 64 /* ObjectFlags.Instantiated */) !== 0)
444
+ return this.instantiation(t);
445
+ if ((objectFlags & (16 /* ObjectFlags.Anonymous */ | 32 /* ObjectFlags.Mapped */)) === 0 || symbol === undefined)
446
+ return this.fail('object without a declaration, object flags ' + objectFlags);
447
+ // The anonymous type of a function, class, enum or module; a variable's own type is what is being shared.
448
+ if ((symbol.flags & sharedValueFlags()) === 0 && c.symbolTypes.get(getSymbolId(symbol)) === t)
449
+ return this.addWithSymbol(7 /* RecordKind.SymbolType */, t, symbol, 0, noNumbers);
450
+ const declaration = (objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 ? t.declaration : symbol.declaration;
451
+ if (declaration !== undefined && c.resolvedTypes.get(declaration.id) === t)
452
+ return this.add(t, new PortableRecord(8 /* RecordKind.NodeType */, t.id, 0, 0, '', undefined, declaration, noNumbers));
453
+ if ((symbol.flags & 4096 /* SymbolFlags.ObjectLiteral */) !== 0 &&
454
+ (objectFlags & (16 /* ObjectFlags.Anonymous */ | 2097152 /* ObjectFlags.MembersResolved */)) ===
455
+ (16 /* ObjectFlags.Anonymous */ | 2097152 /* ObjectFlags.MembersResolved */))
456
+ return this.anonymousObject(t);
457
+ return this.fail('anonymous type ' +
458
+ ((objectFlags & 128 /* ObjectFlags.ObjectLiteral */) !== 0 ? 'object literal ' : '') +
459
+ 'symbol flags ' +
460
+ symbol.flags +
461
+ ' declaration kind ' +
462
+ (symbol.declaration?.kind ?? -1) +
463
+ ' object flags ' +
464
+ objectFlags);
465
+ }
466
+ /** An object literal type, or one made from one, with its properties and index infos. */
467
+ anonymousObject(t) {
468
+ const c = this.c;
469
+ if ((t.objectFlags & -2147483648 /* ObjectFlags.SideState */) !== 0 || c.patternForType.has(t))
470
+ return this.fail('object literal state');
471
+ const resolved = t;
472
+ if (resolved.callSignatures.length !== 0 || resolved.constructSignatures.length !== 0)
473
+ return this.fail('object literal signatures');
474
+ const shell = new PortableRecord(22 /* RecordKind.AnonymousObject */, t.id, t.objectFlags & ~lazyObjectFlags(), 0, '', undefined, undefined, noNumbers);
475
+ if (!this.symbolOf(shell, t.symbol, false))
476
+ return -1;
477
+ const index = this.add(t, shell);
478
+ const members = [];
479
+ for (const prop of resolved.properties) {
480
+ members.push(this.property(prop));
481
+ if (this.failure !== undefined)
482
+ return -1;
483
+ }
484
+ const infos = [];
485
+ for (const info of resolved.indexInfos) {
486
+ const key = this.type(info.keyType);
487
+ const value = this.type(info.valueType);
488
+ if (this.failure !== undefined)
489
+ return -1;
490
+ infos.push(new PortableIndexInfo(key, value, info.isReadonly, info.declaration, info.components.slice()));
491
+ }
492
+ const complete = new PortableRecord(23 /* RecordKind.CompleteObject */, -1, 0, index, '', undefined, undefined, members);
493
+ complete.indexInfos = infos;
494
+ this.push(complete);
495
+ return index;
496
+ }
497
+ /** The records of property symbols, by symbol. */
498
+ properties = new Map();
499
+ /** A property symbol of an object literal type: a checker's own, made from one of the program or from another. */
500
+ property(prop) {
501
+ const known = this.properties.get(prop);
502
+ if (known !== undefined)
503
+ return known;
504
+ const c = this.c;
505
+ if ((prop.flags & 33554432 /* SymbolFlags.Transient */) === 0)
506
+ return this.fail('property of the program');
507
+ if ((prop.checkFlags & ~(8 /* CheckFlags.Readonly */ | 32768 /* CheckFlags.Late */)) !== 0)
508
+ return this.fail('property check flags ' + prop.checkFlags);
509
+ const id = getSymbolId(prop);
510
+ const t = c.symbolTypes.get(id);
511
+ if (t === undefined)
512
+ return this.fail('property without a type');
513
+ const type = this.type(t);
514
+ const nameType = c.symbolNameTypes.get(id);
515
+ const name = nameType === undefined ? -1 : this.type(nameType);
516
+ if (this.failure !== undefined)
517
+ return -1;
518
+ const source = c.symbolTargets.get(id);
519
+ let target = -1;
520
+ let program = undefined;
521
+ if (source !== undefined) {
522
+ if ((source.flags & 33554432 /* SymbolFlags.Transient */) !== 0) {
523
+ target = this.property(source);
524
+ if (this.failure !== undefined)
525
+ return -1;
526
+ }
527
+ else
528
+ program = source;
529
+ }
530
+ const record = new PortableRecord(24 /* RecordKind.Property */, -1, prop.flags, prop.checkFlags, prop.name, program, prop.valueDeclaration, [type, name, target]);
531
+ record.nodes = getDeclarations(prop).slice();
532
+ if (prop.parent !== undefined && !this.symbolOf(record, prop.parent, true))
533
+ return -1;
534
+ if (program !== undefined && getSymbolId(program) > this.symbolLimit)
535
+ return this.fail('symbol of the thread');
536
+ if (!this.sharedNode(prop.valueDeclaration))
537
+ return -1;
538
+ for (const node of record.nodes)
539
+ if (!this.sharedNode(node))
540
+ return -1;
541
+ const index = this.push(record);
542
+ this.properties.set(prop, index);
543
+ this.addedProperties.push(prop);
544
+ return index;
545
+ }
546
+ tupleTarget(t) {
547
+ const record = new PortableRecord(10 /* RecordKind.TupleTarget */, t.id, 0, t.readonly ? 1 : 0, '', undefined, undefined, noNumbers);
548
+ const nums = [];
549
+ const nodes = [];
550
+ for (const info of t.elementInfos) {
551
+ nums.push(info.flags);
552
+ nodes.push(info.labeledDeclaration);
553
+ }
554
+ record.nums = nums;
555
+ record.nodes = nodes;
556
+ return this.add(t, record);
557
+ }
558
+ /** An instantiated anonymous or mapped type, or a deferred type reference: its target and outer type arguments. */
559
+ instantiation(t) {
560
+ const c = this.c;
561
+ const objectFlags = t.objectFlags;
562
+ if ((objectFlags & 33554432 /* ObjectFlags.SingleSignatureType */) !== 0)
563
+ return this.fail('single signature type');
564
+ let declaration;
565
+ let target;
566
+ if ((objectFlags & 4 /* ObjectFlags.Reference */) !== 0) {
567
+ declaration = t.node;
568
+ target = c.resolvedTypes.get(declaration.id);
569
+ if (target === undefined)
570
+ return this.fail('deferred reference');
571
+ }
572
+ else {
573
+ if ((objectFlags & 16777216 /* ObjectFlags.InstantiationExpressionType */) !== 0)
574
+ return this.fail('instantiation expression');
575
+ declaration = t.symbol?.declaration;
576
+ target = t.target;
577
+ }
578
+ if (declaration !== undefined && t.mapper === undefined && c.resolvedTypes.get(declaration.id) === t)
579
+ return this.add(t, new PortableRecord(8 /* RecordKind.NodeType */, t.id, 0, 0, '', undefined, declaration, noNumbers));
580
+ if (declaration === undefined || target === undefined || t.mapper === undefined)
581
+ return this.fail('instantiation, declaration ' + (declaration?.kind ?? -1) + ' target ' + (target !== undefined));
582
+ const typeParameters = c.nodeLinks(declaration).outerTypeParameters;
583
+ if (typeParameters === undefined)
584
+ return this.fail('instantiation without type parameters');
585
+ const args = [];
586
+ for (const tp of typeParameters)
587
+ args.push(getMappedType(tp, t.mapper));
588
+ const generic = sideOf(c, target);
589
+ if (generic.instantiations?.get(typeListHash(args, t.alias, 0), args, t.alias, 0) !== t)
590
+ return this.fail('instantiation not found');
591
+ const refs = [this.type(target), ...this.types(args)];
592
+ if (this.failure !== undefined)
593
+ return -1;
594
+ const record = new PortableRecord(11 /* RecordKind.Instantiation */, t.id, 0, args.length, '', undefined, declaration, refs);
595
+ const index = this.add(t, this.aliasOf(record, t.alias));
596
+ // Only for an export that hasn't failed (its alias may have): optionalType would forget that failure.
597
+ if (index >= 0 && this.failure === undefined)
598
+ this.resolvedReturnTypes(t, refs);
599
+ return index;
600
+ }
601
+ /**
602
+ * Adds to `refs` the return types the checker resolved for the signatures of the instantiation `t`, exported after
603
+ * it. The consumer then creates them right after `t` and before the types that contain it, as this checker did:
604
+ * inference stops at references whose type ids grow along its stack (`isDeeplyNestedType`), so a consumer that
605
+ * created them later, when it resolved them, could stop an inference this checker made.
606
+ */
607
+ resolvedReturnTypes(t, refs) {
608
+ if ((t.objectFlags & 2097152 /* ObjectFlags.MembersResolved */) === 0)
609
+ return;
610
+ for (const signatures of [t.callSignatures, t.constructSignatures])
611
+ for (const signature of signatures) {
612
+ const returnType = resolvedReturnTypeOf(this.c, signature);
613
+ if (returnType === undefined)
614
+ continue;
615
+ const index = this.optionalType(returnType);
616
+ if (index >= 0)
617
+ refs.push(index);
618
+ }
619
+ }
620
+ /**
621
+ * The record of `t`, or -1 if it can't be exported; that leaves the export in progress as it was. An export that
622
+ * failed before stays failed.
623
+ */
624
+ optionalType(t) {
625
+ if (this.failure !== undefined)
626
+ return -1;
627
+ const records = this.records.length;
628
+ const types = this.addedTypes.length;
629
+ const properties = this.addedProperties.length;
630
+ const index = this.type(t);
631
+ if (this.failure === undefined)
632
+ return index;
633
+ for (let i = types; i < this.addedTypes.length; i++)
634
+ this.indexes.delete(this.addedTypes[i]);
635
+ for (let i = properties; i < this.addedProperties.length; i++)
636
+ this.properties.delete(this.addedProperties[i]);
637
+ this.addedTypes.length = types;
638
+ this.addedProperties.length = properties;
639
+ this.records.length = records;
640
+ this.failure = undefined;
641
+ return -1;
642
+ }
643
+ conditional(t) {
644
+ const root = t.root;
645
+ if (t.mapper === undefined) {
646
+ if (this.c.resolvedTypes.get(root.node.id) !== t)
647
+ return this.fail('conditional type');
648
+ return this.add(t, new PortableRecord(8 /* RecordKind.NodeType */, t.id, 0, 0, '', undefined, root.node, noNumbers));
649
+ }
650
+ const args = [];
651
+ for (const tp of root.outerTypeParameters)
652
+ args.push(getMappedType(tp, t.mapper));
653
+ let tag = -1;
654
+ for (let k = 0; k < 2 && tag < 0; k++)
655
+ if (root.instantiations.get(typeListHash(args, t.alias, k), args, t.alias, k) === t)
656
+ tag = k;
657
+ if (tag < 0) {
658
+ const keyed = this.c.conditionalResults?.get(t);
659
+ if (keyed !== undefined) {
660
+ const refs = this.types(keyed.typeArguments);
661
+ if (this.failure !== undefined)
662
+ return -1;
663
+ const record = new PortableRecord(16 /* RecordKind.Conditional */, t.id, 0, keyed.tag, '', undefined, keyed.root.node, refs);
664
+ return this.add(t, this.aliasOf(record, keyed.alias));
665
+ }
666
+ const distributed = this.c.distributedConditionals?.get(t);
667
+ if (distributed === undefined)
668
+ return this.fail('conditional instantiation not found');
669
+ const refs = this.types([...distributed.typeArguments, distributed.constituent]);
670
+ if (this.failure !== undefined)
671
+ return -1;
672
+ const record = new PortableRecord(21 /* RecordKind.DistributedConditional */, t.id, 0, distributed.tag, '', undefined, root.node, refs);
673
+ return this.add(t, this.aliasOf(record, distributed.alias));
674
+ }
675
+ const refs = this.types(args);
676
+ if (this.failure !== undefined)
677
+ return -1;
678
+ const record = new PortableRecord(16 /* RecordKind.Conditional */, t.id, 0, tag, '', undefined, root.node, refs);
679
+ return this.add(t, this.aliasOf(record, t.alias));
680
+ }
681
+ }
682
+ /** Object flags that checkers compute after creating a type (a function: see `sharedValueFlags`). */
683
+ function lazyObjectFlags() {
684
+ return (524288 /* ObjectFlags.CouldContainTypeVariablesComputed */ |
685
+ 1048576 /* ObjectFlags.CouldContainTypeVariables */ |
686
+ 2097152 /* ObjectFlags.MembersResolved */ |
687
+ -2147483648 /* ObjectFlags.SideState */ |
688
+ 134217728 /* ObjectFlags.IdenticalBaseTypeCalculated */ |
689
+ 268435456 /* ObjectFlags.IdenticalBaseTypeExists */);
690
+ }
691
+ /** Translates records into a checker's own types; one translation per producer type. */
692
+ export class Translator {
693
+ c;
694
+ translated = new Map();
695
+ initial;
696
+ /** Set when a record has no counterpart here; the translation is then abandoned. */
697
+ failed = false;
698
+ constructor(c) {
699
+ this.c = c;
700
+ this.initial = initialTypes(c);
701
+ }
702
+ /** A property symbol made as the producer made it. */
703
+ property(r, types, symbols) {
704
+ const c = this.c;
705
+ const prop = c.newSymbolWithCheckFlags(r.flags & ~33554432 /* SymbolFlags.Transient */, r.text, r.num);
706
+ setDeclarations(prop, r.nodes);
707
+ prop.valueDeclaration = r.node;
708
+ if (r.aliasSymbol !== undefined || r.aliasMergedId >= 0)
709
+ prop.parent = r.aliasMergedId >= 0 ? c.mergedSymbols.get(r.aliasMergedId) : r.aliasSymbol;
710
+ const id = getSymbolId(prop);
711
+ c.symbolTypes.set(id, types[r.refs[0]]);
712
+ if (r.refs[1] >= 0)
713
+ c.symbolNameTypes.set(id, types[r.refs[1]]);
714
+ const target = r.refs[2] >= 0 ? symbols[r.refs[2]] : r.symbol;
715
+ if (target !== undefined)
716
+ c.symbolTargets.set(id, target);
717
+ return prop;
718
+ }
719
+ /** Sets the members of the `AnonymousObject` record a `CompleteObject` record completes. */
720
+ complete(r, types, symbols) {
721
+ const c = this.c;
722
+ const t = types[r.num];
723
+ if ((t.objectFlags & 2097152 /* ObjectFlags.MembersResolved */) !== 0)
724
+ return;
725
+ const members = new Map();
726
+ for (const i of r.refs) {
727
+ const prop = symbols[i];
728
+ members.set(prop.name, prop);
729
+ }
730
+ const infos = r.indexInfos.map((info) => new IndexInfo(types[info.keyType], types[info.valueType], info.isReadonly, info.declaration, info.components));
731
+ setStructuredTypeMembers(c, t, members, [], [], infos);
732
+ keepPropertiesOnly(c, t, members, scannedLiteralPropertiesLimit);
733
+ }
734
+ record(r, types) {
735
+ if (r.id >= 0) {
736
+ const known = this.translated.get(r.id);
737
+ if (known !== undefined)
738
+ return known;
739
+ }
740
+ const t = this.build(r, types);
741
+ if (r.id >= 0 && !this.failed)
742
+ this.translated.set(r.id, t);
743
+ return t;
744
+ }
745
+ /**
746
+ * Resolves the declared type of the type alias whose declaration contains the type node `node`, as resolving its
747
+ * nodes through the alias does: that records the alias's type parameters, which its variances are measured with.
748
+ * Sets `failed` if the alias's declared type is being resolved here.
749
+ */
750
+ aliasOfNode(node) {
751
+ const c = this.c;
752
+ for (let n = node; n !== undefined; n = n.parent) {
753
+ if (n.kind !== 267 /* SyntaxKind.TypeAliasDeclaration */ && n.kind !== 346 /* SyntaxKind.JSTypeAliasDeclaration */)
754
+ continue;
755
+ const symbol = getSymbol(n);
756
+ if (symbol === undefined || c.symbolLinks(symbol).declaredType !== undefined)
757
+ return;
758
+ if (findResolutionCycleStartIndex(c, symbol, 2 /* TypeSystemPropertyName.DeclaredType */) >= 0)
759
+ this.failed = true;
760
+ else
761
+ getDeclaredTypeOfSymbol(c, symbol);
762
+ return;
763
+ }
764
+ }
765
+ alias(r, types) {
766
+ if (r.aliasSymbol === undefined && r.aliasMergedId < 0)
767
+ return undefined;
768
+ const symbol = r.aliasMergedId >= 0 ? this.c.mergedSymbols.get(r.aliasMergedId) : r.aliasSymbol;
769
+ // An instantiation of an alias follows its declared type, which records the alias's type parameters.
770
+ getDeclaredTypeOfSymbol(this.c, symbol);
771
+ return new TypeAlias(symbol, r.aliasRefs.map((i) => types[i]));
772
+ }
773
+ symbol(r) {
774
+ return r.mergedId >= 0 ? this.c.mergedSymbols.get(r.mergedId) : r.symbol;
775
+ }
776
+ build(r, types) {
777
+ const c = this.c;
778
+ // An instantiation's refs end with the return types of its signatures, which are built after it.
779
+ const own = r.kind === 11 /* RecordKind.Instantiation */ ? r.refs.slice(0, 1 + r.num) : r.refs;
780
+ const refs = own.map((i) => types[i]);
781
+ switch (r.kind) {
782
+ case 0 /* RecordKind.Initial */:
783
+ return this.initial[r.num];
784
+ case 1 /* RecordKind.Literal */:
785
+ if ((r.flags & 1024 /* TypeFlags.StringLiteral */) !== 0)
786
+ return getStringLiteralType(c, r.text);
787
+ if ((r.flags & 2048 /* TypeFlags.NumberLiteral */) !== 0)
788
+ return getNumberLiteralType(c, r.num);
789
+ return getBigIntLiteralType(c, r.text);
790
+ case 2 /* RecordKind.FreshLiteral */:
791
+ return getFreshTypeOfLiteralType(c, refs[0]);
792
+ case 3 /* RecordKind.EnumLiteral */:
793
+ case 5 /* RecordKind.Declared */:
794
+ return getDeclaredTypeOfSymbol(c, this.symbol(r));
795
+ case 6 /* RecordKind.ThisType */:
796
+ return getDeclaredTypeOfSymbol(c, this.symbol(r)).thisType;
797
+ case 4 /* RecordKind.UniqueSymbol */:
798
+ return getESSymbolLikeTypeForNode(c, this.symbol(r).valueDeclaration);
799
+ case 7 /* RecordKind.SymbolType */:
800
+ return getTypeOfSymbol(c, this.symbol(r));
801
+ case 8 /* RecordKind.NodeType */: {
802
+ const node = r.node;
803
+ const cached = c.resolvedTypes.get(node.id);
804
+ if (cached !== undefined)
805
+ return cached;
806
+ this.aliasOfNode(node);
807
+ if (this.failed)
808
+ return c.errorType;
809
+ const t = getTypeFromTypeNode(c, node);
810
+ return c.resolvedTypes.get(node.id) ?? t;
811
+ }
812
+ case 9 /* RecordKind.Reference */:
813
+ return createTypeReference(c, refs[0], refs.slice(1));
814
+ case 10 /* RecordKind.TupleTarget */: {
815
+ const infos = [];
816
+ for (let i = 0; i < r.nums.length; i++)
817
+ infos.push(new TupleElementInfo(r.nums[i], r.nodes[i]));
818
+ return getTupleTargetType(c, infos, r.num === 1);
819
+ }
820
+ case 11 /* RecordKind.Instantiation */: {
821
+ const target = refs[0];
822
+ const typeParameters = outerTypeParametersOf(c, r.node, target);
823
+ return instantiateTypeWithAlias(c, target, newTypeMapper(typeParameters, refs.slice(1, 1 + r.num)), this.alias(r, types));
824
+ }
825
+ case 12 /* RecordKind.Union */: {
826
+ if (r.num === -2)
827
+ return newUnionType(c, r.flags & 0 /* ObjectFlags.None */, refs);
828
+ const origin = r.num >= 0 ? types[r.num] : undefined;
829
+ return getUnionTypeFromSortedList(c, refs, r.flags & (32768 /* ObjectFlags.PrimitiveUnion */ | 33554432 /* ObjectFlags.ContainsIntersections */), this.alias(r, types), origin);
830
+ }
831
+ case 13 /* RecordKind.Intersection */: {
832
+ if (r.num === -2)
833
+ return newIntersectionType(c, 0 /* ObjectFlags.None */, refs);
834
+ const alias = this.alias(r, types);
835
+ const hash = typeListHash(refs, alias, 0);
836
+ const existing = c.intersectionTypes.get(hash, refs, alias, 0);
837
+ if (existing !== undefined)
838
+ return existing;
839
+ const result = newIntersectionType(c, (r.flags & 134217728 /* ObjectFlags.IsConstrainedTypeVariable */) | getPropagatingFlagsOfTypes(refs, 12 /* TypeFlags.Nullable */), refs);
840
+ result.alias = alias;
841
+ c.intersectionTypes.set(hash, refs, alias, 0, result);
842
+ return result;
843
+ }
844
+ case 14 /* RecordKind.Index */:
845
+ return getIndexTypeEx(c, refs[0], r.num);
846
+ case 15 /* RecordKind.IndexedAccess */:
847
+ return getIndexedAccessTypeEx(c, refs[0], refs[1], r.num, undefined, this.alias(r, types));
848
+ case 16 /* RecordKind.Conditional */: {
849
+ this.aliasOfNode(r.node);
850
+ if (this.failed)
851
+ return c.errorType;
852
+ const declared = c.resolvedTypes.get(r.node.id) ?? getTypeFromTypeNode(c, r.node);
853
+ const root = declared.root;
854
+ return getConditionalTypeInstantiation(c, declared, newTypeMapper(root.outerTypeParameters, refs), r.num === 1, this.alias(r, types));
855
+ }
856
+ case 21 /* RecordKind.DistributedConditional */: {
857
+ this.aliasOfNode(r.node);
858
+ if (this.failed)
859
+ return c.errorType;
860
+ const declared = (c.resolvedTypes.get(r.node.id) ?? getTypeFromTypeNode(c, r.node));
861
+ const root = declared.root;
862
+ const args = refs.slice(0, refs.length - 1);
863
+ const alias = this.alias(r, types);
864
+ getConditionalTypeInstantiation(c, declared, newTypeMapper(root.outerTypeParameters, args), r.num === 1, alias);
865
+ const member = c.distributedByKey?.get(distributedKey(root.node.id, args, alias, r.num, refs[refs.length - 1]));
866
+ if (member === undefined)
867
+ this.failed = true;
868
+ return member ?? c.errorType;
869
+ }
870
+ case 17 /* RecordKind.Template */:
871
+ return getTemplateLiteralType(c, r.texts.slice(), refs);
872
+ case 18 /* RecordKind.StringMapping */:
873
+ return getStringMappingType(c, this.symbol(r), refs[0]);
874
+ case 19 /* RecordKind.Substitution */:
875
+ return getSubstitutionType(c, refs[0], refs[1]);
876
+ case 20 /* RecordKind.NoInfer */:
877
+ return getNoInferType(c, refs[0]);
878
+ case 22 /* RecordKind.AnonymousObject */:
879
+ return newObjectType(c, r.flags | 16 /* ObjectFlags.Anonymous */, this.symbol(r));
880
+ case 23 /* RecordKind.CompleteObject */:
881
+ case 24 /* RecordKind.Property */:
882
+ return c.errorType;
883
+ }
884
+ }
885
+ }
886
+ /** The outer type parameters an instantiation of `target` (declared at `declaration`) maps, as instantiation computes them. */
887
+ function outerTypeParametersOf(c, declaration, target) {
888
+ const known = c.nodeLinks(declaration).outerTypeParameters;
889
+ if (known !== undefined)
890
+ return known;
891
+ // The first instantiation records them; an identity instantiation computes them without creating a type.
892
+ const probe = c.nodeLinks(declaration);
893
+ instantiateTypeWithAlias(c, target, newTypeMapper([c.anyType], [c.anyType]), undefined);
894
+ return probe.outerTypeParameters ?? [];
895
+ }
896
+ /** Whether the type of `symbol` is shared: a variable or property declared in the program, other than parameters. */
897
+ export function isSharedValueSymbol(symbol) {
898
+ if (symbol.checkFlags !== 0 || (symbol.flags & 33554432 /* SymbolFlags.Transient */) !== 0)
899
+ return false;
900
+ if ((symbol.flags & sharedValueFlags()) === 0)
901
+ return false;
902
+ const declaration = symbol.valueDeclaration;
903
+ return (declaration !== undefined &&
904
+ declaration.kind !== 171 /* SyntaxKind.Parameter */ &&
905
+ declaration.kind !== 210 /* SyntaxKind.BindingElement */);
906
+ }
907
+ /** Whether the return type of `sig` is shared: the signature of a declaration, as `getSignatureFromDeclaration` makes it. */
908
+ export function isSharedReturnSignature(c, sig) {
909
+ const declaration = sig.declaration;
910
+ return (declaration !== undefined &&
911
+ sig.target === undefined &&
912
+ sig.composite === undefined &&
913
+ (sig.flags & (16 /* SignatureFlags.IsInnerCallChain */ | 32 /* SignatureFlags.IsOuterCallChain */)) === 0 &&
914
+ c.resolvedSignatures.get(declaration.id) === sig);
915
+ }
916
+ // ---- Sharing between checker threads (TSC_TS_SHARE=1)
917
+ //
918
+ // Checker threads take files from the shared queue as without sharing, and record which checker took each file
919
+ // (`ThreadSharingData.takers`). When a checker needs the value type of a variable or property, or the return type of a
920
+ // declared signature, declared in a file another checker took, it looks the declaration up in a table all threads
921
+ // share (`ResultTable`): a result another checker posted is translated, unless that checker's computation reported
922
+ // diagnostics in a file this one checks or may check; otherwise the checker computes the result itself. After
923
+ // computing a result that took long enough and met no resolution cycle, a checker exports it into its store (each type
924
+ // once) and posts it. A checker that took results for declarations of a file no checker took yet never checks that
925
+ // file: it hands the file on to another checker (`forbidden`, `handoff`), which then computes them itself, as the
926
+ // checker of a file always does.
927
+ /** Whether checker threads share results (TSC_TS_SHARE=1). */
928
+ export const shareThreads = process.env.TSC_TS_SHARE === '1';
929
+ /**
930
+ * The size of each checker's logs: numbers (int32s) and string code units (2 bytes each), 8 MB and 2 MB. Only the
931
+ * pages a checker writes take memory.
932
+ */
933
+ export const numberLogSize = 1 << 21;
934
+ export const stringLogSize = 1 << 20;
935
+ /** The number of records each checker's store can hold. */
936
+ export const recordTableSize = 1 << 20;
937
+ /** The number of entries of each result table: a power of two. */
938
+ export const resultTableSize = 1 << 20;
939
+ /**
940
+ * The most checker threads that share results: a result's state (`postedState`) holds the checker and an offset in
941
+ * its number log, below `numberLogSize` (2^21), in one int32, so the count times 2^21 stays below 2^31 - 2.
942
+ */
943
+ export const maxSharingCheckers = 1023;
944
+ /** The state of the result checker `producer` of `count` posted at `offset` of its number log. */
945
+ export function postedState(count, producer, offset) {
946
+ return -2 - (producer + count * offset);
947
+ }
948
+ /** The checker that posted the result of `state`, of `count` checkers. */
949
+ export function postedProducer(count, state) {
950
+ return (-2 - state) % count;
951
+ }
952
+ /** The offset in its producer's number log of the result of `state`, of `count` checkers. */
953
+ export function postedOffset(count, state) {
954
+ return Math.floor((-2 - state) / count);
955
+ }
956
+ /** The int32 words of each file's forbidden bits (`ThreadSharingData.forbidden`): a bit for each of `count` checkers. */
957
+ export function forbiddenWords(count) {
958
+ return (count + 31) >>> 5;
959
+ }
960
+ /** Whether checker `index` of `count` took results for declarations of file `file` before any checker took it. */
961
+ export function isForbidden(forbidden, count, file, index) {
962
+ return (Atomics.load(forbidden, file * forbiddenWords(count) + (index >>> 5)) & (1 << (index & 31))) !== 0;
963
+ }
964
+ /**
965
+ * An open-addressing table in a SharedArrayBuffer, from a key (a symbol or node id) to a result's state: 0 until a
966
+ * checker posts it, then `postedState`.
967
+ */
968
+ export class ResultTable {
969
+ words;
970
+ constructor(buffer) {
971
+ this.words = new Int32Array(buffer);
972
+ }
973
+ /** The slot of `key`, inserted if absent; -1 if the table is full. */
974
+ slot(key) {
975
+ const words = this.words;
976
+ const mask = resultTableSize - 1;
977
+ let h = Math.imul(key, 0x9e3779b1) >>> 12;
978
+ for (let probe = 0; probe < 64; probe++) {
979
+ const i = (h + probe) & mask;
980
+ const existing = Atomics.load(words, 2 * i);
981
+ if (existing === key + 1)
982
+ return i;
983
+ if (existing === 0) {
984
+ const previous = Atomics.compareExchange(words, 2 * i, 0, key + 1);
985
+ if (previous === 0 || previous === key + 1)
986
+ return i;
987
+ }
988
+ }
989
+ return -1;
990
+ }
991
+ state(slot) {
992
+ return Atomics.load(this.words, 2 * slot + 1);
993
+ }
994
+ /** The slot of `key`, or -1 if it has none. */
995
+ find(key) {
996
+ const words = this.words;
997
+ const mask = resultTableSize - 1;
998
+ let h = Math.imul(key, 0x9e3779b1) >>> 12;
999
+ for (let probe = 0; probe < 64; probe++) {
1000
+ const i = (h + probe) & mask;
1001
+ const existing = Atomics.load(words, 2 * i);
1002
+ if (existing === key + 1)
1003
+ return i;
1004
+ if (existing === 0)
1005
+ return -1;
1006
+ }
1007
+ return -1;
1008
+ }
1009
+ /** Sets the state of `slot` to a posted result's unless one is there already. */
1010
+ publish(slot, state) {
1011
+ Atomics.compareExchange(this.words, 2 * slot + 1, 0, state);
1012
+ }
1013
+ }
1014
+ /** TSC_TS_SHARE_MIN_MS: the shortest computation a checker posts, in milliseconds (32 divided by the checkers by default). */
1015
+ const shareMinValue = process.env.TSC_TS_SHARE_MIN_MS;
1016
+ // Debugging: TSC_TS_SHARE_BLOCK and TSC_TS_SHARE_ALLOW name parts of file names (comma-separated, each optionally with
1017
+ // a range of declaration positions, `name@start-end`) whose results are never or only translated, and
1018
+ // TSC_TS_SHARE_TRACE=1 prints each translation.
1019
+ const shareBlockValue = process.env.TSC_TS_SHARE_BLOCK;
1020
+ const shareAllowValue = process.env.TSC_TS_SHARE_ALLOW;
1021
+ const shareTraceValue = process.env.TSC_TS_SHARE_TRACE;
1022
+ // Debugging: TSC_TS_SHARE_VERIFY=1 computes each result a checker could translate, translates it after, and prints
1023
+ // the results whose translation prints differently.
1024
+ const shareVerifyValue = process.env.TSC_TS_SHARE_VERIFY;
1025
+ /** Checks a translation against the computation it replaces (TSC_TS_SHARE_VERIFY). */
1026
+ function verifyTranslation(c, kind, node, own, translated) {
1027
+ const sharing = c.threadSharing;
1028
+ if (translated === undefined)
1029
+ return;
1030
+ sharing.verified++;
1031
+ if (translated === own)
1032
+ return;
1033
+ const a = typeToString(c, own);
1034
+ const b = typeToString(c, translated);
1035
+ if (a === b) {
1036
+ sharing.verifiedIdentity++;
1037
+ return;
1038
+ }
1039
+ process.stderr.write('share-verify: checker ' +
1040
+ sharing.data.index +
1041
+ ' ' +
1042
+ kind +
1043
+ ' of ' +
1044
+ getSourceFileOfNode(node).fileName +
1045
+ ':' +
1046
+ node.pos +
1047
+ ' computed ' +
1048
+ a +
1049
+ ' translated ' +
1050
+ b +
1051
+ '\n');
1052
+ }
1053
+ /** Whether a part of `list` names `fileName`, and `pos` when the part ends in `@start-end`. */
1054
+ function namesFile(list, fileName, pos) {
1055
+ if (list === undefined)
1056
+ return false;
1057
+ for (const part of list.split(',')) {
1058
+ if (part === '')
1059
+ continue;
1060
+ const at = part.indexOf('@');
1061
+ if (at < 0) {
1062
+ if (fileName.includes(part))
1063
+ return true;
1064
+ continue;
1065
+ }
1066
+ const dash = part.indexOf('-', at);
1067
+ if (fileName.includes(part.slice(0, at)) &&
1068
+ pos >= Number(part.slice(at + 1, dash)) &&
1069
+ pos < Number(part.slice(dash + 1)))
1070
+ return true;
1071
+ }
1072
+ return false;
1073
+ }
1074
+ /** Whether the debugging options keep a result for a declaration at `node` from being translated. */
1075
+ function translationBlocked(node) {
1076
+ if (shareBlockValue === undefined && shareAllowValue === undefined)
1077
+ return false;
1078
+ const fileName = getSourceFileOfNode(node).fileName;
1079
+ if (namesFile(shareBlockValue, fileName, node.pos))
1080
+ return true;
1081
+ return shareAllowValue !== undefined && !namesFile(shareAllowValue, fileName, node.pos);
1082
+ }
1083
+ function traceTranslation(c, kind, node, producer) {
1084
+ if (shareTraceValue !== '1')
1085
+ return;
1086
+ process.stderr.write('share: checker ' +
1087
+ c.threadSharing.data.index +
1088
+ ' translated ' +
1089
+ kind +
1090
+ ' of ' +
1091
+ getSourceFileOfNode(node).fileName +
1092
+ ':' +
1093
+ node.pos +
1094
+ ' from ' +
1095
+ producer +
1096
+ '\n');
1097
+ }
1098
+ let threadSharingData = undefined;
1099
+ /** Sets the sharing data of this checker thread; its first checker shares with the other threads. */
1100
+ export function setThreadSharingData(data) {
1101
+ threadSharingData = data;
1102
+ }
1103
+ /** Gives `c` the thread's sharing state, if the thread shares and no checker of it has it yet. */
1104
+ export function startThreadSharing(c) {
1105
+ const data = threadSharingData;
1106
+ if (data === undefined)
1107
+ return;
1108
+ threadSharingData = undefined;
1109
+ c.threadSharing = new ThreadSharing(c, data);
1110
+ }
1111
+ /** A checker's state of sharing with the other checker threads. */
1112
+ /** A set of ids (symbol or node ids), a bit each. */
1113
+ export class IdBits {
1114
+ bits = new Uint32Array(1024);
1115
+ has(id) {
1116
+ const word = id >>> 5;
1117
+ return word < this.bits.length && (this.bits[word] & (1 << (id & 31))) !== 0;
1118
+ }
1119
+ add(id) {
1120
+ const word = id >>> 5;
1121
+ if (word >= this.bits.length) {
1122
+ let length = this.bits.length * 2;
1123
+ while (length <= word)
1124
+ length *= 2;
1125
+ const bits = new Uint32Array(length);
1126
+ bits.set(this.bits);
1127
+ this.bits = bits;
1128
+ }
1129
+ this.bits[word] = this.bits[word] | (1 << (id & 31));
1130
+ }
1131
+ }
1132
+ /**
1133
+ * The files of the diagnostics of results, by key (a symbol or declaration id), with a bit per key: most results have
1134
+ * none, and the bit answers that without a lookup.
1135
+ */
1136
+ export class FilesByKey {
1137
+ files = new Map();
1138
+ keys = new IdBits();
1139
+ get(key) {
1140
+ return this.keys.has(key) ? this.files.get(key) : undefined;
1141
+ }
1142
+ set(key, files) {
1143
+ this.keys.add(key);
1144
+ this.files.set(key, files);
1145
+ }
1146
+ }
1147
+ export class ThreadSharing {
1148
+ c;
1149
+ data;
1150
+ types;
1151
+ returns;
1152
+ /** TSC_TS_SHARE_MIN_MS: the shortest computation this checker posts. */
1153
+ minMs;
1154
+ initialIndexes = new Map();
1155
+ initial;
1156
+ numberLogs = [];
1157
+ recordTables = [];
1158
+ stringLogs = [];
1159
+ used;
1160
+ takers;
1161
+ forbidden;
1162
+ /** The number of results this checker posted. */
1163
+ posted = 0;
1164
+ translated = 0;
1165
+ /** Outermost shared-kind computations: nesting depth, the kind of the current one, and the time by kind. */
1166
+ depth = 0;
1167
+ kind = 0;
1168
+ kindMs = [0, 0, 0, 0];
1169
+ /** Kinds: 0 owned, 1 computed here for a file another checker took, 2 translated, 3 other. */
1170
+ addOutermost(ms) {
1171
+ this.kindMs[this.kind] += ms;
1172
+ this.kind = 3;
1173
+ }
1174
+ notShareable = 0;
1175
+ notShareableMs = 0;
1176
+ /** Whether the outermost computations are timed by kind (TSC_TS_SHARE_SUMMARY). */
1177
+ timing = process.env.TSC_TS_SHARE_SUMMARY !== undefined;
1178
+ /** TSC_TS_SHARE_VERIFY: translations checked, and those equal only as text. */
1179
+ verified = 0;
1180
+ verifiedIdentity = 0;
1181
+ belowMin = 0;
1182
+ belowMinMs = 0;
1183
+ exportFailed = 0;
1184
+ exportFailedMs = 0;
1185
+ exportFailures = new Map();
1186
+ packFailed = 0;
1187
+ /** Of `packFailed`, the results that didn't fit in this checker's logs. */
1188
+ logFull = 0;
1189
+ computedPrivately = 0;
1190
+ /** How often a posted result couldn't be taken here; and results for declarations of the checker's own files. */
1191
+ sawDoneUnusable = 0;
1192
+ owned = 0;
1193
+ unpackMs = 0;
1194
+ /** The program's nodes results named, by id. */
1195
+ nodesById = new Map();
1196
+ origins = new MergedOrigins();
1197
+ translationMs = 0;
1198
+ exportMs = 0;
1199
+ /** The symbol and signature whose next `getTypeOfSymbol` or `getReturnTypeOfSignature` computes here. */
1200
+ computing = undefined;
1201
+ computingSignature = undefined;
1202
+ /** The value type of `symbol`, or else the return type of `sig`, computed here. */
1203
+ computeHere(symbol, sig) {
1204
+ if (symbol !== undefined) {
1205
+ this.computing = symbol;
1206
+ return getTypeOfSymbol(this.c, symbol);
1207
+ }
1208
+ this.computingSignature = sig;
1209
+ return getReturnTypeOfSignature(this.c, sig);
1210
+ }
1211
+ /**
1212
+ * The files of the diagnostics each value type (by symbol id) and return type (by declaration id) reported, with
1213
+ * those of the results it used, cached and translated ones too; only for results with diagnostics. A checker that
1214
+ * takes a result checks none of these files, since it would have reported the diagnostics in them.
1215
+ */
1216
+ typeFiles = new FilesByKey();
1217
+ returnFiles = new FilesByKey();
1218
+ /** The files of the computations in progress, innermost last. */
1219
+ fileStack = [];
1220
+ /** Adds `files` to those of the computation in progress. */
1221
+ noteFiles(files) {
1222
+ const stack = this.fileStack;
1223
+ if (files === undefined || stack.length === 0)
1224
+ return;
1225
+ let top = stack[stack.length - 1];
1226
+ if (top === undefined) {
1227
+ top = new Set();
1228
+ stack[stack.length - 1] = top;
1229
+ }
1230
+ for (const f of files)
1231
+ top.add(f);
1232
+ }
1233
+ /** The last `computeShared`: whether its result can be shared, and how long it took. */
1234
+ lastShareable = false;
1235
+ lastMs = 0;
1236
+ /** `tracked`, recording whether the result can be shared, which it can't when the computation met a resolution cycle. */
1237
+ computeShared(files, key, symbol, sig) {
1238
+ const c = this.c;
1239
+ const cycles = c.resolutionCycleCount;
1240
+ const start = performance.now();
1241
+ const t = this.tracked(files, key, symbol, sig);
1242
+ this.lastMs = performance.now() - start;
1243
+ this.lastShareable = cycles === c.resolutionCycleCount;
1244
+ return t;
1245
+ }
1246
+ /** Runs `compute`, keeping in `files` under `key` the files of its diagnostics and of the results it used. */
1247
+ tracked(files, key, symbol, sig) {
1248
+ const c = this.c;
1249
+ const diagnostics = c.diagnostics.added;
1250
+ const suggestions = c.suggestionDiagnostics.added;
1251
+ const deferred = c.deferredDiagnosticFiles;
1252
+ const diagnosticsBefore = diagnostics.length;
1253
+ const suggestionsBefore = suggestions.length;
1254
+ const deferredBefore = deferred.length;
1255
+ this.fileStack.push(undefined);
1256
+ try {
1257
+ return this.computeHere(symbol, sig);
1258
+ }
1259
+ finally {
1260
+ let own = this.fileStack.pop();
1261
+ for (let i = diagnosticsBefore; i < diagnostics.length; i++) {
1262
+ if (own === undefined)
1263
+ own = new Set();
1264
+ const file = diagnostics[i].file;
1265
+ own.add(file === undefined ? '' : file.fileName);
1266
+ }
1267
+ for (let i = suggestionsBefore; i < suggestions.length; i++) {
1268
+ if (own === undefined)
1269
+ own = new Set();
1270
+ const file = suggestions[i].file;
1271
+ own.add(file === undefined ? '' : file.fileName);
1272
+ }
1273
+ // A deferred diagnostic is reported where its file is checked, as the diagnostics it reported are.
1274
+ for (let i = deferredBefore; i < deferred.length; i++) {
1275
+ if (own === undefined)
1276
+ own = new Set();
1277
+ own.add(deferred[i]);
1278
+ }
1279
+ if (own !== undefined) {
1280
+ const list = [...own];
1281
+ files.set(key, list);
1282
+ this.noteFiles(list);
1283
+ }
1284
+ }
1285
+ }
1286
+ constructor(c, data) {
1287
+ this.c = c;
1288
+ // `tracked` reads the diagnostics a computation added, and deferred, from these lists.
1289
+ c.diagnostics.added = [];
1290
+ c.suggestionDiagnostics.added = [];
1291
+ c.deferredDiagnosticFiles = [];
1292
+ this.data = data;
1293
+ this.used = new Int32Array(data.used);
1294
+ this.takers = new Int32Array(data.takers);
1295
+ this.forbidden = new Int32Array(data.forbidden);
1296
+ this.types = new ResultTable(data.typeTable);
1297
+ this.returns = new ResultTable(data.returnTable);
1298
+ // A posted result pays when enough checkers need it, so the threshold falls as checkers are added: 8 ms with 4
1299
+ // checkers, 2 ms with 16.
1300
+ this.minMs = shareMinValue === undefined ? 32 / data.count : Number(shareMinValue);
1301
+ this.initial = initialTypes(c);
1302
+ for (let i = 0; i < this.initial.length; i++)
1303
+ this.initialIndexes.set(this.initial[i], i);
1304
+ for (let k = 0; k < data.count; k++) {
1305
+ this.numberLogs.push(new Int32Array(data.numberLogs[k]));
1306
+ this.recordTables.push(new Int32Array(data.recordTables[k]));
1307
+ this.stringLogs.push(new Uint16Array(data.stringLogs[k]));
1308
+ }
1309
+ if (process.env.TSC_TS_SHARE_SUMMARY !== undefined)
1310
+ process.on('exit', () => process.stderr.write(this.summary() + '\n'));
1311
+ }
1312
+ summary() {
1313
+ return ('checker ' +
1314
+ this.data.index +
1315
+ ': outermost ms owned/computed here/translated/other ' +
1316
+ this.kindMs.map((v) => v.toFixed(0)).join('/') +
1317
+ '; posted ' +
1318
+ this.posted +
1319
+ ' (' +
1320
+ this.storedRecords +
1321
+ ' records), translated ' +
1322
+ this.translated +
1323
+ ' (' +
1324
+ this.translationMs.toFixed(0) +
1325
+ ' ms, unpacking ' +
1326
+ this.unpackMs.toFixed(0) +
1327
+ ' ms), export ' +
1328
+ this.exportMs.toFixed(0) +
1329
+ ' ms, computed here ' +
1330
+ this.computedPrivately +
1331
+ ' (' +
1332
+ this.sawDoneUnusable +
1333
+ ' posted but not taken), owned ' +
1334
+ this.owned +
1335
+ '; not posted: cycles ' +
1336
+ this.notShareable +
1337
+ ' (' +
1338
+ this.notShareableMs.toFixed(0) +
1339
+ ' ms), quick ' +
1340
+ this.belowMin +
1341
+ ' (' +
1342
+ this.belowMinMs.toFixed(0) +
1343
+ ' ms), not exported ' +
1344
+ this.exportFailed +
1345
+ ' (' +
1346
+ this.exportFailedMs.toFixed(0) +
1347
+ ' ms: ' +
1348
+ [...this.exportFailures]
1349
+ .sort((a, b) => b[1] - a[1])
1350
+ .slice(0, 4)
1351
+ .map(([k, v]) => k + ' ' + v.toFixed(0))
1352
+ .join('; ') +
1353
+ '), not packed ' +
1354
+ this.packFailed +
1355
+ ' (logs full ' +
1356
+ this.logFull +
1357
+ ', used ' +
1358
+ this.used[2 * this.data.index] +
1359
+ ' numbers, ' +
1360
+ this.used[2 * this.data.index + 1] +
1361
+ ' code units)' +
1362
+ (shareVerifyValue === '1' ? '; verified ' + this.verified + ' (' + this.verifiedIdentity + ' equal as text)' : ''));
1363
+ }
1364
+ /**
1365
+ * Whether this checker checks `file`, or may: a result computed for a declaration in it is never taken here. That is
1366
+ * a file it took, and one checked in statement ranges; a file no checker took yet it never checks once it took a
1367
+ * result for it (`forbid`).
1368
+ */
1369
+ owns(file) {
1370
+ const index = this.c.fileIndex.get(file);
1371
+ if (index === undefined)
1372
+ return true;
1373
+ const taker = Atomics.load(this.takers, index);
1374
+ if (taker === 0)
1375
+ return false;
1376
+ return taker !== -2 && (taker < 0 || taker === this.data.index + 1);
1377
+ }
1378
+ /** After taking a result for a declaration in `file`: if no checker took the file yet, this one never will. */
1379
+ forbid(file) {
1380
+ const index = this.c.fileIndex.get(file);
1381
+ if (index === undefined)
1382
+ return;
1383
+ const me = this.data.index;
1384
+ if (Atomics.load(this.takers, index) === 0)
1385
+ Atomics.or(this.forbidden, index * forbiddenWords(this.data.count) + (me >>> 5), 1 << (me & 31));
1386
+ }
1387
+ /**
1388
+ * Whether taking a result would leave file `index` to no checker: no checker took it, and every other checker
1389
+ * took results for its declarations already. The main thread would check it, alone.
1390
+ */
1391
+ forbidsLast(index) {
1392
+ if (Atomics.load(this.takers, index) !== 0)
1393
+ return false;
1394
+ const count = this.data.count;
1395
+ const me = this.data.index;
1396
+ const words = forbiddenWords(count);
1397
+ for (let w = 0; w < words; w++) {
1398
+ // The bits of the checkers this word holds, and this checker's.
1399
+ const n = Math.min(32, count - 32 * w);
1400
+ const all = n === 32 ? -1 : (1 << n) - 1;
1401
+ const mine = me >>> 5 === w ? 1 << (me & 31) : 0;
1402
+ if ((Atomics.load(this.forbidden, index * words + w) | mine) !== all)
1403
+ return false;
1404
+ }
1405
+ return true;
1406
+ }
1407
+ forbidsLastNamed(fileName) {
1408
+ this.ownsFileNamed(fileName);
1409
+ const file = this.filesByName.get(fileName);
1410
+ const index = file === undefined ? undefined : this.c.fileIndex.get(file);
1411
+ return index !== undefined && this.forbidsLast(index);
1412
+ }
1413
+ forbidNamed(fileName) {
1414
+ this.ownsFileNamed(fileName);
1415
+ const file = this.filesByName.get(fileName);
1416
+ if (file !== undefined)
1417
+ this.forbid(file);
1418
+ }
1419
+ filesByName = undefined;
1420
+ ownsFileNamed(fileName) {
1421
+ let files = this.filesByName;
1422
+ if (files === undefined) {
1423
+ files = new Map();
1424
+ for (const file of this.c.files)
1425
+ files.set(file.fileName, file);
1426
+ this.filesByName = files;
1427
+ }
1428
+ const file = files.get(fileName);
1429
+ return file === undefined || this.owns(file);
1430
+ }
1431
+ /** The result checker `k` posted at `offset` in its number log. */
1432
+ result(k, offset) {
1433
+ const numbers = this.numberLogs[k];
1434
+ const strings = this.stringLogs[k];
1435
+ const root = numbers[offset];
1436
+ const count = numbers[offset + 1];
1437
+ const files = [];
1438
+ for (let i = 0; i < count; i++)
1439
+ files.push(readText(strings, numbers[offset + 2 + 2 * i], numbers[offset + 3 + 2 * i]));
1440
+ return new StoredResult(root, files);
1441
+ }
1442
+ /** The exporter of this checker's store: it exports each type once. */
1443
+ storeExporter = undefined;
1444
+ /**
1445
+ * Exports `t` into this checker's store and logs a result with it as the root; returns its state for the result
1446
+ * tables, -1 if it doesn't fit in the logs or a node or symbol in it can't be named across threads, or why it can't
1447
+ * be exported.
1448
+ */
1449
+ post(t, diagnosticFiles) {
1450
+ const c = this.c;
1451
+ let exporter = this.storeExporter;
1452
+ if (exporter === undefined) {
1453
+ exporter = new Exporter(c, this.initialIndexes);
1454
+ exporter.nodeLimit = this.data.nodeIds;
1455
+ exporter.symbolLimit = this.data.symbolIds;
1456
+ exporter.originsCache = this.origins;
1457
+ this.storeExporter = exporter;
1458
+ }
1459
+ exporter.failure = undefined;
1460
+ exporter.mergedOrigins = undefined;
1461
+ const root = exporter.type(t);
1462
+ if (exporter.failure !== undefined) {
1463
+ const failure = exporter.failure;
1464
+ forgetExport(exporter);
1465
+ return failure;
1466
+ }
1467
+ const me = this.data.index;
1468
+ const numbers = this.numberLogs[me];
1469
+ const strings = this.stringLogs[me];
1470
+ const table = this.recordTables[me];
1471
+ const offset = this.used[2 * me];
1472
+ const p = new RecordPacker(c.fileIndex, strings, this.used[2 * me + 1]);
1473
+ const starts = [];
1474
+ for (const r of exporter.records) {
1475
+ starts.push(p.f.length);
1476
+ if (!packRecord(p, r)) {
1477
+ forgetExport(exporter);
1478
+ return -1;
1479
+ }
1480
+ }
1481
+ const header = p.f.length;
1482
+ p.f.push(root, diagnosticFiles.length);
1483
+ for (const fileName of diagnosticFiles)
1484
+ p.text(fileName);
1485
+ const count = exporter.records.length;
1486
+ let fits = !p.full && offset + p.f.length <= numbers.length && exporter.base + count <= recordTableSize;
1487
+ for (const v of p.f)
1488
+ if ((v | 0) !== v)
1489
+ fits = false;
1490
+ if (!fits) {
1491
+ this.logFull++;
1492
+ forgetExport(exporter);
1493
+ return -1;
1494
+ }
1495
+ for (let i = 0; i < p.f.length; i++)
1496
+ numbers[offset + i] = p.f[i];
1497
+ for (let i = 0; i < count; i++) {
1498
+ const index = exporter.base + i;
1499
+ table[2 * index] = offset + starts[i] + 1;
1500
+ const r = exporter.records[i];
1501
+ if (r.kind === 23 /* RecordKind.CompleteObject */)
1502
+ table[2 * r.num + 1] = index + 1;
1503
+ }
1504
+ // Only this checker writes its logs and store; the result table's state publishes what it wrote.
1505
+ this.used[2 * me] = offset + p.f.length;
1506
+ this.used[2 * me + 1] = p.unitAt;
1507
+ exporter.base += count;
1508
+ exporter.records = [];
1509
+ exporter.addedTypes.length = 0;
1510
+ exporter.addedProperties.length = 0;
1511
+ this.posted++;
1512
+ this.storedRecords += count;
1513
+ return postedState(this.data.count, me, offset + header);
1514
+ }
1515
+ /** The records this checker stored. */
1516
+ storedRecords = 0;
1517
+ /** The readers of the other checkers' stores. */
1518
+ readers = [];
1519
+ /** The translation of `posted` into this checker, or undefined if it can't be taken here. */
1520
+ translatePosted(producer, posted, files, key, declarationFile) {
1521
+ for (const fileName of posted.files)
1522
+ if (fileName === '' || this.ownsFileNamed(fileName) || this.forbidsLastNamed(fileName))
1523
+ return undefined;
1524
+ const declarationIndex = this.c.fileIndex.get(declarationFile);
1525
+ if (declarationIndex !== undefined && this.forbidsLast(declarationIndex))
1526
+ return undefined;
1527
+ const start = performance.now();
1528
+ let reader = this.readers[producer];
1529
+ if (reader === undefined) {
1530
+ reader = new StoreReader(this, producer);
1531
+ this.readers[producer] = reader;
1532
+ }
1533
+ const t = reader.translate(posted.root);
1534
+ this.translationMs += performance.now() - start;
1535
+ if (t !== undefined) {
1536
+ this.translated++;
1537
+ for (const fileName of posted.files)
1538
+ this.forbidNamed(fileName);
1539
+ if (posted.files.length > 0) {
1540
+ files.set(key, posted.files);
1541
+ this.noteFiles(posted.files);
1542
+ }
1543
+ }
1544
+ return t;
1545
+ }
1546
+ }
1547
+ /** A result in a checker's store: the record of its type, and the files of its diagnostics. */
1548
+ export class StoredResult {
1549
+ root;
1550
+ files;
1551
+ constructor(root, files) {
1552
+ this.root = root;
1553
+ this.files = files;
1554
+ }
1555
+ }
1556
+ function readText(strings, start, length) {
1557
+ let text = '';
1558
+ for (let j = 0; j < length; j++)
1559
+ text += String.fromCharCode(strings[start + j]);
1560
+ return text;
1561
+ }
1562
+ /** Forgets the types and properties a failed export of a store gave indexes. */
1563
+ function forgetExport(exporter) {
1564
+ for (const t of exporter.addedTypes)
1565
+ exporter.indexes.delete(t);
1566
+ for (const prop of exporter.addedProperties)
1567
+ exporter.properties.delete(prop);
1568
+ exporter.addedTypes.length = 0;
1569
+ exporter.addedProperties.length = 0;
1570
+ exporter.records = [];
1571
+ exporter.failure = undefined;
1572
+ }
1573
+ /**
1574
+ * Runs `compute` for the result keyed `key` in `table`, then exports and posts it if it can be shared and took long
1575
+ * enough, unless another checker posted it meanwhile. Nothing is written for the others before: a checker that finds
1576
+ * no result computes its own.
1577
+ */
1578
+ function computeAndPost(sharing, table, files, key, symbol, sig) {
1579
+ const t = sharing.computeShared(files, key, symbol, sig);
1580
+ const ms = sharing.lastMs;
1581
+ if (!sharing.lastShareable) {
1582
+ sharing.notShareable++;
1583
+ sharing.notShareableMs += ms;
1584
+ return t;
1585
+ }
1586
+ // A quick computation is cheaper to repeat than to export, post and translate.
1587
+ if (ms < sharing.minMs) {
1588
+ sharing.belowMin++;
1589
+ sharing.belowMinMs += ms;
1590
+ return t;
1591
+ }
1592
+ const slot = table.slot(key);
1593
+ if (slot < 0 || table.state(slot) !== 0)
1594
+ return t;
1595
+ const start = performance.now();
1596
+ // Diagnostics stay with this checker; the others only learn which files they are in.
1597
+ const state = sharing.post(t, files.get(key) ?? []);
1598
+ if (typeof state === 'string') {
1599
+ sharing.exportFailed++;
1600
+ sharing.exportFailedMs += ms;
1601
+ sharing.exportFailures.set(state, (sharing.exportFailures.get(state) ?? 0) + ms);
1602
+ }
1603
+ else if (state === -1)
1604
+ sharing.packFailed++;
1605
+ else
1606
+ table.publish(slot, state);
1607
+ sharing.exportMs += performance.now() - start;
1608
+ return t;
1609
+ }
1610
+ /** Shares the value type of `symbol` with the other checker threads, computing it with `compute` where needed. */
1611
+ export function threadTypeOfSymbol(c, symbol) {
1612
+ const sharing = c.threadSharing;
1613
+ if (!sharing.timing || sharing.depth > 0 || c.symbolTypes.get(getSymbolId(symbol)) !== undefined)
1614
+ return threadTypeOfSymbolWorker(c, symbol);
1615
+ const start = performance.now();
1616
+ sharing.kind = 3;
1617
+ sharing.depth++;
1618
+ try {
1619
+ return threadTypeOfSymbolWorker(c, symbol);
1620
+ }
1621
+ finally {
1622
+ sharing.depth--;
1623
+ sharing.addOutermost(performance.now() - start);
1624
+ }
1625
+ }
1626
+ function threadTypeOfSymbolWorker(c, symbol) {
1627
+ const sharing = c.threadSharing;
1628
+ const id = getSymbolId(symbol);
1629
+ const cached = c.symbolTypes.get(id);
1630
+ if (cached !== undefined) {
1631
+ // Most results have no diagnostics: then there is nothing to look up.
1632
+ if (sharing.fileStack.length > 0)
1633
+ sharing.noteFiles(sharing.typeFiles.get(id));
1634
+ return cached;
1635
+ }
1636
+ if (id > sharing.data.symbolIds)
1637
+ return sharing.tracked(sharing.typeFiles, id, symbol, undefined);
1638
+ const table = sharing.types;
1639
+ if (!sharing.owns(getSourceFileOfNode(symbol.valueDeclaration))) {
1640
+ const slot = table.find(id);
1641
+ const state = slot < 0 ? 0 : table.state(slot);
1642
+ if (state <= -2 &&
1643
+ findResolutionCycleStartIndex(c, symbol, 0 /* TypeSystemPropertyName.Type */) < 0 &&
1644
+ !translationBlocked(symbol.valueDeclaration)) {
1645
+ const producer = postedProducer(sharing.data.count, state);
1646
+ const posted = sharing.result(producer, postedOffset(sharing.data.count, state));
1647
+ const file = getSourceFileOfNode(symbol.valueDeclaration);
1648
+ if (shareVerifyValue === '1') {
1649
+ const own = sharing.tracked(sharing.typeFiles, id, symbol, undefined);
1650
+ verifyTranslation(c, 'types', symbol.valueDeclaration, own, sharing.translatePosted(producer, posted, sharing.typeFiles, id, file));
1651
+ return own;
1652
+ }
1653
+ const t = sharing.translatePosted(producer, posted, sharing.typeFiles, id, file);
1654
+ if (t !== undefined) {
1655
+ traceTranslation(c, 'types', symbol.valueDeclaration, producer);
1656
+ if (sharing.depth === 1)
1657
+ sharing.kind = 2;
1658
+ sharing.forbid(getSourceFileOfNode(symbol.valueDeclaration));
1659
+ const again = c.symbolTypes.get(id);
1660
+ if (again !== undefined)
1661
+ return again;
1662
+ c.symbolTypes.set(id, t);
1663
+ return t;
1664
+ }
1665
+ sharing.sawDoneUnusable++;
1666
+ }
1667
+ sharing.computedPrivately++;
1668
+ if (sharing.depth === 1)
1669
+ sharing.kind = 1;
1670
+ }
1671
+ else {
1672
+ sharing.owned++;
1673
+ if (sharing.depth === 1)
1674
+ sharing.kind = 0;
1675
+ }
1676
+ return computeAndPost(sharing, table, sharing.typeFiles, id, symbol, undefined);
1677
+ }
1678
+ /** Notes that the computation in progress used the cached return type of `sig` (see `ThreadSharing.typeFiles`). */
1679
+ export function noteReturnTypeUse(c, sig) {
1680
+ const sharing = c.threadSharing;
1681
+ if (sharing.fileStack.length === 0 || sig.declaration === undefined)
1682
+ return;
1683
+ sharing.noteFiles(sharing.returnFiles.get(sig.declaration.id));
1684
+ }
1685
+ export function threadReturnType(c, sig) {
1686
+ const sharing = c.threadSharing;
1687
+ if (!sharing.timing || sharing.depth > 0)
1688
+ return threadReturnTypeWorker(c, sig);
1689
+ const start = performance.now();
1690
+ sharing.kind = 3;
1691
+ sharing.depth++;
1692
+ try {
1693
+ return threadReturnTypeWorker(c, sig);
1694
+ }
1695
+ finally {
1696
+ sharing.depth--;
1697
+ sharing.addOutermost(performance.now() - start);
1698
+ }
1699
+ }
1700
+ function threadReturnTypeWorker(c, sig) {
1701
+ const sharing = c.threadSharing;
1702
+ const declaration = sig.declaration;
1703
+ const key = declaration.id;
1704
+ if (key > sharing.data.nodeIds)
1705
+ return sharing.tracked(sharing.returnFiles, key, undefined, sig);
1706
+ const table = sharing.returns;
1707
+ if (!sharing.owns(getSourceFileOfNode(declaration))) {
1708
+ const slot = table.find(key);
1709
+ const state = slot < 0 ? 0 : table.state(slot);
1710
+ if (state <= -2 &&
1711
+ findResolutionCycleStartIndex(c, sig, 3 /* TypeSystemPropertyName.ResolvedReturnType */) < 0 &&
1712
+ !translationBlocked(declaration)) {
1713
+ const producer = postedProducer(sharing.data.count, state);
1714
+ const posted = sharing.result(producer, postedOffset(sharing.data.count, state));
1715
+ const file = getSourceFileOfNode(declaration);
1716
+ if (shareVerifyValue === '1') {
1717
+ const own = sharing.tracked(sharing.returnFiles, key, undefined, sig);
1718
+ verifyTranslation(c, 'returns', declaration, own, sharing.translatePosted(producer, posted, sharing.returnFiles, key, file));
1719
+ return own;
1720
+ }
1721
+ const t = sharing.translatePosted(producer, posted, sharing.returnFiles, key, file);
1722
+ if (t !== undefined) {
1723
+ traceTranslation(c, 'returns', declaration, producer);
1724
+ if (sharing.depth === 1)
1725
+ sharing.kind = 2;
1726
+ sharing.forbid(getSourceFileOfNode(declaration));
1727
+ return t;
1728
+ }
1729
+ sharing.sawDoneUnusable++;
1730
+ }
1731
+ sharing.computedPrivately++;
1732
+ if (sharing.depth === 1)
1733
+ sharing.kind = 1;
1734
+ }
1735
+ else {
1736
+ sharing.owned++;
1737
+ if (sharing.depth === 1)
1738
+ sharing.kind = 0;
1739
+ }
1740
+ return computeAndPost(sharing, table, sharing.returnFiles, key, undefined, sig);
1741
+ }
1742
+ // ---- Records in a checker's store
1743
+ //
1744
+ // Records travel between threads as numbers and strings only: a class instance received in a worker makes the native
1745
+ // build store the number fields of every class it can reach as doubles. A node is written as its file, range, kind
1746
+ // and id, and found again by descending from the file's root; a symbol of the program as the node it is the symbol
1747
+ // of; a merged symbol by the id of a symbol it merged; a string as its range in the store's string log.
1748
+ /** A double and its two int32 halves, sharing their bytes. */
1749
+ class DoubleWords {
1750
+ f = new Float64Array(1);
1751
+ i;
1752
+ constructor() {
1753
+ this.i = new Int32Array(this.f.buffer);
1754
+ }
1755
+ }
1756
+ let doubleWordsValue = undefined;
1757
+ function doubleWords() {
1758
+ if (doubleWordsValue === undefined)
1759
+ doubleWordsValue = new DoubleWords();
1760
+ return doubleWordsValue;
1761
+ }
1762
+ /** Packs records into a checker's store: their numbers into `f`, their strings into its string log from `unitAt`. */
1763
+ class RecordPacker {
1764
+ f = [];
1765
+ fileIndex;
1766
+ strings;
1767
+ unitAt;
1768
+ /** Set when the string log is full. */
1769
+ full = false;
1770
+ constructor(fileIndex, strings, unitAt) {
1771
+ this.fileIndex = fileIndex;
1772
+ this.strings = strings;
1773
+ this.unitAt = unitAt;
1774
+ }
1775
+ text(t) {
1776
+ if (this.unitAt + t.length > this.strings.length) {
1777
+ this.full = true;
1778
+ this.f.push(0, 0);
1779
+ return;
1780
+ }
1781
+ this.f.push(this.unitAt, t.length);
1782
+ for (let j = 0; j < t.length; j++)
1783
+ this.strings[this.unitAt++] = t.charCodeAt(j);
1784
+ }
1785
+ list(values) {
1786
+ this.f.push(values.length);
1787
+ for (const v of values)
1788
+ this.f.push(v);
1789
+ }
1790
+ /** A double as the two int32 halves of its bits. */
1791
+ double(v) {
1792
+ const words = doubleWords();
1793
+ words.f[0] = v;
1794
+ this.f.push(words.i[0], words.i[1]);
1795
+ }
1796
+ node(node) {
1797
+ if (node === undefined) {
1798
+ this.f.push(-1);
1799
+ return true;
1800
+ }
1801
+ const file = getSourceFileOfNode(node);
1802
+ const index = this.fileIndex.get(file);
1803
+ if (index === undefined)
1804
+ return false;
1805
+ this.f.push(index, node.pos, node.end, node.kind, node.id);
1806
+ return true;
1807
+ }
1808
+ nodes(list) {
1809
+ this.f.push(list.length);
1810
+ for (const node of list)
1811
+ if (!this.node(node))
1812
+ return false;
1813
+ return true;
1814
+ }
1815
+ /** A symbol of the program (by the node it is the symbol of, or the export symbol of), or none. */
1816
+ symbol(symbol) {
1817
+ if (symbol === undefined) {
1818
+ this.f.push(-1);
1819
+ return true;
1820
+ }
1821
+ const declaration = symbol.declaration;
1822
+ if (declaration === undefined)
1823
+ return false;
1824
+ const local = getSymbol(declaration);
1825
+ if (local === symbol)
1826
+ this.f.push(0);
1827
+ else if (local !== undefined && local.exportSymbol === symbol)
1828
+ this.f.push(1);
1829
+ else
1830
+ return false;
1831
+ return this.node(declaration);
1832
+ }
1833
+ }
1834
+ /** Writes `r`; false if a node or symbol in it can't be named across threads. */
1835
+ function packRecord(p, r) {
1836
+ p.f.push(r.kind, r.id, r.flags);
1837
+ // A number literal's value is any double, written as its two halves.
1838
+ if (r.kind === 1 /* RecordKind.Literal */)
1839
+ p.double(r.num);
1840
+ else
1841
+ p.f.push(r.num);
1842
+ p.f.push(r.mergedId, r.aliasMergedId);
1843
+ p.text(r.text);
1844
+ if (!p.symbol(r.symbol) || !p.node(r.node) || !p.symbol(r.aliasSymbol))
1845
+ return false;
1846
+ p.list(r.refs);
1847
+ p.list(r.nums);
1848
+ if (!p.nodes(r.nodes))
1849
+ return false;
1850
+ p.f.push(r.texts.length);
1851
+ for (const t of r.texts)
1852
+ p.text(t);
1853
+ p.list(r.aliasRefs);
1854
+ p.f.push(r.indexInfos.length);
1855
+ for (const info of r.indexInfos) {
1856
+ p.f.push(info.keyType, info.valueType, info.isReadonly ? 1 : 0);
1857
+ if (!p.node(info.declaration) || !p.nodes(info.components))
1858
+ return false;
1859
+ }
1860
+ return true;
1861
+ }
1862
+ /** Reads records from a checker's store. */
1863
+ class RecordUnpacker {
1864
+ c;
1865
+ f;
1866
+ strings;
1867
+ at = 0;
1868
+ failed = false;
1869
+ /** The nodes found so far, by id. */
1870
+ nodesById;
1871
+ constructor(c, numbers, strings, nodesById) {
1872
+ this.c = c;
1873
+ this.f = numbers;
1874
+ this.strings = strings;
1875
+ this.nodesById = nodesById;
1876
+ }
1877
+ next() {
1878
+ return this.f[this.at++];
1879
+ }
1880
+ double() {
1881
+ const words = doubleWords();
1882
+ words.i[0] = this.next();
1883
+ words.i[1] = this.next();
1884
+ return words.f[0];
1885
+ }
1886
+ text() {
1887
+ const start = this.next();
1888
+ const length = this.next();
1889
+ return readText(this.strings, start, length);
1890
+ }
1891
+ list() {
1892
+ const n = this.next();
1893
+ const values = [];
1894
+ for (let i = 0; i < n; i++)
1895
+ values.push(this.next());
1896
+ return values;
1897
+ }
1898
+ node() {
1899
+ const fileIndex = this.next();
1900
+ if (fileIndex < 0)
1901
+ return undefined;
1902
+ const pos = this.next();
1903
+ const end = this.next();
1904
+ const kind = this.next();
1905
+ const id = this.next();
1906
+ let node = this.nodesById.get(id);
1907
+ if (node === undefined) {
1908
+ const file = this.c.files[fileIndex];
1909
+ node = file === undefined ? undefined : findNode(file, pos, end, kind, id);
1910
+ if (node === undefined) {
1911
+ this.failed = true;
1912
+ return undefined;
1913
+ }
1914
+ this.nodesById.set(id, node);
1915
+ }
1916
+ return node;
1917
+ }
1918
+ nodes() {
1919
+ const n = this.next();
1920
+ const list = [];
1921
+ for (let i = 0; i < n; i++)
1922
+ list.push(this.node());
1923
+ return list;
1924
+ }
1925
+ symbol() {
1926
+ const how = this.next();
1927
+ if (how < 0)
1928
+ return undefined;
1929
+ const node = this.node();
1930
+ if (node === undefined)
1931
+ return undefined;
1932
+ const local = getSymbol(node);
1933
+ const symbol = how === 0 ? local : local?.exportSymbol;
1934
+ if (symbol === undefined)
1935
+ this.failed = true;
1936
+ return symbol;
1937
+ }
1938
+ }
1939
+ /** Reads a record; undefined if a node or symbol in it isn't in `u`'s program. */
1940
+ function unpackRecord(u) {
1941
+ const kind = u.next();
1942
+ const id = u.next();
1943
+ const flags = u.next();
1944
+ const num = kind === 1 /* RecordKind.Literal */ ? u.double() : u.next();
1945
+ const mergedId = u.next();
1946
+ const aliasMergedId = u.next();
1947
+ const text = u.text();
1948
+ const symbol = u.symbol();
1949
+ const node = u.node();
1950
+ const aliasSymbol = u.symbol();
1951
+ const refs = u.list();
1952
+ const record = new PortableRecord(kind, id, flags, num, text, symbol, node, refs);
1953
+ record.mergedId = mergedId;
1954
+ record.aliasMergedId = aliasMergedId;
1955
+ record.aliasSymbol = aliasSymbol;
1956
+ record.nums = u.list();
1957
+ record.nodes = u.nodes();
1958
+ const textCount = u.next();
1959
+ const texts = [];
1960
+ for (let k = 0; k < textCount; k++)
1961
+ texts.push(u.text());
1962
+ record.texts = texts;
1963
+ record.aliasRefs = u.list();
1964
+ const infoCount = u.next();
1965
+ const infos = [];
1966
+ for (let k = 0; k < infoCount; k++) {
1967
+ const keyType = u.next();
1968
+ const valueType = u.next();
1969
+ const isReadonly = u.next() === 1;
1970
+ const declaration = u.node();
1971
+ const components = u.nodes();
1972
+ infos.push(new PortableIndexInfo(keyType, valueType, isReadonly, declaration, components));
1973
+ }
1974
+ record.indexInfos = infos;
1975
+ return u.failed ? undefined : record;
1976
+ }
1977
+ /** Collects the children of a node (`forEachChild`). */
1978
+ class ChildCollector extends NodeVisitor {
1979
+ children = [];
1980
+ visitNode(node) {
1981
+ this.children.push(node);
1982
+ return false;
1983
+ }
1984
+ }
1985
+ /** The node of `file` with the range, kind and id given, found by descending through the nodes that contain it. */
1986
+ function findNode(file, pos, end, kind, id) {
1987
+ let node = file;
1988
+ for (;;) {
1989
+ if (node.id === id)
1990
+ return node.kind === kind && node.pos === pos && node.end === end ? node : undefined;
1991
+ const collector = new ChildCollector();
1992
+ node.forEachChild(collector);
1993
+ let next = undefined;
1994
+ for (const child of collector.children)
1995
+ if (child.pos <= pos && end <= child.end) {
1996
+ // The innermost of nested nodes with one range is found by its id further down.
1997
+ if (child.id === id)
1998
+ return child.kind === kind && child.pos === pos && child.end === end ? child : undefined;
1999
+ if (next === undefined)
2000
+ next = child;
2001
+ }
2002
+ if (next === undefined)
2003
+ return undefined;
2004
+ node = next;
2005
+ }
2006
+ }
2007
+ /**
2008
+ * A consumer's translations of another checker's store: each record is read and translated once, when a result
2009
+ * first needs it, in the order of the store, which is the order the producer exported them in.
2010
+ */
2011
+ class StoreReader {
2012
+ sharing;
2013
+ producer;
2014
+ translator;
2015
+ table;
2016
+ unpacker;
2017
+ /** By record: the record, its translation and whether it is translated. */
2018
+ records = [];
2019
+ types = [];
2020
+ symbols = [];
2021
+ built = [];
2022
+ constructor(sharing, producer) {
2023
+ this.sharing = sharing;
2024
+ this.producer = producer;
2025
+ this.translator = new Translator(sharing.c);
2026
+ this.table = sharing.recordTables[producer];
2027
+ this.unpacker = new RecordUnpacker(sharing.c, sharing.numberLogs[producer], sharing.stringLogs[producer], sharing.nodesById);
2028
+ }
2029
+ ensure(index) {
2030
+ const placeholder = this.sharing.c.errorType;
2031
+ while (this.types.length <= index) {
2032
+ this.types.push(placeholder);
2033
+ this.symbols.push(undefined);
2034
+ this.records.push(undefined);
2035
+ this.built.push(0);
2036
+ }
2037
+ }
2038
+ /** Record `index`, read on first use; undefined if a node or symbol in it isn't in this program. */
2039
+ record(index) {
2040
+ this.ensure(index);
2041
+ const known = this.records[index];
2042
+ if (known !== undefined)
2043
+ return known;
2044
+ const u = this.unpacker;
2045
+ u.at = this.table[2 * index] - 1;
2046
+ u.failed = false;
2047
+ const start = performance.now();
2048
+ const record = unpackRecord(u);
2049
+ this.sharing.unpackMs += performance.now() - start;
2050
+ if (record !== undefined)
2051
+ this.records[index] = record;
2052
+ return record;
2053
+ }
2054
+ /** The translation of record `root` and the records it needs; undefined if one can't be translated here. */
2055
+ translate(root) {
2056
+ const c = this.sharing.c;
2057
+ const translator = this.translator;
2058
+ const needed = new Set();
2059
+ const stack = [root];
2060
+ while (stack.length > 0) {
2061
+ const i = stack.pop();
2062
+ if (needed.has(i))
2063
+ continue;
2064
+ this.ensure(i);
2065
+ if (this.built[i] === 1)
2066
+ continue;
2067
+ const r = this.record(i);
2068
+ if (r === undefined)
2069
+ return undefined;
2070
+ if ((r.mergedId >= 0 && !c.mergedSymbols.has(r.mergedId)) ||
2071
+ (r.aliasMergedId >= 0 && !c.mergedSymbols.has(r.aliasMergedId)))
2072
+ return undefined;
2073
+ needed.add(i);
2074
+ for (const j of r.refs)
2075
+ if (j >= 0)
2076
+ stack.push(j);
2077
+ for (const j of r.aliasRefs)
2078
+ stack.push(j);
2079
+ if (r.kind === 23 /* RecordKind.CompleteObject */ || (r.kind === 12 /* RecordKind.Union */ && r.num >= 0))
2080
+ stack.push(r.num);
2081
+ for (const info of r.indexInfos) {
2082
+ stack.push(info.keyType);
2083
+ stack.push(info.valueType);
2084
+ }
2085
+ if (r.kind === 22 /* RecordKind.AnonymousObject */) {
2086
+ const completion = this.table[2 * i + 1] - 1;
2087
+ if (completion >= 0)
2088
+ stack.push(completion);
2089
+ }
2090
+ }
2091
+ const order = [...needed].sort((a, b) => a - b);
2092
+ // Translating a type node resolves its type alias first, which fails where that is in progress: before any
2093
+ // record is translated. A translation can start translations of this store again (resolving a type alias, or
2094
+ // a type of a symbol), which translate some of these records first.
2095
+ for (const i of order) {
2096
+ if (this.built[i] === 1)
2097
+ continue;
2098
+ const r = this.records[i];
2099
+ if (r.kind === 8 /* RecordKind.NodeType */ ||
2100
+ r.kind === 16 /* RecordKind.Conditional */ ||
2101
+ r.kind === 21 /* RecordKind.DistributedConditional */)
2102
+ translator.aliasOfNode(r.node);
2103
+ }
2104
+ if (translator.failed) {
2105
+ translator.failed = false;
2106
+ return undefined;
2107
+ }
2108
+ for (const i of order) {
2109
+ if (this.built[i] === 1)
2110
+ continue;
2111
+ const r = this.records[i];
2112
+ if (r.kind === 24 /* RecordKind.Property */)
2113
+ this.symbols[i] = translator.property(r, this.types, this.symbols);
2114
+ else if (r.kind === 23 /* RecordKind.CompleteObject */)
2115
+ translator.complete(r, this.types, this.symbols);
2116
+ else
2117
+ this.types[i] = translator.record(r, this.types);
2118
+ if (translator.failed) {
2119
+ translator.failed = false;
2120
+ return undefined;
2121
+ }
2122
+ this.built[i] = 1;
2123
+ // A translated record is not read again.
2124
+ this.records[i] = undefined;
2125
+ }
2126
+ return this.types[root];
2127
+ }
2128
+ }