AlphaTrans: نهج رمزي عصبي تركيبي لترجمة الكود والتحقق منه على مستوى المستودع AlphaTrans: A Neuro-Symbolic Compositional Approach for Repository-Level Code Translation and Validation

شارك:
المجلة: Proceedings of the ACM on software engineering.، المجلد: 2، العدد: 0
DOI: https://doi.org/10.1145/3729379
تاريخ النشر: 2025-06-19
المؤلف: Ali Reza Ibrahimzada وآخرون
الموضوع الرئيسي: أبحاث هندسة البرمجيات

نظرة عامة

يتناول القسم عملية ترجمة الشيفرة، والتي تتضمن تحويل البرامج من لغة برمجة واحدة (PL) إلى أخرى، بشكل أساسي من أجل تحديث التطبيقات لتحسين القابلية للصيانة والموثوقية. تواجه المحولات التقليدية المعتمدة على القواعد تحديات مع تطور لغات البرمجة، مما يؤدي إلى تقادم القواعد ووجود عمومية محدودة. شهدت التطورات الأخيرة استكشاف نماذج اللغة الكبيرة (LLMs) لأتمتة ترجمة الشيفرة؛ ومع ذلك، غالبًا ما تكافح هذه الطرق مع تعقيدات المشاريع الواقعية، والتي تشمل تبعيات معقدة وميزات خاصة باللغة.

لمعالجة هذه القيود، يقترح المؤلفون AlphaTrans، وهو نهج عصبي رمزي مصمم لأتمتة ترجمة الشيفرة على مستوى المستودع. يقوم AlphaTrans بترجمة كل من الشيفرة المصدرية وشيفرة الاختبار مع استخدام مستويات متعددة من التحقق لضمان الحفاظ على الوظائف. من خلال استخدام تحليل البرنامج، يقوم بتفكيك البرامج إلى أجزاء ويترجمها بترتيب عكسي. أدى تطبيق AlphaTrans على عشرة مشاريع مفتوحة المصدر في العالم الحقيقي إلى ترجمة 17,874 جزءًا، محققًا معدل صحة نحوية قدره 96.40%. علاوة على ذلك، تحقق من سلوك وقت التشغيل وصحة الوظائف لـ 27.03% و25.14% من أجزاء طرق التطبيق، على التوالي. أظهر عملية الترجمة والتحقق المتكاملة قابلية التوسع، بمتوسط 34 ساعة لكل مشروع. تمكن المطورون من حل مشكلات الترجمة في متوسط 20.1 ساعة، مما قلل بشكل كبير من الوقت المطلوب مقارنة بالطرق التقليدية، التي قد تستغرق أسابيع أو أشهر.

مقدمة

تناقش مقدمة الورقة التحديات والتطورات في تحديث التطبيقات، مع التركيز بشكل خاص على ترجمة الشيفرة الآلية من لغة برمجة (PL) إلى أخرى. بينما يعزز التحديث الأداء والقابلية للصيانة والأمان، فإن الهجرة اليدوية غالبًا ما تكون غير فعالة ومعرضة للأخطاء. تكافح المحولات التقليدية، التي تقوم بترجمات قائمة على القواعد، مع الفروق الكبيرة في النحو والدلالة بين لغات البرمجة، مما يؤدي إلى شيفرة غير تعبيرية وصعبة القراءة. أظهرت الجهود الأخيرة لاستخدام نماذج اللغة الكبيرة (LLMs) في توليد الشيفرة وعدًا ولكنها محدودة بالبرامج البسيطة وتواجه تحديات مثل تعقيد المشكلة، وقضايا التحقق، ونوافذ السياق المحدودة.

لمعالجة هذه القيود، تقدم الورقة AlphaTrans، وهو نهج عصبي رمزي لترجمة الشيفرة والتحقق منها على مستوى المستودع. يستخدم AlphaTrans التحليل الثابت لإدارة الميزات الخاصة بلغة البرمجة، ويفكك المشاريع المصدرية إلى أجزاء قابلة للإدارة، ويترجمها مع ضمان الوظائف من خلال الاختبارات الحالية. تظهر الطريقة فعاليتها من خلال ترجمة عشرة مشاريع Java حقيقية إلى Python، محققة 96.40% من الصحة النحوية ووجود مكافئ وظيفي ملحوظ. النهج قابل للتوسع، حيث يكمل الترجمات بكفاءة، ويظهر أداءً محسناً مع نماذج LLMs الأقوى. يتم وضع AlphaTrans ك تقنية رائدة في ترجمة مستوى المستودع، قادرة على إنتاج ترجمات موثقة مع الاستفادة من التوافق اللغوي للتحقق المعزول من الأجزاء المترجمة. النتائج وقطع الشيفرة متاحة للجمهور لمزيد من البحث والتطبيق.

نقاش

يسلط قسم النقاش في ورقة البحث الضوء على عدة تحديات كبيرة تم مواجهتها في ترجمة الشيفرة على مستوى المستودع، خاصة عند ترجمة شيفرة Java إلى Python باستخدام إطار عمل AlphaTrans. التحدي الأول يتعلق بحجم الفئة، حيث يمكن أن يتجاوز العدد الكبير من الرموز في فئة Java حدود السياق للعديد من نماذج اللغة (LLMs). يتعامل AlphaTrans مع هذا من خلال تفكيك الفئات الكبيرة إلى أجزاء أصغر، مترجمًا كل منها بترتيب عكسي لإدارة حدود الرموز بشكل فعال.

تحدٍ آخر هو التعامل مع الخصائص الخاصة بلغة البرمجة، مثل التحميل الزائد للطرق والمُنشئات في Java، والتي ليس لها مكافئ مباشر في Python. يستخدم AlphaTrans تحليل البرنامج لإعادة هيكلة المُنشئات المحملة بشكل زائد إلى طرق مصنع فريدة، مما يضمن الحفاظ على المكافئ الوظيفي أثناء الترجمة. يمثل التحقق من الشيفرة المترجمة تحديًا إضافيًا، خاصة بسبب “أثر اقتران ترجمة الاختبار”، حيث يمكن أن تؤدي المشكلات في طريقة واحدة إلى إخفاء التحقق من طرق أخرى. للتخفيف من ذلك، يقوم AlphaTrans بتنفيذ اختبارات اللغة المصدر مباشرة باستخدام GraalVM، مما يسمح بالتحقق المعزول من كل جزء مترجم.

أخيرًا، تناقش الورقة ضرورة ترجمة الاختبارات والتفكيك لضمان ترجمة وتنفيذ جميع الاختبارات، حتى لو لم تُستخدم مباشرة للتحقق. تساعد هذه الطريقة في الحفاظ على سلامة المشروع المترجم وتسمح بالتحقق الأكثر تفصيلاً من الطرق الفردية. بشكل عام، يستخدم AlphaTrans نهجًا منهجيًا يتضمن تحويل البرنامج، وترجمة الأنواع، والتحقق التراكمي لتعزيز جودة ترجمة الشيفرة عبر لغات البرمجة.

Journal: Proceedings of the ACM on software engineering., Volume: 2, Issue: 0
DOI: https://doi.org/10.1145/3729379
Publication Date: 2025-06-19
Author(s): Ali Reza Ibrahimzada et al.
Primary Topic: Software Engineering Research

Overview

The section discusses the process of code translation, which involves converting programs from one programming language (PL) to another, primarily for application modernization to improve maintainability and reliability. Traditional rule-based transpilers face challenges as programming languages evolve, leading to obsolescence of rules and limited generalizability. Recent advancements have seen the exploration of Large Language Models (LLMs) for automating code translation; however, these methods often struggle with the complexities of real-world projects, which include intricate dependencies and language-specific features.

To address these limitations, the authors propose AlphaTrans, a neuro-symbolic approach designed to automate repository-level code translation. AlphaTrans translates both source and test code while employing multiple validation levels to ensure functional preservation. By utilizing program analysis, it decomposes programs into fragments and translates them in reverse call order. The application of AlphaTrans to ten real-world open-source projects resulted in the translation of 17,874 fragments, achieving a syntactic correctness rate of 96.40%. Furthermore, it validated the runtime behavior and functional correctness for 27.03% and 25.14% of application method fragments, respectively. The integrated translation and validation process demonstrated scalability, averaging 34 hours per project. Developers were able to resolve translation issues in an average of 20.1 hours, significantly reducing the time required compared to traditional methods, which could take weeks or months.

Introduction

The introduction of the paper discusses the challenges and advancements in application modernization, particularly focusing on automated code translation from one programming language (PL) to another. While modernization enhances performance, maintainability, and security, manual migration is often inefficient and prone to errors. Traditional transpilers, which perform rule-based translations, struggle with significant differences in syntax and semantics between PLs, leading to non-idiomatic and hard-to-read code. Recent efforts to utilize Large Language Models (LLMs) for code synthesis have shown promise but are limited to simple programs and face challenges such as problem complexity, validation issues, and limited context windows.

To address these limitations, the paper introduces AlphaTrans, a neuro-symbolic approach for automated repository-level code translation and validation. AlphaTrans employs static analysis to manage PL-specific features, decomposes source projects into manageable fragments, and translates them while ensuring functionality through existing tests. The method demonstrates effectiveness by translating ten real-world Java projects into Python, achieving 96.40% syntactic correctness and notable functional equivalence. The approach is scalable, completing translations efficiently, and shows improved performance with stronger LLMs. AlphaTrans is positioned as a pioneering technique in repository-level translation, capable of generating validated translations while leveraging language interoperability for in-isolation validation of translated fragments. The results and code artifacts are publicly available for further research and application.

Discussion

The discussion section of the research paper highlights several significant challenges encountered in repository-level code translation, particularly when translating Java code to Python using the AlphaTrans framework. The first challenge pertains to class size, where the extensive number of tokens in a Java class can exceed the context limits of many language models (LLMs). AlphaTrans addresses this by decomposing large classes into smaller fragments, translating each in reverse call order to manage token limits effectively.

Another challenge is the handling of programming language-specific properties, such as method and constructor overloading in Java, which does not have a direct equivalent in Python. AlphaTrans employs program analysis to refactor overloaded constructors into unique factory methods, ensuring functional equivalence is maintained during translation. Validation of translated code presents a further challenge, particularly due to the “test translation coupling effect,” where issues in one method can obscure the validation of others. To mitigate this, AlphaTrans executes source language tests directly using GraalVM, allowing for isolated validation of each translated fragment.

Lastly, the paper discusses the necessity of test translation and decomposition to ensure that all tests are translated and executed, even if they are not directly used for validation. This approach helps to maintain the integrity of the translated project and allows for more granular validation of individual methods. Overall, AlphaTrans employs a systematic approach that includes program transformation, type translation, and compositional validation to enhance the quality of code translation across programming languages.

شارك: