Changeset d1864da for doc/theses/fangren_yu_COOP_S20
- Timestamp:
- Sep 13, 2020, 10:42:01 PM (4 years ago)
- 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
- 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 119 119 structures. 120 120 121 \paragraph{Declaration nodes} ~ 122 123 \noindent 121 \subsubsection{Declaration nodes} 122 124 123 A declaration node represents either of: 125 124 \begin{itemize} … … 168 167 parameters and assertions is the following declaration. 169 168 170 \paragraph{Type nodes} ~ 171 172 \noindent 169 \subsubsection{Type nodes} 170 173 171 A type node represents the type of an object or expression. 174 172 Named types reference the corresponding type declarations. The type of a function is its … … 177 175 (actual parameter types). 178 176 179 \paragraph{Statement nodes} ~ 180 181 \noindent 177 \subsubsection{Statement nodes} 178 182 179 Statement nodes represent the statements in the program, including basic expression 183 180 statements, control flows and blocks. 184 181 Local declarations (within a block statement) are represented as declaration statements. 185 182 186 \paragraph{Expression nodes} ~ 187 188 \noindent 183 \subsubsection{Expression nodes} 184 189 185 Some expressions are represented differently in the compiler before and after resolution 190 186 stage: … … 283 279 discussed near the end of this section. 284 280 285 \paragraph{Source: AST/Node.hpp} ~ 286 287 \noindent 281 \subsubsection{Source: AST/Node.hpp} 282 288 283 class @ast::Node@ is the base class of all new-ast node classes, which implements 289 284 reference counting mechanism. Two different counters are recorded: ``strong'' reference … … 305 300 pointers. 306 301 302 \begin{C++} 303 void ast::Node::increment(ref_type ref) 304 \end{C++} 305 Increments this node's strong or weak reference count. 306 \begin{C++} 307 void ast::Node::decrement(ref_type ref, bool do_delete = true) 308 \end{C++} 309 Decrements this node's strong or weak reference count. If strong reference count reaches 310 zero, the node is deleted by default. 311 \textbf{NOTE}: Setting @do_delete@ to false may result in a detached node. Subsequent code should 312 manually delete the node or assign it to a strong pointer to prevent memory leak. 313 Reference counting functions are internally called by @ast::ptr_base@. 314 \begin{C++} 315 template<typename node_t> 316 node_t * shallowCopy(const node_t * node) 317 \end{C++} 318 Returns a mutable, shallow copy of node: all child pointers are pointing to the same child 319 nodes. 320 \begin{C++} 321 template<typename node_t> 322 node_t * mutate(const node_t * node) 323 \end{C++} 324 If node is unique (strong reference count is 1), returns a mutable pointer to the same node. 325 Otherwise, returns shallowCopy(node). 326 It is an error to mutate a shared node that is weak-referenced. Currently this does not 327 happen. The problem may appear once weak pointers to shared nodes (e.g. expression 328 nodes) 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 331 issue is presented at the end of this section. 332 \begin{C++} 333 template<typename node_t, typename parent_t, typename field_t, typename assn_t> 334 const node_t * mutate_field(const node_t * node, field_t parent_t::*field, assn_t && val) 335 \end{C++} 336 \begin{C++} 337 template<typename node_t, typename parent_t, typename coll_t, typename ind_t, 338 typename field_t> 339 const node_t * mutate_field_index(const node_t * node, coll_t parent_t::* field, ind_t i, 340 field_t && val) 341 \end{C++} 342 Helpers for mutating a field on a node using pointer to member (creates shallow copy 343 when necessary). 344 345 \subsubsection{Issue: Undetected sharing} 346 347 The @mutate@ behavior described above has a problem: deeper shared nodes may be 348 mistakenly 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} 355 Suppose that we are working on the tree rooted at P1, which 356 is logically the chain P1-A-B and P2 is irrelevant, and then 357 mutate(B) is called. The algorithm considers B as unique since 358 it is only directly owned by A. However, the other tree P2-A-B 359 indirectly shares the node B and is therefore wrongly mutated. 360 361 To partly address this problem, if the mutation is called higher up the tree, a chain 362 mutation helper can be used: 363 364 \subsubsection{Source: AST/Chain.hpp} 365 366 \begin{C++} 367 template<typename node_t, Node::ref_type ref_t> 368 auto chain_mutate(ptr_base<node_t, ref_t> & base) 369 \end{C++} 370 This function returns a chain mutator handle which takes pointer-to-member to go down 371 the tree while creating shallow copies as necessary; see @struct _chain_mutator@ in the 372 source code for details. 373 307 374 \bibliographystyle{plain} 308 375 \bibliography{pl}
Note: See TracChangeset
for help on using the changeset viewer.