From 3352ea423cab0978adccef0bba06b9552f7cc045 Mon Sep 17 00:00:00 2001 From: Matheus Catarino Date: Wed, 10 Jul 2024 15:02:41 -0300 Subject: [PATCH] druntime + phobos updated to v2.109.1 --- build.zig | 51 ++++++++++-------- build.zig.zon | 4 +- .../src/core/internal/backtrace/libunwind.d | 54 ++++++++++--------- druntime/src/core/internal/backtrace/unwind.d | 43 ++++++--------- druntime/src/core/runtime.d | 39 +++++--------- druntime/src/core/sys/posix/sys/statvfs.d | 50 +++++++++++++++++ phobos/std/algorithm/searching.d | 15 ++++++ phobos/std/typecons.d | 5 +- 8 files changed, 160 insertions(+), 101 deletions(-) diff --git a/build.zig b/build.zig index aeeb578..3ba054e 100644 --- a/build.zig +++ b/build.zig @@ -34,7 +34,10 @@ pub fn build(b: *std.Build) !void { fn buildRuntime(b: *std.Build, options: buildOptions) !void { const source = switch (options.target.result.os.tag) { - .windows => runtime_src ++ &[_][]const u8{"druntime/src/ldc/eh_msvc.d"}, + .windows => runtime_src ++ &[_][]const u8{ + "druntime/src/ldc/eh_msvc.d", + "druntime/src/ldc/msvc.c", + }, else => runtime_src, }; @@ -43,15 +46,8 @@ fn buildRuntime(b: *std.Build, options: buildOptions) !void { .target = options.target, .optimize = options.optimize, }); - complementary.addIncludePath(b.path("druntime/src")); // importc.h complementary.addAssemblyFile(b.path("druntime/src/core/threadasm.S")); complementary.addAssemblyFile(b.path("druntime/src/ldc/eh_asm.S")); - if (options.target.result.abi == .msvc) { - complementary.addCSourceFile(.{ - .file = b.path("druntime/src/ldc/msvc.c"), - }); - complementary.linkLibC(); - } if (options.target.result.cpu.arch.isAARCH64()) { complementary.addCSourceFile(.{ .file = b.path("druntime/src/ldc/arm_unwind.c"), @@ -72,22 +68,24 @@ fn buildRuntime(b: *std.Build, options: buildOptions) !void { }; const tagLabel = switch (options.optimize) { - .Debug => "debug", - else => "release", + .Debug => "-debug", + else => "", }; const linkMode = switch (options.linkage) { - .static => "static", - .dynamic => "shared", + .static => "-static", + .dynamic => "-shared", }; try buildD(b, .{ - .name = b.fmt("druntime-ldc-{s}-{s}", .{ linkMode, tagLabel }), + .name = b.fmt("druntime-ldc{s}{s}", .{ + tagLabel, + linkMode, + }), .kind = .lib, .linkage = options.linkage, .target = options.target, .optimize = options.optimize, .sources = source, .dflags = &.{ - "-Idruntime/src", "-w", "-de", "-preview=dip1000", @@ -97,6 +95,12 @@ fn buildRuntime(b: *std.Build, options: buildOptions) !void { "-defaultlib=", "-debuglib=", }, + .importPaths = &.{ + "druntime/src", + }, + .cIncludePaths = &.{ + "druntime/src", // importc header + }, .versions = versions_config, .artifact = complementary, .use_zigcc = true, @@ -111,23 +115,24 @@ fn buildD(b: *std.Build, options: ldc2.DCompileStep) !void { fn buildPhobos(b: *std.Build, options: buildOptions) !void { const tagLabel = switch (options.optimize) { - .Debug => "debug", - else => "release", + .Debug => "-debug", + else => "", }; const linkMode = switch (options.linkage) { - .static => "static", - .dynamic => "shared", + .static => "-static", + .dynamic => "-shared", }; try buildD(b, .{ - .name = b.fmt("phobos2-ldc-{s}-{s}", .{ linkMode, tagLabel }), + .name = b.fmt("phobos2-ldc{s}{s}", .{ + tagLabel, + linkMode, + }), .kind = .lib, .linkage = options.linkage, .target = options.target, .optimize = options.optimize, .sources = std_src, .dflags = &.{ - "-Iphobos", - "-Idruntime/src", "-w", "-conf=", "-defaultlib=", @@ -138,6 +143,10 @@ fn buildPhobos(b: *std.Build, options: buildOptions) !void { "-preview=fieldwise", "-lowmem", }, + .importPaths = &.{ + "phobos", + "druntime/src", + }, .artifact = buildZlib(b, .{ .target = options.target, .optimize = options.optimize, diff --git a/build.zig.zon b/build.zig.zon index 7a4fbe4..d5c8a25 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,8 +3,8 @@ .version = "1.109.0", .dependencies = .{ .abs = .{ - .url = "git+https://github.com/kassane/anotherBuildStep#b6eee7061021b491f2a31b40ff1fc7c24efc606e", - .hash = "122097056a0f4ed6804c89c145063a120b1687ea316de8a427f6c9ed173acd9b7b2f", + .url = "git+https://github.com/kassane/anotherBuildStep#449e179e966ba95b8a2308a9982cde490b57b3d3", + .hash = "12209e13ee461f2636956b46c663b17305a990338d02a8a70182043ff3a3a7a11356", }, }, .paths = .{""}, diff --git a/druntime/src/core/internal/backtrace/libunwind.d b/druntime/src/core/internal/backtrace/libunwind.d index 75148cd..27183f0 100644 --- a/druntime/src/core/internal/backtrace/libunwind.d +++ b/druntime/src/core/internal/backtrace/libunwind.d @@ -27,11 +27,15 @@ */ module core.internal.backtrace.libunwind; -version (DRuntime_Use_Libunwind) : // Libunwind supports Windows as well, but we currently use a different +version (DRuntime_Use_Libunwind): + +// Libunwind supports Windows as well, but we currently use a different // mechanism for Windows, so the bindings haven't been brought in yet. -version (Posix) : import core.stdc.inttypes; +version (Posix): + +import core.stdc.inttypes; -extern (C): +extern(C): @nogc: nothrow: @@ -56,21 +60,21 @@ struct unw_cursor_t /// struct unw_proc_info_t { - unw_word_t start_ip; /* start address of function */ - unw_word_t end_ip; /* address after end of function */ - unw_word_t lsda; /* address of language specific data area, */ + unw_word_t start_ip; /* start address of function */ + unw_word_t end_ip; /* address after end of function */ + unw_word_t lsda; /* address of language specific data area, */ /* or zero if not used */ - unw_word_t handler; /* personality routine, or zero if not used */ - unw_word_t gp; /* not used */ - unw_word_t flags; /* not used */ - uint format; /* compact unwind encoding, or zero if none */ - uint unwind_info_size; /* size of DWARF unwind info, or zero if none */ + unw_word_t handler; /* personality routine, or zero if not used */ + unw_word_t gp; /* not used */ + unw_word_t flags; /* not used */ + uint format; /* compact unwind encoding, or zero if none */ + uint unwind_info_size; /* size of DWARF unwind info, or zero if none */ // Note: It's a `void*` with LLVM and a `unw_word_t` with upstream - unw_word_t unwind_info; /* address of DWARF unwind info, or zero */ + unw_word_t unwind_info; /* address of DWARF unwind info, or zero */ // Note: upstream might not have this member at all, or it might be a single // byte, however we never pass an array of this type, so this is safe to // just use the bigger (LLVM's) value. - unw_word_t extra; /* mach_header of mach-o image containing func */ + unw_word_t extra; /* mach_header of mach-o image containing func */ } /// Initialize the context at the current call site @@ -113,12 +117,10 @@ else version (X86_64) version (Win64) { enum _LIBUNWIND_CONTEXT_SIZE = 54; - // # ifdef __SEH__ - // # define _LIBUNWIND_CURSOR_SIZE 204 +// # ifdef __SEH__ +// # define _LIBUNWIND_CURSOR_SIZE 204 enum _LIBUNWIND_CURSOR_SIZE = 66; - } - else - { + } else { enum _LIBUNWIND_CONTEXT_SIZE = 21; enum _LIBUNWIND_CURSOR_SIZE = 33; } @@ -136,18 +138,18 @@ else version (PPC) else version (AArch64) { enum _LIBUNWIND_CONTEXT_SIZE = 66; - // # if defined(__SEH__) - // # define _LIBUNWIND_CURSOR_SIZE 164 +// # if defined(__SEH__) +// # define _LIBUNWIND_CURSOR_SIZE 164 enum _LIBUNWIND_CURSOR_SIZE = 78; } else version (ARM) { - // # if defined(__SEH__) - // # define _LIBUNWIND_CONTEXT_SIZE 42 - // # define _LIBUNWIND_CURSOR_SIZE 80 - // # elif defined(__ARM_WMMX) - // # define _LIBUNWIND_CONTEXT_SIZE 61 - // # define _LIBUNWIND_CURSOR_SIZE 68 +// # if defined(__SEH__) +// # define _LIBUNWIND_CONTEXT_SIZE 42 +// # define _LIBUNWIND_CURSOR_SIZE 80 +// # elif defined(__ARM_WMMX) +// # define _LIBUNWIND_CONTEXT_SIZE 61 +// # define _LIBUNWIND_CURSOR_SIZE 68 enum _LIBUNWIND_CONTEXT_SIZE = 42; enum _LIBUNWIND_CURSOR_SIZE = 49; } diff --git a/druntime/src/core/internal/backtrace/unwind.d b/druntime/src/core/internal/backtrace/unwind.d index 44ed077..b31c909 100644 --- a/druntime/src/core/internal/backtrace/unwind.d +++ b/druntime/src/core/internal/backtrace/unwind.d @@ -150,7 +150,7 @@ version (LDC) // simplify runtime function forward declaration else void _Unwind_Resume(_Unwind_Exception* exception_object); _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception* exception_object); -_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void*); +_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void*) nothrow; version (ARM_EABI_UNWINDER) { @@ -160,46 +160,37 @@ version (ARM_EABI_UNWINDER) // On ARM, these are macros resp. not visible (static inline). To avoid // an unmaintainable amount of dependencies on implementation details, // just use a C shim (in ldc/arm_unwind.c). - _Unwind_Word _d_eh_GetGR(_Unwind_Context* context, int index); + _Unwind_Word _d_eh_GetGR(_Unwind_Context* context, int index) nothrow; alias _Unwind_GetGR = _d_eh_GetGR; - void _d_eh_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value); + void _d_eh_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value) nothrow; alias _Unwind_SetGR = _d_eh_SetGR; - _Unwind_Ptr _d_eh_GetIP(_Unwind_Context* context); + _Unwind_Ptr _d_eh_GetIP(_Unwind_Context* context) nothrow; alias _Unwind_GetIP = _d_eh_GetIP; - _Unwind_Ptr _d_eh_GetIPInfo(_Unwind_Context* context, int*); + _Unwind_Ptr _d_eh_GetIPInfo(_Unwind_Context* context, int*) nothrow; alias _Unwind_GetIPInfo = _d_eh_GetIPInfo; - void _d_eh_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value); + void _d_eh_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value) nothrow; alias _Unwind_SetIP = _d_eh_SetIP; } else { - _Unwind_Word _Unwind_GetGR(_Unwind_Context* context, int index); - void _Unwind_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value); - _Unwind_Ptr _Unwind_GetIP(_Unwind_Context* context); - _Unwind_Ptr _Unwind_GetIPInfo(_Unwind_Context* context, int*); - void _Unwind_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value); + _Unwind_Word _Unwind_GetGR(_Unwind_Context* context, int index) nothrow; + void _Unwind_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value) nothrow; + _Unwind_Ptr _Unwind_GetIP(_Unwind_Context* context) nothrow; + _Unwind_Ptr _Unwind_GetIPInfo(_Unwind_Context* context, int*) nothrow; + void _Unwind_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value) nothrow; } -_Unwind_Word _Unwind_GetCFA(_Unwind_Context*); -_Unwind_Word _Unwind_GetBSP(_Unwind_Context*); -void* _Unwind_GetLanguageSpecificData(_Unwind_Context*); -_Unwind_Ptr _Unwind_GetRegionStart(_Unwind_Context* context); -void* _Unwind_FindEnclosingFunction(void* pc); +_Unwind_Word _Unwind_GetCFA(_Unwind_Context*) nothrow; +_Unwind_Word _Unwind_GetBSP(_Unwind_Context*) nothrow; +void* _Unwind_GetLanguageSpecificData(_Unwind_Context*) nothrow; +_Unwind_Ptr _Unwind_GetRegionStart(_Unwind_Context* context) nothrow; +void* _Unwind_FindEnclosingFunction(void* pc) nothrow; -version (X68_64) +version (X86_64) { - _Unwind_Ptr _Unwind_GetDataRelBase(_Unwind_Context* context) - { - return _Unwind_GetGR(context, 1); - } - - _Unwind_Ptr _Unwind_GetTextRelBase(_Unwind_Context* context) - { - assert(0); - } } else { diff --git a/druntime/src/core/runtime.d b/druntime/src/core/runtime.d index 25f74ee..8ece9d2 100644 --- a/druntime/src/core/runtime.d +++ b/druntime/src/core/runtime.d @@ -19,9 +19,17 @@ else version (TVOS) else version (WatchOS) version = Darwin; +version(LDC) version (Darwin) +{ + // Use our own backtrace() based on _Unwind_Backtrace(), as the former (from + // execinfo) doesn't seem to handle missing frame pointers too well. + version = DefineBacktrace_using_UnwindBacktrace; +} + version (DRuntime_Use_Libunwind) { - import core.internal.backtrace.libunwind; + version = DefineBacktrace_using_UnwindBacktrace; + // This shouldn't be necessary but ensure that code doesn't get mixed // It does however prevent the unittest SEGV handler to be installed, // which is desireable as it uses backtrace directly. @@ -670,24 +678,11 @@ extern (C) UnitTestResult runModuleUnitTests() return results; } -version (LDC) version (Darwin) +version (DefineBacktrace_using_UnwindBacktrace) { - nothrow: - - extern (C) - { - enum _URC_NO_REASON = 0; - enum _URC_END_OF_STACK = 5; + import core.internal.backtrace.unwind; - alias _Unwind_Context_Ptr = void*; - alias _Unwind_Trace_Fn = int function(_Unwind_Context_Ptr, void*); - int _Unwind_Backtrace(_Unwind_Trace_Fn, void*); - ptrdiff_t _Unwind_GetIP(_Unwind_Context_Ptr context); - } - - // Use our own backtrce() based on _Unwind_Backtrace(), as the former (from - // execinfo) doesn't seem to handle missing frame pointers too well. - private int backtrace(void** buffer, int maxSize) + private int backtrace(void** buffer, int maxSize) nothrow { if (maxSize < 0) return 0; @@ -698,7 +693,7 @@ version (LDC) version (Darwin) int entriesWritten = 0; } - static extern(C) int handler(_Unwind_Context_Ptr context, void* statePtr) + static extern(C) int handler(_Unwind_Context* context, void* statePtr) { auto state = cast(State*)statePtr; if (state.entriesWritten >= state.maxSize) return _URC_END_OF_STACK; @@ -819,14 +814,8 @@ void defaultTraceDeallocator(Throwable.TraceInfo info) nothrow free(cast(void *)obj); } -version (DRuntime_Use_Libunwind) -{ - import core.internal.backtrace.handler; - - alias DefaultTraceInfo = LibunwindHandler; -} /// Default implementation for most POSIX systems -else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo +version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo { import core.demangle; import core.stdc.stdlib : free; diff --git a/druntime/src/core/sys/posix/sys/statvfs.d b/druntime/src/core/sys/posix/sys/statvfs.d index eae0e5c..9405a6d 100644 --- a/druntime/src/core/sys/posix/sys/statvfs.d +++ b/druntime/src/core/sys/posix/sys/statvfs.d @@ -84,7 +84,57 @@ version (CRuntime_Glibc) { int statvfs (const char * file, statvfs_t* buf); int fstatvfs (int fildes, statvfs_t *buf); } +} +else version (CRuntime_Musl) +{ + struct statvfs_t + { + c_ulong f_bsize; + c_ulong f_frsize; + fsblkcnt_t f_blocks; + fsblkcnt_t f_bfree; + fsblkcnt_t f_bavail; + fsfilcnt_t f_files; + fsfilcnt_t f_ffree; + fsfilcnt_t f_favail; + static if (true /+__BYTE_ORDER == __LITTLE_ENDIAN+/) + { + c_ulong f_fsid; + byte[2*int.sizeof-c_long.sizeof] __padding; + } + else + { + byte[2*int.sizeof-c_long.sizeof] __padding; + c_ulong f_fsid; + } + c_ulong f_flag; + c_ulong f_namemax; + uint f_type; + int[5] __reserved; + } + + enum FFlag + { + ST_RDONLY = 1, /* Mount read-only. */ + ST_NOSUID = 2, + ST_NODEV = 4, /* Disallow access to device special files. */ + ST_NOEXEC = 8, /* Disallow program execution. */ + ST_SYNCHRONOUS = 16, /* Writes are synced at once. */ + ST_MANDLOCK = 64, /* Allow mandatory locks on an FS. */ + ST_WRITE = 128, /* Write on file/directory/symlink. */ + ST_APPEND = 256, /* Append-only file. */ + ST_IMMUTABLE = 512, /* Immutable file. */ + ST_NOATIME = 1024, /* Do not update access times. */ + ST_NODIRATIME = 2048, /* Do not update directory access times. */ + ST_RELATIME = 4096 /* Update atime relative to mtime/ctime. */ + + } + + int statvfs (const char * file, statvfs_t* buf); + int fstatvfs (int fildes, statvfs_t *buf); + alias statvfs statvfs64; + alias fstatvfs fstatvfs64; } else version (NetBSD) { diff --git a/phobos/std/algorithm/searching.d b/phobos/std/algorithm/searching.d index 2d89dea..42a9df5 100644 --- a/phobos/std/algorithm/searching.d +++ b/phobos/std/algorithm/searching.d @@ -3873,6 +3873,21 @@ if (isInputRange!Range && !isInfinite!Range && assert([BigInt(2), BigInt(3)].maxElement == BigInt(3)); } +// https://issues.dlang.org/show_bug.cgi?id=24596 +@safe unittest +{ + static class A { + int i; + int getI() @safe => i; + this(int i) @safe { this.i = i; } + } + auto arr = [new A(2), new A(3)]; + + arr.maxElement!(a => a.getI); + + assert(arr[0].getI == 2); +} + // minPos /** Computes a subrange of `range` starting at the first occurrence of `range`'s diff --git a/phobos/std/typecons.d b/phobos/std/typecons.d index f5b4846..3c425c7 100644 --- a/phobos/std/typecons.d +++ b/phobos/std/typecons.d @@ -3125,7 +3125,10 @@ private: } // call possible struct destructors - .destroy!(No.initialize)(*cast(T*) &this.data); + static if (is(T == struct)) + { + .destroy!(No.initialize)(*cast(T*) &this.data); + } } }