Skip to content

Commit 203b01f

Browse files
committed
Restrict Damian's magic hack to go 1.18 and above
1 parent 464c98b commit 203b01f

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

builder/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
172172
AutomaticStackSize: config.AutomaticStackSize(),
173173
DefaultStackSize: config.Target.DefaultStackSize,
174174
NeedsStackObjects: config.NeedsStackObjects(),
175+
GoMinorVersion: config.GoMinorVersion,
175176
Debug: true,
176177
}
177178

compiler/compiler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Config struct {
5050
AutomaticStackSize bool
5151
DefaultStackSize uint64
5252
NeedsStackObjects bool
53+
GoMinorVersion int
5354
Debug bool // Whether to emit debug information in the LLVM module.
5455
}
5556

compiler/interface.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func (c *compilerContext) getInterfaceMethodSet(typ types.Type) llvm.Value {
329329
// getMethodSignatureName returns a unique name (that can be used as the name of
330330
// a global) for the given method.
331331
func (c *compilerContext) getMethodSignatureName(method *types.Func) string {
332-
signature := methodSignature(method)
332+
signature := c.methodSignature(method)
333333
var globalName string
334334
if token.IsExported(method.Name()) {
335335
globalName = "reflect/methods." + signature
@@ -572,16 +572,16 @@ func (c *compilerContext) getInterfaceInvokeWrapper(fn *ssa.Function, llvmFn llv
572572
//
573573
// String() string
574574
// Read([]byte) (int, error)
575-
func methodSignature(method *types.Func) string {
576-
return method.Name() + signature(method.Type().(*types.Signature))
575+
func (c *compilerContext) methodSignature(method *types.Func) string {
576+
return method.Name() + c.signature(method.Type().(*types.Signature))
577577
}
578578

579579
// Make a readable version of a function (pointer) signature.
580580
// Examples:
581581
//
582582
// () string
583583
// (string, int) (int, error)
584-
func signature(sig *types.Signature) string {
584+
func (c *compilerContext) signature(sig *types.Signature) string {
585585
s := ""
586586
if sig.Params().Len() == 0 {
587587
s += "()"
@@ -591,29 +591,29 @@ func signature(sig *types.Signature) string {
591591
if i > 0 {
592592
s += ", "
593593
}
594-
s += emptyInterfaceToAny(sig.Params().At(i).Type().String())
594+
s += c.emptyInterfaceToAny(sig.Params().At(i).Type().String())
595595
}
596596
s += ")"
597597
}
598598
if sig.Results().Len() == 0 {
599599
// keep as-is
600600
} else if sig.Results().Len() == 1 {
601-
s += " " + emptyInterfaceToAny(sig.Results().At(0).Type().String())
601+
s += " " + c.emptyInterfaceToAny(sig.Results().At(0).Type().String())
602602
} else {
603603
s += " ("
604604
for i := 0; i < sig.Results().Len(); i++ {
605605
if i > 0 {
606606
s += ", "
607607
}
608-
s += emptyInterfaceToAny(sig.Results().At(i).Type().String())
608+
s += c.emptyInterfaceToAny(sig.Results().At(i).Type().String())
609609
}
610610
s += ")"
611611
}
612612
return s
613613
}
614614

615-
func emptyInterfaceToAny(typ string) string {
616-
if typ == "interface{}" {
615+
func (c *compilerContext) emptyInterfaceToAny(typ string) string {
616+
if c.GoMinorVersion >= 18 && typ == "interface{}" {
617617
return "any"
618618
}
619619

0 commit comments

Comments
 (0)