[vm] Fix some missing private name mangling in the kernel reader.

Bug: https://github.com/dart-lang/sdk/issues/32345
Bug: https://github.com/dart-lang/sdk/issues/33326
Bug: https://github.com/dart-lang/sdk/issues/33345
Change-Id: I89fb8f0332ef6f9f40de59c219af2a7c23e5943f
Reviewed-on: https://dart-review.googlesource.com/58400
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
diff --git a/runtime/lib/mirrors_impl.dart b/runtime/lib/mirrors_impl.dart
index 639d6d8..902e7ff 100644
--- a/runtime/lib/mirrors_impl.dart
+++ b/runtime/lib/mirrors_impl.dart
@@ -793,7 +793,8 @@
   List<ParameterMirror> _parameters;
   List<ParameterMirror> get parameters {
     if (_parameters == null) {
-      _parameters = _FunctionTypeMirror_parameters(_functionReflectee);
+      _parameters = _FunctionTypeMirror_parameters(_functionReflectee)
+          .cast<ParameterMirror>();
       _parameters = new UnmodifiableListView<ParameterMirror>(_parameters);
     }
     return _parameters;
diff --git a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
index 0507fcd..cd27d7b 100644
--- a/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
+++ b/runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
@@ -1281,7 +1281,7 @@
 
           closure.SetParameterTypeAt(pos, type);
           closure.SetParameterNameAt(pos,
-                                     H.DartSymbolObfuscate(helper.name_index_));
+                                     H.DartIdentifier(lib, helper.name_index_));
         }
 
         intptr_t named_parameter_count_check = builder_->ReadListLength();
@@ -1298,7 +1298,7 @@
 
           closure.SetParameterTypeAt(pos, type);
           closure.SetParameterNameAt(pos,
-                                     H.DartSymbolObfuscate(helper.name_index_));
+                                     H.DartIdentifier(lib, helper.name_index_));
         }
 
         function_node_helper.SetJustRead(FunctionNodeHelper::kNamedParameters);
@@ -3973,10 +3973,10 @@
 }
 
 void StreamingConstantEvaluator::EvaluateSymbolLiteral() {
-  // The symbol value is read plain and obfuscated later.
-  const String& symbol_value = H.DartSymbolPlain(
-      builder_->ReadStringReference());  // read index into string table.
-
+  const Class& owner =
+      Class::Handle(Z, builder_->parsed_function()->function().Owner());
+  const Library& lib = Library::Handle(Z, owner.library());
+  String& symbol_value = H.DartIdentifier(lib, builder_->ReadStringReference());
   const Class& symbol_class =
       Class::ZoneHandle(Z, I->object_store()->symbol_class());
   ASSERT(!symbol_class.IsNull());
@@ -10871,6 +10871,7 @@
 
   // Step a) Create array of [TypeParameter] objects (without bound).
   type_parameters = TypeArguments::New(type_parameter_count);
+  const Library& lib = Library::Handle(Z, active_class->klass->library());
   {
     AlternativeReadingScope alt(&reader_);
     for (intptr_t i = 0; i < type_parameter_count; i++) {
@@ -10879,7 +10880,7 @@
       parameter = TypeParameter::New(
           set_on_class ? *active_class->klass : Class::Handle(Z),
           parameterized_function, i,
-          H.DartSymbolObfuscate(helper.name_index_),  // read ith name index.
+          H.DartIdentifier(lib, helper.name_index_),  // read ith name index.
           null_bound, TokenPosition::kNoSource);
       type_parameters.SetTypeAt(i, parameter);
     }
@@ -10984,6 +10985,7 @@
     pos++;
   }
 
+  const Library& lib = Library::Handle(Z, active_class->klass->library());
   for (intptr_t i = 0; i < positional_parameter_count; ++i, ++pos) {
     // Read ith variable declaration.
     VariableDeclarationHelper helper(this);
@@ -10996,7 +10998,7 @@
 
     function.SetParameterTypeAt(
         pos, type.IsMalformed() ? Type::dynamic_type() : type);
-    function.SetParameterNameAt(pos, H.DartSymbolObfuscate(helper.name_index_));
+    function.SetParameterNameAt(pos, H.DartIdentifier(lib, helper.name_index_));
   }
 
   intptr_t named_parameter_count_check = ReadListLength();  // read list length.
@@ -11013,7 +11015,7 @@
 
     function.SetParameterTypeAt(
         pos, type.IsMalformed() ? Type::dynamic_type() : type);
-    function.SetParameterNameAt(pos, H.DartSymbolObfuscate(helper.name_index_));
+    function.SetParameterNameAt(pos, H.DartIdentifier(lib, helper.name_index_));
   }
 
   function_node_helper->SetJustRead(FunctionNodeHelper::kNamedParameters);
diff --git a/runtime/vm/compiler/frontend/kernel_to_il.cc b/runtime/vm/compiler/frontend/kernel_to_il.cc
index 83a5a4e..d7f2f9d 100644
--- a/runtime/vm/compiler/frontend/kernel_to_il.cc
+++ b/runtime/vm/compiler/frontend/kernel_to_il.cc
@@ -487,6 +487,13 @@
   return result;
 }
 
+String& TranslationHelper::DartIdentifier(const Library& lib,
+                                          StringIndex string_index) {
+  String& name = DartString(string_index);
+  ManglePrivateName(lib, &name);
+  return name;
+}
+
 const String& TranslationHelper::DartClassName(NameIndex kernel_class) {
   ASSERT(IsClass(kernel_class));
   String& name = DartString(CanonicalNameString(kernel_class));
diff --git a/runtime/vm/compiler/frontend/kernel_to_il.h b/runtime/vm/compiler/frontend/kernel_to_il.h
index dd0d4b2..1559f4f 100644
--- a/runtime/vm/compiler/frontend/kernel_to_il.h
+++ b/runtime/vm/compiler/frontend/kernel_to_il.h
@@ -395,6 +395,8 @@
   const String& DartSymbolObfuscate(const char* content) const;
   String& DartSymbolObfuscate(StringIndex string_index) const;
 
+  String& DartIdentifier(const Library& lib, StringIndex string_index);
+
   const String& DartClassName(NameIndex kernel_class);
 
   const String& DartConstructorName(NameIndex constructor);
diff --git a/tests/lib_2/lib_2_kernel.status b/tests/lib_2/lib_2_kernel.status
index 91e739c..43bb4a0 100644
--- a/tests/lib_2/lib_2_kernel.status
+++ b/tests/lib_2/lib_2_kernel.status
@@ -108,7 +108,7 @@
 mirrors/class_mirror_location_test: RuntimeError
 mirrors/constructor_kinds_test/01: RuntimeError
 mirrors/constructor_kinds_test/none: RuntimeError
-mirrors/constructor_private_name_test: RuntimeError
+mirrors/constructor_private_name_test: RuntimeError # Issue 33345 - Incorrect qualified symbol literal from kernel reader
 mirrors/constructors_test: CompileTimeError # Issue 31402 (Invocation arguments)
 mirrors/dart2js_mirrors_test: RuntimeError # 31916
 mirrors/deferred_mirrors_metadata_test: RuntimeError, CompileTimeError # Deferred loading kernel issue 28335.
@@ -123,11 +123,7 @@
 mirrors/generic_function_typedef_test: RuntimeError
 mirrors/generic_interface_test/01: RuntimeError
 mirrors/generic_mixin_applications_test: RuntimeError
-mirrors/hot_get_field_test: RuntimeError
-mirrors/hot_set_field_test: RuntimeError
 mirrors/invocation_fuzz_test: RuntimeError, Crash
-mirrors/invoke_private_test: RuntimeError
-mirrors/invoke_private_wrong_library_test: RuntimeError
 mirrors/library_declarations_test/none: RuntimeError # Issue 31402 (Invocation arguments)
 mirrors/library_enumeration_deferred_loading_test: RuntimeError
 mirrors/library_exports_hidden_test: RuntimeError # Issue 33098
@@ -163,10 +159,8 @@
 mirrors/parameter_annotation_mirror_test: RuntimeError
 mirrors/parameter_metadata_test: RuntimeError
 mirrors/parameter_of_mixin_app_constructor_test: RuntimeError # Issue 31402 (Invocation arguments)
-mirrors/private_class_field_test: RuntimeError
-mirrors/private_field_test: RuntimeError
-mirrors/private_symbol_test: RuntimeError
-mirrors/private_types_test: RuntimeError
+mirrors/private_symbol_test: RuntimeError # Issue 33326 - CFE/kernel invalid typedef substitution
+mirrors/private_types_test: RuntimeError # Issue 33326 - CFE/kernel invalid typedef substitution
 mirrors/redirecting_factory_different_type_test/01: MissingCompileTimeError
 mirrors/redirecting_factory_test/01: RuntimeError
 mirrors/redirecting_factory_test/02: RuntimeError