Implicit global information matching transplantation method for patch transplantation

By collaboratively processing implicit global information differences in the patch transplantation process through a large language model and a compiler, the problems of high labor costs and large delays in existing technologies are solved, and efficient and accurate automated patch transplantation is achieved, which is suitable for the fields of deep learning and software engineering.

CN120631433APending Publication Date: 2025-09-12ZHEJIANG UNIV +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510767655.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-10
Publication Date
2025-09-12

AI Technical Summary

Technical Problem

Existing patch migration technologies cannot effectively handle the implicit global information differences between source and target projects, resulting in migration failures or high delays and high labor costs.

Method used

Through the collaborative work of the large language model and the compiler, the matching and adjustment of implicit global information in the patch transplant process are automatically handled, including compilation diagnostic information analysis, repair of compilation errors due to non-existent identifiers, function similarity matching and optimization iterations, and the use of code snippets to build prompt templates to guide the transplantation of the large language model.

Benefits of technology

It automates and optimizes the patch migration process, reduces matching errors caused by changes in identifier definitions, can handle complex structural changes, improves the success rate and efficiency of migration, and provides explainability for programmers to verify and adjust.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120631433A_ABST
    Figure CN120631433A_ABST
Patent Text Reader

Abstract

The invention discloses an implicit global information matching transplantation method for patch transplantation, and belongs to the field of deep learning and software engineering. The method comprises the following steps of: applying a given patch to a target code library, and detecting potential implicit global information change which is not correctly transplanted by utilizing a compiler; for the change that the identifier used in the source patch does not exist in the target code library, obtaining the corresponding implementation of the identifier function in the target code library by matching the code snippets used by the identifier in the source code library and the target code library, and executing transplantation by using a large language model; when an identifier used in a source patch exists in a target code library but the definition is changed, compiler diagnosis information is analyzed, a prompt is constructed, and a large model is guided to adjust the patch so as to repair compiling errors; the updated patch is applied to the target code library again, and the detection-repair process is iterated. According to the method, the patch transplanting workflow can be embedded, and the accuracy and efficiency of the existing automatic tool or manual patch transplanting are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of deep learning and software engineering, and in particular to an implicit global information matching transplantation method for patch transplantation. Background Art

[0002] Software reuse techniques (such as forking and branching) are widely used in modern software development to meet the feature and stability requirements of different users. While software reuse improves development efficiency, it also inevitably spreads software defects and vulnerabilities in the reused code. Therefore, patches used to fix defects in the source code repository must be promptly ported to the target code repository. This porting process must maintain the patch semantics while adapting to the differences in the target project's implementation compared to the source project. Currently, patch porting is primarily performed manually by developers, which is associated with high labor costs and significant delays.

[0003] Recently, some automated patch migration technologies have been proposed to reduce the labor cost and delays in the migration process. However, these technologies can only adjust patches based on the implementation differences presented in the local context of the patch, while ignoring the adjustment and migration of differences in implicit global information. For example, the name and calling method of the corresponding function in the target project have changed, and the name and type of the global variable have changed. If these changes in the semantics of code identifiers are not presented in the local context of the patch, they need to be traced and compared to their definitions in the two code bases to be known. Failure to adjust or incorrectly adjust the differences in implicit global information between the source and target projects will cause patch migration to fail. Summary of the Invention

[0004] The purpose of the present invention is to address the deficiencies of the existing patch transplantation technology and provide a method for automatically matching and transplanting implicit global information in the patch transplantation process.

[0005] The object of the present invention is achieved through the following technical solution: an implicit global information matching transplantation method for patch transplantation, comprising the following steps:

[0006] (1) Apply the patches obtained from the initial migration to the target code base;

[0007] (2) compile the updated target code library to obtain compilation diagnostic information;

[0008] (3) Based on the compilation diagnostic information, check whether there is a compilation error whose root cause is that the identifier does not exist;

[0009] (4) If there is a compilation error whose root cause is that the identifier does not exist, then the non-existent identifier is repaired to obtain an optimized patch;

[0010] (5) If there is no compilation error whose root cause is the non-existence of the identifier, all remaining compilation errors are fixed at the same time to obtain an optimized patch;

[0011] (6) Re-execute step (1) using the optimized patch to enter a new round of iteration until no compilation error information can be diagnosed in step (2) or the number of iterations exceeds the set upper limit.

[0012] Furthermore, the step (4) is specifically as follows: if there is a compilation error whose root cause is that the identifier does not exist, for the compilation error whose root cause is that the identifier does not exist, it is replaced with an implementation in the target code library that has the same function as the source identifier; a source code snippet (such as a function) involving the use of the source identifier in the source code library is obtained, and a target code snippet corresponding to the source code snippet in the target code library is obtained, the source code snippet and the corresponding target code snippet form a code snippet pair, and the matching information of the source identifier in the target code library is obtained through the code snippet pair and the transplantation is performed using the large language model.

[0013] Furthermore, the step (4) includes the following sub-steps:

[0014] (4.1) For each compilation error whose root cause is a non-existent identifier, parse the compilation diagnostic information to obtain the non-existent identifier, that is, the identifier used in the source patch but not in the target code base (referred to as the source identifier for short);

[0015] (4.2) Search the source code library to obtain and extract all functions involving the use of the identifier (referred to as source use functions for short);

[0016] (4.3) For each source usage function, traverse the target code base to obtain the target usage function with the highest similarity; specific similarity measurements include text similarity based on code strings and code semantic similarity;

[0017] (4.4) For all the obtained function pairs, first, filter out the function pairs whose function name similarity and function body similarity are lower than the threshold, and then sort them from small to large according to the length (number of lines of code) of the source function.

[0018] (4.5) Take the top k function pairs obtained by sorting and use them to demonstrate the equivalent implementation of the functions implemented by the code snippet containing the source identifier in the target code base; build hints based on the top k function pairs to guide the large language model to transplant the identifiers that do not exist in the input patch according to the equivalent transformation demonstrated by the function pairs to obtain the optimized patch.

[0019] Furthermore, the step (5) is specifically as follows: if there is no compilation error whose root cause is the non-existence of an identifier, for each compilation error, the compilation diagnostic information is parsed to extract the line where the error is located, the identifier involved, and the diagnostic prompt; the parsed information is filled into a defined prompt template to guide the large language model to optimize the input function to fix the compilation error.

[0020] Furthermore, the prompt template includes a template preamble for informing the large language model to provide an erroneous function to be repaired and corresponding compiler diagnostic information, formatted compiler diagnostic information and the function to be repaired, and instructions for guiding the large model to perform repairs based on the compiler diagnostic information.

[0021] The present invention also provides an electronic device, comprising a memory and a processor, wherein the memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the implicit global information matching transplantation method for patch transplantation.

[0022] The present invention also provides a computer-readable storage medium storing a computer program, wherein the program, when executed by a processor, implements the implicit global information matching transplantation method for patch transplantation.

[0023] The beneficial effects of the present invention are that it can automatically match and transplant the implicit global information of patch transplants, thereby significantly optimizing the workflow and effects of existing patch migrations. In the case where the source identifier does not exist in the target code base, the present invention obtains the transplant information of the identifier by indirectly matching the functions involved in the identifier's use. Compared with directly matching through the identifier definition, it has the following beneficial effects: it reduces matching errors caused by major changes in the identifier definition and can handle complex transplant situations involving structural changes. In addition, the use of function pairs as a basis makes the transplant process explainable, allowing programmers to verify and adjust the automated transplant results. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0025] Figure 1 is an overview diagram of the method of the present invention;

[0026] Figure 2A flowchart of the present invention for obtaining transplantation information and guiding the transplantation of a large language model by matching functions involving source identifier usage between a source code library and a target code library;

