IP Library Granted Patent US 12,008,347
Granted Patent B2
US 12,008,347 · App. 17/940,831 · Granted Jun 11, 2024

Matching graphs generated from source code

Inventor: Qianyu Zhang (Sunnyvale, CA)
Assignee: GOOGLE LLC
G06F8/427G06F8/433G06N3/02G06N20/00
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,008,347
App. No.
17/940,831
Granted
Jun 11, 2024
Kind
B2
Abstract

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.

Claims (58)

1. A method implemented by one or more processors, the method comprising:

obtaining a first abstract syntax tree that represents a source code snippet;

generating, from the first abstract syntax tree, a second abstract syntax tree, and a ground truth node alignment between the first abstract syntax tree and the second abstract syntax tree;

modifying the second abstract syntax tree by:

for each node in a first set of nodes in the second abstract syntax tree, changing a field value of the node;

deleting each node in a second set of nodes in the second abstract syntax tree; and

for each node in a third set of nodes in the second abstract syntax tree, changing a parent node of the node; and

training a machine learning model to generate an alignment of nodes based on the first abstract syntax tree and the second abstract syntax tree, comprising:

generating, using the machine learning model, a predicted node alignment between the first abstract syntax tree and the second abstract syntax tree; and

updating the machine learning model based on (i) the predicted node alignment between the first abstract syntax tree and the second abstract syntax tree and (ii) the ground truth node alignment between the first abstract syntax tree and the second abstract syntax tree.

2. The method according to claim 1 , further comprising deleting at least one node in the first abstract syntax tree.

3. The method according to claim 1 , wherein the machine learning model comprises a graph neural network.

4. The method according to claim 1 , further comprising:

obtaining a third abstract syntax tree that represents a predecessor source code snippet and a fourth abstract syntax tree that represents a successor source code snippet;

determining a mapping across the third abstract syntax tree and the fourth abstract syntax tree between pairs of matching nodes;

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 based on the mapping across the third abstract syntax tree and the fourth abstract syntax tree; and

applying the aligned blocks as inputs across the machine learning model to generate an alignment of nodes in the third abstract syntax tree with nodes in the fourth abstract syntax tree.

5. The method according to claim 4 , further comprising generating a change graph based on the alignment of the nodes in the third abstract syntax tree with the nodes in the fourth abstract syntax tree, wherein the change graph represents one or more edits made to the predecessor source code snippet to yield the successor source code snippet.

6. A computer program product comprising one or more non-transitory computer-readable storage media having program instructions collectively stored on the one or more non-transitory computer-readable storage media, the program instructions executable to:

obtain a first abstract syntax tree that represents a source code snippet;

generate, from the first abstract syntax tree, a second abstract syntax tree, and a ground truth node alignment between the first abstract syntax tree and the second abstract syntax tree;

modify the second abstract syntax tree by:

for each node in a first set of nodes in the second abstract syntax tree, changing a field value of the node;

deleting each node in a second set of nodes in the second abstract syntax tree; and

for each node in a third set of nodes in the second abstract syntax tree, changing a parent node of the node; and

train a machine learning model to generate an alignment of nodes based on the first abstract syntax tree and the second abstract syntax tree, comprising:

generating, using the machine learning model, a predicted node alignment between the first abstract syntax tree and the second abstract syntax tree; and

updating the machine learning model based on (i) the predicted node alignment between the first abstract syntax tree and the second abstract syntax tree and (ii) the ground truth node alignment between the first abstract syntax tree and the second abstract syntax tree.

7. The computer program product according to claim 6 , wherein the program instructions are further executable to delete at least one node in the first abstract syntax tree.

8. The computer program product according to claim 6 , wherein the machine learning model comprises a graph neural network.

9. The computer program product according to claim 6 , wherein the program instructions are further executable to:

obtain a third abstract syntax tree that represents a predecessor source code snippet and a fourth abstract syntax tree that represents a successor source code snippet;

determine a mapping across the third abstract syntax tree and the fourth abstract syntax tree between pairs of matching nodes;

obtain 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;

align blocks in the first control-flow graph with blocks in the second control-flow graph based on the mapping across the third abstract syntax tree and the fourth abstract syntax tree; and

apply the aligned blocks as inputs across the machine learning model to generate an alignment of nodes in the third abstract syntax tree with nodes in the fourth abstract syntax tree.

10. The computer program product according to claim 9 , wherein the program instructions are further executable to generate a change graph based on the alignment of the nodes in the third abstract syntax tree with the nodes in the fourth abstract syntax tree, wherein the change graph represents one or more edits made to the predecessor source code snippet to yield the successor source code snippet.

11. A system comprising:

a processor, a computer-readable memory, one or more computer-readable storage media, and program instructions collectively stored on the one or more computer-readable storage media, the program instructions executable to:

obtain a first abstract syntax tree that represents a source code snippet;

generate, from the first abstract syntax tree, a second abstract syntax tree, and a ground truth node alignment between the first abstract syntax tree and the second abstract syntax tree;

modify the second abstract syntax tree by:

for each node in a first set of nodes in the second abstract syntax tree, changing a field value of the node;

deleting each node in a second set of nodes in the second abstract syntax tree; and

for each node in a third set of nodes in the second abstract syntax tree, changing a parent node of the node; and

train a machine learning model to generate an alignment of nodes based on the first abstract syntax tree and the second abstract syntax tree, comprising:

generating, using the machine learning model, a predicted node alignment between the first abstract syntax tree and the second abstract syntax tree; and

updating the machine learning model based on (i) the predicted node alignment between the first abstract syntax tree and the second abstract syntax tree and (ii) the ground truth node alignment between the first abstract syntax tree and the second abstract syntax tree.

12. The system according to claim 11 , wherein the program instructions are further executable to delete at least one node in the first abstract syntax tree.

13. The system according to claim 11 , wherein the machine learning model comprises a graph neural network.

14. The system according to claim 11 , wherein the program instructions are further executable to:

obtain a third abstract syntax tree that represents a predecessor source code snippet and a fourth abstract syntax tree that represents a successor source code snippet;

determine a mapping across the third abstract syntax tree and the fourth abstract syntax tree between pairs of matching nodes;

obtain 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;

align blocks in the first control-flow graph with blocks in the second control-flow graph based on the mapping across the third abstract syntax tree and the fourth abstract syntax tree; and

apply the aligned blocks as inputs across the machine learning model to generate an alignment of nodes in the third abstract syntax tree with nodes in the fourth abstract syntax tree.

15. The system according to claim 14 , wherein the program instructions are further executable to generate a change graph based on the alignment of the nodes in the third abstract syntax tree with the nodes in the fourth abstract syntax tree, wherein the change graph represents one or more edits made to the predecessor source code snippet to yield the successor source code snippet.

Assignments (2)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Feb 2, 2023
From: X DEVELOPMENT LLC
To: GOOGLE LLC
Reel/Frame 062572/0565 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Sep 9, 2022
From: ZHANG, QIANYU
To: X DEVELOPMENT LLC
Reel/Frame 061050/0304 →
Continuity (2)
Continuation 17009306 · Sep 1, 2020
Related Publication 20230004364A1 · Jan 5, 2023