pub fn elaborate_items(
    mut context: ItemContext,
    surface_items: &[surface::Item],
    report: &mut dyn FnMut(Diagnostic),
) -> Vec<core::Item> {
    let mut core_items = Vec::new();

    for item in surface_items.iter() {
        use std::collections::hash_map::Entry;

        match item {
            surface::Item::Alias(alias) => {
                let label = core::Label(alias.name.1.clone());
                let (core_term, ty) = match &alias.ty {
                    Some(surface_ty) => {
                        let context = context.term_context();
                        let core_ty = elaborate_universe(&context, surface_ty, report);
                        let ty = core::semantics::eval(&core_ty);
                        let core_term = check_term(&context, &alias.term, &ty, report);
                        (core::Term::Ann(Arc::new(core_term), Arc::new(core_ty)), ty)
                    }
                    None => synth_term(&context.term_context(), &alias.term, report),
                };

                match context.items.entry(label) {
                    Entry::Vacant(entry) => {
                        let item = core::Alias {
                            span: alias.span,
                            doc: alias.doc.clone(),
                            name: entry.key().clone(),
                            term: core_term,
                        };

                        core_items.push(core::Item::Alias(item));
                        entry.insert((alias.span, ty));
                    }
                    Entry::Occupied(entry) => report(diagnostics::item_redefinition(
                        Severity::Error,
                        context.file_id,
                        entry.key(),
                        alias.span,
                        entry.get().0,
                    )),
                }
            }
            surface::Item::Struct(struct_ty) => {
                let label = core::Label(struct_ty.name.1.clone());
                let field_context = context.field_context();
                let core_fields =
                    elaborate_struct_ty_fields(field_context, &struct_ty.fields, report);

                match context.items.entry(label) {
                    Entry::Vacant(entry) => {
                        let item = core::StructType {
                            span: struct_ty.span,
                            doc: struct_ty.doc.clone(),
                            name: entry.key().clone(),
                            fields: core_fields,
                        };

                        core_items.push(core::Item::Struct(item));
                        entry.insert((
                            struct_ty.span,
                            core::Value::Universe(core::Universe::Format),
                        ));
                    }
                    Entry::Occupied(entry) => report(diagnostics::item_redefinition(
                        Severity::Error,
                        context.file_id,
                        entry.key(),
                        struct_ty.span,
                        entry.get().0,
                    )),
                }
            }
        }
    }

    core_items
}
/// Elaborate items in the surface syntax into items in the core syntax.
Elaborate items in the surface syntax into items in the core syntax.
Elaborate items in the surface syntax into items in the core syntax .
pub fn elaborate_items(
    mut context: ItemContext,
    surface_items: &[surface::Item],
    report: &mut dyn FnMut(Diagnostic),
) -> Vec<core::Item> {
    let mut core_items = Vec::new();
    for item in surface_items.iter() {
        use std::collections::hash_map::Entry;
        match item {
            surface::Item::Alias(alias) => {
                let label = core::Label(alias.name.1.clone());
                let (core_term, ty) = match &alias.ty {
                    Some(surface_ty) => {
                        let context = context.term_context();
                        let core_ty = elaborate_universe(&context, surface_ty, report);
                        let ty = core::semantics::eval(&core_ty);
                        let core_term = check_term(&context, &alias.term, &ty, report);
                        (core::Term::Ann(Arc::new(core_term), Arc::new(core_ty)), ty)
                    }
                    None => synth_term(&context.term_context(), &alias.term, report),
                };
                match context.items.entry(label) {
                    Entry::Vacant(entry) => {
                        let item = core::Alias {
                            span: alias.span,
                            doc: alias.doc.clone(),
                            name: entry.key().clone(),
                            term: core_term,
                        };
                        core_items.push(core::Item::Alias(item));
                        entry.insert((alias.span, ty));
                    }
                    Entry::Occupied(entry) => report(diagnostics::item_redefinition(
                        Severity::Error,
                        context.file_id,
                        entry.key(),
                        alias.span,
                        entry.get().0,
                    )),
                }
            }
            surface::Item::Struct(struct_ty) => {
                let label = core::Label(struct_ty.name.1.clone());
                let field_context = context.field_context();
                let core_fields =
                    elaborate_struct_ty_fields(field_context, &struct_ty.fields, report);
                match context.items.entry(label) {
                    Entry::Vacant(entry) => {
                        let item = core::StructType {
                            span: struct_ty.span,
                            doc: struct_ty.doc.clone(),
                            name: entry.key().clone(),
                            fields: core_fields,
                        };
                        core_items.push(core::Item::Struct(item));
                        entry.insert((
                            struct_ty.span,
                            core::Value::Universe(core::Universe::Format),
                        ));
                    }
                    Entry::Occupied(entry) => report(diagnostics::item_redefinition(
                        Severity::Error,
                        context.file_id,
                        entry.key(),
                        struct_ty.span,
                        entry.get().0,
                    )),
                }
            }
        }
    }
    core_items
}
pub fn elaborate_items ( mut context : ItemContext , surface_items : & [ surface :: Item ] , report : & mut dyn FnMut ( Diagnostic ) , ) -> Vec < core :: Item > { let mut core_items = Vec :: new ( ) ; for item in surface_items . iter ( ) { use std :: collections :: hash_map :: Entry ; match item { surface :: Item :: Alias ( alias ) => { let label = core :: Label ( alias . name . 1 . clone ( ) ) ; let ( core_term , ty ) = match & alias . ty { Some ( surface_ty ) => { let context = context . term_context ( ) ; let core_ty = elaborate_universe ( & context , surface_ty , report ) ; let ty = core :: semantics :: eval ( & core_ty ) ; let core_term = check_term ( & context , & alias . term , & ty , report ) ; ( core :: Term :: Ann ( Arc :: new ( core_term ) , Arc :: new ( core_ty ) ) , ty ) } None => synth_term ( & context . term_context ( ) , & alias . term , report ) , } ; match context . items . entry ( label ) { Entry :: Vacant ( entry ) => { let item = core :: Alias { span : alias . span , doc : alias . doc . clone ( ) , name : entry . key ( ) . clone ( ) , term : core_term , } ; core_items . push ( core :: Item :: Alias ( item ) ) ; entry . insert ( ( alias . span , ty ) ) ; } Entry :: Occupied ( entry ) => report ( diagnostics :: item_redefinition ( Severity :: Error , context . file_id , entry . key ( ) , alias . span , entry . get ( ) . 0 , ) ) , } } surface :: Item :: Struct ( struct_ty ) => { let label = core :: Label ( struct_ty . name . 1 . clone ( ) ) ; let field_context = context . field_context ( ) ; let core_fields = elaborate_struct_ty_fields ( field_context , & struct_ty . fields , report ) ; match context . items . entry ( label ) { Entry :: Vacant ( entry ) => { let item = core :: StructType { span : struct_ty . span , doc : struct_ty . doc . clone ( ) , name : entry . key ( ) . clone ( ) , fields : core_fields , } ; core_items . push ( core :: Item :: Struct ( item ) ) ; entry . insert ( ( struct_ty . span , core :: Value :: Universe ( core :: Universe :: Format ) , ) ) ; } Entry :: Occupied ( entry ) => report ( diagnostics :: item_redefinition ( Severity :: Error , context . file_id , entry . key ( ) , struct_ty . span , entry . get ( ) . 0 , ) ) , } } } } core_items }
Elaborate items in the surface syntax into items in the core syntax.
Elaborate items in the surface syntax into items in the core syntax .
context
ItemContext
surface_items
&[surface::Item]
report
&mut dyn FnMut(Diagnostic)
context
ItemContext
surface_items
&[surface::Item]
report
&mut dyn FnMut(Diagnostic)