/** * A function declaration, from its signature to the result it publishes: the * frame a body is analyzed in, the parameters it declares, the arrow that is * the same thing in expression position, the callable type a name is bound to, * and the Promise hazards an async result carries. * * D114 R1f: `analysis/functions.ts` beside this directory is the *vocabulary* — * the shapes and the sentences a function declaration is written with, which * every cluster reads. This module is the *analysis*: the walk over one * declaration. `Analyzer` keeps `analyzeFunctionDeclaration`, * `inferredFunctionResult`, `resolvedAsyncResult`, `inferParameterDefault` and * `contextualFunctionParameterDefault` as `protected` seams, and every call * this module makes to one of them goes back through the host, so a Web or * Node override is reached exactly as before. */ import { type ArrowFunctionExpression, type Expression, type FunctionDeclaration, type Statement, type TypeParameterDeclaration, type TypeReference } from "../../ast.ts"; import { type ClassField, type ClassInfo } from "../../contracts.ts"; import { type Diagnostic } from "../../diagnostic.ts"; import { type Span } from "../../source.ts"; import { type TypeParameterBound, type ValueType } from "../../types.ts"; import { type AnalyzableFunctionDeclaration, type ReturnContext } from "../functions.ts"; import { type DeferredReadFrame } from "../modules/initialization.ts"; import { type EmptyCollectionTarget } from "../expressions/contextual.ts"; import { type Binding, type BuiltinTypeNamePosition, type MutableCellTarget } from "../scopes.ts"; /** The lowering facts a function declaration records for the emitter. */ export interface FunctionLoweringFacts { readonly asyncResolvedValues: Set; } /** * Everything the function-declaration analysis asks of the analyzer that hosts * it, and nothing more. Every frame the walk pushes and pops — the scopes, the * five depths, the return contexts, the deferred-read frames — is a live * accessor, because the body being analyzed is what moves them. */ export interface FunctionStatementsHost { analyzeFunctionDeclaration(statement: AnalyzableFunctionDeclaration, className: string | null, method?: boolean, declareSelf?: boolean, forceAsynchronous?: boolean, declarationKind?: string): void; analyzeStatements(statements: readonly Statement[]): void; asyncResultContainsPromise(type: ValueType): boolean; readonly arrowCaptureFrames: { captured: { readonly handle: string; readonly depth: number; } | null; }[]; readonly arrowDeferredFrames: Map; readonly arrowOwnedCaptures: Map; readonly asynchronousFunctions: boolean[]; blockAlwaysReturns(statements: readonly Statement[]): boolean; checkTypeParameterDeclarations(declarations: readonly TypeParameterDeclaration[] | undefined): void; classFieldInitializerDepth: number; classInfo(key: string): ClassInfo | undefined; classTypeParameterDeclarations(className: string | null): readonly TypeParameterDeclaration[] | undefined; contextuallyAssignable(actual: ValueType, expected: ValueType, valueSpan: Span): boolean; contextualFunctionParameterDefault(statement: AnalyzableFunctionDeclaration, parameter: AnalyzableFunctionDeclaration["parameters"][number]): ValueType | null; constructorDepth: number; currentClass: string | null; declareBinding(name: string, mutable: boolean, type: ValueType, declarationSpan: Span, internal?: boolean, declaredType?: ValueType, importSource?: string, typeNamePosition?: BuiltinTypeNamePosition): void; refuseGuidedDeclarationName(name: string, position: string, declarationSpan: Span): boolean; readonly deferredConvergenceReports: { readonly report: Diagnostic; readonly resultKey: string; readonly causes: ReadonlySet; }[]; readonly deferredReadFrames: DeferredReadFrame[]; readonly diagnostics: Diagnostic[]; enterScope(): void; exitScope(): void; expandAliases(type: ValueType, seen?: ReadonlySet): ValueType; fieldsOf(identity: string): ReadonlyMap | null; readonly finalizeFunctionResultInference: boolean; finallyLoopDepths: number[]; flowFrameDepth: number; functionDepth: number; readonly functionResultKeys: WeakMap; inferExpression(expression: Expression, contextualType?: ValueType): ValueType; inferParameterDefault(expression: Expression, contextualType?: ValueType): ValueType; inferredFunctionResult(statement: Pick & { readonly abstract?: boolean; }): ValueType; readonly inferredFunctionResultSeeds: ReadonlyMap; readonly inferredFunctionResultTypes: Map; readonly localFunctionFrames: Map; lookup(name: string): Binding | null; loopDepth: number; readonly lowering: FunctionLoweringFacts; memberTypeParameterFrame(classParameters: readonly TypeParameterDeclaration[] | undefined, ownParameters: readonly TypeParameterDeclaration[] | undefined): ReadonlyMap; readonly modulePath: string | null; parameterDefaultDepth: number; readonly predeclared: WeakSet; promiseResolutionHazard(type: ValueType): string | null; promiseResolutionNeedsRuntimeGuard(type: ValueType): boolean; readonly privateFields: Map>; readonly privateMethods: Map>; readonly privateStaticFields: Map>; readonly privateStaticMethods: Map>; recordExportedAny(statement: AnalyzableFunctionDeclaration, className: string | null, reportSpan: Span): void; reportPromiseCarrierHazard(type: ValueType, errorSpan: Span): void; reportPromiseResolutionHazard(type: ValueType, errorSpan: Span): void; recordFlowFactOrigin(binding: Binding): void; recordSemanticBinding(key: string, type: ValueType): void; rejectClassTypeParameterRedeclaration(classParameters: readonly TypeParameterDeclaration[] | undefined, ownParameters: readonly TypeParameterDeclaration[] | undefined, className: string | null): void; readonly reportedResultHoles: Set; requireAssignable(actual: ValueType, expected: ValueType, valueSpan: Span, mutableCell?: MutableCellTarget | null): void; requireSettledCollectionElement(initializer: Expression, declared: ValueType, annotated: boolean, target?: EmptyCollectionTarget | null): boolean; resolveAnnotation(reference: TypeReference | null): ValueType; resolveResult(reference: TypeReference | null): ValueType; resolvedAsyncResult(type: ValueType): ValueType; resolveValidatedAnnotation(reference: TypeReference | null): ValueType; resolveValidatedResult(reference: TypeReference | null): ValueType; readonly returnContexts: ReturnContext[]; readonly scopes: Map[]; selfClassType(className: string): ValueType; staticFieldInitialization: { readonly className: string; readonly initialized: ReadonlySet; } | null; staticMemberTypeParameters: { readonly className: string; readonly names: ReadonlySet; } | null; superMemberContext: "instance" | "static" | null; typeParameterBoundVector(declarations: readonly TypeParameterDeclaration[] | undefined): readonly (TypeParameterBound | null)[] | null; typeParameterFrame(declarations: readonly TypeParameterDeclaration[] | undefined): ReadonlyMap; readonly typeParameterFrames: ReadonlyMap[]; validateTypeReference(reference: TypeReference, resolve?: (reference: TypeReference) => ValueType): boolean; withTypeParameterFrame(frame: ReadonlyMap, action: () => T): T; } export declare class FunctionStatements { private readonly host; constructor(host: FunctionStatementsHost); analyzeFunctionDeclarationStatement(statement: Extract): void; /** * D58 rule 139: `-> null` is the one result annotation that names nothing a * caller can use — a caller that ignores a result already knows as much — so * where a body infers exactly that, the annotation is two spellings of one * declaration and the written one is refused. `extern` declarations, * abstract methods, and function types have no body to infer from and keep * declaring it (VEL4023, VEL2001), and a getter's result is the property's * type, which the parser requires outright (VEL2023). * * Deleting an annotation the compiler would infer identically is provably * equivalent, so it is a mechanical fix under D50 rule 95 — but only there. * D58 correction 2: where the body returns a value, the deletion is not * equivalent, it widens the signature and takes VEL4001 down with it, so the * refusal is reported without a fix and the author decides whether the body * or the intent was wrong. `velar fix` runs unattended because it never does * the second kind of thing. * * D64 rule 162: dropping the fix was only half of that correction. The * message still said "delete the annotation" — the one move the ruling had * just refused to make — so the diagnostic taught an exit it rejects on the * next step, which is the D57 rule 136 shape. The two cases now carry two * messages: where the body does infer null the deletion is the answer, and * where it does not, the disagreement between the body and the annotation is * the answer, and deleting would only widen the signature to hide it. */ private inferredNullResultAnnotation; private reportInferredNullResult; /** * D89 (message correction): the one report a `self` parameter earns, and the * deletion it names. The removed range reaches to the next parameter's start * (or back to the previous one's end), so the separating comma and its * whitespace come with it without reading the source text — the rewrite is a * spelling change with no judgment in it, which is what D38 §48 requires of * a registered fix. */ reportImplicitSelfParameter(parameters: readonly { readonly name: string; readonly span: Span; }[], index: number): void; analyzeFunctionDeclaration(statement: AnalyzableFunctionDeclaration, className: string | null, method?: boolean, declareSelf?: boolean, forceAsynchronous?: boolean, declarationKind?: string): void; /** * The parameter list of one declaration: the implicit-receiver refusal, the * target-owned contextual default, and the binding each parameter declares. * * D115 §一.1: split out of `analyzeFunctionDeclaration` unchanged so both * halves fit in one screen. It reads nothing the loop did not already read * and leaves behind no local the rest of the declaration uses. */ private declareFunctionParameters; /** * What the declaration publishes as its result: the type the body inferred * and the convergence report a recursive contract earns, or the declared * result when one was written. * * D115 §一.1: split out of `analyzeFunctionDeclaration` unchanged. Every * value it needs was computed before the body was analyzed, so the split * point is the line after `analyzeStatements` and the order is the order it * ran in. */ private recordFunctionResultInference; inferArrow(expression: ArrowFunctionExpression, contextualType: ValueType): ValueType; private callableWithInferredResult; private updateInferredCallableResult; functionResultKey(statement: Pick): string; inferredFunctionResult(statement: Pick & { readonly abstract?: boolean; }): ValueType; inferCollectedFunctionResult(returned: readonly ValueType[], fallsThrough: boolean): ValueType; functionType(statement: FunctionDeclaration, classParameters?: readonly TypeParameterDeclaration[]): ValueType; } //# sourceMappingURL=functions.d.ts.map