Fix some checkmate bad schemas

This commit is contained in:
Ayaz Hafiz 2023-07-16 15:16:57 -05:00
parent fcd733e1df
commit b3ccc905a4
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
7 changed files with 125 additions and 157 deletions

3
.gitignore vendored
View file

@ -85,3 +85,6 @@ www/src/roc-tutorial
# snapshot tests temp file
*.pending-snap
# checkmate
checkmate_*.json

View file

@ -3,6 +3,7 @@ use std::fs;
use roc_checkmate_schema::AllEvents;
fn main() {
println!("cargo:rerun-if-changed=../checkmate_schema");
let schema = AllEvents::schema();
fs::write(
"schema.json",

View file

@ -546,82 +546,6 @@
},
"Event": {
"oneOf": [
{
"type": "object",
"oneOf": [
{
"type": "object",
"required": [
"from",
"to",
"type"
],
"properties": {
"from": {
"$ref": "#/definitions/Variable"
},
"to": {
"$ref": "#/definitions/Variable"
},
"type": {
"type": "string",
"enum": [
"Unify"
]
}
}
},
{
"type": "object",
"required": [
"type",
"variable"
],
"properties": {
"content": {
"anyOf": [
{
"$ref": "#/definitions/Content"
},
{
"type": "null"
}
]
},
"rank": {
"anyOf": [
{
"$ref": "#/definitions/Rank"
},
{
"type": "null"
}
]
},
"type": {
"type": "string",
"enum": [
"SetDescriptor"
]
},
"variable": {
"$ref": "#/definitions/Variable"
}
}
}
],
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"VariableEvent"
]
}
}
},
{
"type": "object",
"required": [
@ -660,6 +584,66 @@
]
}
}
},
{
"type": "object",
"required": [
"from",
"to",
"type"
],
"properties": {
"from": {
"$ref": "#/definitions/Variable"
},
"to": {
"$ref": "#/definitions/Variable"
},
"type": {
"type": "string",
"enum": [
"VariableUnified"
]
}
}
},
{
"type": "object",
"required": [
"type",
"variable"
],
"properties": {
"content": {
"anyOf": [
{
"$ref": "#/definitions/Content"
},
{
"type": "null"
}
]
},
"rank": {
"anyOf": [
{
"$ref": "#/definitions/Rank"
},
{
"type": "null"
}
]
},
"type": {
"type": "string",
"enum": [
"VariableSetDescriptor"
]
},
"variable": {
"$ref": "#/definitions/Variable"
}
}
}
]
},
@ -796,14 +780,10 @@
"TagUnionExtension": {
"oneOf": [
{
"type": [
"object",
"integer"
],
"format": "uint32",
"minimum": 0.0,
"type": "object",
"required": [
"type"
"type",
"variable"
],
"properties": {
"type": {
@ -811,18 +791,17 @@
"enum": [
"Openness"
]
},
"variable": {
"$ref": "#/definitions/Variable"
}
}
},
{
"type": [
"object",
"integer"
],
"format": "uint32",
"minimum": 0.0,
"type": "object",
"required": [
"type"
"type",
"variable"
],
"properties": {
"type": {
@ -830,6 +809,9 @@
"enum": [
"Any"
]
},
"variable": {
"$ref": "#/definitions/Variable"
}
}
}

View file

@ -1,6 +1,6 @@
use std::error::Error;
use roc_checkmate_schema::{AllEvents, Event, VariableEvent};
use roc_checkmate_schema::{AllEvents, Event};
use roc_types::subs as s;
use crate::convert::AsSchema;
@ -28,13 +28,13 @@ impl Collector {
pub fn unify(&mut self, subs: &s::Subs, from: s::Variable, to: s::Variable) {
let to = to.as_schema(subs);
let from = from.as_schema(subs);
self.add_event(VariableEvent::Unify { to, from });
self.add_event(Event::VariableUnified { to, from });
}
pub fn set_content(&mut self, subs: &s::Subs, var: s::Variable, content: s::Content) {
let variable = var.as_schema(subs);
let content = content.as_schema(subs);
self.add_event(VariableEvent::SetDescriptor {
self.add_event(Event::VariableSetDescriptor {
variable,
content: Some(content),
rank: None,
@ -44,7 +44,7 @@ impl Collector {
pub fn set_rank(&mut self, subs: &s::Subs, var: s::Variable, rank: s::Rank) {
let variable = var.as_schema(subs);
let rank = rank.as_schema(subs);
self.add_event(VariableEvent::SetDescriptor {
self.add_event(Event::VariableSetDescriptor {
variable,
rank: Some(rank),
content: None,
@ -55,7 +55,7 @@ impl Collector {
let variable = var.as_schema(subs);
let rank = descriptor.rank.as_schema(subs);
let content = descriptor.content.as_schema(subs);
self.add_event(VariableEvent::SetDescriptor {
self.add_event(Event::VariableSetDescriptor {
variable,
rank: Some(rank),
content: Some(content),
@ -161,7 +161,7 @@ impl<'a> EventW<'a> {
match self {
Top(events) => Some(&events.0),
Sub(Event::Unification { subevents, .. }) => Some(subevents),
Sub(Event::VariableEvent(_)) => None,
Sub(Event::VariableUnified { .. } | Event::VariableSetDescriptor { .. }) => None,
}
}
fn subevents_mut(self) -> Option<&'a mut Vec<Event>> {
@ -169,7 +169,7 @@ impl<'a> EventW<'a> {
match self {
Top(events) => Some(&mut events.0),
Sub(Event::Unification { subevents, .. }) => Some(subevents),
Sub(Event::VariableEvent(_)) => None,
Sub(Event::VariableUnified { .. } | Event::VariableSetDescriptor { .. }) => None,
}
}
}

View file

@ -40,7 +40,7 @@ macro_rules! dump_checkmate {
}
pub fn dump_checkmate(collector: &Collector) {
let timestamp = chrono::Utc::now().format("%Y%m%d_%H%M%S");
let timestamp = chrono::Local::now().format("%Y%m%d_%H-%M-%S");
let filename = format!("checkmate_{timestamp}.json");
let fi = std::fs::File::create(&filename).unwrap();
collector.write(fi).unwrap();

View file

@ -6,21 +6,6 @@
*/
export type Event =
| (
| {
from: Variable;
to: Variable;
type: "Unify";
[k: string]: unknown;
}
| {
content?: Content | null;
rank?: Rank | null;
type: "SetDescriptor";
variable: Variable;
[k: string]: unknown;
}
)
| {
left: Variable;
mode: UnificationMode;
@ -29,8 +14,34 @@ export type Event =
success?: boolean | null;
type: "Unification";
[k: string]: unknown;
}
| {
from: Variable;
to: Variable;
type: "VariableUnified";
[k: string]: unknown;
}
| {
content?: Content | null;
rank?: Rank | null;
type: "VariableSetDescriptor";
variable: Variable;
[k: string]: unknown;
};
export type Variable = number;
export type UnificationMode =
| {
type: "Eq";
[k: string]: unknown;
}
| {
type: "Present";
[k: string]: unknown;
}
| {
type: "LambdaSetSpecialization";
[k: string]: unknown;
};
export type Content =
| {
name?: string | null;
@ -176,20 +187,16 @@ export type RecordFieldKind =
[k: string]: unknown;
};
export type TagUnionExtension =
| (
| {
type: "Openness";
[k: string]: unknown;
}
| number
)
| (
| {
type: "Any";
[k: string]: unknown;
}
| number
);
| {
type: "Openness";
variable: Variable;
[k: string]: unknown;
}
| {
type: "Any";
variable: Variable;
[k: string]: unknown;
};
export type NumericRangeKind =
| {
type: "Int";
@ -200,19 +207,6 @@ export type NumericRangeKind =
[k: string]: unknown;
};
export type Rank = number;
export type UnificationMode =
| {
type: "Eq";
[k: string]: unknown;
}
| {
type: "Present";
[k: string]: unknown;
}
| {
type: "LambdaSetSpecialization";
[k: string]: unknown;
};
export type AllEvents = Event[];
export interface ClosureType {

View file

@ -146,7 +146,7 @@ pub enum RecordFieldKind {
}
#[derive(Serialize, JsonSchema, Debug)]
#[serde(tag = "type")]
#[serde(tag = "type", content = "variable")]
pub enum TagUnionExtension {
Openness(Variable),
Any(Variable),
@ -192,7 +192,6 @@ pub enum UnificationMode {
#[derive(Serialize, JsonSchema, Debug)]
#[serde(tag = "type")]
pub enum Event {
VariableEvent(VariableEvent),
Unification {
left: Variable,
right: Variable,
@ -200,30 +199,19 @@ pub enum Event {
success: Option<bool>,
subevents: Vec<Event>,
},
}
#[derive(Serialize, JsonSchema, Debug)]
pub struct AllEvents(pub Vec<Event>);
#[derive(Serialize, JsonSchema, Debug)]
#[serde(tag = "type")]
pub enum VariableEvent {
Unify {
VariableUnified {
from: Variable,
to: Variable,
},
SetDescriptor {
VariableSetDescriptor {
variable: Variable,
rank: Option<Rank>,
content: Option<Content>,
},
}
impl From<VariableEvent> for Event {
fn from(event: VariableEvent) -> Event {
Event::VariableEvent(event)
}
}
#[derive(Serialize, JsonSchema, Debug)]
pub struct AllEvents(pub Vec<Event>);
impl AllEvents {
pub fn schema() -> RootSchema {