Skip to content

Commit 6d9a12e

Browse files
authored
merge: Post apocalypse fixes (#1043)
2 parents 521a9ac + bf4bc75 commit 6d9a12e

32 files changed

+175
-139
lines changed

Diff for: .github/README.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ Aya is under active development, so please expect bugs, usability or performance
1818

1919
+ Dependent types, including pi-types, sigma types, indexed families, etc.
2020
You could write a [type-safe interpreter][gadt].
21-
+ Cartesian cubical type theory with generalized path types
22-
similar to a "bounded" cubical subtype.
23-
+ Implementation prototype of De Morgan cubical: [Guest0x0].
24-
+ Demonstration of higher inductive types: [3-torus] (three-dimensional torus!!).
21+
+ Set-level cubical type theory (XTT).
2522
+ Demonstration of [higher-inductive-inductive-recursive types][hiir].
2623
+ Pattern matching with first-match semantics.
2724
Checkout the [red-black tree][rbtree] (without deletion yet).
@@ -75,13 +72,11 @@ of IDE is IntelliJ IDEA, version 2023.3 or higher is required.
7572
[regularity]: ../base/src/test/resources/success/common/src/Paths.aya
7673
[funExt]: ../base/src/test/resources/success/common/src/Paths.aya
7774
[rbtree]: ../base/src/test/resources/success/common/src/Data/Tree/RedBlack/Direct.aya
78-
[3-torus]: ../base/src/test/resources/success/common/src/Spaces/Torus/T3.aya
7975
[hiir]: ../base/src/test/resources/success/common/src/TypeTheory/Thorsten.aya
8076
[assoc]: ../base/src/test/resources/success/src/Assoc.aya
8177
[foetus]: ../base/src/test/resources/success/src/FoetusLimitation.aya
8278
[mutual]: ../base/src/test/resources/success/src/Order.aya
8379
[maven-repo]: https://repo1.maven.org/maven2/org/aya-prover
84-
[Guest0x0]: https://github.com/ice1000/Guest0x0
8580
[stdlib-style]: ../base/src/test/resources/success/common
8681

8782
## Use as a library
@@ -105,7 +100,10 @@ implementation group: 'org.aya-prover', name: '[project name]', version: '[lates
105100

106101
+ `[project name]` specifies the subproject of Aya you want to use,
107102
and the options are `pretty`, `base`, `cli-impl`, `parser`, etc.
108-
+ The type checker lives in `base` and `parser`.
103+
+ The syntax definitions live in `syntax`.
104+
+ The parser lives in `parser` and `producer`.
105+
+ The type checker lives in `base`.
106+
+ The JIT compiler lives in `jit-compiler`.
109107
+ The generalized pretty printing framework is in `pretty`.
110108
+ The library system, literate mode, single-file type checker, and basic REPL are in `cli-impl`.
111109
+ The generalized tree builder, generalized termination checker,

Diff for: base/src/main/java/org/aya/primitive/PrimFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public boolean have(@NotNull ID name) {
195195
}
196196

197197
public @NotNull Term unfold(@NotNull PrimCall primCall, @NotNull TyckState state) {
198-
var id = primCall.ref().core().id;
198+
var id = primCall.ref().id();
199199
return seeds.get(id).unfold.apply(primCall, state);
200200
}
201201

Diff for: cli-console/build.gradle.kts

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
33
import org.aya.gradle.CommonTasks
44

5+
val mainClassQName = "org.aya.cli.console.Main"
6+
CommonTasks.fatJar(project, mainClassQName)
7+
application.mainClass.set(mainClassQName)
8+
59
dependencies {
610
api(project(":tools-repl"))
711
api(project(":cli-impl"))
@@ -13,3 +17,11 @@ dependencies {
1317
testImplementation(libs.junit.jupiter)
1418
testImplementation(libs.hamcrest)
1519
}
20+
21+
plugins { application }
22+
23+
tasks.withType<AbstractCopyTask>().configureEach {
24+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
25+
}
26+
27+
tasks.withType<JavaCompile>().configureEach { CommonTasks.picocli(this) }

Diff for: cli-impl/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ dependencies {
66
api(project(":base"))
77
api(project(":parser"))
88
api(libs.gson)
9-
implementation(libs.sourcebuddy)
109
implementation(project(":producer"))
1110
implementation(project(":jit-compiler"))
1211
implementation(libs.commonmark)

Diff for: cli-impl/src/main/java/module-info.java

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
requires aya.compiler;
1010
requires org.jetbrains.annotations;
1111
requires org.commonmark;
12+
requires java.compiler;
1213

1314
exports org.aya.cli.interactive;
1415
exports org.aya.cli.library.incremental;

Diff for: cli-impl/src/main/java/org/aya/cli/interactive/ReplCompiler.java

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import java.io.IOException;
5050
import java.nio.file.Files;
5151
import java.nio.file.Path;
52-
import java.util.function.Function;
5352

5453
public class ReplCompiler {
5554
public final @NotNull CountingReporter reporter;

Diff for: cli-impl/src/main/java/org/aya/cli/library/LibraryModuleLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public boolean existsFileLevelModule(@NotNull ModulePath path) {
9090
@NotNull ModulePath mod, @Nullable Path sourcePath,
9191
@Nullable Path corePath, @NotNull ModuleLoader recurseLoader
9292
) {
93-
return advisor.loadCompiledCore(reporter, mod, sourcePath, corePath, recurseLoader);
93+
return advisor.loadCompiledCore(reporter, owner, mod, sourcePath, corePath, recurseLoader);
9494
}
9595

9696
private void saveCompiledCore(

Diff for: cli-impl/src/main/java/org/aya/cli/library/incremental/CompilerAdvisor.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ default void notifyIncrementalJob(
6363
*/
6464
@Nullable ResolveInfo doLoadCompiledCore(
6565
@NotNull Reporter reporter,
66-
@NotNull ModulePath mod,
66+
@NotNull LibraryOwner owner, @NotNull ModulePath mod,
6767
@Nullable Path sourcePath,
6868
@Nullable Path corePath,
6969
@NotNull ModuleLoader recurseLoader
@@ -78,14 +78,14 @@ void doSaveCompiledCore(
7878
@ApiStatus.NonExtendable
7979
default @Nullable ResolveInfo loadCompiledCore(
8080
@NotNull Reporter reporter,
81-
@NotNull ModulePath mod,
81+
@NotNull LibraryOwner owner, @NotNull ModulePath mod,
8282
@Nullable Path sourcePath,
8383
@Nullable Path corePath,
8484
@NotNull ModuleLoader recurseLoader
8585
) {
8686
assert recurseLoader instanceof CachedModuleLoader<?>;
8787
try {
88-
return doLoadCompiledCore(reporter, mod, sourcePath, corePath, recurseLoader);
88+
return doLoadCompiledCore(reporter, owner, mod, sourcePath, corePath, recurseLoader);
8989
} catch (IOException | ClassNotFoundException e) {
9090
throw new Panic("Compiled aya found but cannot be loaded", e);
9191
}

Diff for: cli-impl/src/main/java/org/aya/cli/library/incremental/DelegateCompilerAdvisor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public void notifyIncrementalJob(@NotNull ImmutableSeq<LibrarySource> modified,
5252
}
5353

5454
@Override public @Nullable ResolveInfo
55-
doLoadCompiledCore(@NotNull Reporter reporter, @NotNull ModulePath mod, @Nullable Path sourcePath, @Nullable Path corePath, @NotNull ModuleLoader recurseLoader) throws IOException, ClassNotFoundException {
56-
return delegate.doLoadCompiledCore(reporter, mod, sourcePath, corePath, recurseLoader);
55+
doLoadCompiledCore(@NotNull Reporter reporter, @NotNull LibraryOwner owner, @NotNull ModulePath mod, @Nullable Path sourcePath, @Nullable Path corePath, @NotNull ModuleLoader recurseLoader) throws IOException, ClassNotFoundException {
56+
return delegate.doLoadCompiledCore(reporter, owner, mod, sourcePath, corePath, recurseLoader);
5757
}
5858

5959
@Override public void

Diff for: cli-impl/src/main/java/org/aya/cli/library/incremental/DiskCompilerAdvisor.java

+28-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
import org.aya.cli.library.source.LibraryOwner;
77
import org.aya.cli.library.source.LibrarySource;
88
import org.aya.cli.utils.CompilerUtil;
9-
import org.aya.compiler.CompiledModule;
9+
import org.aya.compiler.*;
1010
import org.aya.resolve.ResolveInfo;
1111
import org.aya.resolve.context.EmptyContext;
1212
import org.aya.resolve.module.ModuleLoader;
13+
import org.aya.syntax.core.def.TopLevelDef;
1314
import org.aya.syntax.core.def.TyckDef;
1415
import org.aya.syntax.ref.ModulePath;
1516
import org.aya.util.FileUtil;
1617
import org.aya.util.reporter.Reporter;
1718
import org.jetbrains.annotations.NotNull;
1819
import org.jetbrains.annotations.Nullable;
1920

21+
import javax.tools.ToolProvider;
2022
import java.io.IOException;
23+
import java.net.URL;
24+
import java.net.URLClassLoader;
2125
import java.nio.file.Files;
2226
import java.nio.file.Path;
2327

@@ -54,7 +58,7 @@ public class DiskCompilerAdvisor implements CompilerAdvisor {
5458
}
5559
@Override public @Nullable ResolveInfo doLoadCompiledCore(
5660
@NotNull Reporter reporter,
57-
@NotNull ModulePath mod,
61+
@NotNull LibraryOwner owner, @NotNull ModulePath mod,
5862
@Nullable Path sourcePath,
5963
@Nullable Path corePath,
6064
@NotNull ModuleLoader recurseLoader
@@ -63,10 +67,13 @@ public class DiskCompilerAdvisor implements CompilerAdvisor {
6367
if (!Files.exists(corePath)) return null;
6468

6569
var context = new EmptyContext(reporter, sourcePath).derive(mod);
66-
// TODO: load defs
6770
try (var inputStream = FileUtil.ois(corePath)) {
6871
var compiledAya = (CompiledModule) inputStream.readObject();
69-
return compiledAya.toResolveInfo(recurseLoader, context);
72+
var baseDir = computeBaseDir(owner);
73+
try (var cl = new URLClassLoader(new URL[]{baseDir.toUri().toURL()})) {
74+
cl.loadClass(AbstractSerializer.getModuleReference(mod));
75+
return compiledAya.toResolveInfo(recurseLoader, context, cl);
76+
}
7077
}
7178
}
7279

@@ -75,8 +82,24 @@ public class DiskCompilerAdvisor implements CompilerAdvisor {
7582
@NotNull ResolveInfo resolveInfo,
7683
@NotNull ImmutableSeq<TyckDef> defs
7784
) throws IOException {
78-
// TODO: compile defs
85+
var name = file.moduleName().last();
86+
var javaCode = new FileSerializer(resolveInfo.shapeFactory())
87+
.serialize(new FileSerializer.FileResult(file.moduleName().dropLast(1), new ModuleSerializer.ModuleResult(
88+
name, defs.filterIsInstance(TopLevelDef.class), ImmutableSeq.empty())))
89+
.result();
90+
var javaSrcPath = FileUtil.resolveFile(computeBaseDir(file.owner()).resolve(AyaSerializer.PACKAGE_BASE),
91+
file.moduleName().module(), ".java");
92+
FileUtil.writeString(javaSrcPath, javaCode);
93+
var compiler = ToolProvider.getSystemJavaCompiler();
94+
var fileManager = compiler.getStandardFileManager(null, null, null);
95+
var compilationUnits = fileManager.getJavaFileObjects(javaSrcPath);
96+
var task = compiler.getTask(null, fileManager, null, null, null, compilationUnits);
97+
task.call();
7998
var coreFile = file.compiledCorePath();
8099
CompilerUtil.saveCompiledCore(coreFile, resolveInfo);
81100
}
101+
102+
private static @NotNull Path computeBaseDir(@NotNull LibraryOwner owner) {
103+
return owner.outDir().resolve("compiled");
104+
}
82105
}

Diff for: cli-impl/src/main/java/org/aya/cli/library/incremental/InMemoryCompilerAdvisor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class InMemoryCompilerAdvisor implements CompilerAdvisor {
6363
@Override
6464
public @Nullable ResolveInfo doLoadCompiledCore(
6565
@NotNull Reporter reporter,
66-
@NotNull ModulePath mod,
66+
@NotNull LibraryOwner owner, @NotNull ModulePath mod,
6767
@Nullable Path sourcePath,
6868
@Nullable Path corePath,
6969
@NotNull ModuleLoader recurseLoader

Diff for: cli-impl/src/test/java/org/aya/test/cli/SimpleTest.java

-39
This file was deleted.

Diff for: gradle/libs.versions.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# The Version of this project, aka, The Aya Theorem Prover.
33
# Remove "-SNAPSHOT" suffix and run gradle publish to release a new version.
44
# After that, increase the version number and add "-SNAPSHOT" suffix back for next cycle.
5-
project = "0.30.0-SNAPSHOT"
5+
project = "0.31.0"
66

77
# https://openjdk.org/
88
java = "21"
@@ -28,8 +28,6 @@ jlink = "3.0.1"
2828
jacoco = "0.8.12"
2929
# https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-delegation
3030
manifold = "2024.1.14"
31-
# https://github.com/sourcebuddy/sourcebuddy
32-
sourcebuddy = "2.5.0"
3331

3432
[plugins]
3533
jlink = { id = "org.beryx.jlink", version.ref = "jlink" }
@@ -62,7 +60,6 @@ hamcrest = { group = "org.hamcrest", name = "hamcrest", version.ref = "hamcrest"
6260

6361
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
6462
commonmark = { group = "org.commonmark", name = "commonmark", version.ref = "commonmark" }
65-
sourcebuddy = { group = "com.javax0.sourcebuddy", name = "SourceBuddy", version.ref = "sourcebuddy" }
6663

6764
manifold-delegate-runtime = { group = "systems.manifold", name = "manifold-delegation-rt", version.ref = "manifold" }
6865
manifold-delegate-codegen = { group = "systems.manifold", name = "manifold-delegation", version.ref = "manifold" }

Diff for: ide-lsp/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ supportedPlatforms.forEach { platform ->
127127
include("bin/aya")
128128
include("bin/aya-lsp")
129129
include("${Constants.jreDirName}/bin/**")
130-
fileMode = "755".toInt(8)
130+
filePermissions { unix("755") }
131131
}
132132
doLast {
133133
val bytes = MessageDigest.getInstance("SHA-256")

Diff for: jit-compiler/build.gradle.kts

-16
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
2-
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
3-
import org.aya.gradle.GenerateVersionTask
4-
51
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
62
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
73

84
dependencies {
95
api(project(":base"))
10-
implementation(libs.sourcebuddy)
116
testImplementation(libs.junit.jupiter)
127
testImplementation(libs.hamcrest)
138
testImplementation(project(":producer"))
149
}
1510

16-
val genTestDir = file("src/test/gen")
17-
idea.module.testSources.from(genTestDir)
18-
idea.module.generatedSourceDirs.add(genTestDir)
19-
sourceSets.test { java.srcDirs(genTestDir) }
20-
21-
val cleanGenerated = tasks.register("cleanGenerated") {
22-
group = "build"
23-
genTestDir.deleteRecursively()
24-
}
25-
26-
tasks.named("clean") { dependsOn(cleanGenerated) }
2711
tasks.withType<JavaExec>().configureEach {
2812
val vmArgs = jvmArgs ?: mutableListOf()
2913
vmArgs.add("-Xss32M")

Diff for: jit-compiler/src/main/java/org/aya/compiler/AyaSerializer.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
import org.aya.compiler.util.SerializeUtils;
1010
import org.aya.syntax.core.term.Term;
1111
import org.aya.syntax.core.term.TupTerm;
12-
import org.aya.syntax.core.term.call.ConCall;
13-
import org.aya.syntax.core.term.call.ConCallLike;
14-
import org.aya.syntax.core.term.call.DataCall;
15-
import org.aya.syntax.core.term.call.FnCall;
12+
import org.aya.syntax.core.term.call.*;
1613
import org.aya.util.error.Panic;
1714
import org.intellij.lang.annotations.Language;
18-
import org.jetbrains.annotations.NotNull;
1915

2016
import static org.aya.compiler.AbstractSerializer.getJavaReference;
2117

@@ -36,11 +32,12 @@ public interface AyaSerializer<T> {
3632
String PACKAGE_BASE = "AYA";
3733
String STATIC_FIELD_INSTANCE = "INSTANCE";
3834
String FIELD_INSTANCE = "ref";
39-
String CLASS_JITCONCALL = getJavaReference(ConCall.class);
35+
String CLASS_CONCALL = getJavaReference(ConCall.class);
4036
String CLASS_CONCALLLIKE = getJavaReference(ConCallLike.class);
4137
String CLASS_TUPLE = getJavaReference(TupTerm.class);
42-
String CLASS_JITFNCALL = getJavaReference(FnCall.class);
43-
String CLASS_JITDATACALL = getJavaReference(DataCall.class);
38+
String CLASS_FNCALL = getJavaReference(FnCall.class);
39+
String CLASS_DATACALL = getJavaReference(DataCall.class);
40+
String CLASS_PRIMCALL = getJavaReference(PrimCall.class);
4441
String CLASS_IMMSEQ = getJavaReference(ImmutableSeq.class);
4542
String CLASS_MUTSEQ = getJavaReference(MutableSeq.class);
4643
String CLASS_SEQ = getJavaReference(Seq.class);

Diff for: jit-compiler/src/main/java/org/aya/compiler/CompiledModule.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ private void serOp(@NotNull TyckDef def) {
166166
}
167167

168168
public @NotNull ResolveInfo toResolveInfo(
169-
@NotNull ModuleLoader loader, @NotNull PhysicalModuleContext context
169+
@NotNull ModuleLoader loader, @NotNull PhysicalModuleContext context, ClassLoader classLoader
170170
) {
171-
var state = new DeState(getClass().getClassLoader());
171+
var state = new DeState(classLoader);
172172
return toResolveInfo(loader, context, state, new PrimFactory(), new ShapeFactory());
173173
}
174174
public @NotNull ResolveInfo toResolveInfo(

Diff for: jit-compiler/src/main/java/org/aya/compiler/ModuleSerializer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ private void doSerialize(@NotNull TyckDef unit) {
4444
.serialize(dataDef);
4545
case ConDef conDef -> new ConSerializer(builder, indent, nameGen)
4646
.serialize(conDef);
47-
case PrimDef primDef -> throw new UnsupportedOperationException("TODO");
47+
case PrimDef primDef -> new PrimSerializer(this)
48+
.serialize(primDef);
4849
}
4950
}
5051

0 commit comments

Comments
 (0)