Skip to content

Commit 9c3565e

Browse files
authored
Merge pull request #1269 from swiftwasm/master
[pull] swiftwasm from master
2 parents ae55a43 + 90cb347 commit 9c3565e

Some content is hidden

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

46 files changed

+328
-161
lines changed

include/swift/AST/ASTPrinter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ class ASTPrinter {
204204
return *this << StringRef(&c, 1);
205205
}
206206

207-
void printKeyword(StringRef name, PrintOptions Opts, StringRef Suffix = "") {
207+
void printKeyword(StringRef name,
208+
const PrintOptions &Opts,
209+
StringRef Suffix = "") {
208210
if (Opts.SkipUnderscoredKeywords && name.startswith("_"))
209211
return;
210212
assert(!name.empty() && "Tried to print empty keyword");

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ SIMPLE_DECL_ATTR(_disfavoredOverload, DisfavoredOverload,
494494
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
495495
87)
496496
SIMPLE_DECL_ATTR(_functionBuilder, FunctionBuilder,
497-
OnNominalType |
497+
OnNominalType | UserInaccessible |
498498
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
499499
88)
500500
DECL_ATTR(_projectedValueProperty, ProjectedValueProperty,

include/swift/AST/GenericSignature.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ class GenericSignature {
136136
return hash_value(sig.getPointer());
137137
}
138138

139-
void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
140-
void print(ASTPrinter &Printer, PrintOptions Opts = PrintOptions()) const;
139+
void print(raw_ostream &OS,
140+
const PrintOptions &Options = PrintOptions()) const;
141+
void print(ASTPrinter &Printer,
142+
const PrintOptions &Opts = PrintOptions()) const;
141143
SWIFT_DEBUG_DUMP;
142144
std::string getAsString() const;
143145

include/swift/AST/SubstitutionMap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ class SubstitutionMap {
150150
/// generic parameters.
151151
ArrayRef<Type> getReplacementTypes() const;
152152

153+
/// Retrieve the array of replacement types for the innermost generic
154+
/// parameters.
155+
ArrayRef<Type> getInnermostReplacementTypes() const;
156+
153157
/// Query whether any replacement types in the map contain archetypes.
154158
bool hasArchetypes() const;
155159

include/swift/AST/Types.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,13 +1813,10 @@ class TypeAliasType final
18131813
return *getTrailingObjects<SubstitutionMap>();
18141814
}
18151815

1816-
/// Get the innermost generic arguments, which correspond to the generic
1817-
/// arguments that are directly applied to the typealias declaration in
1818-
/// produced by \c getDecl().
1819-
///
1820-
/// The result can be empty, if the declaration itself is non-generic but
1821-
/// the parent is generic.
1822-
SmallVector<Type, 2> getInnermostGenericArgs() const;
1816+
/// Get the direct generic arguments, which correspond to the generic
1817+
/// arguments that are directly applied to the typealias declaration
1818+
/// this type references.
1819+
ArrayRef<Type> getDirectGenericArgs() const;
18231820

18241821
// Support for FoldingSet.
18251822
void Profile(llvm::FoldingSetNodeID &id) const;

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ namespace {
35173517
if (T->getParent())
35183518
printRec("parent", T->getParent());
35193519

3520-
for (auto arg : T->getInnermostGenericArgs())
3520+
for (const auto arg : T->getDirectGenericArgs())
35213521
printRec(arg);
35223522
PrintWithColorRAII(OS, ParenthesisColor) << ')';
35233523
}

lib/AST/ASTPrinter.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void StreamPrinter::printText(StringRef Text) {
475475
/// Whether we will be printing a TypeLoc by using the TypeRepr printer
476476
static bool willUseTypeReprPrinting(TypeLoc tyLoc,
477477
Type currentType,
478-
PrintOptions options) {
478+
const PrintOptions &options) {
479479
// Special case for when transforming archetypes
480480
if (currentType && tyLoc.getType())
481481
return false;
@@ -686,7 +686,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
686686
}
687687
}
688688

689-
void printTypeWithOptions(Type T, PrintOptions options) {
689+
void printTypeWithOptions(Type T, const PrintOptions &options) {
690690
if (options.TransformContext) {
691691
// FIXME: it's not clear exactly what we want to keep from the existing
692692
// options, and what we want to discard.
@@ -736,7 +736,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
736736
printTransformedTypeWithOptions(T, Options);
737737
}
738738

739-
void printTypeLocWithOptions(const TypeLoc &TL, PrintOptions options) {
739+
void printTypeLocWithOptions(const TypeLoc &TL, const PrintOptions &options) {
740740
if (CurrentType && TL.getType()) {
741741
printTransformedTypeWithOptions(TL.getType(), options);
742742
return;
@@ -1081,7 +1081,7 @@ void PrintAST::printTypedPattern(const TypedPattern *TP) {
10811081

10821082
/// Determines if we are required to print the name of a property declaration,
10831083
/// or if we can elide it by printing a '_' instead.
1084-
static bool mustPrintPropertyName(VarDecl *decl, PrintOptions opts) {
1084+
static bool mustPrintPropertyName(VarDecl *decl, const PrintOptions &opts) {
10851085
// If we're not allowed to omit the name, we must print it.
10861086
if (!opts.OmitNameOfInaccessibleProperties) return true;
10871087

@@ -2636,8 +2636,10 @@ static bool isEscaping(Type type) {
26362636
return false;
26372637
}
26382638

2639-
static void printParameterFlags(ASTPrinter &printer, PrintOptions options,
2640-
ParameterTypeFlags flags, bool escaping) {
2639+
static void printParameterFlags(ASTPrinter &printer,
2640+
const PrintOptions &options,
2641+
ParameterTypeFlags flags,
2642+
bool escaping) {
26412643
if (!options.excludeAttrKind(TAK_autoclosure) && flags.isAutoClosure())
26422644
printer.printAttrName("@autoclosure ");
26432645
if (!options.excludeAttrKind(TAK_noDerivative) && flags.isNoDerivative())
@@ -3812,7 +3814,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
38123814
}
38133815

38143816
printQualifiedType(T);
3815-
printGenericArgs(T->getInnermostGenericArgs());
3817+
printGenericArgs(T->getDirectGenericArgs());
38163818
}
38173819

38183820
void visitParenType(ParenType *T) {
@@ -4680,12 +4682,13 @@ void GenericSignatureImpl::print(ASTPrinter &Printer, PrintOptions PO) const {
46804682
GenericSignature(const_cast<GenericSignatureImpl *>(this)).print(Printer, PO);
46814683
}
46824684

4683-
void GenericSignature::print(raw_ostream &OS, PrintOptions Opts) const {
4685+
void GenericSignature::print(raw_ostream &OS, const PrintOptions &Opts) const {
46844686
StreamPrinter Printer(OS);
46854687
print(Printer, Opts);
46864688
}
46874689

4688-
void GenericSignature::print(ASTPrinter &Printer, PrintOptions Opts) const {
4690+
void GenericSignature::print(ASTPrinter &Printer,
4691+
const PrintOptions &Opts) const {
46894692
if (isNull()) {
46904693
Printer << "<null>";
46914694
return;

lib/AST/Attr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,8 @@ static std::string getDifferentiationParametersClauseString(
528528
/// - If `omitWrtClause` is true, omit printing the `wrt:` differentiation
529529
/// parameters clause.
530530
static void printDifferentiableAttrArguments(
531-
const DifferentiableAttr *attr, ASTPrinter &printer, PrintOptions Options,
532-
const Decl *D, bool omitWrtClause = false) {
531+
const DifferentiableAttr *attr, ASTPrinter &printer,
532+
const PrintOptions &Options, const Decl *D, bool omitWrtClause = false) {
533533
assert(D);
534534
// Create a temporary string for the attribute argument text.
535535
std::string attrArgText;

lib/AST/SubstitutionMap.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ ArrayRef<Type> SubstitutionMap::getReplacementTypes() const {
9797
return getReplacementTypesBuffer();
9898
}
9999

100+
ArrayRef<Type> SubstitutionMap::getInnermostReplacementTypes() const {
101+
if (empty()) return { };
102+
103+
return getReplacementTypes().take_back(
104+
getGenericSignature()->getInnermostGenericParams().size());
105+
}
106+
100107
GenericSignature SubstitutionMap::getGenericSignature() const {
101108
return storage ? storage->getGenericSignature() : nullptr;
102109
}

lib/AST/Type.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,26 +1384,12 @@ Type SugarType::getSinglyDesugaredTypeSlow() {
13841384
return UnderlyingType;
13851385
}
13861386

1387-
SmallVector<Type, 2> TypeAliasType::getInnermostGenericArgs() const {
1388-
SmallVector<Type, 2> result;
1387+
ArrayRef<Type> TypeAliasType::getDirectGenericArgs() const {
1388+
if (!typealias->isGeneric()) return { };
13891389

1390-
// If the typealias is not generic, there are no generic arguments
1391-
if (!typealias->isGeneric()) return result;
1392-
1393-
// If the substitution map is empty, bail out.
1394-
auto subMap = getSubstitutionMap();
1395-
if (subMap.empty()) return result;
1396-
1397-
// Retrieve the substitutions for the generic parameters (only).
1398-
auto genericSig = subMap.getGenericSignature();
1399-
unsigned numAllGenericParams = genericSig->getGenericParams().size();
1400-
unsigned numMyGenericParams = typealias->getGenericParams()->size();
1401-
result.reserve(numMyGenericParams);
1402-
unsigned startIndex = numAllGenericParams - numMyGenericParams;
1403-
for (auto gp : genericSig->getGenericParams().slice(startIndex)) {
1404-
result.push_back(Type(gp).subst(subMap));
1405-
}
1406-
return result;
1390+
// Otherwise, the innermost replacement types are the direct
1391+
// generic arguments.
1392+
return getSubstitutionMap().getInnermostReplacementTypes();
14071393
}
14081394

14091395
unsigned GenericTypeParamType::getDepth() const {

lib/AST/TypeWalker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Traversal : public TypeVisitor<Traversal, bool>
3939
if (auto parent = ty->getParent())
4040
if (doIt(parent)) return true;
4141

42-
for (auto arg : ty->getInnermostGenericArgs())
42+
for (const auto arg : ty->getDirectGenericArgs())
4343
if (doIt(arg))
4444
return true;
4545

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,8 +1602,11 @@ ExplicitSwiftModuleLoader::create(ASTContext &ctx,
16021602
new ExplicitSwiftModuleLoader(ctx, tracker, loadMode,
16031603
IgnoreSwiftSourceInfoFile));
16041604
auto &Impl = result->Impl;
1605-
// Parse a JSON file to collect explicitly built modules.
1606-
Impl.parseSwiftExplicitModuleMap(ExplicitSwiftModuleMap);
1605+
// If the explicit module map is given, try parse it.
1606+
if (!ExplicitSwiftModuleMap.empty()) {
1607+
// Parse a JSON file to collect explicitly built modules.
1608+
Impl.parseSwiftExplicitModuleMap(ExplicitSwiftModuleMap);
1609+
}
16071610
// Collect .swiftmodule paths from -swift-module-path
16081611
// FIXME: remove these.
16091612
for (auto path: ExplicitModulePaths) {

lib/SILOptimizer/Transforms/SemanticARCOpts.cpp

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -505,63 +505,69 @@ void OwnershipLiveRange::insertEndBorrowsAtDestroys(
505505
}
506506
}
507507

508-
void OwnershipLiveRange::convertOwnedGeneralForwardingUsesToGuaranteed() && {
509-
while (!ownershipForwardingUses.empty()) {
510-
auto *i = ownershipForwardingUses.back()->getUser();
511-
ownershipForwardingUses = ownershipForwardingUses.drop_back();
512-
513-
// If this is a term inst, just convert all of its incoming values that are
514-
// owned to be guaranteed.
515-
if (auto *ti = dyn_cast<TermInst>(i)) {
516-
for (auto &succ : ti->getSuccessors()) {
517-
auto *succBlock = succ.getBB();
508+
static void convertInstructionOwnership(SILInstruction *i,
509+
ValueOwnershipKind oldOwnership,
510+
ValueOwnershipKind newOwnership) {
511+
// If this is a term inst, just convert all of its incoming values that are
512+
// owned to be guaranteed.
513+
if (auto *ti = dyn_cast<TermInst>(i)) {
514+
for (auto &succ : ti->getSuccessors()) {
515+
auto *succBlock = succ.getBB();
518516

519-
// If we do not have any arguments, then continue.
520-
if (succBlock->args_empty())
521-
continue;
517+
// If we do not have any arguments, then continue.
518+
if (succBlock->args_empty())
519+
continue;
522520

523-
for (auto *succArg : succBlock->getSILPhiArguments()) {
524-
// If we have an any value, just continue.
525-
if (succArg->getOwnershipKind() == ValueOwnershipKind::Owned) {
526-
succArg->setOwnershipKind(ValueOwnershipKind::Guaranteed);
527-
}
521+
for (auto *succArg : succBlock->getSILPhiArguments()) {
522+
// If we have an any value, just continue.
523+
if (succArg->getOwnershipKind() == oldOwnership) {
524+
succArg->setOwnershipKind(newOwnership);
528525
}
529526
}
530-
continue;
531527
}
528+
return;
529+
}
532530

533-
assert(i->hasResults());
534-
for (SILValue result : i->getResults()) {
535-
if (auto *svi = dyn_cast<OwnershipForwardingSingleValueInst>(result)) {
536-
if (svi->getOwnershipKind() == ValueOwnershipKind::Owned) {
537-
svi->setOwnershipKind(ValueOwnershipKind::Guaranteed);
538-
}
539-
continue;
531+
assert(i->hasResults());
532+
for (SILValue result : i->getResults()) {
533+
if (auto *svi = dyn_cast<OwnershipForwardingSingleValueInst>(result)) {
534+
if (svi->getOwnershipKind() == oldOwnership) {
535+
svi->setOwnershipKind(newOwnership);
540536
}
537+
continue;
538+
}
541539

542-
if (auto *ofci = dyn_cast<OwnershipForwardingConversionInst>(result)) {
543-
if (ofci->getOwnershipKind() == ValueOwnershipKind::Owned) {
544-
ofci->setOwnershipKind(ValueOwnershipKind::Guaranteed);
545-
}
546-
continue;
540+
if (auto *ofci = dyn_cast<OwnershipForwardingConversionInst>(result)) {
541+
if (ofci->getOwnershipKind() == oldOwnership) {
542+
ofci->setOwnershipKind(newOwnership);
547543
}
544+
continue;
545+
}
548546

549-
if (auto *sei = dyn_cast<OwnershipForwardingSelectEnumInstBase>(result)) {
550-
if (sei->getOwnershipKind() == ValueOwnershipKind::Owned) {
551-
sei->setOwnershipKind(ValueOwnershipKind::Guaranteed);
552-
}
553-
continue;
547+
if (auto *sei = dyn_cast<OwnershipForwardingSelectEnumInstBase>(result)) {
548+
if (sei->getOwnershipKind() == oldOwnership) {
549+
sei->setOwnershipKind(newOwnership);
554550
}
551+
continue;
552+
}
555553

556-
if (auto *mvir = dyn_cast<MultipleValueInstructionResult>(result)) {
557-
if (mvir->getOwnershipKind() == ValueOwnershipKind::Owned) {
558-
mvir->setOwnershipKind(ValueOwnershipKind::Guaranteed);
559-
}
560-
continue;
554+
if (auto *mvir = dyn_cast<MultipleValueInstructionResult>(result)) {
555+
if (mvir->getOwnershipKind() == oldOwnership) {
556+
mvir->setOwnershipKind(newOwnership);
561557
}
562-
563-
llvm_unreachable("unhandled forwarding instruction?!");
558+
continue;
564559
}
560+
561+
llvm_unreachable("unhandled forwarding instruction?!");
562+
}
563+
}
564+
565+
void OwnershipLiveRange::convertOwnedGeneralForwardingUsesToGuaranteed() && {
566+
while (!ownershipForwardingUses.empty()) {
567+
auto *i = ownershipForwardingUses.back()->getUser();
568+
ownershipForwardingUses = ownershipForwardingUses.drop_back();
569+
convertInstructionOwnership(i, ValueOwnershipKind::Owned,
570+
ValueOwnershipKind::Guaranteed);
565571
}
566572
}
567573

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,7 @@ namespace {
25632563
if (!witness || !isa<AbstractFunctionDecl>(witness.getDecl()))
25642564
return nullptr;
25652565
expr->setInitializer(witness);
2566+
expr->setArg(cs.coerceToRValue(expr->getArg()));
25662567
return expr;
25672568
}
25682569

lib/Sema/CSBindings.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ void ConstraintSystem::inferTransitiveSupertypeBindings(
6969

7070
auto type = binding.BindingType;
7171

72+
if (type->isHole())
73+
continue;
74+
7275
if (!existingTypes.insert(type->getCanonicalType()).second)
7376
continue;
7477

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3364,7 +3364,6 @@ Type TypeResolver::resolveImplicitlyUnwrappedOptionalType(
33643364
doDiag = !isDirect;
33653365
break;
33663366
case TypeResolverContext::VariadicFunctionInput:
3367-
case TypeResolverContext::ProtocolWhereClause:
33683367
case TypeResolverContext::ForEachStmt:
33693368
case TypeResolverContext::ExtensionBinding:
33703369
case TypeResolverContext::ExplicitCastExpr:

lib/Sema/TypeCheckType.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ enum class TypeResolverContext : uint8_t {
9797
/// tuple return values. See also: TypeResolutionFlags::Direct
9898
FunctionResult,
9999

100-
/// Whether we are in a protocol's where clause
101-
ProtocolWhereClause,
102-
103100
/// Whether this is a pattern binding entry.
104101
PatternBindingDecl,
105102

@@ -210,7 +207,6 @@ class TypeResolutionOptions {
210207
case Context::FunctionInput:
211208
case Context::VariadicFunctionInput:
212209
case Context::FunctionResult:
213-
case Context::ProtocolWhereClause:
214210
case Context::ExtensionBinding:
215211
case Context::SubscriptDecl:
216212
case Context::EnumElementDecl:

0 commit comments

Comments
 (0)