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 # snapshot tests temp file
*.pending-snap *.pending-snap
# checkmate
checkmate_*.json

View file

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

View file

@ -546,82 +546,6 @@
}, },
"Event": { "Event": {
"oneOf": [ "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", "type": "object",
"required": [ "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": { "TagUnionExtension": {
"oneOf": [ "oneOf": [
{ {
"type": [ "type": "object",
"object",
"integer"
],
"format": "uint32",
"minimum": 0.0,
"required": [ "required": [
"type" "type",
"variable"
], ],
"properties": { "properties": {
"type": { "type": {
@ -811,18 +791,17 @@
"enum": [ "enum": [
"Openness" "Openness"
] ]
},
"variable": {
"$ref": "#/definitions/Variable"
} }
} }
}, },
{ {
"type": [ "type": "object",
"object",
"integer"
],
"format": "uint32",
"minimum": 0.0,
"required": [ "required": [
"type" "type",
"variable"
], ],
"properties": { "properties": {
"type": { "type": {
@ -830,6 +809,9 @@
"enum": [ "enum": [
"Any" "Any"
] ]
},
"variable": {
"$ref": "#/definitions/Variable"
} }
} }
} }

View file

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

View file

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

View file

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