@@ -570,6 +570,11 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
570
570
);
571
571
} else if (target == nativeCallableIsolateLocalConstructor) {
572
572
return _verifyAndReplaceNativeCallableIsolateLocal (node);
573
+ } else if (target == nativeCallableIsolateGroupSharedConstructor) {
574
+ return _verifyAndReplaceNativeCallable (
575
+ node,
576
+ replacement: _replaceNativeCallableIsolateGroupSharedConstructor,
577
+ );
573
578
} else if (target == nativeCallableListenerConstructor) {
574
579
final DartType nativeType = InterfaceType (
575
580
nativeFunctionClass,
@@ -881,18 +886,18 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
881
886
}
882
887
883
888
// 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));
890
889
// isStaticFunction is true:
891
890
// _NativeCallableIsolateLocal<T>(
892
891
// _createNativeCallableIsolateLocal<NativeFunction<T>>(
893
892
// _nativeCallbackFunction<T>(target, exceptionalReturn),
894
893
// null,
895
894
// true);
895
+ // isStaticFunction is false:
896
+ // _NativeCallableIsolateLocal<T>(
897
+ // _createNativeCallableIsolateLocal<NativeFunction<T>>(
898
+ // _nativeIsolateLocalCallbackFunction<T>(exceptionalReturn),
899
+ // target,
900
+ // true));
896
901
Expression _replaceNativeCallableIsolateLocalConstructor (
897
902
StaticInvocation node,
898
903
Expression exceptionalReturn,
@@ -949,7 +954,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
949
954
// void _handler(List args) => target(args[0], args[1], ...)
950
955
// final _callback = _NativeCallableListener<T>(_handler, debugName);
951
956
// _callback._pointer = _createNativeCallableListener<NativeFunction<T>>(
952
- // _nativeAsyncCallbackFunction<T>(), _callback._rawPort );
957
+ // _nativeAsyncCallbackFunction<T>(), _callback._port );
953
958
// expression result: _callback;
954
959
Expression _replaceNativeCallableListenerConstructor (StaticInvocation node) {
955
960
final nativeFunctionType = InterfaceType (
@@ -1017,7 +1022,7 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
1017
1022
)..fileOffset = node.fileOffset;
1018
1023
1019
1024
// _callback._pointer = _createNativeCallableListener<NativeFunction<T>>(
1020
- // _nativeAsyncCallbackFunction<T>(), _callback._rawPort );
1025
+ // _nativeAsyncCallbackFunction<T>(), _callback._port );
1021
1026
final pointerValue = StaticInvocation (
1022
1027
createNativeCallableListenerProcedure,
1023
1028
Arguments (
@@ -1054,9 +1059,73 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
1054
1059
);
1055
1060
}
1056
1061
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 (
1058
1125
StaticInvocation node, {
1059
1126
bool fromFunction = false ,
1127
+ required Expression Function (StaticInvocation , Expression , bool )
1128
+ replacement,
1060
1129
}) {
1061
1130
final DartType nativeType = InterfaceType (
1062
1131
nativeFunctionClass,
@@ -1188,15 +1257,6 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
1188
1257
}
1189
1258
}
1190
1259
1191
- final replacement =
1192
- fromFunction
1193
- ? _replaceFromFunction (node, exceptionalReturn)
1194
- : _replaceNativeCallableIsolateLocalConstructor (
1195
- node,
1196
- exceptionalReturn,
1197
- isStaticFunction,
1198
- );
1199
-
1200
1260
final compoundClasses =
1201
1261
funcType.positionalParameters
1202
1262
.whereType <InterfaceType >()
@@ -1205,7 +1265,25 @@ mixin _FfiUseSiteTransformer on FfiTransformer {
1205
1265
(c) => c.superclass == structClass || c.superclass == unionClass,
1206
1266
)
1207
1267
.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
+ );
1209
1287
}
1210
1288
1211
1289
Expression _replaceGetRef (StaticInvocation node) {
0 commit comments