Skip to content

RequirementMachine: Enable -requirement-machine-protocol-signatures=verify by default #40492

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
Feb 25, 2022
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
2 changes: 2 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.DisableSubstSILFunctionTypes =
Args.hasArg(OPT_disable_subst_sil_function_types);

Opts.RequirementMachineProtocolSignatures = RequirementMachineMode::Verify;

if (auto A = Args.getLastArg(OPT_requirement_machine_protocol_signatures_EQ)) {
auto value = llvm::StringSwitch<Optional<RequirementMachineMode>>(A->getValue())
.Case("off", RequirementMachineMode::Disabled)
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2619,9 +2619,11 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
getDeclContext()->getSelfProtocolDecl()) {
diagnoseInvalid(repr, attrs.getLoc(TAK_unchecked),
diag::unchecked_not_inheritance_clause);
ty = ErrorType::get(getASTContext());
} else if (!ty->isConstraintType()) {
diagnoseInvalid(repr, attrs.getLoc(TAK_unchecked),
diag::unchecked_not_existential, ty);
ty = ErrorType::get(getASTContext());
}

// Nothing to record in the type. Just clear the attribute.
Expand Down
59 changes: 59 additions & 0 deletions test/Generics/derived_via_concrete_in_protocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=off
// RUN: %target-swift-frontend -debug-generic-signatures -typecheck %s -requirement-machine-protocol-signatures=off 2>&1 | %FileCheck %s

// FIXME: Implement concrete contraction for the Requirement Machine's
// RequirementSignatureRequest to get this to pass without turning off
// -requirement-machine-protocol-signatures.

protocol P24 {
associatedtype C: P20
}

protocol P20 { }

struct X24<T: P20> : P24 {
typealias C = T
}

protocol P26 {
associatedtype C: X3
}

struct X26<T: X3> : P26 {
typealias C = T
}

class X3 { }

// CHECK-LABEL: .P25a@
// CHECK-NEXT: Requirement signature: <Self where Self.[P25a]A == X24<Self.[P25a]B>, Self.[P25a]B : P20>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P25a]A == X24<τ_0_0.[P25a]B>, τ_0_0.[P25a]B : P20>
protocol P25a {
associatedtype A: P24 // expected-warning{{redundant conformance constraint 'Self.A' : 'P24'}}
associatedtype B: P20 where A == X24<B> // expected-note{{conformance constraint 'Self.A' : 'P24' implied here}}
}

// CHECK-LABEL: .P25b@
// CHECK-NEXT: Requirement signature: <Self where Self.[P25b]A == X24<Self.[P25b]B>, Self.[P25b]B : P20>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P25b]A == X24<τ_0_0.[P25b]B>, τ_0_0.[P25b]B : P20>
protocol P25b {
associatedtype A
associatedtype B: P20 where A == X24<B>
}

// CHECK-LABEL: .P27a@
// CHECK-NEXT: Requirement signature: <Self where Self.[P27a]A == X26<Self.[P27a]B>, Self.[P27a]B : X3>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P27a]A == X26<τ_0_0.[P27a]B>, τ_0_0.[P27a]B : X3>
protocol P27a {
associatedtype A: P26 // expected-warning{{redundant conformance constraint 'Self.A' : 'P26'}}

associatedtype B: X3 where A == X26<B> // expected-note{{conformance constraint 'Self.A' : 'P26' implied here}}
}

// CHECK-LABEL: .P27b@
// CHECK-NEXT: Requirement signature: <Self where Self.[P27b]A == X26<Self.[P27b]B>, Self.[P27b]B : X3>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P27b]A == X26<τ_0_0.[P27b]B>, τ_0_0.[P27b]B : X3>
protocol P27b {
associatedtype A
associatedtype B: X3 where A == X26<B>
}
46 changes: 2 additions & 44 deletions test/Generics/requirement_inference.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -debug-generic-signatures > %t.dump 2>&1
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=verify
// RUN: %target-typecheck-verify-swift -debug-generic-signatures > %t.dump -requirement-machine-protocol-signatures=verify 2>&1
// RUN: %FileCheck %s < %t.dump

protocol P1 {
Expand Down Expand Up @@ -323,22 +323,6 @@ struct X24<T: P20> : P24 {
typealias C = T
}

// CHECK-LABEL: .P25a@
// CHECK-NEXT: Requirement signature: <Self where Self.[P25a]A == X24<Self.[P25a]B>, Self.[P25a]B : P20>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P25a]A == X24<τ_0_0.[P25a]B>, τ_0_0.[P25a]B : P20>
protocol P25a {
associatedtype A: P24 // expected-warning{{redundant conformance constraint 'Self.A' : 'P24'}}
associatedtype B: P20 where A == X24<B> // expected-note{{conformance constraint 'Self.A' : 'P24' implied here}}
}

// CHECK-LABEL: .P25b@
// CHECK-NEXT: Requirement signature: <Self where Self.[P25b]A == X24<Self.[P25b]B>, Self.[P25b]B : P20>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P25b]A == X24<τ_0_0.[P25b]B>, τ_0_0.[P25b]B : P20>
protocol P25b {
associatedtype A
associatedtype B: P20 where A == X24<B>
}

protocol P25c {
associatedtype A: P24
associatedtype B where A == X<B> // expected-error{{cannot find type 'X' in scope}}
Expand All @@ -349,32 +333,6 @@ protocol P25d {
associatedtype B where A == X24<B> // expected-error{{type 'Self.B' does not conform to protocol 'P20'}}
}

// Similar to the above, but with superclass constraints.
protocol P26 {
associatedtype C: X3
}

struct X26<T: X3> : P26 {
typealias C = T
}

// CHECK-LABEL: .P27a@
// CHECK-NEXT: Requirement signature: <Self where Self.[P27a]A == X26<Self.[P27a]B>, Self.[P27a]B : X3>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P27a]A == X26<τ_0_0.[P27a]B>, τ_0_0.[P27a]B : X3>
protocol P27a {
associatedtype A: P26 // expected-warning{{redundant conformance constraint 'Self.A' : 'P26'}}

associatedtype B: X3 where A == X26<B> // expected-note{{conformance constraint 'Self.A' : 'P26' implied here}}
}

// CHECK-LABEL: .P27b@
// CHECK-NEXT: Requirement signature: <Self where Self.[P27b]A == X26<Self.[P27b]B>, Self.[P27b]B : X3>
// CHECK-NEXT: Canonical requirement signature: <τ_0_0 where τ_0_0.[P27b]A == X26<τ_0_0.[P27b]B>, τ_0_0.[P27b]B : X3>
protocol P27b {
associatedtype A
associatedtype B: X3 where A == X26<B>
}

// ----------------------------------------------------------------------------
// Inference of associated type relationships within a protocol hierarchy
// ----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %target-typecheck-verify-swift -disable-availability-checking
// RUN: %target-typecheck-verify-swift -disable-availability-checking -requirement-machine-protocol-signatures=off

// TODO: Get this to pass with -requirement-machine-protocol-signatures=on.

//===----------------------------------------------------------------------===//
// Use of protocols with Self or associated type requirements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %target-typecheck-verify-swift
// RUN: not %target-swift-frontend -typecheck -dump-type-witness-systems %s 2>&1 | %FileCheck %s
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=off
// RUN: not %target-swift-frontend -typecheck -dump-type-witness-systems %s -requirement-machine-protocol-signatures=off 2>&1 | %FileCheck %s

// TODO: Get this to pass with -requirement-machine-protocol-signatures=on.

protocol P1 where A == Never {
associatedtype A
Expand Down
4 changes: 3 additions & 1 deletion validation-test/compiler_crashers_2_fixed/rdar56398071.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir
// RUN: %target-swift-frontend -primary-file %s -emit-ir -requirement-machine-protocol-signatures=off

// TODO: Get this to pass with -requirement-machine-protocol-signatures=on.

public protocol WrappedSignedInteger: SignedInteger where Stride == Int {
typealias WrappedInteger = Int
Expand Down