Commit Graph

3433 Commits

Author SHA1 Message Date
Alex Hoppen
237c70ea9c [CodeComplete] Offer completion suggestions for default argument values inside the macro declaration
We were not type checking the default argument initializer because `MacroDecl` is not an `AbstractFucntionDecl`. Add `MacroDecl` to the list of nodes we know how to get parameters from.

rdar://108163564
2023-05-01 13:48:18 -07:00
Alex Hoppen
1e505791e4 [CodeComplete] Offer completions for the names: argument of a macro declaration
When completing after `names:`, completion should offer the different ways you can specify the names, i.e. `arbitrary`, `named`, etc.

```
@freestanding(declaration, names: #^COMPLETE^#)
```

rdar://108535077
2023-04-28 17:20:45 -07:00
Alex Hoppen
053d215d55 Merge pull request #65427 from ahoppen/ahoppen/macro-attribute-completions
[CodeCompletion] Support completion for macro roles and the 'names:' argument label
2023-04-28 17:20:24 -07:00
Doug Gregor
593c2364e8 [Macros] "Subsume" the initializer when an accessor macros adds non-observers
When an accessor macro adds a non-observing accessor to a property, it
subsumes the initializer. We had previously modeled this as removing
the initializer, but doing so means that the initializer could not be
used for type inference and was lost in the AST.

Explicitly mark the initializer as "subsumed" here, and be more
careful when querying the initializer to distinguish between "the
initializer that was written" and "the initializer that will execute"
in more places. This distinction already existed at the
pattern-binding level, but not at the variable-declaration level.

This is the proper fix for the circular reference issue described in
rdar://108565923 (test case in the prior commit).
2023-04-28 09:50:00 -07:00
Alex Hoppen
6098a3ca2b [CodeCompletion] Support completion for macro roles and the 'names:' argument label
rdar://108163121
2023-04-27 21:48:06 -07:00
Alex Hoppen
becbdc8203 [Macros] Disallow declaration of codeItem macros 2023-04-27 21:48:06 -07:00
Ellie Shin
e9f847d414 Merge pull request #65336 from apple/es-private
Print package-name in .private.swiftinterface only for better abstraction
2023-04-27 20:07:12 -07:00
Doug Gregor
101f018bc0 [Macros] Adjust starting context for macro expansion mangling
Eliminate another circular reference through macro expansion mangling
by adjusting the starting declaration context to ensure that it is from
a suitable "outer" context.

Fixes rdar://108511666.
2023-04-27 10:16:02 -07:00
Doug Gregor
072536791a [Macros] Allow the back-ticked named(init) to be treated like named(init).
My recent change to parse initializer names in the macro role
introduced names now correctly distinguishes between the two forms, but
this breaks any existing macros written with the back-ticked form.
Treat the former as the latter to provide a grace period for such
macros.

Fixes rdar://108571834.
2023-04-26 13:20:00 -07:00
Doug Gregor
067e4ec501 Merge pull request #65410 from DougGregor/macro-cycle-break-part-deux 2023-04-25 06:37:24 -07:00
Doug Gregor
4f6ab4b9dc Anchor the macro-resolution request on the declaration to which the macro is attached
The macro-resolution request for an attached macro was expressed in
terms of the custom attribute and the declaration context enclosing the
attribute. While the declaration context is the correct one for
resolving the types and arguments of the custom attribute, the
declaration provides a better anchor for cases where the same
attribute applies to multiple declarations, e.g., with
member-attribute macros, leading to false cyclic references.
2023-04-24 21:17:55 -07:00
Doug Gregor
8202acb4ea Merge pull request #65393 from DougGregor/revert-semantic-attrs-cycle-break 2023-04-24 13:19:50 -07:00
nate-chandler
0c0ec72255 Merge pull request #65377 from nate-chandler/rdar108385761
[SILGen] Consuming a param implies it's eager-move.
2023-04-24 12:49:46 -07:00
Doug Gregor
35b784c432 [Macros] Eliminate overaggressive cycle breaking in getSemanticAttrs()
This cycle break means that some attributes introduced by
member-attribute macros aren't getting processed. I'm still reducing a
test case while I look for a fix, but for now I'm reverting this
change to address a regression for macros.

Fixes rdar://108456284.
2023-04-24 10:08:08 -07:00
Nate Chandler
956a963116 [SILGen] A noEagerMove consuming param is lexical. 2023-04-21 21:59:31 -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
Doug Gregor
ae4a5ded8f [Macros] Improve parsing, representation, and serialization of role attributes
Parse compound and special names in the macro role attributes
(`@freestanding` and `@attached`). This allows both compound names and
initializers, e.g., `init(coding:)`.

Fixes rdar://107967344.
2023-04-21 11:36:06 -07:00
Ellie Shin
b081404daa Print package-name in .private.swiftinterface only for better abstraction
Resolves rdar://107638447
2023-04-20 17:45:22 -07:00
Holly Borla
d7388346c5 Merge pull request #65313 from hborla/fix-macro-expansion-walking
[Macros] Fix type-checking local pattern bindings in macro-expanded closures.
2023-04-20 07:39:55 -07:00
Holly Borla
b958e43528 [Macros] Remove ModuleDecl::isInGeneratedBuffer.
This method was misleading. The majority of callers (all but one!) don't want
to unconditionally treat all locations in any macro expansion buffer the
same way, because the code also must handle nested macro expansions. There
is one part of SourceKit (and possibly others) that really do want to ignore
all macro expansions, but those can be handled within SourceKit / IDE code,
because I don't believe this utility is useful in the frontend.
2023-04-19 21:28:09 -07:00
Holly Borla
265c8a47d9 [Macros] Fix an issue where the constraint system skipped local declarations
inside closures while type checking a macro expansion.

PreCheckExpr, ConstraintGenerator, and other walkers do not walk into macro
expansions. However, the implementation of this macro walking behavior in
ASTWalker would skip any declaration that appears inside any macro expansion
buffer. This is incorrect for cases where the parent is in the same macro
expansion buffer, because the local declaration is not inside a new macro
expansion. This caused bogus errors when type checking expanded macro expressions
containing closures with local declarations, because pre-check and constraint
generation mistakenly skipped local pattern bindings.
2023-04-19 20:11:38 -07:00
Doug Gregor
9436899526 Merge pull request #65219 from DougGregor/reference-cycle-visible-name-lookup 2023-04-17 08:05:58 -04:00
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