Commit Graph

2017 Commits

Author SHA1 Message Date
Xiaodi Wu
ce3334d280 [gardening] Adjust line wrapping and code comments for newly added diagnostic 2021-02-27 09:44:59 -05:00
Evan Wilde
9b75f32c58 Merge pull request #36161 from etcwilde/ewilde/remove-has-async-alt-flag
[Concurrency] Remove @hasAsyncAlternative feature flag
2021-02-26 09:48:52 -08:00
Evan Wilde
c5a67fdcb7 Remove feature flag for has-async-alt attr
This patch removes the feature flag for @hasAsyncAlternative since it's
already protected by the experimental concurrency flag and will go in
with the concurrency features.

This fixes one of Doug's comments on
https://github.com/apple/swift/pull/36027.
2021-02-25 08:58:05 -08:00
Rintaro Ishizaki
26aa91e660 Merge pull request #35230 from mininny/default-accessor-error-in-protocol
[Diagnostics] Improve diagnostic for defaulted accessor in a protocol property.
2021-02-24 10:17:53 -08:00
Ben Barham
3a7bf2301b [AST] Add a new attribute @hasAsyncAlternative
This attribute marks a function has having an async alternative,
optionally providing the name of that function as a string. Intended to
be used to allow warnings when using a function with an async
alternative in an asynchronous context, to make the async refactorings
more accurate, and for documentation.
2021-02-18 16:18:38 +10:00
Doug Gregor
8448e61b3a Add support for attributes on closures. 2021-02-16 22:19:43 -08:00
Arnold Schwaighofer
5e851ac5a0 Merge pull request #35945 from aschwaighofer/revert_make_prespecialization_experimental
Revert "Merge pull request #34848 from aschwaighofer/make_prespecialization_experimental"
2021-02-16 07:35:36 -08:00
Slava Pestov
6c69d17e0c Parse: Implement parsing for 'reasync' attribute
Part of <rdar://problem/71098795>.
2021-02-15 22:18:54 -05:00
Arnold Schwaighofer
084db0d38f Revert "Merge pull request #34848 from aschwaighofer/make_prespecialization_experimental"
This reverts commit 3aec862e62, reversing
changes made to 158427bd5b.
2021-02-12 10:12:01 -08:00
Minhyuk Kim
518e1b0a59 [Parse] Improve error for defaulted accessor in a protocol property. SR-13963 2021-02-12 22:40:33 +09:00
Evan Wilde
fc41826da9 Rename 'actor class' -> 'actor'
This patch softly updates the spelling of actors from `actor class` to
`actor`. We still accept using `actor` as a modifying attribute of
class, but emit a warning and fix-it to make the change.

One of the challenges that makes this messier is that the modifier list
can be in any order. e.g, `public actor class Foo {}` is the same as
`actor public class Foo {}`.

Classes have been updated to include whether they were explicitly
declared as an actor. This change updates the swiftmodule serialization
version number to 0.591. The additional bit only gets set of the class
declaration was declared as an actor, not if the actor was applied as an
attribute. This allows us to correctly emit `actor class` vs `actor`
emitting the code back out.
2021-02-10 08:05:57 -08:00
Richard Wei
18fe723543 Merge pull request #35811 from rxwei/69980056-differentiable-reverse
[AutoDiff] Add '@differentiable(reverse)'.
2021-02-08 04:32:27 -08:00
Richard Wei
af8942d940 [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'.
Compiler:
- Add `Forward` and `Reverse` to `DifferentiabilityKind`.
- Expand `DifferentiabilityMask` in `ExtInfo` to 3 bits so that it now holds all 4 cases of `DifferentiabilityKind`.
- Parse `@differentiable(reverse)` and `@differentiable(_forward)` declaration attributes and type attributes.
- Emit a warning for `@differentiable` without `reverse`.
- Emit an error for `@differentiable(_forward)`.
- Rename `@differentiable(linear)` to `@differentiable(_linear)`.
- Make `@differentiable(reverse)` type lowering go through today's `@differentiable` code path. We will specialize it to reverse-mode in a follow-up patch.

ABI:
- Add `Forward` and `Reverse` to `FunctionMetadataDifferentiabilityKind`.
- Extend `TargetFunctionTypeFlags` by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in `DifferentiabilityMask` which is reserved for `AsyncMask` and `ConcurrentMask`; `AsyncMask` is ABI-stable so we cannot change that.

_Differentiation module:
- Replace all occurrences of `@differentiable` with `@differentiable(reverse)`.
- Delete `_transpose(of:)`.

Resolves rdar://69980056.
2021-02-07 14:09:46 -08:00
Rintaro Ishizaki
4c9d9337ea [Parse] Fix hash accumulation in decl member parsing
For example, given:

  class C: P {
    func foo() {}
  }

For the outer context (i.e. source file), the interface hash shoule be
'class C : P { }' for the member list, it's '{ func foo ( ) { } }'.
This must be the same regardless delayed parsing is enabled.
2021-02-01 17:46:44 -08:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
Rintaro Ishizaki
8a58107123 [Parse] Diagnose default argument for subscript in protocols
Protocol requirements don't support default arguments. Although this is
a "semantic" diagnostics, we currently do this for 'func' and 'init' in
Parser. So for fixing a crash, let's to it for 'subscript' in Parser
too.

rdar://problem/73159041
2021-01-22 17:21:17 -08:00
Robert Widmann
73ac8d3531 Replace llvm::MD5 with StableHasher 2021-01-21 17:19:38 -08:00
Alexis Laferrière
8992d2c6b9 [Sema] Accept availability macros in @_originallyDefinedIn
Availability macros passed via the frontend flag -define-availability
should be accepted by @_originallyDefinedIn where they behave as they do
in @available.

rdar://72354787
2021-01-13 10:44:06 -08:00
Doug Gregor
8c123e8505 [Concurrency] Hard-code support for importing @MainActor.
Our name lookup rules for the resolution of custom attributes don't
allow for them to find MainActor within the _Concurrency library.
Therefore, hardcode @MainActor to map to _Concurrency.MainActor.

While here, make sure we drop concurrency-specific attributes that
show up in Clang attributes when we aren't in concurrency mode.
2021-01-08 17:03:50 -08:00
Rintaro Ishizaki
4284a51589 [Parse/CodeCompletion] Implement effects specifier completion
Rewrote and rename 'parseAsyncThrows' to 'parseEffectsSpecifiers'.
Implemented 'CodeCompletionCallbacks::completeEffectsSpecifier()'
2020-12-14 12:38:15 -08:00
Anthony Latsis
413352b77c Merge pull request #34620 from AnthonyLatsis/parse-misc
Parse: Only diagnose dollar-prefixed identifiers that are Swift declarations
2020-12-04 09:09:45 +03:00
Arnold Schwaighofer
8346bf7e90 Pre-specialization: This is an experimental feature
Only enable if explicitly required.
2020-11-20 09:13:16 -08:00
Anthony Latsis
47ce1529f0 Parse: Only diagnose dollar-prefixed identifiers that are Swift declarations 2020-11-19 20:30:53 +03:00
Robert Widmann
27d29262b0 [NFC] Traffic in Fingerprints 2020-11-18 12:20:14 -08:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Slava Pestov
0a9a6405ab Parse: Create a trailing where clause even if it was incomplete
Also, store the end location of the where clause explicitly, so that
we can recover it even if there are no requirements.

This fixes one of the failing tests when parser lookup is disabled in
swift-ide-test by ensuring that the source range of the function
extends to the end of the 'where' clause, even though the 'where'
clause has a code completion token in it.
2020-11-16 16:52:50 -05:00
Slava Pestov
1a6f86be71 Parse: Use InInactiveClauseEnvironment instead of looking at the Scope
We have two ways of knowing if we're inside of an inactive #if clause.
Refactor the only two places that called getScopeInfo().isInactiveConfigBlock()
to check InInactiveClauseEnvironment instead.

This removes the last remaining usage of Scope that's not related to
parse-time name lookup.
2020-11-16 15:35:55 -05:00
Alexis Laferrière
b72b0c30fa Merge pull request #34612 from xymus/dont-skip-nested-types
[Sema] Add flag to optimize building swiftmodule files preserving type info for LLDB
2020-11-12 19:16:21 -08:00
Alexis Laferrière
02c134372f [Sema] Add option to skip non-inlinable functions without types
This frontend flag can be used as an alternative to
-experimental-skip-non-inlinable-function-bodies that doesn’t skip
functions defining nested types. We want to keep these types as they are
used by LLDB. Other functions ares safe to skip parsing and
type-checking.

rdar://71130519
2020-11-12 14:28:09 -08:00
Robert Widmann
cdd54f1a51 Unconditionally Record Type Body Fingerprints
We used to disable these for extensions, which meant changes to
extensions would pessimistically cause every decl in the file to be
considered dirty.
2020-11-11 19:48:04 -08:00
Pavel Yaskevich
51bd8d93d6 Merge pull request #34510 from maustinstar/sr-11711
[SR-11711]  [Parse] Single-expression implicit returns within #if declarations
2020-11-05 21:14:44 -08:00
Doug Gregor
7f738778b8 [Concurrency] Parse 'async let' declarations.
Perform very basic semantic analysis for their well-formedness.
2020-11-04 17:31:31 -08:00
Minhyuk Kim
028594b740 [Parse] Move standalone_dollar_identifier diagnosis to Parser. Resolves SR-13092. 2020-11-04 21:26:54 +09:00
maustinstar
f6c9769bf0 Statement setter for last element 2020-11-03 22:20:23 -05:00
maustinstar
037edf3a8c [SR-11711] Refactor shared parser code for single-expression returns 2020-11-03 22:03:11 -05:00
maustinstar
37b17338e5 [SR-11711] Single-expression returns for #if declarations within functions 2020-11-03 12:47:39 -05:00
Ben Barham
eff5fc9225 [Parse] Remove unused declaration and diagnostic message 2020-10-29 09:18:39 +10:00
John McCall
223d7b9ea3 Fix isStartOfSwiftDecl to allow qualified types and generic arguments in attributes.
Fixes rdar://70158735
2020-10-22 17:28:15 -04:00
Doug Gregor
3b6fd4ece8 Merge pull request #34374 from DougGregor/se-0289-result-builders-rename
[SE-0289] Rename "function builders" to "result builders"
2020-10-21 09:08:46 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Kavon Farvardin
34d22105b8 implemented parsing and typechecking for @actorIndependent(unsafe)
[broken] first impl of @actorIndependent in the type checker.

[broken] fixed mistake in my parsing code wrt invalid source range

[broken] found another spot where ActorIndependent needs custom handling

[broken] incomplete set of @actorIndependent(unsafe) tests

updates to ActorIndependentUnsafe

[fixed] add FIXME plus simple handling of IndependentUnsafe context

finished @actorIndependent(unsafe) regression tests

added wip serialization / deserialization test

focus test to just one actor class

round-trip serialize/deserialize test for @actorIndependent

serialize -> deserialize -> serialize -> compare to original

most of doug's comments

addressed robert's comments

fix printing bug; add module printing to regression test

[nfc] update comment for ActorIsolation::IndependentUnsafe
2020-10-19 15:20:24 -07:00
Arnold Schwaighofer
fd3e3cfdb8 Merge pull request #32657 from aschwaighofer/wip_prespecialize_exported
Preliminary support for `_specialize(exported: true, ...)`
2020-10-13 07:57:51 -07:00
Slava Pestov
ac116cf56a Parse: Remove AlreadyHandledDecls set 2020-10-12 16:05:22 -04:00
Rintaro Ishizaki
1696f4d3ef Merge pull request #34256 from rintaro/ide-completion-rdar69890297
[CodeCompletion] Remove parser hacks regarding type body fingerprints
2020-10-12 09:25:51 -07:00
Arnold Schwaighofer
2a2cf91dcd Add support for marking a _specialize attribute as SPI
```
  @_specialize(exported: true, spi: SPIGroupName, where T == Int)
  public func myFunc() { }
```

The specialized entry point is only visible for modules that import
using `_spi(SPIGroupName) import ModuleDefiningMyFunc `.

rdar://64993425
2020-10-12 09:19:29 -07:00
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Rintaro Ishizaki
df94c4f464 [CodeCompletion] Remove parser hacks regarding type body fingerprints
Take type body fingerprints into account for inteface hash checking.
Since `SourceFile.getInterfacehash()` doesn't digest the type body
fingerprints in the file, enabling type body fingerprints regressed
fast-completion.

rdar://problem/69890297
2020-10-10 16:52:04 -07:00
Nathan Hawes
a91cede79b [Parse][CodeCompletion] Don't special case code completion when forming single-expression closures/function bodies (NFC)
Code completion used to avoid forming single expression closures/function
bodies when the single expression contained the code completion expression
because a contextual type mismatch could result in types not being applied
to the AST, giving no completions.

Completions that have been migrated to the new solver-based completion
mechanism don't need this behavior, however. Rather than trying to guess
whether the type of completion we're going to end up performing is one of
the ones that haven't been migrated to the solver yet when parsing, instead
just always form single-expression closures/function bodies (like we do for
regular compilation) and undo the transformation if and when we know we're
going to perform a completion kind we haven't migrated yet.

Once all completion kinds are migrated, the undo-ing code can be removed.
2020-10-09 16:02:13 -07:00
Alexis Laferrière
fa6f1b6b96 Merge pull request #33439 from xymus/expand-avail
[Sema] Define availability specification macros with a frontend flag
2020-10-08 09:25:32 -07:00