Skip to content

[4.2][migrator] Migrate UIApplicationMain #17640

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

Conversation

nathawes
Copy link
Contributor

@nathawes nathawes commented Jun 29, 2018

CCC Info

Explanation

In Swift 4.2 the type of second parameter of UIApplicationMain exactly matches the type of CommandLine.unsafeArgv so it can be called as below:

UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, ...)

This is how it was intended to be in Swift 4 as well, but the types had optionality differences, so callers instead had to do something similar to the below example, from the Firefox-iOS project:

let pointer = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(
    to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))
UIApplicationMain(CommandLine.argc, pointer, ...)

Now that the type of UIApplicationMain's second parameter has been updated to match CommandLine.unsafeArgv, this workaround is no longer needed. This patch adds a new migration that simply replaces the second argument with CommandLine.unsafeArgv at all call sites where CommandLine.argc is passed as the first argument, as in 99% of cases this is what users would have written had the types matched.

There is an open issue for providing a deprecated version with the old type signature, so we simply leave any callers that don't pass CommandLine.argc for the first argument as they are.

  • Radar: Resolves rdar://problem/40045693.
  • Scope of issue: Affects projects calling UIApplicationMain that migrate to Swift 4.2.
  • Origination: SDK change in the type signature of UIApplicationMain.
  • Risk: Low. Only affects the migration of projects calling UIApplicationMain and the change is small.
  • Reviewed by: Xi Ge
  • Testing: Added regression tests, existing tests pass, and migrated the Firefox-iOS project with no new issues (and this one fixed).

In Swift 4.2 the second parameter of UIApplicationMain exactly matches the type
of CommandLine.unsafeArgv so it can be called as below:

UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, ...)

This is how it was intended to be in Swift 4 as well, but the types had
optionality differences, so callers instead had to do something like the below
example from the Firefox-iOS project:

let pointer = UnsafeMutableRawPointer(CommandLine.unsafeArgv).bindMemory(
    to: UnsafeMutablePointer<Int8>.self, capacity: Int(CommandLine.argc))
UIApplicationMain(CommandLine.argc, pointer, ...)

This migration simply replaces the the second argument with
CommandLine.unsafeArgv if the first argument is CommandLine.argc.

There is an open issue for providing a deprecated version with the old type so
we simply leave as is any callers that don't pass argc for the first argument.

Resolves rdar://problem/40045693.
@nathawes nathawes requested a review from nkcsgexi June 29, 2018 21:09
@nathawes
Copy link
Contributor Author

Cherry-pick of #17619

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

LGTM!

@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes merged commit 3fa6d67 into swiftlang:swift-4.2-branch Jun 29, 2018
@nathawes nathawes deleted the rdar40045693-migrate-ui-application-main-4.2 branch June 29, 2018 23:33
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.

2 participants