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

Issue 1289933004: Implements support for reflection on parameters. (Closed)

Created:
5 years, 4 months ago by eernst
Modified:
5 years, 4 months ago
Reviewers:
floitsch
CC:
eernst+reviews_google.com, reviews_dartlang.org, sigurdm
Base URL:
https://github.com/dart-lang/reflectable.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Implements support for reflection on parameters. During the analysis phase needed in order to see where I could store the parameter related information, I changed many declarations from public to private, and removed many unused classes in mirrors_unimpl.dart. Also renamed `_reflectable` to `_reflector` a few places, for consistency. Added `parameterMirrors` to `ReflectorData`, passed that information all the way through to the *_reflection_data.dart files, and used that to implement `ParameterMirrorImpl`. Extracted `VariableMirrorBase` from `VariableMirrorImpl` as a new superclass containing the shared material (which also means that we can have `ClassMirror` as the return type of `MethodMirror`s `owner` and `MethodMirror` for `ParameterMirror`s `owner`, which would otherwise mess up the return type variance of `owner`). Strengthened the implementation in 'reflectable_implementation.dart' such that `declarations` can only be invoked when a `declarationsCapability` is present, as intended according to the design document. Enforcing the same discipline in the transformer and hence in generated code. Added a mirror implementation for the type `dynamic` (presumably, we cannot expect to avoid that type, and it is not possible to request support for it using existing capabilities, and it's kind of silly to create a new capability for a couple of odd-balls like `dynamic` (maybe `void` and `Null` will be included for the same reason). Decided that the set of type mirrors included should be extended will all reachable parameter types: If we have `typeCapability` and `declarationsCapability` then we can get `declarations` and for the methods among them `parameters`. We should then also be able to get a mirror for the types of those parameters, even in the case where no other reason justifies that those `int` types should be included (e.g., if you have `int foo(String s)..' then `int` and `String` mirrors will be available. This may be expensive, but requiring that all those argument types are requsted otherwise would be very tedious. Programmers can avoid it by omitting `typeCapability`! Parameters whose type is a function type are not covered by this CL. Lots of tests had to be adjusted because they violated the capability semantics: When a test needs to call `declarations` it must also have `declarationCapability`. Finally, unfortunately, a number of diff chunks were created by dartfmt, because it makes different decisions today than it did last time those files were edited. R=floitsch@google.com Committed: https://github.com/dart-lang/reflectable/commit/2696c189b2b4cbcbf92a608b682761954c89424c

Patch Set 1 #

Total comments: 17

Patch Set 2 : Review response #

Patch Set 3 : Merging with code from Sigurd, caused several adjustments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+788 lines, -463 lines) Patch
M reflectable/lib/src/encoding_constants.dart View 2 chunks +6 lines, -0 lines 0 comments Download
M reflectable/lib/src/mirrors_unimpl.dart View 1 2 21 chunks +253 lines, -229 lines 0 comments Download
M reflectable/lib/src/reflectable_implementation.dart View 1 2 26 chunks +93 lines, -40 lines 0 comments Download
M reflectable/lib/src/transformer_implementation.dart View 1 2 38 chunks +180 lines, -131 lines 0 comments Download
M reflectable/test/mock_tests/check_literal_transform_test.dart View 1 2 1 chunk +1 line, -2 lines 0 comments Download
M test_reflectable/.status View 1 2 2 chunks +1 line, -1 line 0 comments Download
M test_reflectable/pubspec.yaml View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M test_reflectable/test/basic_test.dart View 6 chunks +10 lines, -7 lines 0 comments Download
M test_reflectable/test/capabilities_test.dart View 2 chunks +4 lines, -2 lines 0 comments Download
M test_reflectable/test/declarations_test.dart View 3 chunks +46 lines, -38 lines 0 comments Download
M test_reflectable/test/metadata_test.dart View 3 chunks +12 lines, -5 lines 0 comments Download
M test_reflectable/test/parameter_mirrors_test.dart View 1 2 5 chunks +7 lines, -5 lines 0 comments Download
A test_reflectable/test/parameter_test.dart View 1 chunk +170 lines, -0 lines 0 comments Download
M test_reflectable/test/polymer_basic_needs_test.dart View 1 chunk +3 lines, -1 line 0 comments Download
M test_reflectable/test/proxy_test.dart View 1 chunk +1 line, -1 line 0 comments Download
M test_reflectable/test/type_relations_test.dart View 1 chunk +0 lines, -1 line 0 comments Download

Messages

Total messages: 10 (1 generated)
eernst
In response to the priorities indicated by Jacob Macdonald, support for reflection on parameters was ...
5 years, 4 months ago (2015-08-13 15:17:40 UTC) #2
jakemac
On 2015/08/13 15:17:40, eernst wrote: > In response to the priorities indicated by Jacob Macdonald, ...
5 years, 4 months ago (2015-08-13 16:07:01 UTC) #3
floitsch
LGTM. I don't like the private classes. In almost all cases one can just move ...
5 years, 4 months ago (2015-08-13 17:33:36 UTC) #4
eernst
Review response. Will land now. https://codereview.chromium.org/1289933004/diff/1/reflectable/lib/src/mirrors_unimpl.dart File reflectable/lib/src/mirrors_unimpl.dart (right): https://codereview.chromium.org/1289933004/diff/1/reflectable/lib/src/mirrors_unimpl.dart#newcode114 reflectable/lib/src/mirrors_unimpl.dart:114: _dataCache = data[_reflector]; On ...
5 years, 4 months ago (2015-08-14 12:05:34 UTC) #5
eernst
A number of adjustments were required in order to merge with the latest `git cl ...
5 years, 4 months ago (2015-08-14 19:26:21 UTC) #6
eernst
Landing now, further review comments will be taken into account in the next CL.
5 years, 4 months ago (2015-08-17 14:07:39 UTC) #7
eernst
Committed patchset #3 (id:40001) manually as 2696c189b2b4cbcbf92a608b682761954c89424c (presubmit successful).
5 years, 4 months ago (2015-08-17 14:08:25 UTC) #8
floitsch
https://codereview.chromium.org/1289933004/diff/1/reflectable/lib/src/mirrors_unimpl.dart File reflectable/lib/src/mirrors_unimpl.dart (right): https://codereview.chromium.org/1289933004/diff/1/reflectable/lib/src/mirrors_unimpl.dart#newcode114 reflectable/lib/src/mirrors_unimpl.dart:114: _dataCache = data[_reflector]; On 2015/08/14 12:05:34, eernst wrote: > ...
5 years, 4 months ago (2015-08-17 14:32:23 UTC) #9
eernst
5 years, 4 months ago (2015-08-19 13:41:56 UTC) #10
Message was sent while issue was closed.
Followup on old issues, with refs to new CLs.

https://codereview.chromium.org/1289933004/diff/1/reflectable/lib/src/mirrors...
File reflectable/lib/src/mirrors_unimpl.dart (right):

https://codereview.chromium.org/1289933004/diff/1/reflectable/lib/src/mirrors...
reflectable/lib/src/mirrors_unimpl.dart:114: _dataCache = data[_reflector];
On 2015/08/17 14:32:23, floitsch wrote:
> On 2015/08/14 12:05:34, eernst wrote:
> > On 2015/08/13 17:33:36, floitsch wrote:
> > > Why is this lazy? It's just a lookup into a map. That shouldn't be a
problem
> > > when the constructing a mirror-object.
> > > 
> > > If it doesn't need to be lazy, you can remove the class again.
> > 
> > We have done that for a while, I just created the class and used it as a
mixin
> > in order to avoid the code duplication. It is concerned with all lookups
into
> > `data`, which means that an application doing a lot of reflection work could
> > perform that map lookup many times. Whether it is a useful type of caching
is
> > hard to tell. Added a TODO indicating that we should turn it on and off and
> see
> > the effect when we have some more substantial pieces of software using it.
> 
> Why is it not filled at construction?

Could do that, check https://codereview.chromium.org/1284423004

[Since I wrote the above, that experiment showed that it was not easy to make
such a change, so we have abandoned that CL.]

https://codereview.chromium.org/1289933004/diff/1/reflectable/lib/src/mirrors...
reflectable/lib/src/mirrors_unimpl.dart:208: // test that compares owners in
pre/post-transform code.
On 2015/08/17 14:32:23, floitsch wrote:
> On 2015/08/13 17:33:36, floitsch wrote:
> > What's missing to write the test?
> 
> ?

Oops, forgot that. Turned out to require more refactorings than I had expected.
Followup in https://codereview.chromium.org/1297503006.

Powered by Google App Engine
This is Rietveld 408576698