Commit Graph

3461 Commits

Author SHA1 Message Date
Doug Gregor
ab682f1658 [Macros] Break reference cycles involving visible name lookup 2023-04-16 13:31:42 -04:00
Anthony Latsis
39c9ae2fc6 [NFC] ExistentialRequiresAnyRequest → HasSelfOrAssociatedTypeRequirementsRequest
The current name is misleading because it suggests that the request accounts
for language feature state, which it does not (and is not supposed to).
2023-04-13 07:50:06 +03:00
Konrad `ktoso` Malawski
b666fc672e [Executors] Remote distributed actors get "crash on enqueue" default executor (#64969) 2023-04-10 19:12:03 +09:00
Richard Wei
01e6fe2936 [Macros] Code item macros
Add support for declaring and expanding code item macros.  Add experimental feature flag `CodeItemMacros`.
2023-04-04 09:54:57 -07:00
Doug Gregor
7dca692c01 Merge pull request #64840 from DougGregor/macro-lookup-in-types 2023-04-02 07:23:58 -07:00
Doug Gregor
467f8f5e0f [Macros] Ensure that we can find peer macros for members of extensions.
When populating the name lookup tables for a nominal type, we were only
visiting declarations with peer macros within the nominal type
declaration itself. Also visit the members of extensions of the
nominal type.

Without this change, peer-macro-defined members of extensions are not
visible.
2023-03-31 23:05:18 -07:00
Richard Wei
eb8e984b97 [Macros] Private discriminators for outermost-private MacroExpansionDecl (#64813)
Add a private discriminator to the mangling of an outermost-private `MacroExpansionDecl` so that declaration macros in different files won't have colliding macro expansion buffer names.

rdar://107462515
2023-03-31 20:36:29 -07:00
Allan Shortlidge
69f769f3bd Merge pull request #64808 from tshortli/unavailable-opaque-type-optimization
IRGen: Opaque type descriptor and nested type fixes for `-unavailable-decl-optimization`
2023-03-31 13:58:20 -07:00
Allan Shortlidge
367dbd069d IRGen: Skip lowering unavailable opaque type descriptors.
Part of rdar://107425181
2023-03-31 09:36:42 -07:00
Doug Gregor
11a4ff5675 [Macros] Properly compute the innermost declaration context of a macro.
How did we go this long without having the right context? Who knows.
The fix is trivial and obvious.

The failure mode here is that we wouldn't get an appropriate generic
context in the result type of a macro, so we would complain about
generic parameters not meeting their own generic requirements.
2023-03-30 22:33:07 -07:00
Doug Gregor
583ca475bf [Macros] Share storage between linked MacroExpansion(Decl|Expr).
Sometimes we build a `MacroExpansionDecl` from a `MacroExpansionExpr`.
Sometimes we do it the other way. In both cases, we risk the two
copies of must-by-shared data (macro arguments, resolved macro
reference, etc.) getting out-of-sync.

Instead, share the storage between the two representations when we
create one from the other, so that they cannot get out-of-sync. This
allows us to eliminate the extremely-dodgy `cacheOutput` call earlier.
2023-03-30 00:10:21 -07:00
Doug Gregor
9292231e1f [Macros] Start recording expanded macro definitions and replacements
Handle a trivial macro defined in terms of another macro.
2023-03-29 16:32:28 -07:00
Ellie Shin
404895efc6 Merge pull request #64660 from apple/es-tests
Add a missing check for a corner case with package use site / internal decl site
2023-03-29 13:51:26 -07:00
Ellie Shin
1d7ef251d5 Merge pull request #64707 from apple/es-crash
Handle null package context when returning access scope
2023-03-29 09:50:54 -07:00
Ellie Shin
60b264be58 Handle null package context more gracefully
Resolves rdar://106819422
2023-03-28 19:10:32 -07:00
Ellie Shin
772e42e448 Add a missing check for a corner case with package use site / internal decl site
Update tests

Resolves rdar://106732804, rdar://104987455
2023-03-28 16:59:20 -07:00
swift-ci
8ac71b115c Merge pull request #64525 from beccadax/checkmate-ii
Re-merge #63668: Improve @objcImplementation member checking
2023-03-28 00:56:44 -07:00
Angela Laar
175e712b73 Merge pull request #64037 from angela-laar/fix-generic-type-paramters-implicit-some
[NameLookup] Collect implicit opaque GenericParams
2023-03-27 10:18:31 -07:00
Becca Royal-Gordon
43e48ef37f Better support destructors in objcImpl 2023-03-25 14:52:40 -07:00
Allan Shortlidge
adda1f559d IRGen: Weakly link symbols for unavailable declarations.
When computing linkage, the compiler would treat unavailable declarations as if
they were "always available" when they lack an `introduced:` version:

```
// Library
@available(macOS, unavailable)
public func foo() {
  // …
}

// Client
import Library

@available(macOS, unavailable)
func bar() {
  // Even though foo() and bar() are unavalable on macOS the compiler still
  // strongly links foo().
  foo()
}
```

This created an unnecessary dependency between libraries and their clients and
also can interfere with back deployment, since unavailable declarations may not
be present in a library on all OS versions. Developers could work around these
issues by conditionally compiling the code that references an unavailable
declaration, but they shouldn't have to given that unavailable code is meant to
be provably unreachable at runtime. Additionally, it could improve library code
size if we allowed the compiler to strip unavailable declarations from a binary
completely.

Resolves rdar://106673713
2023-03-23 08:57:15 -07:00
Konrad `ktoso` Malawski
345c221f56 [Concurrency] Distributed actor's unownedExecutor should be optional (#64499) 2023-03-22 08:40:41 +09:00
Konrad `ktoso` Malawski
e0877594da [Concurrency] Custom executors with move-only Job (#63569) 2023-03-18 14:02:43 +09:00
Ellie Shin
2bc92a6a59 Merge pull request #64408 from apple/es-inline
Allow @usableFromInline and @inlinable to package decls
2023-03-17 15:34:11 -07:00
Allan Shortlidge
fb03b4aa04 Sema: Relax availability checking for @MainActor.
The `@MainActor` global actor constraint on a declaration does not carry an
inherent ABI impact and therefore use of this constraint should not be limited
to OS versions where Swift concurrency is available.

Resolves rdar://105610970
2023-03-16 14:23:36 -07:00
Ellie Shin
ef321c9fd2 Allow @usableFromInline and @inlinable to package decls
Add tests for packgae inline
Add more package acl tests

Resolves rdar://104617133
2023-03-16 11:21:11 -07:00
Angela Laar
3a20ff0826 [NameLookup] Rename opaque type collector function 2023-03-15 18:07:26 -07:00
Saleem Abdulrasool
b49f2ef5cf Merge pull request #64384 from apple/revert-64353-weak-link-unavailable-symbols
Revert "IRGen: Weakly link symbols for unavailable declarations"
2023-03-15 13:08:59 -07:00
Ellie Shin
584919e86f Merge pull request #64373 from apple/es-tests
Update package name input and access scope check
2023-03-15 10:45:04 -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
Saleem Abdulrasool
79c6d4b9fa Revert "IRGen: Weakly link symbols for unavailable declarations" 2023-03-15 07:38:37 -07:00
Allan Shortlidge
084ef39981 IRGen: Strongly link unavailable declarations with introduced: versions.
If a declaration is unavailable but also has an `introduced:` availability
version, treat that as an indication that it is considered ABI and should be
linked as if it were available.

Part of rdar://106673713
2023-03-14 18:06:04 -07:00
Allan Shortlidge
ab0f7c19f5 IRGen: Weakly link symbols for unavailable declarations.
When computing linkage, the compiler would treat unavailable declarations as if
they were "always available" when they lack an `introduced:` version:

```
// Library
@available(macOS, unavailable)
public func foo() {
  // …
}

// Client
import Library

@available(macOS, unavailable)
func bar() {
  // Even though foo() and bar() are unavalable on macOS the compiler still
  // strongly links foo().
  foo()
}
```

This created an unnecessary dependency between libraries and their clients and
also can interfere with back deployment, since unavailable declarations may not
be present in a library on all OS versions. Developers could work around these
issues by conditionally compiling the code that references an unavailable
declaration, but they shouldn't have to given that unavailable code is meant to
be provably unreachable at runtime. Additionally, it could improve library code
size if we allowed the compiler to strip unavailable declarations from a binary
completely.

Resolves rdar://106673713
2023-03-14 18:06:04 -07:00
Ellie Shin
0fe0d6d221 Allow Swift as a package name
Update AccessScope::isChildOf
Add more tests for package access level
Resolves rdar://106728606
2023-03-14 17:17:14 -07:00
Ellie Shin
1924376658 Merge pull request #64230 from apple/es-dbg
[AccessScope] Treat PackageUnit as enclosing scope of ModuleDecl
2023-03-13 17:00:45 -07:00
Doug Gregor
ce6dec5d70 Merge pull request #64288 from apple/revert-63668-checkmate 2023-03-11 10:47:50 -08:00
Doug Gregor
b829e86027 [Move-only-types] Break cycle with OpaqueReadOwnershipRequest and @objc selector
The interface-type computation in OpaqueReadOwnershipRequest is causing
a cycle with `@objc` names for the getter/setter of a property. Break
the cycle by relying on the fact that `@objc` names can only be
directly on the getter/setter, not on some other accessor, so we can
go through `getAccessor` for both cases.

I am not convinced that we won't have additional issues related to the
interface-type computation in OpaqueReadOwnershipRequest, but I
couldn't see any obvious ones in the code base either.

Fixes rdar://106575164.
2023-03-10 22:52:07 -08:00
Ellie Shin
08485d4dd6 formatting 2023-03-10 16:43:38 -08:00
Ellie Shin
671533fed2 Associate PackageUnit with ModuleDecl
* Weakly reference ModuleDecl from PackageUnit
* Add PackageUnit decl context getter and use it for a package AccessScope
* Return module decl referenced by PackageUnit in getModuleScopeContext and getParentModule
* Handle package acl in access scope checkers
* Remove AccessLimitKind
* Fix tests
Resolves rdar://104987295, rdar://105187216, rdar://104723918
2023-03-10 16:19:32 -08:00
Doug Gregor
ef7f707fcc Revert "Improve @objcImplementation member checking" 2023-03-10 12:00:33 -08:00
Doug Gregor
3c779e7405 [Macros] Ensure that name lookup can find uniquely-generated macro names
While a Swift program cannot directly utter one of the unique names
produced by the macro expansion context outside of the macro itself,
utilities such as type reconstruction require the ability to look up
these names. Note that various kinds of macros can introduce unique
names, and update the name lookup facilities for macro-generated names
to account for them.

Fixes rdar://106053984.
2023-03-07 12:30:14 -08:00
John McCall
db4b16e3dd [WIP] Always use PackTypes as the substitutions for type parameter packs
This simplifies the representation and allows clients to handle fewer
cases.  It also removes an ambiguity in the representation which could
lead us to have two canonical types for the same type.

This is definitely not working yet, but I'm not making progress on
it quickly enough to unblock what we need to unblock; it'll have to
be fixed in parallel.
2023-03-06 17:08:35 -08:00
Ben Barham
edb980eb55 Merge pull request #64095 from bnbarham/do-not-change-refactoring
[Macros] Do not edit macro buffer or position when refactoring
2023-03-06 08:43:30 -08:00
Xi Ge
ffc998a0e7 Merge pull request #63668 from beccadax/checkmate
Improve @objcImplementation member checking
2023-03-06 08:21:59 -08: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
Holly Borla
9b722b9bd2 Merge pull request #64097 from hborla/macro-expansion-validation
[Macros] Diagnose macro expansions containing invalid declarations.
2023-03-05 13:22:38 -08:00
Richard Wei
31d73b81a2 Merge pull request #64071 from rxwei/macro-aux-decl
Always use `Decl::visitAuxiliaryDecls` to visit decls produced by macros, including peer macros and declaration macros. Use name-driven expansion for peer macros. Remove `MacroExpansionDecl::getRewritten()`.

Also make `ExpandMacroExpansionDeclRequest` cache the buffer ID (similar to other macros) instead of an array of decls.
2023-03-05 03:19:58 -08:00
Richard Wei
98c2a837d2 [Macros] Always visit macro-produced decls as auxiliary decls
Always use `Decl::visitAuxiliaryDecls` to visit decls produced by macros, including peer macros and declaration macros. Use name-driven expansion for peer macros. Remove `MacroExpansionDecl::getRewritten()`.

Also make `ExpandMacroExpansionDeclRequest` cache the buffer ID (similar to other macros) instead of an array of decls.
2023-03-04 23:48:21 -08:00
Holly Borla
e4172055c3 [Macros] Allow any decl names in macro expansions when the macro covers arbitrary
names.
2023-03-04 15:31:24 -08:00
Richard Wei
e140d4a6ef [Macro] Fix macro role printing for declaration macros
A declaration macro attribute is currently printed as `@freestanding(freestanding)`, but should be `@freestanding(declaration)`.
2023-03-04 00:19:36 -08:00
Ben Barham
80d27128d8 [Macros] Do not edit macro buffer or position when refactoring
Rather than editing the macro buffer in refactoring, add appropriate
padding and braces when creating the macro.

Don't edit the insertion location - we should update this in a later PR
as well.
2023-03-03 19:48:06 -08:00