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

[CP] [vm/ffi] Support late Finalizable variables #49024

Closed
dcharkes opened this issue May 16, 2022 · 1 comment
Closed

[CP] [vm/ffi] Support late Finalizable variables #49024

dcharkes opened this issue May 16, 2022 · 1 comment
Assignees
Labels
cherry-pick-approved Label for approved cherrypick request cherry-pick-review Issue that need cherry pick triage to approve

Comments

@dcharkes
Copy link
Contributor

Commit(s) to merge

e418026

Target

stable 2.17.1

Issue Description

late variables with (sub)type Finalizable throw LateInitializationErrors when initialized by assignment instead of immediately on the variable declaration.

class Foo implements Finalizable {}

void main() {
  late Foo foo;
  foo = Foo();
  print(foo);
}
Unhandled exception:
LateInitializationError: Local 'foo' has not been initialized.

Finalizables are kept alive by inserting reachabilityFences, and the argument to the fence causes a field-load which get checked for being initailized.

What is the fix

Don't check field-loads for the sentinel value (the value representing that a late field is not initialized) when the field load is an argument to the reachabilityFence method.

Why cherry-pick

We have released NativeFinalizers in Dart 2.17, and any native resource should implement the Finalizable interface.

None of these native resources can then be used in late variables.

(Concrete use case: automatic reference counting for Objective C objects in package:ffigen. cc @liamappelbe @brianquinlan)

Risk

low

Issue link(s)

#49005

Extra Info

cc @mkustermann @mraleph Thanks for your input on the fix!

@dcharkes dcharkes added the cherry-pick-review Issue that need cherry pick triage to approve label May 16, 2022
@dcharkes dcharkes changed the title [CP] <title> [CP] [vm/ffi] Support late Finalizable variables May 16, 2022
@itsjustkevin itsjustkevin added the cherry-pick-approved Label for approved cherrypick request label May 17, 2022
@athomas
Copy link
Member

athomas commented May 17, 2022

Merged to stable in edf0ab2 (2.17.1).

@athomas athomas closed this as completed May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Label for approved cherrypick request cherry-pick-review Issue that need cherry pick triage to approve
Projects
None yet
Development

No branches or pull requests

6 participants