Skip to content

Commit

Permalink
Attribute: convert unimplemented attributes to errors instead of panics
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed Mar 29, 2024
1 parent e379e04 commit 30c93ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ pub fn applyVariableAttributes(p: *Parser, ty: Type, attr_buf_start: usize, tag:
.copy,
.tls_model,
.visibility,
=> std.debug.panic("apply variable attribute {s}", .{@tagName(attr.tag)}),
=> |t| try p.errExtra(.attribute_todo, tok, .{ .attribute_todo = .{ .tag = t, .kind = .variables } }),
else => try ignoredAttrErr(p, tok, attr.tag, "variables"),
};
const existing = ty.getAttributes();
Expand Down Expand Up @@ -823,7 +823,7 @@ pub fn applyTypeAttributes(p: *Parser, ty: Type, attr_buf_start: usize, tag: ?Di
.copy,
.scalar_storage_order,
.nonstring,
=> std.debug.panic("apply type attribute {s}", .{@tagName(attr.tag)}),
=> |t| try p.errExtra(.attribute_todo, tok, .{ .attribute_todo = .{ .tag = t, .kind = .types } }),
else => try ignoredAttrErr(p, tok, attr.tag, "types"),
};

Expand Down Expand Up @@ -943,7 +943,7 @@ pub fn applyFunctionAttributes(p: *Parser, ty: Type, attr_buf_start: usize) !Typ
.visibility,
.weakref,
.zero_call_used_regs,
=> std.debug.panic("apply type attribute {s}", .{@tagName(attr.tag)}),
=> |t| try p.errExtra(.attribute_todo, tok, .{ .attribute_todo = .{ .tag = t, .kind = .functions } }),
else => try ignoredAttrErr(p, tok, attr.tag, "functions"),
};
return ty.withAttributes(p.arena, p.attr_application_buf.items);
Expand Down
8 changes: 8 additions & 0 deletions src/aro/Diagnostics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub const Message = struct {
tag: Attribute.Tag,
specifier: enum { @"struct", @"union", @"enum" },
},
attribute_todo: struct {
tag: Attribute.Tag,
kind: enum { variables, fields, types, functions },
},
builtin_with_header: struct {
builtin: Builtin.Tag,
header: Header,
Expand Down Expand Up @@ -422,6 +426,10 @@ pub fn renderMessage(comp: *Compilation, m: anytype, msg: Message) void {
@tagName(msg.extra.ignored_record_attr.tag),
@tagName(msg.extra.ignored_record_attr.specifier),
}),
.attribute_todo => printRt(m, prop.msg, .{ "{s}", "{s}" }, .{
@tagName(msg.extra.attribute_todo.tag),
@tagName(msg.extra.attribute_todo.kind),
}),
.builtin_with_header => printRt(m, prop.msg, .{ "{s}", "{s}" }, .{
@tagName(msg.extra.builtin_with_header.header),
Builtin.nameFromTag(msg.extra.builtin_with_header.builtin).span(),
Expand Down
5 changes: 5 additions & 0 deletions src/aro/Diagnostics/messages.def
Original file line number Diff line number Diff line change
Expand Up @@ -2472,3 +2472,8 @@ overflow_result_requires_ptr
.msg = "result argument to overflow builtin must be a pointer to a non-const integer ('{s}' invalid)"
.extra = .str
.kind = .@"error"

attribute_todo
.msg = "TODO: implement '{s}' attribute for {s}"
.extra = .attribute_todo
.kind = .@"error"

0 comments on commit 30c93ed

Please sign in to comment.