mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 03:42:17 +00:00
merge upstream/main
This commit is contained in:
commit
cec67721e6
59 changed files with 2542 additions and 990 deletions
|
@ -1,4 +1,5 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
const SIGUSR1: c_int = 10;
|
||||
|
||||
|
@ -18,6 +19,71 @@ pub fn setSharedBuffer(ptr: [*]u8, length: usize) callconv(.C) usize {
|
|||
return 0;
|
||||
}
|
||||
|
||||
pub fn expectFailedStart() callconv(.C) [*]u8 {
|
||||
pub fn expectFailedStartSharedBuffer() callconv(.C) [*]u8 {
|
||||
return SHARED_BUFFER.ptr;
|
||||
}
|
||||
|
||||
pub fn expectFailedStartSharedFile() callconv(.C) [*]u8 {
|
||||
// IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
||||
var name: [100]u8 = undefined;
|
||||
_ = std.fmt.bufPrint(name[0..100], "/roc_expect_buffer_{}\x00", .{roc_getppid()}) catch unreachable;
|
||||
|
||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||
const shared_fd = roc_shm_open(@ptrCast(*const i8, &name), O_RDWR | O_CREAT, 0o666);
|
||||
|
||||
const length = 4096;
|
||||
|
||||
const shared_ptr = roc_mmap(
|
||||
null,
|
||||
length,
|
||||
PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
shared_fd,
|
||||
0,
|
||||
);
|
||||
|
||||
const ptr = @ptrCast([*]u8, shared_ptr);
|
||||
|
||||
return ptr;
|
||||
} else {
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
extern fn roc_send_signal(pid: c_int, sig: c_int) c_int;
|
||||
extern fn roc_shm_open(name: *const i8, oflag: c_int, mode: c_uint) c_int;
|
||||
extern fn roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) *anyopaque;
|
||||
extern fn roc_getppid() c_int;
|
||||
|
||||
pub fn readSharedBufferEnv() callconv(.C) void {
|
||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||
|
||||
// IMPORTANT: shared memory object names must begin with / and contain no other slashes!
|
||||
var name: [100]u8 = undefined;
|
||||
_ = std.fmt.bufPrint(name[0..100], "/roc_expect_buffer_{}\x00", .{roc_getppid()}) catch unreachable;
|
||||
|
||||
const shared_fd = roc_shm_open(@ptrCast(*const i8, &name), O_RDWR | O_CREAT, 0o666);
|
||||
const length = 4096;
|
||||
|
||||
const shared_ptr = roc_mmap(
|
||||
null,
|
||||
length,
|
||||
PROT_WRITE,
|
||||
MAP_SHARED,
|
||||
shared_fd,
|
||||
0,
|
||||
);
|
||||
|
||||
const ptr = @ptrCast([*]u8, shared_ptr);
|
||||
|
||||
SHARED_BUFFER = ptr[0..length];
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expectFailedFinalize() callconv(.C) void {
|
||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||
const parent_pid = roc_getppid();
|
||||
|
||||
_ = roc_send_signal(parent_pid, SIGUSR1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,10 +169,14 @@ comptime {
|
|||
@export(utils.panic, .{ .name = "roc_builtins.utils." ++ "panic", .linkage = .Weak });
|
||||
|
||||
if (builtin.target.cpu.arch != .wasm32) {
|
||||
exportUtilsFn(expect.expectFailedStart, "expect_failed_start");
|
||||
exportUtilsFn(expect.expectFailedStartSharedBuffer, "expect_failed_start_shared_buffer");
|
||||
exportUtilsFn(expect.expectFailedStartSharedFile, "expect_failed_start_shared_file");
|
||||
exportUtilsFn(expect.expectFailedFinalize, "expect_failed_finalize");
|
||||
|
||||
// sets the buffer used for expect failures
|
||||
@export(expect.setSharedBuffer, .{ .name = "set_shared_buffer", .linkage = .Weak });
|
||||
|
||||
exportUtilsFn(expect.readSharedBufferEnv, "read_env_shared_buffer");
|
||||
}
|
||||
|
||||
if (builtin.target.cpu.arch == .aarch64) {
|
||||
|
|
|
@ -22,6 +22,24 @@ extern fn roc_panic(c_ptr: *const anyopaque, tag_id: u32) callconv(.C) void;
|
|||
// should work just like libc memcpy (we can't assume libc is present)
|
||||
extern fn roc_memcpy(dst: [*]u8, src: [*]u8, size: usize) callconv(.C) void;
|
||||
|
||||
extern fn kill(pid: c_int, sig: c_int) c_int;
|
||||
extern fn shm_open(name: *const i8, oflag: c_int, mode: c_uint) c_int;
|
||||
extern fn mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) *anyopaque;
|
||||
extern fn getppid() c_int;
|
||||
|
||||
fn testing_roc_getppid() callconv(.C) c_int {
|
||||
return getppid();
|
||||
}
|
||||
fn testing_roc_send_signal(pid: c_int, sig: c_int) callconv(.C) c_int {
|
||||
return kill(pid, sig);
|
||||
}
|
||||
fn testing_roc_shm_open(name: *const i8, oflag: c_int, mode: c_uint) callconv(.C) c_int {
|
||||
return shm_open(name, oflag, mode);
|
||||
}
|
||||
fn testing_roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) callconv(.C) *anyopaque {
|
||||
return mmap(addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
comptime {
|
||||
const builtin = @import("builtin");
|
||||
// During tests, use the testing allocators to satisfy these functions.
|
||||
|
@ -31,6 +49,13 @@ comptime {
|
|||
@export(testing_roc_dealloc, .{ .name = "roc_dealloc", .linkage = .Strong });
|
||||
@export(testing_roc_panic, .{ .name = "roc_panic", .linkage = .Strong });
|
||||
@export(testing_roc_memcpy, .{ .name = "roc_memcpy", .linkage = .Strong });
|
||||
|
||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||
@export(testing_roc_getppid, .{ .name = "roc_getppid", .linkage = .Strong });
|
||||
@export(testing_roc_mmap, .{ .name = "roc_mmap", .linkage = .Strong });
|
||||
@export(testing_roc_send_signal, .{ .name = "roc_send_signal", .linkage = .Strong });
|
||||
@export(testing_roc_shm_open, .{ .name = "roc_shm_open", .linkage = .Strong });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -215,6 +215,7 @@ fn run_command(mut command: Command, flaky_fail_counter: usize) {
|
|||
// Flaky test errors that only occur sometimes on MacOS ci server.
|
||||
if error_str.contains("FileNotFound")
|
||||
|| error_str.contains("unable to save cached ZIR code")
|
||||
|| error_str.contains("LLVM failed to emit asm")
|
||||
{
|
||||
if flaky_fail_counter == 10 {
|
||||
panic!("{} failed 10 times in a row. The following error is unlikely to be a flaky error: {}", command_str, error_str);
|
||||
|
|
|
@ -368,30 +368,26 @@ contains = \list, needle ->
|
|||
## You can use it in a pipeline:
|
||||
##
|
||||
## [2, 4, 8]
|
||||
## |> List.walk { start: 0, step: Num.add }
|
||||
## |> List.walk 0 Num.add
|
||||
##
|
||||
## This returns 14 because:
|
||||
## * `state` starts at 0 (because of `start: 0`)
|
||||
## * `state` starts at 0
|
||||
## * Each `step` runs `Num.add state elem`, and the return value becomes the new `state`.
|
||||
##
|
||||
## Here is a table of how `state` changes as [List.walk] walks over the elements
|
||||
## `[2, 4, 8]` using #Num.add as its `step` function to determine the next `state`.
|
||||
## `[2, 4, 8]` using [Num.add] as its `step` function to determine the next `state`.
|
||||
##
|
||||
## `state` | `elem` | `step state elem` (`Num.add state elem`)
|
||||
## --------+--------+-----------------------------------------
|
||||
## 0 | |
|
||||
## 0 | 2 | 2
|
||||
## 2 | 4 | 6
|
||||
## 6 | 8 | 14
|
||||
## state | elem | Num.add state elem
|
||||
## :---: | :---: | :----------------:
|
||||
## 0 | |
|
||||
## 0 | 2 | 2
|
||||
## 2 | 4 | 6
|
||||
## 6 | 8 | 14
|
||||
##
|
||||
## So `state` goes through these changes:
|
||||
## 1. `0` (because of `start: 0`)
|
||||
## 2. `1` (because of `Num.add state elem` with `state` = 0 and `elem` = 1
|
||||
## The following returns -6:
|
||||
##
|
||||
## [1, 2, 3]
|
||||
## |> List.walk { start: 0, step: Num.sub }
|
||||
##
|
||||
## This returns -6 because
|
||||
## |> List.walk 0 Num.sub
|
||||
##
|
||||
## Note that in other languages, `walk` is sometimes called `reduce`,
|
||||
## `fold`, `foldLeft`, or `foldl`.
|
||||
|
|
|
@ -404,8 +404,12 @@ pub const UTILS_INCREF: &str = "roc_builtins.utils.incref";
|
|||
pub const UTILS_DECREF: &str = "roc_builtins.utils.decref";
|
||||
pub const UTILS_DECREF_CHECK_NULL: &str = "roc_builtins.utils.decref_check_null";
|
||||
|
||||
pub const UTILS_EXPECT_FAILED_START: &str = "roc_builtins.utils.expect_failed_start";
|
||||
pub const UTILS_EXPECT_FAILED_START_SHARED_BUFFER: &str =
|
||||
"roc_builtins.utils.expect_failed_start_shared_buffer";
|
||||
pub const UTILS_EXPECT_FAILED_START_SHARED_FILE: &str =
|
||||
"roc_builtins.utils.expect_failed_start_shared_file";
|
||||
pub const UTILS_EXPECT_FAILED_FINALIZE: &str = "roc_builtins.utils.expect_failed_finalize";
|
||||
pub const UTILS_EXPECT_READ_ENV_SHARED_BUFFER: &str = "roc_builtins.utils.read_env_shared_buffer";
|
||||
|
||||
pub const UTILS_LONGJMP: &str = "longjmp";
|
||||
pub const UTILS_SETJMP: &str = "setjmp";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue