Commit Graph

49 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Jordan Rose
9a9d139320 [ClangImporter] Import Swift 3 and 4 names for enumerators. (#9523)
Also lays the groundwork for rdar://problem/16513537, which is about
being able to find an enum by its original top-level name so that we
can show a diagnostic for that. I'll file a public bug about that
later.

rdar://problem/31893305
2017-05-12 14:51:40 -07:00
Doug Gregor
5934a86566 [Clang importer] Look through typealiases when importing members of swift_wrappers.
When a swift_wrapper'd type is renamed from Swift 3 -> 4, we create a
typealias for it. We need to look through that typealias when
deserializing members of that type, e.g., global variables of the
swift_wrapper'd type.
2017-05-04 16:41:01 -07:00
Jordan Rose
dbc148bfb3 [ClangImporter] Tag compatibility aliases as such...
...so we can avoid showing an 'aka' for them...unless they are
themselves typealiases.
2017-04-26 13:07:03 -07:00
Jordan Rose
ba230e0500 [ClangImporter] Add tests for generic compatibility typealiases.
The implementation here is pretty slapdash, and I'm about to do
something safer, but it seems to be working now and I don't want
to break it.
2017-04-13 14:08:14 -07:00
Jordan Rose
08b6c5f0c9 [ClangImporter] Add support for 'SwiftImportAsNonGeneric' in API notes (#6962)
Generic Objective-C classes with this annotation will be imported as
non-generic in Swift. The Swift 3 behavior hardcoded a certain set of
class /hierarchies/ as permanently non-generic, and this is preserved
in Swift 3 mode.

Actually using this API note in a versioned way (as opposed to just
marking the class non-generic in all language versions) will cause
horrible source compatibility problems in the mix-and-match cases,
where Swift 3 code presents a non-generic type that Swift 4 expects to
be generic or vice versa.  Fixes for this will come later; right now
it's more important to add support for the feature at all.

To avoid unwanted changes in Swift 4, this commit also adds API notes
to make any existing classes in the previously-hardcoded set continue
to import as non-generic even in Swift 4. The difference is that
/subclasses/ of these classes may come in as generic. (If we want to
make a change here, that can be a separate commit.)

rdar://problem/31226414 (Swift side of rdar://problem/28455962)
2017-04-03 15:39:19 -07:00
Doug Gregor
57c607e339 [SE-0160] Map Clang's swift_objc_members attribute to @objcMembers.
This finishes the implementation of SE-0160, tracked by SR-4481 /
rdar://problem/28497874.
2017-04-03 11:48:55 -07:00
Jordan Rose
0328139a77 [ClangImporter] Don't crash on versioned import-as-member stubs. (#8269)
If a top-level declaration is imported as a member in Swift 4 but not
in Swift 3, it would still show up in the lookup table for the
containing type in Swift 3 mode. We would import it, and then try to
add the top-level declaration to the containing type.

I'm about to redo this anyway so that the versioned stub will show up
(the one for the Swift 4 name) but this is the narrow fix that avoids
the assertion failure we were seeing.

rdar://problem/31161489
2017-03-22 13:48:03 -07:00
practicalswift
4b3d61bb9e [gardening] Fix accidental \t 2017-03-02 15:23:43 +01:00
Jordan Rose
c402030877 [ClangImporter] Give compatibility typealiases the correct version.
Unlike values, we can't import multiple copies of types under
different names and get good results. Instead, we make a typealias
that points back to the original type. Make sure this typealias is
flagged with whatever version is appropriate, rather than always using
"Swift 2".
2017-02-24 16:11:33 -08:00
Jordan Rose
79ed26f575 [ClangImporter] Use the correct name for replacement decls.
When a C declaration is marked unavailable with a replacement, we look
for the replacement to see how it would be imported into Swift. Make
sure we do that with respect to the active language version.
2017-02-24 16:11:33 -08:00
Jordan Rose
b9853c209e [ClangImporter] Fix marking of protocols with missing requirements.
This doesn't actually have any effect yet, but if we start importing
both Swift 3 and Swift 4 versions of protocol requirements and the
non-active one is unavailable, we might mistakenly mark the protocol
un-implementable even when the requirements that are needed are all
there. (Hopefully we would never make a protocol /less/ available in a
newer release, of course.) The test case is designed to catch that.
2017-02-24 16:11:33 -08:00
Doug Gregor
609f9b5a84 [Clang importer] When importing a property as accessors, use accessor types.
When importing a property as accessor methods (rather than as a
property), we were still importing the type of the accessor methods as
if they were Swift getters and setters of a property, which
(necessarily) homogenizes the types. The homogenization is unnecessary
when importing as accessor methods, because the methods are
independent, so just import the accessor method types as if the
property did not exist. This is particularly useful for maintaining
Swift 3 source compatibility for cases where Swift 4 turns a
getter/setter pair into a null_resettable property.

Fixes rdar://problem/30075571.
2017-01-18 10:02:57 -08:00
Doug Gregor
7c81c36742 [API Notes] Add tests for API notes that change types of Clang declarations.
Testing for rdar://problem/28943642.
2016-11-11 23:16:18 -08:00
Jordan Rose
7659012401 [ClangImporter] Respect SwiftImportAsAccessors in APINotes. (#5728)
Swift side of this new flag. This allows Objective-C framework authors
to replace a pair of methods by properties without breaking source
compatibility. This is especially important for class properties,
which were only introduced last year.

Still to come: importing the accessors even when this flag isn't set,
in order to provide better QoI when migrating from a method interface
to a property interface.

Part of rdar://problem/28455962
2016-11-11 17:32:07 -08:00
practicalswift
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
Doug Gregor
c91064ba8e [Clang importer] Pass Swift major version to Clang's API notes.
Clang now accepts an option -fapinotes-swift-version=XX that describes
which Swift version to use when applying API notes to the Clang
AST. Pass this option down to Clang based on the Swift major version
number (e.g., 3 or 4), allowing API notes to introduce
Swift-version-specific behavior.

Fixes rdar://problem/28617631.
2016-10-04 14:23:03 -07:00
Doug Gregor
df9a454650 [API Notes] Update test for new location of API notes in frameworks 2016-10-03 09:06:32 -07:00
Doug Gregor
580a2812a3 [Clang importer] Enable API notes alongside header/frameworks.
Enable newly-introduced Clang functionality to load API notes stored
alongside the headers for a module or, for a framework, in an APINotes
subdirectory within the framework. Fixes rdar://problem/28455644.
2016-09-28 00:13:16 -07:00
Jordan Rose
3d9d0a3c90 Allow nested names in @available(*, renamed:"..."). (#2722)
This can be used as QoI for things like 'NSASCIIStringEncoding', which
is going to canonically be `String.Encoding.ascii` if/when SE-0086 is
accepted.

We can't actually handle this in NS_SWIFT_NAME (that is, we can't
/import/ something onto a nested type), but that's okay: we already
have stricter limitations on NS_SWIFT_NAME enforced by Clang.

rdar://problem/26352374
2016-05-26 12:54:05 -07:00
Joe Groff
ea1bf9c999 Add a test that C functions with malformed import-as-member-property API notes don't crash. 2016-05-18 11:03:52 -07:00
Doug Gregor
c9fa65097e [API Notes] Test SwiftPrivate API notes.
*Clang update required*

Test that rdar://problem/25872038 works for Swift.
2016-04-21 23:37:18 -07:00
Doug Gregor
1899882942 [API Notes] Test API notes for tags and typedefs.
Verifies the Clang-side change for rdar://problem/25365464.

**Clang update required**
2016-03-30 23:37:58 -07:00
Doug Gregor
da60535ced [Driver / API Notes] Re-introduce "-apinotes" driver flag to compile API notes.
Using Clang to compile API notes introduces a dependency on the
underlying Clang, which can cause problems as Clang's support for API
notes evolves. Re-introduce the "-apinotes" driver flag into the Swift
driver to allow us to compile API notes, and use that (rather than
Clang) to precompile API notes for the overlays.
2016-03-04 14:12:15 -08:00
Doug Gregor
88d73faba8 [API Notes] Test use of API notes to change the Swift name of an entity.
*Note*: requires Clang update, which adds support for SwiftName.
2016-02-20 22:03:38 -08:00
Dmitri Hrybenko
db63818d57 Remove old-style API notes infrastructure
Swift SVN r23080
2014-11-03 05:59:30 +00:00
Jordan Rose
9b07f35cc0 Audit NSDictionary's subscript.
This requires a bit of special handling because we override the getter's type
in the importer, to make sure it's compatible with the setter, but other than
that we just use the information from the apinotes file.

<rdar://problem/17891179>

Swift SVN r21027
2014-08-04 23:16:53 +00:00
Doug Gregor
0ad6ad65c8 API notes: add a "Required" field for Objective-C methods.
This allows us to express required initializers in the API notes. Use
it to smooth over NSString differences in the various SDKs even more.

Swift SVN r20511
2014-07-24 20:14:48 +00:00
Anna Zaks
39eb145c10 APINotes: Teach the YAML converter about OS availability.
The converter silently drops the API which are available only on a OS different from the specified "target".

I've restructured the code so that we would not have to pass the parameters around.

TODO:
 - Make the traget argument required.
 - Use it in the build system when building swift
 - Add a test case for when the whole framework is missing. (Tested manually.)

Swift SVN r20464
2014-07-24 03:16:58 +00:00
Anna Zaks
ddaa294eca API notes: turn FactoryAsInit into 3-state on YAML side.
Swift SVN r20463
2014-07-24 03:16:58 +00:00
Doug Gregor
97853b89fa API notes: add support for global functions to the binary format
Swift SVN r20423
2014-07-23 18:46:52 +00:00
Doug Gregor
1e16a23460 API notes: add support for global variables in the binary format
Swift SVN r20417
2014-07-23 17:51:34 +00:00
Doug Gregor
9222a1624d API notes: add a small YAML -> binary -> YAML roundtrip test.
Swift SVN r20414
2014-07-23 17:16:12 +00:00
Doug Gregor
d3456b62d6 Rename test/APIAnnotation to test/APINotes to match the library name.
Swift SVN r20398
2014-07-23 14:24:06 +00:00