Introduce 'Never' type as a safe alternative to always None options

Unfortunately, as documented in:

  https://github.com/IntersectMBO/cardano-ledger/issues/4571

  Some Option fields in the script context certificates are going to
  remain set to None, at least until the next Hard fork. There's a risk
  that people permanently lock their funds if they expect deposits on
  registration credentials to ever be `Some`.

  So, we introduce a special type that emulate an `Option` that can only
  ever be `None`. We call it `Never` and it is the first type of this
  kind (i.e. with constructors indexes not starting at 0).
This commit is contained in:
KtorZ
2024-08-27 11:06:02 +02:00
parent ff25fbd970
commit d74e36d0bc
13 changed files with 269 additions and 68 deletions

View File

@@ -16,6 +16,8 @@ pub const LIST: &str = "List";
pub const MILLER_LOOP_RESULT: &str = "MillerLoopResult";
pub const OPTION: &str = "Option";
pub const OPTION_CONSTRUCTORS: &[&str] = &["Some", "None"];
pub const NEVER: &str = "Never";
pub const NEVER_CONSTRUCTORS: &[&str] = &["__hole", "Never"];
pub const ORDERING: &str = "Ordering";
pub const ORDERING_CONSTRUCTORS: &[&str] = &["Less", "Equal", "Greater"];
pub const PAIR: &str = "Pair";
@@ -297,6 +299,17 @@ impl Type {
})
}
pub fn never() -> Rc<Type> {
Rc::new(Type::App {
public: true,
contains_opaque: false,
name: NEVER.to_string(),
module: "".to_string(),
args: vec![],
alias: None,
})
}
pub fn ordering() -> Rc<Type> {
Rc::new(Type::App {
public: true,