Commit graph

518 commits

Author SHA1 Message Date
Tobias Hunger
61af35afe1 Janitor: Fix clippy::needless_update
This leaves some of these issues in, which may be triggered depending on
selected features. `#[allow(needless_update)]` is used to silence those.
2021-08-05 23:41:56 +02:00
Tobias Hunger
24a2021226 Janitor: Fix clippy::needless_borrow 2021-08-04 22:50:35 +02:00
Olivier Goffart
1dab4c35d9 For embedded data, store the extension in the binary
This is usefull for the detection of SVG
2021-08-03 16:15:31 +02:00
Simon Hausmann
b55931e601 Make the new window() accessor in generated C++ code const 2021-08-03 10:32:04 +02:00
Simon Hausmann
e97ecea480 Fix constness in generated C++ API
run(), show() and hide() should not be const, as well as the window() accessor.
2021-08-03 10:32:04 +02:00
Simon Hausmann
341387c8d0 Provide sixtyfps::Window by reference in the generated C++ API 2021-08-03 10:32:04 +02:00
Simon Hausmann
29f5853332 Provide sixtyfps::Window by reference in the Rust API
This also removes Clone from the Window again, to avoid having to face
the question: Does cloning a window duplicate it on the screen?
2021-08-03 10:32:04 +02:00
Simon Hausmann
23da97bc75 minor cleanup
Rename window_ to window_rc for the private window member in the generated C++ struct.
2021-08-03 10:32:04 +02:00
Simon Hausmann
66891a299c Start a new sixtyfps::Window API for Rust, C++, the interpreters and JS
The generated component now provides access to a Window type
via the window() accessor function.

This is part of #333
2021-08-03 10:32:04 +02:00
Simon Hausmann
ee80d2e1bb Fix Image::load_from_path calls in generated Rust code
* Call unwrap() on the Result() returned by `load_from_path` to avoid `error[E0605]: non-primitive cast: `Result<Image, LoadImageError>` as `Image``

Tested manually with resource embedding disabled and compiling the memory game.
2021-08-02 18:39:23 +02:00
Olivier Goffart
2a74603bfa Another fixup 2021-08-02 18:31:46 +02:00
Olivier Goffart
1146cd1ae2 Another fixup 2021-08-02 18:29:03 +02:00
Olivier Goffart
9a07102345 Fixup previous commit 2021-08-02 18:27:16 +02:00
Simon Hausmann
53757331c7 Fix compilation of generated Rust code when not embedding images
We must construct a Path for `load_from_path`, not a SharedString.
2021-08-02 16:52:39 +02:00
Simon Hausmann
a6f3d91778 cleanup: Fix wording in the comment in the Rust code generator regarding the special return handling
Co-authored-by: Olivier Goffart <ogoffart@sixtyfps.io>
2021-08-02 16:32:33 +02:00
Simon Hausmann
fbf3c5fbd0 Minor reduction in generated Rust code (llvm lines)
When setting a constant, we only need to use a closure for the
expression if it contains a return statement.

This saves about ~14000 llvm lines for a debug build of the printer
demo.
2021-08-02 16:32:33 +02:00
Simon Hausmann
52aee8d366 Another minor reduction in generated code
Further build on b3529d1b75 and move the
strong/weak reference dance into the API crate out of the generated
code.

Saves ~21k llvm lines on the printer demo (debug).

It's also possible to move the as_pin_ref() bit, but that didn't
really give any savings overall.
2021-08-01 09:34:36 +02:00
Tobias Hunger
ec7b7f751b Janitor: Fix clippy::or_fun_call 2021-07-30 09:27:48 +02:00
Tobias Hunger
f7f5a33c67 Janitor: Fix clippy::useless_format 2021-07-30 09:27:48 +02:00
Tobias Hunger
f9f05c3c58 Janitor: Fix clippy::map_clone 2021-07-30 09:27:48 +02:00
Simon Hausmann
b3529d1b75 Rust: Speed up compilation times of generated code
The binding setup functions (set_binding, set_animated_binding, etc.)
are taking the binding basically as an `impl Fn() -> T`, which means
each call site creates a new copy. The bodies of these can be quite big.
Since most of our uses follow the pattern of just capturing the
samereduce the number of copies needed parameter, we can reduce the
number of copies needed by providing wrappers.

With rustc 1.54.0 on my mbp and debug, the build time of

    touch ../ui/printerdemo.60
    cargo rustc

goes from 1m:15s down to 42s, and total llvm lines goes from
2079842 down to 1134237.
2021-07-30 09:22:20 +02:00
Simon Hausmann
3f716ae558 Reduce clippy warnings in generated code even more
... by ignoring all style and complexity related lints, since humans don't typically consume the generated code.

Co-authored-by: Olivier Goffart <ogoffart@sixtyfps.io>
2021-07-30 09:20:01 +02:00
Simon Hausmann
3aa0b7bb8d clippy: ignore warning about ref-deref for field-offset access
As per commit f7248a4863 this *is* a necessary thing for us to do.
2021-07-30 09:20:01 +02:00
Simon Hausmann
a2e800abac clippy: ignore single binding in match warning in generated visit_dynamic
This is a harmless warning affecting only readability, so apply it
to the whole module.
2021-07-30 09:20:01 +02:00
Simon Hausmann
11bc09f153 clippy: don't covert self_rc into... the same type in the new() function of generated code 2021-07-30 09:20:01 +02:00
Olivier Goffart
f38ce3c090 Fix the tests 2021-07-29 18:25:23 +02:00
Olivier Goffart
807377ed40 fix warnings 2021-07-23 15:40:11 +02:00
Olivier Goffart
01f11695a7 Properly merge the animation when inlining and removing aliases
Fix #193
Fix #345
2021-07-23 15:25:53 +02:00
Olivier Goffart
ba32777cab Refactoring: move the animation in the PropertyBinding struct
Since they always belong together.

This will help for issue #193
2021-07-23 15:25:53 +02:00
Tobias Hunger
9e224f579c Janitor: Fix clippy::comparison_to_empty 2021-07-23 13:48:52 +02:00
Olivier Goffart
19ad14b6f2 C++: Fix assigning a @linear-gradient to a color property 2021-07-22 14:38:58 +02:00
Simon Hausmann
3146fb7764 internal cleanup: Remove the sixtyfps::testing::HasWindow trait
and replace it with the internal, re-exported WindowHandleAccess
one.

Strictly speaking, this is a breaking change. In practice the
returned type of this trait was in `sixtyfps::re_exports`, so any
public use is questionable :)
2021-07-21 20:33:02 +02:00
Simon Hausmann
eaddbe664e internal cleanup: Rename ComponentWindow to WindowRc
That's all it is nowadays, it's a wrapper around Rc<Window>. It's not an
alias because we need to also "wrap" it to C++ via cbindgen, but that's
about it.
2021-07-21 20:33:02 +02:00
Simon Hausmann
ef184f7f1a internal cleanup: Remove the rest of the ComponentWindow API
Now it just remains a wrapper around the Rc, and it can soon be moved to
the API crate hopefully.
2021-07-21 17:41:12 +02:00
Simon Hausmann
77ea5b7a15 API cleanup: hide the rest of the ComponentWindow "internals" 2021-07-21 17:41:12 +02:00
Simon Hausmann
4c1d9dc03e internal cleanup: Remove the poup functions from ComponentWindow
Use WindowHandleAccess instead. Also the clone()
isn't needed anymore since the function take a self reference instead of an Rc<Self> by value.
2021-07-21 17:41:12 +02:00
Simon Hausmann
e005058285 internal cleanup: remove free_graphics_resource from the public ComponentWindow API
Use the WindowHandleAccess backdoor instead.
2021-07-21 17:41:12 +02:00
Simon Hausmann
3aa959700c Revert "Attempt to fix a stack overflow in debug"
This reverts commit 51836a9457.

This is not needed anymore since PR #322
2021-07-15 12:20:01 +02:00
Simon Hausmann
42110263f6 Simplify field offset access workaround
As suggested by Olivier, we don't need the temporary variable. A ref followed
by immediate deref works just as well.
2021-07-15 12:19:20 +02:00
Simon Hausmann
aaf162d504 rust codegen: clarify comment about stack usage by referencing github issue 2021-07-15 12:19:20 +02:00
Simon Hausmann
30dbcdcaad rust generator: simplify field access code
There's no need for a separate access_self_field_offset function when
we can use format_ident directly.
2021-07-15 12:19:20 +02:00
Simon Hausmann
f7248a4863 Fix stack overflow with Rust generated code in debug builds on Windows
On Windows the default stack size is less than on Linux/macOS and
therefore an issues surfaces that is however operating system agnostic:

Due to inlining we generate quite big inner components with many fields.
Their field offsets are accumulated in the separate FIELD_OFFSETS
struct. The access pattern typically looks like this:

    Self::FIELD_OFFSETS.some_field.apply_pin(...)

This is destructed into at least two smaller operations, fetching
some_field and then calling apply_pin with that field as self parameter.

In Rust debug builds the first operation, unfortunately, ends up making
a full copy of Self::FIELD_OFFSETS into a temporary variable on the
stack. Unfortunately also that stack space isn't reused, so every access
results in a new stack allocation to hold all of the FIELD_OFFSETS
structure (~5kb in the printer demo).

With so many accesses to that in the generated code, we run out of stack
space already in the new() function, in item_tree() as well as in the
Drop impl that also accesses all field offsets.

This patch applies the following workaround that does the trick. The
above expression is replaced with

    {
        let field = &Self::FIELD_OFFSETS.some_field;
        *field
    }.apply_pin(...)

Fixes #133
2021-07-15 12:19:20 +02:00
Tobias Hunger
ca53abdbc7 Janitor: calls to push immediately after creation
This is clippy::vec_init_then_push.
2021-07-15 07:55:06 +02:00
Olivier Goffart
cc8249212d Fix name conflict when having two global with the same name in different files
Give globals an unique id so two global with the same name imported
from different file don't clash

Fixes #159
2021-07-13 14:36:38 +02:00
Olivier Goffart
7193cbeec1 Revert "C++ Fix struct with a field that has the same name as the struct itself"
This reverts commit 9e70e009a2.

This turns out to break CI

Changed the test not to use the same name for a field and the struct
2021-07-09 15:52:28 +02:00
Olivier Goffart
9e70e009a2 C++ Fix struct with a field that has the same name as the struct itself 2021-07-09 14:37:42 +02:00
Olivier Goffart
6ed5044940 Fix rust compilation when using keywords in struct 2021-07-09 13:33:09 +02:00
Olivier Goffart
5c18e100b0 Fix unary operator + in rust 2021-07-09 12:52:18 +02:00
Olivier Goffart
a987b225b5 Collect all used components before inlining
And do some passes before inlining

We will need the list of components before inlining in order to generate
them if we disable inlining

So we can do some passes on each component before they are inlining

I tried to put the flickable pass in that list, but it did not work
if the Flickable itself is the root of a component
2021-07-07 17:58:43 +02:00
Tobias Hunger
e5bdeaa804 Janitor: Remove unnecessary & 2021-07-07 08:42:28 +02:00