Computer system and source code defect correction support method
The system addresses the token limit challenge in generative AI by prioritizing relevant code snippets for bug corrections, enhancing the accuracy of source code patch generation.
Patent Information
- Application Number
- JP2023213515
- Authority / Receiving Office
- JP · JP
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-12-19
- Publication Date
- 2025-07-01
AI Technical Summary
Generative AI systems face limitations in correcting source code bugs due to the upper limit of tokens in input prompts, leading to incomplete or inaccurate corrections.
A system that identifies bug locations, extracts relevant code snippets, analyzes their relationships, and prioritizes correction material code pieces within the token limit to generate accurate patches using a text generation system.
Enables high-accuracy bug corrections in source code by effectively utilizing the available token limit, improving the precision of code patch generation.
Smart Images

Figure 2025097364000001_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a bug fixing technology for source code using generative AI.
Background Art
[0002] In the debugging work in software development, a technology called APR (Automated Program Repair) is known.
[0003] In recent years, a technology for fixing program bugs (bugs) using generative AI equipped with large language models has emerged. It has been reported that this technology has higher accuracy than APR.
Prior Art Documents
Non-Patent Documents
[0004]
Non-Patent Document 1
Non-Patent Document 2
Non-Patent Document 3
Summary of the Invention
Problems to be Solved by the Invention
[0005] The generative AI receives text (prompt) including the source code of a program, the correction policy, etc., and generates a patch for eliminating bugs. There is a limit to the number of tokens (characters or words) in the prompt input to the generative AI. Therefore, there are cases where the source code cannot be included in the prompt.
[0006] A method of identifying a bug location using the technique of identifying the bug location described in Non-Patent Document 2 etc. and including the code snippet of the bug location in the prompt can be considered. However, in this method, since information necessary for correcting the code snippet of the bug location such as a method is not included, there is a possibility that the source code cannot be corrected correctly.
[0007] The present invention provides a system and method capable of correcting bugs with high accuracy while considering the upper limit of the number of tokens when generating a patch for correcting bugs in source code using generative AI.
Means for Solving the Problem
[0008] A typical example of the invention disclosed in the present application is as follows. That is, a computer system for assisting in the correction of source code defects, comprising a computer having a processor, a storage device connected to the processor, and a network interface connected to the processor, and being accessible to a text generation system that uses a database storing a plurality of source codes constituting a program and a large language model to generate text. The text generation system is capable of receiving an input of a prompt, which is text for instructing the generation of a patch for correcting the source code defect, and the prompt has an upper limit value of the number of tokens, which is the amount of information that can be included. The processor identifies a target source code suspected of having a defect and the defect position of the target source code, records the information of the target source code and the defect position in the storage device, extracts code pieces from the plurality of source codes, records the information of the code pieces in the storage device, identifies a target code piece that is the code piece included in the defect position, analyzes the relationship between the target code piece and a correction material code piece that can be used to correct the defect and is the code piece, calculates a priority for defining the selection order of the correction material code pieces to be included in the prompt based on the result of the analysis, selects the correction material code pieces within the range of the upper limit value of the number of tokens based on the priority, generates a prompt including the selected correction material code pieces, and transmits it to the text generation system.
Advantages of the Invention
[0009] According to the present invention, when generating a patch for correcting a bug in source code using a text generation system (generative AI), it is possible to generate a patch for correcting the bug with high accuracy while considering the upper limit of the number of tokens. Other problems, configurations, and effects than those described above will be clarified by the description of the following embodiments.
Brief Description of the Drawings
[0010]
Figure 1
Figure 2
Figure 3A
Figure 3B
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Figure 9
Figure 10A
Figure 10B
Mode for Carrying Out the Invention
[0011] Hereinafter, examples of the present invention will be described with reference to the drawings. However, the present invention is not to be construed as being limited to the description of the examples shown below. It will be easily understood by those skilled in the art that the specific configuration can be changed without departing from the spirit or gist of the present invention.
[0012] In the configuration of the invention described below, the same or similar configurations or functions are denoted by the same reference numerals, and redundant descriptions are omitted.
[0013] In this specification and the like, notations such as "first", "second", "third", etc. are attached to identify components, and do not necessarily limit numbers or orders.
Example
[0014] FIG. 1 is a diagram showing an example of the configuration of the system of Example 1. FIG. 2 is a diagram showing an example of the hardware configuration of a computer constituting the bug correction support system of Example 1.
[0015] The system of Example 1 includes a bug correction support system 100, a text generation system 101, and a target system 102. Each system is connected to each other via a network such as a LAN (Local Area Network).
[0016] The target system 102 is a system that uses functions realized by a program composed of at least one source code. The bug correction support system 100 executes tests using a program, and when the test fails, corrects bugs in the source code constituting the program using the text generation system 101. The text generation system 101 generates text according to a prompt using a large language model. In this example, a patch for correcting bugs in the source code is generated by the text generation system 101.
[0017] The bug correction support system 100 is composed of a computer 200 as shown in FIG. 2. The computer 200 has a processor 201, a network interface 202, a main memory device 203, and an auxiliary storage device 204. Each hardware element is connected via a bus 205. The computer 200 may have input devices such as a keyboard and a mouse, and output devices such as a display.
[0018] The processor 201 executes a program stored in the main memory device 203. By executing processing according to the program, the processor 201 operates as a functional unit (module) that realizes a specific function. In the following description, when explaining processing with a functional unit as the subject, it indicates that the processor 201 is executing a program that realizes the functional unit.
[0019] The network interface 202 connects to external systems and devices via a network. The main memory device 203 is a memory or the like, and stores programs and various information executed by the processor 201. The auxiliary storage device 204 is an HDD (Hard Disk Drive), an SSD (Solid State Drive), or the like.
[0020] The bug fixing support system 100 includes a test execution unit 110, a bug location identification unit 111, a code snippet extraction unit 112, a prompt generation unit 113, and a patch verification unit 114. Also, the bug fixing support system 100 holds a source code DB 120, a test code DB 121, test information 122, bug location information 123, and code snippet management information 124. Note that the bug fixing support system 100 also holds information regarding a template of a prompt (not shown) and an upper limit value of the number of tokens.
[0021] The source code DB 120 is a database for managing source code. The source code is managed in association with program identification information. In the following description, the source code to be corrected is referred to as the target source code. The source code DB 120 stores source code of a plurality of programs and source code corresponding to execution modules of libraries. Note that the source code DB 120 may be held by a system different from the bug fixing support system 100.
[0022] The test code DB 121 is a database for managing test code for executing tests. Note that the test code DB 121 may be held by a system different from the bug fixing support system 100.
[0023] Test information 122 is information for managing the results of tests using test codes. Bug location information 123 is information for managing the locations of bugs in a program. Code snippet management information 124 is information for managing code snippets. Here, a code snippet means operators, identifiers, expressions, etc. included in source code.
[0024] The test execution unit 110 executes tests of a program. The bug location identification unit 111 identifies the bug locations in a program. The code snippet extraction unit 112 extracts code snippets from source code. The prompt generation unit 113 generates a prompt, which is the text input to the text generation system 101. The patch verification unit 114 verifies the patches generated by the text generation system 101.
[0025] Note that, regarding the functional units of the bug fixing support system 100, a plurality of functional units may be combined into one functional unit, or one functional unit may be divided into a plurality of functional units for each function.
[0026] Here, the data structure of the information managed by the bug fixing support system 100 will be described.
[0027] The test information 122 stores data associating the identification information of the source code to be tested, the identification information of the test code used, and the results of the test.
[0028] The bug location information 123 stores data associating the identification information of the target source code and the locations of bugs in the target source code. The location of a bug is, for example, the line number of the source code.
[0029] The data structure of the code snippet management information 124 will be described with reference to a figure. FIGS. 3A and 3B are diagrams showing an example of the data structure of the code snippet management information 124 of the first embodiment.
[0030] The code piece management information 124 stores, for example, a table 300 as shown in FIG. 3A. The table 300 stores entries including an ID 301, a name 302, code piece information 303, a classification 304, a priority 305, and a flag 306. There is one entry for one code piece.
[0031] The ID 301 is a field that stores the ID of the entry. The name 302 is a field that stores the name of the code piece. The code piece information 303 is a group of fields that store meta information indicating the content and location of the code piece, etc. The code piece information 303 will be described later.
[0032] The classification 304 is a field that stores the classification of the code piece. The code piece is classified into three types: the code piece included in the position of the bug, the code piece used to fix the bug, and the code piece not used to fix the bug. In this embodiment, the classification "1" is set for the correction material code piece, the classification "2" is set for the target code piece, and the classification "0" is set for the excluded code piece.
[0033] In the following description, the code piece included in the position of the bug is referred to as the target code piece, the code piece used to fix the bug is referred to as the correction material code piece, and the code piece not used to fix the bug is referred to as the excluded code piece.
[0034] The priority 305 is a field that stores the priority that defines the selection order of the correction material code pieces to be included in the prompt. The priority is calculated based on the relationship between the correction material code piece and the code pieces included in the target code. The method for calculating the priority will be described later.
[0035] The flag 306 is a field that stores a flag indicating whether it has been included in the prompt. In this embodiment, either "0" indicating that it has not been included in the prompt or "1" indicating that it has been included in the prompt is stored.
[0036] The code piece information 303 includes a signature 351, a Modifier 352, a code piece 353, a description 354, a declaration location 355, and a type 356.
[0037] The signature 351 is a field for storing the signature. The Modifier 352 is a field for storing the access identifier. The code piece 353 is a field for storing the code piece. The description 354 is a field for storing the description of the code piece. When the code piece is a variable or a constant, a declaration instruction is set, and when the code piece is a method, the code defining the method is set. The declaration location 355 is a field for storing the declaration location of the code piece. The type 356 is a field for storing the type of the code piece. Examples of the types and designations of the code pieces include variables, constants, and methods.
[0038] Note that the fields included in the entry are just examples and are not limited to this.
[0039] FIG. 4 is a flowchart for explaining an example of the process executed by the bug fixing support system 100 of Example 1. FIG. 5 is a diagram showing an example of the source code of Example 1.
[0040] When the bug fixing support system 100 receives an execution request including the identification information of the program, it executes the process described below. Note that the failure of the test by the test execution unit 110 may be used as an opportunity for execution.
[0041] The bug location identification unit 111 identifies the bug location of the program (step S101). The bug location identification unit 111 identifies the bug location of the program (the source code and the line where the bug in the source code is suspected), for example, using the technique described in Non-Patent Document 2. For example, the marker portion of the source code in FIG. 5 is identified as the bug location. The bug location identification unit 111 stores the information on the bug location in the bug location information 123.
[0042] Next, the code snippet extraction unit 112 executes code snippet extraction processing (step S102). Details of the code snippet extraction processing will be described later.
[0043] Next, the prompt generation unit 113 executes prompt generation processing (step S103). Details of the prompt generation processing will be described later.
[0044] Next, the patch verification unit 114 acquires the candidate patch generated by the text generation system 101 (step S104) and executes a test of the program (step S105).
[0045] Specifically, the patch verification unit 114 applies the candidate patch to the target source code and instructs the test execution unit 110 to execute a test of the program composed of the modified target source code.
[0046] The patch verification unit 114 acquires the test result from the test execution unit 110 and determines whether the test has passed (step S106).
[0047] If the test has not passed, the patch verification unit 114 calls the prompt generation unit 113 and instructs it to execute the processing. At this time, the patch verification unit 114 outputs the test result to the prompt generation unit 113.
[0048] If the test has passed, the patch verification unit 114 saves the target source code to which the candidate patch has been applied in the source code DB 120 (step S107). At this time, the patch verification unit 114 may upload the program composed of the target source code to which the candidate patch has been applied to the target system 102. Note that the upload of the program can be executed at an arbitrary timing.
[0049] FIG. 6 is a flowchart for explaining an example of the code snippet extraction processing executed by the code snippet extraction unit 112 of the first embodiment. FIG. 7 is a diagram showing an example of the data structure of the modified material code snippet list generated by the code snippet extraction unit 112 of the first embodiment.
[0050] The code piece extraction unit 112 extracts code pieces from the source code stored in the source code DB 120 (step S201). Here, code pieces are extracted from the source code constituting the program to be modified and the source code of the library used by the program. Known techniques may be used for the extraction of code pieces.
[0051] Next, the code piece extraction unit 112 registers the extracted code pieces in the code piece management information 124 (step S202).
[0052] Specifically, the code piece extraction unit 112 adds entries to the code piece management information 124 by the number of code pieces and sets an ID in the ID 301. The code piece extraction unit 112 sets the name of the code piece in the name 302 of each entry. The name is determined based on the content of the code piece. Alternatively, the code piece may be input to the text generation system 101 for determination. The code piece extraction unit 112 sets the meta information of the code piece in the code piece information 303. Alternatively, the description of the code piece may be input to the text generation system 101 for determination. The code piece extraction unit 112 sets "1" in the classification 304 of each entry and sets "0" in the flag 306. At this point, the priority 305 of each entry is blank.
[0053] Next, the code piece extraction unit 112 determines code pieces not used in the process from among the code pieces (step S203). For example, the code piece extraction unit 112 determines the code piece corresponding to the local variable as the code piece not used in the process. At this time, the code piece extraction unit 112 updates the classification 304 of the entry corresponding to the code piece not used in the process to "0".
[0054] Next, the code snippet extraction unit 112 identifies the target code snippet with reference to the bug position information 123 (step S204). For example, the code snippet extraction unit 112 identifies the target code snippet based on the meta information of the code snippet and the bug position information 123. At this time, the code snippet extraction unit 112 updates the classification 304 of the entry corresponding to the identified code snippet to "2". Note that there may be multiple target code snippets included in the bug position.
[0055] Next, the code snippet extraction unit 112 generates a list 700 of code snippets for repair materials (step S205).
[0056] The list 700 of code snippets for repair materials stores entries including an ID 701, a first relationship index 702, and a second relationship index 703. There is one entry for one code snippet for repair materials. The ID 701 is the same field as the ID 301. The first relationship index 702 is a field for storing a first relationship index calculated from the relationship between the processing of the code snippet for repair materials and the target code snippet. Code snippets for repair materials whose processing is similar or dependent are likely to be useful for repairing the target code snippet. The second relationship index 703 is a field for storing a second relationship index calculated from the positional relationship between the code snippet for repair materials and the target code snippet. Code snippets for repair materials close to the position of the target code snippet are likely to be useful for repairing the target code snippet. The initial values of the first relationship index 702 and the second relationship index 703 are set to 0.
[0057] Next, the code snippet extraction unit 112 starts a loop process for the target code snippet (step S206). Here, the code snippet extraction unit 112 selects one target code snippet.
[0058] Next, the code snippet extraction unit 112 starts a loop process for the code snippet for repair materials (step S207). Here, the code snippet extraction unit 112 selects one code snippet for repair materials.
[0059] Next, the code piece extraction unit 112 calculates the first relationship index of the target code piece and the correction material code piece (step S208). Specifically, the following processing is executed.
[0060] (S208-1) The code piece extraction unit 112 calculates a score based on the following rules.
[0061] (Rule 1) The code piece extraction unit 112 determines whether the signatures of the target code piece and the correction material code piece are the same or not. For example, the code piece extraction unit 112 calculates the similarity by comparing the strings representing the signatures, and determines whether the signatures are similar based on the comparison of the similarity and the threshold value. The code piece extraction unit 112 calculates a score based on the result of whether the signatures are the same or not. For example, when the signatures are similar, the score is "+2", and when the signatures are not similar, the score is "0". Note that a score considering the similarity may be calculated.
[0062] (Rule 2) The code piece extraction unit 112 determines whether the names of the target code piece and the correction material code piece are the same or not. For example, the code piece extraction unit 112 calculates the similarity by comparing the strings representing the names, and determines whether the names are similar based on the comparison of the similarity and the threshold value. The code piece extraction unit 112 calculates a score based on the result of whether the names are the same or not. For example, when the names are similar, the score is "+3", and when the names are not similar, the score is "0". Note that a score considering the similarity may be calculated.
[0063] (Rule 3) The code piece extraction unit 112 determines whether the processes of the target code piece and the correction material code piece are the same or not. For example, the code piece extraction unit 112 compares the target code piece and the correction material code piece, and also compares the descriptions, and determines whether the processes are similar or not. The code piece extraction unit 112 calculates a score based on the result of whether the processes are the same or not. For example, when the processes are similar, the score is "+3", and when the processes are not similar, the score is "0".
[0064] (Rule 4) The code piece extraction unit 112 determines the presence or absence of a data dependency relationship of the target code piece with respect to the modified material code piece. For example, the code piece extraction unit 112 determines the data dependency relationship using the technique of Non-Patent Document 3. The code piece extraction unit 112 calculates a score according to the presence or absence of the data dependency relationship. For example, when there is a data dependency relationship, the score is "+1", and when there is no data dependency relationship, the score is "0".
[0065] (S208-2) The code piece extraction unit 112 calculates a first relationship index using the score. For example, the sum of the scores or the weighted sum of the scores is calculated as the first relationship index. The code piece extraction unit 112 adds the calculated first relationship index to the first relationship index 702 of the entry of the selected modified material code piece in the modified material code piece list 700.
[0066] The above is the description of the process of step S208.
[0067] Next, the code piece extraction unit 112 calculates a second relationship index for the target code piece and the modified material code piece (step S209).
[0068] Specifically, the code piece extraction unit 112 calculates a second relationship index based on the declaration locations of the target code piece and the modified material code piece. For example, when the target code piece and the modified material code piece are in the same method, the second relationship index is "4", when the target code piece and the modified material code piece are in the same file, the second relationship index is "3", when the target code piece and the modified material code piece are in the same package, the second relationship index is "2", and in other cases, the second relationship index is "1". The code piece extraction unit 112 adds the calculated second relationship index to the second relationship index 703 of the entry of the selected modified material code piece in the modified material code piece list 700.
[0069] Next, the code piece extraction unit 112 determines whether the processing has been completed for all the modified material code pieces (step S210). If the processing has not been completed for all the modified material code pieces, the code piece extraction unit 112 returns to step S207.
[0070] If the processing has been completed for all the modified material code pieces, the code piece extraction unit 112 ends the loop processing of the modified material code pieces and determines whether the processing has been completed for all the target code pieces (step S211). If the processing has not been completed for all the target code pieces, the code piece extraction unit 112 returns to step S206.
[0071] If the processing has been completed for all the target code pieces, the code piece extraction unit 112 calculates the priority of the modified material code pieces based on the first relationship index and the second relationship index (step S212). For example, the code piece extraction unit 112 calculates the sum of the first relationship index and the second relationship index, or the weighted sum of the first relationship index and the second relationship index, as the priority. The code piece extraction unit 112 sets the calculated priority to the priority 305 of the entry of the modified material code piece in the code piece management information 124.
[0072] Modified material code pieces with high relevance in terms of processing and position are likely to be information useful for modifying the target code pieces. Therefore, by preferentially including highly relevant modified material code pieces in the prompt, an improvement in the accuracy of defect correction can be expected. Note that the priority may be calculated using only one of the first relationship index and the second relationship index.
[0073] FIG. 8 is a flowchart for explaining an example of the prompt generation process executed by the prompt generation unit 113 of the first embodiment. FIG. 9 is a diagram showing an example of the prompt template managed by the bug correction support system 100 of the first embodiment. FIGS. 10A and 10B are diagrams showing an example of the prompt generated by the prompt generation unit 113 of the first embodiment.
[0074] The prompt generation unit 113 acquires a prompt template (step S301). Here, the prompt template will be described.
[0075] The prompt template shown in FIG. 9 includes, as items, "System", "User", "Buggy code block", "Suspicious buggy statement", "Failing test cases", "Other project-specific information", and "Incorrect fixes".
[0076] "System" is an item for setting text that specifies the role assigned to the text generation system 101. "User" is an item for setting text that specifies the method of generating a patch.
[0077] "Buggy code block" is an item for setting the lines around the bug position (buggy code block). "Suspicious buggy statement" is an item for setting the target code snippet.
[0078] "Failing test cases" is an item for setting test information. The content that failed the test and the like are set in this item.
[0079] "Other project-specific information" is an item for setting the code snippet of the correction material.
[0080] "Incorrect fixes" is an item for setting information on patches that failed the test as a result of verification by the patch verification unit 114. Patches and test information are set in "Incorrect fixes".
[0081] Return to the description of FIG. 8. Next, the prompt generation unit 113 identifies a buggy code block (step S302). Specifically, the prompt generation unit 113 identifies a part (block) of the source code including the bug position as a buggy code block based on a predetermined rule. For example, a rule of identifying the 10 lines before and after the bug position as the buggy code block can be considered. Note that the rule can be set arbitrarily.
[0082] Next, the prompt generation unit 113 sets the target code snippet, the buggy code block, and the test information in the prompt template (step S303). Specifically, the prompt generation unit 113 sets the buggy code block of "Buggy code block", sets the target code snippet in "Suspicious buggy statement", and sets the test information in "Failing test cases".
[0083] Next, the prompt generation unit 113 determines whether the number of times of generating the prompt is 2 or more (step S304).
[0084] If the number of times of generating the prompt is 1, the prompt generation unit 113 proceeds to step S306.
[0085] If the number of times of generating the prompt is 2 or more, the prompt generation unit 113 sets the patch and the test information of the test performed after applying the patch in the prompt template (step S305), and then the prompt generation unit 113 proceeds to step S306. Specifically, the prompt generation unit 113 sets the patch and the test information in "Incorrect fixes".
[0086] In step S306, the prompt generation unit 113 determines whether the number of tokens in the prompt template is less than the upper limit value (step S306).
[0087] When the number of tokens in the prompt template is less than the upper limit value, the prompt generation unit 113 selects a modified material code piece based on the priority (step S307). Specifically, the prompt generation unit 113 selects the modified material code pieces in descending order of priority. Note that the modified material code pieces with the flag 306 being "1" are excluded from the selection targets.
[0088] At this time, the prompt generation unit 113 sets "1" to the flag 306 of the entry of the selected modified material code piece in the code piece management information 124. Note that the selection count of the modified material code piece may be counted, and "1" may be set to the flag 306 when the selection count is equal to or more than a predetermined value.
[0089] Next, the prompt generation unit 113 sets the selected modified material code piece to the prompt template (step S308), and then returns to step S306. Specifically, the prompt generation unit 113 sets the selected modified material code piece to "Other project - specific information".
[0090] In step S306, when the number of tokens in the prompt template is equal to or more than the upper limit value, the prompt generation unit 113 transmits the prompt template with various information set thereto to the text generation system 101 as a prompt (step S309). At this time, the prompt generation unit 113 increments the generation count of the prompt.
[0091] For example, a prompt as shown in FIGS. 10A and 10B is transmitted to the text generation system 101.
[0092] As described above, the bug - fixing support system 100 can generate a prompt so as not to exceed the number of tokens. By preferentially including modified material code pieces with a high degree of relevance to the target code piece in the prompt, the accuracy of the correction can be improved while suppressing the number of tokens.
[0093] Note that the present invention is not limited to the above-described embodiments, and includes various modifications. Further, for example, the above-described embodiments have been described in detail for easy understanding of the present invention, and are not necessarily limited to those having all the configurations described. Also, a part of the configuration of each embodiment can be added to, deleted from, or replaced with other configurations.
[0094] In addition, the above-described respective configurations, functions, processing units, processing means, etc. may be realized in hardware by designing a part or all of them, for example, by using an integrated circuit. Also, the present invention can be realized by a program code of software that realizes the functions of the embodiments. In this case, a storage medium recording the program code is provided to a computer, and a processor included in the computer reads the program code stored in the storage medium. In this case, the program code itself read from the storage medium realizes the functions of the above-described embodiments, and the program code itself and the storage medium storing it constitute the present invention. As a storage medium for supplying such a program code, for example, a flexible disk, CD-ROM, DVD-ROM, hard disk, SSD (Solid State Drive), optical disk, magneto-optical disk, CD-R, magnetic tape, non-volatile memory card, ROM, etc. are used.
[0095] Also, the program code for realizing the functions described in this embodiment can be implemented in a wide range of programs or script languages such as assembler, C / C++, perl, Shell, PHP, Python, Java (registered trademark), etc.
[0096] Furthermore, by distributing the program code of software that realizes the functions of the embodiments via a network, it can be stored in a storage means such as a hard disk or memory of a computer or a storage medium such as a CD-RW or CD-R, and a processor included in the computer reads and executes the program code stored in the storage means or the storage medium.
[0097] In the above embodiments, the control lines and information lines show those considered necessary for explanation, and not necessarily all the control lines and information lines are shown on the product. All components may be interconnected with each other.
Explanation of Signs
[0098] 100 Bug Fix Support System 101 Text Generation System 102 Target System 110 Test Execution Unit 111 Bug Location Identification Unit 112 Code Fragment Extraction Unit 113 Prompt Generation Unit 114 Patch Verification Unit 120 Source Code DB 121 Test Code DB 122 Test Information 123 Bug Location Information 124 Code Fragment Management Information 200 Computer 201 Processor 202 Network Interface 203 Main Memory Device 204 Auxiliary Memory Device 700 List of Revised Material Code Fragments
Claims
1. A computer system for assisting in the correction of source code defects, comprising: a computer having a processor, a storage device connected to the processor, and a network interface connected to the processor; accessibly connected to a database for storing a plurality of source codes constituting a program and a text generation system for generating text using a large language model; the text generation system is capable of receiving an input of a prompt, which is text for instructing the generation of a patch for correcting the defect of the source code; the prompt has an upper limit value of the number of tokens, which is the amount of information that can be included; the processor: identifies a target source code suspected of having a defect and the defect position of the target source code, and records the information of the target source code and the defect position in the storage device; extracts code fragments from the plurality of source codes and records the information of the code fragments in the storage device; identifies a target code fragment that is the code fragment included in the defect position; analyzes the relationship between the target code fragment and a correction material code fragment that is the code fragment that can be used to correct the defect, and calculates a priority for defining the selection order of the correction material code fragments to be included in the prompt based on the result of the analysis; selects the correction material code fragments within the range of the upper limit value of the number of tokens based on the priority; generates the prompt including the selected correction material code fragments and transmits it to the text generation system. A computer system characterized by the above.
2. The computer system according to claim 1, wherein the processor analyzes at least one of the processing relationship between the target code fragment and the correction material code fragment and the positional relationship between the target code fragment and the correction material code fragment. A computer system characterized by the above.
3. The computer system according to claim 2, wherein the processor generates the prompt including the test result of the program, the target code fragment, a part of the source code around the defect position, and the selected correction material code fragment. A computer system characterized by the above.
4. The computer system according to claim 3, wherein the processor: obtains the patch generated by the text generation system. Execute the test of the program composed of the target source code to which the patch is applied, If the result of the test fails, exclude the code snippet of the correction material included in the prompt from the selection target, and select the code snippet of the correction material again, A computer system characterized by generating the prompt including the result of the test of the program, the target code snippet, a part of the source code around the defect position, the selected code snippet of the correction material, and the code snippet of the correction material included in the previous prompt.
5. The computer system according to claim 4, Connected to a system that uses the program composed of the target source code, When the result of the test is successful, the processor uploads the program composed of the target source code to which the patch is applied to the system. A computer system characterized by that.
6. A method for assisting in correcting defects in source code executed by a computer system, The computer system is Including a computer having a processor, a storage device connected to the processor, and a network interface connected to the processor, Accessibly connected to a text generation system that generates text using a database storing a plurality of source codes constituting a program and a large language model, The text generation system is capable of receiving an input of a prompt that is text instructing generation of a patch for correcting a defect in the source code, The prompt has an upper limit value of the number of tokens that is the amount of information that can be included, The method for assisting in correcting defects in the source code is A first step in which the processor identifies a target source code suspected of having a defect and a defect position of the target source code, and records information on the target source code and the defect position in the storage device; A second step in which the processor extracts code snippets from the plurality of source codes and records information on the code snippets in the storage device; A third step in which the processor identifies a target code snippet that is the code snippet included in the defect position The fourth step in which the processor analyzes the relationship between the target code piece and a correction material code piece that can be used to correct a defect among the code pieces, and calculates a priority for defining the selection order of the correction material code pieces to be included in the prompt based on the result of the analysis; The fifth step in which the processor selects the correction material code piece within the range of the upper limit value of the number of tokens based on the priority; The sixth step in which the processor generates the prompt including the selected correction material code piece and transmits it to the text generation system, and a method for assisting in correcting a defect in source code, characterized by including the above steps.
7. A method for assisting in correcting a defect in source code according to claim 6, wherein the fourth step includes a step in which the processor analyzes at least either the relationship between the processing of the target code piece and the correction material code piece or the positional relationship between the target code piece and the correction material code piece, and a method for assisting in correcting a defect in source code, characterized by including the above steps.
8. A method for assisting in correcting a defect in source code according to claim 7, wherein the sixth step includes a step in which the processor generates the prompt including the test result of the program, the target code piece, a part of the source code around the defect position, and the selected correction material code piece, and a method for assisting in correcting a defect in source code, characterized by including the above steps.
9. A method for assisting in correcting a defect in source code according to claim 8, wherein the processor obtains the patch generated by the text generation system; the processor executes a test of the program composed of the target source code to which the patch is applied; when the result of the test is a failure, the processor excludes the correction material code piece included in the prompt from the selection target and selects the correction material code piece again. The step of the processor generating the prompt including the test result of the program, the target code snippet, a part of the source code around the defect position, the selected correction material code snippet, and the correction material code snippet included in the previous prompt, and a method for assisting in correcting a defect in source code, characterized by including this step.
10. A method for assisting in correcting a defect in source code according to claim 9, The computer system is connected to a system that uses the program composed of the target source code, When the result of the test is successful, the method for assisting in correcting a defect in source code is characterized in that the processor includes the step of uploading to the system the program composed of the target source code to which the patch has been applied.