Commit Graph

2438 Commits

Author SHA1 Message Date
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
Artem Chikin
cc34ba00e2 [Dependency Scanning] Disable Swift Parser ASTGen during dependency scan
On both input moduel source-files and interface files.
This currently yields dramatic scanning performance improvements at no cost - we do not require an AST during scan.
2023-03-31 15:49:54 -07:00
Alex Hoppen
5bb6f79847 Merge pull request #64609 from ahoppen/ahoppen/no-self-macros
[Macros] Disallow `self` and `Self` as macro names
2023-03-27 11:23:19 -07:00
Doug Gregor
c31f6fa0cc Merge pull request #64631 from DougGregor/macro-parameter-defaults 2023-03-27 06:50:08 -07:00
Doug Gregor
9d9f8326c8 [Macros] Allow macro parameters to have default arguments.
SE-0382 allows macro parameters to have default arguments. Enable these
default arguments, with the normal type checking rules. One
significant quirk to this implementation is that the actual default
argument values don't make it to the macro implementation. This is a
previously-unconsidered design problem we'll need to address.

Tracked by rdar://104043987.
2023-03-26 22:13:37 -07:00
Kim de Vos
8fb787dc27 Downgrade placeholder error to warning for swiftparser 2023-03-24 20:18:02 +01:00
Alex Hoppen
d5a90174f0 [Macros] Disallow self and Self as macro names
We were allowing `self` and `Self` as freestanding macro names, which we don’t want.
2023-03-24 09:32:51 -07:00
Alex Hoppen
6c5ac5179a Merge pull request #63490 from ahoppen/ahoppen/split-ideinspection
Split IDEInspectionCallbacks into CodeCompletionCallbacks and DoneParsingCallback
2023-03-20 09:20:30 -07:00
Saleem Abdulrasool
b52fdb9d4b Apply suggestions from MSVC workaround 2023-03-18 14:11:31 -07:00
Alex Hoppen
024e2c93af [Parse] Add curly braces
Maybe this makes VSCode happy and resolves a Windows-only compilation failure `error C2059: syntax error: ')'`
2023-03-17 13:40:56 -07:00
Alex Hoppen
8a2cd86deb Split IDEInspectionCallbacks into CodeCompletionCallbacks and DoneParsingCallback
Cursor info only cares about the `doneParsing` callback and not about all the `complete` functions that are now defined in `CodeCompletionCallbacks`. To make the design clearer, split `IDEInspectionCallbacks`.

rdar://105120332
2023-03-17 10:31:13 -07:00
Ellie Shin
77b5c79cc0 Allow package(set) at the top level decl site
Treat `package` as a non-contextual keyword when applicable
Add tests
Resolves rdar://105978922, rdar://104931420
2023-03-16 17:38:18 -07:00
Michael Gottesman
40449a6987 [move-only] Emit a clearer message around deinits.
Specifically:

1. Fix the error message so that when we say you can't have a deinit that a
deinit can be on a noncopyable type along side a class or an actor.

2. Even though we already error on @objc enums and say they cannot be
noncopyable, we did not emit an error on the deinit saying that @objc enums
cannot have a deinit. I put in a nice to have error just to make it even
clearer.

rdar://105855978
rdar://106566054
2023-03-12 14:47:34 -07:00
Doug Gregor
ef7f707fcc Revert "Improve @objcImplementation member checking" 2023-03-10 12:00:33 -08:00
Sophia Poirier
739cc2a66c Merge pull request #64104 from sophiapoirier/type-parameter-pack-syntax-each-diagnostics
[Variadic Generics] fix diagnostics dangling reference and fixits for…
2023-03-06 14:27:37 -08:00
Ben Barham
edb980eb55 Merge pull request #64095 from bnbarham/do-not-change-refactoring
[Macros] Do not edit macro buffer or position when refactoring
2023-03-06 08:43:30 -08:00
Xi Ge
ffc998a0e7 Merge pull request #63668 from beccadax/checkmate
Improve @objcImplementation member checking
2023-03-06 08:21:59 -08:00
Richard Wei
833338f9ce [Macros] Top-level freestanding macros (#63553)
Allow freestanding macros to be used at top-level.
- Parse top-level `#…` as `MacroExpansionDecl` when we are not in scripting mode.
- Add macro expansion decls to the source lookup cache with name-driven lazy expansion. Not supporting arbitrary name yet.
- Experimental support for script mode and brace-level declaration macro expansions: When type-checking a `MacroExpansionExpr`, assign it a substitute `MacroExpansionDecl` if the macro reference resolves to a declaration macro. This doesn’t work quite fully yet and will be enabled in a future fix.
2023-03-06 07:15:20 -08:00
Sophia Poirier
cdde853663 [Variadic Generics] fix diagnostics dangling reference and fixits for parameter pack syntax change: T... -> each T 2023-03-04 10:01:16 -08:00
Ben Barham
80d27128d8 [Macros] Do not edit macro buffer or position when refactoring
Rather than editing the macro buffer in refactoring, add appropriate
padding and braces when creating the macro.

Don't edit the insertion location - we should update this in a later PR
as well.
2023-03-03 19:48:06 -08:00