Commit Graph

559 Commits

Author SHA1 Message Date
Robert Widmann
ed18f47d05 Port getInterfaceType() patterns in libAST 2019-09-23 16:49:09 -07:00
swift-ci
8ce5b01307 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 15:09:47 -07:00
Robert Widmann
38bde33067 Merge pull request #27172 from CodaFi/aliasing-artifacts-and-noise-reduction-techniques
Kill validateDeclForNameLookup Harder
2019-09-18 15:00:51 -07:00
swift-ci
a453eda2dc Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 10:09:53 -07:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -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
swift-ci
c30fcd3e88 Merge remote-tracking branch 'origin/master' into master-next 2019-09-14 18:49:28 -07:00
David Ungar
c7e603ddf7 Fix overly restrictive assertion, for -dump-scope-maps case 2019-09-14 13:41:59 -07:00
David Ungar
968c5a8282 Eager tree building for primaries 2019-09-13 17:22:50 -07:00
swift-ci
94d35be2ae Merge remote-tracking branch 'origin/master' into master-next 2019-09-10 09:29:47 -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
af96552a20 Merge remote-tracking branch 'origin/master' into master-next 2019-08-29 16:50:55 -07:00
Slava Pestov
3956fc0653 AST: Fold forAllImportedModules() into collectLinkLibraries() 2019-08-29 15:57:38 -04:00
Slava Pestov
2256b1fcc2 AST: Introduce namelookup::getAllImports() to replace forAllVisibleModules() 2019-08-29 15:57:38 -04:00
swift-ci
895176fab0 Merge remote-tracking branch 'origin/master' into master-next 2019-08-28 18:09:45 -07:00
Slava Pestov
3819f341bd AST: Use ImportCache to simplify SourceFile::isImportedImplementationOnly() 2019-08-28 16:29:49 -04:00
Slava Pestov
acf5371dfc AST: Introduce a new ImportCache singleton 2019-08-28 16:29:49 -04:00
Arnold Schwaighofer
20efacf2d6 Merge remote-tracking branch 'upstream/master' into master-next 2019-08-26 13:30:41 -07:00
Jordan Rose
c50113185f Merge pull request #26816 from jrose-apple/cant-stand-the-rain
Fix a pair of leaks related to FileUnit destructors not being run
2019-08-26 11:06:54 -07:00
Arnold Schwaighofer
2b41f8d8d5 Merge remote-tracking branch 'origin/master' into master-next 2019-08-26 08:57:42 -07:00
Slava Pestov
b5b3718b0d AST: Some const goodness for ModuleDecl 2019-08-23 23:35:25 -04:00
Jordan Rose
5c785d42b3 Enforce that FileUnit + LoadedFile have trivial destructors
We already do this for other ASTContext-allocated types (see
Decl.cpp). This will prevent the sort of mistakes in the previous two
commits.

Note that if any particular subclass of FileUnit wants to have its
destructor run, it can opt into that manually using
ASTContext::addDestructorCleanup. SourceFile and BuiltinUnit both do
this. But we generally don't /want/ to do this if we can avoid it
because it adds to compiler teardown time.
2019-08-23 17:40:46 -07:00
Jordan Rose
e479e1398d [Serialization] Use the module interface as the name of the file
...rather than the buffer, for a compiled module that came from a
module interface.

This was already happening at a higher level
(ModuleDecl::getModuleFilename) so pushing it down to the low-level
ModuleFile::getModuleFilename doesn't really change things much. The
important fix that goes with this is that SerializedASTFile no longer
leaks this name by storing it outside of ModuleFile.

https://bugs.swift.org/browse/SR-11365
2019-08-23 17:40:45 -07:00
swift-ci
c4a70d09b7 Merge remote-tracking branch 'origin/master' into master-next 2019-08-20 16:30:12 -07:00
Jordan Rose
c4ee7ecdc3 Merge pull request #26735 from jrose-apple/heart-healthy
[Serialization] Remove several unnecessary bits of helper logic
2019-08-20 16:20:35 -07:00
swift-ci
c97950d7da Merge remote-tracking branch 'origin/master' into master-next 2019-08-19 21:30:00 -07:00
Slava Pestov
ea5cdd06a3 AST: Remove a couple of expensive FrontendStatsTracers 2019-08-19 23:00:57 -04:00
Slava Pestov
94c5a35bf2 AST: Add some counters related to name lookup 2019-08-19 23:00:57 -04:00
Jordan Rose
c6f033d400 [Serialization] Use existing logic to print a hierarchical module name
No intended functionality change.
2019-08-19 18:27:52 -07:00
Jonas Devlieghere
54dc4a6bab Update make_unique call after the utility got removed upstream.
This probably got auto-merged from master.
2019-08-18 12:53:32 -07:00
swift-ci
f993903828 Merge remote-tracking branch 'origin/master' into master-next 2019-08-17 15:30:10 -07:00
Slava Pestov
1d9f1ec3f8 AST: Add per-module lookup cache
These operations are called frequently, and would get rather
expensive when a ModuleDecl contains a large number of
SourceFiles:

- lookupValue()
- lookupVisibleDecls()
- lookupClassMember()
- lookupClassMembers()

Add fast paths to handle the case where all file units in the
module are SourceFiles, by refactoring SourceFile::LookupCache
from a per-file to a per-module cache.
2019-08-17 02:11:47 -04:00
Jonas Devlieghere
b4d268e9e1 Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances in the swift repo.
2019-08-15 11:32:39 -07:00
Slava Pestov
2f33356083 AST: Optimize construction of the AnyObject dispatch table
Instead of visiting all members of all types and extensions, bail out
early if the type is not a class or protocol, or the extension is not
extending a class. This means we don't visit structs, enums or
protocol extensions at all, which will avoid delayed parsing.

Also, we were evaluating isObjC() on each member, which is an expensive
operation; if the member does not have an explicit @objc we would still
have to check if it overrides an @objc method or witnesses an @objc
protocol requirement.

Since most members are not ever found by dynamic lookup, this is wasted
work. Instead, let's rely on AnyObject lookup filtering non-@objc
members at the call site, which it was already doing anyway.
2019-08-12 17:55:44 -04:00
Slava Pestov
14d0bbfc5e AST: Optimize construction of the global name lookup table
Only visit bodies of types and extensions that may possibly contain
operator definitions.
2019-08-12 17:15:51 -04:00
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -04:00
Sasha Krassovsky
7c5b54f17f Declare SourceFile::~SourceFile() in header (#26059)
There was an error when including Module.h in an external project with
std::default_delete being instantiated when making a std::unique_ptr.
This change declares destructor in header file and sets it to default in
cpp file.
2019-07-10 16:39:35 -07:00
David Ungar
69f6b41a13 Use unique_ptr for Scope, getScope returns a reference 2019-06-12 07:29:00 -07:00
David Ungar
663760e3b7 ASTOOScope ontology 2019-05-28 10:48:22 -07:00
Rintaro Ishizaki
d3d30ee246 [Serialization] Support Swift only system module
Previously 'isSystemModule()' returns true only if the module is:
- Standard library
- Clang module and that is `IsSystem`
- Swift overlay for clang `IsSystem` module

Now:
- Clang module and that is `IsSystem`; or
- Swift overlay for clang `IsSystem` module
- Swift module found in either of these directories:
  - Runtime library directoris (including stdlib)
  - Frameworks in `-Fsystem` directories
  - Frameworks in `$SDKROOT/System/Library/Frameworks/` (Darwin)
  - Frameworks in `$SDKROOT/Library/Frameworks/` (Darwin)

rdar://problem/50516314
2019-05-08 17:03:06 -07:00
Ben Langmuir
34da079aa6 Pass DynamicLookupInfo through VisibleDeclConsumers NFC
This commit adds a new type DynamicLookupInfo that provides information
about how a dynamic member lookup found a particular Decl. This is
needed to correctly handle KeyPath dynamic member lookups, but for now
just plumb it through everywhere.
2019-05-06 10:02:39 -07:00
Joe Groff
22793b4567 Fixes for opaque return types on local functions.
- In Sema, don't traverse nested declarations while deducing the opaque return type. This would
  cause returns inside nested functions to clobber the return type of the outer function.
- In IRGen, walk the list of opaque return types we keep in the SourceFile already for type
  reconstruction, instead of trying to visit them ad-hoc as part of walking the AST, since
  IRGen doesn't normally walk the bodies of function decls directly.

Fixes rdar://problem/50459091
2019-05-03 16:53:21 -07:00
adrian-prantl
f75dea49df Merge pull request #23910 from adrian-prantl/49751363
Record parseable interface imports in the debug info.
2019-04-19 14:23:57 -07:00
Joe Groff
5215290f25 Serialization: Cross-reference opaque return types by mangled name. rdar://problem/50005972 2019-04-18 14:41:26 -07:00
Joe Groff
399332b75b Parsable interface and type reconstruction support for opaque types.
When printing a swiftinterface, represent opaque result types using an attribute that refers to
the mangled name of the defining decl for the opaque type. To turn this back into a reference
to the right decl's implicit OpaqueTypeDecl, use type reconstruction. Since type reconstruction
doesn't normally concern itself with non-type decls, set up a lookup table in SourceFiles and
ModuleFiles to let us handle the mapping from mangled name to opaque type decl in type
reconstruction.

(Since we're invoking type reconstruction during type checking, when the module hasn't yet been
fully validated, we need to plumb a LazyResolver into the ASTBuilder in an unsightly way. Maybe
there's a better way to do this... Longer term, at least, this surface design gives space for
doing things more the right way--a more request-ified decl validator ought to be able to naturally
lazily service this request without the LazyResolver reference, and if type reconstruction in
the future learns how to reconstruct non-type decls, then the lookup tables can go away.)
2019-04-17 14:46:22 -07:00
Slava Pestov
5062a81e3d AST: Start returning SelfProtocolConformances from ModuleDecl::lookupConformance()
Fixes <rdar://problem/49241923>, <https://bugs.swift.org/browse/SR-10015>.
2019-04-16 23:02:50 -04:00
Adrian Prantl
8d03cb7a61 Record parseable interface imports in the debug info.
When a Swift module built with debug info imports a library without
debug info from a textual interface, the textual interface is
necessary to reconstruct types defined in the library's interface.  By
recording the Swift interface files in DWARF dsymutil can collect them
and LLDB can find them.

rdar://problem/49751363
2019-04-11 14:50:07 -07:00
John McCall
ae6561c32c Checks for implementation-only imports in @inlinable code.
Part of rdar://48991061
2019-04-05 16:30:25 -04:00
Jordan Rose
0ba6c495ba Add @_implementationOnly
This is an attribute that gets put on an import in library FooKit to
keep it from being a requirement to import FooKit. It's not checked at
all, meaning that in this form it is up to the author of FooKit to
make sure nothing in its API or ABI depends on the implementation-only
dependency. There's also no debugging support here (debugging FooKit
/should/ import the implementation-only dependency if it's present).

The goal is to get to a point where it /can/ be checked, i.e. FooKit
developers are prevented from writing code that would rely on FooKit's
implementation-only dependency being present when compiling clients of
FooKit. But right now it's not.

rdar://problem/48985979
2019-03-28 15:57:53 -07:00