Commit Graph

196 Commits

Author SHA1 Message Date
Michael Spencer
b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
Allan Shortlidge
8079d9cf45 AST: Fix whitespace for switch statements under -print-ast.
No test changes because the tests for `-print-ast` don't match whitespace.
2023-07-31 21:27:46 -07:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Alex Hoppen
8abe38f9e2 [Rename] Also syntactically rename a macro’s definition
Previously we were skipping the macro’s definition (i.e. the part after `=` in a macro declaration if it wasn’t type checked. Since syntactic rename doesn’t type-check anything, it was thus skippin the macro definition. Add a flag to `ASTWalker` that allows `NameMatcher` to opt-out of this behavior.
2023-04-24 13:33:57 -07:00
Ben Barham
d2de8ed83c [SourceKit] Merge local refactoring implementations
Retrieving local rename ranges and the local rename refactoring both had
almost identical methods, except for the addition of retrieving the
outermost shadowed decl that was added a couple months back. Merge them.

Resolves rdar://106529370.
2023-03-13 15:36:47 -07:00
Ben Barham
4cc7167b60 [Index] Handle shorthand if let/closure captures in local rename
Update rename to pull the outermost-declaration so that references are correctly found.

Rather than keeping suppressed locations in the current parent, keep
them for the whole index. Local rename starts the lookup from the
innermost context it can, which could be a closure. In that case there
is no parent decl on the stack and thus no where to store the locations
to suppress. We could have a specific store for this case, but there
shouldn't be that many of these and they're relatively cheap to store
anyway.

Resolves rdar://104568539.
2023-01-24 11:10:38 -08:00
Anthony Latsis
fa3a95e7b8 Gardening: Migrate test suite to GH issues: refactoring 2022-09-02 01:44:24 +03:00
Alex Hoppen
ff129c3677 [test] Prepend 'python' to 'refactor-check-compiles.py' call
This fixes a test execution failure on Windows where the `refactor-check-compiles.py` is not an executable.
2022-06-22 09:27:34 +02:00
Alex Hoppen
db26e7fc28 [refactoring] Run refactoring tests on Linux
Refactoring tests have been disabled on Linux but I can’t find a reason why that should be the case. Enable them on all platforms.

rdar://92982631
2022-06-21 10:58:06 +02:00
Alex Hoppen
ca4abab9a9 Merge pull request #58746 from ahoppen/pr/enum-assoc-value-is-call
[Index] Consider construction of enums with associated values as a function call
2022-05-13 16:39:07 +02:00
Alex Hoppen
74cd03b098 [Index] Consider construction of enums with associated values as a function call
For enum cases with associated values, their construction is modelled by a function. E.g. if you have
```swift
enum Foo {
  case first(associated: Int)
}
```

then `Foo.first` is a function of type `(Int) -> Foo`. But if you write `Foo.first(associated: 2)` in source code, we consider this construct as a referenced, not a call. This causes us to miss renaming of associated value labels during local refactoring.

rdar://84061868
2022-05-09 22:22:31 +02:00
Alex Hoppen
379ad6cbde Merge pull request #58718 from ahoppen/pr/generate-memberwise-property-wrapper
[Refactoring] Several improvements to memberwise initializer generation
2022-05-09 17:05:36 +02:00
Alex Hoppen
d2f7d518ed [Refactoring] Always walk parent decl context of value decl for local rename
Previously, we only walked the parent scope of the decl context that declared the value to rename if it was a TopLevelCodeDecl. But also functions can have locally declared types that can be used in sibling scopes. Thus, we always need to walk the parent DeclContext of the one declaring the value we are renaming.

rdar://89836229
2022-05-09 17:04:36 +02:00
Alex Hoppen
4f970b4eed [Refactoring] Add memberwise initializer generation test cases for properties with getter and setter 2022-05-06 21:31:09 +02:00
Alex Hoppen
3b5dfbe638 [Refactoring] Maintain backticks from type members when generating memberwise initializer
Previously, we were dropping backticks, which might lead to invalid code if the type member was a keyword.

rdar://81888671
2022-05-06 20:57:12 +02:00
Alex Hoppen
8862e0153b [Refactoring] If type has no memberwise initializable members, generate an empty initializer instead of failing 2022-05-06 20:03:49 +02:00
Alex Hoppen
acf80829f0 [Refactoring] Add members with property wrappers to generated memberwise init
Generating a memberwise init would skip over properties with property wrappers. Switch the implementation of memberwise init generation closer to the one that generates the implicit memberwise init by also using `getMembers()` instead of `getStoredProperties()`.

rdar://89057767
2022-05-06 19:55:55 +02:00
Alex Hoppen
c9eb2d508e Merge pull request #58613 from ahoppen/pr/refactor-misses-prefix-operator
[Refactoring] Fix an issue where refactoring misses to refactor references after prefix operators
2022-05-05 14:31:46 +02:00
Alex Hoppen
6d2582f5b8 [Refactoring] Fix an issue where refactoring misses to refactor references after prefix operators
The removed `else if` branch caused the argument to the `-` operator to be be reported as `Mismatch`. I couldn’t figure out what that branch was for, so I removed it.

rdar://91588948
2022-05-04 09:04:30 +02:00
Alex Hoppen
e835c4a031 [Refactoring] Fix a crash that occurred when converting if/else of enum with raw value to switch statement
If the enum has a raw value, `E` passed in to `BinaryExpr` is a `DeclRefExpr`, not a `DotSyntaxCallExpr`, so we crashed on `dyn_cast<DotSyntaxCallExpr>(E->getFn())->getFn()`.

Only look through `DotSyntaxCallExpr` if `E` is indeed a `DotSyntaxCallExpr`. While at it, fix a few other potential sources of nullptr crashes.

rdar://84707973
2022-05-02 15:52:24 +02:00
Josh Soref
6fd6b13c56 spelling: unwrapped
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
925a7b973c spelling: transform
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
c816df5fa8 spelling: separate
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
bb8674df51 spelling: optional
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
353e4f09ed spelling: multi
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
f7236bc2e9 spelling: handler
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
edf494fa1f spelling: extract
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Josh Soref
5bbb9489a5 spelling: capture
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 15:53:30 -04:00
Rintaro Ishizaki
1cfffb8094 [CodeSynthesis] Improve synthesized Decodable.init(from:) for enums
Since this implementation is exposed to users, we want to make it nice.

* Don't use 'unsafelyUnwrapped' which is usually not recommended to use
* Don't access 'container.allKeys' multiple times as it's a computed
  property

rdar://89150202
2022-03-08 15:56:22 -08:00
Anthony Latsis
6e8dcbe745 ConformanceChecker: Resolve value witnesses unless they depend on invalid type witnesses 2022-02-26 01:06:53 +03: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
Hamish Knight
97a1653863 Merge pull request #39159 from hamishknight/conditions-apply
[Async Refactoring] Drop bool flag parameter binding
2021-09-07 13:35:22 +01:00
Hamish Knight
72070b7d41 [Async Refactoring] Bind known bool param in fallback
Generalize the logic to handle different BlockKinds,
and add binding logic that lets us assign `true` or
`false` to the given bool success param in the
fallback case.
2021-09-06 21:25:09 +01:00
Hamish Knight
00977afc7b [Async Refactoring] Placeholder dropped params in fallback case
Make sure to convert any references to parameters
that get dropped in the fallback case to
placeholders.
2021-09-06 21:25:09 +01:00
Hamish Knight
1e34f31545 [Async Refactoring] Drop bool flag parameter binding
If we have a known bool flag parameter, drop it
from the success parameters being bound in a
refactored await call, as the async variant drops
it.

rdar://81896460
2021-09-06 21:25:08 +01:00
Hamish Knight
9b493970aa [Aync Refactoring] Better handle comment trailing whitespace
Use `getCommentRange` to trim off the comment's
trailing whitespace, avoiding outputting
extraneous empty lines.

rdar://82072147
2021-09-06 17:51:39 +01:00
Michael Gottesman
e2c1db5b64 [test] Change swift-refactor tooling to specify a resource-dir. 2021-09-02 14:08:24 -07:00
Ben Barham
9b8d9e22ef Merge pull request #38981 from apple/skip-underscore
[Refactoring] Do not try to unique '_'
2021-08-24 11:33:15 +10:00
Ben Barham
afaa9e13e4 Merge pull request #38968 from apple/double-async-bad
[Refactoring] Do not add "async" if function is already async
2021-08-21 07:32:39 +10:00
Ben Barham
6a79964ad4 [Refactoring] Do not try to unique '_'
The async refactorings should not try to unique '_' when it's used as
the parameter name. Also skip adding a let binding to the `catch` if the
error parameter is '_'.

Resolves rdar://82158389
2021-08-21 07:30:53 +10:00
Ben Barham
86c47e45f0 [Refactoring] Do not add "async" if function is already async
Convert Function to Async is available on an async function. It could be
useful to run this refactoring still, as it would attempt to convert any
completion-handler functions to their async alternatives. Keep allowing
this, but make sure not to re-add "async" to the function declaration.

Resolves rdar://82156720
2021-08-20 15:24:17 +10:00
Hamish Knight
f58c62c02e [test] Use %refactor-check-compiles in more places
Update a bunch of async refactoring tests to use
%refactor-check-compiles in more cases.
2021-08-18 13:21:06 +01:00
Hamish Knight
1d2d15a52c Merge pull request #38857 from hamishknight/third-times-a-charm
[test] Re-enable convert_bool.swift
2021-08-17 11:33:32 +01: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
Ben Barham
9fc758adc9 [Test] Update convert_function.swift refactoring tests to also compile
Update the async refactoring tests in `convert_function.swift` to
compile the refactored code (where possible) to check for errors. This
would have prevented the issue with the refactored `Result<Void, ...`>
handler producing erroneous code.
2021-08-12 21:13:20 +10:00
Ben Barham
5bd2d0b932 [Refactoring] Fix invalid legacy body for Result<Void, ...> handler
When adding an async alternative for a function with a
`(Result<Void, ...>) -> Void` completion handler, the legacy body was
adding a call to the handler with `.success(result)`. We don't assign to
`result` for `Void` handlers, so pass `()` instead.

Resolves rdar://81829392
2021-08-12 21:04:18 +10:00
Ben Barham
f6a8dab93d [Refactoring] Use known alternative in async refactoring if one exists
Update the async refactorings to use the name from the async alternative
if one is known, rather than always assuming the name matches the
synchronous function.

Note that this could also be used to determine whether results remain
optional or not, but that has been left for a future patch.

Resolves rdar://80612521
2021-08-03 08:46:44 +10:00
Hamish Knight
813a721760 Merge pull request #38674 from hamishknight/following-the-trail 2021-07-29 17:36:10 +01:00
Ben Barham
e7e9b57051 Replace @completionHandlerAsync with @available(*, renamed:)
Instead of a new attribute `@completionHandlerAsync`, allow the use of
the existing `renamed` parameter of `@available` to specify the
asynchronous alternative of a synchronous function.

No errors will be output from invalid names as `@completionHandlerAsync`
had, but if a function is correctly matched then it will be used to
output warnings when using the synchronous function in an asynchronous
context (as before).

Resolves rdar://80612731
2021-07-29 09:14:44 +10:00
Alex Hoppen
1286bbedf1 Merge pull request #38665 from ahoppen/pr/async-refactoring-parens-around-result
[Async Refactoring] Handle parenthesis around params that no longer need to be unwrapped after refactoring
2021-07-28 21:54:29 +02:00