Skip to content

Commit

Permalink
Fix options like WithXXX not working and change default MaxInlineDept…
Browse files Browse the repository at this point in the history
…h=2 (#47)
  • Loading branch information
xiaost authored Jun 12, 2024
1 parent 1a0441f commit d30b692
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions internal/binary/encoder/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ func (self *Compiler) Apply(o opts.Options) *Compiler {
return self
}

func (self *Compiler) resetState() *Compiler {
o := self.o // prevent resetting opts
resetCompiler(self)
self.o = o
return self
}

func (self *Compiler) Compile(vt reflect.Type) (_ Program, err error) {
ret := newProgram()
vtp := (*defs.Type)(nil)
Expand All @@ -188,13 +195,13 @@ func (self *Compiler) Compile(vt reflect.Type) (_ Program, err error) {
/* object measuring */
i := ret.pc()
ret.add(OP_if_hasbuf)
resetCompiler(self).measure(&ret, 0, vtp, ret.pc())
self.resetState().measure(&ret, 0, vtp, ret.pc())

/* object encoding */
j := ret.pc()
ret.add(OP_goto)
ret.pin(i)
resetCompiler(self).compile(&ret, 0, vtp, ret.pc())
self.resetState().compile(&ret, 0, vtp, ret.pc())

/* halt the program */
ret.pin(j)
Expand Down
2 changes: 1 addition & 1 deletion internal/opts/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

const (
_DefaultMaxInlineDepth = 5 // cutoff at 5 levels of inlining
_DefaultMaxInlineDepth = 2 // cutoff at 2 levels of inlining
_DefaultMaxInlineILSize = 50000 // cutoff at 50k of IL instructions
)

Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Option func(*opts.Options)
//
// Set this option to "0" disables this limit, which means inlining everything.
//
// The default value of this option is "5".
// The default value of this option is "2".
func WithMaxInlineDepth(depth int) Option {
if depth < 0 {
panic(fmt.Sprintf("frugal: invalid inline depth: %d", depth))
Expand Down Expand Up @@ -91,7 +91,7 @@ func WithMaxPretouchDepth(depth int) Option {
// This value can also be configured with the `FRUGAL_MAX_INLINE_DEPTH`
// environment variable.
//
// The default value of this option is "5".
// The default value of this option is "2".
//
// Returns the old opts.MaxInlineDepth value.
func SetMaxInlineDepth(depth int) int {
Expand Down

0 comments on commit d30b692

Please sign in to comment.