Skip to content

Small cleanup to aid debugging and some regression tests #28026

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 4 commits into from
Nov 2, 2019
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
46 changes: 29 additions & 17 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1256,9 +1256,11 @@ AccessLevel ExtensionDecl::getMaxAccessLevel() const {

Type ExtensionDecl::getExtendedType() const {
ASTContext &ctx = getASTContext();
return evaluateOrDefault(ctx.evaluator,
ExtendedTypeRequest{const_cast<ExtensionDecl *>(this)},
ErrorType::get(ctx));
if (auto type = evaluateOrDefault(ctx.evaluator,
ExtendedTypeRequest{const_cast<ExtensionDecl *>(this)},
Type()))
return type;
return ErrorType::get(ctx);
}

/// Clone the given generic parameters in the given list. We don't need any
Expand Down Expand Up @@ -2881,19 +2883,21 @@ bool ValueDecl::isRecursiveValidation() const {
}

Type ValueDecl::getInterfaceType() const {
auto &ctx = getASTContext();

// Our clients that don't register the lazy resolver are relying on the
// fact that they can't pull an interface type out to avoid doing work.
// This is a necessary evil until we can wean them off.
if (!getASTContext().getLazyResolver()) {
if (!ctx.getLazyResolver()) {
return TypeAndAccess.getPointer();
}

if (auto Ty =
evaluateOrDefault(getASTContext().evaluator,
if (auto type =
evaluateOrDefault(ctx.evaluator,
InterfaceTypeRequest{const_cast<ValueDecl *>(this)},
ErrorType::get(getASTContext())))
return Ty;
return ErrorType::get(getASTContext());
Type()))
return type;
return ErrorType::get(ctx);
}

void ValueDecl::setInterfaceType(Type type) {
Expand Down Expand Up @@ -3695,9 +3699,11 @@ SourceRange TypeAliasDecl::getSourceRange() const {

Type TypeAliasDecl::getUnderlyingType() const {
auto &ctx = getASTContext();
return evaluateOrDefault(ctx.evaluator,
if (auto type = evaluateOrDefault(ctx.evaluator,
UnderlyingTypeRequest{const_cast<TypeAliasDecl *>(this)},
ErrorType::get(ctx));
Type()))
return type;
return ErrorType::get(ctx);
}

void TypeAliasDecl::setUnderlyingType(Type underlying) {
Expand Down Expand Up @@ -3728,10 +3734,12 @@ UnboundGenericType *TypeAliasDecl::getUnboundGenericType() const {

Type TypeAliasDecl::getStructuralType() const {
auto &ctx = getASTContext();
return evaluateOrDefault(
if (auto type = evaluateOrDefault(
ctx.evaluator,
StructuralTypeRequest{const_cast<TypeAliasDecl *>(this)},
ErrorType::get(ctx));
Type()))
return type;
return ErrorType::get(ctx);
}

Type AbstractTypeParamDecl::getSuperclass() const {
Expand Down Expand Up @@ -6313,9 +6321,11 @@ void SubscriptDecl::setIndices(ParameterList *p) {
Type SubscriptDecl::getElementInterfaceType() const {
auto &ctx = getASTContext();
auto mutableThis = const_cast<SubscriptDecl *>(this);
return evaluateOrDefault(ctx.evaluator,
if (auto type = evaluateOrDefault(ctx.evaluator,
ResultTypeRequest{mutableThis},
ErrorType::get(ctx));
Type()))
return type;
return ErrorType::get(ctx);
}

ObjCSubscriptKind SubscriptDecl::getObjCSubscriptKind() const {
Expand Down Expand Up @@ -6943,9 +6953,11 @@ StaticSpellingKind FuncDecl::getCorrectStaticSpelling() const {
Type FuncDecl::getResultInterfaceType() const {
auto &ctx = getASTContext();
auto mutableThis = const_cast<FuncDecl *>(this);
return evaluateOrDefault(ctx.evaluator,
if (auto type = evaluateOrDefault(ctx.evaluator,
ResultTypeRequest{mutableThis},
ErrorType::get(ctx));
Type()))
return type;
return ErrorType::get(ctx);
}

bool FuncDecl::isUnaryOperator() const {
Expand Down
4 changes: 1 addition & 3 deletions test/Parse/confusables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ if (true ꝸꝸꝸ false) {} // expected-note {{identifier 'ꝸꝸꝸ' contains
// expected-error @+2 {{expected ',' separator}}
// expected-error @+1 {{type '(Int, Int)' cannot conform to 'BinaryInteger'; only struct/enum/class types can conform to protocols}}
if (5 ‒ 5) == 0 {} // expected-note {{unicode character '‒' looks similar to '-'; did you mean to use '-'?}} {{7-10=-}}
// expected-note @-1 {{required by referencing operator function '==' on 'BinaryInteger' where}}
// expected-note @-1 {{required by referencing operator function '==' on 'BinaryInteger' where 'Self' = '(Int, Int)'}}

// FIXME: rdar://56002633
// Above note should read "required by referencing operator function '==' on 'BinaryInteger' where 'Self' = '(Int, Int)'"
17 changes: 17 additions & 0 deletions validation-test/compiler_crashers_2_fixed/rdar56700017.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %target-swift-frontend -typecheck %s

extension Sequence {
func sorted<T: Comparable, K: KeyPath<Element, T>>(by keyPath: K) -> Array<Element> {
self.sorted { $0[keyPath:keyPath] < $1[keyPath:keyPath] }
}
}

struct Foo {
let a: Int
}

func main() {
print([Foo(a: 2), Foo(a:1), Foo(a:4), Foo(a:3)].sorted(by: \Foo.a))
}

main()
46 changes: 46 additions & 0 deletions validation-test/compiler_crashers_2_fixed/sr8968.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// RUN: %target-swift-frontend -typecheck %s

class OFMAttachment : NativeInserting {
typealias SnapshotType = Message.Attachment
}

protocol Snapshotting {
associatedtype NativeType: NativeInserting where NativeType.SnapshotType == Self
associatedtype RecordType: SnapshotRecord where RecordType.SnapshotType == Self
associatedtype ChangeType: SnapshotChange where ChangeType.SnapshotType == Self

static var baseMessageName: String { get }
}

protocol NativeInserting {
associatedtype SnapshotType : Snapshotting where SnapshotType.NativeType == Self
}

protocol SnapshotRecord {
associatedtype SnapshotType : Snapshotting where SnapshotType.RecordType == Self

}

protocol SnapshotChange {
associatedtype SnapshotType : Snapshotting where SnapshotType.ChangeType == Self
}

struct Message {
enum Attachment : Snapshotting {

static var baseMessageName: String = "attachment"

typealias NativeType = OFMAttachment
typealias RecordType = Record
typealias ChangeType = Change
struct Record : SnapshotRecord {
typealias SnapshotType = Message.Attachment
}

struct Change : SnapshotChange {
typealias SnapshotType = Message.Attachment
}

}
}