Skip to content

Commit 1a2aff8

Browse files
authored
Revert "compiler: inline components that are used only once" (#7697)
This reverts commit bf716ff. (And also revert the test part of 259756c) This exposed the bug #7693 and more issues mentined in #7693 (comment) Fixes #7693 CC #7680
1 parent 34b115b commit 1a2aff8

File tree

6 files changed

+9
-46
lines changed

6 files changed

+9
-46
lines changed

internal/compiler/passes/inlining.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ pub fn inline(doc: &Document, inline_selection: InlineSelection, diag: &mut Buil
2323
fn inline_components_recursively(
2424
component: &Rc<Component>,
2525
roots: &HashSet<ByAddress<Rc<Component>>>,
26-
used_once: &HashSet<ByAddress<Rc<Component>>>,
2726
inline_selection: InlineSelection,
2827
diag: &mut BuildDiagnostics,
2928
) {
3029
recurse_elem_no_borrow(&component.root_element, &(), &mut |elem, _| {
3130
let base = elem.borrow().base_type.clone();
3231
if let ElementType::Component(c) = base {
3332
// First, make sure that the component itself is properly inlined
34-
inline_components_recursively(&c, roots, used_once, inline_selection, diag);
33+
inline_components_recursively(&c, roots, inline_selection, diag);
3534

3635
if c.parent_element.upgrade().is_some() {
3736
// We should not inline a repeated element
@@ -49,27 +48,24 @@ pub fn inline(doc: &Document, inline_selection: InlineSelection, diag: &mut Buil
4948
|| component.parent_element.upgrade().is_none() && Rc::ptr_eq(elem, &component.root_element)
5049
// We always inline other roots as a component can't be both a sub component and a root
5150
|| roots.contains(&ByAddress(c.clone()))
52-
|| used_once.contains(&ByAddress(c.clone()))
5351
}
5452
} {
5553
inline_element(elem, &c, component, diag);
5654
}
5755
}
5856
});
5957
component.popup_windows.borrow().iter().for_each(|p| {
60-
inline_components_recursively(&p.component, roots, used_once, inline_selection, diag)
58+
inline_components_recursively(&p.component, roots, inline_selection, diag)
6159
})
6260
}
6361
let mut roots = HashSet::new();
64-
let mut used_once = HashSet::new();
6562
if inline_selection == InlineSelection::InlineOnlyRequiredComponents {
6663
for component in doc.exported_roots().chain(doc.popup_menu_impl.iter().cloned()) {
6764
roots.insert(ByAddress(component.clone()));
6865
}
69-
used_once = collect_subcomponents_used_once(doc);
7066
}
7167
for component in doc.exported_roots().chain(doc.popup_menu_impl.iter().cloned()) {
72-
inline_components_recursively(&component, &roots, &used_once, inline_selection, diag);
68+
inline_components_recursively(&component, &roots, inline_selection, diag);
7369
let mut init_code = component.init_code.borrow_mut();
7470
let inlined_init_code = core::mem::take(&mut init_code.inlined_init_code);
7571
init_code.constructor_code.splice(0..0, inlined_init_code.into_values());
@@ -655,35 +651,3 @@ fn element_require_inlining(elem: &ElementRc) -> bool {
655651

656652
false
657653
}
658-
659-
fn collect_subcomponents_used_once(doc: &Document) -> HashSet<ByAddress<Rc<Component>>> {
660-
fn recursive(component: &Rc<Component>, hash: &mut HashMap<ByAddress<Rc<Component>>, bool>) {
661-
match hash.entry(ByAddress(component.clone())) {
662-
std::collections::hash_map::Entry::Occupied(mut o) => {
663-
if !*o.get() {
664-
// We have already set this element (and its children to "set multiple times"
665-
return;
666-
}
667-
// Element used multiple times, visit all children to set them to multiple times too.
668-
*o.get_mut() = false;
669-
}
670-
std::collections::hash_map::Entry::Vacant(v) => {
671-
v.insert(true);
672-
}
673-
}
674-
675-
recurse_elem(&component.root_element, &(), &mut |elem: &ElementRc, &()| {
676-
let ElementType::Component(base_comp) = &elem.borrow().base_type else { return };
677-
recursive(base_comp, hash);
678-
});
679-
for popup in component.popup_windows.borrow().iter() {
680-
recursive(&popup.component, hash);
681-
}
682-
}
683-
// Stores true for elements that are used once, false for elements that are used multiple times;
684-
let mut result = HashMap::new();
685-
for component in doc.exported_roots().chain(doc.popup_menu_impl.iter().cloned()) {
686-
recursive(&component, &mut result);
687-
}
688-
result.into_iter().filter(|(_, v)| *v).map(|(k, _)| k).collect()
689-
}

internal/compiler/tests/syntax/analysis/binding_loop_layout.slint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

44
TC := Rectangle {
5+
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
56
outer := VerticalLayout {
67
// ^error{The binding for the property 'width' is part of a binding loop}
78
// ^^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
@@ -45,7 +46,6 @@ export Test := Rectangle {
4546

4647
tc := TC {
4748
// ^error{The binding for the property 'preferred-width' is part of a binding loop}
48-
// ^^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
4949
width: preferred-width;
5050
// ^error{The binding for the property 'width' is part of a binding loop}
5151
}

internal/compiler/tests/syntax/analysis/binding_loop_layout3.slint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

44
Compo := Rectangle {
5+
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
56

67
property <string> the_text;
78

@@ -24,7 +25,6 @@ Compo := Rectangle {
2425
export Foo := Rectangle {
2526
Compo {
2627
// ^error{The binding for the property 'preferred-width' is part of a binding loop}
27-
// ^^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
2828
the_text: self.preferred-width / 1px;
2929
// ^error{The binding for the property 'the-text' is part of a binding loop}
3030
}

internal/compiler/tests/syntax/analysis/binding_loop_layout4.slint

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ component Foo {
2424
}
2525

2626
component Bar {
27+
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
2728
HorizontalLayout {
2829
// ^error{The binding for the property 'layout-cache' is part of a binding loop}
2930
// ^^error{The binding for the property 'width' is part of a binding loop}
@@ -39,6 +40,4 @@ export component Apps inherits Window {
3940
Bar {}
4041
// ^error{The binding for the property 'preferred-width' is part of a binding loop}
4142
// ^^error{The binding for the property 'width' is part of a binding loop}
42-
// ^^^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
43-
// ^^^^error{The binding for the property 'min-width' is part of a binding loop}
4443
}

internal/compiler/tests/syntax/analysis/binding_loop_layout_if.slint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ component Wrapper {
1515
}
1616

1717
component WrapperInherited inherits Rectangle {
18+
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
1819
VerticalLayout {
1920
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
2021
if root.width > 200px: Rectangle { }
@@ -29,9 +30,8 @@ export component Test inherits Window {
2930
// ^^error{The binding for the property 'width' is part of a binding loop}
3031
// ^^^error{The binding for the property 'layout-cache' is part of a binding loop}
3132
WrapperInherited { }
32-
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
3333
Wrapper { }
3434
// ^error{The binding for the property 'layoutinfo-h' is part of a binding loop}
3535
}
3636
}
37-
}
37+
}

internal/compiler/tests/syntax/basic/dialog.slint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ MyDiag1 := Dialog {
1111
}
1212

1313
MyDiag2 := Dialog {
14+
// ^error{A Dialog must have a single child element that is not StandardButton}
1415
StandardButton { kind: reset; }
1516
StandardButton {
1617
kind: cancel;
@@ -54,7 +55,6 @@ MyDialog4 := Dialog {
5455
export Test := Rectangle {
5556
MyDiag1 {}
5657
MyDiag2 {}
57-
// ^error{A Dialog must have a single child element that is not StandardButton}
5858
MyDiag3 {}
5959
MyDialog4 {}
6060
}

0 commit comments

Comments
 (0)