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

Add support for gecko-only array values; use for stylo #11851

Merged
merged 7 commits into from Jul 14, 2016

Conversation

@Manishearth
Copy link
Member

Manishearth commented Jun 24, 2016

Doesn't yet work, because I can't grow nsTArrays from Rust. If anyone knows how to add bindings for that, let me know!

Thoughts on the design so far? Once this PR lands, all of the array-accepting background- properties can just use gecko_autoarray_longhand and some iterators in the geckolib implementation without changing much other code to work with arrays.

cc @emilio @bholley


This change is Reviewable

@highfive
Copy link

highfive commented Jun 24, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/longhand/background.mako.rs, components/style/properties/helpers.mako.rs
@highfive
Copy link

highfive commented Jun 24, 2016

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify style code, but no tests are modified. Please consider adding a test!
@Manishearth Manishearth assigned emilio and unassigned mbrubeck Jun 24, 2016
@Manishearth Manishearth force-pushed the Manishearth:stylo-autoarray branch from 6e9eaeb to 871bb57 Jun 24, 2016
self.gecko.mImage.mImageCount = cmp::max(self.gecko.mImage.mLayers.len() as u32,
self.gecko.mImage.mImageCount);

// TODO: pre-grow the nsTArray to the right capacity

This comment has been minimized.

@Manishearth

Manishearth Jun 24, 2016

Author Member

This is where I need the bindings


// TODO: pre-grow the nsTArray to the right capacity
// otherwise the below code won't work
for (image, geckoimage) in images.0.into_iter().zip(self.gecko.mImage.mLayers.iter_mut()) {

This comment has been minimized.

@Manishearth

Manishearth Jun 24, 2016

Author Member

Github doesn't show this diff well, but the below code is simply indented one level with a change to the Gecko_SetGradientImageValue line

"<thing> [ , <thing> ]*", but only support a single value
in servo
</%doc>
<%def name="gecko_autoarray_longhand(name, **kwargs)">

This comment has been minimized.

@Manishearth

Manishearth Jun 24, 2016

Author Member

once servo starts supporting <thing> [ , <thing> ]* properties we can refactor this to work in general and have a thin conditional-compile wrapper around it.

@bholley
Copy link
Contributor

bholley commented Jun 24, 2016

Nice! In terms of reallocating, I think we should just do an FFI call, otherwise there's lots of stuff we need to worry about.

Didn't look too closely here, @emilio should probably review since he did the initial array stuff. But it's great to see a clean and easy abstraction on this stuff! :-)

@emilio
Copy link
Member

emilio commented Jun 24, 2016

Yeah, reallocating is basically why I didn't made a more vec-like interface for nsTArray.

I can't probably take a deeper look today (I'm packing things), but yeah, I'd go with the FFI call to reallocate.

Probably we could share allocators (I already had a patch for it, though I need to double-check it does the correct thing evrrywhere), but for now I think we should try to avoid duplicating all the logic there.

If a template function with a pointer to the nsTArray doesn't work (I don't think it'd work, since the functions won't ever be instantiated), probably passing the size of the element would be sufficient, though it'd require to do a bit more math.

Probably receiving a size and a pointer to nsTArray<uint8_t>, and reallocate to n * size elements could work.

I can prioritize the allocator patch though, if you'd prefer to try to write that logic in rust.

@emilio
Copy link
Member

emilio commented Jun 24, 2016

nsTArray<uint8_t>, I meant

@emilio
Copy link
Member

emilio commented Jun 24, 2016

Ugh, github mobile strips my less than signs, I meant an nsTArray of uint8_t


impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.0.len() >= 1 {

This comment has been minimized.

@emilio

emilio Jun 24, 2016

Member

This is probably a bit more tricky. In some props we might need to write none in the empty case, eg, animation-name.

This comment has been minimized.

@emilio

emilio Jul 5, 2016

Member

Oh, also: !self.0.is_empty()

single_value::parse(context, parser)
}).map(|ok| SpecifiedValue(ok))
}
impl ToComputedValue for SpecifiedValue {

This comment has been minimized.

@emilio

emilio Jun 24, 2016

Member

Some (most?) of these properties are computed-value as specified, which would just involve a generic clone which would be cheaper.

I'm not opposed to land this as is, but I'd want a note about that here.

@bholley
Copy link
Contributor

bholley commented Jun 24, 2016

I think you can force-instantiate a generic function in C++. Something like http://stackoverflow.com/a/2155790/3670407 in the cpp file.

@bholley
Copy link
Contributor

bholley commented Jun 24, 2016

Oh I guess the issue here is that we don't necessarily know the type we want it for in C++? I guess in that case just passing a size might be better.

@Manishearth
Copy link
Member Author

Manishearth commented Jun 24, 2016

Is the allocator patch necessary? I was hoping we could call whatever grow function gecko uses through FFI; I just don't yet know which function that is (havent really looked), and what button to press to get bindings for it.

That way we can use whatever reallcoation logic that gecko uses. And we are not dependent on shared allocators.

@Manishearth
Copy link
Member Author

Manishearth commented Jun 24, 2016

Oh, monomorphization. Ugh.

@emilio
Copy link
Member

emilio commented Jun 24, 2016

Oh, sure you can force-instantiate it, and we can probably know most if not all of the types we'd need. I don't want to know what MSVC would think about that though :P

So yea, I'd go for an ffi fn like:

void Gecko_ResizeArray(nsTArray<uint8_t>* arr, uint32_t n, uint32_t element_size);
@bholley
Copy link
Contributor

bholley commented Jun 24, 2016

If there are only a couple of types, it might be nicer to just have explicit separate FFI calls for each T to avoid too much scary munging. Is it more like 3 or more like 15?

@emilio
Copy link
Member

emilio commented Jun 24, 2016

I think there were about 6 different types in the layers structure, and a few more at least.

@Manishearth
Copy link
Member Author

Manishearth commented Jun 27, 2016

So, https://dxr.mozilla.org/mozilla-central/source/xpcom/glue/nsTArray.h#380 exists and is really all we need here. It is not parametrized on the type, just on the ActualAlloc (not sure what actualalloc we use, or what exactly that is). So it will always be monomorphized.

How do I get bindings to this?

@emilio
Copy link
Member

emilio commented Jun 28, 2016

@Manishearth So our nsTArray bindings are bindings to an actual simpler replacement of nsTArray (search for nsTArray_Simple.

That doesn't change the way we can generate bindings to it though, and it'd be creating a gecko function with the signature as above, and just calling that other function from gecko instead of doing it manually.

@Manishearth
Copy link
Member Author

Manishearth commented Jun 28, 2016

I'm having tons of trouble building bindgen.

First, I tried using llvm38, getting the following error:

"_clang_Cursor_isFunctionInlined", referenced from:
bindgen::clang::Cursor::is_inlined_function::hbf3ecb6d1f288ea8 in libbindgen.rlib(bindgen.0.o)

I have a local clone of LLVM that is close to trunk (cloned a month ago), which I installed. This made the bindgen build work. (I later ran brew install llvm --head which also worked)

Then when running bindgen I get obj-x86_64-apple-darwin15.3.0//dist/include/mozilla/mozalloc.h:16:12: fatal error: 'new' file not found. If I include m-c/build/stlport/stlport/, that goes away and I get a similar error for cstddef. Fixing that by explicitly including /usr/include/c++/4.2.1/ seems to get rid of all the include errors, but now I have errors like:

unsupported type `?` (obj-x86_64-apple-darwin15.3.0//dist/include/mozilla/ServoBindings.h:37:31)
unsupported type `?` (obj-x86_64-apple-darwin15.3.0//dist/include/mozilla/ServoBindings.h:174:36)

The bindings files are just emptied out.

I'm pretty sure I've done something wrong at this point 😄

Could someone with a working bindgen setup explain how theirs was set up? Preferably on a mac.

@bholley
Copy link
Contributor

bholley commented Jun 28, 2016

Yeah, you need to brew install llvm38. We don't actually need the tip stuff for stylo, so @emilio is going to make that dep optional.

For the headers, you need to make sure your standard library is installed to /usr/local. On mac, I think xcode-select --install should do it.

@Manishearth
Copy link
Member Author

Manishearth commented Jun 28, 2016

I did run xcode-select --install, it seemed to already exist. Mine are in /usr/include though. They work when used on an external C++ file; just seems like bindgen can't find them.

So currently we need to use llvm tip to get things working, right? llvm38 is just a future goal?

@Manishearth Manishearth force-pushed the Manishearth:stylo-autoarray branch from f0dd478 to c0c4b34 Jul 13, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Jul 14, 2016

The latest upstream changes (presumably #12339) made this pull request unmergeable. Please resolve the merge conflicts.

@Manishearth Manishearth force-pushed the Manishearth:stylo-autoarray branch from c0c4b34 to 209255b Jul 14, 2016
@emilio
Copy link
Member

emilio commented Jul 14, 2016

@bors-servo: r+

Awesome! :)

@bors-servo
Copy link
Contributor

bors-servo commented Jul 14, 2016

📌 Commit 6a378a8 has been approved by emilio

@emilio
Copy link
Member

emilio commented Jul 14, 2016

@bors-servo: p=1

  • It makes the repo in sync for stylo development.
@bors-servo
Copy link
Contributor

bors-servo commented Jul 14, 2016

Testing commit 6a378a8 with merge ed985f7...

bors-servo added a commit that referenced this pull request Jul 14, 2016
Add support for gecko-only array values; use for stylo

Doesn't yet work, because I can't grow nsTArrays from Rust. If anyone knows how to add bindings for that, let me know!

Thoughts on the design so far? Once this PR lands, all of the array-accepting background- properties can just use gecko_autoarray_longhand and some iterators in the geckolib implementation without changing much other code to work with arrays.

cc @emilio @bholley

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11851)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jul 14, 2016

@bors-servo bors-servo merged commit 6a378a8 into servo:master Jul 14, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@Manishearth Manishearth deleted the Manishearth:stylo-autoarray branch Jul 15, 2016
@Manishearth
Copy link
Member Author

Manishearth commented Jul 15, 2016

First, we probably want a fast path for the "computed value as specified case", so an arg here like computed_value_as_specified=False, and then skipping all the re-declaration of the computed values and just do impl ComputedValueAsSpecified for computed_value::T {}.

This doesn't actually work in this case, because the values aren't the same. One is computed::Image, the other is specified::Image (they differ because the linear gradients contain lengths which are represented differently once computed)

bors-servo added a commit that referenced this pull request Jul 15, 2016
Cleanups in autoarray helper

Addresses @emilio's comments from #11851

- Replace gecko_autoarray_longhand with vector_longhand, make it configurable
- Allow for empty vectors, use empty vector longhand in box-shadow

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12458)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jul 16, 2016
Cleanups in autoarray helper

Addresses @emilio's comments from #11851

- Replace gecko_autoarray_longhand with vector_longhand, make it configurable
- Allow for empty vectors, use empty vector longhand in box-shadow

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12458)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Jul 16, 2016
Cleanups in autoarray helper

Addresses @emilio's comments from #11851

- Replace gecko_autoarray_longhand with vector_longhand, make it configurable
- Allow for empty vectors, use empty vector longhand in box-shadow

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12458)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.