-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Reduce use of the prelude in tests #5683
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
Conversation
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.
Thanks for splitting this out, sorry for being a pain about it.
import library "types"; | ||
|
||
fn Negate(n: i32) -> i32 = "int.snegate"; | ||
fn Negate(a: IntLiteral()) -> IntLiteral() = "int.snegate"; |
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.
fn Negate(a: IntLiteral()) -> IntLiteral() = "int.snegate"; | |
fn Negate(a: Int(32)) -> Int(32) = "int.snegate"; |
Can this more precisely match the prior i32
, or does it specifically need to be IntLiteral
to avoid a conversion?
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.
The old thing was an oversight, we only need to negate literals here. This is more obvious in snegate, where using Int(32) fails with the inputs, since they are larger values. Using Int(32) here instead adds a dependency that the test doesn't need.
library "[[@TEST_NAME]]"; | ||
|
||
class B(N:! i32); | ||
class I {} |
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.
Sorry, small thing. Can you choose something like class A
or class Other
? I
in particular I automatically think "interface".
I was already thinking about this looking at fail_generic_method.carbon, but this file uses the pattern multiple times. :)
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.
Done
// TIP: To dump output, run: | ||
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/generic/deduce_nested_facet_value.carbon | ||
|
||
// --- deduce_nested_facet_value.carbon |
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 -- to the extent that this is about performance of prelude parsing, splitting out tests shouldn't be expected to make tests faster since it's a per-file cost (actually, it'll probably marginally slow down due to the min_prelude + full prelude use instead of just full prelude).
I'd suggest leaving this where it belongs logically, and choose min_prelude based on what works, rather than using min_prelude as a primary rationale for splits.
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.
There's no min_prelude that works for both, so we'd end up with a full prelude - that's why it's moving. The deduce file needs int.carbon as a prelude and it doesn't have TypeAnd. This test needs facet_types.carbon, and it doesn't have i32.
@@ -20,7 +20,7 @@ interface J { | |||
} | |||
|
|||
impl () as J where .U = i32 { | |||
fn F[self: Self](u: i32) -> i32 { return u + 2; } | |||
fn F[self: Self](u: i32) -> i32 { return u; } |
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.
Was this possibly validating that it could make use of the +
operator on i32
? (i.e., doing some minor impls
validation)
Given min_prelude, maybe switch to -u
, which still requires an operator lookup?
fn F[self: Self](u: i32) -> i32 { return u; } | |
fn F[self: Self](u: i32) -> i32 { return -u; } |
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.
I don't think it was, this was testing the ability to call the associated function. But returning something different than it received is fine, sure.
@@ -47,7 +47,7 @@ interface J { | |||
class D { } | |||
|
|||
impl D as J where .U = i32 { | |||
fn F(u: i32) -> i32 { return u + 3; } | |||
fn F(u: i32) -> i32 { return u; } |
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.
fn F(u: i32) -> i32 { return u; } | |
fn F(u: i32) -> i32 { return -u; } |
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.
Done
@@ -66,16 +66,20 @@ interface J { | |||
class E { | |||
extend impl as J where .U = i32 { | |||
fn F(u: i32) -> i32 { | |||
return u + 1; | |||
return u; |
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.
return u; | |
return -u; |
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.
Done
} | ||
fn G[self: Self](v: i32) -> i32 { | ||
return v + 2; | ||
return v; |
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.
return v; | |
return -v; |
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.
Done
impl ImplsSomeInterface as SomeInterface(i32) { | ||
fn F(x: i32) -> i32 { | ||
return x + x; | ||
return x; |
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.
return x; | |
return -x; |
(see other comment about trying to use impls of i32
)
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.
Done
// TODO: This should call the `F` from lib1 and the `F` from lib2, where one | ||
// returns 1 and the other returns 2. Currently it calls the same function | ||
// twice, both returning 1. |
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.
I'll just note, in theory the previous "return 3" comment could be compiled and verified. Now that's not really the case. But the "returns 1" also can't be validated AFAICT, I don't think it's really obvious from the code.
Personally, I'd suggest something more like:
// TODO: This should call the `F` from lib1 and the `F` from lib2, where one | |
// returns 1 and the other returns 2. Currently it calls the same function | |
// twice, both returning 1. | |
// TODO: This should call the `F` from lib1 and the `F` from lib2. Currently | |
// it calls the same function in both (hashes match for both instances of | |
// `call i32 @_CF.Main.<hash>`). |
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.
Yeah, it's only observable/validated by reading the lower output. Thanks, done.
Co-authored-by: Jon Ross-Perkins <[email protected]>
Remove use of i32/bool when a builtin type or test-define class type can work. Make
Sub
user-defines in a test that is testing builtin functions and not trying to test the prelude, in the same way that it defines its own Negate. Reduce use of the + operator when it isn't contributing to the test's coverage, since the + operator needs the full prelude. Remove use of Core.Print when it's not required for the test.Move
deduce_nested_facet_value.carbon
to its own file since it uses TypeAnd, and the rest of deduce.carbon does not, but uses i32. This means they can each use a different min-prelude.