-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Bug with late Finalizable objects #49005
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
Comments
This is an interesting case, in general late variables can be captured before they are initialized. Smaller repro: class Foo implements Finalizable {}
void main() {
late Foo foo;
foo = Foo();
print(foo);
} The kernel transformation inserts
In the VM (in unoptimized), the
But the LoadLocal gets a check whether it is initialized in
Option 1: Basically, we don't want to throw the exception if we load the local and pass it to a reachability fence. Option 2: Alternatively, we could consider trying to not insert the fence. But that would break the semantics of
Option 3: disallow I'll take a stab at option 1 and see how costly it would be to recognize these patterns. cc @lrhn from a language POV. What is the semantics of a cc @mraleph thoughts? ideas? (Besides that your alternative implementation idea would probably not have had this issue. 😅 ) |
Fix underway: https://dart-review.googlesource.com/c/sdk/+/244628 Thanks for reporting @liamappelbe! |
This CL changes the IL building for reachability fences to their call sites. This enables us to catch the field load and tell it to not emit an initialization check for late fields. The sentinel value will now flow into the ReachabilityFenceInstr, where it will be discarded. TEST=tests/language/vm/regress_49005_test.dart Closes: #49005 Change-Id: Ic21c9905290925eb83860d8394b13be7dd7592c1 Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/244628 Reviewed-by: Liam Appelbe <[email protected]> Commit-Queue: Daco Harkes <[email protected]>
In some cases, a late Finalizable will incorrectly report that it's uninitialized:
This test passes if you remove
implements Finalizable
, or change the variable toFoo? foo;
.cc @dcharkes
The text was updated successfully, but these errors were encountered: