Commit Graph

38 Commits

Author SHA1 Message Date
Xi Ge
7312fea3b2 migrator: emit error messages when migration scripts are missing.
We used to assert migration scripts exist. This patch further
decouples these scripts and the compiler by treating missing scripts
as a regular compiler error.

Related: rdar://40538097
2018-05-25 11:25:32 -07:00
Nathan Hawes
9ee3c35186 [migrator] Filter out diag::wrong_argument_labels for the fixit pass
The migrator only applies changes from the APIDiffMigratorPass in the primary
file. This means that if a nominal type was renamed, for example, any members
users have added in an extension in a separate file won't be visible, because
the extension would still have the old name. This can result in 'wrong argument
label' errors with fixits to change the argument labels that, when applied by
the fixit pass, completely change which function was being called and cause
post-migration errors.

This patch updates the fixit pass to ignore diag::wrong_argument_labels.
diag::extra_argument_labels and diag::missing_argument_labels were already
filtered out for other reasons.

Resolves rdar://problem/40170377
2018-05-16 15:49:00 -07:00
Xi Ge
6a4df3e820 migrator: handle return value migration introduced by string enum changes.
This patch migrates the function call whose return type used to "String" and
now becomes "StringRepresentableStruct".
2018-04-17 15:18:33 -07:00
Jordan Rose
ceb51eea80 Clean up fix-it generation for missing cases, esp. with '@unknown'
- Combine the common logic for editor mode and non-editor mode.
- Do a better job minimizing fix-its.
- If '@unknown' is the only missing case, put `fatalError()` in the
  Xcode placeholder, since that's what the compiler would have done.
2018-04-05 16:35:15 -07:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
David Ungar
d3f16229c0 Tweaks to shorten performCompile* a bit more.
# Conflicts:
#	lib/FrontendTool/FrontendTool.cpp
2018-02-05 17:47:47 -08:00
Robert Widmann
b8069fbd8d Update tests to remove @autoclosure in decl position
Also restore some diagnostics in TypeCheckType that should have
migrated with the attributes.  In particular, diagnose cases where
we have @autoclosure with any function type repr with a non-Void
input type.

Resolves SR-5296
2017-07-05 22:09:19 -07:00
Slava Pestov
a6339be1cd Sema: Fix historical quirk with @escaping diagnostics
Saying "implicitly non-escaping because it was declared @autoclosure"
does not make sense. Since Swift 3, parameters of function type are
non-escaping by default, whether or not they are @autoclosure.

We would also inhibit the fixit for inserting @escaping if the
@autoclosure attribute was present. Again, a holdover from the
Swift 2 days, when @autoclosure implied @noescape and the special
@autoclosure(escaping) attribute was used to define an escaping
autoclosure.
2017-06-17 00:48:07 -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
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
3765dcae44 [Migrator] Fix remap printing
- Don't include inserts in the offset calculation
- Fix colon placement when printing JSON
- Consolidate adjacent insert/removal pairs into a single replacement,
  as this is what the remap applier expects.

rdar://problem/31872288
2017-06-14 14:21:50 -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
David Farler
a46127a20e Allow make_decl_objc diagnostic note into the FixitApplyDiagnosticConsumer
This allows the migrator to pick up fix-its from notes such as:

“Argument of #selector refers to instance method '___' that is not
exposed to Objective-C”

Add some more testing for minimal/complete workflows, and upstream
the cross-file fix-it test.

rdar://problem/32228948
2017-05-17 12:13:59 -07:00
David Farler
0c48f71384 Migrator/QoI: Function input type: Don't fix Void to (Void), but fix (Void) to ()
```swift
func foo(f: Void) -> ()) {}
```

This compiler currently suggests we change this to:

```swift
func foo(f: (Void) -> ()) {}
```

That's `(()) -> ()`, almost certainly not what someone wants in Swift
4. We should suggest changing that to:
```swift
func foo(f: () -> ()) {}
```

Additionally,

```swift
func foo(f: (Void) -> ()) {}
```

Should trigger a warning that the `(Void)` input type is `(())`, and you
can't supply `()` to it in Swift 4, and suggest a fix-it change it to:

```swift
func foo(f: () -> ()) {}
```

