-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
874: Reimplement sort system: step 1 r=ice1000 a=ice1000 Support `piDom` checks. Co-authored-by: ice1000 <ice1000kotlin@foxmail.com>
- Loading branch information
Showing
37 changed files
with
527 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2020-2023 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.core.meta; | ||
|
||
import org.aya.core.term.SortTerm; | ||
import org.aya.core.term.Term; | ||
import org.aya.generic.AyaDocile; | ||
import org.aya.pretty.doc.Doc; | ||
import org.aya.tyck.unify.Synthesizer; | ||
import org.aya.util.prettier.PrettierOptions; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Constraints on a meta variable. | ||
* | ||
* @author ice1000 | ||
*/ | ||
public sealed interface MetaInfo extends AyaDocile { | ||
@Nullable Term result(); | ||
boolean isType(@NotNull Synthesizer synthesizer); | ||
/** | ||
* The type of the meta is known. | ||
* We shall check the solution against this type. | ||
*/ | ||
record Result(@NotNull Term result) implements MetaInfo { | ||
@Override public @NotNull Doc toDoc(@NotNull PrettierOptions options) { | ||
return Doc.sep(Doc.symbol("?"), Doc.symbol(":"), result.toDoc(options)); | ||
} | ||
|
||
@Override public boolean isType(@NotNull Synthesizer synthesizer) { | ||
return synthesizer.tryPress(result) instanceof SortTerm; | ||
} | ||
} | ||
|
||
/** | ||
* The meta variable is a type. | ||
* It should be able to appear on the RHS of a judgment. | ||
*/ | ||
record AnyType() implements MetaInfo { | ||
@Override public @Nullable Term result() { | ||
return null; | ||
} | ||
|
||
@Override public boolean isType(@NotNull Synthesizer synthesizer) { | ||
return true; | ||
} | ||
|
||
@Override public @NotNull Doc toDoc(@NotNull PrettierOptions options) { | ||
return Doc.sep(Doc.plain("_"), Doc.symbols(":", "?")); | ||
} | ||
} | ||
|
||
/** | ||
* The meta variable is the domain of a pi type which is of a known type. | ||
* <p> | ||
* See: <code>notes/sort-system.md</code> | ||
*/ | ||
record PiDom(@NotNull SortTerm sort) implements MetaInfo { | ||
@Override public @Nullable Term result() { | ||
return null; | ||
} | ||
|
||
@Override public boolean isType(@NotNull Synthesizer synthesizer) { | ||
return true; | ||
} | ||
|
||
@Override public @NotNull Doc toDoc(@NotNull PrettierOptions options) { | ||
return Doc.sep(Doc.symbols("?", "->", "_", ":"), sort.toDoc(options)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.