Skip to content

Commit

Permalink
compiler: fix boundary and nil optimization analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Oct 6, 2024
1 parent 6f01321 commit de3a6c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/julec/opt/data.jule
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

use "std/jule/sema"

// Optimization preferences for the data.
enum dataFlag {
Default,
// Any conditional expression (such as x != nil) will not considered
// as optimization opportunity.
NoConditional,
}

static mut emptyData = new(data)

// Immutable copy for data.
Expand All @@ -18,6 +26,7 @@ struct data {
boundary: &boundary
nils: &nils
dynamic: &dynamic
flags: dataFlag
}

impl data {
Expand Down
6 changes: 4 additions & 2 deletions src/julec/opt/expr.jule
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,10 @@ impl exprOptimizer {
}

fn binary(self, mut m: &sema::BinaryExprModel) {
self.checkBinaryForBoundary(m)
self.checkBinaryForNil(m)
if self.data.flags&dataFlag.NoConditional != dataFlag.NoConditional {
self.checkBinaryForBoundary(m)
self.checkBinaryForNil(m)
}

if Cond {
match {
Expand Down
7 changes: 7 additions & 0 deletions src/julec/opt/scope.jule
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ impl scopeOptimizer {
}
ret
}

// CAST production is equals to &Data statement for "_ = EXPR" assignments.
// And there is no informative or useful optimization data for some optimizations.
// Therefore avoid using this expressions as useful data for relevant optimizations.
dataFlags := self.data.flags
self.data.flags |= dataFlag.NoConditional
exprOptimizer.optimizeData(d.Model, self.data)
self.data.flags = dataFlags
}

fn optimizeVar(mut &self, mut v: &sema::Var) {
Expand Down

0 comments on commit de3a6c0

Please sign in to comment.