pub struct Session {
pub name: String,
pub options: Box<Options>,
pub source_manager: Arc<dyn SourceManager>,
pub diagnostics: Arc<DiagnosticsHandler>,
pub input: Option<InputFile>,
pub output_files: OutputFiles,
pub statistics: Statistics,
/* private fields */
}Expand description
This struct provides access to all of the metadata and configuration needed during a single compilation session.
Fields§
§name: StringThe name of this session
options: Box<Options>Configuration for the current compiler session
source_manager: Arc<dyn SourceManager>The current source manager
diagnostics: Arc<DiagnosticsHandler>The current diagnostics handler
input: Option<InputFile>The inputs being compiled
output_files: OutputFilesThe outputs to be produced by the compiler during compilation
statistics: StatisticsStatistics gathered from the current compiler session
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(
input: InputFile,
options: Box<Options>,
emitter: Option<Arc<dyn Emitter>>,
source_manager: Arc<dyn SourceManager + Send + Sync>,
) -> Result<Self, Report>
pub fn new( input: InputFile, options: Box<Options>, emitter: Option<Arc<dyn Emitter>>, source_manager: Arc<dyn SourceManager + Send + Sync>, ) -> Result<Self, Report>
Open a session compiling input under options.
§A project locator is read for its facts, not loaded as a project
A .toml input is a locator: it names the project to build rather than being something
the compiler compiles. Three facts about that project are needed before this session
exists, because this constructor is downstream of none of them:
- the package name, which is the artifact name absent
--name, and whichOutputFilesis built from below; - the library target’s kind, which is what
Options::target_typedefaults to, and whichadd_target_link_librariesthen consults to decide whether the Miden protocol is linked; - the executable targets’ names, from which
Options::entrypointis defaulted.
All three come from ProjectManifest, which parses the manifest’s AST and reads
exactly those three things out of it with miden_project’s own extractors. What it
deliberately does not do is build a miden_project::Project: loading the project is
prepare_project’s, in midenc-compile, and the package it loads is the one that gets
assembled. A session that loaded its own would be loading the same manifest twice to
produce a package nothing compiles.
Failing to read the manifest is not an error here. Which project a locator names, and
whether it names one at all, is decided and reported downstream — where the locator is
normalized anyway, and where a Cargo workspace root gets the diagnostic that belongs to
it rather than a “no such file” for the miden-project.toml a workspace root does not
have. So an unreadable manifest falls back to the same name derivation a source-file
input uses, and leaves target_type and entrypoint alone.
Sourcepub fn new_project(
name: String,
input: Option<InputFile>,
options: Box<Options>,
emitter: Option<Arc<dyn Emitter>>,
source_manager: Arc<dyn SourceManager>,
) -> Self
pub fn new_project( name: String, input: Option<InputFile>, options: Box<Options>, emitter: Option<Arc<dyn Emitter>>, source_manager: Arc<dyn SourceManager>, ) -> Self
Open a session named name, for a caller that already knows what it is building.
Session::new derives name from its input; this takes it. Both then do the same
thing, and neither knows anything about the project being built beyond its name.
Sourcepub fn get_flag(&self, name: &str) -> bool
pub fn get_flag(&self, name: &str) -> bool
Get the value of a custom flag with action FlagAction::SetTrue or FlagAction::SetFalse
Sourcepub fn get_flag_count(&self, name: &str) -> usize
pub fn get_flag_count(&self, name: &str) -> usize
Get the count of a specific custom flag with action FlagAction::Count
Sourcepub fn matches(&self) -> &ArgMatches
pub fn matches(&self) -> &ArgMatches
Get the remaining ArgMatches left after parsing the base session configuration
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
The name of this session (used as the name of the project, output file, etc.)
Sourcepub fn package_registry(&self) -> Result<Box<HybridPackageRegistry>, Report>
pub fn package_registry(&self) -> Result<Box<HybridPackageRegistry>, Report>
Get a new package registry instance for this session
Sourcepub fn filesystem_package_cache_dir(&self) -> Result<Option<PathBuf>, Report>
pub fn filesystem_package_cache_dir(&self) -> Result<Option<PathBuf>, Report>
Where compiled dependency packages of this build are published and looked for.
Ok(None) unless this session’s input is a project locator: a session compiling a
standalone source file has no project to exchange packages for. When the calling
process already exported MIDENC_PACKAGE_CACHE, that directory is adopted as-is and
left in place — the caller owns its location and lifetime (this is how a contract
build.rs keeps the packages readable after the compiler exits). Otherwise the
directory is a per-build lease with a globally unique name under the session’s
configured target directory (<target-dir>/packages), created on first access and
deleted when the last clone of this session drops; see the package_lease module for
both lifecycles. Anchoring at the target directory honors a caller-supplied
--target-dir — a writable location for a read-only checkout, for example.
Both readers — this session’s package registry and the nested cargo builds a Rust
project’s dependencies run through — must agree on the answer, which is why there is
one derivation of it. Only the root compilation session derives the path. Nested
dependency sessions receive the root value threaded through their build environment,
rather than deriving paths from their own locators: a dependency with a private
directory could not see its already-assembled transitive dependencies.
Session is Clone, and clones share the lease cell, so every clone observes the
same directory and no clone can mint a second one. Errors when the directory cannot be
created — fail closed, so the build stops here instead of failing later inside a macro
expansion with a confusing missing-package diagnostic; the failure is memoized and
re-reported on every access.
Derived from the input locator rather than from a loaded manifest, which is what
Session::new no longer has. That is also a repair: the manifest path was previously
taken from a package that fixup_cargo_target had rebuilt for every executable
Cargo.toml input, and a rebuilt package has no manifest path — so an executable project
silently got no filesystem cache at all, while a library project of the same shape got one.
Sourcepub fn out_file(&self) -> OutputFile
pub fn out_file(&self) -> OutputFile
Get the OutputFile to write the assembled MAST output to
Sourcepub fn parse_only(&self) -> bool
pub fn parse_only(&self) -> bool
Returns true if the compiler should exit after parsing the input
Sourcepub fn analyze_only(&self) -> bool
pub fn analyze_only(&self) -> bool
Returns true if the compiler should exit after performing semantic analysis
Sourcepub fn rewrite_only(&self) -> bool
pub fn rewrite_only(&self) -> bool
Returns true if the compiler should exit after applying rewrites to the IR
Sourcepub fn should_link(&self) -> bool
pub fn should_link(&self) -> bool
Returns true if an OutputType that requires linking + assembly was requested
Sourcepub fn should_codegen(&self) -> bool
pub fn should_codegen(&self) -> bool
Returns true if an OutputType that requires generating Miden Assembly was requested
Sourcepub fn should_assemble(&self) -> bool
pub fn should_assemble(&self) -> bool
Returns true if an OutputType that requires assembling MAST was requested
Sourcepub fn should_emit(&self, ty: OutputType) -> bool
pub fn should_emit(&self, ty: OutputType) -> bool
Returns true if the given OutputType should be emitted as an output
Sourcepub fn should_print_ir(&self, pass: &str) -> bool
pub fn should_print_ir(&self, pass: &str) -> bool
Returns true if IR should be printed to stdout, after executing a pass named pass
Sourcepub fn should_print_ir_before_stage(&self, stage: &str) -> bool
pub fn should_print_ir_before_stage(&self, stage: &str) -> bool
Returns true if IR should be printed to stdout, at the start of stage
Sourcepub fn should_print_cfg(&self, pass: &str) -> bool
pub fn should_print_cfg(&self, pass: &str) -> bool
Returns true if CFG should be printed to stdout, after executing a pass named pass
Sourcepub fn print(&self, ir: impl Emit, pass: &str) -> Result<()>
pub fn print(&self, ir: impl Emit, pass: &str) -> Result<()>
Print the given emittable IR to stdout, as produced by a pass with name pass
Sourcepub fn emit_to(&self, ty: OutputType, name: Option<Symbol>) -> Option<PathBuf>
pub fn emit_to(&self, ty: OutputType, name: Option<Symbol>) -> Option<PathBuf>
Get the path to emit the given OutputType to
Sourcepub fn emit<E: Emit>(&self, mode: OutputMode, item: &E) -> Result<()>
pub fn emit<E: Emit>(&self, mode: OutputMode, item: &E) -> Result<()>
Emit an item to stdout/file system depending on the current configuration
Sourcepub fn output_path_for(
&self,
output_type: OutputType,
name: Option<&str>,
) -> Option<OutputFile>
pub fn output_path_for( &self, output_type: OutputType, name: Option<&str>, ) -> Option<OutputFile>
Given an OutputType and an optional name, return the output file path that would be written to.
Returns Some if the specified output type should be emitted, and None if it should not.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Session
impl !RefUnwindSafe for Session
impl !Send for Session
impl !Sync for Session
impl !UnwindSafe for Session
impl Unpin for Session
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more