273 Commits

Author SHA1 Message Date
Rintaro Ishizaki
db2c11787b [AST] Inherit doc-brief comment from protocol, superclass, and requirement
rdar://problem/38422822
2019-06-20 10:04:05 -07:00
mishal_shah
1e38fc3030 Update master to build with Xcode 11 beta, macOS 10.15, iOS 13, tvOS 13, and watchOS 6 SDKs 2019-06-03 22:50:02 -07:00
Doug Gregor
96952ea9a2 [AST] Distinguish memberwise-initialized properties for storage vs. declared
The determination of whether a property is memberwise-initialized is
somewhat confused for properties that have synthesized backing properties.
Some clients (Sema/Index) want to see the declared properties, while others
(SILGen) want to see the backing stored properties. Add a flag to
`VarDecl::isMemberwiseInitialized()` to capture this variation.
2019-04-30 10:12:43 -07:00
Doug Gregor
1a169b91bd Centralize the definition of isMemberwiseInitialized()
This utility was defined in Sema, used in Sema and Index, declared in
two headers, and semi- copy-pasted into SILGen. Pull it into
VarDecl::isMemberwiseInitialized() and use it consistently.
2019-04-29 10:30:38 -07:00
Doug Gregor
99d4e8090c [Index] Handle memberwise initializers with defaulted arguments. 2019-04-23 11:32:29 -07:00
Ben Langmuir
6af24d083c [index] Fix dynamicMemberLookup subscript reference implicit role
When building the implicit subscript expression, set the "implicit" bit
correctly and pass it through in the indexer so that we get implicit
refernces to the subscript. This would be useful for e.g. searching for
all uses of the dynamic subscript.
2019-04-16 15:37:32 -07:00
Brent Royal-Gordon
5c03918c82 [NFC] Remove VarDecl guards on staticness checks
Fixes various places where we assume that only a VarDecl can be static so they operate on any AbstractStorageDecl instead. NFC until static subscripts are added.
2019-04-01 18:04:00 -07: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
Nathan Hawes
9291201e32 [sourcekitd][Refactoring] Fix renaming of var decls in fallthrough case statements
We weren't renaming all occurrences of 'x' in the cases like the below:

  case .first(let x), .second(let x):
    print("foo \(x)")
    fallthrough
  case .third(let x):
    print("bar \(x)")

We would previously only rename occurrences within the case statement the query
was made in (ignoring fallthroughs) and for cases with multiple patterns (as in
the first case above) we would only rename the occurrence in the first pattern.
2019-03-20 14:38:08 -07:00
Ben Langmuir
981167d3d5 [index] Add back override relation for associated type witnesses
When conforming to a protocol, the index should have a "override"
relation for each witness, including type witnesses.  This was
accidentally broken in 3bd80e5e31 when we stopped using the
type-checker to find all protocol conformances.

rdar://47833618
2019-02-06 15:45:35 -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
52b91954c2 Fix two places where IDE code is assuming that root conformances are normal. 2018-11-16 16:50:46 -05: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
Slava Pestov
28c5ad3f08 Index: Don't crash if an optional requirement is missing its witness
Possibly fixes <rdar://problem/44499860>.
2018-09-18 20:59:30 -07:00
Argyrios Kyrtzidis
f752844ccd [index] Make sure to walk the accessor bodies of local properties (#19102)
[index] Make sure to walk the accessor bodies of local properties

Otherwise we'll miss global symbols references.
rdar://42301005
2018-09-01 08:27:27 -07:00
Brent Royal-Gordon
dd8072fd23 [swiftIndex] Don’t try to negate a size_t
Convert it to ptrdiff_t first. Fixes UBSan errors in 15 tests.
2018-08-29 22:53:40 -07:00
Argyrios Kyrtzidis
3bd80e5e31 [index] Improvements on how conformances are recorded (#19043)
Query for the local conformances of a DeclContext and record conformances of
functions that are defined in other types as 'implicit' overrides, with
the type that introduces the conformance as container symbol.

This allows more accurate index data, and avoids needing to query for all
protocol requirements, which is expensive to calculate.
2018-08-29 10:31:23 -07:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04: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
Doug Gregor
bd5f5d80e4 [AST] Add ExtensionDecl::getExtendedNominal().
Introduce ExtensionDecl::getExtendedNominal() to provide the nominal
type declaration that the extension declaration extends. Move most
of the existing callers of the callers to getExtendedType() over to
getExtendedNominal(), because they don’t need the full type information.

ExtensionDecl::getExtendedNominal() is itself not very interesting yet,
because it depends on getExtendedType().
2018-08-03 11:26:48 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Slava Pestov
90cd772228 AST: Remove getParameterLists() and friends from AbstractFunctionDecl subclasses
Now, an AbstractFunctionDecl always stores a single parameter list.

Furthermore, ConstructorDecl and DestructorDecl always store a
ParamDecl for 'self'.

FuncDecl only has a 'self' if it is a member of a nominal type or
extension, so we tail-allocate the storage for it.
2018-07-22 20:56:56 -07:00
Slava Pestov
5213f80e7e IDE: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-22 20:56:56 -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
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
John McCall
9022b5152f Rename accessor kinds from IsGetter -> IsGet, etc.
Introduce some metaprogramming of accessors and generally prepare
for storing less-structured accessor lists.

NFC except for a change to the serialization format.
2018-06-14 17:08:55 -04:00
Michael Gottesman
a264b1ed9c [gardening] Use SmallPtrSetImpl instead of SmallPtr<N> in more function parameters/return values.
This is good practice like using SmallVectorImpl instead of SmallVector.
2018-05-07 10:35:51 -07:00
swift-ci
21343fd342 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-12 14:18:57 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Bob Wilson
548e7eaed4 master-next: Update to match LLVM r321411
The SymbolPropertySet subfield of the SymbolInfo struct was moved to the
end.
2017-12-28 14:19:38 -08:00
Slava Pestov
678f70bfb7 IDE: Remove a LValueAccessKind usage
Ok, so behind the scenes SourceEntityWalker is still using
Expr::getLValueAccessKind(). But now that SourceEntityWalker
is really the *only* remaining client, it makes sense to
refactor the calculation of this into a separate pass, which
only SourceKit needs to use.
2017-11-13 22:19:25 -08:00
Slava Pestov
0715eaeaed AST: Move SourceEntityWalker to IDE 2017-11-13 22:10:41 -08:00
Davide Italiano
87de4637fc [gardening] More unused variables/lambda captures. NFCI. 2017-10-31 10:35:24 -07:00
Slava Pestov
e32841d319 Index: Remove usages of getDeclaredTypeOfContext() 2017-09-19 22:12:29 -07:00
Xi Ge
21fd1f65bb [Index] Avoid mistaking nullptr to a meaningful parent identity. rdar://32861438 (#10864) 2017-07-10 18:08:39 -07:00
Nathan Hawes
6c128c2788 [index] Add missing parameter and return type references in subscript declarations
Resolves rdar://problem/32314185.
2017-06-22 23:29:51 -07:00
practicalswift
437a186032 [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar) 2017-05-09 11:26:07 +02:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Nathan Hawes
9abeb0d97a [indexer] Don't index closure params. Resolves rdar://problem/31905371. 2017-05-01 23:28:36 -07:00
Argyrios Kyrtzidis
40c89048ba [index] Make sure that we index implicit constructors
These can be explicitely referenced so we should index their definitions as well
2017-04-29 19:14:03 -07:00
Nathan Hawes
4ff254de97 Move canDeclProvideDefaultImplementationFor() from libIDE into libIndex 2017-04-27 23:23:45 -07:00
Nathan Hawes
8ad6aa4e0d [migrator] Add pass for API type changes
This handles optionality changes and type rewrites in function param and return types and constructor param and failability types.
Resolves rdar://problem/31766010
2017-04-27 22:19:52 -07:00
practicalswift
ab5aaeb359 Merge pull request #9001 from practicalswift/gardening-20170425
[gardening] Unused variables. Unused diagnostics. Namespace comments. Typos.
2017-04-26 09:28:24 +02:00
Argyrios Kyrtzidis
79ef8ae77c [index] Index documentation comment tags
rdar://30569973
2017-04-25 12:16:25 -07:00
practicalswift
861f70e13d [gardening] Use consistent spacing 2017-04-25 21:03:43 +02:00
Nathan Hawes
0127469a27 Merge pull request #8889 from nathawes/rdar31665007-index-memberwise-init-arglabels-as-property-references
[indexer] Index the the arg labels of memberwise initializers as references to the properties they correspond to
2017-04-20 16:53:32 -07:00
Nathan Hawes
081500a4d0 [indexer] Index the the arg labels of memberwise initializers as references to the properties they correspond to
Resolves rdar://problem/31665007
2017-04-20 13:28:50 -07:00
Argyrios Kyrtzidis
e152d4ac1f [index] Mark indexed methods as 'dynamic' when appropriate
'dynamic' for indexing purposes means the method is overridable.
2017-04-19 11:48:52 -07:00
Argyrios Kyrtzidis
dc7373c05b [index] Improve handling of property accessors
- Report accessor function definitions for stored properties as well
- Fix issue where a call to a computed accessor was not reported if its parent was a statement
- Take into account if the stored property is member or not to adjust the symbol kind for the accessor
2017-04-17 22:25:08 -07:00