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

Issue 10692040: Mirrors prototype added to dartdoc. (Closed)

Created:
8 years, 5 months ago by Johnni Winther
Modified:
8 years, 5 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Mirrors prototype added to dartdoc. The mirrors system is local to dartdoc and will merged with the VM version at a later point. TEST=compiler/dart2js/mirrors_test.dart Committed: https://code.google.com/p/dart/source/detail?r=9406

Patch Set 1 #

Total comments: 13

Patch Set 2 : dart2js_mirror.dart included in the cl #

Total comments: 97

Patch Set 3 : Utility libraries added #

Total comments: 79

Patch Set 4 : Fixed cf. lrn's comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+2531 lines, -1 line) Patch
M lib/compiler/implementation/typechecker.dart View 1 chunk +1 line, -1 line 0 comments Download
A lib/dartdoc/mirrors/dart2js_mirror.dart View 1 2 3 1 chunk +1188 lines, -0 lines 0 comments Download
A lib/dartdoc/mirrors/mirrors.dart View 1 2 3 1 chunk +438 lines, -0 lines 0 comments Download
A lib/dartdoc/mirrors/mirrors_util.dart View 1 2 3 1 chunk +72 lines, -0 lines 0 comments Download
A lib/dartdoc/mirrors/util.dart View 1 2 3 1 chunk +161 lines, -0 lines 0 comments Download
A tests/compiler/dart2js/mirrors_helper.dart View 1 2 1 chunk +48 lines, -0 lines 0 comments Download
A tests/compiler/dart2js/mirrors_test.dart View 1 2 3 1 chunk +623 lines, -0 lines 0 comments Download

Messages

Total messages: 7 (0 generated)
Johnni Winther
The first version of the compile-time mirror system is added to dartdoc. It is not ...
8 years, 5 months ago (2012-06-29 12:13:52 UTC) #1
gbracha
lgtm with comments https://chromiumcodereview.appspot.com/10692040/diff/1/lib/dartdoc/mirrors/mirrors.dart File lib/dartdoc/mirrors/mirrors.dart (right): https://chromiumcodereview.appspot.com/10692040/diff/1/lib/dartdoc/mirrors/mirrors.dart#newcode4 lib/dartdoc/mirrors/mirrors.dart:4: All my comments are already at: ...
8 years, 5 months ago (2012-06-30 01:27:32 UTC) #2
Johnni Winther
PTAL
8 years, 5 months ago (2012-07-02 09:29:17 UTC) #3
Lasse Reichstein Nielsen
Lots of style comments. Haven't tried to actually understand everything yet. https://chromiumcodereview.appspot.com/10692040/diff/7001/lib/dartdoc/mirrors/dart2js_mirror.dart File lib/dartdoc/mirrors/dart2js_mirror.dart (right): ...
8 years, 5 months ago (2012-07-02 11:48:53 UTC) #4
Johnni Winther
Utility libraries added. Updated cf. lrn's comments. PTAL https://chromiumcodereview.appspot.com/10692040/diff/7001/lib/dartdoc/mirrors/dart2js_mirror.dart File lib/dartdoc/mirrors/dart2js_mirror.dart (right): https://chromiumcodereview.appspot.com/10692040/diff/7001/lib/dartdoc/mirrors/dart2js_mirror.dart#newcode36 lib/dartdoc/mirrors/dart2js_mirror.dart:36: { ...
8 years, 5 months ago (2012-07-03 07:38:50 UTC) #5
Lasse Reichstein Nielsen
LGTM with suggestions. I haven't checked the logic entirely, but the semantic questions I had ...
8 years, 5 months ago (2012-07-04 10:58:59 UTC) #6
Johnni Winther
8 years, 5 months ago (2012-07-04 13:19:17 UTC) #7
https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
File lib/dartdoc/mirrors/dart2js_mirror.dart (right):

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:80: return [new
Dart2jsFieldMirror(library, element)];
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Type the literal with <Dart2jsMemberMirror>. Or perhaps only <MemberMirror> if
> the collection is ever exposed.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:82: return [new
Dart2jsMethodMirror(library, element)];
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> ditto

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:100: Element element) {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> indent.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:125: String
_getOperatorFromOperatorName(String str) {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> "str"->"name"
> It's not just a string, it's an operator name. In any case, only abbreviate a
> name if the abbreviation is commonly used as a word anyway (e.g., "info" for
> "information"). Otherwise, don't abbreviate at all.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:145: else if (str == 'or') return '|';
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> You could have a constant Map<String, String> to convert, and just check for
> null after converting. It's no less readable than this long nested if-else-if
> (and especially since if's with an else must always use a {...} block).
> I.e., 
>  Map<String, String> mapping = const {
>    'eq' => '==',
>    'not' => 'negate',   // will change.
>    'index' => '[]',
>    ...
>   };
>   String newName = mapping[str];
>   if (newName === null) {
>     throw ...
>   }
>   return newName;

Done. (Using : instead of => in the constant map!)

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:152: = const
Dart2jsDiagnosticListener();
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Consider making it a getter instead of a field. No need to store a constant in
> the objhect.
> If not, move '=' to previous line.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:201: assert(fatal);
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Drop this assert. It's only checking that the 'if' statement works correctly,
> which I think is safe to assume.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:213: : cwd = getCurrentDirectory(),
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> indentation.
Ignored!

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:325: : super(system, element);
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> indentation.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:330: Map<String, InterfaceMirror>
_types;
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Do we really need to make these fields private?
> We have generally not made our implementation details private in the compiler.

I like that they are private when the need initialization (by
_ensureTypes()/_ensureMembers()) before use.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:389: return new
ImmutableMapWrapper<Object,MemberMirror>(_members);
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Space after comma. More cases below.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:459: // declarations
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Capitalize comment.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:544: var link = _class.interfaces;
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Type on "link". I assume it's Link<Something>, but I have no idea what the
> Something is.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:581: return new
AsFilteredImmutableMapWrapper<Object, MemberMirror, MethodMirror>(
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Line length > 80. No, there is no way to make this pretty :(

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:631: String qualifiedName() =>
'${library().qualifiedName()}.${simpleName()}';
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Make this, "location", "library", "typeArguments", "typeVariables",
> "definition", "declaredMembers", "superclass", "interfaces", "constructors"
and
> "defaultType" getters too, if possible. 

This issue will be considered for the whole mirrors API.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:710: {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Brace on previous line (and indentation of initializer list).

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:711: assert (_typeVariableType !==
null);
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> No space after assert. It's written as a function call, not a control flow
> construct.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:757: print('${declarer()} !=
${other.declarer()}');
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Debug-print?
Yes, the one that got away!

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:974: 
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Extra empty line.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:1034: var dollarPos =
_name.indexOf('\$');
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> "var" => "int". No need not to.
> Really, don't use "var" unless the rhs is a constructor call.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:1050: &&
_function.modifiers.isFactory())
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Indent to paren.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:1051: {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Brace on previous line.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:1108:
_function.computeSignature(system.compiler));
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Indentation.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:1143: {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Brace on previous line.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/dart2js_mirror.dart:1149: : this._objectMirror =
objectMirror,
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Indentation, both parameter and ':'.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
File lib/dartdoc/mirrors/mirrors.dart (right):

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/mirrors.dart:19: {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Brace on previous line.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
File lib/dartdoc/mirrors/mirrors_util.dart (right):

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/mirrors_util.dart:49: * returned.
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> If constructorName is given, but name matches a non-Method, that non-Method is
> returned. I.e., constructorName is ignored, even though it seems like the user
> had an intent with it. Is this intentional?

It wasn't. The test has been rewritten.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/mirrors_util.dart:54: map.forEach((_,m) {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> space after comma, give "m" a better name and preferably a type, e.g., "(_,
> Mirror mirror)" (except that "mirror" is already used).
>  
> We really need a find on maps. Something like:
>   Map<K,V> {
>     K findMatch(bool predicate(K key, V value));
> 
> Perhaps use the values collection instead:
>  
>  for (Mirror mirror in map.getValues()) {
>    if (...) {
>      return mirror;
>    }
>  }
>  return null;

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/mirrors_util.dart:57: found = true;
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Seems convoluted, but I guess that's actually for readability.
> How about:
>   if (m is! MethodMirror ||
>       ((constructorName == null || 
>         constructorName == m.constructorName) &&
>        (operatorName == null ||
>         operatorName == m.operatorName))) {
>     mirror = m;
>  } 
This wouldn't work for if [m] is a FieldMirror and [constructorName] is
non-null.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
File lib/dartdoc/mirrors/util.dart (right):

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/util.dart:11: * implemented immutable map.
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> That's what the Map class itself should be!
> Eventually.
> 
> I'd prefer to base it on a way to iterate keys. The forEach iteration can't be
> used lazily, like an iterator can, but that's a performance issue only.

Yes, an iterator is wanted/needed.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/util.dart:68: * mutable operations throw
[UnsupportedOperationException] upon invocation.
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> "mutable operations" -> "mutating operations"

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/util.dart:124: typedef V2 AsFilter<V1,V2>(V1 value);
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Space after comma, evertwhere.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/util.dart:127: * An immutable map wrapper capable of
filtering the input map based on types.
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Tricky. Might need more comments.
Done. (Or tried!)

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/util.dart:129: class
AsFilteredImmutableMapWrapper<K,Vin,Vout> extends AbstractMap<K,Vout> {
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> The "filter" method don't need to do a cast. It can do an arbitrary
translation
> to an unrelated type. You can use it for projections, e.g., with a filter
>   Bar filter(Foo x) => x.bar;
> Can we specify a relation between Vin and Vout - if it's for up-casting,
perhaps
> 
>   <K, Vin extends Vout, Vout>  
> (possibly in a different order).

The filter method could be used for other purposes. The map could be a candidate
for a collection more general utility collections, and should in such a case be
defined and described in the broadest terms.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/util.dart:133: AsFilteredImmutableMapWrapper(this._map,
this._filter);
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Indentation is one too deep from here.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/lib/dartdoc/mirror...
lib/dartdoc/mirrors/util.dart:134: 
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Should you override containsKey/containsValue to return false if filter
returns
> null? Otherwise it won't match length().
It works with the current implementation of AbstractMap whichs uses forEach for
containsKey/containsValue.

https://chromiumcodereview.appspot.com/10692040/diff/10002/tests/compiler/dar...
File tests/compiler/dart2js/mirrors_test.dart (right):

https://chromiumcodereview.appspot.com/10692040/diff/10002/tests/compiler/dar...
tests/compiler/dart2js/mirrors_test.dart:73: "Unexpected mirror type returned");
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Indentation, preferably to paren. Also below.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/tests/compiler/dar...
tests/compiler/dart2js/mirrors_test.dart:101:
Expect.isTrue(containsType(fooClass, computeSubdeclarations(system,
objectType)),
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Line length.

Done.

https://chromiumcodereview.appspot.com/10692040/diff/10002/tests/compiler/dar...
tests/compiler/dart2js/mirrors_test.dart:117: "Class has type arguments");
On 2012/07/04 10:58:59, Lasse Reichstein Nielsen wrote:
> Indentation still off.

Done.

Powered by Google App Engine
This is Rietveld 408576698