|
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
Total comments: 6
|
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
|
Total messages: 17 (11 generated)
|