Skip to content

Commit

Permalink
Minor changes to serialization to support better merging semantics.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Feb 23, 2024
1 parent 6027c26 commit 2c7cbb6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions jasmin/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
"//jasmin/core/internal:function_forward",
"@nth_cc//nth/debug",
"@nth_cc//nth/io/deserialize",
"@nth_cc//nth/io/reader",
"@nth_cc//nth/io/serialize",
Expand Down
4 changes: 3 additions & 1 deletion jasmin/core/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct Function<void> : internal::FunctionBase {
template <nth::io::serializer_with_context<FunctionRegistry> S>
friend nth::io::serializer_result_type<S> NthSerialize(S &s,
Function const *f) {
if (not f) { NTH_UNIMPLEMENTED(); }
return nth::io::serialize(s, s.context(nth::type<FunctionRegistry>).get(f));
}

Expand All @@ -54,7 +55,8 @@ struct Function<void> : internal::FunctionBase {
if (not result) { return result; }
auto &registry = d.context(nth::type<FunctionRegistry>);
fn = registry[id];
return result_type(true);
if (fn == nullptr) { NTH_UNIMPLEMENTED(); }
return result_type(fn != nullptr);
}

protected:
Expand Down
1 change: 0 additions & 1 deletion jasmin/core/function_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ FunctionIdentifier FunctionRegistry::get(Function<> const *f) {
Function<> const *FunctionRegistry::operator[](FunctionIdentifier id) const {
if (id.index_ >= registered_functions_.size()) { return nullptr; }
auto [f, pf] = registered_functions_.from_index(id.index_);
if (pf != id.fragment_) { return nullptr; }
return f;
}

Expand Down
3 changes: 1 addition & 2 deletions jasmin/core/program_fragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ struct ProgramFragment : internal::ProgramFragmentBase {
}

auto [iter, inserted] = p.functions_.try_emplace(name);
if (not inserted) { return result_type(false); }
registry.register_function(p, iter->second);
if (inserted) { registry.register_function(p, iter->second); }
fns.push_back(&iter->second);
}

Expand Down

0 comments on commit 2c7cbb6

Please sign in to comment.