Skip to content

Commit

Permalink
compiler: improve the --opt-deadcode optimization flag for struct met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
mertcandav committed Jul 29, 2024
1 parent 0c2b5ef commit 5fc671c
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/julec/opt/deadcode/define.jule
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ impl ObjectDeadCode {
}
self.pushLive[&StructIns](s)
self.setReferencesAsLive(s.Refers)
for (_, mut ins) in s.Methods {
for (_, mut mins) in ins.Instances {
if self.isLive[&FnIns](mins) {
for (_, mut m) in s.Methods {
for (_, mut ins) in m.Instances {
if self.isLive[&FnIns](ins) {
continue
}
self.pushLive[&FnIns](mins)
self.setReferencesAsLive(mins.Refers)
// Push as live the method if implements a trait's method.
// Other methods will be marked as live by referenced defines,
// no need for special tracking algorithm to caught.
if isTraitMethod(s, ins) {
self.pushLive[&FnIns](ins)
self.setReferencesAsLive(ins.Refers)
}
}
}
}
Expand Down Expand Up @@ -300,4 +305,14 @@ fn findDirective(mut &directives: []&ast::Directive, tag: str): &ast::Directive
// Reports whether directive is exist.
fn hasDirective(&directives: []&ast::Directive, tag: str): bool {
ret findDirective(unsafe { *(&directives) }, tag) != nil
}

// Reports the f function of owner is implements a trait's method.
fn isTraitMethod(mut &owner: &StructIns, &f: &FnIns): bool {
for (_, mut t) in owner.Decl.Implements {
if t.FindMethod(f.Decl.Ident) != nil {
ret true
}
}
ret false
}

0 comments on commit 5fc671c

Please sign in to comment.