Skip to content
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

Invalid JSON for ast-json #71086

Closed
ehuss opened this issue Apr 13, 2020 · 2 comments · Fixed by #71284
Closed

Invalid JSON for ast-json #71086

ehuss opened this issue Apr 13, 2020 · 2 comments · Fixed by #71284
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Apr 13, 2020

The JSON for -Zast-json is broken because the id field for attributes serializes to nothing.

An empty library produces the following:

{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"prelude_import","span":{"lo":0,"hi":0}},"id":3,"args":null}]},"args":"Empty"}]},"id":,"style":"Outer","span":{"lo":0,"hi":0}}],"id":4,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"","span":{"lo":0,"hi":0}},"kind":{"variant":"Use","fields":[{"prefix":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"{{root}}","span":{"lo":0,"hi":0}},"id":5,"args":null},{"ident":{"name":"std","span":{"lo":0,"hi":0}},"id":6,"args":null},{"ident":{"name":"prelude","span":{"lo":0,"hi":0}},"id":7,"args":null},{"ident":{"name":"v1","span":{"lo":0,"hi":0}},"id":8,"args":null}]},"kind":"Glob","span":{"lo":0,"hi":0}}]},"tokens":null},{"attrs":[{"kind":{"variant":"Normal","fields":[{"path":{"span":{"lo":0,"hi":0},"segments":[{"ident":{"name":"macro_use","span":{"lo":0,"hi":0}},"id":9,"args":null}]},"args":"Empty"}]},"id":,"style":"Outer","span":{"lo":0,"hi":0}}],"id":10,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"std","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":null}],"inline":true},"attrs":[],"span":{"lo":0,"hi":0},"proc_macros":[]}

The important bit "id":, which is clearly not valid JSON.

It looks like the AttrId serialization was removed in #70215.

I'm not sure what a solution is here. I'm guessing AST serialization is used elsewhere, where this field isn't needed. I'm not too familiar with rustc_serialize, so I'm not sure if it has something equivalent to #[serde(skip)].

rustc 1.44.0-nightly (b543afca9 2020-04-05)

cc @petrochenkov

This issue has been assigned to @JOE1994 via this comment.

@ehuss ehuss added the C-bug Category: This is a bug. label Apr 13, 2020
@jonas-schievink jonas-schievink added requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 13, 2020
@petrochenkov
Copy link
Contributor

Looks like the encoding/decoding change from #70215 needs to be reverted.
Reverting should be ok because emit_unit and read_nil don't do anything anyway (at least when inlined) during metadata encoding and decoding.

The change is trivial, so marking this as E-easy, but if it's not done until the weekend I'll submit the PR myself.

@petrochenkov petrochenkov added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Apr 16, 2020
@JOE1994
Copy link
Contributor

JOE1994 commented Apr 17, 2020

@rustbot claim

@rustbot rustbot self-assigned this Apr 17, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 20, 2020
fix -Zast-json to output correct JSON form

fixes rust-lang#71086 (Reverts some of the changes made in rust-lang#70215)

JSON output (from an empty library) after fix has something for **"id"** field
```shell
lonelyjoe@lonelyjoe-desktop:~/workspace/empty_lib/src$ rustc lib.rs -Zast-json
```
```json
{
   "module":{
      "inner":{
         "lo":0,
         "hi":94
      },
      "items":[
         {
            "attrs":[
               {
                  "kind":{
                     "variant":"Normal",
                     "fields":[
                        {
                           "path":{
                              "span":{
                                 "lo":0,
                                 "hi":0
                              },
                              "segments":[
                                 {
                                    "ident":{
                                       "name":"prelude_import",
                                       "span":{
                                          "lo":0,
                                          "hi":0
                                       }
                                    },
                                    "id":3,
                                    "args":null
                                 }
                              ]
                           },
                           "args":"Empty"
                        }
                     ]
                  },
                  "id":null,
                  "style":"Outer",
                  "span":{
                     "lo":0,
                     "hi":0
                  }
               }
            ],
            "id":4,
            "span":{
               "lo":0,
               "hi":0
            },
            "vis":{
               "node":"Inherited",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "ident":{
               "name":"",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "kind":{
               "variant":"Use",
               "fields":[
                  {
                     "prefix":{
                        "span":{
                           "lo":0,
                           "hi":0
                        },
                        "segments":[
                           {
                              "ident":{
                                 "name":"{{root}}",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":5,
                              "args":null
                           },
                           {
                              "ident":{
                                 "name":"std",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":6,
                              "args":null
                           },
                           {
                              "ident":{
                                 "name":"prelude",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":7,
                              "args":null
                           },
                           {
                              "ident":{
                                 "name":"v1",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":8,
                              "args":null
                           }
                        ]
                     },
                     "kind":"Glob",
                     "span":{
                        "lo":0,
                        "hi":0
                     }
                  }
               ]
            },
            "tokens":null
         },
         {
            "attrs":[
               {
                  "kind":{
                     "variant":"Normal",
                     "fields":[
                        {
                           "path":{
                              "span":{
                                 "lo":0,
                                 "hi":0
                              },
                              "segments":[
                                 {
                                    "ident":{
                                       "name":"macro_use",
                                       "span":{
                                          "lo":0,
                                          "hi":0
                                       }
                                    },
                                    "id":9,
                                    "args":null
                                 }
                              ]
                           },
                           "args":"Empty"
                        }
                     ]
                  },
                  "id":null,
                  "style":"Outer",
                  "span":{
                     "lo":0,
                     "hi":0
                  }
               }
            ],
            "id":10,
            "span":{
               "lo":0,
               "hi":0
            },
            "vis":{
               "node":"Inherited",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "ident":{
               "name":"std",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "kind":{
               "variant":"ExternCrate",
               "fields":[
                  null
               ]
            },
            "tokens":null
         }
      ],
      "inline":true
   },
   "attrs":[

   ],
   "span":{
      "lo":0,
      "hi":94
   },
   "proc_macros":[

   ]
}
```
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 20, 2020
fix -Zast-json to output correct JSON form

fixes rust-lang#71086 (Reverts some of the changes made in rust-lang#70215)

JSON output (from an empty library) after fix has something for **"id"** field
```shell
lonelyjoe@lonelyjoe-desktop:~/workspace/empty_lib/src$ rustc lib.rs -Zast-json
```
```json
{
   "module":{
      "inner":{
         "lo":0,
         "hi":94
      },
      "items":[
         {
            "attrs":[
               {
                  "kind":{
                     "variant":"Normal",
                     "fields":[
                        {
                           "path":{
                              "span":{
                                 "lo":0,
                                 "hi":0
                              },
                              "segments":[
                                 {
                                    "ident":{
                                       "name":"prelude_import",
                                       "span":{
                                          "lo":0,
                                          "hi":0
                                       }
                                    },
                                    "id":3,
                                    "args":null
                                 }
                              ]
                           },
                           "args":"Empty"
                        }
                     ]
                  },
                  "id":null,
                  "style":"Outer",
                  "span":{
                     "lo":0,
                     "hi":0
                  }
               }
            ],
            "id":4,
            "span":{
               "lo":0,
               "hi":0
            },
            "vis":{
               "node":"Inherited",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "ident":{
               "name":"",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "kind":{
               "variant":"Use",
               "fields":[
                  {
                     "prefix":{
                        "span":{
                           "lo":0,
                           "hi":0
                        },
                        "segments":[
                           {
                              "ident":{
                                 "name":"{{root}}",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":5,
                              "args":null
                           },
                           {
                              "ident":{
                                 "name":"std",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":6,
                              "args":null
                           },
                           {
                              "ident":{
                                 "name":"prelude",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":7,
                              "args":null
                           },
                           {
                              "ident":{
                                 "name":"v1",
                                 "span":{
                                    "lo":0,
                                    "hi":0
                                 }
                              },
                              "id":8,
                              "args":null
                           }
                        ]
                     },
                     "kind":"Glob",
                     "span":{
                        "lo":0,
                        "hi":0
                     }
                  }
               ]
            },
            "tokens":null
         },
         {
            "attrs":[
               {
                  "kind":{
                     "variant":"Normal",
                     "fields":[
                        {
                           "path":{
                              "span":{
                                 "lo":0,
                                 "hi":0
                              },
                              "segments":[
                                 {
                                    "ident":{
                                       "name":"macro_use",
                                       "span":{
                                          "lo":0,
                                          "hi":0
                                       }
                                    },
                                    "id":9,
                                    "args":null
                                 }
                              ]
                           },
                           "args":"Empty"
                        }
                     ]
                  },
                  "id":null,
                  "style":"Outer",
                  "span":{
                     "lo":0,
                     "hi":0
                  }
               }
            ],
            "id":10,
            "span":{
               "lo":0,
               "hi":0
            },
            "vis":{
               "node":"Inherited",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "ident":{
               "name":"std",
               "span":{
                  "lo":0,
                  "hi":0
               }
            },
            "kind":{
               "variant":"ExternCrate",
               "fields":[
                  null
               ]
            },
            "tokens":null
         }
      ],
      "inline":true
   },
   "attrs":[

   ],
   "span":{
      "lo":0,
      "hi":94
   },
   "proc_macros":[

   ]
}
```
@bors bors closed this as completed in 314b78c Apr 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants