Skip to content
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

Progress on #91 #100

Merged
merged 2 commits into from
Nov 16, 2019
Merged

Progress on #91 #100

merged 2 commits into from
Nov 16, 2019

Conversation

thirtytwobits
Copy link
Member

  1. Fixing a problem with unique identifier generation (Issue to_template_unique_name is not working as expected #88)
  2. Generating C++ data structures (Issue Generate C++ #91)

Still TODO for Issue #91 is serialization for types.

@pavel-kirienko
Copy link
Member

I predict that the test I wrote for #99 will fail here because you seem to have encountered the same problem I had there. The culprit is where you added the extra check for none (can't link, am on mobile).

The caching issue may appear to be fixed unless you have a test to validate it, I can't find such test here.

Also, this is a 100-get ❤

Copy link
Member

@pavel-kirienko pavel-kirienko left a comment

Choose a reason for hiding this comment

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

see comment

…enCyphal#91

Disabling the Jinja cache results in the unique name generator state disappearing from the global Jinja context:

    >       return _UniqueNameGenerator.ensure_generator_in_globals(env.globals)('c', adj_base_token, '_', '_')
    E       TypeError: 'NoneType' object is not callable
    .tox/py35-test/lib/python3.5/site-packages/nunavut/lang/c.py:527: TypeError

This issue affects all languages. The following test modification indicates that the state gets replaced with None:

    ------------------------- src/nunavut/lang/__init__.py -------------------------
    index bd6524c..135a29a 100644
    @@ -226,7 +226,7 @@ class _UniqueNameGenerator:
        def ensure_generator_in_globals(cls, environment_globals: typing.Dict[str, typing.Any]) -> '_UniqueNameGenerator':
            from .. import TypeLocalGlobalKey

    -        if TypeLocalGlobalKey not in environment_globals:
    +        if environment_globals.get(TypeLocalGlobalKey) is None:
                environment_globals[TypeLocalGlobalKey] = cls()
            return typing.cast('_UniqueNameGenerator', environment_globals[TypeLocalGlobalKey])

Am stuck.

Progress on OpenCyphal#91

1) Fixing a problem with unique identifier generation (Issue OpenCyphal#88)
2) Generating C++ data structures (Issue OpenCyphal#91)

Still TODO for Issue OpenCyphal#91 is serialization for types.
@thirtytwobits
Copy link
Member Author

Let me know if this works for you. I've provided an example of using a template include instead of a macro to avoid the issues you are seeing with the unique identifiers. This includes a rebase with your change and then a modification of it.

@pavel-kirienko
Copy link
Member

I am uncertain that macros will have anything that isn't an argument reevaluated.

(quote from #99) Macros are allowed to have side effects. They work well in the current PyUAVCAN master where I keep the state in a template variable:

https://github.com/UAVCAN/pyuavcan/blob/7cc79786e212940c4777a8ffa741cc0b6709b17a/pyuavcan/dsdl/_templates/unique_reference.j2

For some reason, they break only when the global state is added from the side of the Python API.

Switching to includes instead of macros is worse than the current solution so it's probably best to keep it unchanged then.

I think we are misusing Jinja, it's getting in the way again.

@pavel-kirienko
Copy link
Member

Maybe we should instead keep the state somewhere inside Nunavut instead of Jinja's globals so that it's not destroyed when a macro is invoked?

@thirtytwobits
Copy link
Member Author

Okay. This is the best I can figure out. There may be a way to create a "runtime macro" extension but that's out of scope for this change.

@pavel-kirienko
Copy link
Member

Now the counter is not reset when a new data type starts being generated. The actual caching problem is not solved unless we use the more verbose macro invocation form. I suggest we go back to the old hack, somehow it seems less hacky that the new solution.

@pavel-kirienko
Copy link
Member

Going back to the old solution means removal of the unique ID filter from Nunavut,

@thirtytwobits
Copy link
Member Author

Now the counter is not reset when a new data type starts being generated. The actual caching problem is not solved unless we use the more verbose macro invocation form. I suggest we go back to the old hack, somehow it seems less hacky that the new solution.

Oh, I can reintroduce resetting the counter for each type but why should that matter?

@pavel-kirienko
Copy link
Member

Because the output code for a type X should not be dependent on that of the type Y, otherwise it complicates tracking the changes, and in compiled languages it may lead to unnecessary recompilation.

@thirtytwobits thirtytwobits force-pushed the feature/91 branch 2 times, most recently from cd334fe to c41bfd9 Compare November 16, 2019 19:39
@thirtytwobits
Copy link
Member Author

Found a fix!

Copy link
Member

@pavel-kirienko pavel-kirienko left a comment

Choose a reason for hiding this comment

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

It works! :shipit:

@thirtytwobits thirtytwobits merged commit 87daa4c into OpenCyphal:master Nov 16, 2019
@thirtytwobits thirtytwobits deleted the feature/91 branch November 16, 2019 23:12
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.

2 participants