<commit_before>// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// This test tries to verify that we produce the correct stack trace when
// throwing exceptions even when functions are inlined.
// The test invokes a bunch of functions and then does a throw. There is a
// catch at the outer function which uses the stack trace produced to return
// a string. The test then verifies that the stack trace contains each
// method in the invocation chain. The test is run during warmup to ensure
// unoptimized code produces the correct result and is then run
// in a loop to ensure optimization kicks in and some inlining is done.
// Note: it appears that functions which have a throw are not inlined (func4)
//       func2 and func1 are not getting inlined and I am not able to explain
//       why inlining is not attempted on those.

class Test {
  String func1(var k) {
    try {
      for (var i = 0; i <= 50; i++) {
        func2(i * k);
      }
      return "";
    } catch (e, stacktrace) {
      var result = e.concat(stacktrace.toString());
      return result;
    }
  }
  int func2(var i) {
    var result = 0;
    for (var k = 0; k <= 10; k++) {
      result += func2a(i + k);
    }
    return result;
  }
  int func2a(var i) {
    var result = 0;
    for (var l = 0; l <= 1; l++) {
      result += func3(i + l);
    }
    return result;
  }
  int func3(var i) {
    var result = 0;
    for (var j = 0; j <= 10; j++) {
      result += func4(i + j);
    }
    return result;
  }
  int func4(var i) {
    if (i >= 1030) throw "show me inlined functions";
    return i;
  }
}

main() {
  var x = new Test();
  var result = x.func1(100000);
  Expect.isTrue(result.contains("show me inlined functions"));
  Expect.isTrue(result.contains("Test.func1"));
  Expect.isTrue(result.contains("Test.func2"));
  Expect.isTrue(result.contains("Test.func2a"));
  Expect.isTrue(result.contains("Test.func3"));
  Expect.isTrue(result.contains("Test.func4"));
  for (var i = 0; i <= 200; i++) {
    result = x.func1(i);
  }
  Expect.isTrue(result.contains("show me inlined functions"));
  Expect.isTrue(result.contains("Test.func1"));
  Expect.isTrue(result.contains("Test.func2"));
  Expect.isTrue(result.contains("Test.func2a"));
  Expect.isTrue(result.contains("Test.func3"));
  Expect.isTrue(result.contains("Test.func4"));
}<commit_msg>Fix comment in test case. Review URL: https://codereview.chromium.org//11783035<commit_after>// Copyright (c) 2012, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// This test tries to verify that we produce the correct stack trace when
// throwing exceptions even when functions are inlined.
// The test invokes a bunch of functions and then does a throw. There is a
// catch at the outer function which uses the stack trace produced to return
// a string. The test then verifies that the stack trace contains each
// method in the invocation chain. The test is run during warmup to ensure
// unoptimized code produces the correct result and is then run
// in a loop to ensure optimization kicks in and some inlining is done.
// Note: it appears that functions which have a throw are not inlined (func4)
//       and functions that have try/catch in them are not optimized (func1).
//       func2 is not inlined as func1 has not been optimized.

class Test {
  String func1(var k) {
    try {
      for (var i = 0; i <= 50; i++) {
        func2(i * k);
      }
      return "";
    } catch (e, stacktrace) {
      var result = e.concat(stacktrace.toString());
      return result;
    }
  }
  int func2(var i) {
    var result = 0;
    for (var k = 0; k <= 10; k++) {
      result += func3(i + k);
    }
    return result;
  }
  int func3(var i) {
    var result = 0;
    for (var l = 0; l <= 1; l++) {
      result += func4(i + l);
    }
    return result;
  }
  int func4(var i) {
    var result = 0;
    for (var j = 0; j <= 10; j++) {
      result += func5(i + j);
    }
    return result;
  }
  int func5(var i) {
    if (i >= 1030) throw "show me inlined functions";
    return i;
  }
}

main() {
  var x = new Test();
  var result = x.func1(100000);
  Expect.isTrue(result.contains("show me inlined functions"));
  Expect.isTrue(result.contains("Test.func1"));
  Expect.isTrue(result.contains("Test.func2"));
  Expect.isTrue(result.contains("Test.func3"));
  Expect.isTrue(result.contains("Test.func4"));
  Expect.isTrue(result.contains("Test.func"));
  for (var i = 0; i <= 200; i++) {
    result = x.func1(i);
  }
  Expect.isTrue(result.contains("show me inlined functions"));
  Expect.isTrue(result.contains("Test.func1"));
  Expect.isTrue(result.contains("Test.func2"));
  Expect.isTrue(result.contains("Test.func3"));
  Expect.isTrue(result.contains("Test.func4"));
  Expect.isTrue(result.contains("Test.func5"));
}
{'fraction_non_alphanumeric': 0.12827586206896552, 'fraction_numerical': 0.023645320197044337, 'mean_word_length': 2.962529274004684, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4663664', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1582, 'n_words': 593}