Skip to content

[SE-0163] Migrate from deprecated Unicode APIs #32920

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

Closed

Conversation

benrimmington
Copy link
Contributor

UnicodeCodec, UnicodeDecodingResult, and some typealiases were deprecated by the SE-0163 proposal.

Copy link
Contributor Author

@benrimmington benrimmington left a comment

Choose a reason for hiding this comment

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

See also: #33167, #33175

@benrimmington
Copy link
Contributor Author

@swift-ci Please smoke test

Comment on lines -34 to -49
@inlinable
public static func == (
lhs: UnicodeDecodingResult,
rhs: UnicodeDecodingResult
) -> Bool {
switch (lhs, rhs) {
case (.scalarValue(let lhsScalar), .scalarValue(let rhsScalar)):
return lhsScalar == rhsScalar
case (.emptyInput, .emptyInput):
return true
case (.error, .error):
return true
default:
return false
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be synthesized by the compiler.

Copy link
Member

Choose a reason for hiding this comment

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

This is not exactly the same, because the synthesized definition isn’t inlinable. How that will affect performance/code size of code using these APIs is difficult to predict.

Comment on lines +265 to +273
}

extension Unicode.UTF8 {
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 non-deprecated APIs could be moved into UTF8.swift:

  • Unicode.UTF8.isContinuation(_:)
  • Unicode.UTF8._nullCodeUnitOffset(in:)
  • Unicode.UTF8._decodeOne(_:) (used in UnicodeLongTest.swift)

The deprecated APIs could be moved into MigrationSupport.swift:

  • UnicodeDecodingResult enum,
  • UnicodeCodec protocol and conformances.

The unused APIs could be moved into LegacyABI.swift:

  • Unicode.UTF16._decodeOne(_:)
  • transcode(_:_:_:_:stopOnError:) (unavailable since Swift 3).

@benrimmington benrimmington requested a review from CodaFi July 28, 2020 19:47
@benrimmington
Copy link
Contributor Author

@CodaFi Please could you review, and merge if possible?

I've added some comments above, for anything which requires more attention or follow-up PRs.

Copy link
Contributor

@CodaFi CodaFi left a comment

Choose a reason for hiding this comment

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

Benchmarks and test changes LGTM. But @milseman or @airspeedswift should sign off on the stdlib changes

@CodaFi
Copy link
Contributor

CodaFi commented Jul 28, 2020

@swift-ci benchmark

@swift-ci

This comment has been minimized.

@milseman
Copy link
Member

I realize this went through SE quite a while ago, but I think it's a bad idea to formally remove the Unicode aliases, especially for UTF8/UTF16.

@benrimmington
Copy link
Contributor Author

@milseman Can we keep the typealiases at deprecated: 100000 indefinitely?

I've copied the simple renames into #33167, in case they can be merged sooner; and to make it easier to review this PR (after rebasing).

//===--- Slicing Support --------------------------------------------------===//

// @available(swift,deprecated: 5.0, renamed: "Unicode.UTF8")
@available(swift, deprecated: 100000, /*obsoleted: TODO,*/ renamed: "Unicode.UTF8")
Copy link
Member

Choose a reason for hiding this comment

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

Even if these deprecations were part of SE-0163, and even if we tie them into a new language mode, implementing them at this point would be wildly disruptive. Swift 4.0 with SE-0163 was released three years ago; a huge amount of Swift code has been written since then that uses these names. Thus, I believe these changes would deserve a standalone proposal.

Copy link
Member

@milseman milseman Jul 29, 2020

Choose a reason for hiding this comment

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

Also, that batch of SEs were part of a larger attempt to reformulate strings that didn't pan out in practice. They have several portions that weren't fully thought through, much less implemented, so I don't think we want to blindly apply them without some reevaluation.

@lorentey
Copy link
Member

Can we keep the typealiases at deprecated: 100000 indefinitely?

Why? The version number 100000 has no special meaning, and it should not appear in any compiler diagnostics or generated documentation. If the reason why SE-0163 intended to deprecate these names still stands, then I think we should reconfirm this through swift-evolution and set the deprecation to a valid version number.

@benrimmington
Copy link
Contributor Author

@lorentey Version number 100000 is from the API_TO_BE_DEPRECATED macro in the <os/availability.h> header.

It seems to affect only the documentation, at least when applied to an OS availability attribute.

For example, in SwiftUI the colorScheme(_:) method has the generated interface:

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
extension View {

    /// Sets this view's color scheme.
    ///
    /// Use `colorScheme(_:)` to set the color scheme for the view to which you
    /// apply it and any subviews. If you want to set the color scheme for all
    /// views in the presentation, use ``View/preferredColorScheme(_:)``
    /// instead.
    ///
    /// - Parameter colorScheme: The color scheme for this view.
    ///
    /// - Returns: A view that sets this view's color scheme.
    @available(iOS, introduced: 13.0, deprecated: 100000.0, renamed: "preferredColorScheme(_:)")
    @available(OSX, introduced: 10.15, deprecated: 100000.0, renamed: "preferredColorScheme(_:)")
    @available(tvOS, introduced: 13.0, deprecated: 100000.0, renamed: "preferredColorScheme(_:)")
    @available(watchOS, introduced: 6.0, deprecated: 100000.0, renamed: "preferredColorScheme(_:)")
    @inlinable public func colorScheme(_ colorScheme: ColorScheme) -> some View
}

@benrimmington
Copy link
Contributor Author

@swift-ci Please smoke test

@lorentey
Copy link
Member

lorentey commented Jul 29, 2020

Version number 100000 is from the API_TO_BE_DEPRECATED macro in the <os/availability.h> header.

Unfortunately AFAIK that only applies to C. :-( We could adopt it in Swift, but without the macro name the number seems opaque. Oh, the fact that it shows up in generated interfaces is rather terrible. 😱

The 9999s we use elsewhere set an unfortunate precedent for doing such things; I guess it's time to replace them too with a better system.

@benrimmington benrimmington deleted the se-0163-migration branch August 7, 2020 09:18
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.

5 participants