@scriptc/compiler 0.0.33 → 0.0.35

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 (133) hide show
  1. package/dist/backend/cc-cache.test.js +1091 -7
  2. package/dist/backend/cc-cache.test.js.map +1 -1
  3. package/dist/backend/cc.d.ts +109 -18
  4. package/dist/backend/cc.js +1057 -289
  5. package/dist/backend/cc.js.map +1 -1
  6. package/dist/backend/emission/emit-exprs.js +26 -1
  7. package/dist/backend/emission/emit-exprs.js.map +1 -1
  8. package/dist/backend/emission/emit-shapes.js +37 -4
  9. package/dist/backend/emission/emit-shapes.js.map +1 -1
  10. package/dist/backend/emission/emitter.d.ts +11 -2
  11. package/dist/backend/emission/emitter.js +11 -5
  12. package/dist/backend/emission/emitter.js.map +1 -1
  13. package/dist/backend/library-identity.d.ts +22 -0
  14. package/dist/backend/library-identity.js +103 -0
  15. package/dist/backend/library-identity.js.map +1 -0
  16. package/dist/backend/llvm/emitter.d.ts +3 -0
  17. package/dist/backend/llvm/emitter.js +35 -5
  18. package/dist/backend/llvm/emitter.js.map +1 -1
  19. package/dist/backend/llvm/shapes.d.ts +1 -0
  20. package/dist/backend/llvm/shapes.js +25 -1
  21. package/dist/backend/llvm/shapes.js.map +1 -1
  22. package/dist/backend/llvm/split.d.ts +43 -0
  23. package/dist/backend/llvm/split.js +227 -0
  24. package/dist/backend/llvm/split.js.map +1 -0
  25. package/dist/backend/llvm/split.test.d.ts +1 -0
  26. package/dist/backend/llvm/split.test.js +102 -0
  27. package/dist/backend/llvm/split.test.js.map +1 -0
  28. package/dist/backend/mangle.d.ts +1 -0
  29. package/dist/backend/mangle.js +3 -0
  30. package/dist/backend/mangle.js.map +1 -1
  31. package/dist/backend/object-localize.d.ts +5 -5
  32. package/dist/backend/object-localize.js +19 -16
  33. package/dist/backend/object-localize.js.map +1 -1
  34. package/dist/backend/object-localize.test.js +57 -13
  35. package/dist/backend/object-localize.test.js.map +1 -1
  36. package/dist/executable/early-cache.d.ts +86 -0
  37. package/dist/executable/early-cache.js +460 -0
  38. package/dist/executable/early-cache.js.map +1 -0
  39. package/dist/executable/early-cache.test.d.ts +1 -0
  40. package/dist/executable/early-cache.test.js +300 -0
  41. package/dist/executable/early-cache.test.js.map +1 -0
  42. package/dist/ffi/profile.d.ts +7 -2
  43. package/dist/ffi/profile.js +1 -0
  44. package/dist/ffi/profile.js.map +1 -1
  45. package/dist/frontend/input-tracker.d.ts +82 -0
  46. package/dist/frontend/input-tracker.js +380 -0
  47. package/dist/frontend/input-tracker.js.map +1 -0
  48. package/dist/frontend/input-tracker.test.d.ts +1 -0
  49. package/dist/frontend/input-tracker.test.js +137 -0
  50. package/dist/frontend/input-tracker.test.js.map +1 -0
  51. package/dist/frontend/lowering/lower-builtins.js +4 -10
  52. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  53. package/dist/frontend/lowering/lower-calls.js +169 -144
  54. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  55. package/dist/frontend/lowering/lower-classes.js +3 -0
  56. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  57. package/dist/frontend/lowering/lower-containers.js +66 -32
  58. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  59. package/dist/frontend/lowering/lower-exprs.js +89 -11
  60. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  61. package/dist/frontend/lowering/lower-inspect.js +45 -26
  62. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  63. package/dist/frontend/lowering/lower-island.js +3 -3
  64. package/dist/frontend/lowering/lower-island.js.map +1 -1
  65. package/dist/frontend/lowering/lower-mixins.js +1 -1
  66. package/dist/frontend/lowering/lower-mixins.js.map +1 -1
  67. package/dist/frontend/lowering/lower-modules.js +1 -1
  68. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  69. package/dist/frontend/lowering/lower-stmts.js +49 -4
  70. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  71. package/dist/frontend/lowering/lowerer.d.ts +73 -29
  72. package/dist/frontend/lowering/lowerer.js +588 -116
  73. package/dist/frontend/lowering/lowerer.js.map +1 -1
  74. package/dist/frontend/lowering/surfaces.js +1 -1
  75. package/dist/frontend/lowering/surfaces.js.map +1 -1
  76. package/dist/frontend/npm-static-rewrite.js +25 -26
  77. package/dist/frontend/npm-static-rewrite.js.map +1 -1
  78. package/dist/frontend/npm-static.js +29 -30
  79. package/dist/frontend/npm-static.js.map +1 -1
  80. package/dist/frontend/npm-static.test.d.ts +1 -0
  81. package/dist/frontend/npm-static.test.js +15 -0
  82. package/dist/frontend/npm-static.test.js.map +1 -0
  83. package/dist/frontend/npm.js +5 -17
  84. package/dist/frontend/npm.js.map +1 -1
  85. package/dist/frontend/program.js +44 -19
  86. package/dist/frontend/program.js.map +1 -1
  87. package/dist/frontend/resolve.js +8 -29
  88. package/dist/frontend/resolve.js.map +1 -1
  89. package/dist/frontend/ts7/checker.d.ts +40 -2
  90. package/dist/frontend/ts7/checker.js +194 -32
  91. package/dist/frontend/ts7/checker.js.map +1 -1
  92. package/dist/frontend/ts7/program.js +17 -18
  93. package/dist/frontend/ts7/program.js.map +1 -1
  94. package/dist/frontend/types.d.ts +33 -0
  95. package/dist/frontend/types.js +134 -45
  96. package/dist/frontend/types.js.map +1 -1
  97. package/dist/index.d.ts +5 -2
  98. package/dist/index.js +458 -141
  99. package/dist/index.js.map +1 -1
  100. package/dist/ir/nodes.d.ts +27 -4
  101. package/dist/ir/nodes.js +28 -0
  102. package/dist/ir/nodes.js.map +1 -1
  103. package/dist/ir/serialize.d.ts +1 -1
  104. package/dist/ir/serialize.js +1 -1
  105. package/dist/ir/validate.js +37 -1
  106. package/dist/ir/validate.js.map +1 -1
  107. package/dist/library/early-cache.d.ts +65 -0
  108. package/dist/library/early-cache.js +361 -0
  109. package/dist/library/early-cache.js.map +1 -0
  110. package/dist/library/early-cache.test.d.ts +1 -0
  111. package/dist/library/early-cache.test.js +528 -0
  112. package/dist/library/early-cache.test.js.map +1 -0
  113. package/dist/library/implementation-identity.d.ts +23 -0
  114. package/dist/library/implementation-identity.js +84 -0
  115. package/dist/library/implementation-identity.js.map +1 -0
  116. package/dist/library/int-infer.js +14 -0
  117. package/dist/library/int-infer.js.map +1 -1
  118. package/dist/library/int-infer.test.js +21 -4
  119. package/dist/library/int-infer.test.js.map +1 -1
  120. package/dist/library/semantic-source.d.ts +13 -0
  121. package/dist/library/semantic-source.js +257 -0
  122. package/dist/library/semantic-source.js.map +1 -0
  123. package/dist/library/semantic-source.test.d.ts +1 -0
  124. package/dist/library/semantic-source.test.js +113 -0
  125. package/dist/library/semantic-source.test.js.map +1 -0
  126. package/dist/library/sidecar.d.ts +6 -0
  127. package/dist/library/sidecar.js +11 -0
  128. package/dist/library/sidecar.js.map +1 -1
  129. package/dist/startup-cache.d.ts +6 -0
  130. package/dist/startup-cache.js +6 -0
  131. package/dist/startup-cache.js.map +1 -0
  132. package/package.json +3 -2
  133. package/surface-manifest.json +1 -1
@@ -4,6 +4,11 @@ export interface ToolchainEnvironmentCachePolicy {
4
4
  }
5
5
  export declare function toolchainEnvironmentCachePolicy(env?: NodeJS.ProcessEnv): ToolchainEnvironmentCachePolicy;
6
6
  export declare function toolchainEnvironmentFingerprint(env?: NodeJS.ProcessEnv): string;
7
+ /** Inputs that can change which native tool/runtime implementation an
8
+ * executable build selects before compileC has a chance to rediscover it.
9
+ * The early whole-program cache keys this exact posture before restoring a
10
+ * final binary; compileC retains its deeper inode/content validation. */
11
+ export declare function executableNativeEnvironmentFingerprint(env?: NodeJS.ProcessEnv): Promise<string>;
7
12
  export interface CcOptions {
8
13
  /** Path of the generated (or hand-written) program TU: a .c file, or the
9
14
  * LLVM backend's .ll — clang compiles IR text natively on the same
@@ -18,6 +23,19 @@ export interface CcOptions {
18
23
  * top-level bytes alone can safely represent. scriptc's frontend supplies
19
24
  * this for its generated C/LLVM IR; `--from-c` deliberately does not. */
20
25
  cacheIdentity?: string;
26
+ /** Native optimization posture. Release preserves the historical -O2
27
+ * executable lane; dev selects -O0 and may compile a caller-provided LLVM
28
+ * shard set into independently cached objects before the final link. */
29
+ optimization?: "release" | "dev";
30
+ /** Optional equivalent LLVM modules for dev compilation. Unsupported
31
+ * targets or merge failures fall back to the canonical cPath TU. */
32
+ programShards?: readonly {
33
+ name: string;
34
+ source: string;
35
+ }[];
36
+ /** Canonical externally visible definitions retained while shard merging
37
+ * demotes generated cross-shard linkage back to local symbols. */
38
+ programPublicSymbols?: readonly string[];
21
39
  /** Build with ASan + the runtime RC audit (test/debug lane). */
22
40
  sanitize?: boolean;
23
41
  /** Additional native archives/objects, appended after the generated
@@ -196,6 +214,17 @@ export interface CcOptions {
196
214
  * The unit also compiles whenever `tls` does — scr_tls.c consults its
197
215
  * default-set override and shared Windows-certificate enumerator. */
198
216
  tlsCa?: boolean;
217
+ /** Internal compiler hook: called only after a strict native artifact hit
218
+ * or a successful stable build has installed `outPath`. The executable
219
+ * frontend cache uses it to publish its stamp after native dependencies
220
+ * have validated; arbitrary compileC callers leave it unset. */
221
+ onArtifactReady?: (artifact: ValidatedNativeArtifact) => Promise<void>;
222
+ }
223
+ /** Native dependency proof attached to an executable frontend-cache entry.
224
+ * compileC produces this only after its strict local/CAS validation succeeds;
225
+ * the early reader replays it before restoring the final executable. */
226
+ export interface ValidatedNativeArtifact {
227
+ dependencies: NativeArtifactDependency[];
199
228
  }
200
229
  /** Structured compiler-driver failure. Most callers still let this surface
201
230
  * as an internal build error; the TypeScript compiler pipeline recognizes it
@@ -264,13 +293,34 @@ export declare function cacheTargetIdentity(driver: Pick<CcDriver, "target">, ho
264
293
  * be used by both arm64 Node and Rosetta/x64 Node on macOS. */
265
294
  export declare function vendorCacheTargetFlavor(driver: Pick<CcDriver, "target">, hostPlatform?: NodeJS.Platform, hostArch?: string): string;
266
295
  /** Vendor prerequisites live outside the content-addressed build root, so
267
- * their directory name must carry the same environment and resolved compiler
268
- * identity as the artifacts that consume them. The short digest keeps the
269
- * package-local path readable while preventing build-order contamination. */
270
- export declare function vendorCacheBuildIdentity(environmentFingerprint: string, compilerIdentity: string): string;
296
+ * their directory name must carry the environment, resolved compiler, owned
297
+ * source bytes, and build-recipe identity of the artifacts that consume them.
298
+ * The short digest keeps the cache path readable while preventing build-order
299
+ * and cross-installation contamination. */
300
+ export declare function vendorCacheBuildIdentity(environmentFingerprint: string, compilerIdentity: string, nativeSourceIdentity: string): string;
271
301
  export interface LibArchiveOptions {
272
302
  /** The program TU (.c or .ll — clang compiles either with -c). */
273
303
  cPath: string;
304
+ /** Invocation-owned program source to compile under `cPath`'s public
305
+ * spelling. Library assembly uses this for the identity-free projection of
306
+ * a complete caller-visible TU; its bytes drive every native cache key. */
307
+ programSource?: string;
308
+ /** Optional equivalent LLVM modules for native compilation. The public
309
+ * `programSource` remains the canonical TU/cache identity; these stable
310
+ * shards compile independently and are relocatably merged into one program
311
+ * object before archive assembly. */
312
+ programShards?: readonly {
313
+ name: string;
314
+ source: string;
315
+ }[];
316
+ /** Canonical externally visible definitions retained while the shard merge
317
+ * demotes generated cross-shard linkage back to local symbols. */
318
+ programPublicSymbols?: readonly string[];
319
+ /** Tiny generated C source carrying volatile library identity getters.
320
+ * Its bytes join the complete archive key, but the source itself exists
321
+ * only in the invocation-private build directory and the large program-
322
+ * object cache is keyed independently. */
323
+ identityCSource?: string;
274
324
  /** The archive to produce (<name>.lib.a). */
275
325
  outPath: string;
276
326
  /** Caller-owned identity for the generated TU's complete non-system
@@ -318,6 +368,16 @@ export declare function compileLibArchive(opts: LibArchiveOptions): Promise<void
318
368
  /** Resolve the build cache without touching the filesystem. Exported from this
319
369
  * internal module so its platform and override behavior can be pinned directly. */
320
370
  export declare function resolveBuildCacheRoot(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform, userHome?: string): string | null;
371
+ /** Shared persistent-cache root for compiler-level tiers. The early library
372
+ * cache deliberately follows the native cache's activation and hard-disable
373
+ * contract, while native compilation retains ownership of toolchain safety. */
374
+ export declare function buildCacheRoot(): string | null;
375
+ /** Harden/create a compiler-level cache root using the same privacy policy as
376
+ * the artifact caches. Failure disables only the optional caller's tier. */
377
+ export declare function prepareBuildCacheRoot(root: string | null): Promise<string | null>;
378
+ /** Register a successful compiler-level cache write with the shared bounded
379
+ * LRU policy. */
380
+ export declare function pruneBuildCache(root: string | null): Promise<void>;
321
381
  export declare function ccVersionOnce(argv: string[], environmentFingerprint?: string, fresh?: boolean): Promise<string>;
322
382
  /** Every system-header spelling consumed by a source tree scriptc owns. The
323
383
  * dependency probe preprocesses these spellings with the selected driver and
@@ -328,24 +388,55 @@ export declare function ccVersionOnce(argv: string[], environmentFingerprint?: s
328
388
  export declare function implicitDependencyProbeIncludes(rtDir: string): Promise<string[]>;
329
389
  export declare function parseLinkTraceFiles(output: string, cwd: string, excludedRoot: string, driverDryRun?: boolean): Promise<string[]>;
330
390
  export declare function runtimeFingerprint(rtDir: string): Promise<string>;
391
+ export interface NativeArtifactDependency {
392
+ path: string;
393
+ kind: "file" | "directory" | "symlink";
394
+ dev: number;
395
+ ino: number;
396
+ size: number;
397
+ mtimeMs: number;
398
+ ctimeMs: number;
399
+ /** Symlinks are identity-bearing paths whose target bytes also matter. */
400
+ targetPath?: string;
401
+ targetKind?: "file" | "directory";
402
+ targetDev?: number;
403
+ targetIno?: number;
404
+ targetSize?: number;
405
+ targetMtimeMs?: number;
406
+ targetCtimeMs?: number;
407
+ /** A directory's recursive namespace. This detects a new nested candidate
408
+ * that can begin shadowing an existing system/header dependency. */
409
+ treeDigest?: string;
410
+ treeExclusions?: string[];
411
+ }
412
+ export declare function nativeArtifactDependenciesStillMatch(dependencies: readonly NativeArtifactDependency[]): Promise<boolean>;
331
413
  /** Give one active link/archive operation private names for its cached
332
414
  * runtime objects. A hard link keeps the inode alive if another process's LRU
333
415
  * sweep unlinks the cache entry; filesystems that cannot hard-link across the
334
416
  * cache/tmp boundary fall back to a copy. If eviction wins before staging,
335
417
  * the caller catches the read failure and performs a fully fresh compile. */
336
418
  export declare function stageRuntimeObjects(objects: ReadonlyMap<string, string>, stageDir: string): Promise<Map<string, string>>;
337
- /** Compiles one C program together with the runtime sources.
338
- * With caching disabled, the runtime (a dozen small files) is recompiled on
339
- * every build in one historical clang invocation — no cached-archive
340
- * staleness bugs. --dynamic additionally compiles
341
- * scr_island.c under SCR_DYNAMIC and links the cached engine archive (built
342
- * lazily, see above); regex-using programs additionally compile scr_regex.c
343
- * and link libregexp (the cached objects, or the archive's own copy under
344
- * --dynamic). Without either, the command line is exactly the historical
345
- * one — regex-free static builds must stay byte-identical.
346
- *
347
- * With a caller-supplied dependency identity and an enabled cache root,
348
- * unchanged programs skip payload code generation/linking via the binary
349
- * cache after lightweight metadata probes, and misses link the program's own
350
- * TU against cached per-flavor runtime objects. */
351
419
  export declare function compileC(opts: CcOptions): Promise<void>;
420
+ export type NativeCacheWarmProfile = "runtime" | "tls" | "dynamic";
421
+ export interface WarmNativeCachesOptions {
422
+ /** Native object posture to seed. Defaults to the shipped release/-O2 lane. */
423
+ optimization?: "release" | "dev";
424
+ /** Seed ASan + RC-audit objects instead of the ordinary lane. */
425
+ sanitize?: boolean;
426
+ /** Feature families to seed. Defaults to every expensive native family. */
427
+ profiles?: readonly NativeCacheWarmProfile[];
428
+ }
429
+ export interface WarmNativeCachesResult {
430
+ cacheRoot: string;
431
+ profiles: {
432
+ profile: NativeCacheWarmProfile;
433
+ elapsedMs: number;
434
+ }[];
435
+ }
436
+ export declare function supportedNativeCacheWarmProfiles(driver: CcDriver): readonly NativeCacheWarmProfile[];
437
+ /** Populate expensive native prerequisites against the current compiler,
438
+ * target, SDK, and environment. The resulting entries use the exact same
439
+ * identities and validators as ordinary builds; this merely pays their cost
440
+ * before a developer's first program asks for them. Synthetic link products
441
+ * are discarded and never enter the complete-executable cache. */
442
+ export declare function warmNativeCaches(options?: WarmNativeCachesOptions): Promise<WarmNativeCachesResult>;