From f34349cabe177c29d6dc7c42dc0cb9e542cebadf 2022-02-25 11:54:59 From: MH Date: 2022-02-25 11:54:59 Subject: [PATCH] WIP: Fix bug related to builtin procedure typechecking --- diff --git a/src/protocol/parser/mod.rs b/src/protocol/parser/mod.rs index f8099e570194ba10d7b2caadbf7ec7786b472e32..e55bf6b31adb04d40e19891ed39a219762f616dd 100644 --- a/src/protocol/parser/mod.rs +++ b/src/protocol/parser/mod.rs @@ -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 (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 diff --git a/src/protocol/parser/pass_typing.rs b/src/protocol/parser/pass_typing.rs index 0ce59543f294a55e55c3f573a53640c36b0b76ad..d1cf2c25d0c529597ddcb8945880bedb241529ee 100644 --- a/src/protocol/parser/pass_typing.rs +++ b/src/protocol/parser/pass_typing.rs @@ -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; +pub(crate) type ResolveQueue = VecDeque; 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). diff --git a/src/protocol/parser/type_table.rs b/src/protocol/parser/type_table.rs index 579443f42433b6563c5ffe4dd69bd04db02c38b1..ff31225f5d0a45f17f7bcd4fe54cbe2567d61000 100644 --- a/src/protocol/parser/type_table.rs +++ b/src/protocol/parser/type_table.rs @@ -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