Skip to content

Commit 78a2dfa

Browse files
authored
Merge pull request github#11939 from github/ginsbach/DocumentNewNamespaces
document new namespaces
2 parents fea97a2 + 8a39720 commit 78a2dfa

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

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

Lines changed: 21 additions & 3 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 the **module namespace** and the **module signature namespace**.
185+
- No keys may be shared between the **type namespace** and the **type signature namespace**.
186+
- No keys may be shared between the **module namespace** and the **type signature namespace**.
187+
- No keys may be shared between the **type namespace** and the **module signature namespace**.
188+
- No keys may be shared between the **predicate namespace** and the **predicate signature namespace**.
189+
- No keys may be shared between the **module signature namespace** and the **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

@@ -182,11 +199,12 @@ The namespaces containing all the built-in entities are called **global namespac
182199
and are automatically available in any module.
183200
In particular:
184201

185-
- The **global module namespace** is empty.
202+
- The **global module namespace** has a single entry ``QlBuiltins``.
186203
- The **global type namespace** has entries for the :ref:`primitive types <primitive-types>` ``int``, ``float``,
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: 16 additions & 2 deletions
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 the **module namespace** and the **module signature namespace**.
103+
- No keys may be shared between the **type namespace** and the **type signature namespace**.
104+
- No keys may be shared between the **module namespace** and the **type signature namespace**.
105+
- No keys may be shared between the **type namespace** and the **module signature namespace**.
106+
- No keys may be shared between the **predicate namespace** and the **predicate signature namespace**.
107+
- No keys may be shared between the **module signature namespace** and the **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

@@ -108,12 +120,14 @@ A *definite* environment has at most one entry for each key. Resolution is uniqu
108120
Global environments
109121
~~~~~~~~~~~~~~~~~~~
110122

111-
The global module environment is empty.
123+
The global module environment has a single entry ``QlBuiltins``.
112124

113125
The global type environment has entries for the primitive types ``int``, ``float``, ``string``, ``boolean``, and ``date``, as well as any types defined in the database schema.
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)