Skip to content

Commit b933c69

Browse files
committed
Resolves some review feedback
1 parent 977a714 commit b933c69

14 files changed

+27
-51
lines changed

lib/std/math/big/int.zig

+14-19
Original file line numberDiff line numberDiff line change
@@ -2225,25 +2225,20 @@ pub const Const = struct {
22252225

22262226
/// Convert self to float type T.
22272227
pub fn toFloat(self: Const, comptime T: type) T {
2228-
switch (@typeInfo(T)) {
2229-
.float => {
2230-
if (self.limbs.len == 0) return 0;
2231-
2232-
const base = std.math.maxInt(std.math.big.Limb) + 1;
2233-
var result: f128 = 0;
2234-
var i: usize = self.limbs.len;
2235-
while (i != 0) {
2236-
i -= 1;
2237-
const limb: f128 = @floatFromInt(self.limbs[i]);
2238-
result = @mulAdd(f128, base, result, limb);
2239-
}
2240-
if (self.positive) {
2241-
return @floatCast(result);
2242-
} else {
2243-
return @floatCast(-result);
2244-
}
2245-
},
2246-
else => @compileError("expected float type, found '" ++ @typeName(T) ++ "'"),
2228+
if (self.limbs.len == 0) return 0;
2229+
2230+
const base = std.math.maxInt(std.math.big.Limb) + 1;
2231+
var result: f128 = 0;
2232+
var i: usize = self.limbs.len;
2233+
while (i != 0) {
2234+
i -= 1;
2235+
const limb: f128 = @floatFromInt(self.limbs[i]);
2236+
result = @mulAdd(f128, base, result, limb);
2237+
}
2238+
if (self.positive) {
2239+
return @floatCast(result);
2240+
} else {
2241+
return @floatCast(-result);
22472242
}
22482243
}
22492244

lib/std/std.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub const Thread = @import("Thread.zig");
4444
pub const Treap = @import("treap.zig").Treap;
4545
pub const Tz = tz.Tz;
4646
pub const Uri = @import("Uri.zig");
47-
pub const zon = @import("zon.zig");
4847

4948
pub const array_hash_map = @import("array_hash_map.zig");
5049
pub const atomic = @import("atomic.zig");
@@ -94,6 +93,7 @@ pub const valgrind = @import("valgrind.zig");
9493
pub const wasm = @import("wasm.zig");
9594
pub const zig = @import("zig.zig");
9695
pub const zip = @import("zip.zig");
96+
pub const zon = @import("zon.zig");
9797
pub const start = @import("start.zig");
9898

9999
const root = @import("root");

lib/std/zig/AstGen.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -11526,7 +11526,7 @@ fn failWithStrLitError(
1152611526
offset: u32,
1152711527
) InnerError {
1152811528
const raw_string = bytes[offset..];
11529-
return AstGen.failOff(
11529+
return failOff(
1153011530
astgen,
1153111531
token,
1153211532
@intCast(offset + err.offset()),

lib/std/zig/Zir.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ pub const Inst = struct {
481481
/// Uses the `pl_node` union field. `payload_index` points to a `FuncFancy`.
482482
func_fancy,
483483
/// Implements the `@import` builtin.
484-
/// Uses the `str_tok` field.
484+
/// Uses the `pl_tok` field.
485485
import,
486486
/// Integer literal that fits in a u64. Uses the `int` union field.
487487
int,

lib/std/zig/ZonGen.zig

-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
270270
if (size == 0) {
271271
try zg.addErrorNodeNotes(node, "void literals are not available in ZON", .{}, &.{
272272
try zg.errNoteNode(node, "void union payloads can be represented by enum literals", .{}),
273-
try zg.errNoteNode(node, "for example, `.{{ .foo = {{}} }}` becomes `.foo`", .{}),
274273
});
275274
} else {
276275
try zg.addErrorNode(node, "blocks are not allowed in ZON", .{});

lib/std/zig/number_literal.zig

-5
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ pub const Error = union(enum) {
6060
period_after_exponent: usize,
6161
};
6262

63-
const FormatWithSource = struct {
64-
bytes: []const u8,
65-
err: Error,
66-
};
67-
6863
/// Parse Zig number literal accepted by fmt.parseInt, fmt.parseFloat and big_int.setString.
6964
/// Valid for any input.
7065
pub fn parseNumberLiteral(bytes: []const u8) Result {

lib/std/zon.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! * anonymous tuple literals
1818
//!
1919
//! Here is an example ZON object:
20-
//! ```zon
20+
//! ```
2121
//! .{
2222
//! .a = 1.5,
2323
//! .b = "hello, world!",
@@ -27,7 +27,7 @@
2727
//! ```
2828
//!
2929
//! Individual primitives are also valid ZON, for example:
30-
//! ```zon
30+
//! ```
3131
//! "This string is a valid ZON object."
3232
//! ```
3333
//!

src/Compilation.zig

+1
Original file line numberDiff line numberDiff line change
@@ -3521,6 +3521,7 @@ pub fn addZirErrorMessages(eb: *ErrorBundle.Wip, file: *Zcu.File) !void {
35213521

35223522
pub fn addZoirErrorMessages(eb: *ErrorBundle.Wip, file: *Zcu.File) !void {
35233523
assert(file.source_loaded);
3524+
assert(file.tree_loaded);
35243525
const gpa = eb.gpa;
35253526
const src_path = try file.fullPath(gpa);
35263527
defer gpa.free(src_path);

src/Sema.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -14453,12 +14453,12 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1445314453
};
1445414454

1445514455
if (extra.res_ty == .none) {
14456-
return sema.fail(block, operand_src, "import ZON must have a known result type", .{});
14456+
return sema.fail(block, operand_src, "'@import' of ZON must have a known result type", .{});
1445714457
}
1445814458
const res_ty_inst = try sema.resolveInst(extra.res_ty);
1445914459
const res_ty = try sema.analyzeAsType(block, operand_src, res_ty_inst);
1446014460
if (res_ty.isGenericPoison()) {
14461-
return sema.fail(block, operand_src, "import ZON must have a known result type", .{});
14461+
return sema.fail(block, operand_src, "'@import' of ZON must have a known result type", .{});
1446214462
}
1446314463

1446414464
const interned = try zon.lower(

src/zon.zig

+3-15
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ fn fail(
7171
return self.sema.failWithOwnedErrorMsg(self.block, err_msg);
7272
}
7373

74-
const Ident = struct {
75-
bytes: []const u8,
76-
owned: bool,
77-
78-
fn deinit(self: *Ident, allocator: Allocator) void {
79-
if (self.owned) {
80-
allocator.free(self.bytes);
81-
}
82-
self.* = undefined;
83-
}
84-
};
85-
8674
fn lowerExpr(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) CompileError!InternPool.Index {
8775
switch (Type.zigTypeTag(res_ty, self.sema.pt.zcu)) {
8876
.bool => return self.lowerBool(node),
@@ -502,7 +490,7 @@ fn lowerTuple(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.I
502490
const field_defaults = tuple_info.values.get(ip);
503491
const field_types = tuple_info.types.get(ip);
504492
const elems = try self.sema.arena.alloc(InternPool.Index, field_types.len);
505-
for (elems) |*v| v.* = .none;
493+
@memset(elems, .none);
506494

507495
for (0..elem_nodes.len) |i| {
508496
if (i >= elems.len) {
@@ -570,7 +558,7 @@ fn lowerStruct(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
570558

571559
const field_defaults = struct_info.field_inits.get(ip);
572560
const field_values = try self.sema.arena.alloc(InternPool.Index, struct_info.field_names.len);
573-
for (field_values) |*v| v.* = .none;
561+
@memset(field_values, .none);
574562

575563
for (0..fields.names.len) |i| {
576564
const field_name = try ip.getOrPutString(
@@ -627,7 +615,7 @@ fn lowerStruct(self: LowerZon, node: Zoir.Node.Index, res_ty: Type) !InternPool.
627615
for (field_values, field_names) |*value, name| {
628616
if (value.* == .none) return self.fail(
629617
.{ .node_abs = node.getAstNode(self.file.zoir.?) },
630-
"missing field {}",
618+
"missing field '{}'",
631619
.{name.fmt(ip)},
632620
);
633621
}

test/cases/compile_errors/@import_zon_bad_import.zig

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ export fn entry() void {
55
}
66

77
// error
8-
// target=native
98
//
109
// :3:9: error: unable to open 'bogus-does-not-exist.zon': FileNotFound

test/cases/compile_errors/@import_zon_no_rt.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export fn entry() void {
66
// error
77
// imports=zon/simple_union.zon
88
//
9-
// tmp.zig:2:23: error: import ZON must have a known result type
9+
// tmp.zig:2:23: error: '@import' of ZON must have a known result type

test/cases/compile_errors/@import_zon_void.zig

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ export fn entry() void {
88
//
99
// void.zon:1:11: error: void literals are not available in ZON
1010
// void.zon:1:11: note: void union payloads can be represented by enum literals
11-
// void.zon:1:11: note: for example, `.{ .foo = {} }` becomes `.foo`

test/src/Cases.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ fn addFromDirInner(
488488
.pie = pie,
489489
.deps = std.ArrayList(DepModule).init(ctx.cases.allocator),
490490
.imports = imports,
491-
.target = b.resolveTargetQuery(target_query),
491+
.target = resolved_target,
492492
});
493493
try cases.append(next);
494494
}

0 commit comments

Comments
 (0)