instantiations_are_cached.carbon 692 B

1234567891011121314151617181920212223242526272829303132
  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. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. interface I { fn F(); }
  8. impl () as I {
  9. fn F() {}
  10. }
  11. impl forall [template T:! type] (T,) as I {
  12. fn F() {
  13. if (true) {
  14. T.(I.F)();
  15. } else {
  16. T.(I.F)();
  17. }
  18. }
  19. }
  20. fn Main() -> i32 {
  21. // This would cause an exponential number of template instantiations if we
  22. // didn't cache them.
  23. ((((((((((((((((((((((((((((((((),),),),),),),),),),),),),),),),),),),),),),),),),),),),),),)).(I.F)();
  24. return 0;
  25. }
  26. // CHECK:STDOUT: result: 0