Skip to content

Commit cb5abcb

Browse files
committed
serde: fix compile
1 parent ad5cce9 commit cb5abcb

File tree

7 files changed

+31
-33
lines changed

7 files changed

+31
-33
lines changed

Diff for: base/src/main/java/org/aya/normalize/Normalizer.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.aya.syntax.ref.LocalVar;
3131
import org.aya.tyck.TyckState;
3232
import org.aya.tyck.tycker.Stateful;
33-
import org.aya.util.error.WithPos;
3433
import org.jetbrains.annotations.NotNull;
3534
import org.jetbrains.annotations.Nullable;
3635

@@ -93,7 +92,7 @@ case FnCall(FnDef.Delegate delegate, int ulift, var args) -> {
9392
continue;
9493
}
9594
case Either.Right(var body): {
96-
var result = tryUnfoldClauses(body.clauses.view().map(WithPos::data),
95+
var result = tryUnfoldClauses(body.matchingsView(),
9796
args, core.is(Modifier.Overlap), ulift);
9897
// we may get stuck
9998
if (result == null) return defaultValue;

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.aya.util.Pair;
3030
import org.aya.util.RepoLike;
3131
import org.aya.util.error.Panic;
32-
import org.aya.util.error.WithPos;
3332
import org.jetbrains.annotations.NotNull;
3433
import org.jetbrains.annotations.Nullable;
3534

@@ -126,7 +125,7 @@ case Pair(Either.Left(var termShape), Either.Left(var term)) ->
126125
case Pair(Either.Right(var clauseShapes), Either.Right(var body)) -> {
127126
var mode = def.is(Modifier.Overlap) ? MatchMode.Sub : MatchMode.Eq;
128127
yield matchInside(() -> captures.put(shape.name(), def.ref()), () ->
129-
matchMany(mode, clauseShapes, body.clauses.view().map(WithPos::data), this::matchClause));
128+
matchMany(mode, clauseShapes, body.matchingsView(), this::matchClause));
130129
}
131130
default -> false;
132131
};

Diff for: base/src/main/java/org/aya/terck/CallResolver.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.aya.syntax.core.term.xtt.PAppTerm;
2525
import org.aya.tyck.TyckState;
2626
import org.aya.tyck.tycker.Stateful;
27-
import org.aya.util.error.WithPos;
2827
import org.aya.util.terck.CallGraph;
2928
import org.aya.util.terck.CallMatrix;
3029
import org.aya.util.terck.Relation;
@@ -139,8 +138,8 @@ private Relation compareConArgs(@NotNull ImmutableSeq<Term> conArgs, @NotNull Pa
139138
}
140139

141140
public void check() {
142-
var clauses = caller.body().getRightValue().clauses;
143-
clauses.view().map(WithPos::data).forEach(this);
141+
var clauses = caller.body().getRightValue().matchingsView();
142+
clauses.forEach(this);
144143
}
145144

146145
@Override public void accept(@NotNull Term.Matching matching) {

Diff for: base/src/main/java/org/aya/tyck/ExprTycker.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ && whnf(type) instanceof DataCall dataCall
191191
ImmutableSeq.fill(discriminant.size(), i ->
192192
new LocalVar("match" + i, discriminant.get(i).sourcePos(), GenerateKind.Basic.Tyck)),
193193
ImmutableSeq.empty(), clauses);
194-
var wellClauses = clauseTycker.check(exprPos)
195-
.wellTyped().clauses.map(WithPos::data);
194+
var wellClauses = clauseTycker.check(exprPos).wellTyped().matchingsView();
196195

197196
// Find free occurrences
198197
var usages = new FreeCollector();
@@ -203,7 +202,8 @@ && whnf(type) instanceof DataCall dataCall
203202
var captures = usages.collected();
204203
var lifted = new Matchy(type.bindTele(wellArgs.size(), captures.view()),
205204
new QName(QPath.fileLevel(fileModule), "match-" + exprPos.lineColumnString()),
206-
wellClauses.map(clause -> clause.update(clause.body().bindTele(clause.bindCount(), captures.view()))));
205+
wellClauses.map(clause -> clause.update(clause.body().bindTele(clause.bindCount(), captures.view())))
206+
.toImmutableSeq());
207207

208208
var wellTerms = wellArgs.map(Jdg::wellTyped);
209209
return new MatchCall(lifted, wellTerms, captures.map(FreeTerm::new));

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

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang.
1+
// Copyright (c) 2020-2025 Tesla (Yinsen) Zhang.
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
33
package org.aya.compiler.serializers;
44

5+
import java.lang.constant.ClassDesc;
6+
import java.lang.constant.ConstantDescs;
7+
import java.util.EnumSet;
8+
import java.util.function.Consumer;
9+
510
import kala.collection.immutable.ImmutableSeq;
611
import kala.control.Either;
712
import org.aya.compiler.free.Constants;
813
import org.aya.compiler.free.FreeClassBuilder;
914
import org.aya.compiler.free.FreeCodeBuilder;
1015
import org.aya.compiler.free.FreeJavaExpr;
11-
import org.aya.compiler.free.data.MethodRef;
1216
import org.aya.compiler.free.data.LocalVariable;
17+
import org.aya.compiler.free.data.MethodRef;
1318
import org.aya.generic.Modifier;
1419
import org.aya.primitive.ShapeFactory;
1520
import org.aya.syntax.compile.JitFn;
1621
import org.aya.syntax.core.def.FnDef;
1722
import org.aya.syntax.core.def.TyckAnyDef;
1823
import org.aya.syntax.core.term.call.FnCall;
19-
import org.aya.util.error.WithPos;
2024
import org.jetbrains.annotations.NotNull;
2125

22-
import java.lang.constant.ClassDesc;
23-
import java.lang.constant.ConstantDescs;
24-
import java.util.EnumSet;
25-
import java.util.function.Consumer;
26-
2726
public final class FnSerializer extends JitTeleSerializer<FnDef> {
2827
private final @NotNull ShapeFactory shapeFactory;
2928

@@ -83,19 +82,17 @@ private void buildInvoke(
8382
}
8483
case Either.Right(var clauses) -> {
8584
var ser = new PatternSerializer(argExprs, onStuckCon, unit.is(Modifier.Overlap));
86-
ser.serialize(builder, clauses.view()
87-
.map(WithPos::data)
88-
.map(matching -> new PatternSerializer.Matching(
89-
matching.bindCount(), matching.patterns(), (patSer, builder0, bindSize) -> {
90-
var result = serializeTermUnderTele(
91-
builder0,
92-
matching.body(),
93-
patSer.result.ref(),
94-
bindSize
95-
);
96-
builder0.returnWith(result);
97-
})
98-
).toImmutableSeq());
85+
ser.serialize(builder, clauses.matchingsView().map(matching -> new PatternSerializer.Matching(
86+
matching.bindCount(), matching.patterns(), (patSer, builder0, bindSize) -> {
87+
var result = serializeTermUnderTele(
88+
builder0,
89+
matching.body(),
90+
patSer.result.ref(),
91+
bindSize
92+
);
93+
builder0.returnWith(result);
94+
})
95+
).toImmutableSeq());
9996
}
10097
}
10198
}

Diff for: syntax/src/main/java/org/aya/prettier/CorePrettier.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.aya.syntax.ref.LocalVar;
3737
import org.aya.util.Arg;
3838
import org.aya.util.error.SourcePos;
39-
import org.aya.util.error.WithPos;
4039
import org.aya.util.prettier.PrettierOptions;
4140
import org.jetbrains.annotations.NotNull;
4241
import org.jetbrains.annotations.Nullable;
@@ -286,7 +285,7 @@ private ImmutableSeq<Term> visibleArgsOf(Callable call) {
286285
yield switch (def.body()) {
287286
case Either.Left(var term) -> Doc.sep(line1sep, FN_DEFINED_AS, term(Outer.Free, term.instTele(subst)));
288287
case Either.Right(var body) -> Doc.vcat(line1sep,
289-
Doc.nest(2, visitClauses(body.clauses.view().map(WithPos::data), tele.view().map(ParamLike::explicit))));
288+
Doc.nest(2, visitClauses(body.matchingsView(), tele.view().map(ParamLike::explicit))));
290289
};
291290
}
292291
case MemberDef field -> Doc.sepNonEmpty(Doc.symbol("|"),

Diff for: syntax/src/main/java/org/aya/syntax/core/def/FnClauseBody.java

+5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
33
package org.aya.syntax.core.def;
44

5+
import kala.collection.SeqView;
56
import kala.collection.immutable.ImmutableSeq;
67
import org.aya.syntax.core.term.Term;
78
import org.aya.util.error.WithPos;
89
import org.aya.util.tyck.pat.PatClass;
10+
import org.jetbrains.annotations.NotNull;
911

1012
public final class FnClauseBody {
1113
public final ImmutableSeq<WithPos<Term.Matching>> clauses;
1214
public ImmutableSeq<PatClass<ImmutableSeq<Term>>> classes;
1315
public FnClauseBody(ImmutableSeq<WithPos<Term.Matching>> clauses) { this.clauses = clauses; }
16+
public @NotNull SeqView<Term.Matching> matchingsView() {
17+
return clauses.view().map(WithPos::data);
18+
}
1419
}

0 commit comments

Comments
 (0)