diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-08-31 20:40:15 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-08-31 20:40:15 -0700 |
| commit | f250802ce794589f77367113335216c1993f7412 (patch) | |
| tree | 80f260bc0447d67924caa4162344ad21bf71ea2a /lib/std | |
| parent | fc23fe90ce1f3d28841c5a5a93a8bdf7edaefc54 (diff) | |
| download | zig-restricted-function-pointers.tar.gz zig-restricted-function-pointers.zip | |
compiler: introduce `@Restrict` builtinrestricted-function-pointers
conservative, incomplete change
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/AstGen.zig | 6 | ||||
| -rw-r--r-- | lib/std/zig/AstRlAnnotate.zig | 1 | ||||
| -rw-r--r-- | lib/std/zig/BuiltinFn.zig | 8 | ||||
| -rw-r--r-- | lib/std/zig/Zir.zig | 11 |
4 files changed, 26 insertions, 0 deletions
diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 848f11ddce..4d700da022 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -2876,6 +2876,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As .validate_array_init_ref_ty, .array_init_elem_type, .array_init_elem_ptr, + .restrict, => break :b false, .extended => switch (gz.astgen.instructions.items(.data)[@intFromEnum(inst)].extended.opcode) { @@ -9547,6 +9548,11 @@ fn builtinCall( }); return rvalue(gz, ri, result, node); }, + .Restrict => { + const operand = try typeExpr(gz, scope, params[0]); + const result = try gz.addUnNode(.restrict, operand, node); + return rvalue(gz, ri, result, node); + }, .add_with_overflow => return overflowArithmetic(gz, scope, ri, node, params, .add_with_overflow), .sub_with_overflow => return overflowArithmetic(gz, scope, ri, node, params, .sub_with_overflow), diff --git a/lib/std/zig/AstRlAnnotate.zig b/lib/std/zig/AstRlAnnotate.zig index 758d329136..f81af4a03c 100644 --- a/lib/std/zig/AstRlAnnotate.zig +++ b/lib/std/zig/AstRlAnnotate.zig @@ -923,6 +923,7 @@ fn builtinCall(astrl: *AstRlAnnotate, block: ?*Block, ri: ResultInfo, node: Ast. .work_item_id, .work_group_size, .work_group_id, + .Restrict, => { _ = try astrl.expr(args[0], block, ResultInfo.type_only); return false; diff --git a/lib/std/zig/BuiltinFn.zig b/lib/std/zig/BuiltinFn.zig index 5ef28fdfaf..27c7b8aee7 100644 --- a/lib/std/zig/BuiltinFn.zig +++ b/lib/std/zig/BuiltinFn.zig @@ -90,6 +90,7 @@ pub const Tag = enum { size_of, splat, reduce, + Restrict, src, sqrt, sin, @@ -796,6 +797,13 @@ pub const list = list: { }, }, .{ + "@Restrict", + .{ + .tag = .Restrict, + .param_count = 1, + }, + }, + .{ "@src", .{ .tag = .src, diff --git a/lib/std/zig/Zir.zig b/lib/std/zig/Zir.zig index e4728dc7ad..a259f4c64b 100644 --- a/lib/std/zig/Zir.zig +++ b/lib/std/zig/Zir.zig @@ -1071,6 +1071,12 @@ pub const Inst = struct { /// Uses the `un_node` field. restore_err_ret_index_fn_entry, + /// Creates a new restricted function pointer type based on the + /// provided function pointer type. + /// + /// Uses the `un_node` field. + restrict, + /// The ZIR instruction tag is one of the `Extended` ones. /// Uses the `extended` union field. extended, @@ -1315,6 +1321,7 @@ pub const Inst = struct { .validate_const, .restore_err_ret_index_unconditional, .restore_err_ret_index_fn_entry, + .restrict, => false, .@"break", @@ -1595,6 +1602,7 @@ pub const Inst = struct { .validate_array_init_ref_ty, .array_init_elem_type, .array_init_elem_ptr, + .restrict, => false, .extended => switch (data.extended.opcode) { @@ -1711,6 +1719,7 @@ pub const Inst = struct { .merge_error_sets = .pl_node, .mod_rem = .pl_node, .ref = .un_tok, + .restrict = .un_node, .ret_node = .un_node, .ret_load = .un_node, .ret_implicit = .un_tok, @@ -4755,6 +4764,8 @@ fn findTrackableInner( try zir.findTrackableBody(gpa, contents, defers, body); } }, + // Restricted function pointer types need tracking, but have no body. + .restrict => return contents.other.append(gpa, inst), } } |
