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

A generator to generate the Worker js automatically based on the @IsolateManagerWorker() anotation #12

Open
1 of 2 tasks
lamnhan066 opened this issue May 13, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@lamnhan066
Copy link
Owner

lamnhan066 commented May 13, 2024

To Do

  • A generator runs along with the build_runner command.
  • A generator run by dart run isolate_manager:generate command.

Concept:

This is a function to add 2 integers:

@IsolateManagerWorker('add')
int add(List<int> params) {
  return params[0] + params[1]
}

The parameter add is optional, the name of the function will be used if it's not specified. To create the js inside a subfolder like workers, change the name add to workers/add.

After running the above command, a temp file will be created with the current file's contents. An import will be added at the beginning and a main will be created at the end of the script like this:

import 'package:isolate_manager/isolate_manager.dart';

//  Other codes...

main() {
  IsolateManagerFunction.workerFunction(add);
}

Then run the dart compile js "path/to/tempFile.dart" -o "web/add.js" -O4 command.

Removes the temp File.

Completed.

@lamnhan066 lamnhan066 self-assigned this May 13, 2024
@lamnhan066
Copy link
Owner Author

Instead of adding an import and a main function to the current file, we only need to create a new file and import the current file. For instance:

import 'functions.dart';
import 'package:isolate_manager/isolate_manager.dart';

main() {
  IsolateManagerFunction.workerFunction(add);
}

@lamnhan066 lamnhan066 changed the title A generator to generate the Worker js automatically based on the @IsolateManagerFunction() anotation A generator to generate the Worker js automatically based on the @IsolateManagerWorker() anotation May 14, 2024
@lamnhan066 lamnhan066 mentioned this issue May 14, 2024
2 tasks
lamnhan066 added a commit that referenced this issue Jun 18, 2024
Target dart2wasm failed: ProcessException: Process exited abnormally with exit code 64:
*NOTE*: Compilation to WasmGC is experimental.
The support may change, or be removed, with no advance notice.

Unhandled exception:
Null check operator used on a null value
#0      SummaryCollector._readReceiver (package:vm/transformations/type_flow/summary_collector.dart:1072)
#1      RuntimeTypeTranslatorImpl.visitTypeParameterType (package:vm/transformations/type_flow/summary_collector.dart:2807)
#2      TypeParameterType.accept (package:kernel/ast.dart:12638)
#3      RuntimeTypeTranslatorImpl.translate (package:vm/transformations/type_flow/summary_collector.dart:2710)
#4      SummaryCollector._typeCheck (package:vm/transformations/type_flow/summary_collector.dart:1254)
#5      SummaryCollector.visitAsExpression (package:vm/transformations/type_flow/summary_collector.dart:1675)
#6      AsExpression.accept (package:kernel/ast.dart:7667)
#7      SummaryCollector._visit (package:vm/transformations/type_flow/summary_collector.dart:970)
#8      SummaryCollector._visitArguments (package:vm/transformations/type_flow/summary_collector.dart:988)
#9      SummaryCollector.visitFunctionInvocation (package:vm/transformations/type_flow/summary_collector.dart:1965)
#10     FunctionInvocation.accept (package:kernel/ast.dart:6095)
#11     SummaryCollector._visit (package:vm/transformations/type_flow/summary_collector.dart:970)
#12     SummaryCollector._visitArguments (package:vm/transformations/type_flow/summary_collector.dart:988)
#13     SummaryCollector.visitStaticInvocation (package:vm/transformations/type_flow/summary_collector.dart:2151)
#14     StaticInvocation.accept (package:kernel/ast.dart:6608)
#15     SummaryCollector._visit (package:vm/transformations/type_flow/summary_collector.dart:970)
#16     SummaryCollector.visitReturnStatement (package:vm/transformations/type_flow/summary_collector.dart:2425)
#17     ReturnStatement.accept (package:kernel/ast.dart:10206)
#18     SummaryCollector._visitWithoutResult (package:vm/transformations/type_flow/summary_collector.dart:973)
#19     List.forEach (dart:core-patch/growable_array.dart:416)
#20     SummaryCollector.visitBlock (package:vm/transformations/type_flow/summary_collector.dart:2268)
#21     Block.accept (package:kernel/ast.dart:9247)
#22     SummaryCollector._visitWithoutResult (package:vm/transformations/type_flow/summary_collector.dart:973)
#23     SummaryCollector.createSummary (package:vm/transformations/type_flow/summary_collector.dart:834)
#24     TypeFlowAnalysis.getSummary (package:vm/transformations/type_flow/analysis.dart:1784)
#25     _DirectInvocation._processFunction (package:vm/transformations/type_flow/analysis.dart:398)
#26     _DirectInvocation.process (package:vm/transformations/type_flow/analysis.dart:287)
#27     _WorkList.processInvocation (package:vm/transformations/type_flow/analysis.dart:1663)
#28     _WorkList.process (package:vm/transformations/type_flow/analysis.dart:1606)
#29     TypeFlowAnalysis.process (package:vm/transformations/type_flow/analysis.dart:1811)
#30     transformComponent (package:vm/transformations/type_flow/transformer.dart:121)
#31     compileToModule (package:dart2wasm/compile.dart:156)
<asynchronous suspension>
#32     generateWasm (package:dart2wasm/generate_wasm.dart:24)
<asynchronous suspension>
#33     main (file:///Volumes/Work/s/w/ir/x/w/sdk/pkg/dart2wasm/bin/dart2wasm.dart:10)
@lamnhan066 lamnhan066 added the enhancement New feature or request label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant