Skip to content

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Aug 21, 2025

Part of a larger refactor where I'm trying to make Writer less stateful during code gen. Currently there's a lot of stuff that should be implemented using visitors that is actually tracked by a bit of Writer state during codegen. End goal is to make the type to string conversion functions take Context instead of Writer.

usedEnumCTypes is only used to generate a warning message when enums are passed through FFI APIs, because doing so is unsafe (different C compilers treat enums differently).

The old logic added the enum to usedEnumCTypes when its getCType method was called during code generation. The enum's own generated bindings don't use getCType, only other bindings that refer to the enum call this method (eg when passing an enum as a function param). So this was a roundabout (and brittle) way of checking if the enum is used in any APIs. If we later decided to use getCType in the enum's own bindings, this check would start producing a ton of false positives.

A more direct approach is just to run a visitor from all non-enum bindings and see if we find any enums.

Part of #2462 and #1259
This is also yak shaving for #2419
The CI failure is unrelated: #2517

Copy link

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 symbol Leaking sources
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 Aug 21, 2025

Coverage Status

coverage: 91.825% (+0.1%) from 91.701%
when pulling 9cfce59 on ffigen_less_writer
into dc4aa33 on main.

@liamappelbe liamappelbe marked this pull request as ready for review August 21, 2025 01:21
@liamappelbe liamappelbe merged commit ca9e9c5 into main Aug 25, 2025
25 checks passed
@liamappelbe liamappelbe deleted the ffigen_less_writer branch August 25, 2025 03:10
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