| author | |
| committer | |
| log | 35c7e376b89f41d8260b70e770e03ef6af68849d |
| tree | 88734375267629dc08d0c33bb43fe399461a4d07 |
| parent | 0333ff4476d0132a2397122dcab964de7fc0f2d3 |
5 files changed, 118 insertions(+), 65 deletions(-)
lib/std/fmt.zig+46-18| ... | @@ -2190,18 +2190,22 @@ test "enum" { | ... | @@ -2190,18 +2190,22 @@ test "enum" { |
| 2190 | } | 2190 | } |
| 2191 | 2191 | ||
| 2192 | test "non-exhaustive enum" { | 2192 | test "non-exhaustive enum" { |
| 2193 | if (builtin.zig_backend == .stage1) { | ||
| 2194 | // stage1 fails to return fully qualified namespaces. | ||
| 2195 | return error.SkipZigTest; | ||
| 2196 | } | ||
| 2193 | const Enum = enum(u16) { | 2197 | const Enum = enum(u16) { |
| 2194 | One = 0x000f, | 2198 | One = 0x000f, |
| 2195 | Two = 0xbeef, | 2199 | Two = 0xbeef, |
| 2196 | _, | 2200 | _, |
| 2197 | }; | 2201 | }; |
| 2198 | try expectFmt("enum: Enum.One\n", "enum: {}\n", .{Enum.One}); | 2202 | try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {}\n", .{Enum.One}); |
| 2199 | try expectFmt("enum: Enum.Two\n", "enum: {}\n", .{Enum.Two}); | 2203 | try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {}\n", .{Enum.Two}); |
| 2200 | try expectFmt("enum: Enum(4660)\n", "enum: {}\n", .{@intToEnum(Enum, 0x1234)}); | 2204 | try expectFmt("enum: fmt.test.non-exhaustive enum.Enum(4660)\n", "enum: {}\n", .{@intToEnum(Enum, 0x1234)}); |
| 2201 | try expectFmt("enum: Enum.One\n", "enum: {x}\n", .{Enum.One}); | 2205 | try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.One\n", "enum: {x}\n", .{Enum.One}); |
| 2202 | try expectFmt("enum: Enum.Two\n", "enum: {x}\n", .{Enum.Two}); | 2206 | try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {x}\n", .{Enum.Two}); |
| 2203 | try expectFmt("enum: Enum.Two\n", "enum: {X}\n", .{Enum.Two}); | 2207 | try expectFmt("enum: fmt.test.non-exhaustive enum.Enum.Two\n", "enum: {X}\n", .{Enum.Two}); |
| 2204 | try expectFmt("enum: Enum(1234)\n", "enum: {x}\n", .{@intToEnum(Enum, 0x1234)}); | 2208 | try expectFmt("enum: fmt.test.non-exhaustive enum.Enum(1234)\n", "enum: {x}\n", .{@intToEnum(Enum, 0x1234)}); |
| 2205 | } | 2209 | } |
| 2206 | 2210 | ||
| 2207 | test "float.scientific" { | 2211 | test "float.scientific" { |
| ... | @@ -2357,6 +2361,10 @@ test "custom" { | ... | @@ -2357,6 +2361,10 @@ test "custom" { |
| 2357 | } | 2361 | } |
| 2358 | 2362 | ||
| 2359 | test "struct" { | 2363 | test "struct" { |
| 2364 | if (builtin.zig_backend == .stage1) { | ||
| 2365 | // stage1 fails to return fully qualified namespaces. | ||
| 2366 | return error.SkipZigTest; | ||
| 2367 | } | ||
| 2360 | const S = struct { | 2368 | const S = struct { |
| 2361 | a: u32, | 2369 | a: u32, |
| 2362 | b: anyerror, | 2370 | b: anyerror, |
| ... | @@ -2367,7 +2375,7 @@ test "struct" { | ... | @@ -2367,7 +2375,7 @@ test "struct" { |
| 2367 | .b = error.Unused, | 2375 | .b = error.Unused, |
| 2368 | }; | 2376 | }; |
| 2369 | 2377 | ||
| 2370 | try expectFmt("S{ .a = 456, .b = error.Unused }", "{}", .{inst}); | 2378 | try expectFmt("fmt.test.struct.S{ .a = 456, .b = error.Unused }", "{}", .{inst}); |
| 2371 | // Tuples | 2379 | // Tuples |
| 2372 | try expectFmt("{ }", "{}", .{.{}}); | 2380 | try expectFmt("{ }", "{}", .{.{}}); |
| 2373 | try expectFmt("{ -1 }", "{}", .{.{-1}}); | 2381 | try expectFmt("{ -1 }", "{}", .{.{-1}}); |
| ... | @@ -2375,6 +2383,10 @@ test "struct" { | ... | @@ -2375,6 +2383,10 @@ test "struct" { |
| 2375 | } | 2383 | } |
| 2376 | 2384 | ||
| 2377 | test "union" { | 2385 | test "union" { |
| 2386 | if (builtin.zig_backend == .stage1) { | ||
| 2387 | // stage1 fails to return fully qualified namespaces. | ||
| 2388 | return error.SkipZigTest; | ||
| 2389 | } | ||
| 2378 | const TU = union(enum) { | 2390 | const TU = union(enum) { |
| 2379 | float: f32, | 2391 | float: f32, |
| 2380 | int: u32, | 2392 | int: u32, |
| ... | @@ -2394,17 +2406,21 @@ test "union" { | ... | @@ -2394,17 +2406,21 @@ test "union" { |
| 2394 | const uu_inst = UU{ .int = 456 }; | 2406 | const uu_inst = UU{ .int = 456 }; |
| 2395 | const eu_inst = EU{ .float = 321.123 }; | 2407 | const eu_inst = EU{ .float = 321.123 }; |
| 2396 | 2408 | ||
| 2397 | try expectFmt("TU{ .int = 123 }", "{}", .{tu_inst}); | 2409 | try expectFmt("fmt.test.union.TU{ .int = 123 }", "{}", .{tu_inst}); |
| 2398 | 2410 | ||
| 2399 | var buf: [100]u8 = undefined; | 2411 | var buf: [100]u8 = undefined; |
| 2400 | const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst}); | 2412 | const uu_result = try bufPrint(buf[0..], "{}", .{uu_inst}); |
| 2401 | try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@")); | 2413 | try std.testing.expect(mem.eql(u8, uu_result[0..18], "fmt.test.union.UU@")); |
| 2402 | 2414 | ||
| 2403 | const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst}); | 2415 | const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst}); |
| 2404 | try std.testing.expect(mem.eql(u8, eu_result[0..3], "EU@")); | 2416 | try std.testing.expect(mem.eql(u8, eu_result[0..18], "fmt.test.union.EU@")); |
| 2405 | } | 2417 | } |
| 2406 | 2418 | ||
| 2407 | test "enum" { | 2419 | test "enum" { |
| 2420 | if (builtin.zig_backend == .stage1) { | ||
| 2421 | // stage1 fails to return fully qualified namespaces. | ||
| 2422 | return error.SkipZigTest; | ||
| 2423 | } | ||
| 2408 | const E = enum { | 2424 | const E = enum { |
| 2409 | One, | 2425 | One, |
| 2410 | Two, | 2426 | Two, |
| ... | @@ -2413,10 +2429,14 @@ test "enum" { | ... | @@ -2413,10 +2429,14 @@ test "enum" { |
| 2413 | 2429 | ||
| 2414 | const inst = E.Two; | 2430 | const inst = E.Two; |
| 2415 | 2431 | ||
| 2416 | try expectFmt("E.Two", "{}", .{inst}); | 2432 | try expectFmt("fmt.test.enum.E.Two", "{}", .{inst}); |
| 2417 | } | 2433 | } |
| 2418 | 2434 | ||
| 2419 | test "struct.self-referential" { | 2435 | test "struct.self-referential" { |
| 2436 | if (builtin.zig_backend == .stage1) { | ||
| 2437 | // stage1 fails to return fully qualified namespaces. | ||
| 2438 | return error.SkipZigTest; | ||
| 2439 | } | ||
| 2420 | const S = struct { | 2440 | const S = struct { |
| 2421 | const SelfType = @This(); | 2441 | const SelfType = @This(); |
| 2422 | a: ?*SelfType, | 2442 | a: ?*SelfType, |
| ... | @@ -2427,10 +2447,14 @@ test "struct.self-referential" { | ... | @@ -2427,10 +2447,14 @@ test "struct.self-referential" { |
| 2427 | }; | 2447 | }; |
| 2428 | inst.a = &inst; | 2448 | inst.a = &inst; |
| 2429 | 2449 | ||
| 2430 | try expectFmt("S{ .a = S{ .a = S{ .a = S{ ... } } } }", "{}", .{inst}); | 2450 | try expectFmt("fmt.test.struct.self-referential.S{ .a = fmt.test.struct.self-referential.S{ .a = fmt.test.struct.self-referential.S{ .a = fmt.test.struct.self-referential.S{ ... } } } }", "{}", .{inst}); |
| 2431 | } | 2451 | } |
| 2432 | 2452 | ||
| 2433 | test "struct.zero-size" { | 2453 | test "struct.zero-size" { |
| 2454 | if (builtin.zig_backend == .stage1) { | ||
| 2455 | // stage1 fails to return fully qualified namespaces. | ||
| 2456 | return error.SkipZigTest; | ||
| 2457 | } | ||
| 2434 | const A = struct { | 2458 | const A = struct { |
| 2435 | fn foo() void {} | 2459 | fn foo() void {} |
| 2436 | }; | 2460 | }; |
| ... | @@ -2442,7 +2466,7 @@ test "struct.zero-size" { | ... | @@ -2442,7 +2466,7 @@ test "struct.zero-size" { |
| 2442 | const a = A{}; | 2466 | const a = A{}; |
| 2443 | const b = B{ .a = a, .c = 0 }; | 2467 | const b = B{ .a = a, .c = 0 }; |
| 2444 | 2468 | ||
| 2445 | try expectFmt("B{ .a = A{ }, .c = 0 }", "{}", .{b}); | 2469 | try expectFmt("fmt.test.struct.zero-size.B{ .a = fmt.test.struct.zero-size.A{ }, .c = 0 }", "{}", .{b}); |
| 2446 | } | 2470 | } |
| 2447 | 2471 | ||
| 2448 | test "bytes.hex" { | 2472 | test "bytes.hex" { |
| ... | @@ -2508,6 +2532,10 @@ test "formatFloatValue with comptime_float" { | ... | @@ -2508,6 +2532,10 @@ test "formatFloatValue with comptime_float" { |
| 2508 | } | 2532 | } |
| 2509 | 2533 | ||
| 2510 | test "formatType max_depth" { | 2534 | test "formatType max_depth" { |
| 2535 | if (builtin.zig_backend == .stage1) { | ||
| 2536 | // stage1 fails to return fully qualified namespaces. | ||
| 2537 | return error.SkipZigTest; | ||
| 2538 | } | ||
| 2511 | const Vec2 = struct { | 2539 | const Vec2 = struct { |
| 2512 | const SelfType = @This(); | 2540 | const SelfType = @This(); |
| 2513 | x: f32, | 2541 | x: f32, |
| ... | @@ -2558,19 +2586,19 @@ test "formatType max_depth" { | ... | @@ -2558,19 +2586,19 @@ test "formatType max_depth" { |
| 2558 | var buf: [1000]u8 = undefined; | 2586 | var buf: [1000]u8 = undefined; |
| 2559 | var fbs = std.io.fixedBufferStream(&buf); | 2587 | var fbs = std.io.fixedBufferStream(&buf); |
| 2560 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 0); | 2588 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 0); |
| 2561 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ ... }")); | 2589 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ ... }")); |
| 2562 | 2590 | ||
| 2563 | fbs.reset(); | 2591 | fbs.reset(); |
| 2564 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 1); | 2592 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 1); |
| 2565 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }")); | 2593 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }")); |
| 2566 | 2594 | ||
| 2567 | fbs.reset(); | 2595 | fbs.reset(); |
| 2568 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 2); | 2596 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 2); |
| 2569 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }")); | 2597 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }")); |
| 2570 | 2598 | ||
| 2571 | fbs.reset(); | 2599 | fbs.reset(); |
| 2572 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 3); | 2600 | try formatType(inst, "", FormatOptions{}, fbs.writer(), 3); |
| 2573 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "S{ .a = S{ .a = S{ .a = S{ ... }, .tu = TU{ ... }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ ... } }, .e = E.Two, .vec = (10.200,2.220) }, .tu = TU{ .ptr = TU{ .ptr = TU{ ... } } }, .e = E.Two, .vec = (10.200,2.220) }")); | 2601 | try std.testing.expect(mem.eql(u8, fbs.getWritten(), "fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ .a = fmt.test.formatType max_depth.S{ ... }, .tu = fmt.test.formatType max_depth.TU{ ... }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }, .tu = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ .ptr = fmt.test.formatType max_depth.TU{ ... } } }, .e = fmt.test.formatType max_depth.E.Two, .vec = (10.200,2.220) }")); |
| 2574 | } | 2602 | } |
| 2575 | 2603 | ||
| 2576 | test "positional" { | 2604 | test "positional" { |
src/AstGen.zig+7| ... | @@ -2753,7 +2753,10 @@ fn varDecl( | ... | @@ -2753,7 +2753,10 @@ fn varDecl( |
| 2753 | const result_loc: ResultLoc = if (type_node != 0) .{ | 2753 | const result_loc: ResultLoc = if (type_node != 0) .{ |
| 2754 | .ty = try typeExpr(gz, scope, type_node), | 2754 | .ty = try typeExpr(gz, scope, type_node), |
| 2755 | } else .none; | 2755 | } else .none; |
| 2756 | const prev_anon_name_strategy = gz.anon_name_strategy; | ||
| 2757 | gz.anon_name_strategy = .dbg_var; | ||
| 2756 | const init_inst = try reachableExpr(gz, scope, result_loc, var_decl.ast.init_node, node); | 2758 | const init_inst = try reachableExpr(gz, scope, result_loc, var_decl.ast.init_node, node); |
| 2759 | gz.anon_name_strategy = prev_anon_name_strategy; | ||
| 2757 | 2760 | ||
| 2758 | try gz.addDbgVar(.dbg_var_val, ident_name, init_inst); | 2761 | try gz.addDbgVar(.dbg_var_val, ident_name, init_inst); |
| 2759 | 2762 | ||
| ... | @@ -2777,6 +2780,7 @@ fn varDecl( | ... | @@ -2777,6 +2780,7 @@ fn varDecl( |
| 2777 | var init_scope = gz.makeSubBlock(scope); | 2780 | var init_scope = gz.makeSubBlock(scope); |
| 2778 | // we may add more instructions to gz before stacking init_scope | 2781 | // we may add more instructions to gz before stacking init_scope |
| 2779 | init_scope.instructions_top = GenZir.unstacked_top; | 2782 | init_scope.instructions_top = GenZir.unstacked_top; |
| 2783 | init_scope.anon_name_strategy = .dbg_var; | ||
| 2780 | defer init_scope.unstack(); | 2784 | defer init_scope.unstack(); |
| 2781 | 2785 | ||
| 2782 | var resolve_inferred_alloc: Zir.Inst.Ref = .none; | 2786 | var resolve_inferred_alloc: Zir.Inst.Ref = .none; |
| ... | @@ -2956,7 +2960,10 @@ fn varDecl( | ... | @@ -2956,7 +2960,10 @@ fn varDecl( |
| 2956 | resolve_inferred_alloc = alloc; | 2960 | resolve_inferred_alloc = alloc; |
| 2957 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; | 2961 | break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc } }; |
| 2958 | }; | 2962 | }; |
| 2963 | const prev_anon_name_strategy = gz.anon_name_strategy; | ||
| 2964 | gz.anon_name_strategy = .dbg_var; | ||
| 2959 | _ = try reachableExprComptime(gz, scope, var_data.result_loc, var_decl.ast.init_node, node, is_comptime); | 2965 | _ = try reachableExprComptime(gz, scope, var_data.result_loc, var_decl.ast.init_node, node, is_comptime); |
| 2966 | gz.anon_name_strategy = prev_anon_name_strategy; | ||
| 2960 | if (resolve_inferred_alloc != .none) { | 2967 | if (resolve_inferred_alloc != .none) { |
| 2961 | _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); | 2968 | _ = try gz.addUnNode(.resolve_inferred_alloc, resolve_inferred_alloc, node); |
| 2962 | } | 2969 | } |
src/Sema.zig+38-11| ... | @@ -914,9 +914,9 @@ fn analyzeBodyInner( | ... | @@ -914,9 +914,9 @@ fn analyzeBodyInner( |
| 914 | // zig fmt: off | 914 | // zig fmt: off |
| 915 | .variable => try sema.zirVarExtended( block, extended), | 915 | .variable => try sema.zirVarExtended( block, extended), |
| 916 | .struct_decl => try sema.zirStructDecl( block, extended, inst), | 916 | .struct_decl => try sema.zirStructDecl( block, extended, inst), |
| 917 | .enum_decl => try sema.zirEnumDecl( block, extended), | 917 | .enum_decl => try sema.zirEnumDecl( block, extended, inst), |
| 918 | .union_decl => try sema.zirUnionDecl( block, extended, inst), | 918 | .union_decl => try sema.zirUnionDecl( block, extended, inst), |
| 919 | .opaque_decl => try sema.zirOpaqueDecl( block, extended), | 919 | .opaque_decl => try sema.zirOpaqueDecl( block, extended, inst), |
| 920 | .this => try sema.zirThis( block, extended), | 920 | .this => try sema.zirThis( block, extended), |
| 921 | .ret_addr => try sema.zirRetAddr( block, extended), | 921 | .ret_addr => try sema.zirRetAddr( block, extended), |
| 922 | .builtin_src => try sema.zirBuiltinSrc( block, extended), | 922 | .builtin_src => try sema.zirBuiltinSrc( block, extended), |
| ... | @@ -2101,7 +2101,7 @@ fn zirStructDecl( | ... | @@ -2101,7 +2101,7 @@ fn zirStructDecl( |
| 2101 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 2101 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 2102 | .ty = Type.type, | 2102 | .ty = Type.type, |
| 2103 | .val = struct_val, | 2103 | .val = struct_val, |
| 2104 | }, small.name_strategy, "struct"); | 2104 | }, small.name_strategy, "struct", inst); |
| 2105 | const new_decl = mod.declPtr(new_decl_index); | 2105 | const new_decl = mod.declPtr(new_decl_index); |
| 2106 | new_decl.owns_tv = true; | 2106 | new_decl.owns_tv = true; |
| 2107 | errdefer mod.abortAnonDecl(new_decl_index); | 2107 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -2133,6 +2133,7 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2133,6 +2133,7 @@ fn createAnonymousDeclTypeNamed( |
| 2133 | typed_value: TypedValue, | 2133 | typed_value: TypedValue, |
| 2134 | name_strategy: Zir.Inst.NameStrategy, | 2134 | name_strategy: Zir.Inst.NameStrategy, |
| 2135 | anon_prefix: []const u8, | 2135 | anon_prefix: []const u8, |
| 2136 | inst: ?Zir.Inst.Index, | ||
| 2136 | ) !Decl.Index { | 2137 | ) !Decl.Index { |
| 2137 | const mod = sema.mod; | 2138 | const mod = sema.mod; |
| 2138 | const namespace = block.namespace; | 2139 | const namespace = block.namespace; |
| ... | @@ -2152,11 +2153,13 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2152,11 +2153,13 @@ fn createAnonymousDeclTypeNamed( |
| 2152 | const name = try std.fmt.allocPrintZ(sema.gpa, "{s}__{s}_{d}", .{ | 2153 | const name = try std.fmt.allocPrintZ(sema.gpa, "{s}__{s}_{d}", .{ |
| 2153 | src_decl.name, anon_prefix, @enumToInt(new_decl_index), | 2154 | src_decl.name, anon_prefix, @enumToInt(new_decl_index), |
| 2154 | }); | 2155 | }); |
| 2156 | errdefer sema.gpa.free(name); | ||
| 2155 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2157 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2156 | return new_decl_index; | 2158 | return new_decl_index; |
| 2157 | }, | 2159 | }, |
| 2158 | .parent => { | 2160 | .parent => { |
| 2159 | const name = try sema.gpa.dupeZ(u8, mem.sliceTo(sema.mod.declPtr(block.src_decl).name, 0)); | 2161 | const name = try sema.gpa.dupeZ(u8, mem.sliceTo(sema.mod.declPtr(block.src_decl).name, 0)); |
| 2162 | errdefer sema.gpa.free(name); | ||
| 2160 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2163 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2161 | return new_decl_index; | 2164 | return new_decl_index; |
| 2162 | }, | 2165 | }, |
| ... | @@ -2188,9 +2191,31 @@ fn createAnonymousDeclTypeNamed( | ... | @@ -2188,9 +2191,31 @@ fn createAnonymousDeclTypeNamed( |
| 2188 | 2191 | ||
| 2189 | try buf.appendSlice(")"); | 2192 | try buf.appendSlice(")"); |
| 2190 | const name = try buf.toOwnedSliceSentinel(0); | 2193 | const name = try buf.toOwnedSliceSentinel(0); |
| 2194 | errdefer sema.gpa.free(name); | ||
| 2191 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | 2195 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); |
| 2192 | return new_decl_index; | 2196 | return new_decl_index; |
| 2193 | }, | 2197 | }, |
| 2198 | .dbg_var => { | ||
| 2199 | const ref = Zir.indexToRef(inst.?); | ||
| 2200 | const zir_tags = sema.code.instructions.items(.tag); | ||
| 2201 | const zir_data = sema.code.instructions.items(.data); | ||
| 2202 | var i = inst.?; | ||
| 2203 | while (i < zir_tags.len) : (i += 1) switch (zir_tags[i]) { | ||
| 2204 | .dbg_var_ptr, .dbg_var_val => { | ||
| 2205 | if (zir_data[i].str_op.operand != ref) continue; | ||
| 2206 | |||
| 2207 | const name = try std.fmt.allocPrintZ(sema.gpa, "{s}.{s}", .{ | ||
| 2208 | src_decl.name, zir_data[i].str_op.getStr(sema.code), | ||
| 2209 | }); | ||
| 2210 | errdefer sema.gpa.free(name); | ||
| 2211 | |||
| 2212 | try mod.initNewAnonDecl(new_decl_index, src_decl.src_line, namespace, typed_value, name); | ||
| 2213 | return new_decl_index; | ||
| 2214 | }, | ||
| 2215 | else => {}, | ||
| 2216 | }; | ||
| 2217 | return sema.createAnonymousDeclTypeNamed(block, typed_value, .anon, anon_prefix, null); | ||
| 2218 | }, | ||
| 2194 | } | 2219 | } |
| 2195 | } | 2220 | } |
| 2196 | 2221 | ||
| ... | @@ -2198,6 +2223,7 @@ fn zirEnumDecl( | ... | @@ -2198,6 +2223,7 @@ fn zirEnumDecl( |
| 2198 | sema: *Sema, | 2223 | sema: *Sema, |
| 2199 | block: *Block, | 2224 | block: *Block, |
| 2200 | extended: Zir.Inst.Extended.InstData, | 2225 | extended: Zir.Inst.Extended.InstData, |
| 2226 | inst: Zir.Inst.Index, | ||
| 2201 | ) CompileError!Air.Inst.Ref { | 2227 | ) CompileError!Air.Inst.Ref { |
| 2202 | const tracy = trace(@src()); | 2228 | const tracy = trace(@src()); |
| 2203 | defer tracy.end(); | 2229 | defer tracy.end(); |
| ... | @@ -2252,7 +2278,7 @@ fn zirEnumDecl( | ... | @@ -2252,7 +2278,7 @@ fn zirEnumDecl( |
| 2252 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 2278 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 2253 | .ty = Type.type, | 2279 | .ty = Type.type, |
| 2254 | .val = enum_val, | 2280 | .val = enum_val, |
| 2255 | }, small.name_strategy, "enum"); | 2281 | }, small.name_strategy, "enum", inst); |
| 2256 | const new_decl = mod.declPtr(new_decl_index); | 2282 | const new_decl = mod.declPtr(new_decl_index); |
| 2257 | new_decl.owns_tv = true; | 2283 | new_decl.owns_tv = true; |
| 2258 | errdefer mod.abortAnonDecl(new_decl_index); | 2284 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -2472,7 +2498,7 @@ fn zirUnionDecl( | ... | @@ -2472,7 +2498,7 @@ fn zirUnionDecl( |
| 2472 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 2498 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 2473 | .ty = Type.type, | 2499 | .ty = Type.type, |
| 2474 | .val = union_val, | 2500 | .val = union_val, |
| 2475 | }, small.name_strategy, "union"); | 2501 | }, small.name_strategy, "union", inst); |
| 2476 | const new_decl = mod.declPtr(new_decl_index); | 2502 | const new_decl = mod.declPtr(new_decl_index); |
| 2477 | new_decl.owns_tv = true; | 2503 | new_decl.owns_tv = true; |
| 2478 | errdefer mod.abortAnonDecl(new_decl_index); | 2504 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -2504,6 +2530,7 @@ fn zirOpaqueDecl( | ... | @@ -2504,6 +2530,7 @@ fn zirOpaqueDecl( |
| 2504 | sema: *Sema, | 2530 | sema: *Sema, |
| 2505 | block: *Block, | 2531 | block: *Block, |
| 2506 | extended: Zir.Inst.Extended.InstData, | 2532 | extended: Zir.Inst.Extended.InstData, |
| 2533 | inst: Zir.Inst.Index, | ||
| 2507 | ) CompileError!Air.Inst.Ref { | 2534 | ) CompileError!Air.Inst.Ref { |
| 2508 | const tracy = trace(@src()); | 2535 | const tracy = trace(@src()); |
| 2509 | defer tracy.end(); | 2536 | defer tracy.end(); |
| ... | @@ -2540,7 +2567,7 @@ fn zirOpaqueDecl( | ... | @@ -2540,7 +2567,7 @@ fn zirOpaqueDecl( |
| 2540 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 2567 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 2541 | .ty = Type.type, | 2568 | .ty = Type.type, |
| 2542 | .val = opaque_val, | 2569 | .val = opaque_val, |
| 2543 | }, small.name_strategy, "opaque"); | 2570 | }, small.name_strategy, "opaque", inst); |
| 2544 | const new_decl = mod.declPtr(new_decl_index); | 2571 | const new_decl = mod.declPtr(new_decl_index); |
| 2545 | new_decl.owns_tv = true; | 2572 | new_decl.owns_tv = true; |
| 2546 | errdefer mod.abortAnonDecl(new_decl_index); | 2573 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -2589,7 +2616,7 @@ fn zirErrorSetDecl( | ... | @@ -2589,7 +2616,7 @@ fn zirErrorSetDecl( |
| 2589 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 2616 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 2590 | .ty = Type.type, | 2617 | .ty = Type.type, |
| 2591 | .val = error_set_val, | 2618 | .val = error_set_val, |
| 2592 | }, name_strategy, "error"); | 2619 | }, name_strategy, "error", inst); |
| 2593 | const new_decl = mod.declPtr(new_decl_index); | 2620 | const new_decl = mod.declPtr(new_decl_index); |
| 2594 | new_decl.owns_tv = true; | 2621 | new_decl.owns_tv = true; |
| 2595 | errdefer mod.abortAnonDecl(new_decl_index); | 2622 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -14632,7 +14659,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -14632,7 +14659,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 14632 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 14659 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 14633 | .ty = Type.type, | 14660 | .ty = Type.type, |
| 14634 | .val = enum_val, | 14661 | .val = enum_val, |
| 14635 | }, .anon, "enum"); | 14662 | }, .anon, "enum", null); |
| 14636 | const new_decl = mod.declPtr(new_decl_index); | 14663 | const new_decl = mod.declPtr(new_decl_index); |
| 14637 | new_decl.owns_tv = true; | 14664 | new_decl.owns_tv = true; |
| 14638 | errdefer mod.abortAnonDecl(new_decl_index); | 14665 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -14722,7 +14749,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -14722,7 +14749,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 14722 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 14749 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 14723 | .ty = Type.type, | 14750 | .ty = Type.type, |
| 14724 | .val = opaque_val, | 14751 | .val = opaque_val, |
| 14725 | }, .anon, "opaque"); | 14752 | }, .anon, "opaque", null); |
| 14726 | const new_decl = mod.declPtr(new_decl_index); | 14753 | const new_decl = mod.declPtr(new_decl_index); |
| 14727 | new_decl.owns_tv = true; | 14754 | new_decl.owns_tv = true; |
| 14728 | errdefer mod.abortAnonDecl(new_decl_index); | 14755 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -14773,7 +14800,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I | ... | @@ -14773,7 +14800,7 @@ fn zirReify(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I |
| 14773 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 14800 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 14774 | .ty = Type.type, | 14801 | .ty = Type.type, |
| 14775 | .val = new_union_val, | 14802 | .val = new_union_val, |
| 14776 | }, .anon, "union"); | 14803 | }, .anon, "union", null); |
| 14777 | const new_decl = mod.declPtr(new_decl_index); | 14804 | const new_decl = mod.declPtr(new_decl_index); |
| 14778 | new_decl.owns_tv = true; | 14805 | new_decl.owns_tv = true; |
| 14779 | errdefer mod.abortAnonDecl(new_decl_index); | 14806 | errdefer mod.abortAnonDecl(new_decl_index); |
| ... | @@ -14941,7 +14968,7 @@ fn reifyStruct( | ... | @@ -14941,7 +14968,7 @@ fn reifyStruct( |
| 14941 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ | 14968 | const new_decl_index = try sema.createAnonymousDeclTypeNamed(block, .{ |
| 14942 | .ty = Type.type, | 14969 | .ty = Type.type, |
| 14943 | .val = new_struct_val, | 14970 | .val = new_struct_val, |
| 14944 | }, .anon, "struct"); | 14971 | }, .anon, "struct", null); |
| 14945 | const new_decl = mod.declPtr(new_decl_index); | 14972 | const new_decl = mod.declPtr(new_decl_index); |
| 14946 | new_decl.owns_tv = true; | 14973 | new_decl.owns_tv = true; |
| 14947 | errdefer mod.abortAnonDecl(new_decl_index); | 14974 | errdefer mod.abortAnonDecl(new_decl_index); |
src/Zir.zig+2| ... | @@ -3156,6 +3156,8 @@ pub const Inst = struct { | ... | @@ -3156,6 +3156,8 @@ pub const Inst = struct { |
| 3156 | /// Create an anonymous name for this declaration. | 3156 | /// Create an anonymous name for this declaration. |
| 3157 | /// Like this: "ParentDeclName_struct_69" | 3157 | /// Like this: "ParentDeclName_struct_69" |
| 3158 | anon, | 3158 | anon, |
| 3159 | /// Use the name specified in the next `dbg_var_{val,ptr}` instruction. | ||
| 3160 | dbg_var, | ||
| 3159 | }; | 3161 | }; |
| 3160 | 3162 | ||
| 3161 | /// Trailing: | 3163 | /// Trailing: |
test/behavior/typename.zig+25-36| ... | @@ -137,43 +137,8 @@ const A_Enum = enum { | ... | @@ -137,43 +137,8 @@ const A_Enum = enum { |
| 137 | 137 | ||
| 138 | fn regular() void {} | 138 | fn regular() void {} |
| 139 | 139 | ||
| 140 | test "fn body decl" { | ||
| 141 | if (builtin.zig_backend == .stage1) { | ||
| 142 | // stage1 fails to return fully qualified namespaces. | ||
| 143 | return error.SkipZigTest; | ||
| 144 | } | ||
| 145 | |||
| 146 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | ||
| 147 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 148 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 149 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 150 | |||
| 151 | try B.doTest(); | ||
| 152 | } | ||
| 153 | |||
| 154 | const B = struct { | 140 | const B = struct { |
| 155 | fn doTest() !void { | 141 | fn doTest() !void {} |
| 156 | const B_Struct = struct {}; | ||
| 157 | const B_Union = union { | ||
| 158 | unused: u8, | ||
| 159 | }; | ||
| 160 | const B_Enum = enum { | ||
| 161 | unused, | ||
| 162 | }; | ||
| 163 | |||
| 164 | try expectEqualStringsIgnoreDigits( | ||
| 165 | "behavior.typename.B.doTest__struct_0", | ||
| 166 | @typeName(B_Struct), | ||
| 167 | ); | ||
| 168 | try expectEqualStringsIgnoreDigits( | ||
| 169 | "behavior.typename.B.doTest__union_0", | ||
| 170 | @typeName(B_Union), | ||
| 171 | ); | ||
| 172 | try expectEqualStringsIgnoreDigits( | ||
| 173 | "behavior.typename.B.doTest__enum_0", | ||
| 174 | @typeName(B_Enum), | ||
| 175 | ); | ||
| 176 | } | ||
| 177 | }; | 142 | }; |
| 178 | 143 | ||
| 179 | test "fn param" { | 144 | test "fn param" { |
| ... | @@ -246,3 +211,27 @@ pub fn expectEqualStringsIgnoreDigits(expected: []const u8, actual: []const u8) | ... | @@ -246,3 +211,27 @@ pub fn expectEqualStringsIgnoreDigits(expected: []const u8, actual: []const u8) |
| 246 | } | 211 | } |
| 247 | return expectEqualStrings(expected, actual_buf[0..actual_i]); | 212 | return expectEqualStrings(expected, actual_buf[0..actual_i]); |
| 248 | } | 213 | } |
| 214 | |||
| 215 | test "local variable" { | ||
| 216 | if (builtin.zig_backend == .stage1) { | ||
| 217 | // stage1 fails to return fully qualified namespaces. | ||
| 218 | return error.SkipZigTest; | ||
| 219 | } | ||
| 220 | |||
| 221 | if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO | ||
| 222 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO | ||
| 223 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO | ||
| 224 | if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO | ||
| 225 | |||
| 226 | const Foo = struct { a: u32 }; | ||
| 227 | const Bar = union { a: u32 }; | ||
| 228 | const Baz = enum { a, b }; | ||
| 229 | const Qux = enum { a, b }; | ||
| 230 | const Quux = enum { a, b }; | ||
| 231 | |||
| 232 | try expectEqualStrings("behavior.typename.test.local variable.Foo", @typeName(Foo)); | ||
| 233 | try expectEqualStrings("behavior.typename.test.local variable.Bar", @typeName(Bar)); | ||
| 234 | try expectEqualStrings("behavior.typename.test.local variable.Baz", @typeName(Baz)); | ||
| 235 | try expectEqualStrings("behavior.typename.test.local variable.Qux", @typeName(Qux)); | ||
| 236 | try expectEqualStrings("behavior.typename.test.local variable.Quux", @typeName(Quux)); | ||
| 237 | } |