Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Issue 1958463003: Mojom compiler: Eliminate duplicate representation of enum values in mojom_files.mojom. (Closed)

Created:
4 years, 7 months ago by rudominer
Modified:
4 years, 7 months ago
Reviewers:
vardhan, azani
CC:
mojo-reviews_chromium.org, gregsimon, qsr+mojo_chromium.org, viettrungluu+watch_chromium.org, abarth-chromium, Aaron Boodman, darin (slow to review), ben+mojo_chromium.org, yzshen+mojopublicwatch_chromium.org
Base URL:
https://github.com/domokit/mojo.git@master
Target Ref:
refs/heads/master
Project:
mojo
Visibility:
Public.

Description

Mojom compiler: Eliminate duplicate representation of enum values in mojom_types.mojom. This cl addresses the problem that in mojom_files.mojom, the full definition of an enum value (including for example the whole DeclarationData) occurred twice: It occurred once in the value registry (i.e. the |resolved_values| map) and once within the owning MojomEnum strcut that lived in the type registry (i.e. the |resolved_types| map.) In order to address this I considered two possible strategies: (a) Replace the field "array<EnumValue> values" within MojomEnum with a new field "array<string> value_keys;" or (b) Take the enum values out of the value registry. Instead of a value registry we have only a constant registry. References to enum values are now references to the owning EnumType plus an index into the list of values within the enum. I first tried (a) In a different patch but I didn't like it (for reasons I will elaborate below*). In this patch strategy (b) is used. Summary of changes: - In mojom_files.mojom in the struct MojomFileGraph replace the field "map<string, UserDefinedValue> resolved_values;" with the field "map<string, DeclaredConstant> resolved_constants;" (I also fixed up some comments.) - In mojom_types.mojom we made three changes: (i) We deleted |UserDefinedValue|. This was meant as a "super-type" to EnumValue and DeclaredConstant. We no longer need this abstraction. (ii) In struct UserValueReference (which represents a reference to a value) we replaced the field string? value_key; with three fields: - string? constant_key; - string? enum_type_key; - uint32 enum_value_index; If the UserValueReference is a reference to a constant then |constant_key| is populated. If the UserValueReference is a reference to an enum value then the |enum_type_key| and |enum_value_index| are populated. The idea is that for enun values instead of referring to them via a key to a value registry we refer to them via a key to the enum in the type registry and an index into the list of enum values. (iii) In struct EnumValue we deleted the field |enum_type_key|. Previously it was possible to access an enum value indirectly via its value key and so it was useful to be able to get the key to the containing enum. In the new scheme an enum value is always accessed via its enum and so this extra data is not useful. - In serialization.go we modified the serialization logic based on these changes. - In mojom_translatory.py we modified the translation logic based on these changes. - All the other files are tests or generated files. *Why did I end up not liking strategy (a)? If you think only about the use of mojom_files.mojom and mojom_types.mojom in the context of the Mojom compiler then strategy (a) sounds good, which is why I initially pursued it. But I soon realized it is not great for the runtime type querying use case. In this use case mojom_files.mojom is not used, only mojom_types.mojom along with service_describer.mojom. Runtime type querying currently has no notion of a value registry, and it does not deal with constants at all--constants don't seem to be useful at runtime. (At least I am not aware of a use for them at this time.) If I had taken the enum values out of the enum then for the runtime type querying use case I would have added a registry of only enum values. It seemed more natural to just leave the enum values within their enum. Strategy (b) also makes this CL shorter (believe it or not) because I don't have to make any changes to any runtime type querying code. BUG=fixes #513 R=azani@chromium.org Committed: https://chromium.googlesource.com/external/mojo/+/a60302d6a4532fc3845a5d68a31d227687257b88

Patch Set 1 #

Total comments: 6

Patch Set 2 : Responded to code reveiw comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+694 lines, -763 lines) Patch
M mojo/dart/packages/_mojo_for_test_only/lib/dart_to_cpp/dart_to_cpp.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/imported/sample_import.mojom.dart View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/imported/sample_import2.mojom.dart View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/math/math_calculator.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/examples/echo.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/rect.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/serialization_test_structs.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/test_enums.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/test_included_unions.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/test_structs.mojom.dart View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/test_unions.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/validation_test_interfaces.mojom.dart View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/mojo/test/versioning/versioning_test_client.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/regression_tests/regression_tests.mojom.dart View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/sample/sample_factory.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/sample/sample_interfaces.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/sample/sample_service.mojom.dart View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/test/echo_service.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/_mojo_for_test_only/lib/test/pingpong_service.mojom.dart View 1 chunk +1 line, -1 line 0 comments Download
M mojo/dart/packages/mojo/lib/mojo/bindings/types/mojom_files.mojom.dart View 6 chunks +15 lines, -18 lines 0 comments Download
M mojo/dart/packages/mojo/lib/mojo/bindings/types/mojom_types.mojom.dart View 1 16 chunks +159 lines, -153 lines 0 comments Download
M mojo/dart/unittests/embedder_tests/bindings_generation_test.dart View 1 chunk +1 line, -2 lines 0 comments Download
M mojo/go/tests/validation_type_test.go View 1 chunk +0 lines, -16 lines 0 comments Download
M mojo/public/interfaces/bindings/mojom_files.mojom View 2 chunks +10 lines, -11 lines 0 comments Download
M mojo/public/interfaces/bindings/mojom_types.mojom View 1 6 chunks +43 lines, -37 lines 0 comments Download
M mojo/public/tools/bindings/mojom_tool/bin/linux64/mojom.sha1 View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/public/tools/bindings/pylib/mojom/generate/generated/mojom_files_mojom.py View 1 chunk +1 line, -1 line 0 comments Download
M mojo/public/tools/bindings/pylib/mojom/generate/generated/mojom_types_mojom.py View 1 4 chunks +17 lines, -16 lines 0 comments Download
M mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator.py View 1 4 chunks +49 lines, -41 lines 0 comments Download
M mojo/public/tools/bindings/pylib/mojom/generate/mojom_translator_unittest.py View 1 5 chunks +11 lines, -24 lines 0 comments Download
M mojom/generated/mojom_files/mojom_files.mojom.go View 6 chunks +23 lines, -20 lines 0 comments Download
M mojom/generated/mojom_types/mojom_types.mojom.go View 1 17 chunks +168 lines, -183 lines 0 comments Download
M mojom/mojom_tool/mojom/user_defined_types.go View 3 chunks +7 lines, -0 lines 0 comments Download
M mojom/mojom_tool/serialization/serialization.go View 1 4 chunks +39 lines, -45 lines 0 comments Download
M mojom/mojom_tool/serialization/serialization_test.go View 1 12 chunks +130 lines, -175 lines 0 comments Download

Messages

Total messages: 17 (11 generated)
rudominer
Alex, Vardhan ptal. After this lands you will need to make some small changes in ...
4 years, 7 months ago (2016-05-06 20:22:55 UTC) #11
vardhan
https://codereview.chromium.org/1958463003/diff/60001/mojo/public/interfaces/bindings/mojom_types.mojom File mojo/public/interfaces/bindings/mojom_types.mojom (right): https://codereview.chromium.org/1958463003/diff/60001/mojo/public/interfaces/bindings/mojom_types.mojom#newcode359 mojo/public/interfaces/bindings/mojom_types.mojom:359: string? enum_type_key; i was going to suggest that enum_type_key ...
4 years, 7 months ago (2016-05-09 22:06:29 UTC) #12
azani
https://codereview.chromium.org/1958463003/diff/60001/mojo/public/interfaces/bindings/mojom_types.mojom File mojo/public/interfaces/bindings/mojom_types.mojom (right): https://codereview.chromium.org/1958463003/diff/60001/mojo/public/interfaces/bindings/mojom_types.mojom#newcode256 mojo/public/interfaces/bindings/mojom_types.mojom:256: array<EnumValue> values; Can you document the order here now ...
4 years, 7 months ago (2016-05-09 22:10:19 UTC) #13
rudominer
ptal https://codereview.chromium.org/1958463003/diff/60001/mojo/public/interfaces/bindings/mojom_types.mojom File mojo/public/interfaces/bindings/mojom_types.mojom (right): https://codereview.chromium.org/1958463003/diff/60001/mojo/public/interfaces/bindings/mojom_types.mojom#newcode256 mojo/public/interfaces/bindings/mojom_types.mojom:256: array<EnumValue> values; On 2016/05/09 22:10:19, azani wrote: > ...
4 years, 7 months ago (2016-05-10 17:57:59 UTC) #14
azani
lgtm
4 years, 7 months ago (2016-05-10 18:38:57 UTC) #15
rudominer
4 years, 7 months ago (2016-05-10 20:27:43 UTC) #17
Message was sent while issue was closed.
Committed patchset #2 (id:80001) manually as
a60302d6a4532fc3845a5d68a31d227687257b88 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698