Graph Neural Network for Source Code Node Alignment

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional heuristics for aligning nodes between predecessor and successor source code graphs are inaccurate, leading to incomplete and semantically incorrect change graphs, which hampers downstream operations such as code change prediction and intent identification.

Innovation Solution

A machine learning model, specifically a graph neural network, is trained to generate alignments between abstract syntax trees and control-flow graphs, using tree-based code differencing algorithms to improve the accuracy of node mappings and generate change graphs representing edits made to source code snippets.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If conventional heuristics are used to align nodes between predecessor and successor source code graphs, then the process is simple and fast, but the accuracy of node mappings is poor leading to incomplete and semantically incorrect change graphs

Engineering Contradiction:
Improveaccuracy of node mappingsVSAvoidcomplexity of alignment process
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent introduces control-flow graphs as an intermediary representation between the predecessor and successor abstract syntax trees. The CFGs serve as a mediating structure that captures the control flow semantics of the code, enabling more accurate node alignment by providing additional contextual information about program execution paths. This intermediary representation helps resolve ambiguities in direct AST node matching.

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent segments the code representation into multiple hierarchical levels: abstract syntax trees for structural representation and control-flow graphs for execution flow representation. By dividing the alignment problem into these separate but complementary representations, the system can leverage the strengths of each - the structural information from ASTs and the control flow information from CFGs - to achieve more accurate node mappings.

Inventive Principle:
Principle #1Segmentation

2Reliability

If conventional heuristics are used for node alignment, then computational resources are conserved, but downstream operations such as code change prediction and intent identification become unreliable

Engineering Contradiction:
Improvereliability of downstream operationsVSAvoidcomputational resource consumption
Core Design Contradiction:
ReliabilityVSUse of energy by moving object

Solution Approach 1:

The patent performs preliminary alignment of control-flow graphs before conducting the main AST node alignment task. By pre-establishing the correspondence between control flow structures, the system creates a reliable foundation that guides the subsequent AST node matching process. This preliminary action ensures that downstream operations receive high-quality input data, improving their reliability.

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent replaces conventional heuristic-based alignment mechanisms with a machine learning model trained on code data. This substitution transitions from rule-based mechanical matching to a learned semantic understanding of code structures and transformations, significantly improving the reliability of node mappings and consequently the downstream operations that depend on them.

Inventive Principle:
Principle #28Mechanics substitution (Replace mechanical system)

3Measurement precision

If a machine learning model is trained to generate alignments between abstract syntax trees and control-flow graphs, then the accuracy of change graph generation is enhanced, but the training process and model complexity increase

Engineering Contradiction:
Improveaccuracy of change graph generationVSAvoidcomplexity of machine learning model
Core Design Contradiction:
Measurement precisionVSDevice complexity

Solution Approach 1:

The patent designs a universal machine learning model that can handle multiple code alignment tasks simultaneously. The model is trained to align both AST nodes and CFG nodes, and can be applied to various programming languages and code transformation scenarios. This multi-functionality justifies the increased model complexity by providing a single versatile solution that improves accuracy across multiple downstream operations.

Inventive Principle:
Principle #6Universality (Multi-functionality)

Solution Approach 2:

The patent combines multiple representation types (AST and CFG) into a composite input structure for the machine learning model. By feeding both structural and control flow information into the model, the system creates a rich composite representation that enables more accurate alignment decisions. The composite nature of the input data necessitates a more complex model architecture but yields significant improvements in change graph generation accuracy.

Inventive Principle:
Principle #40Composite materials

Data Source

PatentUS12008347B2Matching graphs generated from source code
Publication Date: 2024.06.11 GOOGLE LLC
  • US12008347B2 patent drawing
  • US12008347B2 patent drawing
  • US12008347B2 patent drawing

AI summary

Techniques are described herein for training a machine learning model and using the trained machine learning model to more accurately determine alignments between matching/corresponding nodes of predecessor and successor graphs representing predecessor and successor source code snippets. A method includes: obtaining a first abstract syntax tree that represents a predecessor source code snippet and a second abstract syntax tree that represents a successor source code snippet; determining a mapping across the first and second abstract syntax trees; obtaining a first control-flow graph that represents the predecessor source code snippet and a second control-flow graph that represents the successor source code snippet; aligning blocks in the first control-flow graph with blocks in the second control-flow graph; and applying the aligned blocks as inputs across a trained machine learning model to generate an alignment of nodes in the first abstract syntax tree with nodes in the second abstract syntax tree.