Skip to main content

Profile

Struct Profile 

Source
#[non_exhaustive]
pub struct Profile {
Show 15 fields pub discipline: Discipline, pub subtyping: bool, pub records: RecordTyping, pub numeric_widening: bool, pub null_safety: bool, pub exhaustive_match: bool, pub polymorphism: Polymorphism, pub default_int: Prim, pub default_float: Prim, pub string_add: bool, pub certain_errors: bool, pub method_autoref: bool, pub mono: MonoPolicy, pub null_let: NullLet, pub try_hook: TryHook,
}
Expand description

A type-system profile.

Built from a preset and adjusted with the with_* methods; fields are public to read. #[non_exhaustive]: profiles grow toggles as disciplines land, without breaking callers that start from a preset.

§Examples

use typeck_lang::{Profile, RecordTyping};

let iron_like = Profile::static_explicit()
    .with_records(RecordTyping::Nominal)
    .with_numeric_widening(false);
assert!(iron_like.null_safety);
assert!(!iron_like.numeric_widening);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§discipline: Discipline

How much is checked and inferred.

§subtyping: bool

A subclass value may be used where a base class is expected, and (with structural records) a record with extra fields where fewer are expected.

§records: RecordTyping

Nominal or structural records.

§numeric_widening: bool

Lossless numeric conversions are implicit (i32 to i64, f32 to f64, integers to floats that hold them exactly), and integer literals may type as floats.

§null_safety: bool

null inhabits only T? types (Kotlin, Kraken). When false, null coerces to any non-value type: references, pointers, nominal types, functions, strings, slices, maps (Java, Go).

§exhaustive_match: bool

match must cover every value of the scrutinee’s type.

§polymorphism: Polymorphism

Traits, interfaces, or typeclasses: what an interface name means as a type.

§default_int: Prim

The type of an unsuffixed integer literal that nothing constrains.

§default_float: Prim

The type of an unsuffixed float literal that nothing constrains.

§string_add: bool

add on two strings is concatenation.

§certain_errors: bool

Under Dynamic: report the arity and shape errors that are certain whatever the run-time values (wrong argument count to a known function, an unknown named argument or record field, a constructor pattern of the wrong length).

§method_autoref: bool

Method receivers are borrowed (&x, &mut x) and dereferenced implicitly to fit the method’s receiver parameter, and lookup looks through references (Rust, Iron). When false, the receiver must already have the receiver parameter’s type.

§mono: MonoPolicy

Which generic items the monomorphization plan copies per instantiation and which it shares through dictionary passing.

§null_let: NullLet

What let x = null gives x.

§try_hook: TryHook

How ? reaches the checker.

Implementations§

Source§

impl Profile

Source

pub const fn dynamic() -> Self

Python, Lua, Mox: no static type errors, only certain shape errors.

§Examples
use typeck_lang::{Discipline, Profile};

let p = Profile::dynamic();
assert_eq!(p.discipline, Discipline::Dynamic);
assert!(p.certain_errors);
Source

pub const fn gradual() -> Self

TypeScript-like: checked where annotated (0.5).

§Examples
use typeck_lang::{Discipline, Profile};

assert_eq!(Profile::gradual().discipline, Discipline::Gradual);
Source

pub const fn static_explicit() -> Self

C, Go, Zero: declared types, local inference for let.

Nominal records, no subtyping beyond Never, null only in T?, no implicit widening, exhaustive match, i64/f64 literal defaults.

§Examples
use typeck_lang::{Profile, RecordTyping};

let p = Profile::static_explicit();
assert_eq!(p.records, RecordTyping::Nominal);
assert!(p.exhaustive_match);
Source

pub const fn static_inferred() -> Self

Kraken, Iron: bidirectional inference, generics, traits.

As static_explicit, with traits, closure signatures inferred from context, and let x = null giving a nullable type inferred from later uses.

§Examples
use typeck_lang::{Discipline, NullLet, Polymorphism, Profile};

let p = Profile::static_inferred();
assert_eq!(p.discipline, Discipline::StaticInferred);
assert_eq!(p.polymorphism, Polymorphism::Traits);
assert_eq!(p.null_let, NullLet::Nullable);
Source

pub const fn hm() -> Self

ML: Hindley-Milner with let-polymorphism (0.5).

§Examples
use typeck_lang::{Discipline, Polymorphism, Profile};

let p = Profile::hm();
assert_eq!(p.discipline, Discipline::Hm);
assert_eq!(p.polymorphism, Polymorphism::Typeclasses);
Source

pub const fn with_subtyping(self, on: bool) -> Self

Sets subtyping.

§Examples
assert!(typeck_lang::Profile::static_explicit().with_subtyping(true).subtyping);
Source

pub const fn with_records(self, records: RecordTyping) -> Self

Sets records.

§Examples
use typeck_lang::{Profile, RecordTyping};

let p = Profile::static_explicit().with_records(RecordTyping::Structural);
assert_eq!(p.records, RecordTyping::Structural);
Source

pub const fn with_numeric_widening(self, on: bool) -> Self

Sets numeric_widening.

§Examples
assert!(typeck_lang::Profile::static_explicit().with_numeric_widening(true).numeric_widening);
Source

pub const fn with_null_safety(self, on: bool) -> Self

Sets null_safety.

§Examples
assert!(!typeck_lang::Profile::static_explicit().with_null_safety(false).null_safety);
Source

pub const fn with_exhaustive_match(self, on: bool) -> Self

Sets exhaustive_match.

§Examples
assert!(!typeck_lang::Profile::static_explicit().with_exhaustive_match(false).exhaustive_match);
Source

pub const fn with_polymorphism(self, polymorphism: Polymorphism) -> Self

Sets polymorphism.

§Examples
use typeck_lang::{Polymorphism, Profile};

let p = Profile::static_inferred().with_polymorphism(Polymorphism::Interfaces);
assert_eq!(p.polymorphism, Polymorphism::Interfaces);
Source

pub const fn with_literal_defaults(self, int: Prim, float: Prim) -> Self

Sets the literal defaults. A non-integer int or non-float float is refused by check with CheckError::InvalidProfile.

§Examples
use hir_lang::Prim;
use typeck_lang::Profile;

let p = Profile::static_explicit().with_literal_defaults(Prim::I32, Prim::F32);
assert_eq!(p.default_int, Prim::I32);
Source

pub const fn with_string_add(self, on: bool) -> Self

Sets string_add.

§Examples
assert!(typeck_lang::Profile::static_explicit().with_string_add(true).string_add);
Source

pub const fn with_certain_errors(self, on: bool) -> Self

Sets certain_errors.

§Examples
assert!(!typeck_lang::Profile::dynamic().with_certain_errors(false).certain_errors);
Source

pub const fn with_method_autoref(self, on: bool) -> Self

Sets method_autoref.

§Examples
assert!(!typeck_lang::Profile::static_inferred().with_method_autoref(false).method_autoref);
Source

pub const fn with_mono(self, mono: MonoPolicy) -> Self

Sets mono.

§Examples
use typeck_lang::{MonoPolicy, Profile};

let iron = Profile::static_inferred().with_mono(MonoPolicy::Selective { max_nodes: 64 });
assert_eq!(iron.mono, MonoPolicy::Selective { max_nodes: 64 });
Source

pub const fn with_null_let(self, null_let: NullLet) -> Self

Sets null_let.

§Examples
use typeck_lang::{NullLet, Profile};

let p = Profile::static_explicit().with_null_let(NullLet::Nullable);
assert_eq!(p.null_let, NullLet::Nullable);
Source

pub const fn with_try_hook(self, hook: TryHook) -> Self

Sets try_hook.

§Examples
use intern_lang::Interner;
use typeck_lang::{Profile, TryHook};

let mut names = Interner::new();
let hook = TryHook::Intrinsic { name: names.intern("try"), convert: None };
assert_eq!(Profile::static_inferred().with_try_hook(hook).try_hook, hook);

Trait Implementations§

Source§

impl Clone for Profile

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Profile

Source§

impl Debug for Profile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Profile

Source§

impl Eq for Profile

Source§

impl Hash for Profile

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Profile

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Profile

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.