IP Library Granted Patent US 11,455,152
Granted Patent B2
US 11,455,152 · App. 17/009,306 · Granted Sep 27, 2022

Matching graphs generated from source code

Inventor: Qianyu Zhang (Sunnyvale, CA)
Assignee: X DEVELOPMENT 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 11,455,152
App. No.
17/009,306
Granted
Sep 27, 2022
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 (42)

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

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 abstract syntax tree and the second 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 first abstract syntax tree and the second abstract syntax tree; 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.

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

3. The method according to claim 1 , wherein the determining the mapping across the first abstract syntax tree and the second abstract syntax tree comprises using a tree-based code differencing algorithm.

4. The method according to claim 1 , wherein the obtaining the first control-flow graph and the second control-flow graph comprises using a parser to generate the first control-flow graph from the predecessor source code snippet and the second control-flow graph from the successor source code snippet.

5. The method according to claim 1 , wherein the aligning the blocks in the first control-flow graph with the blocks in the second control-flow graph based on the mapping across the first abstract syntax tree and the second abstract syntax tree comprises:

determining a mapping across the first control-flow graph and the second control-flow graph between pairs of similar blocks identified using the mapping across the first abstract syntax tree and the second abstract syntax tree; and

using the mapping across the first control-flow graph and the second control-flow graph to align the blocks in the first control-flow graph with the blocks in the second control-flow graph.

6. The method according to claim 1 , wherein in the applying the aligned blocks as inputs across the trained machine learning model to generate the alignment of nodes in the first abstract syntax tree with nodes in the second abstract syntax tree, candidate node alignments are constrained based on nodes in the aligned blocks.

7. The method according to claim 1 , further comprising generating a change graph based on the alignment of the nodes in the first abstract syntax tree with the nodes in the second 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.

8. 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 predecessor source code snippet and a second abstract syntax tree that represents a successor source code snippet;

determine a mapping across the first abstract syntax tree and the second 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 first abstract syntax tree and the second abstract syntax tree; and

apply 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.

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

10. The computer program product according to claim 8 , wherein the determining the mapping across the first abstract syntax tree and the second abstract syntax tree comprises using a tree-based code differencing algorithm.

11. The computer program product according to claim 8 , wherein the obtaining the first control-flow graph and the second control-flow graph comprises using a parser to generate the first control-flow graph from the predecessor source code snippet and the second control-flow graph from the successor source code snippet.

12. The computer program product according to claim 8 , wherein the aligning the blocks in the first control-flow graph with the blocks in the second control-flow graph based on the mapping across the first abstract syntax tree and the second abstract syntax tree comprises:

determining a mapping across the first control-flow graph and the second control-flow graph between pairs of similar blocks identified using the mapping across the first abstract syntax tree and the second abstract syntax tree; and

using the mapping across the first control-flow graph and the second control-flow graph to align the blocks in the first control-flow graph with the blocks in the second control-flow graph.

13. The computer program product according to claim 8 , wherein in the applying the aligned blocks as inputs across the trained machine learning model to generate the alignment of nodes in the first abstract syntax tree with nodes in the second abstract syntax tree, candidate node alignments are constrained based on nodes in the aligned blocks.

14. The computer program product according to claim 8 , wherein the program instructions are further executable to generate a change graph based on the alignment of the nodes in the first abstract syntax tree with the nodes in the second 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.

15. 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 predecessor source code snippet and a second abstract syntax tree that represents a successor source code snippet;

determine a mapping across the first abstract syntax tree and the second 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 first abstract syntax tree and the second abstract syntax tree; and

apply 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.

16. The system according to claim 15 , wherein the trained machine learning model comprises a graph neural network.

17. The system according to claim 15 , wherein the determining the mapping across the first abstract syntax tree and the second abstract syntax tree comprises using a tree-based code differencing algorithm.

18. The system according to claim 15 , wherein the obtaining the first control-flow graph and the second control-flow graph comprises using a parser to generate the first control-flow graph from the predecessor source code snippet and the second control-flow graph from the successor source code snippet.

19. The system according to claim 15 , wherein the aligning the blocks in the first control-flow graph with the blocks in the second control-flow graph based on the mapping across the first abstract syntax tree and the second abstract syntax tree comprises:

determining a mapping across the first control-flow graph and the second control-flow graph between pairs of similar blocks identified using the mapping across the first abstract syntax tree and the second abstract syntax tree; and

using the mapping across the first control-flow graph and the second control-flow graph to align the blocks in the first control-flow graph with the blocks in the second control-flow graph.

20. The system according to claim 15 , wherein in the applying the aligned blocks as inputs across the trained machine learning model to generate the alignment of nodes in the first abstract syntax tree with nodes in the second abstract syntax tree, candidate node alignments are constrained based on nodes in the aligned blocks.

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 3, 2020
From: ZHANG, QIANYU
To: X DEVELOPMENT LLC
Reel/Frame 053683/0224 →
Continuity (1)
Related Publication 20220066752A1 · Mar 3, 2022
Cited By (13)
US 12,443,462 US 12,475,119 US 12,511,106 US 12,572,338 US 12,579,011 US 12,585,470 US 12,602,230 US 12,619,480 US 12,639,054 US 12,663,995 US 12,688,019 US 12,705,060 US 12,717,561