google/jsonnet

Max stack frames exceeded when using string interpolation in text blocks

Closed this issue · 1 comments

To reproduce:

test.jsonnet

{
  text: |||
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. In pellentesque felis mi, et iaculis
    tellus consectetur pretium. Integer ultricies ullamcorper arcu quis bibendum. Vivamus luctus nec
    nulla id egestas. Vestibulum lectus nibh, lobortis sed gravida ac, pellentesque sit amet eros.
    Nulla urna purus, ornare at iaculis eget, pharetra sed libero. Fusce a neque malesuada,
    hendrerit ex nec, suscipit lorem. Aenean orci quam, placerat sed mollis ut, faucibus nec turpis.
    Vivamus consectetur auctor vehicula. Nam eu risus sit amet eros mattis finibus nec ac enim.
    Quisque velit metus, tristique in urna in, dictum gravida elit.%(a)s

    Aenean laoreet libero nunc. Cras molestie condimentum mollis. Nam quis leo sed enim vestibulum
    dapibus faucibus eget elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class
    aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent
    cursus magna at urna viverra, eget venenatis ante sodales. In vitae magna sed lacus iaculis
    porttitor eu vel nisl. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vitae sapien
    vel eros ultricies iaculis. Pellentesque et metus libero. Proin nec rhoncus est. Vivamus a
    aliquam ipsum, ut vehicula nibh. Sed ac posuere dolor.
  ||| % {
    a: "a",
  }
}
$ jsonnet test.jsonnet
RUNTIME ERROR: Max stack frames exceeded.
    std.jsonnet:337:48-57   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    std.jsonnet:337:71-76   thunk <array_element>
    ...
    std.jsonnet:562:20-33   thunk <a>
    std.jsonnet:915:29  thunk <x>
    std.jsonnet:915:20-30   thunk <ta>
    std.jsonnet:917:33-34   thunk <a>
    std.jsonnet:917:13-39   function <anonymous>
    std.jsonnet:562:20-45   function <format_codes_obj>
    std.jsonnet:600:13-48   function <anonymous>
    std.jsonnet:132:13-28   function <anonymous>
    test.jsonnet:(2:9)-(20:3)   object <anonymous>
    During manifestation

Just adding some notes here:

This code was overly complicated so I simplified it, and this avoided the problem. But the underlying problem still remains, and code that is legitimately complex may trigger it in future.

The problem is we force thunk e in the case of f(e) tailstrict, but if e is an array or a std.makeArray or similar, then its elements are not currently forced.

One solution is to have a std.makeArrayStrict call that will make an array and force the thunks.