-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
add -fdump-analysis to dump type information to json #3372
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit adds -fdump-analysis which creates a `$NAME-analysis.json` file with all of the finished semantic analysis that the stage1 compiler produced. It contains types, packages, declarations, and files. This is an initial implementation; some data will be missing. However it's easy to improve the implementation, which is in `src/dump_analysis.cpp`. The next step for #21 will be to create Zig code which parses this json file and creates user-facing HTML documentation. This feature has other uses, however; for example, it could be used for IDE integration features until the self-hosted compiler is available.
Here's the simplest example I could produce, if you want to see what the JSON looks like: export fn entry() void {}
const builtin = @import("builtin");
pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
while (true) {}
}
{
"typeKinds": [
"Type",
"Void",
"Bool",
"NoReturn",
"Int",
"Float",
"Pointer",
"Array",
"Struct",
"ComptimeFloat",
"ComptimeInt",
"Undefined",
"Null",
"Optional",
"ErrorUnion",
"ErrorSet",
"Enum",
"Union",
"Fn",
"BoundFn",
"ArgTuple",
"Opaque",
"Frame",
"AnyFrame",
"Vector",
"EnumLiteral"
],
"params": {
"zigId": "7qNQjBOgnEoYwB2CHOOrV7SvVwTsUtbVBO1AYpgcSpIsdFryNMtbLkIxZYgzZuks",
"zigVersion": "0.5.0+7640bec8",
"target": "x86_64-linux-gnu"
},
"rootPkg": 0,
"packages": [
{
"name": "",
"file": 0,
"main": 0,
"table": {
"builtin": 1,
"std": 2,
"root": 0
}
},
{
"name": "builtin",
"file": 1,
"main": 1,
"table": {}
}
],
"types": [
{
"name": "",
"kind": 8,
"decls": [
0,
1,
2
],
"file": 0
},
{
"name": "builtin",
"kind": 8,
"decls": [
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32
],
"file": 1
},
{
"name": "type",
"kind": 0
},
{
"name": "extern fn() void",
"kind": 18
},
{
"name": "fn([]const u8, ?*builtin.StackTrace) noreturn",
"kind": 18
},
{
"name": "builtin.StackTrace",
"kind": 8,
"decls": []
}
],
"decls": [
{
"import": 0,
"line": 2,
"col": 0,
"name": "builtin",
"kind": "const",
"type": 2,
"value": 1
},
{
"import": 0,
"line": 0,
"col": 0,
"name": "entry",
"kind": "const",
"type": 3
},
{
"import": 0,
"line": 3,
"col": 4,
"name": "panic",
"kind": "const",
"type": 4
},
{
"import": 1,
"line": 193,
"col": 4,
"name": "AtomicRmwOp"
},
{
"import": 1,
"line": 461,
"col": 4,
"name": "position_independent_code"
},
{
"import": 1,
"line": 458,
"col": 4,
"name": "link_libc"
},
{
"import": 1,
"line": 456,
"col": 4,
"name": "object_format"
},
{
"import": 1,
"line": 453,
"col": 4,
"name": "arch"
},
{
"import": 1,
"line": 422,
"col": 4,
"name": "FloatMode"
},
{
"import": 1,
"line": 449,
"col": 4,
"name": "endian"
},
{
"import": 1,
"line": 457,
"col": 4,
"name": "mode"
},
{
"import": 1,
"line": 452,
"col": 4,
"name": "os"
},
{
"import": 1,
"line": 212,
"col": 4,
"name": "TypeId"
},
{
"import": 1,
"line": 184,
"col": 4,
"name": "AtomicOrder"
},
{
"import": 1,
"line": 169,
"col": 4,
"name": "ObjectFormat"
},
{
"import": 1,
"line": 454,
"col": 4,
"name": "abi"
},
{
"import": 1,
"line": 0,
"col": 4,
"name": "StackTrace",
"kind": "const",
"type": 2,
"value": 5
},
{
"import": 1,
"line": 450,
"col": 4,
"name": "is_test"
},
{
"import": 1,
"line": 5,
"col": 4,
"name": "PanicFn",
"kind": "const",
"type": 2,
"value": 4
},
{
"import": 1,
"line": 47,
"col": 4,
"name": "Arch"
},
{
"import": 1,
"line": 455,
"col": 4,
"name": "glibc_version"
},
{
"import": 1,
"line": 460,
"col": 4,
"name": "valgrind_support"
},
{
"import": 1,
"line": 438,
"col": 4,
"name": "SubSystem"
},
{
"import": 1,
"line": 205,
"col": 4,
"name": "Mode"
},
{
"import": 1,
"line": 427,
"col": 4,
"name": "Endian"
},
{
"import": 1,
"line": 462,
"col": 4,
"name": "strip_debug_info"
},
{
"import": 1,
"line": 7,
"col": 4,
"name": "Os"
},
{
"import": 1,
"line": 432,
"col": 4,
"name": "Version"
},
{
"import": 1,
"line": 451,
"col": 4,
"name": "single_threaded"
},
{
"import": 1,
"line": 177,
"col": 4,
"name": "GlobalLinkage"
},
{
"import": 1,
"line": 144,
"col": 4,
"name": "Abi"
},
{
"import": 1,
"line": 459,
"col": 4,
"name": "have_error_return_tracing"
},
{
"import": 1,
"line": 241,
"col": 4,
"name": "TypeInfo"
}
],
"files": [
"/home/andy/dev/zig/build/test.zig",
"/home/andy/.local/share/zig/stage1/builtin/Mb2TI_lUZey68IlsL1U9nGQ-DfP4mc41hhGstc4Tfls8HIKfojclFH2NTajGhj_8/builtin.zig"
]
} I think this is already enough to start to make progress on #21. |
My eventual hope is that the self-hosted code could merge multiple of these json files in a sort of "multibuilds" fashion (#3028) but even just processing 1 of them into HTML docs would be huge. |
Tests pass locally. |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit adds -fdump-analysis which creates
a
$NAME-analysis.json
file with all of the finishedsemantic analysis that the stage1 compiler produced.
It contains types, packages, declarations, and files.
This is an initial implementation; some data will be
missing. However it's easy to improve the implementation,
which is in
src/dump_analysis.cpp
.The next step for #21 will be to create Zig code which parses
this json file and creates user-facing HTML documentation.
This feature has other uses, however; for example, it could
be used for IDE integration features until the self-hosted
compiler is available.