authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-22 14:37:08-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-22 14:37:08-04:00
log317d1ecb2cf3234b0259daf6cc0baac7d86264e2
tree17c8c50e096fd23e0f9b9194a8a6ac0b8a028711
parentfcadeb50c04199fce2d9675ba2976680c71c67ff
parent16be70cbbf8e6dc658b9fcacd3366df8f83fffa8
signature Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into rewrite-coroutines


9 files changed, 139 insertions(+), 18 deletions(-)

build.zig+6-3
...@@ -122,16 +122,19 @@ pub fn build(b: *Builder) !void {...@@ -122,16 +122,19 @@ pub fn build(b: *Builder) !void {
122 }122 }
123 const modes = chosen_modes[0..chosen_mode_index];123 const modes = chosen_modes[0..chosen_mode_index];
124124
125 const multi_and_single = [_]bool{ false, true };
126 const just_multi = [_]bool{false};
127
125 // run stage1 `zig fmt` on this build.zig file just to make sure it works128 // run stage1 `zig fmt` on this build.zig file just to make sure it works
126 test_step.dependOn(&fmt_build_zig.step);129 test_step.dependOn(&fmt_build_zig.step);
127 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");130 const fmt_step = b.step("test-fmt", "Run zig fmt against build.zig to make sure it works");
128 fmt_step.dependOn(&fmt_build_zig.step);131 fmt_step.dependOn(&fmt_build_zig.step);
129132
130 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, skip_non_native));133 test_step.dependOn(tests.addPkgTests(b, test_filter, "test/stage1/behavior.zig", "behavior", "Run the behavior tests", modes, multi_and_single, skip_non_native));
131134
132 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, skip_non_native));135 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/std.zig", "std", "Run the standard library tests", modes, multi_and_single, skip_non_native));
133136
134 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, skip_non_native));137 test_step.dependOn(tests.addPkgTests(b, test_filter, "std/special/compiler_rt.zig", "compiler-rt", "Run the compiler_rt tests", modes, just_multi, skip_non_native));
135138
136 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));139 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
137 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));140 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
src/analyze.cpp+2-1
...@@ -3346,7 +3346,8 @@ static void resolve_use_decl(CodeGen *g, TldUsingNamespace *tld_using_namespace,...@@ -3346,7 +3346,8 @@ static void resolve_use_decl(CodeGen *g, TldUsingNamespace *tld_using_namespace,
33463346
3347static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, ScopeDecls *dest_decls_scope) {3347static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, ScopeDecls *dest_decls_scope) {
3348 if (using_namespace->base.resolution == TldResolutionOk ||3348 if (using_namespace->base.resolution == TldResolutionOk ||
3349 using_namespace->base.resolution == TldResolutionInvalid)3349 using_namespace->base.resolution == TldResolutionInvalid ||
3350 using_namespace->using_namespace_value != nullptr)
3350 {3351 {
3351 return;3352 return;
3352 }3353 }
std/build.zig+20-11
...@@ -41,9 +41,11 @@ pub const Builder = struct {...@@ -41,9 +41,11 @@ pub const Builder = struct {
41 env_map: *BufMap,41 env_map: *BufMap,
42 top_level_steps: ArrayList(*TopLevelStep),42 top_level_steps: ArrayList(*TopLevelStep),
43 install_prefix: ?[]const u8,43 install_prefix: ?[]const u8,
44 search_prefixes: ArrayList([]const u8),44 dest_dir: ?[]const u8,
45 lib_dir: ?[]const u8,45 lib_dir: ?[]const u8,
46 exe_dir: ?[]const u8,46 exe_dir: ?[]const u8,
47 install_path: []const u8,
48 search_prefixes: ArrayList([]const u8),
47 installed_files: ArrayList(InstalledFile),49 installed_files: ArrayList(InstalledFile),
48 build_root: []const u8,50 build_root: []const u8,
49 cache_root: []const u8,51 cache_root: []const u8,
...@@ -125,10 +127,11 @@ pub const Builder = struct {...@@ -125,10 +127,11 @@ pub const Builder = struct {
125 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),127 .top_level_steps = ArrayList(*TopLevelStep).init(allocator),
126 .default_step = undefined,128 .default_step = undefined,
127 .env_map = env_map,129 .env_map = env_map,
128 .install_prefix = null,
129 .search_prefixes = ArrayList([]const u8).init(allocator),130 .search_prefixes = ArrayList([]const u8).init(allocator),
131 .install_prefix = null,
130 .lib_dir = null,132 .lib_dir = null,
131 .exe_dir = null,133 .exe_dir = null,
134 .dest_dir = env_map.get("DESTDIR"),
132 .installed_files = ArrayList(InstalledFile).init(allocator),135 .installed_files = ArrayList(InstalledFile).init(allocator),
133 .install_tls = TopLevelStep{136 .install_tls = TopLevelStep{
134 .step = Step.initNoOp("install", allocator),137 .step = Step.initNoOp("install", allocator),
...@@ -142,6 +145,7 @@ pub const Builder = struct {...@@ -142,6 +145,7 @@ pub const Builder = struct {
142 .is_release = false,145 .is_release = false,
143 .override_std_dir = null,146 .override_std_dir = null,
144 .override_lib_dir = null,147 .override_lib_dir = null,
148 .install_path = undefined,
145 };149 };
146 try self.top_level_steps.append(&self.install_tls);150 try self.top_level_steps.append(&self.install_tls);
147 try self.top_level_steps.append(&self.uninstall_tls);151 try self.top_level_steps.append(&self.uninstall_tls);
...@@ -164,14 +168,19 @@ pub const Builder = struct {...@@ -164,14 +168,19 @@ pub const Builder = struct {
164 }168 }
165169
166 fn resolveInstallPrefix(self: *Builder) void {170 fn resolveInstallPrefix(self: *Builder) void {
167 const prefix = if (self.install_prefix) |prefix| prefix else blk: {171 if (self.dest_dir) |dest_dir| {
168 const prefix = self.cache_root;172 const install_prefix = self.install_prefix orelse "/usr";
169 self.install_prefix = prefix;173 self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;
170 break :blk prefix;174 } else {
171 };175 const install_prefix = self.install_prefix orelse blk: {
172176 const p = self.cache_root;
173 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "lib" }) catch unreachable;177 self.install_prefix = p;
174 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ prefix, "bin" }) catch unreachable;178 break :blk p;
179 };
180 self.install_path = install_prefix;
181 }
182 self.lib_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "lib" }) catch unreachable;
183 self.exe_dir = fs.path.join(self.allocator, [_][]const u8{ self.install_path, "bin" }) catch unreachable;
175 }184 }
176185
177 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {186 pub fn addExecutable(self: *Builder, name: []const u8, root_src: ?[]const u8) *LibExeObjStep {
...@@ -884,7 +893,7 @@ pub const Builder = struct {...@@ -884,7 +893,7 @@ pub const Builder = struct {
884893
885 fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {894 fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
886 const base_dir = switch (dir) {895 const base_dir = switch (dir) {
887 .Prefix => self.install_prefix.?,896 .Prefix => self.install_path,
888 .Bin => self.exe_dir.?,897 .Bin => self.exe_dir.?,
889 .Lib => self.lib_dir.?,898 .Lib => self.lib_dir.?,
890 };899 };
std/debug.zig+1-1
...@@ -2353,7 +2353,7 @@ pub fn attachSegfaultHandler() void {...@@ -2353,7 +2353,7 @@ pub fn attachSegfaultHandler() void {
2353fn resetSegfaultHandler() void {2353fn resetSegfaultHandler() void {
2354 if (windows.is_the_target) {2354 if (windows.is_the_target) {
2355 if (windows_segfault_handle) |handle| {2355 if (windows_segfault_handle) |handle| {
2356 assert(windows.kernel32.RemoveVectoredExceptionHandler() != 0);2356 assert(windows.kernel32.RemoveVectoredExceptionHandler(handle) != 0);
2357 windows_segfault_handle = null;2357 windows_segfault_handle = null;
2358 }2358 }
2359 return;2359 return;
std/special/compiler_rt.zig+3
...@@ -127,6 +127,7 @@ comptime {...@@ -127,6 +127,7 @@ comptime {
127 @export("__udivmoddi4", @import("compiler_rt/udivmoddi4.zig").__udivmoddi4, linkage);127 @export("__udivmoddi4", @import("compiler_rt/udivmoddi4.zig").__udivmoddi4, linkage);
128 @export("__popcountdi2", @import("compiler_rt/popcountdi2.zig").__popcountdi2, linkage);128 @export("__popcountdi2", @import("compiler_rt/popcountdi2.zig").__popcountdi2, linkage);
129129
130 @export("__muldi3", @import("compiler_rt/muldi3.zig").__muldi3, linkage);
130 @export("__divmoddi4", __divmoddi4, linkage);131 @export("__divmoddi4", __divmoddi4, linkage);
131 @export("__divsi3", __divsi3, linkage);132 @export("__divsi3", __divsi3, linkage);
132 @export("__divdi3", __divdi3, linkage);133 @export("__divdi3", __divdi3, linkage);
...@@ -147,6 +148,8 @@ comptime {...@@ -147,6 +148,8 @@ comptime {
147 @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage);148 @export("__aeabi_unwind_cpp_pr1", __aeabi_unwind_cpp_pr1, linkage);
148 @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage);149 @export("__aeabi_unwind_cpp_pr2", __aeabi_unwind_cpp_pr2, linkage);
149150
151 @export("__aeabi_lmul", @import("compiler_rt/muldi3.zig").__muldi3, linkage);
152
150 @export("__aeabi_ldivmod", __aeabi_ldivmod, linkage);153 @export("__aeabi_ldivmod", __aeabi_ldivmod, linkage);
151 @export("__aeabi_uldivmod", __aeabi_uldivmod, linkage);154 @export("__aeabi_uldivmod", __aeabi_uldivmod, linkage);
152155
std/special/compiler_rt/divti3.zig-1
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const udivmod = @import("udivmod.zig").udivmod;1const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const compiler_rt = @import("../compiler_rt.zig");
43
5pub extern fn __divti3(a: i128, b: i128) i128 {4pub extern fn __divti3(a: i128, b: i128) i128 {
6 @setRuntimeSafety(builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
std/special/compiler_rt/muldi3.zig created+54
...@@ -0,0 +1,54 @@
1const builtin = @import("builtin");
2
3// Ported from
4// https://github.com/llvm/llvm-project/blob/552c2c09d354a3ad9c1c9647e0a3bb5099c31088/compiler-rt/lib/builtins/muldi3.c
5
6const dwords = extern union {
7 all: i64,
8 s: switch (builtin.endian) {
9 .Little => extern struct {
10 low: u32,
11 high: u32,
12 },
13 .Big => extern struct {
14 high: u32,
15 low: u32,
16 },
17 },
18};
19
20fn __muldsi3(a: u32, b: u32) i64 {
21 @setRuntimeSafety(builtin.is_test);
22
23 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
24 const lower_mask = (~u32(0)) >> bits_in_word_2;
25
26 var r: dwords = undefined;
27 r.s.low = (a & lower_mask) *% (b & lower_mask);
28 var t: u32 = r.s.low >> bits_in_word_2;
29 r.s.low &= lower_mask;
30 t += (a >> bits_in_word_2) *% (b & lower_mask);
31 r.s.low +%= (t & lower_mask) << bits_in_word_2;
32 r.s.high = t >> bits_in_word_2;
33 t = r.s.low >> bits_in_word_2;
34 r.s.low &= lower_mask;
35 t +%= (b >> bits_in_word_2) *% (a & lower_mask);
36 r.s.low +%= (t & lower_mask) << bits_in_word_2;
37 r.s.high +%= t >> bits_in_word_2;
38 r.s.high +%= (a >> bits_in_word_2) *% (b >> bits_in_word_2);
39 return r.all;
40}
41
42pub extern fn __muldi3(a: i64, b: i64) i64 {
43 @setRuntimeSafety(builtin.is_test);
44
45 const x = dwords{ .all = a };
46 const y = dwords{ .all = b };
47 var r = dwords{ .all = __muldsi3(x.s.low, y.s.low) };
48 r.s.high +%= x.s.high *% y.s.low +% x.s.low *% y.s.high;
49 return r.all;
50}
51
52test "import muldi3" {
53 _ = @import("muldi3_test.zig");
54}
std/special/compiler_rt/muldi3_test.zig created+51
...@@ -0,0 +1,51 @@
1const __muldi3 = @import("muldi3.zig").__muldi3;
2const testing = @import("std").testing;
3
4fn test__muldi3(a: i64, b: i64, expected: i64) void {
5 const x = __muldi3(a, b);
6 testing.expect(x == expected);
7}
8
9test "muldi3" {
10 test__muldi3(0, 0, 0);
11 test__muldi3(0, 1, 0);
12 test__muldi3(1, 0, 0);
13 test__muldi3(0, 10, 0);
14 test__muldi3(10, 0, 0);
15 test__muldi3(0, 81985529216486895, 0);
16 test__muldi3(81985529216486895, 0, 0);
17
18 test__muldi3(0, -1, 0);
19 test__muldi3(-1, 0, 0);
20 test__muldi3(0, -10, 0);
21 test__muldi3(-10, 0, 0);
22 test__muldi3(0, -81985529216486895, 0);
23 test__muldi3(-81985529216486895, 0, 0);
24
25 test__muldi3(1, 1, 1);
26 test__muldi3(1, 10, 10);
27 test__muldi3(10, 1, 10);
28 test__muldi3(1, 81985529216486895, 81985529216486895);
29 test__muldi3(81985529216486895, 1, 81985529216486895);
30
31 test__muldi3(1, -1, -1);
32 test__muldi3(1, -10, -10);
33 test__muldi3(-10, 1, -10);
34 test__muldi3(1, -81985529216486895, -81985529216486895);
35 test__muldi3(-81985529216486895, 1, -81985529216486895);
36
37 test__muldi3(3037000499, 3037000499, 9223372030926249001);
38 test__muldi3(-3037000499, 3037000499, -9223372030926249001);
39 test__muldi3(3037000499, -3037000499, -9223372030926249001);
40 test__muldi3(-3037000499, -3037000499, 9223372030926249001);
41
42 test__muldi3(4398046511103, 2097152, 9223372036852678656);
43 test__muldi3(-4398046511103, 2097152, -9223372036852678656);
44 test__muldi3(4398046511103, -2097152, -9223372036852678656);
45 test__muldi3(-4398046511103, -2097152, 9223372036852678656);
46
47 test__muldi3(2097152, 4398046511103, 9223372036852678656);
48 test__muldi3(-2097152, 4398046511103, -9223372036852678656);
49 test__muldi3(2097152, -4398046511103, -9223372036852678656);
50 test__muldi3(-2097152, -4398046511103, 9223372036852678656);
51}
test/tests.zig+2-1
...@@ -170,6 +170,7 @@ pub fn addPkgTests(...@@ -170,6 +170,7 @@ pub fn addPkgTests(
170 name: []const u8,170 name: []const u8,
171 desc: []const u8,171 desc: []const u8,
172 modes: []const Mode,172 modes: []const Mode,
173 single_threaded_list: []const bool,
173 skip_non_native: bool,174 skip_non_native: bool,
174) *build.Step {175) *build.Step {
175 const step = b.step(b.fmt("test-{}", name), desc);176 const step = b.step(b.fmt("test-{}", name), desc);
...@@ -179,7 +180,7 @@ pub fn addPkgTests(...@@ -179,7 +180,7 @@ pub fn addPkgTests(
179 continue;180 continue;
180 for (modes) |mode| {181 for (modes) |mode| {
181 for ([_]bool{ false, true }) |link_libc| {182 for ([_]bool{ false, true }) |link_libc| {
182 for ([_]bool{ false, true }) |single_threaded| {183 for (single_threaded_list) |single_threaded| {
183 if (link_libc and !is_native) {184 if (link_libc and !is_native) {
184 // don't assume we have a cross-compiling libc set up185 // don't assume we have a cross-compiling libc set up
185 continue;186 continue;