Commit Graph

2145 Commits

Author SHA1 Message Date
Ben Barham
193cbc95d6 [Test] Add target to new SK test (#63892)
This test uses a module built for the current target. The cursor info
request needs that target as well.
2023-02-24 10:26:04 -08:00
Ben Barham
6f31f84f70 Merge pull request #63790 from bnbarham/refactoring-use-sourceinfo
[Rename] Allow renaming of symbols from another module
2023-02-23 16:59:27 -08:00
Ben Barham
f7aaf02065 [SourceKit] Add an optional path and name to refactoring edits
Add two new fields to refactoring edits:
  - A file path if the edit corresponds to a buffer other than the
    original file
  - A buffer name when the edit is actually source of generated buffer

Macro expansions allow the former as a macro could expand to member
attributes, which may eg. add accessors to each member. The attribute
itself is inside the expansion, but the edit is to the member in the
original source.

The latter will later allow clients to send requests with these names to
allow semantic functionality inside synthesized buffers.
2023-02-22 16:24:02 -08:00
Ben Barham
45b1f9480a [Rename] Allow renaming of symbols from another module
Retrieve the serialized location when checking rename availablity so
that global rename works on references outside the module it was
declared in.

Resolves rdar://94671287.
2023-02-20 13:25:17 -08:00
Ben Barham
b2849551cc Merge pull request #63739 from bnbarham/add-sg-macros
[SymbolGraph] Generate symbol graphs for macro declarations
2023-02-17 10:23:22 -08:00
Ben Barham
0c3f538822 [AST] Allow ignoring macro expansions
Various requests expect to be walking over the current source file.
While we could add checks to all these to skip decls outside of the
current buffer, it's a little nicer to handle this during the walk
instead.

Allow ignoring nodes that are from macro expansions and add that flag to
the various walks that expect it.

Also add a new `getOriginalAttrs` that filters out attributes in
generated source.
2023-02-16 18:04:56 -08:00
Ben Barham
72fb01c0e1 [SymbolGraph] Generate symbol graphs for macro declarations 2023-02-16 17:59:29 -08:00
Holly Borla
f4b2b60446 [Macros] Enable global peer macros.
Global peer macro expansions are not injected into the AST. Instead, they
are visited as "auxiliary declarations" when needed, such as in the decl
checker and during SILGen. This is the same mechanism used for local property
wrappers and local lazy variables.
2023-02-14 16:24:25 -08:00
Ben Barham
2deaf1dc1a Merge pull request #63590 from bnbarham/reenable-sk-test
[Test] Re-enable and cleanup some cursor info tests
2023-02-13 21:44:37 -08:00
Doug Gregor
3b42b96db7 [Macros] Adjust whitespace for macro expansions that get returned 2023-02-13 16:08:28 -08:00
Doug Gregor
b882e0cb1e Add SourceKit support for expanding peer macros 2023-02-11 12:17:39 -08:00
Doug Gregor
a75b64e034 Add refactoring support for accessor macros 2023-02-11 11:23:28 -08:00
Doug Gregor
96380624db [SourceKit] Implement macro expansion for (some) attached macros.
Extend the macro-expansion refactoring to work with member and
member-attribute attached macros. These expansions can return several
different changes, e.g., adding new members, sprinkling member
attributes around, and so on.
2023-02-11 11:23:28 -08:00
Ben Barham
d206e1baa1 [Test] Re-enable and cleanup some cursor info tests
Re-enable `static_vs_class_spelling.swift` - it was just missing the
`-target` in the `sourcekitd-test` lines.

While here, cleanup all the cursor info tests that used `split_file` to
use `split-file` instead.

Resolves rdar://105287822.
2023-02-10 19:33:15 -08:00
Ben Barham
ff8f632f2b [Test] Temporarily disable failing test to unblock CI 2023-02-10 11:39:19 -08:00
Alex Hoppen
a9cba5457c [CursorInfo] Fix a bug that caused solver-based cursor info to crash if invoked on a symbol from a different module 2023-02-09 23:29:07 +01:00
Alex Hoppen
3e460630b7 [CursorInfo] Fix bug when performing solver-based cursor info on Self 2023-02-09 23:29:07 +01:00
Alex Hoppen
e7ee839189 [CursorInfo] A few miscellaneous fixes to the AST-based cursor info and new test cases
In these cases the solver-based and AST-based cursor info differed in their results. Fix the AST-based cursor info to return the correct results and add test cases to make sure the solver-based implementation doesn’t regress them.
2023-02-09 23:29:07 +01:00
Alex Hoppen
fcc5d98f1c [CursorInfo] Deliver results from solver-based cursor info
Running the SourceKit stress tester with verification of solver-based cursor info returned quite a few differences but in all of them, the old AST-based implementation was actually incorrect. So, instead of verifying  the results, deliver the results from solver-baesd cursor info and only fall back to AST-based cursor info if the solver-based implementation returned no results.

rdar://103369449
2023-02-07 14:53:54 +01:00
Alex Hoppen
75771c1579 Merge pull request #63387 from ahoppen/ahoppen/macros-swift-5
[Macros] Compile Macros tests with swift-version 5 instead of swift-version 4
2023-02-07 09:16:44 +01:00
Richard Wei
01e4c8df26 [Macros] Use name lookup for lazy declaration macro expansion (#63411)
- Use the name lookup table instead of adding members from a macro expansion to the parent decl context.
- Require declaration macros to specify introduced names and used the declared names to guide macro expansions lazily.
2023-02-07 11:24:42 +08:00
Alex Hoppen
3c67b06780 Merge pull request #62574 from ahoppen/ahoppen/reuse-ast-context
[SourceKit] Make sure we reuse ASTContext in function bodies for solver-based cursor info
2023-02-06 14:42:31 +01:00
Alex Hoppen
ba5a727983 [Macros] Compile Macros tests with swift-version 5 instead of swift-version 4 2023-02-04 11:10:08 +01:00
Alex Hoppen
9dfeb0a560 [CursorInfo] Fix a bug that caused incorrect discriminators to be assigned to values in completion-like cursor info 2023-02-04 08:51:41 +01:00
Alex Hoppen
a5f85ee10c [SourceKit] Make sure we reuse ASTContext in function bodies for solver-based cursor info
The main problem that prevented us from reusing the ASTContext was that we weren’t remapping the `LocToResolve` in the temporary buffer that only contains the re-parsed function back to the original buffer. Thus `NodeFinder` couldn’t find the node that we want to get cursor info for.

Getting AST reuse to work for top-level items is harder because it currently heavily relies on the `HasCodeCompletion` state being set on the parser result. I’ll try that in a follow-up PR.

rdar://103251263
2023-02-02 22:03:25 +01:00
Alex Hoppen
1ed94ff994 [SourceKit] Trigger generation of synthesized accessors in solver-based cursor info 2023-02-02 22:03:25 +01:00
Alex Hoppen
846a39d86b [IDE] Type check property wrappers so their USRs can be reported in cursor info 2023-02-02 22:03:25 +01:00
Alex Hoppen
ec1ca7f8eb [Sema] Pass self nominal type as a parameter to CheckRedeclarationRequest
The self nominal type decl needs to be passed as a parameter in here so this request doesn't tigger self nominal type computation, which results in an assertion failure.
2023-02-02 22:03:25 +01:00
Alex Hoppen
e47aea448e [SourceKit] Disable completion-like cursor info for ParamDecls 2023-02-02 22:03:25 +01:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Alex Hoppen
ab8b4a2b5d Merge pull request #62637 from ahoppen/ahoppen/stmtcondition-at-loc
[Sema] Teach typeCheckASTNodeAtLoc to check StmtConditionElement
2023-01-31 21:12:27 +01:00
Alex Hoppen
5469760b20 Merge pull request #62636 from ahoppen/ahoppen/always-sourcedocinfo
[SourceKit] Retrieve swiftsourcedocinfo for code completion request
2023-01-31 21:11:44 +01:00
Artem Chikin
4eefefa838 Merge pull request #62883 from artemcm/DepScanConcurrencyShims
Add an implicit dependency on the '_SwiftConcurrencyShims' library
2023-01-18 14:57:45 -08:00
Mishal Shah
9757ccfc45 Bump the Swift version to 5.9 (#63014) 2023-01-13 16:03:25 -08:00
Artem Chikin
c5e1b6baa9 Adjust tests to account for presence of implicit import of '_SwiftConcurrencyShims' 2023-01-13 11:20:35 -08:00
Pavel Yaskevich
945f35f7ca [BuilderTransform] Make sure that synthesized if elements have correct locations
Placeholder variable that represents result of `if` should be placed
at the beginning of the statement, same goes for `Optional(.some(...))`
that wraps the expression in "then" branch.

Resolves: https://github.com/apple/swift/issues/62848
2023-01-10 12:33:30 -08:00
Anthony Latsis
ea7662768e Parse: Use TypeRepr * instead of DeclNameRef in a note that points to an extension 2023-01-07 07:11:29 +03:00
Doug Gregor
db801afbe9 Handle null macro references in the semantic annotator 2023-01-04 10:56:57 -08:00
Doug Gregor
5936b7b585 Add test that started crashing with my initial rework of closure discriminators.
Thanks to Alex Hoppen for providing this test!
2023-01-02 21:22:05 -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
f78f5729c3 Start requiring expression macros to be marked with @expression 2022-12-22 09:18:05 -08:00
Alastair Houghton
da51c04116 Two of the macros tests are failing to import SwiftDiagnostics.
Disabling these for now, pending a fix.
2022-12-22 09:45:59 +00: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
07eb645159 [Sema] Teach typeCheckASTNodeAtLoc to check StmtConditionElement
Type checking a StmtConditionElement is slightly different than type checking the VarDecl declared by it because it doesn’t complain about redeclaration like `if let myVar = myVar`. Thus, we need to handle it in `typeCheckASTNodeAtLoc`
2022-12-16 11:24:36 +01:00
Alex Hoppen
c47a322b9a [SourceKit] Retrieve swiftsourcedocinfo for code completion request
We need swiftsourcedocinfo for cursor info and to be able to reuse the ASTContext from code completion for cursor info, we need to also retrieve the sourcedocinfo for code completion requests.
2022-12-16 11:22:43 +01:00
Alexis Laferrière
4aa857c153 [Test] Disable cursor-info.swift on non-asserts builds 2022-12-14 16:08:50 -08:00
Alex Hoppen
39f8fa5c1c [SourceKit] Pass target-triple in new SourceKit test
Fixes rdar://103268363
2022-12-13 12:56:25 +01:00
Ben Barham
acc462108b [Test] Temporarily disable failing test to unblock CI (#62536)
Tracking re-enabling in rdar://103268363.
2022-12-12 13:57:03 -08:00
Alex Hoppen
9a0a7722f9 [IDE] Disable a few code completion specific paths for solver-based CursorInfo
The lexer will be responsible for knowing whether we have a code completion token, everything else will also work for other IDE inspection features.

The changes start to really make sense once I rename CodeCompletion -> IDEInspection in a lot of places.
2022-12-10 12:12:21 +01:00
Alex Hoppen
e777d37e20 [SourceKit] Don't ignore swiftsourceinfo for solver-based cursor info
Cursor infor needs source info for referenced decls.
2022-12-08 14:39:15 +01:00