tsc-ts 0.0.10 → 0.1.1

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 (379) 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 +29 -18
  6. package/dist/api/compiler/ast.js +1040 -1007
  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 +136 -91
  14. package/dist/api/compiler/checker-contextual.d.ts +20 -0
  15. package/dist/api/compiler/checker-contextual.js +175 -62
  16. package/dist/api/compiler/checker-declaration-order.js +79 -79
  17. package/dist/api/compiler/checker-declarations.d.ts +1 -0
  18. package/dist/api/compiler/checker-declarations.js +160 -136
  19. package/dist/api/compiler/checker-declared-types.js +67 -65
  20. package/dist/api/compiler/checker-decorators.js +77 -77
  21. package/dist/api/compiler/checker-deprecation.d.ts +8 -3
  22. package/dist/api/compiler/checker-deprecation.js +76 -55
  23. package/dist/api/compiler/checker-destructuring.js +47 -45
  24. package/dist/api/compiler/checker-elaboration.js +24 -24
  25. package/dist/api/compiler/checker-emit-helpers.js +4 -4
  26. package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
  27. package/dist/api/compiler/checker-emit-resolver.js +25 -13
  28. package/dist/api/compiler/checker-evaluator.js +9 -9
  29. package/dist/api/compiler/checker-expressions.js +258 -212
  30. package/dist/api/compiler/checker-functions.js +113 -107
  31. package/dist/api/compiler/checker-generated-code.d.ts +0 -11
  32. package/dist/api/compiler/checker-generated-code.js +28 -52
  33. package/dist/api/compiler/checker-grammar.d.ts +1 -0
  34. package/dist/api/compiler/checker-grammar.js +469 -438
  35. package/dist/api/compiler/checker-heritage.js +91 -93
  36. package/dist/api/compiler/checker-inference.d.ts +77 -5
  37. package/dist/api/compiler/checker-inference.js +487 -113
  38. package/dist/api/compiler/checker-iteration.d.ts +0 -10
  39. package/dist/api/compiler/checker-iteration.js +35 -52
  40. package/dist/api/compiler/checker-javascript.js +14 -14
  41. package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
  42. package/dist/api/compiler/checker-jsdoc.js +67 -58
  43. package/dist/api/compiler/checker-jsx.js +107 -89
  44. package/dist/api/compiler/checker-members.d.ts +9 -2
  45. package/dist/api/compiler/checker-members.js +210 -74
  46. package/dist/api/compiler/checker-modules.d.ts +15 -6
  47. package/dist/api/compiler/checker-modules.js +469 -309
  48. package/dist/api/compiler/checker-narrowing.js +273 -189
  49. package/dist/api/compiler/checker-object-literals.js +25 -22
  50. package/dist/api/compiler/checker-operators.js +126 -118
  51. package/dist/api/compiler/checker-overloads.js +27 -27
  52. package/dist/api/compiler/checker-property-access.js +59 -55
  53. package/dist/api/compiler/checker-services.d.ts +1 -0
  54. package/dist/api/compiler/checker-services.js +222 -210
  55. package/dist/api/compiler/checker-signatures.js +65 -49
  56. package/dist/api/compiler/checker-source-file.d.ts +5 -0
  57. package/dist/api/compiler/checker-source-file.js +154 -130
  58. package/dist/api/compiler/checker-statements.js +33 -32
  59. package/dist/api/compiler/checker-super.js +50 -50
  60. package/dist/api/compiler/checker-symbol-types.js +109 -93
  61. package/dist/api/compiler/checker-symbols.d.ts +13 -1
  62. package/dist/api/compiler/checker-symbols.js +264 -149
  63. package/dist/api/compiler/checker-type-factory.d.ts +5 -0
  64. package/dist/api/compiler/checker-type-factory.js +190 -46
  65. package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
  66. package/dist/api/compiler/checker-type-nodes.js +179 -141
  67. package/dist/api/compiler/checker-type-operators.d.ts +2 -0
  68. package/dist/api/compiler/checker-type-operators.js +110 -63
  69. package/dist/api/compiler/checker-types.d.ts +80 -3
  70. package/dist/api/compiler/checker-types.js +121 -2
  71. package/dist/api/compiler/checker-unused.js +114 -118
  72. package/dist/api/compiler/checker-utilities.js +11 -11
  73. package/dist/api/compiler/checker.d.ts +97 -31
  74. package/dist/api/compiler/checker.js +149 -35
  75. package/dist/api/compiler/command-line.d.ts +1 -3
  76. package/dist/api/compiler/command-line.js +47 -44
  77. package/dist/api/compiler/compile-program.d.ts +24 -4
  78. package/dist/api/compiler/compile-program.js +53 -26
  79. package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
  80. package/dist/api/compiler/diagnostic-messages.js +128 -122
  81. package/dist/api/compiler/diagnostics.js +7 -7
  82. package/dist/api/compiler/emitter.d.ts +7 -1
  83. package/dist/api/compiler/emitter.js +53 -11
  84. package/dist/api/compiler/expr-record.d.ts +11 -0
  85. package/dist/api/compiler/expr-record.js +53 -0
  86. package/dist/api/compiler/file-include.d.ts +2 -1
  87. package/dist/api/compiler/file-include.js +11 -7
  88. package/dist/api/compiler/file-loader.d.ts +10 -0
  89. package/dist/api/compiler/file-loader.js +138 -41
  90. package/dist/api/compiler/identifier-name.d.ts +9 -0
  91. package/dist/api/compiler/identifier-name.js +10 -0
  92. package/dist/api/compiler/instantiation.d.ts +7 -0
  93. package/dist/api/compiler/instantiation.js +101 -49
  94. package/dist/api/compiler/jsdoc.js +27 -25
  95. package/dist/api/compiler/link-tables.d.ts +48 -18
  96. package/dist/api/compiler/link-tables.js +80 -37
  97. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  98. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  99. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  100. package/dist/api/compiler/locales/de-DE.js +1 -1
  101. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  102. package/dist/api/compiler/locales/es-ES.js +1 -1
  103. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  104. package/dist/api/compiler/locales/fr-FR.js +1 -1
  105. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  106. package/dist/api/compiler/locales/it-IT.js +1 -1
  107. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  108. package/dist/api/compiler/locales/ja-JP.js +1 -1
  109. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  110. package/dist/api/compiler/locales/ko-KR.js +1 -1
  111. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  112. package/dist/api/compiler/locales/pl-PL.js +1 -1
  113. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  114. package/dist/api/compiler/locales/pt-BR.js +1 -1
  115. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  116. package/dist/api/compiler/locales/ru-RU.js +1 -1
  117. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  118. package/dist/api/compiler/locales/tr-TR.js +1 -1
  119. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  120. package/dist/api/compiler/locales/zh-CN.js +1 -1
  121. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  122. package/dist/api/compiler/locales/zh-TW.js +1 -1
  123. package/dist/api/compiler/module-resolution-types.js +6 -6
  124. package/dist/api/compiler/module-resolution.d.ts +10 -1
  125. package/dist/api/compiler/module-resolution.js +115 -84
  126. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  127. package/dist/api/compiler/module-specifiers.js +24 -18
  128. package/dist/api/compiler/name-resolver.js +74 -65
  129. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  130. package/dist/api/compiler/node-builder-names.js +210 -90
  131. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  132. package/dist/api/compiler/node-builder-reuse.js +23 -22
  133. package/dist/api/compiler/node-builder.d.ts +18 -1
  134. package/dist/api/compiler/node-builder.js +191 -102
  135. package/dist/api/compiler/option-declarations.d.ts +2 -6
  136. package/dist/api/compiler/option-declarations.js +315 -375
  137. package/dist/api/compiler/options.d.ts +15 -33
  138. package/dist/api/compiler/options.js +21 -54
  139. package/dist/api/compiler/output-paths.d.ts +4 -1
  140. package/dist/api/compiler/output-paths.js +6 -11
  141. package/dist/api/compiler/package-json.d.ts +3 -3
  142. package/dist/api/compiler/package-json.js +11 -10
  143. package/dist/api/compiler/parser.d.ts +42 -20
  144. package/dist/api/compiler/parser.js +318 -224
  145. package/dist/api/compiler/path.d.ts +9 -0
  146. package/dist/api/compiler/path.js +20 -3
  147. package/dist/api/compiler/printer/emit-context.d.ts +3 -1
  148. package/dist/api/compiler/printer/emit-context.js +16 -1
  149. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  150. package/dist/api/compiler/printer/factory-base.js +7 -3
  151. package/dist/api/compiler/printer/factory.js +6 -3
  152. package/dist/api/compiler/printer/helpers.js +10 -1
  153. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  154. package/dist/api/compiler/printer/name-generator.js +35 -16
  155. package/dist/api/compiler/printer/printer.d.ts +1 -0
  156. package/dist/api/compiler/printer/printer.js +306 -283
  157. package/dist/api/compiler/printer/utilities.js +149 -147
  158. package/dist/api/compiler/program-checker.d.ts +8 -2
  159. package/dist/api/compiler/program-checker.js +84 -34
  160. package/dist/api/compiler/program-utilities.d.ts +3 -1
  161. package/dist/api/compiler/program-utilities.js +28 -15
  162. package/dist/api/compiler/program.d.ts +2 -0
  163. package/dist/api/compiler/program.js +69 -57
  164. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  165. package/dist/api/compiler/pseudo-bigint.js +18 -0
  166. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  167. package/dist/api/compiler/regexp-checker.js +93 -76
  168. package/dist/api/compiler/relations.d.ts +27 -4
  169. package/dist/api/compiler/relations.js +337 -180
  170. package/dist/api/compiler/reparser.js +64 -59
  171. package/dist/api/compiler/scanner.d.ts +27 -2
  172. package/dist/api/compiler/scanner.js +181 -150
  173. package/dist/api/compiler/shared-results.d.ts +696 -0
  174. package/dist/api/compiler/shared-results.js +2905 -0
  175. package/dist/api/compiler/sourcemap.js +2 -2
  176. package/dist/api/compiler/symbol-accessibility.js +87 -74
  177. package/dist/api/compiler/symbol.d.ts +22 -13
  178. package/dist/api/compiler/symbol.js +15 -1
  179. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  180. package/dist/api/compiler/transformers/alias-references.js +247 -139
  181. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  182. package/dist/api/compiler/transformers/async.d.ts +0 -1
  183. package/dist/api/compiler/transformers/async.js +64 -77
  184. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  185. package/dist/api/compiler/transformers/class-fields.js +81 -78
  186. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  187. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  188. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  189. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  190. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  191. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  192. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  193. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  194. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  195. package/dist/api/compiler/transformers/declarations.js +307 -239
  196. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  197. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  198. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  199. package/dist/api/compiler/transformers/destructuring.js +19 -18
  200. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  201. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  202. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  203. package/dist/api/compiler/transformers/for-await.js +25 -25
  204. package/dist/api/compiler/transformers/import-elision.js +14 -14
  205. package/dist/api/compiler/transformers/jsx.js +12 -12
  206. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  207. package/dist/api/compiler/transformers/module.js +8 -8
  208. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  209. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  210. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  211. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  212. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  213. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  214. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  215. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  216. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  217. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  218. package/dist/api/compiler/transformers/using.js +12 -12
  219. package/dist/api/compiler/transformers/utilities.js +77 -77
  220. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  221. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  222. package/dist/api/compiler/tsconfig.d.ts +10 -2
  223. package/dist/api/compiler/tsconfig.js +136 -48
  224. package/dist/api/compiler/type-printer.js +40 -3
  225. package/dist/api/compiler/types.d.ts +2 -1
  226. package/dist/api/library/ast.generated.d.ts +42 -39
  227. package/dist/api/library/ast.generated.js +1 -1
  228. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  229. package/dist/api/library/compiler-options.generated.js +1 -1
  230. package/dist/api/library/disk.js +12 -1
  231. package/dist/api/library/enums.generated.d.ts +206 -206
  232. package/dist/api/library/enums.generated.js +206 -206
  233. package/dist/api/library/nodes.js +26 -26
  234. package/package.json +9 -9
  235. package/src/compiler/ast-utilities.ts +99 -7
  236. package/src/compiler/ast.ts +74 -38
  237. package/src/compiler/binder.ts +39 -4
  238. package/src/compiler/cgroup.ts +157 -0
  239. package/src/compiler/character-codes.ts +2 -2
  240. package/src/compiler/checker-calls.ts +76 -8
  241. package/src/compiler/checker-classes.ts +80 -25
  242. package/src/compiler/checker-contextual.ts +110 -1
  243. package/src/compiler/checker-declarations.ts +31 -4
  244. package/src/compiler/checker-declared-types.ts +8 -5
  245. package/src/compiler/checker-decorators.ts +1 -1
  246. package/src/compiler/checker-deprecation.ts +29 -8
  247. package/src/compiler/checker-destructuring.ts +10 -3
  248. package/src/compiler/checker-emit-helpers.ts +1 -0
  249. package/src/compiler/checker-emit-resolver.ts +16 -6
  250. package/src/compiler/checker-expressions.ts +95 -47
  251. package/src/compiler/checker-functions.ts +21 -6
  252. package/src/compiler/checker-generated-code.ts +2 -22
  253. package/src/compiler/checker-grammar.ts +133 -60
  254. package/src/compiler/checker-heritage.ts +22 -21
  255. package/src/compiler/checker-inference.ts +514 -87
  256. package/src/compiler/checker-iteration.ts +18 -31
  257. package/src/compiler/checker-javascript.ts +1 -1
  258. package/src/compiler/checker-jsdoc.ts +50 -27
  259. package/src/compiler/checker-jsx.ts +28 -5
  260. package/src/compiler/checker-members.ts +197 -55
  261. package/src/compiler/checker-modules.ts +332 -65
  262. package/src/compiler/checker-narrowing.ts +98 -19
  263. package/src/compiler/checker-object-literals.ts +3 -0
  264. package/src/compiler/checker-operators.ts +11 -4
  265. package/src/compiler/checker-property-access.ts +7 -2
  266. package/src/compiler/checker-services.ts +39 -12
  267. package/src/compiler/checker-signatures.ts +15 -1
  268. package/src/compiler/checker-source-file.ts +39 -13
  269. package/src/compiler/checker-statements.ts +3 -2
  270. package/src/compiler/checker-symbol-types.ts +29 -6
  271. package/src/compiler/checker-symbols.ts +158 -15
  272. package/src/compiler/checker-type-factory.ts +173 -35
  273. package/src/compiler/checker-type-nodes.ts +46 -3
  274. package/src/compiler/checker-type-operators.ts +83 -26
  275. package/src/compiler/checker-types.ts +147 -4
  276. package/src/compiler/checker-unused.ts +9 -14
  277. package/src/compiler/checker.ts +175 -41
  278. package/src/compiler/command-line.ts +28 -28
  279. package/src/compiler/compile-program.ts +59 -25
  280. package/src/compiler/decoder.ts +15 -5
  281. package/src/compiler/diagnostic-messages.ts +1973 -1892
  282. package/src/compiler/doctor-report.ts +133 -0
  283. package/src/compiler/emitter.ts +57 -8
  284. package/src/compiler/encoder.ts +23 -8
  285. package/src/compiler/expr-record.ts +59 -0
  286. package/src/compiler/file-include.ts +9 -3
  287. package/src/compiler/file-loader.ts +139 -32
  288. package/src/compiler/help.ts +10 -14
  289. package/src/compiler/identifier-name.ts +13 -0
  290. package/src/compiler/incremental.ts +86 -18
  291. package/src/compiler/init.ts +2 -7
  292. package/src/compiler/instantiation.ts +77 -22
  293. package/src/compiler/jsdoc.ts +7 -3
  294. package/src/compiler/link-tables.ts +82 -37
  295. package/src/compiler/locales/cs-CZ.ts +1 -1
  296. package/src/compiler/locales/de-DE.ts +1 -1
  297. package/src/compiler/locales/es-ES.ts +1 -1
  298. package/src/compiler/locales/fr-FR.ts +1 -1
  299. package/src/compiler/locales/it-IT.ts +1 -1
  300. package/src/compiler/locales/ja-JP.ts +1 -1
  301. package/src/compiler/locales/ko-KR.ts +1 -1
  302. package/src/compiler/locales/pl-PL.ts +1 -1
  303. package/src/compiler/locales/pt-BR.ts +1 -1
  304. package/src/compiler/locales/ru-RU.ts +1 -1
  305. package/src/compiler/locales/tr-TR.ts +1 -1
  306. package/src/compiler/locales/zh-CN.ts +1 -1
  307. package/src/compiler/locales/zh-TW.ts +1 -1
  308. package/src/compiler/module-resolution.ts +44 -8
  309. package/src/compiler/module-specifiers.ts +62 -20
  310. package/src/compiler/name-resolver.ts +9 -1
  311. package/src/compiler/node-builder-names.ts +236 -54
  312. package/src/compiler/node-builder-pseudo.ts +4 -7
  313. package/src/compiler/node-builder-reuse.ts +5 -4
  314. package/src/compiler/node-builder.ts +130 -31
  315. package/src/compiler/option-declarations.ts +33 -103
  316. package/src/compiler/options.ts +23 -62
  317. package/src/compiler/output-paths.ts +5 -18
  318. package/src/compiler/package-entrypoints.ts +345 -0
  319. package/src/compiler/package-json.ts +4 -4
  320. package/src/compiler/parallel-check.ts +543 -147
  321. package/src/compiler/parallel-emit.ts +4 -4
  322. package/src/compiler/parser.ts +166 -47
  323. package/src/compiler/path.ts +22 -2
  324. package/src/compiler/printer/emit-context.ts +16 -0
  325. package/src/compiler/printer/factory-base.ts +10 -3
  326. package/src/compiler/printer/factory.ts +7 -3
  327. package/src/compiler/printer/helpers.ts +10 -1
  328. package/src/compiler/printer/name-generator.ts +24 -2
  329. package/src/compiler/printer/printer.ts +39 -16
  330. package/src/compiler/printer/utilities.ts +8 -2
  331. package/src/compiler/program-checker.ts +53 -5
  332. package/src/compiler/program-utilities.ts +23 -10
  333. package/src/compiler/program.ts +13 -1
  334. package/src/compiler/pseudo-bigint.ts +17 -0
  335. package/src/compiler/regexp-checker.ts +63 -30
  336. package/src/compiler/relations.ts +233 -77
  337. package/src/compiler/reparser.ts +14 -5
  338. package/src/compiler/run-config.ts +1383 -0
  339. package/src/compiler/run-record-read.ts +87 -0
  340. package/src/compiler/run-records.ts +575 -0
  341. package/src/compiler/scanner.ts +166 -120
  342. package/src/compiler/shared-results.ts +3144 -0
  343. package/src/compiler/show-config.ts +18 -1
  344. package/src/compiler/sourcemap.ts +2 -2
  345. package/src/compiler/symbol-accessibility.ts +26 -3
  346. package/src/compiler/symbol.ts +31 -14
  347. package/src/compiler/syntax-kind.ts +188 -187
  348. package/src/compiler/thread-entry.ts +22 -3
  349. package/src/compiler/transformers/alias-references.ts +123 -4
  350. package/src/compiler/transformers/async.ts +2 -17
  351. package/src/compiler/transformers/class-fields.ts +13 -12
  352. package/src/compiler/transformers/commonjs-module.ts +11 -7
  353. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  354. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  355. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  356. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  357. package/src/compiler/transformers/declarations.ts +136 -49
  358. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  359. package/src/compiler/transformers/destructuring.ts +4 -3
  360. package/src/compiler/transformers/external-module-info.ts +1 -1
  361. package/src/compiler/transformers/jsx.ts +2 -1
  362. package/src/compiler/transformers/reference-resolver.ts +83 -19
  363. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  364. package/src/compiler/transformers/syntax-facts.ts +2 -7
  365. package/src/compiler/transformers/type-eraser.ts +10 -1
  366. package/src/compiler/transformers/type-serialization.ts +3 -2
  367. package/src/compiler/transformers/visitor-base.ts +2 -1
  368. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  369. package/src/compiler/tsc-build.ts +67 -6
  370. package/src/compiler/tsc-cli.ts +35 -4
  371. package/src/compiler/tsc-compile.ts +220 -10
  372. package/src/compiler/tsc-watch.ts +97 -47
  373. package/src/compiler/tsconfig.ts +176 -19
  374. package/src/compiler/type-printer.ts +36 -2
  375. package/src/compiler/types.ts +2 -1
  376. package/src/library/ast.generated.ts +57 -41
  377. package/src/library/compiler-options.generated.ts +117 -103
  378. package/src/library/disk.ts +10 -1
  379. package/src/library/enums.generated.ts +196 -196
@@ -50,8 +50,78 @@ import type { Program } from './program.js';
50
50
  import type { SourceFile } from './ast.js';
51
51
  import { lastSymbolIdValue } from './symbol.js';
52
52
  import { shareMergedGlobals } from './checker-symbols.js';
53
+ import { availableCpus, cgroupMemoryLimit } from './cgroup.js';
53
54
  import { readFileSync } from 'node:fs';
54
- import { availableParallelism, totalmem } from 'node:os';
55
+ import { totalmem } from 'node:os';
56
+ import {
57
+ forbiddenWords,
58
+ isForbidden,
59
+ maxSharingCheckers,
60
+ numberLogSize,
61
+ recordTableSize,
62
+ resultTableSize,
63
+ shareStatColumns,
64
+ shareStatExport,
65
+ shareStatPosted,
66
+ shareStatSaved,
67
+ shareStatTranslation,
68
+ shareStatTranslated,
69
+ stringLogSize,
70
+ usedStride,
71
+ type ThreadSharingData,
72
+ } from './shared-results.js';
73
+ import {
74
+ autoCheckers,
75
+ Automaticity,
76
+ CheckSignals,
77
+ checkersPolicy,
78
+ decideCheck,
79
+ learns,
80
+ libraryBoundCount,
81
+ maxAutoCheckers,
82
+ minSharingCheckers,
83
+ sharePin,
84
+ sharingCandidate,
85
+ sharingPeakShare,
86
+ Source,
87
+ tsgoCheckers,
88
+ type CheckDecision,
89
+ type CheckFit,
90
+ type RunConfig,
91
+ } from './run-config.js';
92
+ import type { RecordShape } from './run-records.js';
93
+
94
+ // The tests of the scheduler read these here, next to the plans they choose between.
95
+ export { autoCheckers, libraryBoundCount };
96
+
97
+ /**
98
+ * `TSC_TS_SHARE` for a run without a run configuration (the emit threads, which share no program to
99
+ * translate against): `1` shares, `0` does not, and unset shares nothing (`sharePin`).
100
+ */
101
+ const shareThreads = sharePin(process.env);
102
+
103
+ /**
104
+ * TSC_TS_SHARE_STOP_AT_MS: `t` or `t:level` stops a sharing run's sharing `t` milliseconds in, whatever
105
+ * the run's numbers say, to check the switch: `2` (the default) stops posting and translating, `1`
106
+ * stops posting. Testing only.
107
+ */
108
+ function shareStopHook(): { readonly at: number; readonly level: number } | undefined {
109
+ const value = process.env.TSC_TS_SHARE_STOP_AT_MS;
110
+ if (value === undefined || value === '') return undefined;
111
+ const colon = value.indexOf(':');
112
+ const at = Number(colon < 0 ? value : value.substring(0, colon));
113
+ if (!Number.isFinite(at) || at < 0) return undefined;
114
+ return { at, level: colon >= 0 && value.substring(colon + 1) === '1' ? 1 : 2 };
115
+ }
116
+
117
+ const shareStop = shareStopHook();
118
+
119
+ /**
120
+ * The window a run without a configuration uses before the main thread weighs what sharing saved against
121
+ * what it cost (`sharingNumbers`): 300 ms. A run with one uses the larger of 200 ms and a tenth of the
122
+ * check time its record measured (`RunConfig.shareWindowMs`, `shareWindowOf`).
123
+ */
124
+ const shareWindowMs = 300;
55
125
 
56
126
  /** With TSC_TS_CHECKERS_TRACE: the process's resident and peak resident set in MB (Linux), else 0. */
57
127
  export function residentMB(): number[] {
@@ -73,7 +143,8 @@ export function residentMB(): number[] {
73
143
  * the main thread emits the program (`checkersEmit`). `emitKinds`, by file index, is what the emit of
74
144
  * each file includes (an `EmitOnly`, or -1 for none) where not every output of every file is emitted
75
145
  * (an incremental program's rebuild); `undefined` for all of them. `units` are the statement ranges of
76
- * declaration files the order has positions for (`CheckPlan.units`).
146
+ * declaration files the order has positions for (`CheckPlan.units`). `globalsInFileDiagnostics` is the main
147
+ * thread's `CheckedProgram.globalsInFileDiagnostics`.
77
148
  */
78
149
  export type CheckerSpawn = (
79
150
  program: Program | undefined,
@@ -87,6 +158,8 @@ export type CheckerSpawn = (
87
158
  emitKinds: number[] | undefined,
88
159
  checking: boolean,
89
160
  units: number[],
161
+ globalsInFileDiagnostics: boolean,
162
+ sharing: ThreadSharingData | undefined,
90
163
  ) => Worker;
91
164
 
92
165
  export class ParallelCheck {
@@ -440,23 +513,9 @@ function checkersEmit(checked: CheckedProgram, emits: boolean): boolean {
440
513
  return emits && parallelCheck.writer !== undefined && options.noEmit !== true && options.listFilesOnly !== true;
441
514
  }
442
515
 
443
- /**
444
- * How the number of checkers is chosen without `--checkers`: `auto` (the default) uses every CPU
445
- * this process may run on (`os.availableParallelism()`, at most `maxAutoCheckers`), and at least
446
- * tsgo's four; fewer than the CPUs, but never fewer than four, when the estimated peak memory of more
447
- * checkers would not fit (`memoryCheckers`). `fixed` (TSC_TS_CHECKERS=fixed) uses tsgo's four.
448
- */
449
- export const checkerPolicy: 'fixed' | 'auto' = process.env.TSC_TS_CHECKERS === 'fixed' ? 'fixed' : 'auto';
450
-
451
- /** tsgo's number of checkers, and the fewest `auto` starts. */
452
- const tsgoCheckers = 4;
453
-
454
- /** The most checkers `auto` starts (measured up to 16 CPUs). */
455
- const maxAutoCheckers = 16;
456
-
457
516
  /**
458
517
  * The number of checker threads for `checkers` (`--checkers`), or 1 to check on this thread. Without
459
- * the option, native builds follow `checkerPolicy` (with `program`, the memory estimate of `auto`
518
+ * the option, native builds follow the checker policy (with `program`, the memory estimate of `auto`
460
519
  * applies); under Node.js, where every thread builds its own copy of the program, tsc-ts checks on
461
520
  * one thread.
462
521
  */
@@ -473,8 +532,8 @@ export function checkerThreads(
473
532
  function defaultCheckers(program: Program | undefined): number {
474
533
  if (!sharesPublishedGraphs) return 1;
475
534
  if (program !== undefined && checksLittle(program)) return 1;
476
- if (checkerPolicy === 'fixed') return tsgoCheckers;
477
- const cpus = Math.min(availableParallelism(), maxAutoCheckers);
535
+ if (checkersPolicy(process.env) === 'fixed') return tsgoCheckers;
536
+ const cpus = Math.min(availableCpus(), maxAutoCheckers);
478
537
  return autoCheckers(cpus, program === undefined ? Number.MAX_SAFE_INTEGER : memoryCheckers(program));
479
538
  }
480
539
 
@@ -500,24 +559,6 @@ function checksLittle(program: Program): boolean {
500
559
  return true;
501
560
  }
502
561
 
503
- /** `auto` with `cpus` CPUs when the memory estimate fits `fit` checkers: tsgo's four at least. */
504
- export function autoCheckers(cpus: number, fit: number): number {
505
- return Math.max(tsgoCheckers, Math.min(cpus, fit));
506
- }
507
-
508
- /**
509
- * The number of threads that parse ahead of a program checked by `checkers` checkers: every CPU this
510
- * process may run on, as tsgo parses on every core whatever its checker count (parse threads hand
511
- * their files to the shared program; what else they allocate is reused by the checker threads), but
512
- * one. The main thread hands out the chunks they load: with a thread on every CPU, it waits for a CPU
513
- * each time a thread returns a chunk, and so does that thread for its next chunk (VS Code's parse took
514
- * 18-57 ms longer with 16 threads on 16 CPUs than with 15).
515
- */
516
- export function parseThreads(checkers: number): number {
517
- const cpus = availableParallelism();
518
- return Math.max(1, Math.min(cpus - 1, Math.max(checkers, Math.min(cpus, maxAutoCheckers))));
519
- }
520
-
521
562
  /**
522
563
  * The program's memory per character of source text, where it can't be measured (`residentBytes`):
523
564
  * 23-28 bytes on the benchmark apps when checking starts (parse threads' arenas included).
@@ -553,9 +594,14 @@ const lastResortShare = 0.95;
553
594
  * bytes, for a program of `programBytes` (`firstCheckerShare`, `checkerBytesPerDeclarationChar`);
554
595
  * at least 1.
555
596
  */
556
- export function checkersFittingMemory(programBytes: number, declarationChars: number, memory: number): number {
557
- const peak = programBytes * (1 + firstCheckerShare);
558
- const perChecker = Math.max(1, declarationChars * checkerBytesPerDeclarationChar);
597
+ export function checkersFittingMemory(
598
+ programBytes: number,
599
+ declarationChars: number,
600
+ memory: number,
601
+ peakShare: number = 1,
602
+ ): number {
603
+ const peak = programBytes * (1 + firstCheckerShare) * peakShare;
604
+ const perChecker = Math.max(1, declarationChars * checkerBytesPerDeclarationChar * peakShare);
559
605
  return Math.max(1, 1 + Math.floor((memoryShare * memory - peak) / perChecker));
560
606
  }
561
607
 
@@ -572,59 +618,6 @@ export function memoryLimit(): number {
572
618
  return limit;
573
619
  }
574
620
 
575
- /**
576
- * The smallest memory limit of this process's cgroup and its ancestors (Linux), or 0 where there is
577
- * none or it is unknown: `memory.max` and `memory.high` under cgroup v2, `memory.limit_in_bytes`
578
- * under v1. `process.constrainedMemory()` does not always see these: libuv reads only the process's
579
- * own cgroup, and scriptc's runtime only the root of the cgroup mount, which is the process's own
580
- * cgroup only inside a cgroup namespace.
581
- */
582
- export function cgroupMemoryLimit(): number {
583
- let membership: string;
584
- try {
585
- membership = readFileSync('/proc/self/cgroup', 'utf8');
586
- } catch {
587
- return 0;
588
- }
589
- let limit = 0;
590
- const lower = (value: number): void => {
591
- if (value > 0 && (limit === 0 || value < limit)) limit = value;
592
- };
593
- for (const line of membership.split('\n')) {
594
- // "0::/path" (v2), "N:memory:/path" or "N:cpu,memory:/path" (v1).
595
- const first = line.indexOf(':');
596
- const second = line.indexOf(':', first + 1);
597
- if (first < 0 || second < 0) continue;
598
- const controllers = line.substring(first + 1, second);
599
- const path = line.substring(second + 1);
600
- if (controllers === '') {
601
- for (let dir = path; ; dir = dir.substring(0, dir.lastIndexOf('/'))) {
602
- const base = '/sys/fs/cgroup' + (dir === '/' ? '' : dir);
603
- lower(cgroupLimitValue(base + '/memory.max'));
604
- lower(cgroupLimitValue(base + '/memory.high'));
605
- if (dir === '/' || dir === '' || dir.lastIndexOf('/') < 0) break;
606
- }
607
- } else if (controllers.split(',').indexOf('memory') >= 0) {
608
- lower(cgroupLimitValue('/sys/fs/cgroup/memory' + (path === '/' ? '' : path) + '/memory.limit_in_bytes'));
609
- }
610
- }
611
- return limit;
612
- }
613
-
614
- /** A cgroup memory limit file's value in bytes, or 0 for `max`, an unreadable file or no number. */
615
- function cgroupLimitValue(file: string): number {
616
- let text: string;
617
- try {
618
- text = readFileSync(file, 'utf8').trim();
619
- } catch {
620
- return 0;
621
- }
622
- if (text === '' || text === 'max') return 0;
623
- const value = Number(text);
624
- // cgroup v1 reports no limit as a page-aligned value near 2^63.
625
- return Number.isFinite(value) && value > 0 && value < 2 ** 62 ? value : 0;
626
- }
627
-
628
621
  /** The program whose text lengths `textLengths` holds. */
629
622
  let lengthsProgram: Program | undefined = undefined;
630
623
  let lengthsOfProgram: number[] = [];
@@ -650,6 +643,27 @@ export function textLengths(program: Program): number[] {
650
643
  * or an estimate from its text where that is unknown.
651
644
  */
652
645
  export function memoryCheckers(program: Program): number {
646
+ const estimate = memoryEstimate(program);
647
+ const fit = checkersFittingMemory(estimate.programBytes, estimate.declarationChars, estimate.memory);
648
+ if (process.env.TSC_TS_CHECKERS_TRACE !== undefined)
649
+ process.stderr.write(
650
+ `checkers: ${estimate.chars} source chars (${estimate.declarationChars} in declaration files), program ${Math.round(estimate.programBytes / 1048576)}MB${estimate.resident > 0 ? '' : ' (estimated)'}, memory ${Math.round(estimate.memory / 1048576)}MB fits ${fit} checkers\n`,
651
+ );
652
+ return fit;
653
+ }
654
+
655
+ /** What the memory fit reads of a program: its text, the declarations in it, and this process's memory. */
656
+ interface MemoryEstimate {
657
+ readonly chars: number;
658
+ readonly declarationChars: number;
659
+ readonly programBytes: number;
660
+ /** Whether `programBytes` is the resident set (`0` where it is an estimate from the text). */
661
+ readonly resident: number;
662
+ readonly memory: number;
663
+ }
664
+
665
+ /** The memory estimate of `program`, of its text (`textLengths`, computed once) and this process's memory. */
666
+ function memoryEstimate(program: Program): MemoryEstimate {
653
667
  let chars = 0;
654
668
  let declarationChars = 0;
655
669
  const files = program.getSourceFiles();
@@ -659,14 +673,24 @@ export function memoryCheckers(program: Program): number {
659
673
  if (files[i]!.isDeclarationFile) declarationChars += length[i]!;
660
674
  }
661
675
  const resident = residentBytes();
662
- const programBytes = resident > 0 ? resident : chars * programBytesPerChar;
663
- const memory = memoryLimit();
664
- const fit = checkersFittingMemory(programBytes, declarationChars, memory);
665
- if (process.env.TSC_TS_CHECKERS_TRACE !== undefined)
666
- process.stderr.write(
667
- `checkers: ${chars} source chars (${declarationChars} in declaration files), program ${Math.round(programBytes / 1048576)}MB${resident > 0 ? '' : ' (estimated)'}, memory ${Math.round(memory / 1048576)}MB fits ${fit} checkers\n`,
668
- );
669
- return fit;
676
+ return {
677
+ chars,
678
+ declarationChars,
679
+ programBytes: resident > 0 ? resident : chars * programBytesPerChar,
680
+ resident,
681
+ memory: memoryLimit(),
682
+ };
683
+ }
684
+
685
+ /**
686
+ * The checkers whose estimated peak memory fits `program` (`checkersFittingMemory`), without sharing and
687
+ * with the peak sharing adds (`sharingPeakShare`), which the sharing rule requires of the count it keeps.
688
+ */
689
+ export function memoryFit(program: Program): CheckFit {
690
+ const estimate = memoryEstimate(program);
691
+ return {
692
+ sharing: checkersFittingMemory(estimate.programBytes, estimate.declarationChars, estimate.memory, sharingPeakShare),
693
+ };
670
694
  }
671
695
 
672
696
  /**
@@ -1450,10 +1474,13 @@ export function planSchedule(
1450
1474
  }
1451
1475
  let all = 0;
1452
1476
  for (const i of order) all += cost[i]!;
1453
- // Files that cost more than a 32nd of a checker's share go first, costliest first: at the end of
1454
- // a range they would make its checker finish last.
1477
+ // Files that cost more than a 128th of the program go first, costliest first: at the end of a range
1478
+ // they would make its checker finish last. A fixed fraction of the program, rather than of a
1479
+ // checker's share, keeps the cut in proportion to how many checkers drain the shared queue: it is a
1480
+ // 32nd of a share at 4 checkers and an eighth at 16, where a range is shorter and a file of the
1481
+ // same size would otherwise sit in it.
1455
1482
  let heavyCount = count;
1456
- while (heavyCount < order.length && cost[order[heavyCount]!]! * count * 32 >= all) heavyCount++;
1483
+ while (heavyCount < order.length && cost[order[heavyCount]!]! * 128 >= all) heavyCount++;
1457
1484
  // The groups go to the shared queue as one entry each, among the costliest files, by total cost.
1458
1485
  const groups = checkGroups(checked, count, groupLoad, costs);
1459
1486
  const grouped = new Set<number>();
@@ -1549,6 +1576,149 @@ export function traceSingleChecker(checked: CheckedProgram): void {
1549
1576
  );
1550
1577
  }
1551
1578
 
1579
+ /** The file a position of the order checks: a file index, or for a statement range, its file's. */
1580
+ function fileOfPosition(order: readonly number[], units: readonly number[], k: number): number {
1581
+ const i = order[k]!;
1582
+ return i >= 0 ? i : units[3 * (-1 - i)]!;
1583
+ }
1584
+
1585
+ /**
1586
+ * Hands position `k` of the order on to another checker (TSC_TS_SHARE). The handed-on positions are a list in
1587
+ * `handoff`: a lock, their number, the number of checkers that may still hand positions on, then the positions.
1588
+ */
1589
+ function handOff(handoff: Int32Array, k: number): void {
1590
+ while (Atomics.compareExchange(handoff, 0, 0, 1) !== 0) {
1591
+ // Another checker hands a position on or takes one.
1592
+ }
1593
+ const n = handoff[1]!;
1594
+ handoff[3 + n] = k;
1595
+ Atomics.store(handoff, 1, n + 1);
1596
+ Atomics.store(handoff, 0, 0);
1597
+ // Checkers with nothing else to check wait for handed-on positions.
1598
+ Atomics.notify(handoff, 1);
1599
+ }
1600
+
1601
+ /**
1602
+ * Once checker `index` has no more positions of its own: a handed-on position it may check, waiting while other
1603
+ * checkers may still hand some on; -1 when none is left for it.
1604
+ */
1605
+ function waitForHandedOff(
1606
+ handoff: Int32Array,
1607
+ forbidden: Int32Array,
1608
+ count: number,
1609
+ order: readonly number[],
1610
+ units: readonly number[],
1611
+ index: number,
1612
+ ): number {
1613
+ Atomics.sub(handoff, 2, 1);
1614
+ const start = performance.now();
1615
+ for (;;) {
1616
+ const n = Atomics.load(handoff, 1);
1617
+ const k = takeHandedOff(handoff, forbidden, count, order, units, index);
1618
+ if (k >= 0) {
1619
+ // Checking it, this checker may hand positions on again.
1620
+ Atomics.add(handoff, 2, 1);
1621
+ return k;
1622
+ }
1623
+ // The main thread checks what is handed on later, as it does the files of a thread that failed.
1624
+ if (Atomics.load(handoff, 2) === 0 || performance.now() - start > 2000) return -1;
1625
+ Atomics.wait(handoff, 1, n, 1);
1626
+ }
1627
+ }
1628
+
1629
+ /**
1630
+ * A handed-on position checker `index` of `count` may check, removed from the handed-on positions; -1 if there is
1631
+ * none.
1632
+ */
1633
+ function takeHandedOff(
1634
+ handoff: Int32Array,
1635
+ forbidden: Int32Array,
1636
+ count: number,
1637
+ order: readonly number[],
1638
+ units: readonly number[],
1639
+ index: number,
1640
+ ): number {
1641
+ if (Atomics.load(handoff, 1) === 0) return -1;
1642
+ while (Atomics.compareExchange(handoff, 0, 0, 1) !== 0) {
1643
+ // Another checker hands a position on or takes one.
1644
+ }
1645
+ const n = handoff[1]!;
1646
+ let found = -1;
1647
+ for (let j = 0; j < n; j++) {
1648
+ const k = handoff[3 + j]!;
1649
+ if (!isForbidden(forbidden, count, fileOfPosition(order, units, k), index)) {
1650
+ found = k;
1651
+ handoff[3 + j] = handoff[3 + n - 1]!;
1652
+ Atomics.store(handoff, 1, n - 1);
1653
+ break;
1654
+ }
1655
+ }
1656
+ Atomics.store(handoff, 0, 0);
1657
+ return found;
1658
+ }
1659
+
1660
+ /** TSC_TS_SHARE: the sharing data of each of `count` checker threads. */
1661
+ function threadSharingOf(
1662
+ count: number,
1663
+ order: readonly number[],
1664
+ units: readonly number[],
1665
+ files: number,
1666
+ bounded: boolean,
1667
+ ): ThreadSharingData[] {
1668
+ const takers = new SharedArrayBuffer(4 * files);
1669
+ const forbidden = new SharedArrayBuffer(4 * files * forbiddenWords(count));
1670
+ // The checkers that missed on a key in each file, which a post requires (`ThreadSharing.demanded`). An unbounded
1671
+ // run posts as Phase 1 does and never reads it, so it gets a word rather than a bit per checker per file.
1672
+ const wanted = bounded ? new SharedArrayBuffer(4 * files * forbiddenWords(count)) : new SharedArrayBuffer(4);
1673
+ const handoff = new SharedArrayBuffer(4 * (3 + order.length));
1674
+ new Int32Array(handoff)[2] = count;
1675
+ const taken = new Int32Array(takers);
1676
+ taken.fill(-2);
1677
+ for (let k = 0; k < order.length; k++) {
1678
+ const i = order[k]!;
1679
+ if (i >= 0) {
1680
+ if (taken[i] === -2) taken[i] = 0;
1681
+ } else taken[units[3 * (-1 - i)]!] = -1;
1682
+ }
1683
+ const typeTable = new SharedArrayBuffer(8 * resultTableSize);
1684
+ const returnTable = new SharedArrayBuffer(8 * resultTableSize);
1685
+ const numberLogs: SharedArrayBuffer[] = [];
1686
+ const recordTables: SharedArrayBuffer[] = [];
1687
+ const stringLogs: SharedArrayBuffer[] = [];
1688
+ for (let i = 0; i < count; i++) {
1689
+ numberLogs.push(new SharedArrayBuffer(4 * numberLogSize));
1690
+ recordTables.push(new SharedArrayBuffer(4 * recordTableSize));
1691
+ stringLogs.push(new SharedArrayBuffer(2 * stringLogSize));
1692
+ }
1693
+ const used = new SharedArrayBuffer(4 * usedStride * count);
1694
+ // The stop switch (0 runs, 1 stops posting, 2 stops posting and translating) and the counters the
1695
+ // main thread reads at its window, a row per checker.
1696
+ const control = new SharedArrayBuffer(4);
1697
+ const stats = new SharedArrayBuffer(8 * shareStatColumns * count);
1698
+ const data: ThreadSharingData[] = [];
1699
+ for (let i = 0; i < count; i++)
1700
+ data.push({
1701
+ index: i,
1702
+ count,
1703
+ bounded,
1704
+ takers,
1705
+ forbidden,
1706
+ wanted,
1707
+ handoff,
1708
+ typeTable,
1709
+ returnTable,
1710
+ nodeIds: lastNodeIdValue(),
1711
+ symbolIds: lastSymbolIdValue(),
1712
+ numberLogs,
1713
+ recordTables,
1714
+ stringLogs,
1715
+ used,
1716
+ control,
1717
+ stats,
1718
+ });
1719
+ return data;
1720
+ }
1721
+
1552
1722
  /**
1553
1723
  * Checks files from the shared queue until it is empty; the main thread and checker threads alike.
1554
1724
  * A checker thread (`onMainThread` false) also sends back its global diagnostics. At `limit` files
@@ -1570,8 +1740,14 @@ export function checkFromQueue(
1570
1740
  emitKinds: readonly number[] | undefined = undefined,
1571
1741
  checking: boolean = true,
1572
1742
  units: readonly number[] = [],
1743
+ sharing: ThreadSharingData | undefined = undefined,
1573
1744
  ): CheckerResult {
1574
1745
  const start = performance.now();
1746
+ // TSC_TS_SHARE: each file's taker, which other checkers then take the results of its declarations from.
1747
+ const takers = sharing === undefined ? undefined : new Int32Array(sharing.takers);
1748
+ const forbidden = sharing === undefined ? undefined : new Int32Array(sharing.forbidden);
1749
+ const handoff = sharing === undefined ? undefined : new Int32Array(sharing.handoff);
1750
+ const sharingCount = sharing === undefined ? 0 : sharing.count;
1575
1751
  const readyAt = Date.now();
1576
1752
  const verbose = process.env.TSC_TS_CHECKERS_TRACE === '3';
1577
1753
  mark('checking');
@@ -1613,16 +1789,29 @@ export function checkFromQueue(
1613
1789
  if (limit > 0 && done.length >= limit) {
1614
1790
  more = true;
1615
1791
  left = reservedBy(index).splice(0);
1792
+ // The thread that continues doesn't share results, so it hands nothing on.
1793
+ if (handoff !== undefined) Atomics.sub(handoff, 2, 1);
1616
1794
  break;
1617
1795
  }
1618
1796
  // Except on checker 0, read the process's memory every 20 ms at most.
1619
1797
  if (retirement > 0 && performance.now() - memoryReadAt >= 20) {
1620
1798
  memoryReadAt = performance.now();
1621
- if (retires(counter, index, retirement)) break;
1799
+ if (retires(counter, index, retirement)) {
1800
+ if (handoff !== undefined) Atomics.sub(handoff, 2, 1);
1801
+ break;
1802
+ }
1622
1803
  }
1623
- const k = takePosition(counter, order.length, index, plan);
1804
+ let k = handoff !== undefined ? takeHandedOff(handoff, forbidden!, sharingCount, order, units, index) : -1;
1805
+ if (k < 0) k = takePosition(counter, order.length, index, plan);
1806
+ if (k < 0 && handoff !== undefined) k = waitForHandedOff(handoff, forbidden!, sharingCount, order, units, index);
1624
1807
  if (k < 0) break;
1625
1808
  const i = order[k]!;
1809
+ // A file this checker took results for before anyone took it goes to another checker.
1810
+ if (forbidden !== undefined && i >= 0 && isForbidden(forbidden, sharingCount, i, index)) {
1811
+ handOff(handoff!, k);
1812
+ continue;
1813
+ }
1814
+ if (takers !== undefined && i >= 0) Atomics.store(takers, i, index + 1);
1626
1815
  if (i < 0) {
1627
1816
  // A statement range of a declaration file, which has nothing to emit.
1628
1817
  const u = -1 - i;
@@ -1698,8 +1887,9 @@ export function checkFromQueue(
1698
1887
  }
1699
1888
  }
1700
1889
  mark(`checked ${done.length} files, ${unitsDone.length} ranges`);
1701
- // The main thread reports its own global diagnostics (CheckedProgram.getGlobalDiagnostics).
1702
- const globals = onMainThread ? [] : checked.getGlobalDiagnostics().slice();
1890
+ // On the main thread, those from before checking are the program's own (`ownGlobalDiagnostics`), and
1891
+ // CheckedProgram.getGlobalDiagnostics deduplicates them with these.
1892
+ const globals = (onMainThread ? checked.checker.getGlobalDiagnostics() : checked.getGlobalDiagnostics()).slice();
1703
1893
  let stats: number[] = [];
1704
1894
  if (process.env.TSC_TS_CHECKERS_TRACE !== undefined) {
1705
1895
  const cpu = process.threadCpuUsage();
@@ -1755,50 +1945,179 @@ export function mainThreadChecks(shared: boolean): boolean {
1755
1945
  }
1756
1946
 
1757
1947
  /**
1758
- * When a checker's own files are a small part of what it resolves (`libraryBoundCheckers`): the least
1759
- * text, in characters, of the libraries the files of a checker's range reach, on average over the
1760
- * ranges, and the least multiple of the text of the range's own files it is.
1948
+ * Whether the run reads the memory fit of sharing (`checkDecisionOf`): the static rule reads it where
1949
+ * the signals point at sharing, and a run the learning rules read may adopt sharing the static rule
1950
+ * leaves off, or explore it, when its samples show the configuration faster (DESIGN 4.3-4.4).
1951
+ *
1952
+ * A pin on sharing chooses sharing without a rule, but where it pins sharing on the learning rules still
1953
+ * compare checker counts with it, and every count they may adopt reads how many fit memory with sharing's
1954
+ * peak: a pinned count that no rule can change, and `TSC_TS_AUTO=0`, read nothing.
1761
1955
  */
1762
- const libraryBoundText = 6_000_000;
1763
- const libraryBoundShare = 5;
1956
+ export function sharingFitNeeded(config: RunConfig, signals: CheckSignals): boolean {
1957
+ if (config.automaticity === Automaticity.Off) return false;
1958
+ if (config.shareSource === Source.Pinned) {
1959
+ return (
1960
+ config.share &&
1961
+ config.checkersSource !== Source.Pinned &&
1962
+ learns(config.automaticity) &&
1963
+ config.record !== undefined
1964
+ );
1965
+ }
1966
+ if (sharingCandidate(signals)) return true;
1967
+ return learns(config.automaticity) && config.record !== undefined;
1968
+ }
1764
1969
 
1765
1970
  /**
1766
- * The number of checkers for `count` checkers whose ranges reach `library` characters of libraries
1767
- * and check `own` characters each, on average: three quarters of them (tsgo's four at least) where
1768
- * every checker spends most of its time resolving the same large libraries (`libraryBoundText`,
1769
- * `libraryBoundShare`), else `count`.
1971
+ * What `decideCheck` needs of the run besides its signals: whether the checker threads of a shared
1972
+ * program may share results (`startParallelCheck` makes the same test), and, where sharing is possible
1973
+ * and a rule that may choose it reads the estimate, how many checkers fit memory with sharing's peak
1974
+ * (`sharingFitNeeded`). The estimate costs a pass over the program's files and its memory limit, so it
1975
+ * is computed only where a rule reads it: a run without a record pays only where the static rule's
1976
+ * signals point at sharing, and one checker, a program that is not shared, a pinned run or
1977
+ * `TSC_TS_AUTO=0` pay nothing.
1978
+ */
1979
+ function checkDecisionOf(config: RunConfig, signals: CheckSignals, program: Program, shared: boolean): CheckDecision {
1980
+ // `mainThreadChecks` is false whenever the program is shared (`!shared`), as sharing needs.
1981
+ const possible = shared && signals.count > 1 && signals.count <= maxSharingCheckers;
1982
+ const fit = possible && sharingFitNeeded(config, signals) ? memoryFit(program) : undefined;
1983
+ // A run whose record the learning rules read also names the shape its samples describe, the CPUs a
1984
+ // count may use, the memory a configuration may not exceed and the time a control sample ages from.
1985
+ const learning = config.records || config.record !== undefined;
1986
+ return {
1987
+ possible,
1988
+ fit,
1989
+ shape: learning ? recordShapeOf(program, signals) : undefined,
1990
+ cpus: Math.min(availableCpus(), maxAutoCheckers),
1991
+ memoryBytes: memoryLimit(),
1992
+ now: Math.floor(Date.now() / 1000),
1993
+ };
1994
+ }
1995
+
1996
+ /** The program's shape for its record (`RecordShape`), with the shares the sharing rule reads as `F`. */
1997
+ function recordShapeOf(program: Program, signals: CheckSignals): RecordShape {
1998
+ const files = program.getSourceFiles();
1999
+ let chars = 0;
2000
+ let declarationChars = 0;
2001
+ for (const file of files) {
2002
+ chars += file.end;
2003
+ if (file.isDeclarationFile) declarationChars += file.end;
2004
+ }
2005
+ return {
2006
+ files: files.length,
2007
+ chars,
2008
+ declarationChars,
2009
+ checkChars: chars - declarationChars,
2010
+ library: Math.round(signals.library),
2011
+ own: Math.round(signals.own),
2012
+ redundancy: signals.redundancy,
2013
+ fileShare: Math.max(signals.declarationShare, signals.nodeModulesShare),
2014
+ };
2015
+ }
2016
+
2017
+ /** What the counters of `count` checkers say at the sharing window: milliseconds saved and spent. */
2018
+ interface SharingNumbers {
2019
+ /** What taking posted results saved, over the checkers: the computations they did not repeat. */
2020
+ readonly saved: number;
2021
+ /**
2022
+ * What posting cost: exporting and translating results. Translating a result reads its records in
2023
+ * place inside `ThreadSharing.translatePosted`'s timed translation, so `translationMs` holds that
2024
+ * reading too; counting a separate unpacking time would charge the window for it twice.
2025
+ */
2026
+ readonly spent: number;
2027
+ readonly posted: number;
2028
+ readonly translated: number;
2029
+ }
2030
+
2031
+ /**
2032
+ * The counters of `count` checkers' rows of `stats` (`ThreadSharing.writeStats`), summed. The tests read
2033
+ * this, next to the window it feeds.
2034
+ */
2035
+ export function sharingNumbers(stats: Float64Array, count: number): SharingNumbers {
2036
+ let saved = 0;
2037
+ let spent = 0;
2038
+ let posted = 0;
2039
+ let translated = 0;
2040
+ for (let i = 0; i < count; i++) {
2041
+ const row = i * shareStatColumns;
2042
+ saved += stats[row + shareStatSaved]!;
2043
+ spent += stats[row + shareStatExport]! + stats[row + shareStatTranslation]!;
2044
+ posted += stats[row + shareStatPosted]!;
2045
+ translated += stats[row + shareStatTranslated]!;
2046
+ }
2047
+ return { saved, spent, posted, translated };
2048
+ }
2049
+
2050
+ /**
2051
+ * The control a sharing run's numbers ask for: 2 when it saved less than 1.5 times what it spent, 1
2052
+ * when the posts go untaken (under 5% of them, and at least one), else 0. Stopping takes a minute at
2053
+ * worst, when the window's numbers are still too early to tell.
2054
+ */
2055
+ export function stopLevel(numbers: SharingNumbers): number {
2056
+ if (numbers.saved < 1.5 * numbers.spent) return 2;
2057
+ if (numbers.posted > 0 && numbers.translated / numbers.posted < 0.05) return 1;
2058
+ return 0;
2059
+ }
2060
+
2061
+ /**
2062
+ * Whether the rules of a run of `config` at `count` checkers read the check signals (`checkSignals`).
2063
+ * Two rules read them:
2064
+ *
2065
+ * - the library-bound cut (`decideCheck`), wherever the count is not pinned and is above tsgo's four.
2066
+ * This is the decision a run made before the automatic selection, and `TSC_TS_AUTO=0` keeps it: with
2067
+ * selection off the count is not cut for sharing either, but dropping the signals would leave the
2068
+ * cut nothing to read and start checkers the cut would not;
2069
+ * - the sharing rule, at `minSharingCheckers` or more, where neither the count nor sharing is pinned
2070
+ * (the cut may leave the count sharing was measured at, so the signals are read before it).
1770
2071
  *
1771
- * Each checker resolves the declarations its files reach, whatever else it checks. Where they are
1772
- * millions of characters, such as an Effect-based project's, and much more than the checker's own
1773
- * files, a checker costs seconds of CPU and hundreds of MB before its files get cheap, and the last
1774
- * quarter of the checkers (on 16 CPUs of 8 cores, the ones sharing a core with another) repeat that
1775
- * work rather than save time: T3 Code's web and server projects ran 3% and 1% faster with 12
1776
- * checkers than with 16, and used 16% and 8% less memory. Where checkers resolve less, or mostly
1777
- * check their own files, 12 of 16 checkers were slower: Excalidraw (1.4M library and 0.15M own
1778
- * characters per range) by 6%, Sentry (5.7M and 3.0M) and the tsc-ts sources by about 11%.
2072
+ * A pinned count and a pinned sharing read neither, and pay nothing for the pass over the ranges.
1779
2073
  */
1780
- export function libraryBoundCount(count: number, library: number, own: number): number {
1781
- return library >= libraryBoundText && library >= libraryBoundShare * own
1782
- ? Math.max(tsgoCheckers, Math.ceil((count * 3) / 4))
1783
- : count;
2074
+ export function signalsNeeded(config: RunConfig, count: number): boolean {
2075
+ const cut = config.checkersSource === Source.Default && count > tsgoCheckers;
2076
+ if (config.automaticity === Automaticity.Off) return cut;
2077
+ return cut || (config.shareSource === Source.Default && count >= minSharingCheckers);
1784
2078
  }
1785
2079
 
1786
2080
  /**
1787
- * The number of checkers for `plan`, made with `count` checkers that `auto` chose
1788
- * (`libraryBoundCount` of what its ranges reach and check).
2081
+ * What `plan`, made with `count` checkers, shows about the cost of checking (`CheckSignals`): the
2082
+ * libraries a range reaches and the files it checks, the share of that a second range reaches too, and
2083
+ * the shares of declaration and node_modules files of the program. Computed where a rule may read them
2084
+ * (`signalsNeeded`) and left at zero elsewhere: a pinned count needs none of them, and the pass over
2085
+ * every range's libraries costs a millisecond on a large program.
1789
2086
  */
1790
- function libraryBoundCheckers(checked: CheckedProgram, plan: CheckPlan, costs: CheckCosts, count: number): number {
1791
- if (checkerPolicy !== 'auto' || checked.program.options.checkers !== undefined || count <= tsgoCheckers) return count;
2087
+ function checkSignals(
2088
+ checked: CheckedProgram,
2089
+ plan: CheckPlan,
2090
+ costs: CheckCosts,
2091
+ count: number,
2092
+ config: RunConfig | undefined = undefined,
2093
+ ): CheckSignals {
2094
+ const ranges = plan.ranges.length >> 1;
2095
+ const signals = new CheckSignals(count, ranges);
1792
2096
  const program = checked.program;
2097
+ // What a rule would read, what the run's record writes (`config.records`), or what a doctor child
2098
+ // reports (`config.measure`), is computed; a pinned count with records off and no report pays nothing.
2099
+ const deciding =
2100
+ config === undefined
2101
+ ? checkersPolicy(process.env) === 'auto' && program.options.checkers === undefined && count > tsgoCheckers
2102
+ : signalsNeeded(config, count);
2103
+ const wanted = deciding || (config !== undefined && (config.records || config.measure));
2104
+ if (!wanted || ranges === 0) return signals;
1793
2105
  const files = program.getSourceFiles();
1794
2106
  const length = textLengths(program);
1795
2107
  const isChecked: boolean[] = [];
1796
- for (let i = 0; i < files.length; i++) isChecked.push(false);
2108
+ let declarationFiles = 0;
2109
+ let nodeModulesFiles = 0;
2110
+ for (let i = 0; i < files.length; i++) {
2111
+ isChecked.push(false);
2112
+ if (files[i]!.isDeclarationFile) declarationFiles++;
2113
+ if (files[i]!.path.indexOf('/node_modules/') >= 0) nodeModulesFiles++;
2114
+ }
1797
2115
  for (const i of costs.order) isChecked[i] = true;
1798
- const ranges = plan.ranges.length >> 1;
1799
- if (ranges === 0) return count;
1800
2116
  let library = 0;
1801
2117
  let own = 0;
2118
+ // The libraries every range reaches together, each counted once (`CheckSignals.redundancy`).
2119
+ const union = new Set<number>();
2120
+ let unionChars = 0;
1802
2121
  for (let r = 0; r < ranges; r++) {
1803
2122
  // The libraries the range's files import, and what they reach through other libraries (as checkCosts counts them).
1804
2123
  const reached = new Set<number>();
@@ -1815,6 +2134,10 @@ function libraryBoundCheckers(checked: CheckedProgram, plan: CheckPlan, costs: C
1815
2134
  while (stack.length > 0) {
1816
2135
  const k = stack.pop()!;
1817
2136
  library += length[k]!;
2137
+ if (!union.has(k)) {
2138
+ union.add(k);
2139
+ unionChars += length[k]!;
2140
+ }
1818
2141
  for (const t of costs.imports[k] ?? [])
1819
2142
  if (
1820
2143
  !reached.has(t) &&
@@ -1827,18 +2150,22 @@ function libraryBoundCheckers(checked: CheckedProgram, plan: CheckPlan, costs: C
1827
2150
  }
1828
2151
  }
1829
2152
  }
1830
- const fewer = libraryBoundCount(count, library / ranges, own / ranges);
2153
+ signals.library = library / ranges;
2154
+ signals.own = own / ranges;
2155
+ signals.redundancy = (library - unionChars) / (library + own);
2156
+ signals.declarationShare = declarationFiles / files.length;
2157
+ signals.nodeModulesShare = nodeModulesFiles / files.length;
2158
+ if (config !== undefined) config.signals = signals;
1831
2159
  if (process.env.TSC_TS_CHECKERS_TRACE !== undefined)
1832
2160
  process.stderr.write(
1833
- `checkers: ranges reach ${Math.round(library / ranges / 1000)}K library chars and check ${Math.round(own / ranges / 1000)}K on average: ${fewer} checkers\n`,
2161
+ `checkers: ranges reach ${Math.round(signals.library / 1000)}K library chars and check ${Math.round(signals.own / 1000)}K on average, ${Math.round(signals.redundancy * 100)}% of it reached twice: ${libraryBoundCount(count, signals.library, signals.own)} checkers\n`,
1834
2162
  );
1835
- return fewer;
2163
+ return signals;
1836
2164
  }
1837
2165
 
1838
2166
  /**
1839
- * Checks `checked` with `checkers` checkers (fewer where `auto` chose them and they would mostly
1840
- * resolve the same libraries: `libraryBoundCheckers`) and calls `done` with the wall time once
1841
- * `checked` holds every file's diagnostics.
2167
+ * Checks `checked` with `checkers` checkers (fewer where the configuration chooses so: `decideCheck`,
2168
+ * run-config.ts) and calls `done` with the wall time once `checked` holds every file's diagnostics.
1842
2169
  */
1843
2170
  /**
1844
2171
  * Shares the program of `checked` with checker threads (scriptc builds): this thread's checker merges the
@@ -1872,7 +2199,8 @@ export function shareWithCheckers(checked: CheckedProgram): void {
1872
2199
  * `emitsTo`, the emit results go only there, by file index, and nothing else the threads find reaches
1873
2200
  * the program: a declaration thread (parallel-emit.ts), while this thread's checker checks. With
1874
2201
  * `declarationsTo`, the same holds for the declaration errors of a `noEmit` program
1875
- * (`checkersReportDeclarations`).
2202
+ * (`checkersReportDeclarations`). `config` is the run's configuration: the count it chose is decided
2203
+ * here, once the program is bound and the plan made, and sharing is what it holds.
1876
2204
  */
1877
2205
  export function startParallelCheck(
1878
2206
  checked: CheckedProgram,
@@ -1883,6 +2211,7 @@ export function startParallelCheck(
1883
2211
  checking: boolean = true,
1884
2212
  emitsTo: (EmitResult | undefined)[] | undefined = undefined,
1885
2213
  declarationsTo: (Diagnostic[] | undefined)[] | undefined = undefined,
2214
+ config: RunConfig | undefined = undefined,
1886
2215
  ): void {
1887
2216
  let count = checkers;
1888
2217
  const start = performance.now();
@@ -1902,7 +2231,12 @@ export function startParallelCheck(
1902
2231
  const orderStart = performance.now();
1903
2232
  const costs = costOrder(checked);
1904
2233
  let plan = planSchedule(checked, count, costs, checking);
1905
- const fewer = libraryBoundCheckers(checked, plan, costs, count);
2234
+ const signals = checkSignals(checked, plan, costs, count, config);
2235
+ if (config !== undefined) config.signals = signals;
2236
+ const fewer =
2237
+ config === undefined
2238
+ ? libraryBoundCount(signals.count, signals.library, signals.own)
2239
+ : decideCheck(config, signals, checkDecisionOf(config, signals, program, shared));
1906
2240
  if (fewer < count) {
1907
2241
  count = fewer;
1908
2242
  plan = planSchedule(checked, count, costs, checking);
@@ -1944,7 +2278,13 @@ export function startParallelCheck(
1944
2278
  const firstThread = mainChecks ? 1 : 0;
1945
2279
  let remaining = count - firstThread;
1946
2280
  let ownDone = false;
2281
+ /** The sharing window's timer, where the threads share results; cleared when they are done. */
2282
+ let shareStopTimer: ReturnType<typeof setTimeout> | undefined = undefined;
1947
2283
  const finish = (): void => {
2284
+ if (shareStopTimer !== undefined) {
2285
+ clearTimeout(shareStopTimer);
2286
+ shareStopTimer = undefined;
2287
+ }
1948
2288
  if (emitsTo !== undefined || declarationsTo !== undefined) {
1949
2289
  mark('emitted on checker threads');
1950
2290
  done(performance.now() - start);
@@ -1952,9 +2292,15 @@ export function startParallelCheck(
1952
2292
  }
1953
2293
  if (checking) {
1954
2294
  joinRanges(checked, units, perUnit, perFile);
1955
- // A thread that failed may have taken files it never checked: check them here.
2295
+ // A thread that failed may have taken files it never checked, and with TSC_TS_SHARE every checker left may
2296
+ // have taken results for declarations of a file handed on: check them here.
2297
+ let left = 0;
1956
2298
  for (const i of order)
1957
- if (i >= 0 && perFile[i] === undefined) perFile[i] = checked.unfilteredDiagnosticsOfFile(files[i]!);
2299
+ if (i >= 0 && perFile[i] === undefined) {
2300
+ perFile[i] = checked.unfilteredDiagnosticsOfFile(files[i]!);
2301
+ left++;
2302
+ }
2303
+ if (trace && left > 0) process.stderr.write(`checkers: the main thread checked ${left} files\n`);
1958
2304
  checked.checkedInParallel = perFile;
1959
2305
  }
1960
2306
  mark('all checked');
@@ -2017,6 +2363,49 @@ export function startParallelCheck(
2017
2363
  if (remaining === 0 && ownDone) finish();
2018
2364
  };
2019
2365
  const diagnosticFiles = new Map<string, DiagnosticFile>();
2366
+ // Whether checker threads share results (shared-results.ts), which the run's configuration decides;
2367
+ // the emit threads of parallel-emit.ts have no configuration and never share (count 1).
2368
+ const sharesResults = config === undefined ? shareThreads === true : config.share;
2369
+ const sharing =
2370
+ sharesResults && shared && !mainChecks && count > 1 && count <= maxSharingCheckers
2371
+ ? threadSharingOf(count, order, units, files.length, config !== undefined && config.bounded)
2372
+ : undefined;
2373
+ if (sharing !== undefined) {
2374
+ // The main thread is idle while the checkers run, so a timer reads their counters at the window and
2375
+ // stops what does not pay (control 1 or 2); every checker computes what it does not take, so the
2376
+ // diagnostics stay the same.
2377
+ const control = new Int32Array(sharing[0]!.control);
2378
+ const stats = new Float64Array(sharing[0]!.stats);
2379
+ const stop = shareStop;
2380
+ const at = stop !== undefined ? stop.at : config !== undefined ? config.shareWindowMs : shareWindowMs;
2381
+ shareStopTimer = setTimeout(() => {
2382
+ const numbers = sharingNumbers(stats, count);
2383
+ if (stop !== undefined) Atomics.store(control, 0, stop.level);
2384
+ else {
2385
+ const level = stopLevel(numbers);
2386
+ if (level === 0) return;
2387
+ Atomics.store(control, 0, level);
2388
+ }
2389
+ // The section says what the window saw, instead of the rule that turned sharing on.
2390
+ if (config !== undefined) {
2391
+ config.shareSource = Source.Measured;
2392
+ config.shareReasons.length = 0;
2393
+ config.shareReasons.push(
2394
+ `stopped after ${at} ms: ${Math.round(numbers.saved)} ms saved for ${Math.round(numbers.spent)} ms spent`,
2395
+ );
2396
+ }
2397
+ if (trace)
2398
+ process.stderr.write(
2399
+ `checkers: stopped sharing after ${at} ms: ${Math.round(numbers.saved)} ms saved for ${Math.round(numbers.spent)} ms spent, ${numbers.translated}/${numbers.posted} posted results taken\n`,
2400
+ );
2401
+ }, at);
2402
+ }
2403
+ const sharingStarted: boolean[] = [];
2404
+ for (let i = 0; i < count; i++) sharingStarted.push(false);
2405
+ const startSharingOf = (i: number): ThreadSharingData => {
2406
+ sharingStarted[i] = true;
2407
+ return sharing![i]!;
2408
+ };
2020
2409
  const spawn = (i: number, reserved: number[]): void => {
2021
2410
  const worker = parallelCheck.spawn!(
2022
2411
  shared ? program : undefined,
@@ -2030,6 +2419,9 @@ export function startParallelCheck(
2030
2419
  emitKinds,
2031
2420
  checking,
2032
2421
  units,
2422
+ checked.globalsInFileDiagnostics,
2423
+ // A thread that continues another's index doesn't share.
2424
+ reserved.length === 0 && sharing !== undefined && !sharingStarted[i] ? startSharingOf(i) : undefined,
2033
2425
  );
2034
2426
  worker.on('message', (message: unknown) => {
2035
2427
  mark(`result from c${i}`);
@@ -2046,7 +2438,8 @@ export function startParallelCheck(
2046
2438
  else threadDone();
2047
2439
  });
2048
2440
  worker.on('error', (error: unknown) => {
2049
- if (trace) process.stderr.write(`checkers: thread ${i} failed: ${String(error)}\n`);
2441
+ // Sharing results (TSC_TS_SHARE) is still checked for such failures, which the main thread hides otherwise.
2442
+ if (trace || sharesResults) process.stderr.write(`checkers: thread ${i} failed: ${String(error)}\n`);
2050
2443
  threadDone();
2051
2444
  });
2052
2445
  };
@@ -2059,6 +2452,9 @@ export function startParallelCheck(
2059
2452
  const emittedHere =
2060
2453
  !mainChecks && emitKinds === undefined ? emitUncheckedFiles(checked, order, emits) : new Map<number, EmitResult>();
2061
2454
  if (mainChecks) {
2455
+ // The program reports the global diagnostics this checker has before checking files as found before
2456
+ // checking; those it finds checking them come with the threads' (`record`).
2457
+ checked.ownGlobalDiagnostics = checked.checker.getGlobalDiagnostics().slice();
2062
2458
  const own = checkFromQueue(
2063
2459
  checked,
2064
2460
  0,