Skip to content

Commit

Permalink
Auto merge of #18854 - servo:servo-unstable-feature, r=nox
Browse files Browse the repository at this point in the history
Make optional the usage of some unstable features

With `--no-default-features --features default-except-unstable`, more crates can now be compiled on stable Rust. This will help integrate them in rustc’s regression testing and compiler performance benchmarking.

<!-- 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/18854)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Oct 13, 2017
2 parents ba77ffe + 11bd81e commit 78aaa85
Show file tree
Hide file tree
Showing 40 changed files with 548 additions and 235 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/canvas_traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ heapsize = "0.4"
heapsize_derive = "0.1"
ipc-channel = "0.8"
lazy_static = "0.2"
nonzero = {path = "../nonzero"}
offscreen_gl_context = { version = "0.11", features = ["serde"] }
serde = "1.0"
servo_config = {path = "../config"}
Expand Down
3 changes: 1 addition & 2 deletions components/canvas_traits/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@

#![crate_name = "canvas_traits"]
#![crate_type = "rlib"]
#![feature(nonzero)]

#![deny(unsafe_code)]

extern crate core;
extern crate cssparser;
extern crate euclid;
extern crate heapsize;
#[macro_use] extern crate heapsize_derive;
extern crate ipc_channel;
#[macro_use] extern crate lazy_static;
extern crate nonzero;
extern crate offscreen_gl_context;
#[macro_use] extern crate serde;
extern crate servo_config;
Expand Down
6 changes: 3 additions & 3 deletions components/canvas_traits/webgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use core::nonzero::NonZero;
use euclid::Size2D;
use nonzero::NonZeroU32;
use offscreen_gl_context::{GLContextAttributes, GLLimits};
use std::fmt;
use webrender_api;
Expand Down Expand Up @@ -242,13 +242,13 @@ pub enum WebGLCommand {
macro_rules! define_resource_id_struct {
($name:ident) => {
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct $name(NonZero<u32>);
pub struct $name(NonZeroU32);

impl $name {
#[allow(unsafe_code)]
#[inline]
pub unsafe fn new(id: u32) -> Self {
$name(NonZero::new_unchecked(id))
$name(NonZeroU32::new_unchecked(id))
}

#[inline]
Expand Down
3 changes: 2 additions & 1 deletion components/compositing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ ipc-channel = "0.8"
log = "0.3.5"
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
nonzero = {path = "../nonzero"}
profile_traits = {path = "../profile_traits"}
script_traits = {path = "../script_traits"}
servo_config = {path = "../config"}
servo_geometry = {path = "../geometry", features = ["servo"]}
servo_geometry = {path = "../geometry"}
servo_url = {path = "../url"}
style_traits = {path = "../style_traits"}
time = "0.1.17"
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use CompositionPipeline;
use SendableFrameTree;
use compositor_thread::{CompositorProxy, CompositorReceiver};
use compositor_thread::{InitialCompositorState, Msg, RenderListener};
use core::nonzero::NonZero;
use euclid::{Point2D, TypedPoint2D, TypedVector2D, ScaleFactor};
use gfx_traits::Epoch;
use gleam::gl;
use image::{DynamicImage, ImageFormat, RgbImage};
use ipc_channel::ipc::{self, IpcSharedMemory};
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId};
use net_traits::image::base::{Image, PixelFormat};
use nonzero::NonZeroU32;
use profile_traits::time::{self, ProfilerCategory, profile};
use script_traits::{AnimationState, AnimationTickType, ConstellationControlMsg};
use script_traits::{ConstellationMsg, LayoutControlMsg, MouseButton};
Expand Down Expand Up @@ -62,7 +62,7 @@ impl ConvertPipelineIdFromWebRender for webrender_api::PipelineId {
fn from_webrender(&self) -> PipelineId {
PipelineId {
namespace_id: PipelineNamespaceId(self.0),
index: PipelineIndex(NonZero::new(self.1).expect("Webrender pipeline zero?")),
index: PipelineIndex(NonZeroU32::new(self.1).expect("Webrender pipeline zero?")),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions components/compositing/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#![deny(unsafe_code)]
#![feature(nonzero)]

extern crate core;
extern crate euclid;
extern crate gfx_traits;
extern crate gleam;
Expand All @@ -15,6 +13,7 @@ extern crate ipc_channel;
extern crate log;
extern crate msg;
extern crate net_traits;
extern crate nonzero;
extern crate profile_traits;
extern crate script_traits;
extern crate servo_config;
Expand Down
34 changes: 34 additions & 0 deletions components/constellation/constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
self.all_descendant_browsing_contexts_iter(BrowsingContextId::from(top_level_browsing_context_id))
}

#[cfg(feature = "unstable")]
/// The joint session future is the merge of the session future of every
/// browsing_context, sorted chronologically.
fn joint_session_future<'a>(&'a self, top_level_browsing_context_id: TopLevelBrowsingContextId)
Expand All @@ -782,12 +783,26 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
.kmerge_by(|a, b| a.instant.cmp(&b.instant) == Ordering::Less)
}

#[cfg(not(feature = "unstable"))]
/// The joint session future is the merge of the session future of every
/// browsing_context, sorted chronologically.
fn joint_session_future<'a>(&'a self, top_level_browsing_context_id: TopLevelBrowsingContextId)
-> Box<Iterator<Item = &'a SessionHistoryEntry> + 'a>
{
Box::new(
self.all_browsing_contexts_iter(top_level_browsing_context_id)
.map(|browsing_context| browsing_context.next.iter().rev())
.kmerge_by(|a, b| a.instant.cmp(&b.instant) == Ordering::Less)
)
}

/// Is the joint session future empty?
fn joint_session_future_is_empty(&self, top_level_browsing_context_id: TopLevelBrowsingContextId) -> bool {
self.all_browsing_contexts_iter(top_level_browsing_context_id)
.all(|browsing_context| browsing_context.next.is_empty())
}

#[cfg(feature = "unstable")]
/// The joint session past is the merge of the session past of every
/// browsing_context, sorted reverse chronologically.
fn joint_session_past<'a>(&'a self, top_level_browsing_context_id: TopLevelBrowsingContextId)
Expand All @@ -804,6 +819,25 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
.map(|(_, entry)| entry)
}

#[cfg(not(feature = "unstable"))]
/// The joint session past is the merge of the session past of every
/// browsing_context, sorted reverse chronologically.
fn joint_session_past<'a>(&'a self, top_level_browsing_context_id: TopLevelBrowsingContextId)
-> Box<Iterator<Item = &'a SessionHistoryEntry> + 'a>
{
Box::new(
self.all_browsing_contexts_iter(top_level_browsing_context_id)
.map(|browsing_context| browsing_context.prev.iter().rev()
.scan(browsing_context.instant, |prev_instant, entry| {
let instant = *prev_instant;
*prev_instant = entry.instant;
Some((instant, entry))
}))
.kmerge_by(|a, b| a.0.cmp(&b.0) == Ordering::Greater)
.map(|(_, entry)| entry)
)
}

/// Is the joint session past empty?
fn joint_session_past_is_empty(&self, top_level_browsing_context_id: TopLevelBrowsingContextId) -> bool {
self.all_browsing_contexts_iter(top_level_browsing_context_id)
Expand Down
2 changes: 1 addition & 1 deletion components/constellation/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#![deny(unsafe_code)]
#![feature(conservative_impl_trait)]
#![cfg_attr(feature = "unstable", feature(conservative_impl_trait))]
#![feature(mpsc_select)]

extern crate backtrace;
Expand Down
4 changes: 0 additions & 4 deletions components/geometry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ publish = false
name = "servo_geometry"
path = "lib.rs"

[features]
# servo as opposed to geckolib
servo = ["euclid/unstable"]

[dependencies]
app_units = "0.5"
euclid = "0.15"
Expand Down
5 changes: 4 additions & 1 deletion components/gfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ publish = false
name = "gfx"
path = "lib.rs"

[features]
unstable = ["simd"]

[dependencies]
app_units = "0.5"
bitflags = "0.7"
Expand Down Expand Up @@ -58,7 +61,7 @@ servo-fontconfig = "0.2.1"
xml5ever = {version = "0.10"}

[target.'cfg(any(target_feature = "sse2", target_feature = "neon"))'.dependencies]
simd = "0.2.0"
simd = {version = "0.2.0", optional = true}

[target.'cfg(target_os = "windows")'.dependencies]
dwrote = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions components/gfx/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// For SIMD
#![cfg_attr(any(target_os = "linux", target_os = "android"), feature(allocator_api))]
#![feature(cfg_target_feature)]
#![cfg_attr(feature = "unstable", feature(cfg_target_feature))]

#![deny(unsafe_code)]

Expand Down Expand Up @@ -53,6 +52,7 @@ extern crate servo_arc;
extern crate servo_geometry;
extern crate servo_url;
#[macro_use] extern crate servo_atoms;
#[cfg(feature = "unstable")]
#[cfg(any(target_feature = "sse2", target_feature = "neon"))]
extern crate simd;
extern crate smallvec;
Expand Down
47 changes: 30 additions & 17 deletions components/gfx/platform/freetype/font_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use freetype::freetype::FT_Memory;
use freetype::freetype::FT_MemoryRec_;
use freetype::freetype::FT_New_Library;
use heapsize::{HeapSizeOf, heap_size_of};
use std::heap::{Heap, Alloc, Layout};
use std::mem;
use std::os::raw::{c_long, c_void};
use std::ptr;
use std::rc::Rc;
Expand All @@ -25,46 +25,59 @@ pub struct User {
const FT_ALIGNMENT: usize = 1;

extern fn ft_alloc(mem: FT_Memory, req_size: c_long) -> *mut c_void {
assert!(FT_ALIGNMENT == 1);
let mut vec = Vec::<u8>::with_capacity(req_size as usize);
let ptr = vec.as_mut_ptr() as *mut c_void;
mem::forget(vec);

unsafe {
let layout = Layout::from_size_align(req_size as usize, FT_ALIGNMENT).unwrap();
let ptr = Heap.alloc(layout).unwrap() as *mut c_void;
let actual_size = heap_size_of(ptr as *const _);

let user = (*mem).user as *mut User;
(*user).size += actual_size;

ptr
}

ptr
}

extern fn ft_free(mem: FT_Memory, ptr: *mut c_void) {
unsafe {
let actual_size = heap_size_of(ptr as *const _);

let user = (*mem).user as *mut User;
(*user).size -= actual_size;

let layout = Layout::from_size_align(actual_size, FT_ALIGNMENT).unwrap();
Heap.dealloc(ptr as *mut u8, layout);
assert!(FT_ALIGNMENT == 1);
mem::drop(Vec::<u8>::from_raw_parts(ptr as *mut u8, actual_size, 0))
}
}

extern fn ft_realloc(mem: FT_Memory, _cur_size: c_long, new_req_size: c_long,
old_ptr: *mut c_void) -> *mut c_void {
let old_actual_size;
let mut vec;
unsafe {
let old_actual_size = heap_size_of(old_ptr as *const _);
let old_layout = Layout::from_size_align(old_actual_size, FT_ALIGNMENT).unwrap();
let new_layout = Layout::from_size_align(new_req_size as usize, FT_ALIGNMENT).unwrap();
let result = Heap.realloc(old_ptr as *mut u8, old_layout, new_layout);
let new_ptr = result.unwrap() as *mut c_void;
let new_actual_size = heap_size_of(new_ptr as *const _);
old_actual_size = heap_size_of(old_ptr as *const _);
vec = Vec::<u8>::from_raw_parts(old_ptr as *mut u8, old_actual_size, old_actual_size);
};

let new_req_size = new_req_size as usize;
if new_req_size > old_actual_size {
vec.reserve_exact(new_req_size - old_actual_size)
} else if new_req_size < old_actual_size {
vec.truncate(new_req_size);
vec.shrink_to_fit()
}

let new_ptr = vec.as_mut_ptr() as *mut c_void;
mem::forget(vec);

unsafe {
let new_actual_size = heap_size_of(new_ptr as *const _);
let user = (*mem).user as *mut User;
(*user).size += new_actual_size;
(*user).size -= old_actual_size;

new_ptr
}

new_ptr
}

// A |*mut User| field in a struct triggers a "use of `#[derive]` with a raw pointer" warning from
Expand Down
Loading

0 comments on commit 78aaa85

Please sign in to comment.