Skip to content

Commit

Permalink
merge: Cherry pick from #1298 (#1299)
Browse files Browse the repository at this point in the history
Also adds partial term in prim, related to #1029
  • Loading branch information
ice1000 authored Feb 1, 2025
2 parents ac52873 + 85cd353 commit 0727d12
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
11 changes: 11 additions & 0 deletions base/src/main/java/org/aya/primitive/PrimFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Function;

import static org.aya.syntax.core.def.PrimDef.*;
import static org.aya.syntax.core.term.SortTerm.Set0;
import static org.aya.syntax.core.term.SortTerm.Type0;

import kala.collection.Map;
Expand Down Expand Up @@ -43,6 +44,7 @@ public PrimFactory() {
stringConcat,
intervalType,
pathType,
partialType,
coe
).map(seed -> Tuple.of(seed.name, seed)));
}
Expand Down Expand Up @@ -129,6 +131,15 @@ public record PrimSeed(
return new PrimCall(prim.ref(), prim.ulift(), ImmutableSeq.of(first, second));
}

final @NotNull PrimSeed partialType = new PrimSeed(ID.PARTIAL, (prim, _) -> {
throw new UnsupportedOperationException("TODO");
}, ref -> {
var paramR = new Param("r", DimTyTerm.INSTANCE, true);
var paramS = new Param("s", DimTyTerm.INSTANCE, true);
var paramA = new Param("A", Type0, true);
return new PrimDef(ref, ImmutableSeq.of(paramR, paramS, paramA), Set0, ID.PARTIAL);
}, ImmutableSeq.of(ID.I));

/*
private final @NotNull PrimSeed hcomp = new PrimSeed(ID.HCOMP, this::hcomp, ref -> {
var varA = new LocalVar("A");
Expand Down
5 changes: 3 additions & 2 deletions base/src/main/java/org/aya/resolve/ResolvingStmt.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2025 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.resolve;

import kala.collection.immutable.ImmutableSeq;
import org.aya.resolve.context.Context;
import org.aya.resolve.context.ModuleContext;
import org.aya.syntax.concrete.stmt.Generalize;
import org.aya.syntax.concrete.stmt.Stmt;
import org.aya.syntax.concrete.stmt.decl.Decl;
Expand Down Expand Up @@ -38,6 +39,6 @@ sealed interface ResolvingDecl extends ResolvingStmt { }

record TopDecl(@NotNull Decl stmt, @NotNull Context context) implements ResolvingDecl { }
record MiscDecl(@NotNull Decl stmt) implements ResolvingDecl { }
record GenStmt(@NotNull Generalize stmt) implements ResolvingStmt { }
record GenStmt(@NotNull Generalize stmt, @NotNull ModuleContext context) implements ResolvingStmt { }
record ModStmt(@NotNull ImmutableSeq<@NotNull ResolvingStmt> resolved) implements ResolvingStmt { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ImmutableSeq<ResolvingStmt> resolveStmt(@NotNull ImmutableSeq<Stmt> stmts
case Generalize variables -> {
for (var variable : variables.variables)
context.defineSymbol(variable, Stmt.Accessibility.Private, variable.sourcePos);
yield new ResolvingStmt.GenStmt(variables);
yield new ResolvingStmt.GenStmt(variables, context);
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions base/src/main/java/org/aya/resolve/visitor/StmtResolver.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
// Copyright (c) 2020-2025 Tesla (Yinsen) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.resolve.visitor;

Expand Down Expand Up @@ -36,8 +36,8 @@ static void resolveStmt(@NotNull ResolvingStmt stmt, @NotNull ResolveInfo info)
switch (stmt) {
case ResolvingStmt.ResolvingDecl decl -> resolveDecl(decl, info);
case ResolvingStmt.ModStmt(var stmts) -> resolveStmt(stmts, info);
case ResolvingStmt.GenStmt(var variables) -> {
var resolver = new ExprResolver(info.thisModule(), false);
case ResolvingStmt.GenStmt(var variables, var context) -> {
var resolver = new ExprResolver(context, false);
resolver.enter(Where.Head);
variables.descentInPlace(resolver, (_, p) -> p);
addReferences(info, new TyckOrder.Head(variables), resolver);
Expand Down
1 change: 1 addition & 0 deletions ide-lsp/src/test/resources/lsp-test-lib/src/PathPrims.aya
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
prim I
prim coe (r s : I) (A : I -> Type) : A r -> A s
prim Path (A : I -> Type) (a : A 0) (b : A 1) : Type
prim Partial (r s : I) (A : Type) : Set
5 changes: 2 additions & 3 deletions syntax/src/main/java/org/aya/syntax/core/def/PrimDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ public enum ID {
STRCONCAT("strcat"),
I("I"),
PATH("Path"),
PARTIAL("Partial"),
COE("coe"),
HCOMP("hcom");

public final @NotNull
@NonNls String id;

public final @NotNull @NonNls String id;
@Override public String toString() { return id; }

public static @Nullable ID find(@NotNull String id) {
Expand Down

0 comments on commit 0727d12

Please sign in to comment.