Skip to content

Fix getDirectlyInheritedNominalTypeDecls #28546

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
Dec 4, 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
3 changes: 2 additions & 1 deletion include/swift/AST/TypeCheckRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ class RequirementSignatureRequest :
friend SimpleRequest;

// Evaluation.
llvm::Expected<ArrayRef<Requirement>> evaluate(Evaluator &evaluator, ProtocolDecl *proto) const;
llvm::Expected<ArrayRef<Requirement>> evaluate(Evaluator &evaluator,
ProtocolDecl *proto) const;

public:
// Separate caching.
Expand Down
21 changes: 21 additions & 0 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,27 @@ swift::getDirectlyInheritedNominalTypeDecls(
// FIXME: Refactor SelfBoundsFromWhereClauseRequest to dig out
// the source location.
SourceLoc loc = SourceLoc();

// For a deserialized protocol, the where clause isn't going to tell us
// anything. Ask the requirement signature instead.
if (protoDecl->wasDeserialized()) {
auto protoSelfTy = protoDecl->getSelfInterfaceType();
for (auto &req : protoDecl->getRequirementSignature()) {
// Dig out a conformance requirement...
if (req.getKind() != RequirementKind::Conformance)
continue;

// constraining Self.
if (!req.getFirstType()->isEqual(protoSelfTy))
continue;

result.emplace_back(
loc, req.getSecondType()->castTo<ProtocolType>()->getDecl());
}
return result;
}

// Else we have access to this information on the where clause.
auto selfBounds = getSelfBoundsFromWhereClause(decl);
anyObject |= selfBounds.anyObject;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
protocol View {
associatedtype Body: View

var body: Self.Body { get }
}

extension Never: View {
typealias Body = Never

var body: Self.Body { fatalError() }
}

struct AnyView: View {
var body: Never { fatalError() }
}

protocol ViewModelRenderable {
var view: AnyView { get }
}

extension ViewModelRenderable where Self: SectionModel {
static func view<Model, MyView: SectionViewModelView>(for model: Model, ofType: MyView.Type) -> AnyView where Model == MyView.BodyViewModel {
fatalError()
}
}

protocol SectionViewModelView where Self: View {
associatedtype BodyViewModel: SectionModel

init(bodyViewModel: BodyViewModel)
}

public protocol SectionModel: Codable {
var sectionName: String { get }
}

extension SectionModel {
public var sectionName: String {
"Hello world!"
}
}

struct NewUserModel: SectionModel {
}

extension NewUserModel: ViewModelRenderable {
var view: AnyView { Self.view(for: self, ofType: NewUserView.self) }
}

struct NewUserView: SectionViewModelView {
var bodyViewModel: NewUserModel = .init()

var body: Never {
fatalError()
}
}
22 changes: 22 additions & 0 deletions test/Interpreter/dynamic_replacement_protocol_self.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift-dylib(%t/%target-library-name(TestModuleLinking)) -module-name TestModuleLinking -emit-module -emit-module-path %t/TestModuleLinking.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_protocol_self_orig.swift -Xfrontend -enable-private-imports -Xfrontend -enable-implicit-dynamic
// RUN: %target-build-swift -I%t -L%t -lTestModuleLinking -o %t/main %target-rpath(%t) %s -swift-version 5
// RUN: %target-codesign %t/main %t/%target-library-name(TestModuleLinking)
// RUN: %target-run %t/main %t/%target-library-name(TestModuleLinking) %t/%target-library-name(TestModuleLinking)

// N.B. We're not actually executing anything here - all we care about is
// if the linker is content.

// REQUIRES: executable_test

// UNSUPPORTED: swift_test_mode_optimize_none_with_implicit_dynamic

@_private(sourceFile: "dynamic_replacement_protocol_self_orig.swift") import TestModuleLinking

extension NewUserModel {
@_dynamicReplacement(for: view) private var __preview__view: AnyView {
Self.view(for: self, ofType: NewUserView.self)
}
}

typealias NewUserModel = TestModuleLinking.NewUserModel