Source File
features.go
Belonging Package
github.com/tetratelabs/wazero/api
package apiimport ()// CoreFeatures is a bit flag of WebAssembly Core specification features. See// https://github.com/WebAssembly/proposals for proposals and their status.//// Constants define individual features, such as CoreFeatureMultiValue, or// groups of "finished" features, assigned to a WebAssembly Core Specification// version, e.g. CoreFeaturesV1 or CoreFeaturesV2.//// Note: Numeric values are not intended to be interpreted except as bit flags.type CoreFeatures uint64// CoreFeaturesV1 are features included in the WebAssembly Core Specification// 1.0. As of late 2022, this is the only version that is a Web Standard (W3C// Recommendation).//// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/const CoreFeaturesV1 = CoreFeatureMutableGlobal// CoreFeaturesV2 are features included in the WebAssembly Core Specification// 2.0 (20220419). As of late 2022, version 2.0 is a W3C working draft, not yet// a Web Standard (W3C Recommendation).//// See https://www.w3.org/TR/2022/WD-wasm-core-2-20220419/appendix/changes.html#release-1-1const CoreFeaturesV2 = CoreFeaturesV1 |CoreFeatureBulkMemoryOperations |CoreFeatureMultiValue |CoreFeatureNonTrappingFloatToIntConversion |CoreFeatureReferenceTypes |CoreFeatureSignExtensionOps |CoreFeatureSIMDconst (// CoreFeatureBulkMemoryOperations adds instructions modify ranges of// memory or table entries ("bulk-memory-operations"). This is included in// CoreFeaturesV2, but not CoreFeaturesV1.//// Here are the notable effects:// - Adds `memory.fill`, `memory.init`, `memory.copy` and `data.drop`// instructions.// - Adds `table.init`, `table.copy` and `elem.drop` instructions.// - Introduces a "passive" form of element and data segments.// - Stops checking "active" element and data segment boundaries at// compile-time, meaning they can error at runtime.//// Note: "bulk-memory-operations" is mixed with the "reference-types"// proposal due to the WebAssembly Working Group merging them// "mutually dependent". Therefore, enabling this feature requires enabling// CoreFeatureReferenceTypes, and vice-versa.//// See https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/bulk-memory-operations/Overview.md// https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/reference-types/Overview.md and// https://github.com/WebAssembly/spec/pull/1287CoreFeatureBulkMemoryOperations CoreFeatures = 1 << iota// CoreFeatureMultiValue enables multiple values ("multi-value"). This is// included in CoreFeaturesV2, but not CoreFeaturesV1.//// Here are the notable effects:// - Function (`func`) types allow more than one result.// - Block types (`block`, `loop` and `if`) can be arbitrary function// types.//// See https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/multi-value/Overview.mdCoreFeatureMultiValue// CoreFeatureMutableGlobal allows globals to be mutable. This is included// in both CoreFeaturesV1 and CoreFeaturesV2.//// When false, an api.Global can never be cast to an api.MutableGlobal, and// any wasm that includes global vars will fail to parse.CoreFeatureMutableGlobal// CoreFeatureNonTrappingFloatToIntConversion enables non-trapping// float-to-int conversions ("nontrapping-float-to-int-conversion"). This// is included in CoreFeaturesV2, but not CoreFeaturesV1.//// The only effect of enabling is allowing the following instructions,// which return 0 on NaN instead of panicking.// - `i32.trunc_sat_f32_s`// - `i32.trunc_sat_f32_u`// - `i32.trunc_sat_f64_s`// - `i32.trunc_sat_f64_u`// - `i64.trunc_sat_f32_s`// - `i64.trunc_sat_f32_u`// - `i64.trunc_sat_f64_s`// - `i64.trunc_sat_f64_u`//// See https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/nontrapping-float-to-int-conversion/Overview.mdCoreFeatureNonTrappingFloatToIntConversion// CoreFeatureReferenceTypes enables various instructions and features// related to table and new reference types. This is included in// CoreFeaturesV2, but not CoreFeaturesV1.//// - Introduction of new value types: `funcref` and `externref`.// - Support for the following new instructions:// - `ref.null`// - `ref.func`// - `ref.is_null`// - `table.fill`// - `table.get`// - `table.grow`// - `table.set`// - `table.size`// - Support for multiple tables per module:// - `call_indirect`, `table.init`, `table.copy` and `elem.drop`// - Support for instructions can take non-zero table index.// - Element segments can take non-zero table index.//// Note: "reference-types" is mixed with the "bulk-memory-operations"// proposal due to the WebAssembly Working Group merging them// "mutually dependent". Therefore, enabling this feature requires enabling// CoreFeatureBulkMemoryOperations, and vice-versa.//// See https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/bulk-memory-operations/Overview.md// https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/reference-types/Overview.md and// https://github.com/WebAssembly/spec/pull/1287CoreFeatureReferenceTypes// CoreFeatureSignExtensionOps enables sign extension instructions// ("sign-extension-ops"). This is included in CoreFeaturesV2, but not// CoreFeaturesV1.//// Adds instructions:// - `i32.extend8_s`// - `i32.extend16_s`// - `i64.extend8_s`// - `i64.extend16_s`// - `i64.extend32_s`//// See https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/sign-extension-ops/Overview.mdCoreFeatureSignExtensionOps// CoreFeatureSIMD enables the vector value type and vector instructions// (aka SIMD). This is included in CoreFeaturesV2, but not CoreFeaturesV1.//// Note: The instruction list is too long to enumerate in godoc.// See https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.mdCoreFeatureSIMD// Update experimental/features.go when adding elements here.)// SetEnabled enables or disables the feature or group of features.func ( CoreFeatures) ( CoreFeatures, bool) CoreFeatures {if {return |}return &^}// IsEnabled returns true if the feature (or group of features) is enabled.func ( CoreFeatures) ( CoreFeatures) bool {return & != 0}// RequireEnabled returns an error if the feature (or group of features) is not// enabled.func ( CoreFeatures) ( CoreFeatures) error {if & == 0 {return fmt.Errorf("feature %q is disabled", )}return nil}// String implements fmt.Stringer by returning each enabled feature.func ( CoreFeatures) () string {var strings.Builderfor := 0; <= 63; ++ { // cycle through all bits to reduce code and maintenance:= CoreFeatures(1 << )if .IsEnabled() {if := featureName(); != "" {if .Len() > 0 {.WriteByte('|')}.WriteString()}}}return .String()}func featureName( CoreFeatures) string {switch {case CoreFeatureMutableGlobal:// match https://github.com/WebAssembly/mutable-globalreturn "mutable-global"case CoreFeatureSignExtensionOps:// match https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/sign-extension-ops/Overview.mdreturn "sign-extension-ops"case CoreFeatureMultiValue:// match https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/multi-value/Overview.mdreturn "multi-value"case CoreFeatureNonTrappingFloatToIntConversion:// match https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/nontrapping-float-to-int-conversion/Overview.mdreturn "nontrapping-float-to-int-conversion"case CoreFeatureBulkMemoryOperations:// match https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/bulk-memory-operations/Overview.mdreturn "bulk-memory-operations"case CoreFeatureReferenceTypes:// match https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/reference-types/Overview.mdreturn "reference-types"case CoreFeatureSIMD:// match https://github.com/WebAssembly/spec/blob/wg-2.0.draft1/proposals/simd/SIMD.mdreturn "simd"}return ""}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |