Skip to content

Commit a732199

Browse files
authored
Merge pull request github#15261 from github/ginsbach/WeakAliasesInLanguageReference
document weak aliases in the language reference
2 parents f111fba + d38d4aa commit a732199

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,20 @@ You could give the predicate a more descriptive name as follows:
123123

124124
.. code-block:: ql
125125
126-
predicate lessThanTen = isSmall/1;
126+
predicate lessThanTen = isSmall/1;
127+
128+
.. _weak_strong_aliases:
129+
130+
Strong and weak aliases
131+
=======================
132+
133+
Every alias definition is either **strong** or **weak**.
134+
An alias definition is **strong** if and only if it is a :ref:`type alias <type-aliases>` definition with
135+
:ref:`annotation <annotations>` ``final``.
136+
During :ref:`name resolution <name-resolution>`, ambiguity between aliases from **weak** alias definitions
137+
for the same module/type/predicate is allowed, but ambiguity between between aliases from distinct **strong**
138+
alias definitions is invalid QL.
139+
Likewise, for the purpose of applicative instantiation of :ref:`parameterised modules <parameterized-modules>`
140+
and `:ref:`parameterised module signatures <parameterized-module-signatures>`, aliases from **weak** alias
141+
definitions for instantiation arguments do not result in separate instantiations, but aliases from **strong**
142+
alias definitions for instantiation arguments do.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ For example, in the previous two snippets, we relied on the predicate signature
180180
signature int transformer(int x);
181181
182182
The instantiation of parameterized modules is applicative.
183-
That is, if you instantiate a parameterized module twice with identical arguments, the resulting object is the same.
183+
That is, if you instantiate a parameterized module twice with equivalent arguments, the resulting object is the same.
184+
Arguments are considered equivalent in this context if they differ only by :ref:`weak aliasing <weak_strong_aliases>`.
184185
This is particularly relevant for type definitions inside parameterized modules as :ref:`classes <classes>`
185186
or via :ref:`newtype <algebraic-datatypes>`, because the duplication of such type definitions would result in
186187
incompatible types.

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Environments may be combined as follows:
115115
- *Union*. This takes the union of the entry sets of the two environments.
116116
- *Overriding union*. This takes the union of two environments, but if there are entries for a key in the first map, then no additional entries for that key are included from the second map.
117117

118-
A *definite* environment has at most one entry for each key. Resolution is unique in a definite environment.
118+
A *definite* environment has only values that are *equal modulo weak aliasing* for each key.
119119

120120
Global environments
121121
~~~~~~~~~~~~~~~~~~~
@@ -334,7 +334,7 @@ For a *completely uninstantiated* parameter, the *bottom-up instantiation-resolu
334334

335335
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.
336336

337-
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*.
337+
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 *bottom-up instantiation-resolution*s relative both *instantiated module*s that are *equivalent modulo weak aliases*.
338338

339339
Module instantiation is applicative, meaning that *equivalent* *instantiated modules* and *equivalent* *instantiation-nested* entities are indistinguishable.
340340

@@ -1763,7 +1763,7 @@ The grammar given in this section is disambiguated first by precedence, and seco
17631763
Aliases
17641764
-------
17651765

1766-
Aliases define new names for existing QL entities.
1766+
Aliases define new names for existing QL bindings.
17671767

17681768
::
17691769

@@ -1772,7 +1772,19 @@ Aliases define new names for existing QL entities.
17721772
| qldoc? annotations "module" modulename "=" moduleExpr ";"
17731773

17741774

1775-
An alias introduces a binding from the new name to the entity referred to by the right-hand side in the current module's declared predicate, type, or module environment respectively.
1775+
An alias introduces a binding from the new name to the binding referred to by the right-hand side in the current module's visible predicate, type, or module environment respectively.
1776+
1777+
An alias is called a *strong alias* if and only if it has the ``final`` annotation. Otherwise, it is called a *weak alias*.
1778+
1779+
Two bindings `A`, `B` are called *equal modulo weak aliasing* if and only if one of the following conditions are satisfied:
1780+
1781+
- `A` and `B` are the same binding or
1782+
1783+
- `A`` is introduced by a *weak alias* for `C`, where `B` and `C` are *equal modulo weak aliasing* (or vice versa) or
1784+
1785+
- `A` and `B` are introduced by the same strong alias and they are aliases for bindings that are *equal modulo weak aliasing*.
1786+
1787+
Note that the third condition is only relevant in :ref:`Parameterized modules`, where the binding introduced by the alias can depend on instantiation parameters.
17761788

17771789
Built-ins
17781790
---------

0 commit comments

Comments
 (0)