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

Macro does not give details when run in command line. #55610

Open
polina-c opened this issue May 1, 2024 · 12 comments
Open

Macro does not give details when run in command line. #55610

polina-c opened this issue May 1, 2024 · 12 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-feature-macros Implement macros features in the CFE feature-macros Implementation of the macros feature

Comments

@polina-c
Copy link
Contributor

polina-c commented May 1, 2024

Steps to repro:

  1. Clone polina-c/disposable_macro@0d1c9f8
  2. Open subfolder disposable_macro in vs code
  3. Open file test/disposable_test.dart
  4. Find you can see link 'Go to augmentationon below@disposable()`
  5. Click the link and see the text:
augment library 'file:///Users/polinach/_/disposable_macro/disposable_macro/test/disposable_test.dart';

import 'dart:core' as prefix0;

augment class TestUser {
  augment TestUser(prefix0.String name, prefix0.int age, ) {assert(false, "hello from macro");}
}
  1. Run the command flutter test --enable-experiment=macros test/disposable_test.dart
  2. Find the command is failing and does not give details of the failure:
00:02 +0: loading /Users/polinach/_/disposable_macro/disposable_macro/test/disposable_test.dart                                                test/disposable_test.dart:5:2: Error: Macro application failed due to a bug in the macro.
@Disposable()
 ^
00:04 +0 -1: loading /Users/polinach/_/disposable_macro/disposable_macro/test/disposable_test.dart [E]                                         
  Failed to load "/Users/polinach/_/disposable_macro/disposable_macro/test/disposable_test.dart": Compilation failed for testPath=/Users/polinach/_/disposable_macro/disposable_macro/test/disposable_test.dart
flutter --version
Flutter 3.22.0-18.0.pre.76 • channel [user-branch] • unknown source
Framework • revision ce822ec8bb (23 hours ago) • 2024-04-30 10:38:21 -0700
Engine • revision 0ce67714ce
Tools • Dart 3.5.0 (build 3.5.0-114.0.dev) • DevTools 2.35.0-dev.16
@jakemac53
Copy link
Contributor

@johnniwinther are we getting any diagnostics at all for macros reported yet from the CFE?

@kevmoo kevmoo added feature-macros Implementation of the macros feature area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels May 1, 2024
@johnniwinther
Copy link
Member

We should report both crashes and errors, maybe a bit crudely at the moment.

@johnniwinther
Copy link
Member

@davidmorgan What is the status of the Flutter integration for macro support?

@johnniwinther johnniwinther added the cfe-feature-macros Implement macros features in the CFE label May 2, 2024
@davidmorgan
Copy link
Contributor

It should work everywhere at this point, although we don't have test coverage.

That error comes from _macros/lib/src/executor/execute_macro.dart, it means there is an unexpected exception, and assumes it's coming from the macro itself. It should be possible to get the detail from a context message, does the CFE ever print those?

@johnniwinther
Copy link
Member

We do print these but the implementation is likely not air tight.

copybara-service bot pushed a commit that referenced this issue May 7, 2024
In response to #55610

Change-Id: I8730a84ca44d85463b7de41112d520588ef86848
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365601
Reviewed-by: Morgan :) <davidmorgan@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
@johnniwinther
Copy link
Member

I've landed https://dart-review.googlesource.com/c/sdk/+/365601 which adds the context messages to the output. In case of a crash the context message is the stack trace.

@polina-c
Copy link
Contributor Author

polina-c commented May 7, 2024

Thank you! Is there an easy way to detect if the change reached flutter muster or is still on the way?

@johnniwinther
Copy link
Member

It's still on the way. The fix is in 3.5.0-134.0.dev but Flutter is on 3.5.0-131.0.dev - as far as I can tell from https://github.com/flutter/engine/blob/main/DEPS

@polina-c
Copy link
Contributor Author

I checked the latest flutter and got interesting issue.

I have my macro code wrapped in try catch, and print custom error.
After change of macro code, I get the error, but next time i do not see it. And in both cases test that uses class with macro passes:

00:01 +0: loading /Users/polinach/_/disposable_macro/macro/test/disposable_test.dart                                                                          Stdout from MacroExecutor at /Users/polinach/_/platform/flutter/bin/cache/dart-sdk/bin/dart:
!!! from macro: Unsupported operation: Augmenting existing constructor bodies is not allowed.

00:01 +1: All tests passed!     
                                                                                                                              
polinach-macbookpro3:macro polinach$ flutter test --enable-experiment=macros test/disposable_test.dart
00:01 +1: All tests passed!                                                                                                                                   
polinach-macbookpro3:macro polinach$

To repro:

  1. Get polina-c/disposable_macro@f63109b
  2. cd macro
  3. Run two times flutter test --enable-experiment=macros test/disposable_test.dart
  4. See different outputs and passed tests

My flutter version:

Flutter 3.22.0-35.0.pre.16 • channel master • git@github.com:flutter/flutter.git
Framework • revision 8b129b9b89 (7 hours ago) • 2024-05-16 04:50:03 +0800
Engine • revision bf1c6da0dd
Tools • Dart 3.5.0 (build 3.5.0-154.0.dev) • DevTools 2.36.0-dev.5

@jakemac53
Copy link
Contributor

and print custom error.

Are you emitting this as an error diagnostic, just calling print, or something else?

@polina-c
Copy link
Contributor Author

polina-c commented May 17, 2024

code is here: https://github.com/polina-c/disposable_macro/blob/main/macro/lib/src/disposable_macro.dart

Should it be done differently?

@jakemac53
Copy link
Contributor

Ah, yes, I think that a print we will only convert into an "info" diagnostic, which isn't an error, so compilation succeeds.

You can throw instead, which we will convert to an error, or you can use the builder.report API to report an error, or you can throw a DiagnosticException as well.

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-macros Implement macros features in the CFE feature-macros Implementation of the macros feature
Projects
None yet
Development

No branches or pull requests

5 participants