Commit Graph

138 Commits

Author SHA1 Message Date
Dylan Sturgeon
ce55a854b9 Emit references to shadowed variables in if-let shorthands as variables when indexing locals is enabled.
Track the original-decl/captured decl as part of the symbol passed to the IndexConsumer. This allows the Rename consumer to check if the symbol is a shadowed reference to a decl being renamed, without the index skipping the other relevant output when visiting shadowing variables.

https://github.com/swiftlang/swift/issues/76805
2024-10-22 16:43:24 -07: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
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Slava Pestov
3fcda140bb AST: ModuleDecl::checkConformance() is a static method 2024-07-06 12:05:46 -04:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Alex Hoppen
155773c38e Fix renaming enum case parameters with unnamed associated arguments
We treated enum case parameters the same way as function parameters and weren’t considering that they can be unlabeled. That caused us to insert eg. `_ ` in front of the case’s type, producing `case myCase(_ String)`, which is invalid. When we are inside an enum case parameter and the parameter label is empty, treat it the same as a function call, which will leave the label untouched if it isn’t modified and insert a label including a colon if a new label is introduced.

https://github.com/apple/sourcekit-lsp/issues/1228
2024-06-11 19:18:59 -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
Alex Hoppen
1a67c61d19 [RelatedIdents] Fix an assertion failure if two invalid declarations have the same base name
For example, the following declarations have the same USR with a single ERROR_TYPE parameter despite being distinct declarations.

```swift
func bar(body: Invalid) {}
func bar(ignoreCase: Bool, body: Invalid) {}
```

We originally intended to check the USR so that local rename behaves more like global rename, which also looks symbols up by USR. But the above example proves that assumption wrong.

rdar://126803702
2024-05-07 18:17:11 -07:00
Rintaro Ishizaki
7177055bdc [Refactoring] Skip failed witness decls in "add codable implementation"
When there are problems in the properties in the target type, witness
methods may not be synthesized. Don't try to add such methods.

https://github.com/apple/swift/issues/72387
2024-03-18 23:49:24 +09:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Rintaro Ishizaki
39606e6269 [refactoring] Rework "add codable implementation" refactoring
* Support extensions including conditional conformance
* Correct access modifiers
* More correct lookup for the synthesized declarations
* Avoid printing decls in nested types (rdar://98025945)
2024-03-13 13:34:32 +09:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Alex Hoppen
63aeedecbd [SourceKit] Only report textual results inside comments and strings from syntactic rename ranges 2024-02-29 15:37:29 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Doug Gregor
81ffafdc6a Merge pull request #70602 from ApolloZhu/macro/expression-as-default-argument
[Macros] Expression macro as caller-side default argument
2024-02-14 16:10:11 -08:00
Hamish Knight
f4b928fd0a Remove FindLocalVal
Replace with an ASTScope lookup. This also lets
us simplify UsableFilteringDeclConsumer, and fixes
a couple of completion bugs.
2024-02-07 23:02:37 +00:00
Apollo Zhu
b09a22a9a0 Somewhat working
Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2024-02-06 15:02:11 -08:00
Hamish Knight
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00:00
Rintaro Ishizaki
b839718351 [AST] Use scoped enum for attribute kinds
Align with other kind enum e.g. DeclKind.
2024-02-02 09:36:48 -08:00
Rintaro Ishizaki
07bb0380a1 [AST] Use class names for type attribute kind enum
Align with DeclAttrKind.
2024-02-02 09:36:47 -08:00
John McCall
41cdfb04ad Introduce a proper TypeAttribute class hierarchy.
The old TypeAttributes reprsentation wasn't too bad for a small number of
simple attributes.  Unfortunately, the number of attributes has grown over
the years by quite a bit, which makes TypeAttributes fairly bulky even at
just a single SourceLoc per attribute.  The bigger problem is that we want
to carry more information than that on some of these attributes, which is
all super ad hoc and awkward.  And given that we want to do some things
for each attribute we see, like diagnosing unapplied attributes, the linear
data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in
with the new representation better.  The most significant change here is the
change to how we handle implicit noescape, where now we're passing the
escaping attribute's presence down in the context instead of resetting the
context anytime we see any attributes at all.  This should be cleaner overall.

The source range changes around some of the @escaping checking is really a
sort of bugfix --- the existing code was really jumping from the @ sign
all the way past the autoclosure keyword in a way that I'm not sure always
works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these
parameter specifiers; it seems better now, at least.
2024-01-28 22:30:26 -05:00
Hamish Knight
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Slava Pestov
14d1fcb51a AST: TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance() 2024-01-16 17:08:00 -05:00
Alex Hoppen
e8d148ab86 [build] Move addition of SWIFT_BUILD_SWIFT_SYNTAX preprocessor flag to top-level CMakeLists.txt 2023-12-12 12:58:15 -08:00
Alex Hoppen
e26c76dbd4 [SourceKit] Migrate getNotableRegions to new NameMatcher in swift-syntax 2023-12-12 12:58:15 -08:00
Alex Hoppen
a5530ce9b6 [SourceKit] Factor out some more bridging code to run the NameMatcher from swift-syntax 2023-12-12 12:58:15 -08:00
Alex Hoppen
32e366a98a [SourceKit] Migrate renameAvailabilityInfo to use the SwiftSyntax NameMatcher
The `NameMatcher` implemented in swift-syntax as slightly different semantics because it consideres `(callable.|callAsFunction)(x: 78)` as a reference to `callAsFunction` instead of a call with argument labels `(x: 78)`, which means that one test needs to be updated.
2023-12-12 12:49:16 -08:00
Alex Hoppen
9219b0cd71 [SourceKit] Address FIXMEs for the NameMatcher
rdar://118996561
2023-12-11 16:56:01 -08:00
Alex Hoppen
516836cb98 [SourceKit] Don't handle labels when renaming operators
This allows us to at least rename the base of operators. The labels don’t matter too much since they only occur on the function definition.
2023-12-07 13:12:12 -08:00
Alex Hoppen
222739a71d Merge pull request #70255 from ahoppen/ahoppen/rename-refactoring
[Rename] Collection of improvements to make syntactic rename easier to read
2023-12-06 19:46:01 -08:00
Alex Hoppen
d53e1b99f8 [SourceKit] Change RenameRangeCollector::startSourceEntity to use early returns 2023-12-06 14:33:14 -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
5cae50a1a6 [SourceKit] Refactor addSyntacticRenameRanges
Refactor `addSyntacticRenameRanges`, adding comments to make it easier to follow and remove its dependency on the `IsFunctionLike` parameter in `RenameLoc`.
2023-12-06 14:31:47 -08:00
Alex Hoppen
c8a87f091e [build] Only link swiftIDEUtilsBridging when SWIFT_BUILD_SWIFT_SYNTAX is set
https://github.com/apple/swift/pull/70174 change swift-refactor and sourcekitd to not use `NameMatcher` from swift-syntax but it did not remove the link dependency from swiftRefactoring on `swiftIDEUtilsBridging` if `SWIFT_BUILD_SWIFT_SYNTAX` is false. Do so now.
2023-12-06 09:32:47 -08:00
Alex Hoppen
a710111001 [SourceKit] Support building sourcekitd without building swift-syntax
This allows building sourcekitd and swift-refactor with `SWIFT_BUILD_SWIFT_SYNTAX=NO`. In these builds, the `relatedidents` and `find-syntactic-rename-ranges` requests will always return an error.
2023-12-04 19:14:01 -08:00
Alex Hoppen
cc858ab253 Merge pull request #70008 from ahoppen/ahoppen/name-matcher-in-swift
Share implementation of local rename and related identifiers + implement `NameMatcher` in Swift
2023-11-30 09:37:53 -08:00
Alex Hoppen
bc5cc43a06 Don’t include <vector> in IDEBridging.h 2023-11-28 14:04:37 -08:00
Doug Gregor
36a2dcd927 Implement function body macros
Function body macros allow one to introduce a function body for a
particular function, either providing a body for a function that
doesn't have one, or wholesale replacing the body of a function that
was written with a new one.
2023-11-27 17:04:55 -08:00
Alex Hoppen
f408619ddc Address Hamish’s review comments 2023-11-27 14:17:04 -08:00
Alex Hoppen
d224549030 [SourceKit] Don’t use C++ to Swift interop to run NameMatcher 2023-11-20 11:30:18 -08:00
Alex Hoppen
8fd025625b [SourceKit] Use NameMatcher that is rewritten in Swift for syntactic rename 2023-11-17 09:30:04 -08:00
Alex Hoppen
1047328b63 [SourceKit] Lowercase members of ResolvedLoc
This type will get exposed to Swift and the members should be lowercase so that they read nicely in Swift.
2023-11-16 16:05:08 -08:00
Alex Hoppen
33e9c30ede [SourceKit] Unify boolean values in ResolvedLoc into a ResolvedLocContext 2023-11-16 16:05:08 -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
ec267e2c08 [SourceKit] Hide RenameRangeDetailCollector as an implementation detail
The usage becomes a lot clearer if there’s just a top-level function that returns the details for the syntactic rename ranges.
2023-11-16 16:05:08 -08:00
Alex Hoppen
a0313e3005 [SourceKit] Merge Renamer and RenameRangeDetailCollector
With `TextReplacementsRenamer` gone, `RenameRangeDetailCollector` was the only remaining subclass of `Renamer`.
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
5d7200a0a1 [SourceKit] Remove the local rename refactoring action
Local refactoring should go through the `find-local-rename-ranges` request.
2023-11-16 16:05:08 -08:00