[0027] Figure 3 This is a prompt template for repairing compilation errors using a large language model in the present invention. DETAILED DESCRIPTION

[0028] Exemplary embodiments will be described in detail herein, examples of which are illustrated in the accompanying drawings. In the following description, when referring to the drawings, like numbers in different figures represent like or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all possible embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present invention, as detailed in the appended claims.

[0029] The terms used in this invention are for the purpose of describing specific embodiments only and are not intended to limit the invention. The singular forms "a," "the," and "the" used in this invention and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.

[0030] The present invention realizes automatic matching and transplantation of implicit global information of patch transplantation through the collaboration among a large language model, a compiler and support tools based on static program analysis (such as obtaining identifier definition, obtaining function signature, etc.).

[0031] like Figure 1 As shown, an embodiment of the present invention provides an implicit global information matching transplantation method for patch transplantation, comprising the following steps:

[0032] (1) Apply the patches obtained from the preliminary migration (which can be obtained by existing automated migration tools or manual migration) to the target code base.

[0033] (2) Compile the updated target code library to obtain compilation diagnostic information.

[0034] (3) Based on the compilation diagnostic information, check whether there are compilation errors whose root cause is the non-existence of identifiers. Specifically, traverse each compilation diagnostic information and determine whether its type belongs to the predefined set of error types for which the corresponding identifier does not exist (such as function does not exist, variable does not exist, etc.).

[0035] (4) If there is a compilation error whose root cause is that the identifier does not exist, the non-existent identifiers are repaired one by one to obtain an optimized patch, which specifically includes the following sub-steps:

[0036] (4.1) For each compilation error whose root cause is the non-existent identifier, parse the compilation diagnostic information to obtain the non-existent identifier, that is, the identifier used in the source patch but not in the target code library (referred to as the source identifier for short), such as the macro ALLOC_ONE.

[0037] (4.2) Search the source code library to obtain and extract all functions involving the use of the identifier (referred to as source use functions for short). In the present invention, this is specifically implemented through GNU Global (a source code marking system).

[0038] (4.3) For each source usage function, traverse the target code base to obtain the target usage function with the highest degree of similarity. Similarity measurement includes textual similarity based on code strings and code semantic similarity. Specifically, first, the n most similar target usage functions are screened out based on the textual similarity of the code strings. Textual similarity is the sum of the similarities of the function name, function header, and function body (textual similarity is measured by edit distance). For the n most similar target usage functions obtained by screening, a large language model is used to determine whether they are semantically consistent with the source usage function.

[0039] (4.4) For all obtained function pairs, first, filter out function pairs with function name and function body similarity below a threshold. This aims to make the function pairs used to demonstrate identifier transformation as similar as possible, thereby reducing the difficulty of understanding for the large language model. Secondly, sort the source function pairs from smallest to largest according to their length (number of lines of code). This aims to make the function pairs used to demonstrate identifier transformation as concise as possible (i.e., contain as little code as possible that is unrelated to the identifier's functionality), ensuring that the large language model focuses on the migration of the specified identifier. For the function pairs of identifier migration information, the source and target functions have similar logic, namely, first creating an ff_stack_T object and then initializing it using input parameters. Therefore, it is easy to infer that the function implemented by the source identifier ALLOC_ONE (allocating memory space for the input type and returning a pointer to that space) can be equivalently implemented in the target code using a combination of xmalloc and sizeof. Compared to matching directly by identifier definition, the indirect matching by identifier usage function in the present invention can reduce matching errors caused by major changes in identifier definitions (identifiers are often used in multiple places in the code base, and valid matches can be selected) and can handle complex migration situations involving structural changes.

[0040] (4.5) Take the top k function pairs obtained by sorting, and use them to demonstrate the equivalent implementation of the functions implemented by the code snippets containing the source identifiers in the target code base. Build prompts based on the top k function pairs to guide the large language model to transplant the identifiers that do not exist in the input patch according to the equivalent transformations demonstrated by the function pairs, so as to obtain the optimized patch. The prompt template specifically includes three parts: the first part tells the large language model how to understand the input function pairs, which is an example used to demonstrate identifier migration; the second part guides the large language model to replace the fragments involving the source identifier in the input patch according to the transformation demonstrated in the provided function pairs; the third part provides specific guidance to make the behavior of the large language model meet expectations (such as defining the output format).

[0041] (5) Conversely, all remaining compilation errors are fixed at the same time to obtain an optimized patch, which specifically includes the following sub-steps:

[0042] (5.1) For each compilation error, parse the compilation diagnostic information to extract the line where the error occurs, the identifier involved, and the diagnostic hint. Convert the original compiler diagnostic information (developer-friendly visual format) into a text format that is friendly to large language models.

[0043] (5.2) Fill the parsed information into the defined prompt template to guide the large language model to optimize the input patch to fix the compilation error. The prompt template is as follows Figure 3 As shown, it specifically includes three parts: the first part is the prompt template preamble, which tells the large language model that an error function to be repaired and the corresponding compiler diagnostic information will be given; the second part is the formatted compiler diagnostic information and the function to be repaired; the third part is the specific instructions that guide the large model to perform repairs based on the compiler diagnostic information.

[0044] (6) Re-execute (1) using the optimized patch to enter a new round of iterations, and iterate until there are no compilation errors in step (2) or the number of iterations exceeds the set upper limit.

[0045] Example 1

[0046] The proposed implicit global information matching and transplantation method for patch transplantation is evaluated in two ways: 1) compared with existing baseline schemes in two patch transplantation scenarios: cross-project and cross-version within a project; 2) the robustness of the proposed method to different large language models is verified.

[0047] The following describes the specific implementation and settings of this method, as well as the specific experimental method and settings for comparison with the baseline solution and exploration of robustness.

[0048] This method's implementation and settings: Llama 3.1-70b is used as the large language model component of this method, with the temperature coefficient set to 0. GCC is used as the compiler component of this method, and the output format of diagnostic information is set to JSON. In this method, browsing the code base to obtain the definitions and uses of specified identifiers is implemented using GNU Global (a source code tagging system). The static analysis functionality of this method is implemented using TreeSitter. The maximum number of iterations of this method is set to 5.

[0049] Performance comparison with the baseline solution: The performance is evaluated using the number and proportion of correctly transplanted patches. Correctly transplanted patches mean that the transplanted patches generated by the solution are semantically consistent with the labeled data. Specifically, due to the lack of an automated method to accurately determine whether two patches are completely semantically consistent, a manual evaluation is performed, with two experts performing the following steps: 1) Check the compilation errors caused by the patches before and after the application of the solution to ensure that the original compilation errors are eliminated and no new compilation errors are introduced. 2) Verify the semantic consistency of the repair and the labeled data. 3) Check that there are no changes unrelated to the repair. After the two experts independently conduct the above evaluation, they discuss any differences to obtain the final evaluation results.

[0050] Table 1 shows the comparison between the present invention and the baseline solution. The performance in the cross-project migration scenario is evaluated by taking the patch migration between Vim and Neovim as an example, and the performance in the same-project cross-version migration scenario is evaluated by taking the patch migration between the main version and the old version of Linux as an example. It includes two baseline solutions: 1) Repair based on the repair suggestions given by the compiler diagnostic information, 2) Repair based on the compiler diagnostic information using a large language model (Llama3.1-70b, which is the same as the default implementation of the present invention, was selected in the experiment). The experimental results show that the present invention can achieve an accuracy rate of 81.3% and 72.7% in the cross-project and cross-version migration scenarios, which are both improved by more than 100% compared to the optimal baseline model. This shows the effectiveness of the present invention in automatically repairing implicit global information changes in patch transplantation.

[0051] Table 1: Performance comparison between the proposed method and the baseline solution

[0052]

[0053] Table 2 demonstrates the robustness of our approach using different large language models, using patch migration between Vim and Neovim as the test dataset. The performance is compared using Llama 3.1-70b (the default setting of our approach), GPT-4o, and DeepSeek-v3. The experimental results show slight performance improvements using GPT-4o and DeepSeek-v3, demonstrating that our approach is robust to different large language models, and that using a more powerful large language model may offer some performance improvements.

[0054] Table 2: Robustness of the present invention using different large language models

[0055] method Correct quantity Correct proportions This method-Llama 52 / 64 81.30% This method - GPT 54 / 64 84.40% This method - DeepSeek 55 / 64 85.90%

[0056] The present invention also provides an electronic device, comprising a memory and a processor, wherein the memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the implicit global information matching transplantation method for patch transplantation.

[0057] The present invention also provides a computer-readable storage medium storing a computer program, wherein the program, when executed by a processor, implements the implicit global information matching transplantation method for patch transplantation.

[0058] The computer-readable storage medium may be an internal storage unit of any device with data processing capabilities described in any of the aforementioned embodiments, such as a hard disk or memory. The computer-readable storage medium may also be any device with data processing capabilities, such as a plug-in hard disk, a smart media card (SMC), an SD card, a flash card, etc. equipped on the device. Furthermore, the computer-readable storage medium may also include both an internal storage unit of any device with data processing capabilities and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capabilities, and may also be used to temporarily store data that has been output or is to be output.

[0059] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not limiting. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the purpose and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.

Claims

1. An implicit global information matching transplantation method for patch transplantation, characterized in that: The steps include: (1) Apply the patches obtained from the initial migration to the target code base; (2) compile the updated target code library to obtain compilation diagnostic information; (3) Based on the compilation diagnostic information, check whether there is a compilation error whose root cause is that the identifier does not exist; (4) If there is a compilation error whose root cause is that the identifier does not exist, then the non-existent identifier is repaired to obtain an optimized patch; (5) If there is no compilation error whose root cause is the non-existence of the identifier, all remaining compilation errors are fixed at the same time to obtain an optimized patch; (6) Re-execute step (1) using the optimized patch to enter a new round of iteration until no compilation error information can be diagnosed in step (2) or the number of iterations exceeds the set upper limit.

2. The implicit global information matching transplantation method for patch transplantation according to claim 1, characterized in that: The step (4) is specifically as follows: If there is a compilation error whose root cause is that the identifier does not exist, for the compilation error whose root cause is that the identifier does not exist, obtain a source code snippet involving the use of the source identifier in the source code library, and obtain a target code snippet corresponding to the source code snippet in the target code library. The source code snippet and the corresponding target code snippet form a code snippet pair. Through the code snippet pair, obtain matching information of the source identifier in the target code library and perform transplantation using a large language model.

3. The implicit global information matching transplantation method for patch transplantation according to claim 1, characterized in that: The step (5) is specifically as follows: If there is no compilation error whose root cause is the non-existence of an identifier, for each compilation error, parse the compilation diagnostic information to extract the error line, the identifier involved, and the diagnostic prompt; The parsed information is filled into the defined prompt template to guide the large language model to optimize the input function to fix compilation errors.

4. The implicit global information matching transplantation method for patch transplantation according to claim 3, characterized in that: The prompt template includes a preamble for informing the large language model that an erroneous function to be repaired and corresponding compiler diagnostic information will be provided, formatted compiler diagnostic information and the function to be repaired, and instructions for guiding the large model to perform repairs based on the compiler diagnostic information.

5. An electronic device comprising a memory and a processor, characterized in that: The memory is coupled to the processor; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the implicit global information matching transplantation method for patch transplantation according to any one of claims 1-4.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the implicit global information matching transplantation method for patch transplantation according to any one of claims 1 to 4 is implemented.