Software Language Comprehension using a Program-Derived Semantic Graph

Roshni G. Iyer, Yizhou Sun, Wei Wang, Justin GottschlicharXiv 2020

TL;DR

This paper introduces the Program-Derived Semantics Graph (PSG), a novel hierarchical graph structure designed to capture code semantics at multiple levels of abstraction. The PSG aims to overcome limitations of traditional code representations like ASTs and XFGs, offering a more flexible and comprehensive way to understand program meaning, which could revolutionize tasks like code translation and bug detection.

What Problem Does This Paper Address?

The paper tackles the challenge of understanding program semantics, especially in the context of Machine Programming (MP), where the goal is to automate software development. A key hurdle is extracting user intent from code, which is complicated by the ever-increasing variety of programming languages (PLs) with different semantic abstraction levels. Existing code representations, such as Abstract Syntax Trees (ASTs) and Contextual Flow Graphs (XFGs), often struggle to capture higher-order semantics or handle the semantic variability across PLs. They can be too tied to syntax or too limited in their structural flexibility, making it difficult to represent complex relationships or adapt to new languages.

Methods

The core contribution is the Program-Derived Semantics Graph (PSG). The PSG is a multi-tiered, PL-agnostic graphical representation that captures program semantics across a spectrum of abstraction levels. It distinguishes between Semantic Abstraction Levels (SeAL) and Syntactic Abstraction Levels (SyAL). Higher SeAL levels capture more abstract, general semantic information, while lower SeAL levels and SyAL levels encode more precise, syntactic details. The PSG is designed to be adaptable and extensible, allowing it to evolve with new PLs and accommodate new semantic concepts. Unlike traditional methods that rely on predefined rules, the authors envision the PSG as a structure that can be learned, potentially using machine learning. They also introduce a method for analyzing structural similarity between code representations by measuring node overlap percentages and differences.

Datasets

Not discussed in the paper. The paper focuses on a conceptual framework and a rudimentary analysis using two semantically equivalent but syntactically different C++ code snippets for exponentiation.

Key Insights and Ideas

  • Hierarchical Abstraction is Key: The PSG's strength lies in its ability to represent semantics at various levels, from high-level concepts to low-level syntactic details, providing a more nuanced understanding than single-level representations.
  • Flexibility Over Rigidity: The PSG's graphical nature, allowing for cycles and complex relationships, makes it more general than tree-based structures like ASTs, enabling the representation of more intricate code semantics.
  • Learning vs. Rule-Based: The authors propose that PSG structures can be learned, moving beyond the limitations of manually defined rules and enabling adaptation to new programming languages and evolving semantic concepts.
  • Bridging Syntax and Semantics: The PSG aims to strike a balance by incorporating some syntactic information (at the lowest SyAL level) to guide semantic learning, preventing the loss of critical details while avoiding over-reliance on implementation specifics.

Key Results

The paper presents a rudimentary analysis comparing the PSG to Aroma's Simplified Parse Tree (SPT) using two C++ exponentiation functions.

  • Structural Similarity: The PSG demonstrated a higher average structural similarity between the semantically equivalent but syntactically different code snippets (70.14%) compared to the SPT (64.21%). This suggests the PSG might be better at capturing underlying semantic equivalence despite syntactic variations.
  • Overlap Percentages: For the PSG, the overlap was 70.83% for the recursive function and 70.37% for the iterative function. For the SPT, the overlap was 64.71% for the recursive function and 65.71% for the iterative function.

These results are presented as anecdotal but provide early intuition about the PSG's potential.

Limitations and Future Work

  • Infancy of Exploration: The authors acknowledge that their exploration into the PSG is in its early stages.
  • Base PSL Limitations: The current "base PSG" is a first-order approximation and is not exhaustive of all semantic concepts and their dependencies.
  • Manual Construction: The current PSG construction is not automated; the paper focuses on the conceptual framework and analysis.

Future work includes:

  • Analyzing the PSG and other state-of-the-art systems against larger code corpora.
  • Developing automated methods for generating the PSG from code.
  • Augmenting the base PSL with data-driven learning to create a more comprehensive and automatically maintained semantic concept language.

Summary updated

BibTeX
@misc{iyer2020software,
  author = {Roshni G. Iyer and Yizhou Sun and Wei Wang and Justin Gottschlich},
  title = {{Software Language Comprehension using a Program-Derived Semantic Graph}},
  year = {2020},
  eprint = {2004.00768},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2004.00768},
}
Figure