@@ -1321,6 +1321,7 @@ pub const Scope = struct {
1321
1321
/// It is shared among all the blocks in an inline or comptime called
1322
1322
/// function.
1323
1323
pub const Inlining = struct {
1324
+ comptime_result : Air.Inst.Ref ,
1324
1325
merges : Merges ,
1325
1326
};
1326
1327
@@ -1643,36 +1644,12 @@ pub const SrcLoc = struct {
1643
1644
const token_starts = tree .tokens .items (.start );
1644
1645
return token_starts [tok_index ];
1645
1646
},
1646
- .node_offset_builtin_call_arg0 = > | node_off | {
1647
- const tree = try src_loc .file_scope .getTree (gpa );
1648
- const node_datas = tree .nodes .items (.data );
1649
- const node_tags = tree .nodes .items (.tag );
1650
- const node = src_loc .declRelativeToNodeIndex (node_off );
1651
- const param = switch (node_tags [node ]) {
1652
- .builtin_call_two , .builtin_call_two_comma = > node_datas [node ].lhs ,
1653
- .builtin_call , .builtin_call_comma = > tree .extra_data [node_datas [node ].lhs ],
1654
- else = > unreachable ,
1655
- };
1656
- const main_tokens = tree .nodes .items (.main_token );
1657
- const tok_index = main_tokens [param ];
1658
- const token_starts = tree .tokens .items (.start );
1659
- return token_starts [tok_index ];
1660
- },
1661
- .node_offset_builtin_call_arg1 = > | node_off | {
1662
- const tree = try src_loc .file_scope .getTree (gpa );
1663
- const node_datas = tree .nodes .items (.data );
1664
- const node_tags = tree .nodes .items (.tag );
1665
- const node = src_loc .declRelativeToNodeIndex (node_off );
1666
- const param = switch (node_tags [node ]) {
1667
- .builtin_call_two , .builtin_call_two_comma = > node_datas [node ].rhs ,
1668
- .builtin_call , .builtin_call_comma = > tree .extra_data [node_datas [node ].lhs + 1 ],
1669
- else = > unreachable ,
1670
- };
1671
- const main_tokens = tree .nodes .items (.main_token );
1672
- const tok_index = main_tokens [param ];
1673
- const token_starts = tree .tokens .items (.start );
1674
- return token_starts [tok_index ];
1675
- },
1647
+ .node_offset_builtin_call_arg0 = > | n | return src_loc .byteOffsetBuiltinCallArg (gpa , n , 0 ),
1648
+ .node_offset_builtin_call_arg1 = > | n | return src_loc .byteOffsetBuiltinCallArg (gpa , n , 1 ),
1649
+ .node_offset_builtin_call_arg2 = > | n | return src_loc .byteOffsetBuiltinCallArg (gpa , n , 2 ),
1650
+ .node_offset_builtin_call_arg3 = > | n | return src_loc .byteOffsetBuiltinCallArg (gpa , n , 3 ),
1651
+ .node_offset_builtin_call_arg4 = > | n | return src_loc .byteOffsetBuiltinCallArg (gpa , n , 4 ),
1652
+ .node_offset_builtin_call_arg5 = > | n | return src_loc .byteOffsetBuiltinCallArg (gpa , n , 5 ),
1676
1653
.node_offset_array_access_index = > | node_off | {
1677
1654
const tree = try src_loc .file_scope .getTree (gpa );
1678
1655
const node_datas = tree .nodes .items (.data );
@@ -1965,6 +1942,31 @@ pub const SrcLoc = struct {
1965
1942
},
1966
1943
}
1967
1944
}
1945
+
1946
+ pub fn byteOffsetBuiltinCallArg (
1947
+ src_loc : SrcLoc ,
1948
+ gpa : * Allocator ,
1949
+ node_off : i32 ,
1950
+ arg_index : u32 ,
1951
+ ) ! u32 {
1952
+ const tree = try src_loc .file_scope .getTree (gpa );
1953
+ const node_datas = tree .nodes .items (.data );
1954
+ const node_tags = tree .nodes .items (.tag );
1955
+ const node = src_loc .declRelativeToNodeIndex (node_off );
1956
+ const param = switch (node_tags [node ]) {
1957
+ .builtin_call_two , .builtin_call_two_comma = > switch (arg_index ) {
1958
+ 0 = > node_datas [node ].lhs ,
1959
+ 1 = > node_datas [node ].rhs ,
1960
+ else = > unreachable ,
1961
+ },
1962
+ .builtin_call , .builtin_call_comma = > tree .extra_data [node_datas [node ].lhs + arg_index ],
1963
+ else = > unreachable ,
1964
+ };
1965
+ const main_tokens = tree .nodes .items (.main_token );
1966
+ const tok_index = main_tokens [param ];
1967
+ const token_starts = tree .tokens .items (.start );
1968
+ return token_starts [tok_index ];
1969
+ }
1968
1970
};
1969
1971
1970
1972
/// Resolving a source location into a byte offset may require doing work
@@ -2032,6 +2034,10 @@ pub const LazySrcLoc = union(enum) {
2032
2034
node_offset_builtin_call_arg0 : i32 ,
2033
2035
/// Same as `node_offset_builtin_call_arg0` except arg index 1.
2034
2036
node_offset_builtin_call_arg1 : i32 ,
2037
+ node_offset_builtin_call_arg2 : i32 ,
2038
+ node_offset_builtin_call_arg3 : i32 ,
2039
+ node_offset_builtin_call_arg4 : i32 ,
2040
+ node_offset_builtin_call_arg5 : i32 ,
2035
2041
/// The source location points to the index expression of an array access
2036
2042
/// expression, found by taking this AST node index offset from the containing
2037
2043
/// Decl AST node, which points to an array access AST node. Next, navigate
@@ -2157,6 +2163,10 @@ pub const LazySrcLoc = union(enum) {
2157
2163
.node_offset_for_cond ,
2158
2164
.node_offset_builtin_call_arg0 ,
2159
2165
.node_offset_builtin_call_arg1 ,
2166
+ .node_offset_builtin_call_arg2 ,
2167
+ .node_offset_builtin_call_arg3 ,
2168
+ .node_offset_builtin_call_arg4 ,
2169
+ .node_offset_builtin_call_arg5 ,
2160
2170
.node_offset_array_access_index ,
2161
2171
.node_offset_slice_sentinel ,
2162
2172
.node_offset_call_func ,
@@ -2205,6 +2215,10 @@ pub const LazySrcLoc = union(enum) {
2205
2215
.node_offset_for_cond ,
2206
2216
.node_offset_builtin_call_arg0 ,
2207
2217
.node_offset_builtin_call_arg1 ,
2218
+ .node_offset_builtin_call_arg2 ,
2219
+ .node_offset_builtin_call_arg3 ,
2220
+ .node_offset_builtin_call_arg4 ,
2221
+ .node_offset_builtin_call_arg5 ,
2208
2222
.node_offset_array_access_index ,
2209
2223
.node_offset_slice_sentinel ,
2210
2224
.node_offset_call_func ,
@@ -2246,6 +2260,9 @@ pub const CompileError = error{
2246
2260
/// because the function is generic. This is only seen when analyzing the body of a param
2247
2261
/// instruction.
2248
2262
GenericPoison ,
2263
+ /// In a comptime scope, a return instruction was encountered. This error is only seen when
2264
+ /// doing a comptime function call.
2265
+ ComptimeReturn ,
2249
2266
};
2250
2267
2251
2268
pub fn deinit (mod : * Module ) void {
@@ -3928,8 +3945,10 @@ pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn) SemaError!Air {
3928
3945
log .debug ("set {s} to in_progress" , .{decl .name });
3929
3946
3930
3947
_ = sema .analyzeBody (& inner_block , fn_info .body ) catch | err | switch (err ) {
3948
+ // TODO make these unreachable instead of @panic
3931
3949
error .NeededSourceLocation = > @panic ("zig compiler bug: NeededSourceLocation" ),
3932
3950
error .GenericPoison = > @panic ("zig compiler bug: GenericPoison" ),
3951
+ error .ComptimeReturn = > @panic ("zig compiler bug: ComptimeReturn" ),
3933
3952
else = > | e | return e ,
3934
3953
};
3935
3954
@@ -4534,7 +4553,6 @@ pub const PeerTypeCandidateSrc = union(enum) {
4534
4553
self : PeerTypeCandidateSrc ,
4535
4554
gpa : * Allocator ,
4536
4555
decl : * Decl ,
4537
- candidates : usize ,
4538
4556
candidate_i : usize ,
4539
4557
) ? LazySrcLoc {
4540
4558
@setCold (true );
@@ -4547,12 +4565,14 @@ pub const PeerTypeCandidateSrc = union(enum) {
4547
4565
return candidate_srcs [candidate_i ];
4548
4566
},
4549
4567
.typeof_builtin_call_node_offset = > | node_offset | {
4550
- if (candidates <= 2 ) {
4551
- switch (candidate_i ) {
4552
- 0 = > return LazySrcLoc { .node_offset_builtin_call_arg0 = node_offset },
4553
- 1 = > return LazySrcLoc { .node_offset_builtin_call_arg1 = node_offset },
4554
- else = > unreachable ,
4555
- }
4568
+ switch (candidate_i ) {
4569
+ 0 = > return LazySrcLoc { .node_offset_builtin_call_arg0 = node_offset },
4570
+ 1 = > return LazySrcLoc { .node_offset_builtin_call_arg1 = node_offset },
4571
+ 2 = > return LazySrcLoc { .node_offset_builtin_call_arg2 = node_offset },
4572
+ 3 = > return LazySrcLoc { .node_offset_builtin_call_arg3 = node_offset },
4573
+ 4 = > return LazySrcLoc { .node_offset_builtin_call_arg4 = node_offset },
4574
+ 5 = > return LazySrcLoc { .node_offset_builtin_call_arg5 = node_offset },
4575
+ else = > {},
4556
4576
}
4557
4577
4558
4578
const tree = decl .namespace .file_scope .getTree (gpa ) catch | err | {
0 commit comments