authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-08-30 02:54:03+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-09-20 02:29:04+02:00
logc5945467acfd580cb3413250ef52f13dc412a8cf
treecd56aa35c06a65ec51a3ade3a3bbb90eb33cb8a1
parent7a5d0cdf45f861f63d89666607dc86b3a2810826

Address Spaces: Pointer and function info in @Type


11 files changed, 121 insertions(+), 48 deletions(-)

lib/std/builtin.zig+2
...@@ -235,6 +235,7 @@ pub const TypeInfo = union(enum) {...@@ -235,6 +235,7 @@ pub const TypeInfo = union(enum) {
235 is_const: bool,235 is_const: bool,
236 is_volatile: bool,236 is_volatile: bool,
237 alignment: comptime_int,237 alignment: comptime_int,
238 address_space: AddressSpace,
238 child: type,239 child: type,
239 is_allowzero: bool,240 is_allowzero: bool,
240241
...@@ -364,6 +365,7 @@ pub const TypeInfo = union(enum) {...@@ -364,6 +365,7 @@ pub const TypeInfo = union(enum) {
364 pub const Fn = struct {365 pub const Fn = struct {
365 calling_convention: CallingConvention,366 calling_convention: CallingConvention,
366 alignment: comptime_int,367 alignment: comptime_int,
368 address_space: AddressSpace,
367 is_generic: bool,369 is_generic: bool,
368 is_var_args: bool,370 is_var_args: bool,
369 return_type: ?type,371 return_type: ?type,
lib/std/mem.zig+2
...@@ -2472,6 +2472,7 @@ fn CopyPtrAttrs(comptime source: type, comptime size: std.builtin.TypeInfo.Point...@@ -2472,6 +2472,7 @@ fn CopyPtrAttrs(comptime source: type, comptime size: std.builtin.TypeInfo.Point
2472 .is_volatile = info.is_volatile,2472 .is_volatile = info.is_volatile,
2473 .is_allowzero = info.is_allowzero,2473 .is_allowzero = info.is_allowzero,
2474 .alignment = info.alignment,2474 .alignment = info.alignment,
2475 .address_space = info.address_space,
2475 .child = child,2476 .child = child,
2476 .sentinel = null,2477 .sentinel = null,
2477 },2478 },
...@@ -2960,6 +2961,7 @@ fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: u29) typ...@@ -2960,6 +2961,7 @@ fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: u29) typ
2960 .is_volatile = info.is_volatile,2961 .is_volatile = info.is_volatile,
2961 .is_allowzero = info.is_allowzero,2962 .is_allowzero = info.is_allowzero,
2962 .alignment = new_alignment,2963 .alignment = new_alignment,
2964 .address_space = info.address_space,
2963 .child = info.child,2965 .child = info.child,
2964 .sentinel = null,2966 .sentinel = null,
2965 },2967 },
lib/std/meta.zig+3
...@@ -235,6 +235,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -235,6 +235,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
235 .is_const = info.is_const,235 .is_const = info.is_const,
236 .is_volatile = info.is_volatile,236 .is_volatile = info.is_volatile,
237 .alignment = info.alignment,237 .alignment = info.alignment,
238 .address_space = info.address_space,
238 .child = @Type(.{239 .child = @Type(.{
239 .Array = .{240 .Array = .{
240 .len = array_info.len,241 .len = array_info.len,
...@@ -254,6 +255,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -254,6 +255,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
254 .is_const = info.is_const,255 .is_const = info.is_const,
255 .is_volatile = info.is_volatile,256 .is_volatile = info.is_volatile,
256 .alignment = info.alignment,257 .alignment = info.alignment,
258 .address_space = info.address_space,
257 .child = info.child,259 .child = info.child,
258 .is_allowzero = info.is_allowzero,260 .is_allowzero = info.is_allowzero,
259 .sentinel = sentinel_val,261 .sentinel = sentinel_val,
...@@ -271,6 +273,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {...@@ -271,6 +273,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
271 .is_const = ptr_info.is_const,273 .is_const = ptr_info.is_const,
272 .is_volatile = ptr_info.is_volatile,274 .is_volatile = ptr_info.is_volatile,
273 .alignment = ptr_info.alignment,275 .alignment = ptr_info.alignment,
276 .address_space = ptr_info.address_space,
274 .child = ptr_info.child,277 .child = ptr_info.child,
275 .is_allowzero = ptr_info.is_allowzero,278 .is_allowzero = ptr_info.is_allowzero,
276 .sentinel = sentinel_val,279 .sentinel = sentinel_val,
lib/std/zig/c_translation.zig+1
...@@ -325,6 +325,7 @@ pub fn FlexibleArrayType(comptime SelfType: type, ElementType: type) type {...@@ -325,6 +325,7 @@ pub fn FlexibleArrayType(comptime SelfType: type, ElementType: type) type {
325 .is_const = ptr.is_const,325 .is_const = ptr.is_const,
326 .is_volatile = ptr.is_volatile,326 .is_volatile = ptr.is_volatile,
327 .alignment = @alignOf(ElementType),327 .alignment = @alignOf(ElementType),
328 .address_space = .generic,
328 .child = ElementType,329 .child = ElementType,
329 .is_allowzero = true,330 .is_allowzero = true,
330 .sentinel = null,331 .sentinel = null,
src/Sema.zig+10-5
...@@ -6413,7 +6413,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -6413,7 +6413,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
64136413
6414 switch (ty.zigTypeTag()) {6414 switch (ty.zigTypeTag()) {
6415 .Fn => {6415 .Fn => {
6416 const field_values = try sema.arena.alloc(Value, 6);6416 const field_values = try sema.arena.alloc(Value, 7);
6417 // calling_convention: CallingConvention,6417 // calling_convention: CallingConvention,
6418 field_values[0] = try Value.Tag.enum_field_index.create(6418 field_values[0] = try Value.Tag.enum_field_index.create(
6419 sema.arena,6419 sema.arena,
...@@ -6421,14 +6421,19 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr...@@ -6421,14 +6421,19 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr
6421 );6421 );
6422 // alignment: comptime_int,6422 // alignment: comptime_int,
6423 field_values[1] = try Value.Tag.int_u64.create(sema.arena, ty.abiAlignment(target));6423 field_values[1] = try Value.Tag.int_u64.create(sema.arena, ty.abiAlignment(target));
6424 // address_space: AddressSpace,
6425 field_values[2] = try Value.Tag.enum_field_index.create(
6426 sema.arena,
6427 @enumToInt(ty.fnAddressSpace()),
6428 );
6424 // is_generic: bool,6429 // is_generic: bool,
6425 field_values[2] = Value.initTag(.bool_false); // TODO
6426 // is_var_args: bool,
6427 field_values[3] = Value.initTag(.bool_false); // TODO6430 field_values[3] = Value.initTag(.bool_false); // TODO
6431 // is_var_args: bool,
6432 field_values[4] = Value.initTag(.bool_false); // TODO
6428 // return_type: ?type,6433 // return_type: ?type,
6429 field_values[4] = try Value.Tag.ty.create(sema.arena, ty.fnReturnType());6434 field_values[5] = try Value.Tag.ty.create(sema.arena, ty.fnReturnType());
6430 // args: []const FnArg,6435 // args: []const FnArg,
6431 field_values[5] = Value.initTag(.null_value); // TODO6436 field_values[6] = Value.initTag(.null_value); // TODO
64326437
6433 return sema.addConstant(6438 return sema.addConstant(
6434 type_info_ty,6439 type_info_ty,
src/stage1/all_types.hpp+8
...@@ -86,6 +86,14 @@ enum CallingConvention {...@@ -86,6 +86,14 @@ enum CallingConvention {
86 CallingConventionSysV86 CallingConventionSysV
87};87};
8888
89// Stage 1 supports only the generic address space
90enum AddressSpace {
91 AddressSpaceGeneric,
92 AddressSpaceGS,
93 AddressSpaceFS,
94 AddressSpaceSS,
95};
96
89// This one corresponds to the builtin.zig enum.97// This one corresponds to the builtin.zig enum.
90enum BuiltinPtrSize {98enum BuiltinPtrSize {
91 BuiltinPtrSizeOne,99 BuiltinPtrSizeOne,
src/stage1/analyze.cpp+10
...@@ -1019,6 +1019,16 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {...@@ -1019,6 +1019,16 @@ bool calling_convention_allows_zig_types(CallingConvention cc) {
1019 zig_unreachable();1019 zig_unreachable();
1020}1020}
10211021
1022const char *address_space_name(AddressSpace as) {
1023 switch (as) {
1024 case AddressSpaceGeneric: return "generic";
1025 case AddressSpaceGS: return "gs";
1026 case AddressSpaceFS: return "fs";
1027 case AddressSpaceSS: return "ss";
1028 }
1029 zig_unreachable();
1030}
1031
1022ZigType *get_stack_trace_type(CodeGen *g) {1032ZigType *get_stack_trace_type(CodeGen *g) {
1023 if (g->stack_trace_type == nullptr) {1033 if (g->stack_trace_type == nullptr) {
1024 g->stack_trace_type = get_builtin_type(g, "StackTrace");1034 g->stack_trace_type = get_builtin_type(g, "StackTrace");
src/stage1/analyze.hpp+2
...@@ -242,6 +242,8 @@ Error get_primitive_type(CodeGen *g, Buf *name, ZigType **result);...@@ -242,6 +242,8 @@ Error get_primitive_type(CodeGen *g, Buf *name, ZigType **result);
242bool calling_convention_allows_zig_types(CallingConvention cc);242bool calling_convention_allows_zig_types(CallingConvention cc);
243const char *calling_convention_name(CallingConvention cc);243const char *calling_convention_name(CallingConvention cc);
244244
245const char *address_space_name(AddressSpace as);
246
245Error ATTRIBUTE_MUST_USE file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents);247Error ATTRIBUTE_MUST_USE file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents);
246248
247void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk);249void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk);
src/stage1/ir.cpp+78-43
...@@ -16124,7 +16124,7 @@ static Stage1AirInst *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,...@@ -16124,7 +16124,7 @@ static Stage1AirInst *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
1612416124
16125static Stage1AirInst *ir_analyze_instruction_ctz(IrAnalyze *ira, Stage1ZirInstCtz *instruction) {16125static Stage1AirInst *ir_analyze_instruction_ctz(IrAnalyze *ira, Stage1ZirInstCtz *instruction) {
16126 Error err;16126 Error err;
16127 16127
16128 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);16128 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
16129 if (type_is_invalid(int_type))16129 if (type_is_invalid(int_type))
16130 return ira->codegen->invalid_inst_gen;16130 return ira->codegen->invalid_inst_gen;
...@@ -16166,7 +16166,7 @@ static Stage1AirInst *ir_analyze_instruction_ctz(IrAnalyze *ira, Stage1ZirInstCt...@@ -16166,7 +16166,7 @@ static Stage1AirInst *ir_analyze_instruction_ctz(IrAnalyze *ira, Stage1ZirInstCt
16166 return ira->codegen->invalid_inst_gen;16166 return ira->codegen->invalid_inst_gen;
16167 if (val->special == ConstValSpecialUndef)16167 if (val->special == ConstValSpecialUndef)
16168 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);16168 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
16169 16169
16170 if (is_vector) {16170 if (is_vector) {
16171 ZigType *smallest_vec_type = get_vector_type(ira->codegen, vector_len, smallest_type);16171 ZigType *smallest_vec_type = get_vector_type(ira->codegen, vector_len, smallest_type);
16172 Stage1AirInst *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, smallest_vec_type);16172 Stage1AirInst *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, smallest_vec_type);
...@@ -16200,7 +16200,7 @@ static Stage1AirInst *ir_analyze_instruction_ctz(IrAnalyze *ira, Stage1ZirInstCt...@@ -16200,7 +16200,7 @@ static Stage1AirInst *ir_analyze_instruction_ctz(IrAnalyze *ira, Stage1ZirInstCt
1620016200
16201static Stage1AirInst *ir_analyze_instruction_clz(IrAnalyze *ira, Stage1ZirInstClz *instruction) {16201static Stage1AirInst *ir_analyze_instruction_clz(IrAnalyze *ira, Stage1ZirInstClz *instruction) {
16202 Error err;16202 Error err;
16203 16203
16204 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);16204 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
16205 if (type_is_invalid(int_type))16205 if (type_is_invalid(int_type))
16206 return ira->codegen->invalid_inst_gen;16206 return ira->codegen->invalid_inst_gen;
...@@ -16242,7 +16242,7 @@ static Stage1AirInst *ir_analyze_instruction_clz(IrAnalyze *ira, Stage1ZirInstCl...@@ -16242,7 +16242,7 @@ static Stage1AirInst *ir_analyze_instruction_clz(IrAnalyze *ira, Stage1ZirInstCl
16242 return ira->codegen->invalid_inst_gen;16242 return ira->codegen->invalid_inst_gen;
16243 if (val->special == ConstValSpecialUndef)16243 if (val->special == ConstValSpecialUndef)
16244 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);16244 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
16245 16245
16246 if (is_vector) {16246 if (is_vector) {
16247 ZigType *smallest_vec_type = get_vector_type(ira->codegen, vector_len, smallest_type);16247 ZigType *smallest_vec_type = get_vector_type(ira->codegen, vector_len, smallest_type);
16248 Stage1AirInst *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, smallest_vec_type);16248 Stage1AirInst *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, smallest_vec_type);
...@@ -16276,7 +16276,7 @@ static Stage1AirInst *ir_analyze_instruction_clz(IrAnalyze *ira, Stage1ZirInstCl...@@ -16276,7 +16276,7 @@ static Stage1AirInst *ir_analyze_instruction_clz(IrAnalyze *ira, Stage1ZirInstCl
1627616276
16277static Stage1AirInst *ir_analyze_instruction_pop_count(IrAnalyze *ira, Stage1ZirInstPopCount *instruction) {16277static Stage1AirInst *ir_analyze_instruction_pop_count(IrAnalyze *ira, Stage1ZirInstPopCount *instruction) {
16278 Error err;16278 Error err;
16279 16279
16280 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);16280 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
16281 if (type_is_invalid(int_type))16281 if (type_is_invalid(int_type))
16282 return ira->codegen->invalid_inst_gen;16282 return ira->codegen->invalid_inst_gen;
...@@ -16318,7 +16318,7 @@ static Stage1AirInst *ir_analyze_instruction_pop_count(IrAnalyze *ira, Stage1Zir...@@ -16318,7 +16318,7 @@ static Stage1AirInst *ir_analyze_instruction_pop_count(IrAnalyze *ira, Stage1Zir
16318 return ira->codegen->invalid_inst_gen;16318 return ira->codegen->invalid_inst_gen;
16319 if (val->special == ConstValSpecialUndef)16319 if (val->special == ConstValSpecialUndef)
16320 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);16320 return ir_const_undef(ira, instruction->base.scope, instruction->base.source_node, ira->codegen->builtin_types.entry_num_lit_int);
16321 16321
16322 if (is_vector) {16322 if (is_vector) {
16323 ZigType *smallest_vec_type = get_vector_type(ira->codegen, vector_len, smallest_type);16323 ZigType *smallest_vec_type = get_vector_type(ira->codegen, vector_len, smallest_type);
16324 Stage1AirInst *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, smallest_vec_type);16324 Stage1AirInst *result = ir_const(ira, instruction->base.scope, instruction->base.source_node, smallest_vec_type);
...@@ -17904,7 +17904,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode...@@ -17904,7 +17904,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode
17904 result->special = ConstValSpecialStatic;17904 result->special = ConstValSpecialStatic;
17905 result->type = type_info_pointer_type;17905 result->type = type_info_pointer_type;
1790617906
17907 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 7);17907 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 8);
17908 result->data.x_struct.fields = fields;17908 result->data.x_struct.fields = fields;
1790917909
17910 // size: Size17910 // size: Size
...@@ -17939,24 +17939,29 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode...@@ -17939,24 +17939,29 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, Scope *scope, AstNode
17939 lazy_align_of->base.id = LazyValueIdAlignOf;17939 lazy_align_of->base.id = LazyValueIdAlignOf;
17940 lazy_align_of->target_type = ir_const_type(ira, scope, source_node, attrs_type->data.pointer.child_type);17940 lazy_align_of->target_type = ir_const_type(ira, scope, source_node, attrs_type->data.pointer.child_type);
17941 }17941 }
17942 // child: type17942 // address_space: AddressSpace,
17943 ensure_field_index(result->type, "child", 4);17943 ensure_field_index(result->type, "address_space", 4);
17944 fields[4]->special = ConstValSpecialStatic;17944 fields[4]->special = ConstValSpecialStatic;
17945 fields[4]->type = ira->codegen->builtin_types.entry_type;17945 fields[4]->type = get_builtin_type(ira->codegen, "AddressSpace");
17946 fields[4]->data.x_type = attrs_type->data.pointer.child_type;17946 bigint_init_unsigned(&fields[4]->data.x_enum_tag, AddressSpaceGeneric);
17947 // is_allowzero: bool17947 // child: type
17948 ensure_field_index(result->type, "is_allowzero", 5);17948 ensure_field_index(result->type, "child", 5);
17949 fields[5]->special = ConstValSpecialStatic;17949 fields[5]->special = ConstValSpecialStatic;
17950 fields[5]->type = ira->codegen->builtin_types.entry_bool;17950 fields[5]->type = ira->codegen->builtin_types.entry_type;
17951 fields[5]->data.x_bool = attrs_type->data.pointer.allow_zero;17951 fields[5]->data.x_type = attrs_type->data.pointer.child_type;
17952 // sentinel: anytype17952 // is_allowzero: bool
17953 ensure_field_index(result->type, "sentinel", 6);17953 ensure_field_index(result->type, "is_allowzero", 6);
17954 fields[6]->special = ConstValSpecialStatic;17954 fields[6]->special = ConstValSpecialStatic;
17955 fields[6]->type = ira->codegen->builtin_types.entry_bool;
17956 fields[6]->data.x_bool = attrs_type->data.pointer.allow_zero;
17957 // sentinel: anytype
17958 ensure_field_index(result->type, "sentinel", 7);
17959 fields[7]->special = ConstValSpecialStatic;
17955 if (attrs_type->data.pointer.sentinel != nullptr) {17960 if (attrs_type->data.pointer.sentinel != nullptr) {
17956 fields[6]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);17961 fields[7]->type = get_optional_type(ira->codegen, attrs_type->data.pointer.child_type);
17957 set_optional_payload(fields[6], attrs_type->data.pointer.sentinel);17962 set_optional_payload(fields[7], attrs_type->data.pointer.sentinel);
17958 } else {17963 } else {
17959 fields[6]->type = ira->codegen->builtin_types.entry_null;17964 fields[7]->type = ira->codegen->builtin_types.entry_null;
17960 }17965 }
1796117966
17962 return result;17967 return result;
...@@ -18465,7 +18470,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18465,7 +18470,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18465 result->special = ConstValSpecialStatic;18470 result->special = ConstValSpecialStatic;
18466 result->type = ir_type_info_get_type(ira, "Fn", nullptr);18471 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
1846718472
18468 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 6);18473 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 7);
18469 result->data.x_struct.fields = fields;18474 result->data.x_struct.fields = fields;
1847018475
18471 // calling_convention: TypeInfo.CallingConvention18476 // calling_convention: TypeInfo.CallingConvention
...@@ -18478,30 +18483,35 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18478,30 +18483,35 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18478 fields[1]->special = ConstValSpecialStatic;18483 fields[1]->special = ConstValSpecialStatic;
18479 fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;18484 fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
18480 bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(ira->codegen, type_entry));18485 bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(ira->codegen, type_entry));
18486 // address_space: AddressSpace
18487 ensure_field_index(result->type, "address_space", 2);
18488 fields[2]->special = ConstValSpecialStatic;
18489 fields[2]->type = get_builtin_type(ira->codegen, "AddressSpace");
18490 bigint_init_unsigned(&fields[2]->data.x_enum_tag, AddressSpaceGeneric);
18481 // is_generic: bool18491 // is_generic: bool
18482 ensure_field_index(result->type, "is_generic", 2);18492 ensure_field_index(result->type, "is_generic", 3);
18483 bool is_generic = type_entry->data.fn.is_generic;18493 bool is_generic = type_entry->data.fn.is_generic;
18484 fields[2]->special = ConstValSpecialStatic;
18485 fields[2]->type = ira->codegen->builtin_types.entry_bool;
18486 fields[2]->data.x_bool = is_generic;
18487 // is_varargs: bool
18488 ensure_field_index(result->type, "is_var_args", 3);
18489 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
18490 fields[3]->special = ConstValSpecialStatic;18494 fields[3]->special = ConstValSpecialStatic;
18491 fields[3]->type = ira->codegen->builtin_types.entry_bool;18495 fields[3]->type = ira->codegen->builtin_types.entry_bool;
18492 fields[3]->data.x_bool = is_varargs;18496 fields[3]->data.x_bool = is_generic;
18493 // return_type: ?type18497 // is_varargs: bool
18494 ensure_field_index(result->type, "return_type", 4);18498 ensure_field_index(result->type, "is_var_args", 4);
18499 bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args;
18495 fields[4]->special = ConstValSpecialStatic;18500 fields[4]->special = ConstValSpecialStatic;
18496 fields[4]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);18501 fields[4]->type = ira->codegen->builtin_types.entry_bool;
18502 fields[4]->data.x_bool = is_varargs;
18503 // return_type: ?type
18504 ensure_field_index(result->type, "return_type", 5);
18505 fields[5]->special = ConstValSpecialStatic;
18506 fields[5]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type);
18497 if (type_entry->data.fn.fn_type_id.return_type == nullptr)18507 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
18498 fields[4]->data.x_optional = nullptr;18508 fields[5]->data.x_optional = nullptr;
18499 else {18509 else {
18500 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();18510 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();
18501 return_type->special = ConstValSpecialStatic;18511 return_type->special = ConstValSpecialStatic;
18502 return_type->type = ira->codegen->builtin_types.entry_type;18512 return_type->type = ira->codegen->builtin_types.entry_type;
18503 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;18513 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
18504 fields[4]->data.x_optional = return_type;18514 fields[5]->data.x_optional = return_type;
18505 }18515 }
18506 // args: []TypeInfo.FnArg18516 // args: []TypeInfo.FnArg
18507 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);18517 ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr);
...@@ -18516,7 +18526,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour...@@ -18516,7 +18526,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour
18516 fn_arg_array->data.x_array.special = ConstArraySpecialNone;18526 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
18517 fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);18527 fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
1851818528
18519 init_const_slice(ira->codegen, fields[5], fn_arg_array, 0, fn_arg_count, false, nullptr);18529 init_const_slice(ira->codegen, fields[6], fn_arg_array, 0, fn_arg_count, false, nullptr);
1852018530
18521 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {18531 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
18522 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];18532 FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index];
...@@ -18826,11 +18836,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -18826,11 +18836,11 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
18826 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));18836 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
18827 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);18837 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
18828 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);18838 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
18829 ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 4);18839 ZigType *elem_type = get_const_field_meta_type(ira, source_node, payload, "child", 5);
18830 if (type_is_invalid(elem_type))18840 if (type_is_invalid(elem_type))
18831 return ira->codegen->invalid_inst_gen->value->type;18841 return ira->codegen->invalid_inst_gen->value->type;
18832 ZigValue *sentinel;18842 ZigValue *sentinel;
18833 if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 6,18843 if ((err = get_const_field_sentinel(ira, scope, source_node, payload, "sentinel", 7,
18834 elem_type, &sentinel)))18844 elem_type, &sentinel)))
18835 {18845 {
18836 return ira->codegen->invalid_inst_gen->value->type;18846 return ira->codegen->invalid_inst_gen->value->type;
...@@ -18845,6 +18855,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -18845,6 +18855,19 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
18845 if (alignment == nullptr)18855 if (alignment == nullptr)
18846 return ira->codegen->invalid_inst_gen->value->type;18856 return ira->codegen->invalid_inst_gen->value->type;
1884718857
18858 ZigValue *as_value = get_const_field(ira, source_node, payload, "address_space", 4);
18859 if (as_value == nullptr)
18860 return ira->codegen->invalid_inst_gen->value->type;
18861 assert(as_value->special == ConstValSpecialStatic);
18862 assert(as_value->type == get_builtin_type(ira->codegen, "AddressSpace"));
18863 AddressSpace as = (AddressSpace)bigint_as_u32(&as_value->data.x_enum_tag);
18864 if (as != AddressSpaceGeneric) {
18865 ir_add_error_node(ira, source_node, buf_sprintf(
18866 "address space '%s' not available in stage 1 compiler, must be .generic",
18867 address_space_name(as)));
18868 return ira->codegen->invalid_inst_gen->value->type;
18869 }
18870
18848 bool is_const;18871 bool is_const;
18849 if ((err = get_const_field_bool(ira, source_node, payload, "is_const", 1, &is_const)))18872 if ((err = get_const_field_bool(ira, source_node, payload, "is_const", 1, &is_const)))
18850 return ira->codegen->invalid_inst_gen->value->type;18873 return ira->codegen->invalid_inst_gen->value->type;
...@@ -18857,13 +18880,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -18857,13 +18880,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
18857 }18880 }
1885818881
18859 bool is_allowzero;18882 bool is_allowzero;
18860 if ((err = get_const_field_bool(ira, source_node, payload, "is_allowzero", 5,18883 if ((err = get_const_field_bool(ira, source_node, payload, "is_allowzero", 6,
18861 &is_allowzero)))18884 &is_allowzero)))
18862 {18885 {
18863 return ira->codegen->invalid_inst_gen->value->type;18886 return ira->codegen->invalid_inst_gen->value->type;
18864 }18887 }
1886518888
18866
18867 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,18889 ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen,
18868 elem_type,18890 elem_type,
18869 is_const,18891 is_const,
...@@ -19308,9 +19330,22 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -19308,9 +19330,22 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
19308 if (alignment == nullptr)19330 if (alignment == nullptr)
19309 return ira->codegen->invalid_inst_gen->value->type;19331 return ira->codegen->invalid_inst_gen->value->type;
1931019332
19333 ZigValue *as_value = get_const_field(ira, source_node, payload, "address_space", 2);
19334 if (as_value == nullptr)
19335 return ira->codegen->invalid_inst_gen->value->type;
19336 assert(as_value->special == ConstValSpecialStatic);
19337 assert(as_value->type == get_builtin_type(ira->codegen, "AddressSpace"));
19338 AddressSpace as = (AddressSpace)bigint_as_u32(&as_value->data.x_enum_tag);
19339 if (as != AddressSpaceGeneric) {
19340 ir_add_error_node(ira, source_node, buf_sprintf(
19341 "address space '%s' not available in stage 1 compiler, must be .generic",
19342 address_space_name(as)));
19343 return ira->codegen->invalid_inst_gen->value->type;
19344 }
19345
19311 Error err;19346 Error err;
19312 bool is_generic;19347 bool is_generic;
19313 if ((err = get_const_field_bool(ira, source_node, payload, "is_generic", 2, &is_generic)))19348 if ((err = get_const_field_bool(ira, source_node, payload, "is_generic", 3, &is_generic)))
19314 return ira->codegen->invalid_inst_gen->value->type;19349 return ira->codegen->invalid_inst_gen->value->type;
19315 if (is_generic) {19350 if (is_generic) {
19316 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type"));19351 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type"));
...@@ -19318,20 +19353,20 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_...@@ -19318,20 +19353,20 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_
19318 }19353 }
1931919354
19320 bool is_var_args;19355 bool is_var_args;
19321 if ((err = get_const_field_bool(ira, source_node, payload, "is_var_args", 3, &is_var_args)))19356 if ((err = get_const_field_bool(ira, source_node, payload, "is_var_args", 4, &is_var_args)))
19322 return ira->codegen->invalid_inst_gen->value->type;19357 return ira->codegen->invalid_inst_gen->value->type;
19323 if (is_var_args && cc != CallingConventionC) {19358 if (is_var_args && cc != CallingConventionC) {
19324 ir_add_error_node(ira, source_node, buf_sprintf("varargs functions must have C calling convention"));19359 ir_add_error_node(ira, source_node, buf_sprintf("varargs functions must have C calling convention"));
19325 return ira->codegen->invalid_inst_gen->value->type;19360 return ira->codegen->invalid_inst_gen->value->type;
19326 }19361 }
1932719362
19328 ZigType *return_type = get_const_field_meta_type_optional(ira, source_node, payload, "return_type", 4);19363 ZigType *return_type = get_const_field_meta_type_optional(ira, source_node, payload, "return_type", 5);
19329 if (return_type == nullptr) {19364 if (return_type == nullptr) {
19330 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type"));19365 ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type"));
19331 return ira->codegen->invalid_inst_gen->value->type;19366 return ira->codegen->invalid_inst_gen->value->type;
19332 }19367 }
1933319368
19334 ZigValue *args_value = get_const_field(ira, source_node, payload, "args", 5);19369 ZigValue *args_value = get_const_field(ira, source_node, payload, "args", 6);
19335 if (args_value == nullptr)19370 if (args_value == nullptr)
19336 return ira->codegen->invalid_inst_gen->value->type;19371 return ira->codegen->invalid_inst_gen->value->type;
19337 assert(args_value->special == ConstValSpecialStatic);19372 assert(args_value->special == ConstValSpecialStatic);
test/behavior/type.zig+1
...@@ -137,6 +137,7 @@ test "@Type create slice with null sentinel" {...@@ -137,6 +137,7 @@ test "@Type create slice with null sentinel" {
137 .is_volatile = false,137 .is_volatile = false,
138 .is_allowzero = false,138 .is_allowzero = false,
139 .alignment = 8,139 .alignment = 8,
140 .address_space = .generic,
140 .child = *i32,141 .child = *i32,
141 .sentinel = null,142 .sentinel = null,
142 },143 },
test/compile_errors.zig+4
...@@ -410,6 +410,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -410,6 +410,7 @@ pub fn addCases(ctx: *TestContext) !void {
410 \\ .Fn = .{410 \\ .Fn = .{
411 \\ .calling_convention = .Unspecified,411 \\ .calling_convention = .Unspecified,
412 \\ .alignment = 0,412 \\ .alignment = 0,
413 \\ .address_space = 0,
413 \\ .is_generic = true,414 \\ .is_generic = true,
414 \\ .is_var_args = false,415 \\ .is_var_args = false,
415 \\ .return_type = u0,416 \\ .return_type = u0,
...@@ -426,6 +427,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -426,6 +427,7 @@ pub fn addCases(ctx: *TestContext) !void {
426 \\ .Fn = .{427 \\ .Fn = .{
427 \\ .calling_convention = .Unspecified,428 \\ .calling_convention = .Unspecified,
428 \\ .alignment = 0,429 \\ .alignment = 0,
430 \\ .address_space = 0,
429 \\ .is_generic = false,431 \\ .is_generic = false,
430 \\ .is_var_args = true,432 \\ .is_var_args = true,
431 \\ .return_type = u0,433 \\ .return_type = u0,
...@@ -442,6 +444,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -442,6 +444,7 @@ pub fn addCases(ctx: *TestContext) !void {
442 \\ .Fn = .{444 \\ .Fn = .{
443 \\ .calling_convention = .Unspecified,445 \\ .calling_convention = .Unspecified,
444 \\ .alignment = 0,446 \\ .alignment = 0,
447 \\ .address_space = 0,
445 \\ .is_generic = false,448 \\ .is_generic = false,
446 \\ .is_var_args = false,449 \\ .is_var_args = false,
447 \\ .return_type = null,450 \\ .return_type = null,
...@@ -711,6 +714,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -711,6 +714,7 @@ pub fn addCases(ctx: *TestContext) !void {
711 \\ .is_const = false,714 \\ .is_const = false,
712 \\ .is_volatile = false,715 \\ .is_volatile = false,
713 \\ .alignment = 1,716 \\ .alignment = 1,
717 \\ .address_space = .generic,
714 \\ .child = u8,718 \\ .child = u8,
715 \\ .is_allowzero = false,719 \\ .is_allowzero = false,
716 \\ .sentinel = 0,720 \\ .sentinel = 0,