Commit 73baed17 authored by Kunshan Wang's avatar Kunshan Wang

Removed the concept of "marked storage type".

parent 28d9f75c
......@@ -1988,13 +1988,6 @@ Memory Accessing
This family of instructions actually load from or store into the memory.
Note about *marked storage type* (currently only ``weakref``): When values of
such types are loaded from the memory to an SSA variable, the variable has its
*unmarked type*. Variables of unmarked types can be used to store to memory
locations of the *marked storage type*. Specifically, ``LOAD`` from
``iref<weakref<T>>`` gets a ``ref<T>``. ``ref<T>`` can be stored into a memory
location referenced by an ``iref<weakref<T>>`` internal reference.
The ``LOAD``, ``STORE``, ``CMPXCHG`` and ``ATOMICRMW`` instructions have
optional exceptional clauses. When the memory location argument *loc* is a NULL
reference, the instruction will *continue exceptionally*.
......@@ -2036,7 +2029,7 @@ loc
excClause
*exception clause*: Used to handle NULL reference errors.
return value
Type is the unmarked type of *T*: The value loaded from *loc*
Type is the strong variant of *T*: The value loaded from *loc*
+------+------+------+-----+------+-----------+
| opct | opct | opct | idt | idt | excClause |
......@@ -2083,7 +2076,7 @@ loc
excClause
*exception clause*: Used to handle NULL reference errors.
newVal
*variable* of the unmarked type of *T*: The new value to store.
Type is the strong variant of *T*: The new value to store.
+------+------+------+-----+------+--------+-----------+
| opct | opct | opct | idt | idt | idt | excClause |
......@@ -2131,15 +2124,16 @@ loc
*variable* of ``iref<T>`` or ``ptr<T>``: The memory location/address to
access.
expected
*variable* of the unmarked type of *T*: The expected value in the memory.
desired
*variable* of the unmarked type of *T*: The new value to store into the
*variable* of the strong variant of *T*: The expected value in the
memory.
desired
*variable* of the strong variant of *T*: The new value to store into
the memory.
excClause
*exception clause*: Used to handle NULL reference errors.
return value:
Type is ``struct<U int<1>>`` where *U* is the unmarked type of *T*: A pair
of the original value in the memory and whether this operation is
Type is ``struct<U int<1>>`` where *U* is the strong variant of *T*:
A pair of the original value in the memory and whether this operation is
successful.
+------+------+------+---------+---------+-----+------+----------+---------+-----------+
......@@ -2162,9 +2156,9 @@ loaded value equals the *expected* value. If it is weak, the comparison succeeds
**only if** the loaded value equals the *expected* value and it may spuriously
fail, that is, it may fail even if the loaded value equals the *expected* value.
The return value of this instruction is a struct of two fields: the unmarked
type of *T* and a 1-bit integer. The first field is the value loaded from the
memory. The second field is 1 if the comparison is successful, or 0 otherwise.
The return value of this instruction is a struct of two fields: The first field
is the value loaded from the memory. The second field is 1 if the comparison is
successful, or 0 otherwise.
The memory order of this instruction is *succOrd* if the comparison succeeds, or
*failOrd* otherwise.
......@@ -2225,12 +2219,12 @@ loc
*variable* of ``iref<T>`` or ``ptr<T>``: The memory location/address to
access.
opnd
*variable* of the unmarked type of *T*: The right-hand-side of the
*variable* of the strong variant of *T*: The right-hand-side of the
operation.
excClause
*exception clause*: Used to handle NULL reference errors.
return value
Type is the unmarked type of *T*: The original value in the memory.
Type is the strong variant of *T*: The original value in the memory.
+------+------+------+------+-----+------+------+-----------+
| opct | opct | opct | opct | idt | idt | idt | excClause |
......
......@@ -72,18 +72,9 @@ There are several kinds of types.
are **EQ-comparable types**.
* **Native-safe types** are defined in the `Native Interface
<native-interface>`__.
A **marked storage type** T1 of another type T2 represents the same set of
values as T2; in this case T2 is called the **unmarked type** of T1. When a
marked storage type is represented by a memory location, it exhibits special
properties. Specifically:
* ``weakref<T>`` is a marked storage type of ``ref<T>``.
A marked storage type cannot be the type of an SSA variable (defined in
`<instruction-set>`__). Loading from a memory location of a marked storage type
gets a value of its unmarked type. An unmarked type can be stored into a memory
location of its marked storage type.
* ``ref<T>`` is the **strong variant** of ``weakref<T>``; ``weakref<T>`` is the
**weak variant** of ``ref<T>``. All other types are the strong variant or weak
variant of themselves.
A **member** of a composite type T is either a field of T if T is a struct, or
an element of T if T is an array or a vector, or the fixed part or any element
......@@ -216,10 +207,12 @@ heap objects.
``iref`` is an internal reference type. An ``iref`` value is an internal
reference to a memory location.
``weakref`` is a weak object reference type. It is a marked storage type of
``ref``. A memory location of ``weakref`` holds a weak reference to a heap
object and can be clear to ``NULL`` by the garbage collector when there is no
strong references to the object the ``weakref`` value refers to.
``weakref`` is a weak object reference type. It is the weak variant of ``ref``.
A memory location of ``weakref`` holds a weak reference to a heap object and can
be clear to ``NULL`` by the garbage collector when there is no strong references
to the object the ``weakref`` value refers to.
NOTE: There is no weak internal reference.
The type parameter ``T`` is the referent type, which is the type of the heap
object or memory location its value refers to.
......@@ -227,7 +220,41 @@ object or memory location its value refers to.
All reference types can have ``NULL`` value which does not refer to any heap
object or memory location.
NOTE: There is no weak internal reference.
Weakref can only be the type of a memory location, not an SSA variable. When a
``weakref`` location is loaded from, the result is a ``ref`` to the same object;
when a ``ref`` is stored to a ``weakref`` location, the location holds a
``weakref`` to that object.
..
NOTE: Allowing SSA variables to hold weak references may cause many
problems. The semantic allows the GC to change it to ``NULL`` at any time
as long as the GC decides the referent object is no longer reachable. For
this reason, it is impossible to guarantee a weak reference is ``NULL``
before accessing. Consider the following program::
%entry:
%notnull = NE <@RefT> %weakref @NULLREF
// Just at this moment, GC changed %weakref to NULL
BRANCH2 %notnull %bb_cont %bb_abnormal
%bb_cont:
%val = LOAD <@T> %weakref // null reference access
...
GC may clear the weak reference right after the program decided it is not
``NULL``.
Requiring an explicit conversion from ``weakref<T>`` to ``ref<T>`` is not
very useful. In that case, the only operation allowed for ``weakref<T>`` is
to convert to ``ref<T>``.
So letting this conversion happen implicitly during memory access is a
natural choice, though not intuitive at all. In Mu's conceptual model, a
memory load is like an IO operation: it does not simply "get" the value
(such as an object reference) in the memory, but is a communication with the
memory system and queries the global state. So it is natural for a load
operation to return a different value each time executed.
..
......
......@@ -134,9 +134,9 @@ introduced via name-binding.
%succ = EXTRACTVALUE <@i64_cmpxchg_result 1> %result
Instructions of similar property include ``SHUFFLEVECTOR`` (result has a new
vector type), ``GETIREF`` (ref to iref), ``LOAD`` (marked storage type to
unmarked type), ``CMPXCHG`` (result is a struct), ``ATOMICRMW`` (marked
storage type to unmarked type).
vector type), ``GETIREF`` (ref to iref), ``LOAD`` (converting ``weakref<T>``
to ``ref<T>``), ``CMPXCHG`` (result is a struct), ``ATOMICRMW`` (same as
``LOAD``).
Names
~~~~~
......@@ -373,9 +373,8 @@ A **constant constructor** can be the following:
..
NOTE: ``weakref`` is a marked storage type of ``ref`` and, thus, cannot be
the type of an SSA variable, but all constants are SSA variables. (See
`<type-system>`__ and `<instruction-set>`__).
NOTE: ``weakref`` cannot be the type of an SSA variable, but all constants
are SSA variables. (See `<type-system>`__ and `<instruction-set>`__).
..
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment