Skip to content

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

Merged
bors-servo merged 7 commits into
servo:masterfrom
Manishearth:stylo-autoarray
Jul 14, 2016
Merged

bors-servo merged 7 commits into
servo:masterfrom
Manishearth:stylo-autoarray

Conversation

@Manishearth

@Manishearth Manishearth commented Jun 24, 2016 •

Copy link
Copy Markdown
Member

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
Copy Markdown

Heads up! This PR modifies the following files:

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

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jun 24, 2016
@highfive

Copy link
Copy Markdown

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
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where I need the bindings

@bholley

bholley commented Jun 24, 2016

Copy link
Copy Markdown
Contributor

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

emilio commented Jun 24, 2016 •

Copy link
Copy Markdown
Member

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

emilio commented Jun 24, 2016

Copy link
Copy Markdown
Member

nsTArray<uint8_t>, I meant

@emilio

emilio commented Jun 24, 2016

Copy link
Copy Markdown
Member

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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bholley

bholley commented Jun 24, 2016

Copy link
Copy Markdown
Contributor

@bholley

bholley commented Jun 24, 2016

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member Author

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
Copy Markdown
Member Author

Oh, monomorphization. Ugh.

@emilio

emilio commented Jun 24, 2016

Copy link
Copy Markdown
Member

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

bholley commented Jun 24, 2016

Copy link
Copy Markdown
Contributor

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

emilio commented Jun 24, 2016

Copy link
Copy Markdown
Member

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

@emilio emilio added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jun 27, 2016
@Manishearth

Copy link
Copy Markdown
Member Author

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

emilio commented Jun 28, 2016

Copy link
Copy Markdown
Member

@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

Manishearth commented Jun 28, 2016 •

Copy link
Copy Markdown
Member Author

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

bholley commented Jun 28, 2016

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member Author

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?

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jul 13, 2016
@bors-servo

Copy link
Copy Markdown
Contributor

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

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jul 14, 2016
@emilio

emilio commented Jul 14, 2016

Copy link
Copy Markdown
Member

@bors-servo: r+

Awesome! :)

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 6a378a8 has been approved by emilio

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors. labels Jul 14, 2016
@emilio

emilio commented Jul 14, 2016

Copy link
Copy Markdown
Member

@bors-servo: p=1

  • It makes the repo in sync for stylo development.

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6a378a8 with merge ed985f7...

bors-servo pushed 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
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows

@bors-servo
bors-servo merged commit 6a378a8 into servo:master Jul 14, 2016
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jul 14, 2016
@Manishearth
Manishearth deleted the stylo-autoarray branch July 15, 2016 08:45
@Manishearth

Copy link
Copy Markdown
Member Author

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 pushed 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 pushed 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 pushed 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants