Skip to content

[ffigen] Remove Constant from public AST - #3556

Merged
liamappelbe merged 59 commits into
mainfrom
ffigen_global_const
Aug 17, 2026
Merged

[ffigen] Remove Constant from public AST#3556
liamappelbe merged 59 commits into
mainfrom
ffigen_global_const

Conversation

@liamappelbe

@liamappelbe liamappelbe commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Constant is used as the base class of UnnamedEnumConstant and MacroConstant. But it's also used in parseVarDeclaration, when we want to codegen the parsed variable as a Dart constant instead of a Global. This pollutes the public AST with internal details. Constant should not be part of the public AST at all.a

Beyond that API issue, it's also a problem for the visitor config migration because part of that constness decision is checking config.globals.includeSymbolAddress at parse time (if a user wants the symbol address, we need to treat it as a Global instead of a Constant). We want to move that config field to a visitor, so this refactor changes parseVarDeclaration to always return a Global. If the variable has a constant value, we store it on the Global. That lets us defer the decision about how to codegen it.

Generally this simplifies things, but it slightly complicates the Library constructor's decision about whether a binding belongs in lookupBindings or noLookupBindings, since a Global is a LookupBinding in the class hierarchy, but doesn't actually look anything up if isConst.

ConstantValue.type mirrors Constant.rawType. It would be nice if we could use the type of the enclosing Global. But it's not that simple because, for example, const char* Globals are codegenned as Pointer<Char>, but we want to codegen the ConstantValue as String.

@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

PR Health

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?

This check can be disabled by tagging the PR with skip-breaking-check.

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

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

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

This check can be disabled by tagging the PR with skip-changelog-check.

@liamappelbe
liamappelbe marked this pull request as ready for review August 17, 2026 04:15
@liamappelbe liamappelbe changed the title WIP [ffigen] Remove Constant from public AST [ffigen] Remove Constant from public AST Aug 17, 2026

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@liamappelbe
liamappelbe merged commit c3203e8 into main Aug 17, 2026
50 of 52 checks passed
@liamappelbe
liamappelbe deleted the ffigen_global_const branch August 17, 2026 23:47
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.

2 participants