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

[compiler] (inline classes/pattern)-related crash. #52667

Closed
modulovalue opened this issue Jun 10, 2023 · 3 comments
Closed

[compiler] (inline classes/pattern)-related crash. #52667

modulovalue opened this issue Jun 10, 2023 · 3 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@modulovalue
Copy link
Contributor

The compiler crashes with the following message when compiling the following code:

Error compiling to JavaScript:
lib/main.dart:
Internal Error: The compiler crashed when compiling this element.

The compiler is broken.

When compiling the above element, the compiler crashed. It is not
possible to tell if this is caused by a problem in your program or
not. Regardless, the compiler should not crash.

The Dart team would greatly appreciate if you would take a moment to
report this problem at http://dartbug.com/new.

Please include the following information:

* the name and version of your operating system,

* the Dart SDK build number (3.1.0-169.0.dev), and

* the entire message you see here (including the full stack trace
  below as well as the source location above).

The compiler crashed: Crash when compiling file:///tmp/dartpadZJKOKV/lib/main.dart at character offset 198:
lib/main.dart:19:10: Internal problem: Unsupported operation: 'Object field target InlineClassRepresentationAccessTarget(ObjectAccessTargetKind.inlineClassRepresentation,InlineType(FooBar),InlineType(FooBar))'.
    case FooBar(i: final a): 
         ^

#0      internalProblem (package:front_end/src/fasta/problems.dart:52:5)
#1      unsupported (package:front_end/src/fasta/problems.dart:85:10)
#2      InferenceVisitorImpl.visitObjectPattern (package:front_end/src/fasta/type_inference/inference_visitor.dart:10509:20)
#3      ObjectPattern.accept1 (package:kernel/src/ast/patterns.dart:622:15)
#4      InferenceVisitorImpl.dispatchPattern (package:front_end/src/fasta/type_inference/inference_visitor.dart:9479:12)
#5      TypeAnalyzer.analyzeSwitchStatement (package:_fe_analyzer_shared/src/type_inference/type_analyzer.dart:1829:11)
#6      InferenceVisitorImpl.visitPatternSwitchStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:8395:9)
#7      PatternSwitchStatement.accept (package:kernel/src/ast/patterns.dart:1820:14)
#8      InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:238:26)
#9      InferenceVisitorImpl.visitLabeledStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:2070:43)
#10     LabeledStatement.accept (package:kernel/ast.dart:9998:43)
#11     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:238:26)
#12     InferenceVisitorImpl._visitStatements (package:front_end/src/fasta/type_inference/inference_visitor.dart:848:50)
#13     InferenceVisitorImpl.visitBlock (package:front_end/src/fasta/type_inference/inference_visitor.dart:869:31)
#14     Block.accept (package:kernel/ast.dart:9788:43)
#15     InferenceVisitorImpl.inferStatement (package:front_end/src/fasta/type_inference/inference_visitor.dart:238:26)
#16     TypeInferrerImpl.inferFunctionBody (package:front_end/src/fasta/type_inference/type_inferrer.dart:202: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:1137: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:3757:14)
#21     Parser.parseTopLevelMemberImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:3514:14)
#22     Parser.parseTopLevelDeclarationImpl (package:_fe_analyzer_shared/src/parser/parser_impl.dart:624:14)
#23     Parser.parseUnit (package:_fe_analyzer_shared/src/parser/parser_impl.dart:414:15)
#24     SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:1266:12)
<asynchronous suspension>
#25     SourceLoader.buildBodies (package:front_end/src/fasta/source/source_loader.dart:672:7)
<asynchronous suspension>
#26     KernelTarget.buildComponent.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:609:7)
<asynchronous suspension>
#27     withCrashReporting (package:front_end/src/fasta/crash.dart:136:12)
<asynchronous suspension>
#28     KernelTarget.buildComponent (package:front_end/src/fasta/kernel/kernel_target.dart:590:12)
<asynchronous suspension>
#29     _buildInternal (package:front_end/src/kernel_generator_impl.dart:208:19)
<asynchronous suspension>
#30     withCrashReporting (package:front_end/src/fasta/crash.dart:136:12)
<asynchronous suspension>
#31     compile.<anonymous closure> (package:front_end/src/api_unstable/dart2js.dart:200:37)
<asynchronous suspension>
#32     compile (package:front_end/src/api_unstable/dart2js.dart:198:36)
<asynchronous suspension>
#33     _loadFromSource (package:compiler/src/phase/load_kernel.dart:303:29)
<asynchronous suspension>
#34     run (package:compiler/src/phase/load_kernel.dart:404:36)
<asynchronous suspension>
#35     Compiler.loadKernel (package:compiler/src/compiler.dart:388:9)
<asynchronous suspension>
#36     Compiler.produceKernel (package:compiler/src/compiler.dart:395:36)
<asynchronous suspension>
#37     Compiler.runSequentialPhases (package:compiler/src/compiler.dart:711:20)
<asynchronous suspension>
#38     Compiler.runInternal.<anonymous closure> (package:compiler/src/compiler.dart:311:7)
<asynchronous suspension>
#39     Compiler.runInternal (package:compiler/src/compiler.dart:310:5)
<asynchronous suspension>
#40     Compiler.run.<anonymous closure> (package:compiler/src/compiler.dart:231:11)
<asynchronous suspension>
#41     main (package:compiler/src/dart2js.dart:1241:3)
<asynchronous suspension>

abstract class Foo {}

inline class FooBar implements Foo {
  final int i;
  
  const FooBar(this.i);
}

inline class FooBaz implements Foo {
  final int i;
  
  const FooBaz(this.i);
}

void main() {
  final a = FooBar(0);
  switch (a) {
    case FooBar(i: final a): 
      print("FooBar $a");
  }
}

Reproducible on DartPad:

master channel
Use Flutter version 3.12.0-2.0.pre and Dart version 3.1.0-169.0.dev
+ Dart experiments: --enable-experiment=inline-class
@lrhn lrhn added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jun 10, 2023
@eernstg
Copy link
Member

eernstg commented Jun 11, 2023

This crash would be caused by missing parts of the implementation of inline classes (the implementation isn't yet complete).

The crash occurred when the example program was running in dart-pad, but it seems to be associated with the common front end.

@johnniwinther, do you agree that this might well be a CFE issue?

abstract class Foo {}

inline class FooBar implements Foo { // (1)
  final int i;
  
  const FooBar(this.i);
}

inline class FooBaz implements Foo { // (2)
  final int i;
  
  const FooBaz(this.i);
}

void main() {
  final a = FooBar(0);
  switch (a) {
    case FooBar(i: final a): 
      print("FooBar $a");
  }
}

(1) and (2) should be reported as compile-time errors. There is ongoing discussion about an extension to the inline class feature which will allow an inline class to have a non-inline class in its implements clause (dart-lang/language#3090), but in the current feature specification it is a compile-time error.

An inline class used in an object pattern (like case FooBar(i: final a)) should amount to a dynamic type check (which is equivalent to a is int) which will succeed, followed by matching of the subpattern that reads i. So the program (where implements Foo has been removed such that there are no compile-time errors) should print 'FooBar 0'.

It actually crashes, in a very similar way as the program with implements Foo, so the main thing is probably the occurrence of an inline class in an object pattern.

@johnniwinther
Copy link
Member

This is a CFE issue. The implementation of inline classes cannot rely on the existing implementation for regular classes so we need to rework all such parts, including the handling in patterns.

@eernstg eernstg added area-front-end Use area-front-end for front end / CFE / kernel format related issues. and removed area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Jun 12, 2023
@eernstg
Copy link
Member

eernstg commented Jun 12, 2023

Thx!

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.
Projects
None yet
Development

No branches or pull requests

4 participants