feat: Add runtime function overload resolution based on Type information #1530
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently, CEL-C++ only supports Type-level function overload resolution during the type-checking phase, while runtime function dispatch is limited to Kind-level resolution. This limitation prevents runtime selection of the most appropriate function overload when dealing with complex type hierarchies or when type information is available but not fully determined during static analysis.
As described in issue #1484, the FunctionRegistry cannot distinguish overloads differing only by container parameter types (e.g.,
list<int>
vslist<string>
) because the current implementation only comparescel::Kind
rather than precisecel::Type
information during function registration and dispatch.Objective
Enable runtime function overload resolution based on precise Type information by propagating overload IDs from the type-checking phase to the runtime execution phase. This enhancement allows the runtime to make more informed decisions about which function overload to invoke, improving both correctness and performance in scenarios where multiple overloads are available.
Implementation
Core Changes
Enhanced Function Interface
Function::Invoke()
method signature to accept an optionaloverload_id
parameter (absl::Span<const std::string>
) with default empty valueCelFunction
implementation to support the new interfaceFlatExpr Builder Integration
reference_map_
field toFlatExprVisitor
to access type-checking reference information during expression compilationFindReference()
helper method to retrieve overload IDs associated with specific expressionsCreateFunctionStep()
andCreateDirectFunctionStep()
calls to pass overload ID information from the reference mapFunction Step Enhancement
AbstractFunctionStep
constructor to accept overload IDs with move semanticsEagerFunctionStep
) and lazy (LazyFunctionStep
) function step implementations to store overload ID informationDirectFunctionStepImpl
) to store and utilize overload ID informationInvoke()
helper function to pass overload IDs to the underlying function implementationTechnical Details
Benefits
Testing
This change maintains full API and ABI compatibility through default parameter values. All existing tests should continue to pass without modification, and new tests can be added to verify type-aware overload resolution behavior.
Closes #1484