WebAssembly type of a WebAssembly value that WebAssembly code could either expect on the evaluation stack or leave on the evaluation stack.
Instances1TestEquality
TestEquality WasmTypeTagDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.Types
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Moduleghc-9.10.3GHC2021
WebAssembly type of a WebAssembly value that WebAssembly code could either expect on the evaluation stack or leave on the evaluation stack.
TestEquality WasmTypeTagDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesSingleton type useful for programming with WasmType at the type level.
TagI32 :: WasmTypeTag 'I32TagI64 :: WasmTypeTag 'I64TagF32 :: WasmTypeTag 'F32TagF64 :: WasmTypeTag 'F64TestEquality WasmTypeTagDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesShow (WasmTypeTag t)Defined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesSomeWasmType :: WasmTypeTag t -> SomeWasmTypeEq SomeWasmTypeDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesList of WebAssembly types used to describe the sequence of WebAssembly values that a block of code may expect on the stack or leave on the stack.
TypeListNil :: TypeList '[]TypeListCons :: WasmTypeTag t -> TypeList ts -> TypeList (t ': ts)The type of a WebAssembly function, loop, block, or conditional. This type says what values the code expects to pop off the stack and what values it promises to push. The WebAssembly standard requires that this type appear explicitly in the code.
For simplicity, we record other metadata in WasmCodeGenState by need, instead of carrying them along with SymName.
Eq SymNameDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesOrd SymNameDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesShow SymNameDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesIsString SymNameDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesUniquable SymNameDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesSymUndefinedNot defined in the current compilation unit.
[ undefined binding=global vis=default ]SymStaticDefined, not visible to other compilation units.
[ binding=local vis=default ]SymDefaultDefined, visible to other compilation units.
Adds .hidden & .globl directives in the output assembly.
[ binding=global vis=hidden ]Represents whether a symbol is a data symbol or a function
symbol. Unlike linkers for other targets, wasm-ld does panic at
link-time if it finds symbol kind inconsistency between the
definition site and other use sites.
Currently we solely rely on isCFunctionLabel to determine a
symbol's kind, but it does take extra effort to make it work. The
main source of inconsistency arises from hand-written Cmm sources,
where it's possible to refer to external entities like xxx_info
and xxx_closure without explicit import CLOSURE declarations.
The Cmm parser will implicitly assume those are foreign function
labels, and then this will break the WebAssembly backend. #22368
provides more context on this issue.
tl;dr for any GHC contributor that accidentally triggers wasm-ld
errors when hacking Cmm: whatever data symbols are used in new
code, just add the corresponding import CLOSURE declarations at
the top of that Cmm file.
WebAssembly doesn't really have proper read-only memory regions yet. Neverthless we add the .rodata logic here, wasm-ld will aggregate all .rodata sections into a single one, which adds possibility for runtime checks later, either via a customized runtime, or via code instrumentation. See https://github.com/llvm/llvm-project/blob/b296aed8ae239c20ebdd7969e978f8d2a3b9c178/lld/wasm/Writer.cpp#L856
Neither Cmm or Wasm type system takes integer signedness into account, therefore we always round up a CmmLit to the right width and handle it as an untyped integer.
FuncBodyfuncLocals :: [SomeWasmType]funcBody :: WasmControl (WasmStatements w) (WasmExpr w w) '[] '[w]Most are Cmm functions, but may also contain synthesized function of other types, sigh.
The w type variable in the Wasm IR stands for "platform word
type", so TagI32 on wasm32, and TagI64 on wasm64. This way, we
can make the codegen logic work on both wasm32/wasm64 in a
type-safe manner.
WasmComment :: String -> WasmInstr a b bWasmNop :: WasmInstr a b bWasmDrop :: WasmInstr a (t ': c) cWasmUnreachable :: WasmInstr a b cWasmConst :: WasmTypeTag t -> Integer -> WasmInstr a b (t ': b)WasmSymConst :: SymName -> WasmInstr a b (a ': b)WasmLoad :: WasmTypeTag t -> Maybe Int -> Signage -> Int -> AlignmentSpec -> WasmInstr a (a ': pre) (t ': pre)WasmStore :: WasmTypeTag t -> Maybe Int -> Int -> AlignmentSpec -> WasmInstr a (t ': a ': c) cWasmGlobalGet :: WasmTypeTag t -> SymName -> WasmInstr a b (t ': b)WasmGlobalSet :: WasmTypeTag t -> SymName -> WasmInstr a (t ': c) cWasmLocalGet :: WasmTypeTag t -> Int -> WasmInstr a b (t ': b)WasmLocalSet :: WasmTypeTag t -> Int -> WasmInstr a (t ': c) cWasmLocalTee :: WasmTypeTag t -> Int -> WasmInstr a (t ': pre) (t ': pre)WasmCCall :: SymName -> WasmInstr a b cWasmCCallIndirect :: TypeList arg_tys -> TypeList ret_tys -> WasmInstr a (a ': pre) cWasmConcat :: WasmInstr a b mid -> WasmInstr a mid c -> WasmInstr a b cWasmReinterpret :: WasmTypeTag t0 -> WasmTypeTag t1 -> WasmInstr a (t0 ': pre) (t1 ': pre)WasmTruncSat :: Signage -> WasmTypeTag t0 -> WasmTypeTag t1 -> WasmInstr a (t0 ': pre) (t1 ': pre)WasmConvert :: Signage -> WasmTypeTag t0 -> WasmTypeTag t1 -> WasmInstr a (t0 ': pre) (t1 ': pre)WasmAdd :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmSub :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmMul :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmDiv :: Signage -> WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmRem :: Signage -> WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmAnd :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmOr :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmXor :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmEq :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (a ': pre)WasmNe :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (a ': pre)WasmLt :: Signage -> WasmTypeTag t -> WasmInstr a (t ': t ': pre) (a ': pre)WasmGt :: Signage -> WasmTypeTag t -> WasmInstr a (t ': t ': pre) (a ': pre)WasmLe :: Signage -> WasmTypeTag t -> WasmInstr a (t ': t ': pre) (a ': pre)WasmGe :: Signage -> WasmTypeTag t -> WasmInstr a (t ': t ': pre) (a ': pre)WasmShl :: WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmShr :: Signage -> WasmTypeTag t -> WasmInstr a (t ': t ': pre) (t ': pre)WasmI32Extend8S :: WasmInstr a ('I32 ': pre) ('I32 ': pre)WasmI32Extend16S :: WasmInstr a ('I32 ': pre) ('I32 ': pre)WasmI64Extend8S :: WasmInstr a ('I64 ': pre) ('I64 ': pre)WasmI64Extend16S :: WasmInstr a ('I64 ': pre) ('I64 ': pre)WasmI64Extend32S :: WasmInstr a ('I64 ': pre) ('I64 ': pre)WasmI64ExtendI32 :: Signage -> WasmInstr a ('I32 ': pre) ('I64 ': pre)WasmI32WrapI64 :: WasmInstr a ('I64 ': pre) ('I32 ': pre)WasmF32DemoteF64 :: WasmInstr a ('F64 ': pre) ('F32 ': pre)WasmF64PromoteF32 :: WasmInstr a ('F32 ': pre) ('F64 ': pre)WasmAbs :: WasmTypeTag t -> WasmInstr a (t ': pre) (t ': pre)WasmSqrt :: WasmTypeTag t -> WasmInstr a (t ': pre) (t ': pre)WasmNeg :: WasmTypeTag t -> WasmInstr a (t ': pre) (t ': pre)WasmCond :: WasmInstr a c c -> WasmInstr a (a ': c) cSomeWasmExpr :: WasmTypeTag t -> WasmExpr w t -> SomeWasmExpr wWasmStatements (forall (pre :: [WasmType]). WasmInstr w pre pre)Representation of WebAssembly control flow.
Normally written as
WasmControl s e pre post
Type parameter s is the type of (unspecified) statements.
It might be instantiated with an open Cmm block or with a sequence
of Wasm instructions.
Parameter e is the type of expressions.
Parameter pre represents the values that are expected on the
WebAssembly stack when the code runs, and post represents
the state of the stack on completion.
WasmPush :: WasmTypeTag t -> b -> WasmControl a b c (t ': c)WasmBlock :: WasmFunctionType c d -> WasmControl a b c d -> WasmControl a b c dWasmLoop :: WasmFunctionType c d -> WasmControl a b c d -> WasmControl a b c dWasmIfTop :: WasmFunctionType pre d -> WasmControl a b pre d -> WasmControl a b pre d -> WasmControl a b ('I32 ': pre) dWasmBr :: Int -> WasmControl a b c dWasmFallthrough :: WasmControl a b c dWasmBrTable :: b -> BrTableInterval -> [Int] -> Int -> WasmControl a b c dWasmTailCall :: b -> WasmControl a b c dWasmActions :: a -> WasmControl a b c cWasmSeq :: WasmControl a b c mid -> WasmControl a b mid d -> WasmControl a b c dShow BrTableIntervalDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesOutputable BrTableIntervalDefined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesWasmCodeGenStatewasmPlatform :: PlatformTarget platform
defaultSyms :: SymSetDefined symbols with SymDefault visibility.
funcTypes :: SymMap ([SomeWasmType], [SomeWasmType])Function types, defined or not. There may exist a function whose type is unknown (e.g. as a function pointer), in that case we fall back to () -> (), it's imperfect but works with wasm-ld.
funcBodies :: SymMap (FuncBody w)Defined function bodies.
dataSections :: SymMap DataSectionDefined data sections.
ctors :: [SymName]ctors in the current compilation unit.
localRegs :: UniqFM LocalReg LocalInfolocalRegsCount :: IntwasmUniqSupply :: UniqSupplyWasmCodeGenM (State (WasmCodeGenState w) a)Monad (WasmCodeGenM w)Defined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesFunctor (WasmCodeGenM w)Defined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesApplicative (WasmCodeGenM w)Defined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.TypesMonadUnique (WasmCodeGenM w)Defined in ghc-9.10.3 · GHC.CmmToAsm.Wasm.Types