Skip to content

Commit 1e03ecc

Browse files
committed
Merge branch 'main' into castmessage-whentypenotfound
2 parents a1e8d29 + 7583850 commit 1e03ecc

File tree

83 files changed

+1809
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1809
-315
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private struct CollectedEffects {
329329

330330
/// Adds effects to a specific value.
331331
///
332-
/// If the value comes from an argument (or mutliple arguments), then the effects are added
332+
/// If the value comes from an argument (or multiple arguments), then the effects are added
333333
/// to the corrseponding `argumentEffects`. Otherwise they are added to the `global` effects.
334334
private mutating func addEffects(_ effects: SideEffects.GlobalEffects, to value: Value) {
335335
addEffects(effects, to: value, fromInitialPath: defaultPath(for: value))

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ReleaseDevirtualizer.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ private func tryDevirtualizeRelease(
107107
// argument.
108108
let functionRef = builder.createFunctionRef(dealloc)
109109

110-
let substitutionMap = context.getContextSubstitutionMap(for: type)
110+
let substitutionMap: SubstitutionMap
111+
if dealloc.isGenericFunction {
112+
substitutionMap = context.getContextSubstitutionMap(for: type)
113+
} else {
114+
// In embedded Swift, dealloc might be a specialized deinit, so the substitution map on the old apply isn't valid for the new apply
115+
substitutionMap = SubstitutionMap()
116+
}
117+
111118
builder.createApply(function: functionRef, substitutionMap, arguments: [beginDealloc])
112119
context.erase(instruction: lastRelease)
113120
}

SwiftCompilerSources/Sources/SIL/Test.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//
3535
// CASE STUDY:
3636
// Here's an example of how it works:
37-
// 0) A source file, NeatUtils.cpp contains
37+
// 0) A source file, NeatUtils.swift contains
3838
//
3939
// fileprivate func myNeatoUtility(int: Int, value: Value, function: Function) { ... }
4040
//

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ ERROR(could_not_find_enum_case,none,
104104
"enum type %0 has no case %1; did you mean %2?",
105105
(Type, DeclNameRef, DeclName))
106106

107+
ERROR(could_not_find_imported_enum_case,none,
108+
"type %0 has no case %1, but it does have a case named %2; if %1 worked "
109+
"before, a recent change to the underlying C enum may have affected how "
110+
"prefixes are stripped from its case names",
111+
(Type, DeclNameRef, ValueDecl *))
112+
107113
NOTE(did_you_mean_raw_type,none,
108114
"did you mean to specify a raw type on the enum declaration?", ())
109115

@@ -1730,6 +1736,9 @@ NOTE(fixit_add_private_for_objc_implementation,none,
17301736
NOTE(fixit_add_final_for_objc_implementation,none,
17311737
"add 'final' to define a Swift %0 that cannot be overridden",
17321738
(DescriptiveDeclKind))
1739+
NOTE(fixit_add_nonobjc_for_objc_implementation,none,
1740+
"add '@nonobjc' to define a Swift-only %0",
1741+
(DescriptiveDeclKind))
17331742

17341743
ERROR(objc_implementation_wrong_category,none,
17351744
"%kind0 should be implemented in extension for "

include/swift/Basic/StringExtras.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ namespace swift {
223223

224224
reverse_iterator rbegin() const { return reverse_iterator(end()); }
225225
reverse_iterator rend() const { return reverse_iterator(begin()); }
226+
227+
bool hasWordStartingAt(unsigned targetPosition) const;
226228
};
227229

228230
/// Retrieve the camelCase words in the given string.
@@ -236,6 +238,10 @@ namespace swift {
236238
/// case of the first letter.
237239
bool startsWithIgnoreFirstCase(StringRef word1, StringRef word2);
238240

241+
/// Check whether the first word ends with the second word, ignoring the
242+
/// case of the first word (handles initialisms).
243+
bool hasWordSuffix(StringRef haystack, StringRef needle);
244+
239245
/// Lowercase the first word within the given camelCase string.
240246
///
241247
/// \param string The string to lowercase.

include/swift/IDE/CompletionLookup.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
105105
TypeInDeclContext,
106106
ImportFromModule,
107107
GenericRequirement,
108+
109+
/// Look up stored properties within a type.
110+
StoredProperty,
108111
};
109112

110113
LookupKind Kind;
@@ -528,6 +531,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
528531
void getValueExprCompletions(Type ExprType, ValueDecl *VD = nullptr,
529532
bool IsDeclUnapplied = false);
530533

534+
/// Add completions for stored properties of \p D.
535+
void getStoredPropertyCompletions(const NominalTypeDecl *D);
536+
531537
void collectOperators(SmallVectorImpl<OperatorDecl *> &results);
532538

533539
void addPostfixBang(Type resultType);

include/swift/Parse/IDEInspectionCallbacks.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,25 @@ enum class CustomSyntaxAttributeKind {
3636
Available,
3737
FreestandingMacro,
3838
AttachedMacro,
39+
StorageRestrictions
40+
};
41+
42+
/// A bit of a hack. When completing inside the '@storageRestrictions'
43+
/// attribute, we use the \c ParamIndex field to communicate where inside the
44+
/// attribute we are performing the completion.
45+
enum class StorageRestrictionsCompletionKind : int {
46+
/// We are completing directly after the '(' and require a 'initializes' or
47+
/// 'accesses' label.
48+
Label,
49+
/// We are completing in a context that only allows arguments (ie. accessed or
50+
/// initialized variables) and doesn't permit an argument label.
51+
Argument,
52+
/// Completion in a context that allows either an argument or the
53+
/// 'initializes' label.
54+
ArgumentOrInitializesLabel,
55+
/// Completion in a context that allows either an argument or the
56+
/// 'accesses' label.
57+
ArgumentOrAccessesLabel
3958
};
4059

4160
/// Parser's interface to code completion.

include/swift/SIL/SILFunctionConventions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ class SILFunctionConventions {
214214
return getSILType(funcTy->getErrorResult(), context);
215215
}
216216

217+
bool isTypedError() const {
218+
return !funcTy->getErrorResult()
219+
.getInterfaceType()->isExistentialWithError();
220+
}
221+
217222
/// Returns an array of result info.
218223
/// Provides convenient access to the underlying SILFunctionType.
219224
ArrayRef<SILResultInfo> getResults() const {

include/swift/Sema/SyntacticElementTarget.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class SyntacticElementTarget {
147147
ForEachStmt *stmt;
148148
DeclContext *dc;
149149
Pattern *pattern;
150-
bool bindPatternVarsOneWay;
150+
bool ignoreWhereClause;
151151
ForEachStmtInfo info;
152152
} forEachStmt;
153153

@@ -227,11 +227,11 @@ class SyntacticElementTarget {
227227
}
228228

229229
SyntacticElementTarget(ForEachStmt *stmt, DeclContext *dc,
230-
bool bindPatternVarsOneWay)
230+
bool ignoreWhereClause)
231231
: kind(Kind::forEachStmt) {
232232
forEachStmt.stmt = stmt;
233233
forEachStmt.dc = dc;
234-
forEachStmt.bindPatternVarsOneWay = bindPatternVarsOneWay;
234+
forEachStmt.ignoreWhereClause = ignoreWhereClause;
235235
}
236236

237237
/// Form a target for the initialization of a pattern from an expression.
@@ -249,7 +249,7 @@ class SyntacticElementTarget {
249249
/// Form a target for a for-in loop.
250250
static SyntacticElementTarget forForEachStmt(ForEachStmt *stmt,
251251
DeclContext *dc,
252-
bool bindPatternVarsOneWay);
252+
bool ignoreWhereClause = false);
253253

254254
/// Form a target for a property with an attached property wrapper that is
255255
/// initialized out-of-line.
@@ -469,10 +469,6 @@ class SyntacticElementTarget {
469469
bool shouldBindPatternVarsOneWay() const {
470470
if (kind == Kind::expression)
471471
return expression.bindPatternVarsOneWay;
472-
473-
if (kind == Kind::forEachStmt)
474-
return forEachStmt.bindPatternVarsOneWay;
475-
476472
return false;
477473
}
478474

@@ -521,6 +517,11 @@ class SyntacticElementTarget {
521517
return expression.initialization.patternBindingIndex;
522518
}
523519

520+
bool ignoreForEachWhereClause() const {
521+
assert(isForEachStmt());
522+
return forEachStmt.ignoreWhereClause;
523+
}
524+
524525
const ForEachStmtInfo &getForEachStmtInfo() const {
525526
assert(isForEachStmt());
526527
return forEachStmt.info;

lib/Basic/StringExtras.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ void WordIterator::computePrevPosition() const {
215215
PrevPositionValid = true;
216216
}
217217

218+
bool camel_case::Words::hasWordStartingAt(unsigned targetPosition) const {
219+
// Iterate over the words until we see one at or past targetPosition.
220+
// FIXME: Is there a faster way to do this by looking at the characters around
221+
// the position?
222+
for (auto i = begin(); i != end() && i.getPosition() <= targetPosition; i++) {
223+
if (i.getPosition() == targetPosition)
224+
return true;
225+
}
226+
return false;
227+
}
228+
218229
StringRef camel_case::getFirstWord(StringRef string) {
219230
if (string.empty())
220231
return "";
@@ -249,6 +260,30 @@ bool camel_case::startsWithIgnoreFirstCase(StringRef word1, StringRef word2) {
249260
return word1.substr(1, word2.size() - 1) == word2.substr(1);
250261
}
251262

263+
bool camel_case::hasWordSuffix(StringRef haystack, StringRef needle) {
264+
// Is it even possible for one to be a suffix of the other?
265+
if (needle.empty() || haystack.size() <= needle.size())
266+
return false;
267+
268+
// Does haystack have a word boundary at the right position?
269+
auto targetPosition = haystack.size() - needle.size();
270+
if (!Words(haystack).hasWordStartingAt(targetPosition))
271+
return false;
272+
273+
StringRef suffix = haystack.substr(targetPosition);
274+
275+
// Fast path: Without potentially copying the strings, do they match?
276+
if (sameWordIgnoreFirstCase(suffix, needle))
277+
return true;
278+
279+
// Flatten out leading initialisms. Do they match?
280+
SmallString<32> suffixScratch, needleScratch;
281+
auto suffixFlat = toLowercaseInitialisms(suffix, suffixScratch);
282+
auto needleFlat = toLowercaseInitialisms(needle, needleScratch);
283+
284+
return suffixFlat == needleFlat;
285+
}
286+
252287
StringRef camel_case::toLowercaseWord(StringRef string,
253288
SmallVectorImpl<char> &scratch) {
254289
if (string.empty())

0 commit comments

Comments
 (0)