US12175220B2ActiveUtilityA1
Code insertion completion
Assignee: MICROSOFT TECHNOLOGY LICENSING LLCPriority: Jun 16, 2022Filed: Jun 16, 2022Granted: Dec 24, 2024
Est. expiryJun 16, 2042(~15.9 yrs left)· nominal 20-yr term from priority
G06F 8/33G06F 8/36G06F 8/427
93
PatentIndex Score
2
Cited by
83
References
20
Claims
Abstract
A code insertion engine predicts one or more statements of a programming language to be inserted at an insertion point in between existing source code statements of a source code program being edited. The code insertion engine extracts the surrounding context of the insertion point which includes the source code immediately preceding and the source code immediately following the insertion point. The code insertion engine uses a neural expansion model and a neural selector model to predict the one or more statements most likely to be inserted into the insertion point that are syntactically and semantically consistent with the surrounding context of the existing program.
Claims
exact text as granted — not AI-modifiedWhat is claimed:
1. A system comprising:
one or more processors; and
a memory that stores one or more programs configured to be executed by the one or more processors, the one or more programs including instructions to perform acts that:
detect an insertion point in a source code program during an edit session of a source code editor, wherein the insertion point represents a location where additional source code is to be inserted in between existing source code segments of the source code program;
extract a context surrounding the insertion point, the context including a prefix and a suffix of the insertion point;
form an input sequence including the prefix, a single non-terminal symbol representing a statement, and the suffix;
obtain from a code insertion engine, one or more source code statements to insert at the insertion point that are syntactically correct with the surrounding context, wherein the code insertion engine decodes the single non-terminal symbol into a sequence of terminal symbols representing the one or more source code statements to insert at the insertion point, wherein the code insertion engine iteratively selects a position of a non-terminal symbol to expand, wherein the position of the non-terminal symbol to expand is based on an output probability generated from a non-terminal selector model, wherein the code insertion engine expands the selected non-terminal symbol into a code state based on a production rule of a programming language of the source code program, wherein the production rule is determined from an output probability generated by an expansion model, wherein each expansion generates a new code state until a stop expansion condition exists, wherein the non-terminal selector model is a trained neural network model that infers a most likely non-terminal symbol to expand given a current code state, wherein the non-terminal expansion model is a trained neural network model that infers a most likely expansion for the selected non-terminal symbol given the current code state;
and
display the one or more source code statements in the source code program of the source code editor.
2. The system of claim 1 , wherein the one or more programs including instructions to perform acts that:
transform the source code program into a concrete syntax tree, wherein the concrete syntax tree includes terminal symbols and non-terminal symbols;
extract terminal symbols representing the prefix and terminal symbols representing the suffix; and
form the input sequence using the terminal symbols representing the prefix, the single non-terminal symbol representing the statement, and terminal symbols representing the suffix.
3. The system of claim 1 , wherein the one or more programs including instructions to perform acts that:
upon user input, embed the one or more source code statements into the source code program.
4. The system of claim 1 , wherein the one or more programs including instructions to perform acts that:
iteratively expand the single non-terminal symbol representing the statement into a new code state that includes all terminal symbols; and
generate an additional non-terminal symbol representing a statement to expand into one or more additional statements.
5. The system of claim 1 , wherein the stop expansion condition includes the stop expansion non-terminal symbol or a maximum length of a code state that has been exceeded.
6. The system of claim 1 , wherein the non-terminal selector model is a multilayer perceptron model.
7. The system of claim 1 , wherein the non-terminal expansion model is a neural transformer model with attention.
8. The system of claim 1 , wherein the single non-terminal symbol representing a statement includes a single statement or a group of statements within a statement block.
9. A computer-implemented method, comprising:
representing a source code program during an edit session of a source code editor as a tree of non-terminal symbols and/or terminal symbols;
accessing a code insertion state of the source code program, wherein the code insertion state includes a prefix, an insertion point and a suffix, wherein the insertion point represents a location in the source code program where one or more source code statements are to be inserted in between the prefix and the suffix, wherein the prefix and the suffix represent existing source code segments of the source code program;
transforming the code insertion state into a sequence of terminal symbols representing the prefix, a single statement non-terminal symbol representing a statement, and a sequence of terminal symbols representing the suffix;
decoding the code insertion state into an insertion candidate representing the one or more source code statements to be inserted at the insertion point, wherein the the single statement non-terminal symbol is expanded iteratively into a series of new code states using production rules of a grammar of a programming language of the source code program until a stop expansion condition exists;
selecting a non-terminal symbol of each new code state to expand based on an output probability generated by a non-terminal selector model given a current code state, wherein the non-terminal selector model is a trained neural network model that produces an output probability indicating a most likely non-terminal symbol to expand given a current code state;
expanding the selected non-terminal symbol based on an output probability generated from a non-terminal expansion model given the current code state, wherein the non-terminal expansion model is a trained neural network model that produces an output probability indicating a most likely production rule to expand the selected non-terminal symbol; and
upon detection of the stop expansion condition, presenting the insertion candidate in the source code program in the source code editor.
10. The computer-implemented method of claim 9 , further comprising:
appending an additional single statement non-terminal symbol into a new code state when the new code state includes a sequence of terminal symbols and the stop expansion condition has not been detected.
11. The computer-implemented method of claim 9 , wherein the stop expansion condition is based on the terminal symbols of the new code state including the suffix.
12. The computer-implemented method of claim 9 , wherein the stop expansion condition is based on the non-terminal selector model selecting a stop non-terminal symbol.
13. The computer-implemented method of claim 9 , wherein the stop expansion condition is based on a length of a new code state exceeding a maximum length.
14. The computer-implemented method of claim 9 , wherein the non-terminal selector model is a multilayer perceptron model.
15. The computer-implemented method of claim 9 , wherein the non-terminal expansion model is a neural transformer model with attention.
16. A non-transitory computer-readable storage medium having instructions that when executed performs operations, comprising:
accessing a non-terminal expansion model to predict a production rule of a grammar of a programming language to expand a non-terminal symbol;
accessing a non-terminal selector model to predict a non-terminal symbol to expand;
obtaining a code insertion state of a source code program in a source code editor, the code insertion state including an input sequence of terminal symbols representing a prefix, a single non-terminal statement symbol, and terminal symbols representing a suffix, wherein the single non-terminal statement symbol represents a location in the source code program to insert predicted source code statements in between the prefix and the suffix;
decoding the single non-terminal statement symbol into the predicted source code statements by iteratively expanding the single non-terminal statement symbol into new code states, a new code state having terminal symbols and zero or more non-terminal symbols, wherein the expansion uses the non-terminal selector model to select a non-terminal symbol to expand at each iteration and the non-terminal expansion model to choose the production rule to expand each selected non-terminal symbol, wherein the non-terminal selector model is a trained neural network model that infers a most likely non-terminal symbol to expand given a current code state, wherein the non-terminal expansion model is a trained neural network model that infers a most likely expansion for the selected non-terminal symbol given the current code state;
generating the predicted source code statements upon expansion of a select one of the new code states into a sequence of all terminal symbols; and
displaying the predicted source code statements in the source code program in the source code editor.
17. The non-transitory computer-readable storage medium of claim 16 having instructions that when executed performs operations, comprising:
upon detecting a new code state having all terminal symbols, expand the new code state to include one or more additional source code statements by appending a second non-terminal statement symbol.
18. The non-transitory computer-readable storage medium of claim 17 having instructions that when executed performs operations, comprising:
iteratively expanding the second non-terminal statement symbol into one or more additional predicted source code statements.
19. The non-transitory computer-readable storage medium of claim 16 having instructions that when executed performs operations, comprising: configuring the non-terminal selector model as a multilayer perceptron model.
20. The non-transitory computer-readable storage medium of claim 16 having instructions that when executed performs operations, comprising: configuring the non-terminal expansion model as a neural transformer model with attention.Cited by (0)
No later patents cite this yet.
References (0)
No backward citations on record.