Commit Graph

513 Commits

Author SHA1 Message Date
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00
John McCall
ebed6afd59 Make it easy to iterate over all the opaque accessors of a declaration. 2018-08-08 22:44:47 -04:00
Doug Gregor
9eb9898321 Merge pull request #18364 from DougGregor/name-lookup-requests
[Name lookup] Introduce requests for several name lookup operations.
2018-07-31 13:23:38 -07:00
Doug Gregor
2860557a77 [Name lookup] Use the declaration-based lookupQualified() where it’s easy.
Switch a number of callers of the Type-based lookupQualified() over to
the newer (and preferred) declaration-based lookupQualified(). These are
the easy ones; NFC.
2018-07-31 10:14:44 -07:00
Slava Pestov
2bd217e58a AST: Change AbstractStorageDecl::getValueInterfaceType() to strip off reference storage qualifiers
Also, remove AbstractStorageDecl::getStorageInterfaceType(), which was
almost identical.
2018-07-31 00:38:09 -07:00
Slava Pestov
463a467046 Merge pull request #18026 from slavapestov/inherited-availability-attribute-part-2
Sema: Fix availability of inherited designated initializers, part 2
2018-07-30 18:40:11 -07:00
Jordan Rose
2e4501105a Merge pull request #18048 from jrose-apple/finding-ways-to-scope
Limit ValueDecl::getFormalAccess and get rid of adjustAccessLevelForProtocolExtension
2018-07-25 16:43:41 -07:00
Slava Pestov
336f51e5bc Sema: Fix availability of inherited designated initializers, part 2
We need to explicitly handle nested types here.

Fixes the (re-opened) <rdar://problem/40853731>,
<https://bugs.swift.org/browse/SR-7881>.
2018-07-24 16:13:45 -07:00
John McCall
70e2aea266 Merge pull request #18156 from rjmccall/generalized-accessors
Implement generalized accessors using yield-once coroutines
2018-07-23 22:58:25 -04:00
Jordan Rose
ca14d6c84d Take away some of ValueDecl::getFormalAccess's capabilities
...to push people towards getFormalAccessScope. The one use case that
isn't covered by that is checking whether a declaration behaves as
'open' in the current file; I've added ValueDecl::hasOpenAccess to
handle that specific case.

No intended functionality change.
2018-07-23 16:36:16 -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
f6b96da3e2 Move TypeChecker::configureInterfaceType() to {AbstractFunction,Subscript}Decl::computeType()
It doesn't actually depend on the type checker, and using
it on synthesized declarations will eliminate a lot of
boilerplate.
2018-07-23 02:09:43 -07:00
Slava Pestov
bfc4121971 AST: Rework AbstractFunctionDecl construction away from multiple parameter lists
There are two general constructor forms here:

- One took the number of parameter lists, to be filled in later.
  Now, this takes a boolean indicating if there is an implicit
  'self'.

- The other one took the actual parameter lists and filled them
  in right away. This now takes a separate 'self' ParamDecl and
  ParameterList.

Instead of storing the number of parameter lists, an
AbstractFunctionDecl now only needs to store if there is a 'self'
or not.

I've updated most places that construct AbstractFunctionDecls to
properly use these new forms. In the ClangImporter, there is
more code that remains to be untangled, so we continue to build
multiple ParameterLists and unpack them into a ParamDecl and
ParameterList at the last minute.
2018-07-21 07:30:30 -07:00
Slava Pestov
e1da265873 Sema: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:21:17 -07:00
Doug Gregor
8741a886fa [Type checker] Allow implicitly-generated initializers to not be @objc.
When an implicitly-generated override of an @objc initializer cannot
be represented in Objective-C, implicitly add @nonobjc. These issues
will be diagnosed early on.

Similarly, when we implicitly create an initializer, allow it to not
be @objc even under Swift 3’s inference rules.
2018-07-18 14:50:41 -07:00
Doug Gregor
d9faa7415c [Type Checker] Add a request kind for ‘dynamic’.
Separate out the semantic state for the ‘dynamic’ check (from the
presence of the attribute), and move all of the computation of the
‘dynamic’ bit into the request-evaluator.

In the process, this fixes a bug where implicitly-synthesized initializers
in subclasses of imported classes would not be implicitly made ‘final’.
2018-07-18 14:50:39 -07:00
Doug Gregor
b70466dc63 [Type Checker] Add a request kind for computing 'ValueDecl::isObjC()'.
Still a WIP
2018-07-18 14:50:39 -07:00
Doug Gregor
0b5ec6f180 [Type Checker] Don’t explicit set overridden decls of accessors.
The overridden declarations of accessors are computed; they don’t need to
be set explicitly.
2018-07-18 14:50:38 -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
381483bd74 AST: Remove Expr's LValueAccessKind 2018-07-05 23:54:13 -07:00
Doug Gregor
d99799486d [Type Checker] Upgrade ObjCReason to a class wrapping an enum.
Provide more information in ObjCReason for the case where we are
@objc because we are a witness to an @objc requirement, by carrying the
@objc requirement in the reason. Use this to eliminate the type checker
parameter from describeObjCReason().
2018-07-05 10:32:59 -07:00
Doug Gregor
f4359b73f9 Merge pull request #17729 from DougGregor/minimize-override-checking
[Type checker] Minimize checking needed to compute the set of overridden declarations
2018-07-05 06:38:46 -07:00
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
Doug Gregor
7279eeeeac [Type checker] Perform more minimal checking in resolveOverriddenDecl().
Rather than deferring to the heavyweight validateDeclForNameLookup()
to perform the “get overridden decls” operation, perform a much more
minimal validation that only looks for exact matches when the ‘override’
modifier is present.

The more-extensive checking (e.g., that one didn’t forget an override
modifier) is only performed as part of the “full” type checking of
a declaration, which will typically only be done within the same source
file as the declaration. The intent here is to reduce the amount of
work performed to check overrides cross-file, and limit the dependencies
of the “get overridden decls” operation.
2018-07-03 17:26:38 -07:00
Doug Gregor
764f14807f [AST] Centralize the storage of the overridden declarations of a declaration.
Several kinds of declarations can override other declarations, but the
computation and storage for these “overridden” declarations was scattered in
at least 3 different places, with different resolution paths. Pull them
all together into two bits of LazySemanticInfo in ValueDecl (“have we computed
overrides?” and “are there any overrides?”), with a side table for the
actual list of overrides.

One side effect here is that the AST can now represent multiple overridden
declarations, although only associated type declarations track this
information.

Start using LazyResolver::resolveOverriddenDecl() more consistently, unifying
it with the separate path we had for associated type overrides. All of this
is staging for a move to the request-evaluator for overridden declaration
computation.
2018-07-02 14:51:28 -07:00
Hamish Knight
893d33128c Add a convenience PatternBindingDecl::createImplicit member and mark some PBDs as implicit (#17441)
Previously, some PBDs weren't being marked implicit even though the associated vars were implicit. PatternBindingDecl::createImplicit will be even nicer when we start parsing the location of the equals token.
2018-07-02 10:42:03 -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
Slava Pestov
1725ecbbd4 Sema: Use a different strategy for computing derived initializer generic signature 2018-06-21 23:13:23 -07:00
Slava Pestov
0e91735822 Sema: Implement inheritance of initializers with generic parameters
Fixes <https://bugs.swift.org/browse/SR-3848>.
2018-06-20 22:56:44 -07:00
Slava Pestov
1f3b5a4f85 Sema: Simplify createDesignatedInitOverride() 2018-06-20 22:56:44 -07:00
John McCall
69f4dd1ec9 Generalize accessor storage to preserve the original accessor list.
Only not NFC because it's detectable by source tools.
2018-06-16 18:16:31 -04:00
Doug Gregor
b7fbe57bf9 [AST] Remove “validated” bit from TypeLoc.
TypeLocs have been “validated” when they have a non-null Type, so eliminate
the separate “validated” bit that was out-of-sync with the Type field.
2018-06-14 15:29:57 -07: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
Joe Groff
da591acbca Sema: Make implicit elementwise struct init insensitive to lazy validation order.
With batch mode, other files may have forced lazy properties to get finalized before the implicit constructor is formed. Avoid the order dependency by making the behavior stable regardless of the type-checking phase of lazy declarations. Fixes rdar://problem/40903186.
2018-06-13 15:01:36 -07:00
Slava Pestov
ae6c75ab5d Sema: Fix availability of inherited designated initializers
Inherited designated initializers got the same availability
as the corresponding initialier in the superclass.

However if the superclass was more available than the subclass,
we would generate a diagnostic that a member cannot be more
available than its containing type.

This diagnostic had an unknown source location, since the
location was for a synthesized declaration, causing confusion.

Fixes <https://bugs.swift.org/browse/SR-7881> aka
<rdar://problem/40853731>.
2018-06-08 23:23:43 -07:00
Slava Pestov
b3bc06e75e Merge pull request #16766 from AnthonyLatsis/generalize_declared_here
[Sema] Generalize the 'declared here' diagnostic
2018-05-22 19:47:53 -07:00
Victor Guerra
68746f2168 [SR-7562] inheriting discardableResult attribute for constructors. (#16699)
Simply checking if constructor has the discardableResult attribute set.
2018-05-22 13:21:42 -07:00
fischertony
7313a90eb1 [Sema] Generalize the 'declared here' diagnostic 2018-05-22 18:17:15 +03:00
Doug Gregor
ebf9cdcc44 [AST] Collapse storage for ConcreteDeclRef.
Rather than ASTContext-allocating ConcreteDeclRef’s storage when there is a
non-empty substitution map, put the SubstitutionMap directly in the
ConcreteDeclRef. Simplify the various interfaces along the way.
2018-05-02 13:39:21 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Slava Pestov
c35d508600 Merge pull request #15731 from slavapestov/decl-checker-cleanup-part-6
Nuke DeclChecker::IsFirstPass
2018-04-06 12:03:48 -07:00
Slava Pestov
5e4f5a4fd5 Sema: Remove DeclChecker::IsFirstPass 2018-04-06 00:55:43 -07:00
Slava Pestov
b4e145dc34 SE-0193: @inlinable implies @usableFromInline 2018-04-06 00:02:29 -07:00
Slava Pestov
fb0233aae5 Sema: Clean up createDesignatedInitOverride() 2018-04-06 00:02:29 -07:00
Slava Pestov
ff56a074af AST: Clean up the terminology around @usableFromInline in a couple of places 2018-04-05 14:31:32 -07:00
Slava Pestov
f250bdb44c Sema: Fix inheritance of @usableFromInline
If the base class initializer was '@inlinable public' and the
derived class was '@usableFromInline internal', the synthesized
initializer was '@inlinable internal', which was an error.
2018-04-04 00:07:50 -07:00
Slava Pestov
3bcdf1a027 AST: New ASTContext::addSynthesizedDecl() method
This adds the declaration to the external declarations list only
if it was part of an imported declaration, eliminating some
boilerplate.
2018-04-02 23:17:58 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Slava Pestov
a8602f8eb8 Sema: Call setValidationStarted() on various synthesized FuncDecls 2018-03-21 23:54:47 -07:00
Slava Pestov
bd1b784eda Sema: Designated initializer overrides are fully type-checked 2018-03-21 21:41:39 -07:00