Skip to content

[AST] Dodge an annoying libc++ std::function quirk requiring complete result types #9284

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 1 commit into from
May 4, 2017
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
7 changes: 5 additions & 2 deletions include/swift/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ enum class SubstFlags {

/// Options for performing substitutions into a type.
struct SubstOptions : public OptionSet<SubstFlags> {
typedef std::function<Type(const NormalProtocolConformance *,
AssociatedTypeDecl *)>
// Note: The unfortunate use of TypeBase * here, rather than Type,
// is due to a libc++ quirk that requires the result type to be
// complete.
typedef std::function<TypeBase *(const NormalProtocolConformance *,
AssociatedTypeDecl *)>
GetTentativeTypeWitness;

/// Function that retrieves a tentative type witness for a protocol
Expand Down
3 changes: 2 additions & 1 deletion lib/AST/ProtocolConformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ NormalProtocolConformance::getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
if (getState() == ProtocolConformanceState::CheckingTypeWitnesses) {
// If there is a tentative-type-witness function, use it.
if (options.getTentativeTypeWitness) {
if (Type witnessType = options.getTentativeTypeWitness(this, assocType))
if (Type witnessType =
Type(options.getTentativeTypeWitness(this, assocType)))
return { witnessType, nullptr };
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4204,10 +4204,10 @@ void ConformanceChecker::resolveTypeWitnesses() {
SubstOptions options(None);
options.getTentativeTypeWitness =
[&](const NormalProtocolConformance *conformance,
AssociatedTypeDecl *assocType) -> Type {
if (conformance != Conformance) return Type(0);
AssociatedTypeDecl *assocType) -> TypeBase * {
if (conformance != Conformance) return nullptr;

return typeWitnesses.begin(assocType)->first;
return typeWitnesses.begin(assocType)->first.getPointer();
};

auto substitutions =
Expand Down