rdar://problem/32143617
2017-05-13 17:36:28 -07:00
Xi Ge
fb77682b5a [Migrator] Add a stub for authored API change list to handle API changes that are not detected automatically. (#9477) 2017-05-10 21:51:25 -07:00
David Farler
0774db030f [Migrator] Separate AST Pass implementations
The SyntacticMigratorPass is getting Too Big To Fail and covers
multiple migrations. There was already an early exit to not run
the pass if APIDigesterDataStorePath wasn't supplied, so SE-0110
tuple splat fix-its weren't getting run. This manifested in Migrator
tests not printing migrated contents on Linux.

New: ASTMigratorPass
Renamed: SyntacticMigratorPass -> APIDiffMigratorPass
New: TupleSplatMigratorPass

These implementations are entirely hidden and can only be invoked
by a swift::migrator function.

rdar://problem/32025974
2017-05-05 23:35:13 -07:00
David Farler
e92ad3bb96 Merge pull request #9197 from bitjammer/rdar-31926195-migrator-everyone-deserves-a-second-chance
[Migrator] Make performing a fix-it run return the instance used
2017-05-02 23:19:59 -07:00
David Farler
a2f48ff8c2 [Migrator] Make performing a fix-it run return the instance used
This CompilerInstance will be used if a fix-it run created an
error-free AST that we can continue to use in the AST passes.

rdar://problem/31926195
2017-05-02 21:37:17 -07:00
Xi Ge
99094782a3 whitelist missing enum cases fixits. 2017-05-02 15:04:24 -07:00
Xi Ge
39c550fc40 [Migrator] Handle function decl renames. rdar://31766131 (#9157) 2017-05-02 10:53:56 -07:00
David Farler
b73b597a79 Merge pull request #9117 from bitjammer/rdar-31895432-migrator-dont-add-type-placeholder
[Migrator] Don't pick up missing argument type placeholder fix-its
2017-05-01 14:34:25 -07:00
David Farler
95e6506682 [Migrator] Don't pick up missing argument type placeholder fix-its
With SE-110, the migrator may get a recommendation to add a Void
placeholder in the call to f in:
func foo(f: (Void) -> ()) {
  f()
}
Here, f was () -> () in Swift 3 but now (()) -> () in Swift 4. Adding a
type placeholder in the f() call isn't helpful for migration, although
this particular fix-it should be to fix the f parameter's type.

rdar://problem/31895432
2017-05-01 12:57:38 -07:00
David Farler
bf52ff032a [Migrator] Conservative and Minimal @objc inference workflows
Based on recommendations in SE-0160, there are two migration workflows:

- Conservative: Maintain @objc visibility that was inferred in Swift 3
  by adding @objc to all declarations that were implicitily visible to
  the Objective-C runtime. This is invoked in the migrator by adding the
  -migrate-keep-objc-visibility flag.
- Minimal: Only declarations that must be visible to Objective-C based
  on their uses (or in cases like dynamic vars) are migrated.

rdar://problem/31876357
2017-04-28 18:28:34 -07:00
Nathan Hawes
8ad6aa4e0d [migrator] Add pass for API type changes
This handles optionality changes and type rewrites in function param and return types and constructor param and failability types.
Resolves rdar://problem/31766010
2017-04-27 22:19:52 -07:00
David Farler
63776b507b When converting some of the old Migrator automation to the new Migrator,
I had set up the driver to invoke a separate frontend invocation with
the "update code" mode. We sort of did this last release, except we
forked to the swift-update binary instead. This is causing problems with
testing in Xcode.

Instead, let's perform a single compile and add the remap file as an
additional output during normal compiles. The driver, seeing
-update-code, will add -emit-remap-file-path $PATH to the -c frontend
invocation.

rdar://problem/31857580
2017-04-27 01:03:00 -07:00
David Farler
58feafc88a [Migrator] Remove unused MigratorOptions in FixitApplyDiagnosticConsumer
This isn't needed right now.
2017-04-26 12:45:22 -07:00
practicalswift
ff827e0455 [gardening] Fix recently introduced typos 2017-04-25 21:03:44 +02:00
Xi Ge
2a2731a797 migrator: add a flag to print incoming usrs to the API diff data store to facilitate testing. NFC (#8969) 2017-04-24 13:53:55 -07:00
Nathan Hawes
a9825bb7c6 [migrator] Add -warn-swift3-objc-inference to the new migrator fixit whitelist. Fixes test failure in Swift(macosx-x86_64).Migrator.objc_inference.swift 2017-04-21 13:12:19 -07:00
David Farler
107593a271 Merge pull request #8891 from bitjammer/migrator-common-fixit-filter
[Migrator] Refactor fixit filter from JSONFixitWriter to common code
2017-04-21 11:09:16 -07:00
Xi Ge
c55b43efc0 [Migrator] Add the simple transformation from global variables to static member variables. (#8865)
This should also handle global string to string enum migration.
2017-04-20 18:36:33 -07:00
David Farler
72e8642a05 [Migrator] Refactor fixit filter from JSONFixitWriter to common code
This filter is used for both applying fix-its during the normal
migration flow and by the -emit-fixits-path output for a normal
-typecheck frontend invocation, for example.

rdar://problem/30926261
2017-04-20 17:10:06 -07:00
David Farler
9701d94f15 [Migrator] Add adapter for clang lib/Edit textual edits
This adds an adapter class that wraps Clang's lib/Edit
Commit and EditedSource classes for use in the initial
"syntactic" passes. Once the passes have completed,
the resulting source file is then passed to the Swift compiler
fix-it passes.

rdar://problem/30926261
2017-04-20 10:54:22 -07:00
Xi Ge
acf4f6e27e [Migrator] Add stubs for API change data files. (#8844)
These data files are installed into runtime resource directory so that migrator can pick them automatically according to specific platforms. To support testing, a front-end option -api-diff-data-file can be used to specify the data file to use and it will overwrite the default ones from resource directory.
2017-04-18 15:20:57 -07:00
practicalswift
a029589093 [gardening] Use consistent headers 2017-04-18 19:51:08 +02:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02: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