Resumable Methods Compiler Extension for Asynchronous Code
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Programming for many-core processors is inefficient due to the lack of native support for asynchronous programming, requiring developers to write complex non-blocking asynchronous code in continuation passing style, which is difficult and error-prone, especially for recursion and concurrency.
Innovation Solution
A unified external mechanism providing APIs that abstract away the specifics of asynchronous processing, allowing for the creation of resumable methods that can be paused and resumed, using control points to transform code into discrete parts, enabling efficient asynchronous programming and recursion through compiler extensions.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If programmers write non-blocking asynchronous code in continuation passing style without language support, then asynchronous programming can be achieved, but code complexity and error-proneness increase significantly
Solution Approach 1:
The patent introduces a compiler as an intermediary that automatically transforms synchronous code into continuation passing style. The compiler inserts continuation objects and manages the transformation of control flow, eliminating the need for programmers to manually write complex CPS code while still achieving asynchronous programming capabilities.
Solution Approach 2:
The system enables self-service by allowing the compiler to automatically generate the necessary continuation passing infrastructure from ordinary synchronous code. The transformation is performed automatically without requiring programmer intervention or manual rewriting of code in CPS style.
2Productivity
If traditional multi-processor programming techniques are used for many-core processors, then existing code can be executed, but programming efficiency decreases
Solution Approach 1:
The patent changes the fundamental parameter of how concurrency is expressed by allowing programmers to write synchronous code (which is more productive and familiar) while the compiler transforms it into the appropriate asynchronous continuation passing style suitable for many-core processors. This parameter change bridges the gap between programmer productivity and processor architecture requirements.
3Reliability
If explicit continuation arguments are used in CPS programming, then control flow can be managed, but code becomes more verbose and difficult to maintain
Solution Approach 1:
The compiler acts as an intermediary that automatically manages the explicit continuation arguments required by CPS programming. It inserts the necessary continuation objects and passes them through function calls automatically, maintaining reliable control flow management while shielding programmers from the verbosity and complexity of explicit continuation handling.
Data Source
Figure 1
Figure 2a~2c
Figure 2e~2f
AI summary
APIs are provided, that are external to a programming language but that provide functionality that can be plugged into a language compiler. The provided APIs tailor functionality associated with asynchronous programming, iterators or writing symmetric co-routines using a generalized pattern-based approach. Several types of resumable methods are provided in the APIs which can be applied to method bodies written in traditional program code. Syntactically distinguishable control points in method bodies written in traditional program code invoke transformation of the code by the compiler using the external APIs. The transformed code enables the pausing and resumption of the code sandwiched between control points in the transformed code. The source code contained within a method having control points in it is transformed so that code within the method can be executed in discrete parts, each part starting and ending at a control point in the transformed code.