Invalid code cleaning method and device, electronic equipment, storage medium and program product

By using a large language model and invalid code cleanup prompts, invalid code in the code repository is automatically identified and removed, solving the problems of code complexity and development efficiency, and improving the accuracy and efficiency of code development and maintenance.

CN120973408APending Publication Date: 2025-11-18BEIJING YOUZHUJU NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511072119.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-31
Publication Date
2025-11-18

AI Technical Summary

Technical Problem

Invalid code accumulated in the code repository increases code complexity and reduces development efficiency. Traditional methods struggle to detect logic code associated with the full whitelist variables and control test variables.

Method used

By using a large language model and invalid code cleanup prompts, the system automatically scans code files, identifies and removes invalid code associated with variables released in full, including logic code associated with variables in the full whitelist and control test variables.

Benefits of technology

It has enabled automated cleanup of code repositories, improved the accuracy and efficiency of code development and maintenance, simplified the development process, and enhanced code readability and maintainability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120973408A_ABST
    Figure CN120973408A_ABST
Patent Text Reader

Abstract

The invention provides an invalid code cleaning method, which comprises the following steps of: scanning a submitted code file to be merged, and determining a target variable which is completely released and is contained in the code file to be merged; traversing code files in the selected code warehouse, and determining a target code file containing the target variable; and rewriting the target code file to obtain an updated code file in which invalid codes associated with the target variable are removed. The invention further provides an invalid code cleaning device, electronic equipment, a computer readable storage medium and a computer program product.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to methods, apparatus, electronic devices, storage media, and program products for invalid code removal. Background Technology

[0002] Code repositories often accumulate unused or redundant code. This not only increases code complexity but also causes unnecessary confusion for developers, ultimately reducing development efficiency. Therefore, a comprehensive cleanup and removal of invalid code is necessary to clear obstacles for subsequent development and maintenance. It's understandable that cleaning up useless logic significantly reduces the difficulty for developers to get started with a project. Developers no longer need to spend a lot of time understanding and interpreting outdated or unnecessary code, allowing them to integrate into project development more quickly and improving overall development efficiency. At the same time, a clean code structure clearly demonstrates code functionality, reduces redundancy and obfuscation, and greatly improves code readability and maintainability. Summary of the Invention

[0003] In view of this, embodiments of the present disclosure provide an invalid code cleanup method, apparatus, electronic device, storage medium, and program product, which can solve or partially solve the above-mentioned problems to a certain extent.

[0004] In some embodiments of this disclosure, the invalid code cleanup method described in this disclosure may include: scanning a submitted code file to be merged to determine a target variable that has been fully released and contained in the code file to be merged; traversing the code files in a selected code repository to determine a target code file containing the target variable; and rewriting the target code file to obtain an updated code file that removes invalid code associated with the target variable.

[0005] In some embodiments of this disclosure, the step of scanning the submitted code file to be merged and determining the target variables that have been fully released contained in the code file to be merged includes: obtaining a list of variables that have been fully released; scanning the code file to be merged and determining the candidate variables contained in the code file to be merged; and matching the candidate variables with the variables in the list of variables that have been fully released to determine the target variables that have been fully released contained in the code file to be merged.

[0006] In some embodiments of this disclosure, the step of traversing the code files in the selected code repository to determine the target code file containing the target variable includes: cloning the selected code repository to obtain a code repository copy; creating a remote branch; switching to the remote branch; extracting candidate code files from the code repository copy, and matching the variables in the candidate code files with the target variable; in response to determining that the candidate code file contains the target variable, determining the candidate code file as the target code file, and returning to the step of extracting candidate code files from the code repository copy until all candidate code files in the code repository copy have been traversed; in response to determining that the candidate code file does not contain the target variable, returning to the step of extracting candidate code files from the code repository copy until all candidate code files in the code repository copy have been traversed; and after obtaining the updated code file, the method further includes: deleting the code repository copy.

[0007] In some embodiments of this disclosure, rewriting the target code file to obtain an updated code file that removes invalid code associated with the target variable includes: generating invalid code cleanup prompts based on the target variable, the target code file, and a pre-determined invalid code cleanup prompt template; and inputting the invalid code cleanup prompts into a large language model, which then rewrites the target code file to remove invalid code associated with the target variable, thereby obtaining the updated code file.

[0008] In some embodiments of this disclosure, the above-described invalid code cleanup method further includes: obtaining code file samples from a sample dataset; wherein the code file samples are code files containing variables that have been fully released; generating invalid code cleanup sample prompts based on the code file samples and the invalid code cleanup prompt template; inputting the invalid code cleanup sample prompts into the large language model, whereby the large language model rewrites the code file samples to remove invalid code associated with the variables that have been fully released, resulting in updated code file samples; evaluating the updated code file samples to determine whether they are bad samples; in response to determining that the updated code file samples are bad samples, generating optimization prompts based on the bad samples and the prompt optimization template; and inputting the optimization prompts into the prompt optimization model to optimize the invalid code cleanup prompt template, and returning to the step of obtaining code file samples from the sample dataset, until the updated code file samples output by the large language model meet the preset conditions.

[0009] In some embodiments of this disclosure, the above-described invalid code cleanup method further includes: generating a merge request based on the updated code file; and merging the updated code file into a pre-production environment based on the merge request.

[0010] In some embodiments of this disclosure, before merging the updated code file into the pre-production environment based on the merge request, the method further includes: obtaining a developer identifier corresponding to the target variable; submitting the updated code file to the developer for review based on the developer identifier; and, in response to determining that a review approval response has been received, performing the step of merging the updated code file into the pre-production environment based on the merge request.

[0011] In some embodiments of this disclosure, the fully published variable list includes: a full whitelist of variables and / or a fully published control test variable.

[0012] In some embodiments of this disclosure, the above-mentioned invalid code cleanup method further includes: generating code file optimization prompts based on the updated code file and a pre-determined code file optimization prompt template; and inputting the code file optimization prompts into the large language model, whereby the large language model rewrites the updated code file to clean up dead code contained in the updated code file.

[0013] Corresponding to the above-described invalid code cleanup method, embodiments of this disclosure also provide an invalid code cleanup apparatus, comprising:

[0014] The target variable determination module is used to scan the submitted code files to be merged and determine the target variables that have been fully released and contained in the code files to be merged.

[0015] The target code file determination module is used to traverse the code files in the selected code repository and determine the target code file containing the target variable; and

[0016] The rewriting module is used to rewrite the target code file to obtain an updated code file that removes invalid code associated with the target variable.

[0017] Furthermore, embodiments of this disclosure also provide an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described invalid code cleanup method.

[0018] Embodiments of this disclosure also provide a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the above-described invalid code cleanup method.

[0019] Embodiments of this disclosure also provide a computer program product, including computer program instructions that, when executed on a computer, cause the computer to perform the above-described invalid code cleanup method.

[0020] Therefore, in the aforementioned invalid code cleanup methods, devices, electronic devices, storage media, and program products, the fully released target variables contained in the user-submitted code files to be merged can be identified first. Further, target code files containing the fully released target variables are searched in the code repository. Finally, the target code files are rewritten to remove invalid code associated with the fully released target variables. This method allows for automatic and comprehensive cleanup of the code repository, removing invalid code and clearing obstacles for subsequent development and maintenance work, thus improving the accuracy and efficiency of code development and maintenance. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in this disclosure or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are only embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 A schematic diagram of an exemplary system provided by some embodiments of the present disclosure is shown.

[0023] Figure 2 The implementation flow of the invalid code cleanup method described in some embodiments of this disclosure is shown.

[0024] Figure 3 The implementation flow of a method for scanning submitted code files to be merged, as described in some embodiments of this disclosure, is shown.

[0025] Figure 4 The implementation flow of the method for determining a target code file containing a fully published target variable, as described in some embodiments of this disclosure, is shown.

[0026] Figure 5 The present disclosure illustrates the implementation flow of a method for rewriting a target code file to obtain an updated code file that removes invalid code associated with a target variable that has been fully released, as described in some embodiments of the present disclosure.

[0027] Figure 6 The implementation flow of the method for optimizing invalid code cleanup prompt word templates as described in some embodiments of this disclosure is shown.

[0028] Figure 7 The internal structure of the invalid code cleanup apparatus described in some embodiments of this disclosure.

[0029] Figure 8 A schematic diagram of a more specific electronic device hardware structure described in some embodiments of this disclosure is shown. Detailed Implementation

[0030] To make the objectives, technical solutions, and advantages of this disclosure clearer, the following detailed description is provided in conjunction with specific embodiments and the accompanying drawings.

[0031] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this disclosure should have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms "first," "second," and similar terms used in the embodiments of this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0032] It is understood that before using the technical solutions of the various embodiments in this disclosure, users will be informed of the type, scope of use, and usage scenarios of the personal information involved in an appropriate manner, and user authorization will be obtained.

[0033] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose, based on the prompt message, whether to provide personal information to the software or hardware such as electronic devices, applications, servers, or storage media performing the operations of this disclosed technical solution.

[0034] As an optional but not limited implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0035] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.

[0036] The term "in response to" as used herein refers to a state in which a corresponding event occurs or a condition is satisfied. It will be understood that the timing of subsequent actions performed in response to such event or condition is not necessarily strongly correlated with the time when the event occurs or the condition is met. For example, in some cases, subsequent actions may be performed immediately upon the occurrence of the event or the fulfillment of the condition; while in others, they may be performed some time after the occurrence of the event or the fulfillment of the condition.

[0037] As mentioned earlier, code repositories often accumulate unused or redundant code. This invalid code not only increases code complexity but also causes unnecessary trouble for developers and reduces development efficiency. Traditional code cleanup techniques typically operate during the build phase, using dependency analysis to detect useless files or dead code that cannot be executed. However, this approach often fails to detect logical branches that will never be reached at runtime through conditional statements, such as logic associated with all whitelisted variables or logic associated with all test variables that have already been fully defined. Moreover, these situations are prevalent in business logic code.

[0038] In view of this, embodiments of the present disclosure provide an invalid code cleanup method, apparatus, electronic device, storage medium, and program product that can automatically and comprehensively clean up and remove invalid code from a code repository, thereby clearing obstacles for subsequent development and maintenance work and improving the accuracy and efficiency of code development and maintenance.

[0039] For clarity, before describing the specific technical solutions of the embodiments of this disclosure, the technical terms involved in the embodiments of this disclosure will be explained first.

[0040] A code repository can refer to the core infrastructure in software development. Essentially, a code repository is a system or directory that centrally stores and manages all code files, historical change records, configuration documents, and other related resources (such as images and configuration files) for a project.

[0041] Invalid code in a program refers to code segments that will never be executed or whose execution results are meaningless; essentially, it's redundant. Generally, invalid code can include dead code, code associated with a full whitelist variable, or code associated with a fully published control test variable. Dead code typically refers to code segments that will never be executed. A full whitelist can be a "trust list" pattern in a security policy that covers all objects (e.g., all IP addresses, users, applications, etc.). A control test variable refers to a specific condition or value used in an experiment to form a benchmark; its core function is to provide a comparison standard to evaluate the experimental effect. It can be understood that fully publishing a control test variable (also known as pushing it to the maximum) will cause some logic code associated with the control test variable to become invalid. It can be seen that whether it's a whitelist variable or a control test variable, fully publishing it (or pushing it to the maximum) may cause some judgment conditions in the code to consistently fail, thus making the logic branch corresponding to that condition a part of the code that will never be executed—that is, invalid code.

[0042] Controlled testing is a scientific experimental method that involves comparing a control group and an experimental group. It can also be called a controlled experiment or an A / B test.

[0043] A Merge Request (MR) is a request initiated by a developer to the project maintainers or other members after making changes to a branch of code. The purpose is to merge these changes into the main branch or other target branch of the project. MR is a core process for code collaboration and version control in modern software development.

[0044] A Large Language Model (LLM) is a neural network model based on deep learning, trained on massive amounts of text data, and capable of understanding, generating, and reasoning about natural language.

[0045] A prompt can be an injected instruction used to "direct" a large model to think about problems and output content according to a preset approach and method. A prompt can be an instruction or message that guides or triggers a response from the large model.

[0046] Git can be a distributed version control system, primarily used to solve version management problems in collaborative code development.

[0047] An Open Application Programming Interface (OpenAPI) can be a specification for defining and describing APIs, aiming to document APIs in a standardized way to make them easier to understand and use.

[0048] Remote Procedure Call (RPC) is a technology that allows a computer program to call a program or function on a remote computer over a network, enabling distributed computing across nodes or servers.

[0049] Figure 1 A schematic diagram of an exemplary system 100 provided in an embodiment of this disclosure is shown.

[0050] like Figure 1 As shown, system 100 may include terminal device 102, terminal device 104, server 106, and code repository 108. Communication links (e.g., a network) may be provided between terminal device 102, terminal device 104 and server 106, and between server 106 and code repository 108. The network may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0051] For example, terminal devices 102 and 104 may have applications or software capable of code development installed on them. Terminal devices 102 and 104 can be hardware or software. When terminal devices 102 and 104 are hardware, they can be various electronic devices with displays, including but not limited to smartphones, tablets, laptops, and desktop computers (PCs). When terminal devices 102 and 104 are software, they can be installed on the aforementioned electronic devices. They can be implemented as multiple software programs or software modules (e.g., to provide distributed services) or as a single software program or software module. No specific limitations are imposed here.

[0052] Server 106 can be a server for a code development platform, such as a backend server providing support for applications or software on terminal devices 102 and 104. Server 106 can be either hardware or software. When server 106 is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When server 106 is software, it can be implemented as multiple software programs or software modules (e.g., used to provide distributed services), or as a single software program or software module. No specific limitations are made here.

[0053] Code repository 108 is primarily used for centralized storage and management of all project code files. Server 106 can read code files from code repository 108, and can also write generated code files to code repository 108.

[0054] It should be understood that Figure 1 The number of terminal devices, users, servers, and code repositories shown is merely illustrative. Depending on implementation needs, there can be any number of terminal devices, users, servers, and code repositories.

[0055] As an example scenario, server 106 can provide code development services. User 112 can use the application on terminal device 102 to submit code files to be merged to server 106. Server 106 cleans up invalid code in the code repository based on the code files submitted by user 112 through terminal device 102. Then, server 106 can use terminal device 104 to send the updated code files after invalid code cleanup back to user 114 for further review, thereby further ensuring the accuracy of the updated code files after invalid code cleanup.

[0056] Based on the aforementioned system 100, in order to solve the problems in the invalid code cleanup process, this disclosure provides an invalid code cleanup method. The invalid code cleanup method provided by this disclosure will be described below with reference to specific embodiments and accompanying drawings.

[0057] Figure 2 The implementation flow of the invalid code cleanup method described in this disclosure embodiment is illustrated. For example... Figure 2 As shown, the invalid code cleanup method described in this embodiment can typically be executed by the server 106, and may specifically include the following steps.

[0058] In step 210, the submitted code files to be merged are scanned to determine the target variables that have been fully released and contained in the code files to be merged.

[0059] In step 220, the code files in the selected code repository are traversed to determine the target code file containing the target variable.

[0060] In step 230, the target code file is rewritten to obtain an updated code file that removes invalid code associated with the target variable.

[0061] Therefore, the above-described invalid code cleanup method first identifies the fully released target variables contained in the user-submitted code files to be merged. Next, it searches the code repository for target code files containing these fully released target variables. Finally, it rewrites the target code files to remove invalid code associated with the fully released target variables. This method allows for automatic and comprehensive cleanup of the code repository, removing invalid code and clearing obstacles for subsequent development and maintenance, thus improving the accuracy and efficiency of code development and maintenance.

[0062] The steps of the invalid code cleanup method described in this disclosure will be explained in detail below with reference to specific examples and accompanying drawings.

[0063] Regarding step 210 above, in the embodiments of this disclosure, the specific method for scanning the submitted code files to be merged can be as follows: Figure 3 As shown, it includes the following steps.

[0064] In step 310, obtain the list of variables that have been fully published.

[0065] In embodiments of this disclosure, the aforementioned fully published variable list may include: a fully whitelisted variable list and / or a fully published control test variable list, etc.

[0066] Specifically, the aforementioned full whitelist variable list can be obtained through the open application programming interface provided by the whitelist platform or through RPC. The aforementioned full whitelist variable list may include variables included in the fully published whitelist, and in the embodiments of this disclosure, it may also be referred to as the full whitelist variable (Whitelist Key).

[0067] Specifically, the list of fully released control test variables mentioned above can be obtained through the open application programming interface provided by the control test platform or via RPC. This list of fully released control test variables may include all fully released control test variables, also known as fully released A / B test variables.

[0068] In step 320, the code files to be merged are scanned to identify the candidate variables contained in the code files to be merged.

[0069] In the embodiments of this disclosure, the scanning process of the above-mentioned code files can be implemented through the code scanning and analysis function provided by the code development platform, which will not be described in detail here.

[0070] In step 330, the candidate variables are matched with the fully published variables in the list of fully published variables to determine the target variables that have been fully published and are contained in the code file to be merged.

[0071] Therefore, code scanning can quickly and accurately identify target variables that have been fully released in the code files to be merged, including fully whitelisted variables or fully released control test variables.

[0072] Regarding step 220 above, in the embodiments of this disclosure, the specific method for traversing the code files in the selected code repository to determine the target code file containing the target variable can be as follows: Figure 4 As shown, it includes the following steps.

[0073] In step 410, the selected code repository is cloned to obtain a copy of the code repository.

[0074] In step 420, a remote branch is created.

[0075] In step 430, switch to the remote branch.

[0076] It is understandable that, in order to achieve secure and efficient code collaboration and version management, operations such as cloning code repositories, creating remote branches, and switching to existing remote branches can avoid directly modifying the main branch in the code repository, achieving code isolation during multi-user collaboration and supporting parallel development of different features or bug fixes. Furthermore, remote branches can retain a complete commit history, facilitating the tracking of changes and the rollback of erroneous commits. In some embodiments of this disclosure, the aforementioned operations such as cloning code repositories, creating remote branches, and switching to existing remote branches can all be implemented by calling the open application programming interface provided by a distributed version control system (such as Git) or directly through Git operations, which will not be elaborated upon here.

[0077] In some embodiments of this disclosure, the code repository selected above can typically be the code repository involved in the code files to be merged or a code repository selected by other developers.

[0078] In step 440, candidate code files are extracted from the code repository copy, and the variables in the candidate code files are matched with the target variables.

[0079] In step 450, it is determined whether the candidate code file contains the target variable.

[0080] If it is determined that a candidate code file contains the target variable, proceed to step 460; if it is determined that a candidate code file does not contain the target variable, return to step 440, until all candidate code files in the code repository copy have been traversed.

[0081] In step 460, the candidate code file is determined to be the target code file. Then return to step 440 until all candidate code files in the code repository copy have been traversed.

[0082] As can be seen, the above method can be used to find code files containing the target variables in the selected code repository, which can then be used as the target code files for subsequent code rewriting. Furthermore, it can be understood that by cloning the code repository, creating remote branches, and switching to existing remote branches, direct modification of the main branch in the code repository can be avoided, achieving code isolation during multi-user collaboration and supporting parallel development of different features or bug fixes.

[0083] Regarding step 230 above, in some embodiments, the target code file is rewritten to obtain an updated code file that removes invalid code associated with the target variable, as shown below. Figure 5 As shown, it includes the following steps.

[0084] In step 510, invalid code cleanup prompts are generated based on the target variable, the target code file, and a pre-determined invalid code cleanup prompt template.

[0085] In step 520, invalid code cleanup prompts are input into the large language model, which then rewrites the target code file to remove invalid code associated with the target variable, resulting in an updated code file.

[0086] In the embodiments of this disclosure, the aforementioned pre-determined invalid code cleanup prompt template may include: a role description section, an input data description section, a processing logic description section, an output requirement section, and a special instruction section. The role description section informs the large language model of its role in performing the invalid code cleanup task. For example, it tells the large language model that it acts as a code optimization assistant, responsible for logically optimizing the target code file based on the provided, fully released target variables. The input data description section mainly provides the large language model with the target code file and the fully released target variables. The processing logic description section mainly informs the large language model of the main operational steps used to logically optimize the target code file. The output requirement section mainly informs the large language model of the specific requirements for the output. The special instruction section mainly reminds the large language model of one or more matters that need attention during the processing. It can be seen that the aforementioned invalid code cleanup prompt template basically determines the basic content of the prompt. Except for the input data description section, all other parts are fixed. Therefore, in step 510, simply filling the target variables and the target code file into the input data description section of the invalid code cleanup prompt template is sufficient to obtain the aforementioned invalid code cleanup prompt.

[0087] It should be noted that benchmark tests have shown that prompt words can significantly affect the format and accuracy of the output results of large language models. Therefore, in order to improve the accuracy of invalid code cleanup, some embodiments of this disclosure further provide a method for optimizing the invalid code cleanup prompt word template. Figure 6 The implementation flow of the method for optimizing invalid code cleanup prompt word templates as described in some embodiments of this disclosure is shown. For example... Figure 6 As shown, the specific method for optimizing the invalid code cleanup prompt template includes the following steps.

[0088] In step 610, obtain the code file samples from the sample dataset.

[0089] In embodiments of this disclosure, the aforementioned sample dataset can be a pre-constructed dataset containing samples of code files that have been fully published. That is, the aforementioned code file samples can be code files associated with the fully published variables.

[0090] In step 620, invalid code cleanup sample prompts are generated based on the code file sample and the invalid code cleanup prompt template.

[0091] The specific implementation of step 620 above can be referred to step 510 above, and will not be repeated here.

[0092] In step 630, the invalid code cleanup sample prompts are input into the large language model, which rewrites the code file sample to remove invalid code associated with variables that have been fully released, resulting in an updated code file sample.

[0093] In step 640, the updated code file sample is evaluated to determine whether the updated code file sample is a bad sample.

[0094] In some embodiments of this disclosure, the accuracy of an updated code file sample can be used to determine whether it is a bad sample. Accuracy measures whether the execution logic of the modified code is consistent with the original logic; consistency indicates accuracy, while inconsistency indicates inaccuracy. Typically, in embodiments of this disclosure, a bad sample refers to an updated code file sample determined to have been modified inaccurately (the execution logic of the modified code is inconsistent with the original logic).

[0095] In other embodiments of this disclosure, whether an updated code file sample is a bad sample can also be determined from two dimensions: accuracy and validity. Validity measures whether the modified code has removed invalid code; if invalid code has been removed, it is considered valid, and if not, it is considered invalid. Typically, in embodiments of this disclosure, the aforementioned bad sample can refer to an updated code file sample that is determined to have been modified inaccurately (the execution logic of the modified code is inconsistent with the original logic) or invalidally (invalid code has not been removed).

[0096] In step 650, in response to determining that the updated code file sample is a bad sample, optimization prompts are generated based on the bad sample and the prompt optimization template.

[0097] Similar to the invalid code cleanup prompt template described above, in the embodiments of this disclosure, the prompt optimization template may also include: a role description section, an input data description section, a processing logic description section, an output requirement section, and a special instruction section. The role description section informs the large language model of its role in performing the prompt optimization task. For example, it tells the large language model that it acts as a prompt template optimization assistant, responsible for optimizing the invalid code cleanup prompt template based on bad samples from the provided updated code file. The input data description section mainly provides the large language model with bad samples from the updated code file. The processing logic description section mainly informs the large language model of the main operational steps used to optimize the invalid code cleanup prompt template. The output requirement section mainly informs the large language model of the specific requirements for the output. The special instruction section mainly reminds the large language model of one or more matters that need attention during the processing. As can be seen from this, the above prompt word optimization template basically determines the basic content of the prompt words. Except for the input data description part, all other parts have been solidified. Therefore, in the above step 650, it is only necessary to fill the bad sample into the input data description part of the invalid code cleanup prompt word template to obtain the above optimized prompt words.

[0098] In step 660, the optimization prompt words are input into the prompt word optimization model to optimize the invalid code cleanup prompt word template. Then, return to step 610 until the updated code file sample output by the above large language model meets the preset conditions.

[0099] In some embodiments of this disclosure, the aforementioned prompt word optimization model can be implemented using a large language model, primarily for optimizing invalid code cleanup prompt word templates. Thus, based on the optimized invalid code cleanup prompt word template, more efficient and accurate invalid code cleanup prompt words can be generated. After inputting such invalid code cleanup prompt words into the large language model, the updated code file output by the large language model can effectively remove invalid code while still maintaining high accuracy.

[0100] In some embodiments of this disclosure, the aforementioned preset conditions may include: the accuracy of the updated code file samples reaches a preset accuracy threshold. The accuracy of the updated code file samples can be defined as the proportion of correctly modified code file samples to the total number of modified code file samples.

[0101] In some other embodiments of this disclosure, the aforementioned preset conditions may include: the effectiveness rate of the updated code file samples reaches a preset effectiveness rate threshold. The effectiveness rate of the updated code file samples can be defined as the proportion of the number of valid modified code file samples to the total number of modified code file samples.

[0102] In some other embodiments of this disclosure, the preset conditions may include: the accuracy of the updated code file sample reaches a preset accuracy threshold and / or the effectiveness of the updated code file sample reaches a preset effectiveness threshold.

[0103] It is understandable that after optimizing the invalid code cleanup prompt template using the above-mentioned invalid code cleanup prompt template optimization method, an optimized invalid code cleanup prompt template will be obtained. Using the optimized invalid code cleanup prompt template to generate invalid code cleanup prompts will achieve a higher accuracy and / or efficiency in updating code file samples, that is, to achieve a higher invalid code cleanup accuracy and / or efficiency.

[0104] In embodiments of this disclosure, after obtaining an updated code file that removes invalid code associated with the fully released target variable, the above invalid code cleanup method may further include: submitting the updated code file and deleting the cloned code repository copy.

[0105] Furthermore, in the embodiments of this disclosure, after obtaining the updated code file containing invalid code associated with the fully released target variable, the aforementioned invalid code cleanup method may further include: generating a merge request based on the updated code file; and merging the updated code file into the pre-production environment based on the merge request. It is understood that after merging the updated code file into the pre-production environment, developers and testers can perform pre-deployment testing on the updated code file, thereby ensuring the efficiency and effectiveness of the updated code file's deployment.

[0106] To further improve the accuracy of updated code files, in the embodiments of this disclosure, before merging the updated code files into the pre-production environment based on the merge request, the above-mentioned invalid code cleanup method may further include: obtaining the developer identifier corresponding to the fully released target variables; submitting the updated code files to the developer for review based on the developer identifier; and, in response to confirming receipt of the review approval response, performing the step of merging the updated code files into the pre-production environment based on the merge request. In the embodiments of this disclosure, the developer identifier corresponding to the full whitelist target variables can be obtained through the open application programming interface provided by the whitelist platform. Typically, the aforementioned developer is the person in charge of maintaining the full whitelist target variables. Furthermore, in the embodiments of this disclosure, the developer identifier corresponding to the fully released control test variables can be obtained through the open application programming interface provided by the control test platform. Typically, the aforementioned developer is the person in charge of maintaining the fully released control test variables. Updated code files that have passed the review by the aforementioned person in charge will have a higher accuracy rate.

[0107] Furthermore, regarding the aforementioned dead code, some embodiments of this disclosure can further clean up dead code in the code file using a large language model. Specifically, after obtaining the updated code file, code file optimization prompts can be generated based on the updated code file and a pre-determined code file optimization prompt template; the generated code file optimization prompts are then input into the large language model, which rewrites the updated code file, cleans up the dead code contained in the updated code file, and further optimizes the updated code file.

[0108] Similar to the invalid code cleanup prompt template and prompt optimization template mentioned above, in the embodiments of this disclosure, the code file optimization prompt template may also include: a role description section, an input data description section, a processing logic description section, an output requirement section, and a special instruction section. The role description section informs the large language model of its role in performing code optimization tasks; for example, it tells the large language model that it acts as a code optimization assistant, responsible for optimizing the provided code file and removing dead code. The input data description section is mainly used to provide the large language model with updated code files. The processing logic description section is mainly used to inform the large language model of the main operational steps used to optimize the code file. The output requirement section is mainly used to inform the large language model of the specific requirements for the output. The special instruction section is mainly used to remind the large language model of one or more matters that need attention during the processing. It can be seen that the above code file optimization prompt template basically determines the basic content of the prompts; except for the input data description section, all other parts are fixed. Therefore, in the above steps, simply filling the updated code file into the input data description section of the code file optimization prompt template will yield the above code file optimization prompts.

[0109] As can be seen, the above methods can automatically clean up invalid code in code files in the code repository, making the modified code files more intuitive in displaying the code functions, reducing redundancy and confusion, and greatly improving the readability and maintainability of the code.

[0110] In some embodiments of this disclosure, the above-described invalid code cleanup method can be implemented based on an automated invalid code cleanup pipeline. This pipeline can include multiple atomic services. Specifically, the invalid code cleanup method can include at least one atomic service for code file scanning (corresponding to step 210) and one atomic service for invalid code removal (corresponding to steps 220 and 230). In practical applications, the invalid code cleanup pipeline is triggered when a code file to be merged is received from a developer, thereby sequentially executing the atomic service for code file scanning and the atomic service for invalid code removal. As can be seen, a pipeline approach can achieve fully automated invalid code cleanup without manual intervention, thus significantly reducing the cleanup and maintenance costs of the code repository.

[0111] Corresponding to the above-described invalid code cleanup method, some embodiments of this disclosure also disclose an invalid code cleanup device. Figure 7 The internal structure of the invalid code cleanup apparatus described in this disclosure embodiment is shown. For example... Figure 7 As shown, the above-mentioned invalid code cleanup device may include the following modules:

[0112] The target variable determination module 710 is used to scan the submitted code files to be merged and determine the target variables that have been fully released and contained in the code files to be merged.

[0113] Target code file determination module 720 is used to traverse the code files in the selected code repository and determine the target code file containing the target variable; and

[0114] The rewriting module 730 is used to rewrite the target code file to obtain an updated code file that removes invalid code associated with the target variable.

[0115] It should be noted that the implementation methods of each module in the above-mentioned invalid code cleanup device and the specific technical effects they can achieve can all refer to the implementation methods of each step in the foregoing embodiments, and will not be repeated here.

[0116] Therefore, it can be seen that the aforementioned invalid code cleanup device can first identify the fully released target variables contained in the user-submitted code files to be merged. Next, it searches the code repository for target code files containing the fully released target variables. Finally, it rewrites the target code files to remove invalid code associated with the fully released target variables. This method can automatically and comprehensively clean up the code repository, removing invalid code and thus clearing obstacles for subsequent development and maintenance work, improving the accuracy and efficiency of code development and maintenance.

[0117] Based on the same inventive concept, corresponding to the methods of any of the above embodiments, this disclosure also provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the invalid code cleanup method described in any of the above embodiments.

[0118] Figure 8 This embodiment illustrates a hardware structure diagram of a more specific electronic device, which may include: a processor 2010, a memory 2020, an input / output interface 2030, a communication interface 2040, and a bus 2050. The processor 2010, memory 2020, input / output interface 2030, and communication interface 2040 are interconnected internally via the bus 2050.

[0119] The processor 2010 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0120] The memory 2020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 2020 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program code is stored in the memory 2020 and is called and executed by the processor 2010.

[0121] The input / output interface 2030 is used to connect input / output devices to enable information input and output. These input / output devices can be configured as components within the device or externally connected to provide corresponding functions. Input devices may include microphones, various sensors, etc., while output devices may include displays, speakers, vibrators, indicator lights, etc.

[0122] The communication interface 2040 is used to connect a communication module (not shown in the figure) to enable communication between this device and other devices. The communication module can communicate via wired means (e.g., USB, Ethernet cable) or wireless means (e.g., mobile network, Wi-Fi, Bluetooth).

[0123] Bus 2050 includes a pathway for transmitting information between various components of the device, such as processor 2010, memory 2020, input / output interface 2030, and communication interface 2040.

[0124] It should be noted that although the above-described device only shows the processor 2010, memory 2020, input / output interface 2030, communication interface 2040, and bus 2050, in specific implementations, the device may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the above-described device may only include the components necessary for implementing the embodiments of this specification, and not necessarily all the components shown in the figures.

[0125] The electronic devices described above are used to implement the corresponding invalid code cleanup methods in any of the foregoing embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0126] Based on the same inventive concept, corresponding to the methods of any of the above embodiments, this disclosure also provides a non-transitory computer-readable storage medium that stores computer instructions for causing the computer to execute the invalid code cleanup method as described in any of the above embodiments.

[0127] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.

[0128] The computer instructions stored in the storage medium of the above embodiments are used to cause the computer to execute the invalid code cleanup method as described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0129] Based on the same inventive concept, corresponding to the invalid code cleanup method of any of the above embodiments, this disclosure also provides a computer program product, which includes computer program instructions. In some embodiments, when the computer program instructions are run on a computer, the computer performs each step of each embodiment of the invalid code cleanup method. Corresponding to the execution entity corresponding to each step in each embodiment of the invalid code cleanup method, the processor performing the corresponding step may belong to the corresponding execution entity.

[0130] The computer program product of the above embodiments is used to cause the processor to execute the invalid code cleanup method as described in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0131] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of this disclosure (including the claims) is limited to these examples; within the framework of this disclosure, the technical features of the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other variations of different aspects of the embodiments of this disclosure as described above, which are not provided in detail for the sake of brevity.

[0132] Additionally, to simplify the description and discussion, and to avoid obscuring the embodiments of this disclosure, the provided drawings may or may not show well-known power / ground connections to integrated circuit (IC) chips and other components. Furthermore, the apparatus may be shown in block diagram form to avoid obscuring the embodiments of this disclosure, and this also takes into account the fact that the details of implementation of these block diagram apparatuses are highly dependent on the platform on which the embodiments of this disclosure will be implemented (i.e., these details should be fully understood by those skilled in the art). While specific details (e.g., circuitry) have been set forth to describe exemplary embodiments of this disclosure, it will be apparent to those skilled in the art that the embodiments of this disclosure may be implemented without these specific details or with variations thereof. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0133] Although this disclosure has been described in conjunction with specific embodiments thereof, many substitutions, modifications, and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may be used with the embodiments discussed.

[0134] This disclosure is intended to cover all such substitutions, modifications, and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A method for cleaning up invalid code, comprising: The submitted code files to be merged are scanned to identify the target variables that have been fully released and contained in the code files to be merged. Iterate through the code files in the selected code repository to determine the target code file that contains the target variable; as well as The target code file is rewritten to obtain an updated code file that removes invalid code associated with the target variable.

2. The method according to claim 1, wherein, The step of scanning the submitted code files to be merged, and determining the target variables that have been fully released contained in the code files to be merged, includes: Get the list of variables that have been fully published; Scan the code files to be merged to identify candidate variables contained within them; and The candidate variables are matched with the variables in the fully published variable list to determine the target variables that have been fully published and are contained in the code file to be merged.

3. The method according to claim 1, wherein, The step of traversing the code files in the selected code repository to determine the target code file containing the target variable includes: Clone the selected code repository to obtain a copy of the code repository; Create a remote branch; Switch to the remote branch; Candidate code files are extracted from the code repository copy, and the variables in the candidate code files are matched with the target variable; In response to determining that the candidate code file contains the target variable, the candidate code file is determined as the target code file, and the step of extracting candidate code files from the code repository copy is returned until all candidate code files in the code repository copy have been traversed; In response to determining that the candidate code file does not contain the target variable, the step of extracting candidate code files from the code repository copy is returned until all candidate code files in the code repository copy have been traversed; and After obtaining the updated code file, the method further includes: Delete the copy of the code repository.

4. The method according to claim 1, wherein, The step of rewriting the target code file to obtain an updated code file that removes invalid code associated with the target variable includes: Generate invalid code cleanup prompts based on the target variable, the target code file, and a pre-determined invalid code cleanup prompt template; and The invalid code cleanup prompt is input into the large language model, which then rewrites the target code file to remove invalid code associated with the target variable, resulting in the updated code file.

5. The method of claim 4, further comprising: Obtain code file samples from the sample dataset; wherein, the code file samples are code files containing the variables that have been fully published; Generate invalid code cleanup sample prompts based on the code file sample and the invalid code cleanup prompt template; The invalid code cleanup sample prompts are input into the large language model, which then rewrites the code file sample to remove invalid code associated with variables that have been fully released, resulting in an updated code file sample. The updated code file sample is evaluated to determine whether it is a bad sample; In response to determining that the updated code file sample is a bad sample, optimization prompts are generated based on the bad sample and the prompt optimization template; and The optimization prompt words are input into the prompt word optimization model to optimize the invalid code cleanup prompt word template, and the process returns to the step of obtaining code file samples in the sample dataset until the updated code file samples output by the large language model meet the preset conditions.

6. The method of claim 1, further comprising: A merge request is generated based on the updated code file; as well as The updated code files are merged into the pre-production environment based on the merge request.

7. The method according to claim 6, wherein, Before merging the updated code file into the pre-production environment based on the merge request, the method further includes: Obtain the developer identifier corresponding to the target variable; Based on the developer identifier, the updated code file is submitted to the developer corresponding to the developer identifier for review; and In response to determining that an approval response has been received, the step of merging the updated code file into the pre-production environment based on the merge request is performed.

8. The method according to claim 2, wherein, The list of variables that have been fully published includes: all whitelisted variables and / or control test variables that have been fully published.

9. The method of claim 4, further comprising: Generate code file optimization prompts based on the updated code file and the pre-determined code file optimization prompt template; as well as The code file optimization suggestions are input into the large language model, which then rewrites the updated code file and cleans up any dead code contained therein.

10. An invalid code cleanup device, comprising: The target variable determination module is used to scan the submitted code files to be merged and determine the target variables that have been fully released and contained in the code files to be merged. The target code file determination module is used to traverse the code files in the selected code repository and determine the target code file containing the target variable. as well as The rewriting module is used to rewrite the target code file to obtain an updated code file that removes invalid code associated with the target variable.

11. An electronic device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the invalid code cleanup method as described in any one of claims 1-9.

12. A non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the invalid code cleanup method according to any one of claims 1-9.

13. A computer program product comprising computer program instructions that, when executed on a computer, cause the computer to perform the invalid code cleanup method as described in any one of claims 1-9.