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
@@ -249,6 +262,73 @@ For qualified identifiers (``a.b``):
249
262
250
263
A qualified module identifier is only valid within an import.
251
264
265
+
Module expressions contain a module identifier and optional arguments. If arguments are present, the module expression instantiates the module that the identifier resolves to (see :ref:`Parameterized modules`).
266
+
267
+
Module expressions cannot refer to :ref:`Parameterized modules`. Instead, parameterized modules must always be fully instantiated when they are referenced.
268
+
269
+
.. _Parameterized modules:
270
+
271
+
Parameterized modules
272
+
~~~~~~~~~~~~~~~~~~~~~
273
+
274
+
Modules with parameters are called *parameterized modules*. A *declared module* has parameters if and only if it is a *library module* and its declaration uses the ``parameters`` syntax.
275
+
276
+
*Parameterized modules* can be instantiated with arguments that match the signatures of the parameters:
277
+
278
+
- Given a type signature, the corresponding argument must be a type that transitively extends the specified ``extends`` types and is a transitive subtype of the specified ``instanceof`` types.
279
+
- Given a predicate signature, the corresponding argument must be a predicate with exactly matching relational types.
280
+
- Given a module signature, the corresponding argument must be a module that exports all the specified type and predicate members. Furthermore, the module must be declared as matching the module signature via the ``implements`` syntax.
281
+
282
+
The result of instantiating a *parameterized module* is an *instantiated module*. The parameterized module is called the *underlying module* of the *instantiated module*.
283
+
284
+
Instantiation-relative and instantiation-nested entities
Given an *instantiated module*, every entity has a corresponding entity called the *instantiation-relative* entity, which is determined as follows:
288
+
289
+
- If the entity is the *underlying module*, its *instantiation-relative* entity is the *instantiated module*.
290
+
- If the entity is a parameter of the *underlying module*, its *instantiation-relative* entity is the corresponding argument.
291
+
- If the entity is declared inside the *underlying module* or its nested modules, its *instantiation-relative* entity is an *instantiation-nested* entity that is generated by the module instantiation. Parameters of any modules that are nested inside the *underlying module* are considered declared inside the module for this purpose.
292
+
- Otherwise, the entity's *instantiation-relative* entity is the initial entity itself.
293
+
294
+
When the *instantiation-relative* entity of an entity is an *instantiation-nested* entity, then the initial entity is called the *underlying nested* entity of the *instantiation-nested* entity*, the *instantiated module* is called the *instantiation root* of the *instantiation-nested* entity, and the *underlying module* is called the *underlying root* of the *instantiation-nested* entity.
295
+
296
+
The components of an *instantiation-nested* entity are the *instantiation-relative* entities of the components of its *underlying nested* entity. Among other things, this applies to:
297
+
298
+
- values in the exported environments of *instantiation-nested* modules,
299
+
- relational types of *instantiation-nested* predicates and predicate signatures,
300
+
- required signatures of *instantiation-nested* parameters,
301
+
- parameters of an *instantiation-nested* *parameterized module*,
302
+
- fields and member predicates of *instantiation-nested* dataclasses.
303
+
304
+
Given an *instantiated module*, any alias in the program has a corresponding alias called the *instantiation-relative* alias, which targets the *instantiation-relative* entity.
305
+
306
+
Applicative instantiation
307
+
~~~~~~~~~~~~~~~~~~~~~~~~~
308
+
309
+
Every entity has an *underlying completely uninstantiated* entity that is determined as follows:
310
+
311
+
- If the entity is an *instantiated module*, its *underlying completely uninstantiated* entity is the *underlying completely uninstantiated* entity of the *underlying module*.
312
+
- If the entity is an *instantiation-nested* entity, its *underlying completely uninstantiated* entity is the *underlying completely uninstantiated* entity of the *underlying nested* entity.
313
+
- Otherwise, its *underlying completely uninstantiated* entity is the entity itself.
314
+
315
+
An entity is called *completely uninstantiated* entity if it is its own *underlying completely uninstantiated* entity.
316
+
317
+
Every *completely uninstantiated* entity has a *relevant set of parameters*, which is the set of all parameters of all the modules that the entity is transitively nested inside. For entities that are not nested inside any modules, the *relevant set of parameters* is empty.
318
+
319
+
Note that the *relevant set of parameters* by construction contains only *completely uninstantiated* parameters.
320
+
321
+
For a *completely uninstantiated* parameter, the *bottom-up instantiation-resolution* relative to an entity is defined as:
322
+
323
+
- If the entity is an *instantiated module* or an *instantiation-nested* entity, the *bottom-up instantiation-resolution* is the *instantiation-relative* entity of the *bottom-up instantiation-resolution* relative to the *underlying module*.
324
+
- Otherwise, the *bottom-up instantiation-resolution* is the parameter itself.
325
+
326
+
An entity is called *fully instantiated* if none of the *bottom-up instantiation-resolutions* of the parameters in the *relevant set of parameters* of the entity's *underlying completely uninstantiated* entity are parameters.
327
+
328
+
Two *instantiated modules* or two *instantiation-nested* entities are considered *equivalent* if they have the same *underlying completely uninstantiated* entity and each parameter in its *relevant set of parameters* has the same *bottom-up instantiation-resolution* relative to either *instantiated module*.
329
+
330
+
Module instantiation is applicative, meaning that *equivalent* *instantiated modules* and *equivalent* *instantiation-nested* entities are indistinguishable.
331
+
252
332
Module references and active modules
253
333
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254
334
@@ -268,7 +348,7 @@ QL is a typed language. This section specifies the kinds of types available, the
268
348
Kinds of types
269
349
~~~~~~~~~~~~~~
270
350
271
-
Types in QL are either *primitive* types, *database* types, *class* types, *character* types or *class domain* types.
351
+
Types in QL are either *primitive* types, *database* types, *class* types, *character* types, *class domain* types, type *parameters*, or *instantiation-nested* types.
272
352
273
353
The primitive types are ``boolean``, ``date``, ``float``, ``int``, and ``string``.
274
354
@@ -289,7 +369,9 @@ With the exception of class domain types and character types (which cannot be re
A type reference is resolved to a type as follows:
295
377
@@ -1960,7 +2042,7 @@ Stratification
1960
2042
1961
2043
A QL program can be *stratified* to a sequence of *layers*. A layer is a set of predicates and types.
1962
2044
1963
-
A valid stratification must include each predicate and type in the QL program. It must not include any other predicates or types.
2045
+
A valid stratification must include each predicate and type in the QL program that is *fully instantiated*. It must not include any other predicates or types.
1964
2046
1965
2047
A valid stratification must not include the same predicate in multiple layers.
0 commit comments