Skip to content

[4.0] Collected fixes #9050

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 3 commits into from
Apr 27, 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: 6 additions & 1 deletion include/swift/AST/GenericSignatureBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ class GenericSignatureBuilder::RequirementSource final
"RequirementSource kind/storageKind mismatch");

storage.type = type.getPointer();
if (kind == ProtocolRequirement)
if (isProtocolRequirement())
getTrailingObjects<ProtocolDecl *>()[0] = protocol;
if (hasTrailingWrittenRequirementLoc)
getTrailingObjects<WrittenRequirementLoc>()[0] = writtenReqLoc;
Expand Down Expand Up @@ -979,6 +979,11 @@ class GenericSignatureBuilder::RequirementSource final
llvm::function_ref<bool(PotentialArchetype *,
const RequirementSource *)> visitor) const;

/// Whether this source is a requirement in a protocol.
bool isProtocolRequirement() const {
return kind == ProtocolRequirement || kind == InferredProtocolRequirement;
}

/// Whether the requirement is inferred or derived from an inferred
/// requirement.
bool isInferredRequirement() const;
Expand Down
3 changes: 1 addition & 2 deletions lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
buildPath = [&](GenericSignature *sig, const RequirementSource *source,
ProtocolDecl *conformingProto, Type rootType) {
// Each protocol requirement is a step along the path.
if (source->kind == RequirementSource::ProtocolRequirement ||
source->kind == RequirementSource::InferredProtocolRequirement) {
if (source->isProtocolRequirement()) {
// Follow the rest of the path to derive the conformance into which
// this particular protocol requirement step would look.
auto inProtocol = source->getProtocolDecl();
Expand Down
9 changes: 4 additions & 5 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ ProtocolDecl *RequirementSource::getProtocolDecl() const {
return nullptr;

case StorageKind::StoredType:
if (kind == ProtocolRequirement)
if (isProtocolRequirement())
return getTrailingObjects<ProtocolDecl *>()[0];
return nullptr;

Expand All @@ -637,7 +637,7 @@ SourceLoc RequirementSource::getLoc() const {
// for a particular requirement, rather than turning on/off location info.
// Locations that fall into this category should be advisory, emitted via
// notes rather than as the normal location.
if (kind == ProtocolRequirement && parent &&
if (isProtocolRequirement() && parent &&
parent->kind != RequirementSignatureSelf)
return parent->getLoc();

Expand Down Expand Up @@ -668,8 +668,7 @@ SourceLoc RequirementSource::getLoc() const {
static unsigned sourcePathLength(const RequirementSource *source) {
unsigned count = 0;
for (; source; source = source->parent) {
if (source->kind == RequirementSource::ProtocolRequirement ||
source->kind == RequirementSource::InferredProtocolRequirement)
if (source->isProtocolRequirement())
++count;
}
return count;
Expand Down Expand Up @@ -942,7 +941,7 @@ bool FloatingRequirementSource::isRecursive(
llvm::SmallSet<std::pair<CanType, ProtocolDecl *>, 4> visitedAssocReqs;
for (auto storedSource = storage.dyn_cast<const RequirementSource *>();
storedSource; storedSource = storedSource->parent) {
if (storedSource->kind != RequirementSource::ProtocolRequirement)
if (!storedSource->isProtocolRequirement())
continue;

if (!visitedAssocReqs.insert(
Expand Down
8 changes: 6 additions & 2 deletions lib/Sema/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,14 @@ static void typeCheckFunctionsAndExternalDecls(TypeChecker &TC) {
// Now that all types have been finalized, run any delayed
// circularity checks.
// This has been written carefully to fail safe + finitely if
// for some reason a type gets re-delayed.
// for some reason a type gets re-delayed in a non-assertions
// build in an otherwise successful build.
// Types can be redelayed in a failing build because we won't
// type-check required declarations from different files.
for (size_t i = 0, e = TC.DelayedCircularityChecks.size(); i != e; ++i) {
TC.checkDeclCircularity(TC.DelayedCircularityChecks[i]);
assert(e == TC.DelayedCircularityChecks.size() &&
assert((e == TC.DelayedCircularityChecks.size() ||
TC.Context.hadError()) &&
"circularity checking for type was re-delayed!");
}
TC.DelayedCircularityChecks.clear();
Expand Down
5 changes: 5 additions & 0 deletions test/Sema/Inputs/circularity_multifile_error_helper.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct External {
var member: Something
}

struct OtherExternal {}
11 changes: 11 additions & 0 deletions test/Sema/circularity_multifile_error.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-swift-frontend -emit-silgen -verify -primary-file %s %S/Inputs/circularity_multifile_error_helper.swift

// SR-4594

struct A {
var b: AnUndefinedType // expected-error {{use of undeclared type 'AnUndefinedType'}}
}

struct B {
var a : External
}