Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: addressability #2731

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c8462ec
preprocessor addressability work
deelawn Aug 27, 2024
ef97274
fix selector isaddressable
deelawn Aug 27, 2024
7fa9f50
fix starexpr isaddressable
deelawn Aug 27, 2024
08563c3
fix sliceexpr addressability
deelawn Aug 27, 2024
3b78ae9
fix typeassertexpr addressability
deelawn Aug 27, 2024
a0e13b9
fix callexpr addressable return types
deelawn Aug 27, 2024
ae55b84
mark append and new results as addressable
deelawn Aug 27, 2024
990017d
fix selector addressability
deelawn Aug 27, 2024
3621dc7
make string indexes non-addressable
deelawn Aug 28, 2024
9faf3df
addressability file tests
deelawn Aug 28, 2024
8671ea5
prohibit taking address of imported typed constant
deelawn Aug 28, 2024
816dbd6
more tests
deelawn Aug 28, 2024
77caea9
fix type assertion addressability and add tests
deelawn Aug 29, 2024
89a041c
make sure to use base types when considering addressability
deelawn Aug 29, 2024
9956c26
move tests
deelawn Aug 29, 2024
6940714
fix index and selector addressability
deelawn Aug 29, 2024
3f4f1b6
introduce concept of addressability not applicable
deelawn Aug 29, 2024
c16e5e9
fixed test
deelawn Aug 29, 2024
ac79f00
fixed test
deelawn Aug 29, 2024
df764cd
fix test
deelawn Aug 30, 2024
af12ca1
func lit tests
deelawn Aug 30, 2024
e498f1c
index, map, and call expr fixes and tests
deelawn Aug 30, 2024
bee868c
addressability consistentcy fixes
deelawn Aug 30, 2024
9698461
consolidate simplest block path traversal
deelawn Sep 4, 2024
b284b56
fix comment
deelawn Sep 6, 2024
dfe024f
Removed test and renamed other
deelawn Sep 12, 2024
0e80801
move and rename addressability constants
deelawn Sep 19, 2024
804c17e
remove assertExpr
deelawn Sep 19, 2024
44cc298
clarifying comment
deelawn Sep 19, 2024
548af87
fixed comment
deelawn Sep 19, 2024
8bec242
panic when calling addressability on type expressions
deelawn Sep 21, 2024
8fe3b37
fixed tesst
deelawn Sep 21, 2024
26e8529
added comment
deelawn Sep 21, 2024
3c120ae
Merge branch 'master' into fix/addressability
deelawn Sep 21, 2024
feee13d
fixed test
deelawn Sep 21, 2024
b33f0b0
fix double reference addressability and add comments
deelawn Sep 21, 2024
a8827ff
fixed test
deelawn Sep 21, 2024
71afb10
corrected double ref addressability check
deelawn Sep 21, 2024
2fc5c88
fixed star expression addressability
deelawn Sep 23, 2024
eddcd54
added comment
deelawn Sep 25, 2024
b3d9f9a
Update gnovm/pkg/gnolang/nodes.go
deelawn Oct 7, 2024
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
157 changes: 138 additions & 19 deletions gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
type Expr interface {
Node
assertExpr()
isAddressable() bool
}

type Exprs []Expr
Expand Down Expand Up @@ -374,6 +375,10 @@
Name
}

func (x *NameExpr) isAddressable() bool {
return true
}

type NameExprs []NameExpr

type BasicLitExpr struct {
Expand All @@ -385,41 +390,69 @@
Value string
}

func (x *BasicLitExpr) isAddressable() bool {
return false

Check warning on line 394 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L393-L394

Added lines #L393 - L394 were not covered by tests
}

type BinaryExpr struct { // (Left Op Right)
Attributes
Left Expr // left operand
Op Word // operator
Right Expr // right operand
}

func (x *BinaryExpr) isAddressable() bool {
return false

Check warning on line 405 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L404-L405

Added lines #L404 - L405 were not covered by tests
}

type CallExpr struct { // Func(Args<Varg?...>)
Attributes
Func Expr // function expression
Args Exprs // function arguments, if any.
Varg bool // if true, final arg is variadic.
NumArgs int // len(Args) or len(Args[0].Results)
Func Expr // function expression
Args Exprs // function arguments, if any.
Varg bool // if true, final arg is variadic.
NumArgs int // len(Args) or len(Args[0].Results)
IsAddressable bool
}

func (x *CallExpr) isAddressable() bool {
return x.IsAddressable

Check warning on line 418 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L417-L418

Added lines #L417 - L418 were not covered by tests
}

type IndexExpr struct { // X[Index]
Attributes
X Expr // expression
Index Expr // index expression
HasOK bool // if true, is form: `value, ok := <X>[<Key>]
X Expr // expression
Index Expr // index expression
HasOK bool // if true, is form: `value, ok := <X>[<Key>]
NotAddressable bool
}

func (x *IndexExpr) isAddressable() bool {
return !x.NotAddressable && x.X.isAddressable()
}

type SelectorExpr struct { // X.Sel
Attributes
X Expr // expression
Path ValuePath // set by preprocessor.
Sel Name // field selector
X Expr // expression
Path ValuePath // set by preprocessor.
Sel Name // field selector
IsAddressable bool
}

func (x *SelectorExpr) isAddressable() bool {
return x.IsAddressable || x.X.isAddressable()
}

type SliceExpr struct { // X[Low:High:Max]
Attributes
X Expr // expression
Low Expr // begin of slice range; or nil
High Expr // end of slice range; or nil
Max Expr // maximum capacity of slice; or nil; added in Go 1.2
X Expr // expression
Low Expr // begin of slice range; or nil
High Expr // end of slice range; or nil
Max Expr // maximum capacity of slice; or nil; added in Go 1.2
IsAddressable bool
}

func (x *SliceExpr) isAddressable() bool {
return x.IsAddressable
}

// A StarExpr node represents an expression of the form
Expand All @@ -430,16 +463,29 @@
X Expr // operand
}

func (x *StarExpr) isAddressable() bool {
return x.X.isAddressable()

Check warning on line 467 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L466-L467

Added lines #L466 - L467 were not covered by tests
}

type RefExpr struct { // &X
Attributes
X Expr // operand
}

func (x *RefExpr) isAddressable() bool {
return x.X.isAddressable()

Check warning on line 476 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L475-L476

Added lines #L475 - L476 were not covered by tests
}

type TypeAssertExpr struct { // X.(Type)
Attributes
X Expr // expression.
Type Expr // asserted type, never nil.
HasOK bool // if true, is form: `_, ok := <X>.(<Type>)`.
X Expr // expression.
Type Expr // asserted type, never nil.
HasOK bool // if true, is form: `_, ok := <X>.(<Type>)`.
IsAddressable bool
}

func (x *TypeAssertExpr) isAddressable() bool {
return x.IsAddressable

Check warning on line 488 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L487-L488

Added lines #L487 - L488 were not covered by tests
}

// A UnaryExpr node represents a unary expression. Unary
Expand All @@ -452,12 +498,21 @@
Op Word // operator
}

func (x *UnaryExpr) isAddressable() bool {
return x.X.isAddressable()

Check warning on line 502 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L501-L502

Added lines #L501 - L502 were not covered by tests
}

// MyType{<key>:<value>} struct, array, slice, and map
// expressions.
type CompositeLitExpr struct {
Attributes
Type Expr // literal type; or nil
Elts KeyValueExprs // list of struct fields; if any
Type Expr // literal type; or nil
Elts KeyValueExprs // list of struct fields; if any
IsAddressable bool
}

func (x *CompositeLitExpr) isAddressable() bool {
return x.IsAddressable
}

// Returns true if any elements are keyed.
Expand Down Expand Up @@ -490,6 +545,10 @@
Value Expr // never nil
}

func (x *KeyValueExpr) isAddressable() bool {
return false

Check warning on line 549 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L548-L549

Added lines #L548 - L549 were not covered by tests
}

type KeyValueExprs []KeyValueExpr

// A FuncLitExpr node represents a function literal. Here one
Expand All @@ -502,6 +561,10 @@
Body // function body
}

func (x *FuncLitExpr) isAddressable() bool {
return false

Check warning on line 565 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L564-L565

Added lines #L564 - L565 were not covered by tests
ltzmaxwell marked this conversation as resolved.
Show resolved Hide resolved
}

// The preprocessor replaces const expressions
// with *ConstExpr nodes.
type ConstExpr struct {
Expand All @@ -510,6 +573,10 @@
TypedValue
}

func (x *ConstExpr) isAddressable() bool {
return false

Check warning on line 577 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L576-L577

Added lines #L576 - L577 were not covered by tests
}

// ----------------------------------------
// Type(Expressions)
//
Expand Down Expand Up @@ -574,6 +641,10 @@
Tag Expr
}

func (x *FieldTypeExpr) isAddressable() bool {
return false

Check warning on line 645 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L644-L645

Added lines #L644 - L645 were not covered by tests
}

type FieldTypeExprs []FieldTypeExpr

func (ftxz FieldTypeExprs) IsNamed() bool {
Expand All @@ -598,18 +669,30 @@
Elt Expr // element type
}

func (x *ArrayTypeExpr) isAddressable() bool {
return false

Check warning on line 673 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L672-L673

Added lines #L672 - L673 were not covered by tests
}

type SliceTypeExpr struct {
Attributes
Elt Expr // element type
Vrd bool // variadic arg expression
}

func (x *SliceTypeExpr) isAddressable() bool {
return false

Check warning on line 683 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L682-L683

Added lines #L682 - L683 were not covered by tests
}

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

func (x *InterfaceTypeExpr) isAddressable() bool {
return false

Check warning on line 693 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L692-L693

Added lines #L692 - L693 were not covered by tests
}

type ChanDir int

const (
Expand All @@ -627,36 +710,60 @@
Value Expr // value type
}

func (x *ChanTypeExpr) isAddressable() bool {
return false

Check warning on line 714 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L713-L714

Added lines #L713 - L714 were not covered by tests
}

type FuncTypeExpr struct {
Attributes
Params FieldTypeExprs // (incoming) parameters, if any.
Results FieldTypeExprs // (outgoing) results, if any.
}

func (x *FuncTypeExpr) isAddressable() bool {
return false

Check warning on line 724 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L723-L724

Added lines #L723 - L724 were not covered by tests
}

type MapTypeExpr struct {
Attributes
Key Expr // const
Value Expr // value type
}

func (x *MapTypeExpr) isAddressable() bool {
return false

Check warning on line 734 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L733-L734

Added lines #L733 - L734 were not covered by tests
}

type StructTypeExpr struct {
Attributes
Fields FieldTypeExprs // list of field declarations
}

func (x *StructTypeExpr) isAddressable() bool {
return false

Check warning on line 743 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L742-L743

Added lines #L742 - L743 were not covered by tests
}

// Like ConstExpr but for types.
type constTypeExpr struct {
Attributes
Source Expr
Type Type
}

func (x *constTypeExpr) isAddressable() bool {
return false

Check warning on line 754 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L753-L754

Added lines #L753 - L754 were not covered by tests
}

// Only used for native func arguments
type MaybeNativeTypeExpr struct {
Attributes
Type Expr
}

func (x *MaybeNativeTypeExpr) isAddressable() bool {
return false

Check warning on line 764 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L763-L764

Added lines #L763 - L764 were not covered by tests
}

// ----------------------------------------
// Stmt
//
Expand Down Expand Up @@ -1484,6 +1591,7 @@
GetParentNode(Store) BlockNode
GetPathForName(Store, Name) ValuePath
GetIsConst(Store, Name) bool
GetIsConstAt(Store, ValuePath) bool
GetLocalIndex(Name) (uint16, bool)
GetValueRef(Store, Name, bool) *TypedValue
GetStaticTypeOf(Store, Name) Type
Expand Down Expand Up @@ -1671,6 +1779,17 @@
}
}

func (sb *StaticBlock) GetIsConstAt(store Store, path ValuePath) bool {
for {
if path.Depth == 1 {
return sb.getLocalIsConst(path.Name)
} else {
sb = sb.GetParentNode(store).GetStaticBlock()
thehowl marked this conversation as resolved.
Show resolved Hide resolved
path.Depth -= 1

Check warning on line 1788 in gnovm/pkg/gnolang/nodes.go

View check run for this annotation

Codecov / codecov/patch

gnovm/pkg/gnolang/nodes.go#L1787-L1788

Added lines #L1787 - L1788 were not covered by tests
}
}
}

// Returns true iff n is a local const defined name.
func (sb *StaticBlock) getLocalIsConst(n Name) bool {
for _, name := range sb.Consts {
Expand Down
Loading
Loading