Commit Graph

153 Commits

Author SHA1 Message Date
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
Ben Barham
1fdda023b3 Rename StringRef::endswith references to StringRef::ends_with
Missed this when doing the `startswith` renaming. `endswith` has also
been deprecated upstream (and presumably soon to be removed).
2024-04-01 10:59:16 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
swift-ci
556272e95f Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 21:54:26 -07:00
Becca Royal-Gordon
78127ce5ee Diagnose possible enum common-prefix mistakes
Clang Importer strips prefixes from enum and option set case names. The logic to do this computes a common prefix from the type name and all non-deprecated case names (to oversimplify), which means that adding, removing, or changing one case can change the prefix that is removed from *all* cases. This typically causes the prefix to become shorter, meaning that additional words are prepended to each existing case name.

Existing diagnostics make it look like the case has disappeared, when in fact it still exists under a different name. A little more information may help developers to figure out what happened.

Add a tailored diagnostic for this scenario which kicks in when (a) a missing member is diagnosed, (b) the base is an imported enum or option set’s metatype, and (c) an enum case or static property exists which has the name we attempted to look up as a suffix.

Fixes rdar://116251319.
2023-10-02 16:50:54 -07:00
Evan Wilde
f3cd71d2d1 [NFC] updating StringRef API
`StringRef::endswith_insensitive` and
`StringRef::startswith_insensitive` is deprecated and being replaced
with `StringRef::ends_with_insensitive` and
`StringRef::starts_with_insensitive` respectively.
2023-07-25 12:28:28 -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
Ben Barham
ee3a47b624 [Frontend] Ignore adjacent swiftmodule in compiler host modules
`lib/swift/host` contains modules/libraries that are built by the host
compiler. Their `.swiftmodule` will never be able to be read, ignore
them entirely.
2023-06-12 16:53:48 -07:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Artem Chikin
57518b5894 Do not escape UNICODE when writing out target info.
Escaping unicode characters results in invalid JSON.

- Refactor writeEscaped routine into StringExtras

Resolves rdar://90108531
2022-03-16 15:30:21 -07:00
Ben Langmuir
5ce7bf9c18 Use std::reverse_iterator_range
We're using c++14, so no need to use the llvm:: copy of this. The llvm
version is going away, so this fixes build errors on the "next" branch.
2022-02-24 13:49:28 -08:00
Rintaro Ishizaki
7ef93b2a67 [Basic] Move copyCString to Basic/StringExtras.
Also, use StringRef.copy() instead of copyString().
2022-02-18 11:34:45 -08:00
Evan Wilde
42ff140171 llvm::StringRef equals_lower -> equals_insensitive
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.

Ran git clang-format.

(cherry picked from commit e21e70a6bf)
2021-07-02 10:55:17 -07:00
Evan Wilde
0919c2cd70 StringRef ends/startswith-lower -> insensitive
Updating StringRef startswith and endswith API to use insensitive rather
than lower.

(cherry picked from commit 1b8b39e6de)
2021-07-02 10:55:17 -07:00
Doug Gregor
ae3049f4b9 [Importer] Make sure we drop "WithBlock" as a completion-handler suffix.
Fixes rdar://73641827.
2021-02-09 15:00:32 -08:00
Robert Widmann
17a2bc5212 [NFC] Use std::mismatch Now That We Live In The Future 2020-12-08 18:20:20 -08:00
Doug Gregor
719e2201c8 [Concurrency] Move "extra" text from completion handler parameter to base name.
When a completion-handler parameter has text before, e.g.,
"WithCompletionHandler", put the extra text on the base name rather
than the corresponding parameter. This ensures that we don't lose the
detail from the text, but always put it into a consistent place.
2020-12-07 16:47:31 -08:00
Doug Gregor
b837675910 [Concurrency] Introduce more completion-handler names to the import heuristics.
Extend the set of completion-handler names we look for to infer an
`async` import of an Objective-C method, which includes:

* (with)CompletionBlock
* (with)reply
* (with)replyTo

