Skip to content

Split the built-in functions by family, and give int64 a header of its own - #1558

Merged
trueqbit merged 7 commits into
devfrom
refactor/split-builtin-functions
Oct 4, 2026
Merged

trueqbit merged 7 commits into
devfrom
refactor/split-builtin-functions

Conversation

@trueqbit

@trueqbit trueqbit commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Split builtin/functions/core.h by function family

The built-in functions in dev/builtin/functions/ are grouped the way SQLite documents them:

Header Functions SQLite docs
core.h the core scalar functions: abs(), coalesce(), length(), lower(), replace(), substr(), ... lang_corefunc
datetime.h date(), time(), datetime(), julianday(), strftime(), unixepoch(), timediff() lang_datefunc
aggregate.h count(*), count(), total(), sum(), avg(), max(), min(), group_concat(), string_agg(), median(), percentile*() lang_aggfunc
math.h the mathematical functions: acos() ... trunc() lang_mathfunc
json.h the JSON functions, including json_group_array() and json_group_object() json1
window.h the window functions (unchanged) windowfunctions
  • Each header is laid out like window.h. The C++17 branch holds the legacy name tags and factories; the C++20 branch holds the ""_builtin definitions and their public names. math.h and json.h guard their whole contents with SQLITE_ENABLE_MATH_FUNCTIONS and SQLITE_ORM_JSON_SUPPORTED.
  • MAX() and MIN() are in aggregate.h together with their scalar forms MAX(X,Y,...) and MIN(X,Y,...), since one C++20 definition covers both. Their doc comments now say so.
  • The general comment on how built-ins are published (copies vs. wrapping function templates, C library name clashes) moves into the umbrella functions.h.
  • The overloaded arithmetic and bitwise operators (- + * / % ~ << >> & |) move from core.h to operators.h, next to the nodes they build. The comparison operators already sit next to theirs in conditions.h. With that, core.h no longer needs to include conditions.h or operators.h.
  • storage.h includes aggregate.h for its aggregate shortcuts.

int64 and uint64 in sqlite3/sqlite3_types.h

  • The int64/uint64 aliases lived in core.h, and several headers saw them only because of include order: storage_base.h, column_result.h and carray.h use int64 outside templates without including anything that declares it.
  • They move to sqlite3/sqlite3_types.h, and every header that uses int64 now includes it. The header is not included from config.h. Because it exports public symbols, it is listed in the amalgamation manifest and in the non-amalgamated include instead.
  • With the alias available on its own, the headers that spelled sqlite_int64 for want of it use int64 throughout: the built-in functions LAST_INSERT_ROWID(), SQLITE_OFFSET() and UNIXEPOCH(), the column factories, and the integer field predicates. sqlite_int64 now appears only where int64 is defined.

The SQLite C API headers in a top-level sqlite3/

  • sqlite3_config.h moves from functional/ to sqlite3/, next to sqlite3_types.h. The folder holds sqlite_orm's interface to the SQLite C library: the configuration derived from <sqlite3.h> and the types republished from it.
  • It sits beside functional/ rather than inside it, because functional/ is C++ language and standard library plumbing that knows nothing about SQLite. functional/config.h still pulls in sqlite3_config.h first, so the configuration stays universally available.

AGENTS.md and the vocabulary-layer doc describe the new layout.

Overlap with #1550-#1553

#1552 (refactor/operators-under-ast) also moves the arithmetic operators beside their nodes, in its case into ast/operators.h. #1550 changes the includes of what was core_functions.h. Merging this PR before them will cause conflicts in that stack: the operator overloads end up in whichever header holds the operator nodes, and the include changes apply to the split headers.

Test plan

The changes only move code. Existing tests cover the moved functions and operators:

  • tests/builtin_functions_tests/ (core, date/time and math functions), tests/json.cpp, tests/window_function_tests.cpp
  • tests/statement_serializer_tests/core_functions.cpp, aggregate_functions.cpp, arithmetic_operators.cpp, bitwise_operators.cpp
  • tests/static_tests/core_function_return_types.cpp, aggregate_function_return_types.cpp, builtin_function_static_tests.cpp, arithmetic_operators_result_type.cpp, operators_adl.cpp
  • tests/operators/arithmetic_operators.cpp, bitwise_operators.cpp
  • the rtree and carray tests, for int64

🤖 Generated with Claude Code

The built-in functions are grouped as SQLite documents them, each header
holding the legacy C++17 name tags and factories as well as the C++20
definitions and their public names, like window.h:

- core.h: the core scalar functions (lang_corefunc)
- datetime.h: the date and time functions (lang_datefunc)
- aggregate.h: the aggregate functions (lang_aggfunc), including COUNT(*)
  and the percentile functions; MAX() and MIN() take their scalar forms
  along, as one definition covers both in C++20 builds
- math.h: the mathematical functions (lang_mathfunc)
- json.h: the JSON functions (json1), including their aggregates

The overloaded arithmetic and bitwise operators move to operators.h,
beside the nodes they build, as the comparison operators are beside theirs
in conditions.h. core.h no longer includes conditions.h and operators.h.

storage.h includes aggregate.h for its aggregate shortcuts, and core.h
still for int64. The legacy unixepoch() returns sqlite_int64 as its C++20
definition does, so datetime.h does not depend on core.h for int64.

Co-Authored-By: Claude Opus 5.5
The aliases of SQLite's 64-bit integer types lived in core.h for lack of a
better home, and were reachable only through the order in which headers
happened to be included: storage_base.h, column_result.h and carray.h use
int64 in non-dependent contexts without including anything that declares
it.

functional/sqlite3_types.h holds the types of the SQLite C API that
sqlite_orm republishes, next to sqlite3_config.h, and every header using
int64 now includes it.

Co-Authored-By: Claude Opus 5.5
sqlite3_config.h and sqlite3_types.h are sqlite_orm's interface to
sqlite3.h - the configuration derived from it and the types republished
from it - and move to a folder of their own.

sqlite3_types.h exports public symbols, hence it is listed in the
amalgamation manifest and the non-amalgamated include instead of relying
on other headers to include it.

Co-Authored-By: Claude Opus 5.5
@trueqbit
trueqbit requested a review from fnc12 October 2, 2026 18:37
Base automatically changed from refactor/builtin-dbos to dev October 3, 2026 07:15
With int64 in a header of its own, the headers that spelled it
sqlite_int64 for want of the alias include sqlite3_types.h and use int64:
the built-in functions LAST_INSERT_ROWID(), SQLITE_OFFSET() and
UNIXEPOCH(), the column factories and the integer field predicates.

Co-Authored-By: Claude Opus 5.5
functional/ holds C++ language and standard library plumbing that knows
nothing about SQLite. sqlite3_config.h and sqlite3_types.h instead sit on
the boundary to the SQLite C library - the configuration derived from
<sqlite3.h> and the types republished from it as public symbols - so
their folder becomes a layer of its own beside functional/.

functional/config.h, the headers using int64, the amalgamation manifest,
the non-amalgamated include and a comment in tests/CMakeLists.txt follow
the move; AGENTS.md describes the folder. The amalgamated code is
unchanged apart from its include comments.

Co-Authored-By: Claude Opus 5.5
@trueqbit
trueqbit requested a review from fnc12 October 4, 2026 06:31
@trueqbit
trueqbit merged commit 17e268e into dev Oct 4, 2026
20 checks passed
@trueqbit
trueqbit deleted the refactor/split-builtin-functions branch October 4, 2026 06:56
trueqbit added a commit that referenced this pull request Oct 4, 2026
…er-ast

dev (#1558) moved the overloaded arithmetic and bitwise operators from
core.h into operators.h, as this branch did when moving operators.h to
ast/operators.h; both sides appended the same block, which is kept once.

Resolved:
- ast/operators.h keeps this branch's includes, relative to ast/.
- core_functions.h, from which this branch took the operators, is gone on
  dev, replaced by builtin/functions/.

Co-Authored-By: Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants