Commit Graph

49 Commits

Author SHA1 Message Date
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Daniel Duan
1ac34471e5 [NFC][Migrator] Make Diff.h private (#28637)
Gardening: `Migrator` is the reason Diff.h is here. Reduce its
visibility.
2019-12-08 15:44:48 -08:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Xi Ge
74ef5ebe86 migrator: run try? migration pass only when migrating from swift<5.
This migration pass is version specific, so we should add an option
controlling whether we should perform it.
2018-12-17 14:54:34 -08:00
BJ Homer
812c821366 Add a migration for the Swift 5 'try?' changes.
This migrates anything using the following pattern:

```swift
if let optX = try? someOptional(),
    let x = optX,
    ...
```

to this:

```swift
if let x = try? someOptional(),
    ...
```
2018-11-06 23:31:02 -07:00
Slava Pestov
8f3379c7c0 Migrator: Remove Swift 3 @objc migration 2018-10-30 16:46:08 -04:00
Xi Ge
1310ffc83f migrator: remove Swift 3 specific migration pass. (#18580) 2018-08-08 16:00:38 -07:00
Rintaro Ishizaki
203a253687 [Parse/Migrator] Drop Swift3 migration support for type(of:) (#17932)
In Swift3, shadowning type(of:) was impossible, because it was a parser
magic. In Swift4, type(of:) is resolved as normal function in stdlib so
it can be shadowed. 'TypeOfMigratorPass' was a targeted migrator pass
that prepend 'Swift.' to 'type(of:)' so that it refers Swift.type(of:)
stdlib builtin function.
2018-08-01 08:22:28 -07:00
Nathan Hawes
d5d058a768 [migrator] Only enable Swift 3 ObjC inference warnings when migrating from Swift 3
They were always enabled, meaning migrating from Swift 4 -> 4.2 would pick up
the associated fixits and add @objc unnecessarily in many places.

Resolves rdar://problem/39951671
2018-05-03 13:34:45 -07:00
Rintaro Ishizaki
fbad8891c5 [Migrator] Use Version::getCurrentLanguageVersion() as latest version 2018-04-27 15:36:22 +09:00
Xi Ge
991cc77d48 migrator: teach the driver to support multiple migration script sets. (#15637)
To support migration from both Swift 3 and 4, this patch
teaches the driver to pick up the right set of migration scripts
according to the given Swift version. We also pushed some placeholder script
files for migration from Swift 4. This patch also brings the migrator
up-to-date by avoiding migration if the Swift version is already 4.2.
2018-03-31 12:37:49 -07:00
David Ungar
d3f16229c0 Tweaks to shorten performCompile* a bit more.
# Conflicts:
#	lib/FrontendTool/FrontendTool.cpp
2018-02-05 17:47:47 -08:00
David Ungar
a9819b6e60 Renaming FrontendInputs -> FrontendInputsAndOutputs
Fix comment in ArtsToFrontendOptionsConverter re getOutputFilenamesFromCommandLineOrFilelist
2018-01-30 18:54:38 -08:00
David Ungar
ec2a9573cc Rename FrontendInputs::AllFiles to AllInputs, getAllFiles to getAllInputs, etc. 2018-01-23 14:01:15 -08:00
David Ungar
a2dca04092 Trivial changes 2017-12-11 22:58:57 -08:00
David Ungar
60827b4be3 Rename accessors to InputFile data. 2017-12-08 12:57:32 -08:00
David Ungar
28b206008f FrontendInputs data structure redo.
- Outlaw duplicate input files, fix driver, fix tests, and add test.
- Reflect that no buffer is present without a (possibly pseudo) named file.
- Reflect fact that every input has a (possible pseudo) name.
- Break up CompilerInstance::setup.

Don't bail on dups.
2017-12-05 17:28:03 -08:00
David Ungar
26537ea26c Address Jordan’s comments:
- Also be consistent about has vs have for Input predicates

Fix bug.
2017-11-18 14:00:32 -08:00
David Ungar
3f3d784144 Factor code from tools & move input conversion. 2017-11-14 20:48:59 -08:00
David Ungar
47ee930a50 git-clang-format'ed 2017-10-08 23:56:03 -07:00
David Ungar
c1821755de NFC: First step (refactoring) towards speeding up compilation by having multiple primary files: Creates new class, FrontendInputs, to encapsulate InputFilenames, InputBuffers, and PrimaryInput, which were formerly in FrontendOptions. Add new instance variable, Inputs, to FrontendOptions in order to hold FrontendInputs.
Encapsulate uses of the variables in FrontendInputs with intention-describing functions. Move some code that sets these variables into FrontendInputs and FrontendOptions classes.

Create new FrontendInputs class to encapsulate InputFilenames, InputBuffers and PrimaryInput, which were formerly in Frontend.

Includes one change in SwiftEditor.cpp to resolve a merge conflict.
2017-10-08 10:20:37 -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
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
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
David Farler
4069d81e55 [Migrator] Turn off buggy line-level diff in diff-match-patch
This code is too clever to survive and is causing crashes in the
migrator. It doesn't appear to be providing a noticeable performance
benefit, so disable line-level diffing and just do a fine-grained
diff throughout.

rdar://problem/32281108
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
6972e1a71e [Migrator] Shift standalone removals
Xcode has some interesting behavior w.r.t. standalone removal
entries. In the previous migrator, there was an adjustment for
that, so port that over.

rdar://problem/31976029
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
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
8450d952bc [Migrator] Integrate diff-match-patch into the Migrator pipeline
After both the syntactic and fix-it passes have run, perform
a diff of the start and end states' texts and output the remap
file.

rdar://problem/30926019
2017-06-14 14:21:50 -07:00
David Farler
d4c9eb1db7 [Migrator] Add null check when pre-fix-it passes fail
If code is irreparably broken when migrating, make sure to
check that the pre-fix-it compiler instance is `nullptr` and
bail if so.

rdar://problem/32240138
2017-05-18 14:26:10 -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
practicalswift
a9c03845cc [gardening] Use consistent headers 2017-05-04 15:24:35 +02: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
Doug Gregor
66b11cbc3d [SE-0160] Make deprecated @objc inference warnings opt-in.
The warnings about deprecated @objc inference in Swift 3 mode can be a
bit annoying; and are mostly relevant to the migration workflow. Make
the warning emission a three-state switch:

* None (the default): don't warn about these issues.
* Minimal (-warn-swift3-objc-inference-minimal): warn about direct
  uses of @objc entrypoints and provide "@objc" Fix-Its for them.
* Complete (-warn-swift3-objc-inference-complete): warn about all
  cases where Swift 3 infers @objc but Swift 4 will not.

Fixes rdar://problem/31922278.
2017-05-01 16:25:50 -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
d4cf06ab2a [Migrator] Only replace primary file with input buffer
In the Migrator, the AST passes (effectively syntactic edits only)
run before the fix-it passes. We try to reuse as much as possible
from the original CompilerInvocation, but we need to replace the
primary input. Nuking all of the inputs is a bit foolish :-).

rdar://problem/31858212
2017-04-27 10:30:28 -07:00
David Farler
bf37eb7f34 Merge pull request #9062 from bitjammer/migrator-remap-additional-output
[Migrator] Make remap file an additional output
2017-04-27 01:40:26 -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
60e4985d3c [Migrator] Set language version to 4 for the fix-it passes
When running the fix-it passes, we should explicitly set the effective
language version to 4, since passing language version 3 may be the
default at first.

rdar://problem/31854159
2017-04-26 19:17:24 -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
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
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
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