Skip to content
Open
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
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/op_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ func (m *Machine) doOpInterfaceType() {
}
// push interface type
it := &InterfaceType{
PkgPath: m.Package.PkgPath,
Methods: methods,
Generic: x.Generic,
PkgPath: m.Package.PkgPath,
FieldTypes: methods,
Generic: x.Generic,
}
m.PushValue(TypedValue{
T: gTypeType,
Expand Down
10 changes: 5 additions & 5 deletions gnovm/pkg/gnolang/realm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,9 @@ func copyTypeWithRefs(typ Type) Type {
}
case *InterfaceType:
return &InterfaceType{
PkgPath: ct.PkgPath,
Methods: copyFieldsWithRefs(ct.Methods),
Generic: ct.Generic,
PkgPath: ct.PkgPath,
FieldTypes: copyFieldsWithRefs(ct.FieldTypes),
Generic: ct.Generic,
}
case *TypeType:
return &TypeType{}
Expand Down Expand Up @@ -1349,8 +1349,8 @@ func fillType(store Store, typ Type) Type {
ct.Value = fillType(store, ct.Value)
return ct
case *InterfaceType:
for i, mthd := range ct.Methods {
ct.Methods[i].Type = fillType(store, mthd.Type)
for i, mthd := range ct.FieldTypes {
ct.FieldTypes[i].Type = fillType(store, mthd.Type)
}
return ct
case *TypeType:
Expand Down
22 changes: 11 additions & 11 deletions gnovm/pkg/gnolang/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,17 +904,17 @@ func (pt *PackageType) IsNamed() bool {
// Interface type

type InterfaceType struct {
PkgPath string
Methods []FieldType
Generic Name // for uverse "generics"
PkgPath string
FieldTypes []FieldType
Generic Name // for uverse "generics"

typeid TypeID
}

// General empty interface.

func (it *InterfaceType) IsEmptyInterface() bool {
return len(it.Methods) == 0
return len(it.FieldTypes) == 0
}

func (it *InterfaceType) Kind() Kind {
Expand All @@ -932,7 +932,7 @@ func (it *InterfaceType) TypeID() TypeID {
// packages may have the same TypeID if and only if
// neither have unexported fields. pt.Path is only
// included in field names that are not uppercase.
ms := FieldTypeList(it.Methods)
ms := FieldTypeList(it.FieldTypes)
// XXX pre-sort.
sort.Sort(ms)
it.typeid = typeid("interface{" + ms.TypeIDForPackage(it.PkgPath).String() + "}")
Expand All @@ -941,8 +941,8 @@ func (it *InterfaceType) TypeID() TypeID {
}

func (it *InterfaceType) GetMethodFieldType(mname Name) *FieldType {
for i := range it.Methods {
im := &it.Methods[i]
for i := range it.FieldTypes {
im := &it.FieldTypes[i]
Comment on lines +944 to +945
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems in consistent with the func name.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right I missed this one, I think the function could be simply GetMethodFieldType => GetFieldType

What do you think ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of the same PR, do you think I should also rename methods to something else in:

gnovm/pkg/gnolang/nodes.go:704

type InterfaceTypeExpr struct {
	Attributes
	Methods FieldTypeExprs // list of methods
	Generic Name           // for uverse generics
}

Copy link
Contributor

@ltzmaxwell ltzmaxwell Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetMethodFieldType => GetFieldType

looks good to me.

As part of the same PR, do you think I should also rename methods to something else in:

gnovm/pkg/gnolang/nodes.go:704

i think yes.

==========================================================
looking back to the InterfaceType, StructType, StructValue definition, i think there's some inaccurate in modification of Methods - > FieldTypes, perhaps Fields would be a better option—especially if we consider that Methods may not be entirely accurate due to embedding situation.

Overall, these are minor differences. I don’t have a strong opinion about changing the name due to the reason mentioned in the initial issue.

cc :/ @thehowl @mvertes for deeper insights.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the rename of Allocator.Allocate to Allocator.Account.
But I'm not convinced that InterfaceType.FieldTypes is better that InterfaceType.Methods. Even if objects implementing an interface have embedded structs to reach a particular method, interface types are still about methods only.

if im.Name == mname {
return im
}
Expand All @@ -954,10 +954,10 @@ func (it *InterfaceType) String() string {
if it.Generic != "" {
return fmt.Sprintf("<%s>{%s}",
it.Generic,
FieldTypeList(it.Methods).String())
FieldTypeList(it.FieldTypes).String())
} else {
return fmt.Sprintf("interface {%s}",
FieldTypeList(it.Methods).String())
FieldTypeList(it.FieldTypes).String())
}
}

Expand Down Expand Up @@ -985,7 +985,7 @@ func (it *InterfaceType) FindEmbeddedFieldType(callerPath string, n Name, m map[
m[it] = struct{}{}
}
// ...
for _, im := range it.Methods {
for _, im := range it.FieldTypes {
if im.Name == n {
// Ensure exposed or package match.
if !isUpper(string(n)) && it.PkgPath != callerPath {
Expand Down Expand Up @@ -1024,7 +1024,7 @@ func (it *InterfaceType) FindEmbeddedFieldType(callerPath string, n Name, m map[
// For run-time type assertion.
// TODO: optimize somehow.
func (it *InterfaceType) VerifyImplementedBy(ot Type) error {
for _, im := range it.Methods {
for _, im := range it.FieldTypes {
if im.Type.Kind() == InterfaceKind {
// field is embedded interface...
im2 := baseOf(im.Type).(*InterfaceType)
Expand Down
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var gErrorType = &DeclaredType{
Name: "error",
Base: &InterfaceType{
PkgPath: uversePkgPath,
Methods: []FieldType{
FieldTypes: []FieldType{
{
Name: "Error",
Type: &FuncType{
Expand All @@ -42,7 +42,7 @@ var gStringerType = &DeclaredType{
Name: "stringer",
Base: &InterfaceType{
PkgPath: uversePkgPath,
Methods: []FieldType{
FieldTypes: []FieldType{
{
Name: "String",
Type: &FuncType{
Expand Down Expand Up @@ -93,7 +93,7 @@ var gRealmType = &DeclaredType{
Name: "realm",
Base: &InterfaceType{
PkgPath: uversePkgPath,
Methods: []FieldType{
FieldTypes: []FieldType{
{
Name: "Address",
Type: &FuncType{
Expand Down
2 changes: 1 addition & 1 deletion gnovm/tests/stdlibs/fmt/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func X_valueOfInternal(v gnolang.TypedValue) (
case gnolang.StructKind:
kind, xlen = "struct", len(baseT.(*gnolang.StructType).Fields)
case gnolang.InterfaceKind:
kind, xlen = "interface", len(baseT.(*gnolang.InterfaceType).Methods)
kind, xlen = "interface", len(baseT.(*gnolang.InterfaceType).FieldTypes)
case gnolang.FuncKind:
kind = "func"
case gnolang.MapKind:
Expand Down
Loading