Manuscript Offprint

arXiv:2610.39489

Program Bindings Inside Code Models

Prateek Kumar Rajput, Yewei Song, Jacques Klein, Tegawendé F. Bissyandé

PRATEEK KUMAR RAJPUT, University of Luxembourg, Luxembourg

YEWEI SONG, University of Luxembourg, Luxembourg

JACQUES KLEIN, University of Luxembourg, Luxembourg

TEGAWENDÉ F. BISSYANDÉ, University of Luxembourg, Luxembourg

Large language models are now used to complete, review, and repair code, tasks that until recently relied on tools built on program analysis. A refactoring engine, for example, resolves every use of a name to its definition before it renames anything, and the correctness of the rename depends on that information. A language model exposes no such structure. Its state is a hidden vector per token at each layer, and when it renames a variable in one place but not in another, a developer cannot inspect which definition the model associated with each use. In this paper, we test whether the hidden states of a code model can be described and edited using the information a compiler front end computes. For each token of a Python program, standard analyzers provide its position in the abstract syntax tree, its scope, its definition–use links, and its syntactic category. We fit a decomposition that expresses every hidden state of a frozen model as a sum of one term per token, each combining the token with this structural label, and we replace the model's own states with the decomposition at every layer while it predicts the output of a small program. If the model still answers correctly, the decomposition preserves the information the model uses. We apply this test to 14 open models, seven of them trained for code, and compare against a baseline decomposition of the same size built from token positions. The static-analysis decomposition preserves the model's answers better than the positional one in 10 of the 14 models, including six of the seven code models, and deleting the definition–use links from it removes most of that advantage on the two models tested. Editing the decomposition, for instance rebinding the argument of a call, makes StarCoder2-15B produce the answer of the edited program in 90 of 100 cases, compared with 19 for the positional baseline. The Qwen2.5 family is the exception on several measures. For most of the models tested, standard static analysis therefore provides both a description of what the hidden states encode about a program and a way to change it without retraining.

CCS Concepts: • Software and its engineering → Software notations and tools; Software testing and debugging; • Computing methodologies → Neural networks.

Additional Key Words and Phrases: code language models, tensor product representations, interpretability, static analysis, causal interventions, program structure

1 Introduction

Large language models (LLMs) are now part of everyday software development tools. They complete code in the editor, propose patches in code review, and generate candidate fixes in automated program repair [9]. Welsh has argued that programming itself is on its way to obsolescence, with software trained rather than written [54], and the observation that code is repetitive enough to be predicted like natural language [20] explains much of why these models work. Both are claims about what the models produce. What a model internally represents about the program it is predicting remains an open question. The tools that preceded these models rely on an explicit representation of the program. A compiler resolves every name to a definition before it generates code, a refactoring engine renames a variable only after it has found every use that the declaration binds, and a static analyzer reports a bug as a path through definitions and uses. The correctness of these tools depends on the representations they build. An LLM builds no representation that a developer can inspect. It has no symbol table and no scope resolver, only one hidden vector per token at each layer, from which the next token is predicted. A recent survey concludes that reliable

Authors' Contact Information: Prateek Kumar Rajput, University of Luxembourg, Luxembourg; Yewei Song, University of Luxembourg, Luxembourg; Jacques Klein, University of Luxembourg, Luxembourg; Tegawendé F. Bissyandé, University of Luxembourg, Luxembourg.

Prateek Kumar Rajput, Yewei Song, Jacques Klein, and Tegawendé F. Bissyandé

systems will have to combine LLMs with traditional program analyses [9], and such a combination requires knowing how what the model represents relates to what the analyses compute.

Figure 1(a) shows the kind of question we study. A developer who adds a configuration to this command builder needs the exact list the call returns in order to write the regression test, which means following the selected variable through the call and keeping the order of the arguments. Code models answer such output-prediction questions well [15, 27, 38], and StarCoder2-15B [29] is correct on 97.8% of the programs in our test set. When it is wrong, however, the developer cannot inspect which list the model associated with arguments, and when the model is asked to rename primary throughout the program, nothing shows whether its internal representation of the program changed accordingly. Studies that perturb the input show the consequences. Neural models of code change their predictions when variables are renamed [40, 58], and current code models track data flow and control flow poorly under counterfactual tests [21]. Whether a model's hidden state is organized by the same bindings a compiler tracks therefore determines how tools built on these models can be checked. If it is, program analysis can be used to inspect, test, and correct the model's internal state. If it is not, such tools can only be validated through their outputs.

Most of the available evidence comes from probing. A classifier is trained on frozen hidden states to predict syntactic or data-flow properties, and its accuracy is taken as a measure of what the model encodes [1, 3, 10, 25, 28, 30, 31, 37, 43, 50, 52, 53]. A probe shows that the information is present. It does not show that the model uses it, because part of the accuracy can come from the probe itself [19], and it offers no way to change what the model has encoded.

In this paper, we take a different approach, summarized in Figure 2. We label every token of a program with the information a standard Python analyzer computes for it, namely its position in the abstract syntax tree, its enclosing scope, its definition-use record, and its syntactic category, obtained from the CPython parser, LibCST, and Beniget with no parser written for the task. We then fit a decomposition that expresses each hidden state of a frozen model as a sum of terms, one per token, each combining the token with its structural label. Such a sum is a tensor product representation in the sense of Smolensky [45], in which the label is called the token's role, and we fit it with the DISCOVER procedure of McCoy et al. [33]. We call labels built from static analysis SE roles and the baseline labels, which record only token positions, positional roles. The test is behavioral. We substitute the decomposition for the model's own states at every layer while the model predicts a program's output, and we count how often the model still produces the correct answer. Because the labels describe program structure, the decomposition can also be edited in the same way a refactoring tool edits source code. We can rebind the argument of a call, or rename a variable, in the decomposition and check whether the model's answer changes accordingly.

We apply this test to 14 open models with 2B to 32B parameters. Seven are trained for code, and six of them are paired with a general-purpose model from the same family (Llama, Qwen2.5 at 3B and at 32B, Gemma, DeepSeek, and Yi). The seventh pair, StarCoder2-15B and Qwen2.5-14B, crosses families. The task is a set of small list-manipulation programs whose expected outputs are obtained by executing them, which allows us to withhold specific combinations of values and positions from the fit and to align edits token by token. The baseline is a decomposition of the same size built from positional roles. The study addresses four research questions.

RQ1 Does a decomposition built from SE roles preserve the model's answers better than one built from positional roles? If it does, the information computed by program analysis describes the model's internal state better than token positions do, which is a prerequisite for using program analysis to inspect such models.

RQ2 Does the fitted decomposition generalize to combinations of values and positions it was never fitted on, and which of its terms carry that generalization? A decomposition that only reproduces the combinations seen during fitting could not be applied to new programs. The ablation of unseen terms shows whether the roles themselves account for the generalization.

RQ3 Do edits made on the decomposition change the model's answer as the corresponding source edit would? This question is the most relevant one for tool support. If rebinding an argument or renaming a variable in the model's state changes the answer in the same way as the corresponding source edit, the state can be edited and tested as a refactoring engine edits source code.

RQ4 Is the effect stronger in models trained for code than in their general-purpose counterparts? A consistent difference within the pairs would indicate that the structure is related to training on code, with the caveat that the paired models differ in more than their training data.

The results are consistent across five model families and reversed in one. SE roles preserve the model's answers better than positional roles in ten of the 14 models, including six of the seven code models, by 5.2 to 38.3 percentage points. On StarCoder2-15B the decomposition preserves 79% of the correct answers, compared with 52% for positional roles, and removing the definition-use information from the labels costs 18.3 and 28.9 points on the two models tested. The decomposition generalizes to withheld combinations in two different ways, one for literal values and one for variable names. Rebinding an argument in the decomposition makes the model produce the new answer more often than the positional edit does in all nine non-Qwen models, and when a rename breaks the program so that its output changes, the model's answer changes accordingly more often under SE roles in all 14. Edits that change a literal value do not benefit from SE roles. In six of seven pairs the advantage is larger in the code model. The Qwen2.5 family is the exception on rebinding, on the variable-name generalization, and on preservation below 32B. In all 14 models the SE decomposition reconstructs the hidden states less accurately than the positional one, so selecting by reconstruction error alone would have favored the wrong decomposition.

This paper makes three contributions.

  • A role scheme for decompositions of hidden states built from standard static analyses, with no task-specific parser, and a positional baseline of equal size against which it is measured.

  • A study of 14 code and general-purpose models with the controls needed to interpret the result, namely removal of the definition-use field, an ablation that removes the terms absent from the training data, control edits whose expected output changes, and no-op and oracle-state checks.

  • A replication package with the code, the protocol and seeds, the frozen corpora, and the per-program predictions behind every table.

The study is limited to one synthetic task, one training seed per condition, and a capped training budget, and the result depends on the model family. The remainder of the paper is organized as follows. Section 2 presents the background and the running example, Section 3 the role scheme, Section 4 the study design, Section 5 the results, and Sections 6 to 8 the discussion, threats to validity, and related work.

References (40)