Skip to content

Commit 66da45b

Browse files
authored
Merge pull request #4849 from slavapestov/ide-cleanup
Moving IDE code to GenericSignature and GenericFunctionType
2 parents 5494e82 + 581c99b commit 66da45b

File tree

60 files changed

+1630
-2362
lines changed

Some content is hidden

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

60 files changed

+1630
-2362
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,20 +1025,6 @@ class RequirementRepr {
10251025
return SeparatorLoc;
10261026
}
10271027

1028-
/// Set during deserialization; used to print out the requirements accurately
1029-
/// for the generated interface.
1030-
StringRef getAsWrittenString() const {
1031-
return AsWrittenString;
1032-
}
1033-
void setAsWrittenString(StringRef Str) {
1034-
AsWrittenString = Str;
1035-
}
1036-
1037-
/// Further analyze the written string, if it's not empty, to collect the first
1038-
/// type, the second type and the requirement kind.
1039-
Optional<std::tuple<StringRef, StringRef, RequirementReprKind>>
1040-
getAsAnalyzedWrittenString() const;
1041-
10421028
SourceRange getSourceRange() const {
10431029
return SourceRange(Types[0].getSourceRange().Start,
10441030
Types[1].getSourceRange().End);
@@ -1048,7 +1034,6 @@ class RequirementRepr {
10481034
void dump() const LLVM_ATTRIBUTE_USED,
10491035
"only for use within the debugger");
10501036
void print(raw_ostream &OS) const;
1051-
void printAsWritten(raw_ostream &OS) const;
10521037
};
10531038

10541039
/// GenericParamList - A list of generic parameters that is part of a generic

include/swift/AST/PrintOptions.h

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/Basic/STLExtras.h"
1717
#include "swift/AST/AttrKind.h"
1818
#include "swift/AST/Identifier.h"
19+
#include "llvm/ADT/Optional.h"
1920
#include <limits.h>
2021
#include <vector>
2122

@@ -31,32 +32,21 @@ class DeclContext;
3132
class Type;
3233
class ModuleDecl;
3334
enum DeclAttrKind : unsigned;
34-
class PrinterTypeTransformer;
3535
class SynthesizedExtensionAnalyzer;
3636
struct PrintOptions;
3737

3838
/// Necessary information for archetype transformation during printing.
3939
struct TypeTransformContext {
40-
Type getTypeBase();
41-
NominalTypeDecl *getNominal();
42-
PrinterTypeTransformer *getTransformer();
43-
bool isPrintingSynthesizedExtension();
44-
bool isPrintingTypeInterface();
45-
TypeTransformContext(PrinterTypeTransformer *Transformer);
46-
TypeTransformContext(PrinterTypeTransformer *Transformer,
47-
Type T);
48-
TypeTransformContext(PrinterTypeTransformer *Transformer,
49-
NominalTypeDecl *NTD,
50-
SynthesizedExtensionAnalyzer *Analyzer);
51-
Type transform(Type Input);
52-
StringRef transform(StringRef Input);
40+
TypeBase *BaseType;
41+
NominalTypeDecl *Nominal = nullptr;
5342

54-
bool shouldPrintRequirement(ExtensionDecl *ED, StringRef Req);
43+
explicit TypeTransformContext(Type T);
44+
explicit TypeTransformContext(NominalTypeDecl* NTD);
5545

56-
~TypeTransformContext();
57-
private:
58-
struct Implementation;
59-
Implementation &Impl;
46+
Type getTypeBase() const;
47+
NominalTypeDecl *getNominal() const;
48+
49+
bool isPrintingSynthesizedExtension() const;
6050
};
6151

6252
typedef std::pair<ExtensionDecl*, bool> ExtensionAndIsSynthesized;
@@ -196,6 +186,10 @@ struct PrintOptions {
196186
/// ([] and ?), even if there are no sugar type nodes.
197187
bool SynthesizeSugarOnTypes = false;
198188

189+
/// \brief Print a dynamic Self type as its underlying type, rather than
190+
/// the keyword `Self`.
191+
bool StripDynamicSelf = false;
192+
199193
/// \brief If true, the printer will explode a pattern like this:
200194
/// \code
201195
/// var (a, b) = f()
@@ -350,7 +344,7 @@ struct PrintOptions {
350344
ModuleDecl *CurrentModule = nullptr;
351345

352346
/// \brief The information for converting archetypes to specialized types.
353-
std::shared_ptr<TypeTransformContext> TransformContext;
347+
llvm::Optional<TypeTransformContext> TransformContext;
354348

355349
/// \brief If this is not \c nullptr then functions (including accessors and
356350
/// constructors) will be printed with a body that is determined by this
@@ -413,16 +407,15 @@ struct PrintOptions {
413407
return result;
414408
}
415409

416-
static PrintOptions printTypeInterface(Type T, DeclContext *DC);
410+
static PrintOptions printTypeInterface(Type T);
417411

418-
void setArchetypeSelfTransform(Type T, DeclContext *DC);
412+
void setArchetypeSelfTransform(Type T);
419413

420-
void setArchetypeSelfTransformForQuickHelp(Type T, DeclContext *DC);
414+
void setArchetypeSelfTransformForQuickHelp(Type T);
421415

422-
void setArchetypeAndDynamicSelfTransform(Type T, DeclContext *DC);
416+
void setArchetypeAndDynamicSelfTransform(Type T);
423417

424-
void initArchetypeTransformerForSynthesizedExtensions(NominalTypeDecl *D,
425-
SynthesizedExtensionAnalyzer *SynAnalyzer);
418+
void initArchetypeTransformerForSynthesizedExtensions(NominalTypeDecl *D);
426419

427420
void clearArchetypeTransformerForSynthesizedExtensions();
428421

include/swift/AST/Requirement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Requirement {
7676
}
7777

7878
void dump() const;
79+
void print(raw_ostream &os, const PrintOptions &opts) const;
7980
};
8081

8182
} // end namespace swift

include/swift/AST/Type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ enum class SubstFlags {
6262
/// is just changing between contextual and interface type
6363
/// representations, using Type::subst() is allowed.
6464
AllowLoweredTypes = 0x02,
65+
/// Map member types to their desugared witness type.
66+
DesugarMemberTypes = 0x04,
6567
};
6668

6769
/// Options for performing substitutions into a type.

include/swift/AST/Types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
554554
/// specialized, but the type Vector is not.
555555
bool isSpecialized();
556556

557-
/// Retrieve the complete set of generic arguments for a specialized type.
558-
///
559-
/// \param scratch Scratch space to use when the complete list needs to be
560-
/// stitched together from multiple lists of generic arguments.
561-
ArrayRef<Type> getAllGenericArgs(SmallVectorImpl<Type> &scratch);
562-
563557
/// Gather all of the substitutions used to produce the given specialized type
564558
/// from its unspecialized type.
565559
///

include/swift/IDE/CodeCompletionCache.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ class CodeCompletionCache {
3939
std::vector<std::string> AccessPath;
4040
bool ResultsHaveLeadingDot;
4141
bool ForTestableLookup;
42+
bool CodeCompleteInitsInPostfixExpr;
4243

4344
friend bool operator==(const Key &LHS, const Key &RHS) {
4445
return LHS.ModuleFilename == RHS.ModuleFilename &&
45-
LHS.ModuleName == RHS.ModuleName &&
46-
LHS.AccessPath == RHS.AccessPath &&
47-
LHS.ResultsHaveLeadingDot == RHS.ResultsHaveLeadingDot &&
48-
LHS.ForTestableLookup == RHS.ForTestableLookup;
46+
LHS.ModuleName == RHS.ModuleName &&
47+
LHS.AccessPath == RHS.AccessPath &&
48+
LHS.ResultsHaveLeadingDot == RHS.ResultsHaveLeadingDot &&
49+
LHS.ForTestableLookup == RHS.ForTestableLookup &&
50+
LHS.CodeCompleteInitsInPostfixExpr == RHS.CodeCompleteInitsInPostfixExpr;
4951
}
5052
};
5153

@@ -101,10 +103,10 @@ template<>
101103
struct DenseMapInfo<swift::ide::CodeCompletionCache::Key> {
102104
using KeyTy = swift::ide::CodeCompletionCache::Key;
103105
static inline KeyTy getEmptyKey() {
104-
return KeyTy{"", "", {}, false, false};
106+
return KeyTy{"", "", {}, false, false, false};
105107
}
106108
static inline KeyTy getTombstoneKey() {
107-
return KeyTy{"", "", {}, true, false};
109+
return KeyTy{"", "", {}, true, false, false};
108110
}
109111
static unsigned getHashValue(const KeyTy &Val) {
110112
size_t H = 0;

include/swift/IDE/Utils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,6 @@ class SemaLocResolver : public SourceEntityWalker {
197197
};
198198
} // namespace ide
199199

200-
class ArchetypeTransformer {
201-
struct Implementation;
202-
Implementation &Impl;
203-
public:
204-
ArchetypeTransformer(DeclContext *DC, Type Ty);
205-
llvm::function_ref<Type(Type)> getTransformerFunc();
206-
~ArchetypeTransformer();
207-
};
208200
} // namespace swift
209201

210202
#endif // SWIFT_IDE_UTILS_H

include/swift/Sema/IDETypeChecking.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ namespace swift {
4646

4747
bool canPossiblyConvertTo(Type T1, Type T2, DeclContext &DC);
4848

49-
Type lookUpTypeInContext(DeclContext *DC, StringRef Name);
50-
5149
void collectDefaultImplementationForProtocolMembers(ProtocolDecl *PD,
5250
llvm::SmallDenseMap<ValueDecl*, ValueDecl*> &DefaultMap);
5351

@@ -57,11 +55,6 @@ namespace swift {
5755
bool typeCheckUnresolvedExpr(DeclContext &DC, Expr* E,
5856
Expr *P, SmallVectorImpl<Type> &PossibleTypes);
5957

60-
/// \brief Given the base type and the trailing identifiers, this function tries
61-
/// to infer the type of BaseType.Name1.Name2.Name3
62-
/// \returns Resolved type on success, nullptr on error.
63-
Type checkMemberType(DeclContext &DC, Type BaseTy, ArrayRef<Identifier> Names);
64-
6558
struct ResolveMemberResult {
6659
ValueDecl *Favored = nullptr;
6760
std::vector<ValueDecl*> OtherViables;

include/swift/Serialization/DeclTypeRecordNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ OTHER(TOP_LEVEL_CODE_DECL_CONTEXT, 239)
168168
OTHER(GENERIC_PARAM_LIST, 240)
169169
TRAILING_INFO(GENERIC_PARAM)
170170
TRAILING_INFO(GENERIC_REQUIREMENT)
171-
TRAILING_INFO(LAST_GENERIC_REQUIREMENT)
172171
TRAILING_INFO(GENERIC_ENVIRONMENT)
173172

174173
OTHER(LOCAL_DISCRIMINATOR, 248)

include/swift/Serialization/ModuleFormat.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 270; // Last change: parameter type flags
57+
const uint16_t VERSION_MINOR = 271; // Stop serializing RequirementReprs
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -1117,19 +1117,7 @@ namespace decls_block {
11171117
GENERIC_REQUIREMENT,
11181118
GenericRequirementKindField, // requirement kind
11191119
TypeIDField, // types involved (two for conformance,
1120-
TypeIDField, // same-type; one for value witness marker)
1121-
BCBlob // as written string
1122-
>;
1123-
1124-
/// Placeholder that marks the last generic requirement in the generic
1125-
/// parameters list.
1126-
///
1127-
/// Used as a buffer between the generic parameter list's requirements and
1128-
/// the generic signature's requirements for nominal type declarations.
1129-
/// FIXME: Expected to go away once the latter is no longer serialized.
1130-
using LastGenericRequirementLayout = BCRecordLayout<
1131-
LAST_GENERIC_REQUIREMENT,
1132-
BCFixed<1> // dummy
1120+
TypeIDField // same-type; one for value witness marker)
11331121
>;
11341122

11351123
/// Specifies the private discriminator string for a private declaration. This

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,6 @@ void RequirementRepr::dump() const {
9090
llvm::errs() << "\n";
9191
}
9292

93-
Optional<std::tuple<StringRef, StringRef, RequirementReprKind>>
94-
RequirementRepr::getAsAnalyzedWrittenString() const {
95-
if (AsWrittenString.empty())
96-
return None;
97-
auto Pair = AsWrittenString.split("==");
98-
auto Kind = RequirementReprKind::SameType;
99-
if (Pair.second.empty()) {
100-
Pair = AsWrittenString.split(":");
101-
Kind = RequirementReprKind::TypeConstraint;
102-
}
103-
assert(!Pair.second.empty() && "cannot get second type.");
104-
return std::make_tuple(Pair.first.trim(), Pair.second.trim(), Kind);
105-
}
106-
10793
void RequirementRepr::printImpl(raw_ostream &out, bool AsWritten) const {
10894
auto printTy = [&](const TypeLoc &TyLoc) {
10995
if (AsWritten && TyLoc.getTypeRepr()) {
@@ -132,14 +118,6 @@ void RequirementRepr::print(raw_ostream &out) const {
132118
printImpl(out, /*AsWritten=*/false);
133119
}
134120

135-
void RequirementRepr::printAsWritten(raw_ostream &out) const {
136-
if (!AsWrittenString.empty()) {
137-
out << AsWrittenString;
138-
} else {
139-
printImpl(out, /*AsWritten=*/true);
140-
}
141-
}
142-
143121
void GenericParamList::print(llvm::raw_ostream &OS) {
144122
OS << '<';
145123
bool First = true;

0 commit comments

Comments
 (0)