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

Add JSON AST dumping #12387

Merged
merged 1 commit into from
Feb 20, 2014
Merged

Add JSON AST dumping #12387

merged 1 commit into from
Feb 20, 2014

Conversation

emberian
Copy link
Member

See the commits

io::println(json);
}
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compile_input function has managed to remain pretty clean since it was created, perhaps the json emission would be better suited inside of the phases themselves?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't possible without exiting the entire process in the phases, which they avoid by having compile_input return early for them if necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(That was the first thing I implemented, before noticing that issue)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you leave the modifications to stop_after_phase_X and then move the emission logic to the end of the phases themselves?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, duh. will-do

On Wed, Feb 19, 2014 at 2:52 AM, Alex Crichton notifications@github.comwrote:

In src/librustc/driver/driver.rs:

@@ -531,7 +541,13 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,

     write_out_deps(sess, input, &outputs, &expanded_crate).unwrap();
  •    if stop_after_phase_2(sess) { return; }
    
  •    if stop_after_phase_2(sess) {
    
  •        if sess.opts.debugging_opts & session::AST_JSON != 0 {
    
  •            let json = json::PrettyEncoder::str_encode(&expanded_crate);
    
  •            io::println(json);
    
  •        }
    
  •        return;
    
  •    }
    

Couldn't you leave the modifications to stop_after_phase_X and then move
the emission logic to the end of the phases themselves?


Reply to this email directly or view it on GitHubhttps://github.com//pull/12387/files#r9856752
.

This is mostly useful for working on rustc, when one is unfamiliar with the
AST a particular construct will produce. It's a -Z flag as it's very much for
debugging.

Closes #10485
bors added a commit that referenced this pull request Feb 20, 2014
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));

if sess.opts.debugging_opts & session::AST_JSON != 0 {
let mut stdout = io::stdout();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be buffered? (Otherwise every single write, including each and every : separator, will be a syscall.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't stdout line buffered by default?

On Wed, Feb 19, 2014 at 7:39 PM, Huon Wilson notifications@github.comwrote:

In src/librustc/driver/driver.rs:

@@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

  • time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate))
    
  • let (krate, map) = time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));
    
  • if sess.opts.debugging_opts & session::AST_JSON != 0 {
  •    let mut stdout = io::stdout();
    

Shouldn't this be buffered? (Otherwise every single write, including each
and every : separator will be a syscall.)


Reply to this email directly or view it on GitHubhttps://github.com//pull/12387/files#r9890950
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task-local stdout handle is line-buffered by default, but those created through io::stdout() are not buffered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feh.

On Wed, Feb 19, 2014 at 7:55 PM, Alex Crichton notifications@github.comwrote:

In src/librustc/driver/driver.rs:

@@ -220,8 +231,16 @@ pub fn phase_2_configure_and_expand(sess: Session,
krate = time(time_passes, "prelude injection", krate, |krate|
front::std_inject::maybe_inject_prelude(sess, krate));

  • time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate))
    
  • let (krate, map) = time(time_passes, "assinging node ids and indexing ast", krate, |krate|
  •     front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));
    
  • if sess.opts.debugging_opts & session::AST_JSON != 0 {
  •    let mut stdout = io::stdout();
    

The task-local stdout handle is line-buffered by default, but those
created through io::stdout() are not buffered.


Reply to this email directly or view it on GitHubhttps://github.com//pull/12387/files#r9891396
.

@bors bors closed this Feb 20, 2014
@bors bors merged commit 34ffe3c into rust-lang:master Feb 20, 2014
@huonw
Copy link
Member

huonw commented Feb 20, 2014

@cmr, also, while you're fixing the buffering ;), it would be good to add a simple run-make test, to ensure the flags keep doing something approximately sane.

@edwardw
Copy link
Contributor

edwardw commented Feb 20, 2014

Awesome!

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
fix(ide-db): correct single-file module rename

Fixes a bug where rust-analyzer would emit `WorkspaceEdit`s with paths to dirs instead of files for the following project layout.

lib.rs
```rust
mod foo;
```

foo.rs
```rust
mod bar {
    struct Bar;
}
```
Also fixes emitted paths for modules with mod.rs.
The bug resulted in panic in helix editor when attempting to rename a module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants