Commit Graph

4105 Commits

Author SHA1 Message Date
Doug Gregor
97ee7024cf Merge pull request #62917 from DougGregor/macro-expansion-diags 2023-01-09 01:29:58 -08:00
Doug Gregor
c06216c36d [Macros] Disable macro expansion within the definition of macros.
... and once we do that, ensure that `#externalMacro` can only be
expanded as the definition of another macro.
2023-01-08 22:43:07 -08:00
Doug Gregor
535aecbd4f [Macros] Check primary-file macro definitions more thoroughly.
Error if a macro is undefined, and warn if it refers to an external
macro definition that cannot be found.
2023-01-08 22:22:27 -08:00
Holly Borla
74bf2f3e7a [AST] Introduce a syntactic distinction betweek vararg type reprs and
pack expansion type reprs.

Classic variadic parameters still use the postfix ellipsis syntax, and
pack expansion types now use a prefix 'repeat' keyword.
2023-01-07 09:50:11 -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
Luciano Almeida
e5e9827bd5 Merge pull request #60680 from cbjeukendrup/diag_unsupported_existential_extension
Improve diagnostics when trying to extend existential type
2023-01-05 10:11:36 -03:00
Michael Gottesman
b95fe48a90 Merge pull request #62742 from gottesmm/pr-947919228bebf49e02eae5aedb1efee8038c2b4b
[borrow-expr] Add simple support for borrow-expr and wire it up to SILGenApply
2023-01-03 08:04:33 -08:00
Doug Gregor
0c5436211c Merge pull request #62768 from DougGregor/macro-omnibus 2023-01-03 07:13:16 -08:00
swift-ci
72146501a1 Merge pull request #62745 from tshortli/has-symbol-clang-decls
Sema/IRGen: Add clang decl support to `#_hasSymbol`
2023-01-03 01:25:34 -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
222bc03c0a [Macros] Prevent recursive expansion of macros. 2023-01-02 21:22:04 -08:00
Doug Gregor
6bb9cb8b5d [Macros] Always parse macro expansions, diagnose later
Always parse macro expansions, regardless of language mode, and
eliminate the fallback path for very, very, very old object literals
like `#Color`. Instead, check for the feature flag for macro
declaration and at macro expansion time, since this is a semantic
restriction.

While here, refactor things so the vast majority of the macro-handling
logic still applies even if the Swift Swift parser is disabled. Only
attempts to expand the macro will fail. This allows us to enable the
macro-diagnostics test everywhere.
2023-01-02 21:22:04 -08:00
Doug Gregor
71ca9c86e6 [Macros] Diagnose when we forget to provide macro arguments.
Unlike functions, you can't curry macros; diagnose when one omits the
arguments in a macro expansion of a macro that has a parameter list.
2023-01-02 21:22:04 -08:00
Doug Gregor
806b5a8777 [Macros] Diagnose errors where a macro is used without the '#'. 2023-01-02 21:22:04 -08:00
Doug Gregor
af49a90dde Customize diagnostic text for extra/missing/mislabeled arguments for callee kind
Most of the diagnostics for extra/missing/mislabeled arguments refer
to argument to a "call". Some (but not call) would substitute in
"subscript". None would refer to an argument to a macro expansion
properly.

Rework all of these to refer to the argument in a call, subscript, or
macro expansion as appropriate. Fix up lots of tests that now say
"subscript" instead, and add tests for macro expansions.
2023-01-02 21:22:04 -08:00
Michael Gottesman
94f1391fbe [borrow-expr] Wire up borrow expr to SILGenApply. 2022-12-22 13:02:04 -08:00
Doug Gregor
f78f5729c3 Start requiring expression macros to be marked with @expression 2022-12-22 09:18:05 -08:00
Allan Shortlidge
d480410931 Sema: Diagnose unsupported clang decls for #_hasSymbol.
Progress towards rdar://103408651.
2022-12-22 10:55:29 -05:00
Holly Borla
0d3504fba6 Merge pull request #62729 from hborla/pack-diagnostics
[CSDiagnostics] Add an error message for pack expansion expressions over packs that don't have the same shape.
2022-12-21 13:44:08 -05:00
Holly Borla
e966b4ef7d [CSDiagnostics] Add an error message for pack expansion expressions over
packs that don't have the same shape.
2022-12-21 08:25:10 -05:00
Pavel Yaskevich
a98a35e2b3 [Sema] RuntimeMetadata: Verify that runtime attribute has a valid initializer 2022-12-20 09:45:01 -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
01fb1f8298 [Sema] RuntimeMetadata: Implement custom attribute placement validation
@<runtime-metadata-type> attribute is applicable to:

- Non-generic types
- global (non-generic) functions
- static and instance (non-generic) methods
- instance properties in concrete type context
2022-12-20 09:33:44 -08:00
Holly Borla
05443c442e Merge pull request #62509 from hborla/explicit-pack-reference-keyword
[Parser] Add a contextual `each` keyword for pack references.
2022-12-13 16:44:11 -08:00
Doug Gregor
54625a3a70 Only diagnose a missing external macro definition when we try to expand 2022-12-12 13:18:13 -08:00
Holly Borla
41298c2466 [AST] Introduce PackReferenceTypeRepr for pack references spelled with
a contextual 'each' keyword.
2022-12-10 16:16:04 -08:00
Alex Lorenz
d0e5372fc0 [interop][SwiftToCxx] give explicit error for @alwaysEmitIntoClient exposed functions 2022-12-06 11:44:29 -08:00
Anthony Latsis
d553d0466a Merge pull request #62355 from AnthonyLatsis/sr-no-sr
[NFC] Migrate remnant Jira issue references to GitHub issues
2022-12-04 12:08:25 +03:00
Anthony Latsis
4cb63c8a0f [NFC] Migrate remnant Jira issue references to GitHub issues 2022-12-04 08:20:34 +03:00
Allan Shortlidge
0aa39e3c7c Merge pull request #62329 from tshortli/allow-has-symbol-on-linux
Sema: Lift restriction preventing use of `#_hasSymbol` on non-Darwin-platforms
2022-11-30 22:39:06 -08:00
Allan Shortlidge
164ac421d6 Sema: Lift restriction preventing use of #_hasSymbol on non-Darwin platforms.
An early approach to codegen for `#_hasSymbol` relied on the Darwin platfom SDK, but now that the feature lowers directly to NULL checks in LLVM IR a platform restriction is no longer needed.

However, the tests for `#_hasSymbol` remain unsupported on Windows since that OS does not support weak linking.
2022-11-30 14:58:28 -08:00
Allan Shortlidge
49ce27acae Sema: Diagnose @_spi on elements of @frozen enums.
rdar://72873771
2022-11-29 22:11:02 -08:00
Doug Gregor
1a10009cae [Macro] Diagnose macros declared in nested scopes 2022-11-28 18:33:10 -08:00
Doug Gregor
e2c66cb67d [Macros] Check access control and availability 2022-11-28 18:33:10 -08:00
Doug Gregor
813dc12ad3 [Macros] Use the external module/type name in lieu of macro registration.
A macro declaration contains the external module and type name of the
macro's implementation. Use that information to find the macro type
(via its type metadata accessor) in a loaded plugin, so we no longer
require the "allMacros" array. Instead, each macro implementation type
must be a public struct.

Since we are now fully dependent on the macro declaration for
everything about a macro except its kind, remove most of the query
infrastructure for compiler plugins.

Replace the macro registration scheme based on the allMacros array with
2022-11-28 18:32:43 -08:00
Xi Ge
afbc4a5ffd Merge pull request #62251 from nkcsgexi/allowable-serialization
serialization: encode allowable client names in binary module format
2022-11-28 18:12:43 -08:00
Alexis Laferrière
c266e9dce5 Merge pull request #62185 from xymus/improve-rmodule-loading
Improve `-Rmodule-loading` to show both the path to the source and to the cached file actually loaded
2022-11-28 14:25:15 -08:00
Xi Ge
c3db946517 sema: diagnose importation from disallowed modules 2022-11-25 23:37:01 -08:00
Alexis Laferrière
319d49816d [Frontend] -Rmodule-loading shows both source path and cached path 2022-11-18 15:28:16 -08:00
Alexis Laferrière
d313760792 [Frontend] Report Swift overlays loaded for indirect cland dependencies 2022-11-18 10:44:07 -08:00
Xi Ge
c5a7eff0c9 Merge pull request #62147 from tshortli/has-symbol-sil-instruction 2022-11-18 04:34:24 -08:00
Richard Wei
1930f86a1a [Macros] Emit diagnostics from plugins
Make `_rewrite` return an buffer containing diagnostics and emit them.
2022-11-17 03:17:57 -08:00
Allan Shortlidge
3da18b6e68 SIL: Serialize and deserialize has_symbol instructions. 2022-11-16 16:07:59 -08:00
Pavel Yaskevich
59163524a5 [Sema] Add skeleton implementation of @runtimeMetadata attribute
Use of the attribute is gated on `RuntimeDiscoverableAttrs` flag.
2022-11-15 17:33:13 -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
Slava Pestov
8caeaa2f9e Sema: Ensure that generic parameters appearing in pack expansion patterns all have the same shape 2022-11-12 02:13:54 -05:00
Kavon Farvardin
6d75fac3b7 Merge pull request #61862 from kavon/isolated-param-holes-100039019
Fix inconsistencies with `isolated` parameters.
2022-11-11 20:09:54 -08:00
Kavon Farvardin
3b3bdaf8d1 enforce correctness rules about isolated parameters
This covers function types, closures, and function declarations:

- only one `isolated` parameter
- no global-actor + `isolated` parameter
- no `nonisolated` + `isolated`.

all diagnostics are warnings until Swift 6
2022-11-11 16:00:12 -08:00
omochimetaru
58bcbb25fd fix diagnostics message for conditional conformance with marker protocol 2022-11-11 10:00:42 +09:00
Konrad `ktoso` Malawski
e94aa362fa [Concurrency] Ban multiple isolated params, as per SE-0313 2022-11-10 12:18:53 -08:00