-
Notifications
You must be signed in to change notification settings - Fork 128
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
Deterministic iteration order for reproducible codegen #846
Deterministic iteration order for reproducible codegen #846
Conversation
7cf813d
to
1c760e0
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.
While I'm all for making code generation reproducible, does this actually have an effect? My reading of this is that the include_directives
set() is used just to tell if we've every included a particular header before. That is, we don't actually iterate over include_directives
at any point, so this is basically a no-op. Can you give an example of what changes with this in place?
We iterated over
There are other |
Fair enough. I think then we should just replace that one with a list. We shouldn't need the rest of the changes here. |
The
is passed to other templates rosidl/rosidl_generator_c/resource/idl__type_support.c.em Lines 45 to 49 in dd05300
rosidl/rosidl_generator_c/resource/idl__type_support.c.em Lines 61 to 65 in dd05300
and those templates then pass I guess we could do --- a/rosidl_generator_c/resource/idl__type_support.c.em
+++ b/rosidl_generator_c/resource/idl__type_support.c.em
@@ -16,16 +16,19 @@ include_parts = [package_name] + list(interface_path.parents[0].parts) + [
'detail', convert_camel_case_to_lower_case_underscore(interface_path.stem)]
include_base = '/'.join(include_parts)
-include_directives = {
+include_directives_ordered = [
'rosidl_typesupport_interface/macros.h',
include_base + '__type_support.h',
include_base + '__struct.h',
- include_base + '__functions.h'}
+ include_base + '__functions.h']
+
+include_directives = set(include_directives_ordered)
+
}@
#include <string.h>
-@[for header_file in include_directives]@
+@[for header_file in include_directives_ordered]@
#include "@(header_file)"
@[end for]@ so we iterate over the ordered list but and use the set in the other templates |
Yeah, I like this. I'd say let's go ahead with that change. Thanks! |
Python set's do not have a deterministic iteration order (unlike dicts), therefore replace usage of set with OrderedDict's for the `includes` variable in `full__description.c.em` to make codegen reproducible. Signed-off-by: Harry Sarson <harry.sarson@codethink.co.uk>
The `include_directives` set is used by the nested templates to prevent generation of duplicate include directives, but is not iterated over by those nested templates. In `idl__type_support.c.em` rather that iterating over the `include_directives` set (which introduces non-determinism) to generate the includes for top level header files, we iterate over those top level includes as a list and seperately construct the `include_directives` set from the list. This ensures deterministic codegen. Signed-off-by: Harry Sarson <harry.sarson@codethink.co.uk>
1c760e0
to
a9ea6b0
Compare
I have had a go at this, please see latest commits. I kept the
|
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.
One more change, then this will be ready for CI. Thanks for iterating.
Pulls: #846 |
Two small changes to get derministic iteration order which makes codegen reproducible
Use OrderedDict for reproducible codegen
therefore replace usage of set with OrderedDict's for the
includes
variable in
full__description.c.em
to make codegen reproducible.Use deterministic iteration in type_support header
The
include_directives
set is used by the nested templates toprevent generation of duplicate include directives, but is not iterated
over by those nested templates.
In
idl__type_support.c.em
rather that iterating over theinclude_directives
set (which introduces non-determinism) to generatethe includes for top level header files, we iterate over those top level
includes as a list and seperately construct the
include_directives
setfrom the list. This ensures deterministic codegen.