Commit Graph

104 Commits

Author SHA1 Message Date
Xi Ge
bc73e4310e Sema: missing switch case fixits should print payload names explicitly instead of printing underscores. rdar://32121806 (#10409) 2017-06-20 14:13:37 -07:00
Xi Ge
b6d753067b FixCode: Add a new line between switch label and the code placeholder. rdar://32121847 (#9576) 2017-05-13 12:21:48 -07:00
Robert Widmann
ce6862731f Improve multi-file decompositions through validation 2017-05-02 00:31:03 -04:00
Robert Widmann
39494b2ba2 Rearrange test code for exhaustiveness 2017-04-28 02:06:39 -04:00
Maxim Moiseev
767e8f31ac Merge pull request #3796 from apple/new-integer-protocols
New integer protocols
2017-04-17 16:46:09 -07:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -07:00
Max Moiseev
b9fb3badc8 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-03-22 12:30:24 -07:00
Xi Ge
b4cf37bf7d Sema: several improvements on missing switch cases diagnostics. (#8026)
1. Make sure the actions taken by fixits are reflected in diagnostics messages.
2. Issue missing cases diagnostics at the start of the switch statement instead of its end.
3. Use <#code#> instead of <#Code#> in the stub.
2017-03-10 19:32:37 -08:00
Max Moiseev
835b8809d2 Merge branch 'master' into new-integer-protocols 2017-03-07 16:18:54 -08:00
Xi Ge
8ec3bd3c0a [FixCode] When fixing missing enum elements in a switch statement, print associated payloads as well. (#7899) 2017-03-03 13:07:35 -08:00
Xi Ge
daac020c61 Sema: Reject empty switch statements during type checking so that we can issue fixits to fill the unhandled switch cases. (#7766) 2017-02-25 08:01:13 -08:00
Xi Ge
d12d3c18ca FixCode: add a fixit to insert the missing enum element cases in switch statements. (#7759)
This doesn't work on entirely empty switch block because we reject such statement during parsing.
2017-02-24 18:09:30 -08:00
Max Moiseev
d128ed42b0 Merge remote-tracking branch 'origin/master' into new-integer-protocols 2017-01-19 14:16:32 -08:00
Max Moiseev
a167238d1d Fixing more tests 2017-01-12 15:54:56 -08:00
Matthew Carroll
0e09bbbb83 [DiagnosticsQoI] SR-3359: Add a fix-it to remove @discardableResult on functions that return Void or Never (#6681)
This commit adds a fix-it to remove @discardableResult on functions that return Void or Never. The fix-it is at the warning level. A test was added to verify that the fix-it removes the @discardableResult. This issue was reported in SR-3359:
https://bugs.swift.org/browse/SR-3359

Changes:
TypeCheckAttr.cpp: implemented AttributeChecker::visitDiscardableResultAttr to add a fix-it to remove @discardableResult on functions returning Void or Never.

DiagnosticsSema.def: Added a warning with a diagnostic message.

LoggingWrappers.swift.gyb, HashedCollections.swift.gyb: Removed @discardableResult on functions returning Void.

fixits-apply-all.swift, fixits-apply-all.swift.result: Added tests to verify that @discardableResult is removed from functions returning Void or Never.
2017-01-11 15:12:36 -08:00
Doug Gregor
e97ab635ea [Constraint solver] Separate bridging conversions from other conversions.
Previously, bridging conversions were handled as a form of "explicit
conversion" that was treated along the same path as normal
conversions in matchTypes(). Historically, this made some
sense---bridging was just another form of conversion---however, Swift
now separates out bridging into a different kind of conversion that is
available only via an explicit "as". This change accomplishes a few
things:

* Improves type inference around "as" coercions. We were incorrectly
  inferring type variables of the "x" in "x as T" in cases where a
  bridging conversion was expected, which cause some type inference
  failures (e.g., the SR-3319 regression).

* Detangles checking for bridging conversions from other conversions,
  so it's easier to isolate when we're applying a bridging
  conversion.

* Explicitly handle optionals when dealing with bridging conversions,
  addressing a number of problems with incorrect diagnostics, e.g.,
  complains about "unrelated type" cast failures that would succeed at
  runtime.

Addresses rdar://problem/29496775 / SR-3319 / SR-2365.
2016-12-21 13:46:14 -08:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Robin Kunde
71364d0d09 fix SR-3168: add fix-it for "'optional' can only be applied to protocol members" (#5717) 2016-11-11 14:00:45 +09:00
practicalswift
2024316e38 [gardening] Remove accidental trailing whitespace (" " and "\t") 2016-10-30 10:59:02 +01:00
Rintaro Ishizaki
202779dea1 [QoI] Don't enclose single type identifier with parens
in fixit for deprecated protocol composition with trailing characters.

protocol<>?       => Any?
protocol<P1>?     => P1?
protocol<P1, P2>? => (P1 & P2)?
2016-10-12 16:41:19 +09:00
practicalswift
c4a6c054b1 Merge pull request #4855 from practicalswift/spacing-consistency
[gardening] Increase consistency with regards to spacing after colons
2016-09-23 11:20:23 +02:00
Jordan Rose
b9e1d4c21c Don't use construction to convert literals in rawValue fix-it. (#4934)
Input:  panel.styleMask = 8345
Old output:  panel.styleMask = NSWindowStyleMask(rawValue: UInt(8345))
New output:  panel.styleMask = NSWindowStyleMask(rawValue: 8345)

rdar://problem/26681232
2016-09-22 17:36:41 -07:00
practicalswift
ef8e43b519 [gardening] Increase consistency with regards to spacing after colons 2016-09-22 16:28:57 +02:00
Jordan Rose
821cdf368d Merge pull request #4910 from jrose-apple/fix-it-swift_newtype-rawValue
Use the existing '.rawValue' fix-it to handle unwrapping objects too.

rdar://problem/26678862
2016-09-21 18:28:40 -07:00
Jordan Rose
693fd9d455 Use the existing '.rawValue' fix-it to handle unwrapping objects too.
We could probably make this even more general, but this specifically
avoids trying to insert an "as AnyObject" fix-it, which will now work
but probably produce an incorrect result. This comes up when working
with swift_newtype wrappers of CF types being passed to CFTypeRef
parameters.

rdar://problem/26678862
2016-09-21 17:16:26 -07:00
Jordan Rose
fea7878806 Auto-apply the new generic parameter fix-it during migration.
Last bit of rdar://problem/27087345.
2016-09-21 18:04:14 -06:00
Jordan Rose
1d7ad9e38a Better generic fix-its for types as well as construction and casts.
Slava pointed out that we have an existing version of the code from
the previous commit that's only used when checking types. Replace it
with the new code, which handles more cases.
2016-09-21 18:04:14 -06:00
Jordan Rose
6bc61fe8ce Fix a fix-it to cast to the destination type, not the source type.
Copy/paste issue, most likely.
2016-09-21 16:40:40 -07:00
Xi Ge
1f6670f113 [Parser] Correct the fixit for protocol composition's syntax change (#4483)
* [Parser] Correct a fixit to preserve the trailing content after replacing Protocol<A, B>. rdar://27992964

When migrating, we found our fixit to replace the old protocol composition syntax, namely "Protocol<A, B>",
to the new syntax, "A & B", does not preserve the trailing content after '>'. For instance, we replace "Protocol<A, B>?"
with "A & B". This patch fixes the issue by inserting whatever after '>' in the old syntax to the new
replacement string. I consider this as a hack; the root-cause fix should be in the lexer to smartly separate
'>' and '?' as two tokens instead of one.

* [test] Update existing test.
2016-08-24 16:16:11 -07:00
Xi Ge
52273554f4 [FixCode] Add diagnosis/fixit to help users deal with BooleanType's removal (#4392)
* [FixCode] Add diagnosis/fixit to help users deal with BooleanType's removal.

Due to migration reasons, types used to conform to BooleanType, which
must contain a member var 'boolValue', now does not convert to Bool. This patch
adds a specific diagnosis/fixit to explicitly invoke 'boolValue' to please the
context types.

* Address Jordan's code review comments.
2016-08-19 08:29:42 -07:00
Xi Ge
2ebab526bf [FixCode] Apply coercion fixits on return statement and initialization as well. rdar://27891589 rdar://27891426
We saw manual migration is necessary on these cases to add 'as Type'. This patch starts
to issue compiler fixits on return statement and initialization just like in other type-mismatch
cases.
2016-08-18 13:21:44 -07:00
Ben Langmuir
a8534530b2 [FixCode] Move AnyObject bits into an objc-interop test
Keep the main test portable by moving the objc_interop bits into their
own test, combined with the existing selector tests.
2016-08-16 18:56:38 -07:00
Argyrios Kyrtzidis
4679525bfb [test] Need to update the result file as well. 2016-08-16 17:28:20 -07:00
Argyrios Kyrtzidis
af15fff58b [test] Mark 'test/FixCode/fixits-apply.swift' as requiring 'objc_interop'.
This is because it depends on using AnyObject.
2016-08-16 16:23:23 -07:00
Xi Ge
b620d3ebfe [FixCode] Apply coercion fixit for assignment types' mismatch too. rdar://27681428 2016-08-16 14:28:18 -07:00
Jordan Rose
3d005f3ad9 [Parse] Add fix-its for empty Swift 2 operator decl braces. (#4309)
And improve the error message for non-empty braces; if we're going to
ignore the contents, we should at least point you in the right
direction for Swift 3.

rdar://problem/27576922
2016-08-15 14:43:09 -07:00
Argyrios Kyrtzidis
895dc90513 [FixCode] Disable a migrating fixit that interacts badly with the migrator.
For such code:
  func test(p: Int, _: String) {}
  test(0, "")

the compiler bizarrely suggests to change order of arguments in the call site.
2016-08-12 13:33:46 -07:00
Argyrios Kyrtzidis
0cd8ca56dc [FixCode] Accept the fixit for the warning that @warn_unused_result is the default now.
rdar://27516354
2016-08-12 11:47:14 -07:00
Argyrios Kyrtzidis
72ac89325f Merge pull request #4240 from akyrtzi/typealias-print
[ASTPrinter] Fix printing of nested typealias types and make it consistent with printing of nominal types.
2016-08-11 16:49:00 -07:00
Ben Langmuir
8b42212543 Merge remote-tracking branch 'benlangmuir/fixit-protocol-comp'
Conflicts:
	lib/FrontendTool/FrontendTool.cpp
	test/FixCode/fixits-apply.swift
	test/FixCode/fixits-apply.swift.result
2016-08-11 12:55:21 -07:00
Ben Langmuir
008a57f7e5 Merge pull request #4205 from benlangmuir/fixit-anyobject
[fixcode] Add ( as AnyObject) fixit to the whitelist
2016-08-11 12:52:39 -07:00
Argyrios Kyrtzidis
69918a966d [ASTPrinter] Fix printing of nested typealias types and make it consistent with printing of nominal types.
This fixes several issues:
- By default parent types of alias types are not printed which results in
	- Erroneous fixits, for example when casting to 'Notification.Name' from a string, which ends up adding erroneous cast
	  as "Name(rawValue: ...)"
	- Hard to understand types in code-completion results and diagnostics
- When printing with 'fully-qualified' option typealias types are printed erroneously like this "<PARENT>.Type.<TYPEALIAS>"

The change make typealias printing same as nominal types and addresses the above.
2016-08-11 12:15:15 -07:00
Ben Langmuir
ec539d6abf [fixcode] Enabled protocol<...> fixits
The old syntax is deprecated in swift 3, and these fixits seem quite
safe, so apply them for migration.

rdar://problem/27794981
2016-08-11 10:28:18 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
Argyrios Kyrtzidis
9bd3e48b21 [AST] Fix the source range for InterpolatedStringLiteralExpr.
This allows fixits to be correctly applied when wrapping such an expression.
2016-08-10 15:22:03 -07:00
Ben Langmuir
454ee8a8d9 [fixcode] Add ( as AnyObject) fixit to the whitelist
This fixit comes from a note, but is very useful for migration of code
that has changed from AnyObject to Any but wants to do AnyObject
dispatch.

rdar://problem/27793389
2016-08-10 14:51:59 -07:00
Xi Ge
398f483557 [FixCode] Blacklist the fixit for enum case renames to avoid reverting migrator's change. rdar://27776887 (#4199)
We added the fixit to help users manually migrate enum case references after the declaration
has been renamed; however, when interacting with the migrator, the fixit may revert migrator's
correct changes, when the migrator updates references before updating the declaration. This patch
blacklists the fixit in migrator's pass, so we leave it to users' manually application if necessary.
2016-08-10 13:52:25 -07:00
Michael Ilseman
f48471ebd4 [noescape by default] purge tests of needless @noescape 2016-08-04 16:14:27 -07:00
Argyrios Kyrtzidis
92c0980a88 [FixCode] Make sure to accept the fixit in warning about 'where' syntax change. 2016-08-02 13:00:45 -07:00
Argyrios Kyrtzidis
c04aadb1a8 [FixCode] Make sure to accept the fixit in note about adding '@escaping'. 2016-08-02 10:04:40 -07:00