Commit Graph

256 Commits

Author SHA1 Message Date
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
practicalswift
40cf4d183d [gardening] Use consistent spacing after if, for and while 2017-04-14 17:35:36 +02:00
Nathan Hawes
a57fd2a4b0 [indexer] Add an option to index local symbols too, and a new index::indexDeclContext() entry point
Resolves rdar://problem/31433002.
2017-04-12 09:04:03 -07:00
Xi Ge
936b4a25da Revert "Index: Expose the logic for deciding whether to index a symbol. NFC. (#8438)"
We currently don't need this logic elsewhere, thus it's good to give
indexer some privacy.
2017-04-01 10:39:36 -07:00
Xi Ge
9e6d584b60 Index: Expose the logic for deciding whether to index a symbol. NFC. (#8438) 2017-03-30 14:00:44 -07:00
Xi Ge
0ccbfdb933 Index: Record override-of relationship between a decl in protocol extension and the protocol requirements it can provide default implementations for. (#8418) 2017-03-29 19:39:39 -07:00
Xi Ge
1827fb1436 RangeInfo: Report RValue type if a decl reference is of read-only LValue type. (#8300) 2017-03-23 15:52:54 -07:00
Hugh Bellamy
7a704b2605 Fix MSVC control path warnings 2017-03-16 08:55:51 +07:00
Nathan Hawes
2c4bee9935 Merge pull request #8094 from nathawes/rdar31039915-index-local-params
[indexer] Index parameter definitions with a distinct external argument label too (but not their refs)
2017-03-14 17:44:25 -07:00
Nathan Hawes
7b75cf792c [indexer] Index parameter definitions with a distinct external argument label too (but not their refs)
Parameter defs with a separate external argument label are marked with the 'Local' symbol property.
This ensures the indexer has enough information for clients to match up a function's argument labels with its child parameter definitions.
Resolves rdar://problem/31039915.
2017-03-14 16:12:48 -07:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Nathan Hawes
28719efd7a [indexer] Fix missing references to protocol properties
Only accessors uses were being reported previously. Resolves rdar://problem/30773201
2017-03-07 16:19:19 -08:00
Argyrios Kyrtzidis
2b9e102b75 [index] Move determination of SymbolProperty::UnitTest at index::getSymbolInfoForDecl()
Otherwise symbol info for relations of such methods does not contain this property.
2017-03-06 12:42:23 -08:00
Argyrios Kyrtzidis
c5456e38ed [index] Handle properly typealiases as inherited types
Report the typalias as reference and its underlying nominal type as an 'implicit' base relation.
2017-03-04 19:23:02 -08:00
Nathan Hawes
583f74017b [indexer] Add RelationContainedBy from references to their containing functions
Resolves rdar://problem/30765261
2017-02-28 16:55:18 -08:00
Nathan Hawes
2684564590 [indexer] report defs/refs of parameters without a separate external name 2017-02-28 11:55:34 -08:00
practicalswift
efb4183c8f [gardening] Remove unused variable NTD 2017-02-24 09:38:00 +01:00
Nathan Hawes
50113b74cf [indexer] Fix all function references being reported with the call role regardless of them actually being called or not 2017-02-22 13:37:32 -08:00