typir
Version:
General purpose type checking library
61 lines • 4.09 kB
TypeScript
/******************************************************************************
* Copyright 2025 TypeFox GmbH
* This program and the accompanying materials are made available under the
* terms of the MIT License, which is available in the project root.
******************************************************************************/
import { TypeGraphListener } from '../../graph/type-graph.js';
import { Type } from '../../graph/type-node.js';
import { CompositeTypeInferenceRule } from '../../services/inference.js';
import { TypirServices, TypirSpecifics } from '../../typir.js';
import { RuleRegistry } from '../../utils/rule-registration.js';
import { FunctionKind, InferFunctionCall } from './function-kind.js';
import { FunctionType } from './function-type.js';
import { FunctionCallArgumentsValidation } from './function-validation-calls.js';
/**
* Collects information about all functions with the same name.
* This is required to handle overloaded functions.
*/
export interface OverloadedFunctionDetails<Specifics extends TypirSpecifics> {
/** All function overloads/signatures with the same name. */
overloadedFunctions: FunctionType[];
/** Collects the details of all functions with the same name, grouped by language keys of their inference rules for function calls. */
details: RuleRegistry<SingleFunctionDetails<Specifics>, Specifics>;
/** Collects the inference rules for all functions with the same name */
inferenceRule: CompositeTypeInferenceRule<Specifics>;
/** If all overloaded functions with the same name have the same output/return type, this type is remembered here (for a small performance optimization). */
sameOutputType: Type | undefined;
}
export interface SingleFunctionDetails<Specifics extends TypirSpecifics, T extends Specifics['LanguageType'] = Specifics['LanguageType']> {
functionType: FunctionType;
inferenceRuleForCalls: InferFunctionCall<Specifics, T>;
}
/**
* Contains all the logic to manage all available functions,
* in particular, to support overloaded functions.
* In each type system, exactly one instance of this class is stored by the FunctionKind.
*/
export declare class AvailableFunctionsManager<Specifics extends TypirSpecifics> implements TypeGraphListener {
protected readonly services: TypirServices<Specifics>;
protected readonly kind: FunctionKind<Specifics>;
/**
* function name => all overloaded functions (with additional information) with this name/key
* - The types could be collected with the TypeGraphListener, but the additional information like inference rules are not available.
* Therefore this map needs to be maintained here.
* - Main purpose is to support inference and validation for overloaded functions:
* Since overloaded functions are realized with one function type for each variant,
* the corresponding rules and logic need to involve multiple types,
* which makes it more complex and requires to manage them here and not in the single types.
*/
protected readonly mapNameTypes: Map<string, OverloadedFunctionDetails<Specifics>>;
protected readonly validatorArgumentsCalls: FunctionCallArgumentsValidation<Specifics>;
constructor(services: TypirServices<Specifics>, kind: FunctionKind<Specifics>);
protected createFunctionCallArgumentsValidation(): FunctionCallArgumentsValidation<Specifics>;
protected createInferenceRuleForOverloads(): CompositeTypeInferenceRule<Specifics>;
getOverloads(functionName: string): OverloadedFunctionDetails<Specifics> | undefined;
getOrCreateOverloads(functionName: string): OverloadedFunctionDetails<Specifics>;
getAllOverloads(): MapIterator<[string, OverloadedFunctionDetails<Specifics>]>;
addFunction(readyFunctionType: FunctionType, inferenceRulesForCalls: Array<InferFunctionCall<Specifics, Specifics['LanguageType']>>): void;
onRemovedType(type: Type, _key: string): void;
protected calculateSameOutputType(overloaded: OverloadedFunctionDetails<Specifics>): void;
}
//# sourceMappingURL=function-overloading.d.ts.map