Ignore:
Timestamp:
Sep 13, 2020, 10:42:01 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
a75d464
Parents:
ae45007
Message:

continue latex version of Fangren's co-op report

Location:
doc/theses/fangren_yu_COOP_S20
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/fangren_yu_COOP_S20/Report.tex

    rae45007 rd1864da  
    119119structures.
    120120
    121 \paragraph{Declaration nodes} ~
    122 
    123 \noindent
     121\subsubsection{Declaration nodes}
     122
    124123A declaration node represents either of:
    125124\begin{itemize}
     
    168167parameters and assertions is the following declaration.
    169168
    170 \paragraph{Type nodes} ~
    171 
    172 \noindent
     169\subsubsection{Type nodes}
     170
    173171A type node represents the type of an object or expression.
    174172Named types reference the corresponding type declarations. The type of a function is its
     
    177175(actual parameter types).
    178176
    179 \paragraph{Statement nodes} ~
    180 
    181 \noindent
     177\subsubsection{Statement nodes}
     178
    182179Statement nodes represent the statements in the program, including basic expression
    183180statements, control flows and blocks.
    184181Local declarations (within a block statement) are represented as declaration statements.
    185182
    186 \paragraph{Expression nodes} ~
    187 
    188 \noindent
     183\subsubsection{Expression nodes}
     184
    189185Some expressions are represented differently in the compiler before and after resolution
    190186stage:
     
    283279discussed near the end of this section.
    284280
    285 \paragraph{Source: AST/Node.hpp} ~
    286 
    287 \noindent
     281\subsubsection{Source: AST/Node.hpp}
     282
    288283class @ast::Node@ is the base class of all new-ast node classes, which implements
    289284reference counting mechanism. Two different counters are recorded: ``strong'' reference
     
    305300pointers.
    306301
     302\begin{C++}
     303void ast::Node::increment(ref_type ref)
     304\end{C++}
     305Increments this node's strong or weak reference count.
     306\begin{C++}
     307void ast::Node::decrement(ref_type ref, bool do_delete = true)
     308\end{C++}
     309Decrements this node's strong or weak reference count. If strong reference count reaches
     310zero, the node is deleted by default.
     311\textbf{NOTE}: Setting @do_delete@ to false may result in a detached node. Subsequent code should
     312manually delete the node or assign it to a strong pointer to prevent memory leak.
     313Reference counting functions are internally called by @ast::ptr_base@.
     314\begin{C++}
     315template<typename node_t>
     316node_t * shallowCopy(const node_t * node)
     317\end{C++}
     318Returns a mutable, shallow copy of node: all child pointers are pointing to the same child
     319nodes.
     320\begin{C++}
     321template<typename node_t>
     322node_t * mutate(const node_t * node)
     323\end{C++}
     324If node is unique (strong reference count is 1), returns a mutable pointer to the same node.
     325Otherwise, returns shallowCopy(node).
     326It is an error to mutate a shared node that is weak-referenced. Currently this does not
     327happen. The problem may appear once weak pointers to shared nodes (e.g. expression
     328nodes) are used; special care will be needed.
     329
     330\textbf{NOTE}: This naive uniqueness check may not be sufficient in some cases. A discussion of the
     331issue is presented at the end of this section.
     332\begin{C++}
     333template<typename node_t, typename parent_t, typename field_t, typename assn_t>
     334const node_t * mutate_field(const node_t * node, field_t parent_t::*field, assn_t && val)
     335\end{C++}
     336\begin{C++}
     337template<typename node_t, typename parent_t, typename coll_t, typename ind_t,
     338                typename field_t>
     339const node_t * mutate_field_index(const node_t * node, coll_t parent_t::* field, ind_t i,
     340                field_t && val)
     341\end{C++}
     342Helpers for mutating a field on a node using pointer to member (creates shallow copy
     343when necessary).
     344
     345\subsubsection{Issue: Undetected sharing}
     346
     347The @mutate@ behavior described above has a problem: deeper shared nodes may be
     348mistakenly considered as unique. \VRef[Figure]{f:DeepNodeSharing} shows how the problem could arise:
     349\begin{figure}
     350\centering
     351\input{DeepNodeSharing}
     352\caption{Deep sharing of nodes}
     353\label{f:DeepNodeSharing}
     354\end{figure}
     355Suppose that we are working on the tree rooted at P1, which
     356is logically the chain P1-A-B and P2 is irrelevant, and then
     357mutate(B) is called. The algorithm considers B as unique since
     358it is only directly owned by A. However, the other tree P2-A-B
     359indirectly shares the node B and is therefore wrongly mutated.
     360
     361To partly address this problem, if the mutation is called higher up the tree, a chain
     362mutation helper can be used:
     363
     364\subsubsection{Source: AST/Chain.hpp}
     365
     366\begin{C++}
     367template<typename node_t, Node::ref_type ref_t>
     368auto chain_mutate(ptr_base<node_t, ref_t> & base)
     369\end{C++}
     370This function returns a chain mutator handle which takes pointer-to-member to go down
     371the tree while creating shallow copies as necessary; see @struct _chain_mutator@ in the
     372source code for details.
     373
    307374\bibliographystyle{plain}
    308375\bibliography{pl}
Note: See TracChangeset for help on using the changeset viewer.