Commit Graph

2699 Commits

Author SHA1 Message Date
Joe Groff
2a187f2606 SILGen: Support mutable consuming parameters.
Emit a box like we would for a local variable, and move the parameter value into the box, as
part of the prolog.
2023-02-28 09:16:45 -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
03a2393a6c IRGen: Track IsCopyable through type infos.
And use the new bit to ensure we don't try to lower move-only types
with common layout value witness surrogates. Take a bit in the runtime
value witness flags to represent types that are not copyable.
2023-02-27 18:52:50 -08:00
Alexis Laferrière
1afc6af739 Merge pull request #63912 from xymus/access-level-import-parsing
[Parser|Sema] Accept access level on imports with experimental flag
2023-02-27 09:27:26 -08:00
Alexis Laferrière
38fbe1d49b [Sema] Preserve information about access level on imports 2023-02-25 09:47:36 -08:00
Holly Borla
a3caacd309 [Macros] Initial implementation of conformance macros. 2023-02-23 20:43:11 -08:00
Allan Shortlidge
f1a8740ba5 AST: Only treat @backDeployed functions as fragile on platforms with an active attribute.
Previously, typechecking and SILGen would treat a function body as fragile as long as the declaration had a `@backDeployed` attribute, regardless of the platform specified by the attribute. This was overly conservative since back deployed functions are only emitted into the client on specific platforms. Now a `@backDeployed` function can reference non-`public` declarations on the platforms it is resilient on:

```
@backDeployed(before: iOS 15)
public func foo() {
  #if os(iOS)
  // Fragile; this code may be emitted into the client.
  #else
  // Resilient; this code won't ever be exposed to clients.
  #endif
}
```

Resolves rdar://105298520
2023-02-23 10:39:42 -08:00
Holly Borla
f6c3aaab96 [Macros] Return a ConcreteDeclRef from ResolveMacroRequest.
This allows callers to access inferred generic arguments for macro
expansion invocations.
2023-02-20 21:17:19 -08:00
swift-ci
815e8cc8e7 Merge pull request #63714 from ahoppen/ahoppen/ideinspectiontarget-charsourcerange
[IDE] Check whether an AST node contains the IDE inspection point based on `CharSourceRange`
2023-02-20 10:20:45 -08:00
Alex Hoppen
8bdf68d483 [IDE] Check whether an AST node contains the IDE inspection point based on CharSourceRange
This fixes an issue if the range ends with a string literal that contains the IDE inspection target. In that case the end of the range will point to the start of the string literal but the IDE inspection target is inside the string literal and thus after the range’s end.
2023-02-20 15:37:38 +01:00
Ben Barham
0c3f538822 [AST] Allow ignoring macro expansions
Various requests expect to be walking over the current source file.
While we could add checks to all these to skip decls outside of the
current buffer, it's a little nicer to handle this during the walk
instead.

Allow ignoring nodes that are from macro expansions and add that flag to
the various walks that expect it.

