Commit Graph

3461 Commits

Author SHA1 Message Date
Slava Pestov
2e484a1c5c Merge pull request #66494 from slavapestov/storage-decl-is-resilient-latent-bug
AST: Spot fix for AbstractStorageDecl::isResilient()
2023-06-09 16:58:48 -04:00
Doug Gregor
759f52066e [Macros] Only freestanding expression macros can have a non-Void result type
Fixes rdar://108871352.
2023-06-09 10:40:28 -07:00
Rintaro Ishizaki
c3d1304345 [SourceKit] Add request to expand macros syntactically
Expand macros in the specified source file syntactically (without any
module imports, nor typechecking).

Request would look like:
```
{
  key.compilerargs: [...]
  key.sourcefile: <file name>
  key.sourcetext: <source text> (optional)
  key.expansions: [<expansion specifier>...]
}
```
`key.compilerargs` are used for getting plugins search paths. If
`key.sourcetext` is not specified, it's loaded from the file system.
Each `<expansion sepecifier>` is
```
{
  key.offset: <offset>
  key.modulename: <plugin module name>
  key.typename: <macro typename>
  key.macro_roles: [<macro role UID>...]
}
```
Clients have to provide the module and type names because that's
semantic.

Response is a `CategorizedEdits` just like (semantic) "ExpandMacro"
refactoring. But without `key.buffer_name`. Nested expnasions are not
supported at this point.
2023-06-07 14:26:40 -07:00
Slava Pestov
d5b354fd5f AST: Spot fix for AbstractStorageDecl::isResilient() 2023-06-07 15:17:54 -04:00
Pavel Yaskevich
274a43b040 Merge pull request #66283 from xedin/init-accessors
[Parse/Sema/SIL] Implementation of init accessors feature (under a flag)
2023-06-07 08:16:35 -07:00
Pavel Yaskevich
ad95e911a8 [Sema/SIL] InitAccessors: Incorporate init accessors into memberwise initializers
Properties with init accessors are used in place of properties they
are supposed to initialize in order of stored properties.
2023-06-06 18:59:46 -07:00
Pavel Yaskevich
4dbaaf3b23 [AST] InitAccessors: Allow assignments to let properties 2023-06-06 18:59:13 -07:00
Holly Borla
9039d8b0c0 [Sema] Add a request for gathering all computed properties in a nominal
type that have an init accessor.
2023-06-06 18:59:13 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Doug Gregor
954a0db60f Parameterize visitAuxiliaryDecls to account for separate traversal
Some places want to do in-order walks of MacroExpansionDecls, but still
visit auxiliary declarations. Rather than force them to specifically
filter out declarations from the MacroExpansionDecl, add a parameter to
visitAuxiliaryDecls to skip them.
2023-06-06 16:47:12 -07:00
Doug Gregor
0caa4531a6 [Macros] Teach SILGen to visit declartions produced by freestanding macros
Fixes a crash where local variables introduced by a freestanding
declaration macro would not get SIL emitted for them, rdar://109721114.
2023-06-06 14:33:11 -07:00
Rintaro Ishizaki
86d405bcd0 [Macros] Unify MacroExpansionDecl/MacroExpansionExpr expansion logic
'MacroExpansionDecl' and 'MacroExpansionExpr' have many common methods.
Introduce a common base class 'FreestandingMacroExpansion' that holds
'MacroExpansionInfo'.

Factor out common expansion logic to 'evaluateFreestandingMacro'
function that resembles 'evaluateAttachedMacro'.
2023-06-02 11:54:05 -07:00
Doug Gregor
af3ea4d142 [Name lookup] Only walk types/extensions to expand macros when we need to
Keep track of which types/extensions have members that could be produced by
a macro expansion, including the names of those members. Use this to
avoid walking into extensions or type definitions to expand macros
when they don't have any related macros.
2023-05-31 15:37:46 -07:00
Doug Gregor
7386a7e7bd [Macros] Rework the way we assign closure and local discriminators
Setting closure and local discriminators depends on an in-order walk
of the AST. For macros, it was walking into both macro expansions and
arguments. However, this doesn't work well with lazy macro expansions,
and could result in some closures/local variables not getting
discriminators set at all.

Make the assignment of discriminators only walk macro arguments, and
then lazily assign discriminators for anything within a macro
expansion or in ill-formed code. This replaces the single global "next
autoclosure discriminator" scheme with a per-DeclContext scheme, that
is more reliable/robust, although it does mean that discriminators
of closures and locals within macro expansions are dependent on
ordering. That shouldn't matter, because these are local values.

Fixes rdar://108682196.
2023-05-28 16:49:20 -07:00
Ellie Shin
79a2ff5efd Merge pull request #66189 from apple/es-diag
Improve diagnostics when package acl is used but no package-name is passed
2023-05-27 12:23:10 -07:00
Ellie Shin
61dd3008f8 Improve diagnostics when package acl is used but no package-name is passed 2023-05-26 15:59:51 -07:00
Ellie Shin
7b27997e37 Fix a crash during an operator type check with package acl
Type-checking an operator requires look up of all of its decls regardless of
which access modifier is used before filtering. If one of them is a package
decl in an imported module that was built with package-name, but the use site
of the operator decl is in a module that is not built with package-name, it
currently crashes as it tries to access package context of the use site, which
is null. This PR checks if both decl site and use site have package contexts
before accessing the package name property, otherwise return false to be filtered
out.

Resolves rdar://108961906
2023-05-25 16:29:51 -07:00
Richard Wei
9c91d1b705 [Macros] Fix lookup of macro-produced variables (#65939)
Calling `getInnermostDeclContext()->getParentSourceFile()` on a macro-produced decl does not seem to be a reliable way to obtain the macro expansion source file, because `PatternBindingDecl` is not a `DeclContext` and `getInnermostDeclContext()` falls back outside the macro expansion file. This patch switches to using `getSourceFileContainingLocation` when possible.

Resolves rdar://109376568.
2023-05-18 15:32:21 -07:00
Rintaro Ishizaki
7c2a73ebbd [Macros] Create type refinement context for MacroExpansionDecl 2023-05-16 20:47:12 -07:00
Konrad `ktoso` Malawski
da6f08a24e [Concurrency] Adopt stable keyword consuming instead of __owned
add test for warnings emitted when missing consuming attribute

use -emit-sil in mock SDK tests for better coverage
2023-05-11 15:18:54 +02:00
Alex Hoppen
53e57230a4 Merge pull request #65572 from ahoppen/ahoppen/macro-arg-completion
[CodeComplete] Offer code completion for attached macro attributes
2023-05-03 19:07:19 -07:00
Alex Hoppen
a39a77e8a2 Merge pull request #65526 from ahoppen/ahoppen/complete-in-macro-default-arg
[CodeComplete] Offer completion suggestions for default argument values inside the macro declaration + argument label inside `#externalMacro`
2023-05-03 18:58:35 -07:00
Konrad `ktoso` Malawski
0bdb39f51e Merge pull request #65455 from ktoso/wip-bincompat-job-rename 2023-05-04 07:34:45 +09:00
Konrad `ktoso` Malawski
b847ee12ce Further hardening: new compiler + old SDK still diagnose correctly 2023-05-03 11:03:34 +09:00
Doug Gregor
db81593be4 Merge pull request #65559 from DougGregor/macro-attached-to-accessors-mangle 2023-05-02 07:02:42 -07:00
Konrad `ktoso` Malawski
8d6980ec10 [Executors] Make move to ExecutorJob binary compatible; deprecate Job 2023-05-02 14:44:11 +09:00
Alex Hoppen
01cebd68a8 [CodeComplete] Offer code completion for attached macro attributes
We need to teach code completion how to invoke the type checker for attached macro attributes. After that, everything started working.

rdar://105232015
2023-05-01 21:11:24 -07:00
Doug Gregor
3547855148 [Macros] Mangle attached macros for accessors
Attached macro mangles for accessors were using a fallback case that
triggers an assertion in +Asserts builds, and conflicting manglings is
non-Asserts builds. Provide a custom mangling for these cases that's
embedded in the identifier.

This is a narrow hack to eliminate an assertion. We are considering a
different approach for the long term that uses entity manglings with a
placeholder type, which will be more flexible long-term.
2023-05-01 15:17:17 -07:00
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