You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/ql-language-reference/name-resolution.rst
+21-3Lines changed: 21 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,10 @@ In summary, the kinds of expressions are:
29
29
- These refer to predicates.
30
30
- They can be simple :ref:`names <names>` or names with arities (for example in an :ref:`alias <aliases>`
31
31
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>`.
32
36
33
37
.. _names:
34
38
@@ -164,14 +168,27 @@ As in many other programming languages, a namespace is a mapping from **keys** t
164
168
**entities**. A key is a kind of identifier, for example a name, and a QL entity is
165
169
a :ref:`module <modules>`, a :ref:`type <types>`, or a :ref:`predicate <predicates>`.
166
170
167
-
Each module in QL has three namespaces:
171
+
Each module in QL has six namespaces:
168
172
169
173
- The **module namespace**, where the keys are module names and the entities are modules.
170
174
- The **type namespace**, where the keys are type names and the entities are types.
171
175
- The **predicate namespace**, where the keys are pairs of predicate names and arities,
172
176
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.
173
181
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.
175
192
For example, two different modules can define a predicate ``getLocation()`` without confusion. As long as
176
193
it's clear which namespace you are in, the QL compiler resolves the name to the correct predicate.
177
194
@@ -182,11 +199,12 @@ The namespaces containing all the built-in entities are called **global namespac
182
199
and are automatically available in any module.
183
200
In particular:
184
201
185
-
- The **global module namespace** is empty.
202
+
- The **global module namespace** has a single entry ``QlBuiltins``.
186
203
- The **global type namespace** has entries for the :ref:`primitive types <primitive-types>` ``int``, ``float``,
187
204
``string``, ``boolean``, and ``date``, as well as any :ref:`database types <database-types>` defined in the database schema.
188
205
- The **global predicate namespace** includes all the `built-in predicates <https://codeql.github.com/docs/ql-language-reference/ql-language-specification/#built-ins>`_,
189
206
as well as any :ref:`database predicates <database-predicates>`.
207
+
- The **global signature namespaces** are empty.
190
208
191
209
In practice, this means that you can use the built-in types and predicates directly in a QL module (without
192
210
importing any libraries). You can also use any database predicates and types directly—these depend on the
Copy file name to clipboardExpand all lines: docs/codeql/ql-language-reference/ql-language-specification.rst
+16-2Lines changed: 16 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,13 +86,25 @@ use information from the database.
86
86
Name resolution
87
87
---------------
88
88
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.
90
90
91
91
The environments are:
92
92
93
93
- The *module environment*, whose keys are module names and whose values are modules.
94
94
- The *type environment*, whose keys are type names and whose values are types.
95
95
- 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**.
96
108
97
109
If not otherwise specified, then the environment for a piece of syntax is the same as the environment of its enclosing syntax.
98
110
@@ -108,12 +120,14 @@ A *definite* environment has at most one entry for each key. Resolution is uniqu
108
120
Global environments
109
121
~~~~~~~~~~~~~~~~~~~
110
122
111
-
The global module environment is empty.
123
+
The global module environment has a single entry ``QlBuiltins``.
112
124
113
125
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.
114
126
115
127
The global predicate environment includes all the built-in classless predicates, as well as any extensional predicates declared in the database schema.
116
128
129
+
The three global signature environments are empty.
130
+
117
131
The program is invalid if any of these environments is not definite.
0 commit comments