Commit Graph

337 Commits

Author SHA1 Message Date
Slava Pestov
07ce01d96d AST: Replace ASTContext's ObjCMethodConflicts list with a per-SourceFile list 2019-04-22 20:42:08 -04:00
Slava Pestov
0fae7e8669 AST: Replace ASTContext's ObjCUnsatisfiedOptReqs list with a per-SourceFile list 2019-04-22 20:42:08 -04:00
Slava Pestov
e97fc4e0c2 AST: Replace ASTContext's ObjCMethods list with a per-SourceFile list 2019-04-22 20:42:07 -04: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
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
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
Jordan Rose
9ed3fe061d Change ModuleDecl::getImportedModules to take an option set
...in preparation for me adding a third kind of import, making the
existing "All" kind a problem. NFC, except that I did rewrite the
ClangModuleUnit implementation of getImportedModules to be simpler!
2019-03-28 14:44:41 -07:00
Slava Pestov
a2049972ca AST: Add ModuleDecl::isResilient()
This cleans up some code. I'm keeping the ResilienceStrategy enum around
though, in case we want to use it to version the ABI in the future.
2019-03-26 18:42:59 -04:00
Jordan Rose
93616cd49e Push Clang's "exported module name" notion up to Swift's FileUnit
It's a pretty obscure feature (and one we wish we didn't need), but
sometimes API is initially exposed through one module in order to
build another one, and we want the canonical presented name to be
something else. Push this concept into Swift's AST properly so that
other parts of the compiler stop having to know that this is a
Clang-specific special case.

No functionality change in this commit; will be used in the next
commit.
2019-03-21 15:16:21 -07:00
Slava Pestov
1159af50d9 Rename -enable-resilience to -enable-library-evolution and make it a driver flag
Fixes <rdar://problem/47679085>.
2019-03-14 22:24:26 -04:00
Doug Gregor
9bf404380f [AST] Hack SourceFile::lookupLocalType() to look through local types.
This is only currently exercised by swift-remoteast-test, so do the
minimum to ensure that we’re getting cached mangled names, but don’t
fret over the linear-time search.
2019-01-25 20:16:31 -08:00
Andrew Trick
0976c1f76e Teach the SIL cast optimizer to handle conditional conformance.
Previously the cast optimizer bailed out on any conformance with
requirements.

We can now constant-propagate this:

```
protocol P {}
struct S<E> {
  var e: E
}

extension S : P where E == Int {}

func specializeMe<T>(_ t: T) {
  if let p = t as? P {
    // do fast things.
  }
}

specializeMe(S(e: 0))
```

This turns out to be as simple as calling the TypeChecker.

<rdar://problem/46375150> Inlining does not seem to handle
specialization properly for Data.

This enabled two SIL transformations required to optimize
the code above:

(1) The witness method call can be devirtualized.

(2) The allows expensive dynamic runtime checks such as:

  unconditional_checked_cast_addr Array<UInt8> in %array : $*Array<UInt8> to ContiguousBytes in %protocol : $*ContiguousBytes

Will be converted into:

  %value = init_existential_addr %existential : $*ContiguousBytes, $Array<UInt8>
  store %array to %value : $*Array<UInt8>
2018-12-11 17:37:54 -08:00
Argyrios Kyrtzidis
cbad3492e4 [Parse/Syntax] Simplify how the final SourceFileSyntax root is formed
Instead of creating multiple CodeBlockItemList nodes, that need to get merged and discarded later on, do this:

* Ensure for libSyntax parsing that we parse the whole file
* Create top-level CodeBlockItem nodes that we just directly wrap with a single CodeBlockItemList node at the end

The importance of this change will become more obvious later on when we'll decouple syntax parsing from the formation of libSyntax tree nodes.
2018-12-10 13:37:15 -08:00
Argyrios Kyrtzidis
9405f1eb09 [AST] Break dependency cycle between swiftAST and swiftClangImporter
NormalProtocolConformance::isRetroactive() introduces dependency on swiftClangImporter by calling ClangModuleUnit::getAdapterModule().
Do some refactoring to break the cycle.
2018-12-06 22:54:33 -08:00
swift-ci
39161d5b36 Merge pull request #20600 from adrian-prantl/36032653 2018-12-05 17:01:58 -08:00
Adrian Prantl
d63debeb60 Experimental: Extend ClangImporter to import clang modules from DWARF
When debugging Objective-C or C++ code on Darwin, the debug info
collected by dsymutil in the .dSYM bundle is entirely
self-contained. It is possible to debug a program, set breakpoints and
print variables even without having the complete original source code
or a matching SDK available. With Swift, this is currently not the
case. Even though .dSYM bundles contain the binary .swiftmodule for
all Swift modules, any Clang modules that the Swift modules depend on,
still need to be imported from source to even get basic LLDB
functionality to work. If ClangImporter fails to import a Clang
module, effectively the entire Swift module depending on it gets
poisoned.

This patch is addressing this issue by introducing a ModuleLoader that
can ask queries about Clang Decls to LLDB, since LLDB knows how to
reconstruct Clang decls from DWARF and clang -gmodules producxes full
debug info for Clang modules that is embedded into the .dSYM budle.

This initial version does not contain any advanced functionality at
all, it merely produces an empty ModuleDecl. Intertestingly, even this
is a considerable improvement over the status quo. LLDB can now print
Swift-only variables in modules with failing Clang depenecies, and
becuase of fallback mechanisms that were implemented earlier, it can
even display the contents of pure Objective-C objects that are
imported into Swift. C structs obviously don't work yet.

rdar://problem/36032653
2018-12-05 13:54:13 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
John McCall
cd2b558280 Fix a bug with inlining self-conformances. 2018-11-16 22:59:12 -05:00
Arnold Schwaighofer
c3230dfc5c Add the implicit dynamic attribute in the IsDynamicRequest query 2018-11-14 12:04:17 -08:00
Arnold Schwaighofer
49cdab2c12 Fix typo 2018-11-14 06:29:22 -08:00
Arnold Schwaighofer
2ac6cda9a7 Make sure the code completion takes both private imports and testable
imports into account separately.
2018-11-12 14:53:56 -08:00
Arnold Schwaighofer
6cc3d377ff Refactor part2 2018-11-08 18:16:17 -08:00
Arnold Schwaighofer
9feb75806a Refactor 2018-11-08 17:50:25 -08:00
Arnold Schwaighofer
e4f4dfcf84 Address feedback 2018-11-08 11:13:42 -08:00
Arnold Schwaighofer
963c64e3e7 Add @_private(from: "SourceFile.swift") imports
A module compiled with `-enable-private-imports` allows other modules to
import private declarations if the importing source file uses an
``@_private(from: "SourceFile.swift") import statement.

rdar://29318654
2018-11-08 08:00:47 -08:00
Slava Pestov
9c50867370 Move RemoteAST's RemoteASTTypeBuilder to lib/AST/ASTDemangler.cpp 2018-11-02 18:19:40 -04:00
Jordan Rose
7cad780701 [AST] Sink ModuleDecl's flags down into the shared Decl bitfields (#20051)
Saves 4 bytes per ModuleDecl. No functionality change.
2018-10-25 15:53:51 -07:00
fischertony
e505d417fa [Parse][CodeCompletion] Completions for precedencegroup decls
Added the 'Module::getPrecedenceGroups' API to separate precedence group lookup
from 'Module::lookupVisibleDecls', which together with 'FileUnit::lookupVisibleDecls',
to which the former is forwarded, are expected to look up only 'ValueDecl'. In particular, this
prevents completions like Module.PrecedenceGroup.
2018-10-03 22:12:20 +03:00
Bruno Rocha
bf84b297f8 [SourceKit] Allow module references to be indexed (#19243)
Module references get indexed as a 'module' symbol; they get USRs similar to how clang would assign a USR for a module reference.

JIRA: https://bugs.swift.org/browse/SR-8677
2018-09-28 12:21:38 -07:00
Jordan Rose
e1901fdad1 Replace explicit 'delete' calls with std::unique_ptr in AST (#19366) 2018-09-18 19:41:11 -07:00
Xi Ge
fe0046ba26 Parser: calculating interface hash only for primary files. 2018-09-07 14:24:30 -07:00
Jordan Rose
37ec248823 Add ModuleDecl::ReverseFullNameIterator
Package up the logic that generates a full Clang module name, so that
(a) we don't have to deal with clang::Module in quite as many places
in the /Swift/ compiler, and (b) we can avoid the cost of a temporary
string in a few places.

The main places where this is /not/ adopted is where we don't just
want to know the parent module name, but actually the module itself.
This is mostly indexing-related queries, which use the very similar
ModuleEntity class also defined in Module.h. I didn't quite see an
obvious way to unify these, but that might be where we want to go.

No functionality change.
2018-09-06 19:53:59 -07:00
Jordan Rose
f6ee9f6dc9 [ModuleInterface] Print imports (including '@_exported')
Part of preserving enough information to reconstitute a textual
interface back to a binary module.
2018-09-06 16:05:16 -07:00
Jordan Rose
737a405596 Add ModuleDecl::isOnoneSupportModule, and use it
A few places around the compiler were checking for this module by its
name. The implementation still checks by name, but at least that only
has to occur in one place.

(Unfortunately I can't eliminate the string constant altogether,
because the implicit import for SwiftOnoneSupport happens by name.)

No functionality change.
2018-09-06 16:05:16 -07:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Jordan Rose
d9e47650d5 Add a new SourceFileKind and InputFileKind for textual interfaces
And test this by tweaking the rules to allow functions without
definitions, like SIL files.
2018-08-07 08:55:07 -07:00
Christopher Rogers
dff1d8983d Fix typos/grammar in comments & docs 2018-07-03 14:31:36 +09:00
Doug Gregor
793ba723f7 [AST] Delete the unused FileUnitKind::Derived.
The last use of this went away a loooooong time ago. NFC.
2018-07-02 13:32:39 -07:00
David Ungar
45c562b8e5 Split up emitReferenceDependencies into 3 steps: provides, depends, interfaceHash. 2018-06-15 11:12:25 -07:00
Alex Hoppen
de9737c946 [incrParse] Support incremental parsing for edited files 2018-05-22 08:52:33 -07:00
Jordan Rose
fb59305342 Drop includePrivateTopLevelImports from ModuleDecl::forAllVisibleModules
One bit of Slava's cleanup that I /can/ keep. No one is using this
parameter anymore.
2018-05-03 22:42:49 -06:00
Jordan Rose
18162a3ed0 Revert "AST: Simplify ModuleDecl::forAllVisibleModules()"
This reverts commit 0c32c54e36.
2018-05-03 22:40:37 -06:00
Jordan Rose
4714fcd50c Revert "Merge pull request #16211 from slavapestov/fix-inlinable-vs-autolinking"
This reverts commit bb16ee049d,
reversing changes made to a8d831f5f5.
It's not sufficient to solve the problem, and the choices were to do
something more complicated, or just take a simple brute force
approach. We're going with the latter.
2018-05-03 22:40:31 -06:00
Jordan Rose
e432971a1a Revert "Sema: Infer '@_usableFromInline' imports by looking at references from inlinable functions (#16326)"
This reverts commit ee6e190e09. It's not
sufficient to solve the problem, and the choices were to do something
more complicated, or just take a simple brute force approach. We're
going with the latter.
2018-05-03 22:39:57 -06:00
Jordan Rose
ee6e190e09 Sema: Infer '@_usableFromInline' imports by looking at references from inlinable functions (#16326)
Basic fix for <rdar://problem/39338239>, but there are still some more cases we haven't handled yet.
2018-05-02 19:23:01 -07:00
Jordan Rose
df2e63d07d Diagnose modules with circular dependencies (#16075)
This can't arise from a clean build, but it can happen if you have
products lingering in a search path and then either rebuild one of
the modules in the cycle, or change the search paths.

The way this is implemented is for each module to track whether its
imports have all been resolved. If, when loading a module, one of its
dependencies hasn't resolved all of its imports yet, then we know
there's a cycle.

This doesn't produce the best diagnostics, but it's hard to get into
this state in the first place, so that's probably okay.

https://bugs.swift.org/browse/SR-7483
2018-05-02 15:01:09 -07:00
Slava Pestov
cfa0ab3dbe AST: Introduce ModuleDecl::ImportFilter::ForLinking
ModuleDecl::forAllVisibleModules() now has a includeLinkOnlyModules
parameter. This is intended to be used when computing the set of
libraries to autolink.
2018-05-01 17:53:51 -07:00
Slava Pestov
753967411a AST: Support '@_usableFromInline import' 2018-05-01 17:53:51 -07:00