Skip to content

feat/parse url - #667

Merged
nahime0 merged 7 commits into
mainfrom
feat/parse_url
Aug 7, 2026
Merged

feat/parse url#667
nahime0 merged 7 commits into
mainfrom
feat/parse_url

Conversation

@nahime0

@nahime0 nahime0 commented Aug 4, 2026

Copy link
Copy Markdown
Member

Summary

Adds PHP-compatible parse_url() on both the AOT compiler path and the Magician eval() runtime, plus the predefined PHP_URL_* constants.

  • AOT: registry builtin (src/builtins/string/parse_url.rs) → RuntimeFnId::ParseUrl → Mixed-returning __rt_parse_url scanner (AArch64 + x86_64) with associative-array and component-selector results, Fresh ownership, and catchable ValueError for invalid selectors.
  • Magician: eval_builtin! home file with a pure-Rust scanner aligned to PHP 8.4 ext/standard/url.c quirks (scheme-relative URLs, IPv6 brackets, empty present components, control-byte substitution, port range checks).
  • Constants: PHP_URL_SCHEMEPHP_URL_FRAGMENT (0–7) wired through checker, prescan, name resolver, autoload interpreter, Magician predefined constants, README, and docs.
  • Parity: shared fixture corpus in tests/fixtures/parse_url_cases.json exercised by Magician unit tests and AOT codegen tests; coverage also includes component shapes, named/callable call sites, invalid URLs (false), selector ValueError, and heap-debug ownership.

Behavior notes

Call Success Missing component Invalid URL
parse_url($url) / negative component assoc array of present keys (port as int) key omitted false
PHP_URL_PORT int null false
other PHP_URL_* string (may be "") null false

Selectors greater than PHP_URL_FRAGMENT raise:

parse_url(): Argument #2 ($component) must be a valid URL component identifier, N given

Any negative component selects the full-array form (PHP 8.4). Invalid URLs return false even when the selector would otherwise be invalid.

Test plan

  • cargo build
  • cargo test --test codegen_tests parse_url
  • cargo test --test error_tests parse_url
  • cargo test -p elephc-magician parse_url
  • git diff --check
  • Optional: ELEPHC_PHP_CHECK=1 cargo test --test codegen_tests parse_url
  • CI matrix: macos-aarch64, linux-aarch64, linux-x86_64

Docs / examples

  • docs/php/strings.md, generated builtin pages, internals runtime note
  • examples/parse-url/main.php
  • CHANGELOG.md [Unreleased] entry

@github-actions github-actions Bot added area:codegen Touches target-aware assembly or backend lowering. area:magician Touches eval, include execution, or elephc-magician. area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:xl Very large pull request that needs deliberate review planning. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities. labels Aug 4, 2026
@nahime0
nahime0 marked this pull request as ready for review August 6, 2026 08:27
@nahime0

nahime0 commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

@greptile-apps review this

@nahime0 nahime0 moved this from Backlog to In review in Elephc Release Track Aug 6, 2026
@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown

Greptile Summary

Adds PHP-compatible parse_url() support to native compilation and the Magician eval runtime.

  • Registers the builtin, predefined PHP_URL_* constants, checker return types, and runtime lowering.
  • Implements matching Rust and AArch64/x86_64 scanners with component selection, associative-array results, and catchable selector errors.
  • Adds shared compatibility fixtures, runtime ownership coverage, documentation, and an example.

Confidence Score: 5/5

The PR appears safe to merge based on the inspected parsing, ABI, ownership, exception, and cross-target behavior.

The native and eval implementations consistently materialize PHP-compatible result shapes, preserve the expected runtime layouts, and are exercised by a shared edge-case corpus; no actionable changed-code failure remains.

Important Files Changed

Filename Overview
crates/elephc-magician/src/interpreter/builtins/string/parse_url.rs Adds the eval builtin, PHP-compatible byte scanner, result materialization, and fixture-driven parity tests; no actionable defect was established.
src/builtins/string/parse_url.rs Registers the AOT builtin and refines static selector result types while retaining Mixed for dynamic selectors.
src/codegen/lower_inst/builtins/strings.rs Lowers URL and selector operands into the architecture-specific runtime ABI without an established register-preservation defect.
src/codegen_support/runtime/strings/parse_url.rs Emits scanner support, static component keys, and catchable ValueError construction for both targets.
src/codegen_support/runtime/strings/parse_url/aarch64.s Implements AArch64 parsing, component copying, Mixed boxing, and associative-hash construction with consistent ABI usage.
src/codegen_support/runtime/strings/parse_url/x86_64.s Implements the corresponding x86_64 scanner and result construction with no concrete architecture divergence found.
tests/fixtures/parse_url_cases.json Provides shared PHP-derived coverage for standard forms, invalid authorities and ports, empty components, IPv6, and control-byte substitution.
Cargo.lock Adds the existing serde_json package to the Magician dependency list without changing the advisory-flagged dependency versions.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["PHP parse_url(url, component)"] --> B{"Execution path"}
  B -->|AOT| C["EIR RuntimeFnId::ParseUrl"]
  C --> D["Target-aware lowering"]
  D --> E["AArch64 / x86_64 scanner"]
  B -->|eval| F["Magician builtin registry"]
  F --> G["Rust URL scanner"]
  E --> H{"Parse result"}
  G --> H
  H -->|Invalid URL| I["false"]
  H -->|Negative selector| J["Associative component array"]
  H -->|Selector 0–7| K["string / int / null"]
  H -->|Selector > 7| L["ValueError"]
Loading

Reviews (1): Last reviewed commit: "docs: add parse_url implementation plan" | Re-trigger Greptile

Comment thread docs/php/builtins/string/parse_url.md
@greptile-apps

greptile-apps Bot commented Aug 7, 2026

Copy link
Copy Markdown

Too many files changed for review (199 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

@nahime0
nahime0 merged commit 6b84875 into main Aug 7, 2026
1 check passed
@nahime0
nahime0 deleted the feat/parse_url branch August 7, 2026 16:38
@github-project-automation github-project-automation Bot moved this from In review to Done in Elephc Release Track Aug 7, 2026
Guikingone added a commit to Guikingone/elephc that referenced this pull request Aug 7, 2026
Brings in parse_url (illegalstudio#667) and the by-ref foreach borrowed-source fixes (illegalstudio#648),
15 upstream commits in all.

Every conflict was a GENERATED builtin page — 152 files under `docs/php/builtins`
and `docs/internals/builtins`, and no source file at all. They were resolved the
only way generated files can be: by regenerating them from the two registries with
`cargo build --example gen_builtins` + `scripts/docs/extract_builtins.py --render
--force`, not by picking a side. 494 builtins, 962 pages; both CI audits
(`audit_builtins.py`, `validate_site_compat.py`) report 0 errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:codegen Touches target-aware assembly or backend lowering. area:magician Touches eval, include execution, or elephc-magician. area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:xl Very large pull request that needs deliberate review planning. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants