Commit Graph

2357 Commits

Author SHA1 Message Date
Holly Borla
7a46466b65 Merge pull request #66967 from hborla/extension-macro
[Macros] Generalize `conformance` macros as `extension` macros
2023-06-29 08:57:04 -07:00
Kuba (Brecka) Mracek
d427696bf9 Allow @_silgen_name to be used on globals and add a @_silgen_name(raw: ...) version that skips mangling (#66540)
Attribute @_silgen_name is today only allowed to be used on functions, this change allows usage on globals as well. The motivation for that is to be able to "forward declare" globals just like it's today possible to do with functions (for the cases where it's not practical or convenient to use a bridging header).

Separately, this change also adds a @_silgen_name(raw: ...) syntax, which simply avoids mangling the name (by using the \01 name prefix that LLVM uses). The motivation for that is to be able to reference the "magic Darwin linker symbols" that can be used to look up section bounds (in the current dylib/module) -- those symbols don't use the underscore prefix in their mangled names.
2023-06-29 08:37:51 -07:00
Holly Borla
c867c7c917 [Macros] Allow extension macros to specify conformances in the attached
attribute.
2023-06-28 00:42:23 -07:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Alex Hoppen
2ff585d6ff [SourceKit] Highlight consuming and borrowing as keywords 2023-06-08 10:59:42 -07:00
Pavel Yaskevich
0e61a75ef9 [Parser] InitAccessors: Properties in initializes/accesses should be separated by comma 2023-06-06 18:59:46 -07:00
Pavel Yaskevich
a090eb4e17 [Parse] InitAccessor: Reject init accessor declarations on subscripts 2023-06-06 18:59:13 -07:00
Pavel Yaskevich
f96e1d7a4e [Parse] InitAccessors: Validate that init accessor declaration context
Init accessors are only allowed on properties.
2023-06-06 18:59:13 -07:00
Holly Borla
404a5239c3 [Parser] Parse 'initializes' and 'accesses' attributes on init accessors. 2023-06-06 18:59:13 -07:00
Holly Borla
e5f75029de [AST] Add 'initializes' and 'accesses' attributes for init accessor
definite initialization dependencies.
2023-06-06 18:59:13 -07:00
Holly Borla
d35da6262b [AST] Add a 'newValue' parameter to init accessors. 2023-06-06 18:59:13 -07:00
Holly Borla
429f1908c7 [Parser] Parse init accessors when the experimental feature is enabled. 2023-06-06 18:57:31 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Rintaro Ishizaki
a61fa5a4c2 Merge pull request #66296 from rintaro/macros-freestandingexpansion
[Macros] Unify MacroExpansionDecl/MacroExpansionExpr expansion logic
2023-06-05 09:35:18 -07:00
Doug Gregor
c28598777b Merge pull request #66327 from DougGregor/local-types-in-macro-expansions 2023-06-05 02:02:35 -07:00
Doug Gregor
e964d1290f [Parser] Add local type declarations to the outermost enclosing source file
The parser is currently responsible for adding local type declarations
to a `SourceFile`, which IR generation later queries. However, IRGen
never sees the source files associated with macro expansion buffers,
so local types introduced there don't get recorded.

In time, this approach of using the parser to record semantic
information should be replaced with something more "pull" oriented.
For now, however, record local type declarations in the outermost
enclosing source file... so we see the ones produced by macro
expansions, too.

Fixes rdar://109370309.
2023-06-04 21:54:25 -07:00
Slava Pestov
3efdc5acfb Merge pull request #66301 from slavapestov/implements-attr-request
AST: Requestify lookup of protocol referenced by ImplementsAttr
2023-06-02 16:33:14 -04:00
Ellie Shin
6eacb40ad3 Merge pull request #66261 from apple/es-spi
Add implicit SPI import feature
2023-06-02 12:27:40 -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
Slava Pestov
7499c222ee AST: Requestify lookup of protocol referenced by ImplementsAttr
Direct lookup relied in primary file checking to have filled in the
protocol type stored in the ImplementsAttr. This was already wrong
with multi-file test cases in non-WMO mode, and crashed in the
ASTPrinter if printing a declaration in a non-primary file.

I don't have a standalone test case that is independent of my
upcoming ASTPrinter changes, but this is a nice cleanup regardless.
2023-06-02 13:17:25 -04:00
Ellie Shin
32f53d1eb8 Add implicit SPI import feature
API development sometimes requires a redesign while supporting early
adopters. Currently this is done by adding @_spi(name) to the API but
that requires adding the attribute in import statements as well, causing
manual overhead of adding and then removing when the redesign is done.

This PR introduces a special spi group name '_' and allows an implicit
spi import of a module containing API attributed with '@_spi(_)'

Resolves rdar://109797632
2023-06-01 15:33:04 -07:00
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Hamish Knight
e064eb228e NFC: Silence unused variable warning 2023-05-24 13:05:52 +01:00
Hamish Knight
58d6694783 Requestify ExportedSourceFile parsing
Avoid parsing the syntax tree up-front, and instead
only parse it when required, which happens when either:

1. ASTGen parsing is enabled (currently disabled
   by default)
2. Round trip checking is enabled for a primary
   file (enabled by default in a debug build,
   except when dep scanning or doing an IDE
   operation)
3. We need to evaluate a macro in that file

This change therefore means that we now no longer
need to parse the syntax tree for secondary files
by default unless we specifically need to evaluate
a macro in them (e.g if we need to lookup a member
on a decl with an attached macro). And the same
for primaries in release builds.

rdar://109283847
2023-05-22 14:55:19 +01:00
Rintaro Ishizaki
e3a0f24cfe [Parse] Improve macro expansion parsing
* Unify macro expansion parsing logic between MacroExpansionExpr and
  MacroExpansionDecl
* Diagnose whitespace between '#' and the macro name
* Diagnose keyword as a macro name
2023-05-17 11:46:10 -07:00
Rintaro Ishizaki
ee5b3b134b Merge pull request #65815 from rintaro/macros-attributes-rdar107386648
[Macros/Parse] Attributes on MacroExpansionDecl
2023-05-15 13:28:53 -07:00
Alex Hoppen
e8a32e45be Merge pull request #65805 from ahoppen/ahoppen/complete-constraint-type
[CodeComplete] Offer completions after `~` in an inheritance clause
2023-05-12 13:32:40 -07:00
Rintaro Ishizaki
9fc1521aeb [Macros/Parser] Attributes on MacroExpansionDecl
* Parse `#<identifier>` attribute list as a `MacroExpansionDecl`
  regardless of the position
* Diagnose whitespaces between `#` and the macro name.
* Correctly attach attributes to `MacroExpansionDecl`
* Fix `OrigDeclAttributes` to handle modifiers (use `getLocation()`
  instead of `AtLoc`.)

Type checking is a TODO

rdar://107386648
2023-05-11 12:04:35 -07:00
Alex Hoppen
2abae1019f [CodeComplete] Offer completions after ~ in an inheritance clause
We should only be suggesting `Copyable` after `~` in an inheritance clause, in accordance with [SE-0390](https://github.com/apple/swift-evolution/blob/main/proposals/0390-noncopyable-structs-and-enums.md)

rdar://109063223
2023-05-09 20:21:30 -07:00
Luciano Almeida
2407256e54 Merge pull request #65748 from LucianoPAlmeida/parse-attr-fix-it
[Parser] Check let/var context when fix-it moving attributes from type to decl
2023-05-09 23:11:02 -03:00
Luciano Almeida
109b785e5d [Parser] Check let/var context when fix-it moving attributes from type to decl 2023-05-08 22:46:57 -03:00
Ben Barham
1426980ba4 Merge pull request #65737 from bnbarham/expand-infinite-loop
[Macros] Terminate parsing expanded members if no progress is made
2023-05-08 09:19:57 -07:00
Ben Barham
cec1fa2dc1 [Macros] Terminate parsing expanded members if no progress is made
Resolves rdar://108563022.
2023-05-05 21:22:56 -07:00
Kavon Farvardin
6d01f25055 Merge pull request #65556 from kavon/barebones-suppress-copyable
Build support for `~Copyable` atop `@_moveOnly`
2023-05-02 11:48:26 -07:00
Kavon Farvardin
ee819c80a9 Build support for ~Copyable atop @_moveOnly
We parse `~Copyable` in an inheritance clause of enum and
struct decls as a synonym for the `@_moveOnly` attribute
being added to that decl. This completely side-steps the
additional infrastructure for generalized suppressed
conformances in favor of a minimal solution. One benefit of
this minimal solution is that it doesn't risk introducing
any back-compat issues with older compilers or stdlibs.

The trade-off is that we're more committed to supporting
`@_moveOnly` in compiled modules in the future. In fact,
this change does not deprecate `@_moveOnly` in any way.

resolves rdar://106775103
2023-05-01 14:36:39 -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
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
Alex Hoppen
caeab5889a Merge pull request #65224 from StevenWong12/diagnositic_on_modifiers_in_operatordecl
[Parser] Make parser aware of the unexpected attributes in operator declarations
2023-04-27 21:03:00 -07:00
Alex Hoppen
186b854721 [Parser] Pass code completion status from attribute parsing to decl parsing
This is needed to be able to perform code completion inside `@freestanding` and `@attached`.
2023-04-27 18:13:16 -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
stevenwong
3cabe08d29 [Parser] Make parser aware of the unexpected attributes 2023-04-21 23:38:57 +08:00
Hamish Knight
017794a7d7 Merge pull request #65098 from hamishknight/poundland 2023-04-21 09:26:10 +01:00
Holly Borla
0ed4b3325f [SE-0393] Enable parameter packs for generic functions.
The VariadicGenerics flag still exists and is required for generic types
with parameter packs
2023-04-15 15:40:05 -07:00
Hamish Knight
48b58eb338 [AST] Introduce BraceStmt::getSingleActiveElement
Use this to replace
`Parser::shouldReturnSingleExpressionElement`.
This should be NFC.
2023-04-12 14:54:21 +01:00
Rintaro Ishizaki
f9feee6b63 [Parse] Enable SwiftParser parisng for code completion
But disable roundtrip/validation testing. So that macro expansions are
correctly performed in code completion, but avoid an assertion failure
caused by existence of null character in the source buffer.

rdar://107900870
2023-04-11 17:35:52 -07:00
Richard Wei
01e6fe2936 [Macros] Code item macros
Add support for declaring and expanding code item macros.  Add experimental feature flag `CodeItemMacros`.
2023-04-04 09:54:57 -07:00