#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.discipline: DisciplineHow much is checked and inferred.
subtyping: boolA 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: RecordTypingNominal or structural records.
numeric_widening: boolLossless 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: boolnull 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: boolmatch must cover every value of the scrutinee’s type.
polymorphism: PolymorphismTraits, interfaces, or typeclasses: what an interface name means as a type.
default_int: PrimThe type of an unsuffixed integer literal that nothing constrains.
default_float: PrimThe type of an unsuffixed float literal that nothing constrains.
string_add: booladd on two strings is concatenation.
certain_errors: boolUnder 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: boolMethod 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: MonoPolicyWhich generic items the monomorphization plan copies per instantiation and which it shares through dictionary passing.
null_let: NullLetWhat let x = null gives x.
try_hook: TryHookHow ? reaches the checker.
Implementations§
Source§impl Profile
impl Profile
Sourcepub const fn dynamic() -> Self
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);Sourcepub const fn gradual() -> Self
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);Sourcepub const fn static_explicit() -> Self
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);Sourcepub const fn static_inferred() -> Self
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);Sourcepub const fn hm() -> Self
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);Sourcepub const fn with_subtyping(self, on: bool) -> Self
pub const fn with_subtyping(self, on: bool) -> Self
Sourcepub const fn with_records(self, records: RecordTyping) -> Self
pub const fn with_records(self, records: RecordTyping) -> Self
Sourcepub const fn with_numeric_widening(self, on: bool) -> Self
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);Sourcepub const fn with_null_safety(self, on: bool) -> Self
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);Sourcepub const fn with_exhaustive_match(self, on: bool) -> Self
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);Sourcepub const fn with_polymorphism(self, polymorphism: Polymorphism) -> Self
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);Sourcepub const fn with_literal_defaults(self, int: Prim, float: Prim) -> Self
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);Sourcepub const fn with_string_add(self, on: bool) -> Self
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);Sourcepub const fn with_certain_errors(self, on: bool) -> Self
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);Sourcepub const fn with_method_autoref(self, on: bool) -> Self
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);