Commit Graph

1073 Commits

Author SHA1 Message Date
Robert Widmann
fdb73797cd Don't re-force member loading in already-forced class hierarchies
When deserializing a the (named) members of a class hierarchy, we
needn't walk all the way up the hierarchy, just into our superclass.
This will, in turn, walk to its superclass, etc.  This is as opposed to
this work being repeated at each level of the recursive hierarchy.
Should be a small perf win over the last patch.
2019-12-12 10:59:02 -08:00
swift_jenkins
9193112dbe Merge remote-tracking branch 'origin/master' into master-next 2019-12-11 20:59:55 -08:00
Robert Widmann
4a3bb30337 Force the entire inheritance hierarchy to load class members
An unfortunate pessimization that is needed in order to properly build the member table to run override checking.  Considering this was happening anyways thanks to re-entrant lookups, there shouldn't actually be a perf hit here.
2019-12-11 17:05:07 -08:00
Robert Widmann
af6e9b95ad Work around extension installation order
Bridging headers are weird.

A general principle in the Clang Importer is that when it comes to the
notion of "overrides" or "redeclarations", it's always better to prefer
a declaration in the same translation unit, module, header, etc. over
a declaration outside of that thing.

This behavior, unfortunately, occurred as an emergent property of the
re-entrant lookup that was being performed when importing properties.
The behavior of the visible categories list is in "deserialization
order" - that is, a category defined in a header that imports a module
can potentially appear before the module has had its declarations fully
deserialized and installed.  We were assuming this order was instead
"source order", in which modules would be recursively expanded and their
declarations installed sequentially. If this assumption were to hold,
then the visible categories list would respect the principle above, and
we would see categories in defining modules and headers before we saw
categories in extant translation units.

This is not the case. Delayed deserialization of modules means
the first category that gets parsed actually wins. We were not noticing
this, however, because the few places where it actually mattered were
performing re-entrant lookup and were accidentally deserializing modules
and installing decls in this fictitious "source order".  Since we've
untangled this behavior, we now have to emulate the order the Importer
expects.

Introduce the notion of a "delayed category" - a category that is
defined outside of a module, usually by us. As the name implies, we'll
try to load the categories defined in modules first, then go after the
delayed categories defined in extant translation units.  This gives us
a stable "source order", preserves the Principle of Closest Definition,
and undoes the behavior change for overriden property declarations in
the previous commit.
2019-12-11 12:30:59 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Vedant Kumar
f67b9cbbdd Rename CompilerInstance::ModuleManager to match D70583 (#28625)
See: https://reviews.llvm.org/D70583
2019-12-06 14:33:05 -08:00
Robert Widmann
4043d43d43 Drop the requirement that nested types be clang::TypeDecls
The nested types table contains more than just nested typedefs and aggregate decls, it also contains classes that we've imported under nested names.  We were previously falling back to direct lookup to resolve (cross) references to these entities.  Instead, relax the preconditions for searching the table.

This breaks a few cycles involving re-entrant calls to lookupDirect/lookupQualified through the ClangImporter.
2019-11-21 11:53:43 -08:00
swift_jenkins
626f712ce0 Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 20:20:15 -08:00
Bruno Cardoso Lopes
c362e925af [ClangImporter] Hash content for validation when using clang modules
Set it up as part of configuring the modules build. Should help diminish
the amount of clang modules rebuilds due to mtime invalidation.

rdar://problem/57309954
2019-11-20 09:18:35 -08:00
Jonas Devlieghere
2ab36e22f9 Adjust for upstream LLVM changes 2019-11-15 17:08:49 -08:00
swift_jenkins
b9f998ffa4 Merge remote-tracking branch 'origin/master' into master-next 2019-11-15 15:56:48 -08:00
Tony Allevato
3c45041b17 Add driver modes to emit and dump Clang precompiled modules. 2019-11-11 15:00:51 -08:00
swift-ci
8f128e0e19 Merge remote-tracking branch 'origin/master' into master-next 2019-11-07 12:49:07 -08:00
Duncan P. N. Exon Smith
178d209072 ClangImporter: Use a separate CompilerInstance for canReadPCH
ClangImporter::canReadPCH has been trying to reset the main
CompilerInstance back to as if it hadn't run, but there's a long tail of
potential memory corruption here.  One example is that it's reusing
HeaderSearch, but HeaderSearch contains a ModuleMap whose
SourceLocations will point into the soon-to-be-released ASTContext on
the stack.  Instead, just use a separate CompilerInstnace, like the rest
of the ClangImporter does when it needs a different ASTContext.

This fixes a few potential memory corruption bugs, and it *may* be
related to the persistent "missing submodule X" problems hitting Linux
bots.
2019-11-07 10:47:01 -08:00
Duncan P. N. Exon Smith
0a1d270d50 ClangImporter: Remove redundant temporary copy of CompilerInvocation 2019-11-07 10:47:01 -08:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
swift-ci
89318956f7 Merge remote-tracking branch 'origin/master' into master-next 2019-10-30 09:10:41 -07: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
swift-ci
ec9c7e39b3 Merge remote-tracking branch 'origin/master' into master-next 2019-10-29 10:10:11 -07:00
Jordan Rose
b00bc829f8 [ClangImporter] Fall back to Swift class names when resolving @class (#27921)
Christopher Rogers' (good) work in 49fd5acbb2 caught places where
the Swift compiler was allowing a @class to resolve to a Swift class
even if that class had a conflicting Objective-C name, or wasn't
intended to be exposed to Objective-C at all. Unfortunately, this
broke source compatibility in projects where people were relying on
this. Restore that functionality, but only as a fallback; matching the
Objective-C name is better than matching the Swift name.

rdar://problem/56681046
2019-10-29 09:50:49 -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
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Christopher Rogers
1dbf3c784c Comment gardening 2019-10-23 10:40:33 +09:00
Christopher Rogers
e81db0af76 Use the Obj-C name here 2019-10-23 10:40:33 +09:00
Mishal Shah
6b33f225eb Merge branch 'master' into master-next 2019-10-01 13:10:07 -07:00
swift-ci
4e19aef732 Merge remote-tracking branch 'origin/master' into master-next 2019-09-25 15:50:14 -07:00
swift-ci
2dbc10e7aa Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-25 15:43:41 -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
swift-ci
8ce5b01307 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 15:09:47 -07:00
swift-ci
463b04648e Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-18 15:03:46 -07:00
Robert Widmann
5e34169aca Separate computing interface types and underlying types
Computing the interface type of a typealias used to push validation forward and recompute the interface type on the fly.  This was fragile and inconsistent with the way interface types are computed in the rest of the decls.  Separate these two notions, and plumb through explicit interface type computations with the same "computeType" idiom.  This will better allow us to identify the places where we have to force an interface type computation.

Also remove access to the underlying type loc.  It's now just a cache location the underlying type request will use.  Push a type repr accessor to the places that need it, and push the underlying type accessor for everywhere else.  Getting the structural type is still preferred for pre-validated computations.

This required the resetting of a number of places where we were - in many cases tacitly - asking the question "does the interface type exist".  This enables the removal of validateDeclForNameLookup
2019-09-17 08:20:55 -07:00
Nathan Lanza
57bf724b1e [ClangImporter] Update an DirectoryEntry usage to DirectoryEntryRef
A DirectoryEntryRef was added to wrap DirectoryEntrys and numerous
APIs were changed to use it in clang. Change one usage here to account
for the difference.
2019-09-11 19:01:42 -07:00
swift-ci
94d35be2ae Merge remote-tracking branch 'origin/master' into master-next 2019-09-10 09:29:47 -07:00
swift-ci
d4521dc7a1 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-10 09:24:32 -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
swift-ci
449b08ea36 Merge remote-tracking branch 'origin/master' into master-next 2019-09-06 14:29:08 -07:00
swift-ci
9bf6d8689d Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-06 14:23:36 -07: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
swift-ci
9a58a12c25 Merge remote-tracking branch 'origin/master' into master-next 2019-09-05 17:09:50 -07:00
swift-ci
9b22737062 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-05 17:03:42 -07:00
Jordan Rose
e42dd5ac08 [ClangImporter] Protect against re-entrant bridging header loading (#27045)
If, while loading a bridging header, we pick up a Clang module that
claims to have an overlay Swift module, and that Swift module turns
out to have a bridging header, we can end up reallocating the array
of modules to process while we're looping over it. Be defensive
against this occurrence.

This just fixes a crash; it does not at all solve the problem of this
being broken in several ways:

- Accidentally naming your module the same as a system module shadows
  the latter (if the system module is a Swift module) or *makes your
  module into an overlay* (if the system module is a Clang module).

- Bridging headers are only officially supported on executable targets
  and unit tests, but this isn't really enforced.

- Implicit inclusion of a bridging header *when you import a Swift
  module* is a hack to begin with, and a hack that worsens when the
  main module also has a bridging header. (All the bridging headers
  get folded together into the "same" module, which leads to more
  visibility than desired as well as cycles in the import graph.)

- Combining all of these can result in some pretty bizarre behavior.

rdar://problem/54581756
2019-09-05 17:00:14 -07:00
Saleem Abdulrasool
285368d261 Merge pull request #27002 from lanza/ref
[ClangImporter] Update an DirectoryEntry usage to DirectoryEntryRef
2019-09-05 10:23:50 -07:00
swift-ci
29220ca204 Merge remote-tracking branch 'origin/master' into master-next 2019-09-04 15:29:49 -07:00
swift-ci
eb52f0c448 Merge remote-tracking branch 'origin/master' into master-rebranch 2019-09-04 15:23:47 -07: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
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
75f4625bee AST: Peel off ClangModuleLoader.h from ASTContext.h 2019-09-03 22:39:35 -04:00