Commit Graph

514 Commits

Author SHA1 Message Date
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
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
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
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
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
d76a8ce920 ClangImporter: Lazily load mirrored protocol members in classes 2020-02-04 09:54:06 -05: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
Slava Pestov
f883fff0b8 ClangImporter: Fix quadratic behavior with property overrides
We would add all imported members to a per-nominal vector, and
then perform shadowing checks on the entire list, followed by
visiting each one to look for a matching member with the
right name.

We were spending a lot of time inside this function as a result.
Instead, change Impl.MembersForNominal to store a mapping from
names to lists of members having that name, changing this into
an O(1) lookup.

Fixes <rdar://problem/58363207>.
2020-01-10 00:21:02 -05:00
Robert Widmann
a4105b1694 [NFC] Clean the ClangImporter a bit
Push some state closer to where it's actually needed and remove helper functions that aren't actually all that helpful.  Replace these with an assertion for the real invariant here.
2020-01-08 23:23:55 -08:00
Kita, Maksim
646e9ac77f SR-11889: Fixed code review issues 2019-12-22 14:42:47 +03:00
Kita, Maksim
b7cb3b67bf SR-11889: Using Located<T> instead of std::pair<SourceLoc, T> 2019-12-20 17:18:58 +03:00
Robert Widmann
a1b451470e Teach loadNamedMembers to import inherited constructors 2019-12-18 16:17:10 -08:00
Robert Widmann
d2f7a27190 [NFC] Const-ify Some ClangImporter Interfaces 2019-12-18 16:17:10 -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
Robert Widmann
4f04a80d17 Redo ObjC Override Checking
The general problem with this approach is that the clang importer is part of the cache-fill for name lookup.  This means that qualified lookups it runs will be re-entrant and result in validation-order-dependent behaviors.

