-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Check equality constraints when checking whether a constraint is satisfied #2294
Merged
zygoloid
merged 8 commits into
carbon-language:trunk
from
zygoloid:explorer-check-equality
Oct 18, 2022
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ae828c6
Add checking that equalities are satisfied.
zygoloid 09bd730
Remove single-step equality and require `=` to be used in impls.
zygoloid 9eeb298
Fix handling of references to generic binding's .Self in its own type.
zygoloid 334eab9
Fix instantiation of witnesses to not fail when interpreting a symbol…
zygoloid 0a90bd1
Add tests for matching and mismatching values.
zygoloid 2bfe19c
Remove lookup into witness from single-step equality checking.
zygoloid 1ed5cba
Factor out some duplicated checks.
zygoloid 26a5f9d
Improve error message.
zygoloid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
explorer/testdata/assoc_const/fail_equal_indirectly.carbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
// Exceptions. See /LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// RUN: %{not} %{explorer} %s | %{FileCheck-strict} %s | ||
// RUN: %{not} %{explorer-trace} %s | %{FileCheck-allow-unmatched} %s | ||
// AUTOUPDATE: %{explorer} %s | ||
|
||
package ExplorerTest api; | ||
|
||
interface Iface { | ||
let T:! Type; | ||
} | ||
|
||
fn F[T:! Iface where .T == i32](x: T) {} | ||
|
||
class Class { | ||
impl as Iface where .T = i32 {} | ||
} | ||
|
||
// OK, constraint on `F` rewritten to `T:! Iface where U == i32`, which we can | ||
// prove from the constraint on `U`. | ||
fn G[U:! Type where .Self == i32, T:! Iface where .T = U](x: T, y: U) { | ||
F(x); | ||
} | ||
|
||
// Not OK: would require looking through two levels of `==`. | ||
fn H[U:! Type where .Self == i32, T:! Iface where .T == U](x: T, y: U) { | ||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assoc_const/fail_equal_indirectly.carbon:[[@LINE+1]]: constraint requires that (T).(Iface.T) == i32, which is not known to be true | ||
F(x); | ||
} | ||
|
||
fn Main() -> i32 { | ||
var x: Class = {}; | ||
G(x, 0); | ||
H(x, 0); | ||
return 0; | ||
} |
35 changes: 35 additions & 0 deletions
35
explorer/testdata/assoc_const/fail_equal_to_dependent_type.carbon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM | ||
// Exceptions. See /LICENSE for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// RUN: %{not} %{explorer} %s | %{FileCheck-strict} %s | ||
// RUN: %{not} %{explorer-trace} %s | %{FileCheck-allow-unmatched} %s | ||
// AUTOUPDATE: %{explorer} %s | ||
|
||
package ExplorerTest api; | ||
|
||
interface Iface { | ||
let T:! Type; | ||
} | ||
|
||
fn F[T:! Iface where .T == i32](x: T) {} | ||
|
||
fn G[T:! Iface where .T == i32](x: T) { | ||
F(x); | ||
} | ||
|
||
fn H[T:! Iface](x: T) { | ||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/assoc_const/fail_equal_to_dependent_type.carbon:[[@LINE+1]]: constraint requires that (T).(Iface.T) == i32, which is not known to be true | ||
F(x); | ||
} | ||
|
||
class Class { | ||
impl as Iface where .T = i32 {} | ||
} | ||
|
||
fn Main() -> i32 { | ||
var x: Class = {}; | ||
G(x); | ||
H(x); | ||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I think this name a bit hard to interpret, maybe "IsDependentType" similar to "IsConcreteType" or "IsType"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this doesn't tell you whether the type is dependent, at least in the C++ sense. For example,
Vector(T)
would probably be considered a dependent type, but the value kind (NominalClassType
) is not dependent -- this is specifically determining whether theValue::Kind
is dependent. I'm having a hard time finding a better name that's still appropriate.