aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-09-06 19:06:09 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-09-06 19:45:02 -0700
commitb7900de1684021ff86c67105e14e34968821ea02 (patch)
treeb881a288071705ffb8cd65ede5f8e7a1452b6dce /lib
parent20145016ac0d098e8e63d5107a05eca376d1e7bb (diff)
parente2bb92b2e27dc54852a0227345e294ae383358fd (diff)
downloadzig-b7900de1684021ff86c67105e14e34968821ea02.tar.gz
zig-b7900de1684021ff86c67105e14e34968821ea02.zip
Merge remote-tracking branch 'origin/master' into llvm15
Diffstat (limited to 'lib')
-rw-r--r--lib/docs/index.html16
-rw-r--r--lib/docs/main.js61
-rw-r--r--lib/std/Thread.zig7
-rw-r--r--lib/std/coff.zig85
-rw-r--r--lib/std/log.zig2
-rw-r--r--lib/std/math/big/rational.zig16
-rw-r--r--lib/std/os.zig4
-rw-r--r--lib/std/zig/c_translation.zig2
-rw-r--r--lib/std/zig/parser_test.zig37
-rw-r--r--lib/std/zig/render.zig25
10 files changed, 231 insertions, 24 deletions
diff --git a/lib/docs/index.html b/lib/docs/index.html
index ddc0ecbfb2..00f570d100 100644
--- a/lib/docs/index.html
+++ b/lib/docs/index.html
@@ -359,7 +359,17 @@
#listFns dt {
font-family: var(--mono);
+ display: flex;
+ flex-direction: colunm;
+ justify-content: space-between;
+ }
+
+ #listFns dt .fnSignature {
+ overflow-x: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
}
+
.argBreaker {
display: none;
}
@@ -711,7 +721,11 @@
<h2>Examples</h2>
<ul id="listFnExamples" class="examples"></ul>
</div>
- <div id="sectTests" class="hidden">
+ <div id="sectDocTests" class="hidden">
+ <h2>DocTests</h2>
+ <pre id="docTestsCode"></pre>
+ </div>
+ <div id="sectTests" class="hidden">
<h2>Tests</h2>
<div class="table-container">
<table>
diff --git a/lib/docs/main.js b/lib/docs/main.js
index 6a3f2620f2..b02b061eb4 100644
--- a/lib/docs/main.js
+++ b/lib/docs/main.js
@@ -13,6 +13,8 @@ var zigAnalysis;
const domListTypes = document.getElementById("listTypes");
const domSectTests = document.getElementById("sectTests");
const domListTests = document.getElementById("listTests");
+ const domSectDocTests = document.getElementById("sectDocTests");
+ const domDocTestsCode = document.getElementById("docTestsCode");
const domSectNamespaces = document.getElementById("sectNamespaces");
const domListNamespaces = document.getElementById("listNamespaces");
const domSectErrSets = document.getElementById("sectErrSets");
@@ -241,7 +243,8 @@ var zigAnalysis;
return (
typeKind === typeKinds.Struct ||
typeKind === typeKinds.Union ||
- typeKind === typeKinds.Enum
+ typeKind === typeKinds.Enum ||
+ typeKind === typeKinds.Opaque
);
}
@@ -384,6 +387,7 @@ var zigAnalysis;
domSectPkgs.classList.add("hidden");
domSectTypes.classList.add("hidden");
domSectTests.classList.add("hidden");
+ domSectDocTests.classList.add("hidden");
domSectNamespaces.classList.add("hidden");
domSectErrSets.classList.add("hidden");
domSectFns.classList.add("hidden");
@@ -452,6 +456,10 @@ var zigAnalysis;
let lastIsDecl = isDecl(last);
let lastIsType = isType(last);
let lastIsContainerType = isContainerType(last);
+
+ if (lastIsDecl){
+ renderDocTest(last);
+ }
if (lastIsContainerType) {
return renderContainer(last);
@@ -477,6 +485,14 @@ var zigAnalysis;
return renderValue(last);
}
+
+ }
+
+ function renderDocTest(decl) {
+ if (!("decltest" in decl)) return;
+ const astNode = zigAnalysis.astNodes[decl.decltest];
+ domSectDocTests.classList.remove("hidden");
+ domDocTestsCode.innerHTML = astNode.code;
}
function renderUnknownDecl(decl) {
@@ -1405,6 +1421,30 @@ var zigAnalysis;
operator += "**";
break;
}
+ case "cmp_eq": {
+ operator += "==";
+ break;
+ }
+ case "cmp_neq": {
+ operator += "!=";
+ break;
+ }
+ case "cmp_gt": {
+ operator += ">";
+ break;
+ }
+ case "cmp_gte": {
+ operator += ">=";
+ break;
+ }
+ case "cmp_lt": {
+ operator += "<";
+ break;
+ }
+ case "cmp_lte": {
+ operator += "<=";
+ break;
+ }
default:
console.log("operator not handled yet or doesn't exist!");
}
@@ -1555,6 +1595,10 @@ var zigAnalysis;
return '"' + escapeHtml(expr.string) + '"';
}
+ case "int_big": {
+ return (expr.int_big.negated ? "-" : "") + expr.int_big.value;
+ }
+
case "anytype": {
return "anytype";
}
@@ -1581,8 +1625,7 @@ var zigAnalysis;
}
case typeKinds.Opaque: {
let opaqueObj = typeObj;
-
- return opaqueObj.name;
+ return opaqueObj;
}
case typeKinds.ComptimeExpr: {
return "anyopaque";
@@ -2285,7 +2328,7 @@ var zigAnalysis;
return "<a style=\"float: right;\" href=\"" +
sourceFileUrlTemplate.replace("{{file}}",
- zigAnalysis.files[srcNode.file]).replace("{{line}}", srcNode.line) + "\">[src]</a>";
+ zigAnalysis.files[srcNode.file]).replace("{{line}}", srcNode.line + 1) + "\">[src]</a>";
}
function renderContainer(container) {
@@ -2393,24 +2436,26 @@ var zigAnalysis;
resizeDomList(
domListFns,
fnsList.length,
- "<div><dt></dt><dd></dd></div>"
+ "<div><dt><div class=\"fnSignature\"></div><div></div></dt><dd></dd></div>"
);
for (let i = 0; i < fnsList.length; i += 1) {
let decl = fnsList[i];
let trDom = domListFns.children[i];
- let tdFnCode = trDom.children[0];
+ let tdFnSignature = trDom.children[0].children[0];
+ let tdFnSrc = trDom.children[0].children[1];
let tdDesc = trDom.children[1];
let declType = resolveValue(decl.value);
console.assert("type" in declType.expr);
- tdFnCode.innerHTML = exprName(declType.expr, {
+ tdFnSignature.innerHTML = exprName(declType.expr, {
wantHtml: true,
wantLink: true,
fnDecl: decl,
linkFnNameDecl: navLinkDecl(decl.name),
- }) + renderSourceFileLink(decl);
+ });
+ tdFnSrc.innerHTML = renderSourceFileLink(decl);
let docs = zigAnalysis.astNodes[decl.src].docs;
if (docs != null) {
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig
index d52515b88d..20985c36a0 100644
--- a/lib/std/Thread.zig
+++ b/lib/std/Thread.zig
@@ -769,16 +769,13 @@ const LinuxThreadImpl = struct {
),
.x86_64 => asm volatile (
\\ movq $11, %%rax
- \\ movq %[ptr], %%rbx
- \\ movq %[len], %%rcx
\\ syscall
\\ movq $60, %%rax
\\ movq $1, %%rdi
\\ syscall
:
- : [ptr] "r" (@ptrToInt(self.mapped.ptr)),
- [len] "r" (self.mapped.len),
- : "memory"
+ : [ptr] "{rdi}" (@ptrToInt(self.mapped.ptr)),
+ [len] "{rsi}" (self.mapped.len),
),
.arm, .armeb, .thumb, .thumbeb => asm volatile (
\\ mov r7, #91
diff --git a/lib/std/coff.zig b/lib/std/coff.zig
index 1caec57c4a..ad440e7757 100644
--- a/lib/std/coff.zig
+++ b/lib/std/coff.zig
@@ -419,6 +419,91 @@ pub const DebugType = enum(u32) {
EX_DLLCHARACTERISTICS = 20,
};
+pub const ImportDirectoryEntry = extern struct {
+ /// The RVA of the import lookup table.
+ /// This table contains a name or ordinal for each import.
+ /// (The name "Characteristics" is used in Winnt.h, but no longer describes this field.)
+ import_lookup_table_rva: u32,
+
+ /// The stamp that is set to zero until the image is bound.
+ /// After the image is bound, this field is set to the time/data stamp of the DLL.
+ time_date_stamp: u32,
+
+ /// The index of the first forwarder reference.
+ forwarder_chain: u32,
+
+ /// The address of an ASCII string that contains the name of the DLL.
+ /// This address is relative to the image base.
+ name_rva: u32,
+
+ /// The RVA of the import address table.
+ /// The contents of this table are identical to the contents of the import lookup table until the image is bound.
+ import_address_table_rva: u32,
+};
+
+pub const ImportLookupEntry32 = struct {
+ pub const ByName = packed struct {
+ name_table_rva: u31,
+ flag: u1 = 0,
+ };
+
+ pub const ByOrdinal = packed struct {
+ ordinal_number: u16,
+ unused: u15 = 0,
+ flag: u1 = 1,
+ };
+
+ const mask = 0x80000000;
+
+ pub fn getImportByName(raw: u32) ?ByName {
+ if (mask & raw != 0) return null;
+ return @bitCast(ByName, raw);
+ }
+
+ pub fn getImportByOrdinal(raw: u32) ?ByOrdinal {
+ if (mask & raw == 0) return null;
+ return @bitCast(ByOrdinal, raw);
+ }
+};
+
+pub const ImportLookupEntry64 = struct {
+ pub const ByName = packed struct {
+ name_table_rva: u31,
+ unused: u32 = 0,
+ flag: u1 = 0,
+ };
+
+ pub const ByOrdinal = packed struct {
+ ordinal_number: u16,
+ unused: u47 = 0,
+ flag: u1 = 1,
+ };
+
+ const mask = 0x8000000000000000;
+
+ pub fn getImportByName(raw: u64) ?ByName {
+ if (mask & raw != 0) return null;
+ return @bitCast(ByName, raw);
+ }
+
+ pub fn getImportByOrdinal(raw: u64) ?ByOrdinal {
+ if (mask & raw == 0) return null;
+ return @bitCast(ByOrdinal, raw);
+ }
+};
+
+/// Every name ends with a NULL byte. IF the NULL byte does not fall on
+/// 2byte boundary, the entry structure is padded to ensure 2byte alignment.
+pub const ImportHintNameEntry = extern struct {
+ /// An index into the export name pointer table.
+ /// A match is attempted first with this value. If it fails, a binary search is performed on the DLL's export name pointer table.
+ hint: u16,
+
+ /// Pointer to NULL terminated ASCII name.
+ /// Variable length...
+ name: [1]u8,
+};
+
pub const SectionHeader = extern struct {
name: [8]u8,
virtual_size: u32,
diff --git a/lib/std/log.zig b/lib/std/log.zig
index 081344f2c8..e0e002d600 100644
--- a/lib/std/log.zig
+++ b/lib/std/log.zig
@@ -38,7 +38,7 @@
//! return,
//! } ++ "): ";
//!
-//! const prefix = "[" ++ level.asText() ++ "] " ++ scope_prefix;
+//! const prefix = "[" ++ comptime level.asText() ++ "] " ++ scope_prefix;
//!
//! // Print the message to stderr, silently ignoring any errors
//! std.debug.getStderrMutex().lock();
diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig
index 895b20d9b5..61e2194eea 100644
--- a/lib/std/math/big/rational.zig
+++ b/lib/std/math/big/rational.zig
@@ -334,13 +334,13 @@ pub const Rational = struct {
/// Returns math.Order.lt, math.Order.eq, math.Order.gt if a < b, a == b or a
/// > b respectively.
pub fn order(a: Rational, b: Rational) !math.Order {
- return cmpInternal(a, b, true);
+ return cmpInternal(a, b, false);
}
/// Returns math.Order.lt, math.Order.eq, math.Order.gt if |a| < |b|, |a| ==
/// |b| or |a| > |b| respectively.
pub fn orderAbs(a: Rational, b: Rational) !math.Order {
- return cmpInternal(a, b, false);
+ return cmpInternal(a, b, true);
}
// p/q > x/y iff p*y > x*q
@@ -704,6 +704,18 @@ test "big.rational order" {
try testing.expect((try a.order(b)) == .eq);
}
+test "big.rational order/orderAbs with negative" {
+ var a = try Rational.init(testing.allocator);
+ defer a.deinit();
+ var b = try Rational.init(testing.allocator);
+ defer b.deinit();
+
+ try a.setRatio(1, 1);
+ try b.setRatio(-2, 1);
+ try testing.expect((try a.order(b)) == .gt);
+ try testing.expect((try a.orderAbs(b)) == .lt);
+}
+
test "big.rational add single-limb" {
var a = try Rational.init(testing.allocator);
defer a.deinit();
diff --git a/lib/std/os.zig b/lib/std/os.zig
index 59f2a2173f..a707331a47 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -3447,6 +3447,9 @@ pub const BindError = error{
/// A nonexistent interface was requested or the requested address was not local.
AddressNotAvailable,
+ /// The address is not valid for the address family of socket.
+ AddressFamilyNotSupported,
+
/// Too many symbolic links were encountered in resolving addr.
SymLinkLoop,
@@ -3502,6 +3505,7 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
.BADF => unreachable, // always a race condition if this error is returned
.INVAL => unreachable, // invalid parameters
.NOTSOCK => unreachable, // invalid `sockfd`
+ .AFNOSUPPORT => return error.AddressFamilyNotSupported,
.ADDRNOTAVAIL => return error.AddressNotAvailable,
.FAULT => unreachable, // invalid `addr` pointer
.LOOP => return error.SymLinkLoop,
diff --git a/lib/std/zig/c_translation.zig b/lib/std/zig/c_translation.zig
index 348e3a7133..6847a92eae 100644
--- a/lib/std/zig/c_translation.zig
+++ b/lib/std/zig/c_translation.zig
@@ -268,7 +268,7 @@ test "sizeof" {
pub const CIntLiteralRadix = enum { decimal, octal, hexadecimal };
fn PromoteIntLiteralReturnType(comptime SuffixType: type, comptime number: comptime_int, comptime radix: CIntLiteralRadix) type {
- const signed_decimal = [_]type{ c_int, c_long, c_longlong };
+ const signed_decimal = [_]type{ c_int, c_long, c_longlong, c_ulonglong };
const signed_oct_hex = [_]type{ c_int, c_uint, c_long, c_ulong, c_longlong, c_ulonglong };
const unsigned = [_]type{ c_uint, c_ulong, c_ulonglong };
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index 2bb8c848bc..0e1817ffab 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -16,6 +16,28 @@ test "zig fmt: preserves clobbers in inline asm with stray comma" {
);
}
+test "zig fmt: remove trailing comma at the end of assembly clobber" {
+ try testTransform(
+ \\fn foo() void {
+ \\ asm volatile (""
+ \\ : [_] "" (-> type),
+ \\ :
+ \\ : "clobber1", "clobber2",
+ \\ );
+ \\}
+ \\
+ ,
+ \\fn foo() void {
+ \\ asm volatile (""
+ \\ : [_] "" (-> type),
+ \\ :
+ \\ : "clobber1", "clobber2"
+ \\ );
+ \\}
+ \\
+ );
+}
+
test "zig fmt: respect line breaks in struct field value declaration" {
try testCanonical(
\\const Foo = struct {
@@ -5035,6 +5057,21 @@ test "zig fmt: make single-line if no trailing comma" {
);
}
+test "zig fmt: preserve container doc comment in container without trailing comma" {
+ try testTransform(
+ \\const A = enum(u32) {
+ \\//! comment
+ \\_ };
+ \\
+ ,
+ \\const A = enum(u32) {
+ \\ //! comment
+ \\ _,
+ \\};
+ \\
+ );
+}
+
test "zig fmt: make single-line if no trailing comma" {
try testCanonical(
\\// Test trailing comma syntax
diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig
index 03f951d0f1..bc59ddc279 100644
--- a/lib/std/zig/render.zig
+++ b/lib/std/zig/render.zig
@@ -1933,12 +1933,15 @@ fn renderContainerDecl(
break :one_line;
}
- // 2. A member of the container has a doc comment.
+ // 2. The container has a container comment.
+ if (token_tags[lbrace + 1] == .container_doc_comment) break :one_line;
+
+ // 3. A member of the container has a doc comment.
for (token_tags[lbrace + 1 .. rbrace - 1]) |tag| {
if (tag == .doc_comment) break :one_line;
}
- // 3. The container has non-field members.
+ // 4. The container has non-field members.
for (container_decl.ast.members) |member| {
if (!node_tags[member].isContainerField()) break :one_line;
}
@@ -2114,9 +2117,19 @@ fn renderAsm(
return renderToken(ais, tree, tok_i + 1, space);
},
.comma => {
- try renderToken(ais, tree, tok_i, .none);
- try renderToken(ais, tree, tok_i + 1, .space);
- tok_i += 2;
+ switch (token_tags[tok_i + 2]) {
+ .r_paren => {
+ ais.setIndentDelta(indent_delta);
+ ais.popIndent();
+ try renderToken(ais, tree, tok_i, .newline);
+ return renderToken(ais, tree, tok_i + 2, space);
+ },
+ else => {
+ try renderToken(ais, tree, tok_i, .none);
+ try renderToken(ais, tree, tok_i + 1, .space);
+ tok_i += 2;
+ },
+ }
},
else => unreachable,
}
@@ -2348,7 +2361,7 @@ fn renderSpace(ais: *Ais, tree: Ast, token_index: Ast.TokenIndex, lexeme_len: us
}
}
-/// Returns true if there exists a comment between any of the tokens from
+/// Returns true if there exists a line comment between any of the tokens from
/// `start_token` to `end_token`. This is used to determine if e.g. a
/// fn_proto should be wrapped and have a trailing comma inserted even if
/// there is none in the source.