Commit Graph

159 Commits

Author SHA1 Message Date
Hamish Knight
ec597c82fa [Completion] Only complete @unchecked et al in inheritance clauses
Add a case for completing type attributes in
inheritance clause position, and limit the
completion of `@unchecked`, `@preconcurrency`, and
`@retroactive` to that case.
2024-07-03 11:41:58 +01:00
Hamish Knight
42f563d6d8 [Completion] Use TypeAttr.def for simple type attributes
Pick up all non-underscored simple type attributes
for code completion, and add support for
`@isolated(any)`.

rdar://130741006
rdar://130288443
2024-07-03 11:41:58 +01:00
Hamish Knight
94ed2418f4 [Completion] Complete .isolation for @isolated(any) functions
This was added in SE-0431.

rdar://124615036
2024-07-01 12:49:52 +01:00
Hamish Knight
1f83e66a3e [Completion] NFC: Factor out addBuiltinMemberRef 2024-07-01 12:49:52 +01: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
Rintaro Ishizaki
79a7410206 [CodeCompletion] Remove CrossActorReference diagnostics too
Same for 'async in non-concurrency' context
2024-05-15 15:10:03 -07:00
Rintaro Ishizaki
39d633f5a8 [CodeCompletion] Remove unused 'isAsync' flag from CodeCompletionResult 2024-05-15 13:43:19 -07:00
Rintaro Ishizaki
46cc32e9a4 [CodeCompletion] Always print argument ':' in filterName
In annotated results.

rdar://124667867
2024-04-05 17:21:40 -07:00
Ben Barham
1fdda023b3 Rename StringRef::endswith references to StringRef::ends_with
Missed this when doing the `startswith` renaming. `endswith` has also
been deprecated upstream (and presumably soon to be removed).
2024-04-01 10:59:16 -07: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
e380c66238 Merge pull request #71357 from hamishknight/scoped-down
Remove FindLocalVal
2024-02-09 10:57:23 +00: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
Hamish Knight
09ab888d89 NFC: Rename DeclVisibilityKind::LocalVariable -> LocalDecl
This includes local types, so make the name a bit
more generic.
2024-02-07 23:02:37 +00:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05: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
8fdc4cc225 [AST] Split Attr.def to DeclAttr.def and TypeAttr.def 2024-02-02 09:36:49 -08: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
Slava Pestov
9bf51a9d3f IDE: Use GenericSignature::getUpperBound() 2024-02-01 23:35:33 -05:00
Alex Hoppen
ece521c12b Merge pull request #71046 from ahoppen/ahoppen/copyable-completion
[CodeComplete] Emit `Copyable` declaration instead of keyword
2024-01-22 17:22:51 -08:00
Alex Hoppen
4c4f3c004b Merge pull request #71063 from ahoppen/ahoppen/delete-dot-in-call
[CodeComplete] Delete `.` in completion suggestions of call pattern
2024-01-22 17:21:40 -08:00
Alex Hoppen
7087da9913 [CodeComplete] Emit Copyable declaration instead of keyword
Now that there is an actual declaration for `Copyable` we should be emitting that as a code completion result instead of a keyword, like we currently do.

rdar://109107817
2024-01-22 12:34:38 -08:00
Alex Hoppen
88275d48e6 [CodeComplete] Delete . in completion suggestions of call pattern
Previously, were were suggesting to add `()` after eg. `x.` if `x` has a function type, resulting in `x.()`, which is incorrect. We need to remove the `.` in the completion suggestion.

rdar://121155241
2024-01-22 12:29:05 -08:00
Holly Borla
47afd21d85 [Concurrency] Remove ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Holly Borla
f581eb7d1b [Concurrency] Remove remaining special cases of ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Slava Pestov
0f072b4803 IDE: Clean up isMemberDeclAppliedInternal()
In preparation for checkRequirements() asserting upon encountering
type parameters. Should be NFC.
2024-01-17 13:08:46 -05:00
Slava Pestov
a7f484b3a4 AST: Clean up isSendableType() 2024-01-16 22:44:43 -05:00
Rintaro Ishizaki
a8ae8e4b8c [CodeCompletion] Check if stdlib decls exist
In some configurations e.g. 'Embedded', some stdlib types don't exist.
We cannot just assume they are always available.

rdar://119691781
2024-01-03 16:31:10 -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
adc9cc9c72 [CodeComplete] Prefer function call if both reference and call are possible
The real-world use case here is the `Task` initializer in the added test case. In general, we should only prefer to insert an unapplied function reference if it has a better type relation than calling the function because, in most cases, you want to call functions and not get unapplied references to them.

rdar://90456105
2023-11-23 10:44:17 -08:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Alex Hoppen
8550799eba [CodeCompletion] Call hasStorage instead of getImplInfo().hasStorage() to determine if a variable is stored
This uncovered a discrepancy between `getImplInfo().hasStorage()` and `hasStorage()`.
2023-09-27 11:19:21 -07:00
Alex Hoppen
ee85314e6f [CodeCompletion] Add completion for @storageRestrictions 2023-09-27 09:33:38 -07:00
Rintaro Ishizaki
fcaae5cc9b [CodeCompletion] Add fake type annotation to custom attributes
Macros and custom attribute types (i.e. `@resultBuilder`,
`@propertyWrapper`, and `@globalActor`) now have fake type
annotations. This would be useful to recognize which candidates are
actually usable in code completions after `@`.

rdar://109062582
2023-09-18 14:07:01 -07:00
Holly Borla
e23e4c32f5 Merge pull request #68414 from hborla/nonisolated-init-hole
[Concurrency] Don't allow nonisolated initializers to introduce data races via superclass property observers.
2023-09-09 09:55:24 -07:00
Holly Borla
a6d078b820 [Concurrency] Use the 'nonisolated' terminology instead of 'independent'.
This commit is NFC; it's mostly renames.
2023-09-08 13:28:55 -07:00
Alex Hoppen
5aa725d5cc [CodeCompletion] Delete dead code 2023-09-06 13:13:01 -07:00
Alex Hoppen
00eaed3af9 [CodeCompletion] Migrate postfix expr completion to solver-based 2023-07-07 19:51:01 +02:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Alex Hoppen
9f51c06db6 Merge pull request #66517 from ahoppen/ahoppen/iterator-invalidation
[CodeCompletion] Fix an issue that causes an iterator to be invalidated while iterating
2023-06-12 11:58:14 -07:00
Holly Borla
706411d2e6 [CodeCompletion] Plumb source locations through code completion name lookup. 2023-06-11 23:10:43 -07:00
Alex Hoppen
0996342b47 [CodeCompletion] Fix an issue that causes an iterator to be invalidated while iterating
In `SourceLookupCache::lookupVisibleDecls`, copy the top level values before iterating them.

If we have 'addinitstotoplevel' enabled, calling 'addConstructorCallsForType' can cause macros to get expanded, which can then cause new members ot get added to 'TopLevelValues', invalidating the current iterator.

I have not been able to reduce this to a test case that doesn’t rely on the `Observation` module in the SDK but here is the test case with which I was able to reproduce the issue very reliably.

```swift
import Foundation
import Observation

@Observable class MyObject {}

extension MyObject {}

// RUN: ~/sbin/sourcekitd-test \
// RUN:   -req=complete.open \
// RUN:   -req-opts=addinitstotoplevel=1 \
// RUN:   -pos=8:1 \
// RUN:   %s \
// RUN:   -- \
// RUN:   %s \
// RUN:   -Xfrontend \
// RUN:   -load-plugin-library \
// RUN:   -Xfrontend \
// RUN:   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/libObservationMacros.dylib \
// RUN:   -sdk \
// RUN:   /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk
```

rdar://109202157
2023-06-09 17:11:28 -07:00
mojh7
2dac0512e7 fix minor typo
exmaple -> example
2023-05-23 15:17:53 +09:00
Alex Hoppen
e8a32e45be Merge pull request #65805 from ahoppen/ahoppen/complete-constraint-type
[CodeComplete] Offer completions after `~` in an inheritance clause
2023-05-12 13:32:40 -07:00
Alex Hoppen
2abae1019f [CodeComplete] Offer completions after ~ in an inheritance clause
We should only be suggesting `Copyable` after `~` in an inheritance clause, in accordance with [SE-0390](https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md)

rdar://109063223
2023-05-09 20:21:30 -07:00
Alex Hoppen
c140fe480c [CodeCompletion] Only show type annotations for macros that return non-void
Showing the type annotation only makes sense if they are not `Void`. That’s consistent with functions where we also don’t show a `Void` return type. Most importantly, we shouldn’t be showing a `Void` type annotation for attached macros.

rdar://108870970
2023-05-04 18:02:26 -07:00
Alex Hoppen
1e505791e4 [CodeComplete] Offer completions for the names: argument of a macro declaration
When completing after `names:`, completion should offer the different ways you can specify the names, i.e. `arbitrary`, `named`, etc.

```
@freestanding(declaration, names: #^COMPLETE^#)
```

rdar://108535077
2023-04-28 17:20:45 -07:00
Alex Hoppen
053d215d55 Merge pull request #65427 from ahoppen/ahoppen/macro-attribute-completions
[CodeCompletion] Support completion for macro roles and the 'names:' argument label
2023-04-28 17:20:24 -07:00