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

[ffigen] Interfaces implement their conformed protocols #1953

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

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Jan 29, 2025

This is the first part of #1462. The major change is that all code-genned interface classes now implement all the classes corresponding to the protocols they conform to. The next change will be to start code-genning id<Foo> (where Foo is a protocol) as Foo instead of ObjCObjectBase.

The protocol classes aren't changing much, and don't have any non-static members, so there's nothing to actually inherit or implement. The protocol classes are just acting as markers to enforce the upcoming id<Foo> changes.

For example, class NSString extends NSObject { has become class NSString extends NSObject implements NSCopying, NSMutableCopying, NSSecureCoding {.

Details

  • The biggest change to protocols is that they're now generated as stubs if they're transitively included, instead of just being omitted, so that they can still be part of the interface's type heirarchy. That means a bunch of changes to their code gen logic, and to their transitive deps logic.
  • I also had to make ObjCProtocol part of the Type family, instead of just being a typeless binding, which means implementing things like subtyping logic for protocols.
  • Protocols are now declared as abstract interface instead of abstract final, and inherit from a new ObjCProtocolBase class.
  • There's an NSObject protocol that collides with the NSObject interface, so I'm renaming it in package:objective_c to NSObjectProtocol. This means that ObjCBuiltInFunctions.builtInProtocols needs to support renaming, like builtInCompounds.
  • Since the NSString declaration has gotten so much longer, the formatter now wants to wrap it in extra_methods.dart, which would break the patching logic in generate_code.dart. I tried a couple of ways of disabling the formatter for this file, but they didn't work, so I renamed it to extra_methods.dart.in.
  • I couldn't think of a sensible changelog entry for ffigen without including the next change, so I'll leave the changelog until next time.

Copy link

github-actions bot commented Jan 29, 2025

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
objective_c Breaking 4.1.0 5.0.0-wip 5.0.0 ✔️
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/objective_c/lib/src/ns_input_stream.dart

@coveralls
Copy link

coveralls commented Jan 30, 2025

Coverage Status

coverage: 87.595% (+0.2%) from 87.37%
when pulling 91f1709 on protoconf
into fbeafe0 on main.

@liamappelbe liamappelbe changed the title WIP: [ffigen] Interfaces implement their conformed protocols [ffigen] Interfaces implement their conformed protocols Jan 30, 2025
@liamappelbe liamappelbe marked this pull request as ready for review January 30, 2025 04:37
Copy link
Member

@HosseinYousefi HosseinYousefi left a comment

Choose a reason for hiding this comment

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

LGTM. One test is failing though.

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.

3 participants