Commit Graph

2390 Commits

Author SHA1 Message Date
Slava Pestov
8fcd74e6b3 AST: GenericParamList::clone() doesn't need to preserve source locations 2020-07-28 02:07:16 -04:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00
Robert Widmann
d8092f4aa9 [NFC] Mark PatternBindingInitializer::getImplicitSelfDecl const
Even though it is not physically const because of the lazy initialization, it is logically const and deserves to be marked as such.
2020-07-23 20:43:27 -07:00
Xi Ge
74edd073e0 AST: consider extension and extended type are from the same module if valid alternative module names are equal
Framework authors may move a type along with its extensions from
a high-level framework to a low-level one. We should compare
alternative module names for them to check if they should be considered from
the same module to preserve ABI stability.

rdar://65889766
2020-07-22 12:54:31 -07:00
Suyash Srijan
58a84ea4c1 [NFC] Cleanup some code to use 'swift::getParameterList(ValueDecl)' to fetch parameter lists (#32979) 2020-07-20 19:50:37 +01:00
Michael Gottesman
d2f986739c Merge pull request #32940 from gottesmm/pr-8414ddbc369ed5bb8c0622162de920b962426cf1
[ast] Rename VarPattern -> BindingPattern.
2020-07-18 20:47:21 -07:00
Holly Borla
61cb9a5f4f Merge pull request #32866 from hborla/property-wrapper-autoclosure
[Property Wrappers] Use autoclosure information from CSApply to compute `VarDecl::getPropertyWrapperInitValueInterfaceType`
2020-07-17 09:16:05 -07:00
Michael Gottesman
092edd6621 [ast] Rename VarPattern -> BindingPattern.
VarPattern is today used to implement both 'let' and 'var' pattern bindings, so
today is already misleading. The reason why the name Var was chosen was done b/c
it is meant to represent a pattern that performs 'variable binding'. Given that
I am going to add a new 'inout' pattern binding to this, it makes sense to
give it now a better fitting name before I make things more confusing.
2020-07-16 18:56:01 -07:00
Holly Borla
a6c33a9611 [Property Wrappers] Use autoclosure information from CSApply to compute
`VarDecl::getPropertyWrapperInitValueInterfaceType`.
2020-07-13 17:22:29 -07:00
Brent Royal-Gordon
acc01aea03 [NFC] Add MagicIdentifierKinds.def
Extracts the list of magic identifier literal kinds into a separate file and updates a lot of code to use macro metaprogramming instead of naming half a dozen cases manually. This is a complicated change, but it should be NFC.
2020-07-13 14:05:13 -07:00
Xi Ge
50142f896b AST: address code review comments on isEquivalentToExtendedContext() 2020-07-01 16:22:15 -07:00
Slava Pestov
faa06bfd87 Merge pull request #32581 from slavapestov/cached-emitted-members-request
Deterministically order class members for emission
2020-06-30 00:47:33 -04:00
Slava Pestov
89b2f27b4d AST: Mark implicit destructor as synthesized to fix non-deterministic function order
We can synthesize the default init() and the implicit deinit in a class in
any order, depending on the order of primary files and how that class was
used in other primary files.

Make sure that EmittedMembersRequest puts the destructor at the end with
all other synthesized members, so that we produce the same object file in
any case.
2020-06-29 22:17:56 -04:00
Slava Pestov
c1b0c93188 Sema: Use request evaluator caching for EmittedMembersRequest 2020-06-29 22:17:56 -04:00
Alexis Laferrière
63d9acda3e [Sema] Report public use of local SPIs by the exportability checker
This change improves slightly the quality of the diagnostics and detects
the use of local SPI types on public property with a default value.
2020-06-29 11:18:04 -07:00
Rintaro Ishizaki
9044aa0376 [AST] ParamDecl::isNonEphemeral() not to evaluate InterfaceTypeRequest
'-dump-parse' for the following code used to hit an assertion failure:

  struct MyStruct {}
  _ = { (val: MyStruct) in }

Because 'isNonEphemeral()' on 'val' parameter unintentionally causes
'InterfaceTypeRequest::evaluate()'. Since 'isNonEphemeral()' inference
based on the interface type is not possible after type checking, return
'false' unless 'hasInterfaceType()'

Also:
  * Dump parameter list on 'EnumElementDecl' as well
  * Adjust the position of 'range=...' in parameter list dumping
2020-06-25 15:01:27 -07:00
Xi Ge
e45fa71ee6 AST: isEquivalentToExtendedContext() should consider use patterns of @_originallyDefinedIn
When a nominal type and its extensions coexist in the same module, mangling may
use the nominal type as the context for extension members. We should preserve this
mechanism for types marked as @_originallyDefinedIn to maintain ABI stability.

rdar://64538537
2020-06-24 12:27:53 -07:00
Robert Widmann
b9427b0a88 [NFC] Strip RequirementRepr of its TypeLocs
Now that the previous commits have removed the data dependencies on TypeLoc, remove the TypeLoc and replace it with a TypeRepr. This makes RequirementRepr a purely syntactic object once again.
2020-06-11 16:18:24 -07:00
Robert Widmann
fb8fdd9644 Replace resolveCustomAttrType with a Request 2020-06-10 19:31:41 -07:00
Robert Widmann
e1015761fb [NFC] Reduce usage of TypedPattern::getTypeLoc 2020-06-10 16:51:10 -07:00
Arnold Schwaighofer
28fba4f5e6 Merge pull request #32195 from aschwaighofer/dyn_repl_objc_method_generic_class
Mark non-foreign entry points of `@objc dynamic` methods in generic c…
2020-06-10 10:31:18 -07:00
Arnold Schwaighofer
825a2a259b Mark non-foreign entry points of @objc dynamic methods in generic classes dynamically_replaceable
```
class Generic<T> {
  @objc dynamic func method() {}
}

extension Generic {
  @_dynamicReplacement(for:method())
  func replacement() {}
}
```

The standard mechanism of using Objective-C categories for dynamically
replacing @objc methods in generic classes does not work.

Instead we mark the native entry point as replaceable.

Because this affects all @objc methods in generic classes (whether there
is a replacement or not) by making the native entry point
`[dynamically_replaceable]` (regardless of optimization mode) we guard this by
the -enable-implicit-dynamic flag because we are late in the release cycle.

* Replace isNativeDynamic and isObjcDynamic by calls to shouldUse*Dispatch and
  shouldUse*Replacement
  This disambiguates between which dispatch method we should use at call
  sites and how these methods should  implement dynamic function
  replacement.

* Don't emit the method entry for @_dynamicReplacement(for:) of generic class
  methods
  There is not way to call this entry point since we can't generate an
  objective-c category for generic classes.

rdar://63679357
2020-06-09 09:23:29 -07:00
AG
11ef9bd92f Merge pull request #32217 from bitjammer/acgarland/rdar-63120829-show-in-interface-not-underscored
[SymbolGraph] Don't consider @show_in_interface for underscored names
2020-06-08 12:21:56 -07:00
Ashley Garland
c647c11bb5 [SymbolGraph] Don't consider @show_in_interface for underscored names
The fact that a declaration has `@_show_in_interface` shouldn't be
used to decide whether something has underscored naming, which
is just one specific kind of check regarding naming only.

Move the check for this attribute out one level.

rdar://63120829
2020-06-05 16:52:35 -07:00
Hamish Knight
f57299a587 Formalize some SourceFile parsing outputs
Currently when parsing a SourceFile, the parser
gets handed pointers so that it can write the
interface hash and collected tokens directly into
the file. It can also call `setSyntaxRoot` at
the end of parsing to set the syntax tree.

In preparation for the removal of
`performParseOnly`, this commit formalizes these
values as outputs of `ParseSourceFileRequest`,
ensuring that the file gets parsed when the
interface hash, collected tokens, or syntax tree
is queried.
2020-06-03 11:03:56 -07:00
Anthony Latsis
267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Slava Pestov
71b2c5003f Merge pull request #31778 from slavapestov/cloned-parameter-list-source-loc
AST: Don't set source location on cloned parameter lists
2020-06-02 00:43:46 -04:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Slava Pestov
68ba9cf96c Merge pull request #32034 from slavapestov/optimize-remove-shadowed-decls
AST: Optimize removeShadowedDecls()
2020-05-29 15:39:04 -04:00
Slava Pestov
6ca148d65e AST: Optimize removeShadowedDecls()
Previously, whenever name lookup returned two declarations with the same
name, we would compute the canonical type of each one as part of the
shadowing check.

The canonical type calculation is rather expensive for GenericFunctionTypes
since it requires constructing a GenericSignatureBuilder to canonicalize
type parameters that appear in the function's signature.

Instead, let's first shard all declarations that have the same name by
their generic signature. If two declarations have the same signature, only
then do we proceed to compute their canonical type.

Since computing a canonical GenericSignature is cheaper than computing a
canonical GenericFunctionType, this should speed up name lookup of
heavily-overloaded names, such as operators.

Fixes <rdar://problem/56800097>.
2020-05-26 23:49:14 -04:00
Slava Pestov
88d8d9fabe AST: Don't set source location on cloned parameter lists 2020-05-26 22:59:08 -04:00
Arnold Schwaighofer
532f0cb865 Type substitution: When substituting SILFunctionTypes we substitute unbound Objective-C generic for bound ones
IRGen does so. So don't assert on this case.

rdar://63509292
2020-05-26 13:26:08 -07:00
Doug Gregor
8e0ec601db Merge pull request #32005 from DougGregor/function-builder-infer
[Function builders] Infer function builder from a protocol requirement.
2020-05-26 10:59:42 -07:00
Doug Gregor
bf7eea08da [Function builders] Infer function builder from a protocol requirement.
Allow a protocol requirement for a function or property to declare
a function builder. A witness to such a protocol requirement will
infer that function builder when all of the following are two:
* The witness does not explicitly adopt a function builder
* The witness is declared within the same context that conforms to the
protocol requirement (e.g., same extension or primary type declaration)
* The witness's body does not contain a "return" statement (since those
disable the function builder transform).
2020-05-24 23:18:18 -07:00
Slava Pestov
6303852c46 AST: Don't clone TypeReprs in ParamDecl::cloneWithoutType() 2020-05-23 02:23:43 -04:00
Slava Pestov
ae77d22893 AST: Don't clone TypeReprs in GenericParamList::clone() 2020-05-23 02:23:43 -04:00
Holly Borla
a97bbf9eee Merge pull request #31949 from hborla/property-wrapper-default-init
[Property Wrappers] Fix handling of properties that are default initialized via property wrapper
2020-05-21 18:01:42 -07:00
Holly Borla
1c8ad0024a [Property Wrappers] Fix ParamDecl::getDefaultValueStringRepresentation
to return a string representing default initialization when a
property is default initialized via property wrapper.
2020-05-21 14:21:50 -07:00
Suyash Srijan
d53cd535ba [Typechecker] Emit a specialised diagnostic for redeclaration errors when the declaration is synthesised (#31915)
* [Typechecker] Emit a specialized diagnostic for redeclaration errors when the declaration is synthesized

* [Test] Update existing tests

* [Typechecker] Diagnose the original wrapped property instead of the nearest non-implicit decl context

* [Test] Update existing tests

* [Typechecker] Do not diagnose redeclarations when both declarations are implicit

* [Test] Update a AutoDiff test
2020-05-21 17:37:55 +01:00
Michael Forster
e69abeba53 Classify C++ structs as loadable or address-only (#31707)
* Classify C++ structs as loadable or address-only

C++ structs are only loadable if they are trivially copyable.

Resolves SR-12472.
2020-05-13 17:16:47 +02:00
Dan Zheng
a5bdbd9774 [AutoDiff] Fix derivative function configurations for accessors. (#31669)
For accessors: make `AbstractFunctionDecl::getDerivativeFunctionConfigurations`
resolve configurations from parent storage declaration `@differentiable`
attributes.

Fixes "no `@differentiable` attribute" non-differentiability error for accessors
whose parent storage declaration `@differentiable` attributes have not been
type-checked (e.g. because the storage declarations are in another file).

Add protocol requirement and class member storage declaration tests.

Resolves TF-1234.
2020-05-09 07:29:15 -07:00
Alexis Laferrière
f46542f0e4 Merge pull request #31591 from xymus/spi-equatable
Allow SPI access within the same module in checkAccess
2020-05-08 11:29:12 -07:00
Saleem Abdulrasool
09975d1253 sprinkle llvm_unreachable for covered switches (NFC)
Annotate the covered switches with `llvm_unreachable` to avoid the MSVC
warning which does not recognise the covered switches.  This allows us
to avoid a spew of warnings.
2020-05-07 11:05:35 -07:00
Alexis Laferrière
4fcebd1256 Allow SPI access within the same module in checkAccess
rdar://problem/61043406
rdar://problem/61987739
2020-05-06 11:19:44 -07:00
Dan Zheng
738ef730e8 [AutoDiff] Fix @differentiable attribute derivative configurations. (#31524)
In `AbstractFunctionDecl::getDerivativeFunctionConfigurations`, type-check
`@differentiable` attributes. This is important to populate derivative
configurations for original functions in other files.

Resolves TF-1271.

Exposes TF-1272: fix derivative configurations for cross-file `@derivative`
attributes. This is a more difficult issue.
2020-05-04 00:44:48 -07:00
Varun Gandhi
65577940d0 [NFC] Get rid of -Wrange-loop-analysis warnings. (#31324) 2020-04-27 09:47:52 -07:00
Joe Groff
b4c7a7e85d Merge pull request #31224 from AnthonyLatsis/rename-getfullname-2
AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl
2020-04-24 12:51:28 -07:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Slava Pestov
ec465e1616 Merge pull request #31212 from slavapestov/direct-to-storage-cleanup
Sema: Merge shouldAccessStorageDirectly() into isDirectToStorageAccess()
2020-04-22 22:03:55 -04:00