Commit Graph

2036 Commits

Author SHA1 Message Date
Slava Pestov
b92918889f AST: Don't cache NominalTypeDecl::getDeclaredTypeInContext() 2019-08-22 01:46:50 -04:00
Jordan Rose
94d1e5efe6 Avoid reserved names in C++ code: "__Consuming" (#26720)
Double-underscored names are reserved for the C++ "implementation"
(language and standard library). Even though "__Consuming" isn't
likely to be part of the C++ standard any time soon, we should follow
the rules.

Note that the API digester will continue to use the string
"__Consuming" for now, even though the underscores aren't really
significant, to avoid invalidating existing dumps.

No functionality change.
2019-08-19 13:06:53 -07:00
Slava Pestov
70bcd74ed0 Sema: Introduce IsImplicitlyUnwrappedOptionalRequest 2019-08-15 18:41:42 -04:00
Slava Pestov
1c3ac86796 AST: Banish OptionalTypeKind to ClangImporter.h
The only place this was used in Decl.h was the failability kind of a
constructor.

I decided to replace this with a boolean isFailable() bit. Now that
we have isImplicitlyUnwrappedOptional(), it seems to make more sense
to not have ConstructorDecl represent redundant information which
might not be internally consistent.

Most callers of getFailability() actually only care if the result is
failable or not; the few callers that care about it being IUO can
check isImplicitlyUnwrappedOptional() as well.
2019-08-15 18:41:42 -04:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Rintaro Ishizaki
0555d30b8c Merge pull request #26546 from rintaro/ide-completion-rdar53034550
[AST] Be lenient with PatternBindingIntializer without PatBindingDecl
2019-08-13 21:21:37 +02:00
Slava Pestov
2f33356083 AST: Optimize construction of the AnyObject dispatch table
Instead of visiting all members of all types and extensions, bail out
early if the type is not a class or protocol, or the extension is not
extending a class. This means we don't visit structs, enums or
protocol extensions at all, which will avoid delayed parsing.

Also, we were evaluating isObjC() on each member, which is an expensive
operation; if the member does not have an explicit @objc we would still
have to check if it overrides an @objc method or witnesses an @objc
protocol requirement.

Since most members are not ever found by dynamic lookup, this is wasted
work. Instead, let's rely on AnyObject lookup filtering non-@objc
members at the call site, which it was already doing anyway.
2019-08-12 17:55:44 -04:00
Slava Pestov
9dd835c71b Sema: Replace the finalizeDecl() mechanism with ClassDecl::getEmittedMembers()
The only thing remaining in finalizeDecl() is synthesis of
certain class members. Let's turn that into a request.
2019-08-09 19:08:47 -04:00
Slava Pestov
0063f158be AST: Request-ify synthesis of the implicit destructor 2019-08-09 19:08:47 -04:00
Rintaro Ishizaki
428bbe1060 [AST] Be lenient with PatternBindingIntializer without PatBindingDecl
PatternBindingInitializer may not be attached to any
PatternBindingDecl. e.g.

  struct S {
    @CustomAttr(something)
  }

In this case DeclContext for 'something' is PatternBindingInitializer,
but it doesn't have PatternBindingDecl because it's not written yet.

Fixes a crash in code-completion.

rdar://problem/53034550
2019-08-08 10:48:47 -07:00
Harlan Haskins
4277f11922 Merge pull request #26506 from harlanhaskins/extremely-default-and-incredibly-nil
[AST] Handle printing default values for tuples of nils
2019-08-07 09:13:47 -07:00
Slava Pestov
05baaa86cc AST: Slightly more efficient requiresNewVTableEntry() 2019-08-06 17:57:41 -04:00
Slava Pestov
6c5ecb5fc9 AST: Introduce AbstractStorageDecl::visit{Parsed,Emitted}Accessors() 2019-08-06 16:30:13 -04:00
Slava Pestov
e0cc652616 AST: Replace AbstractStorageDecl::hasAnyAccessors() with hasParsedAccessors() 2019-08-06 16:21:55 -04:00
Harlan Haskins
7fd8649d30 [AST] Handle printing default values for tuples of nils
If a var has optional type, e.g.

```
var x: Int?
```

It will be implicitly initialized to `nil`. However, there's a second,
undocumented behavior: tuples of optional type, potentially nested infinitely,
will also be initialized, to tuples of nil.

So this var

```
var w: ((Int?, (), Int?), (Int?, Int?))
```

Will be default-initialized to

```
((nil, (), nil), (nil, nil))
```

We need to handle this inside getDefaultValueStringRepresentation,
otherwise we will crash while emitting partial modules.

Fixes one instance of rdar://51560190
2019-08-06 11:58:50 -07:00
David Ungar
e3d6e6b844 Merge pull request #26416 from davidungar/pbd-sourcerange
[ASTScope lookup] Fix PatternBindingEntry initializer getters and rectify its source range
2019-08-05 14:48:47 -07:00
David Ungar
b38076490b Address review comments re clarity
setOrigInit -> setOriginalInit
2019-08-05 13:42:35 -07:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
David Ungar
1011998a97 Fix PatternBindingEntry::getSourceRange 2019-08-01 16:59:40 -07:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Slava Pestov
d3f65e7b4b AST: Remove SubscriptDecl::isSettable() 2019-07-31 21:26:02 -04:00
Slava Pestov
78c71c9ae1 Sema: Change checkOverrideAccessControl() to not need a synthesized setter
We can compute the setter's AccessScope directly, without creating
it first.
2019-07-31 21:26:02 -04:00
Slava Pestov
28d1466577 Sema: Add request to synthesize opaque accessors
For now, this just serves to clean up some code; we still eagerly trigger
synthesis in the same places as before.
2019-07-31 14:54:57 -04:00
Slava Pestov
112a8d095e AST: simple_display() for AccessorKind 2019-07-31 14:54:57 -04:00
Slava Pestov
e41760e44f Sema: Add request to compute if an AccessorDecl is transparent
Implicit accessors are sometimes transparent for performance reasons.
Previously this was done in Sema by maybeMarkTransparent(), which would
add a TransparentAttr. Replace this with a request.
2019-07-31 14:54:57 -04:00
Slava Pestov
37f0d6a613 Sema: Refactor away maybeAddAccessorsToStorage()
This centralizes the decision to add or not to add accessors in one place.
2019-07-31 14:54:57 -04:00
Slava Pestov
714f14603e Sema: Add request to compute if an AbstractStorageDecl requires an opaque modify coroutine 2019-07-31 14:54:57 -04:00
Slava Pestov
6922d976fd Sema: Add request to compute if an AbstractStorageDecl requires opaque accessors 2019-07-31 14:54:57 -04:00
Slava Pestov
66f115f3ea Merge pull request #26364 from theblixguy/fix/emit-vtable-entry-generic-mismatch
[AST] Emit vtable thunk if base method's generic requirements are not satisfied by derived
2019-07-30 19:02:18 -04:00
Slava Pestov
f0c0146801 AST: Clean up findOverridingDecl() and findImplementingMethod()
These are two slightly different operations. Make them share code and
prepare them for when we stop adding accessors to their parent
DeclContext.

Note the FIXMEs; this code could use additional attention.
2019-07-30 15:14:33 -04:00
David Ungar
d236a178ca Merge pull request #26095 from davidungar/parser-changes
[Parser] Fixes for ASTScope lookup
2019-07-29 19:59:00 -07:00
Holly Borla
fd03db42cf Merge remote-tracking branch 'upstream/master' into init-kind-request 2019-07-29 13:39:56 -07:00
Suyash Srijan
41249804d4 [AST] Make parameters 'const' in 'overrideGenericSignatureReqsSatisfied()' and 'getOverrideGenericSignature()' 2019-07-28 20:51:47 +01:00
Joe Groff
61261fcddf Merge pull request #26326 from jckarter/property-wrapper-composition-mutatiness
Sema: Correct composition of property wrappers.
2019-07-27 10:16:44 -07:00
Joe Groff
fa4dd15612 Sema: Correct composition of property wrappers.
Fixes rdar://problem/53407949 | SR-11138. Previously, we'd only look at the outermost property wrapper to decide whether the wrapped property's getter and setter were `mutating` (or exist at all). In reality, this requires considering the semantics of the composed accesses of each wrapper layer's
`wrappedValue` property. Fixing this systematically addresses a number of issues:

- As SR-11138 reported, composing a nonmutating-get-set wrapper ought to produce a composed wrapper
  that's nonmutating.

- We would previously allow a property wrapper with a mutating getter to be nested inside one with
  only a getter, even though the resulting implementation was unsound (because there's no mutable
  context for the inner wrapper to execute its get on.)

- Similarly, we would construct unsound setters in cases where the setter can't exist, such as when
  the nested wrapper isn't settable but the outer wrapper is.
2019-07-26 16:09:54 -07:00
Holly Borla
709efbc52c Sema: implement getInitKind using a request evaluator.
Add the request `InitKind` to lazily compute the kind of an initializer
declaration.
2019-07-26 15:55:09 -07:00
Suyash Srijan
f6d22e5ca4 [AST] Adds a new helper method to check whether a method's generic requirements are satisfied 2019-07-26 22:09:23 +01:00
Suyash Srijan
3a2ab9648a [AST] Emit vtable thunk if base method's generic requirements are not satisfied by the derived method 2019-07-26 00:20:21 +01:00
Joe Groff
0c13a4b759 Check default init before synthesizing wrapper backing properties.
Fixes a regression where the compiler would reject something like:

  @State var x: Int?

as not having an initializer, even though an Int? property ought to default to nil.
rdar://problem/53504653
2019-07-25 15:17:03 -07:00
David Ungar
6577e68b6b Fixes for review 2019-07-25 07:50:39 -07:00
David Ungar
8caf6f39e1 Fixes for ASTScope lookup
1. Track real EndLoc of TypeAliasDecl and SubscriptDecl.
2. Ensure TypeAliasDecl gets added to AST when doing completion.
2019-07-25 07:50:38 -07:00
Slava Pestov
e88f0c2a9a Merge pull request #26282 from slavapestov/storage-impl-info-request
Use a request to compute AbstractStorageDecl::getImplInfo()
2019-07-23 21:12:32 -04:00
Holly Borla
10a4e3ef41 Merge pull request #26278 from hborla/existential-type-supported-request
Sema: implement `existentialTypeSupported` using a request evaluator.
2019-07-23 14:05:35 -07:00
Slava Pestov
60e1dfe8b9 Sema: Use a request to compute AbstractStorageDecl::getImplInfo()
This just moves the code from the parser into a request. Sema will
still overwrite the ImplInfo field for lazy properties and
property wrappers; refactoring that is next.
2019-07-23 16:13:28 -04:00
Slava Pestov
4eec522578 Sema: Fix inheritance of @requires_stored_property_inits
Previously we would copy this attribute from a superclass to the
subclass when validating a subclass. However, this is only correct
if the superclass is always guaranteed to have been validated
before the subclass.

Indeed, it appears this assumption is no longer true, so we would
sometimes lose track of the attribute, which would result in SILGen
failing to emit the ivar initializer entry point.

Instead, check for the attribute as part of the superclass walk
in checkAncestry(), ensuring the result is always up to date, correct,
and cached.

As a follow-up, we should also convert checkAncestry() into a
request, but I'm not doing that here to keep the fix short.

Fixes <rdar://problem/50845438>.
2019-07-23 12:23:27 -04:00
Slava Pestov
454281b226 AST: Split off StorageImplInfo from AbstractStorageDecl::AccessorRecord
We want to compute the former independently of the latter.
It's only 16 bits so storing it inside the Decl is fine;
it also allows us to eliminate the 'compact' representation
where an AbstractStorageDecl without an accessor record is
assumed to be stored.
2019-07-22 20:19:09 -04:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Holly Borla
9f19597f73 Sema: implement existentialTypeSupported using a request evaluator.
Add the request `ExistentialTypeSupportedRequest` to lazily determine
if we are allowed to refer to an existential type conforming to a
protocol.
2019-07-22 15:35:10 -07:00
swift-ci
05d2ef22b8 Merge pull request #26246 from DougGregor/property-wrapper-crash-fixes 2019-07-19 16:21:35 -07:00
Doug Gregor
118a557304 [SE-0258] Check for a NULL type.
Within invalid code, we might encounter expressions without type
information yet. Check for NULL here.

Fixes crash from rdar://problem/53120878.
2019-07-19 10:26:26 -07:00