Commit Graph

73 Commits

Author SHA1 Message Date
Alex Hoppen
10b9daf2b5 [Refactoring] Split ConvertToComputedProperty to its own file 2023-09-11 16:59:27 -07:00
Alex Hoppen
00eaf741ff [Refactoring] Move TrailingClosure to its own file 2023-09-11 16:57:26 -07:00
Alex Hoppen
c7120f466e [Refactoring] Move SimplifyNumberLiteral to its own file 2023-09-11 16:55:53 -07:00
Alex Hoppen
5dc7a79a57 [Refactoring] Move ConvertToDoCatch to its own file 2023-09-11 16:54:32 -07:00
Alex Hoppen
1be0c50acf [Refactoring] Move AddExplicitCodableImplementation to its own file 2023-09-11 16:53:00 -07:00
Alex Hoppen
fdf2586600 [Refactoring] Move AddEquatableConformance to its own file 2023-09-11 16:51:10 -07:00
Alex Hoppen
a48d0f2579 [Refactoring] Move MemberwiseInitLocalRefactoring to its own file 2023-09-11 16:45:31 -07:00
Alex Hoppen
7e87813345 [Refactoring] Move LocalizeString to its own file 2023-09-11 16:43:59 -07:00
Alex Hoppen
94ab95e8c8 [Refactoring] Move ExpandSwitchCases and ExpandDefault to their own file 2023-09-11 16:42:29 -07:00
Alex Hoppen
ef4ee95e24 [Refactoring] Move FillProtocolStubs to its own file 2023-09-11 16:38:01 -07:00
Alex Hoppen
d09be617d2 [Refactoring] Move ExpandTernaryExpr to its own file 2023-09-11 16:35:16 -07:00
Alex Hoppen
563674f888 [Refactoring] Move ExtractExpr to its own file 2023-09-11 16:32:54 -07:00
Alex Hoppen
98f40197a6 [Refactoring] Move ExtractFunction to its own file 2023-09-11 16:31:09 -07:00
Alex Hoppen
d7ada702a2 [Refactoring] Extract Renamer to its own file 2023-09-11 16:24:07 -07:00
Alex Hoppen
53694024fc [Refactoring] Move ConvertIfLetExprToGuardExpr to its own file 2023-09-11 16:04:24 -07:00
Alex Hoppen
308270c1c5 [Refactoring] Move ConvertGuardExprToIfLetExpr to its own file 2023-09-11 16:02:45 -07:00
Alex Hoppen
fc3f7a0629 [Refactoring] Move ConvertToTernaryExpr to its own file 2023-09-11 16:01:01 -07:00
Alex Hoppen
a45cd0305d [Refactoring] Move ExtractRepeatedExpr and ConvertToSwitchStmt to its own file 2023-09-11 15:59:04 -07:00
Alex Hoppen
da69dc566b [Refactoring] Move MoveMembersToExtension to a separate file 2023-09-11 15:30:10 -07:00
Alex Hoppen
514d20a665 [Refactoring] Move ReplaceBodiesWithFatalError to separate file 2023-09-11 15:27:35 -07:00
Alex Hoppen
ec71836b17 [Refactoring] Extract CollapseNestedIfStmt to its own file 2023-09-11 15:25:01 -07:00
Alex Hoppen
6b2e54dc54 Extract RefactoringActionConvertStringsConcatenationToInterpolation to its own file 2023-09-11 15:21:28 -07:00
Alex Hoppen
d5b29f2956 Split definition of refactoring actions to its own header file 2023-09-11 15:19:27 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
Manu
02b5fa2c8e Fix some typos in the codebase 2023-08-31 18:50:10 -03:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Holly Borla
c3e214cbde [Macros] Expand conformance macros as extension macros.
ConformanceMacro now refines ExtensionMacro, so these roles can share
the same expansion request.
2023-06-30 14:25:14 -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
Doug Gregor
a1464cfc2e Correctly remove properties subsumed by init accessors from memberwise inits
The code to remove these subsumed properties was part of creating the
memberwise initializer declaration, which could lead to
inconsistencies with the newly-introduced request for gathering the
memberwise-initialized properties. Move the code into the computation
of the list of memberwise-initialized properties.

