82 Commits

Author SHA1 Message Date
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Apollo Zhu
b09a22a9a0 Somewhat working
Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2024-02-06 15:02:11 -08:00
Alex Hoppen
5d7200a0a1 [SourceKit] Remove the local rename refactoring action
Local refactoring should go through the `find-local-rename-ranges` request.
2023-11-16 16:05:08 -08:00
Alex Hoppen
ada3076628 [SourceKit] Share implemention of local rename and related idents
Local rename and related identifiers were sufficiently similar that we can implement related identifiers in terms of local rename.
2023-11-16 16:05:07 -08:00
Alex Hoppen
755655ac00 [Refactoring] Move FindRenameRangesAnnotatingConsumer to its own file 2023-09-11 19:06:24 -07:00
Alex Hoppen
cf71a105f2 [Refactoring] Move async refactorings into their own files 2023-09-11 19:05:00 -07:00
Alex Hoppen
3074dbe5c5 [Refactoring] Move LocalRename to its own file 2023-09-11 17:14:29 -07:00
Alex Hoppen
c05c573a04 [Refactoring] Move ExpandMacro and InlineMacro to their own file 2023-09-11 17:01:58 -07:00
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