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)
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
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
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
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.
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
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
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.
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.
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
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
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
for checking duplicated results from multiple type checker solutions.
e.g.
protocol Proto {}
struct Generic<T> {
func retProto() -> some Proto
}
func foo() -> Generic<T1>
func foo() -> Generic<T2>
foo().<COMPLETION>
The return type of `Geric<T1>.retProto()` and `Geric<T2>.retProto()` is
different, but they both spelled 'some Proto'. So IDE consumers don't
care the difference.
rdar://107669173
Only return macros that are valid in their current position, ie. an
attached macro is not valid on a nominal.
Also return freestanding expression macros in code block item position
and handle the new freestanding code item macros.
Resolves rdar://105563583.