@@ -570,6 +570,11 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
570570 );
571571 } else if (target == nativeCallableIsolateLocalConstructor) {
572572 return _verifyAndReplaceNativeCallableIsolateLocal (node);
573+ } else if (target == nativeCallableIsolateGroupSharedConstructor) {
574+ return _verifyAndReplaceNativeCallable (
575+ node,
576+ replacement: _replaceNativeCallableIsolateGroupSharedConstructor,
577+ );
573578 } else if (target == nativeCallableListenerConstructor) {
574579 final DartType nativeType = InterfaceType (
575580 nativeFunctionClass,
@@ -881,18 +886,18 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
881886 }
882887
883888 // NativeCallable<T>.isolateLocal(target, exceptionalReturn) calls become:
884- // isStaticFunction is false:
885- // _NativeCallableIsolateLocal<T>(
886- // _createNativeCallableIsolateLocal<NativeFunction<T>>(
887- // _nativeIsolateLocalCallbackFunction<T>(exceptionalReturn),
888- // target,
889- // true));
890889 // isStaticFunction is true:
891890 // _NativeCallableIsolateLocal<T>(
892891 // _createNativeCallableIsolateLocal<NativeFunction<T>>(
893892 // _nativeCallbackFunction<T>(target, exceptionalReturn),
894893 // null,
895894 // true);
895+ // isStaticFunction is false:
896+ // _NativeCallableIsolateLocal<T>(
897+ // _createNativeCallableIsolateLocal<NativeFunction<T>>(
898+ // _nativeIsolateLocalCallbackFunction<T>(exceptionalReturn),
899+ // target,
900+ // true));
896901 Expression _replaceNativeCallableIsolateLocalConstructor (
897902 StaticInvocation node,
898903 Expression exceptionalReturn,
@@ -949,7 +954,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
949954 // void _handler(List args) => target(args[0], args[1], ...)
950955 // final _callback = _NativeCallableListener<T>(_handler, debugName);
951956 // _callback._pointer = _createNativeCallableListener<NativeFunction<T>>(
952- // _nativeAsyncCallbackFunction<T>(), _callback._rawPort );
957+ // _nativeAsyncCallbackFunction<T>(), _callback._port );
953958 // expression result: _callback;
954959 Expression _replaceNativeCallableListenerConstructor (StaticInvocation node) {
955960 final nativeFunctionType = InterfaceType (
@@ -1017,7 +1022,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
10171022 )..fileOffset = node.fileOffset;
10181023
10191024 // _callback._pointer = _createNativeCallableListener<NativeFunction<T>>(
1020- // _nativeAsyncCallbackFunction<T>(), _callback._rawPort );
1025+ // _nativeAsyncCallbackFunction<T>(), _callback._port );
10211026 final pointerValue = StaticInvocation (
10221027 createNativeCallableListenerProcedure,
10231028 Arguments (
@@ -1054,9 +1059,73 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
10541059 );
10551060 }
10561061
1057- Expression _verifyAndReplaceNativeCallableIsolateLocal (
1062+ // NativeCallable<T>.isolateGroupShared(target, exceptionalReturn) calls become:
1063+ // isStaticFunction is true:
1064+ // _NativeCallableIsolateGroupShared<T>(
1065+ // _createNativeCallableIsolateGroupShared<NativeFunction<T>>(
1066+ // _nativeIsolateGroupSharedCallbackFunction<T>(target, exceptionalReturn),
1067+ // null);
1068+ // isStaticFunction is false:
1069+ // _NativeCallableIsolateGroupShared<T>(
1070+ // _createNativeCallableIsolateGroupShared<NativeFunction<T>>(
1071+ // _nativeIsolateGroupSharedClosureFunction<T>(exceptionalReturn),
1072+ // target));
1073+ Expression _replaceNativeCallableIsolateGroupSharedConstructor (
1074+ StaticInvocation node,
1075+ Expression exceptionalReturn,
1076+ bool isStaticFunction,
1077+ ) {
1078+ final nativeFunctionType = InterfaceType (
1079+ nativeFunctionClass,
1080+ currentLibrary.nonNullable,
1081+ node.arguments.types,
1082+ );
1083+ final target = node.arguments.positional[0 ];
1084+ late StaticInvocation pointerValue;
1085+ if (isStaticFunction) {
1086+ pointerValue = StaticInvocation (
1087+ createNativeCallableIsolateGroupSharedProcedure,
1088+ Arguments (
1089+ [
1090+ StaticInvocation (
1091+ nativeIsolateGroupSharedCallbackFunctionProcedure,
1092+ Arguments ([
1093+ target,
1094+ exceptionalReturn,
1095+ ], types: node.arguments.types),
1096+ ),
1097+ NullLiteral (),
1098+ ],
1099+ types: [nativeFunctionType],
1100+ ),
1101+ );
1102+ } else {
1103+ pointerValue = StaticInvocation (
1104+ createNativeCallableIsolateGroupSharedProcedure,
1105+ Arguments (
1106+ [
1107+ StaticInvocation (
1108+ nativeIsolateGroupSharedClosureFunctionProcedure,
1109+ Arguments ([exceptionalReturn], types: node.arguments.types),
1110+ ),
1111+ target,
1112+ ],
1113+ types: [nativeFunctionType],
1114+ ),
1115+ );
1116+ }
1117+
1118+ return ConstructorInvocation (
1119+ nativeCallablePrivateIsolateGroupSharedConstructor,
1120+ Arguments ([pointerValue], types: node.arguments.types),
1121+ );
1122+ }
1123+
1124+ Expression _verifyAndReplaceNativeCallable (
10581125 StaticInvocation node, {
10591126 bool fromFunction = false ,
1127+ required Expression Function (StaticInvocation , Expression , bool )
1128+ replacement,
10601129 }) {
10611130 final DartType nativeType = InterfaceType (
10621131 nativeFunctionClass,
@@ -1188,15 +1257,6 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
11881257 }
11891258 }
11901259
1191- final replacement =
1192- fromFunction
1193- ? _replaceFromFunction (node, exceptionalReturn)
1194- : _replaceNativeCallableIsolateLocalConstructor (
1195- node,
1196- exceptionalReturn,
1197- isStaticFunction,
1198- );
1199-
12001260 final compoundClasses =
12011261 funcType.positionalParameters
12021262 .whereType <InterfaceType >()
@@ -1205,7 +1265,25 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
12051265 (c) => c.superclass == structClass || c.superclass == unionClass,
12061266 )
12071267 .toList ();
1208- return invokeCompoundConstructors (replacement, compoundClasses);
1268+ return invokeCompoundConstructors (
1269+ replacement (node, exceptionalReturn, isStaticFunction),
1270+ compoundClasses,
1271+ );
1272+ }
1273+
1274+ Expression _verifyAndReplaceNativeCallableIsolateLocal (
1275+ StaticInvocation node, {
1276+ bool fromFunction = false ,
1277+ }) {
1278+ return _verifyAndReplaceNativeCallable (
1279+ node,
1280+ fromFunction: fromFunction,
1281+ replacement:
1282+ fromFunction
1283+ ? (node, exceptionalReturn, _) =>
1284+ _replaceFromFunction (node, exceptionalReturn)
1285+ : _replaceNativeCallableIsolateLocalConstructor,
1286+ );
12091287 }
12101288
12111289 Expression _replaceGetRef (StaticInvocation node) {
0 commit comments