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(gnovm): remove preprocessing variable #3728

Merged
merged 5 commits into from
Feb 24, 2025
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
6 changes: 6 additions & 0 deletions gnovm/pkg/gnolang/op_assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func (m *Machine) doOpDefine() {
}
}
}
if !m.PreprocessorMode && isUntyped(rvs[i].T) && rvs[i].T.Kind() != BoolKind {
panic("untyped conversion should not happen at runtime")
}
ptr.Assign2(m.Alloc, m.Store, m.Realm, rvs[i], true)
}
}
Expand All @@ -41,6 +44,9 @@ func (m *Machine) doOpAssign() {
}
}
}
if !m.PreprocessorMode && isUntyped(rvs[i].T) && rvs[i].T.Kind() != BoolKind {
panic("untyped conversion should not happen at runtime")
}
lv.Assign2(m.Alloc, m.Store, m.Realm, rvs[i], true)
}
}
Expand Down
44 changes: 20 additions & 24 deletions gnovm/pkg/gnolang/op_decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,31 @@ func (m *Machine) doOpValueDecl() {
} else {
tv = rvs[i]
}
if nt != nil {
if nt.Kind() == InterfaceKind {
if isUntyped(tv.T) {
ConvertUntypedTo(&tv, nil)
} else {
// keep type as is.

if isUntyped(tv.T) {
if !s.Const {
if !m.PreprocessorMode && rvs[i].T.Kind() != BoolKind {
panic("untyped conversion should not happen at runtime")
}
} else {
if isUntyped(tv.T) {
ConvertUntypedTo(&tv, nt)
} else {
if debug {
if nt.TypeID() != tv.T.TypeID() &&
baseOf(nt).TypeID() != tv.T.TypeID() {
panic(fmt.Sprintf(
"type mismatch: %s vs %s",
nt.TypeID(),
tv.T.TypeID(),
))
}
ConvertUntypedTo(&tv, nil)
}
} else if nt != nil {
// if nt.T is an interface, maintain tv.T as-is.
if nt.Kind() != InterfaceKind {
if debug {
if nt.TypeID() != tv.T.TypeID() &&
baseOf(nt).TypeID() != tv.T.TypeID() {
panic(fmt.Sprintf(
"type mismatch: %s vs %s",
nt.TypeID(),
tv.T.TypeID(),
))
}
tv.T = nt
}
tv.T = nt
}
} else if s.Const {
// leave untyped as is.
} else if isUntyped(tv.T) {
ConvertUntypedTo(&tv, nil)
}

nx := &s.NameExprs[i]
ptr := lb.GetPointerToMaybeHeapDefine(m.Store, nx)
ptr.Assign2(m.Alloc, m.Store, m.Realm, tv, false)
Expand Down
3 changes: 3 additions & 0 deletions gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,9 @@ func makeUverseNode() {
}
}

if isUntyped(exception.Value.T) {
ConvertUntypedTo(&exception.Value, nil)
}
m.PushValue(exception.Value)
// Recover complete; remove exceptions.
m.Exceptions = nil
Expand Down
14 changes: 0 additions & 14 deletions gnovm/pkg/gnolang/values_conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1316,28 +1316,14 @@ func ConvertUntypedTo(tv *TypedValue, t Type) {
}
switch tv.T {
case UntypedBoolType:
if debug {
if t.Kind() != BoolKind {
panic("untyped bool can only be converted to bool kind")
}
}
tv.T = t
case UntypedRuneType:
ConvertUntypedRuneTo(tv, t)
case UntypedBigintType:
if preprocessing.Load() == 0 {
panic("untyped Bigint conversion should not happen during interpretation")
}
ConvertUntypedBigintTo(tv, tv.V.(BigintValue), t)
case UntypedBigdecType:
if preprocessing.Load() == 0 {
panic("untyped Bigdec conversion should not happen during interpretation")
}
ConvertUntypedBigdecTo(tv, tv.V.(BigdecValue), t)
case UntypedStringType:
if preprocessing.Load() == 0 {
panic("untyped String conversion should not happen during interpretation")
}
if t.Kind() == StringKind {
tv.T = t
return
Expand Down
Loading