Skip to content

Let the code generators set the pattern match limit written into generated code #1022

Description

@mwadams

Summary

Generated code (V5 and V4) carries the pattern match limit as a literal: 1 second, written into each [GeneratedRegex] attribute, each Regex constructor call and the options of the generated schema program. A consumer who needs a different limit, or none, has to use the runtime evaluator, where JsonSchemaEvaluatorOptions.RegexMatchTimeout sets it.

This issue asks for a way to choose the limit when code is generated.

Proposal

A generator option for the match limit, with the current 1 second as the default:

  • a switch on the corvusjson CLI and an entry in the generator configuration schema,
  • a property on the source generator's attribute or its MSBuild options.

The value would still be fixed at generation time, so changing it means regenerating. That keeps [GeneratedRegex] usable, since the attribute cannot take a run-time value.

Alternatives considered

  • Read the limit at run time from an AppContext value. [GeneratedRegex] expressions would have to become constructed ones and would lose source generation.
  • Omit the limit and rely on the process-wide REGEX_DEFAULT_MATCH_TIMEOUT. The limit would then be off unless the host sets it, and it would apply to every Regex in the process.

Context

The limit and its default come from the pattern conformance and resource limit work on fix/separated-list-anchors. The restriction is documented in docs/CodeGenerator.md and docs/SourceGenerator.md there.

Activity

  1. added theissue type on Oct 11, 2026
  2. added a commit that references this issue on Nov 2, 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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions