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 {

0 commit comments

Comments
 (0)