authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-12-08 15:43:14+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-08 16:54:32-08:00
log69195d0cd43468f213332c5792df04c941f8313d
treee46e9a16b56d4cde383570c2629e1999453dad62
parentd2700201149fad95c559741839cc2518ffcafa09

AstGen: add error for using inline loops in comptime only scopes


9 files changed, 24 insertions(+), 11 deletions(-)

deps/aro/aro/Attribute.zig+1-1
......@@ -643,7 +643,7 @@ pub const Tag = std.meta.DeclEnum(attributes);
643643pub const Arguments = blk: {
644644 const decls = @typeInfo(attributes).Struct.decls;
645645 var union_fields: [decls.len]ZigType.UnionField = undefined;
646 inline for (decls, &union_fields) |decl, *field| {
646 for (decls, &union_fields) |decl, *field| {
647647 field.* = .{
648648 .name = decl.name,
649649 .type = @field(attributes, decl.name),
lib/std/hash/wyhash.zig+1-1
......@@ -224,7 +224,7 @@ test "test vectors" {
224224
225225test "test vectors at comptime" {
226226 comptime {
227 inline for (vectors) |e| {
227 for (vectors) |e| {
228228 try expectEqual(e.expected, Wyhash.hash(e.seed, e.input));
229229 }
230230 }
lib/std/meta.zig+1-1
......@@ -29,7 +29,7 @@ pub fn stringToEnum(comptime T: type, str: []const u8) ?T {
2929 const kvs = comptime build_kvs: {
3030 const EnumKV = struct { []const u8, T };
3131 var kvs_array: [@typeInfo(T).Enum.fields.len]EnumKV = undefined;
32 inline for (@typeInfo(T).Enum.fields, 0..) |enumField, i| {
32 for (@typeInfo(T).Enum.fields, 0..) |enumField, i| {
3333 kvs_array[i] = .{ enumField.name, @field(T, enumField.name) };
3434 }
3535 break :build_kvs kvs_array[0..];
lib/std/meta/trailer_flags.zig+1-1
......@@ -21,7 +21,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
2121 pub const ActiveFields = std.enums.EnumFieldStruct(FieldEnum, bool, false);
2222 pub const FieldValues = blk: {
2323 comptime var fields: [bit_count]Type.StructField = undefined;
24 inline for (@typeInfo(Fields).Struct.fields, 0..) |struct_field, i| {
24 for (@typeInfo(Fields).Struct.fields, 0..) |struct_field, i| {
2525 fields[i] = Type.StructField{
2626 .name = struct_field.name,
2727 .type = ?struct_field.type,
lib/std/zig/system/NativeTargetInfo.zig+1-1
......@@ -280,7 +280,7 @@ fn detectAbiAndDynamicLinker(
280280 assert(@intFromEnum(Target.Abi.none) == 0);
281281 const fields = std.meta.fields(Target.Abi)[1..];
282282 var array: [fields.len]Target.Abi = undefined;
283 inline for (fields, 0..) |field, i| {
283 for (fields, 0..) |field, i| {
284284 array[i] = @field(Target.Abi, field.name);
285285 }
286286 break :blk array;
src/AstGen.zig+6
......@@ -6306,6 +6306,9 @@ fn whileExpr(
63066306 }
63076307
63086308 const is_inline = while_full.inline_token != null;
6309 if (parent_gz.is_comptime and is_inline) {
6310 return astgen.failTok(while_full.inline_token.?, "redundant inline keyword in comptime scope", .{});
6311 }
63096312 const loop_tag: Zir.Inst.Tag = if (is_inline) .block_inline else .loop;
63106313 const loop_block = try parent_gz.makeBlockInst(loop_tag, node);
63116314 try parent_gz.instructions.append(astgen.gpa, loop_block);
......@@ -6580,6 +6583,9 @@ fn forExpr(
65806583 const need_result_rvalue = @as(LocTag, block_ri.rl) != @as(LocTag, ri.rl);
65816584
65826585 const is_inline = for_full.inline_token != null;
6586 if (parent_gz.is_comptime and is_inline) {
6587 return astgen.failTok(for_full.inline_token.?, "redundant inline keyword in comptime scope", .{});
6588 }
65836589 const tree = astgen.tree;
65846590 const token_tags = tree.tokens.items(.tag);
65856591 const node_tags = tree.nodes.items(.tag);
src/arch/x86/bits.zig+4-4
......@@ -26,22 +26,22 @@ pub const Register = enum(u8) {
2626 /// x86 has. It is embedded in some instructions, such as the `B8 +rd` move
2727 /// instruction, and is used in the R/M byte.
2828 pub fn id(self: Register) u3 {
29 return @truncate(u3, @intFromEnum(self));
29 return @truncate(@intFromEnum(self));
3030 }
3131
3232 /// Convert from any register to its 32 bit alias.
3333 pub fn to32(self: Register) Register {
34 return @enumFromInt(Register, @as(u8, self.id()));
34 return @enumFromInt(@as(u8, self.id()));
3535 }
3636
3737 /// Convert from any register to its 16 bit alias.
3838 pub fn to16(self: Register) Register {
39 return @enumFromInt(Register, @as(u8, self.id()) + 8);
39 return @enumFromInt(@as(u8, self.id()) + 8);
4040 }
4141
4242 /// Convert from any register to its 8 bit alias.
4343 pub fn to8(self: Register) Register {
44 return @enumFromInt(Register, @as(u8, self.id()) + 16);
44 return @enumFromInt(@as(u8, self.id()) + 16);
4545 }
4646
4747 pub fn dwarfLocOp(reg: Register) u8 {
test/cases/compile_errors/redundant_inline.zig created+7
......@@ -0,0 +1,7 @@
1comptime {
2 inline for ("foo") |_| {}
3}
4
5// error
6//
7// :2:5: error: redundant inline keyword in comptime scope
test/src/Cases.zig+2-2
......@@ -908,11 +908,11 @@ const TestManifestConfigDefaults = struct {
908908 // TODO we should also specify ABIs explicitly as the backends are
909909 // getting more and more complete
910910 // Linux
911 inline for (&[_][]const u8{ "x86_64", "arm", "aarch64" }) |arch| {
911 for (&[_][]const u8{ "x86_64", "arm", "aarch64" }) |arch| {
912912 defaults = defaults ++ arch ++ "-linux" ++ ",";
913913 }
914914 // macOS
915 inline for (&[_][]const u8{ "x86_64", "aarch64" }) |arch| {
915 for (&[_][]const u8{ "x86_64", "aarch64" }) |arch| {
916916 defaults = defaults ++ arch ++ "-macos" ++ ",";
917917 }
918918 // Windows