# compiler/concepts

Dark Mode

- Index

Search:
Group by:
Source Edit

New styled concepts for Nim. See https://github.com/nim-lang/RFCs/issues/168 for details. Note this is a first implementation and only the "Concept matching" section has been implemented.

# Code dealing with Concept declarations

# Concept matching

# Imports

ast, astalgo, semdata, lookups, lineinfos, idents, msgs, renderer, types, magicsys

# Procs

    proc conceptMatch(c: PContext; concpt, arg: PType; bindings: var TIdTable;
                      invocation: PType): bool {....raises: [KeyError, Exception],
        tags: [ReadDirEffect, RootEffect].}

  Entry point from sigmatch. 'concpt' is the concept we try to match (here still a PType but we extract its AST via 'concpt.n.lastSon'). 'arg' is the type that might fullfill the concept's requirements. If so, we return true and fill the 'bindings' with pairs of (typeVar, instance) pairs. ('typeVar' is usually simply written as a generic 'T'.) 'invocation' can be nil for atomic concepts. For non-atomic concepts, it contains the 'C[S, T]' parent type that we look for. We need this because we need to store bindings for 'S' and 'T' inside 'bindings' on a successful match. It is very important that we do not add any bindings at all on an unsuccessful match! Source Edit

    proc isSelf(t: PType): bool {.inline, ...raises: [], tags: [].}

  Is this the magical 'Self' type? Source Edit

    proc makeTypeDesc(c: PContext; typ: PType): PType {....raises: [], tags: [].}

  Source Edit

    proc semConceptDeclaration(c: PContext; n: PNode): PNode {....raises: [Exception,
        ValueError, KeyError, OSError, IOError, ERecoverableError], tags: [
        RootEffect, ReadDirEffect, WriteIOEffect, ReadIOEffect, ReadEnvEffect].}

  Semantic checking for the concept declaration. Runs when we process the concept itself, not its matching process. Source Edit