Commit Graph

2036 Commits

Author SHA1 Message Date
Doug Gregor
f5ab62aa81 [SE-0258] Move "has lazy resolver" check later to handle merge-modules properly
The merge-modules phase doesn't have an active type checker, so we were bailing
out of property-wrapper queries before we had a chance to check the cache.
Move the check later, to the points where we actually need a type checker.

Fixes SR-10844 / rdar://problem/51484958.
2019-06-11 09:43:26 -07:00
Jordan Rose
cc6855b21b Merge pull request #17792 from ChristopherRogers/master
[SR-6706] Swift should complain about weak references to classes that don't support them
2019-06-10 20:02:08 -07:00
Christopher Rogers
0b27345d68 Swift should complain about weak references to classes that don't support them
Resolves SR-6706
2019-06-10 19:20:28 -04:00
Xi Ge
6fd332d62c Doc-serialization: skip declarations with double-underscore as name prefix
Double-underscored names suggest the symbols aren't supposed to be used by framework
clients. This patch excludes the doc-comments of these symbols in swiftdoc files.

rdar://51468650
2019-06-10 14:00:41 -07:00
Doug Gregor
1a555dfeda [SE-0258] Fix memberwise initializer involving wrapped properties.
The determination of which type to use within the implicit memberwise
initializer for a wrapper property (between the original property type
and the wrapper type) could be affected by the synthesis of the call
to the default initializer. Rewrite the logic here to depend on
aspects of the AST that don't change with further type checking.
2019-06-06 11:01:45 -07:00
Doug Gregor
a82d33ff4f [SE-0258] Fix crash with implicitly-initialized backing storage.
Fixes SR-10830 / rdar://problem/51443591
2019-06-05 14:05:24 -07:00
Saleem Abdulrasool
731c31f9a5 MSVC: litter the code with llvm_unreachable (NFC)
Add `llvm_unreachable` to mark covered switches which MSVC does not
analyze correctly and believes that there exists a path through the
function without a return value.
2019-06-01 19:02:46 -07:00
Slava Pestov
a31248997c SILGen: Correctly emit vtables when an override is more visible than the base
If an override B.f() is more visible than a base method A.f(), it is
possible that an override C.f() of B.f() cannot see the original method
A.f().

In this case, we would encounter linker errors if we referenced the
method descriptor or method dispatch thunk for A.f().

Make this work by treating B.f() as the least derived method in this
case, and ensuring that the vtable thunk for B.f() dispatches through
the vtable again.

Fixes <rdar://problem/48330571>, <https://bugs.swift.org/browse/SR-10648>.
2019-06-01 00:08:05 -04:00
Hamish Knight
623a6adee0 [AST] Add ValueDecl::getNumCurryLevels 2019-05-31 23:10:48 +01:00
Rintaro Ishizaki
10439a0f00 [CodeCompletion] Hide names starting with '$__' (instead of '$_')
rdar://problem/50073762
2019-05-31 11:10:04 -07:00
Rintaro Ishizaki
fcc35c7012 [SyntaxModel] Don't mark custom attribute as attribute-builtin
rdar://problem/50074156
2019-05-31 11:10:04 -07:00
Rintaro Ishizaki
d0659574ae [CodeCompletion] Don't include symbols starting with '$_'
rdar://problem/50073762
2019-05-31 11:10:04 -07:00
Hamish Knight
197ddb57ab [Sema][NFC] Simplify paramIsIUO implementation 2019-05-31 15:53:26 +01:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Doug Gregor
c02ecf9859 [SE-0258] Rename to Property Wrappers 2019-05-29 22:17:50 -07:00
Alexis Laferrière
d4e6b58214 Merge pull request #24741 from xymus/default-definition-request
Request to lazily compute the default definition type of associated types
2019-05-14 14:17:30 -07:00
Alexis Laferrière
547ba1cbef Intro a request to lazily compute default definition types
The new request, DefaultDefinitionTypeRequest, is triggered
by calling AssociatedTypeDecl::getDefaultDefinitionType.
2019-05-14 10:54:19 -07:00
Andrew Trick
22e5c55b3a Merge pull request #24717 from atrick/cache-field-number
Cache struct/class field offsets in SIL.
2019-05-14 08:36:33 -07:00
Andrew Trick
8f84429565 Add a scale-test for VarDecl::getStoredProperties.
Adds a NumStoredPropertiesQueries stat.

Adds a test case for an increasing number of lazy stored class
properties. Each property requires a formal access within the
initializer. This would manifest as cubic behavior in
AccessEnforcementOpts, which scales as O(1.5) in the above stat.
2019-05-13 16:54:55 -07:00
Slava Pestov
0455913583 AST: Make ConstructorDecl::getInitializerInterfaceType() more forgiving of invalid code 2019-05-13 17:25:48 -04:00
Slava Pestov
37412c2de2 AST: Add ParamDecl::toFunctionParam() 2019-05-10 15:00:49 -04:00
Alexis Laferrière
cfae7bba3d Avoid cycles when computing a requirement signature
Replace most remaining uses of isRequirementSignatureComputed by
isRequirementSignatureComputing which uses Evaluator::hasActiveRequest
to detect if the requirements are currently being computed.
2019-05-09 10:50:45 -07:00
Alexis Laferrière
6c929273db Intro a request to compute the requirement signature of a ProtocolDecl
Replaces the explicit call to computeRequirementSignature from
validateDecl with a lazy getRequirementSignature. A side effect is that
the generic params of a ProtocolDecl are no longer computed from
validateDecl and must be computed lazily too.
2019-05-08 14:28:35 -07:00
Pavel Yaskevich
83d6f027f5 [AST] NFC: Add ValueDecl::getOpaqueResultTypeRepr accessor
Follow-up cleanup to simplify code related to diagnosing of
opaque return type conformance mismatches.
2019-05-03 16:49:36 -07:00
Doug Gregor
6933382ac5 [Property delegates] Fix default argument printing with default initialization 2019-05-02 15:14:39 -07:00
Doug Gregor
f34aa79df1 [Property delegates] Implicit initialization for properties with delegates.
When a property delegate type has a default initializer, use that to
implicitly initialize properties that use that delegate and do not have
their own initializers. For example, this would allow (e.g.), delegate
types like the DelayedImmutable and DelayedMutable examples to drop
the explicit initialization, e.g.,

```
  @DelayedMutable var foo: Int
```

would be implicitly initialized via

```
  $foo = DelayedMutable()
```

This is a simplistic implementation that does not yet propertly handle
definite initialization.

Fixes rdar://problem/50266039.
2019-05-01 23:17:16 -07:00
Doug Gregor
bf2c4d951b Prevent less-visible properties with delegates from affecting memberwise initializer
When a property with an attached delegate has less-than-internal visibility
and is initialized, don’t put it into the memberwise initializer because
doing so lowers the access level of the memberwise initializer, making it
fairly useless.

Longer term, it probably makes sense to have several memberwise initializers
at different access levels, so adding an initialized `private var` make
the memberwise initializer useless throughout the rest of the module.

Addresses rdar://problem/50266245.
2019-05-01 14:10:56 -07:00
Alexis Laferrière
1119b91e80 Merge pull request #24204 from xymus/structural-type-request
GSB: use a request for the structural type of type aliases
2019-04-30 14:39:39 -07:00
swift-ci
ff208b677f Merge pull request #24363 from DougGregor/is-memberwise-initialized 2019-04-30 11:29:27 -07:00
Doug Gregor
96952ea9a2 [AST] Distinguish memberwise-initialized properties for storage vs. declared
The determination of whether a property is memberwise-initialized is
somewhat confused for properties that have synthesized backing properties.
Some clients (Sema/Index) want to see the declared properties, while others
(SILGen) want to see the backing stored properties. Add a flag to
`VarDecl::isMemberwiseInitialized()` to capture this variation.
2019-04-30 10:12:43 -07:00
Doug Gregor
1a169b91bd Centralize the definition of isMemberwiseInitialized()
This utility was defined in Sema, used in Sema and Index, declared in
two headers, and semi- copy-pasted into SILGen. Pull it into
VarDecl::isMemberwiseInitialized() and use it consistently.
2019-04-29 10:30:38 -07:00
Slava Pestov
fa12d85739 AST: Clean up associated type default representation a bit 2019-04-26 21:47:02 -04:00
Alexis Laferrière
c27dca3383 Sema: restrict the options to resolve the structural type of type aliases 2019-04-26 10:28:34 -07:00
Joe Groff
72701a1fba Merge pull request #24166 from jckarter/opaque-overload-checking
Sema: don't consider opaque types distinct for overloading purposes.
2019-04-25 20:29:45 -07:00
Joe Groff
b2d50c86b7 Sema: don't consider opaque types distinct for overloading purposes.
This is necessary because:

```
func foo() -> some P
func foo() -> some P
```

theoretically defines two distinct return types, but there'd be no way to disambiguate them. Disallow overloading only by opaque return type.
2019-04-25 14:28:56 -07:00
Alexis Laferrière
09fbdc20cb Sema: intro a request evaluator to get the structural type of type aliases
This request evaluator doesn't rely on the previous execution of
a compilation phase but it caches the result in a compatible way.
2019-04-25 10:21:36 -07:00
nate-chandler
155a155000 Merge pull request #23251 from nate-chandler/nate/omit-return
Allow return to be omitted from single expression functions.
2019-04-25 08:36:34 -07:00
swift-ci
d24bc38797 Merge pull request #23701 from DougGregor/property-delegates-as-custom-attributes 2019-04-24 22:51:18 -07:00
Nate Chandler
4f269fc6c0 Added diagnostic for dangling expression at end.
If the final expression in a function or closure which is missing a
return has the appropriate type, rather than producing the usual
diagnostic about a missing return, produce a diagnostic with a fixit to
insert a return before thatn final expression.

h/t Nate Cook
2019-04-24 09:59:54 -07:00
Nate Chandler
25bbef19a3 Visited single expression of AbstractFunctionDecl.
Taught getSingleExpressionBody to return null and
setSingleExpressionBody to require null in the case that there is a
single stmt of type FailStmt which replaces return nil during sema for
single expression failable initializers (i.e. init?() { nil }).
2019-04-24 09:59:54 -07:00
Nate Chandler
08bbce336f Addressed issues from PR review.
- preferred dyn_cast to is and get
- restored insertion of () on bare return statements
- used dyn_cast not dyn_cast_or_null when the argument is non-null
- used getSingleExpressionBody accessor during second AST modification
- eliminated erroneous access through null reference
2019-04-24 09:59:53 -07:00
Nate Chandler
74b462b3ba WIP: Allow return to be omitted from single expression functions. 2019-04-24 09:59:53 -07:00
Doug Gregor
7df695536e [Property delegates] Fix printing of memberwise initializer default arguments 2019-04-23 11:32:28 -07:00
Doug Gregor
4f56db2653 [Property delegates] Implement support for storageValue 2019-04-23 11:32:28 -07:00
Doug Gregor
cc68b12d1a [SILGen] Initialization of instance properties with property delegates
The initialization of an instance property that has an attached
property delegate involves the initial value written on the property
declaration, the implicit memberwise initializer, and the default
arguments to the implicit memberwise initializer. Implement SILGen
support for each of these cases.

There is a small semantic change to the creation of the implicit
memberwise initializer due to SE-0242 (default arguments for the
memberwise initializer). Specifically, the memberwise initializer will
use the original property type for the parameter to memberwise
initializer when either of the following is true:

  - The corresponding property has an initial value specified with the
    `=` syntax, e.g., `@Lazy var i = 17`, or
  - The corresponding property has no initial value, but the property
    delegate type has an `init(initialValue:)`.

The specific case that changed is when a property has an initial value
specified as a direct initialization of the delegate *and* the
property delegate type has an `init(initialValue:)`, e.g.,

```swift
struct X {
  @Lazy(closure: { ... })
  var i: Int
}
```

Previously, this would have synthesized an initializer:

```swift
init(i: Int = ???) { ... }
```

However, there is no way for the initialization specified within the
declaration of i to be expressed via the default argument. Now, it
synthesizes an initializer:

```swift
init(i: Lazy<Int> = Lazy(closure: { ... }))
```
2019-04-23 11:31:59 -07:00
Doug Gregor
6526cfa8d4 Memberwise initializer synthesis for properties with attached delegates. 2019-04-23 11:31:58 -07:00
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