Also add a new `getOriginalAttrs` that filters out attributes in
generated source.
2023-02-16 18:04:56 -08:00
Holly Borla
85f2a1a234 [Macros] Factor calls to ResolveMacroRequest into Decl::getResolvedMacro.
This prevents call-sites from making the mistake of passing an incorrect
DeclContext to the request, which can cause re-typechecking issues.
2023-02-15 18:52:02 -08:00
Holly Borla
c33c925e81 [Macros] Remove the macro role argument to ResolveMacroRequest.
The macro role argument presented an opportunity for callers to accidentally
invoke this request twice for the same macro with slightly different macro
roles passed in, which resulted in re-typechecking the macro arguments.
Instead, derive the corresponding macro roles from the macro reference syntax.
2023-02-14 22:38:53 -08:00
Holly Borla
f4b2b60446 [Macros] Enable global peer macros.
Global peer macro expansions are not injected into the AST. Instead, they
are visited as "auxiliary declarations" when needed, such as in the decl
checker and during SILGen. This is the same mechanism used for local property
wrappers and local lazy variables.
2023-02-14 16:24:25 -08:00
Doug Gregor
a712c37c05 Teach the related-id checker to ignore things from other buffers 2023-02-13 10:13:39 -08:00
Doug Gregor
7ebc86e584 Have attached macro requests return an array of expansion buffer IDs.
The result values of the expansion requests for attached macros tended
to be useless, because most of their operation is via side effects on
the nodes they are attached to. Replace the result values with an
array of expansion buffer IDs, so clients can see what effect the
macro expansion had.
2023-02-11 11:21:43 -08:00
Holly Borla
5bfc7e6dac Merge pull request #63538 from hborla/peer-macros
[Macros] Initial implementation of peer macros.
2023-02-11 10:57:28 -08:00
Artem Chikin
02a1577e38 Merge pull request #63503 from artemcm/ConstExtractRuntimeMetadataAttr
[Compile Time Constant Extraction] Extract Runtime Metadata Attributes
2023-02-10 22:45:12 -07:00
Holly Borla
f04f512184 [Macros] Add a new macro role for attached peer macros. 2023-02-10 14:38:22 -08:00
Doug Gregor
04eca73d60 [Macros] Stop parsing the ": <type>" syntax. We always require parameters 2023-02-09 22:11:23 -08:00
Artem Chikin
d5f09b496a [Compile Time Constant Extraction] Extract runtime metadata attributes
Part of rdar://104192094
2023-02-08 14:31:44 -07:00
swift-ci
38c89bf212 Merge pull request #63491 from ktoso/wip-custom-executor-not-directly-on-actor
[CustomExecutors] unownedExecutor can be declared not directly on actor
2023-02-08 01:33:48 -08:00
Konrad `ktoso` Malawski
6b95ff7a25 [Concurrenncy] add internal way to assert we're on expected executor 2023-02-08 15:41:25 +09:00
Konrad `ktoso` Malawski
307ec5a378 [Concurrency] unownedExecutor can be declared not directly on actor 2023-02-08 13:38:02 +09:00
Pavel Yaskevich
1d2e1ed793 [AST] NFC: Move VarDecl::getPointerAuthQualifier implementation to Decl.cpp 2023-02-07 15:58:14 -08: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
Richard Wei
01e4c8df26 [Macros] Use name lookup for lazy declaration macro expansion (#63411)
- Use the name lookup table instead of adding members from a macro expansion to the parent decl context.
- Require declaration macros to specify introduced names and used the declared names to guide macro expansions lazily.
2023-02-07 11:24:42 +08:00
Ben Barham
5d684fb679 Merge pull request #63320 from bnbarham/index-objc-impl-crash
[AST] Avoid possible segfault in isDirectToStorageAccess
2023-02-06 15:49:04 -08:00
Doug Gregor
b1c20c926d Merge pull request #63418 from DougGregor/mangle-attached-macros 2023-02-03 16:23:17 -08:00
Ellie Shin
258b13b05d Merge pull request #63355 from apple/es-export-pr
Add access level and scope checks to package types
2023-02-03 15:20:29 -08:00
Doug Gregor
b63fa566ec [Macros] Add mangling for attached macro expansion.
Extend the name mangling scheme for macro expansions to cover attached
macros, and use that scheme for the names of macro expansions buffers.

Finishes rdar://104038303, stabilizing file/buffer names for macro
expansion buffers.
2023-02-03 13:30:16 -08:00
Ellie Shin
be20333a87 Add access level and scope checks to package types
Resolves rdar://104617227
2023-02-02 16:51:17 -08:00
Allan Shortlidge
d2524a6de8 AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.
For source compatibility `@_backDeploy` continues to be accepted as a spelling.

rdar://102792909
2023-02-01 22:04:33 -08:00
Allan Shortlidge
aa5194cdc5 AST: Correct inferred availability attributes on synthesized declarations.
The `getInnermostDeclWithAvailability()` utility was not looking through extensions to the nominal type declaration when searching for enclosing availability.

Resolves rdar://104931478
2023-02-01 16:50:21 -08:00
Ben Barham
526016c5c1 [AST] Avoid possible segfault in isDirectToStorageAccess
`isAccessibleFrom` allows a `nullptr` for `useDC`. Thus `UseDC` can be a
`nullptr` in the path `checkAccess` -> `getAccessSemanticsFromContext`
-> `isDirectToStorageAccess`.

Resolves rdar://104620331.
2023-01-30 19:06:03 -08:00
Pavel Yaskevich
af639e5bf4 [AST] RuntimeMetadata: Move getRuntimeDiscoverableAttrs to Decl
Reflection metadata attributes could be attached to a `ValueDecl`
and `ExtensionDecl`.
2023-01-30 14:03:40 -08:00
Richard Wei
2eab34a865 [Macros] Unify macro resolution under ResolveMacroRequest (#63293)
This reverts an earlier revert (547d85e643) and fixes the Windows build.
2023-01-30 00:07:40 +08:00
Saleem Abdulrasool
547d85e643 Revert "[Macros] Unify macro resolution under ResolveMacroRequest" (#63289) 2023-01-28 11:49:00 -08:00
Richard Wei
1d6a54794f Merge pull request #63247 from rxwei/resolve-macro-request 2023-01-28 09:25:00 +08:00
Richard Wei
7d6994a200 [Macros] Unify macro resolution under ResolveMacroRequesto
Rename `ResolveAttachedMacroRequest` to `ResolveMacroRequest` and make use of the request in freestanding declaration macro type checking. Add support for type-checking generic arguments on `MacroExpansionDecl`.
2023-01-27 15:07:10 +08:00
Holly Borla
32a0705e90 [Macros] Use the singular 'memberAttribute' spelling for attached member
attribute macros.
2023-01-26 21:52:39 -08:00
Holly Borla
f6f57a8099 [Macros] Rename "synthesized member macros" to "member macros". 2023-01-26 21:52:36 -08:00
Holly Borla
3e6fdb8807 [NameLookup] The custom attribute lookup request only returns nominal types.
Macro attribute lookup is now implemented in ResolveMacroRequest, which happens
later because it needs overload resolution to resolve a custom attribute to a
macro decl.
2023-01-26 17:10:28 -08:00
Doug Gregor
4e50e29f3d Merge pull request #63233 from DougGregor/macros-mangle-buffer-names
[Macros] Mangle the names of macro expansion buffers
2023-01-26 06:57:15 -08:00
Doug Gregor
4ae434eaa1 [Macros] Add a mangling for macro expansions
These aren't ABI, but are useful to provide consistent names to refer
to macro expansions, e.g., in buffer names.
2023-01-25 22:45:14 -08:00
Doug Gregor
72ddbebc08 [Macros] Assign macro expansion discriminators more lazily.
This is a punt. They'll be unique, and they'll be per-context, but
they'll be lazy and therefore not stable.
2023-01-25 22:03:38 -08:00
Doug Gregor
6e3289d4d5 [Macros] Compute discriminators for freestanding macro expansions.
Introduce discriminators into freestanding macro expansion expressions
and declarations. Compute these discriminators alongside closure and
local-declaration discriminators, checking them in the AST verifier.
2023-01-25 22:03:38 -08:00
Doug Gregor
af7ce9e945 [Macros] Remove the @declaration attribute.
We have @freestanding working appropriately now.
2023-01-25 17:07:38 -08:00
Doug Gregor
c188ab4f91 Remove the "@expression" attribute now that it has a better spelling 2023-01-25 17:07:38 -08:00
Doug Gregor
d74f235eb9 Generalize @attached parsing and representation to also include @freestanding.
The attached and freestanding macro attributes use the same parsing
logic and representation, so generalize the "attached" attribute into
a more general "macro role" attribute.
2023-01-25 17:07:38 -08:00