Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: pkg/compiler/lib/src/ssa/builder_kernel.dart

Issue 2981543002: Handle type variable test and typed list literal. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/graph_builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:kernel/ast.dart' as ir; 5 import 'package:kernel/ast.dart' as ir;
6 6
7 import '../closure.dart'; 7 import '../closure.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/codegen.dart' show CodegenRegistry; 9 import '../common/codegen.dart' show CodegenRegistry;
10 import '../common/names.dart'; 10 import '../common/names.dart';
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 this._typeInferenceMap, 110 this._typeInferenceMap,
111 this.localsMap, 111 this.localsMap,
112 this.closedWorld, 112 this.closedWorld,
113 this._worldBuilder, 113 this._worldBuilder,
114 this.registry, 114 this.registry,
115 this.closureDataLookup, 115 this.closureDataLookup,
116 // TODO(het): Should sourceInformationBuilder be in GraphBuilder? 116 // TODO(het): Should sourceInformationBuilder be in GraphBuilder?
117 this.sourceInformationBuilder, 117 this.sourceInformationBuilder,
118 this.functionNode) { 118 this.functionNode) {
119 this.loopHandler = new KernelLoopHandler(this); 119 this.loopHandler = new KernelLoopHandler(this);
120 typeBuilder = new KernelTypeBuilder(_elementMap, this); 120 typeBuilder = new TypeBuilder(this);
121 graph.element = targetElement; 121 graph.element = targetElement;
122 graph.sourceInformation = 122 graph.sourceInformation =
123 sourceInformationBuilder.buildVariableDeclaration(); 123 sourceInformationBuilder.buildVariableDeclaration();
124 this.localsHandler = new LocalsHandler(this, targetElement, targetElement, 124 this.localsHandler = new LocalsHandler(this, targetElement, targetElement,
125 contextClass, null, nativeData, interceptorData); 125 contextClass, null, nativeData, interceptorData);
126 _targetStack.add(targetElement); 126 _targetStack.add(targetElement);
127 } 127 }
128 128
129 CommonElements get _commonElements => _elementMap.commonElements; 129 CommonElements get _commonElements => _elementMap.commonElements;
130 130
(...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 registry?.registerConstSymbol(symbolLiteral.value); 1938 registry?.registerConstSymbol(symbolLiteral.value);
1939 } 1939 }
1940 1940
1941 @override 1941 @override
1942 void visitNullLiteral(ir.NullLiteral nullLiteral) { 1942 void visitNullLiteral(ir.NullLiteral nullLiteral) {
1943 stack.add(graph.addConstantNull(closedWorld)); 1943 stack.add(graph.addConstantNull(closedWorld));
1944 } 1944 }
1945 1945
1946 /// Set the runtime type information if necessary. 1946 /// Set the runtime type information if necessary.
1947 HInstruction _setListRuntimeTypeInfoIfNeeded( 1947 HInstruction _setListRuntimeTypeInfoIfNeeded(
1948 HInstruction object, ir.ListLiteral listLiteral) { 1948 HInstruction object, InterfaceType type) {
1949 InterfaceType type = localsHandler.substInContext(_commonElements
1950 .listType(_elementMap.getDartType(listLiteral.typeArgument)));
1951 if (!rtiNeed.classNeedsRti(type.element) || type.treatAsRaw) { 1949 if (!rtiNeed.classNeedsRti(type.element) || type.treatAsRaw) {
1952 return object; 1950 return object;
1953 } 1951 }
1954 List<HInstruction> arguments = <HInstruction>[]; 1952 List<HInstruction> arguments = <HInstruction>[];
1955 for (DartType argument in type.typeArguments) { 1953 for (DartType argument in type.typeArguments) {
1956 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement)); 1954 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement));
1957 } 1955 }
1958 // TODO(15489): Register at codegen. 1956 // TODO(15489): Register at codegen.
1959 registry?.registerInstantiation(type); 1957 registry?.registerInstantiation(type);
1960 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object); 1958 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object);
1961 } 1959 }
1962 1960
1963 @override 1961 @override
1964 void visitListLiteral(ir.ListLiteral listLiteral) { 1962 void visitListLiteral(ir.ListLiteral listLiteral) {
1965 HInstruction listInstruction; 1963 HInstruction listInstruction;
1966 if (listLiteral.isConst) { 1964 if (listLiteral.isConst) {
1967 listInstruction = graph.addConstant( 1965 listInstruction = graph.addConstant(
1968 _elementMap.getConstantValue(listLiteral), closedWorld); 1966 _elementMap.getConstantValue(listLiteral), closedWorld);
1969 } else { 1967 } else {
1970 List<HInstruction> elements = <HInstruction>[]; 1968 List<HInstruction> elements = <HInstruction>[];
1971 for (ir.Expression element in listLiteral.expressions) { 1969 for (ir.Expression element in listLiteral.expressions) {
1972 element.accept(this); 1970 element.accept(this);
1973 elements.add(pop()); 1971 elements.add(pop());
1974 } 1972 }
1975 listInstruction = 1973 listInstruction =
1976 new HLiteralList(elements, commonMasks.extendableArrayType); 1974 new HLiteralList(elements, commonMasks.extendableArrayType);
1977 add(listInstruction); 1975 add(listInstruction);
1978 listInstruction = 1976 InterfaceType type = localsHandler.substInContext(_commonElements
1979 _setListRuntimeTypeInfoIfNeeded(listInstruction, listLiteral); 1977 .listType(_elementMap.getDartType(listLiteral.typeArgument)));
1978 listInstruction = _setListRuntimeTypeInfoIfNeeded(listInstruction, type);
1980 } 1979 }
1981 1980
1982 TypeMask type = _typeInferenceMap.typeOfListLiteral( 1981 TypeMask type = _typeInferenceMap.typeOfListLiteral(
1983 targetElement, listLiteral, closedWorld); 1982 targetElement, listLiteral, closedWorld);
1984 if (!type.containsAll(closedWorld)) { 1983 if (!type.containsAll(closedWorld)) {
1985 listInstruction.instructionType = type; 1984 listInstruction.instructionType = type;
1986 } 1985 }
1987 stack.add(listInstruction); 1986 stack.add(listInstruction);
1988 } 1987 }
1989 1988
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 return; 2351 return;
2353 } 2352 }
2354 FunctionEntity function = _elementMap.getMember(target); 2353 FunctionEntity function = _elementMap.getMember(target);
2355 TypeMask typeMask = _typeInferenceMap.getReturnTypeOf(function); 2354 TypeMask typeMask = _typeInferenceMap.getReturnTypeOf(function);
2356 2355
2357 // TODO(sra): For JS interop external functions, use a different function to 2356 // TODO(sra): For JS interop external functions, use a different function to
2358 // build arguments. 2357 // build arguments.
2359 List<HInstruction> arguments = 2358 List<HInstruction> arguments =
2360 _visitArgumentsForStaticTarget(target.function, invocation.arguments); 2359 _visitArgumentsForStaticTarget(target.function, invocation.arguments);
2361 2360
2361 // TODO(johnniwinther): Move factory calls to a helper function?
2362 if (function is ConstructorEntity && function.isFactoryConstructor) { 2362 if (function is ConstructorEntity && function.isFactoryConstructor) {
2363 if (function.isExternal && function.isFromEnvironmentConstructor) { 2363 if (function.isExternal && function.isFromEnvironmentConstructor) {
2364 if (invocation.isConst) { 2364 if (invocation.isConst) {
2365 // Just like all const constructors (see visitConstructorInvocation). 2365 // Just like all const constructors (see visitConstructorInvocation).
2366 stack.add(graph.addConstant( 2366 stack.add(graph.addConstant(
2367 _elementMap.getConstantValue(invocation), closedWorld)); 2367 _elementMap.getConstantValue(invocation), closedWorld));
2368 } else { 2368 } else {
2369 generateUnsupportedError( 2369 generateUnsupportedError(
2370 invocation, 2370 invocation,
2371 '${function.enclosingClass.name}.${function.name} ' 2371 '${function.enclosingClass.name}.${function.name} '
2372 'can only be used as a const constructor'); 2372 'can only be used as a const constructor');
2373 } 2373 }
2374 return; 2374 return;
2375 } 2375 }
2376 2376
2377 // Factory constructors take type parameters; other static methods ignore 2377 // Factory constructors take type parameters; other static methods ignore
2378 // them. 2378 // them.
2379
2379 if (closedWorld.rtiNeed.classNeedsRti(function.enclosingClass)) { 2380 if (closedWorld.rtiNeed.classNeedsRti(function.enclosingClass)) {
2380 _addTypeArguments(arguments, invocation.arguments); 2381 _addTypeArguments(arguments, invocation.arguments);
2381 } 2382 }
2383
2384 _pushStaticInvocation(function, arguments, typeMask);
2385
2386 bool isFixedListConstructorCall = false;
2387 bool isGrowableListConstructorCall = false;
2388 ;
Siggi Cherem (dart-lang) 2017/07/11 21:31:14 delete
Johnni Winther 2017/07/13 08:58:18 Done.
2389 if (commonElements.isUnnamedListConstructor(function) &&
2390 invocation.arguments.named.isEmpty) {
2391 isFixedListConstructorCall =
2392 invocation.arguments.positional.length == 1;
2393 isGrowableListConstructorCall = invocation.arguments.positional.isEmpty;
2394 }
2395 bool isJSArrayTypedConstructor =
2396 function == commonElements.jsArrayTypedConstructor;
2397 if (rtiNeed.classNeedsRti(commonElements.listClass) &&
2398 (isFixedListConstructorCall ||
2399 isGrowableListConstructorCall ||
2400 isJSArrayTypedConstructor)) {
2401 InterfaceType type = _elementMap.createInterfaceType(
2402 target.enclosingClass, invocation.arguments.types);
2403 stack.add(_setListRuntimeTypeInfoIfNeeded(pop(), type));
2404 }
2405 } else {
2406 _pushStaticInvocation(function, arguments, typeMask);
2382 } 2407 }
2383
2384 _pushStaticInvocation(function, arguments, typeMask);
2385 } 2408 }
2386 2409
2387 void handleInvokeStaticForeign( 2410 void handleInvokeStaticForeign(
2388 ir.StaticInvocation invocation, ir.Procedure target) { 2411 ir.StaticInvocation invocation, ir.Procedure target) {
2389 String name = target.name.name; 2412 String name = target.name.name;
2390 if (name == 'JS') { 2413 if (name == 'JS') {
2391 handleForeignJs(invocation); 2414 handleForeignJs(invocation);
2392 } else if (name == 'JS_CURRENT_ISOLATE_CONTEXT') { 2415 } else if (name == 'JS_CURRENT_ISOLATE_CONTEXT') {
2393 handleForeignJsCurrentIsolateContext(invocation); 2416 handleForeignJsCurrentIsolateContext(invocation);
2394 } else if (name == 'JS_CALL_IN_ISOLATE') { 2417 } else if (name == 'JS_CALL_IN_ISOLATE') {
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3495 enterBlock.setBlockFlow( 3518 enterBlock.setBlockFlow(
3496 new HTryBlockInformation( 3519 new HTryBlockInformation(
3497 kernelBuilder.wrapStatementGraph(bodyGraph), 3520 kernelBuilder.wrapStatementGraph(bodyGraph),
3498 exception, 3521 exception,
3499 kernelBuilder.wrapStatementGraph(catchGraph), 3522 kernelBuilder.wrapStatementGraph(catchGraph),
3500 kernelBuilder.wrapStatementGraph(finallyGraph)), 3523 kernelBuilder.wrapStatementGraph(finallyGraph)),
3501 exitBlock); 3524 exitBlock);
3502 kernelBuilder.inTryStatement = previouslyInTryStatement; 3525 kernelBuilder.inTryStatement = previouslyInTryStatement;
3503 } 3526 }
3504 } 3527 }
3505
3506 class KernelTypeBuilder extends TypeBuilder {
3507 KernelToElementMapForBuilding _elementMap;
3508
3509 KernelTypeBuilder(this._elementMap, GraphBuilder builder) : super(builder);
3510
3511 @override
3512 InterfaceType getThisType(ClassEntity cls) {
3513 return _elementMap.elementEnvironment.getThisType(cls);
3514 }
3515 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/graph_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698