Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Spaces #9649

Merged
merged 41 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ccc7f99
Address spaces: addrspace(A) parsing
Snektron Sep 2, 2021
7da9fa6
Address spaces: AstGen
Snektron Aug 16, 2021
805e1bf
Address Spaces: Sema basics
Snektron Sep 2, 2021
cfbe9a6
Address spaces: Forbid addrspace and linksection for local variables
Snektron Sep 2, 2021
6023108
Address Spaces: x86 segment address spaces in builtin
Snektron Aug 19, 2021
cd9f600
Address Spaces: decl_ref, *?T => *T, and *(E!T) -> *T
Snektron Aug 20, 2021
0e6dc64
Address Spaces: Return proper address space for &x[y]
Snektron Aug 26, 2021
e182c17
Address Spaces: Disallow coercing pointers to different address spaces
Snektron Aug 26, 2021
64c328a
Address Spaces: Default align, linksection & addrspace for anon decls
Snektron Aug 26, 2021
497c0d3
Allow x.y when x is a pointer
Snektron Aug 26, 2021
538f1bb
Address Spaces: Return proper address space for &x.y
Snektron Aug 26, 2021
8672f26
Address Spaces: zig fmt + tests
Snektron Sep 2, 2021
e77fcf1
Address Spaces: Implement right address space for slicing
Snektron Aug 27, 2021
6336f08
Address Spaces: Address space on local variable test
Snektron Aug 27, 2021
7686165
Address Spaces: Pointer coercion errors tests
Snektron Aug 27, 2021
8f28c58
Address Spaces: compiles() test cases
Snektron Aug 29, 2021
2f43749
Address Spaces: Move stage 2 tests to stage2/llvm.zig
Snektron Sep 1, 2021
e09465f
Address Spaces: Chaining tests
Snektron Aug 29, 2021
ea393b2
Address Spaces: Implement in LLVM codegen
Snektron Aug 29, 2021
68fcbb5
Address Spaces: fmt a bunch of stuff
Snektron Aug 29, 2021
0492b71
Address Spaces: Smol fixup
Snektron Aug 29, 2021
7a5d0cd
Address Spaces: Render addrspace token in docgen
Snektron Aug 29, 2021
c594546
Address Spaces: Pointer and function info in @Type
Snektron Aug 30, 2021
7956eee
Address Spaces: Adapt compile error test cases to @Type with address …
Snektron Aug 30, 2021
90a945b
Address Spaces: Split out stage2 address llvm tests to individual cases
Snektron Sep 1, 2021
13b9171
Address Spaces: basic system to check for validity.
Snektron Sep 1, 2021
e4ac063
Address Spaces: Restructure llvmAddressSpace a bit
Snektron Sep 3, 2021
5a142df
Address Spaces: LLVM F segment address space test
Snektron Sep 3, 2021
95e83af
Address Spaces: Yeet address space on function prototypes
Snektron Sep 5, 2021
619260d
Address Spaces: Fix comments in Ast.zig
Snektron Sep 20, 2021
1f61076
I'm working on a WebAssembly interpreter in zig. WebAssembly uses LEB…
malcolmstill Sep 19, 2021
cfd5b81
Fix compiler builds with tracy on the mingw target
SpexGuy Sep 16, 2021
db181b1
Update `hash` & `crypto` benchmarks run comment (#9790)
alichraghi Sep 20, 2021
b3ae69d
langref: define the inferred error set syntax more explicitly
roryokane Sep 12, 2021
806aeab
adding support for UTF-8 output
HugoFlorentino Sep 11, 2021
5dc2517
Fix compile error in WindowsCondition.wait()
PhaseMage Sep 10, 2021
b9d3527
stage2: implement comptime `@atomicRmw`
andrewrk Sep 20, 2021
f3147de
stage2: extract ZIR printing code into print_zir.zig
andrewrk Sep 20, 2021
4b2d7a9
stage2: implement comptime bitwise nand
andrewrk Sep 20, 2021
abc30f7
stage2: improve handling of 0 bit types
andrewrk Sep 20, 2021
f8b914f
Merge branch 'address-space' of Snektron/zig into Snektron-address-space
andrewrk Sep 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,20 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/lib/std/zig/system.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system/x86.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/tokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/Air.zig"
"${CMAKE_SOURCE_DIR}/src/AstGen.zig"
"${CMAKE_SOURCE_DIR}/src/Cache.zig"
"${CMAKE_SOURCE_DIR}/src/Compilation.zig"
"${CMAKE_SOURCE_DIR}/src/DepTokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/Liveness.zig"
"${CMAKE_SOURCE_DIR}/src/Module.zig"
"${CMAKE_SOURCE_DIR}/src/Package.zig"
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
"${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
"${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/src/AstGen.zig"
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
"${CMAKE_SOURCE_DIR}/src/clang.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options_data.zig"
Expand All @@ -561,17 +565,15 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/codegen/x86_64.zig"
"${CMAKE_SOURCE_DIR}/src/glibc.zig"
"${CMAKE_SOURCE_DIR}/src/introspect.zig"
"${CMAKE_SOURCE_DIR}/src/Air.zig"
"${CMAKE_SOURCE_DIR}/src/libc_installation.zig"
"${CMAKE_SOURCE_DIR}/src/libcxx.zig"
"${CMAKE_SOURCE_DIR}/src/libtsan.zig"
"${CMAKE_SOURCE_DIR}/src/libunwind.zig"
"${CMAKE_SOURCE_DIR}/src/link.zig"
"${CMAKE_SOURCE_DIR}/src/link/C.zig"
"${CMAKE_SOURCE_DIR}/src/link/C/zig.h"
"${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
"${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
"${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"
"${CMAKE_SOURCE_DIR}/src/link/Plan9/aout.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Atom.zig"
Expand All @@ -582,20 +584,22 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/bind.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/commands.zig"
"${CMAKE_SOURCE_DIR}/src/link/Plan9.zig"
"${CMAKE_SOURCE_DIR}/src/link/Plan9/aout.zig"
"${CMAKE_SOURCE_DIR}/src/link/Wasm.zig"
"${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin"
"${CMAKE_SOURCE_DIR}/src/link/tapi.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/Tokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/parse.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/parse/test.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/Tokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/link/tapi/yaml.zig"
"${CMAKE_SOURCE_DIR}/src/link/C/zig.h"
"${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin"
"${CMAKE_SOURCE_DIR}/src/Liveness.zig"
"${CMAKE_SOURCE_DIR}/src/main.zig"
"${CMAKE_SOURCE_DIR}/src/mingw.zig"
"${CMAKE_SOURCE_DIR}/src/musl.zig"
"${CMAKE_SOURCE_DIR}/src/print_air.zig"
"${CMAKE_SOURCE_DIR}/src/print_env.zig"
"${CMAKE_SOURCE_DIR}/src/print_targets.zig"
"${CMAKE_SOURCE_DIR}/src/print_zir.zig"
"${CMAKE_SOURCE_DIR}/src/stage1.zig"
"${CMAKE_SOURCE_DIR}/src/target.zig"
"${CMAKE_SOURCE_DIR}/src/tracy.zig"
Expand All @@ -605,8 +609,6 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/value.zig"
"${CMAKE_SOURCE_DIR}/src/wasi_libc.zig"
"${CMAKE_SOURCE_DIR}/src/windows_sdk.zig"
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
)

if(MSVC)
Expand Down
19 changes: 18 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ pub fn build(b: *Builder) !void {
b.default_step.dependOn(&exe.step);
exe.single_threaded = single_threaded;

if (target.isWindows() and target.getAbi() == .gnu) {
// LTO is currently broken on mingw, this can be removed when it's fixed.
exe.want_lto = false;
}

const exe_options = b.addOptions();
exe.addOptions("build_options", exe_options);

Expand Down Expand Up @@ -239,12 +244,24 @@ pub fn build(b: *Builder) !void {
b.allocator,
&[_][]const u8{ tracy_path, "TracyClient.cpp" },
) catch unreachable;

// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };

exe.addIncludeDir(tracy_path);
exe.addCSourceFile(client_cpp, &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" });
exe.addCSourceFile(client_cpp, tracy_c_flags);
if (!enable_llvm) {
exe.linkSystemLibraryName("c++");
}
exe.linkLibC();

if (target.isWindows()) {
exe.linkSystemLibrary("dbghelp");
exe.linkSystemLibrary("ws2_32");
}
}

const test_filter = b.option([]const u8, "test-filter", "Skip tests that do not match filter");
Expand Down
1 change: 1 addition & 0 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ fn tokenizeAndPrintRaw(
switch (token.tag) {
.eof => break,

.keyword_addrspace,
.keyword_align,
.keyword_and,
.keyword_asm,
Expand Down
2 changes: 1 addition & 1 deletion doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -4955,7 +4955,7 @@ test "merge error sets" {
{#header_open|Inferred Error Sets#}
<p>
Because many functions in Zig return a possible error, Zig supports inferring the error set.
To infer the error set for a function, use this syntax:
To infer the error set for a function, prepend the {#syntax#}!{#endsyntax#} operator to the function’s return type, like {#syntax#}!T{#endsyntax#}:
</p>
{#code_begin|test|inferred_error_sets#}
// With an inferred error set
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Thread/Condition.zig
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub const WindowsCondition = struct {
pub fn wait(cond: *WindowsCondition, mutex: *Mutex) void {
const rc = windows.kernel32.SleepConditionVariableSRW(
&cond.cond,
&mutex.srwlock,
&mutex.impl.srwlock,
windows.INFINITE,
@as(windows.ULONG, 0),
);
Expand Down
10 changes: 10 additions & 0 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ pub const CallingConvention = enum {
SysV,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const AddressSpace = enum {
generic,
gs,
fs,
ss,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const SourceLocation = struct {
Expand Down Expand Up @@ -226,6 +235,7 @@ pub const TypeInfo = union(enum) {
is_const: bool,
is_volatile: bool,
alignment: comptime_int,
address_space: AddressSpace,
child: type,
is_allowzero: bool,

Expand Down
2 changes: 1 addition & 1 deletion lib/std/crypto/benchmark.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// zig run benchmark.zig --release-fast --zig-lib-dir ..
// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig

const std = @import("../std.zig");
const builtin = std.builtin;
Expand Down
8 changes: 4 additions & 4 deletions lib/std/crypto/blake3.zig
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ pub const Blake3 = struct {
return Blake3.init_internal(context_key_words, DERIVE_KEY_MATERIAL);
}

pub fn hash(in: []const u8, out: []u8, options: Options) void {
var hasher = Blake3.init(options);
hasher.update(in);
hasher.final(out);
pub fn hash(b: []const u8, out: []u8, options: Options) void {
var d = Blake3.init(options);
d.update(b);
d.final(out);
}

fn pushCv(self: *Blake3, cv: [8]u32) void {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/hash/benchmark.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// zig run benchmark.zig --release-fast --zig-lib-dir ..
// zig run -O ReleaseFast --zig-lib-dir ../.. benchmark.zig

const builtin = std.builtin;
const std = @import("std");
Expand Down
14 changes: 12 additions & 2 deletions lib/std/leb128.zig
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift));
const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift;
if (remaining_bits != -1) return error.Overflow;
} else {
// If we don't overflow and this is the last byte and the number being decoded
// is negative, check that the remaining bits are 1
if ((byte & 0x80 == 0) and (@bitCast(S, temp) < 0)) {
const remaining_shift = @intCast(u3, @typeInfo(U).Int.bits - @as(u16, shift));
const remaining_bits = @bitCast(i8, byte | 0x80) >> remaining_shift;
if (remaining_bits != -1) return error.Overflow;
}
}

value |= temp;
Expand Down Expand Up @@ -215,6 +223,8 @@ test "deserialize signed LEB128" {
try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x40"));
try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x40"));
try testing.expectError(error.Overflow, test_read_ileb128(i8, "\xff\x7e"));
try testing.expectError(error.Overflow, test_read_ileb128(i32, "\x80\x80\x80\x80\x08"));
try testing.expectError(error.Overflow, test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01"));

// Decode SLEB128
try testing.expect((try test_read_ileb128(i64, "\x00")) == 0);
Expand All @@ -233,8 +243,8 @@ test "deserialize signed LEB128" {
try testing.expect((try test_read_ileb128(i8, "\xff\x7f")) == -1);
try testing.expect((try test_read_ileb128(i16, "\xff\xff\x7f")) == -1);
try testing.expect((try test_read_ileb128(i32, "\xff\xff\xff\xff\x7f")) == -1);
try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x08")) == -0x80000000);
try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x01")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
try testing.expect((try test_read_ileb128(i32, "\x80\x80\x80\x80\x78")) == -0x80000000);
try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == @bitCast(i64, @intCast(u64, 0x8000000000000000)));
try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x40")) == -0x4000000000000000);
try testing.expect((try test_read_ileb128(i64, "\x80\x80\x80\x80\x80\x80\x80\x80\x80\x7f")) == -0x8000000000000000);

Expand Down
3 changes: 3 additions & 0 deletions lib/std/math/big/int.zig
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ pub const Mutable = struct {
llor(r.limbs[0..], b.limbs[0..b.limbs.len], a.limbs[0..a.limbs.len]);
r.len = b.limbs.len;
}
r.positive = a.positive or b.positive;
}

/// r = a & b
Expand All @@ -580,6 +581,7 @@ pub const Mutable = struct {
lland(r.limbs[0..], b.limbs[0..b.limbs.len], a.limbs[0..a.limbs.len]);
r.normalize(a.limbs.len);
}
r.positive = a.positive and b.positive;
}

/// r = a ^ b
Expand All @@ -594,6 +596,7 @@ pub const Mutable = struct {
llxor(r.limbs[0..], b.limbs[0..b.limbs.len], a.limbs[0..a.limbs.len]);
r.normalize(b.limbs.len);
}
r.positive = a.positive or b.positive;
}

/// rma may alias x or y.
Expand Down
2 changes: 2 additions & 0 deletions lib/std/mem.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@ fn CopyPtrAttrs(comptime source: type, comptime size: std.builtin.TypeInfo.Point
.is_volatile = info.is_volatile,
.is_allowzero = info.is_allowzero,
.alignment = info.alignment,
.address_space = info.address_space,
.child = child,
.sentinel = null,
},
Expand Down Expand Up @@ -2960,6 +2961,7 @@ fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: u29) typ
.is_volatile = info.is_volatile,
.is_allowzero = info.is_allowzero,
.alignment = new_alignment,
.address_space = info.address_space,
.child = info.child,
.sentinel = null,
},
Expand Down
3 changes: 3 additions & 0 deletions lib/std/meta.zig
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.is_const = info.is_const,
.is_volatile = info.is_volatile,
.alignment = info.alignment,
.address_space = info.address_space,
.child = @Type(.{
.Array = .{
.len = array_info.len,
Expand All @@ -254,6 +255,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.is_const = info.is_const,
.is_volatile = info.is_volatile,
.alignment = info.alignment,
.address_space = info.address_space,
.child = info.child,
.is_allowzero = info.is_allowzero,
.sentinel = sentinel_val,
Expand All @@ -271,6 +273,7 @@ pub fn Sentinel(comptime T: type, comptime sentinel_val: Elem(T)) type {
.is_const = ptr_info.is_const,
.is_volatile = ptr_info.is_volatile,
.alignment = ptr_info.alignment,
.address_space = ptr_info.address_space,
.child = ptr_info.child,
.is_allowzero = ptr_info.is_allowzero,
.sentinel = sentinel_val,
Expand Down
4 changes: 4 additions & 0 deletions lib/std/os/windows/kernel32.zig
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ pub extern "kernel32" fn GetCommandLineW() callconv(WINAPI) LPWSTR;

pub extern "kernel32" fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: *DWORD) callconv(WINAPI) BOOL;

pub extern "kernel32" fn GetConsoleOutputCP() callconv(WINAPI) UINT;

pub extern "kernel32" fn GetConsoleScreenBufferInfo(hConsoleOutput: HANDLE, lpConsoleScreenBufferInfo: *CONSOLE_SCREEN_BUFFER_INFO) callconv(WINAPI) BOOL;
pub extern "kernel32" fn FillConsoleOutputCharacterA(hConsoleOutput: HANDLE, cCharacter: CHAR, nLength: DWORD, dwWriteCoord: COORD, lpNumberOfCharsWritten: *DWORD) callconv(WINAPI) BOOL;
pub extern "kernel32" fn FillConsoleOutputCharacterW(hConsoleOutput: HANDLE, cCharacter: WCHAR, nLength: DWORD, dwWriteCoord: COORD, lpNumberOfCharsWritten: *DWORD) callconv(WINAPI) BOOL;
Expand Down Expand Up @@ -286,6 +288,8 @@ pub extern "kernel32" fn SetConsoleCtrlHandler(
Add: BOOL,
) callconv(WINAPI) BOOL;

pub extern "kernel32" fn SetConsoleOutputCP(wCodePageID: UINT) callconv(WINAPI) BOOL;

pub extern "kernel32" fn SetFileCompletionNotificationModes(
FileHandle: HANDLE,
Flags: UCHAR,
Expand Down
Loading