Skip to content

[swift2objc] Support Swift ARC features #2055

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

nikeokoronkwo
Copy link
Contributor

@nikeokoronkwo nikeokoronkwo commented Mar 3, 2025

Fixes #2053

This pull request adds support for Swift ARC features including lazy, weak and unowned variables.

  • Parsing the features from the symbol graph
  • Adding minor transformation logic (just an @objc suffices)
  • Updating generation logic to incorporate these features
    • lazy variables
    • weak variables
    • unowned variables
  • Writing tests for the given feature

@nikeokoronkwo nikeokoronkwo changed the title added parsing of ARC features from symbol graph [swift2objc] Support Swift ARC features Mar 3, 2025
@nikeokoronkwo nikeokoronkwo marked this pull request as ready for review April 20, 2025 04:52
@liamappelbe liamappelbe self-requested a review June 9, 2025 22:21
Copy link
Contributor

@liamappelbe liamappelbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to figure out why the workflows aren't running. I'm pretty sure you can't apply any of these annotations to a property with a custom getter. So I think the generated code in classes_and_properties_output.swift won't compile (and the test should fail).

The weak and unowned annotations determine how reference counting works for a stored property. Our wrapper doesn't actually hold any direct references to the underlying property, so these annotations probably aren't relevant to us.

Similarly for the lazy annotation, the laziness is all handled by the underlying property, so I'm not sure it's actually relevant at the wrapper level.

I like the refactor in parse_variable_declaration.dart, with the ParsedPropertyInfo, so
if the rest of this PR isn't needed, maybe it still makes sense to land that by itself?

@nikeokoronkwo
Copy link
Contributor Author

The weak and unowned annotations determine how reference counting works for a stored property. Our wrapper doesn't actually hold any direct references to the underlying property, so these annotations probably aren't relevant to us.

Similarly for the lazy annotation, the laziness is all handled by the underlying property, so I'm not sure it's actually relevant at the wrapper level.

I was thinking we would want to model Swift relationships and functionality as closely as possible, as end users might expect a class to work in a certain way, which is why I aimed at preserved such functionality in the wrappers

@liamappelbe
Copy link
Contributor

I was thinking we would want to model Swift relationships and functionality as closely as possible, as end users might expect a class to work in a certain way, which is why I aimed at preserved such functionality in the wrappers

I don't think you're allowed to put these annotations on computed properties. I think they're only for stored properties. Their functionality wouldn't really make sense for computed properties.

Copy link

github-actions bot commented Jun 9, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbols
License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/jni/lib/src/third_party/generated_bindings.dart
pkgs/native_doc_dartifier/example/native_doc_dartifier_example.dart
pkgs/native_doc_dartifier/lib/native_doc_dartifier.dart
pkgs/native_doc_dartifier/lib/src/native_doc_dartifier_base.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

@coveralls
Copy link

coveralls commented Jun 9, 2025

Coverage Status

coverage: 82.829% (+0.06%) from 82.772%
when pulling 9176d1e on nikeokoronkwo:swift2objc-arc-features
into 9ef9699 on dart-lang:main.

@nikeokoronkwo
Copy link
Contributor Author

I don't think you're allowed to put these annotations on computed properties. I think they're only for stored properties.

I tried using them, and it compiled to give me Objective-C header code successfully.
I believe as long as the computed properties have the necessary getters and setters, they should work.

I like the refactor in parse_variable_declaration.dart, with the ParsedPropertyInfo, so if the rest of this PR isn't needed, maybe it still makes sense to land that by itself?

Much of that refactor should be merged into main already thanks to #2056.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[swift2objc] Add support for Swift ARC Features (weak and unowned variables) and lazy variables
3 participants