Skip to content

Support external library contracts in Latte and LiquidTypeChecking - #35

Merged
alcides merged 1 commit into
feat/latte-liquid-typecheckingfrom
feat/external-library-refinements
Dec 2, 2026
Merged

alcides merged 1 commit into
feat/latte-liquid-typecheckingfrom
feat/external-library-refinements

Conversation

@alcides

@alcides alcides commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

External library specifications were previously rejected as unsupported. This change lets application code refine JDK and third-party library methods, constructors and fields through @ExternalRefinementsFor, using the same contracts in Latte and LiquidTypeChecking. For example, an ArrayList transition through a local alias is visible when checking the original variable's size.

  • Resolve and validate Java signatures, overloads, inherited members and field types in a per-model registry stored on Spoon's AST. Placeholder bodies and field initializers do not become implementation facts.
  • Apply ownership contracts to external parameters and results, including constructor parameters. Preserve shared-object rejection, borrowed mutation effects and consumption of all caller aliases on @Free transfers.
  • Check parameter/result refinements, state transitions and state sets. Include external calls and constructor effects in loop analysis, and retain conservative global and unknown-call effects.
  • Add CLI/API classpath support and analyze separate specification/application paths together. A test builds a library JAR and verifies both API and CLI use without initializing the library.
  • Add checked examples, an external-specification guide, 42 focused tests and 15 promoted upstream inputs. All 410 imported fixture sources remain unchanged.

Validation: mvn -B spotless:apply clean verify -Pcompatibility passes with 522 tests, zero failures/errors, and 180/311 exact upstream matches (previously 165), with zero analysis crashes. The compatibility gate still checks every imported input and rejects newly accepted negative cases.

Library specifications are trusted contracts. Container-size specifications do not infer element ownership or return aliases. Expanded varargs calls require explicit arrays; varargs method references require an explicit-array lambda. These boundaries are documented and unsupported adapters are diagnosed explicitly.

This PR is stacked on feat/latte-liquid-typechecking, whose completed implementation was pushed as 1eb2448. Its diff contains only external-library support and related integration fixes. CI also runs for PRs targeting that base.

@alcides
alcides merged commit b2055c1 into feat/latte-liquid-typechecking Dec 2, 2026
1 check passed
alcides added a commit that referenced this pull request Dec 2, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant