本文介绍了“差异覆盖率”,这是一种调试技术,通过将失败测试的代码覆盖率剖析数据与通过测试的进行对比,从而隔离出仅在失败用例中出现的代码块。作者以 Go 语言为例进行了演示:对比两个覆盖率剖析文件,并使用 go tool cover -html 查看结果,成功地将一个植入的 bug 从 15000 多行代码缩小到 10 行。虽然该技术并非万无一失(例如,数据依赖型的 bug 或不敏感的测试可能会漏网),但它计算成本低廉,能节省大量调试时间。
I have been debugging some code I did not write and was reminded of this technique.
I’m sure it’s a very old debugging technique (like bisection),
but it should be more widely known.
Suppose you have one test case that’s failing.
You can get a sense of what code might be involved by comparing the code coverage
of successful tests with the code coverage of the failing test.
For example, I’ve inserted a bug into my development copy of math/big:
Let’s collect a passing and failing profile:
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
AI 摘要This post proves the correctness of uscale, a fast unrounded scaling algorithm based on a 64×128-bit multiplication and floating-point approximation, which underlies the author's floating-point printing and parsing algorithms (FixedWidth, Short, and Parse). The proof proceeds through a series of lemmas handling exact results, small positive and negative powers, and finally the large-power cases, which cannot be exhaustively tested directly. For those large-power cases, the author uses the Ivy calculator—an APL-inspired language with arbitrary-precision rationals and right-to-left precedence—to implement a two-step approach, loosely following work by Vern Paxson and Tim Peters, that solves a 'modular search' problem to find the first satisfying value and a 'modular minimum' problem to verify all relevant inputs.
AI 摘要This article presents fast floating-point printing and parsing algorithms built on a new primitive called fast unrounded scaling, which approximates scaling by powers of ten, often in a single 64-bit multiplication. These simple algorithms reportedly outperform all prior known methods, including Dragon4, Grisu3, Ryū, Schubfach, and Dragonbox, and the author plans to include a Go implementation in Go 1.27. The post walks through the necessary concepts (fixed-point and floating-point numbers, unrounded numbers) and outlines implementations for fixed-width and shortest-width printing as well as decimal parsing.
AI 摘要This article is a reply to Donald Knuth's 1989 paper on proving the correctness of a program that converts 16-bit fixed-point binary fractions to their shortest accurate decimal representations, written in honor of Knuth's 88th birthday. The author presents what they argue is a better proof of Knuth's program P2 by starting with a simpler program that has a trivial direct correctness proof—implemented in the APL-like Ivy language—and then transforming it into P2 step by step, proving each transformation correct. The post also explores alternative solutions and concludes with reflections on how language and notation shape programs and proofs.
AI 摘要The article introduces the 'Floating Point Formatting' blog series, which began in 2011 and continued with new posts in 2026. It lists four posts covering topics such as floating-point to decimal conversion, a proof inspired by Knuth's fixed-point printer, simple and fast floating-point printing and parsing, and a proof of fast unrounded scaling verified with Ivy.
AI 摘要The article traces the history of debugging with binary search, from bisecting data (such as finding one bad punched card among a thousand) to bisecting version history, which was popularized by tools like git bisect that automatically pinpoint the commit that introduced a bug. It then introduces a new trick for debugging in a different dimension: hash-based bisecting of program locations, which selectively enables or disables subsets of program lines, call stacks, or code sequences to identify exactly which code causes a failure. Illustrated with a Go toolchain example, this technique is presented as a 'magic wand' for debugging large, opaque test failures in unfamiliar code bases, compilers, and runtimes.