Introduce explicit I/O namespace#467
Conversation
2300ab4 to
73481f8
Compare
5a81b5b to
47fe843
Compare
eec7765 to
50c761e
Compare
50c761e to
a43724d
Compare
b230c6e to
0f47709
Compare
0f47709 to
daec090
Compare
|
Will this PR be included in the 2.1 release? I am asking because MS1 has an example using |
|
Generally speaking, I would have thought so. The main motivation for this was to have versioning capabilities for the serialization format 👀 |
Yes, it will be good to have in 2.1 . |
There was a problem hiding this comment.
This is produced by Claude 4.6, with my annotations. Some points can be ignored but keeping for posterity.
High severity
-
is_tensorconcept requires I/O capability —abstract_tensor.hppnow requires{ io::latex::to_string(obj) } -> std::convertible_to<std::wstring>in theis_tensorconcept. This couples the fundamental tensor interface to the I/O layer, inverting the dependency direction. A type should be a "tensor" based on its mathematical properties, not on whether it can produce LaTeX. Consider a separateis_latex_renderable_tensorconcept or removing this requirement fromis_tensor. -
I DON'T THINK THIS IS IMPORTANT:
SerializationErrorbase class change — OldParseErrorinherited fromstd::runtime_error; newSerializationErrorinherits fromException : std::exception. Downstream code catchingstd::runtime_error&will silently miss these errors. -
I DON'T THINK THIS IS NECESSARY: No backward-compat shims for
parse_expr/deparse— The oldparse_expr(wstring_view, ...)anddeparse(ExprPtr, ...)free functions are completely gone with no deprecation wrappers. All downstream code using these will break immediately. The shorthands header providesdeserialize/serializebut not the old names. -
Stale
#undefmacros inserialization.cpp— The file undefsSEQUANT_RESOLVE_PARSE_FUNCandSEQUANT_RESOLVE_DEPARSE_FUNCwhich were never defined. The actually-defined macros (SEQUANT_RESOLVE_DESERIALIZATION_FUNC,RESOLVE_SERIALIZE_FUNC) leak past the end of the file.
Medium severity
-
Include guard naming —
serialization.hppreusesSEQUANT_PARSE_HPP(the old guard).v1/ast.hpphas mismatched guards (SEQUANT_CORE_PARSE_V1_AST_HPPat#ifndefvsSEQUANT_CORE_PARSE_AST_V1_HPPat#endif). These should match the new file paths. -
to_latex(ExprPtr)may not work without dereferencing — The oldto_latex(const ExprPtr&)fromexpr_algorithms.hppwas removed. The newio::latex::to_stringhas apointer_can_call_to_latexconcept overload, but tests were updated fromto_latex(e)toto_latex(*e), suggesting the pointer overload may not be working correctly. Worth verifying. -
is_tensorchanged from trait to concept —is_tensor_v<T>andis_tensor<T>::valueare gone. Any downstreamstd::enable_if_t<is_tensor_v<T>>usage will break. -
to_string/to_wstringrenamed totoUtf8/toUtf16— No deprecated aliases provided for the old names. -
{ label(obj) } -> std::constructible_from<std::wstring>inconsistent — Every other constraint in theis_tensorconcept usesstd::convertible_to<T>, but this one usesstd::constructible_from<T>(more permissive, allows explicit conversions). Should bestd::convertible_to<std::wstring>for consistency. -
to_stringoverload ambiguity risk — The threeio::latex::to_stringoverloads (forhas_to_latex_member,pointer_can_call_to_latex, and_to_latex()) are not fully mutually exclusive. A type with bothto_latex()and_to_latex()would match overloads 1 and 3, with resolution depending on reference binding (T&&vsconst T&). This is fragile.
Low severity
-
Wrong namespace closing comment in
serialization.hpp— Says} // namespace sequant, should be} // namespace sequant::io::serialization. -
Removed diagnostic output in ITF —
itf.hppremovedstd::wcerr << deparse(product)before a throw rather than updating to the new API. Loses debugging info. -
#if 0dead code inutility/string.hpp— The oldto_string/to_wstringtemplates are disabled but not removed. -
python/test.pyadded — Appears unrelated to the I/O namespace refactoring. Accidental inclusion? -
Pre-existing sign bug preserved in
serialize_scalar— TheimagNumerator < 0 ? " + i " : " - i "logic appears inverted for positive imaginary parts (the subsequent.str()includes its own sign, so1 + 3iwould serialize as"1 - i 3"). Carried forward from olddeparse_scalar— not introduced by this PR but the refactor was an opportunity to fix it. -
Tabs in macro block in
serialization.hppv1namespace forward-declarations — inconsistent with the rest of the codebase.
|
also: how about defaulting target type |
This is just a 1-to-1 translation of the previous requirement. I'm happy to drop it though (
It does - the change to the test cases happened at a time when I didn't have the overload for
That was intentional - staying consistent with the meaning of those functions in the In fact, I would like to remove the remaining
That is due to the choice of making Actually, this is something that has been slightly bugging me for some time. Imo using auto name = tensor.label();Looking at this, you might think that you have now an independent copy of the tensor's label. However, if This is arguably not a big deal as it isn't frequently encountered. However, I can't help thinking that using
I was thinking about this as well. I ended up not defaulting this to ensure users are always aware that they can customize the expected type (which I plan to extend in v2 such that we could do |
It feels like we should drop
👍
👍
Yes, sure, views are cheap to copy but expensive to reason about :) copy-on-write strings are probably best.
but even then: C++'s original sin is use of C defaults (=taking pointers is allowed by default). Value semantics is the way to go, but need optimizations for needless copies (move semantics is not panacea).
OK, please do it. |
Support was incomplete anyway and since we don't have intentions on completing it, we remove it in order for nobody to rely on it.
At the same time, switch to consistently using toUtf8/toUtf16
cbb2fed to
c7d74be
Compare
See individual commits.
TODO:
wstring.hppintoutility/string.hppRemove strayto_stringoverloads - support for that is quite inconsistent and user's should prefer using explicit I/O functionsionamespace for all text<->object conversions