From be45e6e6e486bb9bb687dc950340170d4af950b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B3th=20Ambrus?= <32463042+tothambrus11@users.noreply.github.com> Date: Tue, 1 Apr 2025 22:24:16 +0200 Subject: [PATCH 01/14] Upgrade to Swift 6.1 --- .devcontainer/Dockerfile | 17 +++++++++-------- .devcontainer/devcontainer.json | 8 ++++---- .github/workflows/test.yml | 6 +++--- CMakeLists.txt | 1 + Package.swift | 4 ++-- Sources/SwiftyLLVM/AddressSpace.swift | 4 ++-- .../SwiftyLLVM/Values/Constants/Intrinsic.swift | 4 ++-- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 2b0331b3..283b0cbf 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,20 +1,21 @@ -ARG SWIFT_VERSION=5.9 +ARG SWIFT_VERSION=6.1 # Other ARG declarations must follow FROM FROM swift:${SWIFT_VERSION} ARG HYLO_LLVM_BUILD_TYPE=MinSizeRel ARG HYLO_LLVM_BUILD_RELEASE=20250603-162600 ARG HYLO_LLVM_VERSION=17.0.6 +ARG CMAKE_VERSION=3.29.1 ENV HYLO_LLVM_DOWNLOAD_URL="https://github.com/hylo-lang/llvm-build/releases/download" -RUN apt install -y gnupg -RUN apt update -RUN apt install -y curl libzstd-dev libzstd1 lsb-release make ninja-build tar wget zstd software-properties-common python3-pip - -# Get a recent cmake (https://www.kitware.com//cmake-python-wheels/) -RUN if $(/usr/bin/which cmake) ; then apt purge --auto-remove cmake ; fi -RUN pip3 install --upgrade cmake +# Install the dependencies for the LLVM build. +# Note that we do cleanup in the same layer to save disk space. +RUN apt-get update && \ + apt-get install -y --no-install-recommends gnupg curl libzstd-dev libzstd1 lsb-release make \ + ninja-build tar wget zstd software-properties-common python3-pip cmake && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* # Get the LLVM builds for the host architecture RUN < String? { guard let pcp = ProcessInfo.processInfo.environment["PKG_CONFIG_PATH"] else { return nil } return pcp.split(separator: pathSeparator) - .lazy.compactMap({ try? String(contentsOfFile: "\($0)/\(package).pc") }).first + .lazy.compactMap({ try? String(contentsOfFile: "\($0)/\(package).pc", encoding: String.Encoding.utf8) }).first } /// Returns the un-quoted, un-escaped elements in the remainder of the diff --git a/Sources/SwiftyLLVM/AddressSpace.swift b/Sources/SwiftyLLVM/AddressSpace.swift index 4528b25a..a5cc1834 100644 --- a/Sources/SwiftyLLVM/AddressSpace.swift +++ b/Sources/SwiftyLLVM/AddressSpace.swift @@ -1,5 +1,5 @@ /// Properties of a pointer expressed through the data layout. -public struct AddressSpace: Hashable { +public struct AddressSpace: Hashable, Sendable { /// The LLVM representation of this instance. public let llvm: UInt32 @@ -10,6 +10,6 @@ public struct AddressSpace: Hashable { } /// The default address space. - public static var `default` = AddressSpace(0) + public static let `default` = AddressSpace(0) } diff --git a/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift b/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift index 87c9efb8..ab5a5c7b 100644 --- a/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift +++ b/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift @@ -37,7 +37,7 @@ extension Intrinsic { /// The name of an intrinsic. @dynamicMemberLookup - public struct Name { + public struct Name : Sendable { /// The value of this instance. public let value: String @@ -55,6 +55,6 @@ extension Intrinsic { } /// The prefix of all intrinsics. - public static var llvm = Name("llvm") + public static let llvm = Name("llvm") } From a13e86f1d3fbe597d765deb986cc8e22d43c269b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ambrus=20T=C3=B3th?= Date: Wed, 9 Jul 2025 09:08:01 +0000 Subject: [PATCH 02/14] Revert to installing cmake using python --- .devcontainer/Dockerfile | 8 +++++++- .devcontainer/devcontainer.json | 2 +- .gitignore | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 283b0cbf..c318deba 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -13,10 +13,16 @@ ENV HYLO_LLVM_DOWNLOAD_URL="https://github.com/hylo-lang/llvm-build/releases/dow # Note that we do cleanup in the same layer to save disk space. RUN apt-get update && \ apt-get install -y --no-install-recommends gnupg curl libzstd-dev libzstd1 lsb-release make \ - ninja-build tar wget zstd software-properties-common python3-pip cmake && \ + ninja-build tar wget zstd software-properties-common python3-full python3-pip && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* +# Get a recent cmake (https://www.kitware.com/cmake-python-wheels/) +# RUN if $(/usr/bin/which cmake) ; then apt purge --auto-remove cmake ; fi +RUN python3 -m venv python-venv +RUN python-venv/bin/pip install --upgrade cmake + + # Get the LLVM builds for the host architecture RUN < Date: Wed, 9 Jul 2025 13:18:04 +0000 Subject: [PATCH 03/14] asd --- .devcontainer/Dockerfile | 48 +-------------------- .devcontainer/devcontainer.json | 10 ++--- .github/workflows/test.yml | 4 +- Sources/SwiftyLLVM/Module.swift | 17 ++++++++ Sources/SwiftyLLVM/Types/FunctionType.swift | 1 + 5 files changed, 26 insertions(+), 54 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index c318deba..b8ac6648 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,47 +1 @@ -ARG SWIFT_VERSION=6.1 -# Other ARG declarations must follow FROM -FROM swift:${SWIFT_VERSION} - -ARG HYLO_LLVM_BUILD_TYPE=MinSizeRel -ARG HYLO_LLVM_BUILD_RELEASE=20250603-162600 -ARG HYLO_LLVM_VERSION=17.0.6 -ARG CMAKE_VERSION=3.29.1 - -ENV HYLO_LLVM_DOWNLOAD_URL="https://github.com/hylo-lang/llvm-build/releases/download" - -# Install the dependencies for the LLVM build. -# Note that we do cleanup in the same layer to save disk space. -RUN apt-get update && \ - apt-get install -y --no-install-recommends gnupg curl libzstd-dev libzstd1 lsb-release make \ - ninja-build tar wget zstd software-properties-common python3-full python3-pip && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -# Get a recent cmake (https://www.kitware.com/cmake-python-wheels/) -# RUN if $(/usr/bin/which cmake) ; then apt purge --auto-remove cmake ; fi -RUN python3 -m venv python-venv -RUN python-venv/bin/pip install --upgrade cmake - - -# Get the LLVM builds for the host architecture -RUN < /dev/null - rm /tmp/make-pkgconfig.sh - -EOT +FROM ghcr.io/tothambrus11/hylo-compiler-dev-env:latest diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index adea0b0e..f722bcd1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -10,9 +10,9 @@ "features": { "ghcr.io/devcontainers/features/common-utils:2": { "installZsh": "false", - "username": "vscode", - "userUid": "1001", // 1000 is already taken by the default user in the container - "userGid": "1001", + "username": "ubuntu", + "userUid": "automatic", + "userGid": "automatic", "upgradePackages": "false" }, "ghcr.io/devcontainers/features/git:1": { @@ -36,7 +36,7 @@ }, // Add the IDs of extensions you want installed when the container is created. "extensions": [ - "sswg.swift-lang" + "swiftlang.swift-vscode" ] } }, @@ -50,5 +50,5 @@ }, // "postCreateCommand": "sudo ./.devcontainer/postCreateCommand.sh", // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" + "remoteUser": "ubuntu" } diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dde70fb2..c5ac685b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,9 +87,9 @@ jobs: cmake_generator: Xcode include: - - HYLO_LLVM_BUILD_RELEASE: 20250603-162600 + - HYLO_LLVM_BUILD_RELEASE: 20250617-222524 - HYLO_LLVM_DOWNLOAD_URL: https://github.com/hylo-lang/llvm-build/releases/download - - HYLO_LLVM_VERSION: '17.0.6' + - HYLO_LLVM_VERSION: '20.1.6' - llvm_package_suffix: .tar.zst - unpackage_command: tar -x --zstd -f - use_spm: true diff --git a/Sources/SwiftyLLVM/Module.swift b/Sources/SwiftyLLVM/Module.swift index 49f0144f..7e37cbc3 100644 --- a/Sources/SwiftyLLVM/Module.swift +++ b/Sources/SwiftyLLVM/Module.swift @@ -176,6 +176,7 @@ public struct Module { let h = parameters.withHandles { (p) in LLVMGetIntrinsicDeclaration(llvm.raw, i, p.baseAddress, parameters.count) } + return h.map(Intrinsic.init(_:)) } @@ -808,6 +809,22 @@ public struct Module { at p: InsertionPoint ) -> Instruction { var a = arguments.map({ $0.llvm.raw as Optional }) + + // Debug: Print function type and arguments + if let funcType = FunctionType(calleeType) { + let functionName = Function(callee)?.name ?? "unknown" + print("DEBUG: Call to function: \(functionName)") + print("DEBUG: Expected params: \(funcType.parameters.count), Got args: \(arguments.count)") + + // Check if this is a problematic call + if funcType.parameters.count != arguments.count { + print("ERROR: Parameter count mismatch!") + print("Function: \(functionName)") + print("Expected: \(funcType.parameters.count) parameters") + print("Got: \(arguments.count) arguments") + } + } + return .init(LLVMBuildCall2(p.llvm, calleeType.llvm.raw, callee.llvm.raw, &a, UInt32(a.count), "")) } diff --git a/Sources/SwiftyLLVM/Types/FunctionType.swift b/Sources/SwiftyLLVM/Types/FunctionType.swift index 241ad5c6..e88bab05 100644 --- a/Sources/SwiftyLLVM/Types/FunctionType.swift +++ b/Sources/SwiftyLLVM/Types/FunctionType.swift @@ -32,6 +32,7 @@ public struct FunctionType: IRType, Hashable { public var parameters: [IRType] { let n = LLVMCountParamTypes(llvm.raw) var handles: [LLVMAttributeRef?] = .init(repeating: nil, count: Int(n)) + // var handles: [LLVMTypeRef?] = .init(repeating: nil, count: Int(n)) LLVMGetParamTypes(llvm.raw, &handles) return handles.map({ AnyType($0!) as IRType }) } From 3d65b3969abc3b0324f90ed8a060becda38d9373 Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 04:29:57 +0000 Subject: [PATCH 04/14] Fix intrinsics usage in llvm 20 --- .../Values/Constants/Intrinsic.swift | 10 ++++++-- Tests/LLVMTests/CodeGenerationTests.swift | 8 ++++-- .../Values/Constants/IntrinsicTests.swift | 25 +++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift b/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift index ab5a5c7b..db4b9b96 100644 --- a/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift +++ b/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift @@ -26,9 +26,15 @@ public struct Intrinsic: Global, Hashable { LLVMIntrinsicIsOverloaded(identifier) != 0 } - /// The name of the intrinsic. + /// The name of a non-overloaded intrinsic. public var name: String { - String(from: identifier, readingWith: LLVMIntrinsicGetName(_:_:)) ?? "" + precondition(!isOverloaded, "Overloaded intrinsics do not have a single name") + // See https://searchfox.org/llvm/rev/7a089bc4c00fe35c8f07b7c420be6535ad331161/llvm/lib/IR/Intrinsics.cpp#51 + // and https://searchfox.org/llvm/rev/7a089bc4c00fe35c8f07b7c420be6535ad331161/llvm/lib/IR/Core.cpp#2474 + + // We may get the name by LLVMIntrinsicCopyOverloadedName2 if we can recover the parameters based on the ValueRef (that contains a ptr), + // or we could just save them additionally when creating the intrinsic when the user explicitly provides this list. This seems wasteful though. + return String(from: identifier, readingWith: LLVMIntrinsicGetName(_:_:)) ?? "" } } diff --git a/Tests/LLVMTests/CodeGenerationTests.swift b/Tests/LLVMTests/CodeGenerationTests.swift index 56f0bf53..2bddf42a 100644 --- a/Tests/LLVMTests/CodeGenerationTests.swift +++ b/Tests/LLVMTests/CodeGenerationTests.swift @@ -180,9 +180,13 @@ extension Module { let x6 = insertFDiv(x5, double(180), at: endOf(b0)) insertStore(x6, to: r, at: endOf(b0)) - // %12 = call i1 @llvm.coro.end(ptr %4, i1 false) + // %12 = call token @llvm.coro.end.results() + let results = intrinsic(named: Intrinsic.llvm.coro.end.results)! + let resultToken = insertCall(Function(results)!, on: [], at: endOf(b0)) + + // %13 = call i1 @llvm.coro.end(ptr %4, i1 false, token %12) let end = intrinsic(named: Intrinsic.llvm.coro.end)! - _ = insertCall(Function(end)!, on: [coroutineHandle, i1(0)], at: endOf(b0)) + _ = insertCall(Function(end)!, on: [coroutineHandle, i1(0), resultToken], at: endOf(b0)) // unreachable insertUnreachable(at: endOf(b0)) diff --git a/Tests/LLVMTests/Values/Constants/IntrinsicTests.swift b/Tests/LLVMTests/Values/Constants/IntrinsicTests.swift index 10d4b8f8..62efa013 100644 --- a/Tests/LLVMTests/Values/Constants/IntrinsicTests.swift +++ b/Tests/LLVMTests/Values/Constants/IntrinsicTests.swift @@ -5,33 +5,42 @@ final class IntinsicTests: XCTestCase { func testInit() { var m = Module("foo") - XCTAssertNotNil(m.intrinsic(named: Intrinsic.llvm.va_start)) + XCTAssertNotNil(m.intrinsic(named: Intrinsic.llvm.trap)) XCTAssertNil(m.intrinsic(named: Intrinsic.llvm.does_not_exist)) } func testIsOverloaded() throws { var m = Module("foo") - let f = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_start)) - XCTAssertFalse(f.isOverloaded) + // llvm.va_start is overloaded for different address spaces. + let p0 = PointerType(in: &m) + let f = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_start, for: [p0])) + XCTAssertTrue(f.isOverloaded) + + // llvm.smax is overloaded for different integer types. let i16 = IntegerType(16, in: &m) let g = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.smax, for: [i16])) XCTAssert(g.isOverloaded) + + // llvm.trap is not overloaded. + let h = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.trap)) + XCTAssertFalse(h.isOverloaded) } func testName() throws { var m = Module("foo") - let f = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_start)) - XCTAssertEqual(f.name, "llvm.va_start") + let f = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.trap, for: [])) + XCTAssertEqual(f.name, "llvm.trap") } func testEquality() throws { var m = Module("foo") - let f = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_start)) - let g = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_start)) + let p0 = PointerType(in: &m) + let f = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_start, for: [p0])) + let g = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_start, for: [p0])) XCTAssertEqual(f, g) - let h = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_end)) + let h = try XCTUnwrap(m.intrinsic(named: Intrinsic.llvm.va_end, for: [p0])) XCTAssertNotEqual(f, h) } From c650cce104957f2793b2656e4b2ce2d6b71b03e6 Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 04:44:25 +0000 Subject: [PATCH 05/14] Upgrade cmake llvm dependency to 20.1 --- cmake/TopLevelDefaults.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/TopLevelDefaults.cmake b/cmake/TopLevelDefaults.cmake index 1d6a06d5..e407edd9 100644 --- a/cmake/TopLevelDefaults.cmake +++ b/cmake/TopLevelDefaults.cmake @@ -13,8 +13,8 @@ block() set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER) FetchContent_Declare(Hylo-CMakeModules - GIT_REPOSITORY https://github.com/hylo-lang/CMakeModules.git - GIT_TAG 6577fca + GIT_REPOSITORY https://github.com/tothambrus11/CMakeModules.git + GIT_TAG 697fd80f4a78d4f5e479d17b0c778c5f5cae488f OVERRIDE_FIND_PACKAGE ) From 4fdf1f17cbe51ce4f34b18eab39bc7b603df2ac0 Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 05:27:58 +0000 Subject: [PATCH 06/14] Use fixed OS versions --- .github/workflows/test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c5ac685b..ed8fac27 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: cmake_build_type: Release HYLO_LLVM_BUILD_TYPE: MinSizeRel - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 with: @@ -76,14 +76,14 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-14, ubuntu-latest, windows-latest] + os: [macos-14, ubuntu-22.04, windows-2025] spm_configuration: [debug, release] cmake_generator: [Ninja, Xcode] exclude: - - os: ubuntu-latest + - os: ubuntu-22.04 cmake_generator: Xcode - - os: windows-latest + - os: windows-2025 cmake_generator: Xcode include: @@ -95,19 +95,19 @@ jobs: - use_spm: true - triple_cpu: x86_64 - - os: windows-latest + - os: windows-2025 unpackage_command: 7z x -t7z llvm_package_suffix: .7z triple_suffix: unknown-windows-msvc17 - - os: windows-latest + - os: windows-2025 use_spm: false - os: macos-14 triple_suffix: apple-darwin24.1.0 triple_cpu: arm64 - - os: ubuntu-latest + - os: ubuntu-22.04 triple_suffix: unknown-linux-gnu - spm_configuration: debug From 230511d30113b6e6c546a1c01e87cfc5db9840e0 Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 05:29:43 +0000 Subject: [PATCH 07/14] Use fixed docker image version --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index b8ac6648..8092046f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1 +1 @@ -FROM ghcr.io/tothambrus11/hylo-compiler-dev-env:latest +FROM ghcr.io/tothambrus11/hylo-compiler-dev-env:v1.0.1 \ No newline at end of file From dc89d12ad3e39028e90c649025400f75e6f2cf76 Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 06:43:12 +0000 Subject: [PATCH 08/14] Move pkgconfig and remove obsolete symlink --- .devcontainer/make-pkgconfig.sh | 51 -------------------------------- Tools/make-pkgconfig.sh | 52 ++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 52 deletions(-) delete mode 100755 .devcontainer/make-pkgconfig.sh mode change 120000 => 100644 Tools/make-pkgconfig.sh diff --git a/.devcontainer/make-pkgconfig.sh b/.devcontainer/make-pkgconfig.sh deleted file mode 100755 index 65597006..00000000 --- a/.devcontainer/make-pkgconfig.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash -set -e -set -o pipefail - -# Work around https://github.com/hylo-lang/llvm-build/issues/8 -# -# We need to be resilient to no libzstd being found by pkg-config, as it is apparently not on linux. -zstd_dash_L="$(pkg-config --silence-errors --libs-only-L libzstd || true)" -if ! (llvm-config > /dev/null 2>&1); then - if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "cygwin" || "$OSTYPE" == "freebsd"* ]]; then - export LD_LIBRARY_PATH="${zstd_dash_L#-L}:$LD_LIBRARY_PATH" - elif [[ "$OSTYPE" == "darwin"* ]]; then - export DYLD_LIBRARY_PATH="${zstd_dash_L#-L}:$DYLD_LIBRARY_PATH" - elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then - export PATH="${zstd_dash_L#-L}:$PATH" - fi -fi - -version=$(llvm-config --version) -filename=$1 - -mkdir -p `dirname $filename` -touch $filename - -# REVISIT(nickpdemarco): -# Why does macos need the standard library explicitly linked, while linux does not? -# This does not feel like the correct place for this logic. -machine="$(uname -s)" -case "${machine}" in - Darwin*) libs="-lc++";; - *) libs="" -esac - -libs=() -for x in -L$(llvm-config --libdir) ${zstd_dash_L} $(llvm-config --system-libs --libs analysis bitwriter core native passes target); do - libs+=($(printf '%q' "$x")) -done -cflags=() -for x in $(llvm-config --cxxflags); do - cflags+=($(printf '%q' "$x")) -done - -echo Name: LLVM > $filename -echo Description: Low-level Virtual Machine compiler framework >> $filename -echo Version: $(echo ${version} | sed 's/\([0-9.]\+\).*/\1/') >> $filename -echo URL: http://www.llvm.org/ >> $filename -echo Libs: ${libs[@]} >> $filename -echo Cflags: ${cflags[@]} >> $filename - -echo "$filename written:" -cat $filename diff --git a/Tools/make-pkgconfig.sh b/Tools/make-pkgconfig.sh deleted file mode 120000 index 67d518b2..00000000 --- a/Tools/make-pkgconfig.sh +++ /dev/null @@ -1 +0,0 @@ -../.devcontainer/make-pkgconfig.sh \ No newline at end of file diff --git a/Tools/make-pkgconfig.sh b/Tools/make-pkgconfig.sh new file mode 100644 index 00000000..65597006 --- /dev/null +++ b/Tools/make-pkgconfig.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -e +set -o pipefail + +# Work around https://github.com/hylo-lang/llvm-build/issues/8 +# +# We need to be resilient to no libzstd being found by pkg-config, as it is apparently not on linux. +zstd_dash_L="$(pkg-config --silence-errors --libs-only-L libzstd || true)" +if ! (llvm-config > /dev/null 2>&1); then + if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "cygwin" || "$OSTYPE" == "freebsd"* ]]; then + export LD_LIBRARY_PATH="${zstd_dash_L#-L}:$LD_LIBRARY_PATH" + elif [[ "$OSTYPE" == "darwin"* ]]; then + export DYLD_LIBRARY_PATH="${zstd_dash_L#-L}:$DYLD_LIBRARY_PATH" + elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then + export PATH="${zstd_dash_L#-L}:$PATH" + fi +fi + +version=$(llvm-config --version) +filename=$1 + +mkdir -p `dirname $filename` +touch $filename + +# REVISIT(nickpdemarco): +# Why does macos need the standard library explicitly linked, while linux does not? +# This does not feel like the correct place for this logic. +machine="$(uname -s)" +case "${machine}" in + Darwin*) libs="-lc++";; + *) libs="" +esac + +libs=() +for x in -L$(llvm-config --libdir) ${zstd_dash_L} $(llvm-config --system-libs --libs analysis bitwriter core native passes target); do + libs+=($(printf '%q' "$x")) +done +cflags=() +for x in $(llvm-config --cxxflags); do + cflags+=($(printf '%q' "$x")) +done + +echo Name: LLVM > $filename +echo Description: Low-level Virtual Machine compiler framework >> $filename +echo Version: $(echo ${version} | sed 's/\([0-9.]\+\).*/\1/') >> $filename +echo URL: http://www.llvm.org/ >> $filename +echo Libs: ${libs[@]} >> $filename +echo Cflags: ${cflags[@]} >> $filename + +echo "$filename written:" +cat $filename From 31a46c899431041c674f9d8141f52ec7c36521ba Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 06:43:33 +0000 Subject: [PATCH 09/14] Downgrade to windows-2022 image --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ed8fac27..152b7c07 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,14 +76,14 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-14, ubuntu-22.04, windows-2025] + os: [macos-14, ubuntu-22.04, windows-2022] spm_configuration: [debug, release] cmake_generator: [Ninja, Xcode] exclude: - os: ubuntu-22.04 cmake_generator: Xcode - - os: windows-2025 + - os: windows-2022 cmake_generator: Xcode include: @@ -95,12 +95,12 @@ jobs: - use_spm: true - triple_cpu: x86_64 - - os: windows-2025 + - os: windows-2022 unpackage_command: 7z x -t7z llvm_package_suffix: .7z triple_suffix: unknown-windows-msvc17 - - os: windows-2025 + - os: windows-2022 use_spm: false - os: macos-14 From 428f7b9abcac484f0ae7d83d62ccca10431014b5 Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 06:53:13 +0000 Subject: [PATCH 10/14] Add executable permission to make-pkg-config --- Tools/make-pkgconfig.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 Tools/make-pkgconfig.sh diff --git a/Tools/make-pkgconfig.sh b/Tools/make-pkgconfig.sh old mode 100644 new mode 100755 From 7992d8dcc6527a3f6525a6b2b06cb31a33e11748 Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Fri, 11 Jul 2025 20:40:54 +0000 Subject: [PATCH 11/14] Add sendable conformances to everything --- Sources/SwiftyLLVM/AtomicOrdering.swift | 2 +- Sources/SwiftyLLVM/AtomicRMWBinOp.swift | 2 +- Sources/SwiftyLLVM/BasicBlock.swift | 2 +- Sources/SwiftyLLVM/CodeGenerationResultType.swift | 2 +- Sources/SwiftyLLVM/CodeModel.swift | 2 +- Sources/SwiftyLLVM/DataLayout.swift | 2 +- Sources/SwiftyLLVM/InsertionPoint.swift | 2 +- Sources/SwiftyLLVM/LLVMError.swift | 2 +- Sources/SwiftyLLVM/Linkage.swift | 2 +- Sources/SwiftyLLVM/MemoryBuffer.swift | 4 ++-- Sources/SwiftyLLVM/Module.swift | 4 ++-- Sources/SwiftyLLVM/OptimizationLevel.swift | 2 +- Sources/SwiftyLLVM/Refs.swift | 10 +++++----- Sources/SwiftyLLVM/RelocationModel.swift | 2 +- Sources/SwiftyLLVM/Target.swift | 2 +- Sources/SwiftyLLVM/TargetMachine.swift | 2 +- Sources/SwiftyLLVM/Types/IRType.swift | 2 +- Sources/SwiftyLLVM/Types/StructType.swift | 2 +- Sources/SwiftyLLVM/Utils/ManagedPointer.swift | 5 +++-- .../SwiftyLLVM/Values/Constants/ArrayConstant.swift | 2 +- Sources/SwiftyLLVM/Values/Constants/Attribute.swift | 2 +- .../Values/Constants/Function+Attributes.swift | 2 +- Sources/SwiftyLLVM/Values/Constants/Function.swift | 6 +++--- Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift | 4 ++-- .../Values/Constants/Parameter+Attributes.swift | 2 +- .../SwiftyLLVM/Values/Constants/StructConstant.swift | 2 +- Sources/SwiftyLLVM/Values/GlobalVariable.swift | 2 +- Sources/SwiftyLLVM/Values/IRValue.swift | 2 +- .../Values/Instructions/FloatingPointPredicate.swift | 2 +- .../Values/Instructions/IntegerPredicate.swift | 2 +- .../Values/Instructions/OverflowBehavior.swift | 2 +- 31 files changed, 42 insertions(+), 41 deletions(-) diff --git a/Sources/SwiftyLLVM/AtomicOrdering.swift b/Sources/SwiftyLLVM/AtomicOrdering.swift index 655c7b18..cd57e6ee 100644 --- a/Sources/SwiftyLLVM/AtomicOrdering.swift +++ b/Sources/SwiftyLLVM/AtomicOrdering.swift @@ -3,7 +3,7 @@ internal import llvmc /// The ordering for an atomic operation. /// /// See https://en.cppreference.com/w/cpp/atomic/memory_order -public enum AtomicOrdering { +public enum AtomicOrdering: Sendable { /// A load or a store operation that is not atomic. /// diff --git a/Sources/SwiftyLLVM/AtomicRMWBinOp.swift b/Sources/SwiftyLLVM/AtomicRMWBinOp.swift index 09bf7885..391bcfcf 100644 --- a/Sources/SwiftyLLVM/AtomicRMWBinOp.swift +++ b/Sources/SwiftyLLVM/AtomicRMWBinOp.swift @@ -1,7 +1,7 @@ internal import llvmc /// The type of an atomic read-modify-write binary operation. -public enum AtomicRMWBinOp { +public enum AtomicRMWBinOp: Sendable { /// Set the new value and return the one old. case xchg diff --git a/Sources/SwiftyLLVM/BasicBlock.swift b/Sources/SwiftyLLVM/BasicBlock.swift index d6fca2f6..800362ae 100644 --- a/Sources/SwiftyLLVM/BasicBlock.swift +++ b/Sources/SwiftyLLVM/BasicBlock.swift @@ -1,7 +1,7 @@ internal import llvmc /// A basic block in LLVM IR. -public struct BasicBlock: Hashable { +public struct BasicBlock: Hashable, Sendable { /// A handle to the LLVM object wrapped by this instance. public let llvm: BasicBlockRef diff --git a/Sources/SwiftyLLVM/CodeGenerationResultType.swift b/Sources/SwiftyLLVM/CodeGenerationResultType.swift index 07276a04..f6fd1c7c 100644 --- a/Sources/SwiftyLLVM/CodeGenerationResultType.swift +++ b/Sources/SwiftyLLVM/CodeGenerationResultType.swift @@ -1,7 +1,7 @@ internal import llvmc /// The kind of result produced by code generation. -public enum CodeGenerationResultType: Hashable { +public enum CodeGenerationResultType: Hashable, Sendable { /// Assembly. case assembly diff --git a/Sources/SwiftyLLVM/CodeModel.swift b/Sources/SwiftyLLVM/CodeModel.swift index ccdbe20f..7496c89d 100644 --- a/Sources/SwiftyLLVM/CodeModel.swift +++ b/Sources/SwiftyLLVM/CodeModel.swift @@ -1,7 +1,7 @@ internal import llvmc /// Constraints on address ranges that the program and its symbols may use. -public enum CodeModel: Hashable { +public enum CodeModel: Hashable, Sendable { /// The model default to the target for which code is being generated. case `default` diff --git a/Sources/SwiftyLLVM/DataLayout.swift b/Sources/SwiftyLLVM/DataLayout.swift index 3c566b36..731dcf64 100644 --- a/Sources/SwiftyLLVM/DataLayout.swift +++ b/Sources/SwiftyLLVM/DataLayout.swift @@ -1,7 +1,7 @@ internal import llvmc /// How data are represented in memory for a particular target machine. -public struct DataLayout { +public struct DataLayout: @unchecked Sendable { /// A handle to the LLVM object wrapped by this instance. private let wrapped: ManagedPointer diff --git a/Sources/SwiftyLLVM/InsertionPoint.swift b/Sources/SwiftyLLVM/InsertionPoint.swift index ab6c463e..83a2d097 100644 --- a/Sources/SwiftyLLVM/InsertionPoint.swift +++ b/Sources/SwiftyLLVM/InsertionPoint.swift @@ -1,7 +1,7 @@ internal import llvmc /// A cursor specifying where IR instructions should be inserted. -public struct InsertionPoint { +public struct InsertionPoint: @unchecked Sendable { /// A pointer the object wrapped by this instance. private let wrapped: ManagedPointer diff --git a/Sources/SwiftyLLVM/LLVMError.swift b/Sources/SwiftyLLVM/LLVMError.swift index 221cffde..b3a47bae 100644 --- a/Sources/SwiftyLLVM/LLVMError.swift +++ b/Sources/SwiftyLLVM/LLVMError.swift @@ -1,5 +1,5 @@ /// An error that occurred during a LLVM operation. -public struct LLVMError: Error { +public struct LLVMError: Error, Sendable { /// A description of the error. public let description: String diff --git a/Sources/SwiftyLLVM/Linkage.swift b/Sources/SwiftyLLVM/Linkage.swift index 7d18b6ce..1c4e0326 100644 --- a/Sources/SwiftyLLVM/Linkage.swift +++ b/Sources/SwiftyLLVM/Linkage.swift @@ -4,7 +4,7 @@ internal import llvmc /// /// - Note: It is illegal for a global variable or function declaration to have any linkage type /// other than `external` or `extern_weak`. -public enum Linkage { +public enum Linkage: Sendable { /// The name is externally visible; it participates in linkage and can be used to resolve /// external symbol references. diff --git a/Sources/SwiftyLLVM/MemoryBuffer.swift b/Sources/SwiftyLLVM/MemoryBuffer.swift index 97bf2482..c223f482 100644 --- a/Sources/SwiftyLLVM/MemoryBuffer.swift +++ b/Sources/SwiftyLLVM/MemoryBuffer.swift @@ -1,10 +1,10 @@ internal import llvmc /// A read-only access to a block of memory. -public struct MemoryBuffer { +public struct MemoryBuffer: Sendable { /// A handle to the LLVM object representing a memory buffer. - private final class Handle { + private final class Handle: @unchecked Sendable { /// A pointer to a LLVM memory buffer. let llvm: LLVMMemoryBufferRef diff --git a/Sources/SwiftyLLVM/Module.swift b/Sources/SwiftyLLVM/Module.swift index 7e37cbc3..b3a5f33c 100644 --- a/Sources/SwiftyLLVM/Module.swift +++ b/Sources/SwiftyLLVM/Module.swift @@ -2,10 +2,10 @@ internal import llvmc import llvmshims /// The top-level structure in an LLVM program. -public struct Module { +public struct Module: Sendable { /// The resources wrapped by an instance of `Module`. - private final class Handles { + private final class Handles: @unchecked Sendable { /// The context owning the contents of the LLVM module. let context: LLVMContextRef diff --git a/Sources/SwiftyLLVM/OptimizationLevel.swift b/Sources/SwiftyLLVM/OptimizationLevel.swift index fdc6bb1d..0911c569 100644 --- a/Sources/SwiftyLLVM/OptimizationLevel.swift +++ b/Sources/SwiftyLLVM/OptimizationLevel.swift @@ -1,7 +1,7 @@ internal import llvmc /// The level of optimization used during code generation. -public enum OptimitzationLevel: Hashable { +public enum OptimitzationLevel: Hashable, Sendable { /// No optimization (a.k.a. `O0`). case none diff --git a/Sources/SwiftyLLVM/Refs.swift b/Sources/SwiftyLLVM/Refs.swift index e9d431cf..b522cfeb 100644 --- a/Sources/SwiftyLLVM/Refs.swift +++ b/Sources/SwiftyLLVM/Refs.swift @@ -2,7 +2,7 @@ internal import llvmc import Foundation /// An LLVM type reference. -public struct TypeRef: Hashable { +public struct TypeRef: Hashable, @unchecked Sendable { /// The underlying LLVM value. let raw: llvmc.LLVMTypeRef @@ -13,7 +13,7 @@ public struct TypeRef: Hashable { } /// An LLVM value reference. -public struct ValueRef: Hashable { +public struct ValueRef: Hashable, @unchecked Sendable { /// The underlying LLVM value; not exposed to avoid rexporting llvmc let raw: llvmc.LLVMValueRef @@ -24,7 +24,7 @@ public struct ValueRef: Hashable { } /// An LLVM basic block reference. -public struct BasicBlockRef: Hashable { +public struct BasicBlockRef: Hashable, @unchecked Sendable { /// The underlying LLVM value; not exposed to avoid rexporting llvmc let raw: llvmc.LLVMBasicBlockRef @@ -35,7 +35,7 @@ public struct BasicBlockRef: Hashable { } /// An LLVM module reference. -public struct ModuleRef: Hashable { +public struct ModuleRef: Hashable, @unchecked Sendable { /// The underlying LLVM value; not exposed to avoid rexporting llvmc let raw: llvmc.LLVMModuleRef @@ -46,7 +46,7 @@ public struct ModuleRef: Hashable { } /// An LLVM attribute reference. -public struct AttributeRef: Hashable { +public struct AttributeRef: Hashable, @unchecked Sendable { /// The underlying LLVM value; not exposed to avoid rexporting llvmc let raw: llvmc.LLVMAttributeRef diff --git a/Sources/SwiftyLLVM/RelocationModel.swift b/Sources/SwiftyLLVM/RelocationModel.swift index 92511f34..4d609953 100644 --- a/Sources/SwiftyLLVM/RelocationModel.swift +++ b/Sources/SwiftyLLVM/RelocationModel.swift @@ -1,7 +1,7 @@ internal import llvmc /// The settings of position-independent code (PIC) during code generation. -public enum RelocationModel: Hashable { +public enum RelocationModel: Hashable, Sendable { /// The model default to the target for which code is being generated. case `default` diff --git a/Sources/SwiftyLLVM/Target.swift b/Sources/SwiftyLLVM/Target.swift index 25bee373..6d62b428 100644 --- a/Sources/SwiftyLLVM/Target.swift +++ b/Sources/SwiftyLLVM/Target.swift @@ -1,7 +1,7 @@ internal import llvmc /// The specification of a platform on which code runs. -public struct Target { +public struct Target: @unchecked Sendable { /// The triple of the target. /// diff --git a/Sources/SwiftyLLVM/TargetMachine.swift b/Sources/SwiftyLLVM/TargetMachine.swift index b185b196..0d9b66b0 100644 --- a/Sources/SwiftyLLVM/TargetMachine.swift +++ b/Sources/SwiftyLLVM/TargetMachine.swift @@ -1,7 +1,7 @@ internal import llvmc /// The settings necessary for code generation, including target information and compiler options. -public struct TargetMachine { +public struct TargetMachine: @unchecked Sendable { /// A handle to the LLVM object wrapped by this instance. private let wrapped: ManagedPointer diff --git a/Sources/SwiftyLLVM/Types/IRType.swift b/Sources/SwiftyLLVM/Types/IRType.swift index c0b231ce..b4322ed7 100644 --- a/Sources/SwiftyLLVM/Types/IRType.swift +++ b/Sources/SwiftyLLVM/Types/IRType.swift @@ -1,7 +1,7 @@ internal import llvmc /// The type of a value in LLVM IR. -public protocol IRType: CustomStringConvertible { +public protocol IRType: CustomStringConvertible, Sendable { /// A handle to the LLVM object wrapped by this instance. var llvm: TypeRef { get } diff --git a/Sources/SwiftyLLVM/Types/StructType.swift b/Sources/SwiftyLLVM/Types/StructType.swift index e7b75b54..1769cd48 100644 --- a/Sources/SwiftyLLVM/Types/StructType.swift +++ b/Sources/SwiftyLLVM/Types/StructType.swift @@ -65,7 +65,7 @@ public struct StructType: IRType, Hashable { extension StructType { /// A collection containing the fields of a struct type in LLVM IR. - public struct Fields: BidirectionalCollection { + public struct Fields: BidirectionalCollection, Sendable { public typealias Index = Int diff --git a/Sources/SwiftyLLVM/Utils/ManagedPointer.swift b/Sources/SwiftyLLVM/Utils/ManagedPointer.swift index 0c35fdb2..125b1a14 100644 --- a/Sources/SwiftyLLVM/Utils/ManagedPointer.swift +++ b/Sources/SwiftyLLVM/Utils/ManagedPointer.swift @@ -5,10 +5,10 @@ final class ManagedPointer { let llvm: T /// A closure that disposes of an instance pointed by `T`. - private let dispose: (T) -> Void + private let dispose: @Sendable (T) -> Void /// Creates an instance managing `p` and calling `dispose(p)` at the end of its lifetime. - init(_ p: T, dispose: @escaping (T) -> Void) { + init(_ p: T, dispose: @escaping @Sendable (T) -> Void) { self.llvm = p self.dispose = dispose } @@ -18,3 +18,4 @@ final class ManagedPointer { } } +extension ManagedPointer: Sendable where T: Sendable { } \ No newline at end of file diff --git a/Sources/SwiftyLLVM/Values/Constants/ArrayConstant.swift b/Sources/SwiftyLLVM/Values/Constants/ArrayConstant.swift index ad266010..e54d3aa3 100644 --- a/Sources/SwiftyLLVM/Values/Constants/ArrayConstant.swift +++ b/Sources/SwiftyLLVM/Values/Constants/ArrayConstant.swift @@ -1,7 +1,7 @@ internal import llvmc /// A constant array in LLVM IR. -public struct ArrayConstant: Hashable { +public struct ArrayConstant: Hashable, Sendable { /// A handle to the LLVM object wrapped by this instance. public let llvm: ValueRef diff --git a/Sources/SwiftyLLVM/Values/Constants/Attribute.swift b/Sources/SwiftyLLVM/Values/Constants/Attribute.swift index a49cb79c..945ebcea 100644 --- a/Sources/SwiftyLLVM/Values/Constants/Attribute.swift +++ b/Sources/SwiftyLLVM/Values/Constants/Attribute.swift @@ -24,7 +24,7 @@ extension AttributeNameProtocol { } /// An attribute on a function, return value, or parameter in LLVM IR. -public enum Attribute: Hashable { +public enum Attribute: Hashable, Sendable { /// A target-independent attribute. case targetIndependent(llvm: AttributeRef) diff --git a/Sources/SwiftyLLVM/Values/Constants/Function+Attributes.swift b/Sources/SwiftyLLVM/Values/Constants/Function+Attributes.swift index 3ff6a315..aed65279 100644 --- a/Sources/SwiftyLLVM/Values/Constants/Function+Attributes.swift +++ b/Sources/SwiftyLLVM/Values/Constants/Function+Attributes.swift @@ -6,7 +6,7 @@ extension Function: AttributeHolder { public typealias Attribute = SwiftyLLVM.Attribute /// The name of an attribute on a function in LLVM IR. - public enum AttributeName: String, AttributeNameProtocol { + public enum AttributeName: String, AttributeNameProtocol, Sendable { /// Indicates that the inliner should attempt to inline this function into callers whenever /// possible, ignoring any active inlining size threshold for this caller. diff --git a/Sources/SwiftyLLVM/Values/Constants/Function.swift b/Sources/SwiftyLLVM/Values/Constants/Function.swift index 043fa4df..38fde2ec 100644 --- a/Sources/SwiftyLLVM/Values/Constants/Function.swift +++ b/Sources/SwiftyLLVM/Values/Constants/Function.swift @@ -1,7 +1,7 @@ internal import llvmc /// A function in LLVM IR. -public struct Function: Global, Hashable { +public struct Function: Global, Hashable, Sendable { /// A handle to the LLVM object wrapped by this instance. public let llvm: ValueRef @@ -48,7 +48,7 @@ extension Function { /// The return value of a LLVM IR function. - public struct Return: Hashable { + public struct Return: Hashable, Sendable { /// The function defining the return value. public let parent: Function @@ -68,7 +68,7 @@ extension Function { extension Function { /// A collection containing the parameters of a LLVM IR function. - public struct Parameters: BidirectionalCollection { + public struct Parameters: BidirectionalCollection, Sendable { public typealias Index = Int diff --git a/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift b/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift index db4b9b96..3e48204a 100644 --- a/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift +++ b/Sources/SwiftyLLVM/Values/Constants/Intrinsic.swift @@ -6,7 +6,7 @@ import Foundation /// Intrinsic functions have well known names and semantics and are required to follow certain /// restrictions. Overall, these intrinsics represent an extension mechanism for the LLVM language /// that does not require changing all of the transformations in LLVM when adding to the language. -public struct Intrinsic: Global, Hashable { +public struct Intrinsic: Global, Hashable, Sendable { /// A handle to the LLVM object wrapped by this instance. public let llvm: ValueRef @@ -43,7 +43,7 @@ extension Intrinsic { /// The name of an intrinsic. @dynamicMemberLookup - public struct Name : Sendable { + public struct Name: Sendable { /// The value of this instance. public let value: String diff --git a/Sources/SwiftyLLVM/Values/Constants/Parameter+Attributes.swift b/Sources/SwiftyLLVM/Values/Constants/Parameter+Attributes.swift index fbfe9d4b..1122b664 100644 --- a/Sources/SwiftyLLVM/Values/Constants/Parameter+Attributes.swift +++ b/Sources/SwiftyLLVM/Values/Constants/Parameter+Attributes.swift @@ -6,7 +6,7 @@ extension Parameter: AttributeHolder { public typealias Attribute = SwiftyLLVM.Attribute /// The name of an attribute on a parameter in LLVM IR. - public enum AttributeName: String, AttributeNameProtocol { + public enum AttributeName: String, AttributeNameProtocol, Sendable { /// Indicates to the code generator that the parameter or return value should be sign-extended /// to the extent required by the target’s ABI (which is usually 32-bits) by the caller (for a diff --git a/Sources/SwiftyLLVM/Values/Constants/StructConstant.swift b/Sources/SwiftyLLVM/Values/Constants/StructConstant.swift index cf6f7d0a..47e72fea 100644 --- a/Sources/SwiftyLLVM/Values/Constants/StructConstant.swift +++ b/Sources/SwiftyLLVM/Values/Constants/StructConstant.swift @@ -1,7 +1,7 @@ internal import llvmc /// A constant struct in LLVM IR. -public struct StructConstant: Hashable { +public struct StructConstant: Hashable, Sendable { /// A handle to the LLVM object wrapped by this instance. public let llvm: ValueRef diff --git a/Sources/SwiftyLLVM/Values/GlobalVariable.swift b/Sources/SwiftyLLVM/Values/GlobalVariable.swift index 4febd1a9..e3537cf2 100644 --- a/Sources/SwiftyLLVM/Values/GlobalVariable.swift +++ b/Sources/SwiftyLLVM/Values/GlobalVariable.swift @@ -1,7 +1,7 @@ internal import llvmc /// A global value in LLVM IR. -public struct GlobalVariable: Global { +public struct GlobalVariable: Global, Sendable { /// A handle to the LLVM object wrapped by this instance. public let llvm: ValueRef diff --git a/Sources/SwiftyLLVM/Values/IRValue.swift b/Sources/SwiftyLLVM/Values/IRValue.swift index f8fa292b..1d6dafb1 100644 --- a/Sources/SwiftyLLVM/Values/IRValue.swift +++ b/Sources/SwiftyLLVM/Values/IRValue.swift @@ -1,7 +1,7 @@ internal import llvmc /// A value in LLVM IR. -public protocol IRValue: CustomStringConvertible { +public protocol IRValue: CustomStringConvertible, Sendable { /// A handle to the LLVM object wrapped by this instance. var llvm: ValueRef { get } diff --git a/Sources/SwiftyLLVM/Values/Instructions/FloatingPointPredicate.swift b/Sources/SwiftyLLVM/Values/Instructions/FloatingPointPredicate.swift index 93010980..eb9b453f 100644 --- a/Sources/SwiftyLLVM/Values/Instructions/FloatingPointPredicate.swift +++ b/Sources/SwiftyLLVM/Values/Instructions/FloatingPointPredicate.swift @@ -4,7 +4,7 @@ internal import llvmc /// /// - Note: Ordered means that neither operand is a QNAN while unordered means that either operand /// may be a QNAN. -public enum FloatingPointPredicate: String, Hashable { +public enum FloatingPointPredicate: String, Hashable, Sendable { /// No comparison; always false. case alwaysFalse = "false" diff --git a/Sources/SwiftyLLVM/Values/Instructions/IntegerPredicate.swift b/Sources/SwiftyLLVM/Values/Instructions/IntegerPredicate.swift index 15ae99c1..48712aa6 100644 --- a/Sources/SwiftyLLVM/Values/Instructions/IntegerPredicate.swift +++ b/Sources/SwiftyLLVM/Values/Instructions/IntegerPredicate.swift @@ -1,7 +1,7 @@ internal import llvmc /// The predicate of an integer comparison. -public enum IntegerPredicate: String, Hashable { +public enum IntegerPredicate: String, Hashable, Sendable { /// Values are equal. case eq diff --git a/Sources/SwiftyLLVM/Values/Instructions/OverflowBehavior.swift b/Sources/SwiftyLLVM/Values/Instructions/OverflowBehavior.swift index 335144ae..a581f437 100644 --- a/Sources/SwiftyLLVM/Values/Instructions/OverflowBehavior.swift +++ b/Sources/SwiftyLLVM/Values/Instructions/OverflowBehavior.swift @@ -1,5 +1,5 @@ /// The behavior that should occur on overflow during mathematical operations. -public enum OverflowBehavior { +public enum OverflowBehavior: Sendable { /// Overflow is ignored. case ignore From 7e9f0df06f70080ca61999c412745111d079cf6d Mon Sep 17 00:00:00 2001 From: Ambrus Toth Date: Mon, 14 Jul 2025 16:19:15 +0000 Subject: [PATCH 12/14] Avoid printing debug info all the time --- Sources/SwiftyLLVM/Module.swift | 17 +++++++---------- Sources/SwiftyLLVM/Types/FunctionType.swift | 7 +++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Sources/SwiftyLLVM/Module.swift b/Sources/SwiftyLLVM/Module.swift index b3a5f33c..d5d49dc9 100644 --- a/Sources/SwiftyLLVM/Module.swift +++ b/Sources/SwiftyLLVM/Module.swift @@ -812,16 +812,13 @@ public struct Module: Sendable { // Debug: Print function type and arguments if let funcType = FunctionType(calleeType) { - let functionName = Function(callee)?.name ?? "unknown" - print("DEBUG: Call to function: \(functionName)") - print("DEBUG: Expected params: \(funcType.parameters.count), Got args: \(arguments.count)") - - // Check if this is a problematic call - if funcType.parameters.count != arguments.count { - print("ERROR: Parameter count mismatch!") - print("Function: \(functionName)") - print("Expected: \(funcType.parameters.count) parameters") - print("Got: \(arguments.count) arguments") + // Check if this is a problematic call (mismatched number of parameters when not vararg) + if funcType.parameters.count != arguments.count && !funcType.isVarArg { + let functionName = Function(callee)?.name ?? "unknown" + var debugInfo = "Parameter count mismatch on LLVM function call: \(functionName)\n" + debugInfo += "Expected parameters: \(funcType.parameters.count)\n" + debugInfo += "Provided arguments: \(arguments.count)\n" + preconditionFailure(debugInfo) } } diff --git a/Sources/SwiftyLLVM/Types/FunctionType.swift b/Sources/SwiftyLLVM/Types/FunctionType.swift index e88bab05..d20c6608 100644 --- a/Sources/SwiftyLLVM/Types/FunctionType.swift +++ b/Sources/SwiftyLLVM/Types/FunctionType.swift @@ -37,5 +37,12 @@ public struct FunctionType: IRType, Hashable { return handles.map({ AnyType($0!) as IRType }) } + /// Whether the function accepts a variable number of arguments + /// + /// E.g. a function like `declare i1 @llvm.coro.suspend.retcon(...)` + public var isVarArg: Bool { + LLVMIsFunctionVarArg(llvm.raw) != 0 + } + } From e8b18dfc5853419185ab5d60e3aea213ef8e4ca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ambrus=20T=C3=B3th?= Date: Wed, 16 Jul 2025 09:59:42 +0200 Subject: [PATCH 13/14] revert cmake stuff to original repo --- cmake/TopLevelDefaults.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/TopLevelDefaults.cmake b/cmake/TopLevelDefaults.cmake index e407edd9..1036c79d 100644 --- a/cmake/TopLevelDefaults.cmake +++ b/cmake/TopLevelDefaults.cmake @@ -13,8 +13,8 @@ block() set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER) FetchContent_Declare(Hylo-CMakeModules - GIT_REPOSITORY https://github.com/tothambrus11/CMakeModules.git - GIT_TAG 697fd80f4a78d4f5e479d17b0c778c5f5cae488f + GIT_REPOSITORY https://github.com/hylo-lang/CMakeModules.git + GIT_TAG 8b9300848f5a9eaa951dc9d9627b586c875cacd9 OVERRIDE_FIND_PACKAGE ) From 23c35e8de60c6ea5edd0352fd5092b7dae743691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ambrus=20T=C3=B3th?= Date: Wed, 16 Jul 2025 10:10:47 +0200 Subject: [PATCH 14/14] Remove Swift 5 workarounds --- README.md | 5 +---- Sources/llvmshims/src/shim.cc | 13 ++----------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 54342a12..799135f3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ See also: [swift-llvm-bindings](https://github.com/apple/swift-llvm-bindings) ### Swift -This package requires Swift 5.9 +This package requires Swift 6.1 ### LLVM @@ -86,9 +86,6 @@ file for LLVM. ## Building with Swift Package Manager -**Note:** SPM builds are not supported on Windows at least until Swift -6.0 is released. - First, you need to create a `pkgconfig` file specific to your installation and make it visible to your build tools. We use a `bash` script as follows in the top-level directory of this project: diff --git a/Sources/llvmshims/src/shim.cc b/Sources/llvmshims/src/shim.cc index 3e30a28d..1cd4499a 100644 --- a/Sources/llvmshims/src/shim.cc +++ b/Sources/llvmshims/src/shim.cc @@ -2,14 +2,6 @@ #pragma warning(push) #pragma warning(disable: 4624 4244) -// According to compnerd, “a Microsoft update requires a newer clang -// than what swift ships. That’s a second chance that they pushed that -// breaks after working around this. The best option is to use a 6.0 -// pre release.” We don't want to impose that on downstream clients, -// so we use this workaround, which incidentally isn't compatible with -// Swift/C++ interop. -#define _ALLOW_COMPILER_AND_STL_VERSION_MISMATCH 1 - #endif #include "llvm-c/TargetMachine.h" @@ -24,10 +16,9 @@ // Used to create a fatal error in this file. Must follow all other #includes #undef NDEBUG #include - // Used to create a fatal error in this file. Must follow all other - // #includes +// Used to create a fatal error in this file. Must follow all other #includes - using namespace llvm; +using namespace llvm; template T* unsafe_as(U* s) {