Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyuzhai committed Jun 24, 2024
1 parent 2719c35 commit ffc9110
Show file tree
Hide file tree
Showing 59 changed files with 441 additions and 92 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions crates/abstractions/idx-arena/src/ordered_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ impl<T, V> std::ops::Index<ArenaIdx<T>> for ArenaOrderedMap<T, V> {
}
}

impl<T, V> std::ops::IndexMut<ArenaIdx<T>> for ArenaOrderedMap<T, V> {
fn index_mut(&mut self, index: ArenaIdx<T>) -> &mut Self::Output {
&mut self.data[index.index()]
}
}

impl<T, V> salsa::DebugWithDb for ArenaOrderedMap<T, V>
where
T: salsa::DebugWithDb,
Expand Down
2 changes: 1 addition & 1 deletion crates/devtime/husky-trace/src/trace/lazy_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ impl Trace {
SemStmtData::ForBetween {
for_token: _,
particulars: _,
for_loop_var_symbol_idx: _,
for_loop_varible_idx: _,
eol_colon: _,
stmts: _,
} => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/husky-hir-eager-expr/src/pattern_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pub mod let_variable;

use crate::*;
use husky_hir_ty::HirType;
use husky_sem_expr::LetVariableObelisk;
use husky_sem_expr::obelisks::let_variable::LetVariableObelisk;
4 changes: 2 additions & 2 deletions crates/hir/husky-hir-eager-expr/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub enum HirEagerStmtData {
},
ForBetween {
particulars: HirEagerForBetweenParticulars,
// frame_variable_idx: CurrentHirEagerSymbolIdx,
// for_loop_varible_idx: CurrentHirEagerSymbolIdx,
stmts: HirEagerStmtIdxRange,
},
Forext {
Expand Down Expand Up @@ -126,7 +126,7 @@ impl ToHirEager for SemStmtIdx {
},
SemStmtData::ForBetween {
ref particulars,
for_loop_var_symbol_idx: _frame_variable_idx,
for_loop_varible_idx: _for_loop_varible_idx,
stmts: ref block,
..
} => HirEagerStmtData::ForBetween {
Expand Down
4 changes: 2 additions & 2 deletions crates/hir/husky-hir-eager-expr/src/variable/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl HirEagerRuntimeVariableRegionData {
{
let hir_eager_runtime_symbol_idx = arena.alloc_one(hir_eager_runtime_symbol);
variable_to_hir_eager_runtime_symbol_map
.push_inherited(inherited_variable_idx, hir_eager_runtime_symbol_idx)
.insert_new_inherited(inherited_variable_idx, hir_eager_runtime_symbol_idx)
}
}
for (current_variable_idx, current_variable) in variable_region.indexed_current_variables()
Expand All @@ -75,7 +75,7 @@ impl HirEagerRuntimeVariableRegionData {
{
let hir_eager_runtime_symbol_idx = arena.alloc_one(hir_eager_runtime_symbol);
variable_to_hir_eager_runtime_symbol_map
.push_current(current_variable_idx, hir_eager_runtime_symbol_idx)
.insert_new_current(current_variable_idx, hir_eager_runtime_symbol_idx)
}
}
(
Expand Down
5 changes: 3 additions & 2 deletions crates/hir/husky-hir-lazy-expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ impl ToHirLazy for SemExprIdx {
.unwrap(),
),
SemExprData::FrameVarDecl {
frame_variable_idx, ..
for_loop_varible_idx,
..
} => HirLazyExprData::Variable(
builder
.current_variable_to_hir_lazy_variable(frame_variable_idx)
.current_variable_to_hir_lazy_variable(for_loop_varible_idx)
.unwrap(),
),
SemExprData::SelfType(_) => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/husky-hir-lazy-expr/src/pattern.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::*;
use husky_hir_ty::HirType;
use husky_sem_expr::LetVariableObelisk;
use husky_sem_expr::obelisks::let_variable::LetVariableObelisk;
use husky_syn_expr::{pattern::SynPatternData, syndicates::BePatternSyndicate};

#[derive(Debug, PartialEq, Eq, Clone, Hash)]
Expand Down
4 changes: 2 additions & 2 deletions crates/hir/husky-hir-lazy-expr/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl HirLazyVariableRegion {
{
let hir_eager_runtime_symbol_idx = arena.alloc_one(hir_eager_runtime_symbol);
variable_to_hir_eager_runtime_symbol_map
.push_inherited(inherited_variable_idx, hir_eager_runtime_symbol_idx)
.insert_new_inherited(inherited_variable_idx, hir_eager_runtime_symbol_idx)
}
}
for (current_variable_idx, current_variable) in variable_region.indexed_current_variables()
Expand All @@ -152,7 +152,7 @@ impl HirLazyVariableRegion {
{
let hir_eager_runtime_symbol_idx = arena.alloc_one(hir_eager_runtime_symbol);
variable_to_hir_eager_runtime_symbol_map
.push_current(current_variable_idx, hir_eager_runtime_symbol_idx)
.insert_new_current(current_variable_idx, hir_eager_runtime_symbol_idx)
}
}
(Self { arena }, variable_to_hir_eager_runtime_symbol_map)
Expand Down
2 changes: 1 addition & 1 deletion crates/ide/husky-token-info/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl<'a, 'b> DeclTokenInfoEngine<'a, 'b> {
}
| SemExprData::FrameVarDecl {
regional_token_idx,
frame_variable_idx: current_variable_idx,
for_loop_varible_idx: current_variable_idx,
current_variable_kind,
..
} => self.add(
Expand Down
10 changes: 5 additions & 5 deletions crates/semantics/husky-sem-expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub enum SemExprData {
FrameVarDecl {
regional_token_idx: RegionalTokenIdx,
ident: Ident,
frame_variable_idx: CurrentVariableIdx,
for_loop_varible_idx: CurrentVariableIdx,
current_variable_kind: CurrentVariableKind,
},
SelfType(RegionalTokenIdx),
Expand Down Expand Up @@ -887,16 +887,16 @@ impl<'a> SemExprBuilder<'a> {
SynExprData::FrameVarDecl {
ident,
regional_token_idx,
frame_variable_idx,
for_loop_varible_idx,
current_variable_kind,
} => (
Ok(SemExprData::FrameVarDecl {
ident,
regional_token_idx,
frame_variable_idx,
for_loop_varible_idx,
current_variable_kind,
}),
self.get_current_variable_ty(syn_expr_idx, frame_variable_idx),
self.get_current_variable_ty(syn_expr_idx, for_loop_varible_idx),
),
SynExprData::SelfType(regional_token_idx) => (
Ok(SemExprData::SelfType(regional_token_idx)),
Expand Down Expand Up @@ -1554,7 +1554,7 @@ impl<'a> SemExprBuilder<'a> {
SemExprData::FrameVarDecl {
regional_token_idx,
ident,
frame_variable_idx,
for_loop_varible_idx,
current_variable_kind,
} => todo!(),
SemExprData::SelfType(regional_token_idx) => match self.self_ty() {
Expand Down
56 changes: 46 additions & 10 deletions crates/semantics/husky-sem-expr/src/helpers/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::region::sem_expr_region_from_region_path;
use super::*;
use crate::{SemExprData, SemExprIdx, SemExprRegionData, SemStmtIdx, SemStmtIdxRange};
use closure_parameter::ClosureParameterObelisk;
use condition::SemCondition;
use husky_entity_path::region::RegionPath;
use husky_entity_tree::{
Expand All @@ -17,19 +18,31 @@ pub trait VisitSemExpr<'db>: Sized {
fn db(&self) -> &'db ::salsa::Db;
fn sem_expr_region_data(&self) -> &'db SemExprRegionData;
fn visit_expr(&mut self, expr: SemExprIdx, f: impl FnOnce(&mut Self));
fn visit_expr_inner(&mut self, expr: SemExprIdx);
fn visit_expr_itself(&mut self, expr: SemExprIdx);
fn visit_closure_inner(
&mut self,
expr: SemExprIdx,
parameters: &[ClosureParameterObelisk],
f: impl FnOnce(&mut Self),
);
fn visit_stmts(&mut self, stmts: SemStmtIdxRange, f: impl FnOnce(&mut Self));
/// `f` is a closure in which
/// - first the subexpression and substatements of `stmt` will be simulated in evaluation order
/// - then `visit_stmt_inner` will be invoked
///
/// this method `visit_stmt` should set up the proper environment and invoke `f`
fn visit_stmt(&mut self, stmt: SemStmtIdx, f: impl FnOnce(&mut Self));
fn visit_stmt_inner(&mut self, stmt: SemStmtIdx);
fn visit_stmt_itself(&mut self, stmt: SemStmtIdx);
/// `f` is a closure that can be called for arbitrary times, in which
/// - the precondition is simulated if it exists
/// - the loop body is simulated
/// - the postcondition is simulated if it exists
fn visit_for_loop_stmt_inner(
&mut self,
stmt: SemStmtIdx,
for_loop_varible_idx: CurrentVariableIdx,
f: impl Fn(&mut Self),
);
fn visit_loop(&mut self, stmt: SemStmtIdx, f: impl Fn(&mut Self));
fn visit_branches(&mut self, f: impl Fn(&mut Self));
fn visit_branch(&mut self, f: impl Fn(&mut Self));
Expand Down Expand Up @@ -204,15 +217,19 @@ impl SemExprIdx {
rvert_regional_token,
return_ty,
body,
} => body.simulate(visitor),
} => {
visitor.visit_closure_inner(self, parameter_obelisks, |visitor| {
body.simulate(visitor)
});
}
SemExprData::Sorry { regional_token_idx } => todo!(),
// ad hoc
SemExprData::Todo { .. } => (),
// ad hoc
SemExprData::Unreachable { .. } => (),
SemExprData::NestedBlock { stmts, .. } => stmts.simulate(visitor),
}
visitor.visit_expr_inner(self)
visitor.visit_expr_itself(self)
});
}
}
Expand Down Expand Up @@ -275,11 +292,10 @@ impl SemStmtIdx {
SemStmtData::ForBetween {
for_token,
ref particulars,
for_loop_var_symbol_idx,
for_loop_varible_idx,
eol_colon,
stmts,
} => {
// ad hoc
let range = particulars.range();
range
.initial_boundary
Expand All @@ -289,7 +305,9 @@ impl SemStmtIdx {
.final_boundary
.bound_expr
.map(|bound_expr| bound_expr.simulate(visitor));
visitor.visit_loop(self, |visitor| stmts.simulate(visitor));
visitor.visit_for_loop_stmt_inner(self, for_loop_varible_idx, |visitor| {
visitor.visit_loop(self, |visitor| stmts.simulate(visitor))
})
}
SemStmtData::ForIn {
for_token,
Expand Down Expand Up @@ -360,7 +378,7 @@ impl SemStmtIdx {
// ad hoc
SemStmtData::Narrate { .. } => (),
};
visitor.visit_stmt_inner(self);
visitor.visit_stmt_itself(self);
})
}
}
Expand Down Expand Up @@ -450,13 +468,22 @@ fn visit_sem_expr_works() {
f(self)
}

fn visit_expr_inner(&mut self, expr: SemExprIdx) {
fn visit_expr_itself(&mut self, expr: SemExprIdx) {
let token_idx_range =
self.sem_expr_range_region_data[expr].token_idx_range(self.base.unwrap());
let text_range = self.ranged_token_sheet.tokens_text_range(token_idx_range);
self.visits.push(self.text.text_within(text_range));
}

fn visit_closure_inner(
&mut self,
expr: SemExprIdx,
parameters: &[ClosureParameterObelisk],
f: impl FnOnce(&mut Self),
) {
f(self)
}

fn visit_stmts(&mut self, stmts: SemStmtIdxRange, f: impl FnOnce(&mut Self)) {
f(self)
}
Expand All @@ -465,13 +492,22 @@ fn visit_sem_expr_works() {
f(self)
}

fn visit_stmt_inner(&mut self, stmt: SemStmtIdx) {
fn visit_stmt_itself(&mut self, stmt: SemStmtIdx) {
let token_idx_range =
self.sem_expr_range_region_data[stmt].token_idx_range(self.base.unwrap());
let text_range = self.ranged_token_sheet.tokens_text_range(token_idx_range);
self.visits.push(self.text.text_within(text_range));
}

fn visit_for_loop_stmt_inner(
&mut self,
stmt: SemStmtIdx,
for_loop_varible_idx: CurrentVariableIdx,
f: impl Fn(&mut Self),
) {
f(self)
}

fn visit_loop(&mut self, stmt: SemStmtIdx, f: impl Fn(&mut Self)) {
f(self)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/semantics/husky-sem-expr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ pub use self::builder::*;
pub use self::error::*;
pub use self::expr::*;
pub use self::jar::*;
pub use self::obelisks::*;
pub use self::region::*;
pub use self::stmt::*;

use self::jar::SemExprJar as Jar;
use self::obelisks::*;
use either::*;
use husky_dec_signature::*;
use husky_entity_kind::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ pub enum ClosureParameterObelisk {
},
}

impl ClosureParameterObelisk {
pub fn variables(self) -> CurrentVariableIdxRange {
match self {
ClosureParameterObelisk::Simple { variables, .. } => variables,
}
}
}

impl<'a> SemExprBuilder<'a> {
pub(crate) fn build_closure_parameter_obelisk(
&mut self,
Expand Down
8 changes: 4 additions & 4 deletions crates/semantics/husky-sem-expr/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum SemStmtData {
ForBetween {
for_token: StmtForRegionalToken,
particulars: SemaForBetweenParticulars,
for_loop_var_symbol_idx: CurrentVariableIdx,
for_loop_varible_idx: CurrentVariableIdx,
eol_colon: EolRegionalToken,
stmts: SemStmtIdxRange,
},
Expand Down Expand Up @@ -443,13 +443,13 @@ impl<'a> SemExprBuilder<'a> {
SynStmtData::ForBetween {
for_token,
ref particulars,
for_loop_var_symbol_idx,
for_loop_varible_idx,
ref block,
ref eol_colon,
} => {
let expr_expectation = self.expect_unit();
let Ok(particulars) =
self.build_sem_for_between_particulars(particulars, for_loop_var_symbol_idx)
self.build_sem_for_between_particulars(particulars, for_loop_varible_idx)
else {
todo!()
};
Expand All @@ -459,7 +459,7 @@ impl<'a> SemExprBuilder<'a> {
Ok(SemStmtData::ForBetween {
for_token,
particulars,
for_loop_var_symbol_idx,
for_loop_varible_idx,
eol_colon,
stmts: block,
}),
Expand Down
8 changes: 4 additions & 4 deletions crates/semantics/husky-sem-expr/src/stmt/loop_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'a> SemExprBuilder<'a> {
pub(crate) fn build_sem_for_between_particulars(
&mut self,
particulars: &'a SynForBetweenParticulars,
for_loop_var_symbol_idx: CurrentVariableIdx,
for_loop_varible_idx: CurrentVariableIdx,
) -> SynExprResultRef<'a, SemaForBetweenParticulars> {
let Ok(ref range) = particulars.range else {
todo!()
Expand Down Expand Up @@ -76,18 +76,18 @@ impl<'a> SemExprBuilder<'a> {
todo!()
};
// let place = FlyPlace::ImmutableOnStack {
// location: for_loop_var_symbol_idx
// location: for_loop_varible_idx
// .into_local_symbol_idx(self.syn_expr_region_data())
// .into(),
// };
let frame_var_symbol_ty = SymbolType::new_variable_ty(
self,
for_loop_var_symbol_idx,
for_loop_varible_idx,
VariableModifier::Pure,
expected_frame_var_ty,
)
.unwrap();
self.add_symbol_ty(for_loop_var_symbol_idx, frame_var_symbol_ty);
self.add_symbol_ty(for_loop_varible_idx, frame_var_symbol_ty);
let for_between_loop_var_expr_idx = self.build_sem_expr(
particulars.for_between_loop_var_expr_idx,
ExpectCoercion::new_pure(self, frame_var_symbol_ty.term()),
Expand Down
Loading

0 comments on commit ffc9110

Please sign in to comment.