Skip to content

Move the stdlib functions that touch user objects into the prelude #270

Open

Description

@blacktrs

Problem

lib/manticore_stdlib.o is compiled once and knows none of a program's classes, so every stdlib function that can receive a user object has to reach the program's class table through a hook (__mir_obj_to_str, the dump/serialize/json walkers, loose comparison). The stdlib's own copy of those helpers has no arm for a user class: str_replace('x', 'y', $stringable) and preg_replace('/x/', 'y', $stringable) die with "Object of class could not be converted to string", and strtoupper/strlen/strpos read the object pointer as string bytes (#269). It also broke Symfony's cold container cache (ReflectionClassResource hashes preg_replace(.., $reflectionMethod)), so the first request answers 500.

Proposal

Audit src/Runtime/Stdlib and move the functions that touch user objects into prelude/ (compiled with the program, so they see the class table and monomorphize), keeping pure byte/scalar functions in the stdlib.

Candidates (a function that takes mixed / array|string / callable / iterable and coerces, compares or walks the value):

  • str_replace, str_ireplace, strtr, preg_replace, preg_replace_callback, preg_match
  • in_array, array_search, array_unique, the sort family, array_map/usort-style callable users
  • strval, boolval, settype, version_compare, fwrite/fputs (string argument)

Stay in the stdlib: byte functions with plain scalar arguments (strrev, ucfirst, crc32, md5, ctype_*, ...).

Constraints

  • A name cannot live in both: a strong stdlib symbol beats a prelude linkonce_odr body, and a prelude body of a builtin's name replaces the builtin. A move is a deletion from the stdlib, in two steps (see "The two-step rule" in AGENTS.md).
  • Cost: larger program IR and build time (Symfony is already ~650 MB of IR). Move group by group and measure IR size and build time for each.
  • Measure rps as well: the specialised copies may be faster.

Done when

str_replace / preg_replace / strtoupper / strlen / strpos with a Stringable argument match php, and the Symfony skeleton answers 200 on its first request with an empty var/cache.

Activity

  1. added
    enhancement
    area:runtime
    on Oct 15, 2026
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

    area:runtimeenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions