Skip to content

extern type / extern fn declarations not parseable in user source #42

Description

@hyperpolymath

Surfaced by: IDApTIK migration / affinescript-pixijs integration attempt (2026-05-02)
Affected version: v0.1.0
Severity: Blocking for @affinescript/pixijs and any other connector package that uses FFI-style imports. The package's own src/pixi.as cannot be compiled by today's toolchain.

Reproducer

The shape used by affinescript/affinescript-pixijs/src/pixi.as:

extern type Application;
extern fn createApplication(width: Int, height: Int) -> Application;

pub fn init_pixi(width: Int, height: Int) -> Application {
  createApplication(width, height)
}
$ affinescript check pixi.affine
pixi.affine:1:1: parse error: Syntax error
affinescript: Parse error

extern is rejected at the very first character — it's not a recognised keyword in the user-source grammar.

Why this matters

affinescript-pixijs/src/pixi.as (the canonical PixiJS connector) is structured around extern type Application / extern fn createApplication(...) declarations whose implementations are intended to be linked at runtime via "Typed WASM imports" (per the file's header comment). Without extern parsing, the connector itself cannot be compiled, which means any consumer of @affinescript/pixijs is blocked.

For IDApTIK specifically, this gates the entire screen-and-rendering side of the migration (Wave 3 popups, screens, UI primitives) because they all need to call into PixiJS.

Cross-reference

  • This is the connector-layer counterpart to issue ci: Bump softprops/action-gh-release from 2.5.0 to 2.6.1 #3 (effect handling) — both are about how AffineScript code talks to its host environment. extern is the structural mechanism; effect handlers are the runtime mechanism.
  • A fix here unblocks @affinescript/pixijs, @affinescript/dom, and any future @affinescript/* package that uses FFI imports.
  • If extern is intentionally being held back pending a final design, document the interim shape (e.g. @module annotations? hand-written wasm imports table?) so connector authors know what to write.

Activity

  1. hyperpolymath commented on May 2, 2026

    @hyperpolymath
    OwnerAuthor

    Investigated, deferring

    I considered taking this on as a follow-up to PR #67 (which adds [T] array syntax). After reading the lexer + parser + AST, the change is multi-piece:

    1. Lexer: add ("extern", EXTERN) to the keyword table — trivial.
    2. Parser: add EXTERN token decl + rules for extern fn and extern type — moderate.
    3. AST: requires either new constructors (ExternFnDecl, ExternTypeDecl) or a 'no-body' flag on the existing fn_decl/type_decl — this is the sticking point.
    4. Typechecker: needs to treat extern declarations as opaque foreign references whose types are taken on faith.
    5. Codegen: needs to emit wasm imports against the extern declarations.

    (3) cascades through the rest of the compiler. Without local build verification (which would be ~1-2 hours of dune iteration to get right), the risk of getting (3) and downstream wrong is high.

    I've separately filed #73 for a different codegen issue I encountered while validating PR #67, and a comment on PR #67 showing the [T] fix is locally verified. For #42 I'd recommend the maintainer takes it — the multi-piece change benefits from the review-and-iterate cycle that requires an OCaml dev environment.

    Cross-reference: this issue is the connector-layer counterpart to the extern shape used by affinescript-pixijs's own pixi.as, so blocking on it is blocking on the entire Pixi connector. Effort vs leverage is favourable for the maintainer to take on directly.

  2. added a commit that references this issue on May 11, 2026
    09fe883
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions