Skip to content

Commit 0955d72

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents bb10b2a + fda3dc5 commit 0955d72

File tree

12 files changed

+127
-120
lines changed

12 files changed

+127
-120
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,6 @@ ERROR(snake_case_deprecated,none,
960960
"%0 has been replaced with %1 in Swift 3",
961961
(StringRef, StringRef))
962962

963-
964963
// Assignment statement
965964
ERROR(expected_expr_assignment,none,
966965
"expected expression in assignment", ())
@@ -988,6 +987,10 @@ NOTE(indent_expression_to_silence,none,
988987
ERROR(expected_expr_throw,PointsToFirstBadToken,
989988
"expected expression in 'throw' statement", ())
990989

990+
// Await/Async
991+
ERROR(expected_await_not_async,none,
992+
"found 'async' in expression; did you mean 'await'?", ())
993+
991994
// Yield Statment
992995
ERROR(expected_expr_yield,PointsToFirstBadToken,
993996
"expected expression in 'yield' statement", ())

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
632632
///
633633
/// \param typeVariables This vector is populated with the set of
634634
/// type variables referenced by this type.
635-
void getTypeVariables(SmallVectorImpl<TypeVariableType *> &typeVariables);
635+
void getTypeVariables(SmallPtrSetImpl<TypeVariableType *> &typeVariables);
636636

637637
/// Determine whether this type is a type parameter, which is either a
638638
/// GenericTypeParamType or a DependentMemberType.

include/swift/Sema/Constraint.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,43 +381,45 @@ class Constraint final : public llvm::ilist_node<Constraint>,
381381
void *operator new(size_t) = delete;
382382

383383
Constraint(ConstraintKind kind, ArrayRef<Constraint *> constraints,
384-
ConstraintLocator *locator, ArrayRef<TypeVariableType *> typeVars);
384+
ConstraintLocator *locator,
385+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
385386

386387
/// Construct a new constraint.
387388
Constraint(ConstraintKind kind, Type first, Type second,
388389
ConstraintLocator *locator,
389-
ArrayRef<TypeVariableType *> typeVars);
390+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
390391

391392
/// Construct a new constraint.
392393
Constraint(ConstraintKind kind, Type first, Type second, Type third,
393394
ConstraintLocator *locator,
394-
ArrayRef<TypeVariableType *> typeVars);
395+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
395396

396397
/// Construct a new member constraint.
397398
Constraint(ConstraintKind kind, Type first, Type second, DeclNameRef member,
398399
DeclContext *useDC, FunctionRefKind functionRefKind,
399400
ConstraintLocator *locator,
400-
ArrayRef<TypeVariableType *> typeVars);
401+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
401402

402403
/// Construct a new value witness constraint.
403404
Constraint(ConstraintKind kind, Type first, Type second,
404405
ValueDecl *requirement, DeclContext *useDC,
405406
FunctionRefKind functionRefKind, ConstraintLocator *locator,
406-
ArrayRef<TypeVariableType *> typeVars);
407+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
407408

408409
/// Construct a new overload-binding constraint, which might have a fix.
409410
Constraint(Type type, OverloadChoice choice, DeclContext *useDC,
410411
ConstraintFix *fix, ConstraintLocator *locator,
411-
ArrayRef<TypeVariableType *> typeVars);
412+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
412413

413414
/// Construct a restricted constraint.
414415
Constraint(ConstraintKind kind, ConversionRestrictionKind restriction,
415416
Type first, Type second, ConstraintLocator *locator,
416-
ArrayRef<TypeVariableType *> typeVars);
417-
417+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
418+
418419
/// Construct a relational constraint with a fix.
419420
Constraint(ConstraintKind kind, ConstraintFix *fix, Type first, Type second,
420-
ConstraintLocator *locator, ArrayRef<TypeVariableType *> typeVars);
421+
ConstraintLocator *locator,
422+
SmallPtrSetImpl<TypeVariableType *> &typeVars);
421423

422424
/// Retrieve the type variables buffer, for internal mutation.
423425
MutableArrayRef<TypeVariableType *> getTypeVariablesBuffer() {

lib/AST/Type.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,13 @@ Type TypeBase::addCurriedSelfType(const DeclContext *dc) {
445445
return FunctionType::get({selfParam}, type);
446446
}
447447

448-
void
449-
TypeBase::getTypeVariables(SmallVectorImpl<TypeVariableType *> &typeVariables) {
448+
void TypeBase::getTypeVariables(
449+
SmallPtrSetImpl<TypeVariableType *> &typeVariables) {
450450
// If we know we don't have any type variables, we're done.
451451
if (hasTypeVariable()) {
452452
auto addTypeVariables = [&](Type type) -> bool {
453453
if (auto tv = dyn_cast<TypeVariableType>(type.getPointer())) {
454-
typeVariables.push_back(tv);
454+
typeVariables.insert(tv);
455455
}
456456

457457
return false;

lib/Parse/ParseExpr.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,17 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
399399
SyntaxParsingContext ElementContext(SyntaxContext,
400400
SyntaxContextKind::Expr);
401401

402-
if (Tok.isContextualKeyword("await")) {
403-
if (shouldParseExperimentalConcurrency()) {
402+
if (shouldParseExperimentalConcurrency()) {
403+
// A function called "async" is possible, so we don't want to replace it
404+
// with await.
405+
bool isReplaceableAsync = Tok.isContextualKeyword("async") &&
406+
!peekToken().is(tok::l_paren);
407+
if (Tok.isContextualKeyword("await") || isReplaceableAsync) {
408+
// Error on a replaceable async
409+
if (isReplaceableAsync) {
410+
diagnose(Tok.getLoc(), diag::expected_await_not_async)
411+
.fixItReplace(Tok.getLoc(), "await");
412+
}
404413
SourceLoc awaitLoc = consumeToken();
405414
ParserResult<Expr> sub =
406415
parseExprSequenceElement(diag::expected_expr_after_await, isExprBasic);
@@ -416,12 +425,12 @@ ParserResult<Expr> Parser::parseExprSequenceElement(Diag<> message,
416425
sub = makeParserResult(new (Context) AwaitExpr(awaitLoc, sub.get()));
417426
}
418427

419-
return sub;
420-
} else {
421-
// warn that future versions of Swift will parse this token differently.
422-
diagnose(Tok.getLoc(), diag::warn_await_keyword)
423-
.fixItReplace(Tok.getLoc(), "`await`");
428+
return sub;
424429
}
430+
} else if (Tok.isContextualKeyword("await")) {
431+
// warn that future versions of Swift will parse this token differently.
432+
diagnose(Tok.getLoc(), diag::warn_await_keyword)
433+
.fixItReplace(Tok.getLoc(), "`await`");
425434
}
426435

427436
SourceLoc tryLoc;

lib/Sema/CSBindings.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,9 @@ PotentialBindings ConstraintSystem::inferBindingsFor(TypeVariableType *typeVar,
830830
/// \returns the type to bind to, if the binding is okay.
831831
static Optional<Type> checkTypeOfBinding(TypeVariableType *typeVar, Type type) {
832832
// If the type references the type variable, don't permit the binding.
833-
SmallVector<TypeVariableType *, 4> referencedTypeVars;
833+
SmallPtrSet<TypeVariableType *, 4> referencedTypeVars;
834834
type->getTypeVariables(referencedTypeVars);
835-
if (count(referencedTypeVars, typeVar))
835+
if (referencedTypeVars.count(typeVar))
836836
return None;
837837

838838
// If type variable is not allowed to bind to `lvalue`,
@@ -940,21 +940,9 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
940940
if (type->getWithoutSpecifierType()
941941
->lookThroughAllOptionalTypes()
942942
->is<DependentMemberType>()) {
943-
SmallVector<TypeVariableType *, 4> referencedVars;
944-
type->getTypeVariables(referencedVars);
945-
946-
bool containsSelf = false;
947-
for (auto *var : referencedVars) {
948-
// Add all type variables encountered in the type except
949-
// to the current type variable.
950-
if (var != TypeVar) {
951-
AdjacentVars.insert(var);
952-
continue;
953-
}
954-
955-
containsSelf = true;
956-
}
943+
type->getTypeVariables(AdjacentVars);
957944

945+
bool containsSelf = AdjacentVars.erase(TypeVar);
958946
// If inferred type doesn't contain the current type variable,
959947
// let's mark bindings as delayed until dependent member type
960948
// is resolved.
@@ -979,11 +967,8 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
979967
// Check whether we can perform this binding.
980968
if (auto boundType = checkTypeOfBinding(TypeVar, type)) {
981969
type = *boundType;
982-
if (type->hasTypeVariable()) {
983-
SmallVector<TypeVariableType *, 4> referencedVars;
984-
type->getTypeVariables(referencedVars);
985-
AdjacentVars.insert(referencedVars.begin(), referencedVars.end());
986-
}
970+
if (type->hasTypeVariable())
971+
type->getTypeVariables(AdjacentVars);
987972
} else {
988973
auto *bindingTypeVar = type->getRValueType()->getAs<TypeVariableType>();
989974

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,7 +2471,7 @@ namespace {
24712471
// the type variable for the pattern `i`.
24722472
struct CollectVarRefs : public ASTWalker {
24732473
ConstraintSystem &cs;
2474-
llvm::SmallVector<TypeVariableType *, 4> varRefs;
2474+
llvm::SmallPtrSet<TypeVariableType *, 4> varRefs;
24752475
bool hasErrorExprs = false;
24762476

24772477
CollectVarRefs(ConstraintSystem &cs) : cs(cs) { }
@@ -2532,10 +2532,12 @@ namespace {
25322532
if (!inferredType || inferredType->hasError())
25332533
return Type();
25342534

2535-
CS.addUnsolvedConstraint(
2536-
Constraint::create(CS, ConstraintKind::DefaultClosureType,
2537-
closureType, inferredType, locator,
2538-
collectVarRefs.varRefs));
2535+
SmallVector<TypeVariableType *, 4> referencedVars{
2536+
collectVarRefs.varRefs.begin(), collectVarRefs.varRefs.end()};
2537+
2538+
CS.addUnsolvedConstraint(Constraint::create(
2539+
CS, ConstraintKind::DefaultClosureType, closureType, inferredType,
2540+
locator, referencedVars));
25392541

25402542
CS.setClosureType(closure, inferredType);
25412543
return closureType;

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10574,13 +10574,16 @@ ConstraintSystem::addArgumentConversionConstraintImpl(
1057410574
if (auto *argTypeVar = first->getAs<TypeVariableType>()) {
1057510575
if (argTypeVar->getImpl().isClosureType()) {
1057610576
// Extract any type variables present in the parameter's result builder.
10577-
SmallVector<TypeVariableType *, 4> typeVars;
10577+
SmallPtrSet<TypeVariableType *, 4> typeVars;
1057810578
if (auto builderTy = getOpenedResultBuilderTypeFor(*this, locator))
1057910579
builderTy->getTypeVariables(typeVars);
1058010580

10581+
SmallVector<TypeVariableType *, 4> referencedVars{typeVars.begin(),
10582+
typeVars.end()};
10583+
1058110584
auto *loc = getConstraintLocator(locator);
1058210585
addUnsolvedConstraint(
10583-
Constraint::create(*this, kind, first, second, loc, typeVars));
10586+
Constraint::create(*this, kind, first, second, loc, referencedVars));
1058410587
return SolutionKind::Solved;
1058510588
}
1058610589
}

0 commit comments

Comments
 (0)