Skip to content

[Basics] Switch IdentifiableSet to use OrderedDictionary #7630

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
merged 1 commit into from
Jun 4, 2024

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 4, 2024

Motivation:

Turns IdentifiableSet into an ordered collection which should cut on flakiness in tests and other spots that expect certain ordering of elements.

Modifications:

Changes storage of IdentifiableSet from Dictionary to OrderedDictionary.

Result:

Less flakiness throughout.

Turns `IdentifiableSet` into an ordered collection which
should cut on flakiness in tests and other spots that expect
certain ordering of elements.
@xedin
Copy link
Contributor Author

xedin commented Jun 4, 2024

@swift-ci please test

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Thanks!

@MaxDesiatov MaxDesiatov added bug build system Changes to interactions with build systems modules graph Modules dependency resolution labels Jun 4, 2024
@MaxDesiatov
Copy link
Contributor

IMO definitely worth cherry-picking for 6.0.

@rauhul
Copy link
Member

rauhul commented Jun 4, 2024

I was looking at IdentifiableSet recently, is there a reason to duplicate the API surface of SetAlgebra instead of using Set<Identified<Element>>?

struct Identified<Element> where Element: Identifiable {
  var element: Element
}

extension Identified: Equatable {
  static func ==(lhs: Self, rhs: Self) -> Bool { lhs.id == rhs.id }
}

extension Identified: Hashable {
  func hash(into hasher: inout Hasher) -> Bool { hasher.combine(self.id) }
}

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented Jun 4, 2024

How would one look up an element by its ID in Set<Identified<Element>>? We also have subscripts defined on IdentifiableSet, it's a somewhat weird Dictionary/Set hybrid.

@rauhul
Copy link
Member

rauhul commented Jun 4, 2024

How would one look up an element by its ID in Set<Identified<Element>>? We also have subscripts defined on IdentifiableSet, it's a somewhat weird Dictionary/Set hybrid.

Clearly I didn't think this through enough!

@MaxDesiatov
Copy link
Contributor

For a bit more context, we were storing some of its elements in an Array previously, then for deduplication Set made more sense, and we were also storing some of those elements in dictionaries too. To make those element types Sendable and modifications local and predictable, we had to convert them from classes to structs. The synthesized Hashable and Equatable conformances on structs led to performance regressions. Use of Identifiable and IdentifiableSet were introduced to fix that. Then the only remaining hole was non-determinism when iterating through elements, which is now fixed with OrderedDictionary.

@xedin xedin merged commit 0d557ec into swiftlang:main Jun 4, 2024
5 checks passed
xedin added a commit that referenced this pull request Jun 5, 2024
- Explanation:

Turns `IdentifiableSet` into an ordered collection which should cut on
flakiness in tests and other spots that expect certain ordering of
elements.

- Scope: All uses of `IdentifiableSet` i.e. package graph.

- Main Branch PR:
#7630

- Risk: Low

- Reviewed By: @MaxDesiatov 

- Testing: No tests since the change is somewhat NFC.

(cherry picked from commit b0afde9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build system Changes to interactions with build systems modules graph Modules dependency resolution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants