Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the idea of framing modes #1549

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion benchmark/jsonschema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ static void Schema_Frame_OMC_Full(benchmark::State &state) {
"schemas" / "2019_09_omc_json_v2.json")};

for (auto _ : state) {
sourcemeta::core::SchemaFrame frame;
sourcemeta::core::SchemaFrame frame{
sourcemeta::core::SchemaFrame::Mode::Full};
frame.analyse(schema, sourcemeta::core::schema_official_walker,
sourcemeta::core::schema_official_resolver);
benchmark::DoNotOptimize(frame);
Expand Down
3 changes: 2 additions & 1 deletion src/core/jsonschema/bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ auto bundle(sourcemeta::core::JSON &schema, const SchemaWalker &walker,
const std::optional<std::string> &default_dialect) -> void {
const auto vocabularies{
sourcemeta::core::vocabularies(schema, resolver, default_dialect)};
sourcemeta::core::SchemaFrame frame;
sourcemeta::core::SchemaFrame frame{
sourcemeta::core::SchemaFrame::Mode::Full};
bundle_schema(schema, definitions_keyword(vocabularies), schema, frame,
walker, resolver, default_dialect);
}
Expand Down
7 changes: 4 additions & 3 deletions src/core/jsonschema/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ struct CacheSubschema {
const std::optional<sourcemeta::core::Pointer> parent;
};

auto internal_analyse(const sourcemeta::core::JSON &schema,
auto internal_analyse(const sourcemeta::core::SchemaFrame::Mode,
const sourcemeta::core::JSON &schema,
sourcemeta::core::SchemaFrame::Locations &frame,
sourcemeta::core::SchemaFrame::References &references,
const sourcemeta::core::SchemaWalker &walker,
Expand Down Expand Up @@ -940,8 +941,8 @@ auto SchemaFrame::analyse(const JSON &schema, const SchemaWalker &walker,
const std::optional<std::string> &default_dialect,
const std::optional<std::string> &default_id)
-> void {
internal_analyse(schema, this->locations_, this->references_, walker,
resolver, default_dialect, default_id);
internal_analyse(this->mode_, schema, this->locations_, this->references_,
walker, resolver, default_dialect, default_id);
}

auto SchemaFrame::locations() const noexcept -> const Locations & {
Expand Down
15 changes: 13 additions & 2 deletions src/core/jsonschema/include/sourcemeta/core/jsonschema_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ namespace sourcemeta::core {
/// }
/// })JSON");
///
/// sourcemeta::core::SchemaFrame frame;
/// sourcemeta::core::SchemaFrame
/// frame{sourcemeta::core::SchemaFrame::Mode::Full};
///
/// frame.analyse(document,
/// sourcemeta::core::schema_official_walker,
/// sourcemeta::core::schema_official_resolver);
Expand Down Expand Up @@ -101,6 +103,12 @@ namespace sourcemeta::core {
/// ```
class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
public:
/// The mode of framing. More extensive analysis can be compute and memory
/// intensive
enum class Mode { Full };

SchemaFrame(const Mode mode) : mode_{mode} {}

/// A single entry in a JSON Schema reference map
struct ReferencesEntry {
std::string destination;
Expand Down Expand Up @@ -201,6 +209,7 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
std::optional<std::reference_wrapper<const LocationsEntry>>>;

private:
Mode mode_;
// Exporting symbols that depends on the standard C++ library is considered
// safe.
// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
Expand Down Expand Up @@ -250,7 +259,9 @@ using SchemaUnevaluatedEntries = std::map<std::string, SchemaUnevaluatedEntry>;
/// "unevaluatedProperties": false
/// })JSON");
///
/// sourcemeta::core::SchemaFrame frame;
/// sourcemeta::core::SchemaFrame
/// frame{sourcemeta::core::SchemaFrame::Mode::Full};
///
/// frame.analyse(document,
/// sourcemeta::core::schema_official_walker,
/// sourcemeta::core::schema_official_resolver);
Expand Down
6 changes: 4 additions & 2 deletions src/core/jsonschema/jsonschema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,8 @@ auto sourcemeta::core::reference_visit(
const sourcemeta::core::SchemaVisitorReference &callback,
const std::optional<std::string> &default_dialect,
const std::optional<std::string> &default_id) -> void {
sourcemeta::core::SchemaFrame frame;
sourcemeta::core::SchemaFrame frame{
sourcemeta::core::SchemaFrame::Mode::Full};
frame.analyse(schema, walker, resolver, default_dialect, default_id);
for (const auto &entry : frame.locations()) {
if (entry.second.type !=
Expand Down Expand Up @@ -644,7 +645,8 @@ auto sourcemeta::core::unidentify(
const sourcemeta::core::SchemaResolver &resolver,
const std::optional<std::string> &default_dialect) -> void {
// (1) Re-frame before changing anything
sourcemeta::core::SchemaFrame frame;
sourcemeta::core::SchemaFrame frame{
sourcemeta::core::SchemaFrame::Mode::Full};
frame.analyse(schema, walker, resolver, default_dialect);

// (2) Remove all identifiers and anchors
Expand Down
2 changes: 1 addition & 1 deletion src/core/jsonschema/resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ auto SchemaMapResolver::add(const JSON &schema,

// Registering the top-level schema is not enough. We need to check
// and register every embedded schema resource too
SchemaFrame frame;
SchemaFrame frame{SchemaFrame::Mode::Full};
frame.analyse(schema, schema_official_walker, *this, default_dialect,
default_id);

Expand Down
Loading