-
Notifications
You must be signed in to change notification settings - Fork 273
Add recording symbol table #1446
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
Add recording symbol table #1446
Conversation
@NathanJPhillips suggest giving this the once-over |
Can people please please PLEASE start writing commit messages with actual contents? Thank you. Just to add clarification: I'm sure the work done and presented in this PR is very useful and solid, but as-is this is a change impacting a lot of code without a way of understanding why it may be useful or the right thing to do. |
symbol_tablet keep_symbols; | ||
std::unordered_set<irep_idt, irep_id_hash> unreachable_symbols; | ||
for(const auto &sym : symbol_table.symbols) | ||
unreachable_symbols.insert(sym.first); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this is done, but this change appears to be inverting the logic of book-keeping. Surely that's fine, but which of the commits/commit messages does it fit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will factor out and describe
62ce860
to
abac902
Compare
@tautschnig updated this adding explanatory commit messages and moving the book-keeping inversion into its own commit. |
Companion test-gen PR: https://github.com/diffblue/test-gen/pull/1088 |
abac902
to
57b0b63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
602fe34
to
87f36cb
Compare
Added @reuk to review since this now uses his recent symtab changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor comments
src/util/symbol_table.h
Outdated
{ | ||
if(symbolt *sym=get_writeable(id)) | ||
return *sym; | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No else
after return
please
src/util/symbol_table.h
Outdated
{ | ||
if(const symbolt *sym=lookup(id)) | ||
return *sym; | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No else
after return
please
src/util/symbol_table.h
Outdated
|
||
symbolt &get_writeable_ref(const irep_idt &id) | ||
{ | ||
if(symbolt *sym=get_writeable(id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementations of lookup_ref
and get_writeable_ref
should share an implementation, probably using the private static template idiom.
87f36cb
to
eb5b253
Compare
Updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough.
eb5b253
to
769b052
Compare
Many thanks for providing guiding commit messages. Wouldn't it have been possible to avoid the mass-renaming? After all, a |
@tautschnig only the sites that instantiate one have been renamed to |
The only change that doesn't fit that pattern is |
Thanks a lot for the further clarification. Now my final question remains: having understood each individual commit, I am wondering what the overall use case/rationale is? That is, what are the grounds on which a user (developer) would choose one over the other? |
Desired action: after the frontend converts a function, perform post-processing for every symbol it has touched. Usually that will just be the single function in question, but sometimes it can create support functions on demand, such as singleton wrappers for Java static initialisers, or built-in String functions. We thought that rather than make a second pass over the function being converted, or relying on the frontend making a callback for every function it touches, we should make a journalling implementation of the symbol table, such that there's no danger of reported and actual actions becoming unsynchronised. Example usage:
|
769b052
to
526386d
Compare
Would it be possible to add this explanation as doxygen comments? No user/developer should have to guess intentions. |
This is useful because in a forthcoming commit symbol_tablet will become an interface, and therefore lose its `swap` method. In the case where the particular implementation journals its operations this will also provide a more accurate impression of what has taken place (many symbols were erased, cf. this table was swapped with another which experienced many insertions)
75352a3
to
b4f6e18
Compare
@tautschnig done (see last commit) |
I don't know what the timeline/pressure for this work is, but I'd love to see as part of this work: 1) review of all the code location that now got a |
(1) will do tomorrow morning. |
This converts symbol_tablet into an interface and moves its current implementation into concrete_symbol_tablet, permitting the forthcoming interface-compatible alternative journalling implementation.
This is an implementation of symbol_tablet that wraps another symbol_tablet and journals additions, erasures and alterations such that a user can find out what changes have taken place since the recording_symbol_tablet was created.
No functional changes
b4f6e18
to
2c09954
Compare
@tautschnig reviewed them just now. Breakdown:
The link/rename operation could be done incrementally, but I don't think there's anything terribly wrong with the current approach.
Most of the time when this is sometimes sensible there are already overloads of the relevant functions that don't take a namespacet and create a blank one internally -- for example Of the 20 or so uses of this form, the only functions that could maybe gain an overload are
Conclusion: if you like, we could remove a few instances by factoring the blank namespace pattern into |
I fully agree with this being dodgy, all of this (the 25% that you estimated) should simply be removed. |
I disagree-- the fudamental act The alternative to |
(alternatively perhaps I'm missing your intent? Taking |
Here's how I'd patch it (in a slow-migration-path manner): diff --git a/src/analyses/is_threaded.cpp b/src/analyses/is_threaded.cpp
index 1ac32d234..ce0769a63 100644
--- a/src/analyses/is_threaded.cpp
+++ b/src/analyses/is_threaded.cpp
@@ -82,12 +82,10 @@ public:
}
};
-void is_threadedt::compute(const goto_functionst &goto_functions)
+void is_threadedt::compute(
+ const goto_functionst &goto_functions,
+ const namespacet &ns)
{
- // the analysis doesn't actually use the namespace, fake one
- symbol_tablet symbol_table;
- const namespacet ns(symbol_table);
-
ait<is_threaded_domaint> is_threaded_analysis;
is_threaded_analysis(goto_functions, ns);
diff --git a/src/analyses/is_threaded.h b/src/analyses/is_threaded.h
index c5cf48a55..26968551d 100644
--- a/src/analyses/is_threaded.h
+++ b/src/analyses/is_threaded.h
@@ -21,16 +21,24 @@ Date: October 2012
class is_threadedt
{
public:
+ // __attribute__((deprecated))
explicit is_threadedt(
const goto_functionst &goto_functions)
{
- compute(goto_functions);
+ // the analysis doesn't actually use the namespace, fake one
+ symbol_tablet symbol_table;
+ const namespacet ns(symbol_table);
+
+ compute(goto_functions, ns);
}
explicit is_threadedt(
const goto_modelt &goto_model)
{
- compute(goto_model.goto_functions);
+ const goto_functionst &goto_functions=goto_model.goto_functions;
+ const namespacet ns(goto_model.symbol_table);
+
+ compute(goto_functions, ns);
}
bool operator()(const goto_programt::const_targett t) const
@@ -47,8 +55,10 @@ protected:
typedef std::set<goto_programt::const_targett> is_threaded_sett;
is_threaded_sett is_threaded_set;
+ // should use goto_modelt once the public API above is cleaned up
void compute(
- const goto_functionst &goto_functions);
+ const goto_functionst &goto_functions,
+ const namespacet &ns);
};
#endif // CPROVER_ANALYSES_IS_THREADED_H |
Don't you think adding a spurious dependency like that is troubling? (If the comment is correct) then the code doesn't need a namespace, yet we're writing code that strongly suggests it does. Shouldn't we pass it exactly what it actually needs? |
(As an alternative, how about a static global |
Replaced by #1496 |
This upstreams PR https://github.com/diffblue/security-scanner/pull/213, which gives more detail; already reviewed by @thk123 and @reuk over there.