Skip to content

Commit

Permalink
misc: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
HoshinoTented committed Oct 16, 2023
1 parent bdcad91 commit ea233ed
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
2 changes: 1 addition & 1 deletion base/src/main/java/org/aya/core/pat/PatMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void solve(@NotNull Pat pat, @NotNull MetaPatTerm metaPat) throws Mismat
// solve as pat
metaPat.ref().solution().set(metalized);
} else {
// a MetaPat that has solution <==> the solution
// a MetaPat that has a solution <==> the solution
match(pat, todo.toTerm());
}
}
Expand Down
4 changes: 2 additions & 2 deletions base/src/main/java/org/aya/core/serde/SerTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ sealed interface SerShapedFn extends SerTerm permits SerTerm.IntegerOps {
return (Term) deShape(state);
}

@NotNull Shaped.Fn<Term> deShape(@NotNull DeState state);
@NotNull Shaped.Appliable<Term> deShape(@NotNull DeState state);
}

record IntegerOps(
Expand All @@ -351,7 +351,7 @@ record IntegerOps(
@NotNull SerDef.SerShapeResult shapeResult,
@NotNull SerTerm.Data dataCall) implements SerShapedFn {
@Override
public @NotNull Shaped.Fn<Term> deShape(@NotNull DeState state) {
public @NotNull Shaped.Appliable<Term> deShape(@NotNull DeState state) {
DefVar<? extends Def, ? extends TeleDecl<?>> ref = state.resolve(this.ref);
// ref can be empty for now, perhaps it hasn't been de.
var shapeRecog = shapeResult.de(state);
Expand Down
8 changes: 4 additions & 4 deletions base/src/main/java/org/aya/core/serde/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public record Serializer(@NotNull Serializer.State state) {
case FnCall fnCall -> new SerTerm.Fn(
state.def(fnCall.ref()),
serializeCall(fnCall.ulift(), fnCall.args()));
case ShapedFnCall(Shaped.Fn<Term> head, int ulift, ImmutableSeq<Arg<Term>> args) -> new SerTerm.ShapedFn(
case ShapedFnCall(Shaped.Appliable<Term> head, int ulift, ImmutableSeq<Arg<Term>> args) -> new SerTerm.ShapedFn(
serializeShapedFn(head), serializeCall(ulift, args)
);
case ProjTerm proj -> new SerTerm.Proj(serialize(proj.of()), proj.ix());
Expand Down Expand Up @@ -180,12 +180,12 @@ case PAppTerm(var of, var args, var cube) -> new SerTerm.PathApp(serialize(of),
ImmutableMap.from(classCall.args().view().map((k, v) -> Tuple.of(state.def(k), serialize(v)))));
}

private @NotNull SerTerm.SerShapedFn serializeShapedFn(@NotNull Shaped.Fn<Term> shapedFn) {
return switch (shapedFn) {
private @NotNull SerTerm.SerShapedFn serializeShapedFn(@NotNull Shaped.Appliable<Term> shapedAppliable) {
return switch (shapedAppliable) {
case IntegerOpsTerm(var ref, var kind, var recog, var dataCall) -> new SerTerm.IntegerOps(
state.def(ref), kind, SerDef.SerShapeResult.serialize(state, recog), (SerTerm.Data) serialize(dataCall)
);
default -> throw new IllegalStateException("Unexpected value: " + shapedFn);
default -> throw new IllegalStateException("Unexpected value: " + shapedAppliable);
};
}

Expand Down
11 changes: 1 addition & 10 deletions base/src/main/java/org/aya/core/term/IntegerOpsTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public record IntegerOpsTerm(
@NotNull Kind kind,
@NotNull ShapeRecognition paramRecog,
@NotNull DataCall paramType
) implements Shaped.Fn<Term>, Term {
) implements Shaped.Appliable<Term>, Term {
public IntegerOpsTerm {
assert paramRecog.shape() == AyaShape.NAT_SHAPE;

Expand Down Expand Up @@ -100,13 +100,4 @@ public enum Kind implements Serializable {
}
};
}

@Override
public boolean equals(Object obj) {
if (obj instanceof IntegerOpsTerm term) {
return this.ref == term.ref && this.kind == term.kind;
}

return false;
}
}
6 changes: 3 additions & 3 deletions base/src/main/java/org/aya/core/term/ShapedFnCall.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @param args
*/
public record ShapedFnCall(
@NotNull Shaped.Fn<Term> head,
@NotNull Shaped.Appliable<Term> head,
@Override int ulift,
@Override @NotNull ImmutableSeq<Arg<Term>> args
) implements Callable.Tele {
Expand All @@ -30,15 +30,15 @@ public record ShapedFnCall(
return head.ref();
}

private @NotNull ShapedFnCall update(@NotNull Shaped.Fn<Term> head, @NotNull ImmutableSeq<Arg<Term>> args) {
private @NotNull ShapedFnCall update(@NotNull Shaped.Appliable<Term> head, @NotNull ImmutableSeq<Arg<Term>> args) {
return head == this.head && args.sameElements(this.args, true)
? this
: new ShapedFnCall(head, ulift, args);
}

@Override
public @NotNull Term descent(@NotNull UnaryOperator<Term> f, @NotNull UnaryOperator<Pat> g) {
return update((Shaped.Fn<Term>) f.apply((Term) head), args.map(x -> x.descent(f)));
return update((Shaped.Appliable<Term>) f.apply((Term) head), args.map(x -> x.descent(f)));
}

/**
Expand Down
17 changes: 15 additions & 2 deletions base/src/main/java/org/aya/generic/Shaped.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,22 @@ default <O extends AyaDocile> boolean compareUntyped(@NotNull Shaped.List<O> oth
}
}

interface Fn<T extends AyaDocile> extends Shaped<T> {
/**
* Something Shaped which is appliable, like
* {@link org.aya.core.def.FnDef}, {@link CtorDef}, and probably {@link org.aya.core.def.DataDef}
*/
interface Appliable<T extends AyaDocile> extends Shaped<T> {
/**
* The underlying ref
*/
@NotNull DefVar<? extends Def, ? extends TeleDecl<?>> ref();

/**
* Applying arguments.
*
* @param args arguments
* @return null if failed
*/
@Nullable T apply(@NotNull ImmutableSeq<Arg<T>> args);
@Override boolean equals(Object obj);
}
}
6 changes: 3 additions & 3 deletions base/src/main/java/org/aya/tyck/repr/ShapeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.jetbrains.annotations.Nullable;

public final class ShapeFactory {
public static @Nullable Shaped.Fn<Term> ofCtor(
public static @Nullable Shaped.Appliable<Term> ofCtor(
@NotNull DefVar<CtorDef, TeleDecl.DataCtor> ref,
@NotNull AyaShape.Factory factory,
@NotNull DataCall paramType
Expand All @@ -34,7 +34,7 @@ public final class ShapeFactory {
return ofCtor(ref, paramRecog, paramType);
}

public static @Nullable Shaped.Fn<Term> ofCtor(
public static @Nullable Shaped.Appliable<Term> ofCtor(
@NotNull DefVar<CtorDef, TeleDecl.DataCtor> ref,
@NotNull ShapeRecognition paramRecog,
@NotNull DataCall paramType
Expand All @@ -54,7 +54,7 @@ public final class ShapeFactory {
return null;
}

public static @Nullable Shaped.Fn<Term> ofFn(
public static @Nullable Shaped.Appliable<Term> ofFn(
@NotNull DefVar<FnDef, TeleDecl.FnDecl> ref,
@NotNull ShapeRecognition recog,
@NotNull AyaShape.Factory factory
Expand Down
7 changes: 6 additions & 1 deletion base/src/main/java/org/aya/tyck/unify/TermComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ private boolean compareWHNF(Term lhs, Term preRhs, Sub lr, Sub rl, @NotNull Term
return compare(whnf, rhsWhnf, lr, rl, type);
}

/**
* Short path of comparing {@link Callable}
*
* @see #isCall(Term)
*/
private @Nullable Term compareApprox(@NotNull Term preLhs, @NotNull Term preRhs, Sub lr, Sub rl) {
return switch (preLhs) {
case FnCall lhs when preRhs instanceof FnCall rhs ->
Expand All @@ -180,7 +185,7 @@ private boolean compareWHNF(Term lhs, Term preRhs, Sub lr, Sub rl, @NotNull Term
lhs.ref() != rhs.ref() ? null : visitCall(lhs, rhs, lr, rl, lhs.ref(), lhs.ulift());
// TODO[h]: This also involves Con situations, is it bad?
case ShapedFnCall lhs when preRhs instanceof ShapedFnCall rhs ->
(!lhs.head().equals(rhs.head())) ? null : visitCall(lhs, rhs, lr, rl, lhs.ref(), lhs.ulift());
lhs.ref() != rhs.ref() ? null : visitCall(lhs, rhs, lr, rl, lhs.ref(), lhs.ulift());
default -> null;
};
}
Expand Down

0 comments on commit ea233ed

Please sign in to comment.