pub struct Session {
    pub opts: Opts,
    pub dcx: DiagCtxt,
    /* private fields */
}Expand description
Information about the current compiler session.
Fields§
§opts: OptsThe compiler options.
dcx: DiagCtxtThe diagnostics context.
Implementations§
Source§impl Session
 
impl Session
Sourcepub fn builder() -> SessionBuilder
 
pub fn builder() -> SessionBuilder
Creates a new session builder.
Sourcepub fn new(opts: Opts) -> Session
 
pub fn new(opts: Opts) -> Session
Creates a new session from the given options.
See builder for a more flexible way to create a session.
Sourcepub fn infer_language(&mut self)
 
pub fn infer_language(&mut self)
Infers the language from the input files.
Sourcepub fn validate(&self) -> Result<(), ErrorGuaranteed>
 
pub fn validate(&self) -> Result<(), ErrorGuaranteed>
Validates the session options.
Sourcepub fn reconfigure(&self)
 
pub fn reconfigure(&self)
Reconfigures inner state to match any new options.
Call this after updating options.
Sourcepub fn unstable(&self) -> &UnstableOpts
 
pub fn unstable(&self) -> &UnstableOpts
Returns the unstable options.
Sourcepub fn emitted_diagnostics_result(
    &self,
) -> Option<Result<EmittedDiagnostics, EmittedDiagnostics>>
 
pub fn emitted_diagnostics_result( &self, ) -> Option<Result<EmittedDiagnostics, EmittedDiagnostics>>
Returns the emitted diagnostics as a result. Can be empty.
Returns None if the underlying emitter is not a human buffer emitter created with
with_buffer_emitter.
Results Ok if there are no errors, Err otherwise.
§Examples
Print diagnostics to stdout if there are no errors, otherwise propagate with ?:
println!("{}", dcx.emitted_diagnostics_result().unwrap()?);Sourcepub fn emitted_diagnostics(&self) -> Option<EmittedDiagnostics>
 
pub fn emitted_diagnostics(&self) -> Option<EmittedDiagnostics>
Returns the emitted diagnostics. Can be empty.
Returns None if the underlying emitter is not a human buffer emitter created with
with_buffer_emitter.
Sourcepub fn emitted_errors(&self) -> Option<Result<(), EmittedDiagnostics>>
 
pub fn emitted_errors(&self) -> Option<Result<(), EmittedDiagnostics>>
Returns Err with the printed diagnostics if any errors have been emitted.
Returns None if the underlying emitter is not a human buffer emitter created with
with_buffer_emitter.
Sourcepub fn source_map(&self) -> &SourceMap
 
pub fn source_map(&self) -> &SourceMap
Returns a reference to the source map.
Sourcepub fn clone_source_map(&self) -> Arc<SourceMap>
 
pub fn clone_source_map(&self) -> Arc<SourceMap>
Clones the source map.
Sourcepub fn stop_after(&self, stage: CompilerStage) -> bool
 
pub fn stop_after(&self, stage: CompilerStage) -> bool
Returns true if compilation should stop after the given stage.
Sourcepub fn is_sequential(&self) -> bool
 
pub fn is_sequential(&self) -> bool
Returns true if parallelism is not enabled.
Sourcepub fn is_parallel(&self) -> bool
 
pub fn is_parallel(&self) -> bool
Returns true if parallelism is enabled.
Sourcepub fn do_emit(&self, output: CompilerOutput) -> bool
 
pub fn do_emit(&self, output: CompilerOutput) -> bool
Returns true if the given output should be emitted.
Sourcepub fn spawn(&self, f: impl FnOnce() + Send + 'static)
 
pub fn spawn(&self, f: impl FnOnce() + Send + 'static)
Spawns the given closure on the thread pool or executes it immediately if parallelism is not enabled.
NOTE: on a use_current_thread thread pool rayon::spawn will never execute without
yielding to rayon, so prefer using this method over rayon::spawn.
Sourcepub fn join<A, B, RA, RB>(&self, oper_a: A, oper_b: B) -> (RA, RB)
 
pub fn join<A, B, RA, RB>(&self, oper_a: A, oper_b: B) -> (RA, RB)
Takes two closures and potentially runs them in parallel. It returns a pair of the results from those closures.
NOTE: on a use_current_thread thread pool rayon::join will never execute without
yielding to rayon, so prefer using this method over rayon::join.
Sourcepub fn scope<'scope, OP, R>(&self, op: OP) -> R
 
pub fn scope<'scope, OP, R>(&self, op: OP) -> R
Executes the given closure in a fork-join scope.
See rayon::scope for more details.
Sourcepub fn enter_sequential<R>(&self, f: impl FnOnce() -> R) -> R
 
pub fn enter_sequential<R>(&self, f: impl FnOnce() -> R) -> R
Sets up the session globals and executes the given closure in the current thread.
Note that this does not set up the rayon thread pool. This is only useful when parsing
sequentially, like manually using Parser. Otherwise, it might cause panics later on if a
thread pool is expected to be set up correctly.
See enter for more details.
Sourcepub fn intern(&self, s: &str) -> Symbol
 
pub fn intern(&self, s: &str) -> Symbol
Interns a string in this session’s symbol interner.
The symbol may not be usable on its own if the session has not been entered.
Sourcepub fn resolve_symbol(&self, s: Symbol) -> &str
 
pub fn resolve_symbol(&self, s: Symbol) -> &str
Resolves a symbol to its string representation.
The given symbol must have been interned in this session.
Sourcepub fn intern_byte_str(&self, s: &[u8]) -> ByteSymbol
 
pub fn intern_byte_str(&self, s: &[u8]) -> ByteSymbol
Interns a byte string in this session’s symbol interner.
The symbol may not be usable on its own if the session has not been entered.
Sourcepub fn resolve_byte_str(&self, s: ByteSymbol) -> &[u8] ⓘ
 
pub fn resolve_byte_str(&self, s: ByteSymbol) -> &[u8] ⓘ
Resolves a byte symbol to its string representation.
The given symbol must have been interned in this session.
Sourcepub fn is_entered(&self) -> bool
 
pub fn is_entered(&self) -> bool
Returns true if this session has been entered.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, R> CollectAndApply<T, R> for T
 
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
 
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
 
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more