The next commit will restore the expected ordering behavior here.
2019-12-11 12:30:58 -08:00
Robert Widmann
ac08fceacc Add loadDynamicallyReplacedFunctionDecl
To support lazy resolution of the cross-referenced function in a serialized @_dynamicReplacement(for: ...) attribute, add a utility to the LazyMemberLoader and plumb it through.  This is a more general utility than the current resolver, which relies on the type checker to strip the attribute off of VarDecls and fan it back out onto accessors, which means serialization has only ever seen AbstractFunctionDecls.
2019-12-03 15:28:19 -08:00
Jordan Rose
37bb356ced Merge pull request #27924 from jrose-apple/attribute-attribution
[ClangImporter] Diagnose bad swift_name attributes better
2019-10-30 09:02:12 -07:00
Jordan Rose
b7c4c5197b [ClangImporter] Simplify inferDefaultArgument by removing numParams (#27864)
The only thing this was used for is to test if the total number of
parameters was 1, in which case we did the same thing we did for a
first parameter except in one very contrived case: a method with more
than one parameter whose base name starts with "set" and whose first
parameter is an NSZone. There are zero of these in the macOS or iOS
SDKs, and probably even fewer in third-party code.
2019-10-29 15:38:53 -07:00
Jordan Rose
8168669a27 [ClangImporter] Diagnose bad swift_name attributes better
1. Set the diagnostic location to where the attribute was written (or
   to the Clang decl's source, if the attribute came from API notes)

2. Add a note to contact the owners of the framework to make it clear
   that the client of the framework didn't do anything wrong.

rdar://problem/52736145
2019-10-28 22:08:26 -07:00
Jordan Rose
e364552876 [ClangImporter] Pull buffer importing out of ClangDiagnosticConsumer
Emitting Swift diagnostics in Clang buffers requires making those
buffers valid places to put Swift SourceLocs, which means making a
mirror of those buffers in the Swift SourceManager. This isn't a copy;
instead, any Clang SourceManagers that are involved are kept alive
until the importer is torn down. (There might be more than one because
of diagnostics emitted during module building.)

For a long time we only emitted diagnostics in Clang buffers if the
diagnostics came from Clang, but then we added another case for custom
Swift names that fail to import. I'm about to add another such
diagnostic, so let's formalize this buffer mapping first.

No intended functionality change.
2019-10-28 22:08:26 -07:00
Hamish Knight
c1a1ddd458 Requestify needsNewVTableEntry
This commit introduces `NeedsNewVTableEntryRequest`,
which checks whether a class method needs a new
vtable entry.
2019-10-03 19:13:39 -07:00
Slava Pestov
6702d38d87 Sema: Remove most calls to Decl::setValidationToChecked() 2019-10-03 17:11:45 -04:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Jordan Rose
c12b924712 [ClangImporter] Make it easier to get Swift pointer types
No functionality change. Nice to drop a string-based API while I'm at
it.
2019-09-27 13:54:04 -07:00
Jordan Rose
caa5be84d5 [ClangImporter] Use external_source_symbol to identify Swift decls (#27355)
...rather than replacing particular macros with an 'annotate'
attribute and then looking for that. This isn't /really/ any
particular win except maybe ever-so-slightly faster module imports
(with one fewer attribute being added to each declaration in a
mixed-source header).

This doesn't remove the SWIFT_CLASS_EXTRA, SWIFT_PROTOCOL_EXTRA, or
SWIFT_ENUM_EXTRA macros from PrintAsObjC (note that
SWIFT_EXTENSION_EXTRA was never used). They're not exactly needed
anymore, but they're not doing any harm if someone else is using them.
2019-09-25 15:30:03 -07:00
Jordan Rose
80e646642f [ClangImporter] importMethodType -> importMethodParamsAndReturnType (#27349)
And similar for importFunctionParamsAndReturnType and
importAccessorParamsAndReturnType. In all cases the return type isn't
a FunctionType, and there's also a ParameterList out-parameter.

No functionality change.
2019-09-24 18:39:03 -07:00
Jordan Rose
2b25fe0ef2 [ClangImporter] Remove now-unnecessary special case for IUO importing
Back when IUO could be used anywhere in a type in Swift, we had a
special case for imported pointer types that their pointees were never
implicitly-unwrapped, even if they weren't nullability-audited on the
Objective-C side. Now that IUO can only be used in top-level positions
(SE-0054, only fully implemented last year), we don't need a special
case for this; all non-top-level optionals are never
implicitly-unwrapped.

No functionality change.
2019-09-20 17:03:53 -07:00
Jordan Rose
91a5abadd8 Merge pull request #27268 from jrose-apple/the-hit-new-game-sim-plify
[ClangImporter] Assorted NFC cleanups and simplifications
2019-09-20 16:59:48 -07:00
Jordan Rose
311607ec40 [ClangImporter] Simplify typedef bridgeability checking
A typedef might get imported as an alias for a bridged type (String)
or for the original type (NSString), and a few parts of the importer
need to account for this. Simplify this logic based on how it's used
today.
2019-09-19 19:44:07 -07:00
Brent Royal-Gordon
0ce2434d43 [NFC] Convert ClangImporter use to getNSCopyingDecl() 2019-09-19 09:49:49 -07:00
Jordan Rose
d4ac04d25e Move access-path filtering into ModuleNameLookup (out of lookupValue) (#27097)
Removes duplicated logic from the implementations of
FileUnit::lookupValue, and simplifies the interface to
ModuleDecl::lookupValue, where everyone was passing an empty
(non-filtering) access path anyway /except/ during actual lookup from
source code. No functionality change.
2019-09-10 09:13:20 -07:00
Slava Pestov
f292c1b240 AST: Remove GenericContext::setGenericEnvironment()
This was a transitional step before converting all callers to
store a generic signature instead of an environment.
2019-09-06 17:16:04 -04:00
Slava Pestov
0405ab5ffc AST: GenericContexts store a GenericSignature instead of a GenericEnvironment
This eliminates the entire 'lazy generic environment' concept;
essentially, all generic environments are now lazy, and since
each signature has exactly one environment, their construction
no longer needs to be co-ordinated with deserialization.
2019-09-06 17:16:04 -04:00
Slava Pestov
99ea1bb980 ClangImporter: Sink getEffectiveClangNode() down from IDE to the importer and clean up related code 2019-09-06 16:03:51 -04:00
Slava Pestov
06a2d8bf85 ClangImporter: Faster globals-as-members check in the lazy member loading path 2019-09-03 22:53:52 -04:00
Slava Pestov
89d5725c63 ClangImporter: Delay building imported conformances until we ask for them 2019-09-03 22:53:52 -04:00
Slava Pestov
be84556b9e ClangImporter: Record the error wrapper's struct 'Code' member enum in a side table 2019-09-03 22:53:52 -04:00
Slava Pestov
220bc64064 ClangImporter: Directly track constructors imported into a nominal type
This avoids a re-entrant lookup while doing lazy member loading,
and eliminates a usage of LookupDirectFlags::IgnoreNewExtensions,
and the last usage of NominalTypeDecl::makeMemberVisible().
2019-09-03 22:39:36 -04:00
Slava Pestov
2ff39d227c AST: Remove some unused LazyResolver usages 2019-08-23 22:13:34 -04:00
adrian-prantl
793dbed5ee Merge pull request #26707 from adrian-prantl/filter
DWARFImporter: Allow filtering type lookups by containing module.
2019-08-21 16:30:17 -07:00
Slava Pestov
62f18a52c0 Sema: Move attribute checking to typeCheckDecl() 2019-08-20 14:47:52 -04:00
Adrian Prantl
d7c63daf82 DWARFImporter: Allow filtering type lookups by containing module. 2019-08-19 17:24:31 -07:00
adrian-prantl
2d86f23988 Merge pull request #26682 from adrian-prantl/loadmodule
Move ClangImporter::loadModuleClang() into ClangImporter::Implementation
2019-08-16 08:42:53 -07:00
adrian-prantl
2ae84202c4 Merge pull request #26689 from adrian-prantl/dummy-dwarfimporter
Add back the dummy DWARFImporter test to lldb-moduleimport-test.
2019-08-16 08:42:33 -07:00
Slava Pestov
7e788d421a Merge pull request #26684 from slavapestov/is-iuo-request
Introduce IsImplicitlyUnwrappedOptionalRequest
2019-08-15 22:08:00 -04:00
Adrian Prantl
1020d8188a Add back the dummy DWARFImporter test to lldb-moduleimport-test. 2019-08-15 16:35:05 -07:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Adrian Prantl
787b6cb8a4 Move ClangImporter::loadModuleClang() into ClangImporter::Implementation
so it forms an obvious contrast with loadModuleDWARF(). Also document
the difference between the two calls.
2019-08-15 15:17:08 -07:00
Adrian Prantl
c76c810c9d Move the ownership of DWARFImporterDelegate away from ClangImporter (NFC). 2019-08-15 13:31:29 -07:00