@@ -142,35 +142,29 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap {
142
142
for (int libraryIndex = 0 ;
143
143
libraryIndex < _elementMap.libraries.length;
144
144
libraryIndex++ ) {
145
- IndexedLibrary oldLibrary =
146
- _elementMap.libraries.getEntity (libraryIndex)! ;
147
- KLibraryEnv oldEnv = _elementMap.libraries.getEnv (oldLibrary);
148
- KLibraryData data = _elementMap.libraries.getData (oldLibrary);
149
- IndexedLibrary newLibrary = JLibrary (oldLibrary.name! ,
150
- oldLibrary.canonicalUri, oldLibrary.isNonNullableByDefault);
145
+ IndexedLibrary library = _elementMap.libraries.getEntity (libraryIndex)! ;
146
+ KLibraryEnv oldEnv = _elementMap.libraries.getEnv (library);
147
+ KLibraryData data = _elementMap.libraries.getData (library);
151
148
JLibraryEnv newEnv = oldEnv.convert (_elementMap, liveMemberUsage);
152
149
libraryMap[oldEnv.library] =
153
150
libraries.register <IndexedLibrary , JLibraryData , JLibraryEnv >(
154
- newLibrary , data.convert (), newEnv);
155
- assert (newLibrary.libraryIndex == oldLibrary.libraryIndex );
151
+ library , data.convert (), newEnv,
152
+ setEntityIndex : false );
156
153
programEnv.registerLibrary (newEnv);
157
154
}
158
155
// TODO(johnniwinther): Filter unused classes.
159
156
for (int classIndex = 0 ;
160
157
classIndex < _elementMap.classes.length;
161
158
classIndex++ ) {
162
- IndexedClass oldClass = _elementMap.classes.getEntity (classIndex)! ;
163
- KClassEnv env = _elementMap.classes.getEnv (oldClass);
164
- KClassData data = _elementMap.classes.getData (oldClass);
165
- final oldLibrary = oldClass.library as IndexedLibrary ;
166
- LibraryEntity newLibrary = libraries.getEntity (oldLibrary.libraryIndex)! ;
167
- IndexedClass newClass = JClass (newLibrary as JLibrary , oldClass.name,
168
- isAbstract: oldClass.isAbstract);
159
+ IndexedClass cls = _elementMap.classes.getEntity (classIndex)! ;
160
+ KClassEnv env = _elementMap.classes.getEnv (cls);
161
+ KClassData data = _elementMap.classes.getData (cls);
162
+ final library = cls.library as JLibrary ;
169
163
JClassEnv newEnv = env.convert (_elementMap, liveMemberUsage,
170
164
liveAbstractMembers, (ir.Library library) => libraryMap[library]! );
171
- classMap[env.cls] = classes. register (newClass, data. convert (), newEnv);
172
- assert (newClass.classIndex == oldClass.classIndex );
173
- libraries.getEnv (newLibrary ).registerClass (newClass .name, newEnv);
165
+ classMap[env.cls] =
166
+ classes. register (cls, data. convert (), newEnv, setEntityIndex : false );
167
+ libraries.getEnv (library ).registerClass (cls .name, newEnv);
174
168
}
175
169
176
170
for (int memberIndex = 0 ;
@@ -183,68 +177,45 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap {
183
177
continue ;
184
178
}
185
179
KMemberData data = _elementMap.members.getData (oldMember);
186
- final oldLibrary = oldMember.library as IndexedLibrary ;
187
- final oldClass = oldMember.enclosingClass as IndexedClass ? ;
188
- JLibrary newLibrary =
189
- libraries.getEntity (oldLibrary.libraryIndex) as JLibrary ;
190
- JClass ? newClass = oldClass != null
191
- ? classes.getEntity (oldClass.classIndex) as JClass ?
192
- : null ;
193
- IndexedMember newMember;
180
+ final library = oldMember.library as JLibrary ;
181
+ final cls = oldMember.enclosingClass as JClass ? ;
182
+ IndexedMember ? newMember;
194
183
Name memberName = oldMember.memberName;
195
- if (oldMember is IndexedField ) {
196
- final field = oldMember;
197
- newMember = JField (newLibrary, newClass, memberName,
198
- isStatic: field.isStatic,
199
- isAssignable: field.isAssignable,
200
- isConst: field.isConst);
201
- } else if (oldMember is ConstructorEntity ) {
202
- final constructor = oldMember as IndexedConstructor ;
203
- ParameterStructure parameterStructure =
204
- annotations.hasNoElision (constructor) || memberUsage == null
205
- ? constructor.parameterStructure
206
- : memberUsage.invokedParameters! ;
207
- if (constructor.isFactoryConstructor) {
208
- // TODO(redemption): This should be a JFunction.
209
- newMember = JFactoryConstructor (
210
- newClass! , memberName, parameterStructure,
211
- isExternal: constructor.isExternal,
212
- isConst: constructor.isConst,
213
- isFromEnvironmentConstructor:
214
- constructor.isFromEnvironmentConstructor);
215
- } else {
216
- newMember = JGenerativeConstructor (
217
- newClass! , memberName, parameterStructure,
218
- isExternal: constructor.isExternal, isConst: constructor.isConst);
184
+
185
+ // Only create a new entity if some parameters are unused and can be
186
+ // elided.
187
+ if (! annotations.hasNoElision (oldMember) &&
188
+ memberUsage != null &&
189
+ oldMember is IndexedFunction &&
190
+ ! identical (
191
+ oldMember.parameterStructure, memberUsage.invokedParameters)) {
192
+ if (oldMember is ConstructorEntity ) {
193
+ final newParameters = memberUsage.invokedParameters! ;
194
+ final constructor = oldMember as ConstructorEntity ;
195
+ if (constructor.isFactoryConstructor) {
196
+ // TODO(redemption): This should be a JFunction.
197
+ newMember = JFactoryConstructor (cls! , memberName, newParameters,
198
+ isExternal: constructor.isExternal,
199
+ isConst: constructor.isConst,
200
+ isFromEnvironmentConstructor:
201
+ constructor.isFromEnvironmentConstructor);
202
+ } else {
203
+ newMember = JGenerativeConstructor (cls! , memberName, newParameters,
204
+ isExternal: constructor.isExternal,
205
+ isConst: constructor.isConst);
206
+ }
207
+ } else if (oldMember.isFunction && ! oldMember.isAbstract) {
208
+ final newParameters = memberUsage.invokedParameters! ;
209
+ newMember = JMethod (
210
+ library, cls, memberName, newParameters, oldMember.asyncMarker,
211
+ isStatic: oldMember.isStatic,
212
+ isExternal: oldMember.isExternal,
213
+ isAbstract: oldMember.isAbstract);
219
214
}
220
- } else if (oldMember.isGetter) {
221
- final getter = oldMember as IndexedFunction ;
222
- newMember = JGetter (
223
- newLibrary, newClass, memberName, getter.asyncMarker,
224
- isStatic: getter.isStatic,
225
- isExternal: getter.isExternal,
226
- isAbstract: getter.isAbstract);
227
- } else if (oldMember.isSetter) {
228
- final setter = oldMember as IndexedFunction ;
229
- newMember = JSetter (newLibrary, newClass, memberName,
230
- isStatic: setter.isStatic,
231
- isExternal: setter.isExternal,
232
- isAbstract: setter.isAbstract);
233
- } else {
234
- final function = oldMember as IndexedFunction ;
235
- ParameterStructure parameterStructure =
236
- annotations.hasNoElision (function) ||
237
- memberUsage == null ||
238
- function.isAbstract
239
- ? function.parameterStructure
240
- : memberUsage.invokedParameters! ;
241
- newMember = JMethod (newLibrary, newClass, memberName,
242
- parameterStructure, function.asyncMarker,
243
- isStatic: function.isStatic,
244
- isExternal: function.isExternal,
245
- isAbstract: function.isAbstract);
246
215
}
247
- members.register (newMember, data.convert ());
216
+ members.register (newMember ?? oldMember, data.convert (),
217
+ setEntityIndex: newMember != null );
218
+ newMember ?? = oldMember;
248
219
assert (
249
220
newMember.memberIndex == oldMember.memberIndex,
250
221
"Member index mismatch: "
@@ -265,28 +236,33 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap {
265
236
_elementMap.typeVariables.getEntity (typeVariableIndex)! ;
266
237
KTypeVariableData oldTypeVariableData =
267
238
_elementMap.typeVariables.getData (oldTypeVariable);
268
- Entity ? newTypeDeclaration;
269
- if (oldTypeVariable.typeDeclaration is ClassEntity ) {
270
- final cls = oldTypeVariable.typeDeclaration as IndexedClass ;
271
- newTypeDeclaration = classes.getEntity (cls.classIndex);
272
- // TODO(johnniwinther): Skip type variables of unused classes.
273
- } else {
274
- assert (oldTypeVariable.typeDeclaration is MemberEntity );
239
+
240
+ // [JLocalTypeVariable] can have [Local] as a `typeDeclaration` but those
241
+ // should never be inserted into the TypeVariable entity map.
242
+ assert (oldTypeVariable.typeDeclaration is ClassEntity ||
243
+ oldTypeVariable.typeDeclaration is MemberEntity );
244
+
245
+ MemberEntity ? newTypeDeclaration;
246
+ // TODO(johnniwinther): Skip type variables of unused classes.
247
+ if (oldTypeVariable.typeDeclaration is MemberEntity ) {
275
248
final member = oldTypeVariable.typeDeclaration as IndexedMember ;
276
249
newTypeDeclaration = members.getEntity (member.memberIndex);
277
250
if (newTypeDeclaration == null ) {
278
251
typeVariables.skipIndex (typeVariableIndex);
279
252
continue ;
280
253
}
281
254
}
282
- IndexedTypeVariable newTypeVariable = createTypeVariable (
283
- newTypeDeclaration! , oldTypeVariable.name! , oldTypeVariable.index)
284
- as IndexedTypeVariable ;
255
+ IndexedTypeVariable ? newTypeVariable;
256
+ if (newTypeDeclaration != null ) {
257
+ newTypeVariable = createTypeVariable (
258
+ newTypeDeclaration,
259
+ oldTypeVariable.name! ,
260
+ oldTypeVariable.index) as IndexedTypeVariable ;
261
+ }
285
262
typeVariableMap[oldTypeVariableData.node] =
286
263
typeVariables.register <IndexedTypeVariable , JTypeVariableData >(
287
- newTypeVariable, oldTypeVariableData.copy ());
288
- assert (newTypeVariable.typeVariableIndex ==
289
- oldTypeVariable.typeVariableIndex);
264
+ newTypeVariable ?? oldTypeVariable, oldTypeVariableData.copy (),
265
+ setEntityIndex: newTypeVariable != null );
290
266
}
291
267
// TODO(johnniwinther): We should close the environment in the beginning of
292
268
// this constructor but currently we need the [MemberEntity] to query if the
0 commit comments