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

Drop method exported from WASM + removing leaks. #6365

Merged
merged 11 commits into from
Apr 25, 2023
69 changes: 54 additions & 15 deletions app/gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ extern crate core;

use prelude::*;

use wasm_bindgen::prelude::*;

mod profile_workflow;
#[cfg(test)]
mod tests;


// ==============
// === Export ===
Expand All @@ -82,13 +88,9 @@ pub mod transport;

pub use crate::ide::*;
pub use engine_protocol;
use enso_executor::web::EventLoopExecutor;
pub use ide_view as view;



#[cfg(test)]
mod tests;

/// Common types that should be visible across the whole IDE crate.
pub mod prelude {
pub use ast::prelude::*;
Expand Down Expand Up @@ -126,6 +128,12 @@ pub mod prelude {
pub use wasm_bindgen_test::wasm_bindgen_test_configure;
}



// ====================
// === Entry Points ===
// ====================

// These imports are required to have all entry points (such as examples) and `before_main`
// functions (such as the dynamic-asset loader), available in the IDE.
#[allow(unused_imports)]
Expand All @@ -136,13 +144,23 @@ mod imported_for_entry_points {
}
#[allow(unused_imports)]
use imported_for_entry_points::*;
mod profile_workflow;



// ===================
// === Entry Point ===
// ===================
// ====================
// === Global State ===
// ====================

thread_local! {
static EXECUTOR: RefCell<Option<EventLoopExecutor>> = default();
static IDE: RefCell<Option<Result<Ide, FailedIde>>> = default();
}



// =======================
// === IDE Entry Point ===
// =======================

/// IDE startup function.
#[entry_point(ide)]
Expand All @@ -159,16 +177,37 @@ pub fn main() {
"debug_mode_is_active",
analytics::AnonymousData(debug_mode),
);
let config =
crate::config::Startup::from_web_arguments().expect("Failed to read configuration");
let executor = crate::executor::setup_global_executor();
let initializer = crate::ide::initializer::Initializer::new(config);
let config = config::Startup::from_web_arguments().expect("Failed to read configuration");
let executor = executor::setup_global_executor();
EXECUTOR.with(move |global_executor| global_executor.replace(Some(executor)));
let initializer = Initializer::new(config);
executor::global::spawn(async move {
let ide = initializer.start().await;
ensogl::system::web::document
.get_element_by_id("loader")
.map(|t| t.parent_node().map(|p| p.remove_child(&t).unwrap()));
std::mem::forget(ide);
IDE.with(move |global_ide| global_ide.replace(Some(ide)));
});
std::mem::forget(executor);
}



// ================
// === IDE Drop ===
// ================

/// Drop all structure created so far.
///
/// All connections will be closed and all visuals will be removed.
#[wasm_bindgen]
pub fn drop() {
IDE.with(RefCell::take);
EXECUTOR.with(RefCell::take);
leak_detector::TRACKED_OBJECTS.with(|objects| {
let objects = objects.borrow();
if !objects.is_empty() {
error!("Tracked objects leaked after dropping entire application!");
error!("{objects:#?}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this message be prefaced with some info? Maybe error!("Objects that go leaked: {objects:#?}");

}
})
}
23 changes: 11 additions & 12 deletions app/gui/view/graph-editor/src/component/breadcrumbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl display::Object for BreadcrumbsModel {
#[derive(Debug, Clone, CloneRef)]
#[allow(missing_docs)]
pub struct Breadcrumbs {
model: Rc<BreadcrumbsModel>,
model: BreadcrumbsModel,
frp: Frp,
}

Expand All @@ -422,7 +422,7 @@ impl Breadcrumbs {
pub fn new(app: Application) -> Self {
let scene = app.display.default_scene.clone_ref();
let frp = Frp::new();
let model = Rc::new(BreadcrumbsModel::new(app, &frp));
let model = BreadcrumbsModel::new(app, &frp);
let network = &frp.network;

// === Breadcrumb selection ===
Expand All @@ -431,9 +431,8 @@ impl Breadcrumbs {

// === Selecting ===

_breadcrumb_selection <- frp.select_breadcrumb.map(f!([model,frp](index)
frp.source.breadcrumb_select.emit(model.select_breadcrumb(*index));
));
frp.source.breadcrumb_select <+
frp.select_breadcrumb.map(f!((index) model.select_breadcrumb(*index)));


// === Stack Operations ===
Expand Down Expand Up @@ -485,14 +484,14 @@ impl Breadcrumbs {

// === User Interaction ===

eval_ model.project_name.frp.output.mouse_down(frp.select_breadcrumb.emit(0));
eval_ frp.cancel_project_name_editing(model.project_name.frp.cancel_editing.emit(()));
eval_ frp.outside_press(model.project_name.frp.outside_press.emit(()));
frp.select_breadcrumb <+ model.project_name.frp.output.mouse_down.constant(0);
model.project_name.frp.cancel_editing <+ frp.cancel_project_name_editing;
model.project_name.frp.outside_press <+ frp.outside_press;

popped_count <= frp.output.breadcrumb_select.map(|selected| (0..selected.0).collect_vec());
local_calls <= frp.output.breadcrumb_select.map(|selected| selected.1.clone());
eval_ popped_count(frp.source.breadcrumb_pop.emit(()));
eval local_calls((local_call) frp.source.breadcrumb_push.emit(local_call));
frp.source.breadcrumb_pop <+ popped_count.constant(());
frp.source.breadcrumb_push <+ local_calls;


// === Select ===
Expand All @@ -507,8 +506,8 @@ impl Breadcrumbs {

popped_count <= selected.map(|selected| (0..selected.0).collect_vec());
local_calls <= selected.map(|selected| selected.1.clone());
eval_ popped_count(frp.input.debug_pop_breadcrumb.emit(()));
eval local_calls((local_call) frp.input.debug_push_breadcrumb.emit(local_call));
frp.input.debug_pop_breadcrumb <+ popped_count.constant(());
frp.input.debug_push_breadcrumb <+ local_calls;


// === Relayout ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use ensogl::prelude::*;

use crate::application::command::FrpNetworkProvider;
use crate::GraphEditorModelWithNetwork;
use crate::GraphEditorModel;
use crate::NodeId;

use enso_frp as frp;
Expand All @@ -33,11 +33,7 @@ const ANIMATION_LENGTH_COEFFIENT: f32 = 15.0;

/// Initialize edited node growth/shrink animator. It would handle scene layer change for the edited
/// node as well.
pub fn initialize_edited_node_animator(
model: &GraphEditorModelWithNetwork,
frp: &crate::Frp,
scene: &Scene,
) {
pub fn initialize_edited_node_animator(model: &GraphEditorModel, frp: &crate::Frp, scene: &Scene) {
let network = &frp.network();
let out = &frp.output;
let searcher_cam = scene.layers.node_searcher.camera();
Expand Down Expand Up @@ -112,7 +108,7 @@ pub fn initialize_edited_node_animator(

// === Helpers ===

impl GraphEditorModelWithNetwork {
impl GraphEditorModel {
/// Move node to the `edited_node` scene layer, so that it is rendered by the separate camera.
#[profile(Debug)]
fn move_node_to_edited_node_layer(&self, node_id: NodeId) {
Expand Down
Loading