Skip to content

Moving IDE code to GenericSignature and GenericFunctionType #4849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,20 +1025,6 @@ class RequirementRepr {
return SeparatorLoc;
}

/// Set during deserialization; used to print out the requirements accurately
/// for the generated interface.
StringRef getAsWrittenString() const {
return AsWrittenString;
}
void setAsWrittenString(StringRef Str) {
AsWrittenString = Str;
}

/// Further analyze the written string, if it's not empty, to collect the first
/// type, the second type and the requirement kind.
Optional<std::tuple<StringRef, StringRef, RequirementReprKind>>
getAsAnalyzedWrittenString() const;

SourceRange getSourceRange() const {
return SourceRange(Types[0].getSourceRange().Start,
Types[1].getSourceRange().End);
Expand All @@ -1048,7 +1034,6 @@ class RequirementRepr {
void dump() const LLVM_ATTRIBUTE_USED,
"only for use within the debugger");
void print(raw_ostream &OS) const;
void printAsWritten(raw_ostream &OS) const;
};

/// GenericParamList - A list of generic parameters that is part of a generic
Expand Down
45 changes: 19 additions & 26 deletions include/swift/AST/PrintOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "swift/Basic/STLExtras.h"
#include "swift/AST/AttrKind.h"
#include "swift/AST/Identifier.h"
#include "llvm/ADT/Optional.h"
#include <limits.h>
#include <vector>

Expand All @@ -31,32 +32,21 @@ class DeclContext;
class Type;
class ModuleDecl;
enum DeclAttrKind : unsigned;
class PrinterTypeTransformer;
class SynthesizedExtensionAnalyzer;
struct PrintOptions;

/// Necessary information for archetype transformation during printing.
struct TypeTransformContext {
Type getTypeBase();
NominalTypeDecl *getNominal();
PrinterTypeTransformer *getTransformer();
bool isPrintingSynthesizedExtension();
bool isPrintingTypeInterface();
TypeTransformContext(PrinterTypeTransformer *Transformer);
TypeTransformContext(PrinterTypeTransformer *Transformer,
Type T);
TypeTransformContext(PrinterTypeTransformer *Transformer,
NominalTypeDecl *NTD,
SynthesizedExtensionAnalyzer *Analyzer);
Type transform(Type Input);
StringRef transform(StringRef Input);
TypeBase *BaseType;
NominalTypeDecl *Nominal = nullptr;

bool shouldPrintRequirement(ExtensionDecl *ED, StringRef Req);
explicit TypeTransformContext(Type T);
explicit TypeTransformContext(NominalTypeDecl* NTD);

~TypeTransformContext();
private:
struct Implementation;
Implementation &Impl;
Type getTypeBase() const;
NominalTypeDecl *getNominal() const;

bool isPrintingSynthesizedExtension() const;
};

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

/// \brief Print a dynamic Self type as its underlying type, rather than
/// the keyword `Self`.
bool StripDynamicSelf = false;

/// \brief If true, the printer will explode a pattern like this:
/// \code
/// var (a, b) = f()
Expand Down Expand Up @@ -350,7 +344,7 @@ struct PrintOptions {
ModuleDecl *CurrentModule = nullptr;

/// \brief The information for converting archetypes to specialized types.
std::shared_ptr<TypeTransformContext> TransformContext;
llvm::Optional<TypeTransformContext> TransformContext;

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

static PrintOptions printTypeInterface(Type T, DeclContext *DC);
static PrintOptions printTypeInterface(Type T);

void setArchetypeSelfTransform(Type T, DeclContext *DC);
void setArchetypeSelfTransform(Type T);

void setArchetypeSelfTransformForQuickHelp(Type T, DeclContext *DC);
void setArchetypeSelfTransformForQuickHelp(Type T);

void setArchetypeAndDynamicSelfTransform(Type T, DeclContext *DC);
void setArchetypeAndDynamicSelfTransform(Type T);

void initArchetypeTransformerForSynthesizedExtensions(NominalTypeDecl *D,
SynthesizedExtensionAnalyzer *SynAnalyzer);
void initArchetypeTransformerForSynthesizedExtensions(NominalTypeDecl *D);

void clearArchetypeTransformerForSynthesizedExtensions();

Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/Requirement.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Requirement {
}

void dump() const;
void print(raw_ostream &os, const PrintOptions &opts) const;
};

} // end namespace swift
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ enum class SubstFlags {
/// is just changing between contextual and interface type
/// representations, using Type::subst() is allowed.
AllowLoweredTypes = 0x02,
/// Map member types to their desugared witness type.
DesugarMemberTypes = 0x04,
};

/// Options for performing substitutions into a type.
Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
/// specialized, but the type Vector is not.
bool isSpecialized();

/// Retrieve the complete set of generic arguments for a specialized type.
///
/// \param scratch Scratch space to use when the complete list needs to be
/// stitched together from multiple lists of generic arguments.
ArrayRef<Type> getAllGenericArgs(SmallVectorImpl<Type> &scratch);

/// Gather all of the substitutions used to produce the given specialized type
/// from its unspecialized type.
///
Expand Down
14 changes: 8 additions & 6 deletions include/swift/IDE/CodeCompletionCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ class CodeCompletionCache {
std::vector<std::string> AccessPath;
bool ResultsHaveLeadingDot;
bool ForTestableLookup;
bool CodeCompleteInitsInPostfixExpr;

friend bool operator==(const Key &LHS, const Key &RHS) {
return LHS.ModuleFilename == RHS.ModuleFilename &&
LHS.ModuleName == RHS.ModuleName &&
LHS.AccessPath == RHS.AccessPath &&
LHS.ResultsHaveLeadingDot == RHS.ResultsHaveLeadingDot &&
LHS.ForTestableLookup == RHS.ForTestableLookup;
LHS.ModuleName == RHS.ModuleName &&
LHS.AccessPath == RHS.AccessPath &&
LHS.ResultsHaveLeadingDot == RHS.ResultsHaveLeadingDot &&
LHS.ForTestableLookup == RHS.ForTestableLookup &&
LHS.CodeCompleteInitsInPostfixExpr == RHS.CodeCompleteInitsInPostfixExpr;
}
};

Expand Down Expand Up @@ -101,10 +103,10 @@ template<>
struct DenseMapInfo<swift::ide::CodeCompletionCache::Key> {
using KeyTy = swift::ide::CodeCompletionCache::Key;
static inline KeyTy getEmptyKey() {
return KeyTy{"", "", {}, false, false};
return KeyTy{"", "", {}, false, false, false};
}
static inline KeyTy getTombstoneKey() {
return KeyTy{"", "", {}, true, false};
return KeyTy{"", "", {}, true, false, false};
}
static unsigned getHashValue(const KeyTy &Val) {
size_t H = 0;
Expand Down
8 changes: 0 additions & 8 deletions include/swift/IDE/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,6 @@ class SemaLocResolver : public SourceEntityWalker {
};
} // namespace ide

class ArchetypeTransformer {
struct Implementation;
Implementation &Impl;
public:
ArchetypeTransformer(DeclContext *DC, Type Ty);
llvm::function_ref<Type(Type)> getTransformerFunc();
~ArchetypeTransformer();
};
} // namespace swift

#endif // SWIFT_IDE_UTILS_H
Expand Down
7 changes: 0 additions & 7 deletions include/swift/Sema/IDETypeChecking.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ namespace swift {

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

Type lookUpTypeInContext(DeclContext *DC, StringRef Name);

void collectDefaultImplementationForProtocolMembers(ProtocolDecl *PD,
llvm::SmallDenseMap<ValueDecl*, ValueDecl*> &DefaultMap);

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

/// \brief Given the base type and the trailing identifiers, this function tries
/// to infer the type of BaseType.Name1.Name2.Name3
/// \returns Resolved type on success, nullptr on error.
Type checkMemberType(DeclContext &DC, Type BaseTy, ArrayRef<Identifier> Names);

struct ResolveMemberResult {
ValueDecl *Favored = nullptr;
std::vector<ValueDecl*> OtherViables;
Expand Down
1 change: 0 additions & 1 deletion include/swift/Serialization/DeclTypeRecordNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ OTHER(TOP_LEVEL_CODE_DECL_CONTEXT, 239)
OTHER(GENERIC_PARAM_LIST, 240)
TRAILING_INFO(GENERIC_PARAM)
TRAILING_INFO(GENERIC_REQUIREMENT)
TRAILING_INFO(LAST_GENERIC_REQUIREMENT)
TRAILING_INFO(GENERIC_ENVIRONMENT)

OTHER(LOCAL_DISCRIMINATOR, 248)
Expand Down
16 changes: 2 additions & 14 deletions include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
/// in source control, you should also update the comment to briefly
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
const uint16_t VERSION_MINOR = 270; // Last change: parameter type flags
const uint16_t VERSION_MINOR = 271; // Stop serializing RequirementReprs

using DeclID = PointerEmbeddedInt<unsigned, 31>;
using DeclIDField = BCFixed<31>;
Expand Down Expand Up @@ -1117,19 +1117,7 @@ namespace decls_block {
GENERIC_REQUIREMENT,
GenericRequirementKindField, // requirement kind
TypeIDField, // types involved (two for conformance,
TypeIDField, // same-type; one for value witness marker)
BCBlob // as written string
>;

/// Placeholder that marks the last generic requirement in the generic
/// parameters list.
///
/// Used as a buffer between the generic parameter list's requirements and
/// the generic signature's requirements for nominal type declarations.
/// FIXME: Expected to go away once the latter is no longer serialized.
using LastGenericRequirementLayout = BCRecordLayout<
LAST_GENERIC_REQUIREMENT,
BCFixed<1> // dummy
TypeIDField // same-type; one for value witness marker)
>;

/// Specifies the private discriminator string for a private declaration. This
Expand Down
22 changes: 0 additions & 22 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,6 @@ void RequirementRepr::dump() const {
llvm::errs() << "\n";
}

Optional<std::tuple<StringRef, StringRef, RequirementReprKind>>
RequirementRepr::getAsAnalyzedWrittenString() const {
if (AsWrittenString.empty())
return None;
auto Pair = AsWrittenString.split("==");
auto Kind = RequirementReprKind::SameType;
if (Pair.second.empty()) {
Pair = AsWrittenString.split(":");
Kind = RequirementReprKind::TypeConstraint;
}
assert(!Pair.second.empty() && "cannot get second type.");
return std::make_tuple(Pair.first.trim(), Pair.second.trim(), Kind);
}

void RequirementRepr::printImpl(raw_ostream &out, bool AsWritten) const {
auto printTy = [&](const TypeLoc &TyLoc) {
if (AsWritten && TyLoc.getTypeRepr()) {
Expand Down Expand Up @@ -132,14 +118,6 @@ void RequirementRepr::print(raw_ostream &out) const {
printImpl(out, /*AsWritten=*/false);
}

void RequirementRepr::printAsWritten(raw_ostream &out) const {
if (!AsWrittenString.empty()) {
out << AsWrittenString;
} else {
printImpl(out, /*AsWritten=*/true);
}
}

void GenericParamList::print(llvm::raw_ostream &OS) {
OS << '<';
bool First = true;
Expand Down
Loading