Dispatch Predicate for Overloaded Generic Functions
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Programming languages face challenges in efficiently dispatching function calls to overloaded functions with generic type hierarchies that lack contravariance, leading to increased overhead due to complexity in determining specificity and applicability.
Innovation Solution
A system that determines the applicability of overloaded function implementations by using a partial order and performs type inference on generic type parameters, adjusting lower limits and propagating constraints to select the most specific implementation for invocation.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If generic functions are used in overloaded functions to accept parameters from overlapping sets of types, then the versatility and adaptability of the function is improved, but the complexity of determining specificity and applicability during dispatch increases
Solution Approach 1:
The system pre-computes dispatch predicates for each overloaded function implementation during compilation, storing them for runtime use. This preliminary action eliminates the need for complex runtime analysis of generic type hierarchies, as the applicability of each implementation is predetermined based on the function signature and generic type parameters.
Solution Approach 2:
The patent introduces dispatch predicates as intermediary computational objects that mediate between the function call and the overloaded implementations. These predicates encapsulate the complexity of generic type matching and applicability determination, providing a simplified interface for runtime dispatch decisions.
2Measurement precision
If type inference is performed on generic type parameters during runtime dispatch, then the precision of function selection is improved, but the runtime overhead increases
Solution Approach 1:
Type inference rules and constraints are established during compilation rather than runtime. The dispatch predicates incorporate pre-computed type relationships and constraints, allowing the runtime system to simply evaluate predetermined conditions rather than perform complex type inference algorithms.
Solution Approach 2:
The patent extracts type inference complexity from the runtime dispatch process and relocates it to the compilation phase. By separating the inference problem solving (compile-time) from the dispatch execution (runtime), the system achieves precise function selection without runtime performance penalties.
3Measurement precision
If multiple dispatch is used to resolve function calls based on runtime types, then the accuracy of function selection is improved, but the computational overhead during runtime increases
Solution Approach 1:
The system pre-determines the conditions under which each overloaded implementation is applicable by computing dispatch predicates during compilation. At runtime, the system simply evaluates these pre-computed predicates against the actual function arguments, avoiding complex multiple dispatch analysis.
Solution Approach 2:
The patent replaces the traditional mechanical multiple dispatch mechanism (which requires runtime type analysis and comparison) with a predicate evaluation system. Instead of dynamically analyzing type hierarchies and specificity, the system evaluates pre-computed logical predicates that encode the applicability conditions.
Data Source
AI summary
The disclosed embodiments provide a system that facilitates the development and execution of a software program. During runtime of the software program, the system obtains a function call associated with an overloaded function and a generic type hierarchy that lacks contravariance. Next, the system determines an applicability of an implementation of the overloaded function to the function call. Finally, the system selects the implementation for invocation by the function call based on the determined applicability and a partial order of implementations for the overloaded function.


