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
[webview_benchmarks] Migrate to null safety #879
[webview_benchmarks] Migrate to null safety #879
Conversation
@yjbanov / @stuartmorgan . this is ready to be reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left specific notes inline; in general this is using far too much force unwrapping rather than making things actually type-safe.
@@ -156,7 +155,7 @@ class BenchmarkServer { | |||
// Trace data is null when the benchmark is not frame-based, such as RawRecorder. | |||
if (latestPerformanceTrace != null) { | |||
final BlinkTraceSummary traceSummary = | |||
BlinkTraceSummary.fromJson(latestPerformanceTrace); | |||
BlinkTraceSummary.fromJson(latestPerformanceTrace!)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throughout this function, look for opportunities to use locals so that the checks don't require force unwrapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BlinkTraceSummary.fromJson
has not many things that can be replaced with locals, it returns null only in one case.
68a65d7
to
9ab6bea
Compare
@stuartmorgan should I also update dependencies in pubspec.yaml? Since the versions used were to support non-null safe code with +2 to allow null safe. |
Yes, a null-safe package should require null-safe dependencies. |
@yjbanov should do the primary review on this. |
6f3b4f5
to
4fdfbd6
Compare
@yjbanov Ping on this review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few suggestions, but otherwise it looks good!
Thanks for migrating the package!
WipConnection debugConnection; | ||
if (withDebugging) { | ||
WipConnection? debugConnection; | ||
if (options.debugPort != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, use a local variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, made it in sync with this comment as well.
4fdfbd6
to
0ad647c
Compare
@mdebbar I have done the changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/web_benchmarks/CHANGELOG.md
Outdated
@@ -1,3 +1,7 @@ | |||
## 0.0.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there really no breaking changes here? That's very unusual for an NNBD transition, and I see public API that takes non-nullable values which looks breaking to me (since previously, e.g., int
was equivalent to int?
in NNBD code, not int
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please direct me to it. None of the changes look breaking to me.recorder.dart#L66 is one , but it was expected to be non null previously as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please direct me to it.
https://github.com/flutter/packages/pull/879/files#diff-97332f3a9c3e68b393026c3f408eb96ec266dd389c858623f87ad97096207a63R43-R45 for example, is changing three public parameters to non-nullable types.
None of the changes look breaking to me.recorder.dart#L66 is one , but it was expected to be non null previously as well.
I haven't looked at all of the logic, which is why it's a question. Maybe in practice nothing changes, it's just unusual in an NNBD migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @stuartmorgan. I think this needs to be version 0.1.0
. The dart docs recommend indicating the NNBD migration as breaking change:
Update the version of the package to indicate a breaking change:
If your package is already at 1.0.0 or greater, increase the major version. For example, if the previous version is 2.3.2, the new version is 3.0.0.
If your package hasn’t reached 1.0.0 yet, either increase the minor version or update the version to 1.0.0. For example, if the previous version is 0.3.2, the new version is either 0.4.0 or 1.0.0.
https://dart.dev/null-safety/migration-guide#package-version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there are (unsurprisingly) 0 published packages depending on this, which means the ecosystem cost of making this a breaking version change even if it doesn't turn out to be strictly necessary is essentially zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stuartmorgan since there are multiple such cases, i have added a generic line regarding breaking change. Also updated the version constraint
packages/web_benchmarks/testing/test_app/lib/benchmarks/runner.dart
Outdated
Show resolved
Hide resolved
fc65553
to
319ef00
Compare
if (value is! List) { | ||
throw FormatException( | ||
'"Tracing.dataCollected" returned malformed data. ' | ||
'Expected a List but got: ${value.runtimeType}'); | ||
} | ||
_tracingData.addAll(event.params['value'].cast<Map<String, dynamic>>()); | ||
_tracingData! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's enough separation here and for _tracingCompleter
that this is fragile; it would be safer to make new non-nullable locals for both, and then set the fields to the local variable.
Profile profile; | ||
Completer<void> _runCompleter; | ||
late Profile profile; | ||
Completer<void>? _runCompleter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is force-unwrapped a lot; please add a comment explaining which methods it's guaranteed to be non-null in and why.
|
||
/// The number of frames ignored as warm-up frames. | ||
int get warmUpFrameCount => | ||
int? get warmUpFrameCount => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If _warmUpFrameCount
is expected to be non-null whenever useCustomWarmUp
is true, then shouldn't this return be non-nullable, and _warmUpFrameCount
be force-unwrapped in the next line?
if (value < 0.0) { | ||
throw StateError( | ||
'Timeseries $name: negative metric values are not supported. Got: $value', | ||
); | ||
} | ||
_allValues.add(value); | ||
if (useCustomWarmUp && isWarmUpValue) { | ||
_warmUpFrameCount += 1; | ||
_warmUpFrameCount = _warmUpFrameCount! + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case the RHS here can use the getter, and not need to force-unwrap.
_RecordingWidgetsBinding(); | ||
} | ||
return _RecordingWidgetsBinding.instance; | ||
} | ||
|
||
FrameRecorder _recorder; | ||
FrameRecorder? _recorder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my earlier comment, this needs a comment explaining when and why it's safe to force-unwrap.
@@ -117,16 +116,16 @@ class BenchmarkServer { | |||
Completer<List<Map<String, dynamic>>>(); | |||
final List<Map<String, dynamic>> collectedProfiles = | |||
<Map<String, dynamic>>[]; | |||
List<String> benchmarks; | |||
Iterator<String> benchmarkIterator; | |||
List<String>? benchmarks; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this nullable? We strongly prefer non-nullable collections to avoid having two ways of expressing empty, which is very error-prone to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is null, we populate it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if this is still passing tests. Let's rebase and see?
io.Platform.environment['PROGRAMFILES'], | ||
io.Platform.environment['PROGRAMFILES(X86)'], | ||
]) | ||
if (item != null) item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also do ...array.whereNotNull()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this got off my radar, will update this today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...<String?>[
io.Platform.environment['LOCALAPPDATA'],
io.Platform.environment['PROGRAMFILES'],
io.Platform.environment['PROGRAMFILES(X86)'],
].whereType<String>()
could we do this ?
319ef00
to
0e1362b
Compare
ec682d1
to
490ca5f
Compare
This reverts commit 490ca5f.
Migrated package to null safety
List which issues are fixed by this PR. You must list at least one issue.
Fixes: #98647
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.