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

Augment output in dart compile to clarify null safety compilation mode #44234

Closed
vsmenon opened this issue Nov 17, 2020 · 29 comments
Closed

Augment output in dart compile to clarify null safety compilation mode #44234

vsmenon opened this issue Nov 17, 2020 · 29 comments
Assignees
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. area-front-end Use area-front-end for front end / CFE / kernel format related issues. NNBD Issues related to NNBD Release P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug

Comments

@vsmenon
Copy link
Member

vsmenon commented Nov 17, 2020

I got confused when retrying a migration. I'd accidently left a @dart = 2.10 in my entry point but migrated the rest of the app and the pubspec.

Might be worth emitting a warning that the mode disagrees with the pubspec.

Also not sure if this is best done in CFE or flutter tool - @mit-mit @johnniwinther @jonahwilliams

@vsmenon vsmenon added the NNBD Issues related to NNBD Release label Nov 17, 2020
@johnniwinther
Copy link
Member

The CFE never reads the pubspec.yaml. Only the package_config.json (through package:package_config).

@jonahwilliams
Copy link
Contributor

Should this be a warning? Maybe the AI is to make it more obvious what mode we're running in?

@keertip keertip added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Nov 18, 2020
@johnniwinther
Copy link
Member

@mit-mit What are your thoughts on this?

@johnniwinther johnniwinther added the P2 A bug or feature request we're likely to work on label Dec 2, 2020
@mit-mit
Copy link
Member

mit-mit commented Dec 3, 2020

From a discussion in the language team, we think this should not be a warning shown when running dart code (e.g. running dart bin/main.dart; that is potentially breaking. We also don't think it should be shown during analysis, as that could easily get annoying (the developer opts out, and is then immediately hit with warning).

But, we still think it's worth adjusting the output of commands that build release-mode artifacts to state which form of null safety was used. Concretely we'd like to suggest we adjust the output of dart compile and flutter build, so that when the SDK constraint is 2.12 or above, we add output like this:

$ dart compile exe bin/myapp.dart
Compiled exe with sound|sound null safety: /Users/mit/tmp/myapp/bin/myapp.exe

$ flutter build apk
Compiling Dart code with sound|unsound null safety.
Running Gradle task 'assembleRelease'... Done                     113.6s
✓ Built build/app/outputs/flutter-apk/app-release.apk (15.4MB).

WDYT @jonahwilliams @bkonyi @devoncarew ?

@devoncarew
Copy link
Member

Consider highlighting the unsound version:

Compiling Dart code with sound null safety.

vs.

Compiling Dart code with unsound null safety.

@devoncarew
Copy link
Member

Or even:

Compiling Dart code with unsound null safety (see dart.dev/... for more information).

@bkonyi
Copy link
Contributor

bkonyi commented Dec 7, 2020

I'm fairly certain I saw flutter run output a message about running with unsound null safety last week. We should have a way for users to check whether or not they're running with sound/unsound null safety even when running against the JIT (maybe add a new flag or put it behind the --verbose option?). In general though, I'm supportive of adding this as output for commands that generate artifacts.

@zanderso
Copy link
Member

zanderso commented Dec 8, 2020

The proposal in #44234 (comment) makes sense to me. Please file an issue in the Flutter issue tracker for the work needed on the Flutter tool. Thanks!

@mit-mit
Copy link
Member

mit-mit commented Dec 14, 2020

Thanks @zanderso, opened flutter/flutter#72279 for the warning in flutter build

@mit-mit
Copy link
Member

mit-mit commented Dec 14, 2020

Updating the present issue to track the change in dart compile:

$ dart compile exe bin/myapp.dart
Compiled exe with sound|sound null safety: /Users/mit/tmp/myapp/bin/myapp.exe

@mit-mit mit-mit changed the title If pubspec is opted into null safety but entry is opted out, no warning. Augment output in dart compile to clarify null safety compilation mode Dec 14, 2020
@mit-mit mit-mit added area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. P1 A high priority bug; for example, a single project is unusable or has many test failures and removed P2 A bug or feature request we're likely to work on labels Dec 14, 2020
@bkonyi
Copy link
Contributor

bkonyi commented Dec 21, 2020

I'm uncertain as to which level in the stack should be outputting this information, but I'm thinking it needs to be done in each compilation pipeline. dart compile consists of 3 different compilation pipelines: dart2js, dart2native, and snapshot generation done by the standalone VM, each of which should probably be responsible for detecting what type of null safety is being used and outputting the correct message. I can do this for the VM, but someone more familiar with dart2js and dart2native should look into adding this there.

cc/ @dcharkes for dart2native and @sigmundch for dart2js.

@sigmundch
Copy link
Member

Agree this cannot be handled in dart-cli, but in each underlying compiler since the information necessary for this is available much later in time.

One alternative could be to share the logic in the CFE. To clarify on the earlier comments, this wouldn't require reading the pubspec.yaml, it would just mean to report a warning if the main entrypoint is in a library that is using legacy semantics. Doing this in the CFE may be nice since the CFE already reports errors that are similar in nature when the app is in sound mode (e.g. complaining if you import an opted-out library).

Currently we already have Component.setMainMethodAndMode - maybe introducing an indirection to calls to this method could be enough to always report a warning if main is from a legacy library? @johnniwinther what do you think?

@johnniwinther
Copy link
Member

Generally the CFE doesn't know the context for its invocation, meaning that any messaging provided for one context will be misleading/wrong/confusing for another. Besides this case, we for instance mention updating pubspec.yaml in some error message and that doesn't make sense if the package_config.json (which is the file actually read by the CFE) is not generated by pub.

For this reason I'd like to add support for passing an identification of this context to CFE and use this to guide its messaging.

@franklinyow franklinyow added this to the January 2021 milestone Jan 5, 2021
@bkonyi
Copy link
Contributor

bkonyi commented Jan 5, 2021

@johnniwinther it sounds like you have a good handle on what needs to be done here. Can I get you to drive this work?

@johnniwinther
Copy link
Member

I will.

@johnniwinther johnniwinther self-assigned this Jan 6, 2021
@johnniwinther
Copy link
Member

Should the message be reported as a warning (i.e. with colors and "Warning: " prefix) ?

@mit-mit
Copy link
Member

mit-mit commented Jan 6, 2021

No, I think I would classify this as an information message, not a warning.

@bkonyi bkonyi removed their assignment Jan 6, 2021
@mit-mit
Copy link
Member

mit-mit commented Jan 8, 2021

Flutter work (flutter/flutter#72279) is now complete.

@franklinyow franklinyow added the type-enhancement A request for a change that isn't a bug label Jan 8, 2021
@mit-mit
Copy link
Member

mit-mit commented Jan 14, 2021

dart-bot pushed a commit that referenced this issue Jan 15, 2021
This adds a new messages kind 'info' to the CFE for showing general
information during compilation. A 'configuration' options is added
to `CompilerOptions` for telling the CFE how it is run.

The configuration 'compile' is added for when the CFE is invoked to
produces an "executable" as when running `dart compile`. When
configuration is set, the CFE emits an info message about the
null safety compilation mode.

Support for `dart compile exe` and `dart compile js` is added in this
CL. Support for `dart compile kernel|app-jit|aot` is not included.

In response to #44234

TEST=pkg/dartdev/test/commands/compile_test.dart

Change-Id: I08f51e2a3f5ad4841c4d703bcd266b7afb63c7c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178982
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
dart-bot pushed a commit that referenced this issue Jan 18, 2021
This reverts commit f8b0d26.

Reason for revert: Multiple test failures in app-jit and simarm(64)

Original change's description:
> [vm] Pass snapshot flag to kernel_service
>
> Enable reporting of null safety compilation mode when running
> `dart compile aot-snapshot`, `dart compile jit-snapshot`,
> and `dart compile kernel`.
>
> Closes #44234
>
> TEST=pkg/dartdev/test/commands/compile_test.dart
>
> Change-Id: I0d4b35c6ccb4167c0c7539a4eb24a5139e29cf53
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178990
> Commit-Queue: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>

TBR=bkonyi@google.com,johnniwinther@google.com

Change-Id: I83aeaa8620c640d02d5ccfd1fe8112d8209a9ad4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179773
Auto-Submit: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
@askeksa-google
Copy link

Reopening due to revert.

@johnniwinther
Copy link
Member

@bkonyi can you take a look at this? - the app-jit/simarm failures are bit out of my scope.

@vsmenon
Copy link
Member Author

vsmenon commented Jan 19, 2021

@bkonyi @a-siva - does this look fixable soon? Trying to land this week.

@bkonyi
Copy link
Contributor

bkonyi commented Jan 19, 2021

Yes, I'll take a look.

@bkonyi
Copy link
Contributor

bkonyi commented Jan 19, 2021

@johnniwinther it looks like most of these failures can just be approved as the tests are failing due to stdout not matching the test expectations. However, the app_jitk-linux-debug-x64 assertion failures don't look good. @alexmarkov might be the right person to look at that since it's in the compiler.

@bkonyi
Copy link
Contributor

bkonyi commented Jan 19, 2021

Relanding the reverted change will be blocked until #44714 is resolved.

@mit-mit
Copy link
Member

mit-mit commented Jan 20, 2021

@johnniwinther as discussed yesterday, we should rephrase the 'unsound' message a bit, as it is shown both for projects with a 2.12 constraint & an entry-point opt-out, and for projects with a 2.9 constraint. I suggest:

    • "Compiling with sound null safety" (everything is 2.12) or
    • "Compiling without sound null safety" (something isn't 2.12)

dart-bot pushed a commit that referenced this issue Jan 20, 2021
In response to #44234 (comment)

Change-Id: I88ab66199217e817edead394ccc74a3f3b49ba15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180143
Reviewed-by: Michael Thomsen <mit@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
@mit-mit
Copy link
Member

mit-mit commented Jan 20, 2021

"Compiling without sound null safety" UI string change landed in 134a437

@franklinyow
Copy link
Contributor

#44714 is closed

@johnniwinther
Copy link
Member

The reverted CL is ready to reland: https://dart-review.googlesource.com/c/sdk/+/180187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. area-front-end Use area-front-end for front end / CFE / kernel format related issues. NNBD Issues related to NNBD Release P1 A high priority bug; for example, a single project is unusable or has many test failures type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests