arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2608.21483cs.SEcs.PL

SLICE:规约级别的契约执行隔离

SLICE: Specification-Level Isolation of Contract Enforcement

Soohan Lim, Hyundong Jin, Yo-Sub Han

AI总结:

SLICE是一个分阶段的代码生成框架,通过规约结构化、函数体生成、契约断言生成三个阶段,在ContractEval数据集上使代码满足功能需求与输入契约的性能平均提升6.58%。

AI中文摘要:

编程问题通常会同时指定函数应执行的计算以及其输入必须满足的条件。大语言模型被广泛用于从这些问题规约中生成代码,而生成的函数必须实现所需的计算,同时执行所述的输入条件。所述输入条件共同构成了输入契约。执行该契约颇具难度:执行不完整会接受应被拒绝的输入,而过度严格的执行则会拒绝应被接受的输入。现有的代码生成方法并未提供一种既能识别输入契约又能识别功能需求,并生成同时满足二者的代码的生成过程。因此,我们提出了SLICE,这是一个能同时识别需求并通过独立的生成阶段处理这些需求的生成框架。SLICE包含三个阶段:(i)基于图的规约结构化,它将契约条件与规约图中的描述片段关联,并移除仅与契约相关的片段以形成功能视图;(ii)函数体生成,它通过贪心解码和采样解码生成多个候选函数体,使用执行分数对它们进行排名,并使用差异区域对数概率解决平局;(iii)契约断言生成,它从已识别的契约条件中生成输入验证断言,并将其附加到选定的函数体上。我们在ContractEval数据集上对SLICE进行了评估,涉及四个大语言模型,并将其与六种竞争方法进行了比较。相对于每个模型评估中最强的基线,SLICE在生成同时满足功能需求和输入契约的代码方面的性能平均提升了6.58%。我们的代码可在此https URL获取。

英文摘要:

Programming problems commonly specify both the computation a function should perform and the conditions that its inputs must satisfy. Large language models are widely used to generate code from these problem specifications, and the generated function must implement the required computation while enforcing the stated input conditions. The stated input conditions collectively form an input contract. Enforcing this contract is difficult: incomplete enforcement accepts inputs that should be rejected, whereas overly restrictive enforcement rejects inputs that should be accepted. Existing code generation methods do not provide a generation process that identifies both the input contract and the functional requirements and generates code that satisfies them jointly. We therefore introduce SLICE, a generation framework that identifies both requirements and addresses them through separate generation stages. SLICE consists of three stages: (i) Graph-based specification structuring, which grounds contract conditions to description segments in a specification graph and removes contract-only segments to form a functional view; (ii) Functional body generation, which produces multiple candidate function bodies through greedy and sampled decoding, ranks them using execution scores, and resolves ties using difference-region log probabilities; and (iii) Contract assertion generation, which generates input-validation assertions from the identified contract conditions and attaches them to the selected function body. We evaluate SLICE on ContractEval across four LLMs and compare it with six competing methods. Relative to the strongest evaluated baseline for each model, SLICE improves performance in generating code that satisfies both the functional requirements and the input contract by an average of 6.58%. Our code is available at https://github.com/suhanmen/SLICE.

补充信息

↑