Skip to content

Commit 28ee97c

Browse files
committed
refactor(compiler): flatten call lowering branches
Reduce local nesting in inferCallParamTypes and lowerCallArgs without changing the staged call-lowering flow.
1 parent 2301ed0 commit 28ee97c

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

compiler/compiler.go

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,26 @@ func (c *Compiler) inferCallParamTypes(ce *ast.CallExpression, info *ExprInfo) (
239239
paramTypes := []Type{}
240240
useBoundScalars := len(c.pendingLoopRanges(info.Ranges)) == 0
241241
for _, arg := range ce.Arguments {
242-
if useBoundScalars {
243-
if ident, ok := arg.(*ast.Identifier); ok {
244-
if sym, exists := c.getRawSymbol(ident.Value); exists {
245-
paramTypes = append(paramTypes, valType(sym))
246-
continue
247-
}
242+
ident, isIdent := arg.(*ast.Identifier)
243+
if useBoundScalars && isIdent {
244+
if sym, exists := c.getRawSymbol(ident.Value); exists {
245+
paramTypes = append(paramTypes, valType(sym))
246+
continue
248247
}
249248
}
250249

251250
argInfo := c.ExprCache[key(c.FuncNameMangled, arg)]
252251
if argInfo == nil {
253-
if ident, ok := arg.(*ast.Identifier); ok {
254-
sym, exists := c.getRawSymbol(ident.Value)
255-
if !exists {
256-
return nil, c.addCallTypeError(arg.Tok(), fmt.Sprintf("could not resolve type information for call argument %q", ident.Value))
257-
}
258-
paramTypes = append(paramTypes, valType(sym))
259-
continue
252+
if !isIdent {
253+
return nil, c.addCallTypeError(arg.Tok(), "could not resolve type information for call argument")
254+
}
255+
256+
sym, exists := c.getRawSymbol(ident.Value)
257+
if !exists {
258+
return nil, c.addCallTypeError(arg.Tok(), fmt.Sprintf("could not resolve type information for call argument %q", ident.Value))
260259
}
261-
return nil, c.addCallTypeError(arg.Tok(), "could not resolve type information for call argument")
260+
paramTypes = append(paramTypes, valType(sym))
261+
continue
262262
}
263263
for _, argType := range argInfo.OutTypes {
264264
if info.LoopInside {
@@ -2421,21 +2421,25 @@ func (c *Compiler) lowerCallArgs(funcName string, args []callArg, sig *callSigna
24212421
aliasIndices := c.buildCallParamAliasIndices(sig, args, dest)
24222422
for i, arg := range args {
24232423
sym := arg.Symbol
2424-
if sig.ABI.Params[i].Mode == ABIParamIndirect {
2425-
if arg.Name != "" {
2426-
sym, _ = c.getRawSymbol(arg.Name)
2427-
if sym.Type.Kind() != PtrKind {
2428-
sym = c.promoteToMemory(arg.Name)
2429-
}
2430-
} else if sym.Type.Kind() != PtrKind {
2424+
if sig.ABI.Params[i].Mode != ABIParamIndirect {
2425+
args[i].Lowered = c.derefIfPointer(sym, fmt.Sprintf("%s_arg_%d_load", funcName, i))
2426+
continue
2427+
}
2428+
2429+
if arg.Name == "" {
2430+
if sym.Type.Kind() != PtrKind {
24312431
name := fmt.Sprintf("%s_arg_%d", funcName, i)
24322432
sym, _ = c.makePtr(name, sym)
24332433
}
24342434
args[i].Lowered = sym
24352435
continue
24362436
}
24372437

2438-
args[i].Lowered = c.derefIfPointer(sym, fmt.Sprintf("%s_arg_%d_load", funcName, i))
2438+
sym, _ = c.getRawSymbol(arg.Name)
2439+
if sym.Type.Kind() != PtrKind {
2440+
sym = c.promoteToMemory(arg.Name)
2441+
}
2442+
args[i].Lowered = sym
24392443
}
24402444
return aliasIndices
24412445
}

0 commit comments

Comments
 (0)