Commit Graph

2604 Commits

Author SHA1 Message Date
Doug Gregor
22e40fedf5 [SE-0258] Enable default argument for wrapped property going through init().
My recent refactoring of default arguments for the memberwise initializer
accidentally dropped support for getting a default argument when the
attached property wrapper has an init(). Reinstate that support,
fixing rdar://problem/52116923.
2019-06-25 10:03:15 -07:00
Slava Pestov
1e1e812768 Sema: Use a request to create lazy property backing storage 2019-06-19 22:12:55 -04:00
Slava Pestov
9ff34e82b0 Sema: Allow AbstractStorageDecl::overwriteImplInfo() to be called before adding any accessors 2019-06-19 22:12:55 -04:00
Slava Pestov
0ec33bfa4a Sema: Use a request to compute AbstractStorageDecl::getOpaqueReadOwnership() 2019-06-19 14:38:43 -04:00
Slava Pestov
4df9543ee8 Sema: Use a request to compute AbstractStorageDecl::is{Getter,Setter}Mutating() 2019-06-19 14:38:43 -04:00
Slava Pestov
7913d30236 Sema: Use a request to compute FuncDecl::getSelfAccessKind() 2019-06-19 14:38:43 -04:00
Slava Pestov
a1b8913edf Sema: Synthesize accessors for computed local and global properties
If a stored property has a didSet/willSet, we currently synthesize
the getter and the setter inside the parser.  I want to get rid of
the parser's code path for doing that and consolidate all accessor
synthesis here in Sema.

Note that the parser did not synthesize a modify. This is now more
explicit in the code.

Also, we have to relax an assertion since addMemberToContextIfNeeded()
now gets called on declarations in local contexts.
2019-06-18 18:35:03 -04:00
Hamish Knight
e1f8af2389 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-18 19:09:06 +01:00
Doug Gregor
e857852fdc [SE-0258] Rewrite findOriginalPropertyWrapperInitialValue() for composition.
Rewrite findOriginalPropertyWrapperInitialValue() to cope with composition
of property wrappers, making it more robust in the process.

Should fix rdar://problem/51576815.
2019-06-13 22:20:56 -07:00
Doug Gregor
166a6b8042 [SE-0258] Clean up some code repetition involving initialization forms. 2019-06-13 21:44:11 -07:00
Doug Gregor
82ed5e9a02 [SE-0258] Implement basic support for property wrapper composition.
When multiple property wrapper attributes are provided on a declaration,
compose them outside-in to form a composite property wrapper type. For
example,

  @A @B @C var foo = 17

will produce

  var $foo = A(initialValue: B(initialValue: C(initialValue: 17)))

and foo's getter/setter will access "foo.value.value.value".
2019-06-13 18:26:29 -07:00
Hamish Knight
a3ead02902 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-13 14:46:55 +01:00
swift-ci
69c05c09f2 Merge pull request #25386 from DougGregor/property-wrappers-memberwise-and-default-init 2019-06-12 12:59:12 -07:00
Doug Gregor
5244805b17 [SE-0258] Clean up memberwise initializer / default-initialization interaction
When the backing storage of a wrapped property is default-initialized via the
property wrapper type's init(), don't count that as a direct initialization
of the backing storage for the purposes of constructing the memberwise
initializer. Instead, treat this case the same as if there were no initializer,
keying the form of the memberwise initializer off the presence of
init(initialValue:).
2019-06-12 10:29:54 -07:00
John McCall
952eb9d8f9 Allow function-builder attributes on funcs and computed vars.
rdar://50150690
2019-06-11 17:34:45 -07:00
John McCall
007842261f Rework the requests for getting a parameter's function-builder type.
Turn the generic CustomAttrTypeRequest into a helper function and
introduce a FunctionBuilderTypeRequest that starts from a ParamDecl.
This has better caching characteristics and also means we only need to
do a single cache lookup in order to resolve the type in the normal path.
It also means we don't need as much parameterization in the cache.

In addition, check that the parameter has function type in the request,
not just when late-checking the attribute, and add a check that it isn't
an autoclosure.
2019-06-11 17:34:44 -07:00
John McCall
93b3320196 Make getFunctionBuilderType() return a Type. 2019-06-11 17:34:44 -07:00
John McCall
1e4f5f7750 Add @functionBuilder and check its applications to parameters. 2019-06-11 17:34:44 -07:00
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