both as parameter names and as base name suffixes.
2020-12-07 16:47:31 -08:00
Doug Gregor
16104d8045 [Concurrency] Don't lose name information from completion-handler arguments.
When a completion handler parameter has a selector piece that ends with
"WithCompletion(Handler)", prepend the text before that suffix to the
base name or previous argument label, as appropriate. This ensures that
we don't lose information from the name, particularly with delegate names.
2020-10-22 13:32:03 -07:00
Doug Gregor
8521453af3 [Concurrency] Drop "Asynchronously" suffix from imported 'async' methods.
The "Asynchronously" is a needless word for an "async" function. Remove
it.
2020-10-21 21:57:30 -07:00
Doug Gregor
24ea8becc8 [Concurrency] Move removal of leading "get" for async imports.
Name adjustments should be performed by omitNeedlessWords(), not the
early classifcation of async imports.
2020-10-21 21:48:52 -07:00
Jordan Rose
9ecd9abc84 Merge pull request #27750 from jrose-apple/omit-more-needle-swords
Further simplifications to omitNeedlessWords
2019-10-17 10:33:43 -07:00
Jordan Rose
e24c9e755d omitNeedlessWords: Fix self-type-stripping regression (#27742)
Turns out self-type-stripping /always/ operates on a type without
prefixes rather than /never/. Neither of these behaviors are really
what we'd want, but we'll live with it!

rdar://problem/56334797
2019-10-17 09:46:56 -07:00
Jordan Rose
f93811ae24 omitNeedlessWords: use drop_back to simplify suffix stripping 2019-10-16 19:55:48 -07:00
Jordan Rose
2465f5c2c3 omitNeedlessWords: Remove dead code from base name splitting
"and" is not a preposition, so we'll never get a false preposition
match for "and return".
2019-10-16 19:55:48 -07:00
Jordan Rose
6db1e020c2 omitNeedlessWords: Avoid an extra temporary SmallString
Yeah, SmallVectorImpl<char> is less convenient to work with, but
that's no reason to write out a stack buffer and then do a copy.

No functionality change.
2019-10-16 19:55:47 -07:00
Jordan Rose
1ef99c533c omitNeedlessWords: don't bother lowercasing an intermediate name
All of the remaining name-matching logic is case-insensitive, and
the resulting name will have a stronger form of lowercasing applied
anyway, so we can leave the name with a leading uppercase letter in
its intermediate state. Slightly less pure, but also slightly less
code and slightly less memory use.
2019-10-16 19:55:47 -07:00
Jordan Rose
a5d521698c omitNeedlessWords: separate BaseName in trailing type name matching
Method base names are where the most complicated logic is, so let's
split it out from the other cases a bit. Also makes early returns more
explicit.

No intended functionality change.
2019-10-16 19:55:47 -07:00
Jordan Rose
0f071e28ea Simplify getPrepositionKind to isPreposition
No one was distinguishing directional and non-directional prepositions
anymore. No functionality change.
2019-10-16 19:55:46 -07:00
Jordan Rose
86de8b8257 omitNeedlessWords: Rename helper: omitTrailingTypeNameWithSpecialCases
Previously this was /also/ called 'omitNeedlessWords'. Rename it to
avoid confusion and better describe the particular step it's taking.

I don't love the "with special cases" but I think it's important to
note that this isn't an exact parallel of matchLeadingTypeName.
2019-10-10 10:48:14 -07:00
Jordan Rose
758e727e07 omitNeedlessWords: Use existing helpers getPriorStr and getRestOfStr
...rather than asking WordIterators for their position and then
immediately calling StringRef::substr.

No functionality change.
2019-10-10 10:48:13 -07:00
Jordan Rose
e1e885ed7d omitNeedlessWords: delete accidentally dead code
StringRef::drop_back returns a new string instead of mutating the
existing one, so this check would never actually make a
difference. Drat.
2019-10-10 10:48:13 -07:00
Jordan Rose
42f7a35c4d omitNeedlessWords: sink helper enum into .cpp file
No functionality change.
2019-10-10 10:48:12 -07:00
Jordan Rose
3fdbd1b154 omitNeedlessWords: split out BaseNameSelf omission
This is the only omission kind that needs to look in the middle of a
name rather than just at the start or the end. So, handle that
explicitly instead to simplify all the other code.
2019-10-10 10:48:12 -07:00
Jordan Rose
981d1a9fab omitNeedlessWords: Factor out matchTypeNameFromBackWithSpecialCases
Separate the functional searching bit from the actual "omitting" bit
once the type name is matched. This in turn provides a good place to
flip from reverse iterators back to forward iterators, making the
following code about omitting a fair bit clearer.

No functionality change. This is 90% moving things around and 10%
rephrasing.
2019-10-10 10:48:11 -07:00
Jordan Rose
e22d55d27b omitNeedlessWords: Early exit instead of using a big if
Also, use Optional instead of a value and a separate flag.

No functionality change.
2019-10-10 10:48:11 -07:00
Sam Lazarus
2a38b48eea Parse / AST: Allow let / var as argument labels with a warning.
The diagnostic is now a warning and the new message alerts the user that
though it is valid to have let and var as argument label names,
they are interpreted as argument labels, not keywords.
2019-04-26 04:08:01 -04:00
Sho Ikeda
b506cbadb2 Merge pull request #15205 from ikesyo/stringextras-stringswitch
[NFC][StringExtras] Use llvm::StringSwitch in canBeArgumentLabel as with canBeMemberName
2018-03-16 11:58:28 +09:00
Sho Ikeda
521b6598a7 [NFC][StringExtras] Use llvm::StringSwitch in canBeArgumentLabel as with canBeMemberName 2018-03-14 00:59:39 +09:00
Sho Ikeda
eaf33e0998 [gardening][lib/Basic] Replace typedef with using 2018-03-13 13:46:38 +09:00
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
16165482f4 [gardening] Eliminate dead never read variable. Found with clang-tidy. 2016-12-06 23:54:23 -08:00
Michael Gottesman
1af1cbfb76 [gardening] Add a bunch of end namespace comments found by clang-tidy. 2016-12-06 19:22:52 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
17503b0d85 [gardening] Use American English. 2016-11-06 10:12:04 +01:00
Robert Widmann
6accc5989e Disable the ability to use '$' as an identifier harder
When in Swift 3 Compatibility Mode we now acceptable a standalone
'$' as an identifier.  In all other cases this is now disallowed
and must be surrounded by backticks.
2016-10-27 16:51:18 -04:00
Joe Groff
aac85cb93f SIL: Introduce a 'closure' convention for unapplied invocation functions.
We don't want the machine calling conventions for closure invocation functions to necessarily be tied to the convention for normal thin functions or methods. NFC yet; for now, 'closure' follows the same behavior as the 'method' convention, but as part of partial_apply simplification it will be a requirement that partial_apply takes a @convention(closure) function and a box and produces a @convention(thick) function from them.
2016-10-17 15:55:04 -07:00
Ben Langmuir
04107ed8b2 Revert "[omit-needless-words] Fix a bug found by -Wunused-result" 2016-09-14 14:27:32 -07:00