Skip to content

[pull] swiftwasm from main #2341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig
doSomething(x: 0, y: 0) // argument labels are required
```

Unapplied references to functions or initializers no longer carry argument labels. For example:
Unapplied references to functions or initializers no longer carry argument labels. For example:

```swift
let f = doSomething(x:y:) // inferred type is now (Int, Int) -> Void
Expand Down
10 changes: 7 additions & 3 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5737,11 +5737,15 @@ static void addObserverKeywords(CodeCompletionResultSink &Sink) {
addKeyword(Sink, "didSet", CodeCompletionKeywordKind::None);
}

static void addExprKeywords(CodeCompletionResultSink &Sink) {
static void addExprKeywords(CodeCompletionResultSink &Sink,
bool IsConcurrencyEnabled) {
// Expr keywords.
addKeyword(Sink, "try", CodeCompletionKeywordKind::kw_try);
addKeyword(Sink, "try!", CodeCompletionKeywordKind::kw_try);
addKeyword(Sink, "try?", CodeCompletionKeywordKind::kw_try);
if (IsConcurrencyEnabled) {
addKeyword(Sink, "await", CodeCompletionKeywordKind::None);
}
}

static void addOpaqueTypeKeyword(CodeCompletionResultSink &Sink) {
Expand Down Expand Up @@ -5808,7 +5812,7 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
case CompletionKind::ForEachSequence:
addSuperKeyword(Sink);
addLetVarKeywords(Sink);
addExprKeywords(Sink);
addExprKeywords(Sink, Context.LangOpts.EnableExperimentalConcurrency);
addAnyTypeKeyword(Sink, CurDeclContext->getASTContext().TheAnyType);
break;

Expand Down Expand Up @@ -6635,7 +6639,7 @@ void CodeCompletionCallbacksImpl::doneParsing() {
addStmtKeywords(Sink, MaybeFuncBody);
addSuperKeyword(Sink);
addLetVarKeywords(Sink);
addExprKeywords(Sink);
addExprKeywords(Sink, Context.LangOpts.EnableExperimentalConcurrency);
addAnyTypeKeyword(Sink, Context.TheAnyType);
DoPostfixExprBeginning();
}
Expand Down
18 changes: 14 additions & 4 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,9 @@ bool ContextualFailure::diagnoseAsError() {
}

if (isExpr<AssignExpr>(anchor)) {
emitDiagnostic(diag::cannot_convert_assign, getFromType(), getToType());
auto diagnostic = emitDiagnostic(diag::cannot_convert_assign,
getFromType(), getToType());
tryIntegerCastFixIts(diagnostic);
return true;
}

Expand Down Expand Up @@ -2729,6 +2731,15 @@ bool ContextualFailure::tryIntegerCastFixIts(
auto fromType = getFromType();
auto toType = getToType();

auto anchor = getAnchor();
auto exprRange = getSourceRange();

if (auto *assignment = getAsExpr<AssignExpr>(anchor)) {
toType = toType->lookThroughAllOptionalTypes();
anchor = assignment->getSrc();
exprRange = assignment->getSrc()->getSourceRange();
}

if (!isIntegerType(fromType) || !isIntegerType(toType))
return false;

Expand All @@ -2747,8 +2758,8 @@ bool ContextualFailure::tryIntegerCastFixIts(
return parenE->getSubExpr();
};

if (auto *anchor = getAsExpr(getAnchor())) {
if (Expr *innerE = getInnerCastedExpr(anchor)) {
if (auto *expr = getAsExpr(anchor)) {
if (Expr *innerE = getInnerCastedExpr(expr)) {
Type innerTy = getType(innerE);
if (TypeChecker::isConvertibleTo(innerTy, toType, getDC())) {
// Remove the unnecessary cast.
Expand All @@ -2763,7 +2774,6 @@ bool ContextualFailure::tryIntegerCastFixIts(
std::string convWrapBefore = toType.getString();
convWrapBefore += "(";
std::string convWrapAfter = ")";
SourceRange exprRange = getSourceRange();
diagnostic.fixItInsert(exprRange.Start, convWrapBefore);
diagnostic.fixItInsertAfter(exprRange.End, convWrapAfter);
return true;
Expand Down
7 changes: 4 additions & 3 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3722,14 +3722,15 @@ bool ConstraintSystem::repairFailures(
if (lhs->is<FunctionType>() && rhs->is<FunctionType>())
return false;

// If either object type is a bound generic or existential it means
// that follow-up to value-to-optional is going to be:
// If either object type is a generic, nominal or existential type
// it means that follow-up to value-to-optional is going to be:
//
// 1. "deep equality" check, which is handled by generic argument(s)
// mismatch fix, or
// or contextual mismatch fix, or
// 2. "existential" check, which is handled by a missing conformance
// fix.
if ((lhs->is<BoundGenericType>() && rhs->is<BoundGenericType>()) ||
(lhs->is<NominalType>() && rhs->is<NominalType>()) ||
rhs->isAnyExistentialType())
return false;
}
Expand Down
3 changes: 0 additions & 3 deletions stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,11 @@ set(SWIFTLIB_SOURCES
Availability.swift
CollectionDifference.swift
CollectionOfOne.swift
DiscontiguousSlice.swift
Diffing.swift
FloatingPointRandom.swift
Mirror.swift
PlaygroundDisplay.swift
CommandLine.swift
RangeSet.swift
RangeSetStorage.swift
SliceBuffer.swift
SIMDVector.swift
UnfoldSequence.swift
Expand Down
64 changes: 0 additions & 64 deletions stdlib/public/core/CollectionAlgorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,70 +209,6 @@ extension BidirectionalCollection where Element: Equatable {
}
}

//===----------------------------------------------------------------------===//
// subranges(where:) / subranges(of:)
//===----------------------------------------------------------------------===//

extension Collection {
/// Returns the indices of all the elements that match the given predicate.
///
/// For example, you can use this method to find all the places that a
/// vowel occurs in a string.
///
/// let str = "Fresh cheese in a breeze"
/// let vowels: Set<Character> = ["a", "e", "i", "o", "u"]
/// let allTheVowels = str.subranges(where: { vowels.contains($0) })
/// // str[allTheVowels].count == 9
///
/// - Parameter predicate: A closure that takes an element as its argument
/// and returns a Boolean value that indicates whether the passed element
/// represents a match.
/// - Returns: A set of the indices of the elements for which `predicate`
/// returns `true`.
///
/// - Complexity: O(*n*), where *n* is the length of the collection.
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
public func subranges(where predicate: (Element) throws -> Bool) rethrows
-> RangeSet<Index>
{
if isEmpty { return RangeSet() }

var result = RangeSet<Index>()
var i = startIndex
while i != endIndex {
let next = index(after: i)
if try predicate(self[i]) {
result._append(i..<next)
}
i = next
}

return result
}
}

extension Collection where Element: Equatable {
/// Returns the indices of all the elements that are equal to the given
/// element.
///
/// For example, you can use this method to find all the places that a
/// particular letter occurs in a string.
///
/// let str = "Fresh cheese in a breeze"
/// let allTheEs = str.subranges(of: "e")
/// // str[allTheEs].count == 7
///
/// - Parameter element: An element to look for in the collection.
/// - Returns: A set of the indices of the elements that are equal to
/// `element`.
///
/// - Complexity: O(*n*), where *n* is the length of the collection.
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
public func subranges(of element: Element) -> RangeSet<Index> {
subranges(where: { $0 == element })
}
}

//===----------------------------------------------------------------------===//
// partition(by:)
//===----------------------------------------------------------------------===//
Expand Down
Loading