Commit Graph

1278 Commits

Author SHA1 Message Date
Meghana Gupta
b6326f5f24 Add initial support for _resultDependsOn
These attributes are used to establish lifetime dependence between
argument and the result.

Add them under NonEscapableTypes experimental feature
2023-12-06 16:38:38 -08:00
Kavon Farvardin
81ea9981c8 Merge pull request #69842 from kavon/ncgenerics-stdlib-building
[NCGenerics] more work towards getting the stdlib building
2023-11-29 17:31:45 -08:00
Kavon Farvardin
2cd298926f [NCGenerics] fix existential conformances
I was not expanding default requirements in
AbstractGenericSignatureRequest or ExistentialLayout.

Also fixes printing of composition types.
2023-11-15 15:43:11 -08:00
Slava Pestov
fa3eeddf6e ASTDumper: Make the SubstitutionMap dump easier to read
Don't quote generic parameter names because then the tau gets
escaped in canonical types, and expand out the replacement
type with printRec() instead of stringifying it.
2023-11-14 15:46:58 -05:00
Slava Pestov
4ec627effc Merge pull request #69551 from DougGregor/thrown-error-try-opt-bang
Record the thrown error type for try? and try! in the AST
2023-10-31 21:38:32 -04:00
Doug Gregor
c90c055fb6 Record the thrown error type for try? and try! in the AST
SILGen wants this so it knows what kind of error its going to end up
with.
2023-10-31 14:18:31 -07:00
Kavon Farvardin
29acda5136 Merge pull request #69406 from kavon/noncopyable-generics-pt2
[NoncopyableGenerics] handle `~Copyable` in `where`, `some`, and compositions.
2023-10-28 22:36:22 -07:00
Slava Pestov
ad5697778e Merge pull request #69430 from slavapestov/silgen-typed-throws-wip
Preliminary SILGen support for address-only typed throws
2023-10-27 21:00:51 -04:00
Slava Pestov
736d0da1ca ASTDumper: Better dumping of the thrown error type of a function type 2023-10-27 17:37:43 -04:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Doug Gregor
5ad39c84e0 [Typed throws] Record thrown error types and conversions in the AST
For any operation that can throw an error, such as calls, property
accesses, and non-exhaustive do..catch statements, record the thrown
error type along with the conversion from that thrown error to the
error type expected in context, as appropriate. This will prevent
later stages from having to re-compute the conversion sequences.
2023-10-24 12:40:22 -07:00
Kavon Farvardin
66712ce6e0 [Sema] introduce InverseType
This type will become the corresponding type that is resolved for an
`InverseTypeRepr`. This kind of type is not expected to appear past type
 checking (currently, not even past requirement lowering!).
2023-10-23 10:37:22 -07:00
Slava Pestov
c90b8e6e95 ASTDumper: Improve conformance dumping and use forEachAssociatedConformance() 2023-10-11 15:04:09 -04:00
Slava Pestov
44838d4912 ASTDumper: Fix a few minor issues with TypeAliasType 2023-10-11 15:04:09 -04:00
Doug Gregor
51eed19d4b [Typed throws] Type system support for typed throws.
Add the thrown type into the AST representation of function types,
mapping from function type representations and declarations into the
appropriate thrown type. Add tests for serialization, printing, and
basic equivalence of function types that have thrown errors.
2023-09-29 10:51:53 -07:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Kavon Farvardin
a69bcf8a61 Merge pull request #67930 from kavon/copyable-requirement
Copyable as a Requirement Against the Machine
2023-09-21 11:49:23 -07:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Kavon Farvardin
c01360d02e [Sema] reimplement ~C as an general inverse constraint 2023-09-20 09:34:06 -07:00
Holly Borla
549b45250f [Concurrency] Remove ClosureActorIsolation. 2023-09-16 12:22:38 -07:00
Holly Borla
4b23564711 [Concurrency] Rename AbstractClosureExpr::getActorIsolation to
getClosureActorIsolation.

This is preparation for changing AbstractClosureExpr to store
ActorIsolation instead of ClosureActorIsolation, and convert to
ClosureActorIsolation when needed to allow incrementally updating
callers. This change is NFC.
2023-09-16 12:20:53 -07:00
Anthony Latsis
b6be6da277 ASTGen: Translate associated type declarations
Plus tweak `DefaultDefinitionTypeRequest` caching to support querying the
cached type when dumping. This fixes a crash where type computation is
triggered in the dumper before import resolution in `-dump-parse` mode.
2023-09-12 20:37:50 +03:00
Becca Royal-Gordon
8770c7f826 Rework ASTDumper (#68438)
This PR refactors the ASTDumper to make it more structured, less mistake-prone, and more amenable to future changes. For example:

```cpp
  // Before:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E) {
    printCommon(E, "unresolved_dot_expr")
      << " field '" << E->getName() << "'";
    PrintWithColorRAII(OS, ExprModifierColor)
      << " function_ref=" << getFunctionRefKindStr(E->getFunctionRefKind());
    if (E->getBase()) {
      OS << '\n';
      printRec(E->getBase());
    }
    PrintWithColorRAII(OS, ParenthesisColor) << ')';
  }

  // After:
  void visitUnresolvedDotExpr(UnresolvedDotExpr *E, StringRef label) {
    printCommon(E, "unresolved_dot_expr", label);

    printFieldQuoted(E->getName(), "field");
    printField(E->getFunctionRefKind(), "function_ref", ExprModifierColor);

    if (E->getBase()) {
      printRec(E->getBase());
    }

    printFoot();
  }
```

* Values are printed through calls to base class methods, rather than direct access to the underlying `raw_ostream`.
    * These methods tend to reduce the chances of bugs like missing/extra spaces or newlines, too much/too little indentation, etc.
    * More values are quoted, and unprintable/non-ASCII characters in quoted values are escaped before printing.
* Infrastructure to label child nodes now exists.
    * Some weird breaks from the normal "style", like `PatternBindingDecl`'s original and processed initializers, have been brought into line.
* Some types that previously used ad-hoc dumping functions, like conformances and substitution maps, are now structured similarly to the dumper classes.
* I've fixed the odd dumping bug along the way. For example, distributed actors were only marked `actor`, not `distributed actor`.

This PR doesn't change the overall style of AST dumps; they're still pseudo-S-expressions. But the logic that implements this style is now isolated into a relatively small base class, making it feasible to introduce e.g. JSON dumping in the future.
2023-09-11 23:56:38 -07:00
Holly Borla
e23e4c32f5 Merge pull request #68414 from hborla/nonisolated-init-hole
[Concurrency] Don't allow nonisolated initializers to introduce data races via superclass property observers.
2023-09-09 09:55:24 -07:00
Holly Borla
a6d078b820 [Concurrency] Use the 'nonisolated' terminology instead of 'independent'.
This commit is NFC; it's mostly renames.
2023-09-08 13:28:55 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
Hamish Knight
6ee44f09b4 Introduce then statements
These allow multi-statement `if`/`switch` expression
branches that can produce a value at the end by
saying `then <expr>`. This is gated behind
`-enable-experimental-feature ThenStatements`
pending evolution discussion.
2023-09-01 14:32:14 +01:00
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
Pavel Yaskevich
b21e8426a0 [AST] NFC: Remove @runtimeMetadata related code 2023-08-15 12:16:40 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
jturcotti
aa9f1a3584 add an experimental feature DeferSendableChecking to defer the sendable checking of some sites. For now, only diagnostics corresponding to non-sendable arguments passed to calls with unsatisfied isolation are deferred. A SIL pass SendNonSendable is added to emit the deferred diagnostics, and ApplyExpr is appropriately enriched to make that deferral possible. 2023-07-03 09:52:11 -07:00
Keith Smiley
e9ff334778 Fix missing indexing data with overloaded type (#65729)
When you have a type that's ambiguous because it's defined in 2 imported
modules, but you don't have to disambiguate by using the module name,
previously no index references were produced. Now most are for the
common case, but notably nested type constructors and generics still
aren't emitted, partially because of https://github.com/apple/swift/issues/65726

Fixes: https://github.com/apple/swift/issues/64598
2023-06-23 09:58:17 -07:00
Pavel Yaskevich
bf5612c56b [AST] ASTDumper: Print overload choices of non-operator OverloadedDeclRefExprs 2023-06-13 21:59:02 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Michael Gottesman
fd25cf379a Rename MoveExpr -> ConsumeExpr to reflect the final name.
NFC.
2023-05-17 22:42:42 -07:00
Michael Gottesman
e6f1691122 [copy-operator] Add support for the copy operator in preparation for making consuming and borrowing no implicit copy.
Some notes:

1. I implemented this as a contextual keyword that can only apply directly to
lvalues. This ensures that we can still call functions called copy, define
variables named copy, etc. I added tests for both the c++ and swift-syntax based
parsers to validate this. So there shouldn't be any source breaks.

2. I did a little bit of type checker work to ensure that we do not treat
copy_expr's result as an lvalue. Otherwise, one could call mutating functions on
it or assign to it, which we do not want since the result of copy_value is

3. As expected, by creating a specific expr, I was able to have much greater
control of the SILGen codegen and thus eliminate extraneous copies and other
weirdness than if we used a function and had to go through SILGenApply.

rdar://101862423
2023-05-17 22:42:42 -07:00
Kavon Farvardin
3e4bc82aa8 rename _forget to discard; deprecate _forget
SE-390 concluded with choosing the keyword discard rather than forget for
the statement that disables the deinit of a noncopyable type. This commit
adds parsing support for `discard self` and adds a deprecation warning for
`_forget self`.

rdar://108859077
2023-05-08 21:42:19 -07:00
Nate Chandler
abba5ef857 [SILGen] Consuming a param implies it's eager-move
If a parameter is marked consuming and its type is Copyable, that
parameter has eager-move semantics.  Apply that attribute to the
SILFunctionArgument corresponding to the parameter.

rdar://108385761
2023-04-21 21:59:31 -07:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Hamish Knight
37b0a6074f [Sema] Introduce ExprPatternMatchRequest
This replaces `synthesizeTildeEqualsOperatorApplication`,
and synthesizes the match expression and var
on-demand.

Additionally, it pushes the lookup logic into
pre-checking.
2023-03-07 15:16:35 +00:00
Richard Wei
833338f9ce [Macros] Top-level freestanding macros (#63553)
Allow freestanding macros to be used at top-level.
- Parse top-level `#…` as `MacroExpansionDecl` when we are not in scripting mode.
- Add macro expansion decls to the source lookup cache with name-driven lazy expansion. Not supporting arbitrary name yet.
- Experimental support for script mode and brace-level declaration macro expansions: When type-checking a `MacroExpansionExpr`, assign it a substitute `MacroExpansionDecl` if the macro reference resolves to a declaration macro. This doesn’t work quite fully yet and will be enabled in a future fix.
2023-03-06 07:15:20 -08:00
Ellie Shin
7d23db3646 Create PackageUnit class, and Package entries to DeclContext / ASTHierarchy
Previously enum AccessLimitKind was
added to distinguish access scopes b/t package and public while keeping
DeclContext null but it proved to be too limiting. This PR creates package specific entries for DeclContext and
ASTHierarchy. It create a new class PackageUnit that can be set as the parent DeclContext of ModuleDecl. This PR
contains addition of such entries but not the use of them; the actual use of them will be in the upcoming PRs.

Resolves rdar://106155600
2023-03-02 13:20:51 -08:00
Holly Borla
b78b6b9a77 Merge pull request #63991 from hborla/materialize-pack-from-tuple
[ConstraintSystem] Implement type checking for converting a tuple to a pack using the `.element` syntax.
2023-03-01 16:19:33 -08:00
Holly Borla
509188630b [ConstraintSystem] Implement type checking for converting a tuple to a
pack using the `.element` syntax.
2023-02-28 22:56:59 -08:00
Kavon Farvardin
f41ed5926b implement the forget statement
Currently, this is staged in as `_forget`,
as part of SE-390. It can only be used on
`self` for a move-only type within a consuming
method or accessor. There are other rules, see
Sema for the details.

A `forget self` really just consumes self and
performs memberwise destruction of its data.
Thus, the current expansion of this statement
just reuses what we inject into the end of a
deinit.

Parsing of `forget` is "contextual".
By contextual I mean that we do lookahead to
the next token and see if it's identifier-like.
If so, then we parse it as the `forget` statement.
Otherwise, we parse it as though "forget" is an
identifier as part of some expression.

This way, we won't introduce a source break for
people who wrote code that calls a forget
function.

This should make it seamless to change it from
`_forget` to `forget` in the future.

resolves rdar://105795731
2023-02-28 21:15:17 -08:00
Joe Groff
655e9e681d Add ParamSpecifier cases for Borrowing and Consuming.
And do a first pass of auditing existing uses of the parameter specifiers to
make sure that we look at the ValueOwnership mapping in most cases instead of
individual modifiers.
2023-02-28 09:16:44 -08:00
Joe Groff
1311df6544 AST: Combine various ownership TypeReprs into one OwnershipTypeRepr.
This lets us consolidate code paths that mostly run in parallel over the
existing InOutTypeRepr/SharedTypeRepr/OwnedTypeRepr family of types. This
patch by itself is NFC but makes it easier to introduce new spellings,
particularly the newly-official `borrowing` and `consuming` modifiers
that were approved in SE-0377.
2023-02-28 09:15:43 -08:00
Slava Pestov
e0c341d0ac AST: Rename PackReferenceTypeRepr => PackElementTypeRepr 2023-02-15 22:37:07 -05:00
Richard Wei
81943b2b11 [Macros] Clean up MacroExpansionDecl (#63486)
- Remove the `Rewritten` field and `setRewritten()`. Make `getRewritten()` invoke the request.
- Rename fields `Macro` and `MacroLoc` to `MacroName` and `MacroNameLoc` respectively as well as their getters to match those in `MacroExpansionExpr`.
2023-02-07 14:57:02 +08:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00