Skip to content

Commit 1eb2448

Browse files
committed
Implement Latte ownership preprocessing and independent refinement checking
1 parent c8fc5b1 commit 1eb2448

516 files changed

Lines changed: 22030 additions & 2688 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.

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

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,28 @@
1-
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3-
4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
8-
9-
name: Java CI with Maven
10-
1+
name: Java verification
112
on:
123
push:
13-
branches: [ "main" ]
4+
branches: [main]
145
pull_request:
15-
branches: [ "main" ]
6+
branches: [main]
167

178
jobs:
18-
build:
19-
9+
verify:
2010
runs-on: ubuntu-latest
21-
2211
steps:
23-
- uses: actions/checkout@v4
24-
- name: Set up JDK 17
25-
uses: actions/setup-java@v4
26-
with:
27-
java-version: '17'
28-
distribution: 'temurin'
29-
cache: maven
30-
- name: Build with Maven
31-
working-directory: latte
32-
run: mvn -B package --file pom.xml
33-
- name: Run tests with Maven
34-
working-directory: latte
35-
run: mvn test --file pom.xml
36-
- name: Upload test results
37-
if: always() # This ensures the test results are uploaded even if tests fail
38-
uses: actions/upload-artifact@v4.6.2
39-
with:
40-
name: test-results
41-
path: latte/latte/target/test-*.xml # Maven Surefire generates the test result files here
42-
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
43-
- name: Update dependency graph
44-
run: |
45-
cd latte
46-
mvn com.github.ferstl:depgraph-maven-plugin:4.0.1:graph
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-java@v4
14+
with:
15+
java-version: '17'
16+
distribution: temurin
17+
cache: maven
18+
- name: Verify and audit upstream compatibility
19+
working-directory: latte
20+
run: mvn -B clean verify -Pcompatibility
21+
- name: Upload verification reports
22+
if: always()
23+
uses: actions/upload-artifact@v4.6.2
24+
with:
25+
name: verification-reports
26+
path: |
27+
latte/target/surefire-reports/
28+
latte/target/liquidjava-compatibility.json

‎README.md‎

Lines changed: 66 additions & 162 deletions
Large diffs are not rendered by default.

‎docs/compatibility.md‎

Lines changed: 163 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import liquidjava.specification.Refinement;
2+
import specification.*;
3+
4+
class BorrowedAndUnique {
5+
@Unique @Refinement("_ != null") Object owned;
6+
7+
BorrowedAndUnique(@Free @Refinement("_ != null") Object value) {
8+
owned = value;
9+
}
10+
11+
void borrow(@Borrowed @Refinement("_ != null") Object value) {
12+
@Refinement("_ != null") Object localAlias = value;
13+
}
14+
15+
void use() {
16+
@Refinement("_ != null") Object local = new Object();
17+
borrow(local);
18+
@Refinement("_ != null") Object stillLocal = local;
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import liquidjava.specification.*;
2+
3+
/** Latte joins aliases without retaining the guard that selected each possible object. */
4+
class BranchOwnershipLimit {
5+
@StateSet({"open", "closed"})
6+
static class Resource {
7+
@StateRefinement(to = "open(this)") Resource() {}
8+
@StateRefinement(from = "open(this)") void read() {}
9+
}
10+
11+
void joined(boolean chooseLocal, Resource shared) {
12+
Resource local = new Resource();
13+
Resource selected = chooseLocal ? local : shared;
14+
if (chooseLocal) {
15+
selected.read(); // Expect: SHARED_REFINEMENT
16+
}
17+
}
18+
19+
void keptInsideBranch(boolean chooseLocal, Resource shared) {
20+
Resource local = new Resource();
21+
if (chooseLocal) {
22+
Resource selected = local;
23+
selected.read();
24+
}
25+
}
26+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import liquidjava.specification.*;
2+
import specification.*;
3+
4+
/** Constructors preserve stored argument aliases and consume arguments declared @Free. */
5+
class ConstructorAliases {
6+
@StateSet({"open", "closed"})
7+
static class Resource {
8+
@StateRefinement(to = "open(this)") Resource() {}
9+
@StateRefinement(from = "open(this)") void read() {}
10+
@StateRefinement(from = "open(this)", to = "closed(this)") void close() {}
11+
}
12+
13+
static class Box {
14+
@Unique Resource value;
15+
Box(@Unique Resource value) { this.value = value; }
16+
@Borrowed Resource get() { return value; }
17+
}
18+
19+
static class Owner {
20+
@Unique Resource value;
21+
Owner(@Free Resource value) { this.value = value; }
22+
@Borrowed Resource get() { return value; }
23+
}
24+
25+
void storedAlias() {
26+
Resource original = new Resource();
27+
Box box = new Box(original);
28+
box.get().read();
29+
box.get().close();
30+
original.read(); // Expect: STATE
31+
}
32+
33+
void transferredOwnership() {
34+
Resource original = new Resource();
35+
Owner owner = new Owner(original);
36+
owner.get().read();
37+
owner.get().close();
38+
Object stale = original; // Expect: PERMISSION
39+
}
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import liquidjava.specification.*;
2+
3+
class ControlFlowAndFloatingPoint {
4+
@Refinement("_ == 3")
5+
static int cleanup() {
6+
try { return 1; }
7+
finally { return 3; }
8+
}
9+
10+
static void example() {
11+
@Refinement("_ != 0.3") double rounded = 0.1 + 0.2;
12+
@Refinement("_ != _") double nan = Double.NaN;
13+
int count = 0;
14+
while (count < 10) count++;
15+
@Refinement("_ == 10") int completed = count;
16+
int selected = switch (completed) {
17+
case 10 -> cleanup();
18+
default -> 0;
19+
};
20+
@Refinement("_ == 3") int result = selected;
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java.util.Properties;
2+
import liquidjava.specification.Refinement;
3+
4+
class EscapeRejected {
5+
void unsafe() {
6+
Properties local = new Properties();
7+
Properties alias = local;
8+
System.setProperties(local);
9+
@Refinement("_ != null") Object escaped = alias; // Expect: SHARED_REFINEMENT
10+
}
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import liquidjava.specification.*;
2+
3+
// Field functions describe Java storage, and aliases observe the same updates.
4+
class FieldStateAndArrays {
5+
int count;
6+
7+
@StateRefinement(to = "count() == initial")
8+
FieldStateAndArrays(int initial) { count = initial; }
9+
10+
@PrivateRefinement("this.count == next")
11+
@StateRefinement(to = "count() == next")
12+
void set(int next) { count = next; }
13+
14+
static void example() {
15+
FieldStateAndArrays original = new FieldStateAndArrays(2);
16+
FieldStateAndArrays alias = original;
17+
alias.set(5);
18+
@Refinement("_ == 5") int observed = original.count;
19+
20+
int[] values = {1, 2};
21+
int[] same = values;
22+
same[0] = observed;
23+
@Refinement("_ == 5") int element = values[0];
24+
}
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import specification.*;
2+
3+
/** No Java fields are cleared by inference: only unobservable ownership edges are forgotten. */
4+
class InferredOwnershipRelease {
5+
static final class Box {
6+
@Unique Object value;
7+
Box(@Unique Object value) { this.value = value; }
8+
}
9+
10+
@Unique Box head;
11+
12+
static void consume(@Free Object value) {}
13+
static void inspect(@Borrowed Object value) {}
14+
15+
@Free Object abandonedLocal() {
16+
Box box = new Box(new Object());
17+
return box.value; // Accepted: nothing can observe box again.
18+
}
19+
20+
@Free Object detachedNode() {
21+
Box old = head;
22+
Object value = old.value;
23+
head = null; // This clear is still necessary: this survives the call.
24+
return value; // Accepted without old.value = null: old is now unobservable.
25+
}
26+
27+
@Free Object survivingContainer() {
28+
return head.value; // Expect: PERMISSION
29+
}
30+
31+
void survivingLocalAlias() {
32+
Box box = new Box(new Object());
33+
Box alias = box;
34+
consume(box.value); // Expect: PERMISSION
35+
inspect(alias);
36+
}
37+
}

0 commit comments

Comments
 (0)