Commit Graph

2727 Commits

Author SHA1 Message Date
Meghana Gupta
1dac5d48d3 Support for address discriminated pointers 2023-01-27 01:56:44 -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
swift-ci
281088eb73 Merge pull request #63204 from meg-gupta/ptrauthcodegenpr
Initial support for ptrauth qualified function pointers in C
2023-01-25 22:19:34 -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
Meghana Gupta
9239a40e4b Add VarDecl::getPointerAuthQualifier api 2023-01-25 12:38:02 -08:00
Holly Borla
6a17bb64da [Macros] Factor out iteration over all attached macro attributes of a particular
role into `Decl::forEachAttachedMacro`.
2023-01-23 18:20:16 -08:00
Ellie Shin
37af51dc4c Merge branch 'main' into es-pkg-acl 2023-01-19 16:18:17 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Holly Borla
81492d1d96 [Macros] Requestify member attribute macro expansion directly.
Having a request for semantic declaration attributes while still allowing
the original linked list to be mutated directly can cause use-after-frees
on pointers to old decl attributes. For now, introduce a request that
expands member attribute macros with a side effect of adding the new
attributes to the list. We can revisit this once attribute mutation via
getAttrs() is audited across the frontend.
2023-01-17 19:48:22 -08:00
Holly Borla
3f462f0f43 [Decl] Add MissingDecl to use for parser recovery. 2023-01-15 09:55:15 -08:00
Holly Borla
2f170f6ecc [Sema] Introduce a requestified replacement for 'getAttrs'.
Introduce 'getSemanticAttrs', which is a requestified replacement for
'getAttrs'. Right now, AttachedSemanticAttrsRequest calls 'getAttrs',
meaning future additions or removals from the linked list will not be
reflected via 'getSemanticAttrs'. Callers of 'getAttrs' that rely on
mutation will need to turn the computation into a request and vend the
attributes through AttachedSemanticAttrsRequest.
2023-01-15 09:55:15 -08:00
Doug Gregor
de16b47875 [Macros] Introduce the @attached attribute for declaring attached macros.
Describe attached macros with the `@attached` attribute, providing the
macro role and affected names as arguments to the macro. The form of
this macro will remain the same as it gains other kinds of attached
macro roles beyond "accessor".

Remove the "accessors" role from `@declaration`, which will be going
away.
2023-01-13 22:47:59 -08:00
swift-ci
a82e17bffa Merge pull request #62934 from rxwei/freestanding-declaration-macros
[Macros] Freestanding declaration macros
2023-01-10 21:55:16 -08:00
Richard Wei
f17b7c48bf [Macros] Freestanding declaration macros
Add support for freestanding declaration macros.

- Parse `@declaration` attribute.
- Type check and expand `MacroExpansionDecl`.

Known issues:
- Generic macros are not yet handled.
- Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
2023-01-10 19:09:11 -08:00
Allan Shortlidge
abf4d127a4 Sema: Improve diagnostics for decls more available than their containers.
Adopt new request-based utilities for looking up the enclosing declaration's availability when type checking an `@available` attribute. This consolidates implementations of the lookup and improves diagnostics by catching more cases where declarations are more available than their containers.
2023-01-06 16:09:33 -08:00
Allan Shortlidge
76d1565a9d Sema: Lift restriction that declarations with @_backDeploy must have explicit availability.
Resolves rdar://103880356
2023-01-06 08:18:00 -08:00
Doug Gregor
0c5436211c Merge pull request #62768 from DougGregor/macro-omnibus 2023-01-03 07:13:16 -08:00
Pavel Yaskevich
24bd6fc545 Merge pull request #62734 from xedin/enable-result-builder-ast-transform-by-default-with-old-impl
[TypeChecker] Enable result builder AST transform by default
2023-01-03 00:55:43 -08:00
Doug Gregor
7000969f14 Introduce and use #externalMacro for externally-defined macros.
Align the grammar of macro declarations with SE-0382, so that macro
definitions are parsed as an expression. External macro definitions
are referenced via a referenced to the macro `#externalMacro`. Define
that macro in the standard library, and recognize uses of it as the
definition of other macros to use externally-defined macros. For
example, this means that the "stringify" macro used in a lot of
examples is now defined as something like this:

    @expression macro stringify<T>(_ value: T) -> (T, String) =
        #externalMacro(module: "MyMacros", type: "StringifyMacro")

We still parse the old "A.B" syntax for two reasons. First, it's
helpful to anyone who has existing code using the prior syntax, so they
get a warning + Fix-It to rewrite to the new syntax. Second, we use it
to define builtin macros like `externalMacro` itself, which looks like this:

    @expression
    public macro externalMacro<T>(module: String, type: String) -> T =
        Builtin.ExternalMacro

This uses the same virtual `Builtin` module as other library builtins,
and we can expand it to handle other builtin macro implementations
(such as #line) over time.
2023-01-02 21:22:05 -08:00
Doug Gregor
6bad02c50a [Macros] Implement overloading rules 2023-01-02 21:22:04 -08:00
Doug Gregor
c1a85c15ae Merge pull request #62741 from DougGregor/local-named-discriminators
Rework computation of local discriminators for named entities.
2023-01-02 21:19:26 -08:00
Doug Gregor
f78f5729c3 Start requiring expression macros to be marked with @expression 2022-12-22 09:18:05 -08:00
Doug Gregor
3e2bafc2f2 [Macro] Add the expression attribute for macro declarations 2022-12-22 09:10:01 -08:00
Doug Gregor
9e61b01ec1 Rework computation of local discriminators for named entities.
Local discriminators for named entities are currently being set by the
parser, so entities not created by the parser (e.g., that come from
synthesized code) don't get local discriminators. Moreover, there is
no checking to ensure that every named local entity gets a local
discriminator, so some entities would incorrectly get a local
discriminator of 0.

Assign local discriminators as part of setting closure discriminators,
in response to a request asking for the local discriminator, so the
parser does not need to track this information, and all local
declarations---including synthesized ones---get local discriminators.
And add checking to make sure that every entity that needs a local
discriminator gets assigned one.

There are a few interesting cases in here:
* There was a potential mangling collision with local property
wrappers because their generated variables weren't getting local
discriminators
* $interpolation variables introduced for string interpolation weren't
getting local discriminators, they were just wrong.
* "Local rename" when dealing with captures like `[x]` was dependent on
the new delcaration of `x` *not* getting a local discriminator. There
are funny cases involving nesting where it would do the wrong thing.
2022-12-21 15:01:07 -08:00
Alex Hoppen
3c90c892e9 [CodeCompletion] Drop ForCodeCompletion constraint system option for syntactic elements that don't contain completion token 2022-12-21 12:17:56 -08:00
Pavel Yaskevich
f7f2e3709b [Sema] RuntimeMetadata: Synthesize a body for runtime attribute generator
Single expression is not going to cut it in this case because attribute
and attached declaration could have different availability, so we need
to use `if #available` to guard attribute instantiation and return `nil`
in cases where types are not available.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
8a930095fe [AST/Sema] RuntimeMetadata: Switch generator synthesis to produce an expression
The runtime discoverable attribute generator just like a default
argument or a property wrapper doesn't have a distinct name or
a declaration. Sema should synthesize a call that could be used
to obtain a value of an attribute type and everything else is
going to be synthesized in SILGen.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
8a74986964 [Sema] RuntimeMetadata: Add type decl accessor for runtime metadata attribute
One of the intended usages of `getRuntimeDiscoverableAttrTypeDecl`
is IRGen where we need to relate unique attributes to a list of their
(decl) attachments.
2022-12-20 09:45:01 -08:00
Pavel Yaskevich
4806e74fad [AST/Decl] RuntimeMetadata: Make it possible to retrieve a generator for a given attr 2022-12-20 09:33:44 -08:00
Pavel Yaskevich
8e66f193c1 [AST/Sema] RuntimeMetadata: Add a way to retrieve runtime metadata attrs
Adds `ValueDecl::getRuntimeDiscoverableAttrs` which returns all
valid runtime discoverable attributes associated with the given
declaration.
2022-12-20 09:33:44 -08:00
Pavel Yaskevich
2ce48e0b7d [AST/Sema] TypeWrappers: Augment GetTypeWrapper request to produce more info
The request is updated to return attribute, wrapper declaration,
the declaration its attached to and whether or not it has been
inferred (opposite to being declared directly).
2022-12-14 17:50:22 -08:00
Doug Gregor
f0fc1c51bb Remove compiler plugin support library
The functionality of the compiler plugin support library has been
subsumed into parts of the compiler. Remove the functionality and its
last test.
2022-12-05 12:54:36 -08:00
Allan Shortlidge
85ddda128b AST: Introduce a getFirstElement() utility on EnumCaseDecl.
This utility helps codify the practice of using the attributes of the first element of a case decl as the attributes for the entire case.
2022-11-29 22:11:31 -08:00
Doug Gregor
e1102cc098 Merge pull request #62204 from DougGregor/macro-declarations
Macro declarations
2022-11-29 10:04:09 -08:00
Slava Pestov
3113c62a2d AST: Fix performance regression in lookupDirect()
Every call to lookupDirect() was calling prepareLookupTable() followed
by addLoadedExtensions(). While prepareLookupTable() only did its work
once, addLoadedExtensions() would walk all currently-loaded members of
all extensions every time.

However, just merging it with prepareLookupTable() was not enough,
because other places call prepareLookupTable(), which ends up loading
extensions too early after this change.

Instead, separate out the lazy allocation of the lookup table from
initialization. getLookupTable() returns a potentially-uninitialized
lookup table, and prepareLookupTable() now does what it did before
as well as what was formerly in addLoadedExtensions().

With this new split, getLookupTable() can be used instead of
prepareLookupTable() to avoid request cycles in a couple of places.
2022-11-28 23:57:53 -05:00
Doug Gregor
1a124e71d6 [Macros] Implement AST printing and module interface generation for macros 2022-11-28 18:33:10 -08:00
Doug Gregor
b29fcb4e58 [Macros] Parse macro declarations fully, and treat them as normal declarations 2022-11-28 18:32:43 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Xi Ge
c5a7eff0c9 Merge pull request #62147 from tshortli/has-symbol-sil-instruction 2022-11-18 04:34:24 -08:00
Doug Gregor
787af41765 [Macros] Parse generic arguments in macro expansions. 2022-11-17 16:46:43 -08:00
Angela Laar
3d9ce2748a Merge pull request #62161 from angela-laar/some-elision-circular-ref
[AST] Fix circular reference with implicit some
2022-11-17 15:53:52 -08:00
Angela Laar
bde6a465af [AST] Fix circular reference with implicit some
getPotentiallyOpaqueGenericParams has a redundant call to check if
declarations contain any opaque type representations. We don't need
to check this here. Instead we can simply collect the result type
representaions without the additional checks.
2022-11-17 11:53:50 -08:00
Allan Shortlidge
abdc4d9112 SILGen: Use has_symbol instruction in SILGen. 2022-11-16 16:07:29 -08:00
Robert Widmann
4c162b2aeb Delete libSyntax 2022-11-16 14:52:28 -08:00
Pavel Yaskevich
e762d20568 Merge pull request #61982 from xedin/type-wrappers-on-protocols
[Sema] TypeWrappers: Allow type wrappers on protocols and inference from them
2022-11-14 12:46:48 -08:00
Doug Gregor
5ab6b72604 [Macros] Turn Macro into a declaration node.
Although the declaration of macros doesn't appear in Swift source code
that uses macros, they still operate as declarations within the
language. Rework `Macro` as `MacroDecl`, a generic value declaration,
which appropriate models its place in the language.

The vast majority of this change is in extending all of the various
switches on declaration kinds to account for macros.
2022-11-13 12:21:29 -08:00
Allan Shortlidge
114ee28639 AST: Add a DescriptiveDeclKind for actors. 2022-11-08 19:17:09 -08:00
Slava Pestov
16a84fc382 AST: Rename ProtocolDecl::getExistentialType() to getDeclaredExistentialType() 2022-11-07 18:38:06 -05:00
Pavel Yaskevich
db4b6a5c0f [AST/Sema] TypeWrappers: Implement type wrappers on protocols
Adding a type wrapper attribute on a protocol does two things:

- Synthesizes `associatedtype $Storage` declaration with `internal` access
- Synthesizes `var $storage: <#Wrapper#><Self, Self.$Storage>` value requirement
2022-11-07 14:55:05 -08:00
Pavel Yaskevich
82f34b90c1 [AST] NameLookup: Add a request to gather protocol requirements 2022-11-04 11:11:41 -07:00