authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-09 10:07:55-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-09 10:09:17-04:00
log57470e833e4ac545a75ad7b3dd6830fa666cd325
tree382d0275366f2b425abd946ed34471ea4302dc58
parent736df276632ad66294a7491a5e35a039dd2c836f

Module: implement `span` for `.call_arg` of a `@call`

Closes #16750

2 files changed, 52 insertions(+), 16 deletions(-)

src/Module.zig+40-16
...@@ -2133,10 +2133,40 @@ pub const SrcLoc = struct {...@@ -2133,10 +2133,40 @@ pub const SrcLoc = struct {
2133 .call_arg => |call_arg| {2133 .call_arg => |call_arg| {
2134 const tree = try src_loc.file_scope.getTree(gpa);2134 const tree = try src_loc.file_scope.getTree(gpa);
2135 const node = src_loc.declRelativeToNodeIndex(call_arg.call_node_offset);2135 const node = src_loc.declRelativeToNodeIndex(call_arg.call_node_offset);
2136 var buf: [1]Ast.Node.Index = undefined;2136 var buf: [2]Ast.Node.Index = undefined;
2137 const call_full = tree.fullCall(&buf, node).?;2137 const call_full = tree.fullCall(buf[0..1], node) orelse {
2138 const src_node = call_full.ast.params[call_arg.arg_index];2138 const node_tags = tree.nodes.items(.tag);
2139 return nodeToSpan(tree, src_node);2139 assert(node_tags[node] == .builtin_call);
2140 const call_args_node = tree.extra_data[tree.nodes.items(.data)[node].rhs - 1];
2141 switch (node_tags[call_args_node]) {
2142 .array_init_one,
2143 .array_init_one_comma,
2144 .array_init_dot_two,
2145 .array_init_dot_two_comma,
2146 .array_init_dot,
2147 .array_init_dot_comma,
2148 .array_init,
2149 .array_init_comma,
2150 => {
2151 const full = tree.fullArrayInit(&buf, call_args_node).?.ast.elements;
2152 return nodeToSpan(tree, full[call_arg.arg_index]);
2153 },
2154 .struct_init_one,
2155 .struct_init_one_comma,
2156 .struct_init_dot_two,
2157 .struct_init_dot_two_comma,
2158 .struct_init_dot,
2159 .struct_init_dot_comma,
2160 .struct_init,
2161 .struct_init_comma,
2162 => {
2163 const full = tree.fullStructInit(&buf, call_args_node).?.ast.fields;
2164 return nodeToSpan(tree, full[call_arg.arg_index]);
2165 },
2166 else => return nodeToSpan(tree, call_args_node),
2167 }
2168 };
2169 return nodeToSpan(tree, call_full.ast.params[call_arg.arg_index]);
2140 },2170 },
2141 .fn_proto_param => |fn_proto_param| {2171 .fn_proto_param => |fn_proto_param| {
2142 const tree = try src_loc.file_scope.getTree(gpa);2172 const tree = try src_loc.file_scope.getTree(gpa);
...@@ -5926,21 +5956,15 @@ pub fn argSrc(...@@ -5926,21 +5956,15 @@ pub fn argSrc(
5926 });5956 });
5927 return LazySrcLoc.nodeOffset(0);5957 return LazySrcLoc.nodeOffset(0);
5928 };5958 };
5929 const node_tags = tree.nodes.items(.tag);
5930 const node = decl.relativeToNodeIndex(call_node_offset);5959 const node = decl.relativeToNodeIndex(call_node_offset);
5931 var args: [1]Ast.Node.Index = undefined;5960 var args: [1]Ast.Node.Index = undefined;
5932 const full = switch (node_tags[node]) {5961 const call_full = tree.fullCall(&args, node) orelse {
5933 .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => tree.callOne(&args, node),5962 assert(tree.nodes.items(.tag)[node] == .builtin_call);
5934 .call, .call_comma, .async_call, .async_call_comma => tree.callFull(node),5963 const call_args_node = tree.extra_data[tree.nodes.items(.data)[node].rhs - 1];
5935 .builtin_call => {5964 const call_args_offset = decl.nodeIndexToRelative(call_args_node);
5936 const node_datas = tree.nodes.items(.data);5965 return mod.initSrc(call_args_offset, decl, arg_i);
5937 const call_args_node = tree.extra_data[node_datas[node].rhs - 1];
5938 const call_args_offset = decl.nodeIndexToRelative(call_args_node);
5939 return mod.initSrc(call_args_offset, decl, arg_i);
5940 },
5941 else => unreachable,
5942 };5966 };
5943 return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(full.ast.params[arg_i]));5967 return LazySrcLoc.nodeOffset(decl.nodeIndexToRelative(call_full.ast.params[arg_i]));
5944}5968}
59455969
5946pub fn initSrc(5970pub fn initSrc(
test/cases/compile_errors/builtin_call_with_invalid_param.zig created+12
...@@ -0,0 +1,12 @@
1export fn builtinCallBoolFunctionInlineWithVoid() void {
2 @call(.always_inline, boolFunction, .{{}});
3}
4
5fn boolFunction(_: bool) void {}
6
7// error
8// backend=stage2
9// target=native
10//
11// :2:43: error: expected type 'bool', found 'void'
12// :5:20: note: parameter type declared here