[VM] Change internal name for FfiNatives.

Changes the naming format for synthetic variables used for
@FfiNatives.
The name was based on the native function, but since multiple
FfiNatives can reference the same native function, this can
result in name clashes.
Instead the name is now based on the name of the associated
function, which cannot have a name clashing with another function
by the same name.

TEST=CQ
Change-Id: Id829ff3f207ab11e83f3194b8410f4be297623c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206374
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
diff --git a/pkg/vm/lib/transformations/ffi_native.dart b/pkg/vm/lib/transformations/ffi_native.dart
index f3fdb03..4c71d56 100644
--- a/pkg/vm/lib/transformations/ffi_native.dart
+++ b/pkg/vm/lib/transformations/ffi_native.dart
@@ -72,14 +72,14 @@
 
   // Transform:
   //   @FfiNative<Double Function(Double)>('Math_sqrt')
-  //   external double _sqrt(double x);
+  //   external double _square_root(double x);
   //
   // Into:
-  //   final _@FfiNative_Math_sqrt =
+  //   final _@FfiNative__square_root =
   //       Pointer<NativeFunction<Double Function(Double)>>
   //           .fromAddress(_ffi_resolver('dart:math', 'Math_sqrt'))
   //           .asFunction<double Function(double)>();
-  //   double _sqrt(double x) => _@FfiNative_Math_sqrt(x);
+  //   double _square_root(double x) => _@FfiNative__square_root(x);
   Statement transformFfiNative(
       Procedure node, InstanceConstant annotationConst) {
     assert(currentLibrary != null);
@@ -119,8 +119,8 @@
     final asFunctionInvocation = StaticInvocation(asFunctionProcedure,
         Arguments([fromAddressInvocation], types: [nativeType, dartType]));
 
-    // final _@FfiNative_Math_sqrt = ...
-    final fieldName = Name('_@FfiNative_${functionName.value}', currentLibrary);
+    // final _@FfiNative__square_root = ...
+    final fieldName = Name('_@FfiNative_${node.name.text}', currentLibrary);
     final funcPtrField = Field.immutable(fieldName,
         type: dartType,
         initializer: asFunctionInvocation,
@@ -130,7 +130,7 @@
         getterReference: currentLibraryIndex?.lookupGetterReference(fieldName));
     currentLibrary!.addField(funcPtrField);
 
-    // _@FfiNative_Math_sqrt(x)
+    // _@FfiNative__square_root(x)
     final callFuncPtrInvocation = FunctionInvocation(
         FunctionAccessKind.FunctionType,
         StaticGet(funcPtrField),
@@ -144,7 +144,7 @@
   visitProcedure(Procedure node) {
     // Only transform functions that are external and have FfiNative annotation:
     //   @FfiNative<Double Function(Double)>('Math_sqrt')
-    //   external double _sqrt(double x);
+    //   external double _square_root(double x);
     if (!node.isExternal) {
       return node;
     }