Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Fix problem with action parameters with a template type of bool #931

Merged
merged 1 commit into from
Aug 10, 2020

Conversation

jeffreyssmith2nd
Copy link
Contributor

Change Description

Handle action parameters that have a template type that translates to _Bool during codegen.

Fixes #862.

API Changes

  • API Changes

Documentation Additions

  • Documentation Additions

Copy link
Contributor

@johndebord johndebord left a comment

Choose a reason for hiding this comment

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

LGTM.

@jeffreyssmith2nd jeffreyssmith2nd merged commit bb8df39 into develop Aug 10, 2020
@jeffreyssmith2nd jeffreyssmith2nd deleted the fix/parms-bool-template branch August 10, 2020 15:19
// Currently _Bool is the only one of these oddities but others could be handled here if they arise.
auto pos = type_name.find("_Bool");
if (pos != std::string::npos) {
type_name.replace(pos, 5, "bool");

Choose a reason for hiding this comment

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

Is this 5 is actually std::string("_Bool").size() ?
Also, I assume you expect that whole string should be equal to "_Bool" and not somewhere in the middle.
If so implementation could be like that:
static const std::string _Bool = "_Bool"; if (type_name == _Bool){ type_name.replace(0, _Bool.size(), "bool");
also I'm not sure why are you using replace, is it faster comparing to operator assignment? I assume it should have same performance

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replace is needed because _Bool is not the whole string. This change was specifically to handle cases like

std::optional<_Bool> which should be converted to std::optional<bool>

Copy link
Contributor

Choose a reason for hiding this comment

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

Expanding on the question: what will this do with std::optional<My_Bool>?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or, std::optional<MyNS::_Bool>?

C++ types don't meet the requirements of a regular grammar. i.e. neither simple string ops or even regular expressions can disambiguate them.

Choose a reason for hiding this comment

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

@jeffreyssmith2nd got it. do you mind to replace hardcoded 5 with _Bool.size() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

C++ types don't meet the requirements of a regular grammar. i.e. neither simple string ops or even regular expressions can disambiguate them.

@tbfleming Certainly, and that's challenge of some of the string based stuff we do in abi/codegen. In this case, I could add a regex to handle some common scenarions (right after a <, comma, or start of a line, etc) which I think would be worth doing to handle cases like what you showed, but I'm not sure there's a solution that handles everything perfectly.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as it's string based, there's a tradeoff between:

  1. Not recognizing some cases, e.g. binary_extension<optional<vector<bool>>>
  2. Improperly transforming cases which shouldn't match

Saying abigen doesn't recognize specific cases is easier than saying it scrambles certain user-defined types.

Copy link
Contributor

Choose a reason for hiding this comment

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

Especially since working contract code could currently exist which this breaks.

Copy link
Contributor

Choose a reason for hiding this comment

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

_Bool only appears because policy.Bool is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find, that's probably the right way to fix this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants