tsc-ts 0.1.0 → 0.1.2

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 (81) hide show
  1. package/README.md +7 -1
  2. package/dist/api/compiler/ast.d.ts +15 -3
  3. package/dist/api/compiler/ast.js +36 -15
  4. package/dist/api/compiler/checker-classes.js +2 -1
  5. package/dist/api/compiler/checker-contextual.d.ts +20 -0
  6. package/dist/api/compiler/checker-contextual.js +111 -1
  7. package/dist/api/compiler/checker-expressions.js +14 -1
  8. package/dist/api/compiler/checker-grammar.d.ts +39 -4
  9. package/dist/api/compiler/checker-grammar.js +239 -75
  10. package/dist/api/compiler/checker-heritage.js +20 -14
  11. package/dist/api/compiler/checker-jsx.js +2 -1
  12. package/dist/api/compiler/checker-modules.js +4 -2
  13. package/dist/api/compiler/checker-source-file.js +1 -1
  14. package/dist/api/compiler/checker-type-factory.js +70 -19
  15. package/dist/api/compiler/checker-type-nodes.d.ts +1 -1
  16. package/dist/api/compiler/checker-type-nodes.js +5 -5
  17. package/dist/api/compiler/checker-unused.js +15 -10
  18. package/dist/api/compiler/checker.d.ts +7 -1
  19. package/dist/api/compiler/checker.js +14 -4
  20. package/dist/api/compiler/compile-program.d.ts +5 -0
  21. package/dist/api/compiler/compile-program.js +8 -0
  22. package/dist/api/compiler/expr-record.d.ts +11 -0
  23. package/dist/api/compiler/expr-record.js +53 -0
  24. package/dist/api/compiler/file-loader.d.ts +5 -0
  25. package/dist/api/compiler/file-loader.js +7 -0
  26. package/dist/api/compiler/identifier-name.d.ts +9 -0
  27. package/dist/api/compiler/identifier-name.js +10 -0
  28. package/dist/api/compiler/jsdoc.js +4 -2
  29. package/dist/api/compiler/parser.d.ts +2 -1
  30. package/dist/api/compiler/parser.js +10 -8
  31. package/dist/api/compiler/printer/factory.js +3 -2
  32. package/dist/api/compiler/printer/printer.js +3 -2
  33. package/dist/api/compiler/program-checker.d.ts +18 -0
  34. package/dist/api/compiler/program-checker.js +27 -0
  35. package/dist/api/compiler/reparser.js +4 -3
  36. package/dist/api/compiler/scanner.d.ts +8 -0
  37. package/dist/api/compiler/scanner.js +58 -42
  38. package/dist/api/compiler/shared-results.d.ts +376 -143
  39. package/dist/api/compiler/shared-results.js +1550 -773
  40. package/dist/api/compiler/transformers/declarations.js +2 -1
  41. package/package.json +15 -10
  42. package/src/compiler/ast.ts +39 -15
  43. package/src/compiler/cgroup.ts +157 -0
  44. package/src/compiler/checker-classes.ts +2 -1
  45. package/src/compiler/checker-contextual.ts +104 -0
  46. package/src/compiler/checker-expressions.ts +16 -1
  47. package/src/compiler/checker-grammar.ts +247 -88
  48. package/src/compiler/checker-heritage.ts +31 -17
  49. package/src/compiler/checker-jsx.ts +2 -1
  50. package/src/compiler/checker-modules.ts +4 -2
  51. package/src/compiler/checker-source-file.ts +1 -1
  52. package/src/compiler/checker-type-factory.ts +67 -21
  53. package/src/compiler/checker-type-nodes.ts +5 -5
  54. package/src/compiler/checker-unused.ts +13 -8
  55. package/src/compiler/checker.ts +15 -4
  56. package/src/compiler/compile-program.ts +8 -0
  57. package/src/compiler/decoder.ts +2 -1
  58. package/src/compiler/doctor-report.ts +133 -0
  59. package/src/compiler/expr-record.ts +59 -0
  60. package/src/compiler/file-loader.ts +8 -0
  61. package/src/compiler/identifier-name.ts +13 -0
  62. package/src/compiler/jsdoc.ts +4 -2
  63. package/src/compiler/parallel-check.ts +364 -146
  64. package/src/compiler/parallel-emit.ts +3 -3
  65. package/src/compiler/parse-thread.ts +24 -2
  66. package/src/compiler/parser.ts +10 -8
  67. package/src/compiler/printer/factory.ts +3 -2
  68. package/src/compiler/printer/printer.ts +4 -2
  69. package/src/compiler/program-checker.ts +28 -0
  70. package/src/compiler/reparser.ts +7 -3
  71. package/src/compiler/run-config.ts +1383 -0
  72. package/src/compiler/run-record-read.ts +87 -0
  73. package/src/compiler/run-records.ts +575 -0
  74. package/src/compiler/scanner.ts +57 -41
  75. package/src/compiler/shared-results.ts +1626 -896
  76. package/src/compiler/thread-entry.ts +3 -1
  77. package/src/compiler/transformers/declarations.ts +2 -1
  78. package/src/compiler/tsc-build.ts +64 -6
  79. package/src/compiler/tsc-cli.ts +33 -4
  80. package/src/compiler/tsc-compile.ts +223 -9
  81. package/src/compiler/tsc-watch.ts +25 -4
@@ -0,0 +1,59 @@
1
+ // The type the last completed check of an expression produced, by node and check mode, for the
2
+ // expressions that are checked with no contextual type.
3
+ //
4
+ // The checker checks some expressions more than once with the same inputs: a body that the eager
5
+ // pass reached and the deferred pass reaches again, a node re-checked after a loop body, an
6
+ // argument of a second inference round. A check is a function of the node, the check mode and the
7
+ // checker's state, and the state only grows while the checker runs, so a check that completed
8
+ // earlier answers the next check of the same node: the later check would produce the type the
9
+ // earlier one produced, report the diagnostics it reported and defer the nodes it deferred.
10
+ //
11
+ // A contextual type is part of the inputs, so the record can only serve an expression whose check
12
+ // has none: the checker-contextual predicate says so before the record is consulted, and a check
13
+ // under a contextual type never reads or writes the record. For the same reason the record is not
14
+ // consulted while an inference context is in force: what the check infers into depends on it.
15
+ //
16
+ // The record is a direct-mapped table that stores the key beside the value, so a lookup that lands
17
+ // on another node reads the entry as a miss. Its size bounds the memory and the cache the lookups
18
+ // use: an entry is a node id, a mode and a type slot, the whole table takes about 200 KB, and 2^14
19
+ // entries serve nearly all repeats (2^14 against 2^20 loses 0.1% of the check on the largest
20
+ // program measured).
21
+
22
+ import type { Type } from './checker-types.js';
23
+
24
+ /** Entries in the record; a power of two. */
25
+ const EntryCount = 1 << 14;
26
+ const EntryMask = EntryCount - 1;
27
+
28
+ /** The types by entry; a slot holds the type of the check recorded at that entry. */
29
+ function newTypeSlots(): (Type | undefined)[] {
30
+ const slots: (Type | undefined)[] = [];
31
+ for (let i = 0; i < EntryCount; i++) slots.push(undefined);
32
+ return slots;
33
+ }
34
+
35
+ function entryOf(nodeId: number, mode: number): number {
36
+ return (Math.imul(nodeId, 0x9e3779b1) ^ mode) & EntryMask;
37
+ }
38
+
39
+ export class ExprCheckRecord {
40
+ /** The node id of the check at each entry, plus one; zero where no check is recorded. */
41
+ private readonly nodeIds = new Int32Array(EntryCount);
42
+ private readonly modes = new Uint8Array(EntryCount);
43
+ private readonly types = newTypeSlots();
44
+
45
+ /** The type the last completed check of the node under `mode` produced, if the entry holds it. */
46
+ get(nodeId: number, mode: number): Type | undefined {
47
+ const entry = entryOf(nodeId, mode);
48
+ if (this.nodeIds[entry] !== nodeId + 1 || this.modes[entry] !== mode) return undefined;
49
+ return this.types[entry];
50
+ }
51
+
52
+ /** Records that a check of the node under `mode` produced `type`. */
53
+ set(nodeId: number, mode: number, type: Type): void {
54
+ const entry = entryOf(nodeId, mode);
55
+ this.nodeIds[entry] = nodeId + 1;
56
+ this.modes[entry] = mode;
57
+ this.types[entry] = type;
58
+ }
59
+ }
@@ -131,6 +131,12 @@ export class CompilerHost extends ModuleResolutionHost {
131
131
  return this.fs.getAccessibleEntries(path).directories;
132
132
  }
133
133
 
134
+ /**
135
+ * The metadata of the file `FileLoader` is parsing, which it computes from the file's package scope
136
+ * before it parses it; a host that walks the grammar of the parsed file reads it (parse-thread.ts).
137
+ */
138
+ loadingSourceFileMetadata: SourceFileMetadata | undefined = undefined;
139
+
134
140
  /** Parses a file, or returns `undefined` if it can't be read. */
135
141
  getSourceFile(
136
142
  fileName: string,
@@ -1222,6 +1228,8 @@ export class FileLoader {
1222
1228
  ? libFileMetadata
1223
1229
  : (loaded?.metadata ?? this.loadSourceFileMetadata(task.normalizedFilePath));
1224
1230
  const options = this.mapper.getCompilerOptionsForFile(task.path, task.normalizedFilePath);
1231
+ // For the host that walks the grammar of the file as it parses it (parse-thread.ts).
1232
+ this.host.loadingSourceFileMetadata = task.metadata;
1225
1233
  const file = this.host.getSourceFile(
1226
1234
  task.normalizedFilePath,
1227
1235
  task.path,
@@ -0,0 +1,13 @@
1
+ import type { ProgramLifetime } from '@scriptc/types';
2
+
3
+ /**
4
+ * The text of an identifier. The identifiers a parser's scanner interns with the same text share one
5
+ * (scanner.ts `IdentifierTable`), and natively an identifier refers to it in 4 bytes.
6
+ */
7
+ export class IdentifierName implements ProgramLifetime {
8
+ readonly text: string;
9
+
10
+ constructor(text: string) {
11
+ this.text = text;
12
+ }
13
+ }
@@ -57,6 +57,7 @@ import { Reparser } from './reparser.js';
57
57
  import { getLeadingCommentRanges, getTrailingCommentRanges } from './scanner.js';
58
58
  import { SyntaxKind } from './syntax-kind.js';
59
59
  import type { CommentRange } from './types.js';
60
+ import { IdentifierName } from './identifier-name.js';
60
61
 
61
62
  const enum JSDocState {
62
63
  BeginningOfLine,
@@ -1230,16 +1231,17 @@ export class JSDocParser {
1230
1231
  p.parseErrorAtCurrentToken(Diagnostics.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, [
1231
1232
  p.scanner.getTokenText(),
1232
1233
  ]);
1233
- const missing = p.newIdentifier('');
1234
+ const missing = p.newIdentifier(new IdentifierName(''));
1234
1235
  p.finishNode(missing, p.nodePos());
1235
1236
  return missing;
1236
1237
  }
1237
1238
  const pos = p.scanner.getTokenStart();
1238
1239
  const end = p.scanner.getTokenEnd();
1239
1240
  const text = p.scanner.getIdentifierValue();
1241
+ const name = p.scanner.getIdentifierName();
1240
1242
  p.internIdentifier(text);
1241
1243
  p.nextTokenJSDoc();
1242
- const result = p.newIdentifier(text);
1244
+ const result = p.newIdentifier(name);
1243
1245
  p.finishNodeWithEnd(result, pos, end);
1244
1246
  return result;
1245
1247
  }