Commit Graph

2390 Commits

Author SHA1 Message Date
Doug Gregor
b8061eab34 Synthesize backing storage property for properties with attached delegates.
When a property has an attached property delegate, a backing storage
property of the corresponding delegate type will be
synthesized. Perform this synthesis, and also synthesize the
getter/setter for the original property to reference the backing
storage property.
2019-04-23 11:31:58 -07:00
Doug Gregor
53b9e25502 Implement initialization of properties with attached delegates.
A property with an attached delegate can be initialized in one of two ways:

* By directly specifying initialization arguments on the attribute,
  e.g., "@SomeDelegate(x: 17, y: 42) var a".
* By initializing the original property itself, which goes through the
  delegate type's init(initialValue:) initializer, e.g.,
  "@Lazy var x = 17".

Implement support for both forms of initialization, including type
inference and checking for inconsistencies (e.g., if the annotation on
the property type doesn't match what the delegate type would
provide).
2019-04-23 11:31:58 -07:00
Doug Gregor
96279c7044 Use custom attributes to apply property delegates to variables.
A custom attribute can be resolved to a property delegate type. Allow
this for property declarations (only), and diagnose the various places
where properties cannot have property delegates.
2019-04-23 11:31:58 -07:00
Doug Gregor
f9c716df87 Add support for the @propertyDelegate attribute.
Add the @propertyDelegate attribute, enforcing all of the semantic
requirements that are placed on property delegate types.
2019-04-23 11:31:58 -07:00
Arnold Schwaighofer
a0387eea40 Opaque result types: Dynamic replacement fixes for computed properties 2019-04-22 08:32:43 -07:00
Alexis Laferrière
007fbb6ebd Merge pull request #23932 from xymus/IsFinalRequest
Sema: implement `isFinal` using a request evaluator
2019-04-19 13:02:07 -07:00
Nathan Hawes
1060d1af1c Merge pull request #24073 from nathawes/inherit-default-values
[ParseableInterfaces] Support inheriting default arguments in module interfaces via '= super'
2019-04-18 22:21:35 -07:00
Joe Groff
5215290f25 Serialization: Cross-reference opaque return types by mangled name. rdar://problem/50005972 2019-04-18 14:41:26 -07:00
Joe Groff
59fd141457 Validate opaque return types for properties and subscripts. 2019-04-17 14:46:22 -07:00
Joe Groff
455f060967 fix rdar://problem/49230987 2019-04-17 14:46:21 -07:00
Joe Groff
7a8b9401ab Respond to Slava's feedback 2019-04-17 14:43:32 -07:00
Joe Groff
71912bbfd6 AST: Represent OpaqueTypeDecls.
To represent the abstracted interface of an opaque type, we need a generic signature that refines
the outer context generic signature with an additional generic parameter representing the underlying
type and its exposed constraints. Opaque types also need to be keyed by their originating decl, so
that we can treat values of the same opaque type as the same. When we check a FuncDecl with an
opaque type specified as its return type, create an OpaqueTypeDecl and associate it with the
originating decl. (A representation for *types* derived from the opaque decl will come next.)
2019-04-17 14:43:32 -07:00
Alexis Laferrière
98059831c9 Sema: implement isFinal using a request evaluator
Add the request evaluator `IsFinalRequest` to lazily determine if a
`ValueDecl` is final.
2019-04-17 09:17:44 -07:00
Nathan Hawes
c95252e1e5 Change from using the @_inheritedDefaultValue attribute to mark parameters with an inherited default argument to using '= super' 2019-04-16 15:21:25 -07:00
Nathan Hawes
9639bceded Add an attribute to inhert a param's default value from the overridden decl in module interfaces 2019-04-16 11:22:36 -07:00
Slava Pestov
39a22f3d6a AST: Remove ParameterTypeFlags::Escaping
Escapingness is a property of the type of a value, not a property of a function
parameter. Having it as a separate parameter flag just meant one more piece of
state that could get out of sync and cause weird problems.

Instead, always look at the noescape bit in a function type as the canonical
source of truth.

This does mean that '@escaping' is now printed in a few diagnostics where it was
not printed before; we can investigate these as separate issues, but it is
correct to print it there because the function types in question are, in fact,
escaping.

Fixes <https://bugs.swift.org/browse/SR-10256>, <rdar://problem/49522774>.
2019-04-15 00:25:03 -04:00
Brent Royal-Gordon
0fcb09d9ce Fix description of static subscripts in errors 2019-04-10 23:17:04 -07:00
Michael Gottesman
564b4fc11a [silgenpattern] Fix some stack-use-after-free errors caused by iterating over an Optional<ArrayRef<T>>.
Specifically the bad pattern was:

```
   for (auto *vd : *caseStmt->getCaseBodyVariables()) { ... }
```

The problem is that the optional is not lifetime extended over the for loop. To
work around this, I changed the API of CaseStmt's getCaseBodyVariable methods to
never return the inner Optional<MutableArrayRef<T>>. Now we have the following 3
methods (ignoring const differences):

1. CaseStmt::hasCaseBodyVariables().

2. CaseStmt::getCaseBodyVariables(). Asserts if the case body variable array was
   never specified.

3. CaseStmt::getCaseBodyVariablesOrEmptyArray(). Returns either the case body
   variables array or an empty array if we were never given any case body
   variable array.

This should prevent anyone else in the future from hitting this type of bug.

radar://49609717
2019-04-04 13:34:36 -07:00
Michael Gottesman
7b0d8455ca [ast][silgen] Wire up the case body var decls and use them in SILGenPattern emission to fix the evil fallthrough bug.
rdar://47467128
2019-04-03 23:51:06 -07:00
Michael Gottesman
ed94b13d3f [ast] Add a helper method for checking if a pattern contains a var decl and adopt it. 2019-04-03 13:38:03 -07:00
Michael Gottesman
8311f2b050 [ast] Add helpers for grabbing various case stmt corresponding var decls to a specific case stmt var decl. 2019-04-03 13:38:03 -07:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Brent Royal-Gordon
972eda2316 [NFC] AST-level support for static subscripts
* Moves the IsStatic flag from VarDecl to AbstractStorageDecl.
* Adds a StaticSubscriptKind to SubscriptDecl.
* Updates serialization for these changes.
* Updates SubscriptDecl constructor call sites for these changes.
2019-04-01 18:04:00 -07:00
Slava Pestov
bf39d72847 Merge pull request #23457 from Jumhyn/subscript-escaping-overload
Use mapSignatureFunctionType on SubscriptDecls
2019-03-31 02:01:32 -04:00
Ben Langmuir
26de7c1bf9 [index] Fix infinite loop while looking at superclasses
While checking for superclasses in isUnitTest, we need to handle
circular inheritance. For good measure, add tests for protocols as well.

The new API is designed to behave the same as walkInheritedProtocols
except that is walks over superclasses.

rdar://49434989
2019-03-29 15:56:46 -07:00
Frederick Kellison-Linn
427bdc5e4a Return on ErrorType instead of destructuring 2019-03-27 21:44:01 -04:00
Frederick Kellison-Linn
c0c7b45c6d Make isMethod false for SubscriptDecl 2019-03-27 20:27:33 -04:00
Frederick Kellison-Linn
36d1ee7ec8 Use mapSignatureFunctionType on SubscriptDecls 2019-03-27 20:27:33 -04:00
Slava Pestov
1864f6f679 AST: Introduce ClassDecl::isSuperclassOf() 2019-03-26 18:42:59 -04:00
Slava Pestov
cece98b2ed AST: Generalize ClassDecl::checkObjCAncestry() to ClassDecl::checkAncestry()
This replaces ClassDecl::hasObjCMembers() and some hand-coded walks.
2019-03-26 18:42:59 -04:00
Slava Pestov
a2049972ca AST: Add ModuleDecl::isResilient()
This cleans up some code. I'm keeping the ResilienceStrategy enum around
though, in case we want to use it to version the ABI in the future.
2019-03-26 18:42:59 -04:00
Xi Ge
bc9a7dd821 AST: fix a null pointer error found by performing module API checking 2019-03-26 13:03:10 -07:00
Ted Kremenek
fe215edb9b Merge pull request #19743 from Azoy/smarter-struct-init
[Sema] Synthesize default values for memberwise init
2019-03-25 17:31:01 -07:00
swift-ci
35f5c7afb3 Merge pull request #23538 from davezarzycki/diag_qoi_SelfAccessKind 2019-03-25 14:23:42 -07:00
David Zarzycki
f99124569b [Diag] Formalize SelfAccessKind printing 2019-03-25 15:40:26 -04:00
Michael Gottesman
b50d878f5d [parse/sema] Give all case bodies their own var decls without using those var decls for anything.
This is a step in the direction of fixing the fallthrough bug. Specifically, in
this commit I give case stmts a set of var decls for the bodies of the case
statement. I have not wired them up to anything except the var decl
list/typechecking.

rdar://47467128
2019-03-25 10:30:57 -07:00
Azoy
dcedba73f0 fix lazy vars
clean up lazy vars

more docs
2019-03-20 23:01:38 -05:00
Suyash Srijan
25e0a9f749 [Typechecker] Fix an issue with redeclaration checking (#23227)
* [typechecker] fix an issue with redeclaration checking

* [typechecker] use mapSignatureFunctionType in getOverloadSignatureType() to compute the type for the enum element decl, etc

* [typechecker] allow matching enums to functions as well, not just functions to enums

* [typechecker] fix the check for two enums

* [typechecker] check for nominal types as well when comparing enum elements

* [test] add more tests

* [typechecker] check for typealias as well
2019-03-20 00:25:42 -04:00
swift-ci
611534cc77 Merge pull request #23378 from gottesmm/pr-5d07f093c8b0891046d822d507c526e7ec6cfc1d 2019-03-18 16:23:24 -07:00
Michael Gottesman
b1a7b488fd [sema] Wire up VarDecl parent pointers for case stmt related Var Decls
This is in preparation for fixing issues around SILGenPattern fallthrough
emission and bad rename/edit all in scope of case stmt var decls. Specifically,
I am going to ensure that we can get from any VarDecl in the following to any
other VarDecl:

switch x {
case .a(let v1, let v2), .b(let v1, let v2):
  ...
  fallthrough
case .c(let v1, let v2), .d(let v1, let v2):
  ...
}

This will be done by:

1. Pointing the var decls in .d at the corresponding var decls in .c.
2. Pointing the var decls in .c at the corresponding var decls in .b.
3. Pointing the var decls in .b at the corresponding var decls in .a.
4. Pointing the var decls in .a at the case stmt. Recognizing that we are asking
for the next VarDecl, but have a case stmt, we check if we have a fallthrough
case stmt. If so, follow down the fallthrough case stmts until you find a
fallthrough case stmt that doesn't fallthrough itself and then return the
corresponding var decl in the last case label item in that var decl (in the
above .d).

In a subsequent commit I am going to add case body var decls. The only change as
a result of that is that I will insert them into the VarDecl double linked list
after the last case var decl of each case stmt.
2019-03-18 14:13:10 -07:00
Arnold Schwaighofer
a2c651504c Merge pull request #23337 from aschwaighofer/support_dynamic_replacement_of_stored_with_observer
Add support for dynamic replacement of didSet/willSet
2019-03-18 11:18:21 -07:00
Arnold Schwaighofer
35ca0e3423 Add support for dynamic replacement of didSet/willSet
The observer in a dynamic replacement of variables with a observer will
provide the dynamic replacement for the original.

var original : Int = 0 {
  didSet {
    print("original")
  }
}

@_dynamicReplacement(for: original)
var replacement : Int = 0 {
  didSet {
    print("replacement")
  }
}

rdar://48518788
2019-03-15 16:30:03 -07:00
Pavel Yaskevich
d8d5190518 [AST] Allow access-scope based access check inside inaccessible members
This aids expression diagnostics to pinpoint problems related to
chaining of inaccessible members  e.g.

```swift
struct A {
  struct B {}
}

_ = A.B()
```

Here both `B` and its synthesized constructor are inaccessible.
2019-03-15 15:58:11 -07:00
Azoy
6f7d20b99e Synthesize default values for memberwise init
Introduce stored property default argument kind

Fix indent

Assign nil to optionals with no initializers

Don't emit generator for stored property default arg

Fix problem with rebase

Indentation

Serialize stored property default arg text

Fix some tests

Add missing constructor in test

Print stored property's initializer expression

cleanups

preserve switch

complete_constructor

formatting

fix conflict
2019-03-13 18:57:36 -05:00
Arnold Schwaighofer
1719f0cdf1 Serialization: Also serialize the filename for internal storage decls with private accessors
If a value decl is internal hasTestableOrPrivateImport will succeed (or
fail) without looking at the filename. However this breaks when we query
an internal storage decl with private formal access for a private
setter: the query would fail because no filename was serialized for the
decl (we only serialize filenames for private decls). So in the special
case of a internal storage with private accessor also serialize the
filename.

rdar://48516545
2019-03-04 13:12:39 -08:00
Slava Pestov
b9bda84e28 SIL: Fix calls of @_weakLinked functions from serialized SIL
We have to set the SILFunction's 'weakLinked' flag in the defining
module too, so that it can be serialized. Otherwise when we
deserialize it we are not weak linking calls to the function.
2019-02-22 21:10:18 -05:00
Slava Pestov
3bf5a175a3 AST: Check the availability context from Decl::isWeakImported()
Fixes <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Slava Pestov
69d1cafd1c AST: Add AvailabilityContext parameter to Decl::isWeakImported()
For now, it's not used, but we do try to pass the right value down from
our various call sites.

Progress on <rdar://problem/46674512>.
2019-02-19 18:58:44 -05:00
Arnold Schwaighofer
17e64f5e9c Merge pull request #22691 from aschwaighofer/allow_dynamic_replacement_init_non_delegating
Allow dynamic replacement initializers to be non delegating
2019-02-19 08:38:08 -08:00
Arnold Schwaighofer
d5b33ba303 Only allow non resilient non-delegating initializers for now 2019-02-18 15:01:03 -08:00