Commit Graph

1073 Commits

Author SHA1 Message Date
Nathan Lanza
e18bd9903c Convert a clang::Module to non-const to account for a clang API change
An upstream clang changed ASTSourceDescriptor to not have a const
Module pointer. const_cast here to make this agree.

(cherry picked from commit a49bceeedf)
2020-04-10 09:08:33 -07:00
Brent Royal-Gordon
121fa9a058 Ignore transitive ObjC imports when cross-importing
This behavior change reduces the chance of unexpected and unwanted cross-imports being performed.

Fixes rdar://problem/60554019.
2020-04-05 19:06:59 -07:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
Michael Forster
345a9147ec Explicit SmallString->std::string conversion.
This is only needed temporarily until commit d7049213 from upstream
LLVM hits the swift/master branch.
2020-03-13 19:16:49 +01:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Kuba (Brecka) Mracek
ab6533a40f Merge branch 'master' into mracek/arm64e 2020-03-06 15:07:01 -08:00
Doug Gregor
c84bec752f [Clang importer] Suppress method imports found via selector lookup.
When we found Objective-C methods via selector lookup, we would skip the
“should we even try to import this?” check. If the Swift-name-as-derived-
from-Objective-C is different from the actual Swift name, we might try to
(redundantly) import something from the generated Objective-C header,
which can lead to crashes. The specific method causing problems was defined
like this in Swift:

    @objc public class func using(index: AnyObject) -> AnyObject? { return nil }

which produced an Objective-C method like this:

    + (id _Nullable)usingIndex:(id _Nonnull)index;

The Swift name derived from the Objective-C method is `usingIndex(_:)`, which
of course does not match `using(index:)`, meaning that we think these two
methods are different (they aren’t).

The safe fix is to check whether we should import a given Objective-C method
declaration along the found-via-Objective-C-selector path, like we do with
normal name lookup. A longer term fix is to emit swift_name attributes for
such methods.

Fixes the fiendish Clang importer crash in rdar://problem/60046206.
2020-03-05 18:34:29 -08:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Xi Ge
e50096fe22 Merge pull request #30080 from nkcsgexi/ObjCCategoryDecl-canonical
ClangImporter: import non-canonical ObjCCategoryDecl after recent clang changes
2020-02-26 15:49:12 -08:00
Xi Ge
3fe4b89dbf ClangImporter: import non-canonical ObjCCategoryDecl after recent clang changes
Recent clang side change merges ObjCCategoryDecl with the same name. All re-declarations
of a category points to the first category as the canonical one. This patch keeps these
non-canonical redeclarations as separate extensions in Swift.

rdar://problem/59744309
2020-02-26 13:41:09 -08:00
Hamish Knight
d9182af63d [AST] Introduce ModuleDecl::getTopLevelModule
This can be used to retrieve the Swift module
wrapper for a Clang submodule's top-level module.
2020-02-24 20:10:13 -08:00
Brent Royal-Gordon
e248f82773 Add support for loading cross-import files 2020-02-18 11:06:12 -08:00
Slava Pestov
0b502d8c84 AST: loadNamedMembers() never fails
This allows us to simplify lookupDirect() a fair bit as well.
2020-02-12 18:32:46 -05:00
swift-ci
b8eceebd6d Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-08 21:43:28 -08:00
Slava Pestov
7c3cf1d17b ClangImporter: Fix mirroring of instance properties as static methods on NSObject
Because all metaclasses ultimately inherit from NSObject, instance
members of NSObject are also visible as static members of NSObject.

If the instance member is a property, we import the getter as an
ordinary static method, and not a static property.

The lazy loading path normally checks for the presence of alternate
decls with the same name, but it was failing to do this check if the
imported decl was a property and the alternate decl was attached to
the accessor and not the property itself.

This wasn't a problem until recently, because we weren't lazy loading
members of NSObject itself, since it had protocol conformances; now
that we are, this problem was exposed.

Fixes <rdar://problem/59170514>.
2020-02-08 00:06:21 -05:00
swift-ci
6ab5fec4f2 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-04 11:44:06 -08:00
Slava Pestov
d76a8ce920 ClangImporter: Lazily load mirrored protocol members in classes 2020-02-04 09:54:06 -05:00
Slava Pestov
6ba379f3b9 ClangImporter: Refactor loadObjCMethods() to not call CollectMultipleMethodsInGlobalPool()
Let's try calling ObjCInterface::lookupMethod() instead. This also
eliminates an order dependency between selector conflict checking
and protocol member mirroring, which fixes a diagnostics regression
once lazy loading is enabled for mirrored protocol members.
2020-02-04 09:54:06 -05:00
Slava Pestov
c8f990b800 ClangImporter: Don't force loading of all superclass members in loadNamedMembers() 2020-02-04 09:54:06 -05:00
swift-ci
72229ba355 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-24 16:43:36 -08:00
Slava Pestov
305620b354 ClangImporter: Reconcile Clang declaration hidden-ness between loadAllMembers() and lazy loading
Lazy loading checked if the ClangDecl was hidden, but loading all
members did not. Let's make loadAllMembers() behave like the lazy
path, and fix some of the mock SDKs in the test suite.
2020-01-24 17:07:08 -05:00
Erik Eckstein
bbfaccda4b Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-22 08:25:23 +01:00
Devin Coughlin
082421048a [AST/Sema] Add availability attributes for macCatalyst
Add a platform kind and availability attributes for macCatalyst. macCatalyst
uses iOS version numbers and inherits availability from iOS attributes unless
a macCatalyst attribute is explicitly provided.
2020-01-21 20:27:14 -08:00
swift-ci
04e29f0878 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 15:23:13 -08:00
Robert Widmann
e79281d86c Nail Down The Emergent Behaviors of the ClangImporter's Override Checking
The Clang Importer allows for the creation of otherwise illegal Swift
ASTs because it does not run redeclaration checking or override
checking. These behaviors are also not a part of our test suite.

Correct the first issue by re-instating the old emergent behavior of
member loading occurring at all points in the class hierarchy before
a (lazy) lookup.

Correct the second issue by adding a regression test for a common
failure mode in the post-re-entrant-lookup Clang Importer.

We cannot stop accepting these cases, but a future compiler will warn
about them.

Attacks rdar://58493370
2020-01-16 13:18:52 -08:00
Erik Eckstein
1b312a85bd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 10:39:20 +01:00
Robert Widmann
1f59f10f44 Unwind the Bogus Delayed Categories Hack
Delayed categories only existed to keep
ClangImporter/objc_redeclared_properties passing.  But this test
appears to exhibit incorrect behavior as written.

The clang importer implements limited behavior for overwriting
variable declarations. If that overwrite occurs somewhere else in the
class hierarchy, the declaration is rewritten as a Swift override.  The
remaining case is categories, which enable all sorts of awful
redeclaration behaviors.  When a bridging header declares a category
that tries to stomp the API surface of another category, we need to
import that category first, and we would import that category first - by
accident.  Re-entrancy does have its upsides.

In order to keep the tests passing post re-entrant lookup, we stubbed in a hack that delayed
categories in the bridging header so they were installed last, which
meant the variable merging logic would mostly decline to import those
properties.  But the rest of the world expects the opposite: Bridging
header contents are more sacred than the rest of the SDK and must be
installed *first* in order for a number of nightmarish header hacks to
go through.

Unwind the old, incorrect emergent behavior and re-establish the
correct behavior as the way the world ought to work.

Resolves rdar://58493356, rdar://58493357, rdar://58493362, rdar://58493370
2020-01-14 21:42:52 -08:00
Arnold Schwaighofer
0c99cd9734 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 08:00:41 -08:00
Robert Widmann
b05a6223da Merge pull request #29090 from CodaFi/globe-up
[NFC] Unblock Lazy Member Loading For Import-As-Member
2020-01-08 23:09:56 -08:00
Robert Widmann
518ab9f22f [NFC] Unblock Lazy Member Loading For Import-As-Member
Lazy member loading had an antagonistic relationship with the import-as-member facilities. The member tables were stored in a hash map that is keyed by serialized declaration context.  While this was good for importing the entire member set of a given extension, it's in the complete wrong order for lazy member loading, which wants the same data keyed by base name.

Given that it is annoying to redo the globals-as-member tables to support one use case or the other, coupled with the fact that optimizing for one use-case automatically pessimizes the other, just take a page from rdar://18696086 and store the same information twice in two separate formats each optimized for the task at hand.

Preliminary benchmarks indicate that this leads to a 5% reduction in Clang-Imported entities which will drastically speed up most apps that use Dispatch and CoreGraphics.
2020-01-08 21:25:00 -08:00
swift_jenkins
8a3c5c753b Merge remote-tracking branch 'origin/master' into master-next 2020-01-08 09:57:24 -08:00
Arnold Schwaighofer
43c24be5cd Merge remote-tracking branch 'upstream/master' into master-next 2020-01-08 06:41:34 -08:00
Varun Gandhi
afc6ccdeb5 Re-land parsing and printing for Clang function types.
This reverts commit e805fe486e, which reverted
the change earlier. The problem was caused due to a simultaneous change to some
code by the PR with parsing and printing for Clang function types (#28737)
and the PR which introduced Located<T> (#28643).

This commit also includes a small change to make sure the intersecting region
is fixed: the change is limited to using the fields of Located<T> in the
`tryParseClangType` lambda.
2020-01-07 15:58:32 -08:00
Saleem Abdulrasool
e805fe486e Revert "Clang function types v2: Electric Boogaloo (parsing + printing)" 2020-01-06 16:26:08 -08:00
Varun Gandhi
4a1a17d029 Merge pull request #28737 from varungandhi-apple/vg-v3-clang-types-in-swiftinterface
Clang function types v2: Electric Boogaloo (parsing + printing)
2020-01-06 15:42:30 -08:00
Varun Gandhi
96604470ae [AST] Add printing for Clang function types in the AST. 2020-01-06 13:00:04 -08:00
Varun Gandhi
afc6332289 [Sema] Parse a Clang function type from the cType argument. 2020-01-06 13:00:04 -08:00
Kita, Maksim
ea6a2dc094 SR-11889: Fixed code review issues
1. Updated Located field names with Pascal Case
2. Updated Located constuctor
3. Formatted lines with more than 80 symbols
2019-12-20 17:18:59 +03:00
Kita, Maksim
b7cb3b67bf SR-11889: Using Located<T> instead of std::pair<SourceLoc, T> 2019-12-20 17:18:58 +03:00
swift_jenkins
0b31e5b803 Merge remote-tracking branch 'origin/master' into master-next 2019-12-18 18:19:52 -08:00
Robert Widmann
a1b451470e Teach loadNamedMembers to import inherited constructors 2019-12-18 16:17:10 -08:00
swift_jenkins
eee69d9bfa Merge remote-tracking branch 'origin/master' into master-next 2019-12-18 11:19:50 -08:00
Bruno Cardoso Lopes
6eb6bbefd2 Revert "[ClangImporter] Hash content for validation when using clang modules"
This reverts commit c362e925af.

This might be causing hard to reproduce issues. Taking it out until
we have further investigation.

rdar://problem/57964637
2019-12-17 18:25:13 -08:00
swift_jenkins
b8c178351f Merge remote-tracking branch 'origin/master' into master-next 2019-12-17 08:59:51 -08:00
Adrian Prantl
046c849949 Add an option to disable ClangImporter imports form source.
This is primarily meant to used for testing LLDB's DWARFImporterDelegate,
however, this could become the default option for LLDB once
DWARFImporterDelegate is sufficiently mature.

<rdar://problem/57880844>
2019-12-16 13:40:21 -08:00
swift_jenkins
572384f1d2 Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 15:00:26 -08:00
swift-ci
7cdb285791 Merge pull request #28776 from DougGregor/clang-diag-consumer-bridging-pch 2019-12-13 14:41:14 -08:00
Doug Gregor
e40a275e05 [Clang importer] Ensure that we check a bridging PCH in a source file context.
When checking whether we can load a bridging precompiled header (PCH), we end
up parsing module maps. If Clang emits a warning or error while parsing the
module maps we encounter, the Swift compiler would crash because we have not
properly established the invariants of Clang's diagnostic engine. Perform a
pairsed set of BeginSourceFile/EndSourceFile calls on the Clang diagnostic
consumer to set up the appropriate state.

Fixes rdar://problem/57626886.
2019-12-13 11:09:00 -08:00
swift_jenkins
c97c524c80 Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 00:00:34 -08:00
Robert Widmann
dc6858b9e1 Force the entire member table for superclasses
Note that this can be an optimization in many cases since we only have
to scrounge around in the PCMs once.
2019-12-12 21:59:17 -08:00