collapse.carbon 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/const/collapse.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/const/collapse.carbon
  10. // OK, `const (const i32)` is the same type as `const i32`.
  11. // CHECK:STDERR: collapse.carbon:[[@LINE+3]]:25: warning: `const` applied repeatedly to the same type has no additional effect
  12. // CHECK:STDERR: fn F(p: const i32**) -> const (const i32)** {
  13. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  14. fn F(p: const i32**) -> const (const i32)** {
  15. return p;
  16. }
  17. // CHECK:STDOUT: --- collapse.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  23. // CHECK:STDOUT: %.2: type = const_type i32 [template]
  24. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  25. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  26. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  27. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  32. // CHECK:STDOUT: .Int32 = %import_ref
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/operators
  35. // CHECK:STDOUT: import Core//prelude/types
  36. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  37. // CHECK:STDOUT: import Core//prelude/operators/as
  38. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  39. // CHECK:STDOUT: import Core//prelude/operators/comparison
  40. // CHECK:STDOUT: import Core//prelude/types/bool
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .F = %F.decl
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %Core.import = import Core
  51. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  52. // CHECK:STDOUT: %p.patt: %.4 = binding_pattern p
  53. // CHECK:STDOUT: } {
  54. // CHECK:STDOUT: %int.make_type_32.loc15_15: init type = call constants.%Int32() [template = i32]
  55. // CHECK:STDOUT: %.loc15_9.1: type = value_of_initializer %int.make_type_32.loc15_15 [template = i32]
  56. // CHECK:STDOUT: %.loc15_9.2: type = converted %int.make_type_32.loc15_15, %.loc15_9.1 [template = i32]
  57. // CHECK:STDOUT: %.loc15_9.3: type = const_type i32 [template = constants.%.2]
  58. // CHECK:STDOUT: %.loc15_18: type = ptr_type %.2 [template = constants.%.3]
  59. // CHECK:STDOUT: %.loc15_19: type = ptr_type %.3 [template = constants.%.4]
  60. // CHECK:STDOUT: %p.param: %.4 = param p, runtime_param0
  61. // CHECK:STDOUT: %p: %.4 = bind_name p, %p.param
  62. // CHECK:STDOUT: %int.make_type_32.loc15_38: init type = call constants.%Int32() [template = i32]
  63. // CHECK:STDOUT: %.loc15_32.1: type = value_of_initializer %int.make_type_32.loc15_38 [template = i32]
  64. // CHECK:STDOUT: %.loc15_32.2: type = converted %int.make_type_32.loc15_38, %.loc15_32.1 [template = i32]
  65. // CHECK:STDOUT: %.loc15_32.3: type = const_type i32 [template = constants.%.2]
  66. // CHECK:STDOUT: %.loc15_25: type = const_type %.2 [template = constants.%.2]
  67. // CHECK:STDOUT: %.loc15_42: type = ptr_type %.2 [template = constants.%.3]
  68. // CHECK:STDOUT: %.loc15_43: type = ptr_type %.3 [template = constants.%.4]
  69. // CHECK:STDOUT: %return: ref %.4 = var <return slot>
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT:
  73. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @F(%p: %.4) -> %.4 {
  76. // CHECK:STDOUT: !entry:
  77. // CHECK:STDOUT: %p.ref: %.4 = name_ref p, %p
  78. // CHECK:STDOUT: return %p.ref
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: