Skip to content

Commit aab36c6

Browse files
authored
Merge pull request #3725 from swiftwasm/main
2 parents 4303388 + 8f443ff commit aab36c6

Some content is hidden

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

58 files changed

+1868
-783
lines changed

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ ERROR(type_witness_change,APIDigesterBreakage,"%0 has type witness type for %1 c
7676

7777
ERROR(decl_new_witness_table_entry,APIDigesterBreakage,"%0 now requires%select{| no}1 new witness table entry", (StringRef, bool))
7878

79-
ERROR(new_decl_without_intro,APIDigesterBreakage,"%0 is a new API without @available attribute", (StringRef))
79+
WARNING(new_decl_without_intro,APIDigesterBreakage,"%0 is a new API without @available attribute", (StringRef))
8080

8181
ERROR(objc_name_change,APIDigesterBreakage,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))
8282

include/swift/AST/Expr.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,26 +3102,6 @@ class CovariantReturnConversionExpr : public ImplicitConversionExpr {
31023102
}
31033103
};
31043104

3105-
/// Perform a function conversion from a function returning an
3106-
/// Optional<T> to a function returning T.
3107-
///
3108-
/// This is generated during expression type checking in places where
3109-
/// we need to force the result type of a function being called. When
3110-
/// we go to rewrite the call, we remove this node and force the
3111-
/// result of the call to the underlying function. It should never
3112-
/// exist outside of this final stage of expression type checking.
3113-
class ImplicitlyUnwrappedFunctionConversionExpr
3114-
: public ImplicitConversionExpr {
3115-
public:
3116-
ImplicitlyUnwrappedFunctionConversionExpr(Expr *subExpr, Type type)
3117-
: ImplicitConversionExpr(ExprKind::ImplicitlyUnwrappedFunctionConversion,
3118-
subExpr, type) {}
3119-
3120-
static bool classof(const Expr *E) {
3121-
return E->getKind() == ExprKind::ImplicitlyUnwrappedFunctionConversion;
3122-
}
3123-
};
3124-
31253105
/// MetatypeConversionExpr - Convert a metatype to another metatype
31263106
/// using essentially a derived-to-base conversion.
31273107
class MetatypeConversionExpr : public ImplicitConversionExpr {

include/swift/AST/ExprNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ ABSTRACT_EXPR(ImplicitConversion, Expr)
155155
EXPR(FunctionConversion, ImplicitConversionExpr)
156156
EXPR(CovariantFunctionConversion, ImplicitConversionExpr)
157157
EXPR(CovariantReturnConversion, ImplicitConversionExpr)
158-
EXPR(ImplicitlyUnwrappedFunctionConversion, ImplicitConversionExpr)
159158
EXPR(MetatypeConversion, ImplicitConversionExpr)
160159
EXPR(CollectionUpcastConversion, ImplicitConversionExpr)
161160
EXPR(Erasure, ImplicitConversionExpr)

include/swift/AST/Ownership.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include "llvm/Support/Compiler.h"
2525
#include "llvm/Support/ErrorHandling.h"
2626
#include "llvm/Support/raw_ostream.h"
27-
#include <stdint.h>
2827
#include <assert.h>
29-
#include <climits>
28+
#include <limits.h>
29+
#include <stdint.h>
3030

3131
namespace swift {
3232

include/swift/Basic/Platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
#include "swift/Basic/LLVM.h"
1717
#include "swift/Config.h"
18-
#include "llvm/ADT/StringRef.h"
1918
#include "clang/Basic/DarwinSDKInfo.h"
19+
#include "llvm/ADT/StringRef.h"
2020

2121
namespace llvm {
2222
class Triple;

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ CUSTOM_LOCATOR_PATH_ELT(PlaceholderType)
220220
/// The implicit conversion applied at a given location.
221221
CUSTOM_LOCATOR_PATH_ELT(ImplicitConversion)
222222

223+
/// An implicit call to a 'dynamicMember' subscript for a dynamic member lookup.
224+
SIMPLE_LOCATOR_PATH_ELT(ImplicitDynamicMemberSubscript)
225+
223226
/// The element of the closure body e.g. statement, declaration, or expression.
224227
CUSTOM_LOCATOR_PATH_ELT(ClosureBodyElement)
225228

include/swift/Sema/ConstraintSystem.h

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4170,15 +4170,6 @@ class ConstraintSystem {
41704170
}
41714171

41724172
private:
4173-
/// Adjust the constraint system to accommodate the given selected overload, and
4174-
/// recompute the type of the referenced declaration.
4175-
///
4176-
/// \returns a pair containing the adjusted opened type of a reference to
4177-
/// this member and a bit indicating whether or not a bind constraint was added.
4178-
std::pair<Type, bool> adjustTypeOfOverloadReference(
4179-
const OverloadChoice &choice, ConstraintLocator *locator, Type boundType,
4180-
Type refType);
4181-
41824173
/// Add the constraints needed to bind an overload's type variable.
41834174
void bindOverloadType(
41844175
const SelectedOverload &overload, Type boundType,
@@ -4490,6 +4481,12 @@ class ConstraintSystem {
44904481
TypeMatchOptions flags, ConstraintLocatorBuilder locator,
44914482
llvm::function_ref<TypeMatchResult()> formUnsolvedResult);
44924483

4484+
/// Matches two function result types for a function application. This is
4485+
/// usually a bind, but also handles e.g IUO unwraps.
4486+
TypeMatchResult matchFunctionResultTypes(Type expectedResult, Type fnResult,
4487+
TypeMatchOptions flags,
4488+
ConstraintLocatorBuilder locator);
4489+
44934490
public: // FIXME: public due to statics in CSSimplify.cpp
44944491
/// Attempt to match up types \c type1 and \c type2, which in effect
44954492
/// is solving the given type constraint between these two types.
@@ -4525,40 +4522,6 @@ class ConstraintSystem {
45254522
}
45264523

45274524
public:
4528-
/// Given a function type where the eventual result type is an optional,
4529-
/// where "eventual result type" is defined as:
4530-
/// 1. The result type is an optional
4531-
/// 2. The result type is a function type with an eventual result
4532-
/// type that is an optional.
4533-
///
4534-
/// return the same function type but with the eventual result type
4535-
/// replaced by its underlying type.
4536-
///
4537-
/// i.e. return (S) -> T for (S) -> T?
4538-
// return (X) -> () -> Y for (X) -> () -> Y?
4539-
Type replaceFinalResultTypeWithUnderlying(AnyFunctionType *fnTy) {
4540-
auto resultTy = fnTy->getResult();
4541-
if (auto *resultFnTy = resultTy->getAs<AnyFunctionType>())
4542-
resultTy = replaceFinalResultTypeWithUnderlying(resultFnTy);
4543-
else {
4544-
auto objType =
4545-
resultTy->getWithoutSpecifierType()->getOptionalObjectType();
4546-
// Preserve l-value through force operation.
4547-
resultTy =
4548-
resultTy->is<LValueType>() ? LValueType::get(objType) : objType;
4549-
}
4550-
4551-
assert(resultTy);
4552-
4553-
if (auto *genericFn = fnTy->getAs<GenericFunctionType>()) {
4554-
return GenericFunctionType::get(genericFn->getGenericSignature(),
4555-
genericFn->getParams(), resultTy,
4556-
genericFn->getExtInfo());
4557-
}
4558-
4559-
return FunctionType::get(fnTy->getParams(), resultTy, fnTy->getExtInfo());
4560-
}
4561-
45624525
// Build a disjunction that attempts both T? and T for a particular
45634526
// type binding. The choice of T? is preferred, and we will not
45644527
// attempt T if we can type check with T?
@@ -5886,6 +5849,10 @@ class ConjunctionElementProducer : public BindingProducer<ConjunctionElement> {
58865849
bool needsToComputeNext() const override { return false; }
58875850

58885851
bool isExhausted() const override { return Index >= Elements.size(); }
5852+
5853+
void markExhausted() {
5854+
Index = Elements.size();
5855+
}
58895856
};
58905857

58915858
/// Determine whether given type is a known one

include/swift/Sema/OverloadChoice.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ enum class OverloadChoiceKind : int {
6060
TupleIndex,
6161
};
6262

63+
/// The kind of implicitly unwrapped optional for an overload reference.
64+
enum class IUOReferenceKind : uint8_t {
65+
/// This overload references an IUO value which may be directly unwrapped.
66+
Value,
67+
68+
/// This overload references a function, the return value of which may be
69+
/// unwrapped.
70+
ReturnValue,
71+
};
72+
6373
/// Describes a particular choice within an overload set.
6474
///
6575
class OverloadChoice {
@@ -258,11 +268,11 @@ class OverloadChoice {
258268
return isDecl() ? getDecl() : nullptr;
259269
}
260270

261-
/// Returns true if this is either a decl for an optional that was
262-
/// declared as one that can be implicitly unwrapped, or is a
263-
/// function-typed decl that has a return value that is implicitly
264-
/// unwrapped.
265-
bool isImplicitlyUnwrappedValueOrReturnValue() const;
271+
/// Retrieve the type of implicitly unwrapped optional for a reference to this
272+
/// overload choice, or \c None if the choice is not for an IUO decl.
273+
Optional<IUOReferenceKind>
274+
getIUOReferenceKind(ConstraintSystem &cs,
275+
bool forSecondApplication = false) const;
266276

267277
bool isKeyPathDynamicMemberLookup() const {
268278
return getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup;

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,12 +2169,6 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
21692169
printRec(E->getSubExpr());
21702170
PrintWithColorRAII(OS, ParenthesisColor) << ')';
21712171
}
2172-
void visitImplicitlyUnwrappedFunctionConversionExpr(
2173-
ImplicitlyUnwrappedFunctionConversionExpr *E) {
2174-
printCommon(E, "implicitly_unwrapped_function_conversion_expr") << '\n';
2175-
printRec(E->getSubExpr());
2176-
PrintWithColorRAII(OS, ParenthesisColor) << ')';
2177-
}
21782172
void visitUnderlyingToOpaqueExpr(UnderlyingToOpaqueExpr *E){
21792173
printCommon(E, "underlying_to_opaque_expr") << '\n';
21802174
printRec(E->getSubExpr());

lib/AST/Expr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ ConcreteDeclRef Expr::getReferencedDecl(bool stopAtParenExpr) const {
336336
PASS_THROUGH_REFERENCE(FunctionConversion, getSubExpr);
337337
PASS_THROUGH_REFERENCE(CovariantFunctionConversion, getSubExpr);
338338
PASS_THROUGH_REFERENCE(CovariantReturnConversion, getSubExpr);
339-
PASS_THROUGH_REFERENCE(ImplicitlyUnwrappedFunctionConversion, getSubExpr);
340339
PASS_THROUGH_REFERENCE(MetatypeConversion, getSubExpr);
341340
PASS_THROUGH_REFERENCE(CollectionUpcastConversion, getSubExpr);
342341
PASS_THROUGH_REFERENCE(Erasure, getSubExpr);
@@ -661,7 +660,6 @@ bool Expr::canAppendPostfixExpression(bool appendingPostfixOperator) const {
661660
case ExprKind::FunctionConversion:
662661
case ExprKind::CovariantFunctionConversion:
663662
case ExprKind::CovariantReturnConversion:
664-
case ExprKind::ImplicitlyUnwrappedFunctionConversion:
665663
case ExprKind::MetatypeConversion:
666664
case ExprKind::CollectionUpcastConversion:
667665
case ExprKind::Erasure:
@@ -828,7 +826,6 @@ bool Expr::isValidParentOfTypeExpr(Expr *typeExpr) const {
828826
case ExprKind::FunctionConversion:
829827
case ExprKind::CovariantFunctionConversion:
830828
case ExprKind::CovariantReturnConversion:
831-
case ExprKind::ImplicitlyUnwrappedFunctionConversion:
832829
case ExprKind::MetatypeConversion:
833830
case ExprKind::CollectionUpcastConversion:
834831
case ExprKind::Erasure:

lib/AST/RequirementMachine/HomotopyReduction.cpp

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ RewritePath::findRulesAppearingOnceInEmptyContext() const {
218218
result.push_back(rule);
219219
}
220220

221-
std::sort(result.begin(), result.end());
222221
return result;
223222
}
224223

@@ -574,6 +573,64 @@ void HomotopyGenerator::dump(llvm::raw_ostream &out,
574573
out << " [deleted]";
575574
}
576575

576+
/// Check if a rewrite rule is a candidate for deletion in this pass of the
577+
/// minimization algorithm.
578+
bool RewriteSystem::
579+
isCandidateForDeletion(unsigned ruleID,
580+
bool firstPass,
581+
const llvm::DenseSet<unsigned> *redundantConformances) const {
582+
const auto &rule = getRule(ruleID);
583+
584+
// We should not find a rule that has already been marked redundant
585+
// here; it should have already been replaced with a rewrite path
586+
// in all homotopy generators.
587+
assert(!rule.isRedundant());
588+
589+
// Associated type introduction rules are 'permanent'. They're
590+
// not worth eliminating since they are re-added every time; it
591+
// is better to find other candidates to eliminate in the same
592+
// 3-cell instead.
593+
if (rule.isPermanent())
594+
return false;
595+
596+
// Other rules involving unresolved name symbols are derived from an
597+
// associated type introduction rule together with a conformance rule.
598+
// They are eliminated in the first pass.
599+
if (firstPass)
600+
return rule.getLHS().containsUnresolvedSymbols();
601+
602+
// In the second and third pass we should not have any rules involving
603+
// unresolved name symbols, except for permanent rules which were
604+
// already skipped above.
605+
//
606+
// FIXME: This isn't true with invalid code.
607+
assert(!rule.getLHS().containsUnresolvedSymbols());
608+
609+
// Protocol conformance rules are eliminated via a different
610+
// algorithm which computes "generating conformances".
611+
//
612+
// The first and second passes skip protocol conformance rules.
613+
//
614+
// The third pass eliminates any protocol conformance rule which is
615+
// redundant according to both homotopy reduction and the generating
616+
// conformances algorithm.
617+
//
618+
// Later on, we verify that any conformance redundant via generating
619+
// conformances was also redundant via homotopy reduction. This
620+
// means that the set of generating conformances is always a superset
621+
// (or equal to) of the set of minimal protocol conformance
622+
// requirements that homotopy reduction alone would produce.
623+
if (rule.isProtocolConformanceRule()) {
624+
if (!redundantConformances)
625+
return false;
626+
627+
if (!redundantConformances->count(ruleID))
628+
return false;
629+
}
630+
631+
return true;
632+
}
633+
577634
/// Find a rule to delete by looking through all 3-cells for rewrite rules appearing
578635
/// once in empty context. Returns a redundant rule to delete if one was found,
579636
/// otherwise returns None.
@@ -604,63 +661,26 @@ findRuleToDelete(bool firstPass,
604661
SmallVector<unsigned> redundancyCandidates =
605662
loop.Path.findRulesAppearingOnceInEmptyContext();
606663

607-
auto found = std::find_if(
608-
redundancyCandidates.begin(),
609-
redundancyCandidates.end(),
610-
[&](unsigned ruleID) -> bool {
611-
const auto &rule = getRule(ruleID);
612-
613-
// We should not find a rule that has already been marked redundant
614-
// here; it should have already been replaced with a rewrite path
615-
// in all homotopy generators.
616-
assert(!rule.isRedundant());
617-
618-
// Associated type introduction rules are 'permanent'. They're
619-
// not worth eliminating since they are re-added every time; it
620-
// is better to find other candidates to eliminate in the same
621-
// 3-cell instead.
622-
if (rule.isPermanent())
623-
return false;
624-
625-
// Other rules involving unresolved name symbols are derived from an
626-
// associated type introduction rule together with a conformance rule.
627-
// They are eliminated in the first pass.
628-
if (firstPass)
629-
return rule.getLHS().containsUnresolvedSymbols();
630-
631-
// In the second and third pass we should not have any rules involving
632-
// unresolved name symbols, except for permanent rules which were
633-
// already skipped above.
634-
//
635-
// FIXME: This isn't true with invalid code.
636-
assert(!rule.getLHS().containsUnresolvedSymbols());
637-
638-
// Protocol conformance rules are eliminated via a different
639-
// algorithm which computes "generating conformances".
640-
//
641-
// The first and second passes skip protocol conformance rules.
642-
//
643-
// The third pass eliminates any protocol conformance rule which is
644-
// redundant according to both homotopy reduction and the generating
645-
// conformances algorithm.
646-
//
647-
// Later on, we verify that any conformance redundant via generating
648-
// conformances was also redundant via homotopy reduction. This
649-
// means that the set of generating conformances is always a superset
650-
// (or equal to) of the set of minimal protocol conformance
651-
// requirements that homotopy reduction alone would produce.
652-
if (rule.isProtocolConformanceRule()) {
653-
if (!redundantConformances)
654-
return false;
655-
656-
if (!redundantConformances->count(ruleID))
657-
return false;
658-
}
659-
660-
return true;
661-
});
662-
663-
if (found == redundancyCandidates.end())
664+
Optional<unsigned> found;
665+
666+
for (unsigned ruleID : redundancyCandidates) {
667+
if (!isCandidateForDeletion(ruleID, firstPass, redundantConformances))
668+
continue;
669+
670+
if (!found) {
671+
found = ruleID;
672+
continue;
673+
}
674+
675+
const auto &rule = getRule(ruleID);
676+
const auto &otherRule = getRule(*found);
677+
678+
// Prefer to delete "less canonical" rules.
679+
if (rule.compare(otherRule, Protos) > 0)
680+
found = ruleID;
681+
}
682+
683+
if (!found)
664684
continue;
665685

666686
auto ruleID = *found;

0 commit comments

Comments
 (0)