Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CFE] Calculating least upper bound crashes the compiler #53290

Closed
sgrekhov opened this issue Aug 21, 2023 · 1 comment
Closed

[CFE] Calculating least upper bound crashes the compiler #53290

sgrekhov opened this issue Aug 21, 2023 · 1 comment
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-feature-extension-types Implement extension types feature in the CFE crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. feature-extension-types Implementation of the extension type feature

Comments

@sgrekhov
Copy link
Contributor

The following tests crashes the compiler

// SharedOptions=--enable-experiment=inline-class

import '../../Utils/static_type_helper.dart';

extension type ET1(Object? o) {}
extension type ET2(Object o) {}

extension type ET3(Object? o) implements ET1 {}
extension type ET4(Object o) implements ET2 {}

main() {
  var v1 = 2 > 1 ? ET1(Object()) : ET2(Object());
  v1.expectStaticType<Exactly<Object?>>();

  var v2 = 2 > 1 ? ET1(null) : ET2("String");
  v2.expectStaticType<Exactly<Object?>>();

  var v3 = 2 > 1 ? ET1(Object()) : ET3(Object());
  v3.expectStaticType<Exactly<Object?>>();

  var v4 = 2 > 1 ? ET1(Object()) : ET4(Object());
  v4.expectStaticType<Exactly<Object?>>();

  var v5 = 2 > 1 ? ET2(Object()) : ET4(Object());
  v5.expectStaticType<Exactly<Object>>();
}

Output is

/home/sgrekhov/Google/dart-sdk/sdk/out/ReleaseX64/dart-sdk/bin/dart --enable-experiment=inline-class --enable-asserts /home/sgrekhov/Google/sgrekhov/co19/LanguageFeatures/Extension-types/upper_bound_A01_t01.dart
Crash when compiling file:///home/sgrekhov/Google/sgrekhov/co19/LanguageFeatures/Extension-types/upper_bound_A01_t01.dart at character offset 1112:
Unsupported operation: moretop(ExtensionType(ET1), ExtensionType(ET3))

#0      StandardBounds.moretop (package:kernel/src/standard_bounds.dart:124:5)
#1      StandardBounds.getNullabilityAwareStandardUpperBoundInternal (package:kernel/src/standard_bounds.dart:659:42)
#2      TypeSchemaStandardBounds.getNullabilityAwareStandardUpperBoundInternal (package:front_end/src/fasta/type_inference/standard_bounds.dart:59:18)
#3      StandardBounds._getNullabilityAwareStandardUpperBound (package:kernel/src/standard_bounds.dart:642:12)
#4      StandardBounds.getStandardUpperBound (package:kernel/src/standard_bounds.dart:629:14)
#5      InferenceVisitorImpl.visitConditionalExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:1009:51)
#6      ConditionalExpression.accept1 (package:kernel/ast.dart:6760:9)
#7      InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:269:27)
#8      InferenceVisitorImpl.inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:301:40)
#9      InferenceVisitorImpl.visitVariableDeclaration (package:front_end/src/fasta/type_inference/inference_visitor.dart:8647:11)
#10     VariableDeclaration.accept (package:kernel/ast.dart:10532:43)
#11     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:252:26)
#12     InferenceVisitorImpl._visitStatements (package:front_end/src/fasta/type_inference/inference_visitor.dart:856:50)
#13     InferenceVisitorImpl.visitBlock (package:front_end/src/fasta/type_inference/inference_visitor.dart:877:31)
#14     Block.accept (package:kernel/ast.dart:8996:43)
#15     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:252:26)
#16     TypeInferrerImpl.inferFunctionBody (package:front_end/src/fasta/type_inference/type_inferrer.dart:198:17)
#17     BodyBuilder.finishFunction (package:front_end/src/fasta/kernel/body_builder.dart:1263:43)
#18     DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:1217:19)
#19     DietListener.endTopLevelMethod (package:front_end/src/fasta/source/diet_listener.dart:387:5)
#20     Parser.parseTopLevelMethod (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3755:14)
#21     Parser.parseTopLevelMemberImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3499:14)
#22     Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:621:14)
#23     Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:411:15)
#24     SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:1248:12)
<asynchronous suspension>
#25     SourceLoader.buildBodies (package:front_end/src/fasta/source/source_loader.dart:670:7)
<asynchronous suspension>
#26     KernelTarget.buildComponent.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:596:7)
<asynchronous suspension>
#27     withCrashReporting (package:front_end/src/fasta/crash.dart:133:12)
<asynchronous suspension>
#28     KernelTarget.buildComponent (package:front_end/src/fasta/kernel/kernel_target.dart:577:12)
<asynchronous suspension>
#29     _buildInternal (package:front_end/src/kernel_generator_impl.dart:210:19)
<asynchronous suspension>
#30     withCrashReporting (package:front_end/src/fasta/crash.dart:133:12)
<asynchronous suspension>
#31     generateKernel.<anonymous closure> (package:front_end/src/kernel_generator_impl.dart:49:12)
<asynchronous suspension>
#32     CompilerContext.clear (package:front_end/src/fasta/compiler_context.dart:139:3)
<asynchronous suspension>
#33     generateKernel (package:front_end/src/kernel_generator_impl.dart:48:10)
<asynchronous suspension>
#34     kernelForModule (package:front_end/src/api_prototype/kernel_generator.dart:100:11)
<asynchronous suspension>
#35     SingleShotCompilerWrapper.compileInternal (file:///home/sgrekhov/Google/dart-sdk/sdk/pkg/vm/bin/kernel_service.dart:414:11)
<asynchronous suspension>
#36     Compiler.compile.<anonymous closure> (file:///home/sgrekhov/Google/dart-sdk/sdk/pkg/vm/bin/kernel_service.dart:220:45)
<asynchronous suspension>
#37     _processLoadRequest (file:///home/sgrekhov/Google/dart-sdk/sdk/pkg/vm/bin/kernel_service.dart:897:37)
<asynchronous suspension>


Process finished with exit code 252

Tested on the edge (Aug 21, 2023) SDK version on Linux x64

@sgrekhov sgrekhov added area-front-end Use area-front-end for front end / CFE / kernel format related issues. crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. labels Aug 21, 2023
@lrhn
Copy link
Member

lrhn commented Aug 21, 2023

An extension type is never a top type, so the bug is earlier in the algorithm, or in the implementation of TOP.
An extension type shouldn't become an argument to MORE_TOP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-feature-extension-types Implement extension types feature in the CFE crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. feature-extension-types Implementation of the extension type feature
Projects
None yet
Development

No branches or pull requests

4 participants