Skip to content

THRIFT-5992 THRIFT-5993 THRIFT-5994 haxe codegen issues#3478

Merged
Jens-G merged 5 commits into
apache:masterfrom
Jens-G:THRIFT-5992-5993-5994-haxe-codegen
May 14, 2026
Merged

THRIFT-5992 THRIFT-5993 THRIFT-5994 haxe codegen issues#3478
Jens-G merged 5 commits into
apache:masterfrom
Jens-G:THRIFT-5992-5993-5994-haxe-codegen

Conversation

@Jens-G
Copy link
Copy Markdown
Member

@Jens-G Jens-G commented May 14, 2026

Summary

Fixes several Haxe code-generator bugs that caused generated Haxe code to fail compilation.

THRIFT-5992 — Keyword/stdlib-type escaping, typedef import fix, FIELD_ID fix

Compiler generator fixes in `t_haxe_generator.cc`:

  • Keyword escaping (`escape_haxe_keyword()`): appends `_` to any of 45 Haxe reserved keywords used as IDL field/function/parameter names; wire-format strings left unchanged
  • Standard-library type collision (`get_cap_name()` extended): appends `_` when a capitalized IDL type name matches a Haxe stdlib type (`Array`, `Class`, `Dynamic`, `Enum`, `Lambda`, `Map`, `Type`, etc.)
  • Typedef import fix: skips base-type typedefs (no Haxe class is generated for them, so the import was unresolvable)
  • FIELD_ID constant name fix: uses escaped field name consistently for the `FIELD_ID` constant reference — fixes double-underscore error when field name is a reserved keyword

THRIFT-5993 — Cross-package import shadowing and Haxe base-type name collisions

  • Import shadowing fix (`haxe_thrift_add_import()` exclude): suppresses imports whose short name matches the entity being defined, preventing same-named foreign types from shadowing the local interface/class; also suppresses duplicate short-name imports across packages
  • Base-type-named user types (`make_haxe_user_type_name()`): new helper extends the reserved check to Haxe base type names (`String`, `Bool`, `Float`, `Int`, `Void`); applied at struct/enum/service file names, class headers, import short-names, and `type_name()` return values — without affecting base-type annotations in field declarations

THRIFT-5994 — `map<bool,V>`, `map<double,V>`, `map<binary,V>` and set equivalents

The Haxe generator previously emitted `ObjectMap<Bool,V>`, `ObjectMap<Float,V>`, `ObjectMap<Bytes,V>` for these IDL types. `Bool` and `Float` are value types that fail the `K:{}` constraint; `Bytes` satisfies the constraint but gives reference equality, producing semantically incorrect map/set behaviour.

New library helpers in `lib/haxe/src/org/apache/thrift/helper/`:

  • `BoolMap.hx` / `BoolSet.hx` — Bool keys backed by `IntMap` (0=false, 1=true)
  • `FloatMap.hx` / `FloatSet.hx` — Float keys stored as 8-byte IEEE 754 hex in `StringMap`; correctly round-trips NaN, -0.0, infinities
  • `BytesMap.hx` / `BytesSet.hx` — Bytes keys stored as hex in `StringMap` for content equality

Generator wiring: `map<bool,V>` → `BoolMap`, `map<double,V>` → `FloatMap`, `map<binary,V>` → `BytesMap`; same for `set`, `set`, `set`.

Test plan

  • Verified on Linux with separate test script (not part of the PR) 201/201 tests pass

🤖 Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

Jens-G and others added 5 commits May 14, 2026 22:27
…nux test script

Client: haxe

- Add escape_haxe_keyword() to escape 45 Haxe reserved keywords as identifiers
- Extend get_cap_name() to append _ when name conflicts with Haxe stdlib types
- Fix haxe_thrift_add_import() to skip base-type typedefs (no Haxe class generated)
- Fix generate_reflection_getters/setters FIELD_ID constant name mismatch
- Fix run-Haxe-Codegen-Tests.ps1 for Linux/macOS path compatibility
- Update $KNOWN_BUGS: JavaDeepCopyTest, JavaTypes (unfixable Java-specific fixtures),
  Thrift5320 (tracked as THRIFT-5993)
- Result: 201/201 tests pass (3 FAIL_THRIFT skips, 3 known bugs)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generated-by: Claude Sonnet 4.6
…shadowing

Client: haxe

- Fix haxe_thrift_add_import() to suppress imports whose short name matches
  the entity being defined (service/struct), preventing foreign same-named
  types from shadowing the local definition (THRIFT-5993)
- Also suppress duplicate short-name imports to avoid unresolvable ambiguity
  when multiple packages export identically-named types
- Add make_haxe_user_type_name() helper with extended reserved-type list that
  includes Haxe base type names (String, Bool, Float, Int, Void); applied at
  struct/enum file names, class headers, import generation, and type_name()
  branches so user-defined types named after Haxe built-ins are safely renamed
- Remove Thrift5320.thrift from $KNOWN_BUGS (now fixed); update JavaTypes and
  JavaDeepCopyTest comments to reflect only the remaining ObjectMap<Float>
  key-type constraint issue

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generated-by: Claude Sonnet 4.6
… names

Client: haxe

Extend the base-type-name collision fix to service-level naming sites.
All generate_service_{interface,client,server} and generate_service() calls
that previously used get_cap_name(service_name_) now use
make_haxe_user_type_name(service_name_), keeping service file names, class
and interface headers, _iface_ type annotations, and import lines consistent
with the renamed type as returned by type_name() for cross-package references.

No test IDL exercises this path (no service named String/Bool/Float/Int/Void
exists in the tree), but the fix ensures correctness for the edge case.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generated-by: Claude Sonnet 4.6
…y types

Client: haxe

- Add BoolMap<T>/BoolSet: Bool key type encoded as 0/1 in IntMap/IntMap
- Add FloatMap<T>/FloatSet: Float key type stored as 8-byte IEEE 754 hex in
  StringMap for exact equality semantics (correctly round-trips NaN, -0.0,
  infinities)
- Add BytesMap<T>/BytesSet: Bytes key type stored as hex in StringMap for
  content equality (ObjectMap/ObjectSet would give reference equality)
- Wire the new types in type_name(): map<bool,V> -> BoolMap, map<double,V> ->
  FloatMap, map<binary,V> -> BytesMap; set<bool> -> BoolSet, set<double> ->
  FloatSet, set<binary> -> BytesSet
- Clear $KNOWN_BUGS: JavaTypes.thrift and JavaDeepCopyTest.thrift now pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Generated-by: Claude Sonnet 4.6
@Jens-G Jens-G changed the title Thrift 5992 5993 5994 haxe codegen THRIFT-5992 THRIFT-5993 THRIFT-5994 haxe codegen issus May 14, 2026
@Jens-G Jens-G changed the title THRIFT-5992 THRIFT-5993 THRIFT-5994 haxe codegen issus THRIFT-5992 THRIFT-5993 THRIFT-5994 haxe codegen issues May 14, 2026
@Jens-G Jens-G self-assigned this May 14, 2026
@Jens-G Jens-G merged commit d83f4a6 into apache:master May 14, 2026
93 of 94 checks passed
@Jens-G Jens-G deleted the THRIFT-5992-5993-5994-haxe-codegen branch May 21, 2026 07:36
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.

1 participant