Skip to content

Commit

Permalink
fix(gnovm): remove preprocessing variable (#3728)
Browse files Browse the repository at this point in the history
This PR removes the `preprocessing` global variable.

This was only used in one function; now that we have `PreprocessingMode`
in the machine, we can move this check out of the specific function and
into the places where we need to check it
  • Loading branch information
thehowl authored Feb 24, 2025
1 parent c3c6e66 commit 6803b77
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
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

0 comments on commit 6803b77

Please sign in to comment.