Goose  Diff

Differences From Artifact [ea0ad1aea6]:

  • File bs/sema/tc-context.cpp — part of check-in [95bdac72ca] at 2022-07-05 22:10:27 on branch trunk — TypeChecking: keep track of nested repetition indices for each sub context (user: zlodo size: 4132)

To Artifact [5c55bd7f8a]:

  • File bs/sema/tc-context.cpp — part of check-in [a2a6841c8b] at 2022-07-18 00:14:42 on branch trunk — Keep track of the repetition depth of pack TVars, and assign a new value index for each repetition of a pack hole (user: zlodo size: 4712)

28
29
30
31
32
33
34
35

36
37
38
39
40

41
42

43
44
45
46
47
48
49

50
51
52
53
54

55
56

57
58
59
60
61
62
63
28
29
30
31
32
33
34

35
36
37
38
39

40
41

42
43
44
45
46
47
48

49
50
51
52
53

54
55

56
57
58
59
60
61
62
63







-
+




-
+

-
+






-
+




-
+

-
+







    m_context( c )
{}

TypeCheckingContext::TypeCheckingContext( Context&& c ) :
    m_context( move( c ) )
{}

uint32_t TypeCheckingContext::getLHSHoleIndex( StringId name ) const
uint32_t TypeCheckingContext::getLHSHoleIndex( StringId name, uint32_t repetitionIndex ) const
{
    if( name == "_"_sid )
        return InvalidIndex;

    HoleName holeName( name, LHSSubContext().namespaceIndex );
    HoleKey holeKey( name, LHSSubContext().namespaceIndex, repetitionIndex );

    auto it = m_pCow->holeDict.find( holeName );
    auto it = m_pCow->holeDict.find( holeKey );
    if( it == m_pCow->holeDict.end() )
        return InvalidIndex;

    return it->second;
}

uint32_t TypeCheckingContext::getRHSHoleIndex( StringId name ) const
uint32_t TypeCheckingContext::getRHSHoleIndex( StringId name, uint32_t repetitionIndex ) const
{
    if( name == "_"_sid )
        return InvalidIndex;

    HoleName holeName( name, RHSSubContext().namespaceIndex );
    HoleKey holeKey( name, RHSSubContext().namespaceIndex, repetitionIndex );

    auto it = m_pCow->holeDict.find( holeName );
    auto it = m_pCow->holeDict.find( holeKey );
    if( it == m_pCow->holeDict.end() )
        return InvalidIndex;

    return it->second;
}

uint32_t TypeCheckingContext::createValue( bool required )
78
79
80
81
82
83
84
85

86
87
88
89
90
91
92
93
94


95
96
97
98
99
100

101
102
103
104
105
106
107
108
109


110
111
112
113
114
115
116
117
118







119
120
121
122
123
124







125
126
127
128
129
130
131
78
79
80
81
82
83
84

85
86
87
88
89
90
91
92


93
94
95
96
97
98
99

100
101
102
103
104
105
106
107


108
109
110
111
112
113
114
115
116


117
118
119
120
121
122
123
124
125
126
127


128
129
130
131
132
133
134
135
136
137
138
139
140
141







-
+







-
-
+
+





-
+







-
-
+
+







-
-
+
+
+
+
+
+
+




-
-
+
+
+
+
+
+
+








    CoW( m_pCow )->values[index] = { m_pCow->values[index].m_term, true };

    if( !m_pCow->values[index].m_term )
        ++m_numUnknownValues;
}

void TypeCheckingContext::setLHSHoleIndex( StringId name, uint32_t index )
void TypeCheckingContext::setLHSHoleIndex( StringId name, uint32_t repetitionIndex, uint32_t index )
{
    if( name == "_"_sid )
    {
        ++m_numAnonymousHoles;
        return;
    }

    HoleName holeName( name, LHSSubContext().namespaceIndex );
    CoW( m_pCow )->holeDict.emplace( holeName, index );
    HoleKey holeKey( name, LHSSubContext().namespaceIndex, repetitionIndex );
    CoW( m_pCow )->holeDict.emplace( holeKey, index );

    if( m_valuesAreRequired )
        setValueRequired( index );
}

void TypeCheckingContext::setRHSHoleIndex( StringId name, uint32_t index )
void TypeCheckingContext::setRHSHoleIndex( StringId name, uint32_t repetitionIndex, uint32_t index )
{
    if( name == "_"_sid )
    {
        ++m_numAnonymousHoles;
        return;
    }

    HoleName holeName( name, RHSSubContext().namespaceIndex );
    CoW( m_pCow )->holeDict.emplace( holeName, index );
    HoleKey holeKey( name, RHSSubContext().namespaceIndex, repetitionIndex );
    CoW( m_pCow )->holeDict.emplace( holeKey, index );

    if( m_valuesAreRequired )
        setValueRequired( index );
}

void TypeCheckingContext::eraseLHSName( StringId name )
{
    HoleName holeName( name, LHSSubContext().namespaceIndex );
    CoW( m_pCow )->holeDict.erase( holeName );
    HoleKey holeKeyMin( name, LHSSubContext().namespaceIndex, 0 );
    HoleKey holeKeyMax( name, LHSSubContext().namespaceIndex, ~0 );

    auto begin = CoW( m_pCow )->holeDict.lower_bound( holeKeyMin );
    auto end = CoW( m_pCow )->holeDict.upper_bound( holeKeyMax );

    CoW( m_pCow )->holeDict.erase( begin, end );
}

void TypeCheckingContext::eraseRHSName( StringId name )
{
    HoleName holeName( name, RHSSubContext().namespaceIndex );
    CoW( m_pCow )->holeDict.erase( holeName );
    HoleKey holeKeyMin( name, RHSSubContext().namespaceIndex, 0 );
    HoleKey holeKeyMax( name, RHSSubContext().namespaceIndex, ~0 );

    auto begin = CoW( m_pCow )->holeDict.lower_bound( holeKeyMin );
    auto end = CoW( m_pCow )->holeDict.upper_bound( holeKeyMax );

    CoW( m_pCow )->holeDict.erase( begin, end );
}

bool TypeCheckingContext::isHoleLocked( uint32_t index ) const
{
    return m_pCow->lockedHoles.find( index ) != m_pCow->lockedHoles.end();
}