Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(828)

Unified Diff: runtime/vm/isolate_reload_test.cc

Issue 2993013002: Introduce IKG into kernel-service to support incremental compilation. (Closed)
Patch Set: Add TODO to add assert that isolate exists. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/kernel_isolate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/isolate_reload_test.cc
diff --git a/runtime/vm/isolate_reload_test.cc b/runtime/vm/isolate_reload_test.cc
index ea63190baed91aeb0a2d80d9d17a12bbc1f7a7a1..cbe991bd7d588b05383db4fe4f0ec17f8c9d68a7 100644
--- a/runtime/vm/isolate_reload_test.cc
+++ b/runtime/vm/isolate_reload_test.cc
@@ -67,6 +67,217 @@ TEST_CASE(IsolateReload_FunctionReplacement) {
EXPECT_EQ(10, SimpleInvoke(lib, "main"));
}
+TEST_CASE(IsolateReload_IncrementalCompile) {
+ const char* kScriptChars =
+ "main() {\n"
+ " return 42;\n"
+ "}\n";
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
+ EXPECT_VALID(lib);
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ int64_t value = 0;
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(42, value);
+
+ const char* kUpdatedScriptChars =
+ "main() {\n"
+ " return 24;\n"
+ "}\n"
+ "";
+ lib = TestCase::ReloadTestScript(kUpdatedScriptChars);
+ EXPECT_VALID(lib);
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(24, value);
+}
+
+TEST_CASE(IsolateReload_KernelIncrementalCompile) {
+ // clang-format off
+ Dart_SourceFile sourcefiles[] = {
+ {
+ "file:///test-app",
+ "main() {\n"
+ " return 42;\n"
+ "}\n",
+ },
+ {
+ "file:///.packages", "untitled:/"
+ }};
+ // clang-format on
+
+ Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
+ sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
+ NULL /* resolver */, true /* finalize */, true /* incrementally */);
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ int64_t value = 0;
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(42, value);
+
+ // clang-format off
+ Dart_SourceFile updated_sourcefiles[] = {
+ {
+ "file:///test-app",
+ "main() {\n"
+ " return 24;\n"
+ "}\n"
+ ""
+ }};
+ // clang-format on
+ {
+ void* kernel_pgm = NULL;
+ char* error = TestCase::CompileTestScriptWithDFE(
+ "file:///test-app",
+ sizeof(updated_sourcefiles) / sizeof(Dart_SourceFile),
+ updated_sourcefiles, &kernel_pgm, true /* incrementally */);
+ EXPECT(error == NULL);
+ EXPECT_NOTNULL(kernel_pgm);
+
+ lib = TestCase::ReloadTestKernel(kernel_pgm);
+ EXPECT_VALID(lib);
+ }
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(24, value);
+}
+
+TEST_CASE(IsolateReload_KernelIncrementalCompileAppAndLib) {
+ // clang-format off
+ Dart_SourceFile sourcefiles[] = {
+ {
+ "file:///test-app.dart",
+ "import 'test-lib.dart';\n"
+ "main() {\n"
+ " return WhatsTheMeaningOfAllThis();\n"
+ "}\n",
+ },
+ {
+ "file:///test-lib.dart",
+ "WhatsTheMeaningOfAllThis() {\n"
+ " return 42;\n"
+ "}\n",
+ },
+ {
+ "file:///.packages", "untitled:/"
+ }};
+ // clang-format on
+
+ Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
+ sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
+ NULL /* resolver */, true /* finalize */, true /* incrementally */);
+ EXPECT_VALID(lib);
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ int64_t value = 0;
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(42, value);
+
+ // clang-format off
+ Dart_SourceFile updated_sourcefiles[] = {
+ {
+ "file:///test-lib.dart",
+ "WhatsTheMeaningOfAllThis() {\n"
+ " return 24;\n"
+ "}\n"
+ ""
+ }};
+ // clang-format on
+ {
+ void* kernel_pgm = NULL;
+ char* error = TestCase::CompileTestScriptWithDFE(
+ "file:///test-app",
+ sizeof(updated_sourcefiles) / sizeof(Dart_SourceFile),
+ updated_sourcefiles, &kernel_pgm, true /* incrementally */);
+ EXPECT(error == NULL);
+ EXPECT_NOTNULL(kernel_pgm);
+
+ lib = TestCase::ReloadTestKernel(kernel_pgm);
+ EXPECT_VALID(lib);
+ }
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(24, value);
+}
+
+TEST_CASE(IsolateReload_KernelIncrementalCompileGenerics) {
+ // clang-format off
+ Dart_SourceFile sourcefiles[] = {
+ {
+ "file:///test-app.dart",
+ "import 'test-lib.dart';\n"
+ "class Account {\n"
+ " int balance() => 42;\n"
+ "}\n"
+ "class MyAccountState extends State<Account> {\n"
+ " MyAccountState(Account a): super(a) {}\n"
+ "}\n"
+ "main() {\n"
+ " return (new MyAccountState(new Account()))\n"
+ " .howAreTheThings().balance();\n"
+ "}\n",
+ },
+ {
+ "file:///test-lib.dart",
+ "class State<T> {\n"
+ " T t;"
+ " State(this.t);\n"
+ " T howAreTheThings() => t;\n"
+ "}\n",
+ },
+ {
+ "file:///.packages", "untitled:/"
+ }};
+ // clang-format on
+
+ Dart_Handle lib = TestCase::LoadTestScriptWithDFE(
+ sizeof(sourcefiles) / sizeof(Dart_SourceFile), sourcefiles,
+ NULL /* resolver */, true /* finalize */, true /* incrementally */);
+ EXPECT_VALID(lib);
+ Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ int64_t value = 0;
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(42, value);
+
+ // clang-format off
+ Dart_SourceFile updated_sourcefiles[] = {
+ {
+ "file:///test-app.dart",
+ "import 'test-lib.dart';\n"
+ "class Account {\n"
+ " int balance() => 24;\n"
+ "}\n"
+ "class MyAccountState extends State<Account> {\n"
+ " MyAccountState(Account a): super(a) {}\n"
+ "}\n"
+ "main() {\n"
+ " return (new MyAccountState(new Account()))\n"
+ " .howAreTheThings().balance();\n"
+ "}\n",
+ }};
+ // clang-format on
+ {
+ void* kernel_pgm = NULL;
+ char* error = TestCase::CompileTestScriptWithDFE(
+ "file:///test-app",
+ sizeof(updated_sourcefiles) / sizeof(Dart_SourceFile),
+ updated_sourcefiles, &kernel_pgm, true /* incrementally */);
+ EXPECT(error == NULL);
+ EXPECT_NOTNULL(kernel_pgm);
+
+ lib = TestCase::ReloadTestKernel(kernel_pgm);
+ EXPECT_VALID(lib);
+ }
+ result = Dart_Invoke(lib, NewString("main"), 0, NULL);
+ result = Dart_IntegerToInt64(result, &value);
+ EXPECT_VALID(result);
+ EXPECT_EQ(24, value);
+}
+
TEST_CASE(IsolateReload_BadClass) {
const char* kScript =
"class Foo {\n"
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/kernel_isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698