Replace script_plugins with a clippy like rustc driver (named crown) (#30508)

* Remove script_plugins

* Use crown instead of script_plugins

* crown_is_not_used

* Use crown in command base

* bootstrap crown

* tidy happy

* disable sccache

* Bring crown in tree

* Install crown from tree

* fix windows ci

* fix warning

* fix mac

libscript_plugins.dylib is not available anymore

* Update components/script/lib.rs

Co-authored-by: Martin Robinson <mrobinson@igalia.com>

* Update for nightly-2023-03-18

Mostly just based off https://github.com/servo/servo/pull/30630

* Always install crown

it's slow only when there is new version

* Run crown test with `mach test-unit`

* Small fixups; better trace_in_no_trace tests

* Better doc

* crown in config.toml

* Fix tidy for real

* no sccache on rustc_wrapper

* document rustc overrides

* fixup of compiletest

* Make a few minor comment adjustments

* Fix a typo in python/servo/platform/base.py

Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com>

* Proper test types

* Ignore tidy on crown/tests

---------

Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Samson 2023-12-01 16:50:52 +01:00 committed by GitHub
parent 20a73721de
commit 604979e367
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
231 changed files with 881 additions and 680 deletions

View file

@ -42,7 +42,7 @@ pub enum ExceptionHandling {
/// A common base class for representing IDL callback function and
/// callback interface types.
#[derive(JSTraceable)]
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
pub struct CallbackObject {
/// The underlying `JSObject`.
callback: Heap<*mut JSObject>,
@ -63,14 +63,14 @@ pub struct CallbackObject {
}
impl Default for CallbackObject {
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
fn default() -> CallbackObject {
CallbackObject::new()
}
}
impl CallbackObject {
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
fn new() -> CallbackObject {
CallbackObject {
callback: Heap::default(),
@ -133,14 +133,14 @@ pub trait CallbackContainer {
/// A common base class for representing IDL callback function types.
#[derive(JSTraceable, PartialEq)]
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
pub struct CallbackFunction {
object: CallbackObject,
}
impl CallbackFunction {
/// Create a new `CallbackFunction` for this object.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn new() -> CallbackFunction {
CallbackFunction {
object: CallbackObject::new(),
@ -161,7 +161,7 @@ impl CallbackFunction {
/// A common base class for representing IDL callback interface types.
#[derive(JSTraceable, PartialEq)]
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
pub struct CallbackInterface {
object: CallbackObject,
}
@ -241,7 +241,7 @@ pub struct CallSetup {
impl CallSetup {
/// Performs the setup needed to make a call.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn new<T: CallbackContainer>(callback: &T, handling: ExceptionHandling) -> CallSetup {
let global = unsafe { GlobalScope::from_object(callback.callback()) };
if let Some(window) = global.downcast::<Window>() {

View file

@ -6906,7 +6906,7 @@ class CGDictionary(CGThing):
derive = ["JSTraceable"]
mustRoot = ""
if self.membersNeedTracing():
mustRoot = "#[unrooted_must_root_lint::must_root]\n"
mustRoot = "#[crown::unrooted_must_root_lint::must_root]\n"
if not self.hasRequiredFields(self.dictionary):
derive += ["Default"]
@ -7450,7 +7450,7 @@ class CGCallback(CGClass):
constructors=self.getConstructors(),
methods=realMethods,
decorators="#[derive(JSTraceable, PartialEq)]\n"
"#[unrooted_must_root_lint::allow_unrooted_interior]")
"#[crown::unrooted_must_root_lint::allow_unrooted_interior]")
def getConstructors(self):
return [ClassConstructor(

View file

@ -165,7 +165,7 @@ pub mod xmlname;
/// Generated JS-Rust bindings.
#[allow(missing_docs, non_snake_case)]
pub mod codegen {
#[allow(dead_code, unrooted_must_root)]
#[allow(dead_code, crown::unrooted_must_root)]
pub mod Bindings {
include!(concat!(env!("OUT_DIR"), "/Bindings/mod.rs"));
}

View file

@ -80,7 +80,7 @@ impl TrustedPromise {
/// Create a new `TrustedPromise` instance from an existing DOM object. The object will
/// be prevented from being GCed for the duration of the resulting `TrustedPromise` object's
/// lifetime.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn new(promise: Rc<Promise>) -> TrustedPromise {
LIVE_REFERENCES.with(|ref r| {
let r = r.borrow();
@ -130,7 +130,7 @@ impl TrustedPromise {
}
/// A task which will reject the promise.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn reject_task(self, error: Error) -> impl TaskOnce {
let this = self;
task!(reject_promise: move || {
@ -140,7 +140,7 @@ impl TrustedPromise {
}
/// A task which will resolve the promise.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn resolve_task<T>(self, value: T) -> impl TaskOnce
where
T: ToJSValConvertible + Send,
@ -157,7 +157,7 @@ impl TrustedPromise {
/// shared among threads for use in asynchronous operations. The underlying
/// DOM object is guaranteed to live at least as long as the last outstanding
/// `Trusted<T>` instance.
#[unrooted_must_root_lint::allow_unrooted_interior]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct Trusted<T: DomObject> {
/// A pointer to the Rust DOM object of type T, but void to allow
/// sending `Trusted<T>` between threads, regardless of T's sendability.
@ -220,7 +220,7 @@ impl<T: DomObject> Clone for Trusted<T> {
/// The set of live, pinned DOM objects that are currently prevented
/// from being garbage collected due to outstanding references.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub struct LiveDOMReferences {
// keyed on pointer to Rust DOM object
reflectable_table: RefCell<HashMap<*const libc::c_void, Weak<TrustedReference>>>,
@ -244,7 +244,7 @@ impl LiveDOMReferences {
});
}
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
fn addref_promise(&self, promise: Rc<Promise>) {
let mut table = self.promise_table.borrow_mut();
table.entry(&*promise).or_insert(vec![]).push(promise)
@ -294,7 +294,7 @@ fn remove_nulls<K: Eq + Hash + Clone, V>(table: &mut HashMap<K, Weak<V>>) {
}
/// A JSTraceDataOp for tracing reflectors held in LIVE_REFERENCES
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub unsafe fn trace_refcounted_objects(tracer: *mut JSTracer) {
info!("tracing live refcounted references");
LIVE_REFERENCES.with(|ref r| {

View file

@ -42,16 +42,16 @@ where
}
/// A struct to store a reference to the reflector of a DOM object.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
#[derive(MallocSizeOf)]
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
// If you're renaming or moving this field, update the path in plugins::reflector as well
pub struct Reflector {
#[ignore_malloc_size_of = "defined and measured in rust-mozjs"]
object: Heap<*mut JSObject>,
}
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
impl PartialEq for Reflector {
fn eq(&self, other: &Reflector) -> bool {
self.object.get() == other.object.get()

View file

@ -44,8 +44,8 @@ use crate::dom::bindings::trace::{trace_reflector, JSTraceable};
use crate::dom::node::Node;
/// A rooted value.
#[allow(unrooted_must_root)]
#[unrooted_must_root_lint::allow_unrooted_interior]
#[allow(crown::unrooted_must_root)]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct Root<T: StableTraceObject> {
/// The value to root.
value: T,
@ -60,7 +60,7 @@ where
/// Create a new stack-bounded root for the provided value.
/// It cannot outlive its associated `RootCollection`, and it gives
/// out references which cannot outlive this new `Root`.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub unsafe fn new(value: T) -> Self {
unsafe fn add_to_root_list(object: *const dyn JSTraceable) -> *const RootCollection {
assert_in_script();
@ -92,7 +92,7 @@ where
// The JSTraceable impl for Reflector doesn't actually do anything,
// so we need this shenanigan to actually trace the reflector of the
// T pointer in Dom<T>.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
struct ReflectorStackRoot(Reflector);
unsafe impl JSTraceable for ReflectorStackRoot {
unsafe fn trace(&self, tracer: *mut JSTracer) {
@ -111,7 +111,7 @@ where
// The JSTraceable impl for Reflector doesn't actually do anything,
// so we need this shenanigan to actually trace the reflector of the
// T pointer in Dom<T>.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
struct MaybeUnreflectedStackRoot<T>(T);
unsafe impl<T> JSTraceable for MaybeUnreflectedStackRoot<T>
where
@ -316,7 +316,7 @@ where
/// on the stack, the `Dom<T>` can point to freed memory.
///
/// This should only be used as a field in other DOM objects.
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
pub struct Dom<T> {
ptr: ptr::NonNull<T>,
}
@ -341,7 +341,7 @@ impl<T> Dom<T> {
impl<T: DomObject> Dom<T> {
/// Create a Dom<T> from a &T
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn from_ref(obj: &T) -> Dom<T> {
assert_in_script();
Dom {
@ -375,7 +375,7 @@ unsafe impl<T: DomObject> JSTraceable for Dom<T> {
}
/// A traced reference to a DOM object that may not be reflected yet.
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
pub struct MaybeUnreflectedDom<T> {
ptr: ptr::NonNull<T>,
}
@ -384,7 +384,7 @@ impl<T> MaybeUnreflectedDom<T>
where
T: DomObject,
{
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub unsafe fn from_box(value: Box<T>) -> Self {
Self {
ptr: Box::leak(value).into(),
@ -416,7 +416,7 @@ where
/// An unrooted reference to a DOM object for use in layout. `Layout*Helpers`
/// traits must be implemented on this.
#[unrooted_must_root_lint::allow_unrooted_interior]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct LayoutDom<'dom, T> {
value: &'dom T,
}
@ -505,7 +505,7 @@ impl<T> Hash for LayoutDom<'_, T> {
impl<T> Clone for Dom<T> {
#[inline]
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
fn clone(&self) -> Self {
assert_in_script();
Dom {
@ -539,7 +539,7 @@ impl LayoutDom<'_, Node> {
///
/// This should only be used as a field in other DOM objects; see warning
/// on `Dom<T>`.
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
#[derive(JSTraceable)]
pub struct MutDom<T: DomObject> {
val: UnsafeCell<Dom<T>>,
@ -602,7 +602,7 @@ pub(crate) fn assert_in_layout() {
///
/// This should only be used as a field in other DOM objects; see warning
/// on `Dom<T>`.
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
#[derive(JSTraceable)]
pub struct MutNullableDom<T: DomObject> {
ptr: UnsafeCell<Option<Dom<T>>>,
@ -636,14 +636,14 @@ impl<T: DomObject> MutNullableDom<T> {
/// Retrieve a copy of the inner optional `Dom<T>` as `LayoutDom<T>`.
/// For use by layout, which can't use safe types like Temporary.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub unsafe fn get_inner_as_layout(&self) -> Option<LayoutDom<T>> {
assert_in_layout();
(*self.ptr.get()).as_ref().map(|js| js.to_layout())
}
/// Get a rooted value out of this object
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn get(&self) -> Option<DomRoot<T>> {
assert_in_script();
unsafe { ptr::read(self.ptr.get()).map(|o| DomRoot::from_ref(&*o)) }
@ -678,7 +678,7 @@ impl<'a, T: DomObject> PartialEq<Option<&'a T>> for MutNullableDom<T> {
}
impl<T: DomObject> Default for MutNullableDom<T> {
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
fn default() -> MutNullableDom<T> {
assert_in_script();
MutNullableDom {
@ -700,7 +700,7 @@ impl<T: DomObject> MallocSizeOf for MutNullableDom<T> {
///
/// This should only be used as a field in other DOM objects; see warning
/// on `Dom<T>`.
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
pub struct DomOnceCell<T: DomObject> {
ptr: OnceCell<Dom<T>>,
}
@ -711,7 +711,7 @@ where
{
/// Retrieve a copy of the current inner value. If it is `None`, it is
/// initialized with the result of `cb` first.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn init_once<F>(&self, cb: F) -> &T
where
F: FnOnce() -> DomRoot<T>,
@ -722,7 +722,7 @@ where
}
impl<T: DomObject> Default for DomOnceCell<T> {
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
fn default() -> DomOnceCell<T> {
assert_in_script();
DomOnceCell {
@ -738,7 +738,7 @@ impl<T: DomObject> MallocSizeOf for DomOnceCell<T> {
}
}
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
unsafe impl<T: DomObject> JSTraceable for DomOnceCell<T> {
unsafe fn trace(&self, trc: *mut JSTracer) {
if let Some(ptr) = self.ptr.get() {

View file

@ -20,7 +20,7 @@ enum StackEntryKind {
Entry,
}
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
#[derive(JSTraceable)]
struct StackEntry {
global: Dom<GlobalScope>,

View file

@ -100,7 +100,7 @@ unsafe impl<T: JSTraceable> CustomTraceable for OnceCell<T> {
///
/// SAFETY: Inner type must not impl JSTraceable
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[trace_in_no_trace_lint::must_not_have_traceable]
#[crown::trace_in_no_trace_lint::must_not_have_traceable]
pub struct NoTrace<T>(pub T);
impl<T: Display> Display for NoTrace<T> {
@ -130,7 +130,7 @@ impl<T: MallocSizeOf> MallocSizeOf for NoTrace<T> {
/// HashMap wrapper, that has non-jsmanaged keys
///
/// Not all methods are reexposed, but you can access inner type via .0
#[trace_in_no_trace_lint::must_not_have_traceable(0)]
#[crown::trace_in_no_trace_lint::must_not_have_traceable(0)]
#[derive(Clone, Debug)]
pub struct HashMapTracedValues<K, V, S = RandomState>(pub HashMap<K, V, S>);
@ -276,7 +276,7 @@ pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: &Heap<JSVal>)
}
/// Trace the `JSObject` held by `reflector`.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
pub fn trace_reflector(tracer: *mut JSTracer, description: &str, reflector: &Reflector) {
trace!("tracing reflector {}", description);
trace_object(tracer, description, reflector.rootable())
@ -482,7 +482,7 @@ pub use js::gc::RootedTraceableSet;
/// If you have GC things like *mut JSObject or JSVal, use rooted!.
/// If you have an arbitrary number of DomObjects to root, use rooted_vec!.
/// If you know what you're doing, use this.
#[unrooted_must_root_lint::allow_unrooted_interior]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct RootedTraceableBox<T: JSTraceable + 'static>(js::gc::RootedTraceableBox<T>);
unsafe impl<T: JSTraceable + 'static> JSTraceable for RootedTraceableBox<T> {
@ -547,9 +547,9 @@ impl<T: JSTraceable> DerefMut for RootedTraceableBox<T> {
/// Guaranteed to be empty when not rooted.
/// Usage: `rooted_vec!(let mut v);` or if you have an
/// iterator of `DomRoot`s, `rooted_vec!(let v <- iterator);`.
#[allow(unrooted_must_root)]
#[allow(crown::unrooted_must_root)]
#[derive(JSTraceable)]
#[unrooted_must_root_lint::allow_unrooted_interior]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct RootableVec<T: JSTraceable> {
v: Vec<T>,
}
@ -562,7 +562,7 @@ impl<T: JSTraceable> RootableVec<T> {
}
/// A vector of items that are rooted for the lifetime 'a.
#[unrooted_must_root_lint::allow_unrooted_interior]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct RootedVec<'a, T: 'static + JSTraceable> {
root: &'a mut RootableVec<T>,
}

View file

@ -33,14 +33,14 @@ use crate::dom::bindings::trace::JSTraceable;
pub const DOM_WEAK_SLOT: u32 = 1;
/// A weak reference to a JS-managed DOM object.
#[allow(unrooted_must_root)]
#[unrooted_must_root_lint::allow_unrooted_interior]
#[allow(crown::unrooted_must_root)]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct WeakRef<T: WeakReferenceable> {
ptr: ptr::NonNull<WeakBox<T>>,
}
/// The inner box of weak references, public for the finalization in codegen.
#[unrooted_must_root_lint::must_root]
#[crown::unrooted_must_root_lint::must_root]
pub struct WeakBox<T: WeakReferenceable> {
/// The reference count. When it reaches zero, the `value` field should
/// have already been set to `None`. The pointee contributes one to the count.
@ -218,7 +218,7 @@ unsafe impl<T: WeakReferenceable> JSTraceable for MutableWeakRef<T> {
/// A vector of weak references. On tracing, the vector retains
/// only references which still point to live objects.
#[unrooted_must_root_lint::allow_unrooted_interior]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
#[derive(MallocSizeOf)]
pub struct WeakRefVec<T: WeakReferenceable> {
vec: Vec<WeakRef<T>>,
@ -268,7 +268,7 @@ impl<T: WeakReferenceable> DerefMut for WeakRefVec<T> {
/// An entry of a vector of weak references. Passed to the closure
/// given to `WeakRefVec::update`.
#[unrooted_must_root_lint::allow_unrooted_interior]
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
pub struct WeakRefEntry<'a, T: WeakReferenceable> {
vec: &'a mut WeakRefVec<T>,
index: &'a mut usize,