Skip to content

Commit d30b692

Browse files
authored
Fix options like WithXXX not working and change default MaxInlineDepth=2 (#47)
1 parent 1a0441f commit d30b692

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

internal/binary/encoder/compiler.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ func (self *Compiler) Apply(o opts.Options) *Compiler {
172172
return self
173173
}
174174

175+
func (self *Compiler) resetState() *Compiler {
176+
o := self.o // prevent resetting opts
177+
resetCompiler(self)
178+
self.o = o
179+
return self
180+
}
181+
175182
func (self *Compiler) Compile(vt reflect.Type) (_ Program, err error) {
176183
ret := newProgram()
177184
vtp := (*defs.Type)(nil)
@@ -188,13 +195,13 @@ func (self *Compiler) Compile(vt reflect.Type) (_ Program, err error) {
188195
/* object measuring */
189196
i := ret.pc()
190197
ret.add(OP_if_hasbuf)
191-
resetCompiler(self).measure(&ret, 0, vtp, ret.pc())
198+
self.resetState().measure(&ret, 0, vtp, ret.pc())
192199

193200
/* object encoding */
194201
j := ret.pc()
195202
ret.add(OP_goto)
196203
ret.pin(i)
197-
resetCompiler(self).compile(&ret, 0, vtp, ret.pc())
204+
self.resetState().compile(&ret, 0, vtp, ret.pc())
198205

199206
/* halt the program */
200207
ret.pin(j)

internal/opts/limits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
const (
25-
_DefaultMaxInlineDepth = 5 // cutoff at 5 levels of inlining
25+
_DefaultMaxInlineDepth = 2 // cutoff at 2 levels of inlining
2626
_DefaultMaxInlineILSize = 50000 // cutoff at 50k of IL instructions
2727
)
2828

options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Option func(*opts.Options)
3737
//
3838
// Set this option to "0" disables this limit, which means inlining everything.
3939
//
40-
// The default value of this option is "5".
40+
// The default value of this option is "2".
4141
func WithMaxInlineDepth(depth int) Option {
4242
if depth < 0 {
4343
panic(fmt.Sprintf("frugal: invalid inline depth: %d", depth))
@@ -91,7 +91,7 @@ func WithMaxPretouchDepth(depth int) Option {
9191
// This value can also be configured with the `FRUGAL_MAX_INLINE_DEPTH`
9292
// environment variable.
9393
//
94-
// The default value of this option is "5".
94+
// The default value of this option is "2".
9595
//
9696
// Returns the old opts.MaxInlineDepth value.
9797
func SetMaxInlineDepth(depth int) int {

0 commit comments

Comments
 (0)