Skip to content

Commit 19d59b2

Browse files
danakjjonmeow
andauthored
Reduce use of the prelude in tests (#5683)
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. --------- Co-authored-by: Jon Ross-Perkins <[email protected]>
1 parent fd0f62f commit 19d59b2

15 files changed

+774
-1685
lines changed

toolchain/check/testdata/builtins/int/make_type_signed.carbon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ library "[[@TEST_NAME]]";
7878

7979
import library "types";
8080

81-
fn Negate(n: i32) -> i32 = "int.snegate";
81+
fn Negate(a: IntLiteral()) -> IntLiteral() = "int.snegate";
8282

8383
// CHECK:STDERR: fail_negative_size.carbon:[[@LINE+4]]:8: error: integer type width of -1 is not positive [IntWidthNotPositive]
8484
// CHECK:STDERR: var n: Int(Negate(1));

toolchain/check/testdata/builtins/int/snegate.carbon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ fn RuntimeCallIsValid(a: i32, b: i32) -> i32 {
3030
library "[[@TEST_NAME]]";
3131

3232
fn Negate(a: Core.IntLiteral()) -> Core.IntLiteral() = "int.snegate";
33+
fn Sub(a: Core.IntLiteral(), b: Core.IntLiteral()) -> Core.IntLiteral() = "int.ssub";
3334

3435
class Expect(N:! Core.IntLiteral()) {}
3536
fn Test(N:! Core.IntLiteral()) -> Expect(N) { return {}; }
3637

3738
fn F() {
3839
Test(Negate(0)) as Expect(0);
39-
Test(Negate(1)) as Expect(0 - 1);
40-
Test(Negate(0 - 0x8000_0000_0000_0000)) as Expect(0x8000_0000_0000_0000);
40+
Test(Negate(1)) as Expect(Sub(0, 1));
41+
Test(Negate(Sub(0, 0x8000_0000_0000_0000))) as Expect(0x8000_0000_0000_0000);
4142
}
4243

4344
// --- fail_too_few.carbon

toolchain/check/testdata/class/fail_convert_to_invalid.carbon

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// Exceptions. See /LICENSE for license information.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
//
5-
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
6-
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
7-
//
85
// AUTOUPDATE
96
// TIP: To test this file alone, run:
107
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_convert_to_invalid.carbon
@@ -20,63 +17,5 @@ class C {
2017
}
2118

2219
fn Make() -> C {
23-
return {.a = 123};
20+
return {.a = ()};
2421
}
25-
26-
// CHECK:STDOUT: --- fail_convert_to_invalid.carbon
27-
// CHECK:STDOUT:
28-
// CHECK:STDOUT: constants {
29-
// CHECK:STDOUT: %C: type = class_type @C [concrete]
30-
// CHECK:STDOUT: %pattern_type: type = pattern_type %C [concrete]
31-
// CHECK:STDOUT: %Make.type: type = fn_type @Make [concrete]
32-
// CHECK:STDOUT: %Make: %Make.type = struct_value () [concrete]
33-
// CHECK:STDOUT: %int_123: Core.IntLiteral = int_value 123 [concrete]
34-
// CHECK:STDOUT: %struct_type.a: type = struct_type {.a: Core.IntLiteral} [concrete]
35-
// CHECK:STDOUT: }
36-
// CHECK:STDOUT:
37-
// CHECK:STDOUT: imports {
38-
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
39-
// CHECK:STDOUT: import Core//prelude
40-
// CHECK:STDOUT: import Core//prelude/...
41-
// CHECK:STDOUT: }
42-
// CHECK:STDOUT: }
43-
// CHECK:STDOUT:
44-
// CHECK:STDOUT: file {
45-
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
46-
// CHECK:STDOUT: .Core = imports.%Core
47-
// CHECK:STDOUT: .C = %C.decl
48-
// CHECK:STDOUT: .NoSuchType = <poisoned>
49-
// CHECK:STDOUT: .Make = %Make.decl
50-
// CHECK:STDOUT: }
51-
// CHECK:STDOUT: %Core.import = import Core
52-
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
53-
// CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [concrete = constants.%Make] {
54-
// CHECK:STDOUT: %return.patt: %pattern_type = return_slot_pattern [concrete]
55-
// CHECK:STDOUT: %return.param_patt: %pattern_type = out_param_pattern %return.patt, call_param0 [concrete]
56-
// CHECK:STDOUT: } {
57-
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
58-
// CHECK:STDOUT: %return.param: ref %C = out_param call_param0
59-
// CHECK:STDOUT: %return: ref %C = return_slot %return.param
60-
// CHECK:STDOUT: }
61-
// CHECK:STDOUT: }
62-
// CHECK:STDOUT:
63-
// CHECK:STDOUT: class @C {
64-
// CHECK:STDOUT: %NoSuchType.ref: <error> = name_ref NoSuchType, <error> [concrete = <error>]
65-
// CHECK:STDOUT: %.loc19: <error> = field_decl a, element0 [concrete]
66-
// CHECK:STDOUT: %struct_type.a: type = struct_type {.a: <error>} [concrete = <error>]
67-
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.a [concrete = <error>]
68-
// CHECK:STDOUT: complete_type_witness = %complete_type
69-
// CHECK:STDOUT:
70-
// CHECK:STDOUT: !members:
71-
// CHECK:STDOUT: .Self = constants.%C
72-
// CHECK:STDOUT: .NoSuchType = <poisoned>
73-
// CHECK:STDOUT: .a = %.loc19
74-
// CHECK:STDOUT: }
75-
// CHECK:STDOUT:
76-
// CHECK:STDOUT: fn @Make() -> %return.param: %C {
77-
// CHECK:STDOUT: !entry:
78-
// CHECK:STDOUT: %int_123: Core.IntLiteral = int_value 123 [concrete = constants.%int_123]
79-
// CHECK:STDOUT: %.loc23: %struct_type.a = struct_literal (%int_123)
80-
// CHECK:STDOUT: return <error> to %return
81-
// CHECK:STDOUT: }
82-
// CHECK:STDOUT:

toolchain/check/testdata/class/fail_generic_method.carbon

Lines changed: 11 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -2,180 +2,34 @@
22
// Exceptions. See /LICENSE for license information.
33
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44
//
5-
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
6-
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
7-
//
85
// AUTOUPDATE
96
// TIP: To test this file alone, run:
107
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/fail_generic_method.carbon
118
// TIP: To dump output, run:
129
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_generic_method.carbon
1310

11+
class I {}
12+
1413
class Class(T:! type) {
1514
var a: T;
1615
fn F[self: Self](n: T);
1716
}
1817

1918
// TODO: The follow-on errors here aren't great. Investigate whether we can
2019
// enter the scope anyway if the parameters don't match.
21-
// CHECK:STDERR: fail_generic_method.carbon:[[@LINE+15]]:10: error: type `<pattern for i32>` of parameter 1 in redeclaration differs from previous parameter type `<pattern for type>` [RedeclParamDiffersType]
22-
// CHECK:STDERR: fn Class(N:! i32).F[self: Self](n: T) {}
20+
// CHECK:STDERR: fail_generic_method.carbon:[[@LINE+15]]:10: error: type `<pattern for I>` of parameter 1 in redeclaration differs from previous parameter type `<pattern for type>` [RedeclParamDiffersType]
21+
// CHECK:STDERR: fn Class(N:! I).F[self: Self](n: T) {}
2322
// CHECK:STDERR: ^
2423
// CHECK:STDERR: fail_generic_method.carbon:[[@LINE-10]]:13: note: previous declaration's corresponding parameter here [RedeclParamPrevious]
2524
// CHECK:STDERR: class Class(T:! type) {
2625
// CHECK:STDERR: ^
2726
// CHECK:STDERR:
28-
// CHECK:STDERR: fail_generic_method.carbon:[[@LINE+8]]:27: error: name `Self` not found [NameNotFound]
29-
// CHECK:STDERR: fn Class(N:! i32).F[self: Self](n: T) {}
30-
// CHECK:STDERR: ^~~~
27+
// CHECK:STDERR: fail_generic_method.carbon:[[@LINE+8]]:25: error: name `Self` not found [NameNotFound]
28+
// CHECK:STDERR: fn Class(N:! I).F[self: Self](n: T) {}
29+
// CHECK:STDERR: ^~~~
3130
// CHECK:STDERR:
32-
// CHECK:STDERR: fail_generic_method.carbon:[[@LINE+4]]:36: error: name `T` not found [NameNotFound]
33-
// CHECK:STDERR: fn Class(N:! i32).F[self: Self](n: T) {}
34-
// CHECK:STDERR: ^
31+
// CHECK:STDERR: fail_generic_method.carbon:[[@LINE+4]]:34: error: name `T` not found [NameNotFound]
32+
// CHECK:STDERR: fn Class(N:! I).F[self: Self](n: T) {}
33+
// CHECK:STDERR: ^
3534
// CHECK:STDERR:
36-
fn Class(N:! i32).F[self: Self](n: T) {}
37-
38-
// CHECK:STDOUT: --- fail_generic_method.carbon
39-
// CHECK:STDOUT:
40-
// CHECK:STDOUT: constants {
41-
// CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic]
42-
// CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
43-
// CHECK:STDOUT: %Class.type: type = generic_class_type @Class [concrete]
44-
// CHECK:STDOUT: %Class.generic: %Class.type = struct_value () [concrete]
45-
// CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic]
46-
// CHECK:STDOUT: %require_complete.4ae: <witness> = require_complete_type %T [symbolic]
47-
// CHECK:STDOUT: %Class.elem: type = unbound_element_type %Class, %T [symbolic]
48-
// CHECK:STDOUT: %pattern_type.3c1: type = pattern_type %Class [symbolic]
49-
// CHECK:STDOUT: %pattern_type.7dc: type = pattern_type %T [symbolic]
50-
// CHECK:STDOUT: %F.type.6d6: type = fn_type @F.1, @Class(%T) [symbolic]
51-
// CHECK:STDOUT: %F.cca: %F.type.6d6 = struct_value () [symbolic]
52-
// CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %T} [symbolic]
53-
// CHECK:STDOUT: %complete_type.f1b: <witness> = complete_type_witness %struct_type.a [symbolic]
54-
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
55-
// CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
56-
// CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
57-
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
58-
// CHECK:STDOUT: %N.51e: %i32 = bind_symbolic_name N, 0 [symbolic]
59-
// CHECK:STDOUT: %F.type.b25: type = fn_type @F.2 [concrete]
60-
// CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [concrete]
61-
// CHECK:STDOUT: }
62-
// CHECK:STDOUT:
63-
// CHECK:STDOUT: imports {
64-
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
65-
// CHECK:STDOUT: .Int = %Core.Int
66-
// CHECK:STDOUT: import Core//prelude
67-
// CHECK:STDOUT: import Core//prelude/...
68-
// CHECK:STDOUT: }
69-
// CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
70-
// CHECK:STDOUT: }
71-
// CHECK:STDOUT:
72-
// CHECK:STDOUT: file {
73-
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
74-
// CHECK:STDOUT: .Core = imports.%Core
75-
// CHECK:STDOUT: .Class = %Class.decl
76-
// CHECK:STDOUT: .T = <poisoned>
77-
// CHECK:STDOUT: }
78-
// CHECK:STDOUT: %Core.import = import Core
79-
// CHECK:STDOUT: %Class.decl: %Class.type = class_decl @Class [concrete = constants.%Class.generic] {
80-
// CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
81-
// CHECK:STDOUT: } {
82-
// CHECK:STDOUT: %T.loc14_13.1: type = bind_symbolic_name T, 0 [symbolic = %T.loc14_13.2 (constants.%T)]
83-
// CHECK:STDOUT: }
84-
// CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.2 [concrete = constants.%F.c41] {
85-
// CHECK:STDOUT: %self.patt: <error> = binding_pattern self [concrete]
86-
// CHECK:STDOUT: %self.param_patt: <error> = value_param_pattern %self.patt, call_param0 [concrete]
87-
// CHECK:STDOUT: %n.patt: <error> = binding_pattern n [concrete]
88-
// CHECK:STDOUT: %n.param_patt: <error> = value_param_pattern %n.patt, call_param1 [concrete]
89-
// CHECK:STDOUT: } {
90-
// CHECK:STDOUT: %.loc36: type = splice_block %i32 [concrete = constants.%i32] {
91-
// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
92-
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
93-
// CHECK:STDOUT: }
94-
// CHECK:STDOUT: %N.loc36_10.1: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc36_10.2 (constants.%N.51e)]
95-
// CHECK:STDOUT: %self.param: <error> = value_param call_param0
96-
// CHECK:STDOUT: %Self.ref: <error> = name_ref Self, <error> [concrete = <error>]
97-
// CHECK:STDOUT: %self: <error> = bind_name self, %self.param [concrete = <error>]
98-
// CHECK:STDOUT: %n.param: <error> = value_param call_param1
99-
// CHECK:STDOUT: %T.ref: <error> = name_ref T, <error> [concrete = <error>]
100-
// CHECK:STDOUT: %n: <error> = bind_name n, %n.param [concrete = <error>]
101-
// CHECK:STDOUT: }
102-
// CHECK:STDOUT: }
103-
// CHECK:STDOUT:
104-
// CHECK:STDOUT: generic class @Class(%T.loc14_13.1: type) {
105-
// CHECK:STDOUT: %T.loc14_13.2: type = bind_symbolic_name T, 0 [symbolic = %T.loc14_13.2 (constants.%T)]
106-
// CHECK:STDOUT:
107-
// CHECK:STDOUT: !definition:
108-
// CHECK:STDOUT: %require_complete: <witness> = require_complete_type %T.loc14_13.2 [symbolic = %require_complete (constants.%require_complete.4ae)]
109-
// CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T.loc14_13.2) [symbolic = %Class (constants.%Class)]
110-
// CHECK:STDOUT: %Class.elem: type = unbound_element_type %Class, %T.loc14_13.2 [symbolic = %Class.elem (constants.%Class.elem)]
111-
// CHECK:STDOUT: %F.type: type = fn_type @F.1, @Class(%T.loc14_13.2) [symbolic = %F.type (constants.%F.type.6d6)]
112-
// CHECK:STDOUT: %F: @Class.%F.type (%F.type.6d6) = struct_value () [symbolic = %F (constants.%F.cca)]
113-
// CHECK:STDOUT: %struct_type.a.loc17_1.2: type = struct_type {.a: @Class.%T.loc14_13.2 (%T)} [symbolic = %struct_type.a.loc17_1.2 (constants.%struct_type.a)]
114-
// CHECK:STDOUT: %complete_type.loc17_1.2: <witness> = complete_type_witness %struct_type.a.loc17_1.2 [symbolic = %complete_type.loc17_1.2 (constants.%complete_type.f1b)]
115-
// CHECK:STDOUT:
116-
// CHECK:STDOUT: class {
117-
// CHECK:STDOUT: %T.ref: type = name_ref T, %T.loc14_13.1 [symbolic = %T.loc14_13.2 (constants.%T)]
118-
// CHECK:STDOUT: %.loc15: @Class.%Class.elem (%Class.elem) = field_decl a, element0 [concrete]
119-
// CHECK:STDOUT: %F.decl: @Class.%F.type (%F.type.6d6) = fn_decl @F.1 [symbolic = @Class.%F (constants.%F.cca)] {
120-
// CHECK:STDOUT: %self.patt: @F.1.%pattern_type.loc16_8 (%pattern_type.3c1) = binding_pattern self [concrete]
121-
// CHECK:STDOUT: %self.param_patt: @F.1.%pattern_type.loc16_8 (%pattern_type.3c1) = value_param_pattern %self.patt, call_param0 [concrete]
122-
// CHECK:STDOUT: %n.patt: @F.1.%pattern_type.loc16_20 (%pattern_type.7dc) = binding_pattern n [concrete]
123-
// CHECK:STDOUT: %n.param_patt: @F.1.%pattern_type.loc16_20 (%pattern_type.7dc) = value_param_pattern %n.patt, call_param1 [concrete]
124-
// CHECK:STDOUT: } {
125-
// CHECK:STDOUT: %self.param: @F.1.%Class (%Class) = value_param call_param0
126-
// CHECK:STDOUT: %.loc16_14.1: type = splice_block %Self.ref [symbolic = %Class (constants.%Class)] {
127-
// CHECK:STDOUT: %.loc16_14.2: type = specific_constant constants.%Class, @Class(constants.%T) [symbolic = %Class (constants.%Class)]
128-
// CHECK:STDOUT: %Self.ref: type = name_ref Self, %.loc16_14.2 [symbolic = %Class (constants.%Class)]
129-
// CHECK:STDOUT: }
130-
// CHECK:STDOUT: %self: @F.1.%Class (%Class) = bind_name self, %self.param
131-
// CHECK:STDOUT: %n.param: @F.1.%T (%T) = value_param call_param1
132-
// CHECK:STDOUT: %T.ref: type = name_ref T, @Class.%T.loc14_13.1 [symbolic = %T (constants.%T)]
133-
// CHECK:STDOUT: %n: @F.1.%T (%T) = bind_name n, %n.param
134-
// CHECK:STDOUT: }
135-
// CHECK:STDOUT: %struct_type.a.loc17_1.1: type = struct_type {.a: %T} [symbolic = %struct_type.a.loc17_1.2 (constants.%struct_type.a)]
136-
// CHECK:STDOUT: %complete_type.loc17_1.1: <witness> = complete_type_witness %struct_type.a.loc17_1.1 [symbolic = %complete_type.loc17_1.2 (constants.%complete_type.f1b)]
137-
// CHECK:STDOUT: complete_type_witness = %complete_type.loc17_1.1
138-
// CHECK:STDOUT:
139-
// CHECK:STDOUT: !members:
140-
// CHECK:STDOUT: .Self = constants.%Class
141-
// CHECK:STDOUT: .T = <poisoned>
142-
// CHECK:STDOUT: .a = %.loc15
143-
// CHECK:STDOUT: .F = %F.decl
144-
// CHECK:STDOUT: }
145-
// CHECK:STDOUT: }
146-
// CHECK:STDOUT:
147-
// CHECK:STDOUT: generic fn @F.1(@Class.%T.loc14_13.1: type) {
148-
// CHECK:STDOUT: %T: type = bind_symbolic_name T, 0 [symbolic = %T (constants.%T)]
149-
// CHECK:STDOUT: %Class: type = class_type @Class, @Class(%T) [symbolic = %Class (constants.%Class)]
150-
// CHECK:STDOUT: %pattern_type.loc16_8: type = pattern_type %Class [symbolic = %pattern_type.loc16_8 (constants.%pattern_type.3c1)]
151-
// CHECK:STDOUT: %pattern_type.loc16_20: type = pattern_type %T [symbolic = %pattern_type.loc16_20 (constants.%pattern_type.7dc)]
152-
// CHECK:STDOUT:
153-
// CHECK:STDOUT: fn(%self.param: @F.1.%Class (%Class), %n.param: @F.1.%T (%T));
154-
// CHECK:STDOUT: }
155-
// CHECK:STDOUT:
156-
// CHECK:STDOUT: generic fn @F.2(%N.loc36_10.1: %i32) {
157-
// CHECK:STDOUT: %N.loc36_10.2: %i32 = bind_symbolic_name N, 0 [symbolic = %N.loc36_10.2 (constants.%N.51e)]
158-
// CHECK:STDOUT:
159-
// CHECK:STDOUT: !definition:
160-
// CHECK:STDOUT:
161-
// CHECK:STDOUT: fn(%self.param: <error>, %n.param: <error>) {
162-
// CHECK:STDOUT: !entry:
163-
// CHECK:STDOUT: return
164-
// CHECK:STDOUT: }
165-
// CHECK:STDOUT: }
166-
// CHECK:STDOUT:
167-
// CHECK:STDOUT: specific @Class(constants.%T) {
168-
// CHECK:STDOUT: %T.loc14_13.2 => constants.%T
169-
// CHECK:STDOUT: }
170-
// CHECK:STDOUT:
171-
// CHECK:STDOUT: specific @F.1(constants.%T) {
172-
// CHECK:STDOUT: %T => constants.%T
173-
// CHECK:STDOUT: %Class => constants.%Class
174-
// CHECK:STDOUT: %pattern_type.loc16_8 => constants.%pattern_type.3c1
175-
// CHECK:STDOUT: %pattern_type.loc16_20 => constants.%pattern_type.7dc
176-
// CHECK:STDOUT: }
177-
// CHECK:STDOUT:
178-
// CHECK:STDOUT: specific @F.2(constants.%N.51e) {
179-
// CHECK:STDOUT: %N.loc36_10.2 => constants.%N.51e
180-
// CHECK:STDOUT: }
181-
// CHECK:STDOUT:
35+
fn Class(N:! I).F[self: Self](n: T) {}

0 commit comments

Comments
 (0)