Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pub unsupported for Rust tuple struct in Getable derive macro #713

Closed
tyler-conrad opened this issue Apr 16, 2019 · 1 comment · Fixed by #714 or #754
Closed

pub unsupported for Rust tuple struct in Getable derive macro #713

tyler-conrad opened this issue Apr 16, 2019 · 1 comment · Fixed by #714 or #754

Comments

@tyler-conrad
Copy link

The macro for Getable derive doesn't seem to support the pub keyword. I've modified this example:
https://github.com/gluon-lang/gluon/blob/master/codegen/tests/full.rs
to highlight the issue. Note the struct Newtype(pub Struct); line.

extern crate gluon;
#[macro_use]
extern crate gluon_codegen;
#[macro_use]
extern crate gluon_vm;

use gluon::{
    new_vm,
    Thread,
    Compiler,
    vm::{
        self,
        ExternModule,
    },
    import,
};

#[derive(Debug, PartialEq, Getable, Pushable, VmType)]
struct Struct {
    string: String,
    number: u32,
    vec: Vec<f64>,
}

fn load_struct_mod(vm: &Thread) -> vm::Result<ExternModule> {
    let module = record! {
        new_struct => primitive!(1, new_struct),
    };

    ExternModule::new(vm, module)
}

fn new_struct(_: ()) -> Struct {
    Struct {
        string: "hello".to_owned(),
        number: 1,
        vec: vec![1.0, 2.0, 3.0],
    }
}

#[test]
fn normal_struct() {
    let vm = new_vm();
    let mut compiler = Compiler::new();
    import::add_extern_module(&vm, "functions", load_struct_mod);

    let script = r#"
        let { new_struct } = import! functions

        new_struct ()
    "#;

    let (s, _) = compiler
        .run_expr::<Struct>(&vm, "test", script)
        .unwrap_or_else(|why| panic!("{}", why));

    assert_eq!(
        s,
        Struct {
            string: "hello".into(),
            number: 1,
            vec: vec![1.0, 2.0, 3.0],
        }
    );
}

#[derive(Debug, PartialEq, VmType, Pushable, Getable)]
struct Newtype(pub Struct);

fn load_newtype_mod(vm: &Thread) -> vm::Result<ExternModule> {
    let module = record! {
        newtype_id => primitive!(1, newtype_id),
    };

    ExternModule::new(vm, module)
}

fn newtype_id(val: Newtype) -> Newtype {
    val
}

#[test]
fn newtype() {
    let vm = new_vm();
    let mut compiler = Compiler::new();
    import::add_extern_module(&vm, "functions", load_newtype_mod);

    // newtypes should map to the inner type
    let script = r#"
        let { newtype_id } = import! functions
        newtype_id { string = "test", number = 42, vec = [1.0, 1.0, 2.0, 3.0, 5.0] }
    "#;

    let (s, _) = compiler
        .run_expr::<Newtype>(&vm, "test", script)
        .unwrap_or_else(|why| panic!("{}", why));

    assert_eq!(
        s,
        Newtype(Struct {
            string: "test".into(),
            number: 42,
            vec: vec![1.0, 1.0, 2.0, 3.0, 5.0],
        })
    );
}

This is the error I get:

error: expected type, found keyword `pub`
  --> src/main.rs:68:16
   |
68 | struct Newtype(pub Struct);
   |                ^^^

error: proc-macro derive produced unparseable tokens
  --> src/main.rs:67:46
   |
67 | #[derive(Debug, PartialEq, VmType, Pushable, Getable)]
   |                                              ^^^^^^^

error: aborting due to 2 previous errors
Marwes added a commit to Marwes/gluon that referenced this issue Apr 16, 2019
bors bot added a commit that referenced this issue Apr 16, 2019
714: fix: Handle newtypes with a public field r=Marwes a=Marwes

Fixes #713

Co-authored-by: Markus Westerlind <marwes91@gmail.com>
@Marwes
Copy link
Member

Marwes commented Apr 16, 2019

Thanks! Fixed with #714

@bors bors bot closed this as completed in #714 Apr 16, 2019
Marwes added a commit to Marwes/gluon that referenced this issue Jul 6, 2019
<a name="v0.12.0"></a>
## v0.12.0 (2019-07-06)

#### Bug Fixes

*   Remove Userdata and Trace impls for RwLock and Mutex ([e90f02b](gluon-lang@e90f02b))
*   Add missing negate function from the prelude ([0091f47](gluon-lang@0091f47))
*   Refer to registered types by their full name ([a2daace](gluon-lang@a2daace), breaks [#](https://github.com/gluon-lang/gluon/issues/))
*   Handle newtypes with a public field ([d1fef96](gluon-lang@d1fef96), closes [gluon-lang#713](gluon-lang#713))
*   Don't ICE on unapplied, aliased constructors ([2a44a0d](gluon-lang@2a44a0d))
* **check:**
  *  Propagate metadata through parens ([bd767c0](gluon-lang@bd767c0))
  *  Bring nested implicit instances into scope ([ad82bde](gluon-lang@ad82bde))
  *  Don't lose type information in catch-all ([d2a3fbf](gluon-lang@d2a3fbf), closes [gluon-lang#702](gluon-lang#702), [gluon-lang#703](gluon-lang#703), [gluon-lang#704](gluon-lang#704), [gluon-lang#705](gluon-lang#705))
* **codegen:**  Return exactly the same type on VmType derive on enum ([375d3e9](gluon-lang@375d3e9))
* **compiler:**  Don't panic when matching a tuple against an alias ([777bd31](gluon-lang@777bd31), closes [gluon-lang#749](gluon-lang#749))
* **std:**
  *  cleaned up statet.glu exports ([5d8864f](gluon-lang@5d8864f))
  *  export wrap_monad from transformer.glu ([0e9d7bc](gluon-lang@0e9d7bc))
* **vm:**
  *  Check if a collection is needed when creating a child thread ([86e4b9f](gluon-lang@86e4b9f))
  *  Automatically remove the elements added to pushed data ([8cd5152](gluon-lang@8cd5152), closes [gluon-lang#719](gluon-lang#719))

#### Performance

*   Use NonNull for garbage collected pointers ([9c66ede](gluon-lang@9c66ede))
*   Don't recurse into already visited records to find implicits ([b50061f](gluon-lang@b50061f))
*   Avoid recursing into non-implicit types ([c35b29e](gluon-lang@c35b29e))
*   Use SmallVec in Partition ([d8c549b](gluon-lang@d8c549b))
*   Use a scoped collections over a persistent in implicit resolution ([d13097e](gluon-lang@d13097e))
*   Memoize implicit attribute lookups (-3%) ([254af75](gluon-lang@254af75))
*   Speedup Symbol::module ([9566a37](gluon-lang@9566a37))
*   Avoid creating function types unnecessarily ([170f467](gluon-lang@170f467))
* **compiler:**
  *  Shrink the core::Expr type to 40 bytes (from 72) ([779d1b6](gluon-lang@779d1b6))
  *  Copy elements directly into arena ([cd2dd36](gluon-lang@cd2dd36))

#### Features

*   Add gc::Mutex ([d6e1246](gluon-lang@d6e1246))
*   Automatically unroot values stored in `Gc` allocated values ([6ebc398](gluon-lang@6ebc398), closes [gluon-lang#746](gluon-lang#746))
*   Add derive for Traverseable ([844418d](gluon-lang@844418d))
*   Allow mutable references to be passed to gluon ([602220b](gluon-lang@602220b))
*   Add std.env ([b561c8d](gluon-lang@b561c8d))
*   Implement woobly type propagation ([a0b8452](gluon-lang@a0b8452))
* **codegen:**  Add the newtype attribute ([4085463](gluon-lang@4085463))
* **completion:**
  *  Match on the symbols in type declarations ([9d28ba1](gluon-lang@9d28ba1))
  *  Return scoped symbols in the all_symbols query ([94a385a](gluon-lang@94a385a))
  *  Match on the symbols in type declarations ([8fe083a](gluon-lang@8fe083a))
  *  Return scoped symbols in the all_symbols query ([1ad302b](gluon-lang@1ad302b))
* **doc:**  Link to the github source ([da75875](gluon-lang@da75875))
* **vm:**  Allow references to be passed through ([3a92b17](gluon-lang@3a92b17))

#### Breaking Changes

*   Refer to registered types by their full name ([a2daace](gluon-lang@a2daace), breaks [#](https://github.com/gluon-lang/gluon/issues/))
@Marwes Marwes mentioned this issue Jul 6, 2019
bors bot added a commit that referenced this issue Jul 6, 2019
754: Version 0.12.0 r=Marwes a=Marwes

<a name="v0.12.0"></a>
## v0.12.0 (2019-07-06)

#### Bug Fixes

*   Remove Userdata and Trace impls for RwLock and Mutex ([e90f02b](e90f02b))
*   Add missing negate function from the prelude ([0091f47](0091f47))
*   Refer to registered types by their full name ([a2daace](a2daace), breaks [#](https://github.com/gluon-lang/gluon/issues/))
*   Handle newtypes with a public field ([d1fef96](d1fef96), closes [#713](#713))
*   Don't ICE on unapplied, aliased constructors ([2a44a0d](2a44a0d))
* **check:**
  *  Propagate metadata through parens ([bd767c0](bd767c0))
  *  Bring nested implicit instances into scope ([ad82bde](ad82bde))
  *  Don't lose type information in catch-all ([d2a3fbf](d2a3fbf), closes [#702](#702), [#703](#703), [#704](#704), [#705](#705))
* **codegen:**  Return exactly the same type on VmType derive on enum ([375d3e9](375d3e9))
* **compiler:**  Don't panic when matching a tuple against an alias ([777bd31](777bd31), closes [#749](#749))
* **std:**
  *  cleaned up statet.glu exports ([5d8864f](5d8864f))
  *  export wrap_monad from transformer.glu ([0e9d7bc](0e9d7bc))
* **vm:**
  *  Check if a collection is needed when creating a child thread ([86e4b9f](86e4b9f))
  *  Automatically remove the elements added to pushed data ([8cd5152](8cd5152), closes [#719](#719))

#### Performance

*   Use NonNull for garbage collected pointers ([9c66ede](9c66ede))
*   Don't recurse into already visited records to find implicits ([b50061f](b50061f))
*   Avoid recursing into non-implicit types ([c35b29e](c35b29e))
*   Use SmallVec in Partition ([d8c549b](d8c549b))
*   Use a scoped collections over a persistent in implicit resolution ([d13097e](d13097e))
*   Memoize implicit attribute lookups (-3%) ([254af75](254af75))
*   Speedup Symbol::module ([9566a37](9566a37))
*   Avoid creating function types unnecessarily ([170f467](170f467))
* **compiler:**
  *  Shrink the core::Expr type to 40 bytes (from 72) ([779d1b6](779d1b6))
  *  Copy elements directly into arena ([cd2dd36](cd2dd36))

#### Features

*   Add gc::Mutex ([d6e1246](d6e1246))
*   Automatically unroot values stored in `Gc` allocated values ([6ebc398](6ebc398), closes [#746](#746))
*   Add derive for Traverseable ([844418d](844418d))
*   Allow mutable references to be passed to gluon ([602220b](602220b))
*   Add std.env ([b561c8d](b561c8d))
*   Implement woobly type propagation ([a0b8452](a0b8452))
* **codegen:**  Add the newtype attribute ([4085463](4085463))
* **completion:**
  *  Match on the symbols in type declarations ([9d28ba1](9d28ba1))
  *  Return scoped symbols in the all_symbols query ([94a385a](94a385a))
  *  Match on the symbols in type declarations ([8fe083a](8fe083a))
  *  Return scoped symbols in the all_symbols query ([1ad302b](1ad302b))
* **doc:**  Link to the github source ([da75875](da75875))
* **vm:**  Allow references to be passed through ([3a92b17](3a92b17))

#### Breaking Changes

*   Refer to registered types by their full name ([a2daace](a2daace), breaks [#](https://github.com/gluon-lang/gluon/issues/))

Co-authored-by: Markus Westerlind <marwes91@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants