Skip to content

Commit

Permalink
Merge #593
Browse files Browse the repository at this point in the history
593: fix(vm): Correctly assign record field names in derive(Pushable) r=Marwes a=Marwes

Fixes #591

Co-authored-by: Markus Westerlind <marwes91@gmail.com>
  • Loading branch information
bors[bot] and Marwes committed Jul 25, 2018
2 parents a6af9aa + 4a36d82 commit 38e59f7
Show file tree
Hide file tree
Showing 39 changed files with 3,087 additions and 2,617 deletions.
13 changes: 10 additions & 3 deletions base/src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ impl KindEnv for EmptyEnv<Symbol> {
/// These types include `Option` and `(->)` which both have the kind `Type -> Type -> Type`
/// as well as `Functor` which has the kind `Type -> Type -> Type`.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(serialize_state = "::serialization::SeSeed"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(serialize_state = "::serialization::SeSeed")
)]
#[cfg_attr(feature = "serde_derive", serde(de_parameters = "S"))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "S"))]
#[cfg_attr(
feature = "serde_derive", serde(bound(deserialize = "S: AsMut<::serialization::NodeMap>"))
feature = "serde_derive",
serde(bound(deserialize = "S: AsMut<::serialization::NodeMap>"))
)]
pub enum Kind {
Hole,
Expand Down
10 changes: 8 additions & 2 deletions base/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,14 @@ impl<'seed, T, S> AsMut<S> for SharedSeed<'seed, T, S> {
#[derive(DeserializeState, SerializeState)]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "S"))]
#[cfg_attr(feature = "serde_derive", serde(de_parameters = "S"))]
#[cfg_attr(feature = "serde_derive", serde(bound(deserialize = "T: DeserializeState<'de, S>")))]
#[cfg_attr(feature = "serde_derive", serde(bound(serialize = "T: SerializeState<S>")))]
#[cfg_attr(
feature = "serde_derive",
serde(bound(deserialize = "T: DeserializeState<'de, S>"))
)]
#[cfg_attr(
feature = "serde_derive",
serde(bound(serialize = "T: SerializeState<S>"))
)]
#[cfg_attr(feature = "serde_derive", serde(ser_parameters = "S"))]
#[cfg_attr(feature = "serde_derive", serde(serialize_state = "S"))]
pub enum Variant<T> {
Expand Down
5 changes: 4 additions & 1 deletion base/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ where

#[derive(Eq)]
#[cfg_attr(feature = "serde_derive", derive(SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(serialize_state = "::serialization::SeSeed"))]
#[cfg_attr(
feature = "serde_derive",
serde(serialize_state = "::serialization::SeSeed")
)]
pub struct SymbolRef(str);

impl fmt::Debug for SymbolRef {
Expand Down
104 changes: 83 additions & 21 deletions base/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,15 @@ impl BuiltinType {
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(feature = "serde_derive", serde(serialize_state = "SeSeed"))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, T>"))]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, T>")
)]
#[cfg_attr(feature = "serde_derive", serde(de_parameters = "Id, T"))]
pub struct TypeVariable {
#[cfg_attr(feature = "serde_derive", serde(state))]
Expand All @@ -217,8 +223,14 @@ pub struct TypeVariable {
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, T>"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, T>")
)]
#[cfg_attr(
feature = "serde_derive",
serde(
Expand All @@ -230,7 +242,10 @@ pub struct TypeVariable {
)]
#[cfg_attr(feature = "serde_derive", serde(de_parameters = "T"))]
#[cfg_attr(feature = "serde_derive", serde(serialize_state = "SeSeed"))]
#[cfg_attr(feature = "serde_derive", serde(bound(serialize = "Id: SerializeState<SeSeed>")))]
#[cfg_attr(
feature = "serde_derive",
serde(bound(serialize = "Id: SerializeState<SeSeed>"))
)]
pub struct Skolem<Id> {
#[cfg_attr(feature = "serde_derive", serde(state))]
pub name: Id,
Expand All @@ -240,8 +255,14 @@ pub struct Skolem<Id> {
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, T>"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, T>")
)]
#[cfg_attr(
feature = "serde_derive",
serde(
Expand All @@ -253,7 +274,10 @@ pub struct Skolem<Id> {
)]
#[cfg_attr(feature = "serde_derive", serde(de_parameters = "T"))]
#[cfg_attr(feature = "serde_derive", serde(serialize_state = "SeSeed"))]
#[cfg_attr(feature = "serde_derive", serde(bound(serialize = "Id: SerializeState<SeSeed>")))]
#[cfg_attr(
feature = "serde_derive",
serde(bound(serialize = "Id: SerializeState<SeSeed>"))
)]
pub struct Generic<Id> {
#[cfg_attr(feature = "serde_derive", serde(state))]
pub id: Id,
Expand All @@ -270,8 +294,14 @@ impl<Id> Generic<Id> {
/// An alias is wrapper around `Type::Alias`, allowing it to be cheaply converted to a type and
/// dereferenced to `AliasRef`
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, T>"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, T>")
)]
#[cfg_attr(
feature = "serde_derive",
serde(
Expand All @@ -283,7 +313,10 @@ impl<Id> Generic<Id> {
)
)]
#[cfg_attr(feature = "serde_derive", serde(serialize_state = "SeSeed"))]
#[cfg_attr(feature = "serde_derive", serde(bound(serialize = "T: SerializeState<SeSeed>")))]
#[cfg_attr(
feature = "serde_derive",
serde(bound(serialize = "T: SerializeState<SeSeed>"))
)]
pub struct Alias<Id, T> {
#[cfg_attr(feature = "serde_derive", serde(state))]
_typ: T,
Expand Down Expand Up @@ -397,8 +430,14 @@ where
/// Data for a type alias. Probably you want to use `Alias` instead of this directly as Alias allows
/// for cheap conversion back into a type as well.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, T>"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, T>")
)]
#[cfg_attr(
feature = "serde_derive",
serde(
Expand All @@ -422,7 +461,8 @@ pub struct AliasRef<Id, T> {
serde(deserialize_state_with = "::serialization::deserialize_group")
)]
#[cfg_attr(
feature = "serde_derive", serde(serialize_state_with = "::serialization::shared::serialize")
feature = "serde_derive",
serde(serialize_state_with = "::serialization::shared::serialize")
)]
/// The other aliases defined in this group
pub group: Arc<Vec<AliasData<Id, T>>>,
Expand Down Expand Up @@ -470,8 +510,14 @@ where
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, T>"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, T>")
)]
#[cfg_attr(
feature = "serde_derive",
serde(
Expand Down Expand Up @@ -557,8 +603,14 @@ impl<Id, T> Deref for AliasRef<Id, T> {
}

#[derive(Clone, Hash, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, U>"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, U>")
)]
#[cfg_attr(feature = "serde_derive", serde(de_parameters = "U"))]
#[cfg_attr(
feature = "serde_derive",
Expand Down Expand Up @@ -612,8 +664,14 @@ pub enum ArgType {
/// `Type` such as `Type::app` and `Type::record` when constructing types as those will construct
/// the pointer wrapper directly.
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde_derive", derive(DeserializeState, SerializeState))]
#[cfg_attr(feature = "serde_derive", serde(deserialize_state = "Seed<Id, T>"))]
#[cfg_attr(
feature = "serde_derive",
derive(DeserializeState, SerializeState)
)]
#[cfg_attr(
feature = "serde_derive",
serde(deserialize_state = "Seed<Id, T>")
)]
#[cfg_attr(
feature = "serde_derive",
serde(
Expand Down Expand Up @@ -648,7 +706,11 @@ pub enum Type<Id, T = ArcType<Id>> {
/// `Map String Int` would be represented as `App(Map, [String, Int])`.
App(
#[cfg_attr(feature = "serde_derive", serde(state))] T,
#[cfg_attr(feature = "serde_derive", serde(state_with = "::serialization::seq"))] AppVec<T>,
#[cfg_attr(
feature = "serde_derive",
serde(state_with = "::serialization::seq")
)]
AppVec<T>,
),
/// Function type which can have a explicit or implicit argument
Function(
Expand Down
3 changes: 2 additions & 1 deletion check/src/unify_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ where
(
&Type::Function(l_arg_type, ref l_arg, ref l_ret),
&Type::Function(r_arg_type, ref r_arg, ref r_ret),
) if l_arg_type == r_arg_type =>
)
if l_arg_type == r_arg_type =>
{
let arg = unifier.try_match(l_arg, r_arg);
let ret = unifier.try_match(l_ret, r_ret);
Expand Down
3 changes: 2 additions & 1 deletion check/tests/implicits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ let eq_string l r : String -> String -> Bool = True
_ => match expr.value {
ast::Expr::Infix {
ref implicit_args, ..
} if implicit_args.len() == 1 =>
}
if implicit_args.len() == 1 =>
{
let env = MockEnv::new();
assert_eq!(
Expand Down
50 changes: 25 additions & 25 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Various macros for integrating with the `gluon` vm.
//!
//! ## Derive Macros
//!
//!
//! Custom derives for the following `gluon`-Traits are available:
//!
//! ### Getable
Expand All @@ -10,25 +10,25 @@
//! `Getable` (generic type parameters included). If the type is generic over a
//! lifetime, the lifetime will be constrained to that of the `'vm` lifetime in the
//! trait definition.
//!
//!
//! #### Examples
//!
//!
//! Marhalling this gluon type:
//!
//!
//! ```gluon
//! type Comment =
//! type Comment =
//! | Normal String
//! | Multiline String
//! | Doc String
//! ```
//!
//!
//! To this rust enum:
//!
//!
//! ```rust
//! #[macro_use]
//! extern crate gluon_codegen;
//! extern crate gluon;
//!
//!
//! enum Comment {
//! Normal(String),
//! Multiline(String),
Expand All @@ -41,26 +41,26 @@
//!
//! Derives `Pushable` for any enum or struct as long as all fields also implement
//! `Pushable` (generic type parameters included).
//!
//!
//! #### Examples
//!
//!
//! Allowing the `User` struct to be marshalled to gluon code:
//!
//!
//! ```rust
//! #[macro_use]
//! extern crate gluon_codegen;
//! extern crate gluon;
//!
//!
//! #[derive(Pushable)]
//! struct User {
//! name: String,
//! age: u32,
//! }
//! # fn main() {}
//! ```
//!
//!
//! As this compatible Record:
//!
//!
//! ```gluon
//! type User = { name: String, age: Int }
//! ```
Expand All @@ -74,22 +74,22 @@
//!
//! If the rust type has type parameters, they have to implement `VmType` as well.
//! All lifetimes have to be `'static`.
//!
//!
//! #### Examples
//!
//!
//! Assuming the following gluon type in the module `types`:
//!
//!
//! ```gluon
//! type Either l r = | Left l | Right r
//! ```
//!
//!
//! This will map the correct rust type to it:
//!
//!
//! ```rust
//! #[macro_use]
//! extern crate gluon_codegen;
//! extern crate gluon;
//!
//!
//! #[derive(VmType)]
//! #[gluon(vm_type = "types.Either")]
//! enum Either<L, R> {
Expand All @@ -104,18 +104,18 @@
//! Derives `Userdata` and the required `Traverseable` and `VmType` for a rust type.
//! Note that you will still have to use `Thread::register_type` to register the
//! rust type with the vm before it is used.
//!
//!
//! #### Examples
//!
//!
//! Deriving `Userdata` for a type that will be opaque for the gluon code:
//!
//!
//! ```rust
//! #[macro_use]
//! extern crate gluon_codegen;
//! extern crate gluon;
//!
//!
//! use std::sync::Arc;
//!
//!
//! // Userdata requires Debug + Send + Sync
//! #[derive(Userdata, Debug)]
//! struct Ident {
Expand Down
Loading

0 comments on commit 38e59f7

Please sign in to comment.