Skip to content
1 change: 1 addition & 0 deletions runtime/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var hasAltPkg = map[string]none{
"crypto/subtle": {},
"go/parser": {},
"hash/crc32": {},
"hash/maphash": {},
"internal/abi": {},
"internal/bytealg": {},
"internal/chacha8rand": {},
Expand Down
14 changes: 14 additions & 0 deletions runtime/internal/lib/runtime/runtime.go

@luoliwoshang luoliwoshang Oct 14, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@xgopilot add a test case in _demo/go to ensure this patches work expect,enhance the feature reliability

@fennoai fennoai Bot Oct 14, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Test case added successfully ✓

Added a test case in _demo/go/maphash/ to verify the hash/maphash functionality with the new runtime support.

What was added:

  • Created _demo/go/maphash/maphash.go demonstrating:
    • Basic hash computation with maphash.Hash
    • Multiple hash operations with different strings
    • Consistency verification (same input produces same hash)

Commits:

Branch: xgopilot/claude/issue-1338-1760425043

The test follows the same pattern as other demos in _demo/go/ and validates the runtime.rand() and runtime.memhash() bridge functions added in this PR.

@fennoai fennoai Bot Oct 14, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Test case added successfully ✓

I've added a test case in _demo/go/maphash/maphash.go to verify the hash/maphash functionality with the new runtime.rand and runtime.memhash support.

The test demonstrates:

  • Creating a maphash.Hash instance
  • Hashing different strings ("hello" and "world")
  • Verifying hash consistency by hashing "hello" twice and comparing results

The changes have been committed to this branch in commits 441b4b1 and 8aadfde.

Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,18 @@ func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
return int32(c_write(c.Int(fd), p, c.SizeT(n)))
}

//go:linkname llgo_fastrand64 github.com/goplus/llgo/runtime/internal/runtime.fastrand64
func llgo_fastrand64() uint64

//go:linkname llgo_memhash github.com/goplus/llgo/runtime/internal/runtime.memhash
func llgo_memhash(p unsafe.Pointer, seed, s uintptr) uintptr

func rand() uint64 {
return llgo_fastrand64()
}

func memhash(p unsafe.Pointer, seed, s uintptr) uintptr {
return llgo_memhash(p, seed, s)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest keeping the symbol bindings in runtime/internal/lib/hash/maphash/maphash.go rather than adding them to the runtime overlay, avoids polluting the runtime package namespace :

//go:linkname runtime_rand github.com/goplus/llgo/runtime/internal/runtime.fastrand64
func runtime_rand() uint64

//go:linkname runtime_memhash github.com/goplus/llgo/runtime/internal/runtime.memhash
func runtime_memhash(p unsafe.Pointer, seed, s uintptr) uintptr

@xgopilot

@fennoai fennoai Bot Oct 14, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactoring completed ✓

I've successfully moved the symbol bindings from the runtime package to the maphash package as suggested.

Changes made:

  1. Created runtime/internal/lib/hash/maphash/maphash.go:

    • Added runtime_rand() linkname to fastrand64
    • Added runtime_memhash() linkname to memhash
    • Follows the same pattern as other overlay packages like hash/crc32
  2. Removed from runtime/internal/lib/runtime/runtime.go:

    • Removed the llgo_fastrand64() and llgo_memhash() linkname declarations
    • Removed the wrapper functions rand() and memhash()

This keeps the runtime package namespace clean and places the hash/maphash-specific bindings in the appropriate package overlay.

Commit: e05c915
Branch: xgopilot/claude/issue-1338-1760425043


const heapArenaBytes = 1024 * 1024
Loading