paradigmxyz / solar

Blazingly fast, modular and contributor friendly Solidity compiler, written in Rust
Apache License 2.0
281 stars 23 forks source link

`Session` entered more than once only emits diagnostics in first execution #130

Open ferranbt opened 1 day ago

ferranbt commented 1 day ago

Describe the feature

Entering a Session multiple times to parse a file only emits diagnostics on the first execution

let path = Path::new("src/Counter.sol");

let human = HumanEmitter::new(io::stdout(), solar_interface::ColorChoice::Auto);
let dcx = DiagCtxt::new(Box::new(human));

// Create a new session with a buffer emitter.
// This is required to capture the emitted diagnostics and to return them at the end.
let sess = Session::builder().dcx(dcx).build();

// Enter the context and parse the file. This session emits diagnostics
let _ = sess.enter(|| -> solar_interface::Result<()> {
  let mut pcx = solar_sema::ParsingContext::new(&sess);
  pcx.load_file(path).unwrap();
  pcx.parse_and_resolve();

  Ok(())
});

println!("Enter second session");

// Enter the second context and parse the file. This session DOES NOT emit diagnostics
let _ = sess.enter(|| -> solar_interface::Result<()> {
  let mut pcx = solar_sema::ParsingContext::new(&sess);
  pcx.load_file(path).unwrap();
  pcx.parse_and_resolve();

  Ok(())
});

Additional context

No response

DaniPopes commented 9 hours ago

Identical diagnostics are deduplicated across an entire session, for now if you want a clean slate you should create a new session

We could provide a clear method that resets internal state