Skip to content

Commit 127b1ac

Browse files
committed
update handbook and reference with signature namespaces
1 parent fef03a0 commit 127b1ac

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ In summary, the kinds of expressions are:
2929
- These refer to predicates.
3030
- They can be simple :ref:`names <names>` or names with arities (for example in an :ref:`alias <aliases>`
3131
definition), or :ref:`selections <selections>`.
32+
- **signature expressions**
33+
- These refer to module signatures, type signatures, or predicate signatures.
34+
- They can be simple :ref:`names <names>`, names with arities, :ref:`selections <selections>`,
35+
or :ref:`instantiations <parameterized-modules>`.
3236

3337
.. _names:
3438

@@ -164,14 +168,27 @@ As in many other programming languages, a namespace is a mapping from **keys** t
164168
**entities**. A key is a kind of identifier, for example a name, and a QL entity is
165169
a :ref:`module <modules>`, a :ref:`type <types>`, or a :ref:`predicate <predicates>`.
166170

167-
Each module in QL has three namespaces:
171+
Each module in QL has six namespaces:
168172

169173
- The **module namespace**, where the keys are module names and the entities are modules.
170174
- The **type namespace**, where the keys are type names and the entities are types.
171175
- The **predicate namespace**, where the keys are pairs of predicate names and arities,
172176
and the entities are predicates.
177+
- The **module signature namespace**, where the keys are module signature names and the entities are module signatures.
178+
- The **type signature namespace**, where the keys are type signature names and the entities are type signatures.
179+
- The **predicate signature namespace**, where the keys are pairs of predicate signature names and arities,
180+
and the entities are predicate signatures.
173181

174-
It's important to know that there is no relation between names in different namespaces.
182+
The six namespaces of any module are not completely independent of each other:
183+
184+
- No keys may be shared between **module namespace** and **module signature namespace**.
185+
- No keys may be shared between **type namespace** and **type signature namespace**.
186+
- No keys may be shared between **module namespace** and **type signature namespace**.
187+
- No keys may be shared between **type namespace** and **module signature namespace**.
188+
- No keys may be shared between **predicate namespace** and **predicate signature namespace**.
189+
- No keys may be shared between **module signature namespace** and **type signature namespace**.
190+
191+
There is no relation between names in namespaces of different modules.
175192
For example, two different modules can define a predicate ``getLocation()`` without confusion. As long as
176193
it's clear which namespace you are in, the QL compiler resolves the name to the correct predicate.
177194

@@ -187,6 +204,7 @@ In particular:
187204
``string``, ``boolean``, and ``date``, as well as any :ref:`database types <database-types>` defined in the database schema.
188205
- The **global predicate namespace** includes all the `built-in predicates <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#built-ins>`_,
189206
as well as any :ref:`database predicates <database-predicates>`.
207+
- The **global signature namespaces** are empty.
190208

191209
In practice, this means that you can use the built-in types and predicates directly in a QL module (without
192210
importing any libraries). You can also use any database predicates and types directly—these depend on the

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,25 @@ use information from the database.
8686
Name resolution
8787
---------------
8888

89-
All modules have three environments that dictate name resolution. These are multimaps of keys to declarations.
89+
All modules have six environments that dictate name resolution. These are multimaps of keys to declarations.
9090

9191
The environments are:
9292

9393
- The *module environment*, whose keys are module names and whose values are modules.
9494
- The *type environment*, whose keys are type names and whose values are types.
9595
- The *predicate environment*, whose keys are pairs of predicate names and arities and whose values are predicates.
96+
- The *module signature environment*, whose keys are module signature names and whose values are module signatures.
97+
- The *type signature environment*, whose keys are type signature names and whose values are type signatures.
98+
- The *predicate signature environment*, whose keys are pairs of predicate signature names and arities and whose values are predicate signatures.
99+
100+
For each module, some namespaces are enforced to be disjoint:
101+
102+
- No keys may be shared between **module namespace** and **module signature namespace**.
103+
- No keys may be shared between **type namespace** and **type signature namespace**.
104+
- No keys may be shared between **module namespace** and **type signature namespace**.
105+
- No keys may be shared between **type namespace** and **module signature namespace**.
106+
- No keys may be shared between **predicate namespace** and **predicate signature namespace**.
107+
- No keys may be shared between **module signature namespace** and **type signature namespace**.
96108

97109
If not otherwise specified, then the environment for a piece of syntax is the same as the environment of its enclosing syntax.
98110

@@ -114,6 +126,8 @@ The global type environment has entries for the primitive types ``int``, ``float
114126

115127
The global predicate environment includes all the built-in classless predicates, as well as any extensional predicates declared in the database schema.
116128

129+
The three global signature environments are empty.
130+
117131
The program is invalid if any of these environments is not definite.
118132

119133
Module environments

0 commit comments

Comments
 (0)