Skip to content

Commit

Permalink
compiler: add struct method support for scope deadcode analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Sep 5, 2024
1 parent 901ff21 commit 60a87ff
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/julec/opt/deadcode/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::jule::sema::{
Package,
Fn,
Scope,
Struct,
Stmt,
Data,
RetSt,
Expand Down Expand Up @@ -245,7 +246,7 @@ fn eliminateDeadCodeOfScope(mut s: &Scope) {
unsafe { sdc.optimizeStmts() }
}

// Eliminates dead functions.
// Eliminates dead scope elements of functions.
fn eliminateScopeFunctions(mut &funcs: []&Fn) {
for (_, mut func) in funcs {
for (_, mut ins) in func.Instances {
Expand All @@ -254,9 +255,19 @@ fn eliminateScopeFunctions(mut &funcs: []&Fn) {
}
}

// Eliminates dead scope elements of struct methods.
fn eliminateScopeStructMethods(mut &structs: []&Struct) {
for (_, mut s) in structs {
for (_, mut ins) in s.Instances {
eliminateScopeFunctions(ins.Methods)
}
}
}

fn eliminateFunctionsScopePackage(mut &pkg: &Package) {
for (_, mut f) in pkg.Files {
eliminateScopeFunctions(f.Funcs)
eliminateScopeStructMethods(f.Structs)
}
}

Expand Down

0 comments on commit 60a87ff

Please sign in to comment.