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

doc: some WASM documentation #23810

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

enghitalo
Copy link
Contributor

just some docs and better messages for assets.

Copy link

Connected to Huly®: V_0.6-22219

Comment on lines -915 to -916
pub type LabelIndex = int

Copy link
Member

Choose a reason for hiding this comment

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

why delete that?

Comment on lines 917 to 925
pub fn (mut func Function) unreachable() {
func.code << 0x00
func.code << 0x00 // unreachable
}

// nop instruction, does nothing.
// WebAssembly instruction: `nop`.
pub fn (mut func Function) nop() {
func.code << 0x01
func.code << 0x01 // nop
}
Copy link
Member

Choose a reason for hiding this comment

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

that clarifies nothing - the method is already named that

pub fn (mut func Function) c_return() {
func.code << 0x0F // return
}

Copy link
Member

Choose a reason for hiding this comment

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

why move the method, especially in a PR that is titled "some WASM documentation"?

enum Subsection as u8 {
name_module
name_function
name_local
// see: https://github.com/WebAssembly/extended-name-section
Copy link
Member

Choose a reason for hiding this comment

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

why move the comment?
is not its position chosen because the values that follow are mentioned in the link?

Comment on lines +56 to +64
v128_t = 0x7b // 128-bit vector (SIMD)
funcref_t = 0x70 // Function reference
externref_t = 0x6f // External reference
}

// RefType represents reference types in WebAssembly.
pub enum RefType as u8 {
funcref_t = 0x70
externref_t = 0x6f
funcref_t = 0x70 // Function reference
externref_t = 0x6f // External reference
Copy link
Member

Choose a reason for hiding this comment

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

there is no need for those comments - they clarify nothing, just duplicate the already existing names, and make it arguably harder to read (more info to absorb, that is slightly different, so you have to think about the difference, rather than just ignore it ...)

functypes []FuncType // Unique function type signatures
functions map[string]Function // Named functions defined in the module
globals []Global // Global variables
memory ?Memory // Single memory instances (Make it a array for multiple memories)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
memory ?Memory // Single memory instances (Make it a array for multiple memories)
memory ?Memory // Single memory instances (Make it a array for multiple memories)

that is not needed too and makes it more confusing - anyone reading that code should know that ?Type is a single thing, and that []Type means an array of potentially several. Putting that comment makes the reader think about why that is mentioned specifically, when it is obvious.

functions map[string]Function // Named functions defined in the module
globals []Global // Global variables
memory ?Memory // Single memory instances (Make it a array for multiple memories)
start ?string // Optional start function name
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
start ?string // Optional start function name
start ?string // start function name

global_imports []GlobalImport // Imported globals
segments []DataSegment // Data segments (active or passive)
debug bool // Whether to include debug info
mod_name ?string // Optional module name for debug info
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
mod_name ?string // Optional module name for debug info
mod_name ?string // module name for debug info

there is no need to duplicate info that is already present in the type itself

Comment on lines +78 to +79
fn_imports []FunctionImport // Imported functions
global_imports []GlobalImport // Imported globals
Copy link
Member

Choose a reason for hiding this comment

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

are those really needed?

Copy link
Member

Choose a reason for hiding this comment

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

imho the names of the fields are good enough, without the comments

pub mut:
export_name ?string
export_name ?string // Optional export name (defaults to name if unset)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export_name ?string // Optional export name (defaults to name if unset)
export_name ?string // export name (defaults to name if unset)

typ ValType
name ?string
typ ValType // Type of the local (e.g., i32, v128)
name ?string // Optional name for debug info
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name ?string // Optional name for debug info
name ?string // name for debug info

Comment on lines -36 to +46
mod.buf << 0x60 // function type indicator
mod.buf << 0x60 // Function type indicator
Copy link
Member

Choose a reason for hiding this comment

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

why capitalize inline comments?

Comment on lines -21 to +24
$compile_error('values can only be int, i32, i64, f32, f64')
$compile_error('Constant expressions only support be int, i32, i64, f32 and f64')
Copy link
Member

Choose a reason for hiding this comment

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

the previous error was clearer

Comment on lines -38 to +49
This module does not perform verification of the WebAssembly output.
This module does not perform verification of the WebAssembly output, yet.
Copy link
Member

Choose a reason for hiding this comment

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

there is no need of the yet

Copy link
Member

Choose a reason for hiding this comment

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

it either does, or it does not

Comment on lines -34 to +45
os.write_file_array('add.wasm', mod)!
os.write_file_array('add.wasm', mod) or { panic('Write failed: ${err}') }
Copy link
Member

@spytheman spytheman Feb 27, 2025

Choose a reason for hiding this comment

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

The previous line was clearer - in an example like that, clarity of the main purpose is important, and just ! to propagate the potential error is clearer, since the error handling is not the main point of the example.

max ?u32
name string // Name for debugging or export
export bool // Whether to export the memory
min u32 // Minimum size in pages (64KiB each)
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure, that it is in pages, and not in bytes?

@enghitalo enghitalo marked this pull request as draft March 8, 2025 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants