Commit Graph

1776 Commits

Author SHA1 Message Date
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
8f23915334 [Type Checker] Introduce a request for “overridden declarations”.
Introduce a new request kind to capture the computation of the set of
overridden declarations of a given declaration, eliminating the
stateful “setOverriddenDecls()” calls from the type checker.
2018-07-18 14:50:38 -07:00
David Zarzycki
6371d8d48c [AST] NFC: Use exhaustive switch in Decl::isBeingValidated() 2018-07-18 09:45:45 -04:00
Slava Pestov
8d6a55fedb Merge pull request #16655 from davezarzycki/formalize_DeclIsBeingValidatedRAII
[AST] NFC: Formalize Decl validation tracking via RAII
2018-07-17 14:07:53 -07:00
Jordan Rose
07e56a4351 Sprinkle LLVM_READONLY on some potentially recursive accessors (#17913)
I picked accessors that not only return the same result every time,
but also do no interesting validation work with possible side effects.
We have a lot more accessors that return the same result but also
force a bunch of things to be loaded or diagnostics to be emitted, and
I didn't want to change the behavior of any of those.

No intended functionality change; this is just supposed to be a small
optimization hint.
2018-07-12 14:16:29 -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
Xi Ge
f83ccd6438 migrator: handle changed parameter declarations by introducing bridging local variables.
When users override a SDK function whose parameter types have been changed,
we should introduce a local variable in the body of the function definition
to shadow the changed parameter. Also, a proper conversion function should
be applied to bridge the parameter to the local variable.

rdar://41828411
2018-07-11 13:41:37 -07:00
Hamish Knight
c66e68fb93 [Parse][Sema] Emit immediate deallocation warning on the '=' token for PBDs (#17700)
Pass through the location of the equal '=' token for pattern binding decl entries, and use this location for the immediate deallocation diagnostic. Previously, we were just diagnosing on the start of the initialiser expression.

Additionally, this commit moves the call to `diagnoseUnownedImmediateDeallocation` from `typeCheckBinding` to `typeCheckPatternBinding`. This not only gives us easier access to the PBD entry, but also avoids calling the diagnostic logic for statement conditions such as `if let x = <expr>`. We currently never diagnose on these anyway, as the 'weak' and 'unowned' keywords cannot be applied to such bindings.

Resolves [SR-7340](https://bugs.swift.org/browse/SR-7340).
2018-07-06 10:47:49 -07:00
Graydon Hoare
9b87c7be4e Merge pull request #17734 from graydon/access-level-request
Access level request
2018-07-05 16:30:04 -07:00
Doug Gregor
9a73d79da7 [AST] Add Decl::diagnose().
It’s quite common to emit a diagnostic about a specific declaration, where the
“location” of the is the declaration itself. Add a helper method
Decl::diagnose() to get the diagnostics engine from the ASTContext and
emit a diagnostic associated with this declaration.
2018-07-05 09:20:53 -07:00
John McCall
81abcb850e Add a utility function for getting the interface value type of storage; NFC.
Because subscripts can be generic, this isn't quite as universally useful
as you might think; it's pretty much only useful when mapping types into
the context of the declaration, e.g. into an accessor.
2018-07-05 02:48:41 -04:00
Graydon Hoare
a97df371f3 [AST] Fold getFormalAccessImpl into getFormalAccess. 2018-07-04 17:13:50 -07:00
Graydon Hoare
465ca073f8 [Sema] Move AccessLevel calculation to AST-level requests. 2018-07-04 16:56:26 -07:00
Graydon Hoare
01c0a8b5eb [AST] Propagate setterAccess to mutableAddressor as well as other accessors. 2018-07-04 16:54:59 -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
Doug Gregor
aa8b3c4d0e [AST] Move lazily-computed @objc bits into a separate LazySemanticInfo field.
To help us isolate the state that is primarily managed through the
request-evaluator, encapsulate that information in a LazySemanticInfo member
(as we do with superclass info and enum raw type info) rather than scattering
it around the AST.
2018-07-02 13:32:40 -07:00
Doug Gregor
be3974a4f2 [AST] Drop unnecessary pass-by-reference from simple_display for ValueDecls. 2018-07-02 13:32:39 -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
f81036202d Merge pull request #17566 from rjmccall/storage-impls
Generalize storage implementations to support generalized accessors
2018-06-30 12:58:33 -04: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
94feb373c8 AST: Remove 'checked inheritance clause' bit from TypeDecl and ExtensionDecl 2018-06-30 00:20:36 -07:00
Doug Gregor
346e5da333 [AST] Add bits to capture ValueDecl's "isObjC" state and whether it has been computed.
One small step toward computing "isObjC" via the request-evaluator.
2018-06-28 20:22:44 -07:00
Slava Pestov
6d88ab3ab5 Merge pull request #17611 from slavapestov/protocol-superclass-part-1
Protocols with superclass constraints - part 1
2018-06-28 19:00:26 -07:00
Slava Pestov
fcfa1786c8 IRGen: Add another lldb resilience hack
When accessing global variables defined in the REPL, lldb does not consult
debug info, so it does not see that the DW_OP_deref was emitted.

So instead, set a special bit on globals defined in the REPL which bypasses
resilience for them altogether.

Part of the fix <rdar://problem/39722386>.
2018-06-28 16:56:55 -07:00
Slava Pestov
5f4f55caf8 AST: Add superclass field to ProtocolDecl 2018-06-28 15:19:20 -07:00
Slava Pestov
0a60619b70 Sema: Declaration signatures should respect @usableFromInline
Previously we made sure that inlinable function bodies only
reference @usableFromInline or public declarations, but we
also have to make sure that @usableFromInline declarations
only reference other declarations that are at least as
visible.

Otherwise, you could, for example, define a @usableFromInline
typealias which referenced an internal type, and then
reference the typealias from a @usableFromInline function body.
2018-06-26 00:31:32 -07:00
Slava Pestov
aade63e45e AST: Some tweaks for ValueDecl::isUsableFromInline()
Make this method public and fix it to do the right thing for
associated types.
2018-06-25 21:27:49 -07:00
Joe Groff
d82137b3da Merge pull request #17404 from jckarter/trivial-property-descriptors
SILGen: Emit "trivial" property descriptors for properties that withhold no information about their implementation.
2018-06-21 20:33:36 -07:00
Joe Groff
3e4e00c163 SILGen: Emit "trivial" property descriptors for properties that withhold no information about their implementation.
Client code can make a best effort at emitting a key path referencing a property with its publicly exposed API, which in the common case will match what the defining module would produce as the canonical key path component representation of the declaration. We can reduce the code size impact of these descriptors by not emitting them when there's no hidden or possibly-resiliently-changed-in-the-past information about a storage declaration, having the property descriptor symbol reference a sentinel value telling client key paths to use their definition of the key path component.
2018-06-21 15:18:24 -07:00
Doug Gregor
81bee08369 [AST] Make ValueDecls displayable via their DeclRefs. 2018-06-21 06:39:03 -07:00
David Zarzycki
cc0976a678 [AST] NFC: Reorder inline bitfield for performance
As documented in the inline bitfield header, naturally sized fields
should be last for optimal code gen.
2018-06-17 08:11:29 -04: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
7bf8623b52 [AST] Clean up whitespace 2018-06-16 13:05:18 -07:00
swift-ci
27b450180b Merge pull request #17199 from DougGregor/remove-iterative-type-checker 2018-06-16 09:12:18 -07:00
Doug Gregor
3e56d88a92 [AST] Block recursion through ProtocolDecl::getInheritedProtocols(). 2018-06-16 02:14:07 -06:00
Doug Gregor
d098b3e571 [Sema] Remove the IterativeTypeChecker. 2018-06-15 22:46:55 -07:00
Doug Gregor
2b2e143f59 [Request-Evaluator] Introduce a request for getting an "inherited type". 2018-06-14 15:29:57 -07:00
Doug Gregor
99e540f588 [Evaluator] Add an “enum raw type” request and use it consistently.
Similar to get “superclass of class” request, introduce an “enum raw type”
request that is accessed via EnumDecl::getRawType().
2018-06-14 15:29:57 -07:00
Doug Gregor
ef337bb8ba [Evaluator] Use the request-evaluator for the superclass of a class.
Wire up the request-evaluator with an instance in ASTContext, and
introduce two request kinds: one to retrieve the superclass of a class
declaration, and one to compute the type of an entry in the
inheritance clause.

Teach ClassDecl::getSuperclass() to go through the request-evaluator,
centralizing the logic to compute and extract the superclass
type.

Fixes the crasher from rdar://problem/26498438.
2018-06-14 15:28:36 -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
fischertony
7313a90eb1 [Sema] Generalize the 'declared here' diagnostic 2018-05-22 18:17:15 +03:00
Slava Pestov
8bf90f21d4 AST: Remove unneeded isDefinition and needsCapture methods from ValueDecl 2018-05-13 22:42:47 -07:00
Rintaro Ishizaki
9fc09858ae [AST] Stop using side-table for local discriminators 2018-05-11 15:37:01 +09: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
Slava Pestov
753967411a AST: Support '@_usableFromInline import' 2018-05-01 17:53:51 -07:00
Slava Pestov
22fe6181dd AST: Fix uninitialized memory 2018-04-20 10:21:58 -07:00
Slava Pestov
a73bc7b899 AST: Add AbstractFunctionDecl::isSynthesized() flag 2018-04-19 18:22:34 -07:00
Jordan Rose
3cf00637fa AST-verify that 'open' is only used on classes and overridable members (#15996)
...and fix places where it was being used inappropriately.

- Don't use 'open' on non-class members in the importer.
- Use the existing 'copyFormalAccessFrom' instead of an ad hoc version
  for synthesized typealiases for protocol conformances. (This can
  change 'internal' down to 'fileprivate', but only where the
  enclosing type was already 'private' or 'fileprivate'.)
- Fix 'copyFormalAccessFrom' to not copy '@usableFromInline' onto
  declarations that don't support it (namely, the above typealiases).

This should have no visible effect in practice.
2018-04-18 16:47:54 -07:00
Jordan Rose
28a1dc7770 Use 'fileprivate' for synthesized members of 'private' decls (#15980)
Since 'private' means "limit to the enclosing scope (and extensions
thereof)", putting it on a member means that the member can't be
accessed everywhere the type might show up. That's normally a good
thing, but it's not the desired effect for synthesized members used
for derived conformances, and when it comes to class initializers this
actually violates AST invariants.

rdar://problem/39478298
2018-04-17 15:19:35 -07:00
Slava Pestov
75db43b978 AST: Replace ProtocolType::compareProtocols() with TypeDecl::compare() 2018-04-06 15:41:07 -07:00