Loop invariant inference for int locals (Liquid Types / Houdini)
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 18/100
Direção de pesquisa
Read RefinementTypeChecker.visitLoop, havocChangedIn and forgetChanges first: today known is always true at the loop head, and this issue is about filling it with an inferred inductive invariant. The work is a multi-PR design (candidates, Houdini start/step checks plugged into checkUntilFixpoint, post-loop facts), with sub-issues #543-#548 and prerequisite #538; start by reading the Liquid Types and Houdini papers named here plus the test programs in #537 and #479. Done means for (int i = 0; i < 10; i++) use(i) verifies without the i == -1 counterexample and no unsound program is accepted.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Goal
Infer loop invariants for int local variables, so that ordinary loops verify without annotations:
for (int i = 0; i < 10; i++)
use(i); // use(@Refinement("_ >= 0") int x): today "found i < 10", counterexample i == -1
Today a loop havocs every variable it changes: at the loop head the variable gets a fresh instance that keeps only its declared refinement (RefinementTypeChecker.visitLoop → havocChangedIn → forgetChanges(name, known, loop), where known is always true). Inside the body only the loop condition is known about it, so i >= 0 is lost (#537, part of #479). The plan is to fill known at the loop head with an inferred invariant.
Approach: liquid inference / Houdini
This is how Liquid Types infers refinements (Rondon, Kawaguchi, Jhala, Liquid Types, PLDI 2008; LiquidHaskell): conjunctions of qualifiers from a finite set, kept only if they can be proved. The fixed-point step is the Houdini algorithm (Flanagan and Leino, Houdini, an Annotation Assistant for ESC/Java, FME 2001).
- Candidates for each
intlocalxthe loop changes:x >= x_pre,x <= x_pre, wherex_preisx's instance just before the loop (works for symbolic start values too).- The comparisons of the loop condition, weakened to be inductive (
i < ngives the candidatei <= n). - What the body requires of
x(a refined parameter_ >= 0that receivesigivesi >= 0;_ < size(this)givesi < size(l)).
- Start check: drop each candidate the facts before the loop do not prove for
x_pre. - Step check: check the body with the remaining candidates assumed at the head (with the loop condition); at the back edges (end of the body, after a
for's update, eachcontinue) drop each candidate not proved forx's last instance. Repeat until nothing is dropped. This plugs into the existingcheckUntilFixpointloop, which already re-checks the body until typestates stop changing and discards the errors of trial checks. - Use: what survives is the
knownfact of the loop-head instance. After a loop withoutbreak, the instance after the loop also knows the invariant and the negated condition.
Soundness: a candidate survives only if it is proved at the start and preserved by every iteration, so the result is inductive. Wrong guesses can only cost precision, never accept a wrong program. Integers are mathematical integers, as elsewhere in LiquidJava (overflow is not modelled).
Cost: each round checks the body once plus one SMT query per candidate. Rounds only drop candidates, so they terminate; candidates and rounds are capped for IDE response time and nested loops.
Scope (PM decision, 2026-11-23)
intlocal variables only.- No fields (a call can change them out of sight; they stay havocked).
- Object ghosts (e.g.
size(l)) appear only as bounds in candidates; inferring facts about ghosts is out of scope.
Plan: one small PR per sub-issue
Sub-issues are listed below, in order. Each PR builds on the previous one.
Test programs: #537 (counter, accumulator), #479 (i < l.size() and l.get(i)), #538 (guarded accumulation), and the buffer-filling loop from #537.
| Order | Issue | Part |
|---|---|---|
| 0 | #538 | Prerequisite: keep the version-based copy of a path condition when a variable is reassigned (independent of loops) |
| 1 | #543 | Candidate invariants |
| 2 | #544 | Houdini check at the loop head (fixes #537) |
| 3 | #545 | Invariant and negated condition after a loop without break |
| 4 | #546 | Candidates from what the body requires (#479) |
| 5 | #547 | Cost caps and nested loops |
| 6 | #548 | Error messages (needs a PM decision) |
- Linguagem predominante
- Java
- Estrelas
- 73
- Forks
- 38
- Merge médio
- 12h 32min
- PRs com merge (30d)
- 45
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de liquid-java/liquidjava
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
liquid-java/liquidjava#562 ·
Mantenedores costumam responder em até 1 dia
-
A float ghost crashes the verifier: "Ghost not implemented for type float"Talvez já em andamento @MohammedZaid1740 assumiu há 7 dias. Abertabug good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
liquid-java/liquidjava#443 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
bug real-world-finding
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
liquid-java/liquidjava#395 ·
Mantenedores costumam responder em até 1 dia
-
A ternary between arrays crashes: Sorts (Array Int Int) and Bool are incompatibleTalvez já em andamento @CatarinaGamboa assumiu há 4 dias. Abertabug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 15/100
liquid-java/liquidjava#558 ·
Mantenedores costumam responder em até 1 dia
-
new T[a][b] gets length b instead of a (unsound)Talvez já em andamento @CatarinaGamboa assumiu há 4 dias. Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 30/100
liquid-java/liquidjava#557 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de liquid-java/liquidjava
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 60/100
quelea-projection/Quelea#749 ·
Mantenedores costumam responder em até 1 dia
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
erkamyaman/rust-anything#963 ·
Mantenedores costumam responder em até 1 dia
-
api-diagnostics bug jdbc
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
ClickHouse/clickhouse-java#3464 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 Meio dia Facilidade para iniciantes 76/100
-
Deferred
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Sanne/incus-spawn#2768 ·
Mantenedores costumam responder em até 1 dia