Skip to content

Commit a6c8ee5

Browse files
BratishkaErikandrewrk
authored andcommitted
compiler: rename "@xtoy" to "@YFromX", zig fmt: rewrite them
Signed-off-by: Eric Joldasov <[email protected]>
1 parent e6e8cac commit a6c8ee5

22 files changed

+339
-319
lines changed

lib/std/zig/render.zig

+20
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,26 @@ fn renderBuiltinCall(
13961396
try ais.writer().writeAll("@max");
13971397
} else if (mem.eql(u8, slice, "@minimum")) {
13981398
try ais.writer().writeAll("@min");
1399+
}
1400+
//
1401+
else if (mem.eql(u8, slice, "@boolToInt")) {
1402+
try ais.writer().writeAll("@intFromBool");
1403+
} else if (mem.eql(u8, slice, "@enumToInt")) {
1404+
try ais.writer().writeAll("@intFromEnum");
1405+
} else if (mem.eql(u8, slice, "@errorToInt")) {
1406+
try ais.writer().writeAll("@intFromError");
1407+
} else if (mem.eql(u8, slice, "@floatToInt")) {
1408+
try ais.writer().writeAll("@intFromFloat");
1409+
} else if (mem.eql(u8, slice, "@intToEnum")) {
1410+
try ais.writer().writeAll("@enumFromInt");
1411+
} else if (mem.eql(u8, slice, "@intToError")) {
1412+
try ais.writer().writeAll("@errorFromInt");
1413+
} else if (mem.eql(u8, slice, "@intToFloat")) {
1414+
try ais.writer().writeAll("@floatFromInt");
1415+
} else if (mem.eql(u8, slice, "@intToPtr")) {
1416+
try ais.writer().writeAll("@ptrFromInt");
1417+
} else if (mem.eql(u8, slice, "@ptrToInt")) {
1418+
try ais.writer().writeAll("@intFromPtr");
13991419
} else {
14001420
try renderToken(ais, tree, builtin_token, .none); // @name
14011421
}

src/Air.zig

+16-16
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,11 @@ pub const Inst = struct {
478478
/// Converts a pointer to its address. Result type is always `usize`.
479479
/// Pointer type size may be any, including slice.
480480
/// Uses the `un_op` field.
481-
ptrtoint,
481+
int_from_ptr,
482482
/// Given a boolean, returns 0 or 1.
483483
/// Result type is always `u1`.
484484
/// Uses the `un_op` field.
485-
bool_to_int,
485+
int_from_bool,
486486
/// Return a value from a function.
487487
/// Result type is always noreturn; no instructions in a block follow this one.
488488
/// Uses the `un_op` field.
@@ -629,12 +629,12 @@ pub const Inst = struct {
629629
array_to_slice,
630630
/// Given a float operand, return the integer with the closest mathematical meaning.
631631
/// Uses the `ty_op` field.
632-
float_to_int,
633-
/// Same as `float_to_int` with optimized float mode.
634-
float_to_int_optimized,
632+
int_from_float,
633+
/// Same as `int_from_float` with optimized float mode.
634+
int_from_float_optimized,
635635
/// Given an integer operand, return the float with the closest mathematical meaning.
636636
/// Uses the `ty_op` field.
637-
int_to_float,
637+
float_from_int,
638638

639639
/// Transforms a vector into a scalar value by performing a sequential
640640
/// horizontal reduction of its elements using the specified operator.
@@ -1337,9 +1337,9 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
13371337
.struct_field_ptr_index_2,
13381338
.struct_field_ptr_index_3,
13391339
.array_to_slice,
1340-
.float_to_int,
1341-
.float_to_int_optimized,
1342-
.int_to_float,
1340+
.int_from_float,
1341+
.int_from_float_optimized,
1342+
.float_from_int,
13431343
.splat,
13441344
.get_union_tag,
13451345
.clz,
@@ -1387,7 +1387,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
13871387
.c_va_end,
13881388
=> return Type.void,
13891389

1390-
.ptrtoint,
1390+
.int_from_ptr,
13911391
.slice_len,
13921392
.ret_addr,
13931393
.frame_addr,
@@ -1397,7 +1397,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
13971397
.wasm_memory_grow => return Type.i32,
13981398
.wasm_memory_size => return Type.u32,
13991399

1400-
.bool_to_int => return Type.u1,
1400+
.int_from_bool => return Type.u1,
14011401

14021402
.tag_name, .error_name => return Type.slice_const_u8_sentinel_0,
14031403

@@ -1687,8 +1687,8 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
16871687
.is_non_err_ptr,
16881688
.bool_and,
16891689
.bool_or,
1690-
.ptrtoint,
1691-
.bool_to_int,
1690+
.int_from_ptr,
1691+
.int_from_bool,
16921692
.fptrunc,
16931693
.fpext,
16941694
.intcast,
@@ -1718,9 +1718,9 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
17181718
.slice_elem_ptr,
17191719
.ptr_elem_ptr,
17201720
.array_to_slice,
1721-
.float_to_int,
1722-
.float_to_int_optimized,
1723-
.int_to_float,
1721+
.int_from_float,
1722+
.int_from_float_optimized,
1723+
.float_from_int,
17241724
.reduce,
17251725
.reduce_optimized,
17261726
.splat,

src/AstGen.zig

+19-19
Original file line numberDiff line numberDiff line change
@@ -2626,15 +2626,15 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
26262626
.error_set_decl,
26272627
.error_set_decl_anon,
26282628
.error_set_decl_func,
2629-
.int_to_enum,
2630-
.enum_to_int,
2629+
.enum_from_int,
2630+
.int_from_enum,
26312631
.type_info,
26322632
.size_of,
26332633
.bit_size_of,
26342634
.typeof_log2_int_type,
2635-
.ptr_to_int,
2635+
.int_from_ptr,
26362636
.align_of,
2637-
.bool_to_int,
2637+
.int_from_bool,
26382638
.embed_file,
26392639
.error_name,
26402640
.sqrt,
@@ -2655,9 +2655,9 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
26552655
.type_name,
26562656
.frame_type,
26572657
.frame_size,
2658-
.float_to_int,
2659-
.int_to_float,
2660-
.int_to_ptr,
2658+
.int_from_float,
2659+
.float_from_int,
2660+
.ptr_from_int,
26612661
.float_cast,
26622662
.int_cast,
26632663
.ptr_cast,
@@ -8281,11 +8281,11 @@ fn builtinCall(
82818281
.bit_size_of => return simpleUnOpType(gz, scope, ri, node, params[0], .bit_size_of),
82828282
.align_of => return simpleUnOpType(gz, scope, ri, node, params[0], .align_of),
82838283

8284-
.ptr_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .ptr_to_int),
8284+
.int_from_ptr => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .int_from_ptr),
82858285
.compile_error => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .compile_error),
82868286
.set_eval_branch_quota => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .set_eval_branch_quota),
8287-
.enum_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .enum_to_int),
8288-
.bool_to_int => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .bool_to_int),
8287+
.int_from_enum => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .int_from_enum),
8288+
.int_from_bool => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .int_from_bool),
82898289
.embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .embed_file),
82908290
.error_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .anyerror_type } }, params[0], .error_name),
82918291
.set_runtime_safety => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_runtime_safety),
@@ -8308,10 +8308,10 @@ fn builtinCall(
83088308
.Frame => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_type),
83098309
.frame_size => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_size),
83108310

8311-
.float_to_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_to_int),
8312-
.int_to_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_float),
8313-
.int_to_ptr => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_ptr),
8314-
.int_to_enum => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_enum),
8311+
.int_from_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_from_float),
8312+
.float_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_from_int),
8313+
.ptr_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_from_int),
8314+
.enum_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .enum_from_int),
83158315
.float_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .float_cast),
83168316
.int_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .int_cast),
83178317
.ptr_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_cast),
@@ -8352,17 +8352,17 @@ fn builtinCall(
83528352
_ = try gz.addNode(.trap, node);
83538353
return rvalue(gz, ri, .unreachable_value, node);
83548354
},
8355-
.error_to_int => {
8355+
.int_from_error => {
83568356
const operand = try expr(gz, scope, .{ .rl = .none }, params[0]);
8357-
const result = try gz.addExtendedPayload(.error_to_int, Zir.Inst.UnNode{
8357+
const result = try gz.addExtendedPayload(.int_from_error, Zir.Inst.UnNode{
83588358
.node = gz.nodeIndexToRelative(node),
83598359
.operand = operand,
83608360
});
83618361
return rvalue(gz, ri, result, node);
83628362
},
8363-
.int_to_error => {
8363+
.error_from_int => {
83648364
const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u16_type } }, params[0]);
8365-
const result = try gz.addExtendedPayload(.int_to_error, Zir.Inst.UnNode{
8365+
const result = try gz.addExtendedPayload(.error_from_int, Zir.Inst.UnNode{
83668366
.node = gz.nodeIndexToRelative(node),
83678367
.operand = operand,
83688368
});
@@ -8769,7 +8769,7 @@ fn simpleUnOp(
87698769
else
87708770
try expr(gz, scope, operand_ri, operand_node);
87718771
switch (tag) {
8772-
.tag_name, .error_name, .ptr_to_int => try emitDbgStmt(gz, cursor),
8772+
.tag_name, .error_name, .int_from_ptr => try emitDbgStmt(gz, cursor),
87738773
else => {},
87748774
}
87758775
const result = try gz.addUnNode(tag, operand, node);

src/Autodoc.zig

+9-9
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ fn walkInstruction(
14731473

14741474
// builtin functions
14751475
.align_of,
1476-
.bool_to_int,
1476+
.int_from_bool,
14771477
.embed_file,
14781478
.error_name,
14791479
.panic,
@@ -1496,7 +1496,7 @@ fn walkInstruction(
14961496
.type_name,
14971497
.frame_type,
14981498
.frame_size,
1499-
.ptr_to_int,
1499+
.int_from_ptr,
15001500
.bit_not,
15011501
// @check
15021502
.clz,
@@ -1521,10 +1521,10 @@ fn walkInstruction(
15211521
};
15221522
},
15231523

1524-
.float_to_int,
1525-
.int_to_float,
1526-
.int_to_ptr,
1527-
.int_to_enum,
1524+
.int_from_float,
1525+
.float_from_int,
1526+
.ptr_from_int,
1527+
.enum_from_int,
15281528
.float_cast,
15291529
.int_cast,
15301530
.ptr_cast,
@@ -1936,7 +1936,7 @@ fn walkInstruction(
19361936
.expr = .{ .bitSizeOf = operand_index },
19371937
};
19381938
},
1939-
.enum_to_int => {
1939+
.int_from_enum => {
19401940
// not working correctly with `align()`
19411941
const un_node = data[inst_index].un_node;
19421942
const operand = try self.walkRef(
@@ -3021,8 +3021,8 @@ fn walkInstruction(
30213021
},
30223022
};
30233023
},
3024-
.error_to_int,
3025-
.int_to_error,
3024+
.int_from_error,
3025+
.error_from_int,
30263026
.reify,
30273027
.const_cast,
30283028
.volatile_cast,

0 commit comments

Comments
 (0)