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
Symbol should expose the actual symbol name #28372
Comments
This is with the realization that the actual name might be (There is a way to do this with |
In my case I only care about the VM case, in particular the VM case in checked mode, where there's never minification as far as I know. I agree that this would be less useful in other modes. In the context where I'm using this (Flutter's flutter_test test harness), we don't have Having said all that, if dart:mirrors can do it, why couldn't Symbol just do it itself? If dart:mirrors can do it then the data is there, right? Minification or no? |
This is by design. Mirrors traffick in Symbols instead of regular Strings to make minification easier for dart2js, by requiring one to both import 'dart:mirrors' and use a static method perform conversions. |
The typical situation (dart2js compilation is one example) is that import 'dart:mirrors';
class HelloWorld {}
String showName(o) => "HelloWorld";
String showName(o) {
TypeMirror oType = reflect(o).type;
return MirrorSystem.getName(oType.simpleName);
}
main() {
var x = new HelloWorld();
print(showName(x));
} Even though the vm may have the information in any case, it wouldn't be able to deliver it "for free" without destroying the portability of the code. So you have to use mirrors to get at this information. |
I feel like this is a "least common denominator" decision, where the VM experience suffers because of a limitation of one of the other targets. The reality of the situation is that I need to make the Flutter test harness error messages usable, which means showing the actual names of the symbols that I collect from a mock that is collecting Invocations via noSuchMethod. Today I do this by extracting the name from the Since the use case is for tests only, it doesn't matter if it only works in the checked mode, non-AOT, non dart2js target that |
We do expose the name in the Sadly, the same argument goes for the That doesn't meant that we have to use the un-minified name in a minified program. We can return the minified name, if that is what we show in the |
And |
+1 for web use cases too I'm OK with mangled names with optimizations enabled, but I'd like to see:
*There is already a lot of code that uses the abstract class SuperService {}
// If someone refactors the name SuperService, it also applies here.
test('$SuperService should never throw an exception', () {
...
}); |
I'm not sure it will help, but it is possible for Flutter to expose the functionality of
which would work in all VM modes. |
Any updates on this? For code-generations purpose, I would like get the name of functions/classes/variables. I can parse the |
No changes here. As for updates, dart2js no longer supports If anything, I'd put introspection/debugging functionality into dart:developer, rather than piggy-back it on the run-time values derived from the named declarations. For code generation running on the VM, just use dart:mirrors. |
FWIW, Flutter continues to just depend on // Workaround for https://github.com/dart-lang/sdk/issues/28372
String _symbolName(Symbol symbol) {
// WARNING: Assumes a fixed format for Symbol.toString which is *not*
// guaranteed anywhere.
final String s = '$symbol';
return s.substring(8, s.length - 2);
} One change since this bug was filed is that this hack is now part of our public API (the mock canvas logic is now part of |
Have you considerd just hard-coding the symbols that occur in the Something like: lrhn/flutter@b94305e (Map auto-generated by a very simple Dart script, from the source code of the |
That seems vastly less ergonomic and harder to maintain :-) |
It knows it, since it's in the toString, but it's not easily extracted.
The text was updated successfully, but these errors were encountered: