Tail recursion with 1.9

Hi,

I read in the first answer here

that tail recursion is not on by default and is enabled by uncommenting
a line in the source before compilation. Is this still true, and is
there anyway to tell if it’s on or not in a particular installation?

Regards,
Iain

Its commented out.

See vm_opts.h.

As far as sensing it in Ruby I would think

ruby-1.9.2-rc2.tar.bz2>

Snippet of vm_opts.h below:

#ifndef RUBY_VM_OPTS_H
#define RUBY_VM_OPTS_H

/* Compile options.

  • You can change these options at runtime by VM::CompileOption.
  • Following definitions are default values.
    */

#define OPT_TRACE_INSTRUCTION 1
#define OPT_TAILCALL_OPTIMIZATION 0
#define OPT_PEEPHOLE_OPTIMIZATION 1
#define OPT_SPECIALISED_INSTRUCTION 1
#define OPT_INLINE_CONST_CACHE 1

RUN TIME OPTIONS could be interesting to play with. You appear to loose
the
promise of portability.

See iseq.c (Interesting rb_compile_option_t )

static rb_compile_option_t COMPILE_OPTION_DEFAULT = {
OPT_INLINE_CONST_CACHE, /* int inline_const_cache; /
OPT_PEEPHOLE_OPTIMIZATION, /
int peephole_optimization; /
OPT_TAILCALL_OPTIMIZATION, /
int tailcall_optimization /
OPT_SPECIALISED_INSTRUCTION, /
int specialized_instruction; /
OPT_OPERANDS_UNIFICATION, /
int operands_unification; /
OPT_INSTRUCTIONS_UNIFICATION, /
int instructions_unification; /
OPT_STACK_CACHING, /
int stack_caching; /
OPT_TRACE_INSTRUCTION, /
int trace_instruction */
};

On 10 Aug 2010, at 16:43, Joseph E. Savard wrote:

#ifndef RUBY_VM_OPTS_H
#define OPT_SPECIALISED_INSTRUCTION 1
OPT_TAILCALL_OPTIMIZATION, /* int tailcall_optimization /
OPT_SPECIALISED_INSTRUCTION, /
int specialized_instruction; /
OPT_OPERANDS_UNIFICATION, /
int operands_unification; /
OPT_INSTRUCTIONS_UNIFICATION, /
int instructions_unification; /
OPT_STACK_CACHING, /
int stack_caching; /
OPT_TRACE_INSTRUCTION, /
int trace_instruction */
};

Thanks for the reply. Finally got 1.9.1-p429 to compile, and I set
#define OPT_TAILCALL_OPTIMIZATION 1 before compiling, which hopefully
is right, I don’t know C.

Do you know any way I can check it’s definitely on, aside from
attempting to blow the stack with something hugely recursive?

Iain

On 12 August 2010 23:52, Iain B. [email protected] wrote:

*/
See iseq.c (Interesting rb_compile_option_t )
};

Thanks for the reply. Finally got 1.9.1-p429 to compile, and I set #define OPT_TAILCALL_OPTIMIZATION 1 before compiling, which hopefully is right, I don’t know C.

Do you know any way I can check it’s definitely on, aside from attempting to blow the stack with something hugely recursive?

Iain

You should probably dig deeper in your own link :slight_smile:

There is a link on the stackoverflow’s question:
http://redmine.ruby-lang.org/issues/show/1256
The third reply from Nobu might help you :wink:

Regards,
B.D.

On 12 Aug 2010, at 23:11, Benoit D. wrote:

You should probably dig deeper in your own link :slight_smile:

There is a link on the stackoverflow’s question:
http://redmine.ruby-lang.org/issues/show/1256
The third reply from Nobu might help you :wink:

Regards,
B.D.

Thanks. I had already read that, but my brain dumps any information that
I can’t use at that particular moment :slight_smile:

$ irb

RubyVM::InstructionSequence.compile_option[:tailcall_optimization]
=> true

Regards,
Iain