fn insert_metas(
    meta_insertion: MetaInsertion<'_>,
    context: &Context,
    metas: &mut meta::Env,
    span: FileSpan,
    mut term: Rc<syntax::Term>,
    term_ty: &Rc<domain::Type>,
) -> Result<(Rc<syntax::Term>, Rc<domain::Type>), Diagnostic<FileSpan>> {
    use mltt_core::domain::Value::FunType;

    let mut term_ty = term_ty.clone();

    while let FunType(app_mode, _, param_ty, body_ty) = term_ty.as_ref() {
        match (meta_insertion, app_mode) {
            // The user requested we stop inserting metavariables, or
            // we have seen an explicit argument, so we stop inserting
            // metavariables.
            (MetaInsertion::No, _) | (_, AppMode::Explicit) => break,

            // FIXME: mismatches?

            // In these cases we see a matching implicit or instance argument
            // being passed, corresponding to the expected parameter in the
            // type. Therefore we stop inserting metavariables.
            (MetaInsertion::UntilImplicit(l), AppMode::Implicit(label)) if l == label.0 => break,
            (MetaInsertion::UntilInstance(l), AppMode::Instance(label)) if l == label.0 => break,

            // Based on the given type, we expected an implicit argument to be
            // applied. Instead, let's apply a metavariable argument in its
            // place, to be solved later (during unification).
            (_, AppMode::Implicit(_)) => {
                let arg = context.new_meta(metas, span, param_ty.clone());
                let arg_value = context.eval_term(metas, None, &arg)?;
                term = Rc::from(syntax::Term::FunElim(term, app_mode.clone(), arg));
                term_ty = context.app_closure(metas, body_ty, arg_value)?;
            },

            // TODO: Instance arguments
            (_, AppMode::Instance(label)) => {
                let message = "inference of instance arguments is not yet supported";
                return Err(Diagnostic::new_error(message).with_label(
                    DiagnosticLabel::new_primary(span)
                        .with_message(format!("add the argument `{{{{{} = ..}}}}` here", label)),
                ));
            },
        }
    }

    Ok((term, term_ty))
}
/// Insert metavariables based on the expected type.
Insert metavariables based on the expected type.
Insert metavariables based on the expected type .
fn insert_metas(
    meta_insertion: MetaInsertion<'_>,
    context: &Context,
    metas: &mut meta::Env,
    span: FileSpan,
    mut term: Rc<syntax::Term>,
    term_ty: &Rc<domain::Type>,
) -> Result<(Rc<syntax::Term>, Rc<domain::Type>), Diagnostic<FileSpan>> {
    use mltt_core::domain::Value::FunType;
    let mut term_ty = term_ty.clone();
    while let FunType(app_mode, _, param_ty, body_ty) = term_ty.as_ref() {
        match (meta_insertion, app_mode) {
            // The user requested we stop inserting metavariables, or
            // we have seen an explicit argument, so we stop inserting
            // metavariables.
            (MetaInsertion::No, _) | (_, AppMode::Explicit) => break,
            // FIXME: mismatches?
            // In these cases we see a matching implicit or instance argument
            // being passed, corresponding to the expected parameter in the
            // type. Therefore we stop inserting metavariables.
            (MetaInsertion::UntilImplicit(l), AppMode::Implicit(label)) if l == label.0 => break,
            (MetaInsertion::UntilInstance(l), AppMode::Instance(label)) if l == label.0 => break,
            // Based on the given type, we expected an implicit argument to be
            // applied. Instead, let's apply a metavariable argument in its
            // place, to be solved later (during unification).
            (_, AppMode::Implicit(_)) => {
                let arg = context.new_meta(metas, span, param_ty.clone());
                let arg_value = context.eval_term(metas, None, &arg)?;
                term = Rc::from(syntax::Term::FunElim(term, app_mode.clone(), arg));
                term_ty = context.app_closure(metas, body_ty, arg_value)?;
            },
            // TODO: Instance arguments
            (_, AppMode::Instance(label)) => {
                let message = "inference of instance arguments is not yet supported";
                return Err(Diagnostic::new_error(message).with_label(
                    DiagnosticLabel::new_primary(span)
                        .with_message(format!("add the argument `{{{{{} = ..}}}}` here", label)),
                ));
            },
        }
    }
    Ok((term, term_ty))
}
fn insert_metas ( meta_insertion : MetaInsertion < ' _ > , context : & Context , metas : & mut meta :: Env , span : FileSpan , mut term : Rc < syntax :: Term > , term_ty : & Rc < domain :: Type > , ) -> Result < ( Rc < syntax :: Term > , Rc < domain :: Type > ) , Diagnostic < FileSpan > > { use mltt_core :: domain :: Value :: FunType ; let mut term_ty = term_ty . clone ( ) ; while let FunType ( app_mode , _ , param_ty , body_ty ) = term_ty . as_ref ( ) { match ( meta_insertion , app_mode ) { // The user requested we stop inserting metavariables, or // we have seen an explicit argument, so we stop inserting // metavariables. ( MetaInsertion :: No , _ ) | ( _ , AppMode :: Explicit ) => break , // FIXME: mismatches? // In these cases we see a matching implicit or instance argument // being passed, corresponding to the expected parameter in the // type. Therefore we stop inserting metavariables. ( MetaInsertion :: UntilImplicit ( l ) , AppMode :: Implicit ( label ) ) if l == label . 0 => break , ( MetaInsertion :: UntilInstance ( l ) , AppMode :: Instance ( label ) ) if l == label . 0 => break , // Based on the given type, we expected an implicit argument to be // applied. Instead, let's apply a metavariable argument in its // place, to be solved later (during unification). ( _ , AppMode :: Implicit ( _ ) ) => { let arg = context . new_meta ( metas , span , param_ty . clone ( ) ) ; let arg_value = context . eval_term ( metas , None , & arg ) ? ; term = Rc :: from ( syntax :: Term :: FunElim ( term , app_mode . clone ( ) , arg ) ) ; term_ty = context . app_closure ( metas , body_ty , arg_value ) ? ; } , // TODO: Instance arguments ( _ , AppMode :: Instance ( label ) ) => { let message = " " ; return Err ( Diagnostic :: new_error ( message ) . with_label ( DiagnosticLabel :: new_primary ( span ) . with_message ( format ! ( " " label ) ) , ) ) ; } , } } Ok ( ( term , term_ty ) ) }
Insert metavariables based on the expected type.
Insert metavariables based on the expected type .
meta_insertion
MetaInsertion<'_>
context
&Context
metas
&mut meta::Env
span
FileSpan
term
Rc<syntax::Term>
term_ty
&Rc<domain::Type>
meta_insertion
MetaInsertion<'_>
context
&Context
metas
&mut meta::Env
span
FileSpan
term
Rc<syntax::Term>
term_ty
&Rc<domain::Type>