Skip to content

add static interfaces in the form of signature types - #1543

Draft
zerbina wants to merge 20 commits into
nim-works:develfrom
zerbina:signature-types
Draft

add static interfaces in the form of signature types#1543
zerbina wants to merge 20 commits into
nim-works:develfrom
zerbina:signature-types

Conversation

@zerbina

@zerbina zerbina commented May 11, 2025

Copy link
Copy Markdown
Collaborator

Signature types are meant to provide static interfaces, which would be a first step towards type-checked generic routines and (maybe) eventually removing .borrow.

The name signature is a working title. It's not yet clear whether the feature will take over concept or stay as its own entity, and thus the concept syntax is simply reused.

The current specification is not meant to represent the final form. It's a version of the feature as discussed so far that's narrowed-down as much as possible in order to make a robust implementation feasible/possible with the current compiler. Further restrictions due to issues discovered during implementation are likely.

The feature was inspired by the signature feature of Standard ML.


To-Do

  • add a signature pragma
  • add dedicated TType kinds for signature types and their applied form
  • implement signature body analysis (partially done)
  • implement argument-dependent lookup (for signature types)
  • implement signature application (will be based on the existing borrow mechanism, most likely)
  • add tests
  • write a proper commit message

@zerbina zerbina added enhancement New feature or request language-design Language design syntax, semantics, types, statics and dynamics. labels May 11, 2025
Comment thread doc/manual.rst Outdated
Comment thread doc/manual.rst Outdated
Comment thread doc/manual.rst Outdated
@zerbina zerbina changed the title add static interface in the form of signature types add static interfaces in the form of signature types May 25, 2025
@zerbina zerbina mentioned this pull request May 27, 2025
4 tasks
zerbina added 19 commits May 11, 2026 19:38
* there's a dedicated `signature` type constructor now. This is better
  than the concept + pragma approach, but still not ideal
* `method`s are no longer allowed in signatures. I couldn't think of a
  good reason for allowing them ("why not" doesn't count)
* call operators are now allowed. This rule might need to be narrowed
  down again
To represent signature types and applied signature types, respectively.
Applied signature types are concrete types and may thus be used
anywhere concrete types may be used; raw signature types are meta types.
In the context of hooks, applied signature types are ignored and treated
as if they were their underlying type.
They're handled much like concepts, in that they're treated as their
underlying type.
Picking a symbol to borrow via regular overload resolution is wrong
because:
* it cannot enforce specific effects for the overload (raises, tags,
  and noSideEffect)
* it admits conversions
* it effectively ignores `sink` and other type modifiers

all of which are things that are not desired when picking a routine to
borrow from.
* handle pragma lists
* set up the types w.r.t. effects
* set the correct default calling convention for iterators
They're not good, but neither are most of the existing specification
tests...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request language-design Language design syntax, semantics, types, statics and dynamics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants