Skip to content

Lazy loading: load static initializers for needed classes. Fixes #846 #855

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
Apr 27, 2017

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Apr 21, 2017

This adds a wrapper for the needed-methods and needed-classes objects used to accumulate dependencies during lazy loading, such that the first time a class is noted needed, its static initializer if any is also queued for elaboration.

The test case is borrowed from @reuk.

@tautschnig
Copy link
Collaborator

@smowton could you please take a look at the overly long lines reported?

\*******************************************************************/

#include "ci_lazy_methods.h"
#include <string>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit picking: STL headers first, blank line, local include

#include "ci_lazy_methods.h"
#include <string>

void ci_lazy_methodst::add_needed_method(const irep_idt &method_symbol_name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Function comment headers missing


class ci_lazy_methodst
{
public:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Single-character indent - no indent needed for public/private/protected


private:
std::vector<irep_idt> &needed_methods;
std::set<irep_idt> &needed_classes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is one of those a vector while the other is a set?

@smowton smowton force-pushed the fix/lazy_methods_and_clinit branch 3 times, most recently from 94832db to 5bbec11 Compare April 21, 2017 11:56
@smowton
Copy link
Contributor Author

smowton commented Apr 21, 2017

Amended and added comments to address your question about vector vs. set.

Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

See one more comment for a suggested improvement, but otherwise looks good to me.

// needed_classes on the other hand is a true set of every class
// found so far, so we can use a membership test to avoid
// repeatedly exploring a class hierarchy.
std::set<irep_idt> &needed_classes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the clarification; I'd suggest to use std::unordered_set<irep_idt, irep_id_hash> &needed_classes as a minor improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd want to make change a few others too, so I'll do that in a subsequent PR

{
if(!needed_classes.insert(class_symbol_name).second)
return false;
const irep_idt &clinit_name=id2string(class_symbol_name)+".<clinit>:()V";
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for taking a const ref to a temporary here vs. the following?

const irep_idt clinit_name(id2string(class_symbol_name)+".<clinit>:()V");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, fixed

…blue#846

This adds a wrapper for the needed-methods and needed-classes objects used
to accumulate dependencies during lazy loading, such that the first time a
class is noted needed, its static initializer if any is also queued for
elaboration.

The test case is borrowed from @reuk.
@smowton smowton force-pushed the fix/lazy_methods_and_clinit branch from 5bbec11 to 286fcc5 Compare April 21, 2017 13:02
@kroening kroening merged commit 10015b1 into diffblue:master Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants