Code Analysis System with Bounded Execution Time
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Document editing tools face challenges in providing code completion for programming languages with dynamically created elements, as static analysis is insufficient and dynamic analysis can be slow, prone to infinite loops, and incomplete due to scoping rules, especially for large code sets.
Innovation Solution
A code analysis system that compiles each file into an intermediate state, caches results for faster analysis, monitors time and recursion thresholds to prevent prolonged execution, and falls back to static analysis when dynamic analysis fails, ensuring predictable and complete code completion results.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Loss of information
If dynamic analysis is performed to discover all code elements, then code completion completeness is improved, but execution time increases and may become unpredictable
Solution Approach 1:
The system performs preliminary static analysis to collect all statically discoverable code elements before dynamic analysis. This preliminary action reduces the scope of subsequent dynamic analysis, allowing the system to achieve complete code element discovery while limiting execution time to only analyzing dynamically created elements that were not found during static analysis.
Solution Approach 2:
The code analysis process is segmented into two distinct phases: static analysis phase and dynamic analysis phase. Each phase handles different types of code elements - static analysis handles compile-time visible elements while dynamic analysis handles runtime-created elements. This segmentation allows the system to optimize each phase independently and avoid the pitfalls of performing complete dynamic analysis on all code elements.
2Measurement precision
If code is executed to discover dynamic elements, then code completion accuracy is improved, but the system may encounter infinite loops or unpredictable termination
Solution Approach 1:
Static analysis is performed as a preliminary action before dynamic analysis to identify and exclude statically discoverable code elements from dynamic analysis. This reduces the risk of infinite loops during dynamic analysis since many code paths that would cause non-termination are already handled by the static analysis phase.
Solution Approach 2:
The system introduces an intermediary mechanism that monitors execution during dynamic analysis and can intervene to prevent infinite loops. The execution engine includes safeguards that detect when code is not terminating as expected and intervene to stop execution, ensuring reliability while still allowing dynamic analysis to discover accurate code elements.
3Productivity
If static analysis is used for code completion, then execution speed is improved, but code completion completeness deteriorates for dynamically typed languages
Solution Approach 1:
The analysis system is segmented into static analysis and dynamic analysis components that work together. Static analysis provides fast initial results for all statically discoverable elements, while dynamic analysis complements this by discovering runtime-created elements. This segmentation allows the system to maintain high speed through static analysis while achieving completeness through targeted dynamic analysis.
Solution Approach 2:
The system merges the results of static analysis and dynamic analysis to provide complete code completion. Static analysis results are combined with dynamically discovered elements, creating a comprehensive code element list that leverages the speed of static analysis and the completeness of dynamic analysis for dynamically typed languages.
4Loss of information
If dynamic analysis is performed on large code sets, then code completion completeness is improved, but system performance deteriorates
Solution Approach 1:
Static analysis is performed as a preliminary action on the entire code base to identify all statically discoverable elements. This preliminary action creates a comprehensive baseline that covers most code elements, allowing dynamic analysis to focus only on the small subset of runtime-created elements, thereby maintaining high throughput while achieving complete schema discovery.
Solution Approach 2:
Instead of performing exhaustive dynamic analysis on all code elements, the system performs partial dynamic analysis only on elements that were not discovered during static analysis. This partial action is sufficient to achieve complete schema completeness while maintaining high analysis throughput by avoiding redundant dynamic analysis of statically discoverable elements.
Data Source
AI summary
A code analysis system is described herein that provides code completion for programming languages that include elements that are not statically discoverable and that provides results in a predictable period that is acceptable for an interactive user interface. The system compiles each file into an intermediate state that can be stored and cached to speed later analysis of files. In addition, when executing a particular file, the system monitors a time-based threshold and/or a recursion depth so that if the compilation time is exceeding the threshold or a function is exceeding the recursion depth the system can stop the execution and use the intermediate results obtained up to that point to provide as much information as possible within a bounded execution time. When dynamic analysis fails, the system falls back to static analysis.


