Commit Graph

60 Commits

Author SHA1 Message Date
Anthony Latsis
0981b71090 Adjust calls to clang::DiagnosticsEngine ctor (now takes ref vs. ptr)
See https://github.com/llvm/llvm-project/pull/139584
2025-06-13 21:57:36 +01:00
Anthony Latsis
b71e689138 Adjust includes of moved Clang headers
Per 0d150db214e2aa13a825b563c7238e1243d61db1 (llvm-project).
2025-04-24 01:52:46 +01:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Alex Hoppen
63c31033fc [Frontend] Load standard libarary in CompilerInstance::setup
Instead of checking that the stdlib can be loaded in a variety of places, check it when setting up the compiler instance. This required a couple more checks to avoid loading the stdlib in cases where it’s not needed.

To be able to differentiate stdlib loading failures from other setup errors, make `CompilerInstance::setup` return an error message on failure via an inout parameter. Consume that error on the call side, replacing a previous, more generic error message, adding error handling where appropriate or ignoring the error message, depending on the context.
2021-12-13 15:32:08 +01:00
Evan Wilde
8112cda531 Updated F_Text and F_Append
These enum cases were also updated to OF_Text and OF_Append.
2021-06-23 14:29:52 -07:00
Varun Gandhi
4c65e14ca8 [Migrator] Clear LLVM global state before argument setup.
Fixes rdar://78576743.
2021-05-28 11:01:02 -07:00
Robert Widmann
a8766cce5b [NFC] Refactor InputFile's Accessors 2020-09-11 22:28:58 -06:00
Robert Widmann
f103405bb3 Use the new InputFile Constructor 2020-09-11 22:28:58 -06:00
Hamish Knight
f7ae7c0459 [Frontend] Avoid passing CompilerInvocation + CompilerInstance
The invocation can be retrieved from the
CompilerInstance.
2020-04-29 18:58:47 -07:00
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