Commit Graph

189 Commits

Author SHA1 Message Date
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
Pavel Yaskevich
4885fd4203 [Mangling/ABI] NFC: Fix Migrator tests to reflect label mangling changes 2017-12-18 15:45:50 -08:00
Mishal Shah
1006a6e76c Merge pull request #13259 from rudkx/do-not-decay-iuo-to-optional
For Swift 3/4 mode, do not treat IUOs in illegal positions as Optionals.
2017-12-04 17:48:05 -08:00
Mark Lacey
73a492dc4f For Swift 3/4 mode, do not treat IUOs in illegal positions as Optionals.
Instead, just emit a deprecation warning and suggest switching to Optionals.

The old behavior caused several projects to break, so before we change
the behavior here we need to investigate whether we can mitigate most
of those breaks.
2017-12-04 16:15:13 -08:00
Nathan Hawes
f3e9685d88 [migrator] Fix missed dollar arg migration in closures relying on implicit destructuring of tuple type arg.
func foo(_: ((Int, Int)) -> Bool) {}
foo({ $0 > $1 }) // doesn't need migration
let x: ((Int, Int)) -> Bool = { $0 > $1 } // but this does
func bar() -> ((Int, Int)) -> Bool {
  return {$0 > $1} // and this does
}
2017-12-04 11:33:36 -08:00
Ben Cohen
dcab9493ae Removed some warnings (#12753) 2017-11-30 15:12:56 -08:00
Mark Lacey
8b55a0f61b SE-0054: Rework diagnostics for IUOs and revise Swift 3 /4 semantics.
For Swift 3 / 4:

Deprecate the spelling "ImplicitlyUnwrappedOptional", emitting a warning
and suggesting "!" in places where they are allowed according to
SE-0054.

In places where SE-0054 disallowed IUOs but we continued to accept them
in previous compilers, emit a warning suggesting "Optional" or "?"  as
an alternative depending on context and treat the IUO as an Optional,
noting this in the diagnostic.

For Swift 5:

Treat "ImplicitlyUnwrappedOptional" as an error, suggesting
"!" in places where they are allowed by SE-0054.

In places where SE-0054 disallowed IUOs, emit an error suggestion
"Optional" or "?" as an alternative depending on context.
2017-11-18 11:41:53 +09:00
Xi Ge
f2ef42baed [migrator] When renaming a function decl, we should use underscore to represent empty external argument label. rdar://34569243 (#12221) 2017-10-02 12:31:09 -07:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00
Xi Ge
476534d1e2 migrator: handle qualified replacement for member reference expression. rdar://32845918 (#10593)
Previously, we only handle dot syntax call expression for qualified
replacement, i.e. changing from A.a to B.b. This patch teaches the tool
to handle the migration of member reference expression tool.
2017-06-26 15:47:17 -07:00
David Farler
789bd3749f [Migrator] Use toLowercaseWord to lowercase SetterToProperty changes
Post-commit review follow-up:
This works better for properties that were all-caps, such as `URL`.

Thanks @harlanhaskins for the tip!

rdar://problem/32845968
2017-06-26 12:53:15 -07:00
David Farler
71e38d85d4 [Migrator] Make sure to lowercase properties in SetterToProperty
Previously we were only stripping `set` from the name and not
lowercasing the property.

rdar://problem/32845968
2017-06-23 16:37:16 -07:00
David Farler
12ff3794bc [Migrator] Don't run AST passes when in Swift 4 or later
AST passes assume that you are migrating from a version earlier
than Swift 4, where declaration references and type names may be
unconditionally renamed if their USRs match.

For example, this can happen for TypeMemberDiffItem entries where the
Objective-C USR is the same in Swift 3 and Swift 4, but the type is
spelled differently in Swift 4. A concrete example of this is:

`NSDocumentTypeDocumentAttribute` (Swift 3) ->
  `NSAttributedString.DocumentAttributeKey` (Swift 4).

Although this declaration is imported differently in Swift 4, its
Objective-C USR is `c:@NSDocumentTypeDocumentAttribute` for both.

rdar://problem/32604558
2017-06-23 14:04:07 -07:00
David Farler
9c1fa89d41 [Migrator] Remove closure shorthand prefixing.
In https://github.com/apple/swift/pull/10414, some SE-0110 features
were backed out, so the Migrator no longer needs to add `$0` shorthand
prefixing.

rdar://problem/32907276
2017-06-21 14:25:53 -07:00
David Farler
c7e01f2152 Build fix: Update test/Migrator/no_duplicate_aarch64_use_tbi.swift
NFC.
2017-06-21 14:16:56 -07:00
David Farler
177718bf56 [Migrator] Remove some now unnecessary tuple destructuring
Some changes for SE-0110 were backed out in
https://github.com/apple/swift/pull/10414, so the migrator no longer
needs to add its own tuple destructuring.

rdar://problem/32513074
2017-06-20 17:57:48 -07:00
Mark Lacey
1c9f85fc9b Tweak test to make it fail to compile regardless of SE-0110. 2017-06-15 12:07:26 -07:00
David Farler
2b0e04869c [Migrator] Expand tuple destructuring to support tuple input types
The migrator pass that converts single-argument function input types
doesn't handle the case when the function input has a label and is
therefore a tuple. Expand it to handle that possibility.

rdar://problem/32477319
2017-06-14 14:21:51 -07:00
David Farler
b7ca27b38f [Migrator] Remove remap file for primary input at the start of migration
If a file is run through the migration workflow a second or third time,
but fails to compile in its current state in Swift 4, it might be possible
for the previous remap file to get picked up, resulting in the old changes
getting applied twice or at the wrong offsets. At the start of the migration,
proactively remove the remap file to prevent this.

rdar://problem/32545844
2017-06-14 14:21:51 -07:00
David Farler
c2876dfb69 [Migrator] Migrate x.toIntMax() to Int64(x)
These protocol methods were hard-obsoleted in Swift 4.

rdar://problem/32437759
2017-06-14 14:21:51 -07:00
David Farler
e55191f7d5 [Migrator] Don't take redundant replacements during AST Passes
We already had this functionality in the FixitApplyDiagnosticConsumer,
but we also need it in the AST passes because different entries in the
API diff data may drive identical fix-its, namely a general type rename,
which can occur anywhere a DeclRef appears, but also for function overrides'
parameter type changes, which are context specific.

rdar://problem/32431533
2017-06-14 14:21:51 -07:00
Ben Langmuir
a1893460c2 [test] Fix REQUIRES lines in test
Attempt to fix rdar://problem/32470725
2017-06-14 14:21:51 -07:00
David Farler
df45a9ba6b [Migrator] Don't add -aarch64-use-tbi twice
Setting up an invocation adds -aarch64-use-tbi if the target is for
AArch64. In the fix-it passes, we inherit the frontend options which
already has it from the driver passing it down to the frontend.

rdar://problem/32284152
2017-06-14 14:21:51 -07:00
Xi Ge
7b34ab2878 [test][migrator] Add a AppKit test for changing an overriding function to an overriding property. 2017-06-14 14:21:51 -07:00
David Farler
eaa515b9e3 [Migrator] Separate Float80 test to x86_64 platform
Build fix - the reference to Float80 is failing on iOS bots because
the declaration is guarded by an #if.

rdar://problem/32317183
2017-06-14 14:21:51 -07:00
David Farler
6c08f802a6 [Migrator] Don't issue rewrites when diagnostics seen more than once
The clang::RewriteBuffer can do weird things when seeing multiple
replacements where the replacement text is one character longer or
one character shorter than the range it is replacing.

rdar://problem/32234525
2017-06-14 14:21:51 -07:00
David Farler
d19e6a4f8e [Migrator] Migrator.nsopengl_openglversion.swift only runs on macOS
Add a requires line to the test as such.

rdar://problem/32235754
2017-06-14 14:21:51 -07:00
David Farler
e12e077331 [Migrator] Add specific tests for migration to Swift.abs
rdar://problem/31070486
2017-06-14 14:21:50 -07:00
David Farler
970127b745 [Migrator] Add special-case migration for NSOpenGLGetVersion
This was added in the AppKit overlay as a part of general
AppKit API improvements for Swift 4.

rdar://problem/32178777
2017-06-14 14:21:50 -07:00
Xi Ge
17bbad5cdf [test] migrator: correct a test. 2017-06-14 14:21:50 -07:00
Nathan Hawes
07db112f0c [Migrator] Update appkit tests and overlay.json for recently added transformations. 2017-06-14 14:21:50 -07:00
Nathan Hawes
317f69157d [Migrator] Update overlay.json with config for Appkit SDK changes not picked up by the differ
Also add tests covering these API changes. Changes that the migrator doesn't currently support are commented out.
2017-06-14 14:21:50 -07:00
Nathan Hawes
1fdd80ea9a [Migrator] Add initial test for appkit API changes
Resolves rdar://problem/31977848.
2017-06-14 14:21:50 -07:00
Nathan Hawes
39902c927a [test] Re-enable test/Migrator/wrap-optional.swift now the fix has been merged in from github. 2017-06-14 14:21:50 -07:00
Nathan Hawes
d14aa19884 [test] Fix and re-enable test/Migrator/rdar31892850.swift 2017-06-14 14:21:50 -07:00
Arnold Schwaighofer
2fe708aaa8 Disable failing Mirgrator/wrap_optional test
rdar://31897426
2017-06-14 14:21:50 -07:00
Arnold Schwaighofer
005f85cf3c Disable test/Migrator/rdar31892850.swift
rdar://31897099
2017-06-14 14:21:50 -07:00
Nathan Hawes
1d05066891 [migrator] Fix remap entries getting merged incorrectly in some cases. Resolves rdar://problem/31892850. 2017-06-14 14:21:50 -07:00
Robert Widmann
8474340378 Clear the right directory 2017-06-04 15:07:21 -07:00
Robert Widmann
71bf312a25 Migrate the rest of the tests to %empty-directory 2017-06-04 11:08:39 -07:00
Xi Ge
9f456b19a3 migrator: use the right method to get the location of return type. rdar://32545812
TypeLoc::getLoc() is not necessarily the start location of the type repr.
2017-06-02 15:17:24 -07:00
Xi Ge
fa78d9259e migrator/test: move all API diff data files to Inputs directory. NFC (#10074) 2017-06-02 14:20:35 -07:00
Xi Ge
55843a29be migrator: compare sub-kind when checking if two diff items are equivalent to avoid dropping information. rdar://32431567 2017-06-01 18:03:23 -07:00
Xi Ge
0b8b0207e6 migrator: teach the tool to handle qualified replacement. rdar://32466196 2017-06-01 13:15:12 -07:00
David Farler
0a86e66f60 [Migrator] Add return keyword when adding temp bindings in single-expression closures
The migrator pass to add tuple destructuring that now needs to add a
`return` statement for closures that were once single-expression but are
no longer because of the added statement to do the binding.

rdar://problem/32433206
2017-05-31 13:37:35 -07:00
David Farler
726adfb83e [Migrator] Don't pick up extraneous argument label fix-it
This can be incorrectly reported by the type-checker when
argument arity doesn't match in trailing closure arguments.
This diagnostic isn't generally useful for the migrator.

rdar://problem/32477119
rdar://problem/32432254
2017-05-31 11:43:09 -07:00
David Farler
f1ab1572c4 [Migrator] Don't take var -> let fix-it
This isn't generally useful for Swift 4 migration and in some cases
can result in code that doesn't compile, like `for let i in ...`.

rdar://problem/32390791
rdar://problem/32390726
2017-05-24 16:47:38 -07:00
Xi Ge
c7b4e36476 [migrator] Handle renaming from explicit argument label to empty argument label at call sites. rdar://32241559 (#9873) 2017-05-23 11:34:05 -07:00
Xi Ge
1019396663 [migrator] Handle getter function to property change in function overrides. (#9844)
We used to only migrate them in call sites, e.g. changing from
``p.getHeight()`` to ``p.Height``. However, with experimenting on more real-world
projects, we realize migrating overrides is equally important.

rdar://32265583
2017-05-22 16:11:53 -07:00
Ben Langmuir
257c1a6caf [migrator] Fix cities vs. Cities case consistency in tests 2017-05-19 10:41:15 -07:00