Skip to content

feat(types): union types, intersection, DNF #199#637

Closed
kakserpom wants to merge 1 commit into
extphprs:masterfrom
kakserpom:199_union_intersection_dnf
Closed

feat(types): union types, intersection, DNF #199#637
kakserpom wants to merge 1 commit into
extphprs:masterfrom
kakserpom:199_union_intersection_dnf

Conversation

@kakserpom

Copy link
Copy Markdown
Contributor

Implements #199

@kakserpom kakserpom force-pushed the 199_union_intersection_dnf branch 7 times, most recently from eee5f3d to 37e2e32 Compare December 23, 2025 14:50
@coveralls

coveralls commented Dec 23, 2025

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 21821037952

Details

  • 42 of 545 (7.71%) changed or added relevant lines in 7 files are covered.
  • 5 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-2.4%) to 32.437%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/macros/src/impl_.rs 0 5 0.0%
crates/macros/src/lib.rs 0 5 0.0%
src/args.rs 30 82 36.59%
crates/macros/src/union.rs 0 119 0.0%
src/zend/_type.rs 0 131 0.0%
crates/macros/src/function.rs 7 198 3.54%
Files with Coverage Reduction New Missed Lines %
crates/macros/src/impl_.rs 1 5.83%
crates/cli/src/lib.rs 2 0.0%
src/args.rs 2 62.26%
Totals Coverage Status
Change from base Build 21763720164: -2.4%
Covered Lines: 2147
Relevant Lines: 6619

💛 - Coveralls

@kakserpom kakserpom force-pushed the 199_union_intersection_dnf branch 4 times, most recently from 6d96b6e to 9b56970 Compare December 28, 2025 12:01
Comment thread guide/src/macros/function.md
Comment thread crates/macros/src/function.rs Outdated
@kakserpom kakserpom force-pushed the 199_union_intersection_dnf branch 6 times, most recently from 3f757ac to a6833e6 Compare December 29, 2025 06:14
@kakserpom

Copy link
Copy Markdown
Contributor Author

@Xenira ;-)

@kakserpom kakserpom requested a review from Xenira January 3, 2026 13:34
@kakserpom kakserpom force-pushed the 199_union_intersection_dnf branch 3 times, most recently from 81eea53 to 574de49 Compare January 29, 2026 14:07
@kakserpom

Copy link
Copy Markdown
Contributor Author

@ptondereau Rebased. Which one is next?

@kakserpom kakserpom force-pushed the 199_union_intersection_dnf branch 2 times, most recently from 8cbb7d2 to 62562bf Compare February 4, 2026 16:45
@kakserpom kakserpom force-pushed the 199_union_intersection_dnf branch from 62562bf to feeca86 Compare February 9, 2026 10:16
@kakserpom kakserpom force-pushed the 199_union_intersection_dnf branch from feeca86 to 1ab5162 Compare March 13, 2026 07:34
@ptondereau

Copy link
Copy Markdown
Member

Superseded by #734. Thanks for the help

@ptondereau ptondereau closed this May 4, 2026
ptondereau added a commit that referenced this pull request Jun 2, 2026
Wires the slice-05 type-string parser into #[php_function],
#[php_impl] methods, and #[php_interface] trait methods so authors
can declare compound PHP types directly on Rust signatures, e.g.
`#[php(types = "int |string")]` on a parameter or
`#[php(returns = "(\\A & \\B) |\\C")]` on a function. The override is
the source of truth for the registered PHP type, including
nullability; runtime modifiers (default, as_ref, variadic) still
apply.

The macro emits `PhpType::from_str(LIT)` at extension load rather
than at expansion time because crates/macros cannot depend on the
runtime crate (cargo dep cycle: ext-php-rs -> ext-php-rs-derive).
This matches issue 06 acceptance criterion 4 ("re-emitting the
source string and parse()-ing at registration"). Compile-time
validation is restricted to syntactic checks (allowed character
set, non-empty, length cap) with a span on the LitStr. Parser-
rejected strings panic at first `cargo run` with the original
literal in the message. A follow-up captures extracting the parser
to a shared crate so all errors surface at build time.

Per-arg `#[php(...)]` attributes are stripped from the re-emitted
ItemFn so rustc never sees the unknown attribute (regression guard
for PR #637's bug). Function-level `#[php(...)]` was already
stripped; this extends the strip to FnArg::Typed.attrs.

Verification:
- 36 macro-crate unit tests (10 new): syntactic validation, runtime
  emit shape, parser strip, span-on-bad-input.
- 29 integration tests including new tests/src/integration/
  php_types_attr/ module covering primitive union, class union,
  intersection (cfg(php83)), DNF (cfg(php83)), function returns,
  and #[php_impl] method coverage on both arg and return.
- Pass on PHP 8.2 NTS (intersection/DNF cfg-skipped), 8.4 NTS,
  8.4 ZTS via Reflection assertions.
- cargo fmt --check + cargo clippy --workspace --all-targets
  -- -D warnings clean.

Closes issue #199 acceptance criteria for slice 06.
ptondereau added a commit that referenced this pull request Jun 2, 2026
Wires the slice-05 type-string parser into #[php_function],
#[php_impl] methods, and #[php_interface] trait methods so authors
can declare compound PHP types directly on Rust signatures, e.g.
`#[php(types = "int |string")]` on a parameter or
`#[php(returns = "(\\A & \\B) |\\C")]` on a function. The override is
the source of truth for the registered PHP type, including
nullability; runtime modifiers (default, as_ref, variadic) still
apply.

The macro emits `PhpType::from_str(LIT)` at extension load rather
than at expansion time because crates/macros cannot depend on the
runtime crate (cargo dep cycle: ext-php-rs -> ext-php-rs-derive).
This matches issue 06 acceptance criterion 4 ("re-emitting the
source string and parse()-ing at registration"). Compile-time
validation is restricted to syntactic checks (allowed character
set, non-empty, length cap) with a span on the LitStr. Parser-
rejected strings panic at first `cargo run` with the original
literal in the message. A follow-up captures extracting the parser
to a shared crate so all errors surface at build time.

Per-arg `#[php(...)]` attributes are stripped from the re-emitted
ItemFn so rustc never sees the unknown attribute (regression guard
for PR #637's bug). Function-level `#[php(...)]` was already
stripped; this extends the strip to FnArg::Typed.attrs.

Verification:
- 36 macro-crate unit tests (10 new): syntactic validation, runtime
  emit shape, parser strip, span-on-bad-input.
- 29 integration tests including new tests/src/integration/
  php_types_attr/ module covering primitive union, class union,
  intersection (cfg(php83)), DNF (cfg(php83)), function returns,
  and #[php_impl] method coverage on both arg and return.
- Pass on PHP 8.2 NTS (intersection/DNF cfg-skipped), 8.4 NTS,
  8.4 ZTS via Reflection assertions.
- cargo fmt --check + cargo clippy --workspace --all-targets
  -- -D warnings clean.

Closes issue #199 acceptance criteria for slice 06.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants