artiq/symbol_resolver: Handle type of zero-length lists
This commit is contained in:
parent
51c2175c80
commit
3db3061d99
|
@ -991,8 +991,15 @@ impl InnerResolver {
|
||||||
}
|
}
|
||||||
_ => unreachable!("must be list"),
|
_ => unreachable!("must be list"),
|
||||||
};
|
};
|
||||||
let ty = ctx.get_llvm_type(generator, elem_ty);
|
|
||||||
let size_t = generator.get_size_type(ctx.ctx);
|
let size_t = generator.get_size_type(ctx.ctx);
|
||||||
|
let ty = if len == 0
|
||||||
|
&& matches!(&*ctx.unifier.get_ty_immutable(elem_ty), TypeEnum::TVar { .. })
|
||||||
|
{
|
||||||
|
// The default type for zero-length lists of unknown element type is size_t
|
||||||
|
size_t.into()
|
||||||
|
} else {
|
||||||
|
ctx.get_llvm_type(generator, elem_ty)
|
||||||
|
};
|
||||||
let arr_ty = ctx
|
let arr_ty = ctx
|
||||||
.ctx
|
.ctx
|
||||||
.struct_type(&[ty.ptr_type(AddressSpace::default()).into(), size_t.into()], false);
|
.struct_type(&[ty.ptr_type(AddressSpace::default()).into(), size_t.into()], false);
|
||||||
|
|
|
@ -951,9 +951,9 @@ pub fn destructure_range<'ctx>(
|
||||||
/// Allocates a List structure with the given [type][ty] and [length]. The name of the resulting
|
/// Allocates a List structure with the given [type][ty] and [length]. The name of the resulting
|
||||||
/// LLVM value is `{name}.addr`, or `list.addr` if [name] is not specified.
|
/// LLVM value is `{name}.addr`, or `list.addr` if [name] is not specified.
|
||||||
///
|
///
|
||||||
/// Setting `ty` to [`None`] implies that the list does not have a known element type, which is only
|
/// Setting `ty` to [`None`] implies that the list is empty **and** does not have a known element
|
||||||
/// valid for empty lists. It is undefined behavior to generate a sized list with an unknown element
|
/// type, and will therefore set the `list.data` type as `size_t*`. It is undefined behavior to
|
||||||
/// type.
|
/// generate a sized list with an unknown element type.
|
||||||
pub fn allocate_list<'ctx, G: CodeGenerator + ?Sized>(
|
pub fn allocate_list<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
generator: &mut G,
|
generator: &mut G,
|
||||||
ctx: &mut CodeGenContext<'ctx, '_>,
|
ctx: &mut CodeGenContext<'ctx, '_>,
|
||||||
|
|
Loading…
Reference in New Issue