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

feat: visualize latex document #406

Merged
merged 17 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 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 crates/abstractions/idx-arena/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
doctest = false

[dependencies]
serde.workspace = true
# abstractions
salsa.workspace = true
# utils
Expand Down
17 changes: 17 additions & 0 deletions crates/abstractions/idx-arena/src/arena_idx.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
use crate::*;
use serde::{Deserialize, Serialize};
use std::{num::NonZeroU32, ops::AddAssign};

pub struct ArenaIdx<T> {
raw: NonZeroU32,
phantom: PhantomData<T>,
}

impl<T> Serialize for ArenaIdx<T> {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
serializer.serialize_u32(self.raw.get())
}
}

impl<'de, T> Deserialize<'de> for ArenaIdx<T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let raw = u32::deserialize(deserializer)?;
Ok(Self::new(raw as usize))
}
}

#[test]
fn option_arena_idx_size_works() {
assert_eq!(
Expand Down
10 changes: 10 additions & 0 deletions crates/abstractions/idx-arena/src/ordered_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ impl<T, V> ArenaOrderedMap<T, V> {
pub unsafe fn insert_next_unchecked(&mut self, v: V) {
self.data.push(v)
}

pub fn insert_next_batch(
&mut self,
items: impl IntoIterator<Item = ArenaIdx<T>>,
comments: impl IntoIterator<Item = V>,
) {
for (idx, comment) in items.into_iter().zip(comments) {
self.insert_next(idx, comment);
}
}
}

impl<T, V> std::ops::Index<ArenaIdx<T>> for ArenaOrderedMap<T, V> {
Expand Down
44 changes: 44 additions & 0 deletions crates/devtime/husky-devtime/src/figure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::Devtime;
use husky_devsoul::devsoul::IsDevsoul;
use husky_entity_path::path::{major_item::MajorItemPath, ItemPath, ItemPathId};
use husky_figure_zone_protocol::chunk_base::{text::FigureTextChunkBaseData, FigureChunkBase};
use husky_item_path_interface::ItemPathIdInterface;
use husky_linket::linket::Linket;
use husky_linket_impl::ugly::__IsLinketImpl;
use husky_visual_protocol::synchrotron::VisualSynchrotron;

impl<Devsoul: IsDevsoul> Devtime<Devsoul> {
pub fn figure_chunk_base(
&self,
static_var: ItemPathIdInterface,
chunk_idx: u32,
visual_synchrotron: &mut VisualSynchrotron,
) -> FigureChunkBase {
self.figure_chunk_base_cache
.entry((static_var, chunk_idx))
.or_insert_with(|| {
visual_synchrotron.alloc_figure_text_chunk_base(
self.calc_figure_chunk_base(static_var, chunk_idx),
)
})
.clone()
}

fn calc_figure_chunk_base(
&self,
static_var: ItemPathIdInterface,
chunk_idx: u32,
) -> FigureTextChunkBaseData {
let db = self.db();
let item_path_id: ItemPathId = static_var.into();
let item_path: ItemPath = item_path_id.item_path(db);
let ItemPath::MajorItem(MajorItemPath::Form(major_form_path)) = item_path else {
unreachable!()
};
let linket = Linket::new_var(major_form_path, db);
let linket_impl = self.runtime.comptime().linket_impl(linket);
linket_impl
.static_var_svtable()
.figure_chunk_base(chunk_idx)
}
}
40 changes: 26 additions & 14 deletions crates/devtime/husky-devtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![feature(result_flattening)]
#![feature(try_trait_v2)]
pub mod eval;
mod figure;
mod state;
#[cfg(test)]
mod tests;
Expand All @@ -17,11 +18,11 @@ use husky_devsoul::{
devsoul::IsDevsoul,
helpers::{
DevsoulCaryatid, DevsoulChart, DevsoulFigure, DevsoulKiControlFlow, DevsoulStaticVarResult,
DevsoulTraceStalk, DevsoulVmControlFlowFrozen,
DevsoulTraceStalk, DevsoulVarId, DevsoulVmControlFlowFrozen,
},
};
use husky_entity_path::path::ItemPathId;
use husky_figure_zone_protocol::FigureZone;
use husky_figure_zone_protocol::{chunk_base::FigureChunkBase, FigureZone};
use husky_item_path_interface::ItemPathIdInterface;
use husky_ki_repr::repr::KiRepr;
use husky_ki_repr_interface::{KiDomainReprInterface, KiReprInterface};
Expand Down Expand Up @@ -66,6 +67,9 @@ pub struct Devtime<Devsoul: IsDevsoul> {
// when hot reload, reset this
// TODO benchmark this
eager_trace_cache: DashMap<(TracePath, Devsoul::Pedestal), Arc<VmHistory<Devsoul::LinketImpl>>>,
// cache figure chunk bases
// when hot reload, reset this
figure_chunk_base_cache: DashMap<(ItemPathIdInterface, u32), FigureChunkBase>,
vmir_storage: DevVmirStorage<Devsoul::LinketImpl>,
}

Expand All @@ -77,6 +81,7 @@ impl<Devsoul: IsDevsoul> Devtime<Devsoul> {
Ok(Self {
runtime: DevRuntime::new(target_crate, runtime_config)?,
eager_trace_cache: Default::default(),
figure_chunk_base_cache: Default::default(),
vmir_storage: Default::default(),
})
}
Expand Down Expand Up @@ -187,26 +192,33 @@ impl<Devsoul: IsDevsoul> IsTracetime for Devtime<Devsoul> {
let trace_plot_map = trace_visual_cache.calc_plots(figure_key.traces().collect());
match figure_key.figure_zone() {
Some(zone) => match zone {
FigureZone::Gallery => match chart {
FigureZone::Parade => match chart {
Some(chart) => match chart {
Chart::Dim0(_) => todo!(),
Chart::Dim1(chart) => {
IsFigure::new_gallery(chart, trace_plot_map, visual_synchrotron)
IsFigure::new_parading(chart, trace_plot_map, visual_synchrotron)
}
Chart::Dim2(chart) => todo!(),
},
None => IsFigure::new_void(), // ad hoc
},
FigureZone::Text => match chart {
Some(chart) => match chart {
Chart::Dim0(_) => todo!(),
Chart::Dim1(chart) => {
IsFigure::new_text(Some(chart), trace_plot_map, visual_synchrotron)
}
Chart::Dim2(chart) => todo!(),
},
None => IsFigure::new_text(None, trace_plot_map, visual_synchrotron), // ad hoc
},
FigureZone::Roll => {
debug_assert_eq!(figure_key.generic_joint_static_vars().count(), 1);
let the_static_var = figure_key.generic_joint_static_vars().next().unwrap();
let chart = match chart {
Some(Chart::Dim1(chart)) => Some(chart),
None => None,
_ => unreachable!(),
};
IsFigure::new_rolling(
chart,
trace_plot_map,
visual_synchrotron,
|chunk_idx, visual_synchrotron| {
self.figure_chunk_base(the_static_var, chunk_idx, visual_synchrotron)
},
)
}
},
None => match chart {
Some(chart) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
```rust
[]
[
(
Trace {
path: TracePath {
data: TracePathData::StaticVarItem(
StaticVarTracePathData {
static_var_item_path: MajorFormPath(`latex_ast_hsy::AST`, `StaticVar`),
},
),
},
data: StaticVar(
StaticVarTraceData {
path: TracePath(
Id {
value: 1,
},
),
static_var_item_path: MajorFormPath(
ItemPathId(
Id {
value: 2,
},
),
),
},
),
},
(),
),
]
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
```rust
[]
[
Trace {
path: TracePath {
data: TracePathData::StaticVarItem(
StaticVarTracePathData {
static_var_item_path: MajorFormPath(`latex_ast_hsy::AST`, `StaticVar`),
},
),
},
data: StaticVar(
StaticVarTraceData {
path: TracePath(
Id {
value: 1,
},
),
static_var_item_path: MajorFormPath(
ItemPathId(
Id {
value: 2,
},
),
),
},
),
},
]
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
```rust
[]
[
(
Trace {
path: TracePath {
data: TracePathData::StaticVarItem(
StaticVarTracePathData {
static_var_item_path: MajorFormPath(`latex_ast_hsy::AST`, `StaticVar`),
},
),
},
data: StaticVar(
StaticVarTraceData {
path: TracePath(
Id {
value: 1,
},
),
static_var_item_path: MajorFormPath(
ItemPathId(
Id {
value: 2,
},
),
),
},
),
},
Some(
KiRepr {
ki_domain_repr: Omni,
opn: KiOpn::Linket(
Linket {
data: LinketData::MajorStaticVar {
path: MajorFormPath(`latex_ast_hsy::AST`, `StaticVar`),
instantiation: LinInstantiation {
path: ItemPath(`latex_ast_hsy::AST`),
context: LinTypeContext {
comptime_var_overrides: [],
},
variable_resolutions: [],
separator: None,
},
},
},
),
arguments: [],
source: KiReprSource::Val(
MajorFormPath(`latex_ast_hsy::AST`, `StaticVar`),
),
caching_class: Val,
},
),
),
]
```
Loading
Loading