Skip to content

Commit b87122d

Browse files
authored
Merge pull request #1098 from swiftwasm/master
[pull] swiftwasm from master
2 parents f292d2f + ef7da4d commit b87122d

26 files changed

+790
-38
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ SWIFT_TYPEID_NAMED(PatternBindingEntry *, PatternBindingEntry)
5757
SWIFT_TYPEID_NAMED(PostfixOperatorDecl *, PostfixOperatorDecl)
5858
SWIFT_TYPEID_NAMED(PrecedenceGroupDecl *, PrecedenceGroupDecl)
5959
SWIFT_TYPEID_NAMED(PrefixOperatorDecl *, PrefixOperatorDecl)
60+
SWIFT_TYPEID_NAMED(ProtocolConformance *, ProtocolConformance)
6061
SWIFT_TYPEID_NAMED(ProtocolDecl *, ProtocolDecl)
6162
SWIFT_TYPEID_NAMED(SourceFile *, SourceFile)
6263
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct PropertyWrapperTypeInfo;
5252
enum class CtorInitializerKind;
5353
struct PropertyWrapperLValueness;
5454
struct PropertyWrapperMutability;
55+
class ProtocolConformance;
5556
class ProtocolDecl;
5657
class Requirement;
5758
enum class ResilienceExpansion : unsigned;

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5069,6 +5069,14 @@ NOTE(function_builder_remove_attr, none,
50695069
"remove the attribute to explicitly disable the function builder", ())
50705070
NOTE(function_builder_remove_returns, none,
50715071
"remove 'return' statements to apply the function builder", ())
5072+
ERROR(function_builder_infer_ambig, none,
5073+
"ambiguous function builder inferred for %0: %1 or %2",
5074+
(DeclName, Type, Type))
5075+
NOTE(function_builder_infer_add_return, none,
5076+
"add an explicit 'return' statement to not use a function builder", ())
5077+
NOTE(function_builder_infer_pick_specific, none,
5078+
"apply function builder %0 (inferred from protocol %1)",
5079+
(Type, DeclName))
50725080

50735081
//------------------------------------------------------------------------------
50745082
// MARK: Tuple Shuffle Diagnostics

include/swift/AST/TypeCheckRequests.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ class ClosureHasExplicitResultRequest
22402240
bool isCached() const { return true; }
22412241
};
22422242

2243-
using ProtocolConformanceLookupResult = SmallVector<ProtocolConformance *, 2>;
2243+
using ProtocolConformanceLookupResult = std::vector<ProtocolConformance *>;
22442244
void simple_display(llvm::raw_ostream &out, ConformanceLookupKind kind);
22452245

22462246
/// Lookup and expand all conformances in the given context.
@@ -2262,7 +2262,7 @@ class LookupAllConformancesInContextRequest
22622262
: public SimpleRequest<LookupAllConformancesInContextRequest,
22632263
ProtocolConformanceLookupResult(
22642264
const IterableDeclContext *),
2265-
RequestFlags::Uncached |
2265+
RequestFlags::Cached |
22662266
RequestFlags::DependencySink |
22672267
RequestFlags::DependencySource> {
22682268
public:
@@ -2276,6 +2276,8 @@ class LookupAllConformancesInContextRequest
22762276
evaluate(Evaluator &evaluator, const IterableDeclContext *IDC) const;
22772277

22782278
public:
2279+
bool isCached() const { return true; }
2280+
22792281
// Incremental dependencies
22802282
evaluator::DependencySource
22812283
readDependencySource(const evaluator::DependencyRecorder &eval) const;

include/swift/Basic/SimpleDisplay.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,20 @@ namespace swift {
136136
out << "}";
137137
}
138138

139+
template<typename T>
140+
void simple_display(llvm::raw_ostream &out,
141+
const std::vector<T> &vec) {
142+
out << "{";
143+
bool first = true;
144+
for (const T &value : vec) {
145+
if (first) first = false;
146+
else out << ", ";
147+
148+
simple_display(out, value);
149+
}
150+
out << "}";
151+
}
152+
139153
template<typename T, typename U>
140154
void simple_display(llvm::raw_ostream &out,
141155
const llvm::PointerUnion<T, U> &ptrUnion) {

lib/AST/Attr.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,13 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
758758
case DAK_Custom: {
759759
if (!Options.IsForSwiftInterface)
760760
break;
761-
// For Swift interface, we should only print function builder attribute
762-
// on parameter decls. Printing the attribute elsewhere isn't ABI relevant.
761+
// For Swift interface, we should print function builder attributes
762+
// on parameter decls and on protocol requirements.
763+
// Printing the attribute elsewhere isn't ABI relevant.
763764
if (auto *VD = dyn_cast<ValueDecl>(D)) {
764765
if (VD->getAttachedFunctionBuilder() == this) {
765-
if (!isa<ParamDecl>(D))
766+
if (!isa<ParamDecl>(D) &&
767+
!(isa<VarDecl>(D) && isa<ProtocolDecl>(D->getDeclContext())))
766768
return false;
767769
}
768770
}

lib/AST/Decl.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6324,10 +6324,6 @@ void ParamDecl::setStoredProperty(VarDecl *var) {
63246324
}
63256325

63266326
Type ValueDecl::getFunctionBuilderType() const {
6327-
// Fast path: most declarations (especially parameters, which is where
6328-
// this is hottest) do not have any custom attributes at all.
6329-
if (!getAttrs().hasAttribute<CustomAttr>()) return Type();
6330-
63316327
auto &ctx = getASTContext();
63326328
auto mutableThis = const_cast<ValueDecl *>(this);
63336329
return evaluateOrDefault(ctx.evaluator,
@@ -6336,10 +6332,6 @@ Type ValueDecl::getFunctionBuilderType() const {
63366332
}
63376333

63386334
CustomAttr *ValueDecl::getAttachedFunctionBuilder() const {
6339-
// Fast path: most declarations (especially parameters, which is where
6340-
// this is hottest) do not have any custom attributes at all.
6341-
if (!getAttrs().hasAttribute<CustomAttr>()) return nullptr;
6342-
63436335
auto &ctx = getASTContext();
63446336
auto mutableThis = const_cast<ValueDecl *>(this);
63456337
return evaluateOrDefault(ctx.evaluator,

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,6 @@ BraceStmt *swift::applyFunctionBuilderTransform(
14011401
captured.first, captured.second)));
14021402
}
14031403

1404-
/// Find the return statements in the given body, which block the application
1405-
/// of a function builder.
1406-
static std::vector<ReturnStmt *> findReturnStatements(AnyFunctionRef fn);
1407-
14081404
Optional<BraceStmt *> TypeChecker::applyFunctionBuilderBodyTransform(
14091405
FuncDecl *func, Type builderType) {
14101406
// Pre-check the body: pre-check any expressions in it and look
@@ -1708,7 +1704,7 @@ PreCheckFunctionBuilderRequest::evaluate(Evaluator &eval,
17081704
return PreCheckFunctionBuilderApplication(fn, false).run();
17091705
}
17101706

1711-
std::vector<ReturnStmt *> findReturnStatements(AnyFunctionRef fn) {
1707+
std::vector<ReturnStmt *> TypeChecker::findReturnStatements(AnyFunctionRef fn) {
17121708
PreCheckFunctionBuilderApplication precheck(fn, true);
17131709
(void)precheck.run();
17141710
return precheck.getReturnStmts();

lib/Sema/CSFix.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,11 @@ getStructuralTypeContext(const Solution &solution, ConstraintLocator *locator) {
287287
solution.getType(coerceExpr->getSubExpr()),
288288
solution.getType(coerceExpr));
289289
} else if (auto *assignExpr = getAsExpr<AssignExpr>(locator->getAnchor())) {
290-
return std::make_tuple(CTP_AssignSource,
290+
auto CTP = isa<SubscriptExpr>(assignExpr->getDest()) ? CTP_SubscriptAssignSource
291+
: CTP_AssignSource;
292+
return std::make_tuple(CTP,
291293
solution.getType(assignExpr->getSrc()),
292-
solution.getType(assignExpr->getDest()));
294+
solution.getType(assignExpr->getDest())->getRValueType());
293295
} else if (auto *call = getAsExpr<CallExpr>(locator->getAnchor())) {
294296
assert(isa<TypeExpr>(call->getFn()));
295297
return std::make_tuple(
@@ -332,8 +334,10 @@ bool AllowTupleTypeMismatch::coalesceAndDiagnose(
332334
return false;
333335
}
334336

335-
TupleContextualFailure failure(solution, purpose, fromType, toType, indices,
336-
locator);
337+
TupleContextualFailure failure(solution, purpose,
338+
fromType->lookThroughAllOptionalTypes(),
339+
toType->lookThroughAllOptionalTypes(),
340+
indices, locator);
337341
return failure.diagnose(asNote);
338342
}
339343

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,13 +3356,18 @@ bool ConstraintSystem::repairFailures(
33563356
// related to immutability, otherwise it's a type mismatch.
33573357
auto result = matchTypes(lhs, rhs, ConstraintKind::Conversion,
33583358
TMF_ApplyingFix, locator);
3359-
3359+
3360+
auto *loc = getConstraintLocator(locator);
33603361
if (getType(destExpr)->is<LValueType>() || result.isFailure()) {
3361-
conversionsOrFixes.push_back(IgnoreAssignmentDestinationType::create(
3362-
*this, lhs, rhs, getConstraintLocator(locator)));
3363-
} else {
3362+
// Let this asignment failure be diagnosed by the AllowTupleTypeMismatch
3363+
// fix already recorded.
3364+
if (hasFixFor(loc, FixKind::AllowTupleTypeMismatch))
3365+
return true;
3366+
33643367
conversionsOrFixes.push_back(
3365-
TreatRValueAsLValue::create(*this, getConstraintLocator(locator)));
3368+
IgnoreAssignmentDestinationType::create(*this, lhs, rhs, loc));
3369+
} else {
3370+
conversionsOrFixes.push_back(TreatRValueAsLValue::create(*this, loc));
33663371
}
33673372

33683373
return true;
@@ -8865,6 +8870,11 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
88658870
CoerceToCheckedCast::attempt(*this, fromType, toType, loc))
88668871
return !recordFix(fix, impact);
88678872
}
8873+
8874+
// We already have a fix for this locator indicating a
8875+
// tuple mismatch.
8876+
if (hasFixFor(loc, FixKind::AllowTupleTypeMismatch))
8877+
return true;
88688878

88698879
if (restriction == ConversionRestrictionKind::ValueToOptional ||
88708880
restriction == ConversionRestrictionKind::OptionalToOptional)

0 commit comments

Comments
 (0)