mun-lang / mun

Source code for the Mun language and runtime.
https://mun-lang.org
Other
1.83k stars 73 forks source link

Make the `layout` specific to primitives and structs #443

Closed baszalmstra closed 1 year ago

baszalmstra commented 2 years ago

Currently, all types store a layout which describes the size and alignment of storing a specific Type. For primitives and structs this is a dynamic value but for arrays and pointers this value is always the same (the layout of a *const c_void).

We should remove this from the TypeData struct and instead store the layout only in the TypeDataKind of structs and primitives.

baszalmstra commented 1 year ago

Im not sure if this is still needed. The ABI already doesn't store layouts for arrays or pointers since we use TypeIds for them now. The only place this is now stored is in the mun_memory::Type however there I think it makes sense because the layout refers to the stack size of storing the element.

These methods are implemented for mun_codegen::Type, maybe we could explain the difference a little better?

/// Returns the memory layout of the data of the type. This is the layout of the memory when
/// stored on the stack or in the heap.
pub fn value_layout(&self) -> Layout {
  ...
}

/// Returns the layout of the type when being referenced.
pub fn reference_layout(&self) -> Layout {
  ...
}
Wodann commented 1 year ago

The existing comments LGTM.