Conversation
|
Thanks for your pull request and interest in making D better, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9409" |
|
Any suggestion for the failing AppVeyor? The result is |
|
Internally it looks like |
|
Isn't that what the .json output is supposed to do? There's also printast.d |
They're not doing what I want. When the serializer is complete it will print all fields of all classes and structs. Here's an example of the output of passing in an instance of --- &1 !d/class:Module
ident: &2 !d/class:Identifier
value: 120
name: main
parent: null
csym: null
isym: null
comment: null
loc: !d/struct:Loc
filename: null
linnum: 0
charnum: 0
_scope: !d/struct:Scope
enclosing: !d/struct:Scope
enclosing: null
_module: *1
scopesym: &3 !d/class:ScopeDsymbol
ident: null
parent: null
csym: null
isym: null
comment: null
loc: !d/struct:Loc
filename: null
linnum: 0
charnum: 0Here's an example of some struggled I had where this would have helped. UDAs are represented with the This would have been trivial to figure out if I could dump the whole AST, instead there where lots of trail and error. I can also add that both [1] Line 1164 in e7cac4e [2] Line 2645 in e7cac4e |
a3b76ef to
1bac0d8
Compare
I found |
1bac0d8 to
ff41310
Compare
| { | ||
| const result = serialize(true); | ||
| assert(result == "--- true", result); | ||
| } |
There was a problem hiding this comment.
All these unittest test just one function which doesn't need any state. What's the motivation of not using embedded unittests within DMD as they would automatically document the function whereas these tests might be a lot harder to find to a reader.
There was a problem hiding this comment.
- I'm pretty sure you said somewhere that those tests are not being run/are not passing on Windows
- I think this unit test runner is better, it allows to run only a single unit test block
- I think there will be too many unit tests in one place
|
What's up with AppVeyor, some kind of double quoting? |
Yes, that's caused by a cleanup in druntime: #9421 |
That looks an awful lot like the json output. |
@WalterBright it's not anything like the JSON output at all. There are 25 fields in the snippet above, three of those exists in the JSON output, |
|
What I'm suggesting is improve the json output to add missing fields rather than invent a new format. |
@WalterBright so you want me to remove I don't know if the JSON format is supposed to be stable and is specified somewhere. But if I change the field names and the structure of the JSON format I'm sure that tools using that output will break. Like Ddox, for example. |
ff41310 to
2a576f2
Compare
2a576f2 to
800de64
Compare
|
Ping. |
|
@WalterBright ping |
|
I'm also not a huge fan of adding another output format. Does the serializer need to be part of the compiler? Isn't it better suited for the examples folder? |
The existing formats are not suitable for what this is doing or are intended for other things. The JSON format is explicitly indented to not expose the compiler internals. This format is intended to do exactly that. Changing the JSON format will break tools like Ddox. The JSON format doesn't handle arbitrary types.
Yes. I need to be able to call it from anywhere within the compiler.
Absolutely not. I need to be able to call it from anywhere within the compiler. Is it only me that see this as being useable? Does everyone else already know exactly all the internals of the compiler? |
|
Sounds like you are trying to use this instead of a debugger? |
I like it and am in favor. As it's used for debugging, there won't be any overhead for end-users. Though I think we should document all in-compiler debugging facilities for new users somewhere easy to find. |
Yes, but I haven't found anyone that is useable. I've tried now for half an hour to print the dynamic type of a C++ class. And as far as I know the D compiler doesn't output typeid/typeinfo (or whatever it's called) for C++ classes. If that's not available I don't know how it would be possible to inspect the dynamic type. |
This is the firs step in adding a serializer to DMD which can output a textual representation of any type, primarily the AST. This is useful for debugging and learning the AST.
800de64 to
067e956
Compare
I agree. Although this is not useful as is. I'll do that after the other PRs. |
It is? It's intent is to be useful. Just add new fields for what's missing. |
|
We're talking about two different things here. The json output is intended to be read by machines and tools after all semantics has been done. |
If it's like printast.d, why not extend that? We also already have textual representations for expressions and types (as |
| private: | ||
|
|
||
| /// Evaluates to `true` if `T` is a basic type, otherwise `false`. | ||
| template isBasicType(T) |
There was a problem hiding this comment.
This duplicates isTypeBasic()
There was a problem hiding this comment.
isTypeBasic is a member of the class Type. This is intended to pass in native D types, like int and char[]. It's not what the compiler views as a basic type. It's used by the serializer to determine if the value needs to be further decomposed or if it can be transformed into a textual representation as is.
| * value = the value to serialize | ||
| * isTopLevel = indicates if this is the first value to be serialized | ||
| */ | ||
| void serializeBasicType(T)(T value, bool isTopLevel) |
There was a problem hiding this comment.
dmd already has TypeBasic.toChars()
There was a problem hiding this comment.
TypeBasic is not used here. Native D types are used.
|
I'm at a loss why we are to spend so much code on this in the compiler. This is the job of a separate tool using the compiler as a library, which is available after everybody asked for it for years. What, do we now want to build every possible tool into the core compiler? |
I can replace
It returns the source code representation not the AST representation. For example, !d/class:IntegerExp
op: int32Literal
size: 4
parens: 0
loc: !d/struct:Loc
filename: test.d
linnum: 1
charnum: 1
value: 1 |
It's a debugging tool to be used inside the compiler, just as the hundreds of |
This is the firs step in adding a serializer to DMD which can output a textual representation of any type, manly the AST. This is useful for debugging and learning the AST.
When everything is implemented, it's going to look something like: https://github.com/jacob-carlborg/dmd/tree/serializer.
Depends on #9408.