Changeset - f34349cabe17
[Not reviewed]
0 3 0
MH - 3 years ago 2022-02-25 11:54:59
contact@maxhenger.nl
WIP: Fix bug related to builtin procedure typechecking
3 files changed with 28 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/protocol/parser/mod.rs
Show inline comments
 
@@ -301,7 +301,7 @@ impl Parser {
 
            self.pass_typing.queue_module_definitions(&mut ctx, &mut queue);
 
        };
 
        while !queue.is_empty() {
 
            let top = queue.pop().unwrap();
 
            let top = queue.pop_front().unwrap();
 
            let mut ctx = visitor::Ctx{
 
                heap: &mut self.heap,
 
                modules: &mut self.modules,
 
@@ -421,11 +421,11 @@ fn insert_builtin_function<T: Fn(ProcedureDefinitionId) -> (Vec<(&'static str, P
 
    }).unwrap();
 

	
 
    // Insert into type table
 
    let mut concrete_type = ConcreteType::default();
 
    concrete_type.parts.push(ConcreteTypePart::Function(procedure_id, type_poly_vars.len() as u32));
 

	
 
    for _ in 0..type_poly_vars.len() {
 
        concrete_type.parts.push(ConcreteTypePart::Void); // doesn't matter (I hope...)
 
    }
 
    p.type_table.add_builtin_procedure_type(concrete_type, &type_poly_vars);
 
    // let mut concrete_type = ConcreteType::default();
 
    // concrete_type.parts.push(ConcreteTypePart::Function(procedure_id, type_poly_vars.len() as u32));
 
    //
 
    // for _ in 0..type_poly_vars.len() {
 
    //     concrete_type.parts.push(ConcreteTypePart::Void); // doesn't matter (I hope...)
 
    // }
 
    // p.type_table.add_builtin_procedure_type(concrete_type, &type_poly_vars);
 
}
 
\ No newline at end of file
src/protocol/parser/pass_typing.rs
Show inline comments
 
@@ -42,6 +42,8 @@ macro_rules! debug_log {
 
    };
 
}
 

	
 
use std::collections::VecDeque;
 

	
 
use crate::collections::{ScopedBuffer, ScopedSection, DequeSet};
 
use crate::protocol::ast::*;
 
use crate::protocol::input_source::ParseError;
 
@@ -820,7 +822,7 @@ pub(crate) struct ResolveQueueElement {
 
    pub(crate) reserved_monomorph_index: u32,
 
}
 

	
 
pub(crate) type ResolveQueue = Vec<ResolveQueueElement>;
 
pub(crate) type ResolveQueue = VecDeque<ResolveQueueElement>;
 

	
 
struct InferenceNode {
 
    // filled in during type inference
 
@@ -1145,7 +1147,7 @@ impl PassTyping {
 

	
 
                let concrete_type = ConcreteType{ parts: vec![first_concrete_part] };
 
                let type_id = ctx.types.reserve_procedure_monomorph_type_id(&definition_id, concrete_type, monomorph_index);
 
                queue.push(ResolveQueueElement{
 
                queue.push_back(ResolveQueueElement{
 
                    root_id,
 
                    definition_id,
 
                    reserved_type_id: type_id,
 
@@ -2071,12 +2073,17 @@ impl PassTyping {
 
                    let monomorph_index = procedure_to_check.monomorphs.len() as u32;
 
                    procedure_to_check.monomorphs.push(ProcedureDefinitionMonomorph::new_invalid());
 
                    let type_id = ctx.types.reserve_procedure_monomorph_type_id(&definition_id, signature_type, monomorph_index);
 
                    queue.push(ResolveQueueElement{
 
                        root_id: ctx.heap[definition_id].defined_in(),
 
                        definition_id,
 
                        reserved_type_id: type_id,
 
                        reserved_monomorph_index: monomorph_index,
 
                    });
 

	
 
                    if !procedure_to_check.builtin {
 
                        // Only perform typechecking on the user-defined
 
                        // procedures
 
                        queue.push_back(ResolveQueueElement{
 
                            root_id: ctx.heap[definition_id].defined_in(),
 
                            definition_id,
 
                            reserved_type_id: type_id,
 
                            reserved_monomorph_index: monomorph_index,
 
                        });
 
                    }
 

	
 
                    (type_id, monomorph_index)
 
                };
 
@@ -2102,6 +2109,11 @@ impl PassTyping {
 
            monomorph.argument_types.push(type_id)
 
        }
 

	
 
        println!("DEBUG: For procedure {} with polyargs {:#?}", ctx.heap[self.procedure_id].identifier.value.as_str(), self.poly_vars);
 
        for infer_node in self.infer_nodes.iter() {
 
            println!("DEBUG: [{:?}] has type: {}", infer_node.expr_id, infer_node.expr_type.display_name(&ctx.heap));
 
        }
 

	
 
        // Determine if we have already assigned type indices to the expressions
 
        // before (the indices that, for a monomorph, can retrieve the type of
 
        // the expression).
src/protocol/parser/type_table.rs
Show inline comments
 
@@ -476,7 +476,6 @@ impl PartialEq for MonoSearchKey {
 
            let self_end_index = self.find_end_index(self_index);
 
            let other_end_index = other.find_end_index(other_index);
 

	
 

	
 
            if self_in_use == other_in_use {
 
                if self_in_use {
 
                    // Both are in use, so both parts should be equal
0 comments (0 inline, 0 general)