Also update a few more places that were effectively recomputing the
set of memberwise-initialized properties themselves over to the
request.
2023-06-23 11:34:54 -07:00
Doug Gregor
e89fdd3084 Requestify the computation of the list of memberwise initialized properties.
Fixes rdar://110776763, a case where initialized stored properties
introduced by peer macros weren't working alongside declared stored
properties.
2023-06-23 11:34:52 -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
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
Holly Borla
b958e43528 [Macros] Remove ModuleDecl::isInGeneratedBuffer.
This method was misleading. The majority of callers (all but one!) don't want
to unconditionally treat all locations in any macro expansion buffer the
same way, because the code also must handle nested macro expansions. There
is one part of SourceKit (and possibly others) that really do want to ignore
all macro expansions, but those can be handled within SourceKit / IDE code,
because I don't believe this utility is useful in the frontend.
2023-04-19 21:28:09 -07:00
Ben Barham
b9810fb0a3 [SourceKit] Return the original location for decls within generated code
Pass back the original location (ie. where the macro was expanded, not
the location that the generated code would be inserted) for cursor info
and indexing. Also mark any declarations/references within generated
source as implicit.

Resolves rdar://107209132.
2023-03-30 11:20:33 -07:00
Ben Barham
a1c8280d0f [SourceKit] Refactor collection of available refactorings
Update to have a single refactoring collection method for cursor
refactorings and another for ranges. The various functions were only
needed because of the extra availability information on renames, so just
give that to all refactorings.
2023-03-28 13:05:35 -07:00
Ben Barham
fd84ae98c2 Merge pull request #64367 from bnbarham/system-to-sdk
[SourceKit] Stop using `isSystemModule` to represent "non-user" modules
2023-03-17 10:15:04 -07:00
Ben Barham
eec2848508 [SourceKit] Stop using isSystemModule to represent "non-user" modules
Rather than using `ModuleDecl::isSystemModule()` to determine whether a
module is not a user module, instead check whether the module was
defined adjacent to the compiler or if it's part of the SDK.

If no SDK path was given, then `isSystemModule` is still used as a
fallback.

Resolves rdar://89253201.
2023-03-15 14:29:48 -07:00
Ben Barham
277674a642 Merge pull request #64298 from bnbarham/fix-shorthand-rename
[SourceKit] Merge local refactoring implementations
2023-03-14 10:36:44 -07:00
Ben Barham
d2de8ed83c [SourceKit] Merge local refactoring implementations
Retrieving local rename ranges and the local rename refactoring both had
almost identical methods, except for the addition of retrieving the
outermost shadowed decl that was added a couple months back. Merge them.

Resolves rdar://106529370.
2023-03-13 15:36:47 -07:00
Ben Barham
3e76a5edae [Refactoring] Allow expanding freestanding decl expansions 2023-03-09 10:11:11 -08:00
Ben Barham
daa80bba4b [CursorInfo] Handle @ and # position
Allow clients to send the position of @ or #, rather than just the name.

Resolves rdar://106368511.
2023-03-07 18:00:15 -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
Ben Barham
f3a6ce144c Merge pull request #63906 from bnbarham/add-nested-expansion
[Refactor] Allow expanding nested macros
2023-03-02 20:43:35 -08:00
Ben Barham
bb7760b9e0 [Refactor] Allow expanding nested macros
This adds a new `primary_file` key, which defaults to `sourcefile`. For
nested expansions, `primary_file` should be set to the containing file
and `sourcefile` to the name of the macro expansion buffer.
2023-03-02 14:04:46 -08:00
Ellie Shin
7d23db3646 Create PackageUnit class, and Package entries to DeclContext / ASTHierarchy
Previously enum AccessLimitKind was
added to distinguish access scopes b/t package and public while keeping
DeclContext null but it proved to be too limiting. This PR creates package specific entries for DeclContext and
ASTHierarchy. It create a new class PackageUnit that can be set as the parent DeclContext of ModuleDecl. This PR
contains addition of such entries but not the use of them; the actual use of them will be in the upcoming PRs.

Resolves rdar://106155600
2023-03-02 13:20:51 -08:00
Doug Gregor
eb06129463 [SourceKit] Add macro expansion support for conformance macros 2023-03-01 22:07:25 -08:00