Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

swift: force-unwrap file handles in swift-tools-support-core #269015

Merged
merged 4 commits into from
Jan 13, 2024

Conversation

paveloom
Copy link
Member

@paveloom paveloom commented Nov 21, 2023

Description of changes

Fixes the following build errors:

/build/swift-tools-support-core-ac4871e/Sources/TSCBasic/FileSystem.swift:428:24: error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
        defer { fclose(fp) }
                       ^
/build/swift-tools-support-core-ac4871e/Sources/TSCBasic/FileSystem.swift:458:24: error: value of optional type 'UnsafeMutablePointer<FILE>?' (aka 'Optional<UnsafeMutablePointer<_IO_FILE>>') must be unwrapped to a value of type 'UnsafeMutablePointer<FILE>' (aka 'UnsafeMutablePointer<_IO_FILE>')
        defer { fclose(fp) }
                       ^

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Priorities

Add a 馃憤 reaction to pull requests you find important.

@paveloom paveloom changed the title swiftpm: force-unwrap file handles in swift-tools-support-core swift: force-unwrap file handles in swift-tools-support-core Nov 21, 2023
Copy link
Contributor

@hcsch hcsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file handles are guaranteed to be non-nil at the point of unwrapping (otherwise the defer statements would not be reached) so force unwrapping them is sane.
I've tested the commits from this PR locally (rebased onto current nixos-unstable) on my Linux x86_64 machine and swift-tools-support-core and with it also swiftpm build for me and can be used to successfully build a swift package.

Thanks for making the PR :)

@hbjydev
Copy link
Contributor

hbjydev commented Jan 2, 2024

Can we get an urgent merge on this please? Swift has now been broken for over a month...

@donn
Copy link

donn commented Jan 7, 2024

+1 for urgency. Is there anything any of us can do to help this get merged faster?

Copy link
Contributor

@stephank stephank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Maybe the Swift toolchain needs some more maintainers, in light of this.

The change looks good, though.

@hbjydev
Copy link
Contributor

hbjydev commented Jan 10, 2024

Sorry for the delay. Maybe the Swift toolchain needs some more maintainers, in light of this.

Probably not wrong @stephank -- I'd volunteer myself but I don't know enough about the toolchain to be anywhere near maintainer lmao

@wegank
Copy link
Member

wegank commented Jan 11, 2024

Result of nixpkgs-review pr 269015 run on x86_64-linux 1

2 packages failed to build:
  • sourcekit-lsp (swiftPackages.sourcekit-lsp)
  • swift-format (swiftPackages.swift-format)
5 packages built:
  • swift (swiftPackages.swift)
  • swift.man (swiftPackages.swift.man)
  • swiftPackages.swift-docc
  • swiftPackages.swift-driver
  • swiftpm (swiftPackages.swiftpm)

@wegank
Copy link
Member

wegank commented Jan 11, 2024

Similar error for both failed packages:

error: builder for '/nix/store/91jlv5vxakkfsshlsdb091s7xli09q65-swift-format-5.8.drv' failed with exit code 1;
       last 10 log lines:
       >         defer { fclose(fp) }
       >                        ^
       > /build/swift-format-5.8-src/.build/checkouts/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift:481:24: note: coalesce using '??' to provide a default when the optional value contains 'nil'
       >         defer { fclose(fp) }
       >                        ^
       >                           ?? <#default value#>
       > /build/swift-format-5.8-src/.build/checkouts/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift:481:24: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
       >         defer { fclose(fp) }
       >                        ^
       >                          !
       For full logs, run 'nix log /nix/store/91jlv5vxakkfsshlsdb091s7xli09q65-swift-format-5.8.drv'.
error: builder for '/nix/store/w6c8ysbq039j51fkq9crzrd9rj5viwzs-sourcekit-lsp-5.8.drv' failed with exit code 1;
       last 10 log lines:
       >                           ?? <#default value#>
       > /build/sourcekit-lsp-5.8-src/.build/checkouts/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift:458:24: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
       >         defer { fclose(fp) }
       >                        ^
       >                          !
       > [40/634] Compiling llvmSupport Path.cpp
       > [40/634] Compiling llvmSupport SourceMgr.cpp
       > [40/634] Compiling llvmSupport Signals.cpp
       > [40/634] Compiling llvmSupport Program.cpp
       > [40/634] Compiling llvmSupport Process.cpp
       For full logs, run 'nix log /nix/store/w6c8ysbq039j51fkq9crzrd9rj5viwzs-sourcekit-lsp-5.8.drv'.
error: 2 dependencies of derivation '/nix/store/b67sbs9c5zq3xp6fmd4lj49krs73ax1p-review-shell.drv' failed to build

Copy link
Contributor

@stephank stephank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now. We should probably find a better structure for patches in shared swiftpm deps within the toolchain, but I'd rather have things working soon.

patchFlags may be able to replace the swiftpmMakeMutable hack, I'm not sure. It may not have been around when the swiftpm code was written. But I think that's something we should look at separately as well.

@wegank wegank merged commit a291d04 into NixOS:master Jan 13, 2024
22 checks passed
@paveloom paveloom deleted the swiftpm branch January 14, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants