Skip to content

Added Hashable conformance to Async(Throwing)Stream.Continuation #79457

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

Merged

Conversation

nickolas-pohilets
Copy link
Contributor

See the pitch.

@nickolas-pohilets nickolas-pohilets requested review from a team and ktoso as code owners February 18, 2025 12:13
@ktoso ktoso added the swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review label Feb 19, 2025
@ktoso
Copy link
Contributor

ktoso commented Feb 20, 2025

I think we'll need to take this through evolution; the type is not frozen and in general any public api changes need to be evolved.

@nickolas-pohilets
Copy link
Contributor Author

Evolution PR - swiftlang/swift-evolution#2700

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

This was accepted through evolution

@ktoso
Copy link
Contributor

ktoso commented Apr 12, 2025

@swift-ci please smoke test

@ktoso ktoso added swift evolution approved Flag → feature: A feature that was approved through the Swift evolution process and removed swift evolution pending discussion Flag → feature: A feature that has a Swift evolution proposal currently in review labels Apr 12, 2025
@nickolas-pohilets nickolas-pohilets force-pushed the mpokhylets/hashable-stream-continuation branch from f37c498 to d8cbaeb Compare April 13, 2025 11:25
@nickolas-pohilets nickolas-pohilets requested a review from ktoso April 13, 2025 11:26
return hasher.combine(ObjectIdentifier(storage))
}
@available(SwiftStdlib 9999, *)
public var hashValue: Int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why that, isn't the hash function enough?

Copy link
Contributor Author

@nickolas-pohilets nickolas-pohilets Apr 14, 2025

Choose a reason for hiding this comment

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

Apparently no. If omitted it gets synthesised as expected, but then test complains that it does not have availability annotations. I'm not sure if this is expected or a bug in code gen of the Hashable conformance.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this expected @lorentey ?

Copy link
Member

Choose a reason for hiding this comment

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

This definitely is a bug! Conformances with availability are a relatively recent development, and evidently we have not yet tried to combine them with synthesized requirements. The expected behavior is that the synthesized requirement would match the availability of the conformance itself.

It feels like this might be a good candidate for a starter task in compiler development.

(The hashValue as implemented matches the synthesized one; when the compiler issue is resolved, then it can simply be deleted to have it be replaced with the implicit default.)

Copy link
Member

Choose a reason for hiding this comment

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

Oh hang on -- can you tell me what test is failing?

The compiler itself seems fine with it; this compiles with no diagnostic:

@available(macOS 11, *)
public struct Foo {
  public var value: Int
}
@available(macOS 12, *)
extension Foo: Hashable {
  @available(macOS 12, *)
  public func hash(into hasher: inout Hasher) {
    hasher.combine(value)
  }
}

The generated .swiftinterface indeed doesn't set availability directly on the synthesized members (== and hashValue), but they still inherit that from the extension's own context:

import Swift
import _Concurrency
import _StringProcessing
import _SwiftConcurrencyShims
@available(macOS 11, *)
public struct Foo {
  public var value: Swift.Int
}
@available(macOS 12, *)
extension foo.Foo : Swift.Hashable {
  @available(macOS 12, *)
  public func hash(into hasher: inout Swift.Hasher)
  public static func == (a: foo.Foo, b: foo.Foo) -> Swift.Bool
  public var hashValue: Swift.Int {
    get
  }
}

This sounds like it might actually be due to an overzealous test that attempts to analyze the interface. (If my diagnosis is correct, then the choice is between seeing if the test can be adjusted, or changing the compiler to generate the extra @available attributes anyway.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The failing test was test/api-digester/stability-concurrency-abi.test

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, that makes sense.

@ktoso ktoso self-requested a review April 14, 2025 01:27
@ktoso
Copy link
Contributor

ktoso commented Apr 15, 2025

@swift-ci please smoke test

@ktoso
Copy link
Contributor

ktoso commented Apr 16, 2025

lldb-api :: functionalities/fork/concurrent_vfork/TestConcurrentVFork.py

@ktoso
Copy link
Contributor

ktoso commented Apr 16, 2025

@swift-ci please smoke test Linux

1 similar comment
@ktoso
Copy link
Contributor

ktoso commented Apr 16, 2025

@swift-ci please smoke test Linux

@ktoso
Copy link
Contributor

ktoso commented Apr 16, 2025

Unrelated failure

/home/build-user/swift-testing/Sources/Testing/ExitTests/ExitTest.swift:125:32: error: cannot find 'CapturedValue' in scope
123 |   /// child processes.
124 |   @_spi(Experimental) @_spi(ForToolsIntegrationOnly)
125 |   public var capturedValues = [CapturedValue]()
    |                                `- error: cannot find 'CapturedValue' in scope
126 | 
127 |   /// Make a copy of this instance.

@ktoso ktoso merged commit e454c0a into swiftlang:main Apr 16, 2025
3 checks passed
@nickolas-pohilets nickolas-pohilets deleted the mpokhylets/hashable-stream-continuation branch April 18, 2025 23:34
ktoso added a commit to ktoso/swift-evolution that referenced this pull request Apr 24, 2025
Was done in: swiftlang/swift#79457

We missed the 6.2 cherry pick, I'll do that
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift evolution approved Flag → feature: A feature that was approved through the Swift evolution process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants