Commit Graph

3502 Commits

Author SHA1 Message Date
Doug Gregor
b947a47a5d [AST] Reimplement ProtocolDecl::getInheritedProtocols() on decl name lookup.
Use the declaration-based name lookup facilities to re-implement
ProtocolDecl::getInheritedProtocols(), rather than dynamically selecting
between the requirement signature and the inherited types. This reduces
dependencies for this computation down to basic name lookup (no semantic
analysis) and gives us a stable result.
2018-08-06 16:12:09 -07:00
Doug Gregor
6556926cba [AST] Switch ProtocolDecl::requiresClass() over to decl-based resolution.
Resolving whether a protocol is class-bound only requires declaration-based
resolution (not the full type checker), so switch over to those APIs.
2018-08-06 10:07:16 -07:00
Doug Gregor
3018becde7 [Type checker] Eliminate type checking from early extension binding.
Use ExtensionDecl::getExtendedNominal() to wire up extensions to their
nominal types early in type checking (the bindExtensions()) operation,
rather than going through type validation to do so.
2018-08-03 11:26:49 -07:00
Doug Gregor
8dd40bbd5b [AST] Replace TypeBase::getGenericAncestor() with ClassDecl::getGenericAncestor().
This operation does not require type information, so move it over to
ClassDecl where this information is more generally useful.
2018-08-03 11:26:48 -07:00
Doug Gregor
84cb19758e [Name lookup] Introduce a request for “extended nominal type decl”.
Introduce a request for ExtensionDecl::getExtendedNominal() that
uses TypeRepr-based resolution to find the extended nominal
type declaration without going through type resolution.
2018-08-03 11:26:48 -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
Jordan Rose
2dcac4bcb2 Merge pull request #18408 from jrose-apple/default-on-your-futures
[SIL] Don't drop a default when switching on a non-exhaustive enum

rdar://problem/42775178
2018-08-01 10:54:19 -07:00
Jordan Rose
ec8aa9f014 Add EnumDecl::isEffectivelyExhaustive, and use it consistently
...rather than copying the same check around all over the place.
2018-07-31 19:01:00 -07:00
Jordan Rose
b25e561e82 Rename EnumDecl::isExhaustive to isFormallyExhaustive
...in preparation for an isEffectivelyExhaustive coming in the next
commit.
2018-07-31 19:01:00 -07: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
792d934e3e [Clang importer] Avoid recursion through isObjC more directly.
Also address some review comments related to the name lookup requests.
2018-07-31 10:20:15 -07:00
Doug Gregor
d07fa5ab69 Switch many callers of ClassDecl::getSuperclass() to ClassDecl::getSuperclassDecl().
ClassDecl::getSuperclass() produces a complete interface type describing the
superclass of a class, including any generic arguments (for a generic type).
Most callers only need the referenced ClassDecl, which is (now) cheaper
to compute: switch those callers over to ClassDecl::getSuperclassDecl().

Fixes an existing test for SR-5993.
2018-07-31 10:14:44 -07:00
Doug Gregor
cb7c2b4fce [Name lookup] Introduce requests for several name lookup operations.
Introduce three new requests for name lookup operations that avoid performing
type checking/semantic analysis. They work using syntactic information
(e.g., TypeReprs) and AST-level name lookup operations that will (eventually)
avoid and calls back into type checking. The new requests are:

* Retrieve the superclass declaration of a protocol or class declaration. Use
this request for ClassDecl::getSuperclassDecl() and
ProtocolDecl::getSuperclassDecl().
* Retrieve the types “directly referenced” by a particular location in
an inheritance clause. This query is based on looking at the TypeReprs
and performing fairly-minimal lookup, so it does not involve any Type
computations.
* Retrieve the types “directly referenced” by the underlying type of
a typealias. This query allows us to desugar a typealias without forming
a type.

Along with these is a core operation to transform a set of TypeDecl*s
into a set of NominalTypeDecl*s, looking through typealiases, and
without involving Type at all. The superclass-decl request does this
to find a ClassDecl; other requests will eventually do this to (e.g.)
find all of the protocols mentioned in an inheritance clause.
2018-07-31 10:14:44 -07:00
Slava Pestov
75bac0cc97 AST: Change AbstractFunctionDecl::computeType() to be more resilient against ill-formed code
In an upcoming patch we're going to start calling computeType() on
constructors and destructors parsed outside type context, so let's
just bail out if we're not in type context, instead of crashing.
2018-07-31 00:57:16 -07:00
Slava Pestov
5abbf5e4bb AST: Fix handling of error types in FuncDecl::getResultInterfaceType()
We would bail out early if the function type contained an
error type anywhere, which is incorrect.
2018-07-31 00:40:06 -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
Pavel Yaskevich
0781aee89c Merge pull request #16896 from xedin/cs-params-cache
[CSSolver] Add closure parameter type caching
2018-07-30 10:17:55 -07:00
Jordan Rose
6290d9be60 Introduce DescriptiveDeclKind::Property (#18183)
...and collapse StaticVar/ClassVar and StaticLet/ClassLet into
StaticProperty/ClassProperty.

"var" and "let" aren't great nouns to use in diagnostics to begin with,
especially alongside semantic terms like "instance method". Focus on
the type vs. non-type aspect instead with "property", which better
matches how people talk about member vars (and lets) anyway.
2018-07-30 09:23:59 -07:00
Mark Lacey
6b56154881 Use getParams() in findProtocolSelfReferences. 2018-07-29 15:38:37 -07:00
Pavel Yaskevich
0a404529c3 [Sema] Adjust Diagnostics/IDE to not assume that parameters always have types 2018-07-28 20:28:41 -07:00
Jordan Rose
23df594749 Remove a too-strict assertion concerning nested protocols (#18241)
This isn't allowed in the language, but the compiler shouldn't crash!
2018-07-25 19:35:21 -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
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
cd22c5d546 Use access scopes for the hard cases in ValueDecl::isAccessibleFrom
This function (actually checkAccess) was relying on some implicit
assumptions that aren't actually valid in all cases. When they're not,
just fall back to a slower but more correct implementation; when they
are, assert that the two implementations get the same answer. This
allows us to get rid of adjustAccessLevelForProtocolExtension (see
previous commit), though unfortunately not all of the associated hack.

The diff is bigger than I'd like because it includes moving functions
from NameLookup.cpp into Decl.cpp, but most of those didn't change.

- checkAccess only changed in the one if branch for protocols
- ValueDecl::isAccessibleFrom just added the assertion
- AbstractStorageDecl::isSetterAccessibleFrom did not change

No expected functionality change.
2018-07-23 16:36:16 -07: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
106878005e AST: Use AbstractFunctionDecl::computeType() 2018-07-23 02:09:43 -07: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
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
df9f7f979a Parse: Remove uses of getParameterLists() from default argument parsing 2018-07-22 20:56:56 -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
585b06e647 AST: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 12:28:26 -07:00
Slava Pestov
301d9f0cf3 AST: Give destructors a second parameter list
Constructors and methods had two parameter lists, one for self and one
for the formal parameters. Destructors only had one parameter list,
which introduced an annoying corner case.
2018-07-19 12:28:13 -07:00
Doug Gregor
1b63b688bf [AST] Use TinyPtrVector for the list of overridden declarations.
TinyPtrVector is a more-space-efficient SmallVector<_, 1>. Use it.
2018-07-18 16:56:43 -07:00
Doug Gregor
0966cd990a [AST] Performance hack for AssociatedTypeDecl::getOverriddenDecls().
The GenericSignatureBuilder is generating a *huge* number of invocations
of AssociatedTypeDecl::getOverriddenDecls(), causing contention in
the request-evaluator’s core data structures and a significant
slow-down in compile-time performance when the request-evaluator is
handling this computation. 

Those data structures need to be optimized, but in the meantime, 
introduce a performance hack to use the cached entry without going
through the request-evaluator. This will MISS dependencies and needs
to go away quickly.
2018-07-18 14:52:57 -07:00
Doug Gregor
dd6af425ea [AST] Only force computation of the @objc bit if we have a lazy resolver.
SourceKit queries for the Objective-C selector as part of its syntax
model, which is a semantic query. This manifests as a crash because
the type-checking requests haven’t been wired up at this point.

For now, route around the issue by not forcing computation of the
Objective-C name if there is no lazy resolver, but longer term we need
to decide whether (1) we should allow semantic queries here or (2) we
should codify such a “best effort” computation, or (3) SourceKit should
stop doing this.
2018-07-18 14:50:41 -07:00
Doug Gregor
d0a4e3286b [AST] Clang declarations never require a new vtable entry. 2018-07-18 14:50:40 -07:00
Doug Gregor
8b5ce42d3a [AST] Force computation of ‘isObjC’ before getting a selector.
The computation of Objective-C selector names is still stateful,
triggered by computing `isObjC()`. So, trigger `isObjC()` when
asking for an Objective-C selector name.
2018-07-18 14:50:40 -07:00
Doug Gregor
375578acf4 [Type checker] @nonobjc suppresses inheritance of ‘dynamic’.
Support an existing quirk where one can override a (dynamic) @objc
declaration with a @nonobjc one, which suppresses the inference of
‘dynamic’. In such cases, be aware that there is no vtable entry to
override.
2018-07-18 14:50:40 -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
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
Slava Pestov
7fea83e969 Sema: Simplify enum element validation 2018-07-18 01:54:24 -07: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
Matt Diephouse
35592747db Change "enum element" to "enum case" in diagnostics
From the perspective of the compiler implementation, they're elements. But users will think of these as cases—and many diagnostics already refer to these as enum cases.
2018-07-15 16:01:10 -04:00
Rintaro Ishizaki
20a1e5db23 [IDE] Range info for accessor decl.
Attributes on explicit accessor decl may have attributes. Only when the
range contains those attributes, the range-info should report
`SingleDecl`.
2018-07-13 09:47:49 +09: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
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
swift-ci
6516535d14 Merge pull request #17760 from DougGregor/refactor-type-checker-decl-objc 2018-07-05 11:57:07 -07:00