paperbot · PL 论文追踪

全部论文 待读 收藏

P1 Statically Contextualizing Large Language Models with Typed Holes

用类型化洞为大型语言模型提供静态上下文
OOPSLA 8(OOPSLA2)2024匹配度 6/10 · 该论文处在静态分析与 LLM 的交叉点上:用语言服务器暴露的类型与绑定上下文来约束 LLM 代码补全,并贡献了防数据污染的 MVUBench 与具有工业落地潜力的 ChatLSP 协议扩展,契合用户对'PL×LLM 交叉、benchmark 建设、工程落地'的兴趣;但其目标是把静态类型当作 LLM 生成的条件(提升补全质量),而非把静态分析应用于 Agentic 程序,也不是用 LLM 改进静态分析/形式化验证,且实验主体建立在 Hazel 这一低资源研究语言上,与用户画像的核心问题仍有距离。引用 21 inbox
Andrew Blinn, Xiang Li, June Hyung Kim, Cyrus Omar
dblp: 2026-09-10crossref: 2026-09-10arxiv: 2026-09-10

AI 速览

一句话:将LLM代码生成集成到Hazel的带类型洞环境,通过语言服务器提供静态类型与绑定上下文,显著提升补全质量并证明类型定义上下文最有效。

LLM代码补全常因缺乏代码上下文而生成错误代码,尤其当所需定义既不在训练数据中也不在光标附近时。本文将LLM代码生成集成到Hazel实时编程草稿环境,借助语言服务器识别类型化洞的类型与typing context,利用Hazel的语法与类型错误纠正保证有意义的程序草图,以token高效的方式向LLM提供跨代码库的静态上下文,并通过对话迭代精化补全。为评估,提出MVUBench:从零编写的MVU Web应用及单元测试,避免数据污染且易移植。消融实验发现类型定义上下文尤为关键。在Hazel(低资源语言)验证后,将技术移植到TypeScript,并概述ChatLSP——LSP的保守扩展,供语言服务器暴露静态上下文能力。

问题
LLM代码补全系统常因缺乏恰当的代码上下文而生成错误代码,尤其当所需定义既不在训练数据中、也不在光标附近时,这一上下文缺失问题尤为突出。
方法
将LLM集成到Hazel实时编程草稿环境,利用语言服务器识别类型化洞的类型与typing context,以类型定义、函数头和错误消息等静态信息提示LLM,并通过迭代对话精化补全;同时提出ChatLSP扩展LSP以暴露静态上下文能力。
评估
提出MVUBench(从零编写的MVU Web应用及单元测试,避免数据污染且易移植),通过消融实验发现类型定义上下文影响最大,并在Hazel和TypeScript上验证方法的适用性。
原文摘要(Abstract)

Large language models (LLMs) have reshaped the landscape of program synthesis. However, contemporary LLM-based code completion systems often hallucinate broken code because they lack appropriate code context, particularly when working with definitions that are neither in the training data nor near the cursor. This paper demonstrates that tighter integration with the type and binding structure of the programming language in use, as exposed by its language server, can help address this contextualization problem in a token-efficient manner. In short, we contend that AIs need IDEs, too! In particular, we integrate LLM code generation into the Hazel live program sketching environment. The Hazel Language Server is able to identify the type and typing context of the hole that the programmer is filling, with Hazel’s total syntax and type error correction ensuring that a meaningful program sketch is available whenever the developer requests a completion. This allows the system to prompt the LLM with codebase-wide contextual information that is not lexically local to the cursor, nor necessarily in the same file, but that is likely to be semantically local to the developer’s goal. Completions synthesized by the LLM are then iteratively refined via further dialog with the language server, which provides error localization and error messages. To evaluate these techniques, we introduce MVUBench, a dataset of model-view-update (MVU) web applications with accompanying unit tests that have been written from scratch to avoid data contamination, and that can easily be ported to new languages because they do not have large external library dependencies. These applications serve as challenge problems due to their extensive reliance on application-specific data structures. Through an ablation study, we examine the impact of contextualization with type definitions, function headers, and errors messages, individually and in combination. We find that contextualization with type definitions is particularly impactful. After introducing our ideas in the context of Hazel, a low-resource language, we duplicate our techniques and port MVUBench to TypeScript in order to validate the applicability of these methods to higher-resource mainstream languages. Finally, we outline ChatLSP, a conservative extension to the Language Server Protocol (LSP) that language servers can implement to expose capabilities that AI code completion systems of various designs can use to incorporate static context when generating prompts for an LLM.

链接与引用

DOI 原文 · arXiv · PDF(开放获取) · DBLP

BibTeX
@article{BlinnLKO24,
  title = {Statically Contextualizing Large Language Models with Typed Holes},
  author = {Andrew Blinn and Xiang Li and June Hyung Kim and Cyrus Omar},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {8},
  number = {OOPSLA2},
  year = {2024},
  doi = {10.1145/3689728}
}