Skip to main content

flow_types/
std_roles.rs

1//! Where std declares each [`Role`], and the shape it declares it with,
2//! as the bundled std's `@lang` marks say. Generated by flow-check's
3//! `std_roles` test from std's sources; `FLOW_BLESS=1 cargo test -p
4//! flow-check --test std_roles` rewrites it. Do not edit.
5
6use std::sync::Arc;
7
8use crate::{Constructor, EnumShape, Payload, RecordShape, Role};
9
10/// The shape a role's declaration has, when it is a record or an enum.
11#[derive(Clone, Debug)]
12pub enum Shape {
13    /// A record's.
14    Record(Arc<RecordShape>),
15    /// An enum's.
16    Enum(Arc<EnumShape>),
17}
18
19impl Role {
20    /// The std declaration that plays it: its module's path in std and
21    /// its name.
22    pub const fn identity(self) -> (&'static str, &'static str) {
23        match self {
24            Role::Int => ("int", "Int"),
25            Role::Decimal => ("decimal", "Decimal"),
26            Role::Bool => ("prelude", "Bool"),
27            Role::Text => ("text", "Text"),
28            Role::Bytes => ("bytes", "Bytes"),
29            Role::List => ("list", "List"),
30            Role::Dict => ("dict", "Dict"),
31            Role::Set => ("set", "Set"),
32            Role::Unit => ("prelude", "Unit"),
33            Role::Never => ("prelude", "Never"),
34            Role::Option => ("option", "Option"),
35            Role::Result => ("result", "Result"),
36            Role::ToolProblem => ("prelude", "ToolProblem"),
37            Role::Task => ("task", "Task"),
38            Role::TaskTagged => ("task", "Tagged"),
39            Role::TaskStopOutcome => ("task", "Stop"),
40            Role::TaskCall => ("task", "Call"),
41            Role::Instant => ("time", "Instant"),
42            Role::Duration => ("duration", "Duration"),
43            Role::JsonValue => ("json", "Value"),
44            Role::JsonDecodeError => ("json", "DecodeError"),
45            Role::JsonProblem => ("json", "Problem"),
46            Role::JsonStep => ("json", "Step"),
47            Role::JsonNames => ("json", "Names"),
48            Role::Path => ("path", "Path"),
49            Role::Url => ("url", "Url"),
50            Role::MediaType => ("media", "MediaType"),
51            Role::RunId => ("code", "RunId"),
52            Role::TaskPath => ("code", "TaskPath"),
53            Role::SourcePath => ("code", "SourcePath"),
54            Role::CodeTypeMismatch => ("code", "TypeMismatch"),
55            Role::CodeStep => ("code", "Step"),
56            Role::IntLiteral => ("int", "Int"),
57            Role::DecimalLiteral => ("decimal", "Decimal"),
58            Role::TextLiteral => ("text", "Text"),
59            Role::ListLiteral => ("list", "List"),
60            Role::DictLiteral => ("dict", "Dict"),
61        }
62    }
63
64    /// The role the std declaration `name` in the module `module` plays,
65    /// the first of [`Role::ALL`] when it plays more than one.
66    pub fn of(module: &str, name: &str) -> Option<Role> {
67        match (module, name) {
68            ("int", "Int") => Some(Role::Int),
69            ("decimal", "Decimal") => Some(Role::Decimal),
70            ("prelude", "Bool") => Some(Role::Bool),
71            ("text", "Text") => Some(Role::Text),
72            ("bytes", "Bytes") => Some(Role::Bytes),
73            ("list", "List") => Some(Role::List),
74            ("dict", "Dict") => Some(Role::Dict),
75            ("set", "Set") => Some(Role::Set),
76            ("prelude", "Unit") => Some(Role::Unit),
77            ("prelude", "Never") => Some(Role::Never),
78            ("option", "Option") => Some(Role::Option),
79            ("result", "Result") => Some(Role::Result),
80            ("prelude", "ToolProblem") => Some(Role::ToolProblem),
81            ("task", "Task") => Some(Role::Task),
82            ("task", "Tagged") => Some(Role::TaskTagged),
83            ("task", "Stop") => Some(Role::TaskStopOutcome),
84            ("task", "Call") => Some(Role::TaskCall),
85            ("time", "Instant") => Some(Role::Instant),
86            ("duration", "Duration") => Some(Role::Duration),
87            ("json", "Value") => Some(Role::JsonValue),
88            ("json", "DecodeError") => Some(Role::JsonDecodeError),
89            ("json", "Problem") => Some(Role::JsonProblem),
90            ("json", "Step") => Some(Role::JsonStep),
91            ("json", "Names") => Some(Role::JsonNames),
92            ("path", "Path") => Some(Role::Path),
93            ("url", "Url") => Some(Role::Url),
94            ("media", "MediaType") => Some(Role::MediaType),
95            ("code", "RunId") => Some(Role::RunId),
96            ("code", "TaskPath") => Some(Role::TaskPath),
97            ("code", "SourcePath") => Some(Role::SourcePath),
98            ("code", "TypeMismatch") => Some(Role::CodeTypeMismatch),
99            ("code", "Step") => Some(Role::CodeStep),
100            _ => None,
101        }
102    }
103
104    /// The shape its declaration has, when it is a record or an enum.
105    pub fn shape(self) -> Option<Shape> {
106        match self {
107            Role::Int => None,
108            Role::Decimal => None,
109            Role::Bool => None,
110            Role::Text => None,
111            Role::Bytes => None,
112            Role::List => None,
113            Role::Dict => None,
114            Role::Set => None,
115            Role::Unit => None,
116            Role::Never => None,
117            Role::Option => Some(Shape::Enum(EnumShape::new("Option", [Constructor::new("None", Payload::None), Constructor::new("Some", Payload::Positional(1))]))),
118            Role::Result => Some(Shape::Enum(EnumShape::new("Result", [Constructor::new("Ok", Payload::Positional(1)), Constructor::new("Err", Payload::Positional(1))]))),
119            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"]))]))),
120            Role::Task => None,
121            Role::TaskTagged => None,
122            Role::TaskStopOutcome => Some(Shape::Enum(EnumShape::new("Stop", [Constructor::new("Finished", Payload::Positional(1)), Constructor::new("Stopped", Payload::None)]))),
123            Role::TaskCall => Some(Shape::Record(RecordShape::new("Call", ["args", "answer", "site"]))),
124            Role::Instant => None,
125            Role::Duration => None,
126            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))]))),
127            Role::JsonDecodeError => Some(Shape::Record(RecordShape::new("DecodeError", ["path", "problem"]))),
128            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)]))),
129            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))]))),
130            Role::JsonNames => Some(Shape::Enum(EnumShape::new("Names", [Constructor::new("Exact", Payload::None), Constructor::new("Relaxed", Payload::None)]))),
131            Role::Path => None,
132            Role::Url => None,
133            Role::MediaType => None,
134            Role::RunId => None,
135            Role::TaskPath => None,
136            Role::SourcePath => None,
137            Role::CodeTypeMismatch => Some(Shape::Record(RecordShape::new("TypeMismatch", ["wanted", "found", "path"]))),
138            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))]))),
139            Role::IntLiteral => None,
140            Role::DecimalLiteral => None,
141            Role::TextLiteral => None,
142            Role::ListLiteral => None,
143            Role::DictLiteral => None,
144        }
145    }
146}
147
148/// Every public type std declares, as its module's path in std and its
149/// name.
150pub const STD_TYPES: &[(&str, &str)] = &[
151    ("prelude", "Int"),
152    ("prelude", "Decimal"),
153    ("prelude", "Text"),
154    ("prelude", "Bytes"),
155    ("prelude", "List"),
156    ("prelude", "Dict"),
157    ("prelude", "Set"),
158    ("prelude", "Option"),
159    ("prelude", "Result"),
160    ("prelude", "Bool"),
161    ("prelude", "Unit"),
162    ("prelude", "Never"),
163    ("prelude", "ToolProblem"),
164    ("bytes", "Bytes"),
165    ("code", "Program"),
166    ("code", "Module"),
167    ("code", "Import"),
168    ("code", "Reexport"),
169    ("code", "ModulePath"),
170    ("code", "Tree"),
171    ("code", "Repository"),
172    ("code", "Tag"),
173    ("code", "DeclId"),
174    ("code", "Name"),
175    ("code", "Span"),
176    ("code", "Position"),
177    ("code", "Decl"),
178    ("code", "Signature"),
179    ("code", "Param"),
180    ("code", "Function"),
181    ("code", "BodylessFunction"),
182    ("code", "Constant"),
183    ("code", "Annotation"),
184    ("code", "LocalId"),
185    ("code", "Binding"),
186    ("code", "TypeDecl"),
187    ("code", "TypeBody"),
188    ("code", "FieldDecl"),
189    ("code", "ConstructorDecl"),
190    ("code", "PayloadDecl"),
191    ("code", "LocalDecl"),
192    ("code", "LocalSignature"),
193    ("code", "Type"),
194    ("code", "Owner"),
195    ("code", "SourcePath"),
196    ("code", "ToolRef"),
197    ("code", "LocalRef"),
198    ("code", "Bundle"),
199    ("code", "SourceFile"),
200    ("code", "Checked"),
201    ("code", "Value"),
202    ("code", "Shape"),
203    ("code", "Payload"),
204    ("code", "TypeMismatch"),
205    ("code", "Step"),
206    ("code", "Diagnostic"),
207    ("code", "RuleName"),
208    ("code", "Location"),
209    ("code", "Note"),
210    ("code", "Help"),
211    ("code", "Fix"),
212    ("code", "Edit"),
213    ("code", "RunId"),
214    ("code", "TaskPath"),
215    ("code", "Segment"),
216    ("code", "FactNumber"),
217    ("code", "CallPosition"),
218    ("code", "CallAt"),
219    ("code", "Moment"),
220    ("decimal", "Decimal"),
221    ("dict", "Dict"),
222    ("duration", "Duration"),
223    ("int", "Int"),
224    ("json", "Value"),
225    ("json", "Names"),
226    ("json", "DecodeError"),
227    ("json", "Problem"),
228    ("json", "Step"),
229    ("list", "List"),
230    ("media", "MediaType"),
231    ("option", "Option"),
232    ("path", "Path"),
233    ("result", "Result"),
234    ("set", "Set"),
235    ("task", "Task"),
236    ("task", "Stop"),
237    ("task", "Call"),
238    ("task", "Tagged"),
239    ("text", "Text"),
240    ("time", "Instant"),
241    ("time", "Timed"),
242    ("tool", "Problem"),
243    ("url", "Url"),
244];