Update bindgen to use new formatting

This commit is contained in:
Richard Feldman 2022-05-22 22:11:36 -04:00
parent 0456ea4f19
commit 096b738f1e
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798
3 changed files with 24 additions and 24 deletions

View file

@ -287,7 +287,7 @@ fn add_tag_union(
return match payload_vars.len() {
0 => {
// This is a single-tag union with no payload, e.g. `[ Foo ]`
// This is a single-tag union with no payload, e.g. `[Foo]`
// so just generate an empty record
types.add(RocType::Struct {
name,
@ -295,7 +295,7 @@ fn add_tag_union(
})
}
1 => {
// This is a single-tag union with 1 payload field, e.g.`[ Foo Str ]`.
// This is a single-tag union with 1 payload field, e.g.`[Foo Str]`.
// We'll just wrap that.
let var = *payload_vars.get(0).unwrap();
let content = add_type(env, var, types);
@ -303,7 +303,7 @@ fn add_tag_union(
types.add(RocType::TransparentWrapper { name, content })
}
_ => {
// This is a single-tag union with multiple payload field, e.g.`[ Foo Str U32 ]`.
// This is a single-tag union with multiple payload field, e.g.`[Foo Str U32]`.
// Generate a record.
let fields = payload_vars.iter().enumerate().map(|(index, payload_var)| {
let field_name = format!("f{}", index).into();
@ -335,7 +335,7 @@ fn add_tag_union(
}
1 => {
// there's 1 payload item, so it doesn't need its own
// struct - e.g. for `[ Foo Str, Bar Str ]` both of them
// struct - e.g. for `[Foo Str, Bar Str]` both of them
// can have payloads of plain old Str, no struct wrapper needed.
let payload_var = payload_vars.get(0).unwrap();
let payload_id = add_type(env, *payload_var, types);
@ -376,30 +376,30 @@ fn add_tag_union(
match union_layout {
// A non-recursive tag union
// e.g. `Result ok err : [ Ok ok, Err err ]`
// e.g. `Result ok err : [Ok ok, Err err]`
NonRecursive(_) => RocType::TagUnion(RocTagUnion::NonRecursive { name, tags }),
// A recursive tag union (general case)
// e.g. `Expr : [ Sym Str, Add Expr Expr ]`
// e.g. `Expr : [Sym Str, Add Expr Expr]`
Recursive(_) => {
todo!()
}
// A recursive tag union with just one constructor
// Optimization: No need to store a tag ID (the payload is "unwrapped")
// e.g. `RoseTree a : [ Tree a (List (RoseTree a)) ]`
// e.g. `RoseTree a : [Tree a (List (RoseTree a))]`
NonNullableUnwrapped(_) => {
todo!()
}
// A recursive tag union that has an empty variant
// Optimization: Represent the empty variant as null pointer => no memory usage & fast comparison
// It has more than one other variant, so they need tag IDs (payloads are "wrapped")
// e.g. `FingerTree a : [ Empty, Single a, More (Some a) (FingerTree (Tuple a)) (Some a) ]`
// e.g. `FingerTree a : [Empty, Single a, More (Some a) (FingerTree (Tuple a)) (Some a)]`
// see also: https://youtu.be/ip92VMpf_-A?t=164
NullableWrapped { .. } => {
todo!()
}
// A recursive tag union with only two variants, where one is empty.
// Optimizations: Use null for the empty variant AND don't store a tag ID for the other variant.
// e.g. `ConsList a : [ Nil, Cons a (ConsList a) ]`
// e.g. `ConsList a : [Nil, Cons a (ConsList a)]`
NullableUnwrapped { nullable_id, .. } => {
// NullableUnwrapped tag unions should always have exactly 2 tags.
debug_assert_eq!(tags.len(), 2);

View file

@ -486,20 +486,20 @@ pub enum RocTagUnion {
tags: Vec<String>,
},
/// A non-recursive tag union
/// e.g. `Result a e : [ Ok a, Err e ]`
/// e.g. `Result a e : [Ok a, Err e]`
NonRecursive {
name: String,
tags: Vec<(String, Option<TypeId>)>,
},
/// A recursive tag union (general case)
/// e.g. `Expr : [ Sym Str, Add Expr Expr ]`
/// e.g. `Expr : [Sym Str, Add Expr Expr]`
Recursive {
name: String,
tags: Vec<(String, Option<TypeId>)>,
},
/// A recursive tag union with just one constructor
/// Optimization: No need to store a tag ID (the payload is "unwrapped")
/// e.g. `RoseTree a : [ Tree a (List (RoseTree a)) ]`
/// e.g. `RoseTree a : [Tree a (List (RoseTree a))]`
NonNullableUnwrapped {
name: String,
content: TypeId,
@ -508,7 +508,7 @@ pub enum RocTagUnion {
/// A recursive tag union that has an empty variant
/// Optimization: Represent the empty variant as null pointer => no memory usage & fast comparison
/// It has more than one other variant, so they need tag IDs (payloads are "wrapped")
/// e.g. `FingerTree a : [ Empty, Single a, More (Some a) (FingerTree (Tuple a)) (Some a) ]`
/// e.g. `FingerTree a : [Empty, Single a, More (Some a) (FingerTree (Tuple a)) (Some a)]`
/// see also: https://youtu.be/ip92VMpf_-A?t=164
NullableWrapped {
name: String,
@ -518,12 +518,12 @@ pub enum RocTagUnion {
/// A recursive tag union with only two variants, where one is empty.
/// Optimizations: Use null for the empty variant AND don't store a tag ID for the other variant.
/// e.g. `ConsList a : [ Nil, Cons a (ConsList a) ]`
/// e.g. `ConsList a : [Nil, Cons a (ConsList a)]`
NullableUnwrapped {
name: String,
/// e.g. Nil in `StrConsList : [ Nil, Cons Str (ConsList Str) ]`
/// e.g. Nil in `StrConsList : [Nil, Cons Str (ConsList Str)]`
null_tag: String,
/// e.g. Cons in `StrConsList : [ Nil, Cons Str (ConsList Str) ]`
/// e.g. Cons in `StrConsList : [Nil, Cons Str (ConsList Str)]`
non_null_tag: String,
/// There must be a payload associated with the non-null tag.
/// Otherwise, this would have been an Enumeration!

View file

@ -47,7 +47,7 @@ mod test_gen_rs {
Inner : { a : U16, b : F32 }
main : Outer
main = { x: { a: 5, b: 24 }, y: "foo", z: [ 1, 2 ] }
main = { x: { a: 5, b: 24 }, y: "foo", z: [1, 2] }
"#
);
@ -99,7 +99,7 @@ mod test_gen_rs {
#[test]
fn nested_record_anonymous() {
let module = r#"main = { x: { a: 5u16, b: 24f32 }, y: "foo", z: [ 1u8, 2 ] }"#;
let module = r#"main = { x: { a: 5u16, b: 24f32 }, y: "foo", z: [1u8, 2] }"#;
assert_eq!(
generate_bindings(module)
@ -130,7 +130,7 @@ mod test_gen_rs {
fn tag_union_aliased() {
let module = indoc!(
r#"
NonRecursive : [ Foo Str, Bar U128, Blah I32, Baz ]
NonRecursive : [Foo Str, Bar U128, Blah I32, Baz]
main : NonRecursive
main = Foo "blah"
@ -429,7 +429,7 @@ mod test_gen_rs {
fn tag_union_enumeration() {
let module = indoc!(
r#"
Enumeration : [ Blah, Foo, Bar, ]
Enumeration : [Blah, Foo, Bar,]
main : Enumeration
main = Foo
@ -468,7 +468,7 @@ mod test_gen_rs {
fn single_tag_union_with_payloads() {
let module = indoc!(
r#"
UserId : [ Id U32 Str ]
UserId : [Id U32 Str]
main : UserId
main = Id 42 "blah"
@ -496,7 +496,7 @@ mod test_gen_rs {
fn single_tag_union_with_one_payload_field() {
let module = indoc!(
r#"
UserId : [ Id Str ]
UserId : [Id Str]
main : UserId
main = Id "blah"
@ -521,7 +521,7 @@ mod test_gen_rs {
fn cons_list_of_strings() {
let module = indoc!(
r#"
StrConsList : [ Nil, Cons Str StrConsList ]
StrConsList : [Nil, Cons Str StrConsList]
main : StrConsList
main = Cons "Hello, " (Cons "World!" Nil)
@ -657,7 +657,7 @@ mod test_gen_rs {
fn cons_list_of_ints() {
let module = indoc!(
r#"
IntConsList : [ Empty, Prepend U16 IntConsList ]
IntConsList : [Empty, Prepend U16 IntConsList]
main : IntConsList
main = Prepend 42 (Prepend 26 Empty)