Commit Graph

3502 Commits

Author SHA1 Message Date
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
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
Holly Borla
8b9be30783 [Macros] Add a new macro role for synthesized member macros. 2023-01-22 21:19:21 -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
Ellie Shin
792be3fe85 Modify AccessScope to allow checks for package access level
Resolves rdar://103534243
2023-01-19 15:50:32 -08:00
Ellie Shin
f26f810cc8 Merge pull request #62704 from apple/es-pkg2
[NFC] Modify AccessScope to allow checks for package access level
2023-01-19 09:09:27 -08:00
Ellie Shin
288dbe3842 Modify AccessScope to allow checks for package access level
Resolves rdar://103534243
2023-01-19 01:43:53 -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
5d7b280889 [Macros] Use @attached for member attribute macros.
Add MemberAttributes to MacroRole that corresponds to a `memberAttributes`
argument to the `@attached` attribute.
2023-01-15 10:11:00 -08:00
Holly Borla
3f462f0f43 [Decl] Add MissingDecl to use for parser recovery. 2023-01-15 09:55:15 -08:00
Holly Borla
ba7fb5d946 [Property Wrappers] Use getSemanticAttrs in AttachedPropertyWrappersRequest. 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
43cadcad3a [Macros] Serialization and printing for @attached. 2023-01-14 21:48:43 -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
Doug Gregor
69649a40a6 Generalize CustomAttrNominalRequest's name and signature to account for macros 2023-01-11 21:28:26 -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
Doug Gregor
08c5553ac3 Merge pull request #62911 from DougGregor/parent-source-file-in-generated-buffers
Teach DeclContext::getParentSourceFile() to return the innermost source file
2023-01-08 21:56:51 -08:00
Doug Gregor
721d52f998 Add some missing NULL checks 2023-01-08 12:05:52 -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
9df854179e Accessors never have local discriminators 2022-12-22 10:44:43 -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
c849cbe119 Remove extraneous debugging code 2022-12-22 08:30:00 -08:00
Doug Gregor
4de9197125 Opaque types never have local discriminators 2022-12-22 07:15:02 -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
43904e5a89 [ASTPrinter] Mark declarations with runtime attributes as using the feature 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
Arnold Schwaighofer
5004cee9b0 Merge pull request #62686 from aschwaighofer/testing_debacle
IRGen: Don't treat internal but visible via testable import classes as having fragile layout
2022-12-19 16:08:03 -08:00
Arnold Schwaighofer
20ff4dfc57 IRGen: Don't treat internal but visible via testable import classes as having fragile layout
That does not work if there is a resilient class in the hiearchy from a
different module than the testable imported one.  Rather treat an
internal but testable imported class as having resilient metadata.

The scenario that does not work assuming we can build a fragile layout
is the following.

FrameworkA is resilient and defines a public class `Base` with a stored field.
FrameworkB is resilient and defines an internal class `Sub` that inherits from
the class `Base` in FrameworkA and adds some fields. FrameworkB is compiled
with enable-testing.
The test case testable imports FrameworkB and accesses a field in the
internal class `Base` from FrameworkB. The test case only has access to
FrameworkA's public swiftinterface file and therefore does not know
`Base`'s layout.  The layout computation for `Sub` cannot take the field
from `Base` into account and things fail silently.

rdar://103323275
2022-12-19 07:35:56 -08:00
Luciano Almeida
0db4b43f6d Merge pull request #61863 from LucianoPAlmeida/crash-dump-parse-init
[ASTDumper] Special handling for init kind in pre-typecheck dump
2022-12-16 09:42:31 -03:00
Pavel Yaskevich
7b08b30e84 Merge pull request #62586 from xedin/rdar-103270262
[AST/Sema] TypeWrappers: Fix a couple of issues with attribute inference from protocols
2022-12-15 17:49:19 -08:00
Pavel Yaskevich
778285157f [AST] TypeWrappers/NFC: Move local $storage handling code to TypeWrapper.cpp 2022-12-14 12:29:56 -08:00
Alex Hoppen
58aaa4f111 Merge pull request #62522 from ahoppen/ahoppen/rename-completion
[IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
2022-12-13 16:40:28 +01:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Doug Gregor
54625a3a70 Only diagnose a missing external macro definition when we try to expand 2022-12-12 13:18:13 -08:00
Luciano Almeida
70b884cf08 [ASTDumper] Special handling for init kind in pre-typecheck dump 2022-12-06 22:50:00 -03:00
Doug Gregor
3c80b714bf [Macros] Fix end location of macro declarations with where clauses 2022-11-28 18:33:10 -08: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
Pavel Yaskevich
c17d35dc3e Merge pull request #62146 from xedin/rdar-102085039
[AST] `getParameterAt` should check index before retrieving it
2022-11-28 10:01:51 -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