Skip to content

Commit

Permalink
Merge pull request #89 from Wodann/fix/cached-struct-type
Browse files Browse the repository at this point in the history
fix(struct): prevent erroneous caching of struct types
  • Loading branch information
Wodann authored Jan 30, 2020
2 parents 869e4b8 + 4c850ab commit 78cbcde
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/mun_codegen/src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub(crate) fn ir_query(db: &impl IrDatabase, ty: Ty) -> AnyTypeEnum {
/// Returns the LLVM IR type of the specified struct
pub fn struct_ty_query(db: &impl IrDatabase, s: hir::Struct) -> StructType {
let name = s.name(db).to_string();
for field in s.fields(db).iter() {
// Ensure that salsa's cached value incorporates the struct fields
let _field_type_ir = db.type_ir(field.ty(db));
}

db.context().opaque_struct_type(&name)
}

Expand Down
36 changes: 36 additions & 0 deletions crates/mun_runtime/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,39 @@ fn marshal_struct() {
let bar_err: Result<Struct, _> = invoke_fn!(driver.runtime, "bar_new", bar);
assert!(bar_err.is_err());
}

#[test]
fn hotreload_struct_decl() {
let mut driver = TestDriver::new(
r#"
struct(value) Args {
n: int,
foo: Bar,
}
struct(gc) Bar {
m: float,
}
fn args(): Args {
Args { n: 3, foo: Bar { m: 1.0 }, }
}
"#,
);
driver.update(
r#"
struct(value) Args {
n: int,
foo: Bar,
}
struct(gc) Bar {
m: int,
}
fn args(): Args {
Args { n: 3, foo: Bar { m: 1 }, }
}
"#,
);
}

0 comments on commit 78cbcde

Please sign in to comment.