Skip to content

feat: map go and defer of interface method calls - #215

Merged
conr2d merged 1 commit into
mainfrom
feat/interface-method-launch
Dec 4, 2026
Merged

conr2d merged 1 commit into
mainfrom
feat/interface-method-launch

Conversation

@4lmighty

@4lmighty 4lmighty commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

This freezes go i.M(args) and defer i.M(args) where i is an interface value. That is the interface-method part of #67.

Go saves the interface value and evaluates the arguments. Only then does it find that the interface is nil, and it panics in the launching goroutine, so no goroutine starts and no call is deferred. The parity case checks that order: a counter that an argument increments is already incremented when recover sees the panic.

The translation follows the same order:

auto _eo_go_receiver_0 = g;
std::string _eo_go_arg_0_0 = name;
int64_t _eo_go_arg_0_1 = next();
eo::nil_check(_eo_go_receiver_0);
go([=]() mutable { return _eo_go_receiver_0.Greet(_eo_go_arg_0_0, _eo_go_arg_0_1); });
  • src/eo/interface.h: adds eo::nil_check(const I&). For a nil interface value it throws Go's nil dereference panic, as a method call would.
  • docs/GOROUTINE.md: adds an "Interface method calls" section, including the case of a method promoted from an embedded interface field. This form is removed from "Unfrozen launch forms".
  • docs/TRANSLATION_RULES.md: adds the matching deferred form, with eo_defer_co used for a coroutine method. The not-covered lists are updated.
  • tests/parity/interface_method_launch, which covers:
    • go of a plain method and of a coroutine method, where the receiver and the arguments are captured before the variables change;
    • defer of a plain method and of a coroutine method;
    • go and defer on a nil interface, recovered in the launcher, after the arguments are evaluated.

etcd raft needs this. Its rafttest package runs go n.Step(ctx, m) on an embedded raft.Node, and its tests run defer n.Stop().

Test plan

  • The full suite passes locally (396/396).
  • Mutation: dropping nil_check from the nil go fails the case.
  • Mutation: moving nil_check before the arguments in the nil defer fails the case.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ

A go or defer statement that calls a method of an interface value saves
the interface value, then the arguments, and then checks the saved value
with the new eo::nil_check. Go evaluates the arguments before it finds a
nil interface and panics in the launching goroutine, so the check throws
Go's nil dereference panic there, and the call is not launched or
deferred. etcd raft's rafttest launches n.Step of an embedded raft.Node,
and its tests defer n.Stop().

This freezes the interface-method part of #67.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WKhFr4YH1YUGTnN1iSi9bQ
@conr2d
conr2d merged commit 6388b38 into main Dec 4, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants