1#![doc = include_str!("../README.md")]
2#![doc(
3 html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/solar/main/assets/logo.png",
4 html_favicon_url = "https://raw.githubusercontent.com/paradigmxyz/solar/main/assets/favicon.ico"
5)]
6#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
7#![cfg_attr(feature = "nightly", feature(panic_update_hook))]
89#[macro_use]
10extern crate tracing;
1112pub mod diagnostics;
13use diagnostics::ErrorGuaranteed;
1415mod globals;
16pub use globals::SessionGlobals;
1718mod pos;
19pub use pos::{BytePos, CharPos, RelativeBytePos};
2021mod session;
22pub use session::{Session, SessionBuilder};
2324pub mod source_map;
25pub use source_map::SourceMap;
2627mod span;
28pub use span::{Span, Spanned};
2930mod symbol;
31pub use symbol::{Ident, Symbol, kw, sym};
3233pub mod panic_hook;
3435pub use anstream::ColorChoice;
36pub use dunce::canonicalize;
37pub use solar_config as config;
38pub use solar_data_structures as data_structures;
3940/// The current version of the Solar compiler.
41pub const VERSION: &str = env!("CARGO_PKG_VERSION");
4243/// Compiler result type.
44pub type Result<T = (), E = ErrorGuaranteed> = std::result::Result<T, E>;
4546/// Pluralize a word based on a count.
47#[macro_export]
48#[rustfmt::skip]
49macro_rules! pluralize {
50// Pluralize based on count (e.g., apples)
51($x:expr) => {
52if $x == 1 { "" } else { "s" }
53 };
54 ("has", $x:expr) => {
55if $x == 1 { "has" } else { "have" }
56 };
57 ("is", $x:expr) => {
58if $x == 1 { "is" } else { "are" }
59 };
60 ("was", $x:expr) => {
61if $x == 1 { "was" } else { "were" }
62 };
63 ("this", $x:expr) => {
64if $x == 1 { "this" } else { "these" }
65 };
66}
6768/// Creates new session globals on the current thread if they doesn't exist already and then
69/// executes the given closure.
70///
71/// Prefer [`Session::enter_parallel`] to this function if possible to also set the source map and
72/// thread pool.
73///
74/// Using this instead of [`Session::enter_parallel`] may cause unexpected panics.
75#[inline]
76pub fn enter<R>(f: impl FnOnce() -> R) -> R {
77 SessionGlobals::with_or_default(|_| f())
78}