Skip to content

Commit 6e9e66e

Browse files
milianwogoffart
authored andcommitted
Refactor typeregister's BUILTIN_ENUMS => BUILTIN.enums
This will allow us to add more buildin types to this thread local in follow-up patches, to reduce the number of thread local slots.
1 parent 00dec34 commit 6e9e66e

File tree

9 files changed

+29
-19
lines changed

9 files changed

+29
-19
lines changed

internal/compiler/expression_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl BuiltinFunction {
259259
}),
260260
BuiltinFunction::ColorScheme => interned_type!(Function {
261261
return_type: Type::Enumeration(
262-
crate::typeregister::BUILTIN_ENUMS.with(|e| e.ColorScheme.clone()),
262+
crate::typeregister::BUILTIN.with(|e| e.enums.ColorScheme.clone()),
263263
),
264264
args: vec![],
265265
}),

internal/compiler/llr/lower_expression.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::namedreference::NamedReference;
1919
use crate::object_tree::{Element, ElementRc, PropertyAnimation};
2020
use crate::{
2121
expression_tree::{BuiltinFunction, Expression as tree_Expression},
22-
typeregister::BUILTIN_ENUMS,
22+
typeregister::BUILTIN,
2323
};
2424

2525
pub struct ExpressionContext<'a> {
@@ -415,7 +415,7 @@ pub fn lower_animation(a: &PropertyAnimation, ctx: &ExpressionContext<'_>) -> An
415415
(SmolStr::new_static("iteration-count"), Type::Float32),
416416
(
417417
SmolStr::new_static("direction"),
418-
Type::Enumeration(BUILTIN_ENUMS.with(|e| e.AnimationDirection.clone())),
418+
Type::Enumeration(BUILTIN.with(|e| e.enums.AnimationDirection.clone())),
419419
),
420420
(SmolStr::new_static("easing"), Type::Easing),
421421
(SmolStr::new_static("delay"), Type::Int32),
@@ -546,7 +546,7 @@ fn solve_layout(
546546
if let (Some(button_roles), Orientation::Horizontal) = (&layout.dialog_button_roles, o)
547547
{
548548
let cells_ty = cells.ty(ctx);
549-
let e = crate::typeregister::BUILTIN_ENUMS.with(|e| e.DialogButtonRole.clone());
549+
let e = crate::typeregister::BUILTIN.with(|e| e.enums.DialogButtonRole.clone());
550550
let roles = button_roles
551551
.iter()
552552
.map(|r| {
@@ -616,8 +616,8 @@ fn solve_layout(
616616
("padding", padding.ty(ctx), padding),
617617
(
618618
"alignment",
619-
crate::typeregister::BUILTIN_ENUMS
620-
.with(|e| Type::Enumeration(e.LayoutAlignment.clone())),
619+
crate::typeregister::BUILTIN
620+
.with(|e| Type::Enumeration(e.enums.LayoutAlignment.clone())),
621621
bld.alignment,
622622
),
623623
("cells", bld.cells.ty(ctx), bld.cells),
@@ -674,7 +674,7 @@ fn box_layout_data(
674674
let alignment = if let Some(expr) = &layout.geometry.alignment {
675675
llr_Expression::PropertyReference(ctx.map_property_reference(expr))
676676
} else {
677-
let e = crate::typeregister::BUILTIN_ENUMS.with(|e| e.LayoutAlignment.clone());
677+
let e = crate::typeregister::BUILTIN.with(|e| e.enums.LayoutAlignment.clone());
678678
llr_Expression::EnumerationValue(EnumerationValue {
679679
value: e.default_value,
680680
enumeration: e,

internal/compiler/lookup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,10 @@ impl LookupObject for SlintInternal {
823823
f(
824824
"color-scheme",
825825
if style.is_some_and(|s| s.ends_with("-light")) {
826-
let e = crate::typeregister::BUILTIN_ENUMS.with(|e| e.ColorScheme.clone());
826+
let e = crate::typeregister::BUILTIN.with(|e| e.enums.ColorScheme.clone());
827827
Expression::EnumerationValue(e.try_value_from_string("light").unwrap())
828828
} else if style.is_some_and(|s| s.ends_with("-dark")) {
829-
let e = crate::typeregister::BUILTIN_ENUMS.with(|e| e.ColorScheme.clone());
829+
let e = crate::typeregister::BUILTIN.with(|e| e.enums.ColorScheme.clone());
830830
Expression::EnumerationValue(e.try_value_from_string("dark").unwrap())
831831
} else {
832832
Expression::FunctionCall {

internal/compiler/passes/compile_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn compile_path_from_string_literal(
151151
)?;
152152
let path = builder.build();
153153

154-
let event_enum = crate::typeregister::BUILTIN_ENUMS.with(|e| e.PathEvent.clone());
154+
let event_enum = crate::typeregister::BUILTIN.with(|e| e.enums.PathEvent.clone());
155155
let point_type = Type::Struct(Rc::new(Struct {
156156
fields: IntoIterator::into_iter([
157157
(SmolStr::new_static("x"), Type::Float32),

internal/compiler/passes/lower_accessibility.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn apply_builtin(e: &ElementRc) {
6363
let bty = if let Some(bty) = e.borrow().builtin_type() { bty } else { return };
6464
if bty.name == "Text" {
6565
e.borrow_mut().set_binding_if_not_set("accessible-role".into(), || {
66-
let enum_ty = crate::typeregister::BUILTIN_ENUMS.with(|e| e.AccessibleRole.clone());
66+
let enum_ty = crate::typeregister::BUILTIN.with(|e| e.enums.AccessibleRole.clone());
6767
Expression::EnumerationValue(EnumerationValue {
6868
value: enum_ty.values.iter().position(|v| v == "text").unwrap(),
6969
enumeration: enum_ty,

internal/compiler/passes/lower_popups.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn lower_popup_window(
157157
}
158158
},
159159
None => {
160-
let enum_ty = crate::typeregister::BUILTIN_ENUMS.with(|e| e.PopupClosePolicy.clone());
160+
let enum_ty = crate::typeregister::BUILTIN.with(|e| e.enums.PopupClosePolicy.clone());
161161

162162
let mut value = String::from("close-on-click");
163163

internal/compiler/passes/materialize_fake_properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn should_materialize(
116116
} else if prop == "close-policy" {
117117
// PopupWindow::close-policy
118118
return Some(Type::Enumeration(
119-
crate::typeregister::BUILTIN_ENUMS.with(|e| e.PopupClosePolicy.clone()),
119+
crate::typeregister::BUILTIN.with(|e| e.enums.PopupClosePolicy.clone()),
120120
));
121121
}
122122
}

internal/compiler/typeregister.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,18 @@ macro_rules! declare_enums {
7777

7878
i_slint_common::for_each_enums!(declare_enums);
7979

80+
pub struct BuiltinTypes {
81+
pub enums: BuiltinEnums,
82+
}
83+
84+
impl BuiltinTypes {
85+
fn new() -> Self {
86+
Self { enums: BuiltinEnums::new() }
87+
}
88+
}
89+
8090
thread_local! {
81-
pub static BUILTIN_ENUMS: BuiltinEnums = BuiltinEnums::new();
91+
pub static BUILTIN: BuiltinTypes = BuiltinTypes::new();
8292
}
8393

8494
const RESERVED_OTHER_PROPERTIES: &[(&str, Type)] = &[
@@ -163,12 +173,12 @@ pub fn reserved_properties() -> impl Iterator<Item = (&'static str, Type, Proper
163173
("clear-focus", BuiltinFunction::ClearFocusItem.ty(), PropertyVisibility::Public),
164174
(
165175
"dialog-button-role",
166-
Type::Enumeration(BUILTIN_ENUMS.with(|e| e.DialogButtonRole.clone())),
176+
Type::Enumeration(BUILTIN.with(|e| e.enums.DialogButtonRole.clone())),
167177
PropertyVisibility::Constexpr,
168178
),
169179
(
170180
"accessible-role",
171-
Type::Enumeration(BUILTIN_ENUMS.with(|e| e.AccessibleRole.clone())),
181+
Type::Enumeration(BUILTIN.with(|e| e.enums.AccessibleRole.clone())),
172182
PropertyVisibility::Constexpr,
173183
),
174184
]))
@@ -304,7 +314,7 @@ impl TypeRegister {
304314
register.insert_type(Type::Rem);
305315
register.types.insert("Point".into(), logical_point_type());
306316

307-
BUILTIN_ENUMS.with(|e| e.fill_register(&mut register));
317+
BUILTIN.with(|e| e.enums.fill_register(&mut register));
308318

309319
register.supported_property_animation_types.insert(Type::Float32.to_string());
310320
register.supported_property_animation_types.insert(Type::Int32.to_string());
@@ -323,7 +333,7 @@ impl TypeRegister {
323333
($pub_type:ident, Coord) => { Type::LogicalLength };
324334
($pub_type:ident, KeyboardModifiers) => { $pub_type.clone() };
325335
($pub_type:ident, $_:ident) => {
326-
BUILTIN_ENUMS.with(|e| Type::Enumeration(e.$pub_type.clone()))
336+
BUILTIN.with(|e| Type::Enumeration(e.enums.$pub_type.clone()))
327337
};
328338
}
329339
#[rustfmt::skip]

tools/lsp/preview/properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub(super) fn get_properties(
509509
name: "accessible-role".into(),
510510
priority: DEFAULT_PRIORITY - 100,
511511
ty: Type::Enumeration(
512-
i_slint_compiler::typeregister::BUILTIN_ENUMS.with(|e| e.AccessibleRole.clone()),
512+
i_slint_compiler::typeregister::BUILTIN.with(|e| e.enums.AccessibleRole.clone()),
513513
),
514514
declared_at: None,
515515
defined_at: None,

0 commit comments

Comments
 (0)