Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion bbq/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,19 @@ func (c *Compiler[_, _]) VisitEmitStatement(statement *ast.EmitStatement) (_ str
invocationExpression := statement.InvocationExpression
arguments := invocationExpression.Arguments
invocationTypes := c.DesugaredElaboration.InvocationExpressionTypes(invocationExpression)
c.compileArguments(arguments, invocationTypes)

// Instead of compiling arguments as usual (via compileArguments),
// only convert the arguments and don't transfer them.

for index, argument := range arguments {
c.compileExpression(argument.Expression)

parameterType := invocationTypes.ParameterTypes[index]
parameterTypeIndex := c.getOrAddType(parameterType)
c.emit(opcode.InstructionConvert{
Type: parameterTypeIndex,
})
}

argCount := len(arguments)
if argCount >= math.MaxUint16 {
Expand Down
2 changes: 1 addition & 1 deletion bbq/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ func TestCompileEmit(t *testing.T) {
opcode.InstructionStatement{},
// x
opcode.InstructionGetLocal{Local: xIndex},
opcode.InstructionTransferAndConvert{Type: 1},
opcode.InstructionConvert{Type: 1},
// emit
opcode.InstructionEmitEvent{
Type: 2,
Expand Down
2 changes: 1 addition & 1 deletion interpreter/interpreter_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func (interpreter *Interpreter) VisitEmitStatement(statement *ast.EmitStatement)
argumentType := argumentTypes[i]
parameterType := parameterTypes[i]

eventFields[i] = TransferAndConvert(
eventFields[i] = ConvertAndBoxWithValidation(
interpreter,
value,
argumentType,
Expand Down
38 changes: 38 additions & 0 deletions interpreter/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7340,6 +7340,44 @@ func TestInterpretEmitEvent(t *testing.T) {
)
}

func BenchmarkEmit(b *testing.B) {

inter, err := parseCheckAndPrepareWithOptions(
b,
`
event Foo(ints: [Int])

fun test() {
var i = 0
while i < 1000 {
emit Foo(ints: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
i = i + 1
}
}
`,
ParseCheckAndInterpretOptions{
InterpreterConfig: &interpreter.Config{
OnEventEmitted: func(
_ interpreter.ValueExportContext,
_ *sema.CompositeType,
_ []interpreter.Value,
) error {
return nil
},
},
},
)
require.NoError(b, err)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := inter.Invoke("test")
require.NoError(b, err)
}
}

func TestInterpretReferenceEventParameter(t *testing.T) {

t.Parallel()
Expand Down
Loading