Commit Graph

120 Commits

Author SHA1 Message Date
Henrik G. Olsson
cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Ahmed Elrefaey
1bc96857a8 Merge pull request #82464 from a7medev/feat/full-documentation-in-code-completion
[IDE] Add full documentation to code completion result
2025-09-04 10:06:21 +01:00
Egor Zhdan
ba8807802f Merge pull request #83261 from egorzhdan/egorzhdan/allow-qual-swift-name-reland
Reland "[cxx-interop] Allow import-as-member for types in namespaces"
2025-07-25 12:35:59 +01:00
Artem Chikin
b60bc39ee5 [APINotes] Add support for handling Clang modules carrying all versions of APINotes
Controlled from Swift with '-version-independent-apinotes', which, for the underlying Clang invocation enables '-fswift-version-independent-apinotes', results in PCMs which aggregate all versioned APINotes wrapped in a 'SwiftVersionedAttr', with the intent to have the client pick and apply only those that match its current Swift version, discarding the rest.

This change introduces the configuration flags for this mode as well as the corresponding logic at the beginning of `importDeclImpl` to canonicalize versioned attributes, i.e. select the appropriate attributes for the current target and discard the rest.
2025-07-24 09:08:31 -07:00
Egor Zhdan
ab54e00097 Revert "Revert "[cxx-interop] Allow import-as-member for types in namespaces""
This reverts commit dd809c6452.
2025-07-22 18:36:27 +01:00
Ben Barham
dd809c6452 Revert "[cxx-interop] Allow import-as-member for types in namespaces"
This reverts commit e95f6a3ce9.
2025-07-09 12:50:34 -07:00
Egor Zhdan
e95f6a3ce9 [cxx-interop] Allow import-as-member for types in namespaces
This adds support for `swift_name` attribute being used with C++ types that are declared within namespaces, e.g.
```
__attribute__((swift_name("MyNamespace.MyType.my_method()")))
```

Previously import-as-member would only accept a top-level unqualified type name.

rdar://138934888
2025-06-26 12:39:50 +01:00
Pavel Yaskevich
55b8d9538d [CSSimplify] Rework how/when mismatches between optional types are fixed
- Don't attempt to insert fixes if there are restrictions present, they'd inform the failures.

  Inserting fixes too early doesn't help the solver because restriction matching logic would
  record the same fixes.

- Adjust impact of the fixes.

  Optional conversions shouldn't impact the score in any way because
  they are not the source of the issue.

- Look through one level of optional when failure is related to optional injection.

  The diagnostic is going to be about underlying type, so there is no reason to print
  optional on right-hand side.
2024-09-10 10:35:05 -07:00
Rintaro Ishizaki
c9785d955d [SourceKit] Stop printing normal comments in clang generated interface
Generated interfaces for Clang modules used to try printing normal
comments between decls extracted from the header text. That was because
doc-comment was not common in C/ObjC headers. But mainly because of
"import as member feature" Clang decls aren't printed in the order as
they appear in the header file, the logic determinig which comment
belongs to which decl was not working property. We've decided to remove
that feature and only print the proper doc-comments as it has been
getting common.

rdar://93731287
2024-03-21 11:52:32 +09:00
Erik Eckstein
ef73c398bb tests: fix APINotes/blocks.swift
The requirement executable_test is not needed here. It was there for historical reasons.

rdar://problem/70400635
2020-10-20 13:49:58 +02:00
Slava Pestov
94e999a1b5 Sema: Pull availability checking out of resolveType()
We used to diagnose references to unavailable declarations in
two places:

- inside Exprs, right after type checking the expression
- inside TypeReprs, from resolveType()

In broad terms, resolveType() is called with TypeReprs
stored inside both Stmts and Decls.

To handle the first case, I added a new overload of
diagAvailability() that takes a Stmt, to be called from
typeCheckStmt(). This doesn't actually walk into any Exprs
stored inside the statement; this means it only walks
Patterns and such.

For the second case, a new DeclAvailabilityChecker is
now defined in TypeCheckAccess.cpp. It's structure is
analogous to the other three walkers there:

- AccessControlChecker
- UsableFromInlineChecker
- ExportabilityChecker

The new implementation of availability checking for types
introduces a lot more code than the old online logic
it replaces. However, I hope to consolidate some of the
code duplication among the four checkers that are defined
in TypeCheckAccess.cpp, and do some other cleanups that
will make the benefit of the new approach apparent.
2020-10-14 23:42:02 -04:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Pavel Yaskevich
78fda9ed98 [ConstraintSystem] Use new fix/diagnostic for name shadowing
Stop filtering outer overload choices while trying to pre-check
expression, instead have it always fetch those and use new
fix to only attempt them in diagnostic mode (unless it's min/max
situation with conditional conformances).
2020-01-29 09:14:24 -08:00
Holly Borla
0d95a84e91 [Diagnostics] Improve the error message for when a type fails to satisfy
`AnyObject` layout requirement.
2019-10-18 11:27:21 -07:00
Holly Borla
ef0ecc41e5 [ConstraintSystem] Diagnose missing AnyObject conformance using
the MissingConformance constraint fix.
2019-10-16 20:38:00 -07:00
Pavel Yaskevich
ec6a874ac8 [TypeChecker] NFC: Update test-cases improved by new missing arguments diagnostic 2019-09-25 10:47:26 -07:00
Slava Pestov
0063f158be AST: Request-ify synthesis of the implicit destructor 2019-08-09 19:08:47 -04:00
Jordan Rose
a23eaf4a02 Remove API notes compilation support from swiftc (#21759)
We don't use this feature anymore (see 0149129ed), and now that we've
branched Swift 5.0 for the last time it's time to rip it out of swiftc
(and then from Clang).

No functionality change, unless someone was compiling their own API
notes. If you were doing that, just copy them into place as text.
2019-01-16 10:39:39 -08:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Michael Gottesman
40a09c9c21 Fixup tests for -assume-parsing-unqualified-ownership-sil => [ossa] transition. 2018-12-18 00:49:32 -08:00
Saleem Abdulrasool
4be1c23087 test: #import -> #include
Replace `#import` with `#include` as `#import` is a Microsoft type
library inclusion feature on Windows.  This enables additional APINotes
tests to pass on Windows.
2018-12-02 21:15:42 -08:00
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Jordan Rose
abaf05f1b4 [test] Update APINotes tests for Swift 3 removal
For the most part, this moves 3/4 tests to 4/5 tests. There are
some interesting changes here because API notes for 4 also apply
to 3 unless otherwise specified, and 4.2 is the next version after
4 rather than 5, but everything should still be correct and testing
useful stuff.
2018-07-12 15:44:10 -07:00
Slava Pestov
31ab93b82c Remove Swift 3-specific tests 2018-07-02 21:14:22 -07:00
Pavel Yaskevich
1f3714f264 [ClangImporter] Forward generic parameters to renamed typealias
While trying to import declaration which requires renaming forward
generic parameters (if any) to newly created typealias.
2018-06-13 14:59:47 -07:00
Rintaro Ishizaki
b3453c17fe [ClangImporter] Take isCompatibilityAlias() into account in interface printing (#16625)
If the Clang declrations are *types*, canonical declaration in Swift is
imported for newest version of Swift. In interface generation, if the
declaration is versioned and it's imported as a member in either or both
version of Swift, we have to take compatibility typealias into account.

* Fixed 'ClangModuleUnit::getTopLevelDecls' to take isCompatibilityAlias() into account
* Fixed bugs in ClangImporter where member-to-member versioned types aren't properly imported.
  * Fixed 'SwiftDeclConverter::importFullName' to check equality of getEffectiveContext()
  * Fixed 'importer::addEntryToLookupTable' to check equality of getEffectiveContext()
    (moved 'ClangImporter::Implementation::forEachDistinctName' to 'NameImporter')
2018-05-22 13:38:45 +09:00
Ted Kremenek
836e6c11e8 Mark test as requiring Objective-C interoperability. 2018-05-09 22:20:43 -07:00
Ted Kremenek
fe85d5c97e Update obsoleted entries in versioned-multi.swift test. 2018-05-09 09:54:07 -07:00
Ted Kremenek
cc3024d7c5 Swift 4.x (x < 2) names are obsoleted in 4.2, not 5.
In APINotes, when an unversioned name overrides
a previously declared name with a Swift version, if the
previously declared name is guarded under version 4
the obsoleted version should be 4.2, not 5.  In all other
cases, the obsoleted version is the next major Swift
version.

Fixes rdar://problem/39950937
2018-05-09 00:19:42 -07:00
Mark Lacey
9385dbb3fb Fix exponential type checking of tuple literals.
This fixes two easy cases where we would go exponential in type
checking tuple literals.

Instead of generating a conversion to a single type variable (which
results in one large constraint system), we generate a conversion ot
the same type that appears in the initializer expression (which for
tuples is a tuple type, which naturally splits the constraint system).

I experimented with trying to generalize this further, but ran into
problems getting it working, so for now this will have to do.

Fixes rdar://problem/20233198.
2018-03-26 14:46:03 -07:00
Ted Kremenek
c912fcd1ae Add APINotes test for just “Version 4.2”.
This tests that a “Version 4.2” change impacts
-swift-version 3 and 4, but not 5.
2018-03-23 11:20:29 -07:00
Ted Kremenek
3da51018b6 Teach ClangImporter to handle effective Swift version with minor release.
Needed to support Swift 4.2.
2018-03-23 00:30:44 -07:00
Slava Pestov
93d271900c ClangImporter: Don't import initializers as functions named 'init' 2018-03-14 20:18:52 -07:00
Jordan Rose
b7ff0d49ef Type reconstruction: look for Clang types directly, like RemoteAST
ClangImporter::lookupTypeDecl allows a Clang type declaration to be
imported by Clang name instead of by Swift name. Now that we're using
Clang names in mangled names, that's exactly what we need to
reconstruct an AST type from a mangled name.

Also:

- Handle @compatibility_alias in ClangImporter::lookupTypeDecl

- Print errors when type reconstruction fails in swift-ide-test

- Add an extra test for RemoteAST
2018-01-09 17:55:24 -08:00
Jordan Rose
38e2cfe1e2 Mangle imported declarations using their C names.
This makes them consistent no matter what shenanigans are pulled by
the importer, particularly NS_ENUM vs. NS_OPTIONS and NS_SWIFT_NAME.

The 'NSErrorDomain' API note /nearly/ works with this, but the
synthesized error struct is still mangled as a Swift declaration,
which means it's not rename-stable. See follow-up commits.

The main place where this still falls down is NS_STRING_ENUM: when
this is applied, a typedef is imported as a unique struct, but without
it it's just a typealias for the underlying type. There's also still a
problem with synthesized conformances, which have a module mangled
into the witness table symbol even though that symbol is linkonce_odr.

rdar://problem/31616162
2018-01-09 17:55:24 -08:00
Jordan Rose
18689fe223 [Mangling] Uniformly use "So" for imported decls.
...and repurpose "SC" for (C)lang-importer-synthesized decls, instead
of just decls that are C-like instead of ObjC-like. (See next commits.)
2018-01-09 17:55:23 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Pavel Yaskevich
170ccbd36d [Mangling/ABI] NFC: Fix Frontend/APINotes/Index tests to reflect label mangling changes 2017-12-18 15:45:50 -08:00
Jordan Rose
a0117b0cd0 [ClangImporter] Bump the maximum supported version to Swift 5
"...finally."

This was technically enabled two commits ago, since nothing checks
that you're not /over/ maxVersion(). This is only used for

- deciding the canonical way to import renamed types
- trying to import things in multiple ways

...and so there are very few observable differences, especially
before anyone has added any API notes that differentiate Swift 4
and Swift 5.

At some point we should start encoding name versions in the lookup
tables so that we only have to try all the names /once/, but the test
suite doesn't seem to get measureably slower with this change,
probably because it's pretty quick to decide that most things don't
have multiple names. So we can put that off until later.
2017-09-15 14:30:24 -07:00
Jordan Rose
8a9495a3d1 [ClangImporter] Honor Swift 4 API notes in Swift 3 mode
*** Depends on Clang change "[APINotes] Record what version caused ***
*** an annotation to get replaced." Update your Clang checkout!    ***

More generally, change the meaning of the SwiftVersions section in API
notes to be "this version or earlier" rather than "exactly this
version". We mostly get this behavior for free from the Clang-side
changes, but for SwiftName and the enum annotations we look at inactive
attributes as well. The latter is simple, but the former means being
careful about finding the annotation we /would/ have picked, i.e. the
one closest to the version we requested.
2017-09-15 14:30:24 -07:00
Max Moiseev
4c0368a02a [test] Cleaning up tests 2017-08-29 10:04:39 -07:00
Doug Gregor
e82e7d5fbd [Clang importer] Map swift_objc_members attribute found on superclasses.
Fixes rdar://problem/33514802.
2017-07-25 16:18:31 -07:00
Jordan Rose
663c4f9524 [ClangImporter] Don't import compatibility methods named 'print'. (#10928)
...because they make things harder for people trying to use
Swift.print. Before:

  error: 'print' has been renamed to 'printDocument(_:)'

After:

  error: use of 'print' nearly matches global function
    'print(_:separator:terminator:)' in module 'Swift'
    rather than instance method 'print(_:extra:)'

(This actually occurs with AppKit's NSDocument, so it's not just a
hypothetical concern.)

rdar://problem/32839733
2017-07-13 15:44:39 -07:00
Robert Widmann
71bf312a25 Migrate the rest of the tests to %empty-directory 2017-06-04 11:08:39 -07:00
Dmitri Gribenko
486cab447d tests: replace 'rm -rf %t && mkdir -p %t' with '%empty-directory(%t)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Jordan Rose
9b3c177009 [test] Don't depend on "Version: 4" sections working in API notes yet.
This example works fine with just omit-needless-words and a
Swift-3-only name.

Should fix the bots.
2017-05-16 14:23:44 -07:00
Jordan Rose
5886bc1953 Merge pull request #9579 from jrose-apple/members-through-the-ages
[ClangImporter] Import ObjC members under Swift 3 and 4 names.
2017-05-16 10:16:52 -07:00
Jordan Rose
4f26b0182e Update Swift-side tests for Clang providing an unversioned SwiftName. (#9414)
The behavior in versioned-objc.swift changes now that we've fixed
this, since we always prefer to use a type's Swift 4 name. A handful
of new tests have also been added to versioned.swift.
2017-05-15 10:19:16 -07:00
Jordan Rose
ec23dcaaac [ClangImporter] Find Swift 3 / 4 names via dynamic lookup too.
Finishes rdar://problem/29170671
2017-05-13 14:53:18 -07:00
Jordan Rose
280dacea4c [ClangImporter] Import ObjC members under Swift 3 and 4 names.
...so that developers get proper diagnostics when they use the wrong
name.

rdar://problem/29170671
2017-05-13 14:53:18 -07:00