arXiv Science⌕ Search

arXiv · 2611.37595

A View from the Bridge: Detecting Boundary Type Errors in Native Extensions of Dynamic Languages

Abstract

Programs written in dynamic languages, such as Python and JavaScript, often rely on native extensions written in C, C++ or Rust for performance or access to system libraries. Native code accesses the raw memory of the values it receives from the host, so before using a value, it must check the value's tag, which determines its memory layout. When this check is missing, or accepts tags incompatible with the one that the native code later assumes, a boundary type error occurs, and the program crashes or silently corrupts its data. Our key insight is that finding these errors requires no inference of host-language types. Native code must check every value it obtains from the host, so the code itself provides all the information we need: its checks indicate which tags a value may have, while its operations reveal which tag they assume. We capture what native code does with host values in XLIR, a small language in which we define boundary type errors. We then detect them with a flow-sensitive analysis that tracks the tags each check establishes. At each operation, we encode whether some value can pass the preceding checks yet violate the tag that the operation assumes as a satisfiability problem, which we solve with an SMT solver. We have implemented our approach in a tool called Xtypecheck, which analyzes the LLVM IR of Node.js and CPython extensions. It detects all 72 known errors in an existing JavaScript benchmark and 33 of 42 reported in fixed GitHub issues of popular PyPI packages. In the wild, Xtypecheck finds thousands of previously unknown type errors in the native code of 268 npm and 204 PyPI packages and in the built-in standard library extensions of CPython and Node.js. It analyzes most extensions in under ten seconds, and the errors it finds range from hard crashes to silently incorrect output. We have filed 58 issues in 45 of these projects, of which 26 have been fixed.

Explore related subjects

Keep this discovery

Explore connections, maps & timelines

BibTeXRIS

Thodoris Sotiropoulos, Georgios Alexopoulos, Dimitris Mitropoulos. 2026-11-27. A View from the Bridge: Detecting Boundary Type Errors in Native Extensions of Dynamic Languages. https://arxiv.science/abs/2611.37595

Citations retain the original authors and DOI and include this site’s record URL. If this discovery service contributed to your research, you can also cite arXiv Science by Indiciae: BibTeX · RIS.

KEEP EXPLORING

Related papers

What is a Good Projection?: Correctness and Separation Results of End-Point Projections

Multiparty session types (MPST) is a type discipline for ensuring distributed programs are implemented correctly by construction. MPST starts by specifying a choreographic protocol as a global type and projects it onto each participant, generating local types with a guarantee of type soundness and deadlock-freedom. A central issue of MPST is that its type soundness is fragile, as it must be proven each time with respect to a chosen projection algorithm under specific semantics with a specific program correctness goal. To overcome this problem, we propose general criteria for a good projection -- a set of requirements for projection algorithms by which type soundness, deadlock-freedom and liveness of distributed programs are automatically derived. Using the criteria, we prove that 8 distinct projections in the literature are good under both synchronous and asynchronous semantics, and that 4 are incorrect, failing type soundness. We extend the good projection criteria to mixed choice global types and asynchronous communication optimisations, proposing new ``good projection'' algorithms. We apply properties of good projections to prove separation and expressiveness results over the projection algorithms and MPST typing systems. Having a generalised typing system that is robust with respect to the good projection criteria, we provide an implementation with mixed choice global types that is modular with respect to a chosen projection algorithm and desired program properties. Our separation results help programmers make informed trade-offs between complexity and expressiveness when choosing projection algorithms, and our theory ensures their chosen algorithms are correctly applied.

cs.PL↗

Named Commutative Blocks for Parallelization

This paper proposes a new way to exploit code commutativity to parallelize sequential programs. While prior work provided the ability to identify and exploit commutative function calls or adjacent code blocks, this paper describes the first method that dynamically exploits statically-verified commutativity conditions of arbitrary code regions. In this method, programmers give parameterized names to code blocks anywhere in the program, and provide commutativity expressions over those parameters and the global state. Novel algorithms exploit this commutativity and dependence information to automatically construct a program-specific parallelization scheme, yielding asynchronous tasks executed through a commutativity-aware scheduler. We furthermore show that commutativity conditions can be verified automatically, reducing reliance on manual effort and increasing confidence in correctness. We implement our approach in a new compiler and runtime system called Veracity2G that takes in a sequential program and produces a parallel version that dynamically exploits the commutativity conditions. We experimentally demonstrate that Veracity2G (i) strictly generalizes prior commutativity-based parallelization techniques, (ii) enables parallelization opportunities beyond the reach of existing methods, and (iii) automatically verifies commutativity conditions.

cs.PL↗

VAPY: Circuit Optimization with Backpropagation

Parameter sensitivities of analog circuits enable the use of gradient-based design optimization methods and unlock a range of sensitivity analyses. However, it remains a challenge to compute exact design parameter sensitivities for circuits that use PDKs, which use Verilog-A device models comprised of thousands of lines of code. Finite difference methods, which estimate gradients through simulation, require N + 1 to 2N simulations for each gradient depending on the method, which can become prohibitively expensive when many parameters are optimized. We present VAPY, a Verilog-A to JAX transpiler that compiles Verilog-A device models into autodifferentiable JAX code, enabling optimization with Circulax, a JAX-based circuit simulator. VAPY employs taint analysis to ensure only the necessary control-flow is rewritten with JAX-compatible calls, reducing control-flow overheads. We use VAPY and Circulax to optimize three analog circuits implemented in the SkyWater SKY130 PDK, which is built on the BSIM4 device model. VAPY-generated model gradients closely match finite-difference gradients, achieving comparable design quality in over 40X fewer circuit solves and up to 40% lower loss than Bayesian optimization.

cs.PL↗