Commit Graph

2134 Commits

Author SHA1 Message Date
Henrik G. Olsson
0f312adb92 [Swiftify] Always annotate overloads with @_disfavoredOverload (#81579)
Previously we would only add @_disfavoredOverload if the only type
changed was the return type, because in any other case it is unambiguous
which overload to call. However it is still ambiguous when storing the
function as a value rather than calling the function, unless explicit
type annotations are used.

To avoid breaking any existing code, this patch adds
@_disfavoredOverload to every overload generated by @_SwiftifyImport.

rdar://151206394
2025-05-23 21:21:49 -07:00
Hamish Knight
7522a3ea5b [SourceKit] Handle CustomAttrs arguments for placeholder expansion
Introduce a new ASTWalker option for walking CustomAttrs and use it
for the placeholder scanner to ensure we can expand placeholders in
attribute arguments.
2025-05-21 18:06:54 +01:00
Hamish Knight
60952784fc [SourceKit] Handle macro arguments in placeholder expansion
Allow macro argument placeholders to expand into trailing closures.

rdar://150550747
2025-05-21 18:06:54 +01:00
Ben Barham
7e63d08300 Merge pull request #81582 from bnbarham/remove-sk-diag-path
[SourceKit] Remove diagnostics path calculation
2025-05-20 11:17:01 -07:00
Henrik G. Olsson
6534b9b14f [Swiftify] Copy doc comment from clang node (#81584)
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
2025-05-20 08:06:20 -07:00
Ben Barham
381684a389 [SourceKit] Remove diagnostics path calculation
The diagnostic group documentation now point to the swift.org URL rather
than the toolchain path, so it no longer needs to be passed all the way
through sourcekitd.

Resolves rdar://151500502.
2025-05-16 17:58:16 -07:00
Hamish Knight
6eb76dfd15 [Driver] Avoid using response files for SourceKit
We only care about the frontend arguments here, creating a response
file is unnecessary.

rdar://98880399
2025-05-16 15:35:15 +01:00
Hamish Knight
b53c411655 [Frontend] Avoid storing StringRef values in ModuleAliasMap
Previously we would insert StringRefs that reference the keys in the
map, but that breaks if the invocation ever gets copied. Switch to
`std::string`.

rdar://148130166
2025-05-09 19:49:50 +01:00
Ben Barham
0bf1c1f3e1 Merge pull request #80958 from bnbarham/merge-modules
Merge exported modules with the same public name in generated interface
2025-05-05 13:49:12 -07:00
Erik Eckstein
08ce2f00f2 embedded: avoid false error "Deinit of non-copyable type not visible in the current module" in SourceKit
As SourceKit explicitly disables WMO, silence the diagnostic in this case (but leave it enabled for explicit non-WMO builds otherwise).

rdar://150596807
2025-05-05 09:19:08 +02:00
Ben Barham
ddddc667c8 Merge exported modules with the same public name in generated interface
If a module has the same `public-module-name` as the module being
generated and its import is exported, merge it into the same generated
interface.

Fix various always-imported modules from being printed while here and
update all the tests that checked for them.

Resolves rdar://137887712.
2025-05-02 10:59:15 -07:00
Hamish Knight
54e0607091 [Sema] Add missing null check for Type
`getType` here can return a null type if the queried expression isn't
part of the solution, which can currently happen for code completion.
I'm working on a more principled fix for this, but until then this is
a low-risk fix that will unblock the stress tester and can be
cherry-picked to 6.2.

rdar://149759542
2025-04-23 12:58:28 +01:00
Doug Gregor
851950562d Update test 2025-04-14 23:44:16 -07:00
Egor Zhdan
119eeec9df [cxx-interop] Add a test for interface generation of a module requiring C++20
rdar://148840350
2025-04-11 15:09:30 +01:00
Hamish Knight
aaeb38d7f4 [Macros] Expand extension macros at the top-level
Ensure we always expand extension macros after the top-level decl
for the given attached decl. This ensures correct unqualified lookup
behavior, and bans macro implementations from extending the
unqualified name (they're expected to use `providingExtensionsOf`
instead, which uses the qualified name).

rdar://148119538
2025-03-28 21:35:59 +00:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Hamish Knight
f524691cdf [IDE] Avoid inferring container type for implicit expressions
For e.g implicit `buildExpression` calls, we have a location that
matches the argument, but we don't want to consider the result
builder type as the container type.
2025-02-28 21:00:12 +00:00
Hamish Knight
b52d154be4 Merge pull request #78855 from hamishknight/elemental
[Mangler] Handle local archetypes in `getDeclTypeForMangling`
2025-02-27 18:19:32 +00:00
Hamish Knight
35f79e4c07 Merge pull request #79585 from hamishknight/leaps-and-bounds
[Completion] Remove uses of unbounded generic types
2025-02-27 12:38:51 +00:00
Allan Shortlidge
332d770a5c IDE: Stop requiring availability platforms to be classified as keywords. 2025-02-26 18:02:00 -08:00
Hamish Knight
994848f6e5 [Mangler] Handle local archetypes in getDeclTypeForMangling
Element archetypes can occur here when mangling the USR for local
variables for e.g SourceKit cursor info, as well as for regular
compilation for things like lazy variables.

Update `getDeclTypeForMangling` to map local archetypes out of
context, using both the captured generic environments and the
archetypes present in the type. More work is needed to support lazy
variable though (now it crashes in SILGen).

This patch doesn't handle mangling standalone element archetypes for
e.g `printTypeUSR`, ideally we'd fix the clients there to not pass
local archetypes.

rdar://143077965
2025-02-26 11:51:20 +00:00
Hamish Knight
0fc825b6fb [Completion] Remove uses of unbounded generic types
Ensure we always produce bounded generic type annotations and
contextual types.
2025-02-25 14:49:12 +00:00
Rintaro Ishizaki
635494df39 [Parse] Adjust assertions for ParsingFlags::PoundIfAllActive mode
In this mode, multiple #if clauses are active. For now, just use the
first clause as the result.
2025-02-06 12:07:04 -08:00
Rintaro Ishizaki
694e815f07 [Parser] Include all AST nodes from every #if region in ParserUnit
'ParserUnit' is used for analyzing syntax structures _mainly_ in
SourceKit.

Since we removed IfConfigDecl from AST, ParserUnit didn't
inclue any AST in #if ... #endif regions even for active region because
it used to consider all inactive. Instead, consider every region
"active" and include all the AST nodes.

rdar://117387631
2025-02-03 16:22:11 -08:00
QuietMisdreavus
ab26b8b9d7 add support to getTopLevelDecls for clang submodules (#76401)
rdar://126031510
2025-01-30 09:39:58 -07:00
Rintaro Ishizaki
37a2748e0d [ASTPrinter] Print SPI by default
`PrintOptions.InterfaceContentKind` was not initialized. Set it to
`InteraceMode::Private` by default, so SPI declarations and their `@_spi`
attribues are printed. This basically restores the behavior before
aba3b6c24e , and is align with
`AccessFilter` being `AccessLevel::Private` by default.

rdar://131726756
2025-01-22 21:37:54 -08:00
Egor Zhdan
fc8fc76712 Merge pull request #78387 from swiftlang/egorzhdan/fq-template-params
[cxx-interop] Use fully-qualified type names of C++ template parameters
2025-01-03 16:17:30 +00:00
Egor Zhdan
e5899ee167 [cxx-interop] Use fully-qualified type names of C++ template parameters
When importing C++ class template instantiations, Swift generates a type name for each instantiation. The generated names must be unique, since they are used for mangling.

If multiple different C++ types declare nested types with the same name, which are then used as template arguments, Swift was generating the same name for those template instantiations (e.g. `shared_ptr<Impl>` for different `Impl` types).

This change makes sure we use fully-qualified type names of template parameters when generating Swift type names for class template instantiations (e.g. `shared_ptr<MyNamespace.MyClass.Impl>`).

This fixes an assertion failure coming out of IRGen:
```
Assertion failed: (Buffer.empty() && "didn't claim all values out of buffer"), function ~ConstantInitBuilderBase, file ConstantInitBuilder.h, line 75.
```

rdar://141962480
2025-01-02 18:03:56 +00:00
Ben Barham
a2fda1d9f3 [Embedded] Do not produce cannot_specialize_class for live issues
SourceKit explicitly disables WMO, silence the diagnostic in this case
(but leave it enabled for explicit non-WMO builds otherwise).
2024-12-19 15:31:41 -08:00
Hamish Knight
30a8f1988a [SourceKit] Use canonical type in printTypeUSR
Mangling a non-canonical type can run into
unexpected type sugar such as the newly introduced
LocatableType. USRs should be based on canonical
types anyway, so make sure we canonicalize before
mangling.

rdar://141168628
2024-12-09 22:04:10 +00:00
Hamish Knight
c4efa0d5f0 [AST] Factor out Expr::getNameLoc
There are a bunch of AST nodes that can have
associated DeclNameLocs, make sure we cover them
all. I don't think this makes a difference for
`unwrapPropertyWrapperParameterTypes` since the
extra cases should be invalid, but for cursor info
it ensures we handle UnresolvedMemberExprs.
2024-12-05 15:55:19 +00:00
Mishal Shah
9a48056f15 Bump the Swift version to 6.2 2024-11-22 01:04:37 -08:00
Gábor Horváth
88c2269e69 Merge pull request #77323 from swiftlang/gaborh/use-imported-locs
[cxx-interop] Use the locations imported from C++
2024-11-07 17:44:07 +00:00
Hamish Knight
7061a20edd [CS] Remove ConstraintSystem::getVarType
The logic here for completion wasn't actually
helping things since it would result in adding the
var overload to the system, which would result
in an ErrorType binding. We could turn the ErrorType
into a placeholder when resolving the overload,
but the simpler solution is to just allow CSGen
to turn the reference into a PlaceholderType. This
matches what we do for regular solving, and fixes
a crash with an IUO completion.

rdar://89369091
2024-11-04 17:08:20 +00:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Gabor Horvath
6d24c52b80 [cxx-interop] Use the locations imported from C++
A recent PR (#77204) started to import C++ source locations into Swift.
This PR flips a switch so these locations are actually used more widely.
Now some of the diagnostic locations are changed, but they generally
improved the quality of the diagnostics, pointing out conformances
imported from Obj-C code right when they are declared.
2024-11-01 13:49:09 +00:00
swift-ci
6ea9995a81 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-19 18:57:20 -07:00
Allan Shortlidge
cb578172ea Tests: Remove -disable-availability-checking in more tests that use concurrency.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of _Concurrency APIs,
instead of disabling availability checking.
2024-10-19 12:35:20 -07:00
swift-ci
8956a19bd8 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-15 20:34:48 -07:00
John Hui
b58a908082 [cxx-interop] Add Hashable conformance to imported enums (#76940)
* [cxx-interop] Add Hashable conformance to imported enums

Previously, imported enums only conformed to RawRepresentable and Equatable,
so they could not be used as members of a Set or keys of a Dictionary.
This patch adds Hashable conformance to give them that ability,
as well as some test cases to clarify the expected behavior.
Existing test cases are updated to reflect this new conformance.

rdar://129713687
2024-10-15 20:24:35 -07:00
swift-ci
eb44cd10be Merge remote-tracking branch 'origin/main' into rebranch 2024-10-10 23:13:50 -07:00
Allan Shortlidge
af84818e5c IDETool: Register SourceFile for replaced function body.
This prevents a nullptr dereference in `ASTScope::unqualifiedLookup()` after
querying for the `SourceFile` containing a give source location.

Fixes rdar://137652856 and https://github.com/swiftlang/swift/issues/76944.
2024-10-10 17:24:17 -07:00
swift-ci
b8a5d2d6d7 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 01:35:42 -07:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
swift-ci
415b83acd6 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 05:54:22 -07:00
Hamish Knight
0869a3abd9 [test] Add -no-emit-module-separately to a couple of tests
A couple of tests are expecting merge-modules behaviour,
add `-no-emit-module-separately` in those cases to
ensure that merge modules is used in both the old
and new driver.
2024-09-22 21:15:45 +01:00
Konrad `ktoso` Malawski
d89347bed0 Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-20 18:34:45 +09:00
swift-ci
ed74391004 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 12:41:02 -07:00
Alex Hoppen
6ab4f36986 Merge pull request #76441 from vincentisambart/macro-decl-format
[SourceKit] Format macro decl without crashing
2024-09-18 12:25:09 -07:00
Vincent Isambart
93c06738d3 Check that formatting is as expected 2024-09-18 13:16:31 +09:00