Skip to content

Commit

Permalink
chore: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior committed Nov 8, 2023
1 parent 7e7b612 commit 77fdbd5
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 745 deletions.
223 changes: 0 additions & 223 deletions lib/runtime/allocator.go

This file was deleted.

22 changes: 12 additions & 10 deletions lib/runtime/allocator/freeing_bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
const (
Aligment = 8

// each pointer is prefixed with 8 bytes, wich indentifies the list
// each pointer is prefixed with 8 bytes, which indentifies the list
// index to which it belongs
HeaderSize = 8

// The minimum possible allocation size is choosen to be 8 bytes
// The minimum possible allocation size is chosen to be 8 bytes
// because in that case we would have easier time to provide the
// guaranteed alignment of 8
//
Expand All @@ -45,12 +45,14 @@ var (
bytesAllocatedPeakGauge = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gossamer_allocator",
Name: "bytes_allocated_peak",
Help: "the peak number of bytes ever allocated this is the maximum the `bytes_allocated_sum` ever reached",
Help: "the peak number of bytes ever allocated this is the maximum " +
"the `bytes_allocated_sum` ever reached",
})
addressSpaceUsedGague = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "gossamer_allocator",
Name: "address_space_used",
Help: "the amount of address space (in bytes) used by the allocator this is calculated as the difference between the allocator's bumper and the heap base.",
Help: "the amount of address space (in bytes) used by the allocator this is calculated as " +
"the difference between the allocator's bumper and the heap base.",
})
)

Expand All @@ -65,7 +67,7 @@ var (
ErrInvalidPointerForDealocation = errors.New("invalid pointer for deallocation")
ErrEmptyHeader = errors.New("allocation points to an empty header")
ErrAllocatorPoisoned = errors.New("allocator poisoned")
ErrMemoryShrinked = errors.New("memory shrinked")
ErrMemoryShrunk = errors.New("memory shrunk")
)

// The exponent for the power of two sized block adjusted to the minimum size.
Expand Down Expand Up @@ -164,7 +166,7 @@ func linkFromRaw(raw uint32) Link {
// ```ignore
// 64 32 0
//
// +--------------+-------------------+
// +--------------+-------------------+
//
// | 0 | next element link |
// +--------------+-------------------+
Expand All @@ -173,7 +175,7 @@ func linkFromRaw(raw uint32) Link {
// ```ignore
// 64 32 0
//
// +--------------+-------------------+
// +--------------+-------------------+
//
// | 1 | order |
// +--------------+-------------------+
Expand Down Expand Up @@ -211,7 +213,7 @@ func (f Occupied) intoFree() (Link, bool) {
var _ Header = (*Free)(nil)
var _ Header = (*Occupied)(nil)

// readHeaderFromMemory reads a header from memory, returns an error if ther
// readHeaderFromMemory reads a header from memory, returns an error if the
// headerPtr is out of bounds of the linear memory or if the read header is
// corrupted (e.g the order is incorrect)
func readHeaderFromMemory(mem runtime.Memory, headerPtr uint32) (Header, error) {
Expand Down Expand Up @@ -370,7 +372,7 @@ func (f *FreeingBumpHeapAllocator) Allocate(mem runtime.Memory, size uint32) (pt
}()

if mem.Size() < f.lastObservedMemorySize {
return 0, ErrMemoryShrinked
return 0, ErrMemoryShrunk
}

f.lastObservedMemorySize = mem.Size()
Expand Down Expand Up @@ -457,7 +459,7 @@ func (f *FreeingBumpHeapAllocator) Deallocate(mem runtime.Memory, ptr uint32) (e
}()

if mem.Size() < f.lastObservedMemorySize {
return ErrMemoryShrinked
return ErrMemoryShrunk
}

f.lastObservedMemorySize = mem.Size()
Expand Down
4 changes: 2 additions & 2 deletions lib/runtime/allocator/freeing_bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func TestShouldGetMaxItemSizeFromIndex(t *testing.T) {
rawOrder := 22
order, err := orderFromRaw(uint32(rawOrder))
require.NoError(t, err)
require.Equal(t, order.size(), uint32(MaxPossibleAllocations))
require.Equal(t, order.size(), MaxPossibleAllocations)
}

func TestDeallocateNeedsToMaintainLinkedList(t *testing.T) {
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestDoesNotAcceptShrinkingMemory(t *testing.T) {

ptr2, err := heap.Allocate(mem, PageSize/2)
require.Zero(t, ptr2)
require.ErrorIs(t, err, ErrMemoryShrinked)
require.ErrorIs(t, err, ErrMemoryShrunk)
}

func TestShouldGrowMemoryWhenRunningOutOfSpace(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions lib/runtime/allocator/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type MemoryInstance struct {
maxWasmPages uint32
}

//nolint:unparam
func (m *MemoryInstance) setMaxWasmPages(max uint32) {
m.maxWasmPages = max
}
Expand Down Expand Up @@ -39,6 +40,7 @@ func (m *MemoryInstance) Grow(pages uint32) (uint32, bool) {
return prevPages, true
}

//nolint:govet
func (m *MemoryInstance) ReadByte(offset uint32) (byte, bool) { return 0x00, false }
func (m *MemoryInstance) ReadUint64Le(offset uint32) (uint64, bool) {
return binary.LittleEndian.Uint64(m.data[offset : offset+8]), true
Expand All @@ -52,6 +54,8 @@ func (m *MemoryInstance) WriteUint64Le(offset uint32, v uint64) bool {
func (m *MemoryInstance) Read(offset, byteCount uint32) ([]byte, bool) {
return nil, false
}

//nolint:govet
func (m *MemoryInstance) WriteByte(offset uint32, v byte) bool {
return false
}
Expand Down
Loading

0 comments on commit 77fdbd5

Please sign in to comment.