Skip to content

run AstGen even when using the stage1 backend #9191

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

Merged
merged 15 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries
set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")
set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread")
set(ZIG_OMIT_STAGE2 off CACHE BOOL "omit the stage2 backend from stage1")
set(ZIG_ENABLE_LOGGING off CACHE BOOL "enable logging")

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(ZIG_ENABLE_LOGGING ON CACHE BOOL "enable logging")
else()
set(ZIG_ENABLE_LOGGING OFF CACHE BOOL "enable logging")
endif()

if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
set(ZIG_USE_LLVM_CONFIG ON CACHE BOOL "use llvm-config to find LLVM libraries")
Expand Down
4 changes: 2 additions & 2 deletions ci/azure/linux_script
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ unset CXX

make $JOBS install

# Look for formatting errors and AST errors.
# Look for non-conforming code formatting.
# Formatting errors can be fixed by running `zig fmt` on the files printed here.
release/bin/zig fmt --check --ast-check ..
release/bin/zig fmt --check ..

# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
Expand Down
78 changes: 54 additions & 24 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ test "thread local storage" {
thread2.wait();
}

fn testTls(context: void) void {
fn testTls(_: void) void {
assert(x == 1234);
x += 1;
assert(x == 1235);
Expand Down Expand Up @@ -2502,6 +2502,8 @@ test "struct namespaced variable" {

// you can still instantiate an empty struct
const does_nothing = Empty {};

_ = does_nothing;
}

// struct field order is determined by the compiler for optimal performance.
Expand Down Expand Up @@ -3026,11 +3028,12 @@ const Foo = enum { a, b, c };
export fn entry(foo: Foo) void { }
{#code_end#}
<p>
For a C-ABI-compatible enum, use {#syntax#}extern enum{#endsyntax#}:
For a C-ABI-compatible enum, provide an explicit tag type to
the enum:
</p>
{#code_begin|obj#}
const Foo = extern enum { a, b, c };
export fn entry(foo: Foo) void { }
const Foo = enum(c_int) { a, b, c };
export fn entry(foo: Foo) void { _ = foo; }
{#code_end#}
{#header_close#}

Expand Down Expand Up @@ -3392,9 +3395,11 @@ test "inside test block" {
test "separate scopes" {
{
const pi = 3.14;
_ = pi;
}
{
var pi: bool = true;
_ = pi;
}
}
{#code_end#}
Expand Down Expand Up @@ -3432,7 +3437,7 @@ test "switch simple" {
// Switching on arbitrary expressions is allowed as long as the
// expression is known at compile-time.
zz => zz,
comptime blk: {
blk: {
const d: u32 = 5;
const e: u32 = 100;
break :blk d + e;
Expand Down Expand Up @@ -3831,7 +3836,7 @@ test "for basics" {
// To access the index of iteration, specify a second capture value.
// This is zero-indexed.
var sum2: i32 = 0;
for (items) |value, i| {
for (items) |_, i| {
try expect(@TypeOf(i) == usize);
sum2 += @intCast(i32, i);
}
Expand Down Expand Up @@ -3984,7 +3989,7 @@ test "if optional" {
}

const b: ?u32 = null;
if (b) |value| {
if (b) |_| {
unreachable;
} else {
try expect(true);
Expand Down Expand Up @@ -4021,11 +4026,13 @@ test "if error union" {
if (a) |value| {
try expect(value == 0);
} else |err| {
_ = err;
unreachable;
}

const b: anyerror!u32 = error.BadValue;
if (b) |value| {
_ = value;
unreachable;
} else |err| {
try expect(err == error.BadValue);
Expand All @@ -4045,13 +4052,13 @@ test "if error union" {
var c: anyerror!u32 = 3;
if (c) |*value| {
value.* = 9;
} else |err| {
} else |_| {
unreachable;
}

if (c) |value| {
try expect(value == 9);
} else |err| {
} else |_| {
unreachable;
}
}
Expand All @@ -4064,18 +4071,20 @@ test "if error union with optional" {
if (a) |optional_value| {
try expect(optional_value.? == 0);
} else |err| {
_ = err;
unreachable;
}

const b: anyerror!?u32 = null;
if (b) |optional_value| {
try expect(optional_value == null);
} else |err| {
} else |_| {
unreachable;
}

const c: anyerror!?u32 = error.BadValue;
if (c) |optional_value| {
_ = optional_value;
unreachable;
} else |err| {
try expect(err == error.BadValue);
Expand All @@ -4087,13 +4096,13 @@ test "if error union with optional" {
if (optional_value.*) |*value| {
value.* = 9;
}
} else |err| {
} else |_| {
unreachable;
}

if (d) |optional_value| {
try expect(optional_value.? == 9);
} else |err| {
} else |_| {
unreachable;
}
}
Expand Down Expand Up @@ -4246,6 +4255,7 @@ test "type of unreachable" {
{#code_begin|test#}
fn foo(condition: bool, b: u32) void {
const a = if (condition) b else return;
_ = a;
@panic("do something with a");
}
test "noreturn" {
Expand Down Expand Up @@ -4574,7 +4584,7 @@ test "parse u64" {
{#code_begin|syntax#}
fn doAThing(str: []u8) void {
const number = parseU64(str, 10) catch 13;
// ...
_ = number; // ...
}
{#code_end#}
<p>
Expand All @@ -4589,7 +4599,7 @@ fn doAThing(str: []u8) void {
{#code_begin|syntax#}
fn doAThing(str: []u8) !void {
const number = parseU64(str, 10) catch |err| return err;
// ...
_ = number; // ...
}
{#code_end#}
<p>
Expand All @@ -4598,7 +4608,7 @@ fn doAThing(str: []u8) !void {
{#code_begin|syntax#}
fn doAThing(str: []u8) !void {
const number = try parseU64(str, 10);
// ...
_ = number; // ...
}
{#code_end#}
<p>
Expand Down Expand Up @@ -5022,7 +5032,7 @@ extern fn malloc(size: size_t) ?*u8;

fn doAThing() ?*Foo {
const ptr = malloc(1234) orelse return null;
// ...
_ = ptr; // ...
}
{#code_end#}
<p>
Expand Down Expand Up @@ -5135,18 +5145,22 @@ test "optional pointers" {
test "type coercion - variable declaration" {
var a: u8 = 1;
var b: u16 = a;
_ = b;
}

test "type coercion - function call" {
var a: u8 = 1;
foo(a);
}

fn foo(b: u16) void {}
fn foo(b: u16) void {
_ = b;
}

test "type coercion - @as builtin" {
var a: u8 = 1;
var b = @as(u16, a);
_ = b;
}
{#code_end#}
<p>
Expand Down Expand Up @@ -5174,7 +5188,7 @@ test "type coercion - const qualification" {
foo(b);
}

fn foo(a: *const i32) void {}
fn foo(_: *const i32) void {}
{#code_end#}
<p>
In addition, pointers coerce to const optional pointers:
Expand Down Expand Up @@ -5424,7 +5438,7 @@ test "coercion between unions and enums" {
test "coercion of zero bit types" {
var x: void = {};
var y: *void = x;
//var z: void = y; // TODO
_ = y;
}
{#code_end#}
{#header_close#}
Expand Down Expand Up @@ -6569,6 +6583,7 @@ var x: i32 = 1;
test "suspend with no resume" {
var frame = async func();
try expect(x == 2);
_ = frame;
}

fn func() void {
Expand Down Expand Up @@ -6800,6 +6815,7 @@ fn amain() !void {

var global_download_frame: anyframe = undefined;
fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
_ = url; // this is just an example, we don't actually do it!
const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");
errdefer allocator.free(result);
suspend {
Expand All @@ -6811,6 +6827,7 @@ fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {

var global_file_frame: anyframe = undefined;
fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
_ = filename; // this is just an example, we don't actually do it!
const result = try std.mem.dupe(allocator, u8, "this is the file contents");
errdefer allocator.free(result);
suspend {
Expand Down Expand Up @@ -6869,13 +6886,15 @@ fn amain() !void {
}

fn fetchUrl(allocator: *Allocator, url: []const u8) ![]u8 {
_ = url; // this is just an example, we don't actually do it!
const result = try std.mem.dupe(allocator, u8, "this is the downloaded url contents");
errdefer allocator.free(result);
std.debug.print("fetchUrl returning\n", .{});
return result;
}

fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
_ = filename; // this is just an example, we don't actually do it!
const result = try std.mem.dupe(allocator, u8, "this is the file contents");
errdefer allocator.free(result);
std.debug.print("readFile returning\n", .{});
Expand Down Expand Up @@ -8584,6 +8603,7 @@ fn List(comptime T: type) type {
test "integer cast panic" {
var a: u16 = 0xabcd;
var b: u8 = @intCast(u8, a);
_ = b;
}
{#code_end#}
<p>
Expand Down Expand Up @@ -8839,6 +8859,7 @@ comptime {
{#code_begin|exe_err#}
pub fn main() void {
var x = foo("hello");
_ = x;
}

fn foo(x: []const u8) u8 {
Expand Down Expand Up @@ -9107,6 +9128,7 @@ pub fn main() void {
comptime {
const optional_number: ?i32 = null;
const number = optional_number.?;
_ = number;
}
{#code_end#}
<p>At runtime:</p>
Expand Down Expand Up @@ -9140,6 +9162,7 @@ pub fn main() void {
{#code_begin|test_err|caught unexpected error 'UnableToReturnNumber'#}
comptime {
const number = getNumberOrFail() catch unreachable;
_ = number;
}

fn getNumberOrFail() !i32 {
Expand Down Expand Up @@ -9187,6 +9210,7 @@ comptime {
const err = error.AnError;
const number = @errorToInt(err) + 10;
const invalid_err = @intToError(number);
_ = invalid_err;
}
{#code_end#}
<p>At runtime:</p>
Expand All @@ -9197,7 +9221,7 @@ pub fn main() void {
var err = error.AnError;
var number = @errorToInt(err) + 500;
var invalid_err = @intToError(number);
std.debug.print("value: {}\n", .{number});
std.debug.print("value: {}\n", .{invalid_err});
}
{#code_end#}
{#header_close#}
Expand All @@ -9212,6 +9236,7 @@ const Foo = enum {
comptime {
const a: u2 = 3;
const b = @intToEnum(Foo, a);
_ = b;
}
{#code_end#}
<p>At runtime:</p>
Expand Down Expand Up @@ -9396,6 +9421,7 @@ comptime {
pub fn main() void {
var opt_ptr: ?*i32 = null;
var ptr = @ptrCast(*i32, opt_ptr);
_ = ptr;
}
{#code_end#}
{#header_close#}
Expand Down Expand Up @@ -9523,15 +9549,19 @@ pub fn main() !void {
This is why it is an error to pass a string literal to a mutable slice, like this:
</p>
{#code_begin|test_err|expected type '[]u8'#}
fn foo(s: []u8) void {}
fn foo(s: []u8) void {
_ = s;
}

test "string literal to mutable slice" {
foo("hello");
}
{#code_end#}
<p>However if you make the slice constant, then it works:</p>
{#code_begin|test|strlit#}
fn foo(s: []const u8) void {}
fn foo(s: []const u8) void {
_ = s;
}

test "string literal to constant slice" {
foo("hello");
Expand Down Expand Up @@ -10476,7 +10506,7 @@ coding style.
</p>
{#header_close#}
{#header_open|Examples#}
{#code_begin|syntax#}
<pre>{#syntax#}
const namespace_name = @import("dir_name/file_name.zig");
const TypeName = @import("dir_name/TypeName.zig");
var global_var: i32 = undefined;
Expand Down Expand Up @@ -10520,7 +10550,7 @@ const XmlParser = struct {

// The initials BE (Big Endian) are just another word in Zig identifier names.
fn readU32Be() u32 {}
{#code_end#}
{#endsyntax#}</pre>
<p>
See the Zig Standard Library for more examples.
</p>
Expand Down
Loading