Commit Graph

2145 Commits

Author SHA1 Message Date
Kim de Vos
28df294e00 Remove spacing 2023-06-21 10:56:57 +02:00
Hamish Knight
a9f9bd1394 [SourceKit] Record module loading errors when generating interfaces
Record up to two errors emitted when we fail to
load a module for interface generation, and include
these errors in the message we pass back to the
editor. This should help us better pin down the
reason why interface generation failed.

rdar://109511099
2023-06-15 23:55:07 +01:00
QuietMisdreavus
e45c9df2a3 always use the argNames constructor for macro DeclNames (#66497)
rdar://110179186
2023-06-12 09:10:02 -06:00
Alex Hoppen
78d6822840 Merge pull request #66458 from ahoppen/ahoppen/consume-borrow-highlighting
[SourceKit] Highlight `consuming` and `borrowing` as keywords
2023-06-08 16:58:40 -07:00
Alex Hoppen
2ff585d6ff [SourceKit] Highlight consuming and borrowing as keywords 2023-06-08 10:59:42 -07:00
Rintaro Ishizaki
c3d1304345 [SourceKit] Add request to expand macros syntactically
Expand macros in the specified source file syntactically (without any
module imports, nor typechecking).

Request would look like:
```
{
  key.compilerargs: [...]
  key.sourcefile: <file name>
  key.sourcetext: <source text> (optional)
  key.expansions: [<expansion specifier>...]
}
```
`key.compilerargs` are used for getting plugins search paths. If
`key.sourcetext` is not specified, it's loaded from the file system.
Each `<expansion sepecifier>` is
```
{
  key.offset: <offset>
  key.modulename: <plugin module name>
  key.typename: <macro typename>
  key.macro_roles: [<macro role UID>...]
}
```
Clients have to provide the module and type names because that's
semantic.

Response is a `CategorizedEdits` just like (semantic) "ExpandMacro"
refactoring. But without `key.buffer_name`. Nested expnasions are not
supported at this point.
2023-06-07 14:26:40 -07:00
Doug Gregor
1ddecc00cc Merge pull request #66403 from DougGregor/remove-option-set 2023-06-07 06:49:39 -07:00
Doug Gregor
feb5c09d93 Remove OptionSet macro from the standard library. 2023-06-06 23:37:38 -07:00
Doug Gregor
70820749df Update mangled names in test case 2023-06-06 23:22:01 -07:00
Kim de Vos
d0b412e3eb Merge pull request #66106 from kimdv/kimdv/remove-newline-from-swift-syntax-code-gen
[SwiftSyntax] Remove `requiresLeadingNewline` from basic format
2023-05-30 21:32:50 +02:00
QuietMisdreavus
60ef958116 don't break a doc comment with a regular comment (#66136)
rdar://95307936
2023-05-30 08:44:02 -06:00
Kim de Vos
8140efb616 [SwiftSyntax] Remove requiresLeadingNewline from basic format 2023-05-30 09:53:33 +02:00
Richard Wei
7502f3ce83 [Macros] Fix existential diagnostics for declaration macro expansions
`TypeChecker::checkExistentialTypes` has decl-specific logic and backs out without invoking `ExistentialTypeVisitor` on `TypeDecl`s, but `MacroExpansionDecl` isn't a type decl and would fall into `ExistentialTypeVisitor` which will visit its expansion. The caller of `checkExistentialTypes` already visits auxiliary decls, so here we should only visit arguments and generic arguments of a macro.

Fixes a case where a declaration macro produces a type that conforms to a PAT. We now also run existential diagnostics on generic arguments on a `MacroExpansionDecl` that was previously not handled.

Note: I tried bailing out in `walkToDeclPre` but we should really visit macro arguments and generic arguments. Not walking expansions in `ExistentialTypeVisitor` is also not the right fix because we need to be able to visit macro expansions in arguments.

rdar://109779928
2023-05-25 23:25:58 -07:00
Doug Gregor
cfda29ccd4 [SE-0397] Enable freestanding declaration macros by default.
This proposal has been accepted. Move the feature flag from "experimental"
to "always enabled". Tracked by rdar://108637367.
2023-05-24 09:16:55 -07:00
Hamish Knight
5dd258f99f [Diags] Avoid emitting fix-its for generated code
Drop fix-its produced in generated buffers, such
as for macro expansions, as these aren't directly
actionable by the user.

rdar://108231633
2023-05-23 11:37:40 +01:00
Ben Barham
f97d1f2824 Merge pull request #65963 from bnbarham/change-member-attr-mangling
[AST] Use a different operator for member attribute macros
2023-05-18 23:21:39 -07:00
Ben Barham
515d22a486 [AST] Use a different operator for member attribute macros
Macro expansions are currently written to disk using the mangled name of
the macro. Do not use operators that only differ in case-sensitivity to
avoid issues on case-insensitive filesystems.

Resolves rdar://109371653.
2023-05-17 11:25:37 -07:00
Anthony Latsis
3f629315a9 Merge pull request #65731 from AnthonyLatsis/always-print-any
ASTPrinter: Turn on explicit `any` printing for everything and remove the option to disable it
2023-05-16 03:27:36 +03:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Ben Barham
d0c892297c [Test] Avoid verifying SILGen in cursor info test
Verifying SILGen causes `loadAllMembers` to be run, which in turn ends
up actually creating the parent PBD of each `VarDecl` in this test.
Without verification, we never deserialize that PBD and thus end up with
`class` instead of `static` as we should. That's incorrect, but it's an
existing failure (rdar://105239467).

Resolves rdar://109037827.
2023-05-09 13:29:32 -07:00
Ben Barham
01086bc8b5 Merge pull request #65688 from bnbarham/swap-cursor-info-order
[CursorInfo] Prefer AST based results over solver based
2023-05-05 16:54:25 -07:00
Ben Barham
5beeca7cf1 [CursorInfo] Prefer AST based results over solver based
Solver based results are fast within a function, where the `ASTContext`
can be re-used. But it is significantly slower than the AST based
results when outside of a function. Instead of using solver based as the
primary results, only use them as a fallback for when AST based fails.

Resolves rdar://108930110.
2023-05-04 20:53:38 -07:00
Hamish Knight
62b021030f [SourceKit] Include generated macro buffers in diagnostic responses
Introduce a new key `generated_buffers`, which
stores an array of generated buffers. These
include the buffer text, as well as its original
location and any parent buffers.

While here, also fix rdar://107281079 such that
only apply the filename fallback logic to the
pretty-printed Decl case. We ought to remove this
fallback once the editor can handle it though.

rdar://107281079
rdar://107952288
2023-05-02 16:21:44 +01:00
Keith Smiley
5e2c7a9d47 Revert "Fix RelBase indexing with composite types"
This crashes with typealiases referenced across files. I will resubmit
with a fix. See also https://github.com/apple/swift/pull/65545

This reverts commit 7a5e9dcf19.
2023-05-01 11:24:32 -07:00
swift-ci
404b925d8b Merge pull request #64997 from keith/ks/fix-relbase-indexing-with-composite-types
Fix RelBase indexing with composite types
2023-04-29 17:22:45 -07:00
Keith Smiley
7a5e9dcf19 Fix RelBase indexing with composite types
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes https://github.com/apple/swift/issues/56255
2023-04-29 12:46:31 -07:00
Rintaro Ishizaki
c5b72a8503 [SourceKit][Macros] Fix macro expansion test case for mangling change 2023-04-28 19:58:42 -07:00
Ben Barham
38f2e6c2b9 Merge pull request #65450 from bnbarham/format-macro-expansions
[Macros] Automatically format expanded macros
2023-04-28 16:21:33 -07:00
Ben Barham
fe2104ca99 [Macros] Automatically format expanded macros
Rather than requiring macro implementations to add required whitespace
and indentation, basic format all macro expansions. Right now this uses
the default four space indentation, we can consider having that inferred
later. Macros can opt-out of automatic formatting by implementing
`formatMode` and setting it to `.disabled`.

Also moves the extra newlines before/after expansions to a new "Inline
Macro" refactoring.

Resolves rdar://107731047.
2023-04-27 21:24:46 -07:00
Rintaro Ishizaki
35db928e89 [Macros] Requestify MacroExpansionExpr expansion
The request returns the expanded buffer ID even if it failed to
typecheck the expanded buffer.
This makes refactoring 'Expand Macro' work regardless of the
typechecking results.

rdar://108530760
2023-04-27 14:40:34 -07:00
Hamish Knight
a55ae621b0 Merge pull request #65265 from hamishknight/whats-up-doc 2023-04-26 21:18:07 +01:00
Hamish Knight
be31c22e58 Update to use --leading-lines for split-file 2023-04-26 12:38:38 +01:00
Hamish Knight
4606b14fea Refactor a couple of tests
Match the format of the spi and package variants of
these tests.
2023-04-26 12:38:38 +01:00
Hamish Knight
4e838e0a26 Serialize package and SPI doc comments in swiftsourceinfo
Previously we were using the same set of conditions
for serializing as for swiftdoc, so excluded them.
However it's reasonable to have them in the
swiftsourceinfo.
2023-04-26 12:38:38 +01:00
Alex Hoppen
6fcfe7fe28 [CursorInfo] Don’t crash if we are performing cursor info at EOF
When performing code completion at the end of a file, the IDE inspection target would point to the null byte terminating the end of the string. That would cause us to consider this null byte as a code completion marker. When continuing to scan for the actual EOF, we would walk past the end of the buffer.

Simply don’t consider the last null byte as a candidate for the code completion marker to fix the problem.
2023-04-24 15:24:59 -07:00
Alex Hoppen
aef35b917e [SourceKit] Expand editor placeholder to trailing closures inside a TryExpr
rdar://108391690
2023-04-21 17:21:50 -07:00
Rintaro Ishizaki
561b1c00fc [Tests] Disable flaky tests in ASAN environment 2023-04-18 10:01:04 -07:00
Rintaro Ishizaki
5e5c233e94 Merge pull request #65068 from rintaro/sourcekit-pluginpath-rdar107849796
[SourceKit] Pass 'swiftc' path to Driver when creating frontend args
2023-04-13 14:22:54 -07:00
Rintaro Ishizaki
3517db4c3b [SourceKit] Pass 'swiftc' path to Driver when creating frontend args
Driver uses its path to derive the plugin paths (i.e.
'lib/swift/host/plugins' et al.) Previously it was a constant string
'swiftc' that caused SourceKit failed to find dylib plugins in the
toolchain. Since 'SwiftLangSupport' knows the swift-frontend path,
use it, but replacing the filename with 'swiftc', to derive the plugin
paths.

rdar://107849796
2023-04-12 09:53:43 -07:00
Doug Gregor
a23d39bdfb [Macros] Mangle attached macro expansions based only on syntactic information
The mangling of attached macro expansions based on the declaration to
which they are attached requires semantic information (specifically,
the interface type of that declaration) that caused cyclic
dependencies during type checking. Replace the mangling with a
less-complete mangling that only requires syntactic information from
the declaration, i.e., the name of the declaration to which the macro
was attached.

This eliminates reference cycles that occur with attached macros that
produce arbitrary names.
2023-04-11 23:40:28 -04:00
Ben Barham
e5dbe300e4 Merge pull request #64986 from bnbarham/macro-completion
[Completion] Only provide macro completions when they are valid
2023-04-08 11:08:42 -07:00
Ben Barham
31dee1ce1c [Completion] Only provide macro completions when they are valid
Only return macros that are valid in their current position, ie. an
attached macro is not valid on a nominal.

Also return freestanding expression macros in code block item position
and handle the new freestanding code item macros.

Resolves rdar://105563583.
2023-04-07 18:43:06 -07:00
Doug Gregor
efd589018b Merge pull request #64942 from DougGregor/sil-symbol-visitor-aux-decls 2023-04-05 17:35:24 -07:00
Alex Lorenz
ce443011c0 Merge pull request #64924 from hyp/eng/cxx-interop-default-mode
[interop] support 'default' mode for '-cxx-interoperability-mode' option
2023-04-05 15:51:11 -07:00
Doug Gregor
27fbafc281 Fix test expected output harder 2023-04-05 14:05:40 -07:00
Doug Gregor
e77d6b2f3c Fixup test case 2023-04-05 13:29:04 -07:00
Alex Lorenz
00181138fd [interop] support 'default' mode for '-cxx-interoperability-mode' option
Default corresponds to the Swift language version used to compile the input. Swift-5.9 is still supported for now, but will be removed shortly
2023-04-04 15:35:48 -07:00
Ben Barham
e5a28caa9a [Test] Fix swift_swift_parser feature and use in tests
The macro tests were all using "REQUIRES: OS=macosx" as a proxy for
"have the Swift Swift parser". There was an existing feature for this,
but it was just checking whether the path was passed through. Fix that
to use the same variable as in CMake.

Also remove all extraneous `-I` and `-L` to the host libs in the target
invocations.
2023-04-03 09:25:03 -07:00
Richard Wei
eb8e984b97 [Macros] Private discriminators for outermost-private MacroExpansionDecl (#64813)
Add a private discriminator to the mangling of an outermost-private `MacroExpansionDecl` so that declaration macros in different files won't have colliding macro expansion buffer names.

rdar://107462515
2023-03-31 20:36:29 -07:00
Rintaro Ishizaki
9dc7ee8222 Merge pull request #64796 from rintaro/test-hosttriple-rdar107398734
[Test] Add %host_triple and %host_sdk substitutions
2023-03-31 10:43:31 -07:00