Skip to content

Commit a639f13

Browse files
authored
Merge pull request github#12085 from github/ginsbach/DocumentModuleSignatureMemberDefaults
document module signature member defaults
2 parents b8bd98e + e552a62 commit a639f13

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

docs/codeql/ql-language-reference/name-resolution.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ For a module ``M``, it is useful to distinguish between its **privately declared
223223
- The **publically declared** namespaces of ``M`` contain all entities and aliases that are declared—that is, defined—in ``M`` and that are not annotated as ``private``.
224224
- The **exported** namespaces of ``M`` contain
225225
1. all entries from the **publically declared** namespaces of ``M``, and
226-
2. for each module ``N`` that is imported into ``M`` with an import statement that is not annotated as ``private``: all entries from the **exported** namespaces of ``N`` that do not have the same name as any of the entries in the **publically declared** namespaces of ``M``.
226+
2. for each module ``N`` that is imported into ``M`` with an import statement that is not annotated as ``private``: all entries from the **exported** namespaces of ``N`` that do not have the same name as any of the entries in the **publically declared** namespaces of ``M``, and
227+
3. for each module signature ``S`` that is implemented by ``M``: an entry for each module signature default predicate in ``S`` that does not have the same name and arity as any of the entries in the **publically declared** predicate namespace of ``M``.
227228
- The **visible** namespaces of ``M`` contain
228229
1. all entries from the **exported** namespaces of ``M``, and
229230
2. all entries from the **global** namespaces, and

docs/codeql/ql-language-reference/ql-language-specification.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ These are defined as follows (with X denoting the type of entity we are currentl
144144

145145
1. its *publically declared X environment*, and
146146

147-
2. for each module which the current module directly imports (excluding ``private`` imports - see "`Import directives <#import-directives>`__"): all entries from the *exported X environment* that have a key not present in the *publically declared X environment* of the current module.
147+
2. for each module which the current module directly imports (excluding ``private`` imports - see "`Import directives <#import-directives>`__"): all entries from the *exported X environment* that have a key not present in the *publically declared X environment* of the current module, and
148+
149+
3. if X is ``predicates``, then for each module signature ``S`` that is implemented by the current module: an entry for each module signature default predicate in ``S`` that does not have the same name and arity as any of the entries in the **publically declared predicate environment** of the current module.
148150

149151
- The *visible X environment* of a module is the union of
150152

docs/codeql/ql-language-reference/signatures.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,24 @@ In detail, a type signature definition consists of:
8383
#. The name of the module signature. This is an `identifier <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#identifiers>`_
8484
starting with a uppercase letter.
8585
#. Optionally, a list of parameters for :ref:`parameterized module signatures <parameterized-module-signatures>`.
86-
#. The module signature body, consisting of type signatures and predicate signatures enclosed in braces.
86+
#. The module signature body, consisting of type signatures, predicate signatures, and default predicates enclosed in braces.
8787
The ``signature`` keyword is omitted for these contained signatures.
8888

89+
Module signature default predicates are syntactically constructed like predicate signatures,
90+
but preceded by the ``default`` keyword, and with a predicate body instead of the concluding
91+
semicolon ``;``.
92+
Default predicate bodies are restricted in that they may not use entities that in any way
93+
depend on other module signature members or parameters of the module signature or any
94+
existing enclosing modules.
95+
8996
For example:
9097

9198
.. code-block:: ql
9299
93100
signature module MSig {
94101
class T;
95102
predicate restriction(T t);
103+
default string descr(T t) { result = "default" }
96104
}
97105
98106
module Module implements MSig {

0 commit comments

Comments
 (0)