Compile a JSON Schema into a set of low-level instructions for fast evaluation. More...
Typedefs | |
| using | sourcemeta::blaze::SchemaUnevaluatedEntries |
| using | sourcemeta::blaze::Compiler |
Functions | |
| auto | sourcemeta::blaze::default_schema_compiler (const KeywordContext &, const Instructions &) -> Instructions |
| auto | sourcemeta::blaze::compile (const sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const Compiler &compiler, const Mode mode=Mode::FastValidation, const std::string_view default_dialect="", const std::string_view default_id="", const std::string_view entrypoint="", const std::optional< Tweaks > &tweaks=std::nullopt, std::uint64_t max_locations=std::numeric_limits< std::uint64_t >::max()) -> Template |
| auto | sourcemeta::blaze::compile (const sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const Compiler &compiler, const sourcemeta::core::SchemaFrame &frame, const std::string_view entrypoint, const Mode mode=Mode::FastValidation, const std::optional< Tweaks > &tweaks=std::nullopt) -> Template |
| auto | sourcemeta::blaze::compile (const KeywordContext &context, const sourcemeta::core::WeakPointer &schema_suffix, const sourcemeta::core::WeakPointer &instance_suffix=sourcemeta::core::EMPTY_WEAK_POINTER, std::optional< std::string_view > uri=std::nullopt) -> Instructions |
| auto | sourcemeta::blaze::to_json (const Template &schema_template) -> sourcemeta::core::JSON |
Variables | |
| const sourcemeta::core::JSON::String | sourcemeta::blaze::EMPTY_KEYWORD |
Compile a JSON Schema into a set of low-level instructions for fast evaluation.
| struct sourcemeta::blaze::SchemaUnevaluatedEntry |
Public Attributes | |
| std::set< sourcemeta::core::WeakPointer > | static_dependencies |
| The absolute pointers of the static keyword dependencies. | |
| std::set< sourcemeta::core::WeakPointer > | dynamic_dependencies |
| bool | unresolved {false} |
| std::set<sourcemeta::core::WeakPointer> sourcemeta::blaze::SchemaUnevaluatedEntry::dynamic_dependencies |
The absolute pointers of the dynamic keyword dependencies, along with the references that lead to them
| bool sourcemeta::blaze::SchemaUnevaluatedEntry::unresolved {false} |
Whether the entry cannot be fully resolved, which means there might be unknown dynamic dependencies
| struct sourcemeta::blaze::SchemaContext |
The schema compiler context is the current subschema information you have at your disposal to implement a keyword
| struct sourcemeta::blaze::DynamicContext |
The dynamic compiler context is the read-write information you have at your disposal to implement a keyword
Public Member Functions | |
| auto | value () const -> const sourcemeta::core::JSON & |
Public Attributes | |
| const sourcemeta::core::JSON::String & | keyword |
| The schema keyword. | |
| const sourcemeta::core::JSON * | keyword_value {nullptr} |
| The value of the keyword, null in a context that names none. | |
| const sourcemeta::core::WeakPointer & | base_schema_location |
| The schema base keyword path. | |
| const sourcemeta::core::WeakPointer & | base_instance_location |
| The base instance location that the keyword must be evaluated to. | |
|
inlinenodiscard |
What the keyword this context names is set to. Only a context built to compile a keyword carries one
| class sourcemeta::blaze::InstructionExtras |
An accumulator for instruction metadata that refuses to grow past a limit. Compilation makes one entry here for every instruction it makes, including the ones it goes on to throw away and the copies that inlining leaves behind, so what this holds is what compiling the schema cost
Public Member Functions | |
| InstructionExtras (const std::uint64_t limit) | |
| auto | push_back (InstructionExtra &&entry) -> void |
| Make room for another instruction, throwing once out of room. | |
| auto | size () const noexcept -> std::size_t |
| auto | operator[] (const std::size_t index) const noexcept -> const InstructionExtra & |
| auto | operator[] (const std::size_t index) noexcept -> InstructionExtra & |
| auto | release () &&-> std::vector< InstructionExtra > |
| Hand the accumulated entries over to the template that will own them. | |
| struct sourcemeta::blaze::Tweaks |
Advanced knobs that you can tweak for higher control and optimisations
Public Attributes | |
| bool | properties_always_unroll {false} |
| Always unroll properties in a logical AND operation. | |
| bool | properties_reorder {true} |
| Attempt to re-order properties subschemas to evaluate cheaper ones first. | |
| std::size_t | target_inline_threshold {50} |
| Inline jump targets with fewer instructions than this threshold. | |
| bool | format_assertion {false} |
| When set, force format to be compiled as an assertion. | |
| std::optional< std::unordered_set< sourcemeta::core::JSON::StringView > > | annotations {} |
| std::uint64_t | max_instructions {std::numeric_limits<std::uint64_t>::max()} |
| std::uint64_t | max_depth {std::numeric_limits<std::uint64_t>::max()} |
| std::optional<std::unordered_set<sourcemeta::core::JSON::StringView> > sourcemeta::blaze::Tweaks::annotations {} |
Select which keywords emit annotations, regardless of the compilation mode. When not set, every annotation keyword is emitted in exhaustive mode and none in fast mode
| std::uint64_t sourcemeta::blaze::Tweaks::max_depth {std::numeric_limits<std::uint64_t>::max()} |
How deep compilation may descend into a schema before it gives up and throws. Compiling a subschema recurses back into itself through the keyword handlers, so without this a schema nested deeply enough runs the stack out rather than reporting anything the caller can catch
| std::uint64_t sourcemeta::blaze::Tweaks::max_instructions {std::numeric_limits<std::uint64_t>::max()} |
How many instructions compilation may make before it gives up and throws. A schema compiles every target it can be entered through, and inlining copies what it inlines, so what an untrusted schema costs to compile grows faster than the schema itself does
| struct sourcemeta::blaze::Context |
The static compiler context is the information you have at your disposal to implement a keyword that will never change throughout the compilation process
Public Attributes | |
| const sourcemeta::core::JSON & | root |
| The root schema resource. | |
| const sourcemeta::core::SchemaFrame & | frame |
| The reference frame of the entire schema. | |
| const std::vector< std::string > | resources |
| The set of all schema resources in the schema without duplicates. | |
| const sourcemeta::core::SchemaWalker & | walker |
| The schema walker in use. | |
| const sourcemeta::core::SchemaResolver & | resolver |
| The schema resolver in use. | |
| const Compiler & | compiler |
| The schema compiler in use. | |
| const Mode | mode |
| The mode of the schema compiler. | |
| const bool | uses_dynamic_scopes |
| Whether the schema makes use of dynamic scoping. | |
| const bool | collects_annotations |
| Whether evaluating the schema may collect at least one annotation. | |
| const SchemaUnevaluatedEntries | unevaluated |
| The list of unevaluated entries and their dependencies. | |
| const Tweaks | tweaks |
| The set of tweaks for the compiler. | |
| const std::map< std::tuple< sourcemeta::core::SchemaReferenceType, std::string_view, bool >, std::pair< std::size_t, const sourcemeta::core::WeakPointer * > > | targets |
| All possible reference targets (key includes is_property_name context). | |
| std::uint64_t & | depth |
| How deep into the schema compilation currently is. | |
| InstructionExtras & | extra |
| Accumulator for instruction extra data during compilation. | |
| std::vector< sourcemeta::core::SchemaVocabularies::URI > & | vocabularies |
| Accumulator for the vocabularies that instructions refer to. | |
| struct sourcemeta::blaze::KeywordContext |
Everything a keyword is compiled against: the compilation as a whole, the subschema that declares the keyword, and the keyword itself
Public Member Functions | |
| auto | keyword () const -> const sourcemeta::core::JSON::String & |
| The keyword itself. | |
| auto | value () const -> const sourcemeta::core::JSON & |
| What the keyword is set to. | |
| auto | schema () const -> const sourcemeta::core::JSON & |
| The subschema that declares the keyword. | |
| auto | vocabularies () const -> const sourcemeta::core::SchemaVocabularies & |
| The vocabularies in force where the keyword is declared. | |
| auto | base () const -> const sourcemeta::core::URI & |
| The base URI of the subschema that declares the keyword. | |
| auto | mode () const -> Mode |
| The mode the whole schema is being compiled in. | |
| auto | relative () const -> KeywordContext |
Public Attributes | |
| const Context & | global |
| What holds for the entire compilation. | |
| const SchemaContext & | local |
| The subschema that the keyword belongs to. | |
| DynamicContext | target |
|
inlinenodiscard |
The same subschema, addressed from where the keyword sits rather than from the base, which is what an applicator compiles its children against
| DynamicContext sourcemeta::blaze::KeywordContext::target |
The keyword being compiled. Held by value, as the references it carries point at storage that outlives any context derived from it
| class sourcemeta::blaze::CompilerError |
An error that represents a schema compilation failure event
Public Member Functions | |
| CompilerError (sourcemeta::core::URI base, sourcemeta::core::Pointer schema_location, const char *message) | |
| CompilerError (sourcemeta::core::URI base, sourcemeta::core::Pointer schema_location, std::string message)=delete | |
| CompilerError (sourcemeta::core::URI base, sourcemeta::core::Pointer schema_location, std::string &&message)=delete | |
| CompilerError (sourcemeta::core::URI base, sourcemeta::core::Pointer schema_location, std::string_view message)=delete | |
| auto | what () const noexcept -> const char *override |
| auto | base () const noexcept -> const sourcemeta::core::URI & |
| auto | location () const noexcept -> const sourcemeta::core::Pointer & |
|
inlinenodiscardnoexcept |
Where the problem is, as a pointer from the root of the document that the schema came from
| class sourcemeta::blaze::CompilerInvalidRegexError |
An error that represents an invalid regular expression during compilation
Public Member Functions | |
| CompilerInvalidRegexError (sourcemeta::core::URI base, sourcemeta::core::Pointer schema_location, std::string regex) | |
| auto | what () const noexcept -> const char *override |
| auto | base () const noexcept -> const sourcemeta::core::URI & |
| auto | location () const noexcept -> const sourcemeta::core::Pointer & |
| auto | regex () const noexcept -> const std::string & |
|
inlinenodiscardnoexcept |
Where the problem is, as a pointer from the root of the document that the schema came from
| class sourcemeta::blaze::CompilerReferenceTargetNotSchemaError |
An error that represents a reference target that is not a valid schema
Public Member Functions | |
| CompilerReferenceTargetNotSchemaError (const std::string_view identifier, sourcemeta::core::Pointer schema_location) | |
| auto | what () const noexcept -> const char *override |
| auto | identifier () const noexcept -> const std::string & |
| auto | location () const noexcept -> const sourcemeta::core::Pointer & |
|
inlinenodiscardnoexcept |
Where the problem is, as a pointer from the root of the document that the schema came from
| class sourcemeta::blaze::CompilerInstructionLimitError |
An error that represents a schema that compiles into more instructions than the caller was willing to spend on it
Public Member Functions | |
| CompilerInstructionLimitError (const std::uint64_t limit) | |
| auto | what () const noexcept -> const char *override |
| auto | limit () const noexcept -> std::uint64_t |
| The maximum number of instructions that compilation was allowed to make. | |
| class sourcemeta::blaze::CompilerDepthLimitError |
An error that represents a schema that nests deeper than the caller was willing to descend into
Public Member Functions | |
| CompilerDepthLimitError (const std::uint64_t limit) | |
| auto | what () const noexcept -> const char *override |
| auto | limit () const noexcept -> std::uint64_t |
| The deepest that compilation was allowed to descend. | |
| class sourcemeta::blaze::CompilerInvalidEntryPoint |
An error that represents an invalid compilation entrypoint
A compiler is represented as a function that maps a keyword compiler context into a compiler template. You can provide your own to implement your own keywords
The flattened set of unevaluated cases in the schema by absolute URI
| auto sourcemeta::blaze::compile | ( | const KeywordContext & | context, |
| const sourcemeta::core::WeakPointer & | schema_suffix, | ||
| const sourcemeta::core::WeakPointer & | instance_suffix = sourcemeta::core::EMPTY_WEAK_POINTER, | ||
| std::optional< std::string_view > | uri = std::nullopt )->Instructions |
This function compiles a single subschema into a compiler template as determined by the given pointer. If a URI is given, the compiler will attempt to jump to that corresponding frame entry. Otherwise, it will navigate within the current keyword. This function is not meant to be used directly, but instead as a building block for supporting applicators on compiler functions.
| auto sourcemeta::blaze::compile | ( | const sourcemeta::core::JSON & | schema, |
| const sourcemeta::core::SchemaWalker & | walker, | ||
| const sourcemeta::core::SchemaResolver & | resolver, | ||
| const Compiler & | compiler, | ||
| const Mode | mode = Mode::FastValidation, | ||
| const std::string_view | default_dialect = "", | ||
| const std::string_view | default_id = "", | ||
| const std::string_view | entrypoint = "", | ||
| const std::optional< Tweaks > & | tweaks = std::nullopt, | ||
| std::uint64_t | max_locations = std::numeric_limits< std::uint64_t >::max() )->Template |
This function compiles an input JSON Schema into a template that can be later evaluated. For example:
This overload bundles and frames the schema before compiling it, and neither of those is bounded by the compiler tweaks. Pass max_locations to bound them instead. Bundling and framing each get this budget rather than sharing one, so the preamble costs at most twice it. The overload that takes a frame does neither, and so takes no such limit
| auto sourcemeta::blaze::compile | ( | const sourcemeta::core::JSON & | schema, |
| const sourcemeta::core::SchemaWalker & | walker, | ||
| const sourcemeta::core::SchemaResolver & | resolver, | ||
| const Compiler & | compiler, | ||
| const sourcemeta::core::SchemaFrame & | frame, | ||
| const std::string_view | entrypoint, | ||
| const Mode | mode = Mode::FastValidation, | ||
| const std::optional< Tweaks > & | tweaks = std::nullopt )->Template |
This function compiles an input JSON Schema into a template that can be later evaluated, but given an existing schema frame. The schema frame must contain reference information for the given schema and the input schema must be bundled. If those pre-conditions are not met, you will hit undefined behavior.
Don't use this function unless you know what you are doing.
| auto sourcemeta::blaze::default_schema_compiler | ( | const KeywordContext & | , |
| const Instructions & | )->Instructions |
A default compiler that aims to implement every keyword for official JSON Schema dialects.
| auto sourcemeta::blaze::to_json | ( | const Template & | schema_template | ) | ->sourcemeta::core::JSON |
Serialise a template as JSON
| const sourcemeta::core::JSON::String sourcemeta::blaze::EMPTY_KEYWORD |
A global constant instance of the empty schema keyword, which is what a context that names no keyword carries