Skip to content

DOC-56: An overview of grapht and dependence_grapht in corresponding README.md. #4095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2019

Conversation

marek-trtik
Copy link
Contributor

Besides an overview of dependence_graph I've also added a brief (and incomplete) overview of the grapht class, because it might be useful to understand how to use a dependence graph.

### Dependence graph

Implemented in `src/analyses/dependence_graph.h(cpp)`. It is a graph and an
abstract interpreter in the same time. The abstract interpretation nature

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the same time

nature of abstract interpretation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sentence says "nature of the dependence graph being (also) AI analyser" rather than "nature of abstract interpretation".


Implemented in `src/analyses/dependence_graph.h(cpp)`. It is a graph and an
abstract interpreter in the same time. The abstract interpretation nature
allows a dependence graph to build itself (the graph) from a given GOTO program.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean for a graph to build itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a graph in general it would perhaps mean nothing. However, here we speak about a special graph - the dependence graph in our code base. It is not just a graph representing control/data-dependencies is some GOTO program. It is also AI analyser. You do not build it by calling its graph-interface methods for adding nodes and edges. You instead pass it GOTO program and it will run its AI-interface methods on it to perform the data- and control- dependency analyses (i.e. it uses its "AI" nature of being also an AI analyser) and then it runs its finalize method to actually build the graph by calling graph-interface methods (to add control/data-dependency edges) from the results of the analyses.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the wording here ("build itself") is just a bit weird, below you very nicely explain what is going on and it may be worth having a forward reference to that.

A dependence graph extends the class `grapht` with `dep_nodet` as the type of
nodes (see `src/util/graph.h` for more details about
[graph representation](../util/README.md)).
The `dep_nodet` extends `graph_nodet<dep_edget>` by an iterator to a GOTO

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with an iterator?

nodes (see `src/util/graph.h` for more details about
[graph representation](../util/README.md)).
The `dep_nodet` extends `graph_nodet<dep_edget>` by an iterator to a GOTO
program instruction. It means that each graph node corresponds to a particular

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is "It" here?

Copy link
Contributor Author

@marek-trtik marek-trtik Feb 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The information of the previous sentence - the fact that each node stores an iterator to a GOTO instruction.

program instruction. It means that each graph node corresponds to a particular
program instruction. A labelled edge `(u, v)` of a dependence graph expresses
a dependency of the program instruction corresponding to node `u` on the program
instruction corresponding to node `v`. The label of the edge (i.e. data of the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing style guide recommends no latin (i.e.)

Implemented in `src/util/graph.h` as `grapht` class. The class natively defines
only a directional graph. However, an undirected graph can be emulated by
inserting for each edge (u, v) also (v, u). A multi-graph is not supported
though, because parallel edges are not allowed between vertices.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this can be simplified to "The grapht class represents a directed graph"; I don't think there's normally an expectation that any graph representation can also represent a multi graph directly, and a multi graph can be embedded in a directed graph in a similar way to how undirected graphs can be represented, so I don't necessarily think it's worth calling this out as a deficiency.


#### Data representation

A graph is defined by a template class `grapht<N>`, where the type `N` defines

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where N is the type of the nodes of the graph?

- It must be default constructible; the common way how to insert a node to the
graph is to call method `add_node` which pushes a new default-constructed
instance of `N` to the end of the vector and returns its index.
- It must define a type `edget`, representing type of data attached to any edge

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we do it this way; I can't see any obvious reason why the edge type necessarily follows from the node type. It seems the type parameter here doesn't specify the node type, but actually both the node type and the edge type? Maybe it would be worth refactoring the graph to work like this grapht<graph_configt> { using node_t = typename graph_configt::node_t; using edge_t = graph_configt::edge_t; // ... }? Just a thought

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed we just define edges and node types at the same time. But of course this can be improved upon, and improvements are always welcome :-)

of that node, then `(v, u)` (resp. `(u, v)`) represent an edge in the graph,
with attached data `in[v]` (resp. `out[v]`).
- It must define methods `add_in`, `erase_in`, and `add_out`, `erase_out` for
insertion and removal of values to and from the maps `in` and `out`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why we bother having this stuff on the node type at all if all nodes are required to implement them in the same way anyway

insertion and removal of values to and from the maps `in` and `out`.
- It must define a method `pretty` converting the node to a "pretty" string.

One can use a predefined template class `graph_nodet<E>` as the template

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is E here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@marek-trtik
Copy link
Contributor Author

Requested updates are available.


Implemented in `src/analyses/dependence_graph.h(cpp)`. It is a graph and an
abstract interpreter in the same time. The abstract interpretation nature
allows a dependence graph to build itself (the graph) from a given GOTO program.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the wording here ("build itself") is just a bit weird, below you very nicely explain what is going on and it may be worth having a forward reference to that.

@marek-trtik
Copy link
Contributor Author

Updates requested in the review are available: Added forward link from "build itself" to the Construction sub-section.

@tautschnig
Copy link
Collaborator

@marek-trtik This requires a rebase to pick up the Windows CI fix. And doxygen says: README.md:105: warning: unexpected token TK_EOF as the argument of ref.

@marek-trtik
Copy link
Contributor Author

Thanks Michael! Issue fixed, commits squashed, and rebased to latest develop.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️
Passed Diffblue compatibility checks (cbmc commit: a17a64a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100445165

@tautschnig tautschnig merged commit 107d5a8 into diffblue:develop Mar 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants