Scitix: Scalable Constraint-Based Type Inference for Code Snippets with Missing Types
Yiwen Dong, Zhenyang Xu, Yongqiang Tian, Edward Lee, Ondřej Lhoták, Chengnian Sun
Abstract
Code snippets commonly appear in online developer communities, documentation, and LLM-assisted workflows to communicate ideas and algorithms. However, contextual information, like dependencies and the exact types , are often missing in code snippets, which makes their reuse difficult. Some of the most successful automated techniques use logical constraints to infer the types and dependencies, but they do not work in practice because they require an exact knowledge base that contains all possible dependencies and exact types. However, such a knowledge base is both computationally expensive for constraint solving and impossible to achieve in the presence of missing types ( e.g. , user-defined types) in code snippets. To this end, this paper proposes a novel, scalable technique named Scitix. Our insight is two-fold. First, inspired by gradual typing’s use of an unknown type, we represent certain missing types as Any , ignoring such types during constraint solving, improving performance and scalability. Second, our novel, iterative constraint-solving approach saves on computation and skips constraints involving missing types. Our extensive evaluations show that our insights improve both performance and scalability compared to SnR (the state of the art). Specifically, Scitix achieves F1-scores of 94.8% and 86.8% on Stack Overflow and generated code snippets, respectively, using a large knowledge base of over 3,000 jars. In contrast, SnR consistently times out, yielding near 0% F1. Even with the smallest knowledge base, where SnR does not time out, Scitix reduces the number of errors by 77% and 45% compared to SnR. Compared to state-of-the-art large language models (LLMs) like GPT-4o and the LLM-based ZS4C, Scitix improves F1-score by 76.8% and 35.4%, respectively. Scitix’s strong performance highlights its potential as a practical technique for type inference in real-world code snippets.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get 90e6495c-96df-4952-8ca1-6e352d588fa6Related papers
- SnR: Constraint-Based Type Inference for Incomplete Java Code SnippetsYiwen Dong, Tianxiao Gu, Yongqiang Tian, Chengnian SunICSE 2022 · 10 citations
- CKTyper: Enhancing Type Inference for Java Code Snippets by Leveraging Crowdsourcing Knowledge in Stack OverflowAnji Li, Neng Zhang, Ying Zou, Zhixiang Chen et al.FSE 2025 · 1 citation
- Prompt-tuned Code Language Model as a Neural Knowledge Base for Type Inference in Statically-Typed Partial CodeQing Huang, Zhiqiang Yuan, Zhenchang Xing, Xiwei Xu et al.ASE 2022 · 40 citations
- Feedback-Directed Partial ExecutionIshrak Hayet, Adam Scott, Marcelo d'AmorimISSTA 2024 · 1 citation
- TypeT5: Seq2seq Type Inference using Static AnalysisJiayi Wei, Greg Durrett, Isil DilligICLR 2023 · 4 citations
