Skip to content
← Back

src/semantic/types/complement_singletons.ghul

1
namespace Semantic.Types is
2
// The types a narrowing arrived at by eliminating every other
3
// alternative of a closed hierarchy rather than by a test that
4
// checked the value. Under `--submission` a later cell can add an
5
// alternative the elimination never saw, so a use of one is
6
// checked; nothing is ever added outside submission mode.
7
//
8
// Membership is instance identity, which holds only while every
9
// marked type is freshly built where it is marked. A class's own
10
// type object is shared by every value of the class, and marking
11
// that would guard every one of them.
12
class COMPLEMENT_SINGLETONS is
13
_marked: Collections.SET[Type]
14
15
init() is
16
_marked = Collections.SET[Type](Collections.ReferenceEqualityComparer.instance)
17
si
18
19
mark(type: Type?) is
20
if let marked = type then
21
let _ = _marked.add(marked)
22
fi
23
si
24
25
contains(type: Type?) -> bool =>
26
if let asked = type then _marked.contains(asked) else false fi
27
si
28
si