Commit Graph

45 Commits

Author SHA1 Message Date
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
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
Власов Антон Вячеславович
8acd794935 SR-5744 Refactoring action to convert if-let to guard-let and vice versa 2019-07-09 16:21:25 +03:00
Nathan Hawes
d389652998 [IDE][Index] Renaming a wrapped property should also rename the synthesized $-prefixed backing property
This patch achieves this by updating indexing to reporting the position of
`foo` in occurrences of `$foo` as an occurrence of the `foo` symbol, so
that renames initiated on occurrences of the `foo` symbol will also result
in occurrences of the `$foo` symbol being updated correctly. This also means
find-references on foo will show places where $foo is used.

Making rename work in the other direction (invoking rename on $foo upating foo
occurrences too) is still todo.
2019-06-26 18:37:47 -07:00
Xi Ge
bff3f8adcc Merge pull request #16983 from mohitathwani/SR-7292
[WIP] Generating member wise initializer with local refactoring
2018-07-26 13:05:08 -07:00
Mohit Athwani
ce1122921a SR-7292 - Refactoring tool for generating member wise init 2018-07-26 11:31:30 -07:00
Rintaro Ishizaki
639fb85c5f [Refactoring] Rename CollapseNestedIfExpr to CollapseNestedIfStmt
'if' is not expression, but statement.
2018-05-23 17:13:35 +09:00
Mohit Athwani
632a9be198 Adds a new line character to the message when indicating parse position error 2018-05-01 12:57:08 -07:00
Huon Wilson
8056102ee5 [IDE] Refactoring to change function bodies to "fatalError()".
This is immensely useful when working on generic code, where the signatures
of (many) functions are all that is required, and removing the bodies makes
things compile faster, allows tools like creduce to work better and results in
less noise in a debugger.

Unfortunately the design of refactoring means this currently only works on a
single top-level decl, or multiple decls inside a type.
2018-04-13 15:56:56 +10:00
Jordan Rose
3cd9f166bc Don't spend time initializing LLVM when running the driver (#14896)
Tiny start-up time optimization noticed while looking at how we do
PrettyStackTraceProgram. Also add PrettyStackTraceProgram to a few
more of our testing tools, via the new PROGRAM_START macro.
2018-02-28 19:56:19 -08:00
Xi Ge
37f352fe41 sourcekitd: build Swift syntax tree more lazily than collecting parsed tokens. (#14578)
Before this patch, we have one flag (KeepSyntaxInfo) to turn on two syntax
functionalities of parser: (1) collecting parsed tokens for coloring and
(2) building syntax trees. Since sourcekitd is the only consumer of either of these
functionalities, sourcekitd by default always enables such flag.
However, empirical results show (2) is both heavier and less-frequently
needed than (1). Therefore, separating the flag to two flags makes more
sense, where CollectParsedToken controls (1) and BuildSyntaxTree
controls (2).

CollectingParsedToken is always enabled by sourcekitd because
formatting and syntax-coloring need it; however BuildSyntaxTree should
be explicitly switched on by sourcekitd clients.

resolves: rdar://problem/37483076
2018-02-13 16:27:12 -08:00
David Ungar
a9819b6e60 Renaming FrontendInputs -> FrontendInputsAndOutputs
Fix comment in ArtsToFrontendOptionsConverter re getOutputFilenamesFromCommandLineOrFilelist
2018-01-30 18:54:38 -08:00
Roman Roibu
b2d122c4a7 [IDE] Refactoring: Expand a ternary operator into an if statement and vice-versa (#12554) 2017-12-21 12:40:30 -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
Alex Hoppen
746bfc6d59 [Refactoring] Add refactoring action to move type members to extension (#12795)
This implements SR-6297.
2017-11-09 11:08:34 -08:00
Xi Ge
6af5d3c0bf libSyntax: rename KeepTokensInSourceFile to KeepSyntaxInfoInSourceFile. 2017-11-03 18:39:01 -07:00
Rintaro Ishizaki
a57199cf68 [refactoring] Implement "Convert to Trailing Closure" refactoring action 2017-10-16 00:42:05 -07:00
Kacper Harasim
8cd677eb1f [Refactoring] SR-6051 Expansion of switch statement missing cases (#12281) 2017-10-13 09:37:58 -07:00
Kacper Harasim
6fcb8308ff [IDE] Refactoring: conversion from “force try” to error handled version (#12063)
* [IDE] Refactoring: conversion from “force try” do error handled version

* Removed unnecessary empty line

* Changed name of the refactor

* Review fixes

* Fixed recognizing try_! location by CursorResolver

* Review fixes
2017-09-24 09:05:32 -04:00
Kacper Harasim
80698a04b0 [IDE] SR-5745 Refactoring: converting strings concatenation expression to strings interpolation (#11944) 2017-09-19 13:37:42 -07:00
Will T. Ellis
57454eb8c9 SR-5739 Add refactoring action to collapse nested if (#11851) 2017-09-18 16:16:01 -07:00
Xi Ge
0437214b40 Refactoring: avoid re-tokenizing during syntactic renames. NFC 2017-09-11 10:25:44 -07:00
Xi Ge
53585a5e70 Refactoring: Implement a refactoring action to simplify long number literal format. SR-5746
For instance, converting from "100000" to "100_000", and "1000.0001" to
"1_000.000_1".
2017-08-31 14:25:48 -07:00
Robert Widmann
75a83da03e Implement SE-0075: CanImport
This implementation required a compromise between parser
performance and AST structuring.  On the one hand, Parse
must be fast in order to keep things in the IDE zippy, on
the other we must hit the disk to properly resolve 'canImport'
conditions and inject members of the active clause into the AST.
Additionally, a Parse-only pass may not provide platform-specific
information to the compiler invocation and so may mistakenly
activate or de-activate branches in the if-configuration decl.

The compromise is to perform condition evaluation only when
continuing on to semantic analysis.  This keeps the parser quick
and avoids the unpacking that parse does for active conditions
while still retaining the ability to see through to an active
condition when we know we're moving on to semantic analysis anyways.
2017-08-28 18:35:06 -04:00
Argyrios Kyrtzidis
60a91bb736 [refactoring] Upstreaming the implementation for Swift local refactoring (#11568)
[refactoring] Upstreaming the implementation for Swift local refactoring
2017-08-22 16:50:16 -07:00