Commit Graph

50 Commits

Author SHA1 Message Date
Pavel Yaskevich
f10a4819fd [Sema] NFC: Add a variant of addNonIsolatedToSynthesized that checks for @preconcurrency conformances
If derived conformance is marked as `@preconcurrency` instead of
marking synthesized members as `nonisolated` the compiler should
insert dynamic checks.
2025-01-14 15:44:57 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Konrad `ktoso` Malawski
e9c7f3c382 [Distributed] Target identifiers for protocol calls (#70928) 2024-02-16 07:19:20 -08:00
Allan Shortlidge
aef5e42457 Sema: Inherit SPI groups when synthesizing modify accessor.
Resolves rdar://108069565
2023-05-01 15:34:08 -07:00
Allan Shortlidge
7782f862c0 Sema: Avoid adding nonisolated twice to synthesized Hashable methods.
https://github.com/apple/swift/pull/42041 introduced a centralized mechanism for adding the `nonisolated` attribute to synthesized decls but did not clean up the existing code that was already doing so for `Hashable` conformances.

Resolves rdar://102106591
2022-11-08 18:35:27 -08:00
Hamish Knight
9844af214e [Sema] NFC: Silence documentation warning 2022-08-15 18:42:31 +01:00
Hamish Knight
6b9bcf3935 [AST] Change DotSyntaxCallExpr to take an Argument base
This allows us to more easily propagate inout
information to it, which will become a necessity
once InOutExpr is removed.
2022-08-08 15:11:00 +01:00
Slava Pestov
4a124f10ae Sema: Remove unused addFixedLayoutAttr() entrypoint 2022-07-29 11:59:17 -04:00
Doug Gregor
0c7707fb88 Derive nonisolated members for protocol conformances
When deriving witnesses for protocol conformances within an
actor-isolated type, make those members 'nonisolated'. In the case
where this would work, for example because some of the state is
mutable, don't allow derivation of those witnesses.

Fixes rdar://90233250.
2022-03-25 17:27:25 -07:00
Hamish Knight
47754822c7 [CodeSynthesis] Adopt ArgumentList
Most of this should be fairly mechanical, the
changes in PlaygroundTransform are a little more
involved though.
2021-09-01 18:40:26 +01:00
Slava Pestov
3aa33250ec Sema: Sink DiscriminatorFinder down into DebuggerTestingTransform 2020-06-25 19:35:06 -04:00
Dan Zheng
f9c5d7ae6c [AutoDiff] Derive Differentiable.zeroTangentVectorInitializer. (#31823)
`Differentiable` conformance derivation now supports
`Differentiable.zeroTangentVectorInitializer`.

There are two potential cases:
1. Memberwise derivation: done when `TangentVector` can be initialized memberwise.
2. `{ TangentVector.zero }` derivation: done as a fallback.

`zeroTangentVectorInitializer` is a closure that produces a zero tangent vector,
capturing minimal necessary information from `self`.

It is an instance property, unlike the static property `AdditiveArithmetic.zero`,
and should be used by the differentiation transform for correctness.

Remove `Differentiable.zeroTangentVectorInitializer` dummy default implementation.

Update stdlib `Differentiable` conformances and tests.
Clean up DerivedConformanceDifferentiable.cpp cruft.

Resolves TF-1007.
Progress towards TF-1008: differentiation correctness for projection operations.
2020-05-29 01:59:52 -07:00
Hamish Knight
6a7b2e0040 [Sema] Handle metatypes in buildSelfReference
Before attempting to get the superclass of a
self parameter type, check to see if we have a
metatype, and perform the necessary unwrapping and
re-wrapping if needed.
2020-04-03 09:18:58 -07:00
Dan Zheng
bbe86e908d [AutoDiff upstream] Add Differentiable protocol derived conformances. (#30671)
Add `AdditiveArithmetic` derived conformances for structs and classes, gated by
the `-enable-experimental-differentiable-programming` flag.

Structs and classes whose stored properties all conform to `Differentiable` can
derive `Differentiable`:

- `associatedtype TangentVector: Differentiable & AdditiveArithmetic`
  - Member `TangentVector` structs are synthesized whose stored properties are
    all `var` stored properties that conform to `Differentiable` and that are
    not `@noDerivative`.
- `mutating func move(along: TangentVector)`

The `@noDerivative` attribute may be declared on stored properties to opt out of
inclusion in synthesized `TangentVector` structs.

Some stored properties cannot be used in `TangentVector` struct synthesis and
are implicitly marked as `@noDerivative`, with a warning:

- `let` stored properties.
  - These cannot be updated by `mutating func move(along: TangentVector)`.
- Non-`Differentiable`-conforming stored properties.

`@noDerivative` also implies `@_semantics("autodiff.nonvarying")`, which is
relevant for differentiable activity analysis.

Add type-checking and SILGen tests.

Resolves TF-845.
2020-03-27 06:40:04 -07:00
Dan Zheng
7d1341e21c [Sema] NFC: fix typo.
`let` stored -> `let` stored property
2020-03-25 18:40:38 +00:00
Dan Zheng
e5cb871428 [AutoDiff upstream] Add flag-gated AdditiveArithmetic derivation. (#30628)
Add `AdditiveArithmetic` derived conformances for structs, gated by the
`-enable-experimential-additive-arithmetic-derivation` flag.

Structs whose stored properties all conform to `AdditiveArithmetic` can derive
`AdditiveArithmetic`:
- `static var zero: Self`
- `static func +(lhs: Self, rhs: Self) -> Self`
- `static func -(lhs: Self, rhs: Self) -> Self`
- An "effective memberwise initializer":
  - Either a synthesized memberwise initializer or a user-defined initializer
    with the same type.

Effective memberwise initializers are used only by derived conformances for
`Self`-returning protocol requirements like `AdditiveArithmetic.+`, which
require memberwise initialization.

Resolves TF-844.
Unblocks TF-845: upstream `Differentiable` derived conformances.
2020-03-25 10:31:50 -07:00
Robert Widmann
4be0e4a2bd Strip Forward-Declararations of TypeChecker 2020-03-16 19:19:02 -07:00
Slava Pestov
c3b6fd1d55 Sema: Move constructor synthesis code from TypeCheckDecl.cpp to CodeSynthesis.cpp
This was split between the two files; consolidate it in CodeSynthesis.cpp.
2019-08-06 21:36:08 -04:00
Slava Pestov
18ddb959f2 Sema: Move some code to a new file TypeCheckStorage.cpp 2019-08-06 21:20:26 -04:00
Slava Pestov
a4bb3101ea Sema: Remove addExpectedOpaqueAccessorsToStorage() 2019-08-06 16:30:13 -04:00
Slava Pestov
41bb473acd Sema: Refactor away triggerAccessorSynthesis()
This function was called on storage in primary files only. The only
remaining difference between this and addExpectedOpaqueAcessorsToStorage()
was setting the body synthesizer callback, but that's cheap so just do it
unconditionally when we synthesize an accessor.
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
02bad9a479 Sema: Clean up lazy properties and related code 2019-06-19 22:12:55 -04:00
Slava Pestov
95c221a118 Sema: Replace makeFinal() calls in favor of smarter IsFinalRequest 2019-06-13 01:03:33 -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
20dc9a4c6a Sema: Fix circular validation between memberwise initializer and stored property
Fixes <rdar://problem/42704745>.
2019-04-01 22:41:16 -04:00
Slava Pestov
392071e702 Sema: Peel off more code from the TypeChecker instance 2018-12-10 00:00:49 -05:00
Slava Pestov
7aed494bf3 Sema: Move accessor synthesis to the callback mechanism
Also change some TypeChecker usages to ASTContext.
2018-12-07 17:10:08 -05:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04:00
John McCall
ebed6afd59 Make it easy to iterate over all the opaque accessors of a declaration. 2018-08-08 22:44:47 -04: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
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
Doug Gregor
d99799486d [Type Checker] Upgrade ObjCReason to a class wrapping an enum.
Provide more information in ObjCReason for the case where we are
@objc because we are a witness to an @objc requirement, by carrying the
@objc requirement in the reason. Use this to eliminate the type checker
parameter from describeObjCReason().
2018-07-05 10:32:59 -07:00
Doug Gregor
d39aae0e46 [Type Checker] Factor out the Objective-C-specific checking for decls.
There is a lot of code involved in inferring and checking @objc that
was tangled with other checking for declarations and types. Move it
into its own source file with a more narrowly-defined interface. NFC
2018-07-05 10:13:47 -07:00
Doug Gregor
de41b6b523 [Type checker] Move override checking into its own file.
There is a lot of code involved in override checking; move it into its own
source file. NFC
2018-07-02 20:46:43 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Slava Pestov
58d4a07fa6 Sema: Clean up accessor synthesis
- Remove unnecessary calls to validateDecl() and typeCheckDecl()
- Simplify the logic around synthesizing materializeForSet
2016-12-08 23:22:16 -08:00
Slava Pestov
1a991da16d AST: Assign interface types to ParamDecls
First, ensure all ParamDecls that are synthesized from scratch are given
both a contextual type and an interface type.

For ParamDecls written in source, add a new recordParamType() method to
GenericTypeResolver. This calls setType() or setInterfaceType() as
appropriate.

Interestingly enough a handful of diagnostics in the test suite have
improved. I'm not sure why, but I'll take it.

The ParamDecl::createUnboundSelf() method is now only used in the parser,
and no longer sets the type of the self parameter to the unbound generic
type. This was wrong anyway, since the type was always being overwritten.
This allows us to remove DeclContext::getSelfTypeOfContext().

Also, ensure that FuncDecl::getBodyResultTypeLoc() always has an interface
type for synthesized declarations, eliminating a mapTypeOutOfContext()
call when computing the function interface type in configureInterfaceType().

Finally, clean up the logic for resolving the DynamicSelfType. We now
get the interface or contextual type of 'Self' via the resolver, instead
of always getting the contextual type and patching it up inside
configureInterfaceType().
2016-12-04 00:02:21 -08:00
Slava Pestov
287700631a Sema: configureImplicitSelf() no longer needs to return a type 2016-11-29 03:05:34 -07:00
Slava Pestov
0f7a455d7d AST: Don't call setType() on AbstractFunctionDecls and EnumElementDecls 2016-11-29 03:05:33 -07:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
170992c39f AST: Add Throws flag and ThrowsLoc to AbstractFunctionDecl
The verifier now asserts that Throws, ThrowsLoc and isBodyThrowing()
match up.

Also, add /*Label=*/ comments where necessary to make the long argument
lists easier to read, and cleaned up some inconsistent naming conventions.

I caught a case where ClangImporter where we were passing in a loc as
StaticLoc instead of FuncLoc, but probably this didn't affect anything.
2016-05-21 12:51:50 -07:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Slava Pestov
59a74b4dfe Sema: Clean up configureImplicitSelf() and related code to not return a generic parameter list, NFC
Instead, get the generic parameter list from the DeclContext,
since now we need it even if there's no 'self' type.
2015-12-15 22:59:38 -08:00
Slava Pestov
12d835c1d1 Sema: clean up @objc attribute handling a bit
There was a fair amount of code duplication in handling the various
places where @objc could either be explictly specified or be inferred;
centralize these in a new shouldMarkAsObjC() function. NFC

Swift SVN r28125
2015-05-04 19:26:21 +00:00
Doug Gregor
41ae48b22e Start parsing 'throws' on initializers.
Introduce basic validation for throwing @objc initializers, e.g., a
failable @objc initializer cannot also be throwing. However,
Objective-C selector computation is broken.

Swift SVN r27292
2015-04-14 22:52:29 +00:00
Doug Gregor
272371a3f5 Attach a foreign error convention to @objc methods.
For any @objc method, attach either the foreign error convention we inherit
from an overridden method (if available) or the foreign error
convention we computed as part of @objc validation.

Extend the AST dumper to dump the foreign error convention so that we
can test this.

Swift SVN r27267
2015-04-14 00:35:49 +00:00
John McCall
94e5d98ff7 Move 1700 lines of AST-synthesis code out of TypeCheckDecl.cpp.
It's only 6500 lines now!  So much better.

Swift SVN r23994
2014-12-17 23:42:36 +00:00