Skip to content

Consider enabling tail call interpreter for sre_lib.h #161469

Open

Description

@sobolevn

It already supports computed gotos:

#ifdef HAVE_COMPUTED_GOTOS
#ifndef USE_COMPUTED_GOTOS
#define USE_COMPUTED_GOTOS 1
#endif
#elif defined(USE_COMPUTED_GOTOS) && USE_COMPUTED_GOTOS
#error "Computed gotos are not supported on this compiler."
#else
#undef USE_COMPUTED_GOTOS
#define USE_COMPUTED_GOTOS 0
#endif
#if USE_COMPUTED_GOTOS
#define TARGET(OP) TARGET_ ## OP
#define DISPATCH \
do { \
MAYBE_CHECK_SIGNALS; \
goto *sre_targets[*pattern++]; \
} while (0)
#else
#define TARGET(OP) case OP
#define DISPATCH goto dispatch
#endif

Maybe adding tail-calling interpreter will give meaningful speed up for all re calls as well? This might speed up a lot of places in the real code almost for free.

This needs to be researched and measured before making a PR.

Activity

  1. sobolevn commented on Nov 6, 2026

    @sobolevn
    MemberAuthor

    CC @Fidget-Spinner, maybe you have an opinion on this :)

  2. Fidget-Spinner commented on Nov 6, 2026

    @Fidget-Spinner
    Member

    I think I looked at the sre interpreter some time ago and concluded at the time to support things it would be pretty invasive, as some of it has jump targets within labels, and that kind of unstructured control-flow is unsupported by the tailcalling approach. At the very minimum, a refactor of the sre interpreter might be required. I might be remembering wrong and/or thinking of the marshal interpreter though. Anyways, with an AI agent it's probably much easier to do nowdays.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions