Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3597503.3639103acmconferencesArticle/Chapter ViewAbstractPublication PagesicseConference Proceedingsconference-collections
research-article

Rust-lancet: Automated Ownership-Rule-Violation Fixing with Behavior Preservation

Published: 12 April 2024 Publication History

Abstract

As a relatively new programming language, Rust is designed to provide both memory safety and runtime performance. To achieve this goal, Rust conducts rigorous static checks against its safety rules during compilation, effectively eliminating memory safety issues that plague C/C++ programs. Although useful, the safety rules pose programming challenges to Rust programmers, since programmers can easily violate safety rules when coding in Rust, leading their code to be rejected by the Rust compiler, a fact underscored by a recent user study. There exists a desire to automate the process of fixing safety-rule violations to enhance Rust's programmability.
In this paper, we concentrate on Rust's ownership rules and develop rust-lancet to automatically fix their violations. We devise three strategies for altering code, each intended to modify a Rust program and make it pass Rust's compiler checks. Additionally, we introduce mental semantics to model the behaviors of Rust programs that cannot be compiled due to ownership-rule violations. We design an approach to verify whether modified programs preserve their original behaviors before patches are applied. We apply rust-lancet to 160 safety-rule violations from two sources, successfully fixing 102 violations under the optimal configuration --- more than rustc and six LLM-based techniques. Notably, rust-lancet avoids generating any incorrect patches, a distinction from all other baseline techniques. We also verify the effectiveness of each fixing strategy and behavior preservation validation and affirm the rationale behind these components.

References

[1]
2023. announcing-windows-11-insider-preview-build-25905. https://blogs.windows.com/windows-insider/2023/07/12/announcing-windows-11-insider-preview-build-25905/ Accessed: 2023-07-21.
[2]
2023. The crate quote. https://crates.io/crates/quote Accessed: 2023-03-26.
[3]
2023. The crate syn. https://crates.io/crates/syn Accessed: 2023-03-26.
[4]
2023. diff. https://www.gnu.org/software/diffutils/ Accessed: 2023-03-26.
[5]
2023. Mental Semantic Details. https://sites.google.com/view/rust-lancet/index Accessed: 2023-07-31.
[6]
2023. OpenAI. https://openai.com/ Accessed: 2023-03-26.
[7]
2023. Reborrow in Rust. https://github.com/rust-lang/reference/issues/788 Accessed: 2023-03-26.
[8]
2023. rustfmt. https://github.com/rust-lang/rustfmt Accessed: 2023-03-26.
[9]
2024. Rustc. https://github.com/rust-lang/rust/tree/master/tests Accessed: 2024-01-22.
[10]
Parastoo Abtahi and Griffin Dietz. 2020. Learning Rust: How Experienced Programmers Leverage Resources to Learn a New Programming Language. In Extended Abstracts of the 2020 CHI Conference on Human Factors in Computing Systems (CHI EA '20). Honolulu, HI.
[11]
Toufique Ahmed, Noah Rose Ledesma, and Premkumar T. Devanbu. 2021. SYN-FIX: Automatically Fixing Syntax Errors using Compiler Diagnostics. CoRR abs/2104.14671 (2021). arXiv:2104.14671 https://arxiv.org/abs/2104.14671
[12]
Umair Z. Ahmed, Zhiyu Fan, Jooyong Yi, Omar I. Al-Bataineh, and Abhik Roychoudhury. 2022. Verifix: Verified Repair of Programming Assignments. ACM Transactions on Software Engineering and Methodology. 31, 4 (2022), 74:1--74:31.
[13]
Umair Z. Ahmed, Pawan Kumar, Amey Karkare, Purushottam Kar, and Sumit Gulwani. 2018. Compilation error repair: for the student programs, from the student programs. In Proceedings of the 40th International Conference on Software Engineering: Software Engineering Education and Training (ICSE'2018 SEET), Gothenburg, Sweden.
[14]
Umair Z. Ahmed, Renuka Sindhgatta, Nisheeth Srivastava, and Amey Karkare. 2019. Targeted Example Generation for Compilation Errors. In 34th IEEE/ACM International Conference on Automated Software Engineering (ASE'2019), San Diego, CA, USA.
[15]
Matt Asay. 2020. Why AWS loves Rust, and how we'd like to help. https://aws.amazon.com/blogs/opensource/why-aws-loves-rust-and-how-wed-like-to-help/
[16]
Sahil Bhatia and Rishabh Singh. 2016. Automated Correction for Syntax Errors in Programming Assignments using Recurrent Neural Networks. CoRR abs/1603.06129 (2016). arXiv:1603.06129 http://arxiv.org/abs/1603.06129
[17]
Darshak Chhatbar, Umair Z. Ahmed, and Purushottam Kar. 2020. MACER: A Modular Framework for Accelerated Compilation Error Repair. In Proceedings of the 21st International Conference on Artificial Intelligence in Education (AIED'2020), Ifrane, Morocco (Lecture Notes in Computer Science, Vol. 12163).
[18]
Reudismam Rolim de Sousa, Gustavo Soares, Rohit Gheyi, Titus Barik, and Loris D'Antoni. 2021. Learning Quick Fixes from Code Repositories. In Proceedings of the 35th Brazilian Symposium on Software Engineering (SBES'2021), Joinville, Santa Catarina, Brazil.
[19]
Mehmet Emre, Ryan Schroeder, Kyle Dewey, and Ben Hardekopf. 2021. Translating C to safer Rust. Proceedings of the ACM on Programming Languages 5, OOPSLA (2021), 1--29.
[20]
Rahul Gupta, Soham Pal, Aditya Kanade, and Shirish K. Shevade. 2017. DeepFix: Fixing Common C Language Errors by Deep Learning. In Proceedings of the 31st AAAI Conference on Artificial Intelligence (AAAI'2017), San Francisco, California, USA. http://aaai.org/ocs/index.php/AAAI/AAAI17/paper/view/14603
[21]
Foyzul Hassan and Xiaoyin Wang. 2018. HireBuild: an automatic approach to history-driven repair of build scripts. In Proceedings of the 40th International Conference on Software Engineering (ICSE'2018), Gothenburg, Sweden.
[22]
Jaemin Hong. 2023. Improving Automatic C-to-Rust Translation with Static Analysis. In Proceedings of 45th IEEE/ACM International Conference on Software Engineering (ICSE'2023 Companion), Melbourne, Australia.
[23]
Wei Huang, Ana L. Milanova, Werner Dietl, and Michael D. Ernst. 2012. Reim & ReImInfer: checking and inference of reference immutability and method purity. In Proceedings of the 27th Annual ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA'2012), Tucson, AZ, USA.
[24]
Jianfeng Jiang, Hui Xu, and Yangfan Zhou. 2021. RULF: Rust Library Fuzzing via API Dependency Graph Traversal. In Proceedings of 36th IEEE/ACM International Conference on Automated Software Engineering (ASE'2021), Melbourne, Australia.
[25]
Nan Jiang, Kevin Liu, Thibaud Lutellier, and Lin Tan. 2023. Impact of Code Language Models on Automated Program Repair. In Proceedings of the 45th IEEE/ACM International Conference on Software Engineering (ICSE'2023), Melbourne, Australia.
[26]
Dongsun Kim, Jaechang Nam, Jaewoo Song, and Sunghun Kim. 2013. Automatic patch generation learned from human-written patches. In Proceedings of the 36th IEEE/ACM International Conference on Software Engineering (ICSE'14). Hyderabad, India.
[27]
Youngjae Kim, Seungheon Han, Askar Yeltayuly Khamit, and Jooyong Yi. 2023. Automated Program Repair from Fuzzing Perspective. In Proceedings of the 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA'2023), Seattle, WA, USA.
[28]
Steve Klabnik and Carol Nichols. 2023. The Rust programming language. No Starch Press.
[29]
Anil Koyuncu, Kui Liu, Tegawendé F. Bissyandé, Dongsun Kim, Jacques Klein, Martin Monperrus, and Yves Le Traon. 2020. FixMiner: Mining relevant fix patterns for automated program repair. Empir. Softw. Eng. 25, 3 (2020), 1980--2024.
[30]
Xuan-Bach Dinh Le, Lingfeng Bao, David Lo, Xin Xia, Shanping Li, and Corina S. Pasareanu. 2019. On reliability of patch correctness assessment. In Proceedings of the 41st International Conference on Software Engineering (ICSE'2019), Montreal, QC, Canada.
[31]
Xuan-Bach Dinh Le, Ferdian Thung, David Lo, and Claire Le Goues. 2018. Overfitting in semantics-based automated program repair. In Proceedings of the 40th International Conference on Software Engineering (ICSE'2018), Gothenburg, Sweden.
[32]
Thanh Le-Cong, Duc-Minh Luong, Xuan-Bach Dinh Le, David Lo, Nhat-Hoa Tran, Bui Quang Huy, and Quyet-Thang Huynh. 2023. Invalidator: Automated Patch Correctness Assessment Via Semantic and Syntactic Reasoning. IEEE Trans. Software Eng. 49, 6 (2023), 3411--3429.
[33]
Amit Levy, Bradford Campbell, Branden Ghena, Daniel B. Giffin, Pat Pannuto, Prabal Dutta, and Philip Levis. 2017. Multiprogramming a 64kB Computer Safely and Efficiently. In Proceedings of the 26th Symposium on Operating Systems Principles (SOSP '17). Shanghai, China.
[34]
Xueyang Li, Shangqing Liu, Ruitao Feng, Guozhu Meng, Xiaofei Xie, Kai Chen, and Yang Liu. 2022. TransRepair: Context-aware Program Repair for Compilation Errors. In Proceedings of 37th IEEE/ACM International Conference on Automated Software Engineering (ASE'2022), Rochester, MI, USA.
[35]
Kui Liu, Anil Koyuncu, Dongsun Kim, and Tegawendé F. Bissyandé. 2019. AVATAR: Fixing Semantic Bugs with Fix Patterns of Static Analysis Violations. In Proceedings of 26th IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER'2019), Hangzhou, China.
[36]
Kui Liu, Anil Koyuncu, Dongsun Kim, and Tegawendé F. Bissyandé. 2019. TBar: revisiting template-based automated program repair. In Proceedings of the 28th ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA'2019), Beijing, China.
[37]
Nuno P. Lopes, Juneyoung Lee, Chung-Kil Hur, Zhengyang Liu, and John Regehr. 2021. Alive2: bounded translation validation for LLVM. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI'2021), Virtual Event, Canada.
[38]
Yiling Lou, Junjie Chen, Lingming Zhang, Dan Hao, and Lu Zhang. 2019. History-driven build failure fixing: how far are we?. In Proceedings of the 28th ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA'2019), Beijing, China.
[39]
Sergey Mechtaev, Xiang Gao, Shin Hwei Tan, and Abhik Roychoudhury. 2018. Test-Equivalence Analysis for Automatic Patch Generation. ACM Trans. Softw. Eng. Methodol. 27, 4 (2018), 15:1--15:37.
[40]
Xiangxin Meng, Xu Wang, Hongyu Zhang, Hailong Sun, Xudong Liu, and Chunming Hu. 2023. Template-based Neural Program Repair. In Proceedings of the 45th IEEE/ACM International Conference on Software Engineering (ICSE'2023), Melbourne, Australia.
[41]
Ali Mesbah, Andrew Rice, Emily Johnston, Nick Glorioso, and Edward Aftandilian. 2019. DeepDelta: learning to repair compilation errors. In Proceedings of the 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (ESEC/FSE'2019), Tallinn, Estonia.
[42]
David A. Naumann. 2020. Thirty-Seven Years of Relational Hoare Logic: Remarks on Its Principles and History. In Proceedings of the 9th International Symposium on Leveraging Applications of Formal Methods (ISLAFM'2020), Rhodes, Greece.
[43]
Truong Giang Nguyen, Thanh Le-Cong, Hong Jin Kang, Ratnadira Widyasari, Chengran Yang, Zhipeng Zhao, Bowen Xu, Jiayuan Zhou, Xin Xia, Ahmed E. Hassan, Xuan-Bach Dinh Le, and David Lo. 2023. Multi-Granularity Detector for Vulnerability Fixes. CoRR abs/2305.13884 (2023). arXiv:2305.13884
[44]
Kai Pan, Sunghun Kim, and E. James Whitehead Jr. 2009. Toward an understanding of bug fix patterns. Empirical Software Engineering. 14, 3 (2009), 286--315.
[45]
Nikhil Parasaram, Earl T. Barr, and Sergey Mechtaev. 2023. Rete: Learning Namespace Representation for Program Repair. In Proceedings of the 45th IEEE/ACM International Conference on Software Engineering (ICSE'2023), Melbourne, Australia.
[46]
David J Pearce. 2021. A lightweight formalism for reference lifetimes and borrowing in Rust. ACM Transactions on Programming Languages and Systems (TOPLAS) 43, 1 (2021), 1--73.
[47]
Redox. 2023. Redox- Your Next(Gen) OS. https://www.redox-os.org/
[48]
Amr Sabry and Matthias Felleisen. 1993. Reasoning about programs in continuation-passing style. Lisp and symbolic computation 6 (1993), 289--360.
[49]
Eddie Antonio Santos, Joshua Charles Campbell, Dhvani Patel, Abram Hindle, and José Nelson Amaral. 2018. Syntax and sensibility: Using language models to detect and correct syntax errors. In Proceedings of the 25th International Conference on Software Analysis, Evolution and Reengineering (SANER'2018), Campobasso, Italy.
[50]
Servo. 2023. Servo. https://servo.org/
[51]
Edward K. Smith, Earl T. Barr, Claire Le Goues, and Yuriy Brun. 2015. Is the cure worse than the disease? overfitting in automated program repair. In Proceedings of the 10th Joint Meeting on Foundations of Software Engineering (ESEC/FSE'2015), Bergamo, Italy.
[52]
Zhensu Sun, Li Li, Yan Liu, Xiaoning Du, and Li Li. 2022. On the Importance of Building High-quality Training Datasets for Neural Code Search. In Proceedings of the IEEE/ACM 44th International Conference on Software Engineering (ICSE'2022), Pittsburgh, PA, USA.
[53]
Valerio Terragni, Yepang Liu, and Shing-Chi Cheung. 2016. CSNIPPEX: automated synthesis of compilable code snippets from Q&A sites. In Proceedings of the 25th International Symposium on Software Testing and Analysis (ISSTA'2016), Saarbrücken, Germany.
[54]
Priyan Vaithilingam, Tianyi Zhang, and Elena L. Glassman. 2022. Expectation vs. Experience: Evaluating the Usability of Code Generation Tools Powered by Large Language Models. In Proceedings of the Conference on Human Factors in Computing Systems (CHI EA'2022), New Orleans, LA, USA.
[55]
Ming Wen, Junjie Chen, Rongxin Wu, Dan Hao, and Shing-Chi Cheung. 2018. Context-aware patch generation for better automated program repair. In Proceedings of the 40th International Conference on Software Engineering (ICSE'2018), Gothenburg, Sweden.
[56]
Qi Xin and Steven P. Reiss. 2017. Identifying test-suite-overfitted patches through test case generation. In Proceedings of the 26th ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA'2017), Santa Barbara, CA, USA.
[57]
Yingfei Xiong, Xinyuan Liu, Muhan Zeng, Lu Zhang, and Gang Huang. 2018. Identifying patch correctness in test-based program repair. In Proceedings of the 40th International Conference on Software Engineering (ICSE'2018), Gothenburg, Sweden.
[58]
Ke Xu, Yao Xiao, Zhaoheng Zheng, Kaijie Cai, and Ram Nevatia. 2023. PatchZero: Defending against Adversarial Patch Attacks by Detecting and Zeroing the Patch. In Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV'2023), Waikoloa, HI, USA.
[59]
Michihiro Yasunaga and Percy Liang. 2020. Graph-based, Self-Supervised Program Repair from Diagnostic Feedback. In Proceedings of the 37th International Conference on Machine Learning (ICML'2020), Virtual Event. http://proceedings.mlr.press/v119/yasunaga20a.html
[60]
He Ye, Jian Gu, Matias Martinez, Thomas Durieux, and Martin Monperrus. 2022. Automated Classification of Overfitting Patches With Statically Extracted Code Features. IEEE Trans. Software Eng. 48, 8 (2022), 2920--2938.
[61]
He Ye, Matias Martinez, and Martin Monperrus. 2021. Automated patch assessment for program repair at scale. Empir. Softw. Eng. 26, 2 (2021), 20.
[62]
Anna Zeng and Will Crichton. 2018. Identifying Barriers to Adoption for Rust through Online Discourse. In PLATEAU@SPLASH '18. Boston, MA.
[63]
Hanliang Zhang, Cristina David, Yijun Yu, and Meng Wang. 2023. Ownership Guided C to Rust Translation. In Proceedings of the 35th International Conference on Computer Aided Verification (CAV'2023), Paris, France.
[64]
Qian Zhang, Jiyuan Wang, Guoqing Harry Xu, and Miryung Kim. 2022. Hetero-Gen: transpiling C to heterogeneous HLS code with automated test generation and program repair. In Proceedings of the 27th ACM International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS'2022), Lausanne, Switzerland.
[65]
Qihao Zhu, Zeyu Sun, Wenjie Zhang, Yingfei Xiong, and Lu Zhang. 2023. Tare: Type-Aware Neural Program Repair. In Proceedings of the 45th IEEE/ACM International Conference on Software Engineering (ICSE'2023), Melbourne, Australia.
[66]
Shuofei Zhu, Ziyi Zhang, Boqin Qin, Aiping Xiong, and Linhai Song. 2022. Learning and Programming Challenges of Rust: A Mixed-Methods Study. In Proceedings of the 44th International Conference on Software Engineering (ICSE'22). Pittsburgh, Pennsylvania.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
ICSE '24: Proceedings of the IEEE/ACM 46th International Conference on Software Engineering
May 2024
2942 pages
ISBN:9798400702174
DOI:10.1145/3597503
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

In-Cooperation

  • Faculty of Engineering of University of Porto

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 12 April 2024

Check for updates

Author Tags

  1. rust
  2. program repair
  3. compiler error

Qualifiers

  • Research-article

Conference

ICSE '24
Sponsor:

Acceptance Rates

Overall Acceptance Rate 276 of 1,856 submissions, 15%

Upcoming Conference

ICSE 2025

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 113
    Total Downloads
  • Downloads (Last 12 months)113
  • Downloads (Last 6 weeks)27
Reflects downloads up to 15 Oct 2024

Other Metrics

Citations

Cited By

View all

View Options

Get Access

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media