Changeset - 149b39c6603f
[Not reviewed]
0 2 0
MH - 3 years ago 2022-02-25 11:59:37
contact@maxhenger.nl
Disable type deduplication for now
2 files changed with 13 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/protocol/parser/type_table.rs
Show inline comments
 
@@ -33,12 +33,14 @@
 
 *
 
 * As a final bit of global documentation: non-polymorphic types will always
 
 * have one "monomorph" entry. This contains the non-polymorphic type's memory
 
 * layout.
 
 */
 

	
 
// Programmer note: deduplication of types is currently disabled, see the
 
// @Deduplication key. Tests might fail when it is re-enabled.
 
use std::collections::HashMap;
 
use std::hash::{Hash, Hasher};
 

	
 
use crate::protocol::ast::*;
 
use crate::protocol::parser::symbol_table::SymbolScope;
 
use crate::protocol::input_source::ParseError;
 
@@ -449,16 +451,16 @@ impl MonoSearchKey {
 
    }
 
}
 

	
 
impl Hash for MonoSearchKey {
 
    fn hash<H: Hasher>(&self, state: &mut H) {
 
        for index in 0..self.parts.len() {
 
            let (flags, part) = self.parts[index];
 
            if flags & Self::KEY_IN_USE != 0 {
 
            let (_flags, part) = self.parts[index];
 
            // if flags & Self::KEY_IN_USE != 0 { @Deduplication
 
            part.hash(state);
 
            }
 
            // }
 
        }
 
    }
 
}
 

	
 
impl PartialEq for MonoSearchKey {
 
    fn eq(&self, other: &Self) -> bool {
 
@@ -466,14 +468,14 @@ impl PartialEq for MonoSearchKey {
 
        let mut other_index = 0;
 

	
 
        while self_index < self.parts.len() && other_index < other.parts.len() {
 
            // Retrieve part and flags
 
            let (self_bits, _) = self.parts[self_index];
 
            let (other_bits, _) = other.parts[other_index];
 
            let self_in_use = (self_bits & Self::KEY_IN_USE) != 0;
 
            let other_in_use = (other_bits & Self::KEY_IN_USE) != 0;
 
            let self_in_use = true; // (self_bits & Self::KEY_IN_USE) != 0; @Deduplication
 
            let other_in_use = true; // (other_bits & Self::KEY_IN_USE) != 0; @Deduplication
 

	
 
            // Determine ending indices
 
            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 {
 
@@ -2175,13 +2177,13 @@ impl TypeTable {
 
            CTP::Character | CTP::String => {
 
                debug_assert_eq!(type_parts.len(), 1);
 
                search_key.set_top_type(type_parts[0]);
 
            },
 
            // Builtin types with a single nested type
 
            CTP::Array | CTP::Slice | CTP::Input | CTP::Output | CTP::Pointer => {
 
                debug_assert_eq!(type_parts.len(), 2);
 
                debug_assert_eq!(type_parts[0].num_embedded(), 1);
 
                search_key.set(type_parts, &POLY_VARS_IN_USE[..1])
 
            },
 
            // User-defined types
 
            CTP::Tuple(_) => {
 
                Self::set_search_key_to_tuple(search_key, definition_map, type_parts);
 
            },
src/protocol/tests/parser_monomorphs.rs
Show inline comments
 
@@ -54,13 +54,13 @@ fn test_enum_monomorphs() {
 
        .assert_has_monomorph("Answer")
 
        .assert_size_alignment("Answer", 1, 1);
 
    });
 

	
 
    // Note for reader: because the enum doesn't actually use the polymorphic
 
    // variable, we expect to have 1 monomorph: the type only has to be laid
 
    // out once.
 
    // out once. @Deduplication
 
    Tester::new_single_source_expect_ok(
 
        "single polymorph",
 
        "
 
        enum Answer<T> { Yes, No }
 
        func instantiator() -> s32 {
 
            auto a = Answer<s8>::Yes;
 
@@ -68,14 +68,16 @@ fn test_enum_monomorphs() {
 
            auto c = Answer<s32>::Yes;
 
            auto d = Answer<Answer<Answer<s64>>>::No;
 
            return 0;
 
        }
 
        "
 
    ).for_enum("Answer", |e| { e
 
        .assert_num_monomorphs(1)
 
        .assert_has_monomorph("Answer<s8>");
 
        .assert_num_monomorphs(3)
 
        .assert_has_monomorph("Answer<s8>")
 
        .assert_has_monomorph("Answer<s32>")
 
        .assert_has_monomorph("Answer<Answer<Answer<s64>>>");
 
    });
 
}
 

	
 
#[test]
 
fn test_union_monomorphs() {
 
    Tester::new_single_source_expect_ok(
0 comments (0 inline, 0 general)