Giter VIP home page Giter VIP logo

Comments (6)

fmease avatar fmease commented on June 24, 2024

cc @lcnr

from rust.

fmease avatar fmease commented on June 24, 2024

Ofc, I will try to minimize this in the coming hours or days.

from rust.

fmease avatar fmease commented on June 24, 2024

Slightly smaller:

Reproducer (78 LOC)
use std::sync::{Mutex, Arc, Weak};
use std::collections::HashMap;

pub trait Api: Clone {
    type Surface: Surface<A = Self>;
    type Buffer: WasmNotSendSync + 'static;
    type Texture: WasmNotSendSync + 'static;
    type SurfaceTexture: WasmNotSendSync + std::borrow::Borrow<Self::Texture>;
    type TextureView: WasmNotSendSync;
    type Sampler: WasmNotSendSync;
    type QuerySet: WasmNotSendSync;
}

pub trait Surface: WasmNotSendSync {
    type A: Api;
}

pub trait WasmNotSendSync: WasmNotSend + WasmNotSync {}
impl<T: WasmNotSend + WasmNotSync> WasmNotSendSync for T {}

pub trait WasmNotSend: Send {}
impl<T: Send> WasmNotSend for T {}

pub trait WasmNotSync: Sync {}
impl<T: Sync> WasmNotSync for T {}

trait HalApi: Api + 'static {}

struct BindGroup<A: HalApi>(Box<Device<A>>);

struct Device<A: HalApi>(LifetimeTracker<A>);

struct LifetimeTracker<A: HalApi>(
    Vec<Arc<Texture<A>>>,
    ResourceMaps<A>,
    Vec<ActiveSubmission<A>>,
);

struct Buffer<A: HalApi>(
    A::Buffer,
    Arc<Device<A>>,
    std::marker::PhantomData<Buffer<A>>,
    Mutex<Vec<Weak<BindGroup<A>>>>,
);

struct StagingBuffer<A: HalApi>(
    Mutex<Option<A::Buffer>>,
    Arc<Device<A>>,
    std::marker::PhantomData<StagingBuffer<A>>,
);

struct Texture<A: HalApi>(
    Arc<Device<A>>,
    std::marker::PhantomData<Texture<A>>,
    Mutex<Vec<Weak<TextureView<A>>>>,
    Mutex<Vec<Weak<BindGroup<A>>>>,
);

struct TextureView<A: HalApi>(
    A::TextureView,
    Arc<Texture<A>>,
    Arc<Device<A>>,
    std::marker::PhantomData<TextureView<A>>,
);

struct Sampler<A: HalApi>(
    Option<A::Sampler>,
    Arc<Device<A>>,
    std::marker::PhantomData<Self>,
);

struct ResourceMaps<A: HalApi>(
    HashMap<i32, Arc<Buffer<A>>>,
    HashMap<i32, Arc<StagingBuffer<A>>>,
    HashMap<i32, Arc<Texture<A>>>,
    HashMap<i32, Arc<TextureView<A>>>,
    HashMap<i32, Arc<Sampler<A>>>,
    HashMap<i32, Arc<BindGroup<A>>>,
    HashMap<i32, Arc<A>>,
    HashMap<i32, Arc<A>>,
    HashMap<i32, Arc<A>>,
    HashMap<i32, Arc<A>>,
    HashMap<i32, Arc<A>>,
);

struct ActiveSubmission<A: HalApi>(
    ResourceMaps<A>,
    Vec<Arc<Buffer<A>>>,
    Vec<std::marker::PhantomData<A>>,
);

fn main() {
    check::<BindGroup<_>>();
    fn check<T: WasmNotSync>() {}
}

Even smaller:

Reproducer (61 LOC)
use std::sync::{Mutex, Arc, Weak};

pub trait Api {
    type Surface: Surface<A = Self>;
    type Buffer: WasmNotSendSync + 'static;
    type Texture: WasmNotSendSync + 'static;
    type SurfaceTexture: WasmNotSendSync + std::borrow::Borrow<Self::Texture>;
    type TextureView: WasmNotSendSync;
    type Sampler: WasmNotSendSync;
    type QuerySet: WasmNotSendSync;
}

pub trait Surface: WasmNotSendSync {
    type A: Api;
}

pub trait WasmNotSendSync: WasmNotSend + WasmNotSync {}
impl<T: WasmNotSend + WasmNotSync> WasmNotSendSync for T {}

pub trait WasmNotSend: Send {}
impl<T: Send> WasmNotSend for T {}

pub trait WasmNotSync: Sync {}
impl<T: Sync> WasmNotSync for T {}

trait HalApi: Api {}

struct BindGroup<A: HalApi>(Box<Device<A>>);

struct Device<A: HalApi>(ResourceMaps<A>);

struct Buffer<A: HalApi>(
    A::Buffer,
    Arc<Device<A>>,
    std::marker::PhantomData<Buffer<A>>,
    Mutex<Vec<Weak<BindGroup<A>>>>,
);

struct StagingBuffer<A: HalApi>(
    Mutex<Option<A::Buffer>>,
    Arc<Device<A>>,
    std::marker::PhantomData<StagingBuffer<A>>,
);

struct Texture<A: HalApi>(
    Arc<Device<A>>,
    std::marker::PhantomData<Texture<A>>,
    Mutex<Vec<Weak<TextureView<A>>>>,
    Mutex<Vec<Weak<BindGroup<A>>>>,
);

struct TextureView<A: HalApi>(
    A::TextureView,
    Arc<Texture<A>>,
    Arc<Device<A>>,
    std::marker::PhantomData<TextureView<A>>,
);

struct Sampler<A: HalApi>(
    Option<A::Sampler>,
    Arc<Device<A>>,
    std::marker::PhantomData<Self>,
);

struct ResourceMaps<A: HalApi>(
    Arc<Buffer<A>>,
    Arc<StagingBuffer<A>>,
    Arc<TextureView<A>>,
    Arc<Sampler<A>>,
    Arc<BindGroup<A>>,
);

fn main() {
    check::<BindGroup<_>>();
    fn check<T: WasmNotSync>() {}
}

from rust.

fmease avatar fmease commented on June 24, 2024

"Even smaller" (no longer I-hang but still I-compiletime (32.31s on my machine) + I-compilemem (9GB+)):

"Reproducer" (53 LOC)
use std::sync::{Mutex, Arc, Weak};

pub trait HalApi {
    type Surface: Surface<A = Self>;
    type Buffer: WasmNotSendSync;
    type Texture: WasmNotSendSync ;
    type SurfaceTexture: WasmNotSendSync;
    type TextureView: WasmNotSendSync;
    type Sampler: WasmNotSendSync;
}

pub trait Surface: WasmNotSendSync {
    type A: HalApi;
}

pub trait WasmNotSendSync: WasmNotSend + WasmNotSync {}
impl<T: WasmNotSend + WasmNotSync> WasmNotSendSync for T {}

pub trait WasmNotSend: Send {}
impl<T: Send> WasmNotSend for T {}

pub trait WasmNotSync: Sync {}
impl<T: Sync> WasmNotSync for T {}

struct BindGroup<A: HalApi>(Box<Device<A>>);

struct Device<A: HalApi>(ResourceMaps<A>);

struct Buffer<A: HalApi>(
    A::Buffer,
    Arc<Device<A>>,
    std::marker::PhantomData<Buffer<A>>,
    Mutex<Vec<Weak<BindGroup<A>>>>,
);

struct Texture<A: HalApi>(
    Arc<Device<A>>,
    std::marker::PhantomData<Texture<A>>,
    Mutex<Vec<Weak<TextureView<A>>>>,
    Mutex<Vec<Weak<BindGroup<A>>>>,
);

struct TextureView<A: HalApi>(
    A::TextureView,
    Arc<Texture<A>>,
    Arc<Device<A>>,
    std::marker::PhantomData<TextureView<A>>,
);

struct Sampler<A: HalApi>(
    Option<A::Sampler>,
    Arc<Device<A>>,
    std::marker::PhantomData<Self>,
);

struct ResourceMaps<A: HalApi>(
    Arc<Buffer<A>>,
    Arc<TextureView<A>>,
    Arc<Sampler<A>>,
    Arc<BindGroup<A>>,
);

fn main() {
    check::<BindGroup<_>>();
    fn check<T: WasmNotSync>() {}
}

Minimization is prone to distortion (at least with the way I was just pursuing). Stopping right now, will pick it up some other time and will try different approaches that are less aggressive.

from rust.

fmease avatar fmease commented on June 24, 2024

(Replacing I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. with I-compiletime Issue: Problems and improvements with respect to compile times. because I don't think this is a "true" I-hang (spinning/looping indefinitely w/o memory accumulating). For all practical intents and purposes, I would consider the first three reproducers to be I-hang on my machine since proper termination is not observable before OOM death. However, that's only due to resource constraints I presume. On a more powerful machine the original reproducer might eventually terminate properly, I'd wager)

from rust.

lcnr avatar lcnr commented on June 24, 2024

should be fixed by #125981

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.