From 8b48833d7b692627200b6fa37f50bb05aafb51d9 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Sat, 16 Dec 2023 18:49:27 +0100 Subject: [PATCH] chore: Compile on stable rust on CI again The ICE has been fixed so we can restore stable compilation again. https://github.com/rust-lang/rust/issues/112832 --- .github/workflows/rust.yml | 2 +- tests/api.rs | 160 +++++++++++++++++++------------------ 2 files changed, 84 insertions(+), 78 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bac7db3c46..51af20e595 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - rust: [nightly] # This should be reverted back to [stable, nightly] when 1.74 is made the rustc stable version + rust: [stable, nightly] env: CRATE_NAME: gluon CARGO_INCREMENTAL: 0 # Incremental compilation is slower and bloats the cache diff --git a/tests/api.rs b/tests/api.rs index 1d121a4c5a..2055ef8f64 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -16,7 +16,6 @@ use gluon::{ query::Compilation, vm::{ api::{ - de::De, scoped::{Ref, RefMut}, FunctionRef, FutureResult, Hole, OpaqueValue, OwnedFunction, RuntimeResult, VmType, IO, }, @@ -298,47 +297,6 @@ fn tuples_start_at_0() { ); } -#[test] -fn use_type_from_type_field() { - let _ = ::env_logger::try_init(); - let vm = make_vm(); - - #[derive(Serialize, Deserialize, PartialEq, Debug)] - enum Test { - A(i32), - B(String), - C, - } - impl VmType for Test { - type Type = Self; - fn make_type(vm: &Thread) -> ArcType { - if let Some(typ) = vm.get_type::() { - return typ; - } - - let (name, typ) = gluon::vm::api::typ::from_rust::(vm).unwrap(); - vm.register_type_as( - name.clone(), - Alias::new(name, Vec::new(), typ), - ::std::any::TypeId::of::(), - ) - .unwrap() - } - } - - add_extern_module(&vm, "test_types", |vm| { - ExternModule::new(vm, record! { type Test => Test }) - }); - let text = r#" - let { Test } = import! test_types - B "abc" - "#; - let (De(actual), _) = vm - .run_expr::>("test", text) - .unwrap_or_else(|err| panic!("{}", err)); - assert_eq!(actual, Test::B("abc".to_string())); -} - #[test] fn use_rust_created_tuple_as_polymorphic() { let _ = ::env_logger::try_init(); @@ -368,41 +326,6 @@ fn use_rust_created_record_as_polymorphic() { assert_eq!(result, 1); } -#[test] -fn return_btreemap() { - let _ = ::env_logger::try_init(); - - let vm = make_vm(); - - add_extern_module_with_deps( - &vm, - "test", - |vm| { - ExternModule::new( - vm, - primitive!(1, "test", |()| { - vec![("a".to_string(), 1), ("b".to_string(), 2)] - .into_iter() - .collect::>() - }), - ) - }, - vec!["std.map".into(), "std.json.de".into()], - ); - - vm.run_expr::<()>("", "let _ = import! test in ()") - .unwrap_or_else(|err| panic!("{}", err)); - let (result, _) = vm - .run_expr::>("", "(import! test) ()") - .unwrap_or_else(|err| panic!("{}", err)); - assert_eq!( - result, - vec![("a".to_string(), 1), ("b".to_string(), 2)] - .into_iter() - .collect::>() - ); -} - #[test] fn get_value_boxed_or_unboxed() { let _ = ::env_logger::try_init(); @@ -777,3 +700,86 @@ fn clone_userdata() { assert_eq!(*result, Test(123)); } + +#[cfg(feature = "serialization")] +mod serialization { + use super::*; + + use gluon::vm::api::de::De; + + #[test] + fn use_type_from_type_field() { + let _ = ::env_logger::try_init(); + let vm = make_vm(); + + #[derive(Serialize, Deserialize, PartialEq, Debug)] + enum Test { + A(i32), + B(String), + C, + } + impl VmType for Test { + type Type = Self; + fn make_type(vm: &Thread) -> ArcType { + if let Some(typ) = vm.get_type::() { + return typ; + } + + let (name, typ) = gluon::vm::api::typ::from_rust::(vm).unwrap(); + vm.register_type_as( + name.clone(), + Alias::new(name, Vec::new(), typ), + ::std::any::TypeId::of::(), + ) + .unwrap() + } + } + + add_extern_module(&vm, "test_types", |vm| { + ExternModule::new(vm, record! { type Test => Test }) + }); + let text = r#" + let { Test } = import! test_types + B "abc" + "#; + let (De(actual), _) = vm + .run_expr::>("test", text) + .unwrap_or_else(|err| panic!("{}", err)); + assert_eq!(actual, Test::B("abc".to_string())); + } + + #[test] + fn return_btreemap() { + let _ = ::env_logger::try_init(); + + let vm = make_vm(); + + add_extern_module_with_deps( + &vm, + "test", + |vm| { + ExternModule::new( + vm, + primitive!(1, "test", |()| { + vec![("a".to_string(), 1), ("b".to_string(), 2)] + .into_iter() + .collect::>() + }), + ) + }, + vec!["std.map".into(), "std.json.de".into()], + ); + + vm.run_expr::<()>("", "let _ = import! test in ()") + .unwrap_or_else(|err| panic!("{}", err)); + let (result, _) = vm + .run_expr::>("", "(import! test) ()") + .unwrap_or_else(|err| panic!("{}", err)); + assert_eq!( + result, + vec![("a".to_string(), 1), ("b".to_string(), 2)] + .into_iter() + .collect::>() + ); + } +}