Skip to content

@doc and @meta annotations#446

Merged
dmitrii-ubskii merged 9 commits into
typedb:masterfrom
dmitrii-ubskii:doc-annos
Jun 22, 2026
Merged

@doc and @meta annotations#446
dmitrii-ubskii merged 9 commits into
typedb:masterfrom
dmitrii-ubskii:doc-annos

Conversation

@dmitrii-ubskii

@dmitrii-ubskii dmitrii-ubskii commented Apr 28, 2026

Copy link
Copy Markdown
Member

Product change and motivation

We implement @doc("docstring") and @meta("key", "value") schema annotations. These annotations can be attached to types and capabilities i.e. owns, plays, relates, and sub:

define
entity person @doc("this represents an individual client") @meta("icon", ":silhouette.png"),
  owns name @doc("full name including title");
match
  $x isa client;
  let $x_icon = get_meta("icon", $t); # get each client with a UI display icon hint

These annotations can also be attached to function definitions. They go at the end of the signature, before the colon introducing the body of the function:

define
fun get_random_number() -> integer
    @doc("chosen by a fair dice roll"):
match
  let $rand = 4;
return first $rand;

Implementation

@dmitrii-ubskii dmitrii-ubskii force-pushed the doc-annos branch 3 times, most recently from fc420c4 to 1882f30 Compare May 5, 2026 15:24
let mut children = node.into_children();
let keyword = children.consume_any();
let annotation_category = match keyword.as_rule() {
Rule::ANNOTATION_ABSTRACT => AnnotationCategory::Abstract,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh fun can we dissolve the core-specific IR for these now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the Meta category carries a StringLiteral in typeql but a parsed unescaped String in core.

Comment thread rust/parser/typeql.pest
// FUNCTION DEFINITION =========================================================

definition_function = { FUN ~ function_signature ~ COLON ~ function_block }
definition_function = { FUN ~ function_signature ~ annotations? ~ COLON ~ function_block }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how do we expect to write this?

define
fun get_name($p: person) -> { name}
    @doc("..."):
  match $p has name $name;
  return { $name };

?

Comment thread rust/schema/definable/function.rs Outdated

@flyingsilverfin flyingsilverfin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved w comments

@dmitrii-ubskii dmitrii-ubskii merged commit 556db69 into typedb:master Jun 22, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants