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

WIP smup #119

Closed
wants to merge 116 commits into from
Closed

WIP smup #119

wants to merge 116 commits into from

Conversation

fitzgen
Copy link
Contributor

@fitzgen fitzgen commented Jun 2, 2017

This change is Reviewable

fitzgen and others added 30 commits May 10, 2017 14:58
This needs to make its way upstream
This needs to be ported over to the m-c patch queue.
This fixes safe_extern_statics warnings; see
<rust-lang/rust#36247>.
by changing it to use pointers instead.

Fixes servo#311
We should be able to create a default value for any Heap<*mut T> where *mut T implements
GCMethods<*mut T> and Copy, not just for Heap<*mut JSObject>.
Currently, to create a Heap<T>, one first has to create a Heap<T>::default, and then call
Heap<T>::set. This is a common pattern and therefore should be abstracted behind a method.
We expose several JSAPI functions that are used for tracing. By abstracting these functions behind
a trait we can overload them on the type to be traced.
This is what's required for catch_unwind; there's no need to be stricter.
The only remaining OOL calls are ToWindowIfWindowProxy and JS_WrapValue,
like in the equivalent Gecko function.
Rust-mozjs currently does not define any methods to create instances of HandleValueArray.
Consequently, consumers have to create these instances manually. This is unnecessary boilerplate,
and therefore should be abstracted behind a function.
This should make it harder to use Rooted in an unsound way
(when not using the rooted!() macro).
This ensures no unrooted values linger in the Rooted when it is no longer
rooted.

It should be impossible to access the value after that, but Handles currently
lack the lifetime to prevent that (servo#153).
Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

I totally ignored the first two commits. The rest of the changes all look pretty sensible.

@@ -1,12 +0,0 @@
[package]
Copy link
Member

Choose a reason for hiding this comment

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

Is this being upstreamed? Does it cause problems for us somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cargo will complain about malformed toml files and refuse to look any further.

I upstreamed this into the js/src/make-source-package.sh bundling script that creates the source release tarballs. If we ever want to point directly at a revision of m-c, rather than snapshots in this repo, then we will need another fix.

@@ -1,15 +0,0 @@
[package]
Copy link
Member

Choose a reason for hiding this comment

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

Same question - do we need to automate the removal of these each time we update SpiderMonkey?

@@ -25,7 +26,16 @@ fn build_jsglue_cpp() {

/// Find the public include directory within our mozjs-sys crate dependency.
fn get_mozjs_include_dir() -> path::PathBuf {
let entries = glob::glob("./target/*/build/mozjs_sys-*/out/dist/include")
let out_dir = env::var("OUT_DIR")
Copy link
Member

Choose a reason for hiding this comment

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

The commit message mentions the need for upstreaming. Has this happened? Is this still WIP?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The upstreaming is still theoretical because none of js/rust has actually landed in m-c yet. The m-c patches I had are fairly out of date now, and need to be recreated anyways, so this won't get lost.

@@ -122,6 +122,8 @@ const WHITELIST_TYPES: &'static [&'static str] = &[
"js::Class",
"JS::CompartmentOptions",
"JS::ContextOptions",
"js::DOMCallbacks",
Copy link
Member

Choose a reason for hiding this comment

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

Want to squash this with b778ac1 and 42e2f2b?

@@ -160,6 +160,7 @@ const WHITELIST_TYPES: &'static [&'static str] = &[
"JSType",
"JSValueTag",
"JSValueType",
"JSVersion",
Copy link
Member

Choose a reason for hiding this comment

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

Squash this with earlier whitelisting and subsequent similar commits?

callbacks: &jsapi::JSStructuredCloneCallbacks)
-> bool {
unsafe {
(*self.raw).read(Runtime::get(), vp, callbacks as *const _, ptr::null_mut())
Copy link
Member

Choose a reason for hiding this comment

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

The cast should not be necessary.

callbacks: &jsapi::JSStructuredCloneCallbacks)
-> bool {
unsafe {
(*self.raw).write(Runtime::get(), v, callbacks as *const _, ptr::null_mut())
Copy link
Member

Choose a reason for hiding this comment

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

Cast should not be necessary.

pub fn write(&mut self,
v: jsapi::JS::HandleValue,
callbacks: &jsapi::JSStructuredCloneCallbacks)
-> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Let's return Result<(), ()> instead.


/// Copy the given slice into this buffer. Returns false when an underlying
/// JSAPI call fails.
pub fn write_bytes(&mut self, bytes: &[u8]) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Let's return Result<(), ()>.

@@ -5,7 +5,7 @@
extern crate num_cpus;

use std::env;
use std::path;
// use std::path;
Copy link
Member

Choose a reason for hiding this comment

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

Remove this?

@fitzgen
Copy link
Contributor Author

fitzgen commented Jul 10, 2017

@jdm thanks for the initial pass on review! I pushed some new commits that should address your feedback.

@fitzgen
Copy link
Contributor Author

fitzgen commented Jul 10, 2017

Regarding squashing: I can squash everything that isn't a rebase from servo/rust-mozjs into a single commit before landing. That's probably easiest.

@jdm
Copy link
Member

jdm commented Jul 10, 2017

Approval conditional on getting CI working again, of course.

@fitzgen
Copy link
Contributor Author

fitzgen commented Sep 20, 2017

@UK992, hello! I've been informed that you have helped out with Servo + windows build issues in the past before. If you have the cycles, I'd appreciate some help here (no worries if not!). I can build SpiderMonkey on Windows with MSVC just fine from mozjs/js/src/build.rs. However, when attempting to generate bindings with bindgen and libclang from mozjs/js/rust/build.rs, we trigger static_asserts inside SpiderMonkey. I suspect this has to do with differences between MSVC and libclang and interaction with some sort of build configuration. Note that bindgen and libclang work fine on both macOS and Linux, so there is something Windows specific going on here.

Thanks for your help!

c:\mozilla-central\js\rust\target\debug\build\js-ec9b7e18a60f19d9\out\..\..\mozjs_sys-d599741ab008ce05\out\dist\include\mozilla/Assertions.h:216:1: warning: function declared 'noreturn' should not return [-Winvalid-noreturn]
c:/mozbuild\clang\lib\clang\6.0.0\include\adxintrin.h:35:89: warning: ignoring unsupported 'adx' in the target attribute string [-Wignored-attributes]
c:/mozbuild\clang\lib\clang\6.0.0\include\adxintrin.h:43:89: warning: ignoring unsupported 'adx' in the target attribute string [-Wignored-attributes]
c:\mozilla-central\js\rust\target\debug\build\js-ec9b7e18a60f19d9\out\..\..\mozjs_sys-d599741ab008ce05\out\dist\include\js/Utility.h:270:12: warning: 'strdup' is deprecated: The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. [-Wdeprecated-declarations]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\ucrt\string.h:537:20: note: 'strdup' has been explicitly marked deprecated here
c:\mozilla-central\js\rust\target\debug\build\js-ec9b7e18a60f19d9\out\..\..\mozjs_sys-d599741ab008ce05\out\dist\include\js/RootingAPI.h:692:8: warning: 'dllimport' attribute ignored [-Wignored-attributes]
c:\mozilla-central\js\rust\target\debug\build\js-ec9b7e18a60f19d9\out\..\..\mozjs_sys-d599741ab008ce05\out\dist\include\js/Value.h:912:9: error: static_assert failed "JS_STATIC_ASSERT"
c:\mozilla-central\js\rust\target\debug\build\js-ec9b7e18a60f19d9\out\..\..\mozjs_sys-d599741ab008ce05\out\dist\include\js/Value.h:950:1: error: static_assert failed "Value size must leave three tag bits, be a binary power, and is ubiquitously depended upon everywhere"
thread 'main' panicked at 'Should generate JSAPI bindings OK: ()', src\libcore\result.rs:906:4
stack backtrace:
   0: std::sys_common::backtrace::_print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:94
   1: std::panicking::default_hook::{{closure}}
             at C:\projects\rust\src\libstd\panicking.rs:380
   2: std::panicking::default_hook
             at C:\projects\rust\src\libstd\panicking.rs:397
   3: std::panicking::rust_panic_with_hook
             at C:\projects\rust\src\libstd\panicking.rs:611
   4: std::panicking::begin_panic<alloc::string::String>
             at C:\projects\rust\src\libstd\panicking.rs:572
   5: std::panicking::begin_panic_fmt
             at C:\projects\rust\src\libstd\panicking.rs:522
   6: std::panicking::rust_begin_panic
             at C:\projects\rust\src\libstd\panicking.rs:498
   7: core::panicking::panic_fmt
             at C:\projects\rust\src\libcore\panicking.rs:71
   8: core::result::unwrap_failed<()>
             at C:\projects\rust\src\libcore\macros.rs:41
   9: core::result::Result<bindgen::Bindings, ()>::expect<bindgen::Bindings,()>
             at C:\projects\rust\src\libcore\result.rs:799
  10: build_script_build::build_jsapi_bindings
             at .\build.rs:175
  11: build_script_build::main
             at .\build.rs:23
  12: panic_unwind::__rust_maybe_catch_panic
             at C:\projects\rust\src\libpanic_unwind\lib.rs:99
  13: std::rt::lang_start
             at C:\projects\rust\src\libstd\rt.rs:54
  14: main
  15: __scrt_common_main_seh
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:283
  16: BaseThreadInitThunk

@fitzgen fitzgen mentioned this pull request Sep 20, 2017
@bors-servo
Copy link
Contributor

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

@atouchet
Copy link
Contributor

Can this be closed now?

@jdm jdm closed this Aug 21, 2018
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.

None yet