Commit Graph

3522 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
4de19e1c3c Merge pull request #30819 from brentdax/a-less-ambitious-crossover-event
Ignore transitive ObjC imports when cross-importing
2020-04-08 11:40:35 -07:00
Marc Rasi
be9d35cece Merge branch 'master' into derivative-attr-serialization 2020-04-06 16:58:08 -07:00
Stephen Canon
248c554524 Add Float16 to stdlib (#30130)
Add Float16 (IEEE 754 binary16) to the standard library, plus assorted runtime support operations.

Swift Evolution thread: https://forums.swift.org/t/se-0277-float16/33546
2020-04-06 17:57:44 -04:00
Dan Zheng
83f6714334 [AutoDiff] Start fixing SR-12526.
Start fixing SR-12526: `@derivative` attribute cross-module deserialization
crash. Remove original `AbstractFunctionDecl *` from `DerivativeAttr` and store
`DeclID` instead, mimicking `DynamicReplacementAttr`.
2020-04-06 06:37:23 -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
Robert Widmann
b78ed5319b Merge pull request #30800 from CodaFi/erase-install
[Serialization] Lazily Resolve the Eraser Type of @ _typeEraser
2020-04-03 22:32:40 -07:00
Robert Widmann
27b211c1f9 Lazy-load the eraser of @_typeEraser where possible
Type erasure requires a circular construction by its very nature:

@_typeEraser(AnyProto)
protocol Proto { /**/ }
public struct AnyProto : Proto {}

If we eagerly resolve AnyProto, the chain of resolution steps that
deserialization must make goes a little something like this:

Lookup(Proto)
    -> Deserialize(@_typeEraser(AnyProto))
    -> Lookup(AnyProto)
    -> DeserializeInheritedStuff(AnyProto)
    -> Lookup(Proto)

This cycle could be broken if the order of incremental inputs was
such that we had already cached the lookup of Proto.

Resolve this cycle in any case by suspending the deserialization of the
type eraser until the point it's demanded by adding
ResolveTypeEraserTypeRequest.

rdar://61270195
2020-04-03 14:52:21 -07:00
Michael Forster
98bbb81f82 [C++] Make const member variables read-only
This imports const members of C++ structs/classes stored properties with
an inaccessible setter.

Note that in C++ there are ways to change the values of const members,
so we don't use `WriteImplKind::Immutable` storage.

Resolves: [SR-12463](https://bugs.swift.org/browse/SR-12463)
2020-04-03 13:15:33 +02:00
Anthony Latsis
c63b737e92 Collapse all indirect equivalents to ValueDecl::getBaseIdentifier 2020-03-29 00:36:01 +03:00
martinboehme
fa7155073d Don't import C++ class members that are protected or private (#30233)
* Don't import C++ class members that are protected or private.

We omit protected members in addition to private members because Swift
structs can't inherit from C++ classes, so there's effectively no way to
access them.

* Check access specifiers centrally in importDeclImpl().

* Fix macOS build by using <stddef.h> instead of <cstddef>.

Apparently, the macOS toolchain doesn't provide <cstddef>.

<stddef.h> is used in test/Inputs/clang-importer-sdk/usr/include/macros.h,
so I'm assuming it will be OK. (I don't unfortunately have a macOS
machine to test on.)

* Add comment explaining why we skip private and protected C++ class
members.
2020-03-19 08:20:36 -07:00
Martin Boehme
490021fec6 Fix: Access NamedDecl::getName() only if the name is an identifier.
Non-identifier names aren't currently an issue, but it will become one
when we add more support for C++, e.g. for C++ constructors (which I
plan to tackle soon).
2020-03-18 09:04:36 +01: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
Shoaib Meenai
b6301c256c Include TargetInfo.h explicitly
https://github.com/llvm/llvm-project/commit/d7c5037e6b9f removes
implicit transitive includes of TargetInfo.h, so we must include it
explicitly where it's needed.
2020-03-11 23:36:59 -07: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 (Brecka) Mracek
5d918e5ee1 Merge branch 'master' into mracek/arm64e 2020-03-03 08:28:01 -08:00
Robert Widmann
de72824b04 [Gardening] Canonicalize usages of ASTContext::Stats 2020-02-27 17:12:58 -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
df064968f2 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 22:04:41 -08:00
Slava Pestov
362047f5f5 Merge pull request #29679 from slavapestov/fix-enum-error-case-alias
ClangImporter: Fix importEnumCaseAlias() when the original is itself an alias
2020-02-07 00:50:16 -05:00
swift-ci
c8671f672b Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 21:04:42 -08:00
John McCall
faee21b626 Implement Swift serialization and deserialization of Clang types.
As part of this, we have to change the type export rules to
prevent `@convention(c)` function types from being used in
exported interfaces if they aren't serializable.  This is a
more conservative version of the original rule I had, which
was to import such function-pointer types as opaque pointers.
That rule would've completely prevented importing function-pointer
types defined in bridging headers and so simply doesn't work,
so we're left trying to catch the unsupportable cases
retroactively.  This has the unfortunate consequence that we
can't necessarily serialize the internal state of the compiler,
but that was already true due to normal type uses of aggregate
types from bridging headers; if we can teach the compiler to
reliably serialize such types, we should be able to use the
same mechanisms for function types.

This PR doesn't flip the switch to use Clang function types
by default, so many of the clang-function-type-serialization
FIXMEs are still in place.
2020-02-06 22:09:00 -05:00
Slava Pestov
b903382866 ClangImporter: Fix importEnumCaseAlias() when the original is itself an alias
This comes up when an imported error enum has duplicate cases.
The FooError.Code enum has an alias for the duplicate case, and
the wrapper type FooError defines aliases for every member of
FooError.Code.

The implementation of importEnumCaseAlias() assumed that 'original'
was an EnumElementDecl, and built AST accordingly; however if it
is a 'VarDecl', we have to build a MemberRefExpr instead.

This regression was introduced in https://github.com/apple/swift/pull/25009.

Fixes <rdar://problem/58552618>.
2020-02-06 19:47:05 -05:00
swift-ci
1bcabbe6a7 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-04 15:44:54 -08:00
Robert Widmann
e825ca1d32 [ClangImporter] Reject *all* attempts to redeclare properties
Add an algorithm to go search the override tables *and* the existing
loaded members of a class for a redeclaration point.  The idea is that
both mirrored protocol members and categories offer a way to convince
the Clang Importer to import a property twice. We support a limited form
of this multiple-imports behavior today by allowing the redeclared
property to refine a readonly property into a readwrite property.

To maintain both the refinement behavior and to disambiguate any
remaining cases of ambiguity caused by extensions, attempt to identify
a redeclaration point if we can't identify an override point. Then,
decline to import the redeclared member if we're successful.

Note that the algorithm as presented is subject to import ordering. That
is, if a framework declares both an overlay and a clang module unit, if
the overlay is not loaded or members from the overlay are not installed
in the class by the time we see the declaration we may fail to identify
an redeclaration point.

The regression tests are for rdar://59044692, rdar://59075988, and
rdar://59125907.
2020-02-04 13:15:32 -08: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
7e7b6e8b27 ClangImporter: Fix up importSubscript() to not depend on import order
Once lazy loading supports mirrored protocol members, we can end up
calling importSubscript() for a setter method before we've mirrored
the getter. In this case, we call findCounterpart() with the setter,
which finds the imported getter from the ProtocolDecl itself.

Stop processing the potential subscript in this case, since when we
later mirror the protocol member, we'll go and build it again.

This should be NFC without the next change I'm working on.
2020-02-04 09:54:06 -05:00
Slava Pestov
95d9aa0f29 ClangImporter: Refactor importInheritedConstructors()
The lambda here was completely unnecessary.
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
126434e79c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-25 14:44:33 -08:00
Robert Widmann
b09c9957ad Reintroduce NameLookupFlags::IgnoreNewExtensions
Soft revert a09382c. It should now be safe to add this flag back as an optimization to specifically disable lazy member loading instead of all extension loading.

Push the flag back everywhere it was needed, but also push it into lookup for associated type members which will never appear in extensions.
2020-01-25 11:04:53 -08: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
swift-ci
4ce207c556 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-23 10:44:28 -08:00
David Zarzycki
0d7820c613 Merge pull request #29387 from davezarzycki/pr29387
[CMake] Fix missing linker deps when using BUILD_SHARED_LIBS
2020-01-23 13:39:12 -05:00
David Zarzycki
3a7d87b4ed [CMake] Fix missing linker deps when using BUILD_SHARED_LIBS 2020-01-23 09:40:56 -05:00
swift-ci
4289dd952c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-23 05:44:02 -08:00
Slava Pestov
e6e127b09f ClangImporter: Tighten up isMethodAlreadyImported()
Allow two methods to be imported with the same selector, as long as they
have different Swift DeclNames. This is required for lazy mirrored protocol
member loading to work correctly, so that the same declarations are
imported regardless of name lookup order. The commit for the mirrored
protocol member change will have test cases that cover this behavior.
2020-01-23 00:23:21 -05:00
swift-ci
11550b4c0c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-22 09:43:43 -08:00