| author | |
| committer | |
| log | 807a8b6f7549732d73239a649886cc64f0303f34 |
| tree | d947dae63f799b66432744ae3b000f141d71e4cf |
| parent | 5f4c52209eab66666cc4a8fd24bf27c372cfd54f |
This commit breaks struct field analysis; will be fixed in a future
commit.3 files changed, 30 insertions(+), 14 deletions(-)
lib/std/start.zig+2-2| ... | @@ -29,10 +29,10 @@ comptime { | ... | @@ -29,10 +29,10 @@ comptime { |
| 29 | if (builtin.zig_is_stage2) { | 29 | if (builtin.zig_is_stage2) { |
| 30 | if (builtin.output_mode == .Exe) { | 30 | if (builtin.output_mode == .Exe) { |
| 31 | if (builtin.link_libc or builtin.object_format == .c) { | 31 | if (builtin.link_libc or builtin.object_format == .c) { |
| 32 | @export(main2, "main"); | 32 | @export(main2, .{ .name = "main" }); |
| 33 | } else { | 33 | } else { |
| 34 | if (!@hasDecl(root, "_start")) { | 34 | if (!@hasDecl(root, "_start")) { |
| 35 | @export(_start2, "_start"); | 35 | @export(_start2, .{ .name = "_start" }); |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | } | 38 | } |
src/Module.zig+13-1| ... | @@ -497,12 +497,22 @@ pub const Struct = struct { | ... | @@ -497,12 +497,22 @@ pub const Struct = struct { |
| 497 | /// Offset from `owner_decl`, points to the struct AST node. | 497 | /// Offset from `owner_decl`, points to the struct AST node. |
| 498 | node_offset: i32, | 498 | node_offset: i32, |
| 499 | 499 | ||
| 500 | layout: std.builtin.TypeInfo.ContainerLayout, | ||
| 501 | status: enum { | ||
| 502 | none, | ||
| 503 | have_field_types, | ||
| 504 | have_layout, | ||
| 505 | }, | ||
| 506 | |||
| 500 | pub const Field = struct { | 507 | pub const Field = struct { |
| 501 | /// Uses `noreturn` to indicate `anytype`. | 508 | /// Uses `noreturn` to indicate `anytype`. |
| 509 | /// undefined until `status` is `have_field_types` or `have_layout`. | ||
| 502 | ty: Type, | 510 | ty: Type, |
| 503 | abi_align: Value, | 511 | abi_align: Value, |
| 504 | /// Uses `unreachable_value` to indicate no default. | 512 | /// Uses `unreachable_value` to indicate no default. |
| 505 | default_val: Value, | 513 | default_val: Value, |
| 514 | /// undefined until `status` is `have_layout`. | ||
| 515 | offset: u32, | ||
| 506 | is_comptime: bool, | 516 | is_comptime: bool, |
| 507 | }; | 517 | }; |
| 508 | 518 | ||
| ... | @@ -2408,6 +2418,8 @@ pub fn semaFile(mod: *Module, file: *Scope.File) InnerError!void { | ... | @@ -2408,6 +2418,8 @@ pub fn semaFile(mod: *Module, file: *Scope.File) InnerError!void { |
| 2408 | .owner_decl = undefined, // set below | 2418 | .owner_decl = undefined, // set below |
| 2409 | .fields = .{}, | 2419 | .fields = .{}, |
| 2410 | .node_offset = 0, // it's the struct for the root file | 2420 | .node_offset = 0, // it's the struct for the root file |
| 2421 | .layout = .Auto, | ||
| 2422 | .status = .none, | ||
| 2411 | .namespace = .{ | 2423 | .namespace = .{ |
| 2412 | .parent = null, | 2424 | .parent = null, |
| 2413 | .ty = struct_ty, | 2425 | .ty = struct_ty, |
| ... | @@ -2458,7 +2470,7 @@ pub fn semaFile(mod: *Module, file: *Scope.File) InnerError!void { | ... | @@ -2458,7 +2470,7 @@ pub fn semaFile(mod: *Module, file: *Scope.File) InnerError!void { |
| 2458 | 2470 | ||
| 2459 | const main_struct_inst = file.zir.extra[@enumToInt(Zir.ExtraIndex.main_struct)] - | 2471 | const main_struct_inst = file.zir.extra[@enumToInt(Zir.ExtraIndex.main_struct)] - |
| 2460 | @intCast(u32, Zir.Inst.Ref.typed_value_map.len); | 2472 | @intCast(u32, Zir.Inst.Ref.typed_value_map.len); |
| 2461 | try sema.analyzeStructDecl(&block_scope, &new_decl_arena, new_decl, main_struct_inst, .Auto, struct_obj); | 2473 | try sema.analyzeStructDecl(new_decl, main_struct_inst, struct_obj); |
| 2462 | try new_decl.finalizeNewArena(&new_decl_arena); | 2474 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 2463 | 2475 | ||
| 2464 | file.status = .success_air; | 2476 | file.status = .success_air; |
src/Sema.zig+15-11| ... | @@ -664,12 +664,21 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In | ... | @@ -664,12 +664,21 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) In |
| 664 | 664 | ||
| 665 | pub fn analyzeStructDecl( | 665 | pub fn analyzeStructDecl( |
| 666 | sema: *Sema, | 666 | sema: *Sema, |
| 667 | block: *Scope.Block, | ||
| 668 | new_decl_arena: *std.heap.ArenaAllocator, | ||
| 669 | new_decl: *Decl, | 667 | new_decl: *Decl, |
| 670 | inst: Zir.Inst.Index, | 668 | inst: Zir.Inst.Index, |
| 671 | layout: std.builtin.TypeInfo.ContainerLayout, | ||
| 672 | struct_obj: *Module.Struct, | 669 | struct_obj: *Module.Struct, |
| 670 | ) InnerError!void { | ||
| 671 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | ||
| 672 | const extra = sema.code.extraData(Zir.Inst.StructDecl, inst_data.payload_index); | ||
| 673 | const decls_len = extra.data.decls_len; | ||
| 674 | |||
| 675 | _ = try sema.mod.scanNamespace(&struct_obj.namespace, extra.end, decls_len, new_decl); | ||
| 676 | } | ||
| 677 | |||
| 678 | pub fn analyzeStructFields( | ||
| 679 | sema: *Sema, | ||
| 680 | block: *Scope.Block, | ||
| 681 | new_decl_arena: *std.heap.ArenaAllocator, | ||
| 673 | ) InnerError!void { | 682 | ) InnerError!void { |
| 674 | const tracy = trace(@src()); | 683 | const tracy = trace(@src()); |
| 675 | defer tracy.end(); | 684 | defer tracy.end(); |
| ... | @@ -682,13 +691,6 @@ pub fn analyzeStructDecl( | ... | @@ -682,13 +691,6 @@ pub fn analyzeStructDecl( |
| 682 | const fields_len = extra.data.fields_len; | 691 | const fields_len = extra.data.fields_len; |
| 683 | const decls_len = extra.data.decls_len; | 692 | const decls_len = extra.data.decls_len; |
| 684 | 693 | ||
| 685 | var extra_index: usize = try mod.scanNamespace( | ||
| 686 | &struct_obj.namespace, | ||
| 687 | extra.end, | ||
| 688 | decls_len, | ||
| 689 | new_decl, | ||
| 690 | ); | ||
| 691 | |||
| 692 | const body = sema.code.extra[extra_index..][0..extra.data.body_len]; | 694 | const body = sema.code.extra[extra_index..][0..extra.data.body_len]; |
| 693 | if (fields_len == 0) { | 695 | if (fields_len == 0) { |
| 694 | assert(body.len == 0); | 696 | assert(body.len == 0); |
| ... | @@ -824,13 +826,15 @@ fn zirStructDecl( | ... | @@ -824,13 +826,15 @@ fn zirStructDecl( |
| 824 | .owner_decl = sema.owner_decl, | 826 | .owner_decl = sema.owner_decl, |
| 825 | .fields = .{}, | 827 | .fields = .{}, |
| 826 | .node_offset = inst_data.src_node, | 828 | .node_offset = inst_data.src_node, |
| 829 | .layout = layout, | ||
| 830 | .status = .none, | ||
| 827 | .namespace = .{ | 831 | .namespace = .{ |
| 828 | .parent = sema.owner_decl.namespace, | 832 | .parent = sema.owner_decl.namespace, |
| 829 | .ty = struct_ty, | 833 | .ty = struct_ty, |
| 830 | .file_scope = block.getFileScope(), | 834 | .file_scope = block.getFileScope(), |
| 831 | }, | 835 | }, |
| 832 | }; | 836 | }; |
| 833 | try sema.analyzeStructDecl(block, &new_decl_arena, new_decl, inst, layout, struct_obj); | 837 | try sema.analyzeStructDecl(new_decl, inst, struct_obj); |
| 834 | try new_decl.finalizeNewArena(&new_decl_arena); | 838 | try new_decl.finalizeNewArena(&new_decl_arena); |
| 835 | return sema.analyzeDeclVal(block, src, new_decl); | 839 | return sema.analyzeDeclVal(block, src, new_decl); |
| 836 | } | 840 | } |