Skip to content

Commit

Permalink
chore: Compile on stable rust on CI again
Browse files Browse the repository at this point in the history
The ICE has been fixed so we can restore stable compilation again.

rust-lang/rust#112832
  • Loading branch information
Marwes committed Dec 16, 2023
1 parent 6431991 commit 8b48833
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
160 changes: 83 additions & 77 deletions tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use gluon::{
query::Compilation,
vm::{
api::{
de::De,
scoped::{Ref, RefMut},
FunctionRef, FutureResult, Hole, OpaqueValue, OwnedFunction, RuntimeResult, VmType, IO,
},
Expand Down Expand Up @@ -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::<Self>() {
return typ;
}

let (name, typ) = gluon::vm::api::typ::from_rust::<Self>(vm).unwrap();
vm.register_type_as(
name.clone(),
Alias::new(name, Vec::new(), typ),
::std::any::TypeId::of::<Self>(),
)
.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::<De<Test>>("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();
Expand Down Expand Up @@ -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::<BTreeMap<_, _>>()
}),
)
},
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::<BTreeMap<_, _>>("", "(import! test) ()")
.unwrap_or_else(|err| panic!("{}", err));
assert_eq!(
result,
vec![("a".to_string(), 1), ("b".to_string(), 2)]
.into_iter()
.collect::<BTreeMap<_, _>>()
);
}

#[test]
fn get_value_boxed_or_unboxed() {
let _ = ::env_logger::try_init();
Expand Down Expand Up @@ -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::<Self>() {
return typ;
}

let (name, typ) = gluon::vm::api::typ::from_rust::<Self>(vm).unwrap();
vm.register_type_as(
name.clone(),
Alias::new(name, Vec::new(), typ),
::std::any::TypeId::of::<Self>(),
)
.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::<De<Test>>("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::<BTreeMap<_, _>>()
}),
)
},
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::<BTreeMap<_, _>>("", "(import! test) ()")
.unwrap_or_else(|err| panic!("{}", err));
assert_eq!(
result,
vec![("a".to_string(), 1), ("b".to_string(), 2)]
.into_iter()
.collect::<BTreeMap<_, _>>()
);
}
}

0 comments on commit 8b48833

Please sign in to comment.