Skip to content
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
2 changes: 0 additions & 2 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,6 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
.Keyword_for,
.Keyword_if,
.Keyword_inline,
.Keyword_nakedcc,
.Keyword_noalias,
.Keyword_noinline,
.Keyword_nosuspend,
Expand All @@ -813,7 +812,6 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
.Keyword_return,
.Keyword_linksection,
.Keyword_callconv,
.Keyword_stdcallcc,
.Keyword_struct,
.Keyword_suspend,
.Keyword_switch,
Expand Down
11 changes: 3 additions & 8 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -6713,7 +6713,7 @@ const assert = std.debug.assert;
test "async fn pointer in a struct field" {
var data: i32 = 1;
const Foo = struct {
bar: async fn (*i32) void,
bar: fn (*i32) callconv(.Async) void,
};
var foo = Foo{ .bar = func };
var bytes: [64]u8 align(@alignOf(@Frame(func))) = undefined;
Expand All @@ -6723,7 +6723,7 @@ test "async fn pointer in a struct field" {
assert(data == 4);
}

async fn func(y: *i32) void {
fn func(y: *i32) void {
defer y.* += 2;
y.* += 1;
suspend;
Expand Down Expand Up @@ -10088,7 +10088,7 @@ TopLevelDecl
/ (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl
/ KEYWORD_usingnamespace Expr SEMICOLON

FnProto <- FnCC? KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_var / TypeExpr)
FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_var / TypeExpr)

VarDecl <- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? LinkSection? (EQUAL Expr)? SEMICOLON

Expand Down Expand Up @@ -10255,11 +10255,6 @@ WhileContinueExpr <- COLON LPAREN AssignExpr RPAREN

LinkSection <- KEYWORD_linksection LPAREN Expr RPAREN

# Fn specific
FnCC
<- KEYWORD_extern
/ KEYWORD_async

ParamDecl <- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType

ParamType
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
pub extern "c" fn utimensat(dirfd: fd_t, pathname: [*:0]const u8, times: *[2]timespec, flags: u32) c_int;
pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;

pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int;
pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: fn (?*c_void) callconv(.C) ?*c_void, noalias arg: ?*c_void) c_int;
pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c/dragonfly.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;

pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;

pub const pthread_mutex_t = extern struct {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c/freebsd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub extern "c" fn sendfile(
flags: u32,
) c_int;

pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;

pub const pthread_mutex_t = extern struct {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub extern "c" fn inotify_add_watch(fd: fd_t, pathname: [*]const u8, mask: u32)
/// See std.elf for constants for this
pub extern "c" fn getauxval(__type: c_ulong) c_ulong;

pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;

pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c/netbsd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ usingnamespace std.c;
extern "c" fn __errno() *c_int;
pub const _errno = __errno;

pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;

pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
Expand Down
11 changes: 4 additions & 7 deletions lib/std/event/channel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn Channel(comptime T: type) type {

/// await this function to get an item from the channel. If the buffer is empty, the frame will
/// complete when the next item is put in the channel.
pub async fn get(self: *SelfChannel) T {
pub fn get(self: *SelfChannel) callconv(.Async) T {
// TODO https://github.com/ziglang/zig/issues/2765
var result: T = undefined;
var my_tick_node = Loop.NextTickNode.init(@frame());
Expand Down Expand Up @@ -305,8 +305,7 @@ test "std.event.Channel wraparound" {
channel.put(7);
testing.expectEqual(@as(i32, 7), channel.get());
}

async fn testChannelGetter(channel: *Channel(i32)) void {
fn testChannelGetter(channel: *Channel(i32)) callconv(.Async) void {
const value1 = channel.get();
testing.expect(value1 == 1234);

Expand All @@ -321,12 +320,10 @@ async fn testChannelGetter(channel: *Channel(i32)) void {
testing.expect(value4.? == 4444);
await last_put;
}

async fn testChannelPutter(channel: *Channel(i32)) void {
fn testChannelPutter(channel: *Channel(i32)) callconv(.Async) void {
channel.put(1234);
channel.put(4567);
}

async fn testPut(channel: *Channel(i32), value: i32) void {
fn testPut(channel: *Channel(i32), value: i32) callconv(.Async) void {
channel.put(value);
}
4 changes: 2 additions & 2 deletions lib/std/event/future.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn Future(comptime T: type) type {
/// Obtain the value. If it's not available, wait until it becomes
/// available.
/// Thread-safe.
pub async fn get(self: *Self) *T {
pub fn get(self: *Self) callconv(.Async) *T {
if (@atomicLoad(Available, &self.available, .SeqCst) == .Finished) {
return &self.data;
}
Expand All @@ -59,7 +59,7 @@ pub fn Future(comptime T: type) type {
/// should start working on the data.
/// It's not required to call start() before resolve() but it can be useful since
/// this method is thread-safe.
pub async fn start(self: *Self) ?*T {
pub fn start(self: *Self) callconv(.Async) ?*T {
const state = @cmpxchgStrong(Available, &self.available, .NotStarted, .Started, .SeqCst, .SeqCst) orelse return null;
switch (state) {
.Started => {
Expand Down
16 changes: 6 additions & 10 deletions lib/std/event/group.zig
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn Group(comptime ReturnType: type) type {
/// Wait for all the calls and promises of the group to complete.
/// Thread-safe.
/// Safe to call any number of times.
pub async fn wait(self: *Self) ReturnType {
pub fn wait(self: *Self) callconv(.Async) ReturnType {
const held = self.lock.acquire();
defer held.release();

Expand Down Expand Up @@ -127,8 +127,7 @@ test "std.event.Group" {

const handle = async testGroup(std.heap.page_allocator);
}

async fn testGroup(allocator: *Allocator) void {
fn testGroup(allocator: *Allocator) callconv(.Async) void {
var count: usize = 0;
var group = Group(void).init(allocator);
var sleep_a_little_frame = async sleepALittle(&count);
Expand All @@ -145,20 +144,17 @@ async fn testGroup(allocator: *Allocator) void {
another.add(&something_that_fails_frame) catch @panic("memory");
testing.expectError(error.ItBroke, another.wait());
}

async fn sleepALittle(count: *usize) void {
fn sleepALittle(count: *usize) callconv(.Async) void {
std.time.sleep(1 * std.time.millisecond);
_ = @atomicRmw(usize, count, .Add, 1, .SeqCst);
}

async fn increaseByTen(count: *usize) void {
fn increaseByTen(count: *usize) callconv(.Async) void {
var i: usize = 0;
while (i < 10) : (i += 1) {
_ = @atomicRmw(usize, count, .Add, 1, .SeqCst);
}
}

async fn doSomethingThatFails() anyerror!void {}
async fn somethingElse() anyerror!void {
fn doSomethingThatFails() callconv(.Async) anyerror!void {}
fn somethingElse() callconv(.Async) anyerror!void {
return error.ItBroke;
}
8 changes: 3 additions & 5 deletions lib/std/event/lock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub const Lock = struct {
while (self.queue.get()) |node| resume node.data;
}

pub async fn acquire(self: *Lock) Held {
pub fn acquire(self: *Lock) callconv(.Async) Held {
var my_tick_node = Loop.NextTickNode.init(@frame());

errdefer _ = self.queue.remove(&my_tick_node); // TODO test canceling an acquire
Expand Down Expand Up @@ -134,8 +134,7 @@ test "std.event.Lock" {
const expected_result = [1]i32{3 * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
testing.expectEqualSlices(i32, &expected_result, &shared_test_data);
}

async fn testLock(lock: *Lock) void {
fn testLock(lock: *Lock) callconv(.Async) void {
var handle1 = async lockRunner(lock);
var tick_node1 = Loop.NextTickNode{
.prev = undefined,
Expand Down Expand Up @@ -167,8 +166,7 @@ async fn testLock(lock: *Lock) void {

var shared_test_data = [1]i32{0} ** 10;
var shared_test_index: usize = 0;

async fn lockRunner(lock: *Lock) void {
fn lockRunner(lock: *Lock) callconv(.Async) void {
suspend; // resumed by onNextTick

var i: usize = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/event/locked.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn Locked(comptime T: type) type {
self.lock.deinit();
}

pub async fn acquire(self: *Self) HeldLock {
pub fn acquire(self: *Self) callconv(.Async) HeldLock {
return HeldLock{
// TODO guaranteed allocation elision
.held = self.lock.acquire(),
Expand Down
2 changes: 1 addition & 1 deletion lib/std/event/loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ pub const Loop = struct {
}
}

pub async fn bsdWaitKev(self: *Loop, ident: usize, filter: i16, fflags: u32) void {
pub fn bsdWaitKev(self: *Loop, ident: usize, filter: i16, fflags: u32) callconv(.Async) void {
var resume_node = ResumeNode.Basic{
.base = ResumeNode{
.id = ResumeNode.Id.Basic,
Expand Down
13 changes: 5 additions & 8 deletions lib/std/event/rwlock.zig
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub const RwLock = struct {
while (self.reader_queue.get()) |node| resume node.data;
}

pub async fn acquireRead(self: *RwLock) HeldRead {
pub fn acquireRead(self: *RwLock) callconv(.Async) HeldRead {
_ = @atomicRmw(usize, &self.reader_lock_count, .Add, 1, .SeqCst);

suspend {
Expand Down Expand Up @@ -130,7 +130,7 @@ pub const RwLock = struct {
return HeldRead{ .lock = self };
}

pub async fn acquireWrite(self: *RwLock) HeldWrite {
pub fn acquireWrite(self: *RwLock) callconv(.Async) HeldWrite {
suspend {
var my_tick_node = Loop.NextTickNode{
.data = @frame(),
Expand Down Expand Up @@ -225,8 +225,7 @@ test "std.event.RwLock" {
const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
testing.expectEqualSlices(i32, expected_result, shared_test_data);
}

async fn testLock(allocator: *Allocator, lock: *RwLock) void {
fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void {
var read_nodes: [100]Loop.NextTickNode = undefined;
for (read_nodes) |*read_node| {
const frame = allocator.create(@Frame(readRunner)) catch @panic("memory");
Expand Down Expand Up @@ -259,8 +258,7 @@ const shared_it_count = 10;
var shared_test_data = [1]i32{0} ** 10;
var shared_test_index: usize = 0;
var shared_count: usize = 0;

async fn writeRunner(lock: *RwLock) void {
fn writeRunner(lock: *RwLock) callconv(.Async) void {
suspend; // resumed by onNextTick

var i: usize = 0;
Expand All @@ -277,8 +275,7 @@ async fn writeRunner(lock: *RwLock) void {
shared_test_index = 0;
}
}

async fn readRunner(lock: *RwLock) void {
fn readRunner(lock: *RwLock) callconv(.Async) void {
suspend; // resumed by onNextTick
std.time.sleep(1);

Expand Down
4 changes: 2 additions & 2 deletions lib/std/event/rwlocked.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ pub fn RwLocked(comptime T: type) type {
self.lock.deinit();
}

pub async fn acquireRead(self: *Self) HeldReadLock {
pub fn acquireRead(self: *Self) callconv(.Async) HeldReadLock {
return HeldReadLock{
.held = self.lock.acquireRead(),
.value = &self.locked_data,
};
}

pub async fn acquireWrite(self: *Self) HeldWriteLock {
pub fn acquireWrite(self: *Self) callconv(.Async) HeldWriteLock {
return HeldWriteLock{
.held = self.lock.acquireWrite(),
.value = &self.locked_data,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/os/bits/darwin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub const empty_sigset = sigset_t(0);

/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
pub const Sigaction = extern struct {
handler: extern fn (c_int) void,
handler: fn (c_int) callconv(.C) void,
sa_mask: sigset_t,
sa_flags: c_int,
};
Expand Down
12 changes: 6 additions & 6 deletions lib/std/os/bits/dragonfly.zig
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,9 @@ pub const S_IFSOCK = 49152;
pub const S_IFWHT = 57344;
pub const S_IFMT = 61440;

pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);
pub const BADSIG = SIG_ERR;
pub const SIG_BLOCK = 1;
pub const SIG_UNBLOCK = 2;
Expand Down Expand Up @@ -519,13 +519,13 @@ pub const sigset_t = extern struct {
pub const sig_atomic_t = c_int;
pub const Sigaction = extern struct {
__sigaction_u: extern union {
__sa_handler: ?extern fn (c_int) void,
__sa_sigaction: ?extern fn (c_int, [*c]siginfo_t, ?*c_void) void,
__sa_handler: ?fn (c_int) callconv(.C) void,
__sa_sigaction: ?fn (c_int, [*c]siginfo_t, ?*c_void) callconv(.C) void,
},
sa_flags: c_int,
sa_mask: sigset_t,
};
pub const sig_t = [*c]extern fn (c_int) void;
pub const sig_t = [*c]fn (c_int) callconv(.C) void;

pub const sigvec = extern struct {
sv_handler: [*c]__sighandler_t,
Expand Down
10 changes: 5 additions & 5 deletions lib/std/os/bits/freebsd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,16 @@ pub const winsize = extern struct {

const NSIG = 32;

pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);

/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
/// signal handler
__sigaction_u: extern union {
__sa_handler: extern fn (i32) void,
__sa_sigaction: extern fn (i32, *__siginfo, usize) void,
__sa_handler: fn (i32) callconv(.C) void,
__sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void,
},

/// see signal options
Expand Down
10 changes: 5 additions & 5 deletions lib/std/os/bits/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -813,15 +813,15 @@ pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffff
pub const k_sigaction = if (is_mips)
extern struct {
flags: usize,
sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
sigaction: ?fn (i32, *siginfo_t, ?*c_void) callconv(.C) void,
mask: [4]u32,
restorer: extern fn () void,
restorer: fn () callconv(.C) void,
}
else
extern struct {
sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
sigaction: ?fn (i32, *siginfo_t, ?*c_void) callconv(.C) void,
flags: usize,
restorer: extern fn () void,
restorer: fn () callconv(.C) void,
mask: [2]u32,
};

Expand All @@ -831,7 +831,7 @@ pub const Sigaction = extern struct {
sigaction: ?sigaction_fn,
mask: sigset_t,
flags: u32,
restorer: ?extern fn () void = null,
restorer: ?fn () callconv(.C) void = null,
};

pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
Expand Down
Loading