Skip to content

postcheck panic from record with a function field with function defined on its own line #10030

Description

@austinclem1

Version

commit 8f7bb2d
Roc compiler version debug-8f7bb2d9

Failing Code

r : { f : U8 -> U8 }
r = {
	f = |n| n * 2
	{
		f
	}
}

main! = |_args| {
	_n = r.f(2)
	Ok({})
}

Observations

Failed with roc build command, roc check no failure

Changes that prevent the segfault:

  • Remove type annotation from r
  • Function f return value doesn't depend on n i.e. f = |_n| 2
  • Define f field inline like so (no intermediate f definition):
{
    f: |n| n * 2
}
  • Pass n argument directly to output, no arithmetic or any other operation on it, i.e. f = |n| n
Stack Trace
thread 15434 panic: postcheck invariant violated: dispatch plan reached monotype lowering without a resolution
/home/austinclem1/projects/roc/src/postcheck/common.zig:82:24: 0x621c46c in invariant__anon_308050 (mod.zig)
        std.debug.panic("postcheck invariant violated: {s}", .{message});
                       ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:17175:29: 0x621b94d in dispatchTarget (mod.zig)
            Common.invariant("dispatch plan reached monotype lowering without a resolution");
                            ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:16320:43: 0x63aec93 in lowerDispatchExprAtType (mod.zig)
        const lookup = self.dispatchTarget(plan, dispatcher_ty);
                                          ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:15829:77: 0x613e9c8 in lowerExprAtType (mod.zig)
            .dispatch_call => |plan| return try self.lowerDispatchExprAtType(expr.ty, plan, ty),
                                                                            ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:21307:85: 0x61dbd48 in lowerBindingContinuation (mod.zig)
                if (args.index >= args.args.len) break :blk try self.lowerExprAtType(args.body, result_ty);
                                                                                    ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8189:53: 0x64263ac in lowerLambdaArgsAndBody (mod.zig)
        var body = try self.lowerBindingContinuation(.{ .materialized_args = .{
                                                    ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8129:56: 0x642475f in lowerLambdaTemplate__anon_299582 (mod.zig)
        const lowered = try self.lowerLambdaArgsAndBody(lambda.args, arg_tys, lambda.body, fn_data.ret);
                                                       ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8251:44: 0x6479a97 in lowerNestedLambdaTemplate__anon_326789 (mod.zig)
        return try self.lowerLambdaTemplate(lambda, fn_ty);
                                           ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8234:67: 0x6478f10 in lowerNestedFunction (mod.zig)
            .lambda => |lambda| try self.lowerNestedLambdaTemplate(lambda, fn_ty),
                                                                  ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:2910:60: 0x64772b2 in lowerNestedFnRequest (mod.zig)
        const lowered = try request.ctx.lowerNestedFunction(request.expr_id, body_fn_ty);
                                                           ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:2858:45: 0x64757c3 in lowerNestedFnFromContext (mod.zig)
        return try self.lowerNestedFnRequest(.{
                                            ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:15133:65: 0x628d6c6 in restoreConstFnTemplate (mod.zig)
                return try self.builder.lowerNestedFnFromContext(&fn_ctx, checkedLambdaExprIdForConstFn(fn_view, fn_value.fn_def), template, null);
                                                                ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:15115:59: 0x628c913 in restoreConstFn (mod.zig)
        const mono_fn_id = try self.restoreConstFnTemplate(fn_value, template);
                                                          ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:14942:47: 0x6481729 in restoreConstNodeAtType (mod.zig)
                return try self.restoreConstFn(store_view, fn_id, ty);
                                              ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:15051:57: 0x64846fe in restoreConstRecord (mod.zig)
                .value = try self.restoreConstNodeAtType(store_view, type_view, item, field.ty),
                                                        ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:14988:72: 0x6482f0f in restoreConstData (mod.zig)
            .record => |items| .{ .record = try self.restoreConstRecord(store_view, type_view, ty, items) },
                                                                       ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:14954:47: 0x6481d88 in restoreConstNodeAtType (mod.zig)
        const data = try self.restoreConstData(store_view, type_view, value, ty);
                                              ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:14832:70: 0x628504c in restoreConstUseAtType (mod.zig)
            .stored_const => |stored| try self.restoreConstNodeAtType(store_view, self.view, stored.node, ty),
                                                                     ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:14717:82: 0x627e617 in lowerLookupExprAtType (mod.zig)
            .top_level_const => |const_use| return try self.restoreConstUseAtType(const_use, ty, try self.evidenceForUseSite(record.expr)),
                                                                                 ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:15833:76: 0x613f165 in lowerExprAtType (mod.zig)
            .lookup_local => |lookup| return try self.lowerLookupExprAtType(expr.ty, lookup.resolved, ty),
                                                                           ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8562:57: 0x6145864 in lowerExprWithType (mod.zig)
                    .receiver = try self.lowerExprAtType(field.receiver, receiver_ty),
                                                        ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:15864:51: 0x61401d8 in lowerExprAtType (mod.zig)
        const lowered = try self.lowerExprWithType(checked_expr, ty);
                                                  ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:13975:51: 0x63d4c87 in lowerCallAtType__anon_302798 (mod.zig)
                .callee = try self.lowerExprAtType(call.func, fn_ty),
                                                  ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:13914:40: 0x6241c6e in lowerCall__anon_309300 (mod.zig)
        return try self.lowerCallAtType(checked_ret_ty, call, null);
                                       ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8658:43: 0x623fdd1 in lowerCallExpr__anon_309280 (mod.zig)
        const lowered = try self.lowerCall(checked_ret_ty, call);
                                          ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8341:46: 0x623dd79 in lowerExpr (mod.zig)
                return try self.lowerCallExpr(expr_id, expr.ty, call);
                                             ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:23650:41: 0x61d9f72 in lowerPatternStatement (mod.zig)
        const value = try self.lowerExpr(expr);
                                        ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:23542:58: 0x61c050f in lowerStatement (mod.zig)
                break :blk try self.lowerPatternStatement(decl.pattern, decl.expr, statement.source_region);
                                                         ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:22187:75: 0x6159ca9 in lowerBlockStatements (mod.zig)
                try lowered.append(self.allocator, try self.lowerStatement(statement));
                                                                          ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:22149:52: 0x6236eab in lowerBlock__anon_303039 (mod.zig)
        const stmts = try self.lowerBlockStatements(block.statements);
                                                   ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8572:50: 0x6145ffd in lowerExprWithType (mod.zig)
            .block => |block| try self.lowerBlock(block, ty),
                                                 ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:15864:51: 0x61401d8 in lowerExprAtType (mod.zig)
        const lowered = try self.lowerExprWithType(checked_expr, ty);
                                                  ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:21307:85: 0x61dbd48 in lowerBindingContinuation (mod.zig)
                if (args.index >= args.args.len) break :blk try self.lowerExprAtType(args.body, result_ty);
                                                                                    ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8189:53: 0x64263ac in lowerLambdaArgsAndBody (mod.zig)
        var body = try self.lowerBindingContinuation(.{ .materialized_args = .{
                                                    ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8129:56: 0x642475f in lowerLambdaTemplate__anon_299582 (mod.zig)
        const lowered = try self.lowerLambdaArgsAndBody(lambda.args, arg_tys, lambda.body, fn_data.ret);
                                                       ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:8042:69: 0x60e3525 in lowerTemplateBody (mod.zig)
                    .lambda => |lambda| try self.lowerLambdaTemplate(lambda, fn_ty),
                                                                    ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:1491:55: 0x60b4933 in lowerTemplateWithMonoFor (mod.zig)
        const lowered = try body_ctx.lowerTemplateBody(template_ref, template, body_fn_ty);
                                                      ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:3006:50: 0x60b126a in drainSpecRequestsFrom (mod.zig)
            _ = try self.lowerTemplateWithMonoFor(
                                                 ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:2984:39: 0x60b0bc5 in drainSpecRequests (mod.zig)
        try self.drainSpecRequestsFrom(graph, 0);
                                      ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:1493:35: 0x60b4af5 in lowerTemplateWithMonoFor (mod.zig)
        try self.drainSpecRequests(graph);
                                  ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:1264:49: 0x63a77aa in lowerTemplateWithMono (mod.zig)
        return try self.lowerTemplateWithMonoFor(template_ref, source_fn_ty, source_fn_key, fn_ty, evidence, null, null, null, null);
                                                ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:1253:46: 0x64eec76 in lowerTemplate (mod.zig)
        return try self.lowerTemplateWithMono(template_ref, source_fn_ty, source_ty_view.types.rootKey(source_fn_ty), fn_ty, &.{});
                                             ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:933:35: 0x64dc779 in lowerRoot (mod.zig)
            try self.lowerTemplate(template, moduleView(self.root_view), request.checked_type)
                                  ^
/home/austinclem1/projects/roc/src/postcheck/monotype/lower.zig:102:30: 0x5fa1b9a in run (mod.zig)
        try builder.lowerRoot(request);
                             ^
/home/austinclem1/projects/roc/src/lir/checked_pipeline.zig:210:48: 0x594a033 in lowerCheckedModulesToLir (mod.zig)
    var mono = try postcheck.Monotype.Lower.run(
                                               ^
/home/austinclem1/projects/roc/src/cli/main.zig:8244:67: 0x861786d in rocBuildLlvm (main.zig)
    var lowered = try lir.CheckedPipeline.lowerCheckedModulesToLir(
                                                                  ^
/home/austinclem1/projects/roc/src/cli/main.zig:6784:42: 0x9da6b12 in rocBuildDefaultApp (main.zig)
        .size, .speed => try rocBuildLlvm(ctx, synthetic_args),
                                         ^
/home/austinclem1/projects/roc/src/cli/main.zig:6729:34: 0x8613810 in rocBuild (main.zig)
        return rocBuildDefaultApp(ctx, args, source);
                                 ^
/home/austinclem1/projects/roc/src/cli/main.zig:1119:40: 0x4cf0763 in mainArgs (main.zig)
        .build => |build_args| rocBuild(&ctx, build_args, args[0]) catch |err| switch (err) {
                                       ^
/home/austinclem1/projects/roc/src/cli/main.zig:976:13: 0x4cee592 in main (main.zig)
    mainArgs(gpa, arena, args, init.io) catch |err| {
            ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions