OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library js_backend.backend; | 5 library js_backend.backend; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/backend_api.dart' | 8 import '../common/backend_api.dart' |
9 show ForeignResolver, NativeRegistry, ImpactTransformer; | 9 show ForeignResolver, NativeRegistry, ImpactTransformer; |
10 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem; | 10 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem; |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 } | 471 } |
472 } | 472 } |
473 | 473 |
474 JavaScriptBackend(this.compiler, | 474 JavaScriptBackend(this.compiler, |
475 {bool generateSourceMap: true, | 475 {bool generateSourceMap: true, |
476 bool useStartupEmitter: false, | 476 bool useStartupEmitter: false, |
477 bool useMultiSourceInfo: false, | 477 bool useMultiSourceInfo: false, |
478 bool useNewSourceInfo: false, | 478 bool useNewSourceInfo: false, |
479 bool useKernel: false}) | 479 bool useKernel: false}) |
480 : _rti = new _RuntimeTypes(compiler), | 480 : _rti = new _RuntimeTypes(compiler), |
481 annotations = new OptimizerHintsForTests(compiler), | 481 annotations = new OptimizerHintsForTests( |
Siggi Cherem (dart-lang)
2017/05/02 20:04:22
ditto
Johnni Winther
2017/05/03 08:05:59
Done.
| |
482 compiler.elementEnvironment, compiler.commonElements), | |
482 this.sourceInformationStrategy = createSourceInformationStrategy( | 483 this.sourceInformationStrategy = createSourceInformationStrategy( |
483 generateSourceMap: generateSourceMap, | 484 generateSourceMap: generateSourceMap, |
484 useMultiSourceInfo: useMultiSourceInfo, | 485 useMultiSourceInfo: useMultiSourceInfo, |
485 useNewSourceInfo: useNewSourceInfo), | 486 useNewSourceInfo: useNewSourceInfo), |
486 constantCompilerTask = new JavaScriptConstantTask(compiler), | 487 constantCompilerTask = new JavaScriptConstantTask(compiler), |
487 _nativeDataResolver = new NativeDataResolverImpl(compiler), | 488 _nativeDataResolver = new NativeDataResolverImpl(compiler), |
488 _rtiNeedBuilder = | 489 _rtiNeedBuilder = |
489 compiler.frontEndStrategy.createRuntimeTypesNeedBuilder() { | 490 compiler.frontEndStrategy.createRuntimeTypesNeedBuilder() { |
490 _target = new JavaScriptBackendTarget(this); | 491 _target = new JavaScriptBackendTarget(this); |
491 impacts = new BackendImpacts(compiler.options, commonElements); | 492 impacts = new BackendImpacts(compiler.options, commonElements); |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1172 bool isTargetSpecificLibrary(LibraryElement library) { | 1173 bool isTargetSpecificLibrary(LibraryElement library) { |
1173 Uri canonicalUri = library.canonicalUri; | 1174 Uri canonicalUri = library.canonicalUri; |
1174 if (canonicalUri == Uris.dart__js_helper || | 1175 if (canonicalUri == Uris.dart__js_helper || |
1175 canonicalUri == Uris.dart__interceptors) { | 1176 canonicalUri == Uris.dart__interceptors) { |
1176 return true; | 1177 return true; |
1177 } | 1178 } |
1178 return false; | 1179 return false; |
1179 } | 1180 } |
1180 | 1181 |
1181 /// Process backend specific annotations. | 1182 /// Process backend specific annotations. |
1183 // TODO(johnniwinther): Merge this with [AnnotationProcessor] and use | |
1184 // [ElementEnvironment.getMemberMetadata] in [AnnotationProcessor]. | |
1182 void processAnnotations( | 1185 void processAnnotations( |
1183 MemberElement element, ClosedWorldRefiner closedWorldRefiner) { | 1186 MemberEntity element, ClosedWorldRefiner closedWorldRefiner) { |
1184 if (element.isMalformed) { | 1187 if (element is MemberElement && element.isMalformed) { |
1185 // Elements that are marked as malformed during parsing or resolution | 1188 // Elements that are marked as malformed during parsing or resolution |
1186 // might be registered here. These should just be ignored. | 1189 // might be registered here. These should just be ignored. |
1187 return; | 1190 return; |
1188 } | 1191 } |
1189 | 1192 |
1190 if (element.isFunction || element.isConstructor) { | 1193 if (element.isFunction || element.isConstructor) { |
1191 MethodElement method = element.implementation; | 1194 if (annotations.noInline(element)) { |
1192 if (annotations.noInline(method)) { | 1195 inlineCache.markAsNonInlinable(element); |
1193 inlineCache.markAsNonInlinable(method); | |
1194 } | 1196 } |
1195 } | 1197 } |
1196 if (element.isField) return; | 1198 if (element.isField) return; |
1197 MethodElement method = element; | 1199 FunctionEntity method = element; |
1198 | 1200 |
1199 LibraryElement library = method.library; | 1201 LibraryEntity library = method.library; |
1200 if (!library.isPlatformLibrary && !canLibraryUseNative(library)) return; | 1202 if (library.canonicalUri.scheme != 'dart' && |
1203 !canLibraryUseNative(library)) { | |
1204 return; | |
1205 } | |
1201 bool hasNoInline = false; | 1206 bool hasNoInline = false; |
1202 bool hasForceInline = false; | 1207 bool hasForceInline = false; |
1203 bool hasNoThrows = false; | 1208 bool hasNoThrows = false; |
1204 bool hasNoSideEffects = false; | 1209 bool hasNoSideEffects = false; |
1205 for (MetadataAnnotation metadata in method.implementation.metadata) { | 1210 for (ConstantValue constantValue |
1206 metadata.ensureResolved(resolution); | 1211 in compiler.elementEnvironment.getMemberMetadata(method)) { |
1207 ConstantValue constantValue = | |
1208 compiler.constants.getConstantValue(metadata.constant); | |
1209 if (!constantValue.isConstructedObject) continue; | 1212 if (!constantValue.isConstructedObject) continue; |
1210 ObjectConstantValue value = constantValue; | 1213 ObjectConstantValue value = constantValue; |
1211 ClassElement cls = value.type.element; | 1214 ClassEntity cls = value.type.element; |
1212 if (cls == commonElements.forceInlineClass) { | 1215 if (cls == commonElements.forceInlineClass) { |
1213 hasForceInline = true; | 1216 hasForceInline = true; |
1214 if (VERBOSE_OPTIMIZER_HINTS) { | 1217 if (VERBOSE_OPTIMIZER_HINTS) { |
1215 reporter.reportHintMessage( | 1218 reporter.reportHintMessage( |
1216 method, MessageKind.GENERIC, {'text': "Must inline"}); | 1219 method, MessageKind.GENERIC, {'text': "Must inline"}); |
1217 } | 1220 } |
1218 inlineCache.markAsMustInline(method); | 1221 inlineCache.markAsMustInline(method); |
1219 } else if (cls == commonElements.noInlineClass) { | 1222 } else if (cls == commonElements.noInlineClass) { |
1220 hasNoInline = true; | 1223 hasNoInline = true; |
1221 if (VERBOSE_OPTIMIZER_HINTS) { | 1224 if (VERBOSE_OPTIMIZER_HINTS) { |
1222 reporter.reportHintMessage( | 1225 reporter.reportHintMessage( |
1223 method, MessageKind.GENERIC, {'text': "Cannot inline"}); | 1226 method, MessageKind.GENERIC, {'text': "Cannot inline"}); |
1224 } | 1227 } |
1225 inlineCache.markAsNonInlinable(method); | 1228 inlineCache.markAsNonInlinable(method); |
1226 } else if (cls == commonElements.noThrowsClass) { | 1229 } else if (cls == commonElements.noThrowsClass) { |
1227 hasNoThrows = true; | 1230 hasNoThrows = true; |
1228 if (!Elements.isStaticOrTopLevelFunction(method) && | 1231 bool isValid = true; |
1229 !method.isFactoryConstructor) { | 1232 if (method.isTopLevel) { |
1233 isValid = true; | |
1234 } else if (method.isStatic) { | |
1235 isValid = true; | |
1236 } else if (method is ConstructorEntity && method.isFactoryConstructor) { | |
1237 isValid = true; | |
1238 } | |
1239 if (!isValid) { | |
1230 reporter.internalError( | 1240 reporter.internalError( |
1231 method, | 1241 method, |
1232 "@NoThrows() is currently limited to top-level" | 1242 "@NoThrows() is currently limited to top-level" |
1233 " or static functions and factory constructors."); | 1243 " or static functions and factory constructors."); |
1234 } | 1244 } |
1235 if (VERBOSE_OPTIMIZER_HINTS) { | 1245 if (VERBOSE_OPTIMIZER_HINTS) { |
1236 reporter.reportHintMessage( | 1246 reporter.reportHintMessage( |
1237 method, MessageKind.GENERIC, {'text': "Cannot throw"}); | 1247 method, MessageKind.GENERIC, {'text': "Cannot throw"}); |
1238 } | 1248 } |
1239 closedWorldRefiner.registerCannotThrow(method); | 1249 closedWorldRefiner.registerCannotThrow(method); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1446 | 1456 |
1447 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { | 1457 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { |
1448 return !selector.isGetter; | 1458 return !selector.isGetter; |
1449 } | 1459 } |
1450 | 1460 |
1451 /// Returns `true` if [member] is called from a subclass via `super`. | 1461 /// Returns `true` if [member] is called from a subclass via `super`. |
1452 bool isAliasedSuperMember(MemberEntity member) { | 1462 bool isAliasedSuperMember(MemberEntity member) { |
1453 return _aliasedSuperMembers.contains(member); | 1463 return _aliasedSuperMembers.contains(member); |
1454 } | 1464 } |
1455 } | 1465 } |
OLD | NEW |