Commit Graph

74 Commits

Author SHA1 Message Date
Ian Anderson
cdb42c3535 [ClangImporter] clang's -iframework comes before builtin usr/local/include, but Swift's -Fsystem comes after
When Swift passes search paths to clang, it does so directly into the HeaderSearch. That means that those paths get ordered inconsistently compared to the equivalent clang flag, and causes inconsistencies when building clang modules with clang and with Swift. Instead of touching the HeaderSearch directly, pass Swift search paths as driver flags, just do them after the -Xcc ones.

Swift doesn't have a way to pass a search path to clang as -isystem, only as -I which usually isn't the right flag. Add an -Isystem Swift flag so that those paths can be passed to clang as -isystem.

rdar://93951328
2024-12-23 22:15:52 -08: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
Saleem Abdulrasool
c3d79f9178 tools: demote swift-refactor to testing
This is not currently shipped with the toolchain and is meant for
testing purposes. Mark the component as testing-tools.
2024-02-01 15:09:32 -08:00
Alex Hoppen
e538a5ed61 [SourceKit] Merge RenameLoc and RenameLocation
It’s easier to understand the code if we don’t have these two nearly, but not quite, identical types.
2023-12-06 14:33:14 -08:00
Alex Hoppen
899368037c [SourceKit] Return results from rename using return values instead of consumers
This makes it a lot easier to follow the code.
2023-11-16 16:05:08 -08:00
Alex Hoppen
bfad46d524 [SourceKit] Remove the -syntactic-rename option from swift-refactor
With the local refactoring being removed, all production refactoring paths return a set of ranges to rename and don’t apply edits to the file. Thus, the `syntactic-rename` action also doesn’t make sense anymore.
2023-11-16 16:05:08 -08:00
Alex Hoppen
d9eef8c229 [SourceKit] Remove IsNonProtocolType parameter from rename locations
The parameter was never checked anywhere.
2023-11-16 16:05:07 -08:00
Alex Hoppen
d095d0a186 [SourceKit] Remove newName from RenameLoc
We should (and do) have one new name for the entire rename operation, not a separate new name for different positions at which the renamed symbol occurs.
2023-11-16 16:05:07 -08:00
Hamish Knight
af7134b884 Fully enable ExperimentalStringProcessing
Previously we would only enable by default when
`parseArgs` was called. However this wouldn't
enable it for clients such as LLDB, who provide
their own invocation. Switch the default to `true`
in the `LangOptions`, and remove some redundant
uses of `-enable-experimental-string-processing`.
The frontend flag remains, as it may be useful to
disable.

rdar://107419385
rdar://101765556
2023-03-31 18:10:39 +01:00
Ben Barham
a1c8280d0f [SourceKit] Refactor collection of available refactorings
Update to have a single refactoring collection method for cursor
refactorings and another for ranges. The various functions were only
needed because of the extra availability information on renames, so just
give that to all refactorings.
2023-03-28 13:05:35 -07:00
Ben Barham
bb7760b9e0 [Refactor] Allow expanding nested macros
This adds a new `primary_file` key, which defaults to `sourcefile`. For
nested expansions, `primary_file` should be set to the containing file
and `sourcefile` to the name of the macro expansion buffer.
2023-03-02 14:04:46 -08: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
Robert Widmann
9ff5d88847 Remove SourceKit Support for the libSyntax Tree 2022-11-16 14:52:28 -08:00
Rintaro Ishizaki
45828af5ed [Refactoring] Separate refactoring files to its own library
IDE/Refactoring had dependencies to libswiftIndex, but libswiftIndex
also depends on libswiftIDE (SourceEntityWalker, etc.)

To break libswiftIndex <-> libswiftIDE dependency cycle, move
"refactoring" related files to a new library 'libswiftRefactoring'

rdar://101692282
2022-11-02 12:39:26 -07:00
Ben Barham
6de34f37e5 [NFC] Revert SmallVector<T> -> SmallVector<T, N> fixes
With the change to include `SmallVector.h` directly in `LLVM.h` rather
than forward declaring in the only case it matters (ie. Clang <= 5),
these fixes are no longer needed. Since defaulted version is preferred
when there's no better choice (which is presumably the case if that's
how they were originally added), use it instead. Some uses were instead
changed to add `llvm::` so remove that too.
2022-08-05 21:25:55 -07:00
Louis D'hauwe
5d36507a2f [Refactoring] Add Codable refactoring action
Inserts the synthesized implementation.
As part of this, fix some ASTPrinter bugs.

rdar://87904700
2022-02-02 14:14:23 -08: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
Richard Wei
65bffd7ad7 Add _MatchingEngine and _StringProcessing modules.
These modules are part of the experimental declarative string processing feature. If accepted to the Standard Library, _StringProcessing will be available via implicit import just like _Concurrency, though _MatchingEngine will still be hidden as an implementation detail.

`_MatchingEngine` will contain the general-purpose pattern matching engine ISA, bytecode, and executor. `_StringProcessing` will contain regular expression and pattern matching APIs whose implementation depends on the matching engine..

Also consolidates frontend flag `-enable-experimental-regex` as `-enable-experimental-string-processing`.

Resolves rdar://85478647.
2021-11-19 09:27:33 -08:00
swift-ci
00d00b1927 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-02 18:13:05 -07:00
Michael Gottesman
558aee9e65 [swift-refactor] Add the option -resource-dir.
This lets one customize in the compiler invocation where the compiler looks for
the stdlib. This is necessary if the toolchain is not using a stdlib installed
with it.
2021-09-02 14:08:24 -07:00
swift-ci
79ca271751 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-20 14:53:15 -07:00
Ben Barham
3b99e9079b Merge pull request #38920 from apple/show-cursor-refactorings
[Refactorings] Add cursor refactorings for the start of the range
2021-08-21 07:35:51 +10:00
Ben Barham
c7620fa979 [Refactorings] Add cursor refactorings for the start of the range
When a range is a single expression/statement/decl or part of
expression, also return cursor based refactorings for the start of the
range.

This is a stop gap until the available refactorings are properly fixed
to be more lenient in general - the current fix is a little odd as eg.
if all of `foo.bar()` is selected, rename will be returned as an
available refactoring for `foo`. Still an improvement over completely
missing cursor based refactorings, however.

Resolves rdar://82060063
2021-08-18 14:04:10 +10:00
swift-ci
685f31b87a Merge remote-tracking branch 'origin/main' into rebranch 2021-08-17 03:54:04 -07:00
Hamish Knight
95ba42387c [test] Re-enable convert_bool.swift
`%build-clang-importer-objc-overlays` builds the
overlays for the current target rather than the
host, so update the `%refactor` invocations to
take the target as an argument.

rdar://81128571
2021-08-12 14:57:22 +01:00
Arnold Schwaighofer
c288cbb6ab Fix some more SmallVector usage without an on stack size 2021-08-05 12:15:23 -07:00
Ben Barham
3b51e86796 [Refactoring] Disable availability checking to reduce errors 2021-07-28 13:39:46 +10:00
Ben Barham
717a932a3f [Utils] Make sure to write the rewritten file in refactor-check-compiles
`ClangFileRewriterHelper` only outputs the rewritten buffer when it's
destroyed, but the consumers were never being freed. Cleanup the
lifetime management of the stream and consumers so that they're properly
destroyed.

Rename `DuplicatingSourceEditConsumer` to
`BroadcastingSourceEditConsumer` to better describe its purpose.
2021-06-03 21:11:00 +10:00
Michael Gottesman
8f876cf4ff Merge pull request #37721 from gottesmm/pr-a29fee875eff61d38bd51f7fff8c622eaf3d526e
[cmake] Work around a bug in the swift-driver by passing host side libraries from LLVMSupport to linker jobs via a -Xlinker flag.
2021-06-02 15:35:36 -07:00
Michael Gottesman
4a189d8025 [cmake] Work around a bug in the swift-driver by passing host side libraries from LLVMSupport to linker jobs via a -Xlinker flag.
Clang and Swift both support this so we can do this until the actual fix lands
in a host toolchain to unblock ErikE.

The specific problem is the swift driver should just push tbd files through to
the linker, but it treats it as an input file. I am going to be putting a fix
into 5.5. This patch in the mean time filters out the tbd files in cmake. This
is a temporary fix.

I also had to add direct dependencies from swift-refactor and
libSwiftSyntaxParser on LLVMSupport to ensure that the right linker flags get to
them.
2021-06-01 18:43:12 -07:00
Alex Hoppen
16846dbdbc Merge pull request #37528 from JiarenWang/jrw-SR14587
[Refactoring] generate both '-dump-text' and `dump-rewritten` from a single swift-refactor invocation
2021-05-31 19:09:31 +02:00
Hamish Knight
f33deeff0a [swift-refactor] Support -I and -sdk 2021-05-28 13:10:26 +01:00
jiaren wang
68eb0d7087 [Refactoring] generate both '-dump-text' and dump-rewritten from a single swift-refactor invocation (SR-14587) 2021-05-27 16:29:59 +08:00
Hamish Knight
10038b6fce [Refactoring] Add async wrapper refactoring action
This allows an async alternative function to be
created that forwards onto the user's completion
handler function through the use of
`withCheckedContinuation`/`withCheckedThrowingContinuation`.

rdar://77802486
2021-05-19 20:46:02 +01:00
Ben Barham
762337cc9b [Refactoring] Add @completionHandlerAsync to sync function
When adding an async alternative, add the @completionHandlerAsync
attribute to the sync function. Check for this attribute in addition to
the name check, ie. convert a call if the callee has either
@completionHandlerAsync or a name that is completion-handler-like name.

The addition of the attribute is currently gated behind the experimental
concurrency flag.

Resolves rdar://77486504
2021-05-14 20:19:02 +10:00
Ben Barham
3ea9bed415 [SourceKit/CursorInfo] Add constructor to call results
Cursor info for a constructor would previously give the cursor info for
the containing type only. It now also adds cursor info for the
constructor itself in a "secondary_symbols" field.

Refactor `passCursorInfoForDecl` to use a single allocator rather than
keeping track of positions in a buffer and assigning everything at the
end of the function.

Refactor the various available refactoring gathering functions to take a
SmallVectorImpl and to not copy strings where they don't need to.

Resolves rdar://75385556
2021-03-30 13:23:59 +10:00
Varun Gandhi
0d1e7abc9a Merge pull request #35757 from cypherean/refactor_transform
Replace std::transform with llvm::transform
2021-02-05 08:17:48 -08:00
shreyaa-sharmaa
2b11d7acc7 Task SR-14138 Replace std::transform with llvm::transform 2021-02-04 12:58:33 +05:30
Ben Barham
a9073b0922 [Refactoring] Add async refactorings
Adds three refactorings intended to help users migrate their existing
code to use the new async language features:
  1. Convert call to use async alternative
  2. Convert function to async
  3. Add async alternative function

A function is considered to have an async alternative if it has a void
return type and has a void returning closure as its last parameter. A
method to explicitly mark functions as having an async alternative may
be added to make this more accurate in the future (required for eg.
a warning about a call to the non-async version of a function in an
async context).

(1) converts a call to use the new `await` async language syntax. If the
async alternative throws, it will also add `try`. The closure itself is
hoisted out of the call, see the comments on
`AsyncConversionStringBuilder` for specifics.

(2) converts a whole function to `async`, using (1) to convert any calls
in the function to their async alternatives. (3) is similar to (2), but
instead *adds* a function and replaces calls to its
completion/handler/callback closure parameter with `return` or `throws`.

Resolves rdar://68254700
2021-02-03 15:54:46 +10:00
Ben Barham
83915ccc4a [IDE] Add swift-refactor option to output as plain text
Current modes are:
  1. output the whole rewritten buffer, with RUN and CHECK lines removed
  2. output each replacement in JSON

To make each refactoring (rather than the whole file) easier to test,
add a plain text output option that can be easily checked with
FileCheck.
2021-02-03 15:54:46 +10:00
Ben Barham
e31bd9db6a [Gardening] Formatting and typo in swift-refactor.cpp 2021-02-03 15:54:45 +10:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Hamish Knight
1ed810653c [Frontend] Remove performParseOnly
Most clients were only using it to populate the
main module with files, which is now done by
`getMainModule`. Instead, they can now just rely
on parsing happening lazily.
2020-06-08 12:44:15 -07:00
Hamish Knight
5d72c464eb [Frontend] Remove parsing option params from performParseOnly
Lift the `DisablePoundIfEvaluation` parsing option
into `LangOptions` to subsume the need for the
`EvaluateConditionals` parameter, and sink the
computation of `CanDelayBodies` down into
`createSourceFileForMainModule`.
2020-06-08 12:44:13 -07:00
Andrew Tkachuk
fc382d2085 Merge branch 'master' into add-equatable-conformance 2020-04-17 19:14:20 +03:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Andrew Tkachuk
ad15f21cde [SR-7293] Refactoring action to add Equatable Conformance 2020-02-14 19:31:58 +02:00
Vlasov Anton
904bd0bf63 SR-5740 Refactoring action to convert if statement to switch 2020-02-02 12:44:48 +03:00
Vlasov Anton
b52a0929c4 SR-5741 Refactoring action to convert from field initialization to computed property 2019-12-08 21:17:39 +03:00
Xi Ge
8915cf8c4d Sourcekit/Evaluator: refactor cursor-info resolver to using the evaluator model. NFC
This change adds a new IDE request ID zone and refactors the cursor-info resolver
to use the request evaluator model.
2019-07-16 09:55:16 -07:00