aboutsummaryrefslogtreecommitdiff
path: root/src/link
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-07 00:39:23 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-07-07 00:39:23 -0700
commit13f04e3012b6b2eee141923f9780fce55f7a999d (patch)
treefd8d164d7926d76a1e967b89283322ee6ad88bb0 /src/link
parentd481acc7dbebb5501b5fef608ee1f6b13c442c6a (diff)
downloadzig-13f04e3012b6b2eee141923f9780fce55f7a999d.tar.gz
zig-13f04e3012b6b2eee141923f9780fce55f7a999d.zip
stage2: implement `@panic` and beginnigs of inferred error sets
* ZIR: add two instructions: - ret_err_value_code - ret_err_value * AstGen: add countDefers and utilize it to emit more efficient ZIR for return expressions in the presence of defers. * AstGen: implement |err| payloads for `errdefer` syntax. - There is not an "unused capture" error for it yet. * AstGen: `return error.Foo` syntax gets a hot path in return expressions, using the new ZIR instructions. This also is part of implementing inferred error sets, since we need to tell Sema to add an error value to the inferred error set before it gets coerced. * Sema: implement `@setCold`. - Implement `@setCold` support for C backend. * `@panic` and regular safety panics such as `unreachable` now properly invoke `std.builtin.panic`. * C backend: improve pointer and function value rendering. * C linker: fix redundant typedefs. * Add Type.error_set_inferred. * Fix Value.format for enum_literal, enum_field_index, bytes. * Remove the C backend test that checks for identical text I measured a 14% reduction in Total ZIR Bytes from master branch for std/os.zig.
Diffstat (limited to 'src/link')
-rw-r--r--src/link/C.zig10
-rw-r--r--src/link/C/zig.h6
2 files changed, 10 insertions, 6 deletions
diff --git a/src/link/C.zig b/src/link/C.zig
index 1793b95210..875fd2e964 100644
--- a/src/link/C.zig
+++ b/src/link/C.zig
@@ -207,7 +207,7 @@ pub fn flushModule(self: *C, comp: *Compilation) !void {
}
var fn_count: usize = 0;
- var typedefs = std.HashMap(Type, []const u8, Type.HashContext, std.hash_map.default_max_load_percentage).init(comp.gpa);
+ var typedefs = std.HashMap(Type, void, Type.HashContext, std.hash_map.default_max_load_percentage).init(comp.gpa);
defer typedefs.deinit();
// Typedefs, forward decls and non-functions first.
@@ -217,14 +217,12 @@ pub fn flushModule(self: *C, comp: *Compilation) !void {
if (!decl.has_tv) continue;
const buf = buf: {
if (decl.val.castTag(.function)) |_| {
+ try typedefs.ensureUnusedCapacity(decl.fn_link.c.typedefs.count());
var it = decl.fn_link.c.typedefs.iterator();
while (it.next()) |new| {
- if (typedefs.get(new.key_ptr.*)) |previous| {
- try err_typedef_writer.print("typedef {s} {s};\n", .{ previous, new.value_ptr.name });
- } else {
- try typedefs.ensureCapacity(typedefs.capacity() + 1);
+ const gop = typedefs.getOrPutAssumeCapacity(new.key_ptr.*);
+ if (!gop.found_existing) {
try err_typedef_writer.writeAll(new.value_ptr.rendered);
- typedefs.putAssumeCapacityNoClobber(new.key_ptr.*, new.value_ptr.name);
}
}
fn_count += 1;
diff --git a/src/link/C/zig.h b/src/link/C/zig.h
index ad2b5d4498..a3e571d245 100644
--- a/src/link/C/zig.h
+++ b/src/link/C/zig.h
@@ -12,6 +12,12 @@
#define zig_threadlocal zig_threadlocal_unavailable
#endif
+#if __GNUC__
+#define ZIG_COLD __attribute__ ((cold))
+#else
+#define ZIG_COLD
+#endif
+
#if __STDC_VERSION__ >= 199901L
#define ZIG_RESTRICT restrict
#elif defined(__GNUC__)