Commit Graph

296 Commits

Author SHA1 Message Date
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
Slava Pestov
f9f5ebbba9 Sema: Remove DeclChecker::IsSecondPass
The DeclChecker had three possible states:

- IsFirstPass true, IsSecondPass false. This is the 'first pass' for
  declarations that appear at the top-level, or are nested inside
  top-level types.

- IsFirstPass false, IsSecondPass true. This is the 'second pass' for
  declarations that appear at the top-level, or are nested inside
  top-level types.

- IsFirstPass false, IsSecondPass false. This was used for (some)
  local declarations.

This is unnecessarily confusing. We can eliminate the third state
by calling typeCheckDecl() twice in a few places. This allows
IsSecondPass to be removed entirely since it's now always equal to
!IsFirstPass.
2018-03-21 21:41:38 -07:00
Slava Pestov
9ffff87621 ClangImporter: Don't fall back on Sema for synthesizing the memberwise init
The importer would only synthesize its own memberwise init if the
declaration had a zero initializer, which supresses Sema's automatic
synthesis. Trouble is we cannot rely on Sema synthesizing the
memberwise init in case we deserialize declarations after type
checking.

Some other changes caught this with an assert, so fix the importer
to do the right thing here.
2018-03-21 21:41:38 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Slava Pestov
11f949e5f1 Sema: Fix signature of materializeForSet with mutating getter and non-mutating setter
I admit this is an odd corner case that is unlikely to ever
come up in practice.

Fixes <rdar://problem/32860203>.
2018-03-10 03:39:08 -08:00
Huon Wilson
b1115af1eb Switch a pile of VarDecl::Specifier::Owneds to ::Default.
A lot of these probably should be Owned, but deciding that is work for
another time.
2018-03-08 12:36:37 +11:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Slava Pestov
8f9f7afc55 AST: Static properties of fixed-layout types are resilient
We don't want @_fixed_layout to apply to static properties, or you
get fun consequences like not being able to change static stored
properties defined in extensions of imported types to computed.
2018-01-21 01:31:44 -08:00
John McCall
52bb547a7e Merge pull request #13866 from rjmccall/accessor-decl
Split AccessorDecl out from FuncDecl.  NFC.
2018-01-12 17:02:35 -05: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
Slava Pestov
9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Jordan Rose
ca9d5a9df9 In Swift 3/4 mode, continue treating 'lazy override' as an override (#13335)
Follow-up for 7c707ce97c. Without this, the declaration would be
accepted, but any uses of the overridden property would be treated as
ambiguous because the property wouldn't really be marked as an
override.

rdar://problem/35900345
2017-12-11 15:13:55 -08:00
Huon Wilson
5f70f68c0d [AST] Store only interface types in NormalProtocolConformances.
Rather than storing contextual types in the type witnesses and associated
conformances of NormalProtocolConformance, store only interface types.

@huonw did most of the work here, and @DougGregor patched things up to
complete the change.
2017-11-16 11:45:18 -08:00
Slava Pestov
2920b4fd1c AST: Remove DeclContext::mapTypeOutOfContext() 2017-11-15 22:52:28 -08:00
Graydon Hoare
207a94ddd6 [Sema] Remove TypeChecker::addImplicitDestructor entirely. 2017-11-06 14:43:34 -08:00
Graydon Hoare
7e363ff97a [AST] Add implicit dtors outside typechecking, rdar://35198678 2017-11-04 02:59:52 -07:00
Slava Pestov
0f2da217a4 Sema: Fix some issues with overrides of materializeForSet
When overriding storage with a forced static dispatch materializeForSet,
the override's materializeForSet should not override the base
materializeForSet.

This is the case where a dynamic property witnesses a protocol
requirement, and Sema synthesizes a materializeForSet for it.

In this case, the synthesized materializeForSet dynamically dispatches
to the dynamic property's getter and setter, and the protocol witness
thunk directly calls the synthesized materializeForSet.

The subclass only needs to override the getter and setter in this case,
since the base class's materializeForSet will already do the right
thing.

In fact, marking it as an override exposes a problem where we cannot
serialize an xref to an imported property's materializeForSet, since
it was not created by the importer.
2017-10-26 17:11:09 -07:00