pub struct Types { /* private fields */ }Expand description
T3.6b (R4.1): the intern table TyId is minted from. Owned per
check_record invocation (design settled in the identity-and-totality
track doc §9 before this slice started): created fresh at check_record’s
entry, threaded through Ctx, carried out on TypedCommons/RecordCheck
alongside expr_types, and forwarded across the bynk-check→bynk-emit
boundary on CheckedProgram (T3.7a/T3.7b already built that seam).
Confirmed safe by checking how cross-unit type references actually flow:
compose_unit_symbols merges TypeDecl (immutable AST declarations)
across units, never an already-interned Ty/TyId — every unit
re-interns its own Ty graph from shared declarations, so TyIds are
never compared across two different check_record invocations.
Why intern takes &self, not &mut self. The table
is reached from Ctx, whose other fields (expr_types, errors, the
sinks) are themselves &mut and are routinely live across an interning
call — ctx.tys.intern(…) inside a loop over ctx.scopes is the common
shape, not the exception. A &mut Types would make the borrow checker,
not the type system, the thing every one of the ~200 minting sites is
written around. Interior mutability keeps &'a Types Copy, so a
function that needs the table just reads ctx.tys once and is done.
Why a Mutex and Arc, not a RefCell and Rc. The compiler itself
is single-threaded, so a cell would do for bynk-check and bynk-emit —
but the table rides out on TypedCommons/ProjectAnalysis into
bynk-lsp, whose tower-lsp handlers are async and therefore require
Send. A non-atomic refcount is exactly what Send forbids, so the
choice is made by the consumer, not by the compiler’s own threading. The
lock is uncontended in every current caller.
Implementations§
Source§impl Types
impl Types
pub fn new() -> Self
Sourcepub fn intern(&self, ty: Ty) -> TyId
pub fn intern(&self, ty: Ty) -> TyId
Intern ty, returning its TyId. The same Ty value (by Eq)
always yields the same TyId — the property ty_hash_eq_ord_tests
(T3.6b’s own settling-review prerequisite) pins directly. Dedup is by
the shallow Ty, which is sound precisely because every recursive
field is already a TyId: two structurally-equal types have equal
children ids by induction, so they hash and compare equal here.
Sourcepub fn get(&self, id: TyId) -> Arc<Ty>
pub fn get(&self, id: TyId) -> Arc<Ty>
The node id was interned from.
Panics on a TyId minted by a different table. That is the one new
failure mode interning introduces, and it is a wiring bug in the
compiler, never something a Bynk program can provoke — so it fails
loudly and by name rather than as a bare index-out-of-bounds. It was
worth the message: this fired twice while T3.6b was being built, both
times a synthesised TypedCommons that had been given a table of its
own while its expr_types was filled in from another.
Both of those were the shorter-table shape, where a bounds check
alone catches it. The dangerous shape is the other one: a foreign id
that happens to be in range resolves to an unrelated Ty and the
caller mis-diagnoses or mis-emits in silence. So in debug builds the
check is identity, not length — TyId carries its table’s tag and
this compares it. Release builds keep the bounds check only, which is
what indexing would have cost anyway.
Sourcepub fn display(&self, id: TyId) -> String
pub fn display(&self, id: TyId) -> String
Ty::display for an already-interned type.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of distinct types interned so far. Exposed for the interner’s own tests (dedup is observable only as “the table did not grow”).
pub fn is_empty(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Types
impl RefUnwindSafe for Types
impl Send for Types
impl Sync for Types
impl Unpin for Types
impl UnsafeUnpin for Types
impl UnwindSafe for Types
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<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);