@scriptc/compiler 0.2.9 → 0.2.10
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.
- package/dist/backend/cycle-analysis.d.ts +56 -0
- package/dist/backend/cycle-analysis.js +175 -14
- package/dist/backend/cycle-analysis.js.map +1 -1
- package/dist/backend/cycle-analysis.test.js +94 -1
- package/dist/backend/cycle-analysis.test.js.map +1 -1
- package/dist/backend/cycle-mutability.d.ts +2 -6
- package/dist/backend/cycle-mutability.js +3 -12
- package/dist/backend/cycle-mutability.js.map +1 -1
- package/dist/backend/immutability.d.ts +57 -0
- package/dist/backend/immutability.js +178 -0
- package/dist/backend/immutability.js.map +1 -0
- package/dist/backend/immutability.test.d.ts +1 -0
- package/dist/backend/immutability.test.js +131 -0
- package/dist/backend/immutability.test.js.map +1 -0
- package/dist/backend/llvm/borrowed-inputs.d.ts +9 -2
- package/dist/backend/llvm/borrowed-inputs.js +31 -3
- package/dist/backend/llvm/borrowed-inputs.js.map +1 -1
- package/dist/backend/llvm/classes.d.ts +28 -0
- package/dist/backend/llvm/classes.js +45 -5
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/classes.test.js +129 -1
- package/dist/backend/llvm/classes.test.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +13 -0
- package/dist/backend/llvm/common.js +13 -0
- package/dist/backend/llvm/common.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.js +5 -4
- package/dist/backend/llvm/dense-array-access.js.map +1 -1
- package/dist/backend/llvm/dense-array-access.test.js +9 -1
- package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
- package/dist/backend/llvm/dyn.d.ts +2 -0
- package/dist/backend/llvm/dyn.js +3 -3
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +64 -2
- package/dist/backend/llvm/emitter.js +390 -45
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/emitter.test.js +18 -0
- package/dist/backend/llvm/emitter.test.js.map +1 -1
- package/dist/backend/llvm/expr-calls.js +14 -6
- package/dist/backend/llvm/expr-calls.js.map +1 -1
- package/dist/backend/llvm/expr-containers.js +30 -7
- package/dist/backend/llvm/expr-containers.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.js +30 -3
- package/dist/backend/llvm/expr-primitives.js.map +1 -1
- package/dist/backend/llvm/expr-primitives.test.js +53 -0
- package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
- package/dist/backend/llvm/expr-stream-bridges.js +4 -4
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
- package/dist/backend/llvm/local-array-reads.js +3 -3
- package/dist/backend/llvm/local-array-reads.js.map +1 -1
- package/dist/backend/llvm/loop-array-borrows.d.ts +5 -2
- package/dist/backend/llvm/loop-array-borrows.js +27 -8
- package/dist/backend/llvm/loop-array-borrows.js.map +1 -1
- package/dist/backend/llvm/map-number-lookup.d.ts +7 -0
- package/dist/backend/llvm/map-number-lookup.js +18 -1
- package/dist/backend/llvm/map-number-lookup.js.map +1 -1
- package/dist/backend/llvm/map-read-lifetimes.d.ts +5 -0
- package/dist/backend/llvm/map-read-lifetimes.js +14 -4
- package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
- package/dist/backend/llvm/map-read-lifetimes.test.js +5 -0
- package/dist/backend/llvm/map-read-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/reference-writes.d.ts +124 -0
- package/dist/backend/llvm/reference-writes.js +1090 -0
- package/dist/backend/llvm/reference-writes.js.map +1 -0
- package/dist/backend/llvm/shapes.d.ts +8 -5
- package/dist/backend/llvm/shapes.js +36 -11
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/string-lifetimes.test.js +39 -10
- package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
- package/dist/backend/llvm/string-reads.d.ts +3 -0
- package/dist/backend/llvm/string-reads.js +31 -0
- package/dist/backend/llvm/string-reads.js.map +1 -1
- package/dist/backend/llvm/switch-dispatch.d.ts +2 -2
- package/dist/backend/llvm/switch-dispatch.js +35 -22
- package/dist/backend/llvm/switch-dispatch.js.map +1 -1
- package/dist/backend/llvm/switch-dispatch.test.js +28 -10
- package/dist/backend/llvm/switch-dispatch.test.js.map +1 -1
- package/dist/backend/llvm/walk-borrows.d.ts +8 -1
- package/dist/backend/llvm/walk-borrows.js +15 -4
- package/dist/backend/llvm/walk-borrows.js.map +1 -1
- package/dist/backend/may-throw.d.ts +36 -2
- package/dist/backend/may-throw.js +308 -12
- package/dist/backend/may-throw.js.map +1 -1
- package/dist/backend/may-throw.test.js +146 -1
- package/dist/backend/may-throw.test.js.map +1 -1
- package/dist/backend/publication.d.ts +5 -0
- package/dist/backend/publication.js +10 -0
- package/dist/backend/publication.js.map +1 -1
- package/dist/backend/runtime-abi.d.ts +2 -2
- package/dist/backend/runtime-abi.js +2 -2
- package/dist/backend/runtime-pack-targets.test.js +1 -1
- package/dist/backend/runtime-pack.test.js +1 -1
- package/dist/contracts/check.d.ts +8 -0
- package/dist/contracts/check.js +1577 -0
- package/dist/contracts/check.js.map +1 -0
- package/dist/executable/prepare.js +9 -0
- package/dist/executable/prepare.js.map +1 -1
- package/dist/frontend/contract-types.d.ts +50 -0
- package/dist/frontend/contract-types.js +232 -0
- package/dist/frontend/contract-types.js.map +1 -0
- package/dist/frontend/lowering/coercions/unions.d.ts +12 -0
- package/dist/frontend/lowering/coercions/unions.js +63 -0
- package/dist/frontend/lowering/coercions/unions.js.map +1 -1
- package/dist/frontend/lowering/expressions/optional-chains.js +4 -1
- package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +9 -2
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +83 -1
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +9 -0
- package/dist/frontend/lowering/lowerer.js +47 -0
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/narrowing-stability.d.ts +100 -0
- package/dist/frontend/lowering/narrowing-stability.js +1174 -0
- package/dist/frontend/lowering/narrowing-stability.js.map +1 -0
- package/dist/frontend/lowering/narrowing-stability.test.d.ts +1 -0
- package/dist/frontend/lowering/narrowing-stability.test.js +150 -0
- package/dist/frontend/lowering/narrowing-stability.test.js.map +1 -0
- package/dist/frontend/program.js +1 -1
- package/dist/frontend/type-mapper.js +43 -0
- package/dist/frontend/type-mapper.js.map +1 -1
- package/dist/ir/int32-slots.d.ts +26 -0
- package/dist/ir/int32-slots.js +147 -47
- package/dist/ir/int32-slots.js.map +1 -1
- package/dist/ir/integer-loops.js +3 -0
- package/dist/ir/integer-loops.js.map +1 -1
- package/dist/ir/integer-loops.test.js +26 -1
- package/dist/ir/integer-loops.test.js.map +1 -1
- package/dist/ir/integer-ranges.d.ts +20 -0
- package/dist/ir/integer-ranges.js +178 -21
- package/dist/ir/integer-ranges.js.map +1 -1
- package/dist/ir/integer-ranges.test.js +148 -3
- package/dist/ir/integer-ranges.test.js.map +1 -1
- package/dist/ir/ir.d.ts +32 -0
- package/dist/ir/ir.js.map +1 -1
- package/dist/ir/serialize.d.ts +5 -1
- package/dist/ir/serialize.js +8 -0
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/unshare.d.ts +14 -0
- package/dist/ir/unshare.js +60 -0
- package/dist/ir/unshare.js.map +1 -0
- package/dist/ir/unshare.test.d.ts +1 -0
- package/dist/ir/unshare.test.js +115 -0
- package/dist/ir/unshare.test.js.map +1 -0
- package/dist/library/prepare.js +9 -0
- package/dist/library/prepare.js.map +1 -1
- package/package.json +20 -20
- package/surface-manifest.json +1 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type CycleInitFlag } from "./cycle-initialization.js";
|
|
2
2
|
import type { FieldLift } from "./coercions/structural-plans.js";
|
|
3
3
|
import { CoercionState } from "./coercions/state.js";
|
|
4
|
+
import { NarrowingStability } from "./narrowing-stability.js";
|
|
4
5
|
import { StringIndexBounds } from "./string-index-bounds.js";
|
|
5
6
|
import { NanCodedReads } from "./nan-coded-reads.js";
|
|
6
7
|
import { RuntimeOptionalLocals } from "./runtime-optional-locals.js";
|
|
8
|
+
import { type ContractAnnotations } from "../contract-types.js";
|
|
7
9
|
import type { WidthLift } from "./width-lift.js";
|
|
8
10
|
import { type FnCtx } from "./function-context.js";
|
|
9
11
|
import type { FrontendServices } from "../services.js";
|
|
@@ -88,6 +90,9 @@ export interface LowerResult {
|
|
|
88
90
|
/** Present iff diagnostics is empty. */
|
|
89
91
|
module: IrModule | null;
|
|
90
92
|
diagnostics: ScrDiagnostic[];
|
|
93
|
+
/** The program's written contract types (@scriptc/types), keyed by the
|
|
94
|
+
* source locations the IR carries; absent when it writes none. */
|
|
95
|
+
contracts?: ContractAnnotations;
|
|
91
96
|
/** JS statements whose compile fences DEFERRED to runtime (runtimeFence
|
|
92
97
|
* statements in the module) — off the build, on the coverage report. */
|
|
93
98
|
runtimeFences: ScrDiagnostic[];
|
|
@@ -476,6 +481,10 @@ export declare class Lowerer {
|
|
|
476
481
|
* discriminant was captured. A case match narrows the captured value,
|
|
477
482
|
* not that mutable binding; preserve its tagged representation on reads. */
|
|
478
483
|
readonly unstableSwitchBindings: Set<ts.Symbol>;
|
|
484
|
+
/** Whether a checker narrowing of a mutable member or closure-assigned
|
|
485
|
+
* binding still holds at its use (calls do not reset TypeScript's
|
|
486
|
+
* narrowing). Stale ones read the declared storage or check it. */
|
|
487
|
+
readonly narrowing: NarrowingStability;
|
|
479
488
|
/** All storage slots widened for runtime absence, including slots whose
|
|
480
489
|
* current control-flow branch has temporarily narrowed the value. */
|
|
481
490
|
readonly runtimeOptionalStorageLocals: Set<IrLocal>;
|
|
@@ -19,12 +19,14 @@ import { lowerUtilTypeValue, pathModuleValue, utilTypesModuleValue, } from "./lo
|
|
|
19
19
|
import { everyExprChild, everyStmtChild, transformStmtList } from "../../ir/traverse.js";
|
|
20
20
|
import { RuntimeOptionalProvenance } from "./runtime-optional-provenance.js";
|
|
21
21
|
import { presentAtUse, reassignedBindings } from "./runtime-optional-guards.js";
|
|
22
|
+
import { NarrowingStability } from "./narrowing-stability.js";
|
|
22
23
|
import { ArrayElementStates } from "./runtime-optional-elements.js";
|
|
23
24
|
import { indexReadInBounds } from "./runtime-optional-bounds.js";
|
|
24
25
|
import { ArrayOwnership } from "./runtime-optional-ownership.js";
|
|
25
26
|
import { StringIndexBounds } from "./string-index-bounds.js";
|
|
26
27
|
import { NanCodedReads } from "./nan-coded-reads.js";
|
|
27
28
|
import { RuntimeOptionalLocals } from "./runtime-optional-locals.js";
|
|
29
|
+
import { collectContractAnnotations } from "../contract-types.js";
|
|
28
30
|
import { sanitizeUnregisteredClassTypes } from "./sanitize-class-types.js";
|
|
29
31
|
import { UnregisteredClassTypes } from "./unregistered-class-types.js";
|
|
30
32
|
import { bindingInContext, captureContextBinding, declareContextLocal, declareContextThis, } from "./function-context.js";
|
|
@@ -395,6 +397,39 @@ export function lowerToIr(program, entry, moduleOrder, options = {}) {
|
|
|
395
397
|
timing("divergence-scan", { found: divergences.length });
|
|
396
398
|
if (divergences.length > 0)
|
|
397
399
|
result = { ...result, divergences };
|
|
400
|
+
// Contract types (@scriptc/types): written annotations, checked against
|
|
401
|
+
// the IR by the compile pipeline (contracts/check.ts).
|
|
402
|
+
// Acyclic object types name the IR unit the program lowered them to; a
|
|
403
|
+
// type the module never uses has no unit (mapping it now only touches the
|
|
404
|
+
// lowerer's tables, never the finished module).
|
|
405
|
+
const lowered = result.module;
|
|
406
|
+
const contracts = collectContractAnnotations(program.getTypeChecker(), moduleOrder, (type) => {
|
|
407
|
+
if (lowered === null)
|
|
408
|
+
return null;
|
|
409
|
+
const mapped = panicSafe(() => resultLowerer.mapTypeOf(type), null);
|
|
410
|
+
if (mapped?.kind === "object")
|
|
411
|
+
return lowered.classes?.some((c) => c.name === mapped.className)
|
|
412
|
+
? `object:${mapped.className}`
|
|
413
|
+
: null;
|
|
414
|
+
if (mapped?.kind === "record")
|
|
415
|
+
return lowered.records?.some((r) => r.id === mapped.shapeId)
|
|
416
|
+
? `record:${mapped.shapeId}`
|
|
417
|
+
: null;
|
|
418
|
+
if (mapped?.kind === "union")
|
|
419
|
+
return lowered.unions?.some((u) => u.id === mapped.unionId)
|
|
420
|
+
? `union:${mapped.unionId}`
|
|
421
|
+
: null;
|
|
422
|
+
return null;
|
|
423
|
+
});
|
|
424
|
+
timing("contract-annotations", { found: contracts.count });
|
|
425
|
+
if (contracts.diagnostics.length > 0)
|
|
426
|
+
result = {
|
|
427
|
+
...result,
|
|
428
|
+
module: null,
|
|
429
|
+
diagnostics: [...result.diagnostics, ...contracts.diagnostics],
|
|
430
|
+
};
|
|
431
|
+
else if (contracts.count > 0)
|
|
432
|
+
result = { ...result, contracts };
|
|
398
433
|
if (options.coverage !== true)
|
|
399
434
|
return result;
|
|
400
435
|
const remainder = new Lowerer(program, entry, moduleOrder, dynamic, {
|
|
@@ -1219,6 +1254,10 @@ export class Lowerer {
|
|
|
1219
1254
|
* discriminant was captured. A case match narrows the captured value,
|
|
1220
1255
|
* not that mutable binding; preserve its tagged representation on reads. */
|
|
1221
1256
|
unstableSwitchBindings = new Set();
|
|
1257
|
+
/** Whether a checker narrowing of a mutable member or closure-assigned
|
|
1258
|
+
* binding still holds at its use (calls do not reset TypeScript's
|
|
1259
|
+
* narrowing). Stale ones read the declared storage or check it. */
|
|
1260
|
+
narrowing = new NarrowingStability(this);
|
|
1222
1261
|
/** All storage slots widened for runtime absence, including slots whose
|
|
1223
1262
|
* current control-flow branch has temporarily narrowed the value. */
|
|
1224
1263
|
runtimeOptionalStorageLocals = new Set();
|
|
@@ -4941,6 +4980,7 @@ export class Lowerer {
|
|
|
4941
4980
|
}
|
|
4942
4981
|
run() {
|
|
4943
4982
|
const parts = this.splitFiles();
|
|
4983
|
+
this.narrowing.setFiles(parts.map((fp) => fp.sf));
|
|
4944
4984
|
// The coverage remainder deliberately visits every body that reachable
|
|
4945
4985
|
// emit skipped. Those files are already phase-managed, so an ordinary
|
|
4946
4986
|
// checker miss would stay a one-node IPC query instead of falling back
|
|
@@ -5320,6 +5360,7 @@ export class Lowerer {
|
|
|
5320
5360
|
emitReachable(extraRoots) {
|
|
5321
5361
|
this.deferredModuleInitializers = new DeferredModuleInitializers();
|
|
5322
5362
|
const parts = this.splitFiles();
|
|
5363
|
+
this.narrowing.setFiles(parts.map((fp) => fp.sf));
|
|
5323
5364
|
// Direct lowering callers do not necessarily run program preflight.
|
|
5324
5365
|
// Establish the same managed header/top-level batch here before
|
|
5325
5366
|
// collection, while the production path simply finds warm memos.
|
|
@@ -6145,6 +6186,12 @@ export class Lowerer {
|
|
|
6145
6186
|
const narrowed = this.chainNarrowedType.get(node);
|
|
6146
6187
|
if (narrowed)
|
|
6147
6188
|
return narrowed;
|
|
6189
|
+
// A stale narrowing of a mutable member or closure-assigned binding in
|
|
6190
|
+
// an absence/type test (or a slot accepting the declared type) reads
|
|
6191
|
+
// as declared, so the test inspects the stored value.
|
|
6192
|
+
const widened = this.narrowing.widenedType(node);
|
|
6193
|
+
if (widened)
|
|
6194
|
+
return widened;
|
|
6148
6195
|
const t = this.checker.getTypeAtLocation(node);
|
|
6149
6196
|
// ALIASED-TYPEOF narrowing: inside a branch a `type === 'string'`
|
|
6150
6197
|
// test proves (type = typeof val, both never reassigned), references
|