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

underestimatedCount complexity documentation is broken #70755

Open
dabrahams opened this issue Jan 7, 2024 · 0 comments
Open

underestimatedCount complexity documentation is broken #70755

dabrahams opened this issue Jan 7, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. documentation inaccurate info Bug → documentation: Inaccurate info Sequence Area → standard library: The `Sequence` protocol standard library Area: Standard library umbrella swift 6.0

Comments

@dabrahams
Copy link
Collaborator

dabrahams commented Jan 7, 2024

Description

  /// - Complexity: O(1), except if the sequence also conforms to `Collection`.
  ///   In this case, see the documentation of `Collection.underestimatedCount`.

This was done in ea49459
The correct complexity bound is O(N) where N is the length of the sequence.

The current wording is meaningless, other than to say the complexity bound is O(N) (as given by Collection's requirements). When you are handling a Sequence, (modulo dynamic casts that you couldn't even perform when that change was made and that nobody does in practice), you don't know that it isn't a Collection. Furthermore, nearly any Sequence can be made to conform to Collection post-hoc. I don't know what made anyone think they could tighten a complexity bound on an existing protocol, but (obviously) when you do that you break anyone that had a previously-valid conformance. More generally, it is broken and wrong to loosen constraints in a refinement. In this case that would make every Collection not-a Sequence.

Reproduction

Read the docs.

Expected behavior

The docs make sense and are meaningful.

Environment

Any environment you like

Additional information

No response

@dabrahams dabrahams added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jan 7, 2024
@AnthonyLatsis AnthonyLatsis added standard library Area: Standard library umbrella documentation inaccurate info Bug → documentation: Inaccurate info swift 6.0 Sequence Area → standard library: The `Sequence` protocol and removed triage needed This issue needs more specific labels labels Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. documentation inaccurate info Bug → documentation: Inaccurate info Sequence Area → standard library: The `Sequence` protocol standard library Area: Standard library umbrella swift 6.0
Projects
None yet
Development

No branches or pull requests

2 participants