Commit Graph

608 Commits

Author SHA1 Message Date
Slava Pestov
2b90ad1b4a ASTMangler: Don't optimize protocol names in debugger mangling 2019-01-30 01:28:48 -05: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
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
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
John McCall
49ba9c59d1 Allow Error to conform to itself.
Most of the foundation for this was laid in earlier patches.
2018-11-17 02:51:45 -05:00
John McCall
cd2b558280 Fix a bug with inlining self-conformances. 2018-11-16 22:59:12 -05: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
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
2b5a2ad84c Rework the integrated REPL to use separate modules for every line
...like LLDB does, instead of parsing into a single SourceFile.
This does break some functionality:

- no more :dump_ast
- no redeclaration checking, but no shadowing either---redeclarations
  just become ambiguous
- pretty much requires EnableAccessControl to be off, since we don't
  walk decls to promote them to 'public'

...but it allows us to remove a bit of longstanding support for
type-checking / SILGen-ing / IRGen-ing only part of a SourceFile that
was only used by the integrated REPL.

...which, need I remind everyone, is still /deprecated/...but sometimes
convenient. So most of it still works.
2018-09-25 09:13:52 -07:00
Jordan Rose
e1901fdad1 Replace explicit 'delete' calls with std::unique_ptr in AST (#19366) 2018-09-18 19:41:11 -07:00
Saleem Abdulrasool
d281b98220 litter the tree with llvm_unreachable
This silences the instances of the warning from Visual Studio about not all
codepaths returning a value.  This makes the output more readable and less
likely to lose useful warnings.  NFC.
2018-09-13 15:26:14 -07:00
Jordan Rose
3c5fba3797 When sorting imports for uniquing purposes, use full module names
Fixes a longstanding issue where submodules with the same name in
different top-level modules weren't being sorted deterministically.
This doesn't come up very much in practice, and it would have been
hard to notice anything wrong, but it's good to be right.
2018-09-06 19:53:59 -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
Graydon Hoare
ffa1bf1979 [Stats] Expand and improve traceable-entity vocabulary. 2018-09-01 00:05:58 -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
Doug Gregor
b947a47a5d [AST] Reimplement ProtocolDecl::getInheritedProtocols() on decl name lookup.
Use the declaration-based name lookup facilities to re-implement
ProtocolDecl::getInheritedProtocols(), rather than dynamically selecting
between the requirement signature and the inherited types. This reduces
dependencies for this computation down to basic name lookup (no semantic
analysis) and gives us a stable result.
2018-08-06 16:12:09 -07:00
David Zarzycki
b29d2784ed [AST] NFC: Formalize Decl validation tracking via RAII
After this change, RAII ensures that the validation state is accurate as
possible.
2018-07-12 10:30:26 -04:00
Slava Pestov
45fb11ce3c AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass
More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
2018-07-02 22:06:33 -07: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
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
098b170d02 Just autolink every imported module, public or private
This is unfortunate in that it makes the linker do extra work, but in
practice it probably doesn't matter much, and meanwhile it handles all
our problems with @inlinable.

Alternate solution to rdar://problem/39338239
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
ab8d72c5f3 Revert "AST: Fold forAllImportedModules() into forAllVisibleModules()"
This reverts commit a12f42cc36.
2018-05-03 22:40:36 -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
a12f42cc36 AST: Fold forAllImportedModules() into forAllVisibleModules() 2018-04-26 23:37:17 -07:00
Slava Pestov
0c32c54e36 AST: Simplify ModuleDecl::forAllVisibleModules() 2018-04-26 23:37:16 -07:00
Robert Widmann
9973b31d5b Skip invalid declarations in SourceLookupCache
Crashers 28598 and 28778 are creating invalid validation requests for the ITC
by using unqualified lookup to get the validator to jump inside of a
transitively invalid DeclContext.

Just don't load these members.
2018-04-16 13:10:34 +02:00
Doug Gregor
ee70e19c3c Make SourceFile::collectLinkLibraries() visit all visible modules; use it.
Centralize the logic for collecting the link libraries of a source file
in SourceFile::collectLinkLibraries(), extending it to look at all visible
modules. Use it in the main place that counts for autolinking.
2018-04-10 23:09:52 -07:00
David Ungar
488db9fb9b Fix ReferencedNameTracker in preparation for batch mode. 2018-02-16 22:28:10 -07:00
Xi Ge
37f352fe41 sourcekitd: build Swift syntax tree more lazily than collecting parsed tokens. (#14578)
Before this patch, we have one flag (KeepSyntaxInfo) to turn on two syntax
functionalities of parser: (1) collecting parsed tokens for coloring and
(2) building syntax trees. Since sourcekitd is the only consumer of either of these
functionalities, sourcekitd by default always enables such flag.
However, empirical results show (2) is both heavier and less-frequently
needed than (1). Therefore, separating the flag to two flags makes more
sense, where CollectParsedToken controls (1) and BuildSyntaxTree
controls (2).

CollectingParsedToken is always enabled by sourcekitd because
formatting and syntax-coloring need it; however BuildSyntaxTree should
be explicitly switched on by sourcekitd clients.

resolves: rdar://problem/37483076
2018-02-13 16:27:12 -08:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00
David Zarzycki
f0c08a3010 [AST] NFC: Add Decl::getAsGenericContext()
Adding getAsGenericContext() cleans up some code, and improves the
Swift.swiftmodule build time by almost half a percent on LLVM
top-of-tree and with a simulated fix for LLVM PR35909.
2018-01-14 09:34:27 -05:00
David Zarzycki
e9b643026b [AST] NFC: Stop over aligning DeclContexts
DeclContexts as they exist today are "over aligned" when compared to
their natural alignment boundary and therefore they can easily cause
adjacent padding when dropped into the middle of objects via C++
inheritance, or when the clang importer prefaces Swift AST allocations
with a pointer to the corresponding clang AST node.

With this change, we move DeclContexts to the front of the memory layout
of AST nodes. This allows us to restore natural alignment, save memory,
and as a side effect: more easily avoid "over alignment" in the future
because DeclContexts now only need to directly track which AST node
hierarchy they're associated with, not specific AST nodes within each
hierarchy.

Finally, as a word of caution, after this change one can no longer
assume that AST nodes safely convert back and forth with "void*". For
example, WitnessTableEntry needed fixing with this change.
2018-01-08 12:21:14 -05:00
Xi Ge
6af5d3c0bf libSyntax: rename KeepTokensInSourceFile to KeepSyntaxInfoInSourceFile. 2017-11-03 18:39:01 -07:00
Xi Ge
4ee32a125e [test] Always enable libSyntax creation in swift-ide-test to get some free test coverage. NFC 2017-11-03 18:39:01 -07:00
Slava Pestov
4970d7d7e8 AST: Don't include Token.h from Module.h 2017-10-24 20:45:50 -07:00