mlabs-haskell / lambda-buffers

LambdaBuffers toolkit for sharing types and their semantics between different languages
https://mlabs-haskell.github.io/lambda-buffers/
Apache License 2.0
29 stars 0 forks source link

Rust codegen: Json correctness impacted by Result/Either ty arg mismatch #242

Open bladyjoker opened 1 month ago

bladyjoker commented 1 month ago

Why do tests succeed?

https://github.com/mlabs-haskell/lambda-buffers/blob/0670960b08aa65a4c6e0bb4bc9e276c21d0f32b7/testsuites/lbt-prelude/lbt-prelude-rust/tests/goldens.rs#L161-L163

We defined goldens in Rust with Rust's Result and not LBs Either alias (https://github.com/mlabs-haskell/lambda-buffers/blob/0670960b08aa65a4c6e0bb4bc9e276c21d0f32b7/lambda-buffers-codegen/data/rust-prelude-base.json#L18-L22)

Where's the error coming from?

We alias LB Prelude.Either<A,B> into Rust's Result<A,B> but the order of type arguments is switched

enum Result<T, E> {
   Ok(T),
   Err(E),
}

The code generated

#![no_implicit_prelude]
#![allow(warnings)]
extern crate lbr_prelude;
extern crate num_bigint;
extern crate std;

pub type Bool = std::primitive::bool;

pub type Bytes = std::vec::Vec<u8>;

pub type Char = char;

pub type Either<A,B> = std::result::Result<A,B>; !!!!!!!!!!!!!!!! PROBLEM!!!!!!!!!!!!!!!

pub type Integer = num_bigint::BigInt;

pub type List<A> = std::vec::Vec<A>;

pub type Map<A,B> = std::collections::BTreeMap<A,B>;

pub type Maybe<A> = std::option::Option<A>;

pub type Set<A> = std::collections::BTreeSet<A>;

pub type Text = std::string::String;
bladyjoker commented 1 month ago

This was solved in #243 . We still have to update lambda-buffers-demo and then we can close it.