tsz_solver/
type_factory.rs1use crate::caches::db::TypeDatabase;
7use crate::types::{
8 CallableShape, ConditionalType, FunctionShape, MappedType, ObjectFlags, ObjectShape,
9 PropertyInfo, TemplateSpan, TupleElement, TypeId, TypeParamInfo,
10};
11use tsz_binder::SymbolId;
12use tsz_common::interner::Atom;
13
14#[derive(Clone, Copy)]
15pub struct TypeFactory<'db> {
16 db: &'db dyn TypeDatabase,
17}
18
19impl<'db> TypeFactory<'db> {
20 pub(crate) fn new(db: &'db dyn TypeDatabase) -> Self {
21 Self { db }
22 }
23
24 #[inline]
25 pub fn literal_string(&self, value: &str) -> TypeId {
26 self.db.literal_string(value)
27 }
28
29 #[inline]
30 pub fn literal_number(&self, value: f64) -> TypeId {
31 self.db.literal_number(value)
32 }
33
34 #[inline]
35 pub fn literal_boolean(&self, value: bool) -> TypeId {
36 self.db.literal_boolean(value)
37 }
38
39 #[inline]
40 pub fn literal_bigint(&self, value: &str) -> TypeId {
41 self.db.literal_bigint(value)
42 }
43
44 #[inline]
45 pub fn literal_bigint_with_sign(&self, negative: bool, digits: &str) -> TypeId {
46 self.db.literal_bigint_with_sign(negative, digits)
47 }
48
49 #[inline]
50 pub fn literal_string_atom(&self, atom: Atom) -> TypeId {
51 self.db.literal_string_atom(atom)
52 }
53
54 #[inline]
55 pub fn union(&self, members: Vec<TypeId>) -> TypeId {
56 self.db.union(members)
57 }
58
59 #[inline]
60 pub fn union2(&self, left: TypeId, right: TypeId) -> TypeId {
61 self.db.union2(left, right)
62 }
63
64 #[inline]
65 pub fn union3(&self, first: TypeId, second: TypeId, third: TypeId) -> TypeId {
66 self.db.union3(first, second, third)
67 }
68
69 #[inline]
70 pub fn intersection(&self, members: Vec<TypeId>) -> TypeId {
71 self.db.intersection(members)
72 }
73
74 #[inline]
75 pub fn array(&self, element: TypeId) -> TypeId {
76 self.db.array(element)
77 }
78
79 #[inline]
80 pub fn tuple(&self, elements: Vec<TupleElement>) -> TypeId {
81 self.db.tuple(elements)
82 }
83
84 #[inline]
85 pub fn object(&self, properties: Vec<PropertyInfo>) -> TypeId {
86 self.db.object(properties)
87 }
88
89 #[inline]
90 pub fn object_with_flags(&self, properties: Vec<PropertyInfo>, flags: ObjectFlags) -> TypeId {
91 self.db.object_with_flags(properties, flags)
92 }
93
94 #[inline]
95 pub fn object_fresh(&self, properties: Vec<PropertyInfo>) -> TypeId {
96 self.db.object_fresh(properties)
97 }
98
99 #[inline]
100 pub fn object_with_index(&self, shape: ObjectShape) -> TypeId {
101 self.db.object_with_index(shape)
102 }
103
104 #[inline]
105 pub fn object_with_flags_and_symbol(
106 &self,
107 properties: Vec<PropertyInfo>,
108 flags: ObjectFlags,
109 symbol: Option<SymbolId>,
110 ) -> TypeId {
111 self.db
112 .object_with_flags_and_symbol(properties, flags, symbol)
113 }
114
115 #[inline]
116 pub fn function(&self, shape: FunctionShape) -> TypeId {
117 self.db.function(shape)
118 }
119
120 #[inline]
121 pub fn callable(&self, shape: CallableShape) -> TypeId {
122 self.db.callable(shape)
123 }
124
125 #[inline]
126 pub fn template_literal(&self, spans: Vec<TemplateSpan>) -> TypeId {
127 self.db.template_literal(spans)
128 }
129
130 #[inline]
131 pub fn conditional(&self, conditional: ConditionalType) -> TypeId {
132 self.db.conditional(conditional)
133 }
134
135 #[inline]
136 pub fn mapped(&self, mapped: MappedType) -> TypeId {
137 self.db.mapped(mapped)
138 }
139
140 #[inline]
141 pub fn reference(&self, symbol: crate::types::SymbolRef) -> TypeId {
142 self.db.reference(symbol)
143 }
144
145 #[inline]
146 pub fn lazy(&self, def_id: crate::def::DefId) -> TypeId {
147 self.db.lazy(def_id)
148 }
149
150 #[inline]
151 pub fn bound_parameter(&self, index: u32) -> TypeId {
152 self.db.bound_parameter(index)
153 }
154
155 #[inline]
156 pub fn recursive(&self, depth: u32) -> TypeId {
157 self.db.recursive(depth)
158 }
159
160 #[inline]
161 pub fn type_param(&self, info: TypeParamInfo) -> TypeId {
162 self.db.type_param(info)
163 }
164
165 #[inline]
166 pub fn type_query(&self, symbol: crate::types::SymbolRef) -> TypeId {
167 self.db.type_query(symbol)
168 }
169
170 #[inline]
171 pub fn enum_type(&self, def_id: crate::def::DefId, structural_type: TypeId) -> TypeId {
172 self.db.enum_type(def_id, structural_type)
173 }
174
175 #[inline]
176 pub fn application(&self, base: TypeId, args: Vec<TypeId>) -> TypeId {
177 self.db.application(base, args)
178 }
179
180 #[inline]
181 pub fn union_preserve_members(&self, members: Vec<TypeId>) -> TypeId {
182 self.db.union_preserve_members(members)
183 }
184
185 #[inline]
186 pub fn readonly_type(&self, inner: TypeId) -> TypeId {
187 self.db.readonly_type(inner)
188 }
189
190 #[inline]
191 pub fn keyof(&self, inner: TypeId) -> TypeId {
192 self.db.keyof(inner)
193 }
194
195 #[inline]
196 pub fn index_access(&self, object_type: TypeId, index_type: TypeId) -> TypeId {
197 self.db.index_access(object_type, index_type)
198 }
199}