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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor path model #6509

Merged
merged 1 commit into from May 4, 2023
Merged

refactor path model #6509

merged 1 commit into from May 4, 2023

Conversation

tomerd
Copy link
Member

@tomerd tomerd commented May 2, 2023

motivation: deprecate TSC, move to swift-system

changes:

  • create AbsolutePath and RelativePath in SwiftPM, at this point just a wrapper for the TSC version. In next PR we will start refactoring them
  • remove all direct imports of TSBasic and replace them with data type specific imports to help migration
  • reduce sue of TSCTestSupport, stop exporting it from SPMTestSupport
  • update all call sites and tests

@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

/// normalization, because it is normally the responsibility of the shell and
/// not the program being invoked (e.g. when invoking `cd ~`, it is the shell
/// that evaluates the tilde; the `cd` command receives an absolute path).
public struct AbsolutePath: Hashable, Sendable {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the key change


// MARK: - Custom path

extension FileSystem {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is an adapter so FS work with the "new" types

/// This string manipulation may change the meaning of a path if any of the
/// path components are symbolic links on disk. However, the file system is
/// never accessed in any way when initializing a RelativePath.
public struct RelativePath: Hashable, Sendable {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the key change

// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
Copy link
Member Author

Choose a reason for hiding this comment

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

this is a shim between utility functions in TSC and the "new" types

@@ -119,18 +133,31 @@ private extension FileSystem {
public class VirtualFileSystem: FileSystem {
Copy link
Member Author

Choose a reason for hiding this comment

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

concrete FS implementation use the TSC types

@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

"self-hosted" tests expected to fail since they do not support cross repo testing

@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

@swift-ci smoke test

@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

@swift-ci smoke test windows

@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

cc @abertelrud @compnerd this is the first step towards cleaning this up

@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test

@tomerd tomerd force-pushed the fractor/path-01 branch 2 times, most recently from d1f03e1 to 2befe02 Compare May 2, 2023 21:40
@tomerd
Copy link
Member Author

tomerd commented May 2, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test


/// Unlike ``AbsolutePath//extension``, this property returns all characters after the first `.` character in a
/// filename. If no dot character is present in the filename or first dot is the last character, `nil` is returned.
public var allExtensions: [String]? {
Copy link
Member

Choose a reason for hiding this comment

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

I guess this was a Basics-provided extension before? Might be worth keeping that separation?

/// Returns the absolute path with additional extension appended.
///
public func appending(extension: String) -> AbsolutePath {
guard !self.isRoot else { return self }
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@@ -74,7 +76,7 @@ public struct Netrc {
}
}

public struct NetrcParser {
public enum NetrcParser {
Copy link
Member

Choose a reason for hiding this comment

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

🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

swift format made me do it

Copy link
Member

Choose a reason for hiding this comment

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

That's pretty weird?

@@ -23,11 +23,11 @@ public struct SwiftVersion {
public var buildIdentifier: String?

/// The major component of the version number.
public var major: Int { return self.version.major }
Copy link
Member

Choose a reason for hiding this comment

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

😭

Copy link
Member

@neonichu neonichu left a comment

Choose a reason for hiding this comment

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

Looks good, some small comments

@tomerd
Copy link
Member Author

tomerd commented May 3, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test

@tomerd
Copy link
Member Author

tomerd commented May 3, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test windows

@tomerd
Copy link
Member Author

tomerd commented May 3, 2023

@compnerd does the windows build failure make sense you? looks like a compiler crash

@compnerd
Copy link
Collaborator

compnerd commented May 3, 2023

It is an assertion failure:

Assertion failed: Ptr && "Cannot dereference a null Type!", file C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\swift\include\swift/AST/Type.h, line 249

Looks like a swift compiler issue.

@MaxDesiatov
Copy link
Member

@swift-ci test windows

@tomerd
Copy link
Member Author

tomerd commented May 3, 2023

@compnerd its only crashing in windows tho, is this something you can help with?

@compnerd
Copy link
Collaborator

compnerd commented May 3, 2023

I think that @xymus would be better able to help than I would. However, the last run seems to be failing differently:

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\sourcekit-lsp\Sources\SKSwiftPMWorkspace\SwiftPMWorkspace.swift:108:59: error: cannot convert value of type 'TSCBasic.AbsolutePath' to expected argument type 'Basics.AbsolutePath'

    var location = try Workspace.Location(forRootPackage: packageRoot, fileSystem: fileSystem)

                                                          ^

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\sourcekit-lsp\Sources\SKSwiftPMWorkspace\SwiftPMWorkspace.swift:179:51: error: cannot convert value of type 'TSCBasic.AbsolutePath' to expected element type 'Basics.AbsolutePath'

      rootInput: PackageGraphRootInput(packages: [packageRoot]),

                                                  ^

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\sourcekit-lsp\Sources\SKSwiftPMWorkspace\SwiftPMWorkspace.swift:238:28: error: cannot convert return expression of type 'Basics.AbsolutePath' to return type 'TSCBasic.AbsolutePath'

    return buildParameters.buildPath

           ~~~~~~~~~~~~~~~~^~~~~~~~~

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\sourcekit-lsp\Sources\SKSwiftPMWorkspace\SwiftPMWorkspace.swift:242:51: error: cannot convert return expression of type 'AbsolutePath' to return type 'AbsolutePath?'

    return buildParameters.indexStoreMode == .off ? nil : buildParameters.indexStore

           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\sourcekit-lsp\Sources\SKSwiftPMWorkspace\SwiftPMWorkspace.swift:360:19: error: cannot convert value of type 'TSCBasic.AbsolutePath' to expected argument type 'Basics.AbsolutePath'

        filePath: path, 

                  ^

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\sourcekit-lsp\Sources\SKSwiftPMWorkspace\SwiftPMWorkspace.swift:422:55: error: binary operator '==' cannot be applied to operands of type 'TSCBasic.AbsolutePath' and 'Basics.AbsolutePath'

      for package in packageGraph.packages where path == package.manifest.path {

                                                 ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~

C:\Users\swift-ci\jenkins\workspace\swiftpm-PR-windows\sourcekit-lsp\Sources\SKSwiftPMWorkspace\SwiftPMWorkspace.swift:506:70: error: binary operator '==' cannot be applied to operands of type 'Basics.AbsolutePath' and 'TSCBasic.AbsolutePath'

    let compilePath = try td.compilePaths().first(where: { $0.source == nativePath })

                                                           ~~~~~~~~~ ^  ~~~~~~~~~~

@tomerd
Copy link
Member Author

tomerd commented May 3, 2023

@compnerd I think its because @MaxDesiatov forgot to include the LSP PR

@tomerd
Copy link
Member Author

tomerd commented May 3, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test windows

motivation: deprecate TSC, move to swift-system

changes:
* create AbsolutePath and RelativePath in SwiftPM, at this point just a wrapper for the TSC version. In next PR we will start refactoring them
* remove all direct imports of TSBasic and replace them with data type specific imports to help migration
* reduce sue of TSCTestSupport, stop exporting it from SPMTestSupport
* update all call sites and tests
@tomerd
Copy link
Member Author

tomerd commented May 4, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test windows

@tomerd
Copy link
Member Author

tomerd commented May 4, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test

@tomerd tomerd enabled auto-merge (squash) May 4, 2023 19:37
@tomerd
Copy link
Member Author

tomerd commented May 4, 2023

apple/sourcekit-lsp#741

@swift-ci smoke test windows

@tomerd tomerd merged commit 828c41f into apple:main May 4, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants