Skip to content

Commit 2d4c696

Browse files
authored
Add Java 21 library contracts and external effect summaries (#36)
## Description Library calls previously lost local ownership and refinement facts when their mutation effects or returned aliases were unknown. Add `@Modifies` footprints and `@ReturnsView` relationships shared through Spoon's AST, and use them in Latte and LiquidTypeChecking. Local array copies, borrowed constructor inputs and ArrayList views retain the information needed by later checks. Target Java 21 in the build and CI. Add an opt-in, package-selectable Java SE 21 catalog covering all 178 packages, 4,055 API types and 47,030 member entries: 501 stronger declarations across 190 types, including 443 mutation footprints, with explicit conservative policies elsewhere. Generated inventories and audit reports are marked for GitHub's generated-file handling. Also fix the array-constructor metadata null dereference and deep solver-translation stack overflow. Include checked examples, catalog generation/validation tools, runtime witnesses, documentation and a replay of the original 1,481 OpenJDK test sources. The follow-up in [docs/jdk21-effects-followup.md](docs/jdk21-effects-followup.md) records specific improvements and remaining limitations. Branch-dependent aliases and repeated allocation summaries remain imprecise. Read-only calls still reject overlapping borrowed arguments such as `Arrays.equals(values, values)`; this PR documents that gap rather than claiming it is fixed. ## Example With `--jdk all`, this now verifies because the local view captures its backing list without making it shared: ```java var root = new java.util.ArrayList<Integer>(); var view = root.subList(0, 0); root.add(42); ``` The backing-list mutation invalidates the view for subsequent checked operations. Footprints do not imply freshness; ownership and return-view guarantees remain separate annotations. ## Related Issue Stacked on #35, targeting `feat/external-library-refinements`. The diff contains the Java 21 catalog, effect/view support and follow-up fixes and audits. CI is enabled for this PR base. ## Type of change - [x] Bug fix - [x] New feature - [x] Documentation update - [x] Code refactoring ## How Has This Been Tested? - Java 21 Maven verification and compatibility profile: **616 tests, zero failures/errors/skips**, Spotless passes, **180/311 exact upstream compatibility matches**. The remaining mismatches are documented, not counted as successes. - The tested source/catalog files are unchanged since the verified build; subsequent edits are documentation and the CI branch trigger. - Replayed exactly **1,481 unchanged OpenJDK sources**, with and without the catalog: **1,460 completed pairs**, 20 catalog timeouts and one existing Spoon type-erasure failure. These are source analyses, not execution or proof of the complete jtreg suite. - On the same **1,389 previously completed files**, after reviewed expected-exception exclusions, ownership/state diagnostics increase from **1,052 to 1,168** as additional calls are checked. `Arrays/FloatDoubleOrder.java` becomes diagnostic-free; 14 previous diagnostics disappear from now-clear lines. The report does not claim an overall reduction. - Recorded **17 focused reproductions**, including four controlled comparisons with only the effect/view annotations removed. - Validated audit hashes/counts, documentation links, Java 21 workflow configuration and staged whitespace.
1 parent 89ded1e commit 2d4c696

447 files changed

Lines changed: 656819 additions & 66 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitattributes‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Rebuild with latte.jdk.Jdk21Inventory; review the generator and stronger Java contracts directly.
2+
specifications/jdk21/api/*.json linguist-generated=true
3+
specifications/jdk21/api-types.txt linguist-generated=true
4+
specifications/jdk21/inventory.json linguist-generated=true
5+
specifications/jdk21/packages.json linguist-generated=true
6+
specifications/jdk21/migration-from17.json linguist-generated=true
7+
specifications/jdk21/baseline-java17.json.gz linguist-generated=true
8+
docs/jdk21-coverage.md linguist-generated=true
9+
# Recorded OpenJDK test-source audit; see docs/jdk21-upstream-audit.md for interpretation.
10+
audits/jdk21-upstream/*.json linguist-generated=true

‎.github/workflows/maven-2.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push:
44
branches: [main]
55
pull_request:
6-
branches: [main, feat/latte-liquid-typechecking]
6+
branches: [main, feat/latte-liquid-typechecking, feat/external-library-refinements]
77

88
jobs:
99
verify:
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- uses: actions/setup-java@v4
1414
with:
15-
java-version: '17'
15+
java-version: '21'
1616
distribution: temurin
1717
cache: maven
1818
- name: Verify and audit upstream compatibility

‎README.md‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The verifier now covers floating-point arithmetic, exception and switch flow, de
66

77
## Build and run
88

9-
Use JDK 17 or newer and Maven 3.9 or newer:
9+
Use JDK 21 and Maven 3.9 or newer:
1010

1111
```sh
1212
cd latte
@@ -15,11 +15,11 @@ java -jar target/latte-cli.jar ../examples/refinements/LocalAliases.java
1515
java -jar target/latte-cli.jar ../examples/refinements/StaleAliasRejected.java
1616
```
1717

18-
The first example succeeds. The second reports a state refinement failure and exits with status 1. Add `--explain` to include the proof obligation and solver counterexample. Each path is a separate analysis; pass a source directory to analyze related classes together. Parsing failure and unsupported analysis also produce a nonzero exit status.
18+
The first example succeeds. The second reports a state refinement failure and exits with status 1. Add `--explain` to include the proof obligation and solver counterexample. Multiple input paths are analyzed together in one Spoon model; source directories can contain related application classes and external specifications. Parsing failure and unsupported analysis also produce a nonzero exit status.
1919

2020
The small library jar is `target/latte-0.0.1-SNAPSHOT.jar`. The runnable `latte-cli.jar` also includes Spoon and Z3, including the native solver libraries supplied by `z3-turnkey`.
2121

22-
`mvn test` runs 522 tests, including the focused tests, legacy Latte regressions and 180 promoted upstream regression inputs. A separate imported-fixture test enforces the intentional fresh-reference comparison difference. `mvn verify -Pcompatibility` also runs **every** imported input and writes `target/liquidjava-compatibility.json`. A successful build does not mean that all upstream expectations match.
22+
`mvn test` runs 616 tests, including the focused tests, Java 21 catalog checks and runtime witnesses, legacy Latte regressions and 180 promoted upstream regression inputs. A separate imported-fixture test enforces the intentional fresh-reference comparison difference. `mvn verify -Pcompatibility` also runs **every** imported input and writes `target/liquidjava-compatibility.json`. A successful build does not mean that all upstream expectations match.
2323

2424
## Ownership policy
2525

@@ -69,6 +69,10 @@ class Example {
6969

7070
Use `@ExternalRefinementsFor` to provide ownership and refinement contracts for JDK or third-party library methods, constructors and fields. Both passes resolve the same contracts on the Spoon AST. See the [external contract guide](docs/external-refinements.md) and [checked examples](examples/refinements/ExternalLibraryContracts.java). Use `--classpath` for library JARs; multiple input paths are analyzed together.
7171

72+
The opt-in [Java 21 catalog](docs/jdk21-contracts.md) covers **all 178 Java SE packages**: 4,055 API types and 47,030 member entries. It combines **501 stronger declarations for 190 types** with explicit conservative policies for the remaining API. Use `--jdk all` or exact package selections such as `--jdk java.lang,java.util`. The [coverage inventory](docs/jdk21-coverage.md) distinguishes complete API classification from stronger behavioral guarantees. Coverage and effective call policies are stored on the Spoon AST. The [effect inventory](docs/jdk21-effects.md) records 443 explicit mutation footprints, captured ArrayList views and the remaining conservative boundaries.
73+
74+
The [OpenJDK test-source audit](docs/jdk21-upstream-audit.md) records how these contracts affect unchanged Java 21 tests, including expected call-domain failures, ownership/precision limits and analyzer failures.
75+
7276
## AST handoff and embedding
7377

7478
```java
@@ -85,6 +89,8 @@ for (var local : result.model().getElements(
8589

8690
`LatteFacts.KEY` is `latte.analysis.facts.v1`. Evaluated expressions, declarations and statements retain immutable `before` and `after` ownership stores and their reference identity. `LiquidTypeChecking` reads this metadata; it does not rerun ownership analysis. These facts belong to a particular AST and source position. Reanalyze after editing the AST. An unvisited or unsupported node must not be treated as having a successful ownership proof.
8791

92+
External contracts can declare `@Modifies` footprints and `@ReturnsView` capture relationships; see the [annotation guide and checked examples](docs/external-refinements.md#explicit-mutation-footprints-modifies). View identities, backing edges and operation summaries are retained on the same Spoon AST.
93+
8894
`MutationEffects.KEY` is `latte.analysis.effects.v1`. Source method declarations retain immutable summaries of the receiver, parameters and global storage they can change, including transitive calls and source overrides.
8995

9096
`ConstructionFacts.KEY` is `latte.analysis.construction.v1`. Constructor calls retain mappings from transferred ownership identities to their consumed caller identities, allowing the refinement pass to preserve state under the new owner. Constructor evaluation uses call-specific bindings without overwriting the declaration's published facts.
@@ -93,6 +99,8 @@ for (var local : result.model().getElements(
9399

94100
`ClosureFacts.KEY` is `latte.analysis.closure.v1`. Closures record their captured binding names and whether execution can be deferred or escape. Capture references are stored as immutable `capture:` heap edges in `LatteFacts`. `ClosureInvocation.KEY` is `latte.analysis.closure.call.v1`; local calls retain their possible closure targets, captured references, mutations, ownership transfers and separate body facts for each invocation. LiquidTypeChecking reads these facts from the same AST.
95101

102+
`Jdk21Coverage.KEY` is `latte.jdk21.coverage.v1`. With `--jdk`, the model retains the complete API ledger and selected packages. `Jdk21Coverage.use(reference)` reports the effective external-contract, conservative or outside-baseline policy on each selected library executable/field reference. The ownership pass uses this metadata to avoid assuming that unmodeled JDK constructors keep their receivers local.
103+
96104
`Verification.Result` retains the model and structured, source-located diagnostics. Analysis does not rewrite source files. The old `api.App.launcher` entry point delegates to this pipeline.
97105

98106
## Implementation

0 commit comments

Comments
 (0)