carrick 0.3.135 → 0.3.136
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/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/capture/api.d.ts +11 -2
- package/sidecar/dist/src/capture/index.js +71 -1
- package/sidecar/dist/src/index.js +17 -11
- package/sidecar/dist/src/library-claims.d.ts +2 -0
- package/sidecar/dist/src/library-claims.js +30 -5
- package/sidecar/dist/src/type-inferrer.d.ts +63 -19
- package/sidecar/dist/src/type-inferrer.js +192 -71
- package/sidecar/dist/src/types.d.ts +4 -1
- package/sidecar/dist/src/validators.d.ts +6 -0
- package/sidecar/dist/src/validators.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carrick",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.136",
|
|
4
4
|
"carrickCache": {
|
|
5
5
|
"cache_version": 22,
|
|
6
6
|
"intent_cache_version": 2
|
|
@@ -114,11 +114,11 @@
|
|
|
114
114
|
"zod": "^3.23.0"
|
|
115
115
|
},
|
|
116
116
|
"optionalDependencies": {
|
|
117
|
-
"@carrick-tools/cli-darwin-arm64": "0.3.
|
|
118
|
-
"@carrick-tools/cli-darwin-x64": "0.3.
|
|
119
|
-
"@carrick-tools/cli-linux-arm64": "0.3.
|
|
120
|
-
"@carrick-tools/cli-linux-x64": "0.3.
|
|
121
|
-
"@carrick-tools/cli-win32-x64": "0.3.
|
|
117
|
+
"@carrick-tools/cli-darwin-arm64": "0.3.136",
|
|
118
|
+
"@carrick-tools/cli-darwin-x64": "0.3.136",
|
|
119
|
+
"@carrick-tools/cli-linux-arm64": "0.3.136",
|
|
120
|
+
"@carrick-tools/cli-linux-x64": "0.3.136",
|
|
121
|
+
"@carrick-tools/cli-win32-x64": "0.3.136"
|
|
122
122
|
},
|
|
123
123
|
"devDependencies": {
|
|
124
124
|
"@types/node": "^24.13.3"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carrick",
|
|
3
3
|
"description": "Claude Code plugin for Carrick, which indexes TypeScript codebases across service and repository boundaries. After each edit it adds the file's routes, calls, and cross-service type mismatches to the session, and it registers Carrick's language server. It pairs with the Carrick MCP server, which lets agents search functions by intent rather than name.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.136",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Carrick",
|
|
7
7
|
"email": "hello@carrick.tools"
|
|
@@ -236,10 +236,15 @@ export type SelfCheckOutcome = 'ok' | 'allowlisted_external' | 'decayed_internal
|
|
|
236
236
|
* into a function that builds the request body from it, and the body that
|
|
237
237
|
* function builds cannot be typed, so the argument is not the body and no
|
|
238
238
|
* contract is published (carrick#2628).
|
|
239
|
+
* - `reshaped_by_callback`: a consumer call's untyped result is handed
|
|
240
|
+
* unread to a callback in its chain (`.mapOk`, `.then`, `.andThen`, any
|
|
241
|
+
* name) that builds a new value from it, and nothing in the chain states
|
|
242
|
+
* the body, so the value the chain ends in is not the response the call
|
|
243
|
+
* receives and no contract is published (carrick#3004).
|
|
239
244
|
* - `not_recorded`: the position carries a top type and this layer has no
|
|
240
245
|
* cause for it.
|
|
241
246
|
*/
|
|
242
|
-
export type TypeProvenanceReason = 'declared' | 'unresolved_import' | 'budget_exhausted' | 'no_payload_evidence' | 'machinery_envelope' | 'coerced_input' | 'no_success_payload' | 'no_request_body' | 'projected_value_only' | 'serialised_body_unread' | 'body_built_by_callee' | 'result_member_missing' | 'not_recorded';
|
|
247
|
+
export type TypeProvenanceReason = 'declared' | 'unresolved_import' | 'budget_exhausted' | 'no_payload_evidence' | 'machinery_envelope' | 'coerced_input' | 'no_success_payload' | 'no_request_body' | 'projected_value_only' | 'serialised_body_unread' | 'body_built_by_callee' | 'reshaped_by_callback' | 'result_member_missing' | 'not_recorded';
|
|
243
248
|
/**
|
|
244
249
|
* One `any`/`unknown` finding inside a captured or inferred type, with its
|
|
245
250
|
* position and its cause. Sorted by `path` wherever a list is emitted, so the
|
|
@@ -382,8 +387,12 @@ export interface CaptureStubResult {
|
|
|
382
387
|
/** Number of emitted specifiers rewritten by the post-emit pass
|
|
383
388
|
* (tsconfig-paths mappings and absolute internal import types). */
|
|
384
389
|
specifier_rewrites: number;
|
|
385
|
-
/** True when the source repo had no node_modules at capture time
|
|
390
|
+
/** True when the source repo had no node_modules at capture time, or a
|
|
391
|
+
* dependency its package.json declares does not resolve from the service
|
|
392
|
+
* root (carrick#2999). */
|
|
386
393
|
bare_checkout: boolean;
|
|
394
|
+
/** The first few declared dependencies that did not resolve, sorted. */
|
|
395
|
+
unresolved_dependencies: string[];
|
|
387
396
|
ts_version: string;
|
|
388
397
|
errors: string[];
|
|
389
398
|
}
|
|
@@ -108,6 +108,7 @@ function fail(stubDir, packageName, errors) {
|
|
|
108
108
|
augmentation_files: [],
|
|
109
109
|
specifier_rewrites: 0,
|
|
110
110
|
bare_checkout: false,
|
|
111
|
+
unresolved_dependencies: [],
|
|
111
112
|
ts_version: ts.version,
|
|
112
113
|
errors,
|
|
113
114
|
};
|
|
@@ -518,7 +519,20 @@ export function captureStub(opts) {
|
|
|
518
519
|
console.error(`[sidecar] capture ${packageName}: ${edgeCount} dependency edge(s) recorded from the installed tree, ` +
|
|
519
520
|
`${resolution.unrecorded} left to the registry`);
|
|
520
521
|
const dependencyRoot = deno?.config.workspaceRoot ?? repoRoot;
|
|
521
|
-
const
|
|
522
|
+
const nodeModulesPresent = fs.existsSync(path.join(dependencyRoot, 'node_modules'));
|
|
523
|
+
const declared = deno || !nodeModulesPresent
|
|
524
|
+
? { unresolved: [], runtimeDeclared: 0, runtimeResolved: 0 }
|
|
525
|
+
: declaredDependencyResolution(dependencyRoot);
|
|
526
|
+
const unresolvedDependencies = declared.unresolved;
|
|
527
|
+
// Bare: no node_modules, or every declared runtime dependency dangles (a
|
|
528
|
+
// missing pnpm store). One missing package, or missing devDependencies,
|
|
529
|
+
// leaves the installed ones usable (carrick#2999).
|
|
530
|
+
const bareCheckout = !deno &&
|
|
531
|
+
(!nodeModulesPresent || (declared.runtimeDeclared > 0 && declared.runtimeResolved === 0));
|
|
532
|
+
if (unresolvedDependencies.length > 0) {
|
|
533
|
+
console.error(`[sidecar] capture ${packageName}: declared dependencies do not resolve` +
|
|
534
|
+
`${bareCheckout ? ' (bare checkout)' : ''}: ${unresolvedDependencies.join(', ')}`);
|
|
535
|
+
}
|
|
522
536
|
stubGuard.writeFile(path.join(stubDir, 'package.json'), JSON.stringify({
|
|
523
537
|
name: packageName,
|
|
524
538
|
version: '0.0.0-carrick',
|
|
@@ -568,10 +582,66 @@ export function captureStub(opts) {
|
|
|
568
582
|
augmentation_files: augmentationFiles.sort(),
|
|
569
583
|
specifier_rewrites: specifierRewrites,
|
|
570
584
|
bare_checkout: bareCheckout,
|
|
585
|
+
unresolved_dependencies: unresolvedDependencies,
|
|
571
586
|
ts_version: ts.version,
|
|
572
587
|
errors,
|
|
573
588
|
};
|
|
574
589
|
}
|
|
590
|
+
/** How many unresolved packages a capture result names. */
|
|
591
|
+
const UNRESOLVED_DEPENDENCIES_NAMED = 5;
|
|
592
|
+
/**
|
|
593
|
+
* How `root/package.json` dependencies resolve from `root`: no
|
|
594
|
+
* `node_modules/<name>` in `root` or any parent directory means unresolved.
|
|
595
|
+
* `existsSync` follows links, so a pnpm link into a missing store reads as
|
|
596
|
+
* unresolved (carrick#2999). `unresolved` is the first few names across
|
|
597
|
+
* dependencies and devDependencies, sorted; the runtime counts cover
|
|
598
|
+
* `dependencies` only. Declared names only, one stat per ancestor.
|
|
599
|
+
*/
|
|
600
|
+
function declaredDependencyResolution(root) {
|
|
601
|
+
const none = { unresolved: [], runtimeDeclared: 0, runtimeResolved: 0 };
|
|
602
|
+
let manifest;
|
|
603
|
+
try {
|
|
604
|
+
manifest = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
605
|
+
}
|
|
606
|
+
catch {
|
|
607
|
+
return none;
|
|
608
|
+
}
|
|
609
|
+
if (manifest === null || typeof manifest !== 'object')
|
|
610
|
+
return none;
|
|
611
|
+
const names = (field) => {
|
|
612
|
+
const group = manifest[field];
|
|
613
|
+
return group !== null && typeof group === 'object' ? Object.keys(group) : [];
|
|
614
|
+
};
|
|
615
|
+
const resolves = (name) => {
|
|
616
|
+
let dir = path.resolve(root);
|
|
617
|
+
for (;;) {
|
|
618
|
+
if (fs.existsSync(path.join(dir, 'node_modules', name)))
|
|
619
|
+
return true;
|
|
620
|
+
const parent = path.dirname(dir);
|
|
621
|
+
if (parent === dir)
|
|
622
|
+
return false;
|
|
623
|
+
dir = parent;
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
const runtime = new Set(names('dependencies'));
|
|
627
|
+
const all = new Set([...runtime, ...names('devDependencies')]);
|
|
628
|
+
let runtimeResolved = 0;
|
|
629
|
+
const unresolved = [];
|
|
630
|
+
for (const name of [...all].sort()) {
|
|
631
|
+
if (resolves(name)) {
|
|
632
|
+
if (runtime.has(name))
|
|
633
|
+
runtimeResolved++;
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
unresolved.push(name);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
unresolved: unresolved.slice(0, UNRESOLVED_DEPENDENCIES_NAMED),
|
|
641
|
+
runtimeDeclared: runtime.size,
|
|
642
|
+
runtimeResolved,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
575
645
|
/**
|
|
576
646
|
* Phase B: build the program of the final entry and emit its declarations.
|
|
577
647
|
*
|
|
@@ -61,16 +61,16 @@ function initializedLoader() {
|
|
|
61
61
|
return projectLoader;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
|
-
* carrick#
|
|
65
|
-
* `
|
|
66
|
-
* scanner's binary:
|
|
67
|
-
* not a whole number
|
|
64
|
+
* carrick#2629: the most readings one batch's unwidened reading may make,
|
|
65
|
+
* when `CARRICK_UNWIDENED_READINGS_CAP` sets it. A switch for tests that
|
|
66
|
+
* drive the scanner's binary: 0 forces every reading past the cap, on any
|
|
67
|
+
* machine. Unset or not a whole number, the inferrer's default stands.
|
|
68
68
|
*/
|
|
69
|
-
function
|
|
70
|
-
const value = process.env.
|
|
69
|
+
function unwidenedLimitsFromEnv() {
|
|
70
|
+
const value = process.env.CARRICK_UNWIDENED_READINGS_CAP;
|
|
71
71
|
if (value === undefined || !/^\d+$/.test(value.trim()))
|
|
72
72
|
return undefined;
|
|
73
|
-
return Number(value.trim());
|
|
73
|
+
return { readings: Number(value.trim()) };
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Get the project-backed components, building the project if this is the
|
|
@@ -94,7 +94,7 @@ function projectComponents(key = '') {
|
|
|
94
94
|
project,
|
|
95
95
|
repoRoot,
|
|
96
96
|
packageOf: (filePath) => loader.packageOf(filePath),
|
|
97
|
-
|
|
97
|
+
unwidenedLimits: unwidenedLimitsFromEnv(),
|
|
98
98
|
});
|
|
99
99
|
built = {
|
|
100
100
|
typeBundler: new TypeBundler({ project, repoRoot }),
|
|
@@ -351,13 +351,19 @@ function handleInfer(request) {
|
|
|
351
351
|
}
|
|
352
352
|
// One count for the request, whichever programs its items span.
|
|
353
353
|
let done = 0;
|
|
354
|
-
|
|
354
|
+
let readingSteps = 0;
|
|
355
|
+
const report = atMostEvery(PROGRESS_INTERVAL_MS, () => writeProgress(request.request_id, 'infer', readingSteps === 0
|
|
356
|
+
? `${done} of ${request.requests.length}`
|
|
357
|
+
: `${done} of ${request.requests.length}, unwidened reading step ${readingSteps}`));
|
|
355
358
|
const results = [...groups].map(([key, items]) => {
|
|
356
359
|
const built = projectComponents(key);
|
|
357
360
|
return built.typeInferrer.infer(items, request.extraction_config, () => {
|
|
358
361
|
done += 1;
|
|
359
362
|
report();
|
|
360
|
-
}, request.model_symbols, labelledMembersFor(built, key, items, request.server_claims))
|
|
363
|
+
}, request.model_symbols, labelledMembersFor(built, key, items, request.server_claims), () => {
|
|
364
|
+
readingSteps += 1;
|
|
365
|
+
report();
|
|
366
|
+
});
|
|
361
367
|
});
|
|
362
368
|
const result = results.length === 1
|
|
363
369
|
? results[0]
|
|
@@ -637,7 +643,7 @@ function handleListLibrarySurface(request) {
|
|
|
637
643
|
const { claimsVerifier } = projectComponents();
|
|
638
644
|
const fromDir = path.resolve(projectLoader.getRepoRoot(), request.from_dir);
|
|
639
645
|
log(`Listing the declared surface of ${request.packages.length} specifier(s) from ${fromDir}`);
|
|
640
|
-
const { surfaces, surface_sha256 } = claimsVerifier.listSurface(fromDir, request.packages, request.max_entries ?? SURFACE_MAX_ENTRIES, request.exports ?? {}, { handlers: request.handlers, resultCandidates: request.result_candidates });
|
|
646
|
+
const { surfaces, surface_sha256 } = claimsVerifier.listSurface(fromDir, request.packages, request.max_entries ?? SURFACE_MAX_ENTRIES, request.exports ?? {}, { handlers: request.handlers, resultCandidates: request.result_candidates, maxHandlerMembers: request.max_handler_members });
|
|
641
647
|
return { request_id: request.request_id, status: 'success', surfaces, surface_sha256 };
|
|
642
648
|
}
|
|
643
649
|
catch (err) {
|
|
@@ -208,5 +208,7 @@ export interface SurfaceOptions {
|
|
|
208
208
|
handlers?: boolean;
|
|
209
209
|
/** Each signature's `result_candidates` (carrick#2817). */
|
|
210
210
|
resultCandidates?: boolean;
|
|
211
|
+
/** Handler-parameter members the whole call may list (default `HANDLER_LISTING_BUDGET`, carrick#3016). */
|
|
212
|
+
maxHandlerMembers?: number;
|
|
211
213
|
}
|
|
212
214
|
export {};
|
|
@@ -751,10 +751,14 @@ export class LibraryClaimsVerifier {
|
|
|
751
751
|
}
|
|
752
752
|
});
|
|
753
753
|
const firstBuild = imports.length + importLines.length;
|
|
754
|
-
const surfaces = this.readProbe(fromDir, [...imports, ...importLines, ...buildLines], (checker, reader, file) =>
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
754
|
+
const surfaces = this.readProbe(fromDir, [...imports, ...importLines, ...buildLines], (checker, reader, file) => {
|
|
755
|
+
// One budget for the whole call, spent across its specifiers: the answer is one line.
|
|
756
|
+
reader.startListing(options.maxHandlerMembers ?? HANDLER_LISTING_BUDGET);
|
|
757
|
+
return packages.map((pkg, i) => reader.listPackage(pkg, probeOf(file, i), maxEntries, only[pkg], options, (name, receiver) => {
|
|
758
|
+
const index = builtIndex.get(builtKey({ package: pkg, export: name }, receiver));
|
|
759
|
+
return index === undefined ? undefined : resolvedBuild(checker, file.statements[firstBuild + index]);
|
|
760
|
+
}));
|
|
761
|
+
});
|
|
758
762
|
return { surfaces, surface_sha256: fullSurfaceSha256(surfaces) };
|
|
759
763
|
}
|
|
760
764
|
/** `read` over a probe file holding `lines` in `fromDir`, removed again afterwards. */
|
|
@@ -1072,8 +1076,14 @@ class DeclarationReader {
|
|
|
1072
1076
|
/** `takesString` per signature, and `scopeMembers` per type and home: the same types recur across receivers. */
|
|
1073
1077
|
takesStringRead = new Map();
|
|
1074
1078
|
scopeMembersRead = new Map();
|
|
1075
|
-
/** Handler-parameter members `HANDLER_MEMBER_CAP` dropped in the package being listed. */
|
|
1079
|
+
/** Handler-parameter members `HANDLER_MEMBER_CAP` and the listing's budget dropped in the package being listed. */
|
|
1076
1080
|
handlersDropped = 0;
|
|
1081
|
+
/** Handler-parameter members the rest of this `listSurface` call may still list (carrick#3016). */
|
|
1082
|
+
handlerBudget = HANDLER_LISTING_BUDGET;
|
|
1083
|
+
/** Begin one `listSurface` call: its specifiers share `handlerBudget` handler-parameter members. */
|
|
1084
|
+
startListing(handlerBudget) {
|
|
1085
|
+
this.handlerBudget = handlerBudget;
|
|
1086
|
+
}
|
|
1077
1087
|
/** Whether the package being listed lists each signature's `result_candidates`. */
|
|
1078
1088
|
listResultCandidates = false;
|
|
1079
1089
|
/** The service root as given and as a realpath, longest first: what a listing prints as `<root>`. */
|
|
@@ -3595,6 +3605,12 @@ class DeclarationReader {
|
|
|
3595
3605
|
return;
|
|
3596
3606
|
const { members, dropped } = this.handlerMembersOf(type);
|
|
3597
3607
|
this.handlersDropped += dropped;
|
|
3608
|
+
// Past the listing's budget a parameter is left out whole and counted (carrick#3016).
|
|
3609
|
+
if (members.length > this.handlerBudget) {
|
|
3610
|
+
this.handlersDropped += members.length;
|
|
3611
|
+
return;
|
|
3612
|
+
}
|
|
3613
|
+
this.handlerBudget -= members.length;
|
|
3598
3614
|
listed.push({ param: index, name: parameter.getName(), type: this.printed(type), members });
|
|
3599
3615
|
});
|
|
3600
3616
|
return listed;
|
|
@@ -4229,6 +4245,15 @@ const HANDLER_MEMBER_DEPTH = 2;
|
|
|
4229
4245
|
* order, so this must stay at least that.
|
|
4230
4246
|
*/
|
|
4231
4247
|
const HANDLER_MEMBER_CAP = 500;
|
|
4248
|
+
/**
|
|
4249
|
+
* The most handler-parameter members one `listSurface` call lists, across all
|
|
4250
|
+
* its specifiers (carrick#3016). The answer is one JSON line and a string
|
|
4251
|
+
* passes V8's limit at about 512 MiB; a member costs about 150 bytes, so this
|
|
4252
|
+
* keeps the handlers near 75 MB beside an export listing of tens of MB. A
|
|
4253
|
+
* server framework handing 50 distinct request types to thousands of members
|
|
4254
|
+
* listed 8.99 million of them (1.3 GB) before it.
|
|
4255
|
+
*/
|
|
4256
|
+
const HANDLER_LISTING_BUDGET = 500_000;
|
|
4232
4257
|
const PRINT_FLAGS = ts.NodeBuilderFlags.AllowUniqueESSymbolType |
|
|
4233
4258
|
ts.NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope |
|
|
4234
4259
|
ts.NodeBuilderFlags.IgnoreErrors |
|
|
@@ -74,16 +74,40 @@ export interface TypeInferrerOptions {
|
|
|
74
74
|
*/
|
|
75
75
|
repoRoot: string;
|
|
76
76
|
/**
|
|
77
|
-
* How
|
|
78
|
-
* (carrick#
|
|
77
|
+
* How much work the unwidened reading of one `infer` batch may do
|
|
78
|
+
* (carrick#2629). Each field defaults to its `UNWIDENED_*` constant.
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
unwidenedLimits?: Partial<UnwidenedLimits>;
|
|
81
|
+
/**
|
|
82
|
+
* The clock the unwidened reading's last-resort time limit reads, in
|
|
83
|
+
* milliseconds. Defaults to `performance.now`; a test passes a slow one.
|
|
84
|
+
*/
|
|
85
|
+
now?: () => number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The bounds on one batch's unwidened reading (carrick#2629). The first two
|
|
89
|
+
* count work, so a batch reads the same on a quiet machine and a loaded one;
|
|
90
|
+
* the third is a wall-clock backstop for a reading that runs away.
|
|
91
|
+
*/
|
|
92
|
+
export interface UnwidenedLimits {
|
|
93
|
+
/** Readings (requests re-read in the rewrite) one batch may make. */
|
|
94
|
+
readings: number;
|
|
95
|
+
/** Files one batch may type-check before and after its rewrite. */
|
|
96
|
+
files: number;
|
|
97
|
+
/** The longest the reading may run, from its start, before it stops. */
|
|
98
|
+
backstopMs: number;
|
|
81
99
|
}
|
|
82
100
|
/**
|
|
83
101
|
* Called each time an `infer` batch is done with one of its requests,
|
|
84
102
|
* whatever that request answered: skipped, refused, failed or inferred.
|
|
85
103
|
*/
|
|
86
104
|
export type InferRequestDone = () => void;
|
|
105
|
+
/**
|
|
106
|
+
* Called each time the unwidened reading finishes a unit of its work: a file
|
|
107
|
+
* type-checked or a request re-read (carrick#2629). The reading runs after
|
|
108
|
+
* every request is done, so this is what keeps a long one from going silent.
|
|
109
|
+
*/
|
|
110
|
+
export type UnwidenedStepDone = () => void;
|
|
87
111
|
/**
|
|
88
112
|
* TypeInferrer - Extracts types from source code, both explicit and inferred
|
|
89
113
|
*
|
|
@@ -101,7 +125,8 @@ export declare class TypeInferrer {
|
|
|
101
125
|
* unwidened reading re-reads from here (carrick#1516).
|
|
102
126
|
*/
|
|
103
127
|
private readonly readNodes;
|
|
104
|
-
private readonly
|
|
128
|
+
private readonly unwidenedLimits;
|
|
129
|
+
private readonly now;
|
|
105
130
|
/**
|
|
106
131
|
* The files a request has named to this inferrer, as the requests named
|
|
107
132
|
* them (carrick#1985). It lives as long as the project does, so the first
|
|
@@ -122,9 +147,10 @@ export declare class TypeInferrer {
|
|
|
122
147
|
* @param requests - Array of inference requests
|
|
123
148
|
* @param extractionConfig - Agent-generated extraction config for payload unwrapping
|
|
124
149
|
* @param onRequestDone - Called once per request, as the batch is done with it
|
|
150
|
+
* @param onUnwidenedStep - Called once per unit of the unwidened reading's work
|
|
125
151
|
* @returns InferResult with inferred types or errors
|
|
126
152
|
*/
|
|
127
|
-
infer(requests: InferRequestItem[], extractionConfig?: ExtractionConfig, onRequestDone?: InferRequestDone, modelSymbols?: ModelSymbol[], labels?: LabelledMembers): InferResult;
|
|
153
|
+
infer(requests: InferRequestItem[], extractionConfig?: ExtractionConfig, onRequestDone?: InferRequestDone, modelSymbols?: ModelSymbol[], labels?: LabelledMembers, onUnwidenedStep?: UnwidenedStepDone): InferResult;
|
|
128
154
|
/** The types the model named, by the alias of the row each is for (carrick#2111). */
|
|
129
155
|
private modelSymbols;
|
|
130
156
|
/**
|
|
@@ -177,11 +203,15 @@ export declare class TypeInferrer {
|
|
|
177
203
|
* and every file restored before returning, so the project other requests
|
|
178
204
|
* read is the project the scan loaded.
|
|
179
205
|
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
206
|
+
* The reading is bounded by work, not time (carrick#2629): a batch makes at
|
|
207
|
+
* most `UnwidenedLimits.readings` readings over at most `.files` files,
|
|
208
|
+
* taken in request order, the responses first. The first request past
|
|
209
|
+
* either cap and every request after it are marked
|
|
210
|
+
* `unwidened_out_of_budget` (carrick#2100) and publish no reading, on any
|
|
211
|
+
* machine. A reading still running at the wall-clock backstop stops the
|
|
212
|
+
* same way and says so in the log. A request that never needed a reading
|
|
213
|
+
* (a declared return, nothing to mark) or lost it for a reason of its own
|
|
214
|
+
* (a marking that added a diagnostic) is never marked.
|
|
185
215
|
*/
|
|
186
216
|
private addUnwidenedReadings;
|
|
187
217
|
/**
|
|
@@ -893,20 +923,34 @@ export declare class TypeInferrer {
|
|
|
893
923
|
* the chain ends in is what the caller computed from it, and publishing
|
|
894
924
|
* that as the body is the false mismatch this rule exists for.
|
|
895
925
|
*
|
|
896
|
-
*
|
|
926
|
+
* A call that narrows that parameter (a schema validates it, or a function
|
|
927
|
+
* returns it unchanged) states it the same way (carrick#3004).
|
|
928
|
+
*
|
|
929
|
+
* Exactly one such read across the whole chain answers. None, or more than
|
|
897
930
|
* one (a callback on the failure side can be handed an `unknown` too), and
|
|
898
|
-
*
|
|
899
|
-
*
|
|
900
|
-
*
|
|
931
|
+
* `handedUnread` says a callback was handed the body all the same: what it
|
|
932
|
+
* returns is a value built from the body (`.mapOk`, `.then`, `.andThen`,
|
|
933
|
+
* whatever the name), so the value the chain ends in is never the body
|
|
934
|
+
* (carrick#3004). A parameter typed `any` is not read: an unresolved
|
|
935
|
+
* library types every callback that way, success and failure alike, so it
|
|
936
|
+
* says nothing about which one is the body.
|
|
901
937
|
*/
|
|
902
938
|
private bodyReadInCallbackChain;
|
|
903
939
|
/**
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
|
|
940
|
+
* `type`, or a type argument it is instantiated with at any depth, is
|
|
941
|
+
* `any` or `unknown`: `Chain<unknown>`, `Task<Outcome<unknown, E>>`. The
|
|
942
|
+
* value such a carrier hands its callbacks is untyped (carrick#3004).
|
|
943
|
+
*/
|
|
944
|
+
private holdsTopTypeArgument;
|
|
945
|
+
/**
|
|
946
|
+
* What a callback states about its first parameter, when the compiler types
|
|
947
|
+
* that parameter `unknown`, or `undefined` when it is not handed one. A
|
|
948
|
+
* statement is a cast whose operand is the parameter itself (`response as
|
|
949
|
+
* T`, `<T>response`), or a call that narrows it (`callStatesItsArgument`:
|
|
950
|
+
* a schema validates it, or a function returns it unchanged). A cast that
|
|
951
|
+
* leaves a position open states nothing about the body and is skipped.
|
|
908
952
|
*/
|
|
909
|
-
private
|
|
953
|
+
private statementsOfUnreadParameter;
|
|
910
954
|
/**
|
|
911
955
|
* The zero-argument whole-body read taken in place on the value `callExpr`
|
|
912
956
|
* yields, or `undefined` (carrick#1851): `(await fetch(url)).text()`. The
|
|
@@ -201,6 +201,7 @@ const DECIDED_ABSTAIN_REASONS = new Set([
|
|
|
201
201
|
'projected_value_only',
|
|
202
202
|
'serialised_body_unread',
|
|
203
203
|
'body_built_by_callee',
|
|
204
|
+
'reshaped_by_callback',
|
|
204
205
|
]);
|
|
205
206
|
/** The provenance sentence for each reason a branch was not read. */
|
|
206
207
|
const SERIALISED_BODY_UNREAD_DETAIL = {
|
|
@@ -397,21 +398,22 @@ function isBareStringText(text) {
|
|
|
397
398
|
members.every((member) => member === 'string' || member === 'null' || member === 'undefined'));
|
|
398
399
|
}
|
|
399
400
|
/**
|
|
400
|
-
* How
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
401
|
+
* How many readings one batch may make (carrick#2629). A count, not a time,
|
|
402
|
+
* so whether a reading is made never depends on the machine's load: a reading
|
|
403
|
+
* a batch cannot make marks its response `unwidened_out_of_budget`, and the
|
|
404
|
+
* check then abstains on every mismatch against it (carrick#2100). Sized well
|
|
405
|
+
* above the largest batch measured; see the PR that set it.
|
|
405
406
|
*/
|
|
406
|
-
const
|
|
407
|
+
const UNWIDENED_MAX_READINGS = 5_000;
|
|
408
|
+
/** How many files one batch's reading may type-check (carrick#2629). */
|
|
409
|
+
const UNWIDENED_MAX_FILES = 5_000;
|
|
407
410
|
/**
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* reading, as before.
|
|
411
|
+
* The last resort: a reading still running this long after it started stops
|
|
412
|
+
* and says so in the log. The reading reports progress after every file it
|
|
413
|
+
* checks and every request it re-reads, so the scanner's limit on silence
|
|
414
|
+
* never needs it; it is here for a reading that runs away.
|
|
413
415
|
*/
|
|
414
|
-
const
|
|
416
|
+
const UNWIDENED_BACKSTOP_MS = 30 * 60_000;
|
|
415
417
|
/**
|
|
416
418
|
* TypeInferrer - Extracts types from source code, both explicit and inferred
|
|
417
419
|
*
|
|
@@ -429,7 +431,8 @@ export class TypeInferrer {
|
|
|
429
431
|
* unwidened reading re-reads from here (carrick#1516).
|
|
430
432
|
*/
|
|
431
433
|
readNodes = new WeakMap();
|
|
432
|
-
|
|
434
|
+
unwidenedLimits;
|
|
435
|
+
now;
|
|
433
436
|
/**
|
|
434
437
|
* The files a request has named to this inferrer, as the requests named
|
|
435
438
|
* them (carrick#1985). It lives as long as the project does, so the first
|
|
@@ -440,7 +443,12 @@ export class TypeInferrer {
|
|
|
440
443
|
this.project = options.project;
|
|
441
444
|
this.packageOf = options.packageOf;
|
|
442
445
|
this.repoRoot = options.repoRoot;
|
|
443
|
-
this.
|
|
446
|
+
this.unwidenedLimits = {
|
|
447
|
+
readings: options.unwidenedLimits?.readings ?? UNWIDENED_MAX_READINGS,
|
|
448
|
+
files: options.unwidenedLimits?.files ?? UNWIDENED_MAX_FILES,
|
|
449
|
+
backstopMs: options.unwidenedLimits?.backstopMs ?? UNWIDENED_BACKSTOP_MS,
|
|
450
|
+
};
|
|
451
|
+
this.now = options.now ?? (() => performance.now());
|
|
444
452
|
}
|
|
445
453
|
/**
|
|
446
454
|
* What the structural printer needs to tell the user's own declarations from
|
|
@@ -461,10 +469,10 @@ export class TypeInferrer {
|
|
|
461
469
|
* @param requests - Array of inference requests
|
|
462
470
|
* @param extractionConfig - Agent-generated extraction config for payload unwrapping
|
|
463
471
|
* @param onRequestDone - Called once per request, as the batch is done with it
|
|
472
|
+
* @param onUnwidenedStep - Called once per unit of the unwidened reading's work
|
|
464
473
|
* @returns InferResult with inferred types or errors
|
|
465
474
|
*/
|
|
466
|
-
infer(requests, extractionConfig, onRequestDone, modelSymbols, labels) {
|
|
467
|
-
const started = performance.now();
|
|
475
|
+
infer(requests, extractionConfig, onRequestDone, modelSymbols, labels, onUnwidenedStep) {
|
|
468
476
|
this.modelSymbols = new Map((modelSymbols ?? []).map((symbol) => [symbol.alias, symbol]));
|
|
469
477
|
this.statedParams = this.statedParamsFor(labels ?? { sends: new Map(), bodies: new Set() });
|
|
470
478
|
const inferredTypes = [];
|
|
@@ -541,7 +549,14 @@ export class TypeInferrer {
|
|
|
541
549
|
}
|
|
542
550
|
}
|
|
543
551
|
try {
|
|
544
|
-
|
|
552
|
+
// One allowance for the batch: the responses draw on it first, the
|
|
553
|
+
// bodies on what they leave.
|
|
554
|
+
const work = {
|
|
555
|
+
readings: this.unwidenedLimits.readings,
|
|
556
|
+
files: this.unwidenedLimits.files,
|
|
557
|
+
backstopAt: this.now() + this.unwidenedLimits.backstopMs,
|
|
558
|
+
step: onUnwidenedStep ?? (() => { }),
|
|
559
|
+
};
|
|
545
560
|
// The responses' rewrite forgets every node of the files it touches, so
|
|
546
561
|
// each body's read node is kept as its span, taken now and found again
|
|
547
562
|
// in the restored file.
|
|
@@ -558,22 +573,22 @@ export class TypeInferrer {
|
|
|
558
573
|
};
|
|
559
574
|
});
|
|
560
575
|
try {
|
|
561
|
-
this.addUnwidenedReadings(responses, extractionConfig,
|
|
576
|
+
this.addUnwidenedReadings(responses, extractionConfig, work, 'response');
|
|
562
577
|
}
|
|
563
578
|
catch (err) {
|
|
564
579
|
// The reading only ever adds a field; it never costs an answer.
|
|
565
580
|
this.logError(`Unwidened reading failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
566
581
|
}
|
|
567
582
|
try {
|
|
568
|
-
// Second, and in a rewrite of its own: the bodies
|
|
569
|
-
// response's
|
|
570
|
-
// abstention (carrick#2100).
|
|
571
|
-
this.addUnwidenedReadings(bodySpans, extractionConfig,
|
|
583
|
+
// Second, and in a rewrite of its own: the bodies never take a
|
|
584
|
+
// response's share of the work, whose cap a spent allowance turns into
|
|
585
|
+
// an abstention (carrick#2100).
|
|
586
|
+
this.addUnwidenedReadings(bodySpans, extractionConfig, work, 'request_body');
|
|
572
587
|
}
|
|
573
588
|
catch (err) {
|
|
574
589
|
this.logError(`Unwidened reading of request bodies failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
575
590
|
// carrick#2011: a body whose reading was not made is judged on its
|
|
576
|
-
// widened type alone, so it is marked the way a spent
|
|
591
|
+
// widened type alone, so it is marked the way a spent work cap marks it
|
|
577
592
|
// and its pair abstains on a mismatch rather than report one.
|
|
578
593
|
for (const body of bodies) {
|
|
579
594
|
if (body.result.unwidened_type_string === undefined) {
|
|
@@ -693,25 +708,28 @@ export class TypeInferrer {
|
|
|
693
708
|
* and every file restored before returning, so the project other requests
|
|
694
709
|
* read is the project the scan loaded.
|
|
695
710
|
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
|
|
702
|
-
|
|
711
|
+
* The reading is bounded by work, not time (carrick#2629): a batch makes at
|
|
712
|
+
* most `UnwidenedLimits.readings` readings over at most `.files` files,
|
|
713
|
+
* taken in request order, the responses first. The first request past
|
|
714
|
+
* either cap and every request after it are marked
|
|
715
|
+
* `unwidened_out_of_budget` (carrick#2100) and publish no reading, on any
|
|
716
|
+
* machine. A reading still running at the wall-clock backstop stops the
|
|
717
|
+
* same way and says so in the log. A request that never needed a reading
|
|
718
|
+
* (a declared return, nothing to mark) or lost it for a reason of its own
|
|
719
|
+
* (a marking that added a diagnostic) is never marked.
|
|
720
|
+
*/
|
|
721
|
+
addUnwidenedReadings(responses, extractionConfig, work, read) {
|
|
722
|
+
const started = this.now();
|
|
703
723
|
const outOfTime = (stage, unread) => {
|
|
704
|
-
if (
|
|
724
|
+
if (this.now() <= work.backstopAt)
|
|
705
725
|
return false;
|
|
706
|
-
this.log(`Unwidened reading stopped ${stage}: it ran
|
|
707
|
-
|
|
726
|
+
this.log(`Unwidened reading stopped ${stage}: it ran past its last-resort time limit ` +
|
|
727
|
+
`(${this.unwidenedLimits.backstopMs} ms), ${unread.length} reading(s) not made`);
|
|
708
728
|
for (const plan of unread)
|
|
709
729
|
plan.result.unwidened_out_of_budget = true;
|
|
710
730
|
return true;
|
|
711
731
|
};
|
|
712
|
-
const
|
|
713
|
-
const insertionsByFile = new Map();
|
|
714
|
-
const checkedFiles = new Set();
|
|
732
|
+
const planned = [];
|
|
715
733
|
// Every position is read before the first rewrite: a rewrite forgets
|
|
716
734
|
// every node of its file.
|
|
717
735
|
for (const { request, result, readSpan } of responses) {
|
|
@@ -724,25 +742,21 @@ export class TypeInferrer {
|
|
|
724
742
|
if (!readNode)
|
|
725
743
|
continue;
|
|
726
744
|
const functions = pathOf(readNode);
|
|
727
|
-
|
|
745
|
+
const planInsertions = [];
|
|
728
746
|
for (const fn of functions) {
|
|
729
747
|
const insertions = literalInsertions(fn, read === 'request_body' ? readNode : undefined);
|
|
730
|
-
marked += insertions.length;
|
|
731
748
|
if (insertions.length === 0)
|
|
732
749
|
continue;
|
|
733
|
-
|
|
734
|
-
insertionsByFile.set(file, [...(insertionsByFile.get(file) ?? []), ...insertions]);
|
|
750
|
+
planInsertions.push([fn.getSourceFile(), insertions]);
|
|
735
751
|
}
|
|
736
752
|
// Nothing on the path to mark: the reading would equal the published type.
|
|
737
|
-
if (
|
|
753
|
+
if (planInsertions.length === 0)
|
|
738
754
|
continue;
|
|
739
755
|
const path = functions.map((fn) => ({
|
|
740
756
|
file: fn.getSourceFile(),
|
|
741
757
|
start: fn.getStart(),
|
|
742
758
|
end: fn.getEnd(),
|
|
743
759
|
}));
|
|
744
|
-
for (const fn of path)
|
|
745
|
-
checkedFiles.add(fn.file);
|
|
746
760
|
let locatedByText;
|
|
747
761
|
if (request.expression_text && request.span_start === undefined) {
|
|
748
762
|
const sourceFile = this.getSourceFile(request.file_path);
|
|
@@ -752,24 +766,62 @@ export class TypeInferrer {
|
|
|
752
766
|
if (located)
|
|
753
767
|
locatedByText = { start: located.getStart(), end: located.getEnd() };
|
|
754
768
|
}
|
|
755
|
-
|
|
769
|
+
planned.push({
|
|
756
770
|
request,
|
|
757
771
|
result,
|
|
758
772
|
read: { file: readNode.getSourceFile(), start: readNode.getStart(), end: readNode.getEnd() },
|
|
759
773
|
path,
|
|
774
|
+
insertions: planInsertions,
|
|
760
775
|
locatedByText,
|
|
761
776
|
});
|
|
762
777
|
}
|
|
763
|
-
if (
|
|
778
|
+
if (planned.length === 0)
|
|
764
779
|
return;
|
|
780
|
+
// The work cap: requests are taken in order while both allowances last.
|
|
781
|
+
const checkedFiles = new Set();
|
|
782
|
+
let taken = 0;
|
|
783
|
+
for (const plan of planned) {
|
|
784
|
+
const added = new Set(plan.path.map((fn) => fn.file).filter((f) => !checkedFiles.has(f)));
|
|
785
|
+
if (work.readings < 1 || added.size > work.files)
|
|
786
|
+
break;
|
|
787
|
+
work.readings -= 1;
|
|
788
|
+
work.files -= added.size;
|
|
789
|
+
for (const file of added)
|
|
790
|
+
checkedFiles.add(file);
|
|
791
|
+
taken += 1;
|
|
792
|
+
}
|
|
793
|
+
const plans = planned.slice(0, taken);
|
|
794
|
+
const capped = planned.slice(taken);
|
|
795
|
+
if (capped.length > 0) {
|
|
796
|
+
this.log(`Unwidened reading stopped at its work cap (${this.unwidenedLimits.readings} readings, ` +
|
|
797
|
+
`${this.unwidenedLimits.files} files per batch): ${capped.length} reading(s) not made`);
|
|
798
|
+
for (const plan of capped)
|
|
799
|
+
plan.result.unwidened_out_of_budget = true;
|
|
800
|
+
}
|
|
801
|
+
/** Readings that came back narrower than the published type, and so were published. */
|
|
802
|
+
let narrower = 0;
|
|
803
|
+
const report = () => this.log(`Unwidened reading of ${read === 'response' ? 'responses' : 'request bodies'}: ` +
|
|
804
|
+
`${planned.length} planned, ${plans.length} taken over ${checkedFiles.size} file(s), ` +
|
|
805
|
+
`${narrower} narrower than published, ${Math.round(this.now() - started)} ms`);
|
|
806
|
+
if (plans.length === 0) {
|
|
807
|
+
report();
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
const insertionsByFile = new Map();
|
|
811
|
+
for (const plan of plans) {
|
|
812
|
+
for (const [file, list] of plan.insertions) {
|
|
813
|
+
insertionsByFile.set(file, [...(insertionsByFile.get(file) ?? []), ...list]);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
765
816
|
const insertions = new Map();
|
|
766
817
|
for (const [file, list] of insertionsByFile)
|
|
767
818
|
insertions.set(file, normalise(list));
|
|
768
819
|
const before = new Map();
|
|
769
820
|
for (const file of checkedFiles) {
|
|
770
821
|
if (outOfTime('before the rewrite', plans))
|
|
771
|
-
return;
|
|
822
|
+
return report();
|
|
772
823
|
before.set(file, fileDiagnostics(file));
|
|
824
|
+
work.step();
|
|
773
825
|
}
|
|
774
826
|
const originals = new Map();
|
|
775
827
|
for (const file of insertions.keys())
|
|
@@ -784,9 +836,11 @@ export class TypeInferrer {
|
|
|
784
836
|
const tainted = new Set();
|
|
785
837
|
for (const file of checkedFiles) {
|
|
786
838
|
if (outOfTime('while checking the rewrite', plans))
|
|
787
|
-
return;
|
|
839
|
+
return report();
|
|
788
840
|
const list = insertions.get(file) ?? [];
|
|
789
|
-
|
|
841
|
+
const after = fileDiagnostics(file);
|
|
842
|
+
work.step();
|
|
843
|
+
for (const at of addedDiagnostics(before.get(file), after, list)) {
|
|
790
844
|
const holders = plans.flatMap((plan) => plan.path).filter((fn) => fn.file === file && fn.start <= at && at < fn.end);
|
|
791
845
|
for (const plan of plans) {
|
|
792
846
|
const onPath = plan.path.some((fn) => holders.length > 0 ? holders.includes(fn) : fn.file === file);
|
|
@@ -797,7 +851,7 @@ export class TypeInferrer {
|
|
|
797
851
|
}
|
|
798
852
|
for (const [at, plan] of plans.entries()) {
|
|
799
853
|
if (outOfTime('while re-reading', plans.slice(at).filter((rest) => !tainted.has(rest)))) {
|
|
800
|
-
return;
|
|
854
|
+
return report();
|
|
801
855
|
}
|
|
802
856
|
if (tainted.has(plan)) {
|
|
803
857
|
this.log(`Unwidened reading for ${plan.request.file_path}:${plan.request.line_number} ` +
|
|
@@ -812,6 +866,7 @@ export class TypeInferrer {
|
|
|
812
866
|
catch {
|
|
813
867
|
again = null;
|
|
814
868
|
}
|
|
869
|
+
work.step();
|
|
815
870
|
if (!again || again.type_string === plan.result.type_string)
|
|
816
871
|
continue;
|
|
817
872
|
// An invariant, not a case: `mappedRequest` is what keeps the re-read
|
|
@@ -830,7 +885,9 @@ export class TypeInferrer {
|
|
|
830
885
|
continue;
|
|
831
886
|
}
|
|
832
887
|
plan.result.unwidened_type_string = again.type_string;
|
|
888
|
+
narrower += 1;
|
|
833
889
|
}
|
|
890
|
+
report();
|
|
834
891
|
}
|
|
835
892
|
finally {
|
|
836
893
|
for (const [file, text] of originals)
|
|
@@ -2151,7 +2208,11 @@ export class TypeInferrer {
|
|
|
2151
2208
|
typeString = unwrapResult.typeString;
|
|
2152
2209
|
isExplicit = unwrapResult.isExplicit;
|
|
2153
2210
|
}
|
|
2154
|
-
|
|
2211
|
+
// carrick#3004: around a call whose body a chain callback reshapes, an
|
|
2212
|
+
// annotation or a cast further out states the reshaped value.
|
|
2213
|
+
const explicitType = use.handedUnreadBody
|
|
2214
|
+
? null
|
|
2215
|
+
: this.extractExplicitTypeFromAncestor(terminalNode);
|
|
2155
2216
|
if (explicitType) {
|
|
2156
2217
|
typeString = explicitType;
|
|
2157
2218
|
isExplicit = true;
|
|
@@ -2161,7 +2222,7 @@ export class TypeInferrer {
|
|
|
2161
2222
|
// source narrows the value later (`return json as { data: Item[] }`).
|
|
2162
2223
|
// The narrowed statement is the body, and it is reported as stated, so a
|
|
2163
2224
|
// model symbol naming an element inside it is not kept as the body.
|
|
2164
|
-
const narrowed = func ? this.narrowedBodyStatement(terminalNode, func) : undefined;
|
|
2225
|
+
const narrowed = func && !use.handedUnreadBody ? this.narrowedBodyStatement(terminalNode, func) : undefined;
|
|
2165
2226
|
if (narrowed) {
|
|
2166
2227
|
typeString = narrowed.text;
|
|
2167
2228
|
isExplicit = true;
|
|
@@ -2341,6 +2402,28 @@ export class TypeInferrer {
|
|
|
2341
2402
|
// typed parameter. A function that converts the value into something new
|
|
2342
2403
|
// states nothing about it, and neither does a use on a failure path.
|
|
2343
2404
|
const untypedAnswer = typeString.trim() === 'any' || typeString.trim() === 'unknown';
|
|
2405
|
+
// carrick#3004: the call's own value is untyped and a callback in its
|
|
2406
|
+
// chain is handed it unread and builds a new value from it. The function
|
|
2407
|
+
// around the call states that new value, not the body, so nothing here
|
|
2408
|
+
// is a response contract. The decision rides the row: a plain answer is
|
|
2409
|
+
// re-read by the capture's own locator, which publishes the chain end.
|
|
2410
|
+
// A carrier's payload or a rule's that is itself a carrier of an untyped
|
|
2411
|
+
// value (a transport response around `unknown`) is no read either.
|
|
2412
|
+
const callPayload = carrierPayload ??
|
|
2413
|
+
(unwrapResult.wasUnwrapped && !untypedAnswer ? unwrapResult.payloadType : undefined) ??
|
|
2414
|
+
returnType;
|
|
2415
|
+
if (use.handedUnreadBody && (untypedAnswer || this.holdsTopTypeArgument(callPayload))) {
|
|
2416
|
+
this.log(`Call result at ${where} is untyped and handed unread to a callback that builds a ` +
|
|
2417
|
+
'new value from it; this site states no response contract');
|
|
2418
|
+
return this.decidedAbstain(request, this.getNodeLocation(callExpr), {
|
|
2419
|
+
path: '',
|
|
2420
|
+
kind: 'unknown',
|
|
2421
|
+
reason: 'reshaped_by_callback',
|
|
2422
|
+
detail: "this call's result is handed unread to a callback in its chain that builds a new " +
|
|
2423
|
+
'value from it, and nothing in the chain states the body, so the value the chain ' +
|
|
2424
|
+
'ends in is not the response this call receives',
|
|
2425
|
+
});
|
|
2426
|
+
}
|
|
2344
2427
|
if (untypedAnswer && func && !explicitType && !unwrapResult.wasUnwrapped && !carrierPayload) {
|
|
2345
2428
|
const stated = this.statedInFunction(callExpr, func, {
|
|
2346
2429
|
returned: true,
|
|
@@ -3083,9 +3166,14 @@ export class TypeInferrer {
|
|
|
3083
3166
|
// the body unread and casts it. That cast is the body read, and it comes
|
|
3084
3167
|
// before the return-statement answer below, which for a chain is the
|
|
3085
3168
|
// value the caller computed from the body, not the body.
|
|
3086
|
-
const
|
|
3087
|
-
if (
|
|
3088
|
-
return { terminal:
|
|
3169
|
+
const chain = this.bodyReadInCallbackChain(callExpr);
|
|
3170
|
+
if (chain.read) {
|
|
3171
|
+
return { terminal: chain.read, projectionOnly: false, projections: [] };
|
|
3172
|
+
}
|
|
3173
|
+
// carrick#3004: a callback is handed the body unread and nothing states
|
|
3174
|
+
// it. The return below would answer the value that callback built.
|
|
3175
|
+
if (chain.handedUnread) {
|
|
3176
|
+
return { terminal: callExpr, projectionOnly: false, projections: [], handedUnreadBody: true };
|
|
3089
3177
|
}
|
|
3090
3178
|
// A return statement answers only for a call of the function it returns
|
|
3091
3179
|
// from (carrick#2282). The nearest `return` above a call in a callback is
|
|
@@ -4315,14 +4403,21 @@ export class TypeInferrer {
|
|
|
4315
4403
|
* the chain ends in is what the caller computed from it, and publishing
|
|
4316
4404
|
* that as the body is the false mismatch this rule exists for.
|
|
4317
4405
|
*
|
|
4318
|
-
*
|
|
4406
|
+
* A call that narrows that parameter (a schema validates it, or a function
|
|
4407
|
+
* returns it unchanged) states it the same way (carrick#3004).
|
|
4408
|
+
*
|
|
4409
|
+
* Exactly one such read across the whole chain answers. None, or more than
|
|
4319
4410
|
* one (a callback on the failure side can be handed an `unknown` too), and
|
|
4320
|
-
*
|
|
4321
|
-
*
|
|
4322
|
-
*
|
|
4411
|
+
* `handedUnread` says a callback was handed the body all the same: what it
|
|
4412
|
+
* returns is a value built from the body (`.mapOk`, `.then`, `.andThen`,
|
|
4413
|
+
* whatever the name), so the value the chain ends in is never the body
|
|
4414
|
+
* (carrick#3004). A parameter typed `any` is not read: an unresolved
|
|
4415
|
+
* library types every callback that way, success and failure alike, so it
|
|
4416
|
+
* says nothing about which one is the body.
|
|
4323
4417
|
*/
|
|
4324
4418
|
bodyReadInCallbackChain(callExpr) {
|
|
4325
4419
|
const reads = [];
|
|
4420
|
+
let handedUnread = false;
|
|
4326
4421
|
let receiver = callExpr;
|
|
4327
4422
|
for (let link = 0; link < 64; link++) {
|
|
4328
4423
|
const access = receiver.getParent();
|
|
@@ -4337,36 +4432,62 @@ export class TypeInferrer {
|
|
|
4337
4432
|
}
|
|
4338
4433
|
for (const arg of call.getArguments()) {
|
|
4339
4434
|
if (Node.isArrowFunction(arg) || Node.isFunctionExpression(arg)) {
|
|
4340
|
-
|
|
4435
|
+
const statements = this.statementsOfUnreadParameter(arg);
|
|
4436
|
+
if (statements) {
|
|
4437
|
+
handedUnread = true;
|
|
4438
|
+
reads.push(...statements);
|
|
4439
|
+
}
|
|
4341
4440
|
}
|
|
4342
4441
|
}
|
|
4343
4442
|
receiver = call;
|
|
4344
4443
|
}
|
|
4345
|
-
return reads.length === 1 ? reads[0] :
|
|
4444
|
+
return reads.length === 1 ? { read: reads[0], handedUnread } : { handedUnread };
|
|
4445
|
+
}
|
|
4446
|
+
/**
|
|
4447
|
+
* `type`, or a type argument it is instantiated with at any depth, is
|
|
4448
|
+
* `any` or `unknown`: `Chain<unknown>`, `Task<Outcome<unknown, E>>`. The
|
|
4449
|
+
* value such a carrier hands its callbacks is untyped (carrick#3004).
|
|
4450
|
+
*/
|
|
4451
|
+
holdsTopTypeArgument(type, depth = 0) {
|
|
4452
|
+
if (type.isAny() || type.isUnknown())
|
|
4453
|
+
return true;
|
|
4454
|
+
if (depth >= 6)
|
|
4455
|
+
return false;
|
|
4456
|
+
const args = [...type.getTypeArguments(), ...type.getAliasTypeArguments()];
|
|
4457
|
+
return args.some((arg) => this.holdsTopTypeArgument(arg, depth + 1));
|
|
4346
4458
|
}
|
|
4347
4459
|
/**
|
|
4348
|
-
*
|
|
4349
|
-
* parameter `unknown
|
|
4350
|
-
*
|
|
4351
|
-
*
|
|
4460
|
+
* What a callback states about its first parameter, when the compiler types
|
|
4461
|
+
* that parameter `unknown`, or `undefined` when it is not handed one. A
|
|
4462
|
+
* statement is a cast whose operand is the parameter itself (`response as
|
|
4463
|
+
* T`, `<T>response`), or a call that narrows it (`callStatesItsArgument`:
|
|
4464
|
+
* a schema validates it, or a function returns it unchanged). A cast that
|
|
4465
|
+
* leaves a position open states nothing about the body and is skipped.
|
|
4352
4466
|
*/
|
|
4353
|
-
|
|
4467
|
+
statementsOfUnreadParameter(callback) {
|
|
4354
4468
|
const param = callback.getParameters()[0];
|
|
4355
4469
|
const name = param?.getNameNode();
|
|
4356
4470
|
if (!param || !name || !Node.isIdentifier(name) || !param.getType().isUnknown()) {
|
|
4357
|
-
return
|
|
4471
|
+
return undefined;
|
|
4358
4472
|
}
|
|
4359
4473
|
const symbol = name.getSymbol();
|
|
4360
4474
|
if (!symbol)
|
|
4361
4475
|
return [];
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
return false;
|
|
4365
|
-
let operand = node.getExpression();
|
|
4476
|
+
const isParameter = (node) => {
|
|
4477
|
+
let operand = node;
|
|
4366
4478
|
while (Node.isParenthesizedExpression(operand)) {
|
|
4367
4479
|
operand = operand.getExpression();
|
|
4368
4480
|
}
|
|
4369
|
-
|
|
4481
|
+
return Node.isIdentifier(operand) && operand.getSymbol() === symbol;
|
|
4482
|
+
};
|
|
4483
|
+
return callback.getDescendants().filter((node) => {
|
|
4484
|
+
if (Node.isCallExpression(node)) {
|
|
4485
|
+
const index = node.getArguments().findIndex(isParameter);
|
|
4486
|
+
return index >= 0 && this.callStatesItsArgument(node, index);
|
|
4487
|
+
}
|
|
4488
|
+
if (!Node.isAsExpression(node) && !Node.isTypeAssertion(node))
|
|
4489
|
+
return false;
|
|
4490
|
+
if (!isParameter(node.getExpression()))
|
|
4370
4491
|
return false;
|
|
4371
4492
|
const stated = node.getType();
|
|
4372
4493
|
const statedNode = node.getTypeNode();
|
|
@@ -681,6 +681,8 @@ export interface ListLibrarySurfaceRequest extends BaseRequest {
|
|
|
681
681
|
exports?: Record<string, string[]>;
|
|
682
682
|
/** List each member's handler-parameter members (`handlers`, carrick#2674 S3); default false (carrick#2966). */
|
|
683
683
|
handlers?: boolean;
|
|
684
|
+
/** The most handler-parameter members the whole listing lists; default 500000 (carrick#3016). */
|
|
685
|
+
max_handler_members?: number;
|
|
684
686
|
/** List each signature's `result_candidates` (carrick#2817); default false (carrick#2966). */
|
|
685
687
|
result_candidates?: boolean;
|
|
686
688
|
}
|
|
@@ -1137,7 +1139,8 @@ export interface LibrarySurface {
|
|
|
1137
1139
|
truncated: number;
|
|
1138
1140
|
/**
|
|
1139
1141
|
* With `handlers: true`, the handler-parameter members dropped by the cap of
|
|
1140
|
-
* 500 per parameter (carrick#2966)
|
|
1142
|
+
* 500 per parameter (carrick#2966) and the parameters the listing's budget
|
|
1143
|
+
* left out (`max_handler_members`, carrick#3016), summed over every parameter.
|
|
1141
1144
|
*/
|
|
1142
1145
|
handlers_truncated?: number;
|
|
1143
1146
|
exports: SurfaceExport[];
|
|
@@ -2812,6 +2812,7 @@ export declare const ListLibrarySurfaceRequestSchema: z.ZodObject<{
|
|
|
2812
2812
|
exports: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
2813
2813
|
handlers: z.ZodOptional<z.ZodBoolean>;
|
|
2814
2814
|
result_candidates: z.ZodOptional<z.ZodBoolean>;
|
|
2815
|
+
max_handler_members: z.ZodOptional<z.ZodNumber>;
|
|
2815
2816
|
}, "strip", z.ZodTypeAny, {
|
|
2816
2817
|
packages: string[];
|
|
2817
2818
|
request_id: string;
|
|
@@ -2821,6 +2822,7 @@ export declare const ListLibrarySurfaceRequestSchema: z.ZodObject<{
|
|
|
2821
2822
|
result_candidates?: boolean | undefined;
|
|
2822
2823
|
max_entries?: number | undefined;
|
|
2823
2824
|
exports?: Record<string, string[]> | undefined;
|
|
2825
|
+
max_handler_members?: number | undefined;
|
|
2824
2826
|
}, {
|
|
2825
2827
|
packages: string[];
|
|
2826
2828
|
request_id: string;
|
|
@@ -2830,6 +2832,7 @@ export declare const ListLibrarySurfaceRequestSchema: z.ZodObject<{
|
|
|
2830
2832
|
result_candidates?: boolean | undefined;
|
|
2831
2833
|
max_entries?: number | undefined;
|
|
2832
2834
|
exports?: Record<string, string[]> | undefined;
|
|
2835
|
+
max_handler_members?: number | undefined;
|
|
2833
2836
|
}>;
|
|
2834
2837
|
/**
|
|
2835
2838
|
* The main sidecar request schema - a discriminated union on the 'action' field
|
|
@@ -5396,6 +5399,7 @@ export declare const SidecarRequestSchema: z.ZodDiscriminatedUnion<"action", [z.
|
|
|
5396
5399
|
exports: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
5397
5400
|
handlers: z.ZodOptional<z.ZodBoolean>;
|
|
5398
5401
|
result_candidates: z.ZodOptional<z.ZodBoolean>;
|
|
5402
|
+
max_handler_members: z.ZodOptional<z.ZodNumber>;
|
|
5399
5403
|
}, "strip", z.ZodTypeAny, {
|
|
5400
5404
|
packages: string[];
|
|
5401
5405
|
request_id: string;
|
|
@@ -5405,6 +5409,7 @@ export declare const SidecarRequestSchema: z.ZodDiscriminatedUnion<"action", [z.
|
|
|
5405
5409
|
result_candidates?: boolean | undefined;
|
|
5406
5410
|
max_entries?: number | undefined;
|
|
5407
5411
|
exports?: Record<string, string[]> | undefined;
|
|
5412
|
+
max_handler_members?: number | undefined;
|
|
5408
5413
|
}, {
|
|
5409
5414
|
packages: string[];
|
|
5410
5415
|
request_id: string;
|
|
@@ -5414,6 +5419,7 @@ export declare const SidecarRequestSchema: z.ZodDiscriminatedUnion<"action", [z.
|
|
|
5414
5419
|
result_candidates?: boolean | undefined;
|
|
5415
5420
|
max_entries?: number | undefined;
|
|
5416
5421
|
exports?: Record<string, string[]> | undefined;
|
|
5422
|
+
max_handler_members?: number | undefined;
|
|
5417
5423
|
}>, z.ZodObject<{
|
|
5418
5424
|
request_id: z.ZodString;
|
|
5419
5425
|
} & {
|
|
@@ -590,6 +590,7 @@ export const ListLibrarySurfaceRequestSchema = BaseRequestSchema.extend({
|
|
|
590
590
|
exports: z.record(z.string(), z.array(z.string().min(1))).optional(),
|
|
591
591
|
handlers: z.boolean().optional(),
|
|
592
592
|
result_candidates: z.boolean().optional(),
|
|
593
|
+
max_handler_members: z.number().int().positive().optional(),
|
|
593
594
|
});
|
|
594
595
|
// ============================================================================
|
|
595
596
|
// Discriminated Union Schema
|