flow-types 0.1.0-rc.5

The Flow declaration model with no values: types, declarations and their identities, record and enum shapes, and which types decoding may build.
Documentation
//! Where std declares each [`Role`], and the shape it declares it with,
//! as the bundled std's `@lang` marks say. Generated by flow-check's
//! `std_roles` test from std's sources; `FLOW_BLESS=1 cargo test -p
//! flow-check --test std_roles` rewrites it. Do not edit.

use std::sync::Arc;

use crate::{Constructor, EnumShape, Payload, RecordShape, Role};

/// The shape a role's declaration has, when it is a record or an enum.
#[derive(Clone, Debug)]
pub enum Shape {
    /// A record's.
    Record(Arc<RecordShape>),
    /// An enum's.
    Enum(Arc<EnumShape>),
}

impl Role {
    /// The std declaration that plays it: its module's path in std and
    /// its name.
    pub const fn identity(self) -> (&'static str, &'static str) {
        match self {
            Role::Int => ("int", "Int"),
            Role::Decimal => ("decimal", "Decimal"),
            Role::Bool => ("prelude", "Bool"),
            Role::Text => ("text", "Text"),
            Role::Bytes => ("bytes", "Bytes"),
            Role::List => ("list", "List"),
            Role::Dict => ("dict", "Dict"),
            Role::Set => ("set", "Set"),
            Role::Unit => ("prelude", "Unit"),
            Role::Never => ("prelude", "Never"),
            Role::Option => ("option", "Option"),
            Role::Result => ("result", "Result"),
            Role::ToolProblem => ("prelude", "ToolProblem"),
            Role::Task => ("task", "Task"),
            Role::TaskTagged => ("task", "Tagged"),
            Role::TaskStopOutcome => ("task", "Stop"),
            Role::TaskCall => ("task", "Call"),
            Role::Instant => ("time", "Instant"),
            Role::Duration => ("duration", "Duration"),
            Role::JsonValue => ("json", "Value"),
            Role::JsonDecodeError => ("json", "DecodeError"),
            Role::JsonProblem => ("json", "Problem"),
            Role::JsonStep => ("json", "Step"),
            Role::JsonNames => ("json", "Names"),
            Role::Path => ("path", "Path"),
            Role::Url => ("url", "Url"),
            Role::MediaType => ("media", "MediaType"),
            Role::RunId => ("code", "RunId"),
            Role::TaskPath => ("code", "TaskPath"),
            Role::SourcePath => ("code", "SourcePath"),
            Role::CodeTypeMismatch => ("code", "TypeMismatch"),
            Role::CodeStep => ("code", "Step"),
            Role::IntLiteral => ("int", "Int"),
            Role::DecimalLiteral => ("decimal", "Decimal"),
            Role::TextLiteral => ("text", "Text"),
            Role::ListLiteral => ("list", "List"),
            Role::DictLiteral => ("dict", "Dict"),
        }
    }

    /// The role the std declaration `name` in the module `module` plays,
    /// the first of [`Role::ALL`] when it plays more than one.
    pub fn of(module: &str, name: &str) -> Option<Role> {
        match (module, name) {
            ("int", "Int") => Some(Role::Int),
            ("decimal", "Decimal") => Some(Role::Decimal),
            ("prelude", "Bool") => Some(Role::Bool),
            ("text", "Text") => Some(Role::Text),
            ("bytes", "Bytes") => Some(Role::Bytes),
            ("list", "List") => Some(Role::List),
            ("dict", "Dict") => Some(Role::Dict),
            ("set", "Set") => Some(Role::Set),
            ("prelude", "Unit") => Some(Role::Unit),
            ("prelude", "Never") => Some(Role::Never),
            ("option", "Option") => Some(Role::Option),
            ("result", "Result") => Some(Role::Result),
            ("prelude", "ToolProblem") => Some(Role::ToolProblem),
            ("task", "Task") => Some(Role::Task),
            ("task", "Tagged") => Some(Role::TaskTagged),
            ("task", "Stop") => Some(Role::TaskStopOutcome),
            ("task", "Call") => Some(Role::TaskCall),
            ("time", "Instant") => Some(Role::Instant),
            ("duration", "Duration") => Some(Role::Duration),
            ("json", "Value") => Some(Role::JsonValue),
            ("json", "DecodeError") => Some(Role::JsonDecodeError),
            ("json", "Problem") => Some(Role::JsonProblem),
            ("json", "Step") => Some(Role::JsonStep),
            ("json", "Names") => Some(Role::JsonNames),
            ("path", "Path") => Some(Role::Path),
            ("url", "Url") => Some(Role::Url),
            ("media", "MediaType") => Some(Role::MediaType),
            ("code", "RunId") => Some(Role::RunId),
            ("code", "TaskPath") => Some(Role::TaskPath),
            ("code", "SourcePath") => Some(Role::SourcePath),
            ("code", "TypeMismatch") => Some(Role::CodeTypeMismatch),
            ("code", "Step") => Some(Role::CodeStep),
            _ => None,
        }
    }

    /// The shape its declaration has, when it is a record or an enum.
    pub fn shape(self) -> Option<Shape> {
        match self {
            Role::Int => None,
            Role::Decimal => None,
            Role::Bool => None,
            Role::Text => None,
            Role::Bytes => None,
            Role::List => None,
            Role::Dict => None,
            Role::Set => None,
            Role::Unit => None,
            Role::Never => None,
            Role::Option => Some(Shape::Enum(EnumShape::new("Option", [Constructor::new("None", Payload::None), Constructor::new("Some", Payload::Positional(1))]))),
            Role::Result => Some(Shape::Enum(EnumShape::new("Result", [Constructor::new("Ok", Payload::Positional(1)), Constructor::new("Err", Payload::Positional(1))]))),
            Role::ToolProblem => Some(Shape::Enum(EnumShape::new("ToolProblem", [Constructor::new("NotStarted", Payload::Positional(1)), Constructor::new("Interrupted", Payload::Positional(1)), Constructor::new("NetworkError", Payload::named(["sent", "reason"]))]))),
            Role::Task => None,
            Role::TaskTagged => None,
            Role::TaskStopOutcome => Some(Shape::Enum(EnumShape::new("Stop", [Constructor::new("Finished", Payload::Positional(1)), Constructor::new("Stopped", Payload::None)]))),
            Role::TaskCall => Some(Shape::Record(RecordShape::new("Call", ["args", "answer", "site"]))),
            Role::Instant => None,
            Role::Duration => None,
            Role::JsonValue => Some(Shape::Enum(EnumShape::new("Value", [Constructor::new("Null", Payload::None), Constructor::new("Bool", Payload::Positional(1)), Constructor::new("Number", Payload::Positional(1)), Constructor::new("Text", Payload::Positional(1)), Constructor::new("List", Payload::Positional(1)), Constructor::new("Object", Payload::Positional(1))]))),
            Role::JsonDecodeError => Some(Shape::Record(RecordShape::new("DecodeError", ["path", "problem"]))),
            Role::JsonProblem => Some(Shape::Enum(EnumShape::new("Problem", [Constructor::new("Syntax", Payload::named(["at"])), Constructor::new("Missing", Payload::None), Constructor::new("Unknown", Payload::None), Constructor::new("Duplicate", Payload::None), Constructor::new("Mismatch", Payload::None), Constructor::new("TooLarge", Payload::None)]))),
            Role::JsonStep => Some(Shape::Enum(EnumShape::new("Step", [Constructor::new("Field", Payload::Positional(1)), Constructor::new("Element", Payload::Positional(1)), Constructor::new("Key", Payload::Positional(1)), Constructor::new("Constructor", Payload::Positional(1))]))),
            Role::JsonNames => Some(Shape::Enum(EnumShape::new("Names", [Constructor::new("Exact", Payload::None), Constructor::new("Relaxed", Payload::None)]))),
            Role::Path => None,
            Role::Url => None,
            Role::MediaType => None,
            Role::RunId => None,
            Role::TaskPath => None,
            Role::SourcePath => None,
            Role::CodeTypeMismatch => Some(Shape::Record(RecordShape::new("TypeMismatch", ["wanted", "found", "path"]))),
            Role::CodeStep => Some(Shape::Enum(EnumShape::new("Step", [Constructor::new("Field", Payload::Positional(1)), Constructor::new("Element", Payload::Positional(1)), Constructor::new("Key", Payload::Positional(1)), Constructor::new("Constructor", Payload::Positional(1))]))),
            Role::IntLiteral => None,
            Role::DecimalLiteral => None,
            Role::TextLiteral => None,
            Role::ListLiteral => None,
            Role::DictLiteral => None,
        }
    }
}

/// Every public type std declares, as its module's path in std and its
/// name.
pub const STD_TYPES: &[(&str, &str)] = &[
    ("prelude", "Int"),
    ("prelude", "Decimal"),
    ("prelude", "Text"),
    ("prelude", "Bytes"),
    ("prelude", "List"),
    ("prelude", "Dict"),
    ("prelude", "Set"),
    ("prelude", "Option"),
    ("prelude", "Result"),
    ("prelude", "Bool"),
    ("prelude", "Unit"),
    ("prelude", "Never"),
    ("prelude", "ToolProblem"),
    ("bytes", "Bytes"),
    ("code", "Program"),
    ("code", "Module"),
    ("code", "Import"),
    ("code", "Reexport"),
    ("code", "ModulePath"),
    ("code", "Tree"),
    ("code", "Repository"),
    ("code", "Tag"),
    ("code", "DeclId"),
    ("code", "Name"),
    ("code", "Span"),
    ("code", "Position"),
    ("code", "Decl"),
    ("code", "Signature"),
    ("code", "Param"),
    ("code", "Function"),
    ("code", "BodylessFunction"),
    ("code", "Constant"),
    ("code", "Annotation"),
    ("code", "LocalId"),
    ("code", "Binding"),
    ("code", "TypeDecl"),
    ("code", "TypeBody"),
    ("code", "FieldDecl"),
    ("code", "ConstructorDecl"),
    ("code", "PayloadDecl"),
    ("code", "LocalDecl"),
    ("code", "LocalSignature"),
    ("code", "Type"),
    ("code", "Owner"),
    ("code", "SourcePath"),
    ("code", "ToolRef"),
    ("code", "LocalRef"),
    ("code", "Bundle"),
    ("code", "SourceFile"),
    ("code", "Checked"),
    ("code", "Value"),
    ("code", "Shape"),
    ("code", "Payload"),
    ("code", "TypeMismatch"),
    ("code", "Step"),
    ("code", "Diagnostic"),
    ("code", "RuleName"),
    ("code", "Location"),
    ("code", "Note"),
    ("code", "Help"),
    ("code", "Fix"),
    ("code", "Edit"),
    ("code", "RunId"),
    ("code", "TaskPath"),
    ("code", "Segment"),
    ("code", "FactNumber"),
    ("code", "CallPosition"),
    ("code", "CallAt"),
    ("code", "Moment"),
    ("decimal", "Decimal"),
    ("dict", "Dict"),
    ("duration", "Duration"),
    ("int", "Int"),
    ("json", "Value"),
    ("json", "Names"),
    ("json", "DecodeError"),
    ("json", "Problem"),
    ("json", "Step"),
    ("list", "List"),
    ("media", "MediaType"),
    ("option", "Option"),
    ("path", "Path"),
    ("result", "Result"),
    ("set", "Set"),
    ("task", "Task"),
    ("task", "Stop"),
    ("task", "Call"),
    ("task", "Tagged"),
    ("text", "Text"),
    ("time", "Instant"),
    ("time", "Timed"),
    ("tool", "Problem"),
    ("url", "Url"),
];