Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Themes: GAT & MultiTheme #57

Merged
merged 8 commits into from
Feb 18, 2020
Merged

Themes: GAT & MultiTheme #57

merged 8 commits into from
Feb 18, 2020

Conversation

dhardy
Copy link
Collaborator

@dhardy dhardy commented Feb 18, 2020

This PR uses Generic Associated Types to avoid the unsafety around draw_handle and size_handle, fixing a possible memory-safety violation in the process.

Additionally, this uses the stack_dst crate to provide ThemeDst and WindowDst traits (parameterised only by Draw type), which allows MultiTheme to be made more generic and moved into kas. As part of this, we also depend on the unsize nightly feature (although this could be avoided if necessary).

Unfortunately, the Rust's GAT implementation is too immature to enable by default, hence is gated behind the gat feature flag. As such, it doesn't play well with the usage of stack_dst, hence that is behind another flag and the two are mutually incompatible.

This PR therefore complicates testing significantly, as well as any Theme implementation (including the custom-theme example), however I feel it is justified since:

  • generic associated types remove a usage of unsafe (revealing a bug in the process), and are almost certainly the way forward (once the compiler properly supports this)
  • usage of stack_dst allows for a much improved MultiTheme implementation with negligible performance impact and most of the unsafe pushed into a small, shared crate (even if currently it has zero dependencies and few downloads), though it does seem sensible to feature-gate this dependency

Unfortunately the two features do not combine well, not only because of bugs around GATs, but also because stack_dst::ValueA is not parametrisable over lifetimes (probably a dedicated RefA type would be required).

Fixes a borrow violation obscured by unsafe code: Manager
includes TkWindow includes mut ref to kas_wgpu::shared;
shared.theme is also borrowed via draw_handle.
Caveat: does not currently work with enums (rust#69184),
hence MultiTheme is disabled
Unfortunately support for this feature within the compiler
is insufficient (even if we put up with warning messages and
accept another dependency on nightly Rust).
Using this with stack_dst (see next commit) is problematic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant