Papers
Topics
Authors
Recent
Search
2000 character limit reached

AlphaTrans: A Neuro-Symbolic Compositional Approach for Repository-Level Code Translation and Validation

Published 31 Oct 2024 in cs.SE and cs.LG | (2410.24117v5)

Abstract: Code translation transforms programs from one programming language (PL) to another. Several rule-based transpilers have been designed to automate code translation between different pairs of PLs. However, the rules can become obsolete as the PLs evolve and cannot generalize to other PLs. Recent studies have explored the automation of code translation using LLMs. One key observation is that such techniques may work well for crafted benchmarks but fail to generalize to the scale and complexity of real-world projects with dependencies, custom types, PL-specific features, etc. We propose AlphaTrans, a neuro-symbolic approach to automate repository-level code translation. AlphaTrans translates both source and test code, and employs multiple levels of validation to ensure the translation preserves the functionality of the source program. To break down the problem for LLMs, AlphaTrans leverages program analysis to decompose the program into fragments and translates them in the reverse call order. We leveraged AlphaTrans to translate ten real-world open-source projects consisting of <836, 8575, 2719> classes, methods, and tests. AlphaTrans breaks down these projects into 17874 fragments and translates the entire repository. 96.40% of the translated fragments are syntactically correct, and AlphaTrans validates the translations' runtime behavior and functional correctness for 27.03% and 25.14% of fragments. On average, the integrated translation and validation take 34 hours to translate a project, showing its scalability in practice. For the incorrect translations, AlphaTrans generates a report including existing translation, stack trace, test errors, or assertion failures. We provided these artifacts to two developers to fix the translation bugs in four projects. They were able to fix the issues in 20.1 hours on average and achieve all passing tests.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (63)
  1. AVATAR: A Parallel Corpus for Java-Python Program Translation. In ACL. ACL, Toronto, Canada, 2268–2281.
  2. Anthropic AI. 2024. Claude 3. https://www.anthropic.com/news/claude-3-family.
  3. Transpilers: A Systematic Mapping Review of Their Usage in Research and Industry. Applied Sciences 13 (2023), 3667.
  4. Ned Batchelder. 2024. Coverage.py. https://pypi.org/project/coverage.
  5. Dante Broggi and Yi Liu. 2023. On the Interoperability of Programming Languages via Translation. In CSCE. IEEE, Las Vegas, NV, USA, 2579–2585.
  6. Tree-to-tree Neural Networks for Program Translation. In NIPS. Curran Associates Inc., Red Hook, NY, USA, 2552 – 2562.
  7. CodeFuse-13B: A Pretrained Multi-lingual Code Large Language Model. In ICSE-SIEP. ACM, New York, NY, USA, 418–429.
  8. Programming Language Inter-Conversion. International Journal of Computer Applications 1, 20 (2010), 63–69.
  9. Hadeel A. Osman Eman J. Coco and Niemah I. Osman. 2018. JPT : A Simple Java-Python Translator. CAIJ 5, 2 (2018), 1–18.
  10. The Apache Software Foundation. 2024a. Apache Commons CLI. https://github.com/apache/commons-cli
  11. The Apache Software Foundation. 2024b. Apache Commons Codec. https://github.com/apache/commons-codec
  12. The Apache Software Foundation. 2024c. Apache Commons CSV. https://github.com/apache/commons-csv
  13. The Apache Software Foundation. 2024d. Apache Commons Exec. https://github.com/apache/commons-exec
  14. The Apache Software Foundation. 2024e. Apache Commons FileUpload. https://github.com/apache/commons-fileupload
  15. The Apache Software Foundation. 2024f. Apache Commons Graph. https://github.com/apache/commons-graph
  16. The Apache Software Foundation. 2024g. Apache Commons Pool. https://github.com/apache/commons-pool
  17. The Apache Software Foundation. 2024h. Apache Commons Validator. https://github.com/apache/commons-validator
  18. Gordon Fraser and Andrea Arcuri. 2011. EvoSuite: automatic test suite generation for object-oriented software. In Proceedings of the 19th ACM SIGSOFT Symposium and the 13th European Conference on Foundations of Software Engineering (Szeged, Hungary) (ESEC/FSE ’11). Association for Computing Machinery, New York, NY, USA, 416–419. https://doi.org/10.1145/2025113.2025179
  19. GitHub. 2024. CodeQL. https://codeql.github.com
  20. GraalVM. 2024. Polyglot API. https://www.graalvm.org/latest/reference-manual/polyglot-programming.
  21. Mutation analysis for evaluating code translation. Empirical Software Engineering 29 (2023), 23 pages.
  22. DeepSeek-Coder: When the Large Language Model Meets Programming – The Rise of Code Intelligence. arXiv:2401.14196
  23. Ali Reza Ibrahimzada. 2024. Program Decomposition and Translation with Static Analysis. In Proceedings of the 2024 IEEE/ACM 46th International Conference on Software Engineering: Companion Proceedings. 453–455.
  24. Immunant. 2024. C2Rust Transpiler. https://github.com/immunant/c2rust.
  25. Paul Irwin. 2024. Java to CSharp Converter. https://github.com/paulirwin/JavaToCSharp.
  26. Suman Jain and Inderveer Chana. 2015. Modernization of Legacy Systems: A Generalised Roadmap. In ICCCT. ACM, New York, NY, USA, 62–67.
  27. Cloud Migration Research: A Systematic Review. IEEE Transactions on Cloud Computing 1 (2013), 142–157.
  28. On the evaluation of neural code translation: Taxonomy and benchmark. In 2023 38th IEEE/ACM International Conference on Automated Software Engineering (ASE). IEEE, Las Vegas, NV, USA, 1529–1541.
  29. How Do Professionals Perceive Legacy Systems and Software Modernization? In ICSE. ACM, New York, NY, USA, 36–47.
  30. Modernization Framework to Enhance the Security of Legacy Information Systems. Intelligent Automation & Soft Computing 32 (2022), 543–555.
  31. Intelligent CAT Lab. 2024. Artifact Website. https://github.com/Intelligent-CAT-Lab/AlphaTrans.
  32. Kevin Lano and Hanan Siala. 2024. Using model-driven engineering to automate software language translation. Automated Software Engineering 31 (2024), 59 pages.
  33. Daniel Lemire. 2024. JavaFastPFOR. https://github.com/lemire/JavaFastPFOR
  34. Retrieval-augmented generation for knowledge-intensive nlp tasks. Advances in Neural Information Processing Systems 33 (2020), 9459–9474.
  35. Lost in the Middle: How Language Models Use Long Contexts. TACL 12 (2024), 157–173.
  36. Lexical Statistical Machine Translation for Language Migration. In FSE. ACM, New York, NY, USA, 651–654.
  37. Migrating Code with Statistical Machine Translation. In ICSE Companion. ACM, New York, NY, USA, 544–547.
  38. Divide-and-Conquer Approach for Multi-phase Statistical Migration for Source Code. In ASE. IEEE, Las Vegas, NV, USA, 585–596.
  39. SpecTra: Enhancing the Code Translation Ability of Language Models by Generating Multi-Modal Specifications. arXiv:2405.18574
  40. OpenAI. 2023. GPT-4 Technical Report. arXiv:2303.08774
  41. Oracle. 2024. GraalVM. https://www.graalvm.org.
  42. Lost in Translation: A Study of Bugs Introduced by Large Language Models while Translating Code. In ICSE. ACM, New York, NY, USA, 866–866.
  43. Automated Test Case Generation as a Many-Objective Optimisation Problem with Dynamic Selection of the Targets. IEEE Transactions on Software Engineering 44, 2 (2018), 122–158. https://doi.org/10.1109/TSE.2017.2663435
  44. Mono Project. 2023. Sharpen - Automated Java-¿C# coversion. https://github.com/mono/sharpen.
  45. pytest dev. 2024. Pytest. https://www.pytest.org.
  46. Lili Qiu. 1999. Programming Language Translation. Technical Report. Cornell University, USA.
  47. Unsupervised Translation of Programming Languages. In NIPS. Curran Associates Inc., Red Hook, NY, USA, 20601 – 20611.
  48. Leveraging Automated Unit Tests for Unsupervised Code Translation. arXiv:2110.06773
  49. Fuse Source. 2024. Jansi. https://github.com/fusesource/jansi
  50. Charles Spearman. 1961. The Proof and Measurement of Association between Two Things. The American Journal of Psychology 15 (1961), 72 –– 101.
  51. The JaCoCo Team. 2024a. Java Code Coverage. https://www.eclemma.org/jacoco/
  52. The JUnit Team. 2024b. JUnit. https://junit.org/junit5/
  53. Andrey A Terekhov and Chris Verhoef. 2000. The Realities of Language Conversions. IEEE Software 17 (2000), 111–124.
  54. TIOBE. 2023. TIOBE Index. https://www.tiobe.com/tiobe-index.
  55. StructCoder: Structure-Aware Transformer for Code Generation. Transactions on Knowledge Discovery from Data 18 (2024), 1–20.
  56. Go Transpile. 2024. C to Go Translator. https://github.com/gotranspile/cxgo.
  57. Tree-Sitter. 2024. Tree-Sitter Library. https://tree-sitter.github.io/tree-sitter/
  58. One VM to Rule Them All. In Onward! ACM, New York, NY, USA, 187–204.
  59. CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translation. In EMNLP. ACL, Singapore, 5067–5089.
  60. VERT: Verified Equivalent Rust Transpilation with Large Language Models as Few-Shot Learners. arXiv:2404.18852
  61. Exploring and Unleashing the Power of Large Language Models in Automated Code Translation. FSE 1 (2024), 1585–1608.
  62. Rectifier: Code Translation with Corrector via LLMs. arXiv:2407.07472
  63. Multilingual Code Snippets Training for Program Translation. AAAI 36 (2022), 11783–11790.

Summary

  • The paper introduces AlphaTrans, a neuro-symbolic technique combining program analysis and LLMs for translating entire code repositories, demonstrated from Java to Python.
  • AlphaTrans employs a three-phase methodology covering program decomposition, type mapping, and iterative compositional translation with functional validation techniques.
  • Evaluation shows high syntactic correctness (99.1%) and successful type mapping (92%), identifying functional validation tied to test coverage as a primary challenge and area for future research.

Repository-Level Compositional Code Translation and Validation

The paper "Repository-Level Compositional Code Translation and Validation" proposes AlphaTrans, a novel technique for automated code translation at the repository level, focusing on the critical task of translating entire repositories from Java to Python. Unlike traditional methods that focus on rule-based transpilers or crafted benchmarks, AlphaTrans employs a neuro-symbolic approach that integrates program analysis and the capabilities of advanced LLMs. This technique addresses prevalent challenges in code translation, such as complexity, validation, and contextualization of code.

Technical Contributions

AlphaTrans is introduced as a comprehensive answer to several limitations in current code translation approaches. The methodology is built in three distinct phases: program transformation and decomposition, type translation and skeleton construction, and compositional translation and validation.

  1. Program Transformation and Decomposition: In this phase, AlphaTrans tackles the complexity associated with language-specific features like method and constructor overloading in Java. Through refactoring, these constructs are transformed into expressions more amenable to Python, facilitating accurate translation. Furthermore, the decomposition of the program into smaller fragments enables more manageable inputs for the LLM, overcoming the limitations of its context window.
  2. Type Translation and Skeleton Construction: A crucial part of establishing an executable target language structure is creating a type mapping system. Here, AlphaTrans adapts types from the source language to suitable counterparts in the target language (Python in this case), building a project skeleton that can support iterative inclusion of translated code fragments.
  3. Compositional Translation and Validation: This phase utilizes iterative feedback and validation techniques to ensure the translated code is functionally equivalent to the source. By leveraging GraalVM's language interoperability features, AlphaTrans inspects runtime behavior and functional correctness through both source hooks and translated tests.

Results and Evaluation

The authors demonstrate AlphaTrans's efficacy by testing it on ten substantial open-source Java projects, numbering over 8,500 methods and more than 2,700 tests. The translation system achieves a high syntactical correctness rate of 99.1%. Functional correctness is validated at 25.8%, albeit with a test coverage constraint influencing this figure. The adoption of automated type translation yielded successful mappings for approximately 92% of types.

Implications and Future Directions

The results show that while AlphaTrans is highly effective in producing syntactically correct translations, the main challenge lies in functional validation, largely contingent on the quality and coverage of the original test suite. This suggests avenues for future work in improving translation validation through enhanced test generation, possibly leveraging LLMs for this purpose.

Another important implication is the potential scalability of AlphaTrans across multiple language pairs beyond Java and Python, given sufficient adaptation of program decomposition and type translation processes. Additionally, enhancing the LLM's ability to correctly infer equivalent idiomatic expressions between languages remains an open research avenue.

Conclusion

The paper presents AlphaTrans as a robust step forward in repository-level code translation by integrating symbolic methods with the generative capabilities of LLMs. Though challenges in complete functional validation remain, this approach provides effective solutions to many challenges in the field, particularly with respect to syntactical correctness and adaptation to LLMs. Future enhancements focused on validation could further solidify its place as a standard method for comprehensive codebase translation.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Continue Learning

We haven't generated follow-up questions for this paper yet.

Collections

Sign up for free to add this paper to one or more collections.

Tweets

Sign up for free to view the 4 tweets with 64 likes about this paper.