Skip to content

Give each function the signatures of the types it serves - #81

Merged
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:feat/per-function-type-scope
Aug 13, 2026
Merged

Give each function the signatures of the types it serves#81
estebanzimanyi merged 1 commit into
MobilityDB:masterfrom
estebanzimanyi:feat/per-function-type-scope

Conversation

@estebanzimanyi

Copy link
Copy Markdown
Member

A PG wrapper commonly backs a whole per-type family. Set_values is the body behind getValues(intset), getValues(cbufferset) and fourteen more, and every one of those MEOS functions names that wrapper in its @csqlfn. A wrapper's signature list is therefore the union over its claimants, and attaching it whole says intset_values serves cbufferset. Of 1675 wrappers, 231 are claimed by more than one public function; a binding that trusts sqlSignatures as the type authority registers one function's body under every sibling's type.

Each function keeps only the signatures its TYPE SCOPE covers, read from what MEOS states rather than from the function's name:

  • its own VALIDATE_* macro,
  • the MeosType literals in its body,
  • a class predicate it calls (tnumber_type, tspatial_type, …),
  • its C parameter types, resolved through the catalog's base-type relations.

The macros are read from their definitions, so a class macro resolves as well: VALIDATE_TGEO is written over ensure_tgeo_type_all, and a name-shaped reading sees only the single-type macros and misses every class. Scopes match in both spellings, since a SQL signature says integer where meostype_name says int4.

Of the claimants, 720 resolve through a VALIDATE_* macro, 105 through C parameters and 82 through MeosType literals. The 27 that state nothing are declared in meta/type-scope.json with the reason each is unstated, and require_scopes fails generation on any claimant that is neither derived nor declared. Guessing is what the mechanism exists to avoid: assuming "all" keeps the wrong signatures, assuming "none" drops real registrations, and both are invisible downstream.

A filtered function keeps its OWN overload, which carries its own SQL name (bigintset_in) rather than the representative the @sqlfn tag names (intset_in), so the single-name shortcut preserves exactly the signature the scope proves belongs to it.

Measured against one MobilityDB commit, before and after: 5513 functions both sides, none gains a signature, 868 shrink to the types they serve (intset_values 16 → 1, cbufferset_values 16 → 1), and tgeo_stboxes keeps all 6 of the types its single C entry point genuinely serves. 20 keep none: each is a wrapper whose overloads the claimant does not serve — the jsonb comparisons MEOS exports without any SQL declaration, and functions whose @csqlfn names a wrapper belonging to another type.

tests/test_typescope.py covers the filter, the generic case, the empty case, return-type placement, and the SQL spelling map.

A PG wrapper commonly backs a whole per-type family: Set_values is the body
behind getValues(intset), getValues(cbufferset) and fourteen more, and every one
of those MEOS functions names that wrapper in its @csqlfn. The wrapper's
signature list is therefore the union over its claimants, and attaching it whole
told a binding that intset_values serves cbufferset. Of 1675 wrappers, 231 are
claimed by more than one public function.

Each function now keeps only the signatures its TYPE SCOPE covers, read from
what MEOS itself states: its VALIDATE_* macro, the MeosType literals in its
body, a class predicate it calls, or its C parameter types resolved through the
catalog's base-type relations. The macros are read from their DEFINITIONS, so a
class macro resolves too — VALIDATE_TGEO is written over ensure_tgeo_type_all,
and a name-shaped reading would see only the single-type macros. Scopes are
compared in both spellings, since SQL says integer where meostype_name says
int4.

Of the claimants, 720 resolve through a VALIDATE_* macro, 105 through C
parameters and 82 through MeosType literals. The 27 that state nothing are
declared in meta/type-scope.json with the reason each is unstated, and
require_scopes fails generation on any claimant that is neither derived nor
declared: guessing keeps the wrong signatures or drops real ones, and both are
invisible downstream.

A filtered function keeps its OWN overload, which carries its own SQL name
(bigintset_in) rather than the representative the @sqlfn tag names (intset_in),
so the single-name shortcut no longer drops it.

Measured against the same MobilityDB commit: 5513 functions before and after,
none gains a signature, 868 shrink to the types they serve. 20 keep none, each
a wrapper whose overloads the claimant genuinely does not serve — the jsonb
comparisons MEOS exports without a SQL declaration, and functions whose @csqlfn
names a wrapper of another type.
@estebanzimanyi
estebanzimanyi merged commit 4fe4d4a into MobilityDB:master Aug 13, 2026
2 checks passed
@estebanzimanyi
estebanzimanyi deleted the feat/per-function-type-scope branch August 13, 2026 09:45
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